@ada-support/web-storage 0.1.0 → 0.3.0

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/README.md CHANGED
@@ -1,2 +1,2 @@
1
1
  # web-storage
2
- A module to provide access to Web Storage API
2
+ A module to provide access to Web Storage API.
package/README_NPM.md ADDED
@@ -0,0 +1 @@
1
+ > _This module is meant to be used internally by Ada projects only._
@@ -0,0 +1,10 @@
1
+ import type { AdaFunctionalStorageValue } from "./functional-storage";
2
+ import type { StorageValueByKey } from "./storage-keys";
3
+ export declare const createStorage: (storageProvider: Storage) => {
4
+ readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
5
+ readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
6
+ /** Stores a key/value pair within `ada-functional-storage` Storage key */
7
+ readonly setFnItem: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
8
+ /** Gets a value under `ada-functional-storage` Storage key */
9
+ readonly getFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
10
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ exports.__esModule = true;
14
+ exports.createStorage = void 0;
15
+ var WEB_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access Web Storage API";
16
+ var createStorage = function (storageProvider) {
17
+ var storage = {
18
+ setItem: function (key, value) {
19
+ try {
20
+ storageProvider.setItem(key, JSON.stringify(value));
21
+ }
22
+ catch (e) {
23
+ console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
24
+ }
25
+ },
26
+ getItem: function (key) {
27
+ try {
28
+ var rawStorageValue = storageProvider.getItem(key);
29
+ return rawStorageValue && JSON.parse(rawStorageValue);
30
+ }
31
+ catch (e) {
32
+ console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
33
+ return null;
34
+ }
35
+ },
36
+ /** Stores a key/value pair within `ada-functional-storage` Storage key */
37
+ setFnItem: function (key, value) {
38
+ var _a;
39
+ var currentValue = storage.getItem("ada-functional-storage") || {};
40
+ var newValue = __assign(__assign({}, currentValue), (_a = {}, _a[key] = value, _a));
41
+ storage.setItem("ada-functional-storage", newValue);
42
+ },
43
+ /** Gets a value under `ada-functional-storage` Storage key */
44
+ getFnItem: function (key) {
45
+ var value = storage.getItem("ada-functional-storage");
46
+ return (value && value[key]) || null;
47
+ }
48
+ };
49
+ return storage;
50
+ };
51
+ exports.createStorage = createStorage;
@@ -5,4 +5,7 @@ export interface AdaFunctionalStorageValue {
5
5
  rolloutLastValue: {
6
6
  [clientHandle: string]: number;
7
7
  };
8
+ marketing_campaigns_shown: {
9
+ [clientHandle: string]: string;
10
+ };
8
11
  }
package/dist/index.d.ts CHANGED
@@ -1,26 +1,14 @@
1
- import type { AdaFunctionalStorageValue } from "./functional-storage";
2
- import type { StorageValueByKey } from "./storage-keys";
3
- export declare const createStorage: (storageProvider: Storage) => {
4
- readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
5
- readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
6
- /** Stores a key/value pair within `ada-functional-storage` Storage key */
7
- readonly setFnItem: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
8
- /** Gets a value under `ada-functional-storage` Storage key */
9
- readonly getFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
10
- };
1
+ import type { StorageKey } from "./storage-keys";
11
2
  export declare const adaLocalStorage: {
12
- readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
13
- readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
14
- /** Stores a key/value pair within `ada-functional-storage` Storage key */
15
- readonly setFnItem: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
16
- /** Gets a value under `ada-functional-storage` Storage key */
17
- readonly getFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
3
+ readonly setItem: <K extends keyof import("./storage-keys").StorageValueByKey>(key: K, value: import("./storage-keys").StorageValueByKey[K]) => void;
4
+ readonly getItem: <K_1 extends keyof import("./storage-keys").StorageValueByKey>(key: K_1) => import("./storage-keys").StorageValueByKey[K_1] | null;
5
+ readonly setFnItem: <K_2 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_2, value: import("./functional-storage").AdaFunctionalStorageValue[K_2]) => void;
6
+ readonly getFnItem: <K_3 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_3) => import("./functional-storage").AdaFunctionalStorageValue[K_3] | null;
18
7
  };
19
8
  export declare const adaSessionStorage: {
20
- readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
21
- readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
22
- /** Stores a key/value pair within `ada-functional-storage` Storage key */
23
- readonly setFnItem: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
24
- /** Gets a value under `ada-functional-storage` Storage key */
25
- readonly getFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
9
+ readonly setItem: <K extends keyof import("./storage-keys").StorageValueByKey>(key: K, value: import("./storage-keys").StorageValueByKey[K]) => void;
10
+ readonly getItem: <K_1 extends keyof import("./storage-keys").StorageValueByKey>(key: K_1) => import("./storage-keys").StorageValueByKey[K_1] | null;
11
+ readonly setFnItem: <K_2 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_2, value: import("./functional-storage").AdaFunctionalStorageValue[K_2]) => void;
12
+ readonly getFnItem: <K_3 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_3) => import("./functional-storage").AdaFunctionalStorageValue[K_3] | null;
26
13
  };
