Options
All
  • Public
  • Public/Protected
  • All
Menu

Module helpers

Index

References

BaseUriParameters

Re-exports BaseUriParameters

CompositeParameters

Re-exports CompositeParameters

CustomParams

Re-exports CustomParams

PathParameters

Re-exports PathParameters

QueryParameters

Re-exports QueryParameters

RequireParametersUnlessAllAreOptional

Re-exports RequireParametersUnlessAllAreOptional

UrlParameters

Re-exports UrlParameters

authorize

Re-exports authorize

callCustomEndpoint

Re-exports callCustomEndpoint

createCodeVerifier

Re-exports createCodeVerifier

doFetch

Re-exports doFetch

fetch

Re-exports fetch

generateCodeChallenge

Re-exports generateCodeChallenge

getCodeAndUsidFromUrl

Re-exports getCodeAndUsidFromUrl

globalObject

Re-exports globalObject

hasFetchAvailable

Re-exports hasFetchAvailable

isBrowser

Re-exports isBrowser

isNode

Re-exports isNode

loginGuestUser

Re-exports loginGuestUser

loginGuestUserPrivate

Re-exports loginGuestUserPrivate

loginRegisteredUserB2C

Re-exports loginRegisteredUserB2C

logout

Re-exports logout

refreshAccessToken

Re-exports refreshAccessToken

stringToBase64

Re-exports stringToBase64

Type aliases

CompositeParameters

CompositeParameters<MethodParameters, ConfigParameters>: Prettify<Omit<MethodParameters, keyof ConfigParameters> & Partial<MethodParameters>>

Generates the types required on a method, based on those provided in the config.

Type parameters

  • MethodParameters: Record<string, unknown>

  • ConfigParameters: Record<string, unknown>

Prettify

Prettify<T>: NonNullable<{}>

Makes a type easier to read.

Type parameters

  • T

RequireParametersUnlessAllAreOptional

RequireParametersUnlessAllAreOptional<T>: Record<string, never> extends NonNullable<T["parameters"]> ? T : Prettify<T & Required<Pick<T, "parameters">>>

If an object has a parameters property, and the parameters object has required properties, then the parameters property on the root object is marked as required.

Type parameters

  • T: { parameters?: Record<string, unknown> }

UrlParameters

Generic interface for all parameter types.

Variables

Const fetch

