UNPKG

salsify-experiences-sdk

Version:

SDK to be used by commerce websites to implement product experiences.

92 lines (91 loc) 2.97 kB
import SdkOptions from './options'; import { EnhancedContentSettings } from './settings'; import EnhancedContentApi from './enhancedContent'; import EventsApi from './events'; /** @internal */ export interface Context { /** URL of the website serving the enhanced content, if operating within the browser */ url: string | undefined; /** UUID for the user visiting the website if operating within the browser, * stored in / retrieved from a session cookie unless tracking is set to false * * If tracking is false, this is set to "NOT_TRACKED" */ sessionId: string | undefined; /** UUID for the page visit, if operating within the browser * * Not stored in a cookie; reset across page visits */ pageSessionId: string | undefined; /** Whether or not cookie-based user tracking is enabled. The host site is responsible * for displaying any user consent dialogs and setting this option based on the user's * preference. */ tracking: boolean; /** Client identifier (UUID) provided by Salsify that uniquely identifies the website */ clientId: string; /** Locale identifier that determines the language of the page content */ languageCode: string; /** Enhanced Content settings, including the product identifier type */ enhancedContent: EnhancedContentSettings; /** SDK version */ version: string; jsSource: 'bundle' | 'npm'; } /** * The Salsify Experiences SDK. * * This class is responsible for initializing the SDK and exposing the public getter methods for each different available API. */ export default class SdkApi { #private; /** @internal */ constructor(jsSource: 'bundle' | 'npm'); /** * Initializes the SDK. * * @example * ```javascript * window.salsifyExperiencesSdk.init({ clientId, enhancedContent: { idType }}) * ``` * * @param options The options to initialize the SDK with. */ init(options: SdkOptions): void; /** * Whether the SDK has been initialized. * * @example * ```javascript * const salsify = window.salsifyExperiencesSdk; * salsify.initialized; // false * salsify.init({ clientId, enhancedContent: { idType } }); * salsify.initialized; // true * ``` */ get initialized(): boolean; /** * The initialized Enhanced Content API. * * Throws an error if the SDK has not been initialized. * * @example * ```javascript * const salsify = window.salsifyExperiencesSdk; * const ec = salsify.enhancedContent; * ``` */ get enhancedContent(): EnhancedContentApi; /** * The initialized Events API. * * Throws an error if the SDK has not been initialized. * * @example * ```javascript * const salsify = window.salsifyExperiencesSdk; * const events = salsify.events; * ``` */ get events(): EventsApi; }