Manual Reference Source Test
import IdentityServer from 'src/modules/identity-server.js'
public class | source

IdentityServer

Identity server

Constructor Summary

Public Constructor
public

constructor(options: Object)

IdentityServer constructor

Member Summary

Public Members
public

config: *

Method Summary

Public Methods
public

call(path: string, options: Object): Promise

Makes an Identity server API call

public

Returns an Identity Call URL with specified path

public

getSdkUrl(path: String, customBase: String): String

Returns a SDK URL with specified path

public

request(pathOrUrl: string, options: Object): Promise

Requests specified path (or URL) and returns a Promise of JSON parsed response body

public

sdk(path: String, customBase: String, options: Object): Promise

Requests a response from an SDK path

public

setConfig(config: Object)

Set the config in the server scope

Public Constructors

public constructor(options: Object) source

IdentityServer constructor

Params:

NameTypeAttributeDescription
options Object
  • optional
  • default: {}

Options

options.env string
  • optional
  • default: 'production'

Environment to use, e.g: dev/stage/..

options.idmVersion string
  • optional
  • default: 'v2'

Identity server API version

options.sdkVersion string
  • optional
  • default: 'test'

Identity server API version

options.timeout number
  • optional
  • default: 20

Default request timeout in seconds (0 to disable)

Public Members

public config: * source

Public Methods

public call(path: string, options: Object): Promise source

Makes an Identity server API call

This adds some standard headers and then requests specified path (e.g: endpoint).

See IdentityServer#getSdkUrl for details on the URL that is used. See IdentityServer#request for further supported options etc.

Params:

NameTypeAttributeDescription
path string

Request path

options Object
  • optional
  • default: {}

Request options

options.headers Object
  • optional
  • default: {}

Request headers

Return:

Promise

Promise of response body

public getCallUrl(path: string): string source

Returns an Identity Call URL with specified path

This defaults to using the server url as base, but uses a special proxy instead when we are cross origin. Note: This proxy currently only supports envs: dev and stage TODO: Get rid of this workaround once Akamai supports adding /index.html and we can use *-id.nbc.com/sdk/

Params:

NameTypeAttributeDescription
path string
  • optional
  • default: ''

Identity Call path

Return:

string

Identity Call URL with specified path

public getSdkUrl(path: String, customBase: String): String source

Returns a SDK URL with specified path

This defaults to using the server url + /sdk as base, but uses the s3-website instead when we are cross origin.

This also adds the SDK version to the URL to serve as a cache buster.

See IdentityServer#request for supported options etc.

Params:

NameTypeAttributeDescription
path String
  • optional
  • default: ''

SDK Request path

customBase String
  • optional
  • default: null

Custom SDK base URL

Return:

String

SDK URL with specified path

public request(pathOrUrl: string, options: Object): Promise source

Requests specified path (or URL) and returns a Promise of JSON parsed response body

If response is not OK the returned Promise is rejected.

If the returned Promise is rejected, the associated Error instance is decorated with status (number), statusText (string) and retry (function) properties. The retry function can be called to retry the request.

If a body is specified it will be JSON stringified and a Content-Type: application/json header will be added.

If a timeout is specified that will be used, otherwise the default IdentityServer timeout will be used.

Besides these options, standard fetch init properties (e.g: method) are supported as options as well.

Params:

NameTypeAttributeDescription
pathOrUrl string

Request path or URL

options Object
  • optional
  • default: {}

Options

options.headers Object
  • optional
  • default: {}

Request headers

options.body Object
  • optional

Request body

options.timeout number
  • optional

Request timeout in seconds (0 to disable)

Return:

Promise

Promise of JSON parsed response body

See:

public sdk(path: String, customBase: String, options: Object): Promise source

Requests a response from an SDK path

See IdentityServer#getSdkUrl for details on the URL that is used. See IdentityServer#request for supported options etc.

Params:

NameTypeAttributeDescription
path String

SDK Request path

customBase String
  • optional
  • default: null

Custom SDK base URL

options Object
  • optional
  • default: {}

Request options

Return:

Promise

Promise of JSON parsed response body

public setConfig(config: Object) source

Set the config in the server scope

Params:

NameTypeAttributeDescription
config Object