@monterosa/sdk-storage-kit 0.18.7 → 0.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -106,6 +106,10 @@ exports.StorageError = void 0;
106
106
  * Indicates an error occurred in the parent app.
107
107
  */
108
108
  StorageError["ParentAppError"] = "parent_app_error";
109
+ /**
110
+ * Indicates a timeout occurred when communicating with the parent app.
111
+ */
112
+ StorageError["ParentTimeoutError"] = "parent_timeout_error";
109
113
  /**
110
114
  * Indicates an error occurred when reading from the storage.
111
115
  */
@@ -130,10 +134,15 @@ var StorageErrorMessages = (_a = {},
130
134
  _a[exports.StorageError.ParentAppError] = function (error) {
131
135
  return "Parent application error: " + error;
132
136
  },
133
- _a[exports.StorageError.ReadError] = function (error) { return "Read error: " + error; },
134
- _a[exports.StorageError.WriteError] = function (error) { return "Write error: " + error; },
135
- _a[exports.StorageError.RemoveError] = function (error) { return "Remove error: " + error; },
136
- _a[exports.StorageError.ClearError] = function (error) { return "Clear error: " + error; },
137
+ _a[exports.StorageError.ParentTimeoutError] = function (error) {
138
+ return "Parent application timeout: " + error + ". Please check if the storage-kit is imported on the parent page.";
139
+ },
140
+ _a[exports.StorageError.ReadError] = function (error) { return "Storage read error: " + error; },
141
+ _a[exports.StorageError.WriteError] = function (error) { return "Storage write error: " + error; },
142
+ _a[exports.StorageError.RemoveError] = function (error) {
143
+ return "Storage remove error: " + error;
144
+ },
145
+ _a[exports.StorageError.ClearError] = function (error) { return "Storage clear error: " + error; },
137
146
  _a);
138
147
 
139
148
  /**
@@ -266,10 +275,12 @@ function listenStorageMessages(experience) {
266
275
  }
267
276
  function parentAppRequest(parentApp, action, payload) {
268
277
  return __awaiter(this, void 0, void 0, function () {
269
- var response, _a, value, error;
278
+ var response, _a, value, error, err_1, errorMessage;
270
279
  return __generator(this, function (_b) {
271
280
  switch (_b.label) {
272
- case 0: return [4 /*yield*/, sdkLauncherKit.sendSdkRequest(parentApp, action, payload)];
281
+ case 0:
282
+ _b.trys.push([0, 2, , 3]);
283
+ return [4 /*yield*/, sdkLauncherKit.sendSdkRequest(parentApp, action, payload)];
273
284
  case 1:
274
285
  response = _b.sent();
275
286
  _a = response.payload, value = _a.value, error = _a.error;
@@ -277,6 +288,15 @@ function parentAppRequest(parentApp, action, payload) {
277
288
  throw sdkUtil.createError(exports.StorageError.ParentAppError, StorageErrorMessages, error);
278
289
  }
279
290
  return [2 /*return*/, value];
291
+ case 2:
292
+ err_1 = _b.sent();
293
+ if (err_1 instanceof sdkUtil.MonterosaError &&
294
+ err_1.code === sdkLauncherKit.BridgeError.RequestTimeoutError) {
295
+ errorMessage = sdkUtil.getErrorMessage(err_1);
296
+ throw sdkUtil.createError(exports.StorageError.ParentTimeoutError, StorageErrorMessages, errorMessage);
297
+ }
298
+ throw err_1;
299
+ case 3: return [2 /*return*/];
280
300
  }
281
301
  });
282
302
  });
