aeria-sdk 0.0.220 → 0.0.222
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/dist/storage.js +33 -12
- package/package.json +3 -3
package/dist/storage.js
CHANGED
|
@@ -5,42 +5,63 @@ export const storageKey = (key, config) => {
|
|
|
5
5
|
return `${namespace}:${key}`;
|
|
6
6
|
};
|
|
7
7
|
export const getStorage = (config) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
let strategy;
|
|
9
|
+
if (config.storage?.strategy) {
|
|
10
|
+
if (config.storage.strategy === 'localStorage') {
|
|
11
|
+
// eslint-disable-next-line
|
|
12
|
+
if (typeof localStorage === 'object' && localStorage && typeof localStorage.getItem === 'function') {
|
|
13
|
+
strategy = 'localStorage';
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
console.warn('localStorage not available, failing back to memory storage');
|
|
17
|
+
strategy = 'memo';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
strategy = config.storage.strategy;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
strategy = 'none';
|
|
26
|
+
}
|
|
13
27
|
function get(key) {
|
|
14
28
|
switch (strategy) {
|
|
15
|
-
case 'memo':
|
|
29
|
+
case 'memo': {
|
|
16
30
|
return storageMemo[key] || null;
|
|
17
|
-
|
|
31
|
+
}
|
|
32
|
+
case 'localStorage': {
|
|
18
33
|
const value = localStorage.getItem(storageKey(key, config));
|
|
19
34
|
return value
|
|
20
35
|
? JSON.parse(value)
|
|
21
36
|
: null;
|
|
37
|
+
}
|
|
22
38
|
}
|
|
23
39
|
}
|
|
24
40
|
return {
|
|
25
41
|
get,
|
|
26
42
|
remove: (key) => {
|
|
27
43
|
switch (strategy) {
|
|
28
|
-
case 'memo':
|
|
44
|
+
case 'memo': {
|
|
29
45
|
delete storageMemo[key];
|
|
30
46
|
break;
|
|
31
|
-
|
|
47
|
+
}
|
|
48
|
+
case 'localStorage': {
|
|
32
49
|
localStorage.removeItem(storageKey(key, config));
|
|
33
50
|
break;
|
|
51
|
+
}
|
|
34
52
|
}
|
|
35
53
|
},
|
|
36
54
|
set: (key, value) => {
|
|
37
55
|
switch (strategy) {
|
|
38
|
-
case 'memo':
|
|
56
|
+
case 'memo': {
|
|
39
57
|
storageMemo[key] = value;
|
|
40
58
|
break;
|
|
41
|
-
|
|
59
|
+
}
|
|
60
|
+
case 'localStorage': {
|
|
42
61
|
const serialized = JSON.stringify(value);
|
|
43
|
-
|
|
62
|
+
localStorage.setItem(storageKey(key, config), serialized);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
44
65
|
}
|
|
45
66
|
},
|
|
46
67
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aeria-sdk",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.222",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@aeriajs/types": "link:../types"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@aeriajs/common": "^0.0.
|
|
50
|
-
"@aeriajs/types": "^0.0.
|
|
49
|
+
"@aeriajs/common": "^0.0.168",
|
|
50
|
+
"@aeriajs/types": "^0.0.141"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"jwt-decode": "^4.0.0"
|