@ada-support/web-storage 0.3.1 → 0.5.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 +1 @@
1
- > _This module is meant to be used internally by Ada projects only._
1
+ _This module is meant to be used internally by Ada projects only._
@@ -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: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
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: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
10
+ readonly getFnItem: <K_4 extends keyof AdaFunctionalStorageValue>(key: K_4) => AdaFunctionalStorageValue[K_4] | null;
10
11
  };
@@ -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,19 @@
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 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;
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 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;
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;
18
+ /** Checks if Web Storage API is supported */
19
+ export declare const isWebStorageSupported: () => boolean;
package/dist/index.js CHANGED
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.adaSessionStorage = exports.adaLocalStorage = void 0;
3
+ exports.isWebStorageSupported = exports.adaSessionStorage = exports.adaLocalStorage = void 0;
4
4
  var create_storage_1 = require("./create-storage");
5
5
  exports.adaLocalStorage = (0, create_storage_1.createStorage)(localStorage);
6
6
  exports.adaSessionStorage = (0, create_storage_1.createStorage)(sessionStorage);
7
+ /** Checks if Web Storage API is supported */
8
+ var isWebStorageSupported = function () {
9
+ try {
10
+ var key = "key_to_test_local_storage";
11
+ localStorage.setItem(key, key);
12
+ localStorage.removeItem(key);
13
+ return true;
14
+ }
15
+ catch (e) {
16
+ return false;
17
+ }
18
+ };
19
+ exports.isWebStorageSupported = isWebStorageSupported;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ada-support/web-storage",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "A package to provide access to Web Storage API",
5
5
  "main": "dist/index.js",
6
6
  "publishConfig": {
@@ -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,20 @@
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;
8
+
9
+ /** Checks if Web Storage API is supported */
10
+ export const isWebStorageSupported = (): boolean => {
11
+ try {
12
+ const key = "key_to_test_local_storage";
13
+ localStorage.setItem(key, key);
14
+ localStorage.removeItem(key);
15
+
16
+ return true;
17
+ } catch (e) {
18
+ return false;
19
+ }
20
+ };
@@ -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