@monterosa/sdk-identify-kit 0.18.4 → 0.18.5-rc.2

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
@@ -361,16 +361,28 @@ function isSdk(value) {
361
361
  function api(url, token, method) {
362
362
  if (method === void 0) { method = 'GET'; }
363
363
  return __awaiter(this, void 0, void 0, function () {
364
- var response, data;
364
+ var headers, credentials, response, data;
365
365
  return __generator(this, function (_a) {
366
366
  switch (_a.label) {
367
- case 0: return [4 /*yield*/, fetch(url, {
368
- method: method,
369
- headers: {
370
- accept: 'application/json',
371
- Authorization: "Bearer " + token,
372
- },
373
- })];
367
+ case 0:
368
+ headers = {
369
+ accept: 'application/json',
370
+ };
371
+ // Only include Authorization header for bearer token authentication
372
+ // When token is 'cookie', use credentials: 'include' to ensure HttpOnly
373
+ // cookies are sent
374
+ if (token === 'cookie') {
375
+ // Use credentials: 'include' to ensure HttpOnly cookies are sent
376
+ credentials = 'include';
377
+ }
378
+ else {
379
+ headers.Authorization = "Bearer " + token;
380
+ }
381
+ return [4 /*yield*/, fetch(url, {
382
+ method: method,
383
+ headers: headers,
384
+ credentials: credentials,
385
+ })];
374
386
  case 1:
375
387
  response = _a.sent();
376
388
  return [4 /*yield*/, response.json()];
@@ -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 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 is a string value representing the user's authentication token.\n *\n * @example\n * ```javascript\n * const credentials: Credentials = { token: \"abc123\" };\n * ```\n */\nexport type Credentials = {\n token: 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 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\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};\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\n if (!Object.prototype.hasOwnProperty.call(listings.assets, EXTENSION_ID)) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return listings.assets[EXTENSION_ID][0].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 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, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n ParentApplication,\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: string,\n method: string = 'GET',\n): Promise<T> {\n const response = await fetch(url, {\n method,\n headers: {\n accept: 'application/json',\n Authorization: `Bearer ${token}`,\n },\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 parentApp: ParentApplication,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const response = await sendSdkRequest(parentApp, action, payload);\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>(parentApp, 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>(parentApp, 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 parentApp,\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 parentApp,\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 parentApp,\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 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\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\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 try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(identify);\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(identify);\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(identify, {\n token: message.payload.token as string,\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","sendSdkRequest","getSdk","getParentApplication","subscribe","onSdk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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;;;;;;;;;;;;;;;;"}
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 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 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\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};\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\n if (!Object.prototype.hasOwnProperty.call(listings.assets, EXTENSION_ID)) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return listings.assets[EXTENSION_ID][0].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 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, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n ParentApplication,\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 parentApp: ParentApplication,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const response = await sendSdkRequest(parentApp, action, payload);\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>(parentApp, 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>(parentApp, 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 parentApp,\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 parentApp,\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 parentApp,\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 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\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\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 try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(identify);\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(identify);\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(identify, {\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","sendSdkRequest","getSdk","getParentApplication","subscribe","onSdkMessage","sendSdkMessage","respondToSdkMessage","getErrorMessage","registerEmbedHook"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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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;;;;;;;;;;;;;;;;"}
@@ -224,12 +224,24 @@ function isSdk(value) {
224
224
  return value instanceof Sdk;
225
225
  }
226
226
  async function api(url, token, method = 'GET') {
227
+ const headers = {
228
+ accept: 'application/json',
229
+ };
230
+ let credentials;
231
+ // Only include Authorization header for bearer token authentication
232
+ // When token is 'cookie', use credentials: 'include' to ensure HttpOnly
233
+ // cookies are sent
234
+ if (token === 'cookie') {
235
+ // Use credentials: 'include' to ensure HttpOnly cookies are sent
236
+ credentials = 'include';
237
+ }
238
+ else {
239
+ headers.Authorization = `Bearer ${token}`;
240
+ }
227
241
  const response = await fetch(url, {
228
242
  method,
229
- headers: {
230
- accept: 'application/json',
231
- Authorization: `Bearer ${token}`,
232
- },
243
+ headers,
244
+ credentials,
233
245
  });
234
246
  const data = (await response.json());
235
247
  if (data.result < 0) {
@@ -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 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 is a string value representing the user's authentication token.\n *\n * @example\n * ```javascript\n * const credentials: Credentials = { token: \"abc123\" };\n * ```\n */\nexport type Credentials = {\n token: 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 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\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};\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\n if (!Object.prototype.hasOwnProperty.call(listings.assets, EXTENSION_ID)) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return listings.assets[EXTENSION_ID][0].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 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, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n ParentApplication,\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: string,\n method: string = 'GET',\n): Promise<T> {\n const response = await fetch(url, {\n method,\n headers: {\n accept: 'application/json',\n Authorization: `Bearer ${token}`,\n },\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 parentApp: ParentApplication,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const response = await sendSdkRequest(parentApp, action, payload);\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>(parentApp, 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>(parentApp, 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 parentApp,\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 parentApp,\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 parentApp,\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 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\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\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 try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(identify);\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(identify);\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(identify, {\n token: message.payload.token as string,\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":[],"m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OAAO,CAAC,KAAe;qBACvC,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 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 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\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};\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\n if (!Object.prototype.hasOwnProperty.call(listings.assets, EXTENSION_ID)) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return listings.assets[EXTENSION_ID][0].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 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, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n ParentApplication,\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 parentApp: ParentApplication,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const response = await sendSdkRequest(parentApp, action, payload);\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>(parentApp, 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>(parentApp, 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 parentApp,\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 parentApp,\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 parentApp,\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 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\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\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 try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(identify);\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(identify);\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(identify, {\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 sdkMessageUns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BAE7C,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,QAAQ,EAAE;wBAC7B,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;;;;"}
@@ -357,16 +357,28 @@ function isSdk(value) {
357
357
  function api(url, token, method) {
358
358
  if (method === void 0) { method = 'GET'; }
359
359
  return __awaiter(this, void 0, void 0, function () {
360
- var response, data;
360
+ var headers, credentials, response, data;
361
361
  return __generator(this, function (_a) {
362
362
  switch (_a.label) {
363
- case 0: return [4 /*yield*/, fetch(url, {
364
- method: method,
365
- headers: {
366
- accept: 'application/json',
367
- Authorization: "Bearer " + token,
368
- },
369
- })];
363
+ case 0:
364
+ headers = {
365
+ accept: 'application/json',
366
+ };
367
+ // Only include Authorization header for bearer token authentication
368
+ // When token is 'cookie', use credentials: 'include' to ensure HttpOnly
369
+ // cookies are sent
370
+ if (token === 'cookie') {
371
+ // Use credentials: 'include' to ensure HttpOnly cookies are sent
372
+ credentials = 'include';
373
+ }
374
+ else {
375
+ headers.Authorization = "Bearer " + token;
376
+ }
377
+ return [4 /*yield*/, fetch(url, {
378
+ method: method,
379
+ headers: headers,
380
+ credentials: credentials,
381
+ })];
370
382
  case 1:
371
383
  response = _a.sent();
372
384
  return [4 /*yield*/, response.json()];
@@ -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 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 is a string value representing the user's authentication token.\n *\n * @example\n * ```javascript\n * const credentials: Credentials = { token: \"abc123\" };\n * ```\n */\nexport type Credentials = {\n token: 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 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\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};\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\n if (!Object.prototype.hasOwnProperty.call(listings.assets, EXTENSION_ID)) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return listings.assets[EXTENSION_ID][0].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 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, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n ParentApplication,\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: string,\n method: string = 'GET',\n): Promise<T> {\n const response = await fetch(url, {\n method,\n headers: {\n accept: 'application/json',\n Authorization: `Bearer ${token}`,\n },\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 parentApp: ParentApplication,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const response = await sendSdkRequest(parentApp, action, payload);\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>(parentApp, 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>(parentApp, 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 parentApp,\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 parentApp,\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 parentApp,\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 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\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\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 try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(identify);\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(identify);\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(identify, {\n token: message.payload.token as string,\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;;;;;;;;;;;AA6IA;;;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,CA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;oBAAtC,QAAQ,GAAG,SAA2B;oBAE5C,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,QAAQ,EAAE;wBAC7B,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,KAAe;qBACvC,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;;;;"}
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 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 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\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};\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\n if (!Object.prototype.hasOwnProperty.call(listings.assets, EXTENSION_ID)) {\n throw createError(IdentifyError.ExtensionNotSetup, IdentifyErrorMessages);\n }\n\n return listings.assets[EXTENSION_ID][0].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 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, Sdk, getSdk } from '@monterosa/sdk-core';\nimport { subscribe, Unsubscribe, createError } from '@monterosa/sdk-util';\nimport {\n Payload,\n ParentApplication,\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 parentApp: ParentApplication,\n action: IdentifyAction,\n payload?: Payload,\n): Promise<T> {\n const response = await sendSdkRequest(parentApp, action, payload);\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>(parentApp, 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>(parentApp, 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 parentApp,\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 parentApp,\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 parentApp,\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 Monterosa. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\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\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 try {\n switch (message.action) {\n case IdentifyAction.RequestLogin: {\n await requestLogin(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Login request succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.Logout: {\n await logout(identify);\n\n respondToSdkMessage(experience, message, {\n result: 'success',\n message: 'Logout succesful',\n data: {},\n });\n\n break;\n }\n case IdentifyAction.GetSessionSignature: {\n const signature = await getSessionSignature(identify);\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(identify);\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(identify, {\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;;;;;;;;;;;AAmJA;;;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;AACrC,CAAC,EAtBW,aAAa,KAAb,aAAa,QAsBxB;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,G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M,cAAc,CAAC,QAAQ,EAAE;wBAC7B,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/dist/types.d.ts CHANGED
@@ -12,15 +12,21 @@ import { MonterosaSdk } from '@monterosa/sdk-core';
12
12
  import { Emitter, Unsubscribe } from '@monterosa/sdk-util';
13
13
  /**
14
14
  * The type represents a user credentials. It contains a single property, token,
15
- * which is a string value representing the user's authentication token.
15
+ * which can be either the literal 'cookie' for cookie-based authentication or
16
+ * a string value representing the user's authentication token for bearer token
17
+ * authentication.
16
18
  *
17
19
  * @example
18
20
  * ```javascript
21
+ * // Bearer token authentication
19
22
  * const credentials: Credentials = { token: "abc123" };
23
+ *
24
+ * // Cookie-based authentication
25
+ * const credentials: Credentials = { token: "cookie" };
20
26
  * ```
21
27
  */
22
28
  export declare type Credentials = {
23
- token: string;
29
+ token: 'cookie' | string;
24
30
  };
25
31
  /**
26
32
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monterosa/sdk-identify-kit",
3
- "version": "0.18.4",
3
+ "version": "0.18.5-rc.2",
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.4",
34
- "@monterosa/sdk-interact-interop": "^0.18.4",
35
- "@monterosa/sdk-interact-kit": "^0.18.4",
36
- "@monterosa/sdk-launcher-kit": "^0.18.4",
37
- "@monterosa/sdk-util": "^0.18.4"
33
+ "@monterosa/sdk-core": "^0.18.5-rc.2",
34
+ "@monterosa/sdk-interact-interop": "^0.18.5-rc.2",
35
+ "@monterosa/sdk-interact-kit": "^0.18.5-rc.2",
36
+ "@monterosa/sdk-launcher-kit": "^0.18.5-rc.2",
37
+ "@monterosa/sdk-util": "^0.18.5-rc.2"
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": "f26d951a03f57fa425b5d244f30f2c8e5e103c26"
54
+ "gitHead": "1ebb1213fcd40ca11d97f56001200a242e084a28"
55
55
  }