@monterosa/sdk-identify-kit 0.18.7 → 0.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1034,7 +1034,7 @@ function onExperienceEmbed(experience) {
1034
1034
  });
1035
1035
  });
1036
1036
  var sdkMessageUnsub = sdkLauncherKit.onSdkMessage(experience, function (message) { return __awaiter(_this, void 0, void 0, function () {
1037
- var origin, sdk, originIdentify, _a, signature, userData, err_1;
1037
+ var origin, originSdk, originIdentify, _a, signature, userData, err_1;
1038
1038
  return __generator(this, function (_b) {
1039
1039
  switch (_b.label) {
1040
1040
  case 0:
@@ -1042,8 +1042,10 @@ function onExperienceEmbed(experience) {
1042
1042
  return [2 /*return*/];
1043
1043
  }
1044
1044
  origin = message.payload.origin;
1045
- sdk = getOrConfigureSdk(origin.host, origin.projectId);
1046
- originIdentify = getIdentify(sdk);
1045
+ originSdk = origin
1046
+ ? getOrConfigureSdk(origin.host, origin.projectId)
1047
+ : experience.sdk;
1048
+ originIdentify = getIdentify(originSdk);
1047
1049
  _b.label = 1;
1048
1050
  case 1:
1049
1051
  _b.trys.push([1, 13, , 14]);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/constants.ts","../src/identify.ts","../src/api.ts","../src/bridge.ts"],"sourcesContent":["/**\n * @license\n * public_types.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk } from '@monterosa/sdk-core';\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * The type represents a user credentials. It contains a single property, token,\n * which can be either the literal 'cookie' for cookie-based authentication or\n * a string value representing the user's authentication token for bearer token\n * authentication.\n *\n * @example\n * ```javascript\n * // Bearer token authentication\n * const credentials: Credentials = { token: \"abc123\" };\n *\n * // Cookie-based authentication\n * const credentials: Credentials = { token: \"cookie\" };\n * ```\n */\nexport type Credentials = {\n token: 'cookie' | string;\n};\n\n/**\n *\n * The type represents a digital signature. It contains three properties:\n * `userId`, `timestamp`, and `signature`. These properties are respectively of\n * type `string`, `number`, and `string`.\n *\n * @example\n * ```javascript\n * const signature: Signature = [\"user123\", 1646956195, \"abc123\"];\n * ```\n */\nexport type Signature = [userId: string, timestamp: number, signature: string];\n\n/**\n * The type represents a set of user data. It contains three properties:\n * `userId`, `timestamp`, and `signature`. In addition, it allows for any\n * number of additional properties to be defined using TypeScript's index\n * signature syntax. The `userId` property is a string value representing\n * the user's unique identifier. The `timestamp` property is a number value\n * representing the time when the user's data was last updated. The `signature`\n * property is a string value representing the digital signature of the user's\n * data.\n *\n * @example\n * ```javascript\n * const userData: UserData = {\n * userId: \"user123\",\n * timeStamp: 1646956195,\n * signature: \"abc123\",\n * name: \"John Doe\",\n * age: 30,\n * email: \"john.doe@example.com\"\n * };\n * ```\n */\nexport type UserData = {\n [key: string]: any;\n};\n\nexport type ResponsePayload<T> = {\n result: 'success' | 'failure';\n data: T;\n message: string;\n};\n\n/**\n * @internal\n */\nexport type IdentifyHook = (identify: IdentifyKit) => Unsubscribe;\n\nexport interface IdentifyOptions {\n readonly deviceId?: string;\n readonly strategy?: string;\n readonly provider?: string;\n readonly version?: number;\n}\n\n/**\n * The `IdentifyKit` interface provides a set of properties and methods\n * for managing user identification.\n */\nexport interface IdentifyKit extends Emitter {\n /**\n * @internal\n */\n sdk: MonterosaSdk;\n /**\n * @internal\n */\n options: IdentifyOptions;\n /**\n * @internal\n */\n credentials: Credentials | null;\n /**\n * @internal\n */\n signature: Signature | null;\n /**\n * @internal\n */\n userData: UserData | null;\n\n /**\n * @internal\n */\n expireSignature(delay: number): void;\n\n /**\n * @internal\n */\n expireUserData(delay: number): void;\n\n /**\n * @internal\n */\n getUrl(path?: string): Promise<string>;\n}\n\nexport interface Response {\n message: string;\n result: number;\n data: {\n [key: string]: any;\n };\n}\n\nexport interface UserResponse extends Response {}\n\nexport interface UserCheckResponse extends Response {\n data: {\n userId: string;\n timeStamp: number;\n signature: string;\n [key: string]: any;\n };\n}\n\n/**\n * @internal\n */\nexport enum IdentifyEvent {\n LoginRequested = 'login_requested',\n SignatureUpdated = 'signature_updated',\n CredentialsUpdated = 'credentials_updated',\n UserdataUpdated = 'userdata_updated',\n ApiUserCheckFailed = 'api_user_check_failed',\n ApiUserDataFailed = 'api_user_data_failed',\n CredentialsValidationFailed = 'credentials_validation_failed',\n}\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Identify kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the IdentifyKit\n * } catch (err) {\n * if (err.code === IdentifyError.NoCredentials) {\n * // handle missing credentials error\n * } else if (err.code === IdentifyError.NotInitialised) {\n * // handle initialization error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `IdentifyError` enum provides a convenient way to handle errors\n * encountered when using the `IdentifyKit` module. By checking the code\n * property of the caught error against the values of the enum, the error\n * type can be determined and appropriate action taken.\n *\n * - The `IdentifyError` enum is not intended to be instantiated or extended.\n */\nexport enum IdentifyError {\n /**\n * Indicates an error occurred during the call to the extension API.\n */\n ExtensionApiError = 'extension_api_error',\n /**\n * Indicates the extension required by the IdentifyKit is not set up properly.\n */\n ExtensionNotSetup = 'extension_not_setup',\n /**\n * Indicates the user's authentication credentials are not available\n * or have expired.\n */\n NoCredentials = 'no_credentials',\n /**\n * Indicates the IdentifyKit has not been initialized properly.\n */\n NotInitialised = 'not_initialised',\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates there is no parent application to delegate to.\n */\n NoParentApplication = 'no_parent_application',\n}\n\n/**\n * @internal\n */\nexport const IdentifyErrorMessages = {\n [IdentifyError.ExtensionApiError]: (error: string) =>\n `Identify extension API returned an error: ${error}`,\n [IdentifyError.ExtensionNotSetup]: () =>\n 'Identify extension is not set up for this project',\n [IdentifyError.NoCredentials]: () => 'Identify credentials are not set',\n [IdentifyError.NotInitialised]: () => 'Identify instance is not initialised',\n [IdentifyError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [IdentifyError.NoParentApplication]: () =>\n 'No parent application available for delegation',\n};\n\nexport enum IdentifyAction {\n RequestLogin = 'identifyRequestLogin',\n Logout = 'identifyLogout',\n GetSessionSignature = 'identifyGetSessionSignature',\n GetUserData = 'identifyGetUserData',\n SetCredentials = 'identifySetCredentials',\n OnCredentialsUpdated = 'identifyOnCredentialsUpdated',\n OnUserDataUpdated = 'identifyOnUserDataUpdated',\n OnSessionSignatureUpdated = 'identifyOnSessionSignatureUpdated',\n OnLoginRequestedByExperience = 'identifyOnLoginRequestedByExperience',\n OnCredentialsValidationFailed = 'identifyOnCredentialsValidationFailed',\n}\n","/**\n * @license\n * constants.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-22\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport const EXTENSION_ID = 'lvis-id-custom-tab';\n\nexport const SIGNATURE_TTL = 10000;\n\nexport const USER_DATA_TTL = 10000;\n","/**\n * @license\n * identify.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, getDeviceId } from '@monterosa/sdk-core';\nimport { Emitter, createError } from '@monterosa/sdk-util';\nimport { fetchListings } from '@monterosa/sdk-interact-interop';\n\nimport {\n IdentifyKit,\n IdentifyOptions,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n Credentials,\n Signature,\n UserData,\n} from './types';\n\nimport { EXTENSION_ID } from './constants';\n\nexport default class Identify extends Emitter implements IdentifyKit {\n private host?: string;\n\n private readonly _options: IdentifyOptions;\n\n private _credentials: Credentials | null = null;\n private _signature: Signature | null = null;\n private _userData: UserData | null = null;\n private signatureExpireTimeout!: ReturnType<typeof setTimeout>;\n private userDataExpireTimeout!: ReturnType<typeof setTimeout>;\n\n constructor(public sdk: MonterosaSdk, options: IdentifyOptions = {}) {\n super();\n\n this._options = {\n strategy: 'email',\n deviceId: getDeviceId(),\n version: 1,\n ...options,\n };\n }\n\n expireSignature(delay: number) {\n clearTimeout(this.signatureExpireTimeout);\n\n this.signatureExpireTimeout = setTimeout(() => {\n this.signature = null;\n }, delay);\n }\n\n expireUserData(delay: number) {\n clearTimeout(this.userDataExpireTimeout);\n\n this.userDataExpireTimeout = setTimeout(() => {\n this.userData = null;\n }, delay);\n }\n\n private static async fetchIdentifyHost(\n host: string,\n projectId: string,\n ): Promise<string> {\n const listings = await fetchListings(host, projectId);\n const extensionAssets = listings.assets?.[EXTENSION_ID] ?? [];\n\n const endpointAsset = extensionAssets.find(\n ({ name }) => name === 'endpoint',\n );\n\n if (!endpointAsset) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return endpointAsset.data;\n }\n\n get options() {\n return this._options;\n }\n\n set signature(signature: Signature | null) {\n if (this._signature === signature) {\n return;\n }\n\n this._signature = signature;\n\n clearTimeout(this.signatureExpireTimeout);\n\n this.emit(IdentifyEvent.SignatureUpdated, this.signature);\n }\n\n get signature(): Signature | null {\n return this._signature;\n }\n\n set credentials(credentials: Credentials | null) {\n if (this._credentials === credentials) {\n return;\n }\n\n this._credentials = credentials;\n\n // if credentials are updated, user data and signature are cleared\n this.userData = null;\n this.signature = null;\n\n this.emit(IdentifyEvent.CredentialsUpdated, credentials);\n }\n\n get credentials(): Credentials | null {\n return this._credentials;\n }\n\n set userData(data: UserData | null) {\n if (this._userData === data) {\n return;\n }\n\n this._userData = data;\n\n this.emit(IdentifyEvent.UserdataUpdated, data);\n }\n\n get userData(): UserData | null {\n return this._userData;\n }\n\n async getUrl(path: string = '') {\n const {\n options: { host, projectId },\n } = this.sdk;\n\n if (this.host === undefined) {\n this.host = await Identify.fetchIdentifyHost(host, projectId);\n }\n\n const url = new URL(this.host!);\n const { version, deviceId, strategy, provider } = this._options;\n\n url.pathname = `/v${version}${path}`;\n\n url.searchParams.set('projectId', projectId);\n url.searchParams.set('deviceId', deviceId!);\n url.searchParams.set('strategy', strategy!);\n\n if (provider !== undefined) {\n url.searchParams.set('provider', provider);\n }\n\n return url.toString();\n }\n}\n","/**\n * @license\n * api.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n getParentApplication,\n sendSdkRequest,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n Response,\n ResponsePayload,\n UserResponse,\n UserCheckResponse,\n Credentials,\n Signature,\n UserData,\n IdentifyOptions,\n IdentifyAction,\n IdentifyHook,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n} from './types';\n\nimport { SIGNATURE_TTL, USER_DATA_TTL } from './constants';\n\nimport Identify from './identify';\n\nconst identifyKits: Map<string, Identify> = new Map();\nconst identifyHooks: IdentifyHook[] = [];\n\nfunction isSdk(value: MonterosaSdk | any): value is MonterosaSdk {\n return value instanceof Sdk;\n}\n\nasync function api<T extends Response>(\n url: string,\n token: Credentials['token'],\n method: string = 'GET',\n): Promise<T> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n };\n\n let credentials: RequestCredentials | undefined;\n\n // Only include Authorization header for bearer token authentication\n // When token is 'cookie', use credentials: 'include' to ensure HttpOnly\n // cookies are sent\n if (token === 'cookie') {\n // Use credentials: 'include' to ensure HttpOnly cookies are sent\n credentials = 'include';\n } else {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n credentials,\n });\n\n const data = (await response.json()) as T;\n\n if (data.result < 0) {\n throw createError(\n IdentifyError.ExtensionApiError,\n IdentifyErrorMessages,\n data.message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest<T>(\n identify: IdentifyKit,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n throw createError(IdentifyError.NoParentApplication, IdentifyErrorMessages);\n }\n\n const { host, projectId } = identify.sdk.options;\n\n // Preserve existing origin (relay) or set from current context (source)\n const origin = payload?.origin ?? { host, projectId };\n\n const response = await sendSdkRequest(parentApp, action, {\n ...payload,\n origin,\n });\n\n const { result, data, message } = response.payload as ResponsePayload<T>;\n\n if (result === 'failure') {\n throw createError(\n IdentifyError.ParentAppError,\n IdentifyErrorMessages,\n message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport function registerIdentifyHook(hook: IdentifyHook) {\n identifyHooks.push(hook);\n}\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param sdk - An instance of the MonterosaSdk class.\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\n\nexport function getIdentify(\n sdk?: MonterosaSdk,\n options?: IdentifyOptions,\n): IdentifyKit;\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\nexport function getIdentify(options?: IdentifyOptions): IdentifyKit;\n\nexport function getIdentify(\n sdkOrOptions?: MonterosaSdk | IdentifyOptions,\n options?: IdentifyOptions,\n): IdentifyKit {\n let sdk: MonterosaSdk;\n let identifyOptions: IdentifyOptions;\n\n if (isSdk(sdkOrOptions)) {\n /**\n * Interface: getIdentify(sdk, options?)\n */\n\n sdk = sdkOrOptions;\n\n if (options !== undefined) {\n identifyOptions = options;\n } else {\n identifyOptions = {};\n }\n } else if (sdkOrOptions !== undefined) {\n /**\n * Interface: getIdentify(options)\n */\n\n sdk = getSdk();\n identifyOptions = sdkOrOptions;\n } else {\n /**\n * Interface: getIdentify()\n */\n\n sdk = getSdk();\n identifyOptions = {};\n }\n\n const {\n options: { projectId },\n } = sdk;\n\n if (identifyKits.has(projectId)) {\n return identifyKits.get(projectId) as Identify;\n }\n\n const identify = new Identify(sdk, identifyOptions);\n\n for (const hook of identifyHooks) {\n hook(identify);\n }\n\n identifyKits.set(projectId, identify);\n\n return identify;\n}\n\n/**\n * A function that requests a user login via the `IdentifyKit` of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await requestLogin(identify);\n *\n * console.log('Login request successful');\n * } catch (err) {\n * console.error('Error requesting login:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to handle the login process.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the login request\n * is completed.\n */\nexport async function requestLogin(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.RequestLogin);\n\n return;\n }\n\n identify.emit(IdentifyEvent.LoginRequested);\n}\n\n/**\n * A function that requests a user logout and removing their signature and\n * credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await logout(identify);\n *\n * console.log('User logged out');\n * } catch (err) {\n * console.error('Error logout:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to log the user out.\n *\n * - If the request is successful, the function resolves with void.\n * If not, a MonterosaError is thrown.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the logout request\n * is completed.\n */\nexport async function logout(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.Logout);\n\n return;\n }\n\n identify.signature = null;\n identify.credentials = null;\n}\n\n/**\n * Returns a signature for a user session. The signature is based on the\n * user's identifying information provided in the `IdentifyKit` instance.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getSession } from '@monterosa/sdk-identify-kit';\n * import { getConnect, login } from '@monterosa/sdk-connect-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const session = await getSession(identify);\n *\n * const connect = await getConnect();\n * await login(connect, ...session);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get session signature.\n *\n * - If the request is successful, the function resolves with `Signature`.\n * If not, a `MonterosaError` is thrown.\n *\n * - The function can be used to fetch a signature for a user session that\n * can be used to authenticate user with `ConnectKit`.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves to an object of type `Signature`.\n */\nexport async function getSessionSignature(\n identify: IdentifyKit,\n): Promise<Signature> {\n if (identify.signature !== null) {\n return identify.signature;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const signature = await parentAppRequest<Signature>(\n identify,\n IdentifyAction.GetSessionSignature,\n );\n\n return signature;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user/check');\n\n const { data } = await api<UserCheckResponse>(\n url,\n identify.credentials.token,\n );\n\n const signature: Signature = [data.userId, data.timeStamp, data.signature];\n\n identify.signature = signature;\n identify.expireSignature(SIGNATURE_TTL);\n\n return signature;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserCheckFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * The function that takes an instance of `IdentifyKit` as its argument and\n * returns a Promise that resolves to a `UserData` object.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getUserData } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const { userId } = await getUserData(identify);\n *\n * console.log(`User id is ${userId}`);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get user data.\n *\n * - If the request is successful, the function resolves with `UserData`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @returns A Promise that resolves to a `UserData` object. The `UserData`\n * object contains information about the user, including their `userId`,\n * `timestamp`, and `signature`, as well as any additional properties.\n */\nexport async function getUserData(identify: IdentifyKit): Promise<UserData> {\n if (identify.userData !== null) {\n return identify.userData;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const userData = await parentAppRequest<UserData>(\n identify,\n IdentifyAction.GetUserData,\n );\n\n return userData;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user');\n\n const { data } = await api<UserResponse>(url, identify.credentials.token);\n\n identify.userData = data;\n identify.expireUserData(USER_DATA_TTL);\n\n return data;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserDataFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * Sets the user's authentication credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, setCredentials } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const credentials = { token: 'abc123' };\n * const identify = getIdentify();\n *\n * await setCredentials(identify, credentials)\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to set user credentials.\n *\n * - If the request is successful, the function resolves to `void`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param credentials - An object representing the user's authentication\n * credentials.\n * @returns A Promise that resolves to `void`.\n */\nexport async function setCredentials(\n identify: IdentifyKit,\n credentials: Credentials,\n): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(\n identify,\n IdentifyAction.SetCredentials,\n credentials,\n );\n\n return;\n }\n\n identify.credentials = credentials;\n}\n\n/**\n * Registers a callback function that will be called whenever the `Credentials`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsUpdated(identify, (credentials) => {\n * if (credentials !== null) {\n * console.log(\"Credentials updated:\", credentials);\n * } else {\n * console.log(\"Credentials cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Credentials` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsUpdated(\n identify: IdentifyKit,\n callback: (credentials: Credentials | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.CredentialsUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `Signature`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onSignatureUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onSignatureUpdated(identify, (signature) => {\n * if (signature !== null) {\n * console.log(\"Signature updated:\", signature);\n * } else {\n * console.log(\"Signature cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Signature` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onSignatureUpdated(\n identify: IdentifyKit,\n callback: (signature: Signature | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.SignatureUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `UserData`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onUserDataUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onUserDataUpdated(identify, (userData) => {\n * if (userData !== null) {\n * console.log(\"User's data updated:\", userData);\n * } else {\n * console.log(\"User's data cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `UserData` object as its only argument.\n * If the value `null` is received, it indicates that the user's data has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onUserDataUpdated(\n identify: IdentifyKit,\n callback: (userData: UserData | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.UserdataUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called when a login is requested\n * by an Experience.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onLoginRequestedByExperience } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onLoginRequestedByExperience(identify, () => {\n * showLoginForm();\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when a login is requested by an experience.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onLoginRequestedByExperience(\n identify: IdentifyKit,\n callback: () => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.LoginRequested, callback);\n}\n\n/**\n * Registers a callback function that will be called when the credentials validation fails.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsValidationFailed } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsValidationFailed(identify, (error) => {\n * console.log(error);\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when an error occured.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsValidationFailed(\n identify: IdentifyKit,\n callback: (error: string) => void,\n): Unsubscribe {\n return subscribe(\n identify,\n IdentifyEvent.CredentialsValidationFailed,\n callback,\n );\n}\n","/**\n * @license\n * bridge.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-07\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, configure, getSdks } from '@monterosa/sdk-core';\nimport { Unsubscribe, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n getParentApplication,\n registerEmbedHook,\n respondToSdkMessage,\n sendSdkMessage,\n onSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n IdentifyAction,\n Credentials,\n Signature,\n UserData,\n IdentifyEvent,\n} from './types';\n\nimport {\n getIdentify,\n getUserData,\n getSessionSignature,\n setCredentials,\n requestLogin,\n logout,\n onCredentialsUpdated,\n onSignatureUpdated,\n onUserDataUpdated,\n onCredentialsValidationFailed,\n registerIdentifyHook,\n} from './api';\n\n/**\n * @internal\n */\nexport function parentMessagesHook(identify: IdentifyKit) {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, ({ action, payload }) => {\n switch (action) {\n case IdentifyAction.OnCredentialsUpdated: {\n identify.credentials = payload.credentials as Credentials;\n break;\n }\n case IdentifyAction.OnSessionSignatureUpdated: {\n identify.signature = payload.signature as Signature;\n break;\n }\n case IdentifyAction.OnUserDataUpdated: {\n identify.userData = payload.userData as UserData;\n break;\n }\n case IdentifyAction.OnCredentialsValidationFailed: {\n identify.emit(IdentifyEvent.CredentialsValidationFailed, payload.error);\n break;\n }\n }\n });\n}\n\n/**\n * Finds an existing SDK with matching projectId, or creates a new one.\n */\nfunction getOrConfigureSdk(host: string, projectId: string): MonterosaSdk {\n const existingSdk = getSdks().find(\n (sdk) => sdk.options.projectId === projectId,\n );\n\n return existingSdk ?? configure({ host, projectId }, projectId);\n}\n\nfunction onExperienceEmbed(experience: Experience): Unsubscribe {\n const identify = getIdentify(experience.sdk);\n\n const credentialsUpdatedUnsub = onCredentialsUpdated(\n identify,\n (credentials) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsUpdated, {\n credentials,\n });\n },\n );\n\n const signatureUpdatedUnsub = onSignatureUpdated(identify, (signature) => {\n sendSdkMessage(experience, IdentifyAction.OnSessionSignatureUpdated, {\n signature,\n });\n });\n\n const userDataUpdatedUnsub = onUserDataUpdated(identify, (userData) => {\n sendSdkMessage(experience, IdentifyAction.OnUserDataUpdated, {\n userData,\n });\n });\n\n const validationFailedUnsub = onCredentialsValidationFailed(\n identify,\n (error) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsValidationFailed, {\n error,\n });\n },\n );\n\n const sdkMessageUnsub = onSdkMessage(experience, async (message) => {\n if (\n !Object.values(IdentifyAction).includes(message.action as IdentifyAction)\n ) {\n return;\n }\n\n // Get origin context from payload\n const { origin } = message.payload as {\n origin: { host: string; projectId: string };\n };\n\n // Always use origin to get identify for the originating layer's context\n const sdk = getOrConfigureSdk(origin.host, origin.projectId);\n const originIdentify = getIdentify(sdk);\n\n try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Session signature obtained successfully',\n data: signature,\n });\n break;\n }\n case IdentifyAction.GetUserData: {\n const userData = await getUserData(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'User data obtained successfully',\n data: userData,\n });\n break;\n }\n case IdentifyAction.SetCredentials: {\n await setCredentials(originIdentify, {\n token: message.payload.token as Credentials['token'],\n });\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Credentials updated successfully',\n data: {},\n });\n\n break;\n }\n }\n } catch (err) {\n respondToSdkMessage(experience, message, {\n result: 'failure',\n message: getErrorMessage(err),\n data: {},\n });\n }\n });\n\n return () => {\n credentialsUpdatedUnsub();\n signatureUpdatedUnsub();\n userDataUpdatedUnsub();\n sdkMessageUnsub();\n validationFailedUnsub();\n };\n}\n\nregisterEmbedHook(onExperienceEmbed);\nregisterIdentifyHook(parentMessagesHook);\n"],"names":["IdentifyError","getDeviceId","fetchListings","createError","Emitter","Sdk","getParentApplication","sendSdkRequest","getSdk","subscribe","onSdkMessage","getSdks","configure","sendSdkMessage","respondToSdkMessage","getErrorMessage","registerEmbedHook"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAuJA;;;AAGA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,mDAA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EAAE,CAAC;QAClB,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC;AAEDC,gCAAiB,CAAC,iBAAiB,CAAC,CAAC;AACrC,oBAAoB,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/constants.ts","../src/identify.ts","../src/api.ts","../src/bridge.ts"],"sourcesContent":["/**\n * @license\n * public_types.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk } from '@monterosa/sdk-core';\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * The type represents a user credentials. It contains a single property, token,\n * which can be either the literal 'cookie' for cookie-based authentication or\n * a string value representing the user's authentication token for bearer token\n * authentication.\n *\n * @example\n * ```javascript\n * // Bearer token authentication\n * const credentials: Credentials = { token: \"abc123\" };\n *\n * // Cookie-based authentication\n * const credentials: Credentials = { token: \"cookie\" };\n * ```\n */\nexport type Credentials = {\n token: 'cookie' | string;\n};\n\n/**\n *\n * The type represents a digital signature. It contains three properties:\n * `userId`, `timestamp`, and `signature`. These properties are respectively of\n * type `string`, `number`, and `string`.\n *\n * @example\n * ```javascript\n * const signature: Signature = [\"user123\", 1646956195, \"abc123\"];\n * ```\n */\nexport type Signature = [userId: string, timestamp: number, signature: string];\n\n/**\n * The type represents a set of user data. It contains three properties:\n * `userId`, `timestamp`, and `signature`. In addition, it allows for any\n * number of additional properties to be defined using TypeScript's index\n * signature syntax. The `userId` property is a string value representing\n * the user's unique identifier. The `timestamp` property is a number value\n * representing the time when the user's data was last updated. The `signature`\n * property is a string value representing the digital signature of the user's\n * data.\n *\n * @example\n * ```javascript\n * const userData: UserData = {\n * userId: \"user123\",\n * timeStamp: 1646956195,\n * signature: \"abc123\",\n * name: \"John Doe\",\n * age: 30,\n * email: \"john.doe@example.com\"\n * };\n * ```\n */\nexport type UserData = {\n [key: string]: any;\n};\n\nexport type ResponsePayload<T> = {\n result: 'success' | 'failure';\n data: T;\n message: string;\n};\n\n/**\n * @internal\n */\nexport type IdentifyHook = (identify: IdentifyKit) => Unsubscribe;\n\nexport interface IdentifyOptions {\n readonly deviceId?: string;\n readonly strategy?: string;\n readonly provider?: string;\n readonly version?: number;\n}\n\n/**\n * The `IdentifyKit` interface provides a set of properties and methods\n * for managing user identification.\n */\nexport interface IdentifyKit extends Emitter {\n /**\n * @internal\n */\n sdk: MonterosaSdk;\n /**\n * @internal\n */\n options: IdentifyOptions;\n /**\n * @internal\n */\n credentials: Credentials | null;\n /**\n * @internal\n */\n signature: Signature | null;\n /**\n * @internal\n */\n userData: UserData | null;\n\n /**\n * @internal\n */\n expireSignature(delay: number): void;\n\n /**\n * @internal\n */\n expireUserData(delay: number): void;\n\n /**\n * @internal\n */\n getUrl(path?: string): Promise<string>;\n}\n\nexport interface Response {\n message: string;\n result: number;\n data: {\n [key: string]: any;\n };\n}\n\nexport interface UserResponse extends Response {}\n\nexport interface UserCheckResponse extends Response {\n data: {\n userId: string;\n timeStamp: number;\n signature: string;\n [key: string]: any;\n };\n}\n\n/**\n * @internal\n */\nexport enum IdentifyEvent {\n LoginRequested = 'login_requested',\n SignatureUpdated = 'signature_updated',\n CredentialsUpdated = 'credentials_updated',\n UserdataUpdated = 'userdata_updated',\n ApiUserCheckFailed = 'api_user_check_failed',\n ApiUserDataFailed = 'api_user_data_failed',\n CredentialsValidationFailed = 'credentials_validation_failed',\n}\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Identify kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the IdentifyKit\n * } catch (err) {\n * if (err.code === IdentifyError.NoCredentials) {\n * // handle missing credentials error\n * } else if (err.code === IdentifyError.NotInitialised) {\n * // handle initialization error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `IdentifyError` enum provides a convenient way to handle errors\n * encountered when using the `IdentifyKit` module. By checking the code\n * property of the caught error against the values of the enum, the error\n * type can be determined and appropriate action taken.\n *\n * - The `IdentifyError` enum is not intended to be instantiated or extended.\n */\nexport enum IdentifyError {\n /**\n * Indicates an error occurred during the call to the extension API.\n */\n ExtensionApiError = 'extension_api_error',\n /**\n * Indicates the extension required by the IdentifyKit is not set up properly.\n */\n ExtensionNotSetup = 'extension_not_setup',\n /**\n * Indicates the user's authentication credentials are not available\n * or have expired.\n */\n NoCredentials = 'no_credentials',\n /**\n * Indicates the IdentifyKit has not been initialized properly.\n */\n NotInitialised = 'not_initialised',\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates there is no parent application to delegate to.\n */\n NoParentApplication = 'no_parent_application',\n}\n\n/**\n * @internal\n */\nexport const IdentifyErrorMessages = {\n [IdentifyError.ExtensionApiError]: (error: string) =>\n `Identify extension API returned an error: ${error}`,\n [IdentifyError.ExtensionNotSetup]: () =>\n 'Identify extension is not set up for this project',\n [IdentifyError.NoCredentials]: () => 'Identify credentials are not set',\n [IdentifyError.NotInitialised]: () => 'Identify instance is not initialised',\n [IdentifyError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [IdentifyError.NoParentApplication]: () =>\n 'No parent application available for delegation',\n};\n\nexport enum IdentifyAction {\n RequestLogin = 'identifyRequestLogin',\n Logout = 'identifyLogout',\n GetSessionSignature = 'identifyGetSessionSignature',\n GetUserData = 'identifyGetUserData',\n SetCredentials = 'identifySetCredentials',\n OnCredentialsUpdated = 'identifyOnCredentialsUpdated',\n OnUserDataUpdated = 'identifyOnUserDataUpdated',\n OnSessionSignatureUpdated = 'identifyOnSessionSignatureUpdated',\n OnLoginRequestedByExperience = 'identifyOnLoginRequestedByExperience',\n OnCredentialsValidationFailed = 'identifyOnCredentialsValidationFailed',\n}\n","/**\n * @license\n * constants.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-22\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport const EXTENSION_ID = 'lvis-id-custom-tab';\n\nexport const SIGNATURE_TTL = 10000;\n\nexport const USER_DATA_TTL = 10000;\n","/**\n * @license\n * identify.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, getDeviceId } from '@monterosa/sdk-core';\nimport { Emitter, createError } from '@monterosa/sdk-util';\nimport { fetchListings } from '@monterosa/sdk-interact-interop';\n\nimport {\n IdentifyKit,\n IdentifyOptions,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n Credentials,\n Signature,\n UserData,\n} from './types';\n\nimport { EXTENSION_ID } from './constants';\n\nexport default class Identify extends Emitter implements IdentifyKit {\n private host?: string;\n\n private readonly _options: IdentifyOptions;\n\n private _credentials: Credentials | null = null;\n private _signature: Signature | null = null;\n private _userData: UserData | null = null;\n private signatureExpireTimeout!: ReturnType<typeof setTimeout>;\n private userDataExpireTimeout!: ReturnType<typeof setTimeout>;\n\n constructor(public sdk: MonterosaSdk, options: IdentifyOptions = {}) {\n super();\n\n this._options = {\n strategy: 'email',\n deviceId: getDeviceId(),\n version: 1,\n ...options,\n };\n }\n\n expireSignature(delay: number) {\n clearTimeout(this.signatureExpireTimeout);\n\n this.signatureExpireTimeout = setTimeout(() => {\n this.signature = null;\n }, delay);\n }\n\n expireUserData(delay: number) {\n clearTimeout(this.userDataExpireTimeout);\n\n this.userDataExpireTimeout = setTimeout(() => {\n this.userData = null;\n }, delay);\n }\n\n private static async fetchIdentifyHost(\n host: string,\n projectId: string,\n ): Promise<string> {\n const listings = await fetchListings(host, projectId);\n const extensionAssets = listings.assets?.[EXTENSION_ID] ?? [];\n\n const endpointAsset = extensionAssets.find(\n ({ name }) => name === 'endpoint',\n );\n\n if (!endpointAsset) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return endpointAsset.data;\n }\n\n get options() {\n return this._options;\n }\n\n set signature(signature: Signature | null) {\n if (this._signature === signature) {\n return;\n }\n\n this._signature = signature;\n\n clearTimeout(this.signatureExpireTimeout);\n\n this.emit(IdentifyEvent.SignatureUpdated, this.signature);\n }\n\n get signature(): Signature | null {\n return this._signature;\n }\n\n set credentials(credentials: Credentials | null) {\n if (this._credentials === credentials) {\n return;\n }\n\n this._credentials = credentials;\n\n // if credentials are updated, user data and signature are cleared\n this.userData = null;\n this.signature = null;\n\n this.emit(IdentifyEvent.CredentialsUpdated, credentials);\n }\n\n get credentials(): Credentials | null {\n return this._credentials;\n }\n\n set userData(data: UserData | null) {\n if (this._userData === data) {\n return;\n }\n\n this._userData = data;\n\n this.emit(IdentifyEvent.UserdataUpdated, data);\n }\n\n get userData(): UserData | null {\n return this._userData;\n }\n\n async getUrl(path: string = '') {\n const {\n options: { host, projectId },\n } = this.sdk;\n\n if (this.host === undefined) {\n this.host = await Identify.fetchIdentifyHost(host, projectId);\n }\n\n const url = new URL(this.host!);\n const { version, deviceId, strategy, provider } = this._options;\n\n url.pathname = `/v${version}${path}`;\n\n url.searchParams.set('projectId', projectId);\n url.searchParams.set('deviceId', deviceId!);\n url.searchParams.set('strategy', strategy!);\n\n if (provider !== undefined) {\n url.searchParams.set('provider', provider);\n }\n\n return url.toString();\n }\n}\n","/**\n * @license\n * api.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n getParentApplication,\n sendSdkRequest,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n Response,\n ResponsePayload,\n UserResponse,\n UserCheckResponse,\n Credentials,\n Signature,\n UserData,\n IdentifyOptions,\n IdentifyAction,\n IdentifyHook,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n} from './types';\n\nimport { SIGNATURE_TTL, USER_DATA_TTL } from './constants';\n\nimport Identify from './identify';\n\nconst identifyKits: Map<string, Identify> = new Map();\nconst identifyHooks: IdentifyHook[] = [];\n\nfunction isSdk(value: MonterosaSdk | any): value is MonterosaSdk {\n return value instanceof Sdk;\n}\n\nasync function api<T extends Response>(\n url: string,\n token: Credentials['token'],\n method: string = 'GET',\n): Promise<T> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n };\n\n let credentials: RequestCredentials | undefined;\n\n // Only include Authorization header for bearer token authentication\n // When token is 'cookie', use credentials: 'include' to ensure HttpOnly\n // cookies are sent\n if (token === 'cookie') {\n // Use credentials: 'include' to ensure HttpOnly cookies are sent\n credentials = 'include';\n } else {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n credentials,\n });\n\n const data = (await response.json()) as T;\n\n if (data.result < 0) {\n throw createError(\n IdentifyError.ExtensionApiError,\n IdentifyErrorMessages,\n data.message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest<T>(\n identify: IdentifyKit,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n throw createError(IdentifyError.NoParentApplication, IdentifyErrorMessages);\n }\n\n const { host, projectId } = identify.sdk.options;\n\n // Preserve existing origin (relay) or set from current context (source)\n const origin = payload?.origin ?? { host, projectId };\n\n const response = await sendSdkRequest(parentApp, action, {\n ...payload,\n origin,\n });\n\n const { result, data, message } = response.payload as ResponsePayload<T>;\n\n if (result === 'failure') {\n throw createError(\n IdentifyError.ParentAppError,\n IdentifyErrorMessages,\n message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport function registerIdentifyHook(hook: IdentifyHook) {\n identifyHooks.push(hook);\n}\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param sdk - An instance of the MonterosaSdk class.\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\n\nexport function getIdentify(\n sdk?: MonterosaSdk,\n options?: IdentifyOptions,\n): IdentifyKit;\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\nexport function getIdentify(options?: IdentifyOptions): IdentifyKit;\n\nexport function getIdentify(\n sdkOrOptions?: MonterosaSdk | IdentifyOptions,\n options?: IdentifyOptions,\n): IdentifyKit {\n let sdk: MonterosaSdk;\n let identifyOptions: IdentifyOptions;\n\n if (isSdk(sdkOrOptions)) {\n /**\n * Interface: getIdentify(sdk, options?)\n */\n\n sdk = sdkOrOptions;\n\n if (options !== undefined) {\n identifyOptions = options;\n } else {\n identifyOptions = {};\n }\n } else if (sdkOrOptions !== undefined) {\n /**\n * Interface: getIdentify(options)\n */\n\n sdk = getSdk();\n identifyOptions = sdkOrOptions;\n } else {\n /**\n * Interface: getIdentify()\n */\n\n sdk = getSdk();\n identifyOptions = {};\n }\n\n const {\n options: { projectId },\n } = sdk;\n\n if (identifyKits.has(projectId)) {\n return identifyKits.get(projectId) as Identify;\n }\n\n const identify = new Identify(sdk, identifyOptions);\n\n for (const hook of identifyHooks) {\n hook(identify);\n }\n\n identifyKits.set(projectId, identify);\n\n return identify;\n}\n\n/**\n * A function that requests a user login via the `IdentifyKit` of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await requestLogin(identify);\n *\n * console.log('Login request successful');\n * } catch (err) {\n * console.error('Error requesting login:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to handle the login process.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the login request\n * is completed.\n */\nexport async function requestLogin(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.RequestLogin);\n\n return;\n }\n\n identify.emit(IdentifyEvent.LoginRequested);\n}\n\n/**\n * A function that requests a user logout and removing their signature and\n * credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await logout(identify);\n *\n * console.log('User logged out');\n * } catch (err) {\n * console.error('Error logout:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to log the user out.\n *\n * - If the request is successful, the function resolves with void.\n * If not, a MonterosaError is thrown.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the logout request\n * is completed.\n */\nexport async function logout(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.Logout);\n\n return;\n }\n\n identify.signature = null;\n identify.credentials = null;\n}\n\n/**\n * Returns a signature for a user session. The signature is based on the\n * user's identifying information provided in the `IdentifyKit` instance.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getSession } from '@monterosa/sdk-identify-kit';\n * import { getConnect, login } from '@monterosa/sdk-connect-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const session = await getSession(identify);\n *\n * const connect = await getConnect();\n * await login(connect, ...session);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get session signature.\n *\n * - If the request is successful, the function resolves with `Signature`.\n * If not, a `MonterosaError` is thrown.\n *\n * - The function can be used to fetch a signature for a user session that\n * can be used to authenticate user with `ConnectKit`.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves to an object of type `Signature`.\n */\nexport async function getSessionSignature(\n identify: IdentifyKit,\n): Promise<Signature> {\n if (identify.signature !== null) {\n return identify.signature;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const signature = await parentAppRequest<Signature>(\n identify,\n IdentifyAction.GetSessionSignature,\n );\n\n return signature;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user/check');\n\n const { data } = await api<UserCheckResponse>(\n url,\n identify.credentials.token,\n );\n\n const signature: Signature = [data.userId, data.timeStamp, data.signature];\n\n identify.signature = signature;\n identify.expireSignature(SIGNATURE_TTL);\n\n return signature;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserCheckFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * The function that takes an instance of `IdentifyKit` as its argument and\n * returns a Promise that resolves to a `UserData` object.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getUserData } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const { userId } = await getUserData(identify);\n *\n * console.log(`User id is ${userId}`);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get user data.\n *\n * - If the request is successful, the function resolves with `UserData`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @returns A Promise that resolves to a `UserData` object. The `UserData`\n * object contains information about the user, including their `userId`,\n * `timestamp`, and `signature`, as well as any additional properties.\n */\nexport async function getUserData(identify: IdentifyKit): Promise<UserData> {\n if (identify.userData !== null) {\n return identify.userData;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const userData = await parentAppRequest<UserData>(\n identify,\n IdentifyAction.GetUserData,\n );\n\n return userData;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user');\n\n const { data } = await api<UserResponse>(url, identify.credentials.token);\n\n identify.userData = data;\n identify.expireUserData(USER_DATA_TTL);\n\n return data;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserDataFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * Sets the user's authentication credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, setCredentials } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const credentials = { token: 'abc123' };\n * const identify = getIdentify();\n *\n * await setCredentials(identify, credentials)\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to set user credentials.\n *\n * - If the request is successful, the function resolves to `void`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param credentials - An object representing the user's authentication\n * credentials.\n * @returns A Promise that resolves to `void`.\n */\nexport async function setCredentials(\n identify: IdentifyKit,\n credentials: Credentials,\n): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(\n identify,\n IdentifyAction.SetCredentials,\n credentials,\n );\n\n return;\n }\n\n identify.credentials = credentials;\n}\n\n/**\n * Registers a callback function that will be called whenever the `Credentials`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsUpdated(identify, (credentials) => {\n * if (credentials !== null) {\n * console.log(\"Credentials updated:\", credentials);\n * } else {\n * console.log(\"Credentials cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Credentials` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsUpdated(\n identify: IdentifyKit,\n callback: (credentials: Credentials | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.CredentialsUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `Signature`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onSignatureUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onSignatureUpdated(identify, (signature) => {\n * if (signature !== null) {\n * console.log(\"Signature updated:\", signature);\n * } else {\n * console.log(\"Signature cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Signature` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onSignatureUpdated(\n identify: IdentifyKit,\n callback: (signature: Signature | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.SignatureUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `UserData`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onUserDataUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onUserDataUpdated(identify, (userData) => {\n * if (userData !== null) {\n * console.log(\"User's data updated:\", userData);\n * } else {\n * console.log(\"User's data cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `UserData` object as its only argument.\n * If the value `null` is received, it indicates that the user's data has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onUserDataUpdated(\n identify: IdentifyKit,\n callback: (userData: UserData | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.UserdataUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called when a login is requested\n * by an Experience.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onLoginRequestedByExperience } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onLoginRequestedByExperience(identify, () => {\n * showLoginForm();\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when a login is requested by an experience.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onLoginRequestedByExperience(\n identify: IdentifyKit,\n callback: () => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.LoginRequested, callback);\n}\n\n/**\n * Registers a callback function that will be called when the credentials validation fails.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsValidationFailed } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsValidationFailed(identify, (error) => {\n * console.log(error);\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when an error occured.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsValidationFailed(\n identify: IdentifyKit,\n callback: (error: string) => void,\n): Unsubscribe {\n return subscribe(\n identify,\n IdentifyEvent.CredentialsValidationFailed,\n callback,\n );\n}\n","/**\n * @license\n * bridge.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-07\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, configure, getSdks } from '@monterosa/sdk-core';\nimport { Unsubscribe, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n getParentApplication,\n registerEmbedHook,\n respondToSdkMessage,\n sendSdkMessage,\n onSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n IdentifyAction,\n Credentials,\n Signature,\n UserData,\n IdentifyEvent,\n} from './types';\n\nimport {\n getIdentify,\n getUserData,\n getSessionSignature,\n setCredentials,\n requestLogin,\n logout,\n onCredentialsUpdated,\n onSignatureUpdated,\n onUserDataUpdated,\n onCredentialsValidationFailed,\n registerIdentifyHook,\n} from './api';\n\n/**\n * @internal\n */\nexport function parentMessagesHook(identify: IdentifyKit) {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, ({ action, payload }) => {\n switch (action) {\n case IdentifyAction.OnCredentialsUpdated: {\n identify.credentials = payload.credentials as Credentials;\n break;\n }\n case IdentifyAction.OnSessionSignatureUpdated: {\n identify.signature = payload.signature as Signature;\n break;\n }\n case IdentifyAction.OnUserDataUpdated: {\n identify.userData = payload.userData as UserData;\n break;\n }\n case IdentifyAction.OnCredentialsValidationFailed: {\n identify.emit(IdentifyEvent.CredentialsValidationFailed, payload.error);\n break;\n }\n }\n });\n}\n\n/**\n * Finds an existing SDK with matching projectId, or creates a new one.\n */\nfunction getOrConfigureSdk(host: string, projectId: string): MonterosaSdk {\n const existingSdk = getSdks().find(\n (sdk) => sdk.options.projectId === projectId,\n );\n\n return existingSdk ?? configure({ host, projectId }, projectId);\n}\n\nfunction onExperienceEmbed(experience: Experience): Unsubscribe {\n const identify = getIdentify(experience.sdk);\n\n const credentialsUpdatedUnsub = onCredentialsUpdated(\n identify,\n (credentials) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsUpdated, {\n credentials,\n });\n },\n );\n\n const signatureUpdatedUnsub = onSignatureUpdated(identify, (signature) => {\n sendSdkMessage(experience, IdentifyAction.OnSessionSignatureUpdated, {\n signature,\n });\n });\n\n const userDataUpdatedUnsub = onUserDataUpdated(identify, (userData) => {\n sendSdkMessage(experience, IdentifyAction.OnUserDataUpdated, {\n userData,\n });\n });\n\n const validationFailedUnsub = onCredentialsValidationFailed(\n identify,\n (error) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsValidationFailed, {\n error,\n });\n },\n );\n\n const sdkMessageUnsub = onSdkMessage(experience, async (message) => {\n if (\n !Object.values(IdentifyAction).includes(message.action as IdentifyAction)\n ) {\n return;\n }\n\n // Extract origin context from payload if available.\n // New clients include origin (host, projectId) to ensure correct project context\n // in multilevel integrations. Old clients don't send origin, so we fall back\n // to the experience's SDK to maintain backward compatibility.\n const { origin } = message.payload as {\n origin?: { host: string; projectId: string };\n };\n\n const originSdk = origin\n ? getOrConfigureSdk(origin.host, origin.projectId)\n : experience.sdk;\n\n const originIdentify = getIdentify(originSdk);\n\n try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Session signature obtained successfully',\n data: signature,\n });\n break;\n }\n case IdentifyAction.GetUserData: {\n const userData = await getUserData(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'User data obtained successfully',\n data: userData,\n });\n break;\n }\n case IdentifyAction.SetCredentials: {\n await setCredentials(originIdentify, {\n token: message.payload.token as Credentials['token'],\n });\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Credentials updated successfully',\n data: {},\n });\n\n break;\n }\n }\n } catch (err) {\n respondToSdkMessage(experience, message, {\n result: 'failure',\n message: getErrorMessage(err),\n data: {},\n });\n }\n });\n\n return () => {\n credentialsUpdatedUnsub();\n signatureUpdatedUnsub();\n userDataUpdatedUnsub();\n sdkMessageUnsub();\n validationFailedUnsub();\n };\n}\n\nregisterEmbedHook(onExperienceEmbed);\nregisterIdentifyHook(parentMessagesHook);\n"],"names":["IdentifyError","getDeviceId","fetchListings","createError","Emitter","Sdk","getParentApplication","sendSdkRequest","getSdk","subscribe","onSdkMessage","getSdks","configure","sendSdkMessage","respondToSdkMessage","getErrorMessage","registerEmbedHook"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAuJA;;;AAGA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,mDAAkC,CAAA;IAClC,uDAAsC,CAAA;IACtC,2DAA0C,CAAA;IAC1C,qDAAoC,CAAA;IACpC,6DAA4C,CAAA;IAC5C,2DAA0C,CAAA;IAC1C,8EAA6D,CAAA;AAC/D,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BYA;AAAZ,WAAY,aAAa;;;;IAIvB,0DAAyC,CAAA;;;;IAIzC,0DAAyC,CAAA;;;;;IAKzC,iDAAgC,CAAA;;;;IAIhC,mDAAkC,CAAA;;;;IAIlC,oDAAmC,CAAA;;;;IAInC,8DAA6C,CAAA;AAC/C,CAAC,EA1BWA,qBAAa,KAAbA,qBAAa,QA0BxB;AAED;;;AAGO,IAAM,qBAAqB;IAChC,GAACA,qBAAa,CAAC,iBAA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BAA5C,QAAQ,GAAG,SAAiC;oBAElDA,kCAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,iCAAiC;wBAC1C,IAAI,EAAE,QAAQ;qBACf,CAAC,CAAC;oBACH,yBAAM;yBAGN,qBAAM,cAAc,CAAC,cAAc,EAAE;wBACnC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAA6B;qBACrD,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBAEHA,kCAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,kCAAkC;wBAC3C,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;oBAEH,yBAAM;;;;oBAIVA,kCAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAEC,uBAAe,CAAC,KAAG,CAAC;wBAC7B,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;;;;;SAEN,CAAC,CAAC;IAEH,OAAO;QACL,uBAAuB,EAAE,CAAC;QAC1B,qBAAqB,EAAE,CAAC;QACxB,oBAAoB,EAAE,CAAC;QACvB,eAAe,EAAE,CAAC;QAClB,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC;AAEDC,gCAAiB,CAAC,iBAAiB,CAAC,CAAC;AACrC,oBAAoB,CAAC,kBAAkB,CAAC;;;;;;;;;;;;;;;;"}
@@ -808,11 +808,15 @@ function onExperienceEmbed(experience) {
808
808
  if (!Object.values(IdentifyAction).includes(message.action)) {
809
809
  return;
810
810
  }
811
- // Get origin context from payload
811
+ // Extract origin context from payload if available.
812
+ // New clients include origin (host, projectId) to ensure correct project context
813
+ // in multilevel integrations. Old clients don't send origin, so we fall back
814
+ // to the experience's SDK to maintain backward compatibility.
812
815
  const { origin } = message.payload;
813
- // Always use origin to get identify for the originating layer's context
814
- const sdk = getOrConfigureSdk(origin.host, origin.projectId);
815
- const originIdentify = getIdentify(sdk);
816
+ const originSdk = origin
817
+ ? getOrConfigureSdk(origin.host, origin.projectId)
818
+ : experience.sdk;
819
+ const originIdentify = getIdentify(originSdk);
816
820
  try {
817
821
  switch (message.action) {
818
822
  case IdentifyAction.RequestLogin: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm2017.js","sources":["../src/types.ts","../src/constants.ts","../src/identify.ts","../src/api.ts","../src/bridge.ts"],"sourcesContent":["/**\n * @license\n * public_types.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk } from '@monterosa/sdk-core';\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * The type represents a user credentials. It contains a single property, token,\n * which can be either the literal 'cookie' for cookie-based authentication or\n * a string value representing the user's authentication token for bearer token\n * authentication.\n *\n * @example\n * ```javascript\n * // Bearer token authentication\n * const credentials: Credentials = { token: \"abc123\" };\n *\n * // Cookie-based authentication\n * const credentials: Credentials = { token: \"cookie\" };\n * ```\n */\nexport type Credentials = {\n token: 'cookie' | string;\n};\n\n/**\n *\n * The type represents a digital signature. It contains three properties:\n * `userId`, `timestamp`, and `signature`. These properties are respectively of\n * type `string`, `number`, and `string`.\n *\n * @example\n * ```javascript\n * const signature: Signature = [\"user123\", 1646956195, \"abc123\"];\n * ```\n */\nexport type Signature = [userId: string, timestamp: number, signature: string];\n\n/**\n * The type represents a set of user data. It contains three properties:\n * `userId`, `timestamp`, and `signature`. In addition, it allows for any\n * number of additional properties to be defined using TypeScript's index\n * signature syntax. The `userId` property is a string value representing\n * the user's unique identifier. The `timestamp` property is a number value\n * representing the time when the user's data was last updated. The `signature`\n * property is a string value representing the digital signature of the user's\n * data.\n *\n * @example\n * ```javascript\n * const userData: UserData = {\n * userId: \"user123\",\n * timeStamp: 1646956195,\n * signature: \"abc123\",\n * name: \"John Doe\",\n * age: 30,\n * email: \"john.doe@example.com\"\n * };\n * ```\n */\nexport type UserData = {\n [key: string]: any;\n};\n\nexport type ResponsePayload<T> = {\n result: 'success' | 'failure';\n data: T;\n message: string;\n};\n\n/**\n * @internal\n */\nexport type IdentifyHook = (identify: IdentifyKit) => Unsubscribe;\n\nexport interface IdentifyOptions {\n readonly deviceId?: string;\n readonly strategy?: string;\n readonly provider?: string;\n readonly version?: number;\n}\n\n/**\n * The `IdentifyKit` interface provides a set of properties and methods\n * for managing user identification.\n */\nexport interface IdentifyKit extends Emitter {\n /**\n * @internal\n */\n sdk: MonterosaSdk;\n /**\n * @internal\n */\n options: IdentifyOptions;\n /**\n * @internal\n */\n credentials: Credentials | null;\n /**\n * @internal\n */\n signature: Signature | null;\n /**\n * @internal\n */\n userData: UserData | null;\n\n /**\n * @internal\n */\n expireSignature(delay: number): void;\n\n /**\n * @internal\n */\n expireUserData(delay: number): void;\n\n /**\n * @internal\n */\n getUrl(path?: string): Promise<string>;\n}\n\nexport interface Response {\n message: string;\n result: number;\n data: {\n [key: string]: any;\n };\n}\n\nexport interface UserResponse extends Response {}\n\nexport interface UserCheckResponse extends Response {\n data: {\n userId: string;\n timeStamp: number;\n signature: string;\n [key: string]: any;\n };\n}\n\n/**\n * @internal\n */\nexport enum IdentifyEvent {\n LoginRequested = 'login_requested',\n SignatureUpdated = 'signature_updated',\n CredentialsUpdated = 'credentials_updated',\n UserdataUpdated = 'userdata_updated',\n ApiUserCheckFailed = 'api_user_check_failed',\n ApiUserDataFailed = 'api_user_data_failed',\n CredentialsValidationFailed = 'credentials_validation_failed',\n}\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Identify kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the IdentifyKit\n * } catch (err) {\n * if (err.code === IdentifyError.NoCredentials) {\n * // handle missing credentials error\n * } else if (err.code === IdentifyError.NotInitialised) {\n * // handle initialization error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `IdentifyError` enum provides a convenient way to handle errors\n * encountered when using the `IdentifyKit` module. By checking the code\n * property of the caught error against the values of the enum, the error\n * type can be determined and appropriate action taken.\n *\n * - The `IdentifyError` enum is not intended to be instantiated or extended.\n */\nexport enum IdentifyError {\n /**\n * Indicates an error occurred during the call to the extension API.\n */\n ExtensionApiError = 'extension_api_error',\n /**\n * Indicates the extension required by the IdentifyKit is not set up properly.\n */\n ExtensionNotSetup = 'extension_not_setup',\n /**\n * Indicates the user's authentication credentials are not available\n * or have expired.\n */\n NoCredentials = 'no_credentials',\n /**\n * Indicates the IdentifyKit has not been initialized properly.\n */\n NotInitialised = 'not_initialised',\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates there is no parent application to delegate to.\n */\n NoParentApplication = 'no_parent_application',\n}\n\n/**\n * @internal\n */\nexport const IdentifyErrorMessages = {\n [IdentifyError.ExtensionApiError]: (error: string) =>\n `Identify extension API returned an error: ${error}`,\n [IdentifyError.ExtensionNotSetup]: () =>\n 'Identify extension is not set up for this project',\n [IdentifyError.NoCredentials]: () => 'Identify credentials are not set',\n [IdentifyError.NotInitialised]: () => 'Identify instance is not initialised',\n [IdentifyError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [IdentifyError.NoParentApplication]: () =>\n 'No parent application available for delegation',\n};\n\nexport enum IdentifyAction {\n RequestLogin = 'identifyRequestLogin',\n Logout = 'identifyLogout',\n GetSessionSignature = 'identifyGetSessionSignature',\n GetUserData = 'identifyGetUserData',\n SetCredentials = 'identifySetCredentials',\n OnCredentialsUpdated = 'identifyOnCredentialsUpdated',\n OnUserDataUpdated = 'identifyOnUserDataUpdated',\n OnSessionSignatureUpdated = 'identifyOnSessionSignatureUpdated',\n OnLoginRequestedByExperience = 'identifyOnLoginRequestedByExperience',\n OnCredentialsValidationFailed = 'identifyOnCredentialsValidationFailed',\n}\n","/**\n * @license\n * constants.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-22\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport const EXTENSION_ID = 'lvis-id-custom-tab';\n\nexport const SIGNATURE_TTL = 10000;\n\nexport const USER_DATA_TTL = 10000;\n","/**\n * @license\n * identify.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, getDeviceId } from '@monterosa/sdk-core';\nimport { Emitter, createError } from '@monterosa/sdk-util';\nimport { fetchListings } from '@monterosa/sdk-interact-interop';\n\nimport {\n IdentifyKit,\n IdentifyOptions,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n Credentials,\n Signature,\n UserData,\n} from './types';\n\nimport { EXTENSION_ID } from './constants';\n\nexport default class Identify extends Emitter implements IdentifyKit {\n private host?: string;\n\n private readonly _options: IdentifyOptions;\n\n private _credentials: Credentials | null = null;\n private _signature: Signature | null = null;\n private _userData: UserData | null = null;\n private signatureExpireTimeout!: ReturnType<typeof setTimeout>;\n private userDataExpireTimeout!: ReturnType<typeof setTimeout>;\n\n constructor(public sdk: MonterosaSdk, options: IdentifyOptions = {}) {\n super();\n\n this._options = {\n strategy: 'email',\n deviceId: getDeviceId(),\n version: 1,\n ...options,\n };\n }\n\n expireSignature(delay: number) {\n clearTimeout(this.signatureExpireTimeout);\n\n this.signatureExpireTimeout = setTimeout(() => {\n this.signature = null;\n }, delay);\n }\n\n expireUserData(delay: number) {\n clearTimeout(this.userDataExpireTimeout);\n\n this.userDataExpireTimeout = setTimeout(() => {\n this.userData = null;\n }, delay);\n }\n\n private static async fetchIdentifyHost(\n host: string,\n projectId: string,\n ): Promise<string> {\n const listings = await fetchListings(host, projectId);\n const extensionAssets = listings.assets?.[EXTENSION_ID] ?? [];\n\n const endpointAsset = extensionAssets.find(\n ({ name }) => name === 'endpoint',\n );\n\n if (!endpointAsset) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return endpointAsset.data;\n }\n\n get options() {\n return this._options;\n }\n\n set signature(signature: Signature | null) {\n if (this._signature === signature) {\n return;\n }\n\n this._signature = signature;\n\n clearTimeout(this.signatureExpireTimeout);\n\n this.emit(IdentifyEvent.SignatureUpdated, this.signature);\n }\n\n get signature(): Signature | null {\n return this._signature;\n }\n\n set credentials(credentials: Credentials | null) {\n if (this._credentials === credentials) {\n return;\n }\n\n this._credentials = credentials;\n\n // if credentials are updated, user data and signature are cleared\n this.userData = null;\n this.signature = null;\n\n this.emit(IdentifyEvent.CredentialsUpdated, credentials);\n }\n\n get credentials(): Credentials | null {\n return this._credentials;\n }\n\n set userData(data: UserData | null) {\n if (this._userData === data) {\n return;\n }\n\n this._userData = data;\n\n this.emit(IdentifyEvent.UserdataUpdated, data);\n }\n\n get userData(): UserData | null {\n return this._userData;\n }\n\n async getUrl(path: string = '') {\n const {\n options: { host, projectId },\n } = this.sdk;\n\n if (this.host === undefined) {\n this.host = await Identify.fetchIdentifyHost(host, projectId);\n }\n\n const url = new URL(this.host!);\n const { version, deviceId, strategy, provider } = this._options;\n\n url.pathname = `/v${version}${path}`;\n\n url.searchParams.set('projectId', projectId);\n url.searchParams.set('deviceId', deviceId!);\n url.searchParams.set('strategy', strategy!);\n\n if (provider !== undefined) {\n url.searchParams.set('provider', provider);\n }\n\n return url.toString();\n }\n}\n","/**\n * @license\n * api.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n getParentApplication,\n sendSdkRequest,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n Response,\n ResponsePayload,\n UserResponse,\n UserCheckResponse,\n Credentials,\n Signature,\n UserData,\n IdentifyOptions,\n IdentifyAction,\n IdentifyHook,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n} from './types';\n\nimport { SIGNATURE_TTL, USER_DATA_TTL } from './constants';\n\nimport Identify from './identify';\n\nconst identifyKits: Map<string, Identify> = new Map();\nconst identifyHooks: IdentifyHook[] = [];\n\nfunction isSdk(value: MonterosaSdk | any): value is MonterosaSdk {\n return value instanceof Sdk;\n}\n\nasync function api<T extends Response>(\n url: string,\n token: Credentials['token'],\n method: string = 'GET',\n): Promise<T> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n };\n\n let credentials: RequestCredentials | undefined;\n\n // Only include Authorization header for bearer token authentication\n // When token is 'cookie', use credentials: 'include' to ensure HttpOnly\n // cookies are sent\n if (token === 'cookie') {\n // Use credentials: 'include' to ensure HttpOnly cookies are sent\n credentials = 'include';\n } else {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n credentials,\n });\n\n const data = (await response.json()) as T;\n\n if (data.result < 0) {\n throw createError(\n IdentifyError.ExtensionApiError,\n IdentifyErrorMessages,\n data.message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest<T>(\n identify: IdentifyKit,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n throw createError(IdentifyError.NoParentApplication, IdentifyErrorMessages);\n }\n\n const { host, projectId } = identify.sdk.options;\n\n // Preserve existing origin (relay) or set from current context (source)\n const origin = payload?.origin ?? { host, projectId };\n\n const response = await sendSdkRequest(parentApp, action, {\n ...payload,\n origin,\n });\n\n const { result, data, message } = response.payload as ResponsePayload<T>;\n\n if (result === 'failure') {\n throw createError(\n IdentifyError.ParentAppError,\n IdentifyErrorMessages,\n message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport function registerIdentifyHook(hook: IdentifyHook) {\n identifyHooks.push(hook);\n}\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param sdk - An instance of the MonterosaSdk class.\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\n\nexport function getIdentify(\n sdk?: MonterosaSdk,\n options?: IdentifyOptions,\n): IdentifyKit;\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\nexport function getIdentify(options?: IdentifyOptions): IdentifyKit;\n\nexport function getIdentify(\n sdkOrOptions?: MonterosaSdk | IdentifyOptions,\n options?: IdentifyOptions,\n): IdentifyKit {\n let sdk: MonterosaSdk;\n let identifyOptions: IdentifyOptions;\n\n if (isSdk(sdkOrOptions)) {\n /**\n * Interface: getIdentify(sdk, options?)\n */\n\n sdk = sdkOrOptions;\n\n if (options !== undefined) {\n identifyOptions = options;\n } else {\n identifyOptions = {};\n }\n } else if (sdkOrOptions !== undefined) {\n /**\n * Interface: getIdentify(options)\n */\n\n sdk = getSdk();\n identifyOptions = sdkOrOptions;\n } else {\n /**\n * Interface: getIdentify()\n */\n\n sdk = getSdk();\n identifyOptions = {};\n }\n\n const {\n options: { projectId },\n } = sdk;\n\n if (identifyKits.has(projectId)) {\n return identifyKits.get(projectId) as Identify;\n }\n\n const identify = new Identify(sdk, identifyOptions);\n\n for (const hook of identifyHooks) {\n hook(identify);\n }\n\n identifyKits.set(projectId, identify);\n\n return identify;\n}\n\n/**\n * A function that requests a user login via the `IdentifyKit` of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await requestLogin(identify);\n *\n * console.log('Login request successful');\n * } catch (err) {\n * console.error('Error requesting login:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to handle the login process.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the login request\n * is completed.\n */\nexport async function requestLogin(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.RequestLogin);\n\n return;\n }\n\n identify.emit(IdentifyEvent.LoginRequested);\n}\n\n/**\n * A function that requests a user logout and removing their signature and\n * credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await logout(identify);\n *\n * console.log('User logged out');\n * } catch (err) {\n * console.error('Error logout:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to log the user out.\n *\n * - If the request is successful, the function resolves with void.\n * If not, a MonterosaError is thrown.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the logout request\n * is completed.\n */\nexport async function logout(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.Logout);\n\n return;\n }\n\n identify.signature = null;\n identify.credentials = null;\n}\n\n/**\n * Returns a signature for a user session. The signature is based on the\n * user's identifying information provided in the `IdentifyKit` instance.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getSession } from '@monterosa/sdk-identify-kit';\n * import { getConnect, login } from '@monterosa/sdk-connect-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const session = await getSession(identify);\n *\n * const connect = await getConnect();\n * await login(connect, ...session);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get session signature.\n *\n * - If the request is successful, the function resolves with `Signature`.\n * If not, a `MonterosaError` is thrown.\n *\n * - The function can be used to fetch a signature for a user session that\n * can be used to authenticate user with `ConnectKit`.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves to an object of type `Signature`.\n */\nexport async function getSessionSignature(\n identify: IdentifyKit,\n): Promise<Signature> {\n if (identify.signature !== null) {\n return identify.signature;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const signature = await parentAppRequest<Signature>(\n identify,\n IdentifyAction.GetSessionSignature,\n );\n\n return signature;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user/check');\n\n const { data } = await api<UserCheckResponse>(\n url,\n identify.credentials.token,\n );\n\n const signature: Signature = [data.userId, data.timeStamp, data.signature];\n\n identify.signature = signature;\n identify.expireSignature(SIGNATURE_TTL);\n\n return signature;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserCheckFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * The function that takes an instance of `IdentifyKit` as its argument and\n * returns a Promise that resolves to a `UserData` object.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getUserData } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const { userId } = await getUserData(identify);\n *\n * console.log(`User id is ${userId}`);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get user data.\n *\n * - If the request is successful, the function resolves with `UserData`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @returns A Promise that resolves to a `UserData` object. The `UserData`\n * object contains information about the user, including their `userId`,\n * `timestamp`, and `signature`, as well as any additional properties.\n */\nexport async function getUserData(identify: IdentifyKit): Promise<UserData> {\n if (identify.userData !== null) {\n return identify.userData;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const userData = await parentAppRequest<UserData>(\n identify,\n IdentifyAction.GetUserData,\n );\n\n return userData;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user');\n\n const { data } = await api<UserResponse>(url, identify.credentials.token);\n\n identify.userData = data;\n identify.expireUserData(USER_DATA_TTL);\n\n return data;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserDataFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * Sets the user's authentication credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, setCredentials } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const credentials = { token: 'abc123' };\n * const identify = getIdentify();\n *\n * await setCredentials(identify, credentials)\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to set user credentials.\n *\n * - If the request is successful, the function resolves to `void`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param credentials - An object representing the user's authentication\n * credentials.\n * @returns A Promise that resolves to `void`.\n */\nexport async function setCredentials(\n identify: IdentifyKit,\n credentials: Credentials,\n): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(\n identify,\n IdentifyAction.SetCredentials,\n credentials,\n );\n\n return;\n }\n\n identify.credentials = credentials;\n}\n\n/**\n * Registers a callback function that will be called whenever the `Credentials`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsUpdated(identify, (credentials) => {\n * if (credentials !== null) {\n * console.log(\"Credentials updated:\", credentials);\n * } else {\n * console.log(\"Credentials cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Credentials` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsUpdated(\n identify: IdentifyKit,\n callback: (credentials: Credentials | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.CredentialsUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `Signature`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onSignatureUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onSignatureUpdated(identify, (signature) => {\n * if (signature !== null) {\n * console.log(\"Signature updated:\", signature);\n * } else {\n * console.log(\"Signature cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Signature` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onSignatureUpdated(\n identify: IdentifyKit,\n callback: (signature: Signature | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.SignatureUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `UserData`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onUserDataUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onUserDataUpdated(identify, (userData) => {\n * if (userData !== null) {\n * console.log(\"User's data updated:\", userData);\n * } else {\n * console.log(\"User's data cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `UserData` object as its only argument.\n * If the value `null` is received, it indicates that the user's data has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onUserDataUpdated(\n identify: IdentifyKit,\n callback: (userData: UserData | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.UserdataUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called when a login is requested\n * by an Experience.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onLoginRequestedByExperience } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onLoginRequestedByExperience(identify, () => {\n * showLoginForm();\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when a login is requested by an experience.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onLoginRequestedByExperience(\n identify: IdentifyKit,\n callback: () => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.LoginRequested, callback);\n}\n\n/**\n * Registers a callback function that will be called when the credentials validation fails.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsValidationFailed } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsValidationFailed(identify, (error) => {\n * console.log(error);\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when an error occured.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsValidationFailed(\n identify: IdentifyKit,\n callback: (error: string) => void,\n): Unsubscribe {\n return subscribe(\n identify,\n IdentifyEvent.CredentialsValidationFailed,\n callback,\n );\n}\n","/**\n * @license\n * bridge.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-07\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, configure, getSdks } from '@monterosa/sdk-core';\nimport { Unsubscribe, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n getParentApplication,\n registerEmbedHook,\n respondToSdkMessage,\n sendSdkMessage,\n onSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n IdentifyAction,\n Credentials,\n Signature,\n UserData,\n IdentifyEvent,\n} from './types';\n\nimport {\n getIdentify,\n getUserData,\n getSessionSignature,\n setCredentials,\n requestLogin,\n logout,\n onCredentialsUpdated,\n onSignatureUpdated,\n onUserDataUpdated,\n onCredentialsValidationFailed,\n registerIdentifyHook,\n} from './api';\n\n/**\n * @internal\n */\nexport function parentMessagesHook(identify: IdentifyKit) {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, ({ action, payload }) => {\n switch (action) {\n case IdentifyAction.OnCredentialsUpdated: {\n identify.credentials = payload.credentials as Credentials;\n break;\n }\n case IdentifyAction.OnSessionSignatureUpdated: {\n identify.signature = payload.signature as Signature;\n break;\n }\n case IdentifyAction.OnUserDataUpdated: {\n identify.userData = payload.userData as UserData;\n break;\n }\n case IdentifyAction.OnCredentialsValidationFailed: {\n identify.emit(IdentifyEvent.CredentialsValidationFailed, payload.error);\n break;\n }\n }\n });\n}\n\n/**\n * Finds an existing SDK with matching projectId, or creates a new one.\n */\nfunction getOrConfigureSdk(host: string, projectId: string): MonterosaSdk {\n const existingSdk = getSdks().find(\n (sdk) => sdk.options.projectId === projectId,\n );\n\n return existingSdk ?? configure({ host, projectId }, projectId);\n}\n\nfunction onExperienceEmbed(experience: Experience): Unsubscribe {\n const identify = getIdentify(experience.sdk);\n\n const credentialsUpdatedUnsub = onCredentialsUpdated(\n identify,\n (credentials) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsUpdated, {\n credentials,\n });\n },\n );\n\n const signatureUpdatedUnsub = onSignatureUpdated(identify, (signature) => {\n sendSdkMessage(experience, IdentifyAction.OnSessionSignatureUpdated, {\n signature,\n });\n });\n\n const userDataUpdatedUnsub = onUserDataUpdated(identify, (userData) => {\n sendSdkMessage(experience, IdentifyAction.OnUserDataUpdated, {\n userData,\n });\n });\n\n const validationFailedUnsub = onCredentialsValidationFailed(\n identify,\n (error) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsValidationFailed, {\n error,\n });\n },\n );\n\n const sdkMessageUnsub = onSdkMessage(experience, async (message) => {\n if (\n !Object.values(IdentifyAction).includes(message.action as IdentifyAction)\n ) {\n return;\n }\n\n // Get origin context from payload\n const { origin } = message.payload as {\n origin: { host: string; projectId: string };\n };\n\n // Always use origin to get identify for the originating layer's context\n const sdk = getOrConfigureSdk(origin.host, origin.projectId);\n const originIdentify = getIdentify(sdk);\n\n try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Session signature obtained successfully',\n data: signature,\n });\n break;\n }\n case IdentifyAction.GetUserData: {\n const userData = await getUserData(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'User data obtained successfully',\n data: userData,\n });\n break;\n }\n case IdentifyAction.SetCredentials: {\n await setCredentials(originIdentify, {\n token: message.payload.token as Credentials['token'],\n });\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Credentials updated successfully',\n data: {},\n });\n\n break;\n }\n }\n } catch (err) {\n respondToSdkMessage(experience, message, {\n result: 'failure',\n message: getErrorMessage(err),\n data: {},\n });\n }\n });\n\n return () => {\n credentialsUpdatedUnsub();\n signatureUpdatedUnsub();\n userDataUpdatedUnsub();\n sdkMessageUnsub();\n validationFailedUnsub();\n };\n}\n\nregisterEmbedHook(onExperienceEmbed);\nregisterIdentifyHook(parentMessagesHook);\n"],"names":[],"mappings":";;;;;AAAA;;;;;;;;;;AAuJA;;;AAGA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,mDAAkC,CAAA;IAClC,uDAAsC,CAAA;IACtC,2DAA0C,CAAA;IAC1C,qDAAoC,CAAA;IACpC,6DAA4C,CAAA;IAC5C,2DAA0C,CAAA;IAC1C,8EAA6D,CAAA;AAC/D,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BY;AAAZ,WAAY,aAAa;;;;IAIvB,0DAAyC,CAAA;;;;IAIzC,0DAAyC,CAAA;;;;;IAKzC,iDAAgC,CAAA;;;;IAIhC,mDAAkC,CAAA;;;;IAIlC,oDAAmC,CAAA;;;;IAInC,8DAA6C,CAAA;AAC/C,CAAC,EA1BW,aAAa,KAAb,aAAa,QA0BxB;AAED;;;AAGO,MAAM,qBAAqB,GAAG;IACnC,CAAC,aAAa,CAAC,iBAAiB,GAAG,CAAC,KAAa,KAC/C,6CAA6C,KAAK,EAAE;IACtD,CAAC,aAAa,CAAC,iBAAiB,GAAG,MACjC,mDAAmD;IACrD,CAAC,aAAa,CAAC,aAAa,GAAG,MAAM,kCAAkC;IACvE,CAAC,aAAa,CAAC,cAAc,GAAG,MAAM,sCAAsC;IAC5E,CAAC,aAAa,CAAC,cAAc,GAAG,CAAC,KAAa,KAC5C,6BAA6B,KAAK,EAAE;IACtC,CAAC,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AC,WAAW,EAAE;oBAC/B,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,cAAc,CAAC,CAAC;oBAEnD,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,iCAAiC;wBAC1C,IAAI,EAAE,QAAQ;qBACf,CAAC,CAAC;oBACH,MAAM;iBACP;gBACD,KAAK,cAAc,CAAC,cAAc,EAAE;oBAClC,MAAM,cAAc,CAAC,cAAc,EAAE;wBACnC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAA6B;qBACrD,CAAC,CAAC;oBAEH,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,kCAAkC;wBAC3C,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;oBAEH,MAAM;iBACP;aACF;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;gBACvC,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC;gBAC7B,IAAI,EAAE,EAAE;aACT,CAAC,CAAC;SACJ;KACF,CAAC,CAAC;IAEH,OAAO;QACL,uBAAuB,EAAE,CAAC;QAC1B,qBAAqB,EAAE,CAAC;QACxB,oBAAoB,EAAE,CAAC;QACvB,eAAe,EAAE,CAAC;QAClB,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC;AAED,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AACrC,oBAAoB,CAAC,kBAAkB,CAAC;;;;"}
1
+ {"version":3,"file":"index.esm2017.js","sources":["../src/types.ts","../src/constants.ts","../src/identify.ts","../src/api.ts","../src/bridge.ts"],"sourcesContent":["/**\n * @license\n * public_types.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk } from '@monterosa/sdk-core';\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * The type represents a user credentials. It contains a single property, token,\n * which can be either the literal 'cookie' for cookie-based authentication or\n * a string value representing the user's authentication token for bearer token\n * authentication.\n *\n * @example\n * ```javascript\n * // Bearer token authentication\n * const credentials: Credentials = { token: \"abc123\" };\n *\n * // Cookie-based authentication\n * const credentials: Credentials = { token: \"cookie\" };\n * ```\n */\nexport type Credentials = {\n token: 'cookie' | string;\n};\n\n/**\n *\n * The type represents a digital signature. It contains three properties:\n * `userId`, `timestamp`, and `signature`. These properties are respectively of\n * type `string`, `number`, and `string`.\n *\n * @example\n * ```javascript\n * const signature: Signature = [\"user123\", 1646956195, \"abc123\"];\n * ```\n */\nexport type Signature = [userId: string, timestamp: number, signature: string];\n\n/**\n * The type represents a set of user data. It contains three properties:\n * `userId`, `timestamp`, and `signature`. In addition, it allows for any\n * number of additional properties to be defined using TypeScript's index\n * signature syntax. The `userId` property is a string value representing\n * the user's unique identifier. The `timestamp` property is a number value\n * representing the time when the user's data was last updated. The `signature`\n * property is a string value representing the digital signature of the user's\n * data.\n *\n * @example\n * ```javascript\n * const userData: UserData = {\n * userId: \"user123\",\n * timeStamp: 1646956195,\n * signature: \"abc123\",\n * name: \"John Doe\",\n * age: 30,\n * email: \"john.doe@example.com\"\n * };\n * ```\n */\nexport type UserData = {\n [key: string]: any;\n};\n\nexport type ResponsePayload<T> = {\n result: 'success' | 'failure';\n data: T;\n message: string;\n};\n\n/**\n * @internal\n */\nexport type IdentifyHook = (identify: IdentifyKit) => Unsubscribe;\n\nexport interface IdentifyOptions {\n readonly deviceId?: string;\n readonly strategy?: string;\n readonly provider?: string;\n readonly version?: number;\n}\n\n/**\n * The `IdentifyKit` interface provides a set of properties and methods\n * for managing user identification.\n */\nexport interface IdentifyKit extends Emitter {\n /**\n * @internal\n */\n sdk: MonterosaSdk;\n /**\n * @internal\n */\n options: IdentifyOptions;\n /**\n * @internal\n */\n credentials: Credentials | null;\n /**\n * @internal\n */\n signature: Signature | null;\n /**\n * @internal\n */\n userData: UserData | null;\n\n /**\n * @internal\n */\n expireSignature(delay: number): void;\n\n /**\n * @internal\n */\n expireUserData(delay: number): void;\n\n /**\n * @internal\n */\n getUrl(path?: string): Promise<string>;\n}\n\nexport interface Response {\n message: string;\n result: number;\n data: {\n [key: string]: any;\n };\n}\n\nexport interface UserResponse extends Response {}\n\nexport interface UserCheckResponse extends Response {\n data: {\n userId: string;\n timeStamp: number;\n signature: string;\n [key: string]: any;\n };\n}\n\n/**\n * @internal\n */\nexport enum IdentifyEvent {\n LoginRequested = 'login_requested',\n SignatureUpdated = 'signature_updated',\n CredentialsUpdated = 'credentials_updated',\n UserdataUpdated = 'userdata_updated',\n ApiUserCheckFailed = 'api_user_check_failed',\n ApiUserDataFailed = 'api_user_data_failed',\n CredentialsValidationFailed = 'credentials_validation_failed',\n}\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Identify kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the IdentifyKit\n * } catch (err) {\n * if (err.code === IdentifyError.NoCredentials) {\n * // handle missing credentials error\n * } else if (err.code === IdentifyError.NotInitialised) {\n * // handle initialization error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `IdentifyError` enum provides a convenient way to handle errors\n * encountered when using the `IdentifyKit` module. By checking the code\n * property of the caught error against the values of the enum, the error\n * type can be determined and appropriate action taken.\n *\n * - The `IdentifyError` enum is not intended to be instantiated or extended.\n */\nexport enum IdentifyError {\n /**\n * Indicates an error occurred during the call to the extension API.\n */\n ExtensionApiError = 'extension_api_error',\n /**\n * Indicates the extension required by the IdentifyKit is not set up properly.\n */\n ExtensionNotSetup = 'extension_not_setup',\n /**\n * Indicates the user's authentication credentials are not available\n * or have expired.\n */\n NoCredentials = 'no_credentials',\n /**\n * Indicates the IdentifyKit has not been initialized properly.\n */\n NotInitialised = 'not_initialised',\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates there is no parent application to delegate to.\n */\n NoParentApplication = 'no_parent_application',\n}\n\n/**\n * @internal\n */\nexport const IdentifyErrorMessages = {\n [IdentifyError.ExtensionApiError]: (error: string) =>\n `Identify extension API returned an error: ${error}`,\n [IdentifyError.ExtensionNotSetup]: () =>\n 'Identify extension is not set up for this project',\n [IdentifyError.NoCredentials]: () => 'Identify credentials are not set',\n [IdentifyError.NotInitialised]: () => 'Identify instance is not initialised',\n [IdentifyError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [IdentifyError.NoParentApplication]: () =>\n 'No parent application available for delegation',\n};\n\nexport enum IdentifyAction {\n RequestLogin = 'identifyRequestLogin',\n Logout = 'identifyLogout',\n GetSessionSignature = 'identifyGetSessionSignature',\n GetUserData = 'identifyGetUserData',\n SetCredentials = 'identifySetCredentials',\n OnCredentialsUpdated = 'identifyOnCredentialsUpdated',\n OnUserDataUpdated = 'identifyOnUserDataUpdated',\n OnSessionSignatureUpdated = 'identifyOnSessionSignatureUpdated',\n OnLoginRequestedByExperience = 'identifyOnLoginRequestedByExperience',\n OnCredentialsValidationFailed = 'identifyOnCredentialsValidationFailed',\n}\n","/**\n * @license\n * constants.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-22\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport const EXTENSION_ID = 'lvis-id-custom-tab';\n\nexport const SIGNATURE_TTL = 10000;\n\nexport const USER_DATA_TTL = 10000;\n","/**\n * @license\n * identify.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, getDeviceId } from '@monterosa/sdk-core';\nimport { Emitter, createError } from '@monterosa/sdk-util';\nimport { fetchListings } from '@monterosa/sdk-interact-interop';\n\nimport {\n IdentifyKit,\n IdentifyOptions,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n Credentials,\n Signature,\n UserData,\n} from './types';\n\nimport { EXTENSION_ID } from './constants';\n\nexport default class Identify extends Emitter implements IdentifyKit {\n private host?: string;\n\n private readonly _options: IdentifyOptions;\n\n private _credentials: Credentials | null = null;\n private _signature: Signature | null = null;\n private _userData: UserData | null = null;\n private signatureExpireTimeout!: ReturnType<typeof setTimeout>;\n private userDataExpireTimeout!: ReturnType<typeof setTimeout>;\n\n constructor(public sdk: MonterosaSdk, options: IdentifyOptions = {}) {\n super();\n\n this._options = {\n strategy: 'email',\n deviceId: getDeviceId(),\n version: 1,\n ...options,\n };\n }\n\n expireSignature(delay: number) {\n clearTimeout(this.signatureExpireTimeout);\n\n this.signatureExpireTimeout = setTimeout(() => {\n this.signature = null;\n }, delay);\n }\n\n expireUserData(delay: number) {\n clearTimeout(this.userDataExpireTimeout);\n\n this.userDataExpireTimeout = setTimeout(() => {\n this.userData = null;\n }, delay);\n }\n\n private static async fetchIdentifyHost(\n host: string,\n projectId: string,\n ): Promise<string> {\n const listings = await fetchListings(host, projectId);\n const extensionAssets = listings.assets?.[EXTENSION_ID] ?? [];\n\n const endpointAsset = extensionAssets.find(\n ({ name }) => name === 'endpoint',\n );\n\n if (!endpointAsset) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return endpointAsset.data;\n }\n\n get options() {\n return this._options;\n }\n\n set signature(signature: Signature | null) {\n if (this._signature === signature) {\n return;\n }\n\n this._signature = signature;\n\n clearTimeout(this.signatureExpireTimeout);\n\n this.emit(IdentifyEvent.SignatureUpdated, this.signature);\n }\n\n get signature(): Signature | null {\n return this._signature;\n }\n\n set credentials(credentials: Credentials | null) {\n if (this._credentials === credentials) {\n return;\n }\n\n this._credentials = credentials;\n\n // if credentials are updated, user data and signature are cleared\n this.userData = null;\n this.signature = null;\n\n this.emit(IdentifyEvent.CredentialsUpdated, credentials);\n }\n\n get credentials(): Credentials | null {\n return this._credentials;\n }\n\n set userData(data: UserData | null) {\n if (this._userData === data) {\n return;\n }\n\n this._userData = data;\n\n this.emit(IdentifyEvent.UserdataUpdated, data);\n }\n\n get userData(): UserData | null {\n return this._userData;\n }\n\n async getUrl(path: string = '') {\n const {\n options: { host, projectId },\n } = this.sdk;\n\n if (this.host === undefined) {\n this.host = await Identify.fetchIdentifyHost(host, projectId);\n }\n\n const url = new URL(this.host!);\n const { version, deviceId, strategy, provider } = this._options;\n\n url.pathname = `/v${version}${path}`;\n\n url.searchParams.set('projectId', projectId);\n url.searchParams.set('deviceId', deviceId!);\n url.searchParams.set('strategy', strategy!);\n\n if (provider !== undefined) {\n url.searchParams.set('provider', provider);\n }\n\n return url.toString();\n }\n}\n","/**\n * @license\n * api.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n getParentApplication,\n sendSdkRequest,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n Response,\n ResponsePayload,\n UserResponse,\n UserCheckResponse,\n Credentials,\n Signature,\n UserData,\n IdentifyOptions,\n IdentifyAction,\n IdentifyHook,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n} from './types';\n\nimport { SIGNATURE_TTL, USER_DATA_TTL } from './constants';\n\nimport Identify from './identify';\n\nconst identifyKits: Map<string, Identify> = new Map();\nconst identifyHooks: IdentifyHook[] = [];\n\nfunction isSdk(value: MonterosaSdk | any): value is MonterosaSdk {\n return value instanceof Sdk;\n}\n\nasync function api<T extends Response>(\n url: string,\n token: Credentials['token'],\n method: string = 'GET',\n): Promise<T> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n };\n\n let credentials: RequestCredentials | undefined;\n\n // Only include Authorization header for bearer token authentication\n // When token is 'cookie', use credentials: 'include' to ensure HttpOnly\n // cookies are sent\n if (token === 'cookie') {\n // Use credentials: 'include' to ensure HttpOnly cookies are sent\n credentials = 'include';\n } else {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n credentials,\n });\n\n const data = (await response.json()) as T;\n\n if (data.result < 0) {\n throw createError(\n IdentifyError.ExtensionApiError,\n IdentifyErrorMessages,\n data.message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest<T>(\n identify: IdentifyKit,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n throw createError(IdentifyError.NoParentApplication, IdentifyErrorMessages);\n }\n\n const { host, projectId } = identify.sdk.options;\n\n // Preserve existing origin (relay) or set from current context (source)\n const origin = payload?.origin ?? { host, projectId };\n\n const response = await sendSdkRequest(parentApp, action, {\n ...payload,\n origin,\n });\n\n const { result, data, message } = response.payload as ResponsePayload<T>;\n\n if (result === 'failure') {\n throw createError(\n IdentifyError.ParentAppError,\n IdentifyErrorMessages,\n message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport function registerIdentifyHook(hook: IdentifyHook) {\n identifyHooks.push(hook);\n}\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param sdk - An instance of the MonterosaSdk class.\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\n\nexport function getIdentify(\n sdk?: MonterosaSdk,\n options?: IdentifyOptions,\n): IdentifyKit;\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\nexport function getIdentify(options?: IdentifyOptions): IdentifyKit;\n\nexport function getIdentify(\n sdkOrOptions?: MonterosaSdk | IdentifyOptions,\n options?: IdentifyOptions,\n): IdentifyKit {\n let sdk: MonterosaSdk;\n let identifyOptions: IdentifyOptions;\n\n if (isSdk(sdkOrOptions)) {\n /**\n * Interface: getIdentify(sdk, options?)\n */\n\n sdk = sdkOrOptions;\n\n if (options !== undefined) {\n identifyOptions = options;\n } else {\n identifyOptions = {};\n }\n } else if (sdkOrOptions !== undefined) {\n /**\n * Interface: getIdentify(options)\n */\n\n sdk = getSdk();\n identifyOptions = sdkOrOptions;\n } else {\n /**\n * Interface: getIdentify()\n */\n\n sdk = getSdk();\n identifyOptions = {};\n }\n\n const {\n options: { projectId },\n } = sdk;\n\n if (identifyKits.has(projectId)) {\n return identifyKits.get(projectId) as Identify;\n }\n\n const identify = new Identify(sdk, identifyOptions);\n\n for (const hook of identifyHooks) {\n hook(identify);\n }\n\n identifyKits.set(projectId, identify);\n\n return identify;\n}\n\n/**\n * A function that requests a user login via the `IdentifyKit` of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await requestLogin(identify);\n *\n * console.log('Login request successful');\n * } catch (err) {\n * console.error('Error requesting login:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to handle the login process.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the login request\n * is completed.\n */\nexport async function requestLogin(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.RequestLogin);\n\n return;\n }\n\n identify.emit(IdentifyEvent.LoginRequested);\n}\n\n/**\n * A function that requests a user logout and removing their signature and\n * credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await logout(identify);\n *\n * console.log('User logged out');\n * } catch (err) {\n * console.error('Error logout:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to log the user out.\n *\n * - If the request is successful, the function resolves with void.\n * If not, a MonterosaError is thrown.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the logout request\n * is completed.\n */\nexport async function logout(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.Logout);\n\n return;\n }\n\n identify.signature = null;\n identify.credentials = null;\n}\n\n/**\n * Returns a signature for a user session. The signature is based on the\n * user's identifying information provided in the `IdentifyKit` instance.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getSession } from '@monterosa/sdk-identify-kit';\n * import { getConnect, login } from '@monterosa/sdk-connect-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const session = await getSession(identify);\n *\n * const connect = await getConnect();\n * await login(connect, ...session);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get session signature.\n *\n * - If the request is successful, the function resolves with `Signature`.\n * If not, a `MonterosaError` is thrown.\n *\n * - The function can be used to fetch a signature for a user session that\n * can be used to authenticate user with `ConnectKit`.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves to an object of type `Signature`.\n */\nexport async function getSessionSignature(\n identify: IdentifyKit,\n): Promise<Signature> {\n if (identify.signature !== null) {\n return identify.signature;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const signature = await parentAppRequest<Signature>(\n identify,\n IdentifyAction.GetSessionSignature,\n );\n\n return signature;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user/check');\n\n const { data } = await api<UserCheckResponse>(\n url,\n identify.credentials.token,\n );\n\n const signature: Signature = [data.userId, data.timeStamp, data.signature];\n\n identify.signature = signature;\n identify.expireSignature(SIGNATURE_TTL);\n\n return signature;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserCheckFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * The function that takes an instance of `IdentifyKit` as its argument and\n * returns a Promise that resolves to a `UserData` object.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getUserData } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const { userId } = await getUserData(identify);\n *\n * console.log(`User id is ${userId}`);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get user data.\n *\n * - If the request is successful, the function resolves with `UserData`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @returns A Promise that resolves to a `UserData` object. The `UserData`\n * object contains information about the user, including their `userId`,\n * `timestamp`, and `signature`, as well as any additional properties.\n */\nexport async function getUserData(identify: IdentifyKit): Promise<UserData> {\n if (identify.userData !== null) {\n return identify.userData;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const userData = await parentAppRequest<UserData>(\n identify,\n IdentifyAction.GetUserData,\n );\n\n return userData;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user');\n\n const { data } = await api<UserResponse>(url, identify.credentials.token);\n\n identify.userData = data;\n identify.expireUserData(USER_DATA_TTL);\n\n return data;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserDataFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * Sets the user's authentication credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, setCredentials } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const credentials = { token: 'abc123' };\n * const identify = getIdentify();\n *\n * await setCredentials(identify, credentials)\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to set user credentials.\n *\n * - If the request is successful, the function resolves to `void`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param credentials - An object representing the user's authentication\n * credentials.\n * @returns A Promise that resolves to `void`.\n */\nexport async function setCredentials(\n identify: IdentifyKit,\n credentials: Credentials,\n): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(\n identify,\n IdentifyAction.SetCredentials,\n credentials,\n );\n\n return;\n }\n\n identify.credentials = credentials;\n}\n\n/**\n * Registers a callback function that will be called whenever the `Credentials`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsUpdated(identify, (credentials) => {\n * if (credentials !== null) {\n * console.log(\"Credentials updated:\", credentials);\n * } else {\n * console.log(\"Credentials cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Credentials` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsUpdated(\n identify: IdentifyKit,\n callback: (credentials: Credentials | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.CredentialsUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `Signature`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onSignatureUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onSignatureUpdated(identify, (signature) => {\n * if (signature !== null) {\n * console.log(\"Signature updated:\", signature);\n * } else {\n * console.log(\"Signature cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Signature` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onSignatureUpdated(\n identify: IdentifyKit,\n callback: (signature: Signature | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.SignatureUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `UserData`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onUserDataUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onUserDataUpdated(identify, (userData) => {\n * if (userData !== null) {\n * console.log(\"User's data updated:\", userData);\n * } else {\n * console.log(\"User's data cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `UserData` object as its only argument.\n * If the value `null` is received, it indicates that the user's data has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onUserDataUpdated(\n identify: IdentifyKit,\n callback: (userData: UserData | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.UserdataUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called when a login is requested\n * by an Experience.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onLoginRequestedByExperience } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onLoginRequestedByExperience(identify, () => {\n * showLoginForm();\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when a login is requested by an experience.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onLoginRequestedByExperience(\n identify: IdentifyKit,\n callback: () => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.LoginRequested, callback);\n}\n\n/**\n * Registers a callback function that will be called when the credentials validation fails.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsValidationFailed } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsValidationFailed(identify, (error) => {\n * console.log(error);\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when an error occured.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsValidationFailed(\n identify: IdentifyKit,\n callback: (error: string) => void,\n): Unsubscribe {\n return subscribe(\n identify,\n IdentifyEvent.CredentialsValidationFailed,\n callback,\n );\n}\n","/**\n * @license\n * bridge.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-07\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, configure, getSdks } from '@monterosa/sdk-core';\nimport { Unsubscribe, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n getParentApplication,\n registerEmbedHook,\n respondToSdkMessage,\n sendSdkMessage,\n onSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n IdentifyAction,\n Credentials,\n Signature,\n UserData,\n IdentifyEvent,\n} from './types';\n\nimport {\n getIdentify,\n getUserData,\n getSessionSignature,\n setCredentials,\n requestLogin,\n logout,\n onCredentialsUpdated,\n onSignatureUpdated,\n onUserDataUpdated,\n onCredentialsValidationFailed,\n registerIdentifyHook,\n} from './api';\n\n/**\n * @internal\n */\nexport function parentMessagesHook(identify: IdentifyKit) {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, ({ action, payload }) => {\n switch (action) {\n case IdentifyAction.OnCredentialsUpdated: {\n identify.credentials = payload.credentials as Credentials;\n break;\n }\n case IdentifyAction.OnSessionSignatureUpdated: {\n identify.signature = payload.signature as Signature;\n break;\n }\n case IdentifyAction.OnUserDataUpdated: {\n identify.userData = payload.userData as UserData;\n break;\n }\n case IdentifyAction.OnCredentialsValidationFailed: {\n identify.emit(IdentifyEvent.CredentialsValidationFailed, payload.error);\n break;\n }\n }\n });\n}\n\n/**\n * Finds an existing SDK with matching projectId, or creates a new one.\n */\nfunction getOrConfigureSdk(host: string, projectId: string): MonterosaSdk {\n const existingSdk = getSdks().find(\n (sdk) => sdk.options.projectId === projectId,\n );\n\n return existingSdk ?? configure({ host, projectId }, projectId);\n}\n\nfunction onExperienceEmbed(experience: Experience): Unsubscribe {\n const identify = getIdentify(experience.sdk);\n\n const credentialsUpdatedUnsub = onCredentialsUpdated(\n identify,\n (credentials) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsUpdated, {\n credentials,\n });\n },\n );\n\n const signatureUpdatedUnsub = onSignatureUpdated(identify, (signature) => {\n sendSdkMessage(experience, IdentifyAction.OnSessionSignatureUpdated, {\n signature,\n });\n });\n\n const userDataUpdatedUnsub = onUserDataUpdated(identify, (userData) => {\n sendSdkMessage(experience, IdentifyAction.OnUserDataUpdated, {\n userData,\n });\n });\n\n const validationFailedUnsub = onCredentialsValidationFailed(\n identify,\n (error) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsValidationFailed, {\n error,\n });\n },\n );\n\n const sdkMessageUnsub = onSdkMessage(experience, async (message) => {\n if (\n !Object.values(IdentifyAction).includes(message.action as IdentifyAction)\n ) {\n return;\n }\n\n // Extract origin context from payload if available.\n // New clients include origin (host, projectId) to ensure correct project context\n // in multilevel integrations. Old clients don't send origin, so we fall back\n // to the experience's SDK to maintain backward compatibility.\n const { origin } = message.payload as {\n origin?: { host: string; projectId: string };\n };\n\n const originSdk = origin\n ? getOrConfigureSdk(origin.host, origin.projectId)\n : experience.sdk;\n\n const originIdentify = getIdentify(originSdk);\n\n try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Session signature obtained successfully',\n data: signature,\n });\n break;\n }\n case IdentifyAction.GetUserData: {\n const userData = await getUserData(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'User data obtained successfully',\n data: userData,\n });\n break;\n }\n case IdentifyAction.SetCredentials: {\n await setCredentials(originIdentify, {\n token: message.payload.token as Credentials['token'],\n });\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Credentials updated successfully',\n data: {},\n });\n\n break;\n }\n }\n } catch (err) {\n respondToSdkMessage(experience, message, {\n result: 'failure',\n message: getErrorMessage(err),\n data: {},\n });\n }\n });\n\n return () => {\n credentialsUpdatedUnsub();\n signatureUpdatedUnsub();\n userDataUpdatedUnsub();\n sdkMessageUnsub();\n validationFailedUnsub();\n };\n}\n\nregisterEmbedHook(onExperienceEmbed);\nregisterIdentify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AAM,cAAc,CAAC,cAAc,EAAE;wBACnC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAA6B;qBACrD,CAAC,CAAC;oBAEH,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,kCAAkC;wBAC3C,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;oBAEH,MAAM;iBACP;aACF;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;gBACvC,MAAM,EAAE,SAAS;gBACjB,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC;gBAC7B,IAAI,EAAE,EAAE;aACT,CAAC,CAAC;SACJ;KACF,CAAC,CAAC;IAEH,OAAO;QACL,uBAAuB,EAAE,CAAC;QAC1B,qBAAqB,EAAE,CAAC;QACxB,oBAAoB,EAAE,CAAC;QACvB,eAAe,EAAE,CAAC;QAClB,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC;AAED,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AACrC,oBAAoB,CAAC,kBAAkB,CAAC;;;;"}
@@ -1030,7 +1030,7 @@ function onExperienceEmbed(experience) {
1030
1030
  });
1031
1031
  });
1032
1032
  var sdkMessageUnsub = onSdkMessage(experience, function (message) { return __awaiter(_this, void 0, void 0, function () {
1033
- var origin, sdk, originIdentify, _a, signature, userData, err_1;
1033
+ var origin, originSdk, originIdentify, _a, signature, userData, err_1;
1034
1034
  return __generator(this, function (_b) {
1035
1035
  switch (_b.label) {
1036
1036
  case 0:
@@ -1038,8 +1038,10 @@ function onExperienceEmbed(experience) {
1038
1038
  return [2 /*return*/];
1039
1039
  }
1040
1040
  origin = message.payload.origin;
1041
- sdk = getOrConfigureSdk(origin.host, origin.projectId);
1042
- originIdentify = getIdentify(sdk);
1041
+ originSdk = origin
1042
+ ? getOrConfigureSdk(origin.host, origin.projectId)
1043
+ : experience.sdk;
1044
+ originIdentify = getIdentify(originSdk);
1043
1045
  _b.label = 1;
1044
1046
  case 1:
1045
1047
  _b.trys.push([1, 13, , 14]);
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm5.js","sources":["../src/types.ts","../src/constants.ts","../src/identify.ts","../src/api.ts","../src/bridge.ts"],"sourcesContent":["/**\n * @license\n * public_types.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk } from '@monterosa/sdk-core';\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * The type represents a user credentials. It contains a single property, token,\n * which can be either the literal 'cookie' for cookie-based authentication or\n * a string value representing the user's authentication token for bearer token\n * authentication.\n *\n * @example\n * ```javascript\n * // Bearer token authentication\n * const credentials: Credentials = { token: \"abc123\" };\n *\n * // Cookie-based authentication\n * const credentials: Credentials = { token: \"cookie\" };\n * ```\n */\nexport type Credentials = {\n token: 'cookie' | string;\n};\n\n/**\n *\n * The type represents a digital signature. It contains three properties:\n * `userId`, `timestamp`, and `signature`. These properties are respectively of\n * type `string`, `number`, and `string`.\n *\n * @example\n * ```javascript\n * const signature: Signature = [\"user123\", 1646956195, \"abc123\"];\n * ```\n */\nexport type Signature = [userId: string, timestamp: number, signature: string];\n\n/**\n * The type represents a set of user data. It contains three properties:\n * `userId`, `timestamp`, and `signature`. In addition, it allows for any\n * number of additional properties to be defined using TypeScript's index\n * signature syntax. The `userId` property is a string value representing\n * the user's unique identifier. The `timestamp` property is a number value\n * representing the time when the user's data was last updated. The `signature`\n * property is a string value representing the digital signature of the user's\n * data.\n *\n * @example\n * ```javascript\n * const userData: UserData = {\n * userId: \"user123\",\n * timeStamp: 1646956195,\n * signature: \"abc123\",\n * name: \"John Doe\",\n * age: 30,\n * email: \"john.doe@example.com\"\n * };\n * ```\n */\nexport type UserData = {\n [key: string]: any;\n};\n\nexport type ResponsePayload<T> = {\n result: 'success' | 'failure';\n data: T;\n message: string;\n};\n\n/**\n * @internal\n */\nexport type IdentifyHook = (identify: IdentifyKit) => Unsubscribe;\n\nexport interface IdentifyOptions {\n readonly deviceId?: string;\n readonly strategy?: string;\n readonly provider?: string;\n readonly version?: number;\n}\n\n/**\n * The `IdentifyKit` interface provides a set of properties and methods\n * for managing user identification.\n */\nexport interface IdentifyKit extends Emitter {\n /**\n * @internal\n */\n sdk: MonterosaSdk;\n /**\n * @internal\n */\n options: IdentifyOptions;\n /**\n * @internal\n */\n credentials: Credentials | null;\n /**\n * @internal\n */\n signature: Signature | null;\n /**\n * @internal\n */\n userData: UserData | null;\n\n /**\n * @internal\n */\n expireSignature(delay: number): void;\n\n /**\n * @internal\n */\n expireUserData(delay: number): void;\n\n /**\n * @internal\n */\n getUrl(path?: string): Promise<string>;\n}\n\nexport interface Response {\n message: string;\n result: number;\n data: {\n [key: string]: any;\n };\n}\n\nexport interface UserResponse extends Response {}\n\nexport interface UserCheckResponse extends Response {\n data: {\n userId: string;\n timeStamp: number;\n signature: string;\n [key: string]: any;\n };\n}\n\n/**\n * @internal\n */\nexport enum IdentifyEvent {\n LoginRequested = 'login_requested',\n SignatureUpdated = 'signature_updated',\n CredentialsUpdated = 'credentials_updated',\n UserdataUpdated = 'userdata_updated',\n ApiUserCheckFailed = 'api_user_check_failed',\n ApiUserDataFailed = 'api_user_data_failed',\n CredentialsValidationFailed = 'credentials_validation_failed',\n}\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Identify kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the IdentifyKit\n * } catch (err) {\n * if (err.code === IdentifyError.NoCredentials) {\n * // handle missing credentials error\n * } else if (err.code === IdentifyError.NotInitialised) {\n * // handle initialization error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `IdentifyError` enum provides a convenient way to handle errors\n * encountered when using the `IdentifyKit` module. By checking the code\n * property of the caught error against the values of the enum, the error\n * type can be determined and appropriate action taken.\n *\n * - The `IdentifyError` enum is not intended to be instantiated or extended.\n */\nexport enum IdentifyError {\n /**\n * Indicates an error occurred during the call to the extension API.\n */\n ExtensionApiError = 'extension_api_error',\n /**\n * Indicates the extension required by the IdentifyKit is not set up properly.\n */\n ExtensionNotSetup = 'extension_not_setup',\n /**\n * Indicates the user's authentication credentials are not available\n * or have expired.\n */\n NoCredentials = 'no_credentials',\n /**\n * Indicates the IdentifyKit has not been initialized properly.\n */\n NotInitialised = 'not_initialised',\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates there is no parent application to delegate to.\n */\n NoParentApplication = 'no_parent_application',\n}\n\n/**\n * @internal\n */\nexport const IdentifyErrorMessages = {\n [IdentifyError.ExtensionApiError]: (error: string) =>\n `Identify extension API returned an error: ${error}`,\n [IdentifyError.ExtensionNotSetup]: () =>\n 'Identify extension is not set up for this project',\n [IdentifyError.NoCredentials]: () => 'Identify credentials are not set',\n [IdentifyError.NotInitialised]: () => 'Identify instance is not initialised',\n [IdentifyError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [IdentifyError.NoParentApplication]: () =>\n 'No parent application available for delegation',\n};\n\nexport enum IdentifyAction {\n RequestLogin = 'identifyRequestLogin',\n Logout = 'identifyLogout',\n GetSessionSignature = 'identifyGetSessionSignature',\n GetUserData = 'identifyGetUserData',\n SetCredentials = 'identifySetCredentials',\n OnCredentialsUpdated = 'identifyOnCredentialsUpdated',\n OnUserDataUpdated = 'identifyOnUserDataUpdated',\n OnSessionSignatureUpdated = 'identifyOnSessionSignatureUpdated',\n OnLoginRequestedByExperience = 'identifyOnLoginRequestedByExperience',\n OnCredentialsValidationFailed = 'identifyOnCredentialsValidationFailed',\n}\n","/**\n * @license\n * constants.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-22\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport const EXTENSION_ID = 'lvis-id-custom-tab';\n\nexport const SIGNATURE_TTL = 10000;\n\nexport const USER_DATA_TTL = 10000;\n","/**\n * @license\n * identify.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, getDeviceId } from '@monterosa/sdk-core';\nimport { Emitter, createError } from '@monterosa/sdk-util';\nimport { fetchListings } from '@monterosa/sdk-interact-interop';\n\nimport {\n IdentifyKit,\n IdentifyOptions,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n Credentials,\n Signature,\n UserData,\n} from './types';\n\nimport { EXTENSION_ID } from './constants';\n\nexport default class Identify extends Emitter implements IdentifyKit {\n private host?: string;\n\n private readonly _options: IdentifyOptions;\n\n private _credentials: Credentials | null = null;\n private _signature: Signature | null = null;\n private _userData: UserData | null = null;\n private signatureExpireTimeout!: ReturnType<typeof setTimeout>;\n private userDataExpireTimeout!: ReturnType<typeof setTimeout>;\n\n constructor(public sdk: MonterosaSdk, options: IdentifyOptions = {}) {\n super();\n\n this._options = {\n strategy: 'email',\n deviceId: getDeviceId(),\n version: 1,\n ...options,\n };\n }\n\n expireSignature(delay: number) {\n clearTimeout(this.signatureExpireTimeout);\n\n this.signatureExpireTimeout = setTimeout(() => {\n this.signature = null;\n }, delay);\n }\n\n expireUserData(delay: number) {\n clearTimeout(this.userDataExpireTimeout);\n\n this.userDataExpireTimeout = setTimeout(() => {\n this.userData = null;\n }, delay);\n }\n\n private static async fetchIdentifyHost(\n host: string,\n projectId: string,\n ): Promise<string> {\n const listings = await fetchListings(host, projectId);\n const extensionAssets = listings.assets?.[EXTENSION_ID] ?? [];\n\n const endpointAsset = extensionAssets.find(\n ({ name }) => name === 'endpoint',\n );\n\n if (!endpointAsset) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return endpointAsset.data;\n }\n\n get options() {\n return this._options;\n }\n\n set signature(signature: Signature | null) {\n if (this._signature === signature) {\n return;\n }\n\n this._signature = signature;\n\n clearTimeout(this.signatureExpireTimeout);\n\n this.emit(IdentifyEvent.SignatureUpdated, this.signature);\n }\n\n get signature(): Signature | null {\n return this._signature;\n }\n\n set credentials(credentials: Credentials | null) {\n if (this._credentials === credentials) {\n return;\n }\n\n this._credentials = credentials;\n\n // if credentials are updated, user data and signature are cleared\n this.userData = null;\n this.signature = null;\n\n this.emit(IdentifyEvent.CredentialsUpdated, credentials);\n }\n\n get credentials(): Credentials | null {\n return this._credentials;\n }\n\n set userData(data: UserData | null) {\n if (this._userData === data) {\n return;\n }\n\n this._userData = data;\n\n this.emit(IdentifyEvent.UserdataUpdated, data);\n }\n\n get userData(): UserData | null {\n return this._userData;\n }\n\n async getUrl(path: string = '') {\n const {\n options: { host, projectId },\n } = this.sdk;\n\n if (this.host === undefined) {\n this.host = await Identify.fetchIdentifyHost(host, projectId);\n }\n\n const url = new URL(this.host!);\n const { version, deviceId, strategy, provider } = this._options;\n\n url.pathname = `/v${version}${path}`;\n\n url.searchParams.set('projectId', projectId);\n url.searchParams.set('deviceId', deviceId!);\n url.searchParams.set('strategy', strategy!);\n\n if (provider !== undefined) {\n url.searchParams.set('provider', provider);\n }\n\n return url.toString();\n }\n}\n","/**\n * @license\n * api.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n getParentApplication,\n sendSdkRequest,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n Response,\n ResponsePayload,\n UserResponse,\n UserCheckResponse,\n Credentials,\n Signature,\n UserData,\n IdentifyOptions,\n IdentifyAction,\n IdentifyHook,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n} from './types';\n\nimport { SIGNATURE_TTL, USER_DATA_TTL } from './constants';\n\nimport Identify from './identify';\n\nconst identifyKits: Map<string, Identify> = new Map();\nconst identifyHooks: IdentifyHook[] = [];\n\nfunction isSdk(value: MonterosaSdk | any): value is MonterosaSdk {\n return value instanceof Sdk;\n}\n\nasync function api<T extends Response>(\n url: string,\n token: Credentials['token'],\n method: string = 'GET',\n): Promise<T> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n };\n\n let credentials: RequestCredentials | undefined;\n\n // Only include Authorization header for bearer token authentication\n // When token is 'cookie', use credentials: 'include' to ensure HttpOnly\n // cookies are sent\n if (token === 'cookie') {\n // Use credentials: 'include' to ensure HttpOnly cookies are sent\n credentials = 'include';\n } else {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n credentials,\n });\n\n const data = (await response.json()) as T;\n\n if (data.result < 0) {\n throw createError(\n IdentifyError.ExtensionApiError,\n IdentifyErrorMessages,\n data.message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest<T>(\n identify: IdentifyKit,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n throw createError(IdentifyError.NoParentApplication, IdentifyErrorMessages);\n }\n\n const { host, projectId } = identify.sdk.options;\n\n // Preserve existing origin (relay) or set from current context (source)\n const origin = payload?.origin ?? { host, projectId };\n\n const response = await sendSdkRequest(parentApp, action, {\n ...payload,\n origin,\n });\n\n const { result, data, message } = response.payload as ResponsePayload<T>;\n\n if (result === 'failure') {\n throw createError(\n IdentifyError.ParentAppError,\n IdentifyErrorMessages,\n message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport function registerIdentifyHook(hook: IdentifyHook) {\n identifyHooks.push(hook);\n}\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param sdk - An instance of the MonterosaSdk class.\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\n\nexport function getIdentify(\n sdk?: MonterosaSdk,\n options?: IdentifyOptions,\n): IdentifyKit;\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\nexport function getIdentify(options?: IdentifyOptions): IdentifyKit;\n\nexport function getIdentify(\n sdkOrOptions?: MonterosaSdk | IdentifyOptions,\n options?: IdentifyOptions,\n): IdentifyKit {\n let sdk: MonterosaSdk;\n let identifyOptions: IdentifyOptions;\n\n if (isSdk(sdkOrOptions)) {\n /**\n * Interface: getIdentify(sdk, options?)\n */\n\n sdk = sdkOrOptions;\n\n if (options !== undefined) {\n identifyOptions = options;\n } else {\n identifyOptions = {};\n }\n } else if (sdkOrOptions !== undefined) {\n /**\n * Interface: getIdentify(options)\n */\n\n sdk = getSdk();\n identifyOptions = sdkOrOptions;\n } else {\n /**\n * Interface: getIdentify()\n */\n\n sdk = getSdk();\n identifyOptions = {};\n }\n\n const {\n options: { projectId },\n } = sdk;\n\n if (identifyKits.has(projectId)) {\n return identifyKits.get(projectId) as Identify;\n }\n\n const identify = new Identify(sdk, identifyOptions);\n\n for (const hook of identifyHooks) {\n hook(identify);\n }\n\n identifyKits.set(projectId, identify);\n\n return identify;\n}\n\n/**\n * A function that requests a user login via the `IdentifyKit` of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await requestLogin(identify);\n *\n * console.log('Login request successful');\n * } catch (err) {\n * console.error('Error requesting login:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to handle the login process.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the login request\n * is completed.\n */\nexport async function requestLogin(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.RequestLogin);\n\n return;\n }\n\n identify.emit(IdentifyEvent.LoginRequested);\n}\n\n/**\n * A function that requests a user logout and removing their signature and\n * credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await logout(identify);\n *\n * console.log('User logged out');\n * } catch (err) {\n * console.error('Error logout:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to log the user out.\n *\n * - If the request is successful, the function resolves with void.\n * If not, a MonterosaError is thrown.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the logout request\n * is completed.\n */\nexport async function logout(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.Logout);\n\n return;\n }\n\n identify.signature = null;\n identify.credentials = null;\n}\n\n/**\n * Returns a signature for a user session. The signature is based on the\n * user's identifying information provided in the `IdentifyKit` instance.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getSession } from '@monterosa/sdk-identify-kit';\n * import { getConnect, login } from '@monterosa/sdk-connect-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const session = await getSession(identify);\n *\n * const connect = await getConnect();\n * await login(connect, ...session);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get session signature.\n *\n * - If the request is successful, the function resolves with `Signature`.\n * If not, a `MonterosaError` is thrown.\n *\n * - The function can be used to fetch a signature for a user session that\n * can be used to authenticate user with `ConnectKit`.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves to an object of type `Signature`.\n */\nexport async function getSessionSignature(\n identify: IdentifyKit,\n): Promise<Signature> {\n if (identify.signature !== null) {\n return identify.signature;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const signature = await parentAppRequest<Signature>(\n identify,\n IdentifyAction.GetSessionSignature,\n );\n\n return signature;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user/check');\n\n const { data } = await api<UserCheckResponse>(\n url,\n identify.credentials.token,\n );\n\n const signature: Signature = [data.userId, data.timeStamp, data.signature];\n\n identify.signature = signature;\n identify.expireSignature(SIGNATURE_TTL);\n\n return signature;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserCheckFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * The function that takes an instance of `IdentifyKit` as its argument and\n * returns a Promise that resolves to a `UserData` object.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getUserData } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const { userId } = await getUserData(identify);\n *\n * console.log(`User id is ${userId}`);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get user data.\n *\n * - If the request is successful, the function resolves with `UserData`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @returns A Promise that resolves to a `UserData` object. The `UserData`\n * object contains information about the user, including their `userId`,\n * `timestamp`, and `signature`, as well as any additional properties.\n */\nexport async function getUserData(identify: IdentifyKit): Promise<UserData> {\n if (identify.userData !== null) {\n return identify.userData;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const userData = await parentAppRequest<UserData>(\n identify,\n IdentifyAction.GetUserData,\n );\n\n return userData;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user');\n\n const { data } = await api<UserResponse>(url, identify.credentials.token);\n\n identify.userData = data;\n identify.expireUserData(USER_DATA_TTL);\n\n return data;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserDataFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * Sets the user's authentication credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, setCredentials } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const credentials = { token: 'abc123' };\n * const identify = getIdentify();\n *\n * await setCredentials(identify, credentials)\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to set user credentials.\n *\n * - If the request is successful, the function resolves to `void`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param credentials - An object representing the user's authentication\n * credentials.\n * @returns A Promise that resolves to `void`.\n */\nexport async function setCredentials(\n identify: IdentifyKit,\n credentials: Credentials,\n): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(\n identify,\n IdentifyAction.SetCredentials,\n credentials,\n );\n\n return;\n }\n\n identify.credentials = credentials;\n}\n\n/**\n * Registers a callback function that will be called whenever the `Credentials`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsUpdated(identify, (credentials) => {\n * if (credentials !== null) {\n * console.log(\"Credentials updated:\", credentials);\n * } else {\n * console.log(\"Credentials cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Credentials` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsUpdated(\n identify: IdentifyKit,\n callback: (credentials: Credentials | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.CredentialsUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `Signature`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onSignatureUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onSignatureUpdated(identify, (signature) => {\n * if (signature !== null) {\n * console.log(\"Signature updated:\", signature);\n * } else {\n * console.log(\"Signature cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Signature` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onSignatureUpdated(\n identify: IdentifyKit,\n callback: (signature: Signature | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.SignatureUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `UserData`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onUserDataUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onUserDataUpdated(identify, (userData) => {\n * if (userData !== null) {\n * console.log(\"User's data updated:\", userData);\n * } else {\n * console.log(\"User's data cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `UserData` object as its only argument.\n * If the value `null` is received, it indicates that the user's data has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onUserDataUpdated(\n identify: IdentifyKit,\n callback: (userData: UserData | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.UserdataUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called when a login is requested\n * by an Experience.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onLoginRequestedByExperience } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onLoginRequestedByExperience(identify, () => {\n * showLoginForm();\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when a login is requested by an experience.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onLoginRequestedByExperience(\n identify: IdentifyKit,\n callback: () => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.LoginRequested, callback);\n}\n\n/**\n * Registers a callback function that will be called when the credentials validation fails.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsValidationFailed } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsValidationFailed(identify, (error) => {\n * console.log(error);\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when an error occured.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsValidationFailed(\n identify: IdentifyKit,\n callback: (error: string) => void,\n): Unsubscribe {\n return subscribe(\n identify,\n IdentifyEvent.CredentialsValidationFailed,\n callback,\n );\n}\n","/**\n * @license\n * bridge.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-07\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, configure, getSdks } from '@monterosa/sdk-core';\nimport { Unsubscribe, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n getParentApplication,\n registerEmbedHook,\n respondToSdkMessage,\n sendSdkMessage,\n onSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n IdentifyAction,\n Credentials,\n Signature,\n UserData,\n IdentifyEvent,\n} from './types';\n\nimport {\n getIdentify,\n getUserData,\n getSessionSignature,\n setCredentials,\n requestLogin,\n logout,\n onCredentialsUpdated,\n onSignatureUpdated,\n onUserDataUpdated,\n onCredentialsValidationFailed,\n registerIdentifyHook,\n} from './api';\n\n/**\n * @internal\n */\nexport function parentMessagesHook(identify: IdentifyKit) {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, ({ action, payload }) => {\n switch (action) {\n case IdentifyAction.OnCredentialsUpdated: {\n identify.credentials = payload.credentials as Credentials;\n break;\n }\n case IdentifyAction.OnSessionSignatureUpdated: {\n identify.signature = payload.signature as Signature;\n break;\n }\n case IdentifyAction.OnUserDataUpdated: {\n identify.userData = payload.userData as UserData;\n break;\n }\n case IdentifyAction.OnCredentialsValidationFailed: {\n identify.emit(IdentifyEvent.CredentialsValidationFailed, payload.error);\n break;\n }\n }\n });\n}\n\n/**\n * Finds an existing SDK with matching projectId, or creates a new one.\n */\nfunction getOrConfigureSdk(host: string, projectId: string): MonterosaSdk {\n const existingSdk = getSdks().find(\n (sdk) => sdk.options.projectId === projectId,\n );\n\n return existingSdk ?? configure({ host, projectId }, projectId);\n}\n\nfunction onExperienceEmbed(experience: Experience): Unsubscribe {\n const identify = getIdentify(experience.sdk);\n\n const credentialsUpdatedUnsub = onCredentialsUpdated(\n identify,\n (credentials) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsUpdated, {\n credentials,\n });\n },\n );\n\n const signatureUpdatedUnsub = onSignatureUpdated(identify, (signature) => {\n sendSdkMessage(experience, IdentifyAction.OnSessionSignatureUpdated, {\n signature,\n });\n });\n\n const userDataUpdatedUnsub = onUserDataUpdated(identify, (userData) => {\n sendSdkMessage(experience, IdentifyAction.OnUserDataUpdated, {\n userData,\n });\n });\n\n const validationFailedUnsub = onCredentialsValidationFailed(\n identify,\n (error) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsValidationFailed, {\n error,\n });\n },\n );\n\n const sdkMessageUnsub = onSdkMessage(experience, async (message) => {\n if (\n !Object.values(IdentifyAction).includes(message.action as IdentifyAction)\n ) {\n return;\n }\n\n // Get origin context from payload\n const { origin } = message.payload as {\n origin: { host: string; projectId: string };\n };\n\n // Always use origin to get identify for the originating layer's context\n const sdk = getOrConfigureSdk(origin.host, origin.projectId);\n const originIdentify = getIdentify(sdk);\n\n try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Session signature obtained successfully',\n data: signature,\n });\n break;\n }\n case IdentifyAction.GetUserData: {\n const userData = await getUserData(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'User data obtained successfully',\n data: userData,\n });\n break;\n }\n case IdentifyAction.SetCredentials: {\n await setCredentials(originIdentify, {\n token: message.payload.token as Credentials['token'],\n });\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Credentials updated successfully',\n data: {},\n });\n\n break;\n }\n }\n } catch (err) {\n respondToSdkMessage(experience, message, {\n result: 'failure',\n message: getErrorMessage(err),\n data: {},\n });\n }\n });\n\n return () => {\n credentialsUpdatedUnsub();\n signatureUpdatedUnsub();\n userDataUpdatedUnsub();\n sdkMessageUnsub();\n validationFailedUnsub();\n };\n}\n\nregisterEmbedHook(onExperienceEmbed);\nregisterIdentifyHook(parentMessagesHook);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAuJA;;;AAGA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,mDAAkC,CAAA;IAClC,uDAAsC,CAAA;IACtC,2DAA0C,CAAA;IAC1C,qDAAoC,CAAA;IACpC,6DAA4C,CAAA;IAC5C,2DAA0C,CAAA;IAC1C,8EAA6D,CAAA;AAC/D,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BY;AAAZ,WAAY,aAAa;;;;IAIvB,0DAAyC,CAAA;;;;IAIzC,0DAAyC,CAAA;;;;;IAKzC,iDAAgC,CAAA;;;;IAIhC,mDAAkC,CAAA;;;;IAIlC,oDAAmC,CAAA;;;;IAInC,8DAA6C,CAAA;AAC/C,CAAC,EA1BW,aAAa,KAAb,aAAa,QA0BxB;AAED;;;AAGO,IAAM,qBAAqB;IAChC,GAAC,aAAa,CAAC,iBAAiB,IAAG,UAAC,KAAa;QAC/C,OAAA,+CAA6C,KAAO;KAAA;IACtD,GAAC,aAAa,CAAC,iBAAiB,IAAG;QACjC,OAAA,mDAAmD;KAAA;IACrD,GAAC,aAAa,CAAC,aAAa,IAAG,cAAM,OAAA,kCAAkC,GAAA;IACvE,GAAC,aAAa,CAAC,cAAc,IAAG,cAAM,OAAA,sCAAsC,GAAA;IAC5E,GAAC,aAAa,CAAC,cAAc,IAAG,UAAC,KAAa;QAC5C,OA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AAE,EAAE;qBACT,CAAC,CAAC;oBAEH,yBAAM;;;;oBAIV,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,eAAe,CAAC,KAAG,CAAC;wBAC7B,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;;;;;SAEN,CAAC,CAAC;IAEH,OAAO;QACL,uBAAuB,EAAE,CAAC;QAC1B,qBAAqB,EAAE,CAAC;QACxB,oBAAoB,EAAE,CAAC;QACvB,eAAe,EAAE,CAAC;QAClB,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC;AAED,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AACrC,oBAAoB,CAAC,kBAAkB,CAAC;;;;"}
1
+ {"version":3,"file":"index.esm5.js","sources":["../src/types.ts","../src/constants.ts","../src/identify.ts","../src/api.ts","../src/bridge.ts"],"sourcesContent":["/**\n * @license\n * public_types.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk } from '@monterosa/sdk-core';\nimport { Emitter, Unsubscribe } from '@monterosa/sdk-util';\n\n/**\n * The type represents a user credentials. It contains a single property, token,\n * which can be either the literal 'cookie' for cookie-based authentication or\n * a string value representing the user's authentication token for bearer token\n * authentication.\n *\n * @example\n * ```javascript\n * // Bearer token authentication\n * const credentials: Credentials = { token: \"abc123\" };\n *\n * // Cookie-based authentication\n * const credentials: Credentials = { token: \"cookie\" };\n * ```\n */\nexport type Credentials = {\n token: 'cookie' | string;\n};\n\n/**\n *\n * The type represents a digital signature. It contains three properties:\n * `userId`, `timestamp`, and `signature`. These properties are respectively of\n * type `string`, `number`, and `string`.\n *\n * @example\n * ```javascript\n * const signature: Signature = [\"user123\", 1646956195, \"abc123\"];\n * ```\n */\nexport type Signature = [userId: string, timestamp: number, signature: string];\n\n/**\n * The type represents a set of user data. It contains three properties:\n * `userId`, `timestamp`, and `signature`. In addition, it allows for any\n * number of additional properties to be defined using TypeScript's index\n * signature syntax. The `userId` property is a string value representing\n * the user's unique identifier. The `timestamp` property is a number value\n * representing the time when the user's data was last updated. The `signature`\n * property is a string value representing the digital signature of the user's\n * data.\n *\n * @example\n * ```javascript\n * const userData: UserData = {\n * userId: \"user123\",\n * timeStamp: 1646956195,\n * signature: \"abc123\",\n * name: \"John Doe\",\n * age: 30,\n * email: \"john.doe@example.com\"\n * };\n * ```\n */\nexport type UserData = {\n [key: string]: any;\n};\n\nexport type ResponsePayload<T> = {\n result: 'success' | 'failure';\n data: T;\n message: string;\n};\n\n/**\n * @internal\n */\nexport type IdentifyHook = (identify: IdentifyKit) => Unsubscribe;\n\nexport interface IdentifyOptions {\n readonly deviceId?: string;\n readonly strategy?: string;\n readonly provider?: string;\n readonly version?: number;\n}\n\n/**\n * The `IdentifyKit` interface provides a set of properties and methods\n * for managing user identification.\n */\nexport interface IdentifyKit extends Emitter {\n /**\n * @internal\n */\n sdk: MonterosaSdk;\n /**\n * @internal\n */\n options: IdentifyOptions;\n /**\n * @internal\n */\n credentials: Credentials | null;\n /**\n * @internal\n */\n signature: Signature | null;\n /**\n * @internal\n */\n userData: UserData | null;\n\n /**\n * @internal\n */\n expireSignature(delay: number): void;\n\n /**\n * @internal\n */\n expireUserData(delay: number): void;\n\n /**\n * @internal\n */\n getUrl(path?: string): Promise<string>;\n}\n\nexport interface Response {\n message: string;\n result: number;\n data: {\n [key: string]: any;\n };\n}\n\nexport interface UserResponse extends Response {}\n\nexport interface UserCheckResponse extends Response {\n data: {\n userId: string;\n timeStamp: number;\n signature: string;\n [key: string]: any;\n };\n}\n\n/**\n * @internal\n */\nexport enum IdentifyEvent {\n LoginRequested = 'login_requested',\n SignatureUpdated = 'signature_updated',\n CredentialsUpdated = 'credentials_updated',\n UserdataUpdated = 'userdata_updated',\n ApiUserCheckFailed = 'api_user_check_failed',\n ApiUserDataFailed = 'api_user_data_failed',\n CredentialsValidationFailed = 'credentials_validation_failed',\n}\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Identify kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the IdentifyKit\n * } catch (err) {\n * if (err.code === IdentifyError.NoCredentials) {\n * // handle missing credentials error\n * } else if (err.code === IdentifyError.NotInitialised) {\n * // handle initialization error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `IdentifyError` enum provides a convenient way to handle errors\n * encountered when using the `IdentifyKit` module. By checking the code\n * property of the caught error against the values of the enum, the error\n * type can be determined and appropriate action taken.\n *\n * - The `IdentifyError` enum is not intended to be instantiated or extended.\n */\nexport enum IdentifyError {\n /**\n * Indicates an error occurred during the call to the extension API.\n */\n ExtensionApiError = 'extension_api_error',\n /**\n * Indicates the extension required by the IdentifyKit is not set up properly.\n */\n ExtensionNotSetup = 'extension_not_setup',\n /**\n * Indicates the user's authentication credentials are not available\n * or have expired.\n */\n NoCredentials = 'no_credentials',\n /**\n * Indicates the IdentifyKit has not been initialized properly.\n */\n NotInitialised = 'not_initialised',\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates there is no parent application to delegate to.\n */\n NoParentApplication = 'no_parent_application',\n}\n\n/**\n * @internal\n */\nexport const IdentifyErrorMessages = {\n [IdentifyError.ExtensionApiError]: (error: string) =>\n `Identify extension API returned an error: ${error}`,\n [IdentifyError.ExtensionNotSetup]: () =>\n 'Identify extension is not set up for this project',\n [IdentifyError.NoCredentials]: () => 'Identify credentials are not set',\n [IdentifyError.NotInitialised]: () => 'Identify instance is not initialised',\n [IdentifyError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [IdentifyError.NoParentApplication]: () =>\n 'No parent application available for delegation',\n};\n\nexport enum IdentifyAction {\n RequestLogin = 'identifyRequestLogin',\n Logout = 'identifyLogout',\n GetSessionSignature = 'identifyGetSessionSignature',\n GetUserData = 'identifyGetUserData',\n SetCredentials = 'identifySetCredentials',\n OnCredentialsUpdated = 'identifyOnCredentialsUpdated',\n OnUserDataUpdated = 'identifyOnUserDataUpdated',\n OnSessionSignatureUpdated = 'identifyOnSessionSignatureUpdated',\n OnLoginRequestedByExperience = 'identifyOnLoginRequestedByExperience',\n OnCredentialsValidationFailed = 'identifyOnCredentialsValidationFailed',\n}\n","/**\n * @license\n * constants.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-22\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport const EXTENSION_ID = 'lvis-id-custom-tab';\n\nexport const SIGNATURE_TTL = 10000;\n\nexport const USER_DATA_TTL = 10000;\n","/**\n * @license\n * identify.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, getDeviceId } from '@monterosa/sdk-core';\nimport { Emitter, createError } from '@monterosa/sdk-util';\nimport { fetchListings } from '@monterosa/sdk-interact-interop';\n\nimport {\n IdentifyKit,\n IdentifyOptions,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n Credentials,\n Signature,\n UserData,\n} from './types';\n\nimport { EXTENSION_ID } from './constants';\n\nexport default class Identify extends Emitter implements IdentifyKit {\n private host?: string;\n\n private readonly _options: IdentifyOptions;\n\n private _credentials: Credentials | null = null;\n private _signature: Signature | null = null;\n private _userData: UserData | null = null;\n private signatureExpireTimeout!: ReturnType<typeof setTimeout>;\n private userDataExpireTimeout!: ReturnType<typeof setTimeout>;\n\n constructor(public sdk: MonterosaSdk, options: IdentifyOptions = {}) {\n super();\n\n this._options = {\n strategy: 'email',\n deviceId: getDeviceId(),\n version: 1,\n ...options,\n };\n }\n\n expireSignature(delay: number) {\n clearTimeout(this.signatureExpireTimeout);\n\n this.signatureExpireTimeout = setTimeout(() => {\n this.signature = null;\n }, delay);\n }\n\n expireUserData(delay: number) {\n clearTimeout(this.userDataExpireTimeout);\n\n this.userDataExpireTimeout = setTimeout(() => {\n this.userData = null;\n }, delay);\n }\n\n private static async fetchIdentifyHost(\n host: string,\n projectId: string,\n ): Promise<string> {\n const listings = await fetchListings(host, projectId);\n const extensionAssets = listings.assets?.[EXTENSION_ID] ?? [];\n\n const endpointAsset = extensionAssets.find(\n ({ name }) => name === 'endpoint',\n );\n\n if (!endpointAsset) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return endpointAsset.data;\n }\n\n get options() {\n return this._options;\n }\n\n set signature(signature: Signature | null) {\n if (this._signature === signature) {\n return;\n }\n\n this._signature = signature;\n\n clearTimeout(this.signatureExpireTimeout);\n\n this.emit(IdentifyEvent.SignatureUpdated, this.signature);\n }\n\n get signature(): Signature | null {\n return this._signature;\n }\n\n set credentials(credentials: Credentials | null) {\n if (this._credentials === credentials) {\n return;\n }\n\n this._credentials = credentials;\n\n // if credentials are updated, user data and signature are cleared\n this.userData = null;\n this.signature = null;\n\n this.emit(IdentifyEvent.CredentialsUpdated, credentials);\n }\n\n get credentials(): Credentials | null {\n return this._credentials;\n }\n\n set userData(data: UserData | null) {\n if (this._userData === data) {\n return;\n }\n\n this._userData = data;\n\n this.emit(IdentifyEvent.UserdataUpdated, data);\n }\n\n get userData(): UserData | null {\n return this._userData;\n }\n\n async getUrl(path: string = '') {\n const {\n options: { host, projectId },\n } = this.sdk;\n\n if (this.host === undefined) {\n this.host = await Identify.fetchIdentifyHost(host, projectId);\n }\n\n const url = new URL(this.host!);\n const { version, deviceId, strategy, provider } = this._options;\n\n url.pathname = `/v${version}${path}`;\n\n url.searchParams.set('projectId', projectId);\n url.searchParams.set('deviceId', deviceId!);\n url.searchParams.set('strategy', strategy!);\n\n if (provider !== undefined) {\n url.searchParams.set('provider', provider);\n }\n\n return url.toString();\n }\n}\n","/**\n * @license\n * api.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-02-21\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n getParentApplication,\n sendSdkRequest,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n Response,\n ResponsePayload,\n UserResponse,\n UserCheckResponse,\n Credentials,\n Signature,\n UserData,\n IdentifyOptions,\n IdentifyAction,\n IdentifyHook,\n IdentifyEvent,\n IdentifyError,\n IdentifyErrorMessages,\n} from './types';\n\nimport { SIGNATURE_TTL, USER_DATA_TTL } from './constants';\n\nimport Identify from './identify';\n\nconst identifyKits: Map<string, Identify> = new Map();\nconst identifyHooks: IdentifyHook[] = [];\n\nfunction isSdk(value: MonterosaSdk | any): value is MonterosaSdk {\n return value instanceof Sdk;\n}\n\nasync function api<T extends Response>(\n url: string,\n token: Credentials['token'],\n method: string = 'GET',\n): Promise<T> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n };\n\n let credentials: RequestCredentials | undefined;\n\n // Only include Authorization header for bearer token authentication\n // When token is 'cookie', use credentials: 'include' to ensure HttpOnly\n // cookies are sent\n if (token === 'cookie') {\n // Use credentials: 'include' to ensure HttpOnly cookies are sent\n credentials = 'include';\n } else {\n headers.Authorization = `Bearer ${token}`;\n }\n\n const response = await fetch(url, {\n method,\n headers,\n credentials,\n });\n\n const data = (await response.json()) as T;\n\n if (data.result < 0) {\n throw createError(\n IdentifyError.ExtensionApiError,\n IdentifyErrorMessages,\n data.message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest<T>(\n identify: IdentifyKit,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n throw createError(IdentifyError.NoParentApplication, IdentifyErrorMessages);\n }\n\n const { host, projectId } = identify.sdk.options;\n\n // Preserve existing origin (relay) or set from current context (source)\n const origin = payload?.origin ?? { host, projectId };\n\n const response = await sendSdkRequest(parentApp, action, {\n ...payload,\n origin,\n });\n\n const { result, data, message } = response.payload as ResponsePayload<T>;\n\n if (result === 'failure') {\n throw createError(\n IdentifyError.ParentAppError,\n IdentifyErrorMessages,\n message,\n );\n }\n\n return data;\n}\n\n/**\n * @internal\n */\nexport function registerIdentifyHook(hook: IdentifyHook) {\n identifyHooks.push(hook);\n}\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param sdk - An instance of the MonterosaSdk class.\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\n\nexport function getIdentify(\n sdk?: MonterosaSdk,\n options?: IdentifyOptions,\n): IdentifyKit;\n\n/**\n * A factory function that creates a new instance of the `IdentifyKit` class,\n * which is a kit of the Monterosa SDK used for user identification.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * ```\n *\n * @remarks\n * - The `getIdentify` function returns an instance of the `IdentifyKit` class\n * using optional MonterosaSdk instance as a parameter.\n *\n * - The `IdentifyKit` instance returned by `getIdentify` can be used to authenticate\n * users and perform other user identification-related operations.\n *\n * - Subsequent calls to getIdentify with the same MonterosaSdk instance will return\n * the same `IdentifyKit` instance.\n *\n * @param options - List of `IdentifyKit` options\n * @returns An instance of the `IdentifyKit` class, which is used for user\n * identification.\n */\nexport function getIdentify(options?: IdentifyOptions): IdentifyKit;\n\nexport function getIdentify(\n sdkOrOptions?: MonterosaSdk | IdentifyOptions,\n options?: IdentifyOptions,\n): IdentifyKit {\n let sdk: MonterosaSdk;\n let identifyOptions: IdentifyOptions;\n\n if (isSdk(sdkOrOptions)) {\n /**\n * Interface: getIdentify(sdk, options?)\n */\n\n sdk = sdkOrOptions;\n\n if (options !== undefined) {\n identifyOptions = options;\n } else {\n identifyOptions = {};\n }\n } else if (sdkOrOptions !== undefined) {\n /**\n * Interface: getIdentify(options)\n */\n\n sdk = getSdk();\n identifyOptions = sdkOrOptions;\n } else {\n /**\n * Interface: getIdentify()\n */\n\n sdk = getSdk();\n identifyOptions = {};\n }\n\n const {\n options: { projectId },\n } = sdk;\n\n if (identifyKits.has(projectId)) {\n return identifyKits.get(projectId) as Identify;\n }\n\n const identify = new Identify(sdk, identifyOptions);\n\n for (const hook of identifyHooks) {\n hook(identify);\n }\n\n identifyKits.set(projectId, identify);\n\n return identify;\n}\n\n/**\n * A function that requests a user login via the `IdentifyKit` of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await requestLogin(identify);\n *\n * console.log('Login request successful');\n * } catch (err) {\n * console.error('Error requesting login:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to handle the login process.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the login request\n * is completed.\n */\nexport async function requestLogin(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.RequestLogin);\n\n return;\n }\n\n identify.emit(IdentifyEvent.LoginRequested);\n}\n\n/**\n * A function that requests a user logout and removing their signature and\n * credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, logout } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * try {\n * const identify = getIdentify();\n *\n * await logout(identify);\n *\n * console.log('User logged out');\n * } catch (err) {\n * console.error('Error logout:', error.message)\n * }\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to log the user out.\n *\n * - If the request is successful, the function resolves with void.\n * If not, a MonterosaError is thrown.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves with `void` when the logout request\n * is completed.\n */\nexport async function logout(identify: IdentifyKit): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(identify, IdentifyAction.Logout);\n\n return;\n }\n\n identify.signature = null;\n identify.credentials = null;\n}\n\n/**\n * Returns a signature for a user session. The signature is based on the\n * user's identifying information provided in the `IdentifyKit` instance.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getSession } from '@monterosa/sdk-identify-kit';\n * import { getConnect, login } from '@monterosa/sdk-connect-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const session = await getSession(identify);\n *\n * const connect = await getConnect();\n * await login(connect, ...session);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get session signature.\n *\n * - If the request is successful, the function resolves with `Signature`.\n * If not, a `MonterosaError` is thrown.\n *\n * - The function can be used to fetch a signature for a user session that\n * can be used to authenticate user with `ConnectKit`.\n *\n * @param identify - An instance of the `IdentifyKit` class used for user\n * identification.\n * @returns A Promise that resolves to an object of type `Signature`.\n */\nexport async function getSessionSignature(\n identify: IdentifyKit,\n): Promise<Signature> {\n if (identify.signature !== null) {\n return identify.signature;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const signature = await parentAppRequest<Signature>(\n identify,\n IdentifyAction.GetSessionSignature,\n );\n\n return signature;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user/check');\n\n const { data } = await api<UserCheckResponse>(\n url,\n identify.credentials.token,\n );\n\n const signature: Signature = [data.userId, data.timeStamp, data.signature];\n\n identify.signature = signature;\n identify.expireSignature(SIGNATURE_TTL);\n\n return signature;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserCheckFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * The function that takes an instance of `IdentifyKit` as its argument and\n * returns a Promise that resolves to a `UserData` object.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, getUserData } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n * const { userId } = await getUserData(identify);\n *\n * console.log(`User id is ${userId}`);\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to get user data.\n *\n * - If the request is successful, the function resolves with `UserData`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @returns A Promise that resolves to a `UserData` object. The `UserData`\n * object contains information about the user, including their `userId`,\n * `timestamp`, and `signature`, as well as any additional properties.\n */\nexport async function getUserData(identify: IdentifyKit): Promise<UserData> {\n if (identify.userData !== null) {\n return identify.userData;\n }\n\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n const userData = await parentAppRequest<UserData>(\n identify,\n IdentifyAction.GetUserData,\n );\n\n return userData;\n }\n\n if (identify.credentials === null) {\n throw createError(IdentifyError.NoCredentials, IdentifyErrorMessages);\n }\n\n try {\n const url = await identify.getUrl('/user');\n\n const { data } = await api<UserResponse>(url, identify.credentials.token);\n\n identify.userData = data;\n identify.expireUserData(USER_DATA_TTL);\n\n return data;\n } catch (err) {\n if (err instanceof Error) {\n identify.emit(IdentifyEvent.ApiUserDataFailed, err.message);\n identify.emit(IdentifyEvent.CredentialsValidationFailed, err.message);\n }\n\n throw err;\n }\n}\n\n/**\n * Sets the user's authentication credentials.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, setCredentials } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const credentials = { token: 'abc123' };\n * const identify = getIdentify();\n *\n * await setCredentials(identify, credentials)\n * ```\n *\n * @remarks\n * - If the app is running within a third-party application that uses\n * the Monterosa SDK, the function delegates to the parent app\n * to set user credentials.\n *\n * - If the request is successful, the function resolves to `void`.\n * If not, a `MonterosaError` is thrown.\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param credentials - An object representing the user's authentication\n * credentials.\n * @returns A Promise that resolves to `void`.\n */\nexport async function setCredentials(\n identify: IdentifyKit,\n credentials: Credentials,\n): Promise<void> {\n const parentApp = getParentApplication();\n\n if (parentApp !== null) {\n await parentAppRequest<void>(\n identify,\n IdentifyAction.SetCredentials,\n credentials,\n );\n\n return;\n }\n\n identify.credentials = credentials;\n}\n\n/**\n * Registers a callback function that will be called whenever the `Credentials`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsUpdated(identify, (credentials) => {\n * if (credentials !== null) {\n * console.log(\"Credentials updated:\", credentials);\n * } else {\n * console.log(\"Credentials cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Credentials` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsUpdated(\n identify: IdentifyKit,\n callback: (credentials: Credentials | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.CredentialsUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `Signature`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onSignatureUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onSignatureUpdated(identify, (signature) => {\n * if (signature !== null) {\n * console.log(\"Signature updated:\", signature);\n * } else {\n * console.log(\"Signature cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `Signature` object as its only argument.\n * If the value `null` is received, it indicates that the signature has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onSignatureUpdated(\n identify: IdentifyKit,\n callback: (signature: Signature | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.SignatureUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called whenever the `UserData`\n * object associated with the `IdentifyKit` instance is updated.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onUserDataUpdated } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onUserDataUpdated(identify, (userData) => {\n * if (userData !== null) {\n * console.log(\"User's data updated:\", userData);\n * } else {\n * console.log(\"User's data cleared.\");\n * }\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will be\n * called with the updated `UserData` object as its only argument.\n * If the value `null` is received, it indicates that the user's data has\n * been cleared\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onUserDataUpdated(\n identify: IdentifyKit,\n callback: (userData: UserData | null) => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.UserdataUpdated, callback);\n}\n\n/**\n * Registers a callback function that will be called when a login is requested\n * by an Experience.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onLoginRequestedByExperience } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onLoginRequestedByExperience(identify, () => {\n * showLoginForm();\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when a login is requested by an experience.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onLoginRequestedByExperience(\n identify: IdentifyKit,\n callback: () => void,\n): Unsubscribe {\n return subscribe(identify, IdentifyEvent.LoginRequested, callback);\n}\n\n/**\n * Registers a callback function that will be called when the credentials validation fails.\n *\n * @example\n * ```javascript\n * import { configure } from '@monterosa/sdk-core';\n * import { getIdentify, onCredentialsValidationFailed } from '@monterosa/sdk-identify-kit';\n *\n * configure({ host: '...', projectId: '...' });\n *\n * const identify = getIdentify();\n *\n * const unsubscribe = onCredentialsValidationFailed(identify, (error) => {\n * console.log(error);\n * });\n *\n * // Call unsubscribe() to unregister the callback function\n * // unsubscribe();\n * ```\n *\n * @param identify - An instance of `IdentifyKit` that provides the user\n * identification functionality.\n * @param callback - The callback function to register. This function will\n * be called when an error occured.\n * @returns An `Unsubscribe` function that can be called to unregister\n * the callback function.\n */\nexport function onCredentialsValidationFailed(\n identify: IdentifyKit,\n callback: (error: string) => void,\n): Unsubscribe {\n return subscribe(\n identify,\n IdentifyEvent.CredentialsValidationFailed,\n callback,\n );\n}\n","/**\n * @license\n * bridge.ts\n * identify-kit\n *\n * Created by Rygor Kharytanovich <rygor@monterosa.co.uk> on 2023-03-07\n * Copyright © 2023-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaSdk, configure, getSdks } from '@monterosa/sdk-core';\nimport { Unsubscribe, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n getParentApplication,\n registerEmbedHook,\n respondToSdkMessage,\n sendSdkMessage,\n onSdkMessage,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n IdentifyKit,\n IdentifyAction,\n Credentials,\n Signature,\n UserData,\n IdentifyEvent,\n} from './types';\n\nimport {\n getIdentify,\n getUserData,\n getSessionSignature,\n setCredentials,\n requestLogin,\n logout,\n onCredentialsUpdated,\n onSignatureUpdated,\n onUserDataUpdated,\n onCredentialsValidationFailed,\n registerIdentifyHook,\n} from './api';\n\n/**\n * @internal\n */\nexport function parentMessagesHook(identify: IdentifyKit) {\n const parentApp = getParentApplication();\n\n if (parentApp === null) {\n return () => {};\n }\n\n return onSdkMessage(parentApp, ({ action, payload }) => {\n switch (action) {\n case IdentifyAction.OnCredentialsUpdated: {\n identify.credentials = payload.credentials as Credentials;\n break;\n }\n case IdentifyAction.OnSessionSignatureUpdated: {\n identify.signature = payload.signature as Signature;\n break;\n }\n case IdentifyAction.OnUserDataUpdated: {\n identify.userData = payload.userData as UserData;\n break;\n }\n case IdentifyAction.OnCredentialsValidationFailed: {\n identify.emit(IdentifyEvent.CredentialsValidationFailed, payload.error);\n break;\n }\n }\n });\n}\n\n/**\n * Finds an existing SDK with matching projectId, or creates a new one.\n */\nfunction getOrConfigureSdk(host: string, projectId: string): MonterosaSdk {\n const existingSdk = getSdks().find(\n (sdk) => sdk.options.projectId === projectId,\n );\n\n return existingSdk ?? configure({ host, projectId }, projectId);\n}\n\nfunction onExperienceEmbed(experience: Experience): Unsubscribe {\n const identify = getIdentify(experience.sdk);\n\n const credentialsUpdatedUnsub = onCredentialsUpdated(\n identify,\n (credentials) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsUpdated, {\n credentials,\n });\n },\n );\n\n const signatureUpdatedUnsub = onSignatureUpdated(identify, (signature) => {\n sendSdkMessage(experience, IdentifyAction.OnSessionSignatureUpdated, {\n signature,\n });\n });\n\n const userDataUpdatedUnsub = onUserDataUpdated(identify, (userData) => {\n sendSdkMessage(experience, IdentifyAction.OnUserDataUpdated, {\n userData,\n });\n });\n\n const validationFailedUnsub = onCredentialsValidationFailed(\n identify,\n (error) => {\n sendSdkMessage(experience, IdentifyAction.OnCredentialsValidationFailed, {\n error,\n });\n },\n );\n\n const sdkMessageUnsub = onSdkMessage(experience, async (message) => {\n if (\n !Object.values(IdentifyAction).includes(message.action as IdentifyAction)\n ) {\n return;\n }\n\n // Extract origin context from payload if available.\n // New clients include origin (host, projectId) to ensure correct project context\n // in multilevel integrations. Old clients don't send origin, so we fall back\n // to the experience's SDK to maintain backward compatibility.\n const { origin } = message.payload as {\n origin?: { host: string; projectId: string };\n };\n\n const originSdk = origin\n ? getOrConfigureSdk(origin.host, origin.projectId)\n : experience.sdk;\n\n const originIdentify = getIdentify(originSdk);\n\n try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout successful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Session signature obtained successfully',\n data: signature,\n });\n break;\n }\n case IdentifyAction.GetUserData: {\n const userData = await getUserData(originIdentify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'User data obtained successfully',\n data: userData,\n });\n break;\n }\n case IdentifyAction.SetCredentials: {\n await setCredentials(originIdentify, {\n token: message.payload.token as Credentials['token'],\n });\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Credentials updated successfully',\n data: {},\n });\n\n break;\n }\n }\n } catch (err) {\n respondToSdkMessage(experience, message, {\n result: 'failure',\n message: getErrorMessage(err),\n data: {},\n });\n }\n });\n\n return () => {\n credentialsUpdatedUnsub();\n signatureUpdatedUnsub();\n userDataUpdatedUnsub();\n sdkMessageUnsub();\n validationFailedUnsub();\n };\n}\n\nregisterEmbedHook(onExperienceEmbed);\nregisterIdentifyHook(parentMessagesHook);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AAuJA;;;AAGA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,mDAAkC,CAAA;IAClC,uDAAsC,CAAA;IACtC,2DAA0C,CAAA;IAC1C,qDAAoC,CAAA;IACpC,6DAA4C,CAAA;IAC5C,2DAA0C,CAAA;IAC1C,8EAA6D,CAAA;AAC/D,CAAC,EARW,aAAa,KAAb,aAAa,QAQxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2BY;AAAZ,WAAY,aAAa;;;;IAIvB,0DAAyC,CAAA;;;;IAIzC,0DAAyC,CAAA;;;;;IAKzC,iDAAgC,CAAA;;;;IAIh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AAS;qBAChB,CAAC,CAAC;oBACH,yBAAM;wBAGW,qBAAM,WAAW,CAAC,cAAc,CAAC,EAAA;;oBAA5C,QAAQ,GAAG,SAAiC;oBAElD,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,iCAAiC;wBAC1C,IAAI,EAAE,QAAQ;qBACf,CAAC,CAAC;oBACH,yBAAM;yBAGN,qBAAM,cAAc,CAAC,cAAc,EAAE;wBACnC,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAA6B;qBACrD,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBAEH,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,kCAAkC;wBAC3C,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;oBAEH,yBAAM;;;;oBAIV,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE;wBACvC,MAAM,EAAE,SAAS;wBACjB,OAAO,EAAE,eAAe,CAAC,KAAG,CAAC;wBAC7B,IAAI,EAAE,EAAE;qBACT,CAAC,CAAC;;;;;SAEN,CAAC,CAAC;IAEH,OAAO;QACL,uBAAuB,EAAE,CAAC;QAC1B,qBAAqB,EAAE,CAAC;QACxB,oBAAoB,EAAE,CAAC;QACvB,eAAe,EAAE,CAAC;QAClB,qBAAqB,EAAE,CAAC;KACzB,CAAC;AACJ,CAAC;AAED,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AACrC,oBAAoB,CAAC,kBAAkB,CAAC;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monterosa/sdk-identify-kit",
3
- "version": "0.18.7",
3
+ "version": "0.18.8",
4
4
  "description": "Identify Kit for the Monterosa JS SDK",
5
5
  "author": "Monterosa <hello@monterosa.co.uk> (https://www.monterosa.co/)",
6
6
  "main": "dist/index.cjs.js",
@@ -30,11 +30,11 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/runtime": "^7.15.4",
33
- "@monterosa/sdk-core": "^0.18.7",
34
- "@monterosa/sdk-interact-interop": "^0.18.7",
35
- "@monterosa/sdk-interact-kit": "^0.18.7",
36
- "@monterosa/sdk-launcher-kit": "^0.18.7",
37
- "@monterosa/sdk-util": "^0.18.7"
33
+ "@monterosa/sdk-core": "^0.18.8",
34
+ "@monterosa/sdk-interact-interop": "^0.18.8",
35
+ "@monterosa/sdk-interact-kit": "^0.18.8",
36
+ "@monterosa/sdk-launcher-kit": "^0.18.8",
37
+ "@monterosa/sdk-util": "^0.18.8"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@rollup/plugin-json": "^4.1.0",
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "cee6a1ddf6db6c544cf5b7cb7b349d9be45b3893"
54
+ "gitHead": "66794ba6e6dccd31382eb63cdd3b3d9307a53974"
55
55
  }