@ada-support/web-storage 0.3.1 → 0.4.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 +1 -1
- package/dist/create-storage.d.ts +3 -2
- package/dist/create-storage.js +8 -0
- package/dist/index.d.ts +12 -9
- package/dist/storage-keys.d.ts +9 -1
- package/package.json +1 -1
- package/src/create-storage.ts +9 -0
- package/src/index.ts +3 -2
- package/src/storage-keys.ts +13 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
_This module is meant to be used internally by Ada projects only._
|
package/dist/create-storage.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import type { StorageValueByKey } from "./storage-keys";
|
|
|
3
3
|
export declare const createStorage: (storageProvider: Storage) => {
|
|
4
4
|
readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
|
|
5
5
|
readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
|
|
6
|
+
readonly removeItem: <K_2 extends keyof StorageValueByKey>(key: K_2) => void;
|
|
6
7
|
/** Stores a key/value pair within `ada-functional-storage` Storage key */
|
|
7
|
-
readonly setFnItem: <
|
|
8
|
+
readonly setFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3, value: AdaFunctionalStorageValue[K_3]) => void;
|
|
8
9
|
/** Gets a value under `ada-functional-storage` Storage key */
|
|
9
|
-
readonly getFnItem: <
|
|
10
|
+
readonly getFnItem: <K_4 extends keyof AdaFunctionalStorageValue>(key: K_4) => AdaFunctionalStorageValue[K_4] | null;
|
|
10
11
|
};
|
package/dist/create-storage.js
CHANGED
|
@@ -33,6 +33,14 @@ var createStorage = function (storageProvider) {
|
|
|
33
33
|
return null;
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
+
removeItem: function (key) {
|
|
37
|
+
try {
|
|
38
|
+
storageProvider.removeItem(key);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
36
44
|
/** Stores a key/value pair within `ada-functional-storage` Storage key */
|
|
37
45
|
setFnItem: function (key, value) {
|
|
38
46
|
var _a;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import type { StorageKey } from "./storage-keys";
|
|
1
|
+
import type { StorageKey, StorageValueByKey } from "./storage-keys";
|
|
2
2
|
export declare const adaLocalStorage: {
|
|
3
|
-
readonly setItem: <K extends keyof
|
|
4
|
-
readonly getItem: <K_1 extends keyof
|
|
5
|
-
readonly
|
|
6
|
-
readonly
|
|
3
|
+
readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
|
|
4
|
+
readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
|
|
5
|
+
readonly removeItem: <K_2 extends keyof StorageValueByKey>(key: K_2) => void;
|
|
6
|
+
readonly setFnItem: <K_3 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_3, value: import("./functional-storage").AdaFunctionalStorageValue[K_3]) => void;
|
|
7
|
+
readonly getFnItem: <K_4 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_4) => import("./functional-storage").AdaFunctionalStorageValue[K_4] | null;
|
|
7
8
|
};
|
|
8
9
|
export declare const adaSessionStorage: {
|
|
9
|
-
readonly setItem: <K extends keyof
|
|
10
|
-
readonly getItem: <K_1 extends keyof
|
|
11
|
-
readonly
|
|
12
|
-
readonly
|
|
10
|
+
readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
|
|
11
|
+
readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
|
|
12
|
+
readonly removeItem: <K_2 extends keyof StorageValueByKey>(key: K_2) => void;
|
|
13
|
+
readonly setFnItem: <K_3 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_3, value: import("./functional-storage").AdaFunctionalStorageValue[K_3]) => void;
|
|
14
|
+
readonly getFnItem: <K_4 extends keyof import("./functional-storage").AdaFunctionalStorageValue>(key: K_4) => import("./functional-storage").AdaFunctionalStorageValue[K_4] | null;
|
|
13
15
|
};
|
|
14
16
|
export declare type AdaStorageKey = StorageKey;
|
|
17
|
+
export declare type AdaStorageValueByKey = StorageValueByKey;
|
package/dist/storage-keys.d.ts
CHANGED
|
@@ -8,6 +8,14 @@ export interface StorageValueByKey {
|
|
|
8
8
|
"ada-embed_chatter-created": string;
|
|
9
9
|
/** Used to determine if the drawer was opened previously so when users navigate to other pages we can automatically open chat. */
|
|
10
10
|
"ada-embed_is-drawer-open": boolean;
|
|
11
|
+
/** Use to cache Zendesk tags assigned to a conversation. */
|
|
12
|
+
"ada-embed_zd-previous-tags": string;
|
|
13
|
+
/** Stores Zendesk session id. */
|
|
14
|
+
"ada-embed_zd-session-id": string;
|
|
15
|
+
/** Used to determine whether Zendesk session is expired. */
|
|
16
|
+
"ada-embed_zd-messaging-chatter-created": string;
|
|
17
|
+
/** Stores Zendesk internal user id. */
|
|
18
|
+
"ada-embed_zd-messaging-external-user-id": string;
|
|
11
19
|
/** Used to store general information about Ada application state. */
|
|
12
20
|
"ada-functional-storage": Partial<AdaFunctionalStorageValue>;
|
|
13
21
|
/** Used to identify the user within Ada. */
|
|
@@ -16,7 +24,7 @@ export interface StorageValueByKey {
|
|
|
16
24
|
"inLiveChat": boolean;
|
|
17
25
|
/** Indicates whether user is waiting to connect to a live agent. */
|
|
18
26
|
"liveChatPending": boolean;
|
|
19
|
-
/** Used for chatter authentication */
|
|
27
|
+
/** Used for chatter authentication. */
|
|
20
28
|
"session_token": string;
|
|
21
29
|
}
|
|
22
30
|
export declare type StorageKey = keyof StorageValueByKey;
|
package/package.json
CHANGED
package/src/create-storage.ts
CHANGED
|
@@ -5,6 +5,7 @@ const WEB_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access Web Storage API";
|
|
|
5
5
|
|
|
6
6
|
export const createStorage = (storageProvider: Storage) => {
|
|
7
7
|
const storage = {
|
|
8
|
+
|
|
8
9
|
setItem: <K extends StorageKey>(key: K, value: StorageValueByKey[K]): void => {
|
|
9
10
|
try {
|
|
10
11
|
storageProvider.setItem(key, JSON.stringify(value));
|
|
@@ -25,6 +26,14 @@ export const createStorage = (storageProvider: Storage) => {
|
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
|
|
29
|
+
removeItem: <K extends StorageKey>(key: K): void => {
|
|
30
|
+
try {
|
|
31
|
+
storageProvider.removeItem(key);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.warn(WEB_STORAGE_ACCESS_ERROR_MESSAGE);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
|
|
28
37
|
/** Stores a key/value pair within `ada-functional-storage` Storage key */
|
|
29
38
|
setFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K, value: AdaFunctionalStorageValue[K]): void => {
|
|
30
39
|
const currentValue = storage.getItem("ada-functional-storage") || {};
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createStorage } from "./create-storage";
|
|
2
|
-
import type { StorageKey } from "./storage-keys";
|
|
2
|
+
import type { StorageKey, StorageValueByKey } from "./storage-keys";
|
|
3
3
|
|
|
4
4
|
export const adaLocalStorage = createStorage(localStorage);
|
|
5
5
|
export const adaSessionStorage = createStorage(sessionStorage);
|
|
6
|
-
export type AdaStorageKey = StorageKey
|
|
6
|
+
export type AdaStorageKey = StorageKey;
|
|
7
|
+
export type AdaStorageValueByKey = StorageValueByKey;
|
package/src/storage-keys.ts
CHANGED
|
@@ -13,6 +13,18 @@ export interface StorageValueByKey {
|
|
|
13
13
|
/** Used to determine if the drawer was opened previously so when users navigate to other pages we can automatically open chat. */
|
|
14
14
|
"ada-embed_is-drawer-open": boolean;
|
|
15
15
|
|
|
16
|
+
/** Use to cache Zendesk tags assigned to a conversation. */
|
|
17
|
+
"ada-embed_zd-previous-tags": string;
|
|
18
|
+
|
|
19
|
+
/** Stores Zendesk session id. */
|
|
20
|
+
"ada-embed_zd-session-id": string;
|
|
21
|
+
|
|
22
|
+
/** Used to determine whether Zendesk session is expired. */
|
|
23
|
+
"ada-embed_zd-messaging-chatter-created": string;
|
|
24
|
+
|
|
25
|
+
/** Stores Zendesk internal user id. */
|
|
26
|
+
"ada-embed_zd-messaging-external-user-id": string;
|
|
27
|
+
|
|
16
28
|
/** Used to store general information about Ada application state. */
|
|
17
29
|
"ada-functional-storage": Partial<AdaFunctionalStorageValue>;
|
|
18
30
|
|
|
@@ -25,7 +37,7 @@ export interface StorageValueByKey {
|
|
|
25
37
|
/** Indicates whether user is waiting to connect to a live agent. */
|
|
26
38
|
"liveChatPending": boolean;
|
|
27
39
|
|
|
28
|
-
/** Used for chatter authentication */
|
|
40
|
+
/** Used for chatter authentication. */
|
|
29
41
|
"session_token": string;
|
|
30
42
|
}
|
|
31
43
|
|