fetch: FetchFunction = (() => {if (isNode) {// .default is added because the newer versions of babel doesn't get the default export automatically for require().// eslint-disable-next-line global-require, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-member-accessreturn require('node-fetch').default;}// difficult to test in node environment/* istanbul ignore next */if (!hasFetchAvailable)throw new Error('Bad environment: it is not a node environment but fetch is not defined');return globalObject.fetch;})()

Const globalObject

globalObject: globalThis = isBrowser ? window : globalThis

Const hasFetchAvailable

hasFetchAvailable: boolean = typeof globalObject.fetch === 'function'

Const isBrowser

isBrowser: boolean = typeof window === 'object' && typeof window.document === 'object'

Const isNode

isNode: boolean = typeof process === 'object' &&typeof process.versions === 'object' &&typeof process.versions.node === 'string'

Const stringToBase64

stringToBase64: btoa = isBrowser? btoa: (unencoded: string): string => Buffer.from(unencoded).toString('base64')

Functions

authorize

  • authorize(slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>, codeVerifier: string, parameters: { hint?: undefined | string; redirectURI: string; usid?: undefined | string }): Promise<{ code: string; url: string; usid: string }>
  • Wrapper for the authorization endpoint. For federated login (3rd party IDP non-guest), the caller should redirect the user to the url in the url field of the returned object. The url will be the login page for the 3rd party IDP and the user will be sent to the redirectURI on success. Guest sessions return the code and usid directly with no need to redirect.

    Parameters

    • slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>

      a configured instance of the ShopperLogin SDK client

    • codeVerifier: string

      random string created by client app to use as a secret in the request

    • parameters: { hint?: undefined | string; redirectURI: string; usid?: undefined | string }

      Request parameters used by the authorizeCustomer endpoint.

      • Optional hint?: undefined | string
      • redirectURI: string

        the location the client will be returned to after successful login with 3rd party IDP. Must be registered in SLAS.

      • Optional usid?: undefined | string

    Returns Promise<{ code: string; url: string; usid: string }>

    login url, user id and authorization code if available

Const callCustomEndpoint

  • callCustomEndpoint(args: { clientConfig: ClientConfigInit<CustomParams>; options: { body?: BodyInit | globalThis.BodyInit | unknown; customApiPathParameters?: undefined | { apiName?: undefined | string; apiVersion?: undefined | string; endpointPath?: undefined | string; organizationId?: undefined | string; shortCode?: undefined | string }; headers?: { authorization?: undefined | string } & {}; method?: undefined | string; parameters?: undefined | {} }; rawResponse?: undefined | false | true }): Promise<Response | unknown>
  • A helper function designed to make calls to a custom API endpoint For more information about custom APIs, please refer to the API documentation

    Parameters

    • args: { clientConfig: ClientConfigInit<CustomParams>; options: { body?: BodyInit | globalThis.BodyInit | unknown; customApiPathParameters?: undefined | { apiName?: undefined | string; apiVersion?: undefined | string; endpointPath?: undefined | string; organizationId?: undefined | string; shortCode?: undefined | string }; headers?: { authorization?: undefined | string } & {}; method?: undefined | string; parameters?: undefined | {} }; rawResponse?: undefined | false | true }

      Argument object containing data used for custom API request

      • clientConfig: ClientConfigInit<CustomParams>
      • options: { body?: BodyInit | globalThis.BodyInit | unknown; customApiPathParameters?: undefined | { apiName?: undefined | string; apiVersion?: undefined | string; endpointPath?: undefined | string; organizationId?: undefined | string; shortCode?: undefined | string }; headers?: { authorization?: undefined | string } & {}; method?: undefined | string; parameters?: undefined | {} }
        • Optional body?: BodyInit | globalThis.BodyInit | unknown
        • Optional customApiPathParameters?: undefined | { apiName?: undefined | string; apiVersion?: undefined | string; endpointPath?: undefined | string; organizationId?: undefined | string; shortCode?: undefined | string }
        • Optional headers?: { authorization?: undefined | string } & {}
        • Optional method?: undefined | string
        • Optional parameters?: undefined | {}
      • Optional rawResponse?: undefined | false | true

    Returns Promise<Response | unknown>

    Raw response or data from response based on rawResponse argument from fetch call

Const contentTypeHeaderExists

  • contentTypeHeaderExists(headers: Record<string, string> | undefined): boolean
  • Parameters

    • headers: Record<string, string> | undefined

    Returns boolean

Const createCodeVerifier

  • createCodeVerifier(): string
  • Creates a random string to use as a code verifier. This code is created by the client and sent with both the authorization request (as a code challenge) and the token request.

    Returns string

    code verifier

Const doFetch

  • doFetch<Params>(url: string, options?: undefined | { body?: BodyInit | globalThis.BodyInit | unknown; headers?: { authorization?: undefined | string } & {}; method?: undefined | string }, clientConfig?: ClientConfigInit<Params>, rawResponse?: undefined | false | true): Promise<Response | unknown>
  • A wrapper function around fetch designed for making requests using the SDK

    Type parameters

    Parameters

    • url: string

      The url of the resource that you wish to fetch

    • Optional options: undefined | { body?: BodyInit | globalThis.BodyInit | unknown; headers?: { authorization?: undefined | string } & {}; method?: undefined | string }
    • Optional clientConfig: ClientConfigInit<Params>
    • Optional rawResponse: undefined | false | true

    Returns Promise<Response | unknown>

    Raw response or data from response based on rawResponse argument from fetch call

Const generateCodeChallenge

  • generateCodeChallenge(codeVerifier: string): Promise<string>
  • Encodes a code verifier to a code challenge to send to the authorization endpoint

    Parameters

    • codeVerifier: string

      random string to use as a code verifier

    Returns Promise<string>

    code challenge

Const getCodeAndUsidFromUrl

  • getCodeAndUsidFromUrl(urlString: string): { code: string; usid: string }
  • Parse out the code and usid from a redirect url

    Parameters

    • urlString: string

      A url that contains code and usid query parameters, typically returned when calling a Shopper Login endpoint

    Returns { code: string; usid: string }

    An object containing the code and usid.

    • code: string
    • usid: string

loginGuestUser

  • loginGuestUser(slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>, parameters: { redirectURI: string; usid?: undefined | string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Public Client Guest Login with proof key for code exchange flow as described in the API documentation.

    Parameters

    • slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>

      a configured instance of the ShopperLogin SDK client.

    • parameters: { redirectURI: string; usid?: undefined | string }

      parameters to pass in the API calls.

      • redirectURI: string

        Per OAuth standard, a valid app route. Must be listed in your SLAS configuration. On server, this will not be actually called. On browser, this will be called, but ignored.

      • Optional usid?: undefined | string

    Returns Promise<TokenResponse>

    TokenResponse

loginGuestUserPrivate

  • loginGuestUserPrivate(slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>, parameters: { usid?: undefined | string }, credentials: { clientSecret: string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Guest Login as described in the API documentation. Note: this func can run on client side. Only use this one when the slas client secret is secured.

    Parameters

    • slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>

      a configured instance of the ShopperLogin SDK client

    • parameters: { usid?: undefined | string }

      parameters to pass in the API calls.

      • Optional usid?: undefined | string
    • credentials: { clientSecret: string }

      client secret used for authentication

      • clientSecret: string

        secret associated with client ID

    Returns Promise<TokenResponse>

    TokenResponse

loginRegisteredUserB2C

  • loginRegisteredUserB2C(slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>, credentials: { clientSecret?: undefined | string; password: string; username: string }, parameters: { redirectURI: string; usid?: undefined | string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Public Client Registered User B2C Login with proof key for code exchange flow as described in the API documentation. Note: this func can run on client side. Only use private slas when the slas client secret is secured.

    Parameters

    • slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>

      a configured instance of the ShopperLogin SDK client.

    • credentials: { clientSecret?: undefined | string; password: string; username: string }

      the id and password and clientSecret (if applicable) to login with.

      • Optional clientSecret?: undefined | string
      • password: string

        the password of the user to login with.

      • username: string

        the id of the user to login with.

    • parameters: { redirectURI: string; usid?: undefined | string }

      parameters to pass in the API calls.

      • redirectURI: string

        Per OAuth standard, a valid app route. Must be listed in your SLAS configuration. On server, this will not be actually called. On browser, this will be called, but ignored.

      • Optional usid?: undefined | string

    Returns Promise<TokenResponse>

    TokenResponse

logout

  • logout(slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>, parameters: { accessToken: string; refreshToken: string }): Promise<TokenResponse>
  • Logout a shopper. The shoppers access token and refresh token will be revoked and if the shopper authenticated with ECOM the OCAPI JWT will also be revoked.

    Parameters

    • slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>

      a configured instance of the ShopperLogin SDK client.

    • parameters: { accessToken: string; refreshToken: string }

      parameters to pass in the API calls.

      • accessToken: string

        a valid access token to exchange for a new access token (and refresh token).

      • refreshToken: string

        a valid refresh token to exchange for a new access token (and refresh token).

    Returns Promise<TokenResponse>

    TokenResponse

Const nanoid

  • nanoid(): string
  • Adds entropy to nanoid() using seedrandom to ensure that the code_challenge sent to SCAPI by Google's crawler browser is unique. Solves the issue with Google's crawler getting the same result from nanoid() in two different runs, which results in the same PKCE code_challenge being used twice.

    Returns string

refreshAccessToken

  • refreshAccessToken(slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>, parameters: { refreshToken: string }, credentials?: undefined | { clientSecret?: undefined | string }): Promise<TokenResponse>
  • Exchange a refresh token for a new access token. Note: this func can run on client side. Only use private slas when the slas client secret is secured.

    Parameters

    • slasClient: ShopperLogin<{ clientId: string; organizationId: string; shortCode: string; siteId: string }>

      a configured instance of the ShopperLogin SDK client.

    • parameters: { refreshToken: string }

      parameters to pass in the API calls.

      • refreshToken: string

        a valid refresh token to exchange for a new access token (and refresh token).

    • Optional credentials: undefined | { clientSecret?: undefined | string }

      the clientSecret (if applicable) to login with.

    Returns Promise<TokenResponse>

    TokenResponse

Generated using TypeDoc