@@ -321,7 +341,7 @@ function setStoragePersistent(persistent) {
321
341
  */
322
342
  function storageRead(key) {
323
343
  return __awaiter(this, void 0, void 0, function () {
324
- var parentApp, value, err_1, errorMessage;
344
+ var parentApp, value, err_2, errorMessage;
325
345
  return __generator(this, function (_a) {
326
346
  switch (_a.label) {
327
347
  case 0:
@@ -342,9 +362,9 @@ function storageRead(key) {
342
362
  _a.label = 4;
343
363
  case 4: return [3 /*break*/, 6];
344
364
  case 5:
345
- err_1 = _a.sent();
346
- errorMessage = sdkUtil.getErrorMessage(err_1);
347
- console.error("Unable to read storage item " + key + " with error: " + errorMessage);
365
+ err_2 = _a.sent();
366
+ errorMessage = sdkUtil.getErrorMessage(err_2);
367
+ console.error("Unable to read storage item \"" + key + "\" with error: " + errorMessage);
348
368
  throw sdkUtil.createError(exports.StorageError.ReadError, StorageErrorMessages, errorMessage);
349
369
  case 6: return [2 /*return*/, value];
350
370
  }
@@ -366,7 +386,7 @@ function storageRead(key) {
366
386
  */
367
387
  function storageWrite(key, value) {
368
388
  return __awaiter(this, void 0, void 0, function () {
369
- var parentApp, err_2, errorMessage;
389
+ var parentApp, err_3, errorMessage;
370
390
  return __generator(this, function (_a) {
371
391
  switch (_a.label) {
372
392
  case 0:
@@ -387,9 +407,9 @@ function storageWrite(key, value) {
387
407
  _a.label = 4;
388
408
  case 4: return [3 /*break*/, 6];
389
409
  case 5:
390
- err_2 = _a.sent();
391
- errorMessage = sdkUtil.getErrorMessage(err_2);
392
- console.error("Unable to write storage item " + key + " with error: " + errorMessage);
410
+ err_3 = _a.sent();
411
+ errorMessage = sdkUtil.getErrorMessage(err_3);
412
+ console.error("Unable to write storage item \"" + key + "\" with error: " + errorMessage);
393
413
  throw sdkUtil.createError(exports.StorageError.WriteError, StorageErrorMessages, errorMessage);
394
414
  case 6: return [2 /*return*/];
395
415
  }
@@ -410,7 +430,7 @@ function storageWrite(key, value) {
410
430
  */
411
431
  function storageRemove(key) {
412
432
  return __awaiter(this, void 0, void 0, function () {
413
- var parentApp, err_3, errorMessage;
433
+ var parentApp, err_4, errorMessage;
414
434
  return __generator(this, function (_a) {
415
435
  switch (_a.label) {
416
436
  case 0:
@@ -428,9 +448,9 @@ function storageRemove(key) {
428
448
  _a.label = 4;
429
449
  case 4: return [3 /*break*/, 6];
430
450
  case 5:
431
- err_3 = _a.sent();
432
- errorMessage = sdkUtil.getErrorMessage(err_3);
433
- console.error("Unable to remove storage item " + key + " with error: " + errorMessage);
451
+ err_4 = _a.sent();
452
+ errorMessage = sdkUtil.getErrorMessage(err_4);
453
+ console.error("Unable to remove storage item \"" + key + "\" with error: " + errorMessage);
434
454
  throw sdkUtil.createError(exports.StorageError.RemoveError, StorageErrorMessages, errorMessage);
435
455
  case 6: return [2 /*return*/];
436
456
  }
@@ -449,7 +469,7 @@ function storageRemove(key) {
449
469
  */
450
470
  function storageClear() {
451
471
  return __awaiter(this, void 0, void 0, function () {
452
- var parentApp, err_4, errorMessage;
472
+ var parentApp, err_5, errorMessage;
453
473
  return __generator(this, function (_a) {
454
474
  switch (_a.label) {
455
475
  case 0:
@@ -467,8 +487,8 @@ function storageClear() {
467
487
  _a.label = 4;
468
488
  case 4: return [3 /*break*/, 6];
469
489
  case 5:
470
- err_4 = _a.sent();
471
- errorMessage = sdkUtil.getErrorMessage(err_4);
490
+ err_5 = _a.sent();
491
+ errorMessage = sdkUtil.getErrorMessage(err_5);
472
492
  console.error("Unable to clear storage with error: " + errorMessage);
473
493
  throw sdkUtil.createError(exports.StorageError.ClearError, StorageErrorMessages, errorMessage);
474
494
  case 6: return [2 /*return*/];
@@ -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 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.ReadError]: (error: string) => `Read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Write error: ${error}`,\n [StorageError.RemoveError]: (error: string) => `Remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `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 { Unsubscribe, createError, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\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 const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(StorageError.ParentAppError, StorageErrorMessages, error);\n }\n\n return value;\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","getParentApplication","registerEmbedHook"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;AAUA,IAAY,a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AY,GAAGH,uBAAe,CAAC,KAAG,CAAC,CAAC;oBAE1C,OAAO,CAAC,KAAK,CACX,mCAAiC,GAAG,qBAAgB,YAAc,CACnE,CAAC;oBAEF,MAAME,mBAAW,CACfV,oBAAY,CAAC,WAAW,EACxB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAED;;;;;;;;;;SAUsB,YAAY;;;;;;oBAC1B,SAAS,GAAGW,mCAAoB,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,GAAGH,uBAAe,CAAC,KAAG,CAAC,CAAC;oBAE1C,OAAO,CAAC,KAAK,CAAC,yCAAuC,YAAc,CAAC,CAAC;oBAErE,MAAME,mBAAW,CACfV,oBAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAEDY,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;;;;;;;;;;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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O,CAAC,KAAK,CACX,qCAAkC,GAAG,uBAAiB,YAAc,CACrE,CAAC;oBAEF,MAAME,mBAAW,CACfV,oBAAY,CAAC,WAAW,EACxB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAED;;;;;;;;;;SAUsB,YAAY;;;;;;oBAC1B,SAAS,GAAGa,mCAAoB,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,GAAGL,uBAAe,CAAC,KAAG,CAAC,CAAC;oBAE1C,OAAO,CAAC,KAAK,CAAC,yCAAuC,YAAc,CAAC,CAAC;oBAErE,MAAME,mBAAW,CACfV,oBAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;;;;;CAEL;AAEDc,gCAAiB,CAAC,qBAAqB,CAAC;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
- import { checkAvailability, setItem, clear, getItem, removeItem, getErrorMessage, createError } from '@monterosa/sdk-util';
2
- import { registerEmbedHook, onSdkMessage, respondToSdkMessage, sendSdkRequest, getParentApplication } from '@monterosa/sdk-launcher-kit';
1
+ import { checkAvailability, setItem, clear, getItem, removeItem, getErrorMessage, createError, MonterosaError } from '@monterosa/sdk-util';
2
+ import { registerEmbedHook, onSdkMessage, respondToSdkMessage, sendSdkRequest, BridgeError, getParentApplication } from '@monterosa/sdk-launcher-kit';
3
3
 
4
4
  /**
5
5
  * @license
@@ -48,6 +48,10 @@ var StorageError;
48
48
  * Indicates an error occurred in the parent app.
49
49
  */
50
50
  StorageError["ParentAppError"] = "parent_app_error";
51
+ /**
52
+ * Indicates a timeout occurred when communicating with the parent app.
53
+ */
54
+ StorageError["ParentTimeoutError"] = "parent_timeout_error";
51
55
  /**
52
56
  * Indicates an error occurred when reading from the storage.
53
57
  */
@@ -70,10 +74,11 @@ var StorageError;
70
74
  */
71
75
  const StorageErrorMessages = {
72
76
  [StorageError.ParentAppError]: (error) => `Parent application error: ${error}`,
73
- [StorageError.ReadError]: (error) => `Read error: ${error}`,
74
- [StorageError.WriteError]: (error) => `Write error: ${error}`,
75
- [StorageError.RemoveError]: (error) => `Remove error: ${error}`,
76
- [StorageError.ClearError]: (error) => `Clear error: ${error}`,
77
+ [StorageError.ParentTimeoutError]: (error) => `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,
78
+ [StorageError.ReadError]: (error) => `Storage read error: ${error}`,
79
+ [StorageError.WriteError]: (error) => `Storage write error: ${error}`,
80
+ [StorageError.RemoveError]: (error) => `Storage remove error: ${error}`,
81
+ [StorageError.ClearError]: (error) => `Storage clear error: ${error}`,
77
82
  };
78
83
 
79
84
  /**
@@ -199,12 +204,22 @@ function listenStorageMessages(experience) {
199
204
  });
200
205
  }
201
206
  async function parentAppRequest(parentApp, action, payload) {
202
- const response = await sendSdkRequest(parentApp, action, payload);
203
- const { value, error } = response.payload;
204
- if (error !== undefined) {
205
- throw createError(StorageError.ParentAppError, StorageErrorMessages, error);
207
+ try {
208
+ const response = await sendSdkRequest(parentApp, action, payload);
209
+ const { value, error } = response.payload;
210
+ if (error !== undefined) {
211
+ throw createError(StorageError.ParentAppError, StorageErrorMessages, error);
212
+ }
213
+ return value;
214
+ }
215
+ catch (err) {
216
+ if (err instanceof MonterosaError &&
217
+ err.code === BridgeError.RequestTimeoutError) {
218
+ const errorMessage = getErrorMessage(err);
219
+ throw createError(StorageError.ParentTimeoutError, StorageErrorMessages, errorMessage);
220
+ }
221
+ throw err;
206
222
  }
207
- return value;
208
223
  }
209
224
  /**
210
225
  * The `setStoragePersistent` function is a simple function that allows to
@@ -259,7 +274,7 @@ async function storageRead(key) {
259
274
  }
260
275
  catch (err) {
261
276
  const errorMessage = getErrorMessage(err);
262
- console.error(`Unable to read storage item ${key} with error: ${errorMessage}`);
277
+ console.error(`Unable to read storage item "${key}" with error: ${errorMessage}`);
263
278
  throw createError(StorageError.ReadError, StorageErrorMessages, errorMessage);
264
279
  }
265
280
  return value;
@@ -292,7 +307,7 @@ async function storageWrite(key, value) {
292
307
  }
293
308
  catch (err) {
294
309
  const errorMessage = getErrorMessage(err);
295
- console.error(`Unable to write storage item ${key} with error: ${errorMessage}`);
310
+ console.error(`Unable to write storage item "${key}" with error: ${errorMessage}`);
296
311
  throw createError(StorageError.WriteError, StorageErrorMessages, errorMessage);
297
312
  }
298
313
  }
@@ -320,7 +335,7 @@ async function storageRemove(key) {
320
335
  }
321
336
  catch (err) {
322
337
  const errorMessage = getErrorMessage(err);
323
- console.error(`Unable to remove storage item ${key} with error: ${errorMessage}`);
338
+ console.error(`Unable to remove storage item "${key}" with error: ${errorMessage}`);
324
339
  throw createError(StorageError.RemoveError, StorageErrorMessages, errorMessage);
325
340
  }
326
341
  }
@@ -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 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.ReadError]: (error: string) => `Read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Write error: ${error}`,\n [StorageError.RemoveError]: (error: string) => `Remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `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 { Unsubscribe, createError, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\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 const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(StorageError.ParentAppError, StorageErrorMessages, error);\n }\n\n return value;\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,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CACX,iCAAiC,GAAG,gBAAgB,YAAY,EAAE,CACnE,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;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;IAyBY;AAAZ,WAAY,YAAY;;;;IAItB,mDAAmC,CAAA;;;;IAInC,2DAA2C,CAAA;;;;IAI3C,wCAAwB,CAAA;;;;IAIxB,0CAA0B,CAAA;;;;IAI1B,4CAA4B,CAAA;;;;IAI5B,0CAA0B,CAAA;AAC5B,CAAC,EAzBW,YAAY,KAAZ,YAAY,QAyBvB;AAED;;;AAGO,MAAM,oBAAoB,GAAG;IAClC,CAAC,YAAY,CAAC,cAAc,GAAG,CAAC,KAAa,KAC3C,6BAA6B,KAAK,EAAE;IACtC,CAAC,YAAY,CAAC,kBAAkB,GAAG,CAAC,KAAa,KAC/C,+BAA+B,KAAK,mEAAmE;IACzG,CAAC,YAAY,CAAC,SAAS,GAAG,CAAC,KAAa,KAAK,uBAAuB,KAAK,EAAE;IAC3E,CAAC,YAAY,CA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AAC;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,5 +1,5 @@
1
- import { setItem, clear, getItem, removeItem, checkAvailability, getErrorMessage, createError } from '@monterosa/sdk-util';
2
- import { registerEmbedHook, onSdkMessage, respondToSdkMessage, sendSdkRequest, getParentApplication } from '@monterosa/sdk-launcher-kit';
1
+ import { setItem, clear, getItem, removeItem, checkAvailability, getErrorMessage, MonterosaError, createError } from '@monterosa/sdk-util';
2
+ import { registerEmbedHook, onSdkMessage, respondToSdkMessage, BridgeError, sendSdkRequest, getParentApplication } from '@monterosa/sdk-launcher-kit';
3
3
 
4
4
  /*! *****************************************************************************
5
5
  Copyright (c) Microsoft Corporation.
@@ -102,6 +102,10 @@ var StorageError;
102
102
  * Indicates an error occurred in the parent app.
103
103
  */
104
104
  StorageError["ParentAppError"] = "parent_app_error";
105
+ /**
106
+ * Indicates a timeout occurred when communicating with the parent app.
107
+ */
108
+ StorageError["ParentTimeoutError"] = "parent_timeout_error";
105
109
  /**
106
110
  * Indicates an error occurred when reading from the storage.
107
111
  */
@@ -126,10 +130,15 @@ var StorageErrorMessages = (_a = {},
126
130
  _a[StorageError.ParentAppError] = function (error) {
127
131
  return "Parent application error: " + error;
128
132
  },
129
- _a[StorageError.ReadError] = function (error) { return "Read error: " + error; },
130
- _a[StorageError.WriteError] = function (error) { return "Write error: " + error; },
131
- _a[StorageError.RemoveError] = function (error) { return "Remove error: " + error; },
132
- _a[StorageError.ClearError] = function (error) { return "Clear error: " + error; },
133
+ _a[StorageError.ParentTimeoutError] = function (error) {
134
+ return "Parent application timeout: " + error + ". Please check if the storage-kit is imported on the parent page.";
135
+ },
136
+ _a[StorageError.ReadError] = function (error) { return "Storage read error: " + error; },
137
+ _a[StorageError.WriteError] = function (error) { return "Storage write error: " + error; },
138
+ _a[StorageError.RemoveError] = function (error) {
139
+ return "Storage remove error: " + error;
140
+ },
141
+ _a[StorageError.ClearError] = function (error) { return "Storage clear error: " + error; },
133
142
  _a);
134
143
 
135
144
  /**
@@ -262,10 +271,12 @@ function listenStorageMessages(experience) {
262
271
  }
263
272
  function parentAppRequest(parentApp, action, payload) {
264
273
  return __awaiter(this, void 0, void 0, function () {
265
- var response, _a, value, error;
274
+ var response, _a, value, error, err_1, errorMessage;
266
275
  return __generator(this, function (_b) {
267
276
  switch (_b.label) {
268
- case 0: return [4 /*yield*/, sendSdkRequest(parentApp, action, payload)];
277
+ case 0:
278
+ _b.trys.push([0, 2, , 3]);
279
+ return [4 /*yield*/, sendSdkRequest(parentApp, action, payload)];
269
280
  case 1:
270
281
  response = _b.sent();
271
282
  _a = response.payload, value = _a.value, error = _a.error;
@@ -273,6 +284,15 @@ function parentAppRequest(parentApp, action, payload) {
273
284
  throw createError(StorageError.ParentAppError, StorageErrorMessages, error);
274
285
  }
275
286
  return [2 /*return*/, value];
287
+ case 2:
288
+ err_1 = _b.sent();
289
+ if (err_1 instanceof MonterosaError &&
290
+ err_1.code === BridgeError.RequestTimeoutError) {
291
+ errorMessage = getErrorMessage(err_1);
292
+ throw createError(StorageError.ParentTimeoutError, StorageErrorMessages, errorMessage);
293
+ }
294
+ throw err_1;
295
+ case 3: return [2 /*return*/];
276
296
  }
277
297
  });
278
298
  });
@@ -317,7 +337,7 @@ function setStoragePersistent(persistent) {
317
337
  */
318
338
  function storageRead(key) {
319
339
  return __awaiter(this, void 0, void 0, function () {
320
- var parentApp, value, err_1, errorMessage;
340
+ var parentApp, value, err_2, errorMessage;
321
341
  return __generator(this, function (_a) {
322
342
  switch (_a.label) {
323
343
  case 0:
@@ -338,9 +358,9 @@ function storageRead(key) {
338
358
  _a.label = 4;
339
359
  case 4: return [3 /*break*/, 6];
340
360
  case 5:
341
- err_1 = _a.sent();
342
- errorMessage = getErrorMessage(err_1);
343
- console.error("Unable to read storage item " + key + " with error: " + errorMessage);
361
+ err_2 = _a.sent();
362
+ errorMessage = getErrorMessage(err_2);
363
+ console.error("Unable to read storage item \"" + key + "\" with error: " + errorMessage);
344
364
  throw createError(StorageError.ReadError, StorageErrorMessages, errorMessage);
345
365
  case 6: return [2 /*return*/, value];
346
366
  }
@@ -362,7 +382,7 @@ function storageRead(key) {
362
382
  */
363
383
  function storageWrite(key, value) {
364
384
  return __awaiter(this, void 0, void 0, function () {
365
- var parentApp, err_2, errorMessage;
385
+ var parentApp, err_3, errorMessage;
366
386
  return __generator(this, function (_a) {
367
387
  switch (_a.label) {
368
388
  case 0:
@@ -383,9 +403,9 @@ function storageWrite(key, value) {
383
403
  _a.label = 4;
384
404
  case 4: return [3 /*break*/, 6];
385
405
  case 5:
386
- err_2 = _a.sent();
387
- errorMessage = getErrorMessage(err_2);
388
- console.error("Unable to write storage item " + key + " with error: " + errorMessage);
406
+ err_3 = _a.sent();
407
+ errorMessage = getErrorMessage(err_3);
408
+ console.error("Unable to write storage item \"" + key + "\" with error: " + errorMessage);
389
409
  throw createError(StorageError.WriteError, StorageErrorMessages, errorMessage);
390
410
  case 6: return [2 /*return*/];
391
411
  }
@@ -406,7 +426,7 @@ function storageWrite(key, value) {
406
426
  */
407
427
  function storageRemove(key) {
408
428
  return __awaiter(this, void 0, void 0, function () {
409
- var parentApp, err_3, errorMessage;
429
+ var parentApp, err_4, errorMessage;
410
430
  return __generator(this, function (_a) {
411
431
  switch (_a.label) {
412
432
  case 0:
@@ -424,9 +444,9 @@ function storageRemove(key) {
424
444
  _a.label = 4;
425
445
  case 4: return [3 /*break*/, 6];
426
446
  case 5:
427
- err_3 = _a.sent();
428
- errorMessage = getErrorMessage(err_3);
429
- console.error("Unable to remove storage item " + key + " with error: " + errorMessage);
447
+ err_4 = _a.sent();
448
+ errorMessage = getErrorMessage(err_4);
449
+ console.error("Unable to remove storage item \"" + key + "\" with error: " + errorMessage);
430
450
  throw createError(StorageError.RemoveError, StorageErrorMessages, errorMessage);
431
451
  case 6: return [2 /*return*/];
432
452
  }
@@ -445,7 +465,7 @@ function storageRemove(key) {
445
465
  */
446
466
  function storageClear() {
447
467
  return __awaiter(this, void 0, void 0, function () {
448
- var parentApp, err_4, errorMessage;
468
+ var parentApp, err_5, errorMessage;
449
469
  return __generator(this, function (_a) {
450
470
  switch (_a.label) {
451
471
  case 0:
@@ -463,8 +483,8 @@ function storageClear() {
463
483
  _a.label = 4;
464
484
  case 4: return [3 /*break*/, 6];
465
485
  case 5:
466
- err_4 = _a.sent();
467
- errorMessage = getErrorMessage(err_4);
486
+ err_5 = _a.sent();
487
+ errorMessage = getErrorMessage(err_5);
468
488
  console.error("Unable to clear storage with error: " + errorMessage);
469
489
  throw createError(StorageError.ClearError, StorageErrorMessages, errorMessage);
470
490
  case 6: return [2 /*return*/];
@@ -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 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.ReadError]: (error: string) => `Read error: ${error}`,\n [StorageError.WriteError]: (error: string) => `Write error: ${error}`,\n [StorageError.RemoveError]: (error: string) => `Remove error: ${error}`,\n [StorageError.ClearError]: (error: string) => `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 { Unsubscribe, createError, getErrorMessage } from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n registerEmbedHook,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onSdkMessage,\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 const response = await sendSdkRequest(parentApp, action, payload);\n\n const { value, error } = response.payload as ResponsePayload;\n\n if (error !== undefined) {\n throw createError(StorageError.ParentAppError, StorageErrorMessages, error);\n }\n\n return value;\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,CAAA;IACtB,yCAAwB,CAAA;IACxB,uCAAsB,CAAA;AACxB,CAAC,EALW,aAAa,KAAb,aAAa,QAKxB;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;IAyBY;AAAZ,WAAY,YAAY;;;;IAItB,mDAAmC,CAAA;;;;IAInC,wCAAwB,CAAA;;;;IAIxB,0CAA0B,CAAA;;;;IAI1B,4CAA4B,CAAA;;;;IAI5B,0CAA0B,CAAA;AAC5B,CAAC,EArBW,YAAY,KAAZ,YAAY,QAqBvB;AAED;;;AAGO,IAAM,oBAAoB;IAC/B,GAAC,YAAY,CAAC,cAAc,IAAG,UAAC,KAAa;QAC3C,OAAA,+BAA6B,KAAO;KAAA;IACtC,GAAC,YAAY,CAAC,SAAS,IAAG,UAAC,KAAa,IAAK,OAAA,iBAAe,KAAO,GAAA;IACnE,GAAC,YAAY,CAAC,UAAU,IAAG,UAAC,KAAa,IAAK,OAAA,kBAAgB,KAAO,GAAA;IACrE,GAAC,YAAY,CAAC,WAAW,IAAG,UAAC,KAAa,IAAK,OAAA,mBAAiB,KAAO,GAAA;IACvE,GAAC,YAAY,CAAC,UAAU,IAAG,UAAC,KAAa,IAAK,OAAA,kBAAgB,KAAO,GAAA;OACtE;;ACjFD;;;;;;;;;AAkBA;IAAA;QACU,gBAAW,GAA8B,EAAE,CAAC;QAC5C,eAAU,GAAY,iBAAiB,EAAE,CAAC;QAC1C,gBAAW,GAAY,IAAI,CAAC;KAgErC;IA9DC,sBAAI,mCAAU;aAuBd;YACE,OAAO,IAAI,CAAC,WAAW,CAAC;SACzB;aAzBD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Aa,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,mCAAiC,GAAG,qBAAgB,YAAc,CACnE,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;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;IAyBY;AAAZ,WAAY,YAAY;;;;IAItB,mDAAmC,CAAA;;;;IAInC,2DAA2C,CAAA;;;;IAI3C,wCAAwB,CAAA;;;;IAIxB,0CAA0B,CAAA;;;;IAI1B,4CAA4B,CAAA;;;;IAI5B,0CAA0B,CAAA;AAC5B,CAAC,EAzBW,YAAY,KAAZ,YAAY,QAyBvB;AAED;;;AAGO,IAAM,oBAAoB;IAC/B,GAA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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;;;;"}
package/dist/types.d.ts CHANGED
@@ -48,6 +48,10 @@ export declare enum StorageError {
48
48
  * Indicates an error occurred in the parent app.
49
49
  */
50
50
  ParentAppError = "parent_app_error",
51
+ /**
52
+ * Indicates a timeout occurred when communicating with the parent app.
53
+ */
54
+ ParentTimeoutError = "parent_timeout_error",
51
55
  /**
52
56
  * Indicates an error occurred when reading from the storage.
53
57
  */
@@ -70,6 +74,7 @@ export declare enum StorageError {
70
74
  */
71
75
  export declare const StorageErrorMessages: {
72
76
  parent_app_error: (error: string) => string;
77
+ parent_timeout_error: (error: string) => string;
73
78
  read_error: (error: string) => string;
74
79
  write_error: (error: string) => string;
75
80
  remove_error: (error: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monterosa/sdk-storage-kit",
3
- "version": "0.18.7",
3
+ "version": "0.18.8",
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.7",
31
- "@monterosa/sdk-launcher-kit": "^0.18.7",
32
- "@monterosa/sdk-util": "^0.18.7"
30
+ "@monterosa/sdk-core": "^0.18.8",
31
+ "@monterosa/sdk-launcher-kit": "^0.18.8",
32
+ "@monterosa/sdk-util": "^0.18.8"
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": "cee6a1ddf6db6c544cf5b7cb7b349d9be45b3893"
48
+ "gitHead": "66794ba6e6dccd31382eb63cdd3b3d9307a53974"
49
49
  }