14
+ export declare type AdaStorageKey = StorageKey;
package/dist/index.js CHANGED
@@ -1,53 +1,6 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  exports.__esModule = true;
14
- exports.adaSessionStorage = exports.adaLocalStorage = exports.createStorage = void 0;
15
- var WEB_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access Web Storage API";
16
- var createStorage = function (storageProvider) {
17
- var storage = {
18
- setItem: function (key, value) {
19
- try {
20
- storageProvider.setItem(key, JSON.stringify(value));
21
- }
22
- catch (e) {
23
- console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
24
- }
25
- },
26
- getItem: function (key) {
27
- try {
28
- var rawStorageValue = storageProvider.getItem(key);
29
- return rawStorageValue && JSON.parse(rawStorageValue);
30
- }
31
- catch (e) {
32
- console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
33
- return null;
34
- }
35
- },
36
- /** Stores a key/value pair within `ada-functional-storage` Storage key */
37
- setFnItem: function (key, value) {
38
- var _a;
39
- var currentValue = storage.getItem("ada-functional-storage") || {};
40
- var newValue = __assign(__assign({}, currentValue), (_a = {}, _a[key] = value, _a));
41
- storage.setItem("ada-functional-storage", newValue);
42
- },
43
- /** Gets a value under `ada-functional-storage` Storage key */
44
- getFnItem: function (key) {
45
- var value = storage.getItem("ada-functional-storage");
46
- return (value && value[key]) || null;
47
- }
48
- };
49
- return storage;
50
- };
51
- exports.createStorage = createStorage;
52
- exports.adaLocalStorage = (0, exports.createStorage)(localStorage);
53
- exports.adaSessionStorage = (0, exports.createStorage)(sessionStorage);
3
+ exports.adaSessionStorage = exports.adaLocalStorage = void 0;
4
+ var create_storage_1 = require("./create-storage");
5
+ exports.adaLocalStorage = (0, create_storage_1.createStorage)(localStorage);
6
+ exports.adaSessionStorage = (0, create_storage_1.createStorage)(sessionStorage);
@@ -3,12 +3,20 @@ export interface StorageValueByKey {
3
3
  /** Used to store the chat version assigned to a user (for A/B testing purposes). */
4
4
  "ada-embed_chat-assigned-version": string;
5
5
  /** Used to store information about current versions available (“canary” or “stable”). */
6
- "ada-embed_chat-manifest-cache": object;
6
+ "ada-embed_chat-manifest-cache": string;
7
+ /** Used to determine whether chatter session is expired. */
8
+ "ada-embed_chatter-created": string;
7
9
  /** Used to determine if the drawer was opened previously so when users navigate to other pages we can automatically open chat. */
8
10
  "ada-embed_is-drawer-open": boolean;
9
- /** Use to store general information about Ada application state. */
11
+ /** Used to store general information about Ada application state. */
10
12
  "ada-functional-storage": Partial<AdaFunctionalStorageValue>;
11
13
  /** Used to identify the user within Ada. */
12
14
  "chatter": string;
15
+ /** Indicates whether user is connected to a live agent. */
16
+ "inLiveChat": boolean;
17
+ /** Indicates whether user is waiting to connect to a live agent. */
18
+ "liveChatPending": boolean;
19
+ /** Used for chatter authentication */
20
+ "session_token": string;
13
21
  }
14
22
  export declare type StorageKey = keyof StorageValueByKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/web-storage",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "A package to provide access to Web Storage API",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -0,0 +1,48 @@
