@monterosa/sdk-storage-kit 2.0.0-rc.1 → 2.0.0-rc.3

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/api.d.ts CHANGED
@@ -26,6 +26,9 @@ export declare function handleExperienceUnmounted(experience: Experience): void;
26
26
  * @internal
27
27
  */
28
28
  export declare function parentAppRequest(parentApp: ParentApplication, action: StorageAction.Read, payload?: Payload): Promise<string | null>;
29
+ /**
30
+ * @internal
31
+ */
29
32
  export declare function parentAppRequest(parentApp: ParentApplication, action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear, payload?: Payload): Promise<undefined>;
30
33
  /**
31
34
  * The `setStoragePersistent` function is a simple function that allows to
package/dist/index.cjs ADDED
@@ -0,0 +1,426 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var sdkUtil = require('@monterosa/sdk-util');
6
+ var sdkLauncherKit = require('@monterosa/sdk-launcher-kit');
7
+
8
+ /**
9
+ * @license
10
+ * types.ts
11
+ * storage-kit
12
+ *
13
+ * Copyright © 2025 Monterosa Productions Limited. All rights reserved.
14
+ *
15
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
16
+ */
17
+ /**
18
+ * Storage bridge action types used internally to communicate with the parent application.
19
+ */
20
+ var StorageAction;
21
+ (function (StorageAction) {
22
+ /**
23
+ * Read a value from storage.
24
+ */
25
+ StorageAction["Read"] = "storageRead";
26
+ /**
27
+ * Write a value to storage.
28
+ */
29
+ StorageAction["Write"] = "storageWrite";
30
+ /**
31
+ * Remove a value from storage.
32
+ */
33
+ StorageAction["Remove"] = "storageRemove";
34
+ /**
35
+ * Clear all values from storage.
36
+ */
37
+ StorageAction["Clear"] = "storageClear";
38
+ })(StorageAction || (StorageAction = {}));
39
+ /**
40
+ * Defines a set of error codes that may be encountered when using the
41
+ * Storage kit of the Monterosa SDK.
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * try {
46
+ * // some code that uses the StorageKit
47
+ * } catch (err) {
48
+ * if (err.code === StorageError.ParentAppError) {
49
+ * // handle parent app error
50
+ * } else {
51
+ * // handle other error types
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * @remarks
57
+ * - The `StorageError` enum provides a convenient way to handle errors
58
+ * encountered when using the `StorageKit` module. By checking the code
59
+ * property of the caught error against the values of the enum, the error
60
+ * type can be determined and appropriate action taken.
61
+ *
62
+ * - The `StorageError` enum is not intended to be instantiated or extended.
63
+ */
64
+ exports.StorageError = void 0;
65
+ (function (StorageError) {
66
+ /**
67
+ * Indicates an error occurred in the parent app.
68
+ */
69
+ StorageError["ParentAppError"] = "parent_app_error";
70
+ /**
71
+ * Indicates a timeout occurred when communicating with the parent app.
72
+ */
73
+ StorageError["ParentTimeoutError"] = "parent_timeout_error";
74
+ /**
75
+ * Indicates an error occurred when reading from the storage.
76
+ */
77
+ StorageError["ReadError"] = "read_error";
78
+ /**
79
+ * Indicates an error occurred when writing to the storage.
80
+ */
81
+ StorageError["WriteError"] = "write_error";
82
+ /**
83
+ * Indicates an error occurred when removing from the storage.
84
+ */
85
+ StorageError["RemoveError"] = "remove_error";
86
+ /**
87
+ * Indicates an error occurred when clearing the storage.
88
+ */
89
+ StorageError["ClearError"] = "clear_error";
90
+ })(exports.StorageError || (exports.StorageError = {}));
91
+ /**
92
+ * @internal
93
+ */
94
+ const StorageErrorMessages = {
95
+ [exports.StorageError.ParentAppError]: (error) => `Parent application error: ${error}`,
96
+ [exports.StorageError.ParentTimeoutError]: (error) => `Parent application timeout: ${error}. Please check if the storage-kit is imported on the parent page.`,
97
+ [exports.StorageError.ReadError]: (error) => `Storage read error: ${error}`,
98
+ [exports.StorageError.WriteError]: (error) => `Storage write error: ${error}`,
99
+ [exports.StorageError.RemoveError]: (error) => `Storage remove error: ${error}`,
100
+ [exports.StorageError.ClearError]: (error) => `Storage clear error: ${error}`,
101
+ };
102
+
103
+ /**
104
+ * @license
105
+ * storage_impl.ts
106
+ * storage-kit
107
+ *
108
+ * Copyright © 2025 Monterosa Productions Limited. All rights reserved.
109
+ *
110
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
111
+ */
112
+ class StorageImpl {
113
+ constructor() {
114
+ this.memoryStore = {};
115
+ this.accessible = sdkUtil.checkAvailability();
116
+ this._persistent = true;
117
+ }
118
+ set persistent(newValue) {
119
+ const oldValue = this._persistent;
120
+ if (oldValue === newValue) {
121
+ return;
122
+ }
123
+ const swapToStorage = newValue === true && this.accessible;
124
+ const swapToMemory = newValue === false && this.accessible;
125
+ if (swapToStorage) {
126
+ for (const [key, value] of Object.entries(this.memoryStore)) {
127
+ sdkUtil.setItem(key, value);
128
+ }
129
+ }
130
+ if (swapToMemory) {
131
+ sdkUtil.clear();
132
+ }
133
+ this._persistent = newValue;
134
+ }
135
+ get persistent() {
136
+ return this._persistent;
137
+ }
138
+ getItem(key) {
139
+ if (this.persistent && this.accessible) {
140
+ return sdkUtil.getItem(key);
141
+ }
142
+ if (Object.prototype.hasOwnProperty.call(this.memoryStore, key)) {
143
+ return this.memoryStore[key];
144
+ }
145
+ return null;
146
+ }
147
+ setItem(key, value) {
148
+ if (this.persistent && this.accessible) {
149
+ sdkUtil.setItem(key, value);
150
+ }
151
+ this.memoryStore[key] = value;
152
+ }
153
+ removeItem(key) {
154
+ if (this.persistent && this.accessible) {
155
+ sdkUtil.removeItem(key);
156
+ }
157
+ delete this.memoryStore[key];
158
+ }
159
+ clear() {
160
+ if (this.persistent && this.accessible) {
161
+ sdkUtil.clear();
162
+ }
163
+ this.memoryStore = {};
164
+ }
165
+ }
166
+
167
+ /**
168
+ * @license
169
+ * api.ts
170
+ * storage-kit
171
+ *
172
+ * Copyright © 2025-2026 Monterosa Productions Limited. All rights reserved.
173
+ *
174
+ * More details on the license can be found at https://www.monterosa.co/sdk/license
175
+ */
176
+ /**
177
+ * @internal
178
+ */
179
+ const storage = new StorageImpl();
180
+ /**
181
+ * @internal
182
+ */
183
+ const unsubs = new Map();
184
+ /**
185
+ * @internal
186
+ */
187
+ function handleExperienceEmbedded(experience) {
188
+ const unsub = sdkLauncherKit.onSdkMessage(experience, (message) => {
189
+ var _a;
190
+ if (!Object.values(StorageAction).includes(message.action)) {
191
+ return;
192
+ }
193
+ try {
194
+ let payload = {};
195
+ switch (message.action) {
196
+ case StorageAction.Read:
197
+ payload = {
198
+ key: message.payload.key,
199
+ value: storage.getItem(message.payload.key),
200
+ };
201
+ break;
202
+ case StorageAction.Write:
203
+ payload = {
204
+ key: message.payload.key,
205
+ };
206
+ storage.setItem(message.payload.key, message.payload.value);
207
+ break;
208
+ case StorageAction.Remove:
209
+ payload = {
210
+ key: message.payload.key,
211
+ };
212
+ storage.removeItem(message.payload.key);
213
+ break;
214
+ case StorageAction.Clear:
215
+ storage.clear();
216
+ break;
217
+ }
218
+ sdkLauncherKit.respondToSdkMessage(experience, message, payload);
219
+ }
220
+ catch (err) {
221
+ const errorMessage = sdkUtil.getErrorMessage(err);
222
+ const key = (_a = message.payload) === null || _a === void 0 ? void 0 : _a.key;
223
+ const keyInfo = key ? ` for key "${key}"` : '';
224
+ console.error(`Unable to handle storage action ${message.action}${keyInfo} with error: ${errorMessage}`);
225
+ sdkLauncherKit.respondToSdkMessage(experience, message, {
226
+ key: message.payload.key,
227
+ error: errorMessage,
228
+ });
229
+ }
230
+ });
231
+ unsubs.set(experience.id, unsub);
232
+ }
233
+ /**
234
+ * @internal
235
+ */
236
+ function handleExperienceUnmounted(experience) {
237
+ const unsub = unsubs.get(experience.id);
238
+ if (unsub) {
239
+ unsub();
240
+ unsubs.delete(experience.id);
241
+ }
242
+ }
243
+ /**
244
+ * @internal
245
+ */
246
+ async function parentAppRequest(parentApp, action, payload) {
247
+ try {
248
+ const response = await sdkLauncherKit.sendSdkRequest(parentApp, action, payload);
249
+ const { value, error } = response.payload;
250
+ if (error !== undefined) {
251
+ throw sdkUtil.createError(exports.StorageError.ParentAppError, StorageErrorMessages, error);
252
+ }
253
+ return value;
254
+ }
255
+ catch (err) {
256
+ if (err instanceof sdkUtil.MonterosaError &&
257
+ err.code === sdkLauncherKit.BridgeError.RequestTimeoutError) {
258
+ const errorMessage = sdkUtil.getErrorMessage(err);
259
+ throw sdkUtil.createError(exports.StorageError.ParentTimeoutError, StorageErrorMessages, errorMessage);
260
+ }
261
+ throw err;
262
+ }
263
+ }
264
+ /**
265
+ * The `setStoragePersistent` function is a simple function that allows to
266
+ * control the persistence of the SDK storage. If the argument `persistent` is
267
+ * set to `true`, then the storage will be persistent across browser sessions
268
+ * and if it is set to `false`, then the storage will save to memory.
269
+ * It is important to note that the use of persistent storage may be subject
270
+ * to laws and regulations, such as those related to data privacy and protection.
271
+ *
272
+ * @remarks
273
+ * - We transition from persistent to memory and memory to persistent in
274
+ * a seamless manner for you
275
+ *
276
+ * - By default we store in memory
277
+ *
278
+ * - The value of storage persistent persists across session (aka put it to true,
279
+ * it will remain so, put it back to false, it will remain so)
280
+ *
281
+ * - You have the responsibility to comply with any laws and regulations, and
282
+ * store only the data if you know it's valid to do so
283
+ *
284
+ * @param persistent - Determines whether or not SDK storage should persist
285
+ * across browser sessions.
286
+ */
287
+ function setStoragePersistent(persistent) {
288
+ storage.persistent = persistent;
289
+ }
290
+ /**
291
+ * The function allows to read data from the SDK storage.
292
+ *
293
+ * @param key - The name of the item to be read from storage.
294
+ *
295
+ * @throws
296
+ * The function throws an error if there is a timeout reading the data
297
+ * from the parent application storage.
298
+ *
299
+ * @returns A promise that resolves to the value
300
+ * of the item in storage or `null` if the item doesn't exist.
301
+ */
302
+ async function storageRead(key) {
303
+ const parentApp = sdkLauncherKit.getParentApplication();
304
+ let value = null;
305
+ try {
306
+ if (parentApp !== null) {
307
+ value = await parentAppRequest(parentApp, StorageAction.Read, {
308
+ key,
309
+ });
310
+ }
311
+ else {
312
+ value = storage.getItem(key);
313
+ }
314
+ }
315
+ catch (err) {
316
+ const errorMessage = sdkUtil.getErrorMessage(err);
317
+ console.error(`Unable to read storage item "${key}" with error: ${errorMessage}`);
318
+ throw sdkUtil.createError(exports.StorageError.ReadError, StorageErrorMessages, errorMessage);
319
+ }
320
+ return value;
321
+ }
322
+ /**
323
+ * The function allows to write data to the SDK storage.
324
+ *
325
+ * @param key - A name of the item to be stored.
326
+ * @param value - A value to be stored.
327
+ *
328
+ * @throws
329
+ * The function throws an error if there is a timeout writing the data
330
+ * to the parent's application storage.
331
+ *
332
+ * @returns A promise that resolves to `void` once the data has
333
+ * been successfully stored.
334
+ */
335
+ async function storageWrite(key, value) {
336
+ const parentApp = sdkLauncherKit.getParentApplication();
337
+ try {
338
+ if (parentApp !== null) {
339
+ await parentAppRequest(parentApp, StorageAction.Write, {
340
+ key,
341
+ value,
342
+ });
343
+ }
344
+ else {
345
+ storage.setItem(key, value);
346
+ }
347
+ }
348
+ catch (err) {
349
+ const errorMessage = sdkUtil.getErrorMessage(err);
350
+ console.error(`Unable to write storage item "${key}" with error: ${errorMessage}`);
351
+ throw sdkUtil.createError(exports.StorageError.WriteError, StorageErrorMessages, errorMessage);
352
+ }
353
+ }
354
+ /**
355
+ * The function allows to remove an item from the SDK storage.
356
+ *
357
+ * @param key - A name of the item to be removed.
358
+ *
359
+ * @throws
360
+ * The function throws an error if there is a timeout removing the data
361
+ * from the parent's application storage.
362
+ *
363
+ * @returns A promise that resolves to `void` once the data has
364
+ * been successfully removed.
365
+ */
366
+ async function storageRemove(key) {
367
+ const parentApp = sdkLauncherKit.getParentApplication();
368
+ try {
369
+ if (parentApp !== null) {
370
+ await parentAppRequest(parentApp, StorageAction.Remove, { key });
371
+ }
372
+ else {
373
+ storage.removeItem(key);
374
+ }
375
+ }
376
+ catch (err) {
377
+ const errorMessage = sdkUtil.getErrorMessage(err);
378
+ console.error(`Unable to remove storage item "${key}" with error: ${errorMessage}`);
379
+ throw sdkUtil.createError(exports.StorageError.RemoveError, StorageErrorMessages, errorMessage);
380
+ }
381
+ }
382
+ /**
383
+ * The function allows to clear all data from the SDK storage.
384
+ *
385
+ * @throws
386
+ * The function throws an error if there is a timeout clearing the parent's
387
+ * application storage.
388
+ *
389
+ * @returns A promise that resolves to `void` once the data has been
390
+ * successfully cleared.
391
+ */
392
+ async function storageClear() {
393
+ const parentApp = sdkLauncherKit.getParentApplication();
394
+ try {
395
+ if (parentApp !== null) {
396
+ await parentAppRequest(parentApp, StorageAction.Clear);
397
+ }
398
+ else {
399
+ storage.clear();
400
+ }
401
+ }
402
+ catch (err) {
403
+ const errorMessage = sdkUtil.getErrorMessage(err);
404
+ console.error(`Unable to clear storage with error: ${errorMessage}`);
405
+ throw sdkUtil.createError(exports.StorageError.ClearError, StorageErrorMessages, errorMessage);
406
+ }
407
+ }
408
+ sdkLauncherKit.onStateChanged((experience, state) => {
409
+ if (state === 'mounted') {
410
+ handleExperienceEmbedded(experience);
411
+ }
412
+ else if (state === 'unmounted') {
413
+ handleExperienceUnmounted(experience);
414
+ }
415
+ });
416
+
417
+ exports.handleExperienceEmbedded = handleExperienceEmbedded;
418
+ exports.handleExperienceUnmounted = handleExperienceUnmounted;
419
+ exports.parentAppRequest = parentAppRequest;
420
+ exports.setStoragePersistent = setStoragePersistent;
421
+ exports.storage = storage;
422
+ exports.storageClear = storageClear;
423
+ exports.storageRead = storageRead;
424
+ exports.storageRemove = storageRemove;
425
+ exports.storageWrite = storageWrite;
426
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","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\n/**\n * Storage bridge action types used internally to communicate with the parent application.\n */\nexport enum StorageAction {\n /**\n * Read a value from storage.\n */\n Read = 'storageRead',\n /**\n * Write a value to storage.\n */\n Write = 'storageWrite',\n /**\n * Remove a value from storage.\n */\n Remove = 'storageRemove',\n /**\n * Clear all values from storage.\n */\n Clear = 'storageClear',\n}\n\n/**\n * Response payload returned from a storage bridge request.\n */\nexport type ResponsePayload = {\n /**\n * The storage key that was operated on.\n */\n key: string;\n /**\n * The value read from storage, or `null` if not found. Only present for read\n * operations.\n */\n value?: string | null;\n /**\n * Error message, if the operation failed.\n */\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.ParentAppError) {\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-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onStateChanged,\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 */\nconst unsubs: Map<string, () => void> = new Map();\n\n/**\n * @internal\n */\nexport function handleExperienceEmbedded(experience: Experience) {\n const unsub = 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 const key = message.payload?.key;\n const keyInfo = key ? ` for key \"${key}\"` : '';\n\n console.error(\n `Unable to handle storage action ${message.action}${keyInfo} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n\n unsubs.set(experience.id, unsub);\n}\n\n/**\n * @internal\n */\nexport function handleExperienceUnmounted(experience: Experience) {\n const unsub = unsubs.get(experience.id);\n\n if (unsub) {\n unsub();\n unsubs.delete(experience.id);\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\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\n/**\n * @internal\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\nonStateChanged((experience, state) => {\n if (state === 'mounted') {\n handleExperienceEmbedded(experience);\n } else if (state === 'unmounted') {\n handleExperienceUnmounted(experience);\n }\n});\n"],"names":["StorageError","checkAvailability","setItem","clear","getItem","removeItem","onSdkMessage","respondToSdkMessage","getErrorMessage","sendSdkRequest","createError","MonterosaError","BridgeError","getParentApplication","onStateChanged"],"mappings":";;;;;;;AAAA;;;;;;;;AAQG;AAEH;;AAEG;AACH,IAAY,aAiBX,CAAA;AAjBD,CAAA,UAAY,aAAa,EAAA;AACvB;;AAEG;AACH,IAAA,aAAA,CAAA,MAAA,CAAA,GAAA,aAAoB,CAAA;AACpB;;AAEG;AACH,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACtB;;AAEG;AACH,IAAA,aAAA,CAAA,QAAA,CAAA,GAAA,eAAwB,CAAA;AACxB;;AAEG;AACH,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACxB,CAAC,EAjBW,aAAa,KAAb,aAAa,GAiBxB,EAAA,CAAA,CAAA,CAAA;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;AACSA,8BAyBX;AAzBD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AACH,IAAA,YAAA,CAAA,gBAAA,CAAA,GAAA,kBAAmC,CAAA;AACnC;;AAEG;AACH,IAAA,YAAA,CAAA,oBAAA,CAAA,GAAA,sBAA2C,CAAA;AAC3C;;AAEG;AACH,IAAA,YAAA,CAAA,WAAA,CAAA,GAAA,YAAwB,CAAA;AACxB;;AAEG;AACH,IAAA,YAAA,CAAA,YAAA,CAAA,GAAA,aAA0B,CAAA;AAC1B;;AAEG;AACH,IAAA,YAAA,CAAA,aAAA,CAAA,GAAA,cAA4B,CAAA;AAC5B;;AAEG;AACH,IAAA,YAAA,CAAA,YAAA,CAAA,GAAA,aAA0B,CAAA;AAC5B,CAAC,EAzBWA,oBAAY,KAAZA,oBAAY,GAyBvB,EAAA,CAAA,CAAA,CAAA;AAED;;AAEG;AACI,MAAM,oBAAoB,GAAG;AAClC,IAAA,CAACA,oBAAY,CAAC,cAAc,GAAG,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,KAAA;SAAM,IAAI,KAAK,KAAK,WAAW,EAAE;QAChC,yBAAyB,CAAC,UAAU,CAAC,CAAC;AACvC,KAAA;AACH,CAAC,CAAC;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Persists key-value data across sessions via the parent application.
3
+ *
4
+ * @packageDocumentation
5
+ */
1
6
  /**
2
7
  * @license
3
8
  * index.ts
@@ -7,10 +12,5 @@
7
12
  *
8
13
  * More details on the license can be found at https://www.monterosa.co/sdk/license
9
14
  */
10
- /**
11
- * Monterosa SDK / Storage Kit
12
- *
13
- * @packageDocumentation
14
- */
15
15
  export * from './api';
16
16
  export { StorageError } from './types';
@@ -10,11 +10,26 @@ import { onStateChanged, onSdkMessage, respondToSdkMessage, sendSdkRequest, Brid
10
10
  *
11
11
  * More details on the license can be found at https://www.monterosa.co/sdk/license
12
12
  */
13
+ /**
14
+ * Storage bridge action types used internally to communicate with the parent application.
15
+ */
13
16
  var StorageAction;
14
17
  (function (StorageAction) {
18
+ /**
19
+ * Read a value from storage.
20
+ */
15
21
  StorageAction["Read"] = "storageRead";
22
+ /**
23
+ * Write a value to storage.
24
+ */
16
25
  StorageAction["Write"] = "storageWrite";
26
+ /**
27
+ * Remove a value from storage.
28
+ */
17
29
  StorageAction["Remove"] = "storageRemove";
30
+ /**
31
+ * Clear all values from storage.
32
+ */
18
33
  StorageAction["Clear"] = "storageClear";
19
34
  })(StorageAction || (StorageAction = {}));
20
35
  /**
@@ -26,7 +41,7 @@ var StorageAction;
26
41
  * try {
27
42
  * // some code that uses the StorageKit
28
43
  * } catch (err) {
29
- * if (err.code === StorageError.ParentApp) {
44
+ * if (err.code === StorageError.ParentAppError) {
30
45
  * // handle parent app error
31
46
  * } else {
32
47
  * // handle other error types
@@ -221,6 +236,9 @@ function handleExperienceUnmounted(experience) {
221
236
  unsubs.delete(experience.id);
222
237
  }
223
238
  }
239
+ /**
240
+ * @internal
241
+ */
224
242
  async function parentAppRequest(parentApp, action, payload) {
225
243
  try {
226
244
  const response = await sendSdkRequest(parentApp, action, payload);
@@ -393,4 +411,4 @@ onStateChanged((experience, state) => {
393
411
  });
394
412
 
395
413
  export { StorageError, handleExperienceEmbedded, handleExperienceUnmounted, parentAppRequest, setStoragePersistent, storage, storageClear, storageRead, storageRemove, storageWrite };
396
- //# sourceMappingURL=index.esm.js.map
414
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.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\n/**\n * Storage bridge action types used internally to communicate with the parent application.\n */\nexport enum StorageAction {\n /**\n * Read a value from storage.\n */\n Read = 'storageRead',\n /**\n * Write a value to storage.\n */\n Write = 'storageWrite',\n /**\n * Remove a value from storage.\n */\n Remove = 'storageRemove',\n /**\n * Clear all values from storage.\n */\n Clear = 'storageClear',\n}\n\n/**\n * Response payload returned from a storage bridge request.\n */\nexport type ResponsePayload = {\n /**\n * The storage key that was operated on.\n */\n key: string;\n /**\n * The value read from storage, or `null` if not found. Only present for read\n * operations.\n */\n value?: string | null;\n /**\n * Error message, if the operation failed.\n */\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.ParentAppError) {\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-2026 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport {\n MonterosaError,\n createError,\n getErrorMessage,\n} from '@monterosa/sdk-util';\nimport {\n Experience,\n Payload,\n ParentApplication,\n getParentApplication,\n sendSdkRequest,\n respondToSdkMessage,\n onStateChanged,\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 */\nconst unsubs: Map<string, () => void> = new Map();\n\n/**\n * @internal\n */\nexport function handleExperienceEmbedded(experience: Experience) {\n const unsub = 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 const key = message.payload?.key;\n const keyInfo = key ? ` for key \"${key}\"` : '';\n\n console.error(\n `Unable to handle storage action ${message.action}${keyInfo} with error: ${errorMessage}`,\n );\n\n respondToSdkMessage(experience, message, {\n key: message.payload.key,\n error: errorMessage,\n });\n }\n });\n\n unsubs.set(experience.id, unsub);\n}\n\n/**\n * @internal\n */\nexport function handleExperienceUnmounted(experience: Experience) {\n const unsub = unsubs.get(experience.id);\n\n if (unsub) {\n unsub();\n unsubs.delete(experience.id);\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\n/**\n * @internal\n */\nexport async function parentAppRequest(\n parentApp: ParentApplication,\n action: StorageAction.Write | StorageAction.Remove | StorageAction.Clear,\n payload?: Payload,\n): Promise<undefined>;\n\n/**\n * @internal\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\nonStateChanged((experience, state) => {\n if (state === 'mounted') {\n handleExperienceEmbedded(experience);\n } else if (state === 'unmounted') {\n handleExperienceUnmounted(experience);\n }\n});\n"],"names":[],"mappings":";;;AAAA;;;;;;;;AAQG;AAEH;;AAEG;AACH,IAAY,aAiBX,CAAA;AAjBD,CAAA,UAAY,aAAa,EAAA;AACvB;;AAEG;AACH,IAAA,aAAA,CAAA,MAAA,CAAA,GAAA,aAAoB,CAAA;AACpB;;AAEG;AACH,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACtB;;AAEG;AACH,IAAA,aAAA,CAAA,QAAA,CAAA,GAAA,eAAwB,CAAA;AACxB;;AAEG;AACH,IAAA,aAAA,CAAA,OAAA,CAAA,GAAA,cAAsB,CAAA;AACxB,CAAC,EAjBW,aAAa,KAAb,aAAa,GAiBxB,EAAA,CAAA,CAAA,CAAA;AAqBD;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;IACS,aAyBX;AAzBD,CAAA,UAAY,YAAY,EAAA;AACtB;;AAEG;AAC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;AACxD,SAAA;AAAM,aAAA;YACL,OAAO,CAAC,KAAK,EAAE,CAAC;AACjB,SAAA;AACF,KAAA;AAAC,IAAA,OAAO,GAAG,EAAE;AACZ,QAAA,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;AAE1C,QAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,YAAY,CAAA,CAAE,CAAC,CAAC;QAErE,MAAM,WAAW,CACf,YAAY,CAAC,UAAU,EACvB,oBAAoB,EACpB,YAAY,CACb,CAAC;AACH,KAAA;AACH,CAAC;AAED,cAAc,CAAC,CAAC,UAAU,EAAE,KAAK,KAAI;IACnC,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,wBAAwB,CAAC,UAAU,CAAC,CAAC;AACtC,KAAA;SAAM,IAAI,KAAK,KAAK,WAAW,EAAE;QAChC,yBAAyB,CAAC,UAAU,CAAC,CAAC;AACvC,KAAA;AACH,CAAC,CAAC;;;;"}
package/dist/types.d.ts CHANGED
@@ -7,15 +7,43 @@
7
7
  *
8
8
  * More details on the license can be found at https://www.monterosa.co/sdk/license
9
9
  */
10
+ /**
11
+ * Storage bridge action types used internally to communicate with the parent application.
12
+ */
10
13
  export declare enum StorageAction {
14
+ /**
15
+ * Read a value from storage.
16
+ */
11
17
  Read = "storageRead",
18
+ /**
19
+ * Write a value to storage.
20
+ */
12
21
  Write = "storageWrite",
22
+ /**
23
+ * Remove a value from storage.
24
+ */
13
25
  Remove = "storageRemove",
26
+ /**
27
+ * Clear all values from storage.
28
+ */
14
29
  Clear = "storageClear"
15
30
  }
31
+ /**
32
+ * Response payload returned from a storage bridge request.
33
+ */
16
34
  export type ResponsePayload = {
35
+ /**
36
+ * The storage key that was operated on.
37
+ */
17
38
  key: string;
39
+ /**
40
+ * The value read from storage, or `null` if not found. Only present for read
41
+ * operations.
42
+ */
18
43
  value?: string | null;
44
+ /**
45
+ * Error message, if the operation failed.
46
+ */
19
47
  error?: string;
20
48
  };
21
49
  /**
@@ -27,7 +55,7 @@ export type ResponsePayload = {
27
55
  * try {
28
56
  * // some code that uses the StorageKit
29
57
  * } catch (err) {
30
- * if (err.code === StorageError.ParentApp) {
58
+ * if (err.code === StorageError.ParentAppError) {
31
59
  * // handle parent app error
32
60
  * } else {
33
61
  * // handle other error types