even-toolkit 1.5.6 → 1.5.8
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.
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent storage for Even Hub apps.
|
|
3
|
+
*
|
|
4
|
+
* The Even Hub WebView doesn't persist browser localStorage across app restarts.
|
|
5
|
+
* This module uses the SDK's `bridge.setLocalStorage/getLocalStorage` which DO persist,
|
|
6
|
+
* with browser localStorage as a sync-read cache and fallback for web/dev.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { storageSet, storageGetSync, hydrateFromSDK } from 'even-toolkit/storage';
|
|
10
|
+
*
|
|
11
|
+
* // In main.tsx — hydrate before render:
|
|
12
|
+
* hydrateFromSDK(['my-app:settings', 'my-app:data']).finally(() => {
|
|
13
|
+
* createRoot(...).render(<App />);
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Read (synchronous):
|
|
17
|
+
* const data = storageGetSync<MyData>('my-app:data', defaultValue);
|
|
18
|
+
*
|
|
19
|
+
* // Write (dual-write to localStorage + SDK bridge):
|
|
20
|
+
* storageSet('my-app:data', data);
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Read a JSON value synchronously from browser localStorage.
|
|
24
|
+
* Call `hydrateFromSDK()` at startup to ensure localStorage has the latest SDK data.
|
|
25
|
+
*/
|
|
26
|
+
export declare function storageGetSync<T>(key: string, fallback: T): T;
|
|
27
|
+
/**
|
|
28
|
+
* Write a JSON-serializable value to both localStorage and SDK bridge.
|
|
29
|
+
*/
|
|
30
|
+
export declare function storageSet(key: string, value: unknown): void;
|
|
31
|
+
/**
|
|
32
|
+
* Write a raw string value to both localStorage and SDK bridge.
|
|
33
|
+
* Use for pre-serialized or encrypted values that shouldn't be double-stringified.
|
|
34
|
+
*/
|
|
35
|
+
export declare function storageSetRaw(key: string, value: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Remove a key from both localStorage and SDK bridge.
|
|
38
|
+
*/
|
|
39
|
+
export declare function storageRemove(key: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Hydrate browser localStorage from SDK bridge on app startup.
|
|
42
|
+
* Call once before React renders so `storageGetSync` reads fresh data.
|
|
43
|
+
*
|
|
44
|
+
* @param keys - All storage keys used by the app
|
|
45
|
+
*/
|
|
46
|
+
export declare function hydrateFromSDK(keys: string[]): Promise<void>;
|
|
47
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../glasses/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAM7D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAO5D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAM9D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAM/C;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAYlE"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent storage for Even Hub apps.
|
|
3
|
+
*
|
|
4
|
+
* The Even Hub WebView doesn't persist browser localStorage across app restarts.
|
|
5
|
+
* This module uses the SDK's `bridge.setLocalStorage/getLocalStorage` which DO persist,
|
|
6
|
+
* with browser localStorage as a sync-read cache and fallback for web/dev.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { storageSet, storageGetSync, hydrateFromSDK } from 'even-toolkit/storage';
|
|
10
|
+
*
|
|
11
|
+
* // In main.tsx — hydrate before render:
|
|
12
|
+
* hydrateFromSDK(['my-app:settings', 'my-app:data']).finally(() => {
|
|
13
|
+
* createRoot(...).render(<App />);
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Read (synchronous):
|
|
17
|
+
* const data = storageGetSync<MyData>('my-app:data', defaultValue);
|
|
18
|
+
*
|
|
19
|
+
* // Write (dual-write to localStorage + SDK bridge):
|
|
20
|
+
* storageSet('my-app:data', data);
|
|
21
|
+
*/
|
|
22
|
+
function getBridge() {
|
|
23
|
+
return window.__evenBridge ?? null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Read a JSON value synchronously from browser localStorage.
|
|
27
|
+
* Call `hydrateFromSDK()` at startup to ensure localStorage has the latest SDK data.
|
|
28
|
+
*/
|
|
29
|
+
export function storageGetSync(key, fallback) {
|
|
30
|
+
try {
|
|
31
|
+
const raw = localStorage.getItem(key);
|
|
32
|
+
if (raw)
|
|
33
|
+
return JSON.parse(raw);
|
|
34
|
+
}
|
|
35
|
+
catch { /* ignore */ }
|
|
36
|
+
return fallback;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Write a JSON-serializable value to both localStorage and SDK bridge.
|
|
40
|
+
*/
|
|
41
|
+
export function storageSet(key, value) {
|
|
42
|
+
const json = JSON.stringify(value);
|
|
43
|
+
try {
|
|
44
|
+
localStorage.setItem(key, json);
|
|
45
|
+
}
|
|
46
|
+
catch { /* ignore */ }
|
|
47
|
+
const bridge = getBridge();
|
|
48
|
+
if (bridge?.setLocalStorage) {
|
|
49
|
+
bridge.setLocalStorage(key, json).catch(() => { });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Write a raw string value to both localStorage and SDK bridge.
|
|
54
|
+
* Use for pre-serialized or encrypted values that shouldn't be double-stringified.
|
|
55
|
+
*/
|
|
56
|
+
export function storageSetRaw(key, value) {
|
|
57
|
+
try {
|
|
58
|
+
localStorage.setItem(key, value);
|
|
59
|
+
}
|
|
60
|
+
catch { /* ignore */ }
|
|
61
|
+
const bridge = getBridge();
|
|
62
|
+
if (bridge?.setLocalStorage) {
|
|
63
|
+
bridge.setLocalStorage(key, value).catch(() => { });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Remove a key from both localStorage and SDK bridge.
|
|
68
|
+
*/
|
|
69
|
+
export function storageRemove(key) {
|
|
70
|
+
localStorage.removeItem(key);
|
|
71
|
+
const bridge = getBridge();
|
|
72
|
+
if (bridge?.setLocalStorage) {
|
|
73
|
+
bridge.setLocalStorage(key, '').catch(() => { });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Hydrate browser localStorage from SDK bridge on app startup.
|
|
78
|
+
* Call once before React renders so `storageGetSync` reads fresh data.
|
|
79
|
+
*
|
|
80
|
+
* @param keys - All storage keys used by the app
|
|
81
|
+
*/
|
|
82
|
+
export async function hydrateFromSDK(keys) {
|
|
83
|
+
const bridge = getBridge();
|
|
84
|
+
if (!bridge?.getLocalStorage)
|
|
85
|
+
return;
|
|
86
|
+
for (const key of keys) {
|
|
87
|
+
try {
|
|
88
|
+
const value = await bridge.getLocalStorage(key);
|
|
89
|
+
if (value && value !== '') {
|
|
90
|
+
localStorage.setItem(key, value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch { /* ignore */ }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../glasses/storage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,SAAS,SAAS;IAChB,OAAQ,MAAc,CAAC,YAAY,IAAI,IAAI,CAAC;AAC9C,CA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CAAC,GAAW;IACvC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAI,MAAM,EAAE,eAAe,EAAE,CAAC;QAC5B,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAc;IACjD,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAI,CAAC,MAAM,EAAE,eAAe;QAAE,OAAO;IAErC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;YAChD,IAAI,KAAK,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;gBAC1B,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persistent storage for Even Hub apps.
|
|
3
|
+
*
|
|
4
|
+
* The Even Hub WebView doesn't persist browser localStorage across app restarts.
|
|
5
|
+
* This module uses the SDK's `bridge.setLocalStorage/getLocalStorage` which DO persist,
|
|
6
|
+
* with browser localStorage as a sync-read cache and fallback for web/dev.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* import { storageSet, storageGetSync, hydrateFromSDK } from 'even-toolkit/storage';
|
|
10
|
+
*
|
|
11
|
+
* // In main.tsx — hydrate before render:
|
|
12
|
+
* hydrateFromSDK(['my-app:settings', 'my-app:data']).finally(() => {
|
|
13
|
+
* createRoot(...).render(<App />);
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Read (synchronous):
|
|
17
|
+
* const data = storageGetSync<MyData>('my-app:data', defaultValue);
|
|
18
|
+
*
|
|
19
|
+
* // Write (dual-write to localStorage + SDK bridge):
|
|
20
|
+
* storageSet('my-app:data', data);
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function getBridge(): any {
|
|
24
|
+
return (window as any).__evenBridge ?? null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Read a JSON value synchronously from browser localStorage.
|
|
29
|
+
* Call `hydrateFromSDK()` at startup to ensure localStorage has the latest SDK data.
|
|
30
|
+
*/
|
|
31
|
+
export function storageGetSync<T>(key: string, fallback: T): T {
|
|
32
|
+
try {
|
|
33
|
+
const raw = localStorage.getItem(key);
|
|
34
|
+
if (raw) return JSON.parse(raw);
|
|
35
|
+
} catch { /* ignore */ }
|
|
36
|
+
return fallback;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Write a JSON-serializable value to both localStorage and SDK bridge.
|
|
41
|
+
*/
|
|
42
|
+
export function storageSet(key: string, value: unknown): void {
|
|
43
|
+
const json = JSON.stringify(value);
|
|
44
|
+
try { localStorage.setItem(key, json); } catch { /* ignore */ }
|
|
45
|
+
const bridge = getBridge();
|
|
46
|
+
if (bridge?.setLocalStorage) {
|
|
47
|
+
bridge.setLocalStorage(key, json).catch(() => {});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Write a raw string value to both localStorage and SDK bridge.
|
|
53
|
+
* Use for pre-serialized or encrypted values that shouldn't be double-stringified.
|
|
54
|
+
*/
|
|
55
|
+
export function storageSetRaw(key: string, value: string): void {
|
|
56
|
+
try { localStorage.setItem(key, value); } catch { /* ignore */ }
|
|
57
|
+
const bridge = getBridge();
|
|
58
|
+
if (bridge?.setLocalStorage) {
|
|
59
|
+
bridge.setLocalStorage(key, value).catch(() => {});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Remove a key from both localStorage and SDK bridge.
|
|
65
|
+
*/
|
|
66
|
+
export function storageRemove(key: string): void {
|
|
67
|
+
localStorage.removeItem(key);
|
|
68
|
+
const bridge = getBridge();
|
|
69
|
+
if (bridge?.setLocalStorage) {
|
|
70
|
+
bridge.setLocalStorage(key, '').catch(() => {});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Hydrate browser localStorage from SDK bridge on app startup.
|
|
76
|
+
* Call once before React renders so `storageGetSync` reads fresh data.
|
|
77
|
+
*
|
|
78
|
+
* @param keys - All storage keys used by the app
|
|
79
|
+
*/
|
|
80
|
+
export async function hydrateFromSDK(keys: string[]): Promise<void> {
|
|
81
|
+
const bridge = getBridge();
|
|
82
|
+
if (!bridge?.getLocalStorage) return;
|
|
83
|
+
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
try {
|
|
86
|
+
const value = await bridge.getLocalStorage(key);
|
|
87
|
+
if (value && value !== '') {
|
|
88
|
+
localStorage.setItem(key, value);
|
|
89
|
+
}
|
|
90
|
+
} catch { /* ignore */ }
|
|
91
|
+
}
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "even-toolkit",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8",
|
|
4
4
|
"bin": {
|
|
5
5
|
"even-toolkit": "./bin/create.js"
|
|
6
6
|
},
|
|
@@ -77,6 +77,10 @@
|
|
|
77
77
|
"types": "./dist/glasses/splash.d.ts",
|
|
78
78
|
"import": "./dist/glasses/splash.js"
|
|
79
79
|
},
|
|
80
|
+
"./storage": {
|
|
81
|
+
"types": "./dist/glasses/storage.d.ts",
|
|
82
|
+
"import": "./dist/glasses/storage.js"
|
|
83
|
+
},
|
|
80
84
|
"./text-clean": {
|
|
81
85
|
"types": "./dist/glasses/text-clean.d.ts",
|
|
82
86
|
"import": "./dist/glasses/text-clean.js"
|