1
+ import type { AdaFunctionalStorageValue } from "./functional-storage";
2
+ import type { StorageKey, StorageValueByKey } from "./storage-keys";
3
+
4
+ const WEB_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access Web Storage API";
5
+
6
+ export const createStorage = (storageProvider: Storage) => {
7
+ const storage = {
8
+ setItem: <K extends StorageKey>(key: K, value: StorageValueByKey[K]): void => {
9
+ try {
10
+ storageProvider.setItem(key, JSON.stringify(value));
11
+ } catch (e) {
12
+ console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
13
+ }
14
+ },
15
+
16
+ getItem: <K extends StorageKey>(key: K): StorageValueByKey[K] | null => {
17
+ try {
18
+ const rawStorageValue = storageProvider.getItem(key);
19
+
20
+ return rawStorageValue && JSON.parse(rawStorageValue);
21
+ } catch (e) {
22
+ console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
23
+
24
+ return null;
25
+ }
26
+ },
27
+
28
+ /** Stores a key/value pair within `ada-functional-storage` Storage key */
29
+ setFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K, value: AdaFunctionalStorageValue[K]): void => {
30
+ const currentValue = storage.getItem("ada-functional-storage") || {};
31
+ const newValue = {
32
+ ...currentValue,
33
+ [key]: value,
34
+ };
35
+
36
+ storage.setItem("ada-functional-storage", newValue);
37
+ },
38
+
39
+ /** Gets a value under `ada-functional-storage` Storage key */
40
+ getFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K): AdaFunctionalStorageValue[K] | null => {
41
+ const value = storage.getItem("ada-functional-storage");
42
+
43
+ return (value && value[key]) || null;
44
+ },
45
+ } as const;
46
+
47
+ return storage;
48
+ };
@@ -5,4 +5,7 @@ export interface AdaFunctionalStorageValue {
5
5
  rolloutLastValue: {
6
6
  [clientHandle: string]: number;
7
7
  };
8
+ marketing_campaigns_shown: {
9
+ [clientHandle: string]: string;
10
+ };
8
11
  }
package/src/index.ts CHANGED
@@ -1,51 +1,6 @@
1
- import type { AdaFunctionalStorageValue } from "./functional-storage";
2
- import type { StorageKey, StorageValueByKey } from "./storage-keys";
3
-
4
- const WEB_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access Web Storage API";
5
-
6
- export const createStorage = (storageProvider: Storage) => {
7
- const storage = {
8
- setItem: <K extends StorageKey>(key: K, value: StorageValueByKey[K]): void => {
9
- try {
10
- storageProvider.setItem(key, JSON.stringify(value));
11
- } catch (e) {
12
- console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
13
- }
14
- },
15
-
16
- getItem: <K extends StorageKey>(key: K): StorageValueByKey[K] | null => {
17
- try {
18
- const rawStorageValue = storageProvider.getItem(key);
19
-
20
- return rawStorageValue && JSON.parse(rawStorageValue);
21
- } catch (e) {
22
- console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
23
-
24
- return null;
25
- }
26
- },
27
-
28
- /** Stores a key/value pair within `ada-functional-storage` Storage key */
29
- setFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K, value: AdaFunctionalStorageValue[K]): void => {
30
- const currentValue = storage.getItem("ada-functional-storage") || {};
31
- const newValue = {
32
- ...currentValue,
33
- [key]: value,
34
- };
35
-
36
- storage.setItem("ada-functional-storage", newValue);
37
- },
38
-
39
- /** Gets a value under `ada-functional-storage` Storage key */
40
- getFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K): AdaFunctionalStorageValue[K] | null => {
41
- const value = storage.getItem("ada-functional-storage");
42
-
43
- return (value && value[key]) || null;
44
- },
45
- } as const;
46
-
47
- return storage;
48
- };
1
+ import { createStorage } from "./create-storage";
2
+ import type { StorageKey } from "./storage-keys";
49
3
 
50
4
  export const adaLocalStorage = createStorage(localStorage);
51
5
  export const adaSessionStorage = createStorage(sessionStorage);
6
+ export type AdaStorageKey = StorageKey
@@ -5,16 +5,28 @@ export interface StorageValueByKey {
5
5
  "ada-embed_chat-assigned-version": string;
6
6
 
7
7
  /** Used to store information about current versions available (“canary” or “stable”). */
8
- "ada-embed_chat-manifest-cache": object;
8
+ "ada-embed_chat-manifest-cache": string;
9
+
10
+ /** Used to determine whether chatter session is expired. */
11
+ "ada-embed_chatter-created": string;
9
12
 
10
13
  /** Used to determine if the drawer was opened previously so when users navigate to other pages we can automatically open chat. */
11
14
  "ada-embed_is-drawer-open": boolean;
12
15
 
13
- /** Use to store general information about Ada application state. */
16
+ /** Used to store general information about Ada application state. */
14
17
  "ada-functional-storage": Partial<AdaFunctionalStorageValue>;
15
18
 
16
19
  /** Used to identify the user within Ada. */
17
20
  "chatter": string;
21
+
22
+ /** Indicates whether user is connected to a live agent. */
23
+ "inLiveChat": boolean;
24
+
25
+ /** Indicates whether user is waiting to connect to a live agent. */
26
+ "liveChatPending": boolean;
27
+
28
+ /** Used for chatter authentication */
29
+ "session_token": string;
18
30
  }
19
31
 
20
32
  export type StorageKey = keyof StorageValueByKey;