@ada-support/web-storage 0.0.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/.eslintignore +2 -0
- package/.eslintrc +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
- package/.github/workflows/npm-publish.yml +29 -0
- package/.github/workflows/verify-code.yml +28 -0
- package/README.md +2 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +47 -0
- package/dist/storage-keys.d.ts +19 -0
- package/dist/storage-keys.js +2 -0
- package/package.json +27 -0
- package/src/index.ts +43 -0
- package/src/storage-keys.ts +21 -0
- package/tsconfig.json +7 -0
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: "NPM publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
npm-publish:
|
|
9
|
+
name: "NPM publish"
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- name: "Checkout source code"
|
|
13
|
+
uses: "actions/checkout@v2"
|
|
14
|
+
env:
|
|
15
|
+
GITHUB_TOKEN: ${{ secrets.PUSH_ACCESS_TOKEN }}
|
|
16
|
+
with:
|
|
17
|
+
ref: ${{ github.ref }}
|
|
18
|
+
|
|
19
|
+
- uses: actions/setup-node@v2
|
|
20
|
+
with:
|
|
21
|
+
node-version: "16.x"
|
|
22
|
+
registry-url: "https://registry.npmjs.org"
|
|
23
|
+
|
|
24
|
+
- run: |
|
|
25
|
+
yarn install
|
|
26
|
+
yarn compile
|
|
27
|
+
npm publish
|
|
28
|
+
env:
|
|
29
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: "Verify code"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
jobs:
|
|
6
|
+
verify:
|
|
7
|
+
name: "Verify code"
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
steps:
|
|
10
|
+
- name: "Checkout source code"
|
|
11
|
+
uses: "actions/checkout@v3"
|
|
12
|
+
env:
|
|
13
|
+
GITHUB_TOKEN: ${{ secrets.PUSH_ACCESS_TOKEN }}
|
|
14
|
+
with:
|
|
15
|
+
ref: ${{ github.ref }}
|
|
16
|
+
|
|
17
|
+
- uses: actions/setup-node@v3
|
|
18
|
+
with:
|
|
19
|
+
node-version: "16"
|
|
20
|
+
registry-url: "https://registry.npmjs.org"
|
|
21
|
+
cache: 'npm'
|
|
22
|
+
|
|
23
|
+
- run: |
|
|
24
|
+
yarn install
|
|
25
|
+
yarn compile
|
|
26
|
+
yarn lint
|
|
27
|
+
env:
|
|
28
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AdaFunctionalStorageValue, StorageValueByKey } from "./storage-keys";
|
|
2
|
+
export declare const adaLocalStorage: {
|
|
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
|
+
/** Stores a key/value pair within `ada-functional` localStorage key */
|
|
6
|
+
readonly setFnItem: <K_2 extends keyof AdaFunctionalStorageValue>(key: K_2, value: AdaFunctionalStorageValue[K_2]) => void;
|
|
7
|
+
/** Gets an value under `ada-functional` localStorage key */
|
|
8
|
+
readonly getFnItem: <K_3 extends keyof AdaFunctionalStorageValue>(key: K_3) => AdaFunctionalStorageValue[K_3] | null;
|
|
9
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
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.adaLocalStorage = void 0;
|
|
15
|
+
var LOCAL_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access localStorage";
|
|
16
|
+
exports.adaLocalStorage = {
|
|
17
|
+
setItem: function (key, value) {
|
|
18
|
+
try {
|
|
19
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.warn(LOCAL_STORAGE_ACCESS_ERROR_MESSAGE);
|
|
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
|
+
}
|
|
47
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface AdaFunctionalStorageValue {
|
|
2
|
+
rolloutGroup: {
|
|
3
|
+
[clientHandle: string]: "A" | "B";
|
|
4
|
+
};
|
|
5
|
+
rollout: {
|
|
6
|
+
group: {
|
|
7
|
+
[clientHandle: string]: "A" | "B";
|
|
8
|
+
};
|
|
9
|
+
lastProbability: {
|
|
10
|
+
[clientHandle: string]: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface StorageValueByKey {
|
|
15
|
+
"ada-embed_is-drawer-open": boolean;
|
|
16
|
+
"chatter": string;
|
|
17
|
+
"ada-functional": Partial<AdaFunctionalStorageValue>;
|
|
18
|
+
}
|
|
19
|
+
export declare type StorageKey = keyof StorageValueByKey;
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ada-support/web-storage",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "A package to provide access to Web Storage API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "tsc --noEmit && npx eslint --ext .ts .",
|
|
11
|
+
"compile": "rm -rf dist && npx tsc"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/AdaSupport/web-storage.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"homepage": "https://github.com/AdaSupport/web-storage#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"typescript": "^4.8.4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@ada-support/eslint-config-ada": "^1.2.4",
|
|
25
|
+
"eslint": "^8.24.0"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AdaFunctionalStorageValue, StorageKey, StorageValueByKey } from "./storage-keys";
|
|
2
|
+
|
|
3
|
+
const LOCAL_STORAGE_ACCESS_ERROR_MESSAGE = "Cannot access localStorage";
|
|
4
|
+
|
|
5
|
+
export const adaLocalStorage = {
|
|
6
|
+
setItem: <K extends StorageKey>(key: K, value: StorageValueByKey[K]): void => {
|
|
7
|
+
try {
|
|
8
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.warn(LOCAL_STORAGE_ACCESS_ERROR_MESSAGE);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
getItem: <K extends StorageKey>(key: K): StorageValueByKey[K] | null => {
|
|
15
|
+
try {
|
|
16
|
+
const rawStorageValue = localStorage.getItem(key);
|
|
17
|
+
|
|
18
|
+
return rawStorageValue && JSON.parse(rawStorageValue);
|
|
19
|
+
} catch (e) {
|
|
20
|
+
console.warn(LOCAL_STORAGE_ACCESS_ERROR_MESSAGE);
|
|
21
|
+
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
/** Stores a key/value pair within `ada-functional` localStorage key */
|
|
27
|
+
setFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K, value: AdaFunctionalStorageValue[K]): void => {
|
|
28
|
+
const currentValue = adaLocalStorage.getItem("ada-functional") || {};
|
|
29
|
+
const newValue = {
|
|
30
|
+
...currentValue,
|
|
31
|
+
[key]: value,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
adaLocalStorage.setItem("ada-functional", newValue);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
/** Gets an value under `ada-functional` localStorage key */
|
|
38
|
+
getFnItem: <K extends keyof AdaFunctionalStorageValue>(key: K): AdaFunctionalStorageValue[K] | null => {
|
|
39
|
+
const value = adaLocalStorage.getItem("ada-functional");
|
|
40
|
+
|
|
41
|
+
return (value && value[key]) || null;
|
|
42
|
+
},
|
|
43
|
+
} as const;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface AdaFunctionalStorageValue {
|
|
2
|
+
rolloutGroup: {
|
|
3
|
+
[clientHandle: string]: "A" | "B";
|
|
4
|
+
};
|
|
5
|
+
rollout: {
|
|
6
|
+
group: {
|
|
7
|
+
[clientHandle: string]: "A" | "B";
|
|
8
|
+
};
|
|
9
|
+
lastProbability: {
|
|
10
|
+
[clientHandle: string]: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface StorageValueByKey {
|
|
16
|
+
"ada-embed_is-drawer-open": boolean;
|
|
17
|
+
"chatter": string;
|
|
18
|
+
"ada-functional": Partial<AdaFunctionalStorageValue>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type StorageKey = keyof StorageValueByKey;
|