@applicaster/zapp-react-native-utils 12.0.0-rc.136 → 12.0.0-rc.138

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-rc.136",
3
+ "version": "12.0.0-rc.138",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "12.0.0-rc.136",
31
+ "@applicaster/applicaster-types": "12.0.0-rc.138",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -0,0 +1,48 @@
1
+ import {
2
+ DEFAULT_STORAGE_NAMESPACE,
3
+ getWebStorageKey,
4
+ NAMESPACE_STORAGE_SEPARATOR_WEB,
5
+ } from "./storageWebUtils.web";
6
+
7
+ export function saveSync(
8
+ key: string,
9
+ value: string,
10
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
11
+ ) {
12
+ const storageWebKey = getWebStorageKey(key, namespace);
13
+
14
+ return localStorage.setItem(storageWebKey, value);
15
+ }
16
+
17
+ export function getSync(
18
+ key: string,
19
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
20
+ ) {
21
+ const storageWebKey = getWebStorageKey(key, namespace);
22
+
23
+ return localStorage.getItem(storageWebKey);
24
+ }
25
+
26
+ export function getAllSync(namespace: string = DEFAULT_STORAGE_NAMESPACE) {
27
+ const allItems = {};
28
+
29
+ for (let i = 0; i < localStorage.length; i++) {
30
+ const key = localStorage.key(i);
31
+
32
+ if (key && key.startsWith(namespace + NAMESPACE_STORAGE_SEPARATOR_WEB)) {
33
+ const itemKey = key.split(NAMESPACE_STORAGE_SEPARATOR_WEB)[1];
34
+ allItems[itemKey] = localStorage.getItem(key);
35
+ }
36
+ }
37
+
38
+ return allItems;
39
+ }
40
+
41
+ export function removeSync(
42
+ key: string,
43
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
44
+ ) {
45
+ const storageWebKey = getWebStorageKey(key, namespace);
46
+
47
+ return localStorage.removeItem(storageWebKey);
48
+ }
@@ -0,0 +1,32 @@
1
+ import {
2
+ DEFAULT_STORAGE_NAMESPACE,
3
+ getWebStorageKey,
4
+ } from "./storageWebUtils.web";
5
+
6
+ export function saveSync(
7
+ key: string,
8
+ value: string,
9
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
10
+ ) {
11
+ const storageWebKey = getWebStorageKey(key, namespace);
12
+
13
+ return sessionStorage.setItem(storageWebKey, value);
14
+ }
15
+
16
+ export function getSync(
17
+ key: string,
18
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
19
+ ) {
20
+ const storageWebKey = getWebStorageKey(key, namespace);
21
+
22
+ return sessionStorage.getItem(storageWebKey);
23
+ }
24
+
25
+ export function removeSync(
26
+ key: string,
27
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
28
+ ) {
29
+ const storageWebKey = getWebStorageKey(key, namespace);
30
+
31
+ return sessionStorage.removeItem(storageWebKey);
32
+ }
@@ -0,0 +1,24 @@
1
+ import { DEFAULT_STORAGE_NAMESPACE } from "./storageWebUtils.web";
2
+ import { getSync as getLocalStorage } from "./localStorageServiceSync.web";
3
+ import { getSync as getSessionStorage } from "./sessionStorageServiceSync.web";
4
+
5
+ export const getFromSessionOrLocalStorage = (
6
+ key: string,
7
+ namespace: string = DEFAULT_STORAGE_NAMESPACE
8
+ ) => getSessionStorage(key, namespace) || getLocalStorage(key, namespace);
9
+
10
+ export const resolveStorageContextKey = (storageKey: string) => {
11
+ if (!storageKey) {
12
+ return;
13
+ }
14
+
15
+ const splitKey = storageKey.split(".");
16
+ const namespaceOrKey = splitKey[0];
17
+ const key = splitKey[1];
18
+
19
+ if (!key) {
20
+ return getFromSessionOrLocalStorage(key);
21
+ } else {
22
+ return getFromSessionOrLocalStorage(key, namespaceOrKey);
23
+ }
24
+ };
@@ -0,0 +1,10 @@
1
+ export const DEFAULT_STORAGE_NAMESPACE = "applicaster.v2";
2
+
3
+ export const NAMESPACE_STORAGE_SEPARATOR_WEB = "_::_";
4
+
5
+ export const getWebStorageKey = (
6
+ key: String,
7
+ namespace: String = DEFAULT_STORAGE_NAMESPACE
8
+ ) => {
9
+ return `${namespace}${NAMESPACE_STORAGE_SEPARATOR_WEB}${key}`;
10
+ };