@ada-support/web-storage 0.0.5 → 0.1.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/.github/workflows/notify-people.yml +18 -10
- package/CODEOWNERS +1 -0
- package/dist/functional-storage.d.ts +8 -0
- package/dist/functional-storage.js +2 -0
- package/dist/index.d.ts +20 -3
- package/dist/index.js +38 -32
- package/dist/storage-keys.d.ts +9 -9
- package/package.json +1 -1
- package/src/functional-storage.ts +8 -0
- package/src/index.ts +51 -43
- package/src/storage-keys.ts +13 -9
|
@@ -2,19 +2,27 @@ name: "Notify people"
|
|
|
2
2
|
|
|
3
3
|
on:
|
|
4
4
|
pull_request:
|
|
5
|
-
types: [ready_for_review]
|
|
5
|
+
types: [opened, reopened, ready_for_review]
|
|
6
6
|
jobs:
|
|
7
7
|
notify:
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
|
+
env:
|
|
10
|
+
SLACK_CHANNEL: "#chatx-engineering-internal" #default
|
|
11
|
+
SLACK_USERNAME: "`@ada-support/web-storage` package updates"
|
|
12
|
+
SLACK_ICON_EMOJI: ":sparkles:"
|
|
13
|
+
SLACK_COLOR: "#f5e512"
|
|
14
|
+
SLACK_TITLE: "Changes to `web-storage` are ready for review"
|
|
15
|
+
SLACK_MESSAGE: "Pull request: ${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number }}"
|
|
16
|
+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
17
|
+
MSG_MINIMAL: true
|
|
18
|
+
|
|
9
19
|
steps:
|
|
10
|
-
- name:
|
|
20
|
+
- name: "Notify ChatX team"
|
|
21
|
+
uses: rtCamp/action-slack-notify@v2
|
|
22
|
+
env:
|
|
23
|
+
SLACK_CHANNEL: "#chatx-engineering-internal"
|
|
24
|
+
|
|
25
|
+
- name: "Notify #p-cookies-updates-management"
|
|
11
26
|
uses: rtCamp/action-slack-notify@v2
|
|
12
27
|
env:
|
|
13
|
-
|
|
14
|
-
SLACK_ICON_EMOJI: ":sparkles:"
|
|
15
|
-
SLACK_CHANNEL: "chatx"
|
|
16
|
-
SLACK_COLOR: "#f5e512"
|
|
17
|
-
SLACK_TITLE: "Changes to `web-storage` are ready for review"
|
|
18
|
-
SLACK_MESSAGE: "Pull request: ${{ github.server_url }}/${{ github.repository }}/pull/${{ github.event.number }}"
|
|
19
|
-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
|
|
20
|
-
MSG_MINIMAL: true
|
|
28
|
+
SLACK_CHANNEL: "#p-cookies-updates-management"
|
package/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
src/ @AdaSupport/chatx
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import type { AdaFunctionalStorageValue
|
|
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
|
+
};
|
|
2
11
|
export declare const adaLocalStorage: {
|
|
3
12
|
readonly setItem: <K extends keyof StorageValueByKey>(key: K, value: StorageValueByKey[K]) => void;
|
|
4
13
|
readonly getItem: <K_1 extends keyof StorageValueByKey>(key: K_1) => StorageValueByKey[K_1] | null;
|
|
5
|
-
/** Stores a key/value pair within `ada-functional`
|
|
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;
|
|
18
|
+
};
|
|
19
|
+
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 */
|
|
6
23
|
readonly setFnItem: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
|
|
7
|
-
/** Gets
|
|
24
|
+
/** Gets a value under `ada-functional-storage` Storage key */
|
|
8
25
|
readonly getFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
|
|
9
26
|
};
|
package/dist/index.js
CHANGED
|
@@ -11,37 +11,43 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
exports.__esModule = true;
|
|
14
|
-
exports.adaLocalStorage = void 0;
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
20
47
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
getItem: function (key) {
|
|
26
|
-
try {
|
|
27
|
-
var rawStorageValue = localStorage.getItem(key);
|
|
28
|
-
return rawStorageValue && JSON.parse(rawStorageValue);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
console.warn(LOCAL_STORAGE_ACCESS_ERROR_MESSAGE);
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
/** Stores a key/value pair within `ada-functional` localStorage key */
|
|
36
|
-
setFnItem: function (key, value) {
|
|
37
|
-
var _a;
|
|
38
|
-
var currentValue = exports.adaLocalStorage.getItem("ada-functional") || {};
|
|
39
|
-
var newValue = __assign(__assign({}, currentValue), (_a = {}, _a[key] = value, _a));
|
|
40
|
-
exports.adaLocalStorage.setItem("ada-functional", newValue);
|
|
41
|
-
},
|
|
42
|
-
/** Gets an value under `ada-functional` localStorage key */
|
|
43
|
-
getFnItem: function (key) {
|
|
44
|
-
var value = exports.adaLocalStorage.getItem("ada-functional");
|
|
45
|
-
return (value && value[key]) || null;
|
|
46
|
-
}
|
|
48
|
+
};
|
|
49
|
+
return storage;
|
|
47
50
|
};
|
|
51
|
+
exports.createStorage = createStorage;
|
|
52
|
+
exports.adaLocalStorage = (0, exports.createStorage)(localStorage);
|
|
53
|
+
exports.adaSessionStorage = (0, exports.createStorage)(sessionStorage);
|
package/dist/storage-keys.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
rolloutGroup: {
|
|
3
|
-
[clientHandle: string]: "A" | "B";
|
|
4
|
-
};
|
|
5
|
-
rolloutLastValue: {
|
|
6
|
-
[clientHandle: string]: number;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
import type { AdaFunctionalStorageValue } from "./functional-storage";
|
|
9
2
|
export interface StorageValueByKey {
|
|
3
|
+
/** Used to store the chat version assigned to a user (for A/B testing purposes). */
|
|
4
|
+
"ada-embed_chat-assigned-version": string;
|
|
5
|
+
/** Used to store information about current versions available (“canary” or “stable”). */
|
|
6
|
+
"ada-embed_chat-manifest-cache": object;
|
|
7
|
+
/** Used to determine if the drawer was opened previously so when users navigate to other pages we can automatically open chat. */
|
|
10
8
|
"ada-embed_is-drawer-open": boolean;
|
|
9
|
+
/** Use to store general information about Ada application state. */
|
|
10
|
+
"ada-functional-storage": Partial<AdaFunctionalStorageValue>;
|
|
11
|
+
/** Used to identify the user within Ada. */
|
|
11
12
|
"chatter": string;
|
|
12
|
-
"ada-functional": Partial<AdaFunctionalStorageValue>;
|
|
13
13
|
}
|
|
14
14
|
export declare type StorageKey = keyof StorageValueByKey;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,43 +1,51 @@
|
|
|
1
|
-
import type { AdaFunctionalStorageValue
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
};
|
|
49
|
+
|
|
50
|
+
export const adaLocalStorage = createStorage(localStorage);
|
|
51
|
+
export const adaSessionStorage = createStorage(sessionStorage);
|
package/src/storage-keys.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
rolloutGroup: {
|
|
3
|
-
[clientHandle: string]: "A" | "B";
|
|
4
|
-
};
|
|
5
|
-
rolloutLastValue: {
|
|
6
|
-
[clientHandle: string]: number;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
import type { AdaFunctionalStorageValue } from "./functional-storage";
|
|
9
2
|
|
|
10
3
|
export interface StorageValueByKey {
|
|
4
|
+
/** Used to store the chat version assigned to a user (for A/B testing purposes). */
|
|
5
|
+
"ada-embed_chat-assigned-version": string;
|
|
6
|
+
|
|
7
|
+
/** Used to store information about current versions available (“canary” or “stable”). */
|
|
8
|
+
"ada-embed_chat-manifest-cache": object;
|
|
9
|
+
|
|
10
|
+
/** Used to determine if the drawer was opened previously so when users navigate to other pages we can automatically open chat. */
|
|
11
11
|
"ada-embed_is-drawer-open": boolean;
|
|
12
|
+
|
|
13
|
+
/** Use to store general information about Ada application state. */
|
|
14
|
+
"ada-functional-storage": Partial<AdaFunctionalStorageValue>;
|
|
15
|
+
|
|
16
|
+
/** Used to identify the user within Ada. */
|
|
12
17
|
"chatter": string;
|
|
13
|
-
"ada-functional": Partial<AdaFunctionalStorageValue>;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
export type StorageKey = keyof StorageValueByKey;
|