@monterosa/sdk-storage-kit 0.18.9 → 0.18.10
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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/storage_impl.ts","../src/api.ts"],"sourcesContent":["/**\n * @license\n * types.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport enum StorageAction {\n Read = 'storageRead',\n Write = 'storageWrite',\n Remove = 'storageRemove',\n Clear = 'storageClear',\n}\n\nexport type ResponsePayload = {\n key: string;\n value?: string | null;\n error?: string;\n};\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Storage kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the StorageKit\n * } catch (err) {\n * if (err.code === StorageError.ParentApp) {\n * // handle parent app error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `StorageError` enum provides a convenient way to handle errors\n * encountered when using the `StorageKit` 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 `StorageError` enum is not intended to be instantiated or extended.\n */\nexport enum StorageError {\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates a timeout occurred when communicating with the parent app.\n */\n ParentTimeoutError = 'parent_timeout_error',\n /**\n * Indicates an error occurred when reading from the storage.\n */\n ReadError = 'read_error',\n /**\n * Indicates an error occurred when writing to the storage.\n */\n WriteError = 'write_error',\n /**\n * Indicates an error occurred when removing from the storage.\n */\n RemoveError = 'remove_error',\n /**\n * Indicates an error occurred when clearing the storage.\n */\n ClearError = 'clear_error',\n}\n\n/**\n * @internal\n */\nexport const StorageErrorMessages = {\n [StorageError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [StorageError.ParentTimeoutError]: (error: string) =>\n `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,\n [StorageError.ReadError]: (error: string) => `Storage read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Storage write error: ${error}`,\n [StorageError.RemoveError]: (error: string) =>\n `Storage remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `Storage clear error: ${error}`,\n};\n","/**\n * @license\n * storage_impl.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n checkAvailability,\n getItem,\n setItem,\n removeItem,\n clear,\n} from '@monterosa/sdk-util';\n\nexport class StorageImpl {\n private memoryStore: { [key: string]: string } = {};\n private accessible: boolean = checkAvailability();\n private _persistent: boolean = true;\n\n set persistent(newValue: boolean) {\n const oldValue = this._persistent;\n\n if (oldValue === newValue) {\n return;\n }\n\n const swapToStorage = newValue === true && this.accessible;\n const swapToMemory = newValue === false && this.accessible;\n\n if (swapToStorage) {\n for (const [key, value] of Object.entries(this.memoryStore)) {\n setItem(key, value);\n }\n }\n\n if (swapToMemory) {\n clear();\n }\n\n this._persistent = newValue;\n }\n\n get persistent(): boolean {\n return this._persistent;\n }\n\n getItem(key: string): string | null {\n if (this.persistent && this.accessible) {\n return getItem(key);\n }\n\n if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {\n return this.memoryStore[key];\n }\n\n return null;\n }\n\n setItem(key: string, value: string): void {\n if (this.persistent && this.accessible) {\n setItem(key, value);\n }\n\n this.memoryStore[key] = value;\n }\n\n removeItem(key: string): void {\n if (this.persistent && this.accessible) {\n removeItem(key);\n }\n\n delete this.memoryStore[key];\n }\n\n clear(): void {\n if (this.persistent && this.accessible) {\n clear();\n }\n\n this.memoryStore = {};\n }\n}\n","/**\n * @license\n * api.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n Unsubscribe,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\n BridgeError,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n StorageAction,\n ResponsePayload,\n StorageError,\n StorageErrorMessages,\n} from './types';\nimport { StorageImpl } from './storage_impl';\n\n/**\n * @internal\n */\nexport const storage = new StorageImpl();\n\n/**\n * @internal\n */\nexport function listenStorageMessages(experience: Experience): Unsubscribe {\n return onSdkMessage(experience, (message) => {\n if (\n !Object.values(StorageAction).includes(message.action as StorageAction)\n ) {\n return;\n }\n\n try {\n let payload: Payload = {};\n\n switch (message.action) {\n case StorageAction.Read:\n payload = {\n key: message.payload.key,\n value: storage.getItem(message.payload.key),\n };\n break;\n case StorageAction.Write:\n payload = {\n key: message.payload.key,\n };\n storage.setItem(message.payload.key, message.payload.value);\n break;\n case StorageAction.Remove:\n payload = {\n key: message.payload.key,\n };\n storage.removeItem(message.payload.key);\n break;\n case StorageAction.Clear:\n storage.clear();\n break;\n }\n\n respondToSdkMessage(experience, message, payload);\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to handle storage message ${message.action} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Read,\n payload?: Payload,\n): Promise<string | null>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction,\n payload?: Payload,\n): Promise<string | null | undefined> {\n try {\n const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(\n StorageError.ParentAppError,\n StorageErrorMessages,\n error,\n );\n }\n\n return value;\n } catch (err) {\n if (\n err instanceof MonterosaError &&\n err.code === BridgeError.RequestTimeoutError\n ) {\n const errorMessage = getErrorMessage(err);\n\n throw createError(\n StorageError.ParentTimeoutError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n throw err;\n }\n}\n\n/**\n * The `setStoragePersistent` function is a simple function that allows to\n * control the persistence of the SDK storage. If the argument `persistent` is\n * set to `true`, then the storage will be persistent across browser sessions\n * and if it is set to `false`, then the storage will save to memory.\n * It is important to note that the use of persistent storage may be subject\n * to laws and regulations, such as those related to data privacy and protection.\n *\n * @remarks\n * - We transition from persistent to memory and memory to persistent in\n * a seamless manner for you\n *\n * - By default we store in memory\n *\n * - The value of storage persistent persists across session (aka put it to true,\n * it will remain so, put it back to false, it will remain so)\n *\n * - You have the responsibility to comply with any laws and regulations, and\n * store only the data if you know it's valid to do so\n *\n * @param persistent - Determines whether or not SDK storage should persist\n * across browser sessions.\n */\nexport function setStoragePersistent(persistent: boolean): void {\n storage.persistent = persistent;\n}\n\n/**\n * The function allows to read data from the SDK storage.\n *\n * @param key - The name of the item to be read from storage.\n *\n * @throws\n * The function throws an error if there is a timeout reading the data\n * from the parent application storage.\n *\n * @returns A promise that resolves to the value\n * of the item in storage or `null` if the item doesn't exist.\n */\nexport async function storageRead(key: string): Promise<string | null> {\n const parentApp = getParentApplication();\n\n let value: string | null = null;\n\n try {\n if (parentApp !== null) {\n value = await parentAppRequest(parentApp, StorageAction.Read, {\n key,\n });\n } else {\n value = storage.getItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to read storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.ReadError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n return value;\n}\n\n/**\n * The function allows to write data to the SDK storage.\n *\n * @param key - A name of the item to be stored.\n * @param value - A value to be stored.\n *\n * @throws\n * The function throws an error if there is a timeout writing the data\n * to the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully stored.\n */\nexport async function storageWrite(key: string, value: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Write, {\n key,\n value,\n });\n } else {\n storage.setItem(key, value);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to write storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.WriteError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to remove an item from the SDK storage.\n *\n * @param key - A name of the item to be removed.\n *\n * @throws\n * The function throws an error if there is a timeout removing the data\n * from the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully removed.\n */\nexport async function storageRemove(key: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Remove, { key });\n } else {\n storage.removeItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to remove storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.RemoveError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to clear all data from the SDK storage.\n *\n * @throws\n * The function throws an error if there is a timeout clearing the parent's\n * application storage.\n *\n * @returns A promise that resolves to `void` once the data has been\n * successfully cleared.\n */\nexport async function storageClear(): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Clear);\n } else {\n storage.clear();\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(`Unable to clear storage with error: ${errorMessage}`);\n\n throw createError(\n StorageError.ClearError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\nregisterEmbedHook(listenStorageMessages);\n"],"names":["StorageError","checkAvailability","setItem","clear","getItem","removeItem","onSdkMessage","respondToSdkMessage","getErrorMessage","sendSdkRequest","createError","MonterosaError","BridgeError","getParentApplication","registerEmbedHook"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;AAUA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,qCAAoB,CAAA;IACpB,uCAAsB,CAAA;IACtB,yCAAwB,CAAA;IACxB,uCAAsB,CAAA;AACxB,CAAC,EALW,aAAa,KAAb,aAAa,QAKxB;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;AAyBYA;AAAZ,WAAY,YAAY;;;;IAItB,mDAAmC,CAAA;;;;IAInC,2DAA2C,CAAA;;;;IAI3C,wCAAwB,CAAA;;;;IAIxB,0CAA0B,CAAA;;;;IAI1B,4CAA4B,CAAA;;;;IAI5B,0CAA0B,CAAA;AAC5B,CAAC,EAzBWA,oBAAY,KAAZA,oBAAY,QAyBvB;AAED;;;AAGO,IAAM,oBAAoB;IAC/B,GAACA,oBAAY,CAAC,cAAc,IAAG,UAAC,KAAa;QAC3C,OAAA,+BAA6B,KAAO;KAAA;IACtC,GAACA,oBAAY,CAAC,kBAAkB,IAAG,UAAC,KAAa;QAC/C,OAAA,iCAA+B,KAAK,sEAAmE;KAAA;IACzG,GAACA,oBAAY,CAAC,SAAS,IAAG,UAAC,KAAa,IAAK,OAAA,yBAAuB,KAAO,GAAA;IAC3E,GAACA,oBAAY,CAAC,UAAU,IAAG,UAAC,KAAa,IAAK,OAAA,0BAAwB,KAAO,GAAA;IAC7E,GAACA,oBAAY,CAAC,WAAW,IAAG,UAAC,KAAa;QACxC,OAAA,2BAAyB,KAAO;KAAA;IAClC,GAACA,oBAAY,CAAC,UAAU,IAAG,UAAC,KAAa,IAAK,OAAA,0BAAwB,KAAO,GAAA;OAC9E;;ACxFD;;;;;;;;;AAkBA;IAAA;QACU,gBAAW,GAA8B,EAAE,CAA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AAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAEDc,gCAAiB,CAAC,qBAAqB,CAAC;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/storage_impl.ts","../src/api.ts"],"sourcesContent":["/**\n * @license\n * types.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport enum StorageAction {\n Read = 'storageRead',\n Write = 'storageWrite',\n Remove = 'storageRemove',\n Clear = 'storageClear',\n}\n\nexport type ResponsePayload = {\n key: string;\n value?: string | null;\n error?: string;\n};\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Storage kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the StorageKit\n * } catch (err) {\n * if (err.code === StorageError.ParentApp) {\n * // handle parent app error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `StorageError` enum provides a convenient way to handle errors\n * encountered when using the `StorageKit` 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 `StorageError` enum is not intended to be instantiated or extended.\n */\nexport enum StorageError {\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates a timeout occurred when communicating with the parent app.\n */\n ParentTimeoutError = 'parent_timeout_error',\n /**\n * Indicates an error occurred when reading from the storage.\n */\n ReadError = 'read_error',\n /**\n * Indicates an error occurred when writing to the storage.\n */\n WriteError = 'write_error',\n /**\n * Indicates an error occurred when removing from the storage.\n */\n RemoveError = 'remove_error',\n /**\n * Indicates an error occurred when clearing the storage.\n */\n ClearError = 'clear_error',\n}\n\n/**\n * @internal\n */\nexport const StorageErrorMessages = {\n [StorageError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [StorageError.ParentTimeoutError]: (error: string) =>\n `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,\n [StorageError.ReadError]: (error: string) => `Storage read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Storage write error: ${error}`,\n [StorageError.RemoveError]: (error: string) =>\n `Storage remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `Storage clear error: ${error}`,\n};\n","/**\n * @license\n * storage_impl.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n checkAvailability,\n getItem,\n setItem,\n removeItem,\n clear,\n} from '@monterosa/sdk-util';\n\nexport class StorageImpl {\n private memoryStore: { [key: string]: string } = {};\n private accessible: boolean = checkAvailability();\n private _persistent: boolean = true;\n\n set persistent(newValue: boolean) {\n const oldValue = this._persistent;\n\n if (oldValue === newValue) {\n return;\n }\n\n const swapToStorage = newValue === true && this.accessible;\n const swapToMemory = newValue === false && this.accessible;\n\n if (swapToStorage) {\n for (const [key, value] of Object.entries(this.memoryStore)) {\n setItem(key, value);\n }\n }\n\n if (swapToMemory) {\n clear();\n }\n\n this._persistent = newValue;\n }\n\n get persistent(): boolean {\n return this._persistent;\n }\n\n getItem(key: string): string | null {\n if (this.persistent && this.accessible) {\n return getItem(key);\n }\n\n if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {\n return this.memoryStore[key];\n }\n\n return null;\n }\n\n setItem(key: string, value: string): void {\n if (this.persistent && this.accessible) {\n setItem(key, value);\n }\n\n this.memoryStore[key] = value;\n }\n\n removeItem(key: string): void {\n if (this.persistent && this.accessible) {\n removeItem(key);\n }\n\n delete this.memoryStore[key];\n }\n\n clear(): void {\n if (this.persistent && this.accessible) {\n clear();\n }\n\n this.memoryStore = {};\n }\n}\n","/**\n * @license\n * api.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n Unsubscribe,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\n BridgeError,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n StorageAction,\n ResponsePayload,\n StorageError,\n StorageErrorMessages,\n} from './types';\nimport { StorageImpl } from './storage_impl';\n\n/**\n * @internal\n */\nexport const storage = new StorageImpl();\n\n/**\n * @internal\n */\nexport function listenStorageMessages(experience: Experience): Unsubscribe {\n return onSdkMessage(experience, (message) => {\n if (\n !Object.values(StorageAction).includes(message.action as StorageAction)\n ) {\n return;\n }\n\n try {\n let payload: Payload = {};\n\n switch (message.action) {\n case StorageAction.Read:\n payload = {\n key: message.payload.key,\n value: storage.getItem(message.payload.key),\n };\n break;\n case StorageAction.Write:\n payload = {\n key: message.payload.key,\n };\n storage.setItem(message.payload.key, message.payload.value);\n break;\n case StorageAction.Remove:\n payload = {\n key: message.payload.key,\n };\n storage.removeItem(message.payload.key);\n break;\n case StorageAction.Clear:\n storage.clear();\n break;\n }\n\n respondToSdkMessage(experience, message, payload);\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to handle storage message ${message.action} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Read,\n payload?: Payload,\n): Promise<string | null>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction,\n payload?: Payload,\n): Promise<string | null | undefined> {\n try {\n const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(\n StorageError.ParentAppError,\n StorageErrorMessages,\n error,\n );\n }\n\n return value;\n } catch (err) {\n if (\n err instanceof MonterosaError &&\n err.code === BridgeError.RequestTimeoutError\n ) {\n const errorMessage = getErrorMessage(err);\n\n throw createError(\n StorageError.ParentTimeoutError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n throw err;\n }\n}\n\n/**\n * The `setStoragePersistent` function is a simple function that allows to\n * control the persistence of the SDK storage. If the argument `persistent` is\n * set to `true`, then the storage will be persistent across browser sessions\n * and if it is set to `false`, then the storage will save to memory.\n * It is important to note that the use of persistent storage may be subject\n * to laws and regulations, such as those related to data privacy and protection.\n *\n * @remarks\n * - We transition from persistent to memory and memory to persistent in\n * a seamless manner for you\n *\n * - By default we store in memory\n *\n * - The value of storage persistent persists across session (aka put it to true,\n * it will remain so, put it back to false, it will remain so)\n *\n * - You have the responsibility to comply with any laws and regulations, and\n * store only the data if you know it's valid to do so\n *\n * @param persistent - Determines whether or not SDK storage should persist\n * across browser sessions.\n */\nexport function setStoragePersistent(persistent: boolean): void {\n storage.persistent = persistent;\n}\n\n/**\n * The function allows to read data from the SDK storage.\n *\n * @param key - The name of the item to be read from storage.\n *\n * @throws\n * The function throws an error if there is a timeout reading the data\n * from the parent application storage.\n *\n * @returns A promise that resolves to the value\n * of the item in storage or `null` if the item doesn't exist.\n */\nexport async function storageRead(key: string): Promise<string | null> {\n const parentApp = getParentApplication();\n\n let value: string | null = null;\n\n try {\n if (parentApp !== null) {\n value = await parentAppRequest(parentApp, StorageAction.Read, {\n key,\n });\n } else {\n value = storage.getItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to read storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.ReadError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n return value;\n}\n\n/**\n * The function allows to write data to the SDK storage.\n *\n * @param key - A name of the item to be stored.\n * @param value - A value to be stored.\n *\n * @throws\n * The function throws an error if there is a timeout writing the data\n * to the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully stored.\n */\nexport async function storageWrite(key: string, value: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Write, {\n key,\n value,\n });\n } else {\n storage.setItem(key, value);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to write storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.WriteError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to remove an item from the SDK storage.\n *\n * @param key - A name of the item to be removed.\n *\n * @throws\n * The function throws an error if there is a timeout removing the data\n * from the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully removed.\n */\nexport async function storageRemove(key: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Remove, { key });\n } else {\n storage.removeItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to remove storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.RemoveError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to clear all data from the SDK storage.\n *\n * @throws\n * The function throws an error if there is a timeout clearing the parent's\n * application storage.\n *\n * @returns A promise that resolves to `void` once the data has been\n * successfully cleared.\n */\nexport async function storageClear(): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Clear);\n } else {\n storage.clear();\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(`Unable to clear storage with error: ${errorMessage}`);\n\n throw createError(\n StorageError.ClearError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\nregisterEmbedHook(listenStorageMessages);\n"],"names":["StorageError","checkAvailability","setItem","clear","getItem","removeItem","onSdkMessage","respondToSdkMessage","getErrorMessage","sendSdkRequest","createError","MonterosaError","BridgeError","getParentApplication","registerEmbedHook"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;AAQG;;AAEH,IAAY,aAKX,CAAA;AALD,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,MAAA,CAAA,GAAA,aAAoB,CAAA;AACpB,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACtB,IAAA,aAAA,CAAA,QAAA,CAAA,GAAA,eAAwB,CAAA;AACxB,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACxB,CAAC,EALW,aAAa,KAAb,aAAa,GAKxB,EAAA,CAAA,CAAA,CAAA;AAQD;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACSA,8BAyBX;AAzBD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AACH,IAAA,YAAA,CAAA,gBAAA,CAAA,GAAA,kBAAmC,CAAA;AACnC;;AAEG;AACH,IAAA,YAAA,CAAA,oBAAA,CAAA,GAAA,sBAA2C,CAAA;AAC3C;;AAEG;AACH,IAAA,YAAA,CAAA,WAAA,CAAA,GAAA,YAAwB,CAAA;AACxB;;AAEG;AACH,IAAA,YAAA,CAAA,YAAA,CAAA,GAAA,aAA0B,CAAA;AAC1B;;AAEG;AACH,IAAA,YAAA,CAAA,aAAA,CAAA,GAAA,cAA4B,CAAA;AAC5B;;AAEG;AACH,IAAA,YAAA,CAAA,YAAA,CAAA,GAAA,aAA0B,CAAA;AAC5B,CAAC,EAzBWA,oBAAY,KAAZA,oBAAY,GAyBvB,EAAA,CAAA,CAAA,CAAA;AAED;;AAEG;AACI,IAAM,oBAAoB,IAAA,EAAA,GAAA,EAAA;AAC/B,IAAA,EAAA,CAACA,oBAAY,CAAC,cAAc,CAAA,GAAG,UAAC,KAAa,EAAA;AAC3C,QAAA,OAAA,+B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EDc,gCAAiB,CAAC,qBAAqB,CAAC;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm2017.js","sources":["../src/types.ts","../src/storage_impl.ts","../src/api.ts"],"sourcesContent":["/**\n * @license\n * types.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport enum StorageAction {\n Read = 'storageRead',\n Write = 'storageWrite',\n Remove = 'storageRemove',\n Clear = 'storageClear',\n}\n\nexport type ResponsePayload = {\n key: string;\n value?: string | null;\n error?: string;\n};\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Storage kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the StorageKit\n * } catch (err) {\n * if (err.code === StorageError.ParentApp) {\n * // handle parent app error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `StorageError` enum provides a convenient way to handle errors\n * encountered when using the `StorageKit` 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 `StorageError` enum is not intended to be instantiated or extended.\n */\nexport enum StorageError {\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates a timeout occurred when communicating with the parent app.\n */\n ParentTimeoutError = 'parent_timeout_error',\n /**\n * Indicates an error occurred when reading from the storage.\n */\n ReadError = 'read_error',\n /**\n * Indicates an error occurred when writing to the storage.\n */\n WriteError = 'write_error',\n /**\n * Indicates an error occurred when removing from the storage.\n */\n RemoveError = 'remove_error',\n /**\n * Indicates an error occurred when clearing the storage.\n */\n ClearError = 'clear_error',\n}\n\n/**\n * @internal\n */\nexport const StorageErrorMessages = {\n [StorageError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [StorageError.ParentTimeoutError]: (error: string) =>\n `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,\n [StorageError.ReadError]: (error: string) => `Storage read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Storage write error: ${error}`,\n [StorageError.RemoveError]: (error: string) =>\n `Storage remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `Storage clear error: ${error}`,\n};\n","/**\n * @license\n * storage_impl.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n checkAvailability,\n getItem,\n setItem,\n removeItem,\n clear,\n} from '@monterosa/sdk-util';\n\nexport class StorageImpl {\n private memoryStore: { [key: string]: string } = {};\n private accessible: boolean = checkAvailability();\n private _persistent: boolean = true;\n\n set persistent(newValue: boolean) {\n const oldValue = this._persistent;\n\n if (oldValue === newValue) {\n return;\n }\n\n const swapToStorage = newValue === true && this.accessible;\n const swapToMemory = newValue === false && this.accessible;\n\n if (swapToStorage) {\n for (const [key, value] of Object.entries(this.memoryStore)) {\n setItem(key, value);\n }\n }\n\n if (swapToMemory) {\n clear();\n }\n\n this._persistent = newValue;\n }\n\n get persistent(): boolean {\n return this._persistent;\n }\n\n getItem(key: string): string | null {\n if (this.persistent && this.accessible) {\n return getItem(key);\n }\n\n if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {\n return this.memoryStore[key];\n }\n\n return null;\n }\n\n setItem(key: string, value: string): void {\n if (this.persistent && this.accessible) {\n setItem(key, value);\n }\n\n this.memoryStore[key] = value;\n }\n\n removeItem(key: string): void {\n if (this.persistent && this.accessible) {\n removeItem(key);\n }\n\n delete this.memoryStore[key];\n }\n\n clear(): void {\n if (this.persistent && this.accessible) {\n clear();\n }\n\n this.memoryStore = {};\n }\n}\n","/**\n * @license\n * api.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n Unsubscribe,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\n BridgeError,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n StorageAction,\n ResponsePayload,\n StorageError,\n StorageErrorMessages,\n} from './types';\nimport { StorageImpl } from './storage_impl';\n\n/**\n * @internal\n */\nexport const storage = new StorageImpl();\n\n/**\n * @internal\n */\nexport function listenStorageMessages(experience: Experience): Unsubscribe {\n return onSdkMessage(experience, (message) => {\n if (\n !Object.values(StorageAction).includes(message.action as StorageAction)\n ) {\n return;\n }\n\n try {\n let payload: Payload = {};\n\n switch (message.action) {\n case StorageAction.Read:\n payload = {\n key: message.payload.key,\n value: storage.getItem(message.payload.key),\n };\n break;\n case StorageAction.Write:\n payload = {\n key: message.payload.key,\n };\n storage.setItem(message.payload.key, message.payload.value);\n break;\n case StorageAction.Remove:\n payload = {\n key: message.payload.key,\n };\n storage.removeItem(message.payload.key);\n break;\n case StorageAction.Clear:\n storage.clear();\n break;\n }\n\n respondToSdkMessage(experience, message, payload);\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to handle storage message ${message.action} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Read,\n payload?: Payload,\n): Promise<string | null>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction,\n payload?: Payload,\n): Promise<string | null | undefined> {\n try {\n const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(\n StorageError.ParentAppError,\n StorageErrorMessages,\n error,\n );\n }\n\n return value;\n } catch (err) {\n if (\n err instanceof MonterosaError &&\n err.code === BridgeError.RequestTimeoutError\n ) {\n const errorMessage = getErrorMessage(err);\n\n throw createError(\n StorageError.ParentTimeoutError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n throw err;\n }\n}\n\n/**\n * The `setStoragePersistent` function is a simple function that allows to\n * control the persistence of the SDK storage. If the argument `persistent` is\n * set to `true`, then the storage will be persistent across browser sessions\n * and if it is set to `false`, then the storage will save to memory.\n * It is important to note that the use of persistent storage may be subject\n * to laws and regulations, such as those related to data privacy and protection.\n *\n * @remarks\n * - We transition from persistent to memory and memory to persistent in\n * a seamless manner for you\n *\n * - By default we store in memory\n *\n * - The value of storage persistent persists across session (aka put it to true,\n * it will remain so, put it back to false, it will remain so)\n *\n * - You have the responsibility to comply with any laws and regulations, and\n * store only the data if you know it's valid to do so\n *\n * @param persistent - Determines whether or not SDK storage should persist\n * across browser sessions.\n */\nexport function setStoragePersistent(persistent: boolean): void {\n storage.persistent = persistent;\n}\n\n/**\n * The function allows to read data from the SDK storage.\n *\n * @param key - The name of the item to be read from storage.\n *\n * @throws\n * The function throws an error if there is a timeout reading the data\n * from the parent application storage.\n *\n * @returns A promise that resolves to the value\n * of the item in storage or `null` if the item doesn't exist.\n */\nexport async function storageRead(key: string): Promise<string | null> {\n const parentApp = getParentApplication();\n\n let value: string | null = null;\n\n try {\n if (parentApp !== null) {\n value = await parentAppRequest(parentApp, StorageAction.Read, {\n key,\n });\n } else {\n value = storage.getItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to read storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.ReadError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n return value;\n}\n\n/**\n * The function allows to write data to the SDK storage.\n *\n * @param key - A name of the item to be stored.\n * @param value - A value to be stored.\n *\n * @throws\n * The function throws an error if there is a timeout writing the data\n * to the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully stored.\n */\nexport async function storageWrite(key: string, value: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Write, {\n key,\n value,\n });\n } else {\n storage.setItem(key, value);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to write storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.WriteError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to remove an item from the SDK storage.\n *\n * @param key - A name of the item to be removed.\n *\n * @throws\n * The function throws an error if there is a timeout removing the data\n * from the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully removed.\n */\nexport async function storageRemove(key: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Remove, { key });\n } else {\n storage.removeItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to remove storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.RemoveError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to clear all data from the SDK storage.\n *\n * @throws\n * The function throws an error if there is a timeout clearing the parent's\n * application storage.\n *\n * @returns A promise that resolves to `void` once the data has been\n * successfully cleared.\n */\nexport async function storageClear(): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Clear);\n } else {\n storage.clear();\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(`Unable to clear storage with error: ${errorMessage}`);\n\n throw createError(\n StorageError.ClearError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\nregisterEmbedHook(listenStorageMessages);\n"],"names":[],"mappings":";;;AAAA;;;;;;;;;AAUA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,qCAAoB,CAAA;IACpB,uCAAsB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BAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;SAClE;aAAM;YACL,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;SACzB;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QAE1C,OAAO,CAAC,KAAK,CACX,kCAAkC,GAAG,iBAAiB,YAAY,EAAE,CACrE,CAAC;QAEF,MAAM,WAAW,CACf,YAAY,CAAC,WAAW,EACxB,oBAAoB,EACpB,YAAY,CACb,CAAC;KACH;AACH,CAAC;AAED;;;;;;;;;;AAUO,eAAe,YAAY;IAChC,MAAM,SAAS,GAAG,oBAAoB,EAAE,CAAC;IAEzC,IAAI;QACF,IAAI,SAAS,KAAK,IAAI,EAAE;YACtB,MAAM,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;SACxD;aAAM;YACL,OAAO,CAAC,KAAK,EAAE,CAAC;SACjB;KACF;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QAE1C,OAAO,CAAC,KAAK,CAAC,uCAAuC,YAAY,EAAE,CAAC,CAAC;QAErE,MAAM,WAAW,CACf,YAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;KACH;AACH,CAAC;AAED,iBAAiB,CAAC,qBAAqB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm2017.js","sources":["../src/types.ts","../src/storage_impl.ts","../src/api.ts"],"sourcesContent":["/**\n * @license\n * types.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport enum StorageAction {\n Read = 'storageRead',\n Write = 'storageWrite',\n Remove = 'storageRemove',\n Clear = 'storageClear',\n}\n\nexport type ResponsePayload = {\n key: string;\n value?: string | null;\n error?: string;\n};\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Storage kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the StorageKit\n * } catch (err) {\n * if (err.code === StorageError.ParentApp) {\n * // handle parent app error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `StorageError` enum provides a convenient way to handle errors\n * encountered when using the `StorageKit` 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 `StorageError` enum is not intended to be instantiated or extended.\n */\nexport enum StorageError {\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates a timeout occurred when communicating with the parent app.\n */\n ParentTimeoutError = 'parent_timeout_error',\n /**\n * Indicates an error occurred when reading from the storage.\n */\n ReadError = 'read_error',\n /**\n * Indicates an error occurred when writing to the storage.\n */\n WriteError = 'write_error',\n /**\n * Indicates an error occurred when removing from the storage.\n */\n RemoveError = 'remove_error',\n /**\n * Indicates an error occurred when clearing the storage.\n */\n ClearError = 'clear_error',\n}\n\n/**\n * @internal\n */\nexport const StorageErrorMessages = {\n [StorageError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [StorageError.ParentTimeoutError]: (error: string) =>\n `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,\n [StorageError.ReadError]: (error: string) => `Storage read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Storage write error: ${error}`,\n [StorageError.RemoveError]: (error: string) =>\n `Storage remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `Storage clear error: ${error}`,\n};\n","/**\n * @license\n * storage_impl.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n checkAvailability,\n getItem,\n setItem,\n removeItem,\n clear,\n} from '@monterosa/sdk-util';\n\nexport class StorageImpl {\n private memoryStore: { [key: string]: string } = {};\n private accessible: boolean = checkAvailability();\n private _persistent: boolean = true;\n\n set persistent(newValue: boolean) {\n const oldValue = this._persistent;\n\n if (oldValue === newValue) {\n return;\n }\n\n const swapToStorage = newValue === true && this.accessible;\n const swapToMemory = newValue === false && this.accessible;\n\n if (swapToStorage) {\n for (const [key, value] of Object.entries(this.memoryStore)) {\n setItem(key, value);\n }\n }\n\n if (swapToMemory) {\n clear();\n }\n\n this._persistent = newValue;\n }\n\n get persistent(): boolean {\n return this._persistent;\n }\n\n getItem(key: string): string | null {\n if (this.persistent && this.accessible) {\n return getItem(key);\n }\n\n if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {\n return this.memoryStore[key];\n }\n\n return null;\n }\n\n setItem(key: string, value: string): void {\n if (this.persistent && this.accessible) {\n setItem(key, value);\n }\n\n this.memoryStore[key] = value;\n }\n\n removeItem(key: string): void {\n if (this.persistent && this.accessible) {\n removeItem(key);\n }\n\n delete this.memoryStore[key];\n }\n\n clear(): void {\n if (this.persistent && this.accessible) {\n clear();\n }\n\n this.memoryStore = {};\n }\n}\n","/**\n * @license\n * api.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n Unsubscribe,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\n BridgeError,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n StorageAction,\n ResponsePayload,\n StorageError,\n StorageErrorMessages,\n} from './types';\nimport { StorageImpl } from './storage_impl';\n\n/**\n * @internal\n */\nexport const storage = new StorageImpl();\n\n/**\n * @internal\n */\nexport function listenStorageMessages(experience: Experience): Unsubscribe {\n return onSdkMessage(experience, (message) => {\n if (\n !Object.values(StorageAction).includes(message.action as StorageAction)\n ) {\n return;\n }\n\n try {\n let payload: Payload = {};\n\n switch (message.action) {\n case StorageAction.Read:\n payload = {\n key: message.payload.key,\n value: storage.getItem(message.payload.key),\n };\n break;\n case StorageAction.Write:\n payload = {\n key: message.payload.key,\n };\n storage.setItem(message.payload.key, message.payload.value);\n break;\n case StorageAction.Remove:\n payload = {\n key: message.payload.key,\n };\n storage.removeItem(message.payload.key);\n break;\n case StorageAction.Clear:\n storage.clear();\n break;\n }\n\n respondToSdkMessage(experience, message, payload);\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to handle storage message ${message.action} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Read,\n payload?: Payload,\n): Promise<string | null>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction,\n payload?: Payload,\n): Promise<string | null | undefined> {\n try {\n const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(\n StorageError.ParentAppError,\n StorageErrorMessages,\n error,\n );\n }\n\n return value;\n } catch (err) {\n if (\n err instanceof MonterosaError &&\n err.code === BridgeError.RequestTimeoutError\n ) {\n const errorMessage = getErrorMessage(err);\n\n throw createError(\n StorageError.ParentTimeoutError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n throw err;\n }\n}\n\n/**\n * The `setStoragePersistent` function is a simple function that allows to\n * control the persistence of the SDK storage. If the argument `persistent` is\n * set to `true`, then the storage will be persistent across browser sessions\n * and if it is set to `false`, then the storage will save to memory.\n * It is important to note that the use of persistent storage may be subject\n * to laws and regulations, such as those related to data privacy and protection.\n *\n * @remarks\n * - We transition from persistent to memory and memory to persistent in\n * a seamless manner for you\n *\n * - By default we store in memory\n *\n * - The value of storage persistent persists across session (aka put it to true,\n * it will remain so, put it back to false, it will remain so)\n *\n * - You have the responsibility to comply with any laws and regulations, and\n * store only the data if you know it's valid to do so\n *\n * @param persistent - Determines whether or not SDK storage should persist\n * across browser sessions.\n */\nexport function setStoragePersistent(persistent: boolean): void {\n storage.persistent = persistent;\n}\n\n/**\n * The function allows to read data from the SDK storage.\n *\n * @param key - The name of the item to be read from storage.\n *\n * @throws\n * The function throws an error if there is a timeout reading the data\n * from the parent application storage.\n *\n * @returns A promise that resolves to the value\n * of the item in storage or `null` if the item doesn't exist.\n */\nexport async function storageRead(key: string): Promise<string | null> {\n const parentApp = getParentApplication();\n\n let value: string | null = null;\n\n try {\n if (parentApp !== null) {\n value = await parentAppRequest(parentApp, StorageAction.Read, {\n key,\n });\n } else {\n value = storage.getItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to read storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.ReadError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n return value;\n}\n\n/**\n * The function allows to write data to the SDK storage.\n *\n * @param key - A name of the item to be stored.\n * @param value - A value to be stored.\n *\n * @throws\n * The function throws an error if there is a timeout writing the data\n * to the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully stored.\n */\nexport async function storageWrite(key: string, value: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Write, {\n key,\n value,\n });\n } else {\n storage.setItem(key, value);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to write storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.WriteError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to remove an item from the SDK storage.\n *\n * @param key - A name of the item to be removed.\n *\n * @throws\n * The function throws an error if there is a timeout removing the data\n * from the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully removed.\n */\nexport async function storageRemove(key: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Remove, { key });\n } else {\n storage.removeItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to remove storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.RemoveError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to clear all data from the SDK storage.\n *\n * @throws\n * The function throws an error if there is a timeout clearing the parent's\n * application storage.\n *\n * @returns A promise that resolves to `void` once the data has been\n * successfully cleared.\n */\nexport async function storageClear(): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Clear);\n } else {\n storage.clear();\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(`Unable to clear storage with error: ${errorMessage}`);\n\n throw createError(\n StorageError.ClearError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\nregisterEmbedHook(listenStorageMessages);\n"],"names":[],"mappings":";;;AAAA;;;;;;;;AAQG;AAEH,IAAY,aAKX,CAAA;AALD,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,MAAA,CAAA,GAAA,aAAoB,CAAA;AACpB,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACtB,IAAA,aAAA,CAAA,QAAA,CAAA,GAAA,eAAwB,CAAA;AACxB,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACxB,CAAC,EALW,aAAa,KAAb,aAAa,GAKxB,EAAA,CAAA,CAAA,CAAA;AAQD;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;IACS,aAyBX;AAzBD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;A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B,SAAA;AACF,KAAA;AAAC,IAAA,OAAO,GAAG,EAAE;AACZ,QAAA,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;QAE1C,OAAO,CAAC,KAAK,CACX,CAAA,+BAAA,EAAkC,GAAG,CAAiB,cAAA,EAAA,YAAY,CAAE,CAAA,CACrE,CAAC;QAEF,MAAM,WAAW,CACf,YAAY,CAAC,WAAW,EACxB,oBAAoB,EACpB,YAAY,CACb,CAAC;AACH,KAAA;AACH,CAAC;AAED;;;;;;;;;AASG;AACI,eAAe,YAAY,GAAA;AAChC,IAAA,MAAM,SAAS,GAAG,oBAAoB,EAAE,CAAC;IAEzC,IAAI;QACF,IAAI,SAAS,KAAK,IAAI,EAAE;YACtB,MAAM,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;AACxD,SAAA;AAAM,aAAA;YACL,OAAO,CAAC,KAAK,EAAE,CAAC;AACjB,SAAA;AACF,KAAA;AAAC,IAAA,OAAO,GAAG,EAAE;AACZ,QAAA,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;AAE1C,QAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,YAAY,CAAA,CAAE,CAAC,CAAC;QAErE,MAAM,WAAW,CACf,YAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;AACH,KAAA;AACH,CAAC;AAED,iBAAiB,CAAC,qBAAqB,CAAC;;;;"}
|
package/dist/index.esm5.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getItem, setItem, removeItem, clear, checkAvailability, getErrorMessage, MonterosaError, createError } from '@monterosa/sdk-util';
|
|
2
2
|
import { registerEmbedHook, onSdkMessage, respondToSdkMessage, BridgeError, sendSdkRequest, getParentApplication } from '@monterosa/sdk-launcher-kit';
|
|
3
3
|
|
|
4
4
|
/*! *****************************************************************************
|
package/dist/index.esm5.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm5.js","sources":["../src/types.ts","../src/storage_impl.ts","../src/api.ts"],"sourcesContent":["/**\n * @license\n * types.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport enum StorageAction {\n Read = 'storageRead',\n Write = 'storageWrite',\n Remove = 'storageRemove',\n Clear = 'storageClear',\n}\n\nexport type ResponsePayload = {\n key: string;\n value?: string | null;\n error?: string;\n};\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Storage kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the StorageKit\n * } catch (err) {\n * if (err.code === StorageError.ParentApp) {\n * // handle parent app error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `StorageError` enum provides a convenient way to handle errors\n * encountered when using the `StorageKit` 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 `StorageError` enum is not intended to be instantiated or extended.\n */\nexport enum StorageError {\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates a timeout occurred when communicating with the parent app.\n */\n ParentTimeoutError = 'parent_timeout_error',\n /**\n * Indicates an error occurred when reading from the storage.\n */\n ReadError = 'read_error',\n /**\n * Indicates an error occurred when writing to the storage.\n */\n WriteError = 'write_error',\n /**\n * Indicates an error occurred when removing from the storage.\n */\n RemoveError = 'remove_error',\n /**\n * Indicates an error occurred when clearing the storage.\n */\n ClearError = 'clear_error',\n}\n\n/**\n * @internal\n */\nexport const StorageErrorMessages = {\n [StorageError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [StorageError.ParentTimeoutError]: (error: string) =>\n `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,\n [StorageError.ReadError]: (error: string) => `Storage read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Storage write error: ${error}`,\n [StorageError.RemoveError]: (error: string) =>\n `Storage remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `Storage clear error: ${error}`,\n};\n","/**\n * @license\n * storage_impl.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n checkAvailability,\n getItem,\n setItem,\n removeItem,\n clear,\n} from '@monterosa/sdk-util';\n\nexport class StorageImpl {\n private memoryStore: { [key: string]: string } = {};\n private accessible: boolean = checkAvailability();\n private _persistent: boolean = true;\n\n set persistent(newValue: boolean) {\n const oldValue = this._persistent;\n\n if (oldValue === newValue) {\n return;\n }\n\n const swapToStorage = newValue === true && this.accessible;\n const swapToMemory = newValue === false && this.accessible;\n\n if (swapToStorage) {\n for (const [key, value] of Object.entries(this.memoryStore)) {\n setItem(key, value);\n }\n }\n\n if (swapToMemory) {\n clear();\n }\n\n this._persistent = newValue;\n }\n\n get persistent(): boolean {\n return this._persistent;\n }\n\n getItem(key: string): string | null {\n if (this.persistent && this.accessible) {\n return getItem(key);\n }\n\n if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {\n return this.memoryStore[key];\n }\n\n return null;\n }\n\n setItem(key: string, value: string): void {\n if (this.persistent && this.accessible) {\n setItem(key, value);\n }\n\n this.memoryStore[key] = value;\n }\n\n removeItem(key: string): void {\n if (this.persistent && this.accessible) {\n removeItem(key);\n }\n\n delete this.memoryStore[key];\n }\n\n clear(): void {\n if (this.persistent && this.accessible) {\n clear();\n }\n\n this.memoryStore = {};\n }\n}\n","/**\n * @license\n * api.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n Unsubscribe,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\n BridgeError,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n StorageAction,\n ResponsePayload,\n StorageError,\n StorageErrorMessages,\n} from './types';\nimport { StorageImpl } from './storage_impl';\n\n/**\n * @internal\n */\nexport const storage = new StorageImpl();\n\n/**\n * @internal\n */\nexport function listenStorageMessages(experience: Experience): Unsubscribe {\n return onSdkMessage(experience, (message) => {\n if (\n !Object.values(StorageAction).includes(message.action as StorageAction)\n ) {\n return;\n }\n\n try {\n let payload: Payload = {};\n\n switch (message.action) {\n case StorageAction.Read:\n payload = {\n key: message.payload.key,\n value: storage.getItem(message.payload.key),\n };\n break;\n case StorageAction.Write:\n payload = {\n key: message.payload.key,\n };\n storage.setItem(message.payload.key, message.payload.value);\n break;\n case StorageAction.Remove:\n payload = {\n key: message.payload.key,\n };\n storage.removeItem(message.payload.key);\n break;\n case StorageAction.Clear:\n storage.clear();\n break;\n }\n\n respondToSdkMessage(experience, message, payload);\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to handle storage message ${message.action} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Read,\n payload?: Payload,\n): Promise<string | null>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction,\n payload?: Payload,\n): Promise<string | null | undefined> {\n try {\n const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(\n StorageError.ParentAppError,\n StorageErrorMessages,\n error,\n );\n }\n\n return value;\n } catch (err) {\n if (\n err instanceof MonterosaError &&\n err.code === BridgeError.RequestTimeoutError\n ) {\n const errorMessage = getErrorMessage(err);\n\n throw createError(\n StorageError.ParentTimeoutError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n throw err;\n }\n}\n\n/**\n * The `setStoragePersistent` function is a simple function that allows to\n * control the persistence of the SDK storage. If the argument `persistent` is\n * set to `true`, then the storage will be persistent across browser sessions\n * and if it is set to `false`, then the storage will save to memory.\n * It is important to note that the use of persistent storage may be subject\n * to laws and regulations, such as those related to data privacy and protection.\n *\n * @remarks\n * - We transition from persistent to memory and memory to persistent in\n * a seamless manner for you\n *\n * - By default we store in memory\n *\n * - The value of storage persistent persists across session (aka put it to true,\n * it will remain so, put it back to false, it will remain so)\n *\n * - You have the responsibility to comply with any laws and regulations, and\n * store only the data if you know it's valid to do so\n *\n * @param persistent - Determines whether or not SDK storage should persist\n * across browser sessions.\n */\nexport function setStoragePersistent(persistent: boolean): void {\n storage.persistent = persistent;\n}\n\n/**\n * The function allows to read data from the SDK storage.\n *\n * @param key - The name of the item to be read from storage.\n *\n * @throws\n * The function throws an error if there is a timeout reading the data\n * from the parent application storage.\n *\n * @returns A promise that resolves to the value\n * of the item in storage or `null` if the item doesn't exist.\n */\nexport async function storageRead(key: string): Promise<string | null> {\n const parentApp = getParentApplication();\n\n let value: string | null = null;\n\n try {\n if (parentApp !== null) {\n value = await parentAppRequest(parentApp, StorageAction.Read, {\n key,\n });\n } else {\n value = storage.getItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to read storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.ReadError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n return value;\n}\n\n/**\n * The function allows to write data to the SDK storage.\n *\n * @param key - A name of the item to be stored.\n * @param value - A value to be stored.\n *\n * @throws\n * The function throws an error if there is a timeout writing the data\n * to the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully stored.\n */\nexport async function storageWrite(key: string, value: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Write, {\n key,\n value,\n });\n } else {\n storage.setItem(key, value);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to write storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.WriteError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to remove an item from the SDK storage.\n *\n * @param key - A name of the item to be removed.\n *\n * @throws\n * The function throws an error if there is a timeout removing the data\n * from the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully removed.\n */\nexport async function storageRemove(key: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Remove, { key });\n } else {\n storage.removeItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to remove storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.RemoveError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to clear all data from the SDK storage.\n *\n * @throws\n * The function throws an error if there is a timeout clearing the parent's\n * application storage.\n *\n * @returns A promise that resolves to `void` once the data has been\n * successfully cleared.\n */\nexport async function storageClear(): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Clear);\n } else {\n storage.clear();\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(`Unable to clear storage with error: ${errorMessage}`);\n\n throw createError(\n StorageError.ClearError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\nregisterEmbedHook(listenStorageMessages);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;AAUA,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,qCAAoB,CAAA;IACpB,uCA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C,SAAS,GAAG,oBAAoB,EAAE,CAAC;;;;0BAGnC,SAAS,KAAK,IAAI,CAAA,EAAlB,wBAAkB;oBACpB,qBAAM,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,EAAE,EAAE,GAAG,KAAA,EAAE,CAAC,EAAA;;oBAAhE,SAAgE,CAAC;;;oBAEjE,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;;;;;oBAGpB,YAAY,GAAG,eAAe,CAAC,KAAG,CAAC,CAAC;oBAE1C,OAAO,CAAC,KAAK,CACX,qCAAkC,GAAG,uBAAiB,YAAc,CACrE,CAAC;oBAEF,MAAM,WAAW,CACf,YAAY,CAAC,WAAW,EACxB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAED;;;;;;;;;;SAUsB,YAAY;;;;;;oBAC1B,SAAS,GAAG,oBAAoB,EAAE,CAAC;;;;0BAGnC,SAAS,KAAK,IAAI,CAAA,EAAlB,wBAAkB;oBACpB,qBAAM,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,KAAK,CAAC,EAAA;;oBAAtD,SAAsD,CAAC;;;oBAEvD,OAAO,CAAC,KAAK,EAAE,CAAC;;;;;oBAGZ,YAAY,GAAG,eAAe,CAAC,KAAG,CAAC,CAAC;oBAE1C,OAAO,CAAC,KAAK,CAAC,yCAAuC,YAAc,CAAC,CAAC;oBAErE,MAAM,WAAW,CACf,YAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAED,iBAAiB,CAAC,qBAAqB,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.esm5.js","sources":["../src/types.ts","../src/storage_impl.ts","../src/api.ts"],"sourcesContent":["/**\n * @license\n * types.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nexport enum StorageAction {\n Read = 'storageRead',\n Write = 'storageWrite',\n Remove = 'storageRemove',\n Clear = 'storageClear',\n}\n\nexport type ResponsePayload = {\n key: string;\n value?: string | null;\n error?: string;\n};\n\n/**\n * Defines a set of error codes that may be encountered when using the\n * Storage kit of the Monterosa SDK.\n *\n * @example\n * ```javascript\n * try {\n * // some code that uses the StorageKit\n * } catch (err) {\n * if (err.code === StorageError.ParentApp) {\n * // handle parent app error\n * } else {\n * // handle other error types\n * }\n * }\n * ```\n *\n * @remarks\n * - The `StorageError` enum provides a convenient way to handle errors\n * encountered when using the `StorageKit` 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 `StorageError` enum is not intended to be instantiated or extended.\n */\nexport enum StorageError {\n /**\n * Indicates an error occurred in the parent app.\n */\n ParentAppError = 'parent_app_error',\n /**\n * Indicates a timeout occurred when communicating with the parent app.\n */\n ParentTimeoutError = 'parent_timeout_error',\n /**\n * Indicates an error occurred when reading from the storage.\n */\n ReadError = 'read_error',\n /**\n * Indicates an error occurred when writing to the storage.\n */\n WriteError = 'write_error',\n /**\n * Indicates an error occurred when removing from the storage.\n */\n RemoveError = 'remove_error',\n /**\n * Indicates an error occurred when clearing the storage.\n */\n ClearError = 'clear_error',\n}\n\n/**\n * @internal\n */\nexport const StorageErrorMessages = {\n [StorageError.ParentAppError]: (error: string) =>\n `Parent application error: ${error}`,\n [StorageError.ParentTimeoutError]: (error: string) =>\n `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,\n [StorageError.ReadError]: (error: string) => `Storage read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Storage write error: ${error}`,\n [StorageError.RemoveError]: (error: string) =>\n `Storage remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `Storage clear error: ${error}`,\n};\n","/**\n * @license\n * storage_impl.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n checkAvailability,\n getItem,\n setItem,\n removeItem,\n clear,\n} from '@monterosa/sdk-util';\n\nexport class StorageImpl {\n private memoryStore: { [key: string]: string } = {};\n private accessible: boolean = checkAvailability();\n private _persistent: boolean = true;\n\n set persistent(newValue: boolean) {\n const oldValue = this._persistent;\n\n if (oldValue === newValue) {\n return;\n }\n\n const swapToStorage = newValue === true && this.accessible;\n const swapToMemory = newValue === false && this.accessible;\n\n if (swapToStorage) {\n for (const [key, value] of Object.entries(this.memoryStore)) {\n setItem(key, value);\n }\n }\n\n if (swapToMemory) {\n clear();\n }\n\n this._persistent = newValue;\n }\n\n get persistent(): boolean {\n return this._persistent;\n }\n\n getItem(key: string): string | null {\n if (this.persistent && this.accessible) {\n return getItem(key);\n }\n\n if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {\n return this.memoryStore[key];\n }\n\n return null;\n }\n\n setItem(key: string, value: string): void {\n if (this.persistent && this.accessible) {\n setItem(key, value);\n }\n\n this.memoryStore[key] = value;\n }\n\n removeItem(key: string): void {\n if (this.persistent && this.accessible) {\n removeItem(key);\n }\n\n delete this.memoryStore[key];\n }\n\n clear(): void {\n if (this.persistent && this.accessible) {\n clear();\n }\n\n this.memoryStore = {};\n }\n}\n","/**\n * @license\n * api.ts\n * storage-kit\n *\n * Copyright © 2025 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n Unsubscribe,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\n BridgeError,\n} from '@monterosa/sdk-launcher-kit';\n\nimport {\n StorageAction,\n ResponsePayload,\n StorageError,\n StorageErrorMessages,\n} from './types';\nimport { StorageImpl } from './storage_impl';\n\n/**\n * @internal\n */\nexport const storage = new StorageImpl();\n\n/**\n * @internal\n */\nexport function listenStorageMessages(experience: Experience): Unsubscribe {\n return onSdkMessage(experience, (message) => {\n if (\n !Object.values(StorageAction).includes(message.action as StorageAction)\n ) {\n return;\n }\n\n try {\n let payload: Payload = {};\n\n switch (message.action) {\n case StorageAction.Read:\n payload = {\n key: message.payload.key,\n value: storage.getItem(message.payload.key),\n };\n break;\n case StorageAction.Write:\n payload = {\n key: message.payload.key,\n };\n storage.setItem(message.payload.key, message.payload.value);\n break;\n case StorageAction.Remove:\n payload = {\n key: message.payload.key,\n };\n storage.removeItem(message.payload.key);\n break;\n case StorageAction.Clear:\n storage.clear();\n break;\n }\n\n respondToSdkMessage(experience, message, payload);\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to handle storage message ${message.action} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n}\n\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Read,\n payload?: Payload,\n): Promise<string | null>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction,\n payload?: Payload,\n): Promise<string | null | undefined> {\n try {\n const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(\n StorageError.ParentAppError,\n StorageErrorMessages,\n error,\n );\n }\n\n return value;\n } catch (err) {\n if (\n err instanceof MonterosaError &&\n err.code === BridgeError.RequestTimeoutError\n ) {\n const errorMessage = getErrorMessage(err);\n\n throw createError(\n StorageError.ParentTimeoutError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n throw err;\n }\n}\n\n/**\n * The `setStoragePersistent` function is a simple function that allows to\n * control the persistence of the SDK storage. If the argument `persistent` is\n * set to `true`, then the storage will be persistent across browser sessions\n * and if it is set to `false`, then the storage will save to memory.\n * It is important to note that the use of persistent storage may be subject\n * to laws and regulations, such as those related to data privacy and protection.\n *\n * @remarks\n * - We transition from persistent to memory and memory to persistent in\n * a seamless manner for you\n *\n * - By default we store in memory\n *\n * - The value of storage persistent persists across session (aka put it to true,\n * it will remain so, put it back to false, it will remain so)\n *\n * - You have the responsibility to comply with any laws and regulations, and\n * store only the data if you know it's valid to do so\n *\n * @param persistent - Determines whether or not SDK storage should persist\n * across browser sessions.\n */\nexport function setStoragePersistent(persistent: boolean): void {\n storage.persistent = persistent;\n}\n\n/**\n * The function allows to read data from the SDK storage.\n *\n * @param key - The name of the item to be read from storage.\n *\n * @throws\n * The function throws an error if there is a timeout reading the data\n * from the parent application storage.\n *\n * @returns A promise that resolves to the value\n * of the item in storage or `null` if the item doesn't exist.\n */\nexport async function storageRead(key: string): Promise<string | null> {\n const parentApp = getParentApplication();\n\n let value: string | null = null;\n\n try {\n if (parentApp !== null) {\n value = await parentAppRequest(parentApp, StorageAction.Read, {\n key,\n });\n } else {\n value = storage.getItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to read storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.ReadError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n\n return value;\n}\n\n/**\n * The function allows to write data to the SDK storage.\n *\n * @param key - A name of the item to be stored.\n * @param value - A value to be stored.\n *\n * @throws\n * The function throws an error if there is a timeout writing the data\n * to the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully stored.\n */\nexport async function storageWrite(key: string, value: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Write, {\n key,\n value,\n });\n } else {\n storage.setItem(key, value);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to write storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.WriteError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to remove an item from the SDK storage.\n *\n * @param key - A name of the item to be removed.\n *\n * @throws\n * The function throws an error if there is a timeout removing the data\n * from the parent's application storage.\n *\n * @returns A promise that resolves to `void` once the data has\n * been successfully removed.\n */\nexport async function storageRemove(key: string): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Remove, { key });\n } else {\n storage.removeItem(key);\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(\n `Unable to remove storage item \"${key}\" with error: ${errorMessage}`,\n );\n\n throw createError(\n StorageError.RemoveError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\n/**\n * The function allows to clear all data from the SDK storage.\n *\n * @throws\n * The function throws an error if there is a timeout clearing the parent's\n * application storage.\n *\n * @returns A promise that resolves to `void` once the data has been\n * successfully cleared.\n */\nexport async function storageClear(): Promise<void> {\n const parentApp = getParentApplication();\n\n try {\n if (parentApp !== null) {\n await parentAppRequest(parentApp, StorageAction.Clear);\n } else {\n storage.clear();\n }\n } catch (err) {\n const errorMessage = getErrorMessage(err);\n\n console.error(`Unable to clear storage with error: ${errorMessage}`);\n\n throw createError(\n StorageError.ClearError,\n StorageErrorMessages,\n errorMessage,\n );\n }\n}\n\nregisterEmbedHook(listenStorageMessages);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;AAQG;;AAEH,IAAY,aAKX,CAAA;AALD,CAAA,UAAY,aAAa,EAAA;AACvB,IAAA,aAAA,CAAA,MAAA,CAAA,GAAA,aAAoB,CAAA;AACpB,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACtB,IAAA,aAAA,CAAA,QAAA,CAAA,GAAA,eAAwB,CAAA;AACxB,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACxB,CAAC,EALW,aAAa,KAAb,aAAa,GAKx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AY,CAAC,WAAW,EACxB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;AAEL,CAAA;AAED;;;;;;;;;AASG;SACmB,YAAY,GAAA;;;;;;oBAC1B,SAAS,GAAG,oBAAoB,EAAE,CAAC;;;;AAGnC,oBAAA,IAAA,EAAA,SAAS,KAAK,IAAI,CAAA,EAAlB,OAAkB,CAAA,CAAA,YAAA,CAAA,CAAA,CAAA;oBACpB,OAAM,CAAA,CAAA,YAAA,gBAAgB,CAAC,SAAS,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA,CAAA;;AAAtD,oBAAA,EAAA,CAAA,IAAA,EAAsD,CAAC;;;oBAEvD,OAAO,CAAC,KAAK,EAAE,CAAC;;;;;AAGZ,oBAAA,YAAY,GAAG,eAAe,CAAC,KAAG,CAAC,CAAC;AAE1C,oBAAA,OAAO,CAAC,KAAK,CAAC,sCAAuC,GAAA,YAAc,CAAC,CAAC;oBAErE,MAAM,WAAW,CACf,YAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;AAEL,CAAA;AAED,iBAAiB,CAAC,qBAAqB,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monterosa/sdk-storage-kit",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.10",
|
|
4
4
|
"description": "Storage 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",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@monterosa/sdk-util": "0.x"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@monterosa/sdk-core": "^0.18.
|
|
31
|
-
"@monterosa/sdk-launcher-kit": "^0.18.
|
|
32
|
-
"@monterosa/sdk-util": "^0.18.
|
|
30
|
+
"@monterosa/sdk-core": "^0.18.10",
|
|
31
|
+
"@monterosa/sdk-launcher-kit": "^0.18.10",
|
|
32
|
+
"@monterosa/sdk-util": "^0.18.10"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@rollup/plugin-json": "^4.1.0",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "94e238b4c612d70a2ffbc9e1dcec5e55cd029927"
|
|
49
49
|
}
|