Options
All
  • Public
  • Public/Protected
  • All
Menu

Module helpers

Index

References

slasHelpers

Re-exports slasHelpers

Type aliases

CustomApiParameters

CustomApiParameters: { apiName?: string; apiVersion?: string; endpointName?: string; organizationId?: string; shortCode?: string }

Type declaration

  • Optional apiName?: string
  • Optional apiVersion?: string
  • Optional endpointName?: string
  • Optional organizationId?: string
  • Optional shortCode?: string

LoginRequest

LoginRequest: { channel_id: string; client_id?: string; code_challenge?: string; redirect_uri: string; response_type?: string; scope?: string; state?: string; usid?: string } & {}

TokenRequest

TokenRequest: { channel_id?: string; client_id?: string; code?: string; code_verifier?: string; grant_type: string; redirect_uri?: string; refresh_token?: string; usid?: string } & {}

TokenResponse

TokenResponse: { access_token: string; customer_id: string; enc_user_id: string; expires_in: number; id_token: string; idp_access_token: string; refresh_token: string; token_type: string; usid: string } & {}

Variables

Const CUSTOM_API_DEFAULT_BASE_URI

CUSTOM_API_DEFAULT_BASE_URI: "https://{shortCode}.api.commercecloud.salesforce.com/custom/{apiName}/{apiVersion}" = "https://{shortCode}.api.commercecloud.salesforce.com/custom/{apiName}/{apiVersion}"

Functions

authorize

  • authorize(slasClient: ISlasClient, codeVerifier: string, parameters: { hint?: string; redirectURI: string; usid?: 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: ISlasClient

      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?: string; redirectURI: string; usid?: string }

      Request parameters used by the authorizeCustomer endpoint.

      • Optional hint?: 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?: string

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

    login url, user id and authorization code if available

Const callCustomEndpoint

  • callCustomEndpoint(args: { clientConfig: ClientConfig<CustomApiParameters & CommonParameters>; options: { body?: BodyInit | unknown; customApiPathParameters?: CustomApiParameters; enableTransformBody?: boolean; fetchOptions?: RequestInit; headers?: { authorization?: string } & {}; method?: string; parameters?: {}; retrySettings?: OperationOptions }; rawResponse?: boolean }): 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: ClientConfig<CustomApiParameters & CommonParameters>; options: { body?: BodyInit | unknown; customApiPathParameters?: CustomApiParameters; enableTransformBody?: boolean; fetchOptions?: RequestInit; headers?: { authorization?: string } & {}; method?: string; parameters?: {}; retrySettings?: OperationOptions }; rawResponse?: boolean }

      Argument object containing data used for custom API request

      • clientConfig: ClientConfig<CustomApiParameters & CommonParameters>
      • options: { body?: BodyInit | unknown; customApiPathParameters?: CustomApiParameters; enableTransformBody?: boolean; fetchOptions?: RequestInit; headers?: { authorization?: string } & {}; method?: string; parameters?: {}; retrySettings?: OperationOptions }
        • Optional body?: BodyInit | unknown
        • Optional customApiPathParameters?: CustomApiParameters
        • Optional enableTransformBody?: boolean
        • Optional fetchOptions?: RequestInit
        • Optional headers?: { authorization?: string } & {}
        • Optional method?: string
        • Optional parameters?: {}
          • [key: string]: string | number | boolean | string[] | number[]
        • Optional retrySettings?: OperationOptions
      • Optional rawResponse?: boolean

    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 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

  • 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: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • parameters: { redirectURI: string; usid?: 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

      • Optional usid?: string

    Returns Promise<TokenResponse>

    TokenResponse

loginGuestUserPrivate

  • loginGuestUserPrivate(slasClient: ISlasClient, credentials: { clientSecret: string }, usid?: string): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Guest Login as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client

    • credentials: { clientSecret: string }

      client secret used for authentication

      • clientSecret: string

        secret associated with client ID

    • Optional usid: string

    Returns Promise<TokenResponse>

    TokenResponse

loginRegisteredUserB2C

  • loginRegisteredUserB2C(slasClient: ISlasClient, credentials: { password: string; username: string }, parameters: { redirectURI: string; usid?: string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Registered User B2C Login with proof key for code exchange flow as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • credentials: { password: string; username: string }

      the id and password to login with.

      • password: string

        the password of the user to login with.

      • username: string

        the id of the user to login with.

    • parameters: { redirectURI: string; usid?: 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?: string

    Returns Promise<TokenResponse>

    TokenResponse

loginRegisteredUserB2Cprivate

  • loginRegisteredUserB2Cprivate(slasClient: ISlasClient, credentials: { clientSecret: string; password: string; username: string }, parameters: { redirectURI: string; usid?: string }): Promise<TokenResponse>
  • A single function to execute the ShopperLogin Private Client Registered User B2C Login as described in the API documentation.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • credentials: { clientSecret: string; password: string; username: string }

      the shopper username and password for login and client secret for additional authentication

      • clientSecret: string

        secret associated with client ID

      • password: string

        the password of the user to login with

      • username: string

        the id of the user to login with

    • parameters: { redirectURI: string; usid?: 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

      • Optional usid?: string

    Returns Promise<TokenResponse>

    TokenResponse

logout

  • 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: ISlasClient

      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

refreshAccessToken

  • Exchange a refresh token for a new access token.

    Parameters

    • slasClient: ISlasClient

      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).

    Returns Promise<TokenResponse>

    TokenResponse

refreshAccessTokenPrivate

  • refreshAccessTokenPrivate(slasClient: ISlasClient, credentials: { clientSecret: string }, parameters: { refreshToken: string }): Promise<TokenResponse>
  • Exchange a refresh token for a new access token.

    Parameters

    • slasClient: ISlasClient

      a configured instance of the ShopperLogin SDK client.

    • credentials: { clientSecret: string }

      client secret used for authentication

      • clientSecret: string

        secret associated with client ID

    • 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).

    Returns Promise<TokenResponse>

    TokenResponse

Const stringToBase64

  • stringToBase64(unencoded: string): string
  • Converts a string into Base64 encoding

    Parameters

    • unencoded: string

      A string to be encoded

    Returns string

    Base64 encoded string

Object literals

Const helpers

helpers: object

callCustomEndpoint

callCustomEndpoint: callCustomEndpoint

Generated using TypeDoc