@freeappstore/sdk 0.16.17 → 0.16.18

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/README.md CHANGED
@@ -5,6 +5,12 @@ Browser SDK for free apps published on **freeappstore.online**.
5
5
  PWA lifecycle APIs live at `@freeappstore/sdk/pwa`, with Vite options at
6
6
  `@freeappstore/sdk/pwa-config`. See [safe updates and offline capabilities](https://github.com/freeappstore-online/platform/blob/main/docs/pwa-lifecycle.md).
7
7
 
8
+ Device-local preferences, IndexedDB, and large-file metadata live at
9
+ `@freeappstore/sdk/persist`. That data is not the signed-in account. Account
10
+ keys remain `fas.kv`. A failed save returns a status instead of throwing a
11
+ success path, and corrupt values are left in place. See
12
+ [device-local persistence](https://github.com/freeappstore-online/platform/blob/main/docs/sdk.md#device-local-persistence-freeappstoresdkpersist).
13
+
8
14
  ## Installation
9
15
 
10
16
  ```bash
package/dist/logger.d.ts CHANGED
@@ -35,7 +35,7 @@ export interface BuildMeta {
35
35
  viewport: string;
36
36
  theme?: string | undefined;
37
37
  }
38
- export declare const SDK_VERSION = "0.16.16";
38
+ export declare const SDK_VERSION = "0.16.17";
39
39
  export declare class Logger {
40
40
  private readonly appId;
41
41
  private readonly apiBase;
package/dist/logger.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Must track package.json version — bumped on release. Guarded by version.test.ts
2
2
  // so a forgotten bump fails CI instead of silently misattributing telemetry.
3
- export const SDK_VERSION = '0.16.16';
3
+ export const SDK_VERSION = '0.16.17';
4
4
  const MEMORY_LIMIT = 200;
5
5
  const STORAGE_LIMIT = 500;
6
6
  const STORAGE_KEY_PREFIX = 'fas_logs:';
@@ -0,0 +1,20 @@
1
+ import { type StorageResult } from './status.js';
2
+ /**
3
+ * Register a storage capability at startup or the first time a feature runs.
4
+ *
5
+ * Installing again returns the capability already registered and does not call
6
+ * the installer. Installers must not delete databases, preference keys, or
7
+ * edited app data. `getCapability` distinguishes a name that was never
8
+ * registered (`not-installed`) from one that is registered while its store is
9
+ * blocked (`unavailable`, with detail `installed`).
10
+ */
11
+ export interface StorageCapability {
12
+ /**
13
+ * Probe the backing store without reading or writing app records.
14
+ * Return `{ ok: false, reason: 'unavailable' }` when storage is blocked.
15
+ */
16
+ probe: () => StorageResult<true>;
17
+ }
18
+ export declare function installCapability(name: string, installer: () => StorageCapability): StorageResult<StorageCapability>;
19
+ export declare function getCapability(name: string): StorageResult<StorageCapability>;
20
+ //# sourceMappingURL=capability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.d.ts","sourceRoot":"","sources":["../../src/persist/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAErB;;;;;;;;GAQG;AAEH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,KAAK,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,CAAC;CAClC;AAID,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,iBAAiB,GACjC,aAAa,CAAC,iBAAiB,CAAC,CAYlC;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAY5E"}
@@ -0,0 +1,36 @@
1
+ import { checkSegment, classifyStorageError, errorMessage, failure, } from './status.js';
2
+ const installed = new Map();
3
+ export function installCapability(name, installer) {
4
+ const checked = checkSegment(name, 'Capability name');
5
+ if (!checked.ok)
6
+ return checked;
7
+ const existing = installed.get(checked.value);
8
+ if (existing)
9
+ return { ok: true, value: existing };
10
+ try {
11
+ const created = installer();
12
+ installed.set(checked.value, created);
13
+ return { ok: true, value: created };
14
+ }
15
+ catch (error) {
16
+ return failure(classifyStorageError(error), errorMessage(error));
17
+ }
18
+ }
19
+ export function getCapability(name) {
20
+ const checked = checkSegment(name, 'Capability name');
21
+ if (!checked.ok)
22
+ return checked;
23
+ const existing = installed.get(checked.value);
24
+ if (!existing)
25
+ return failure('not-installed');
26
+ try {
27
+ const probe = existing.probe();
28
+ if (!probe.ok)
29
+ return failure(probe.reason, 'installed');
30
+ return { ok: true, value: existing };
31
+ }
32
+ catch (error) {
33
+ return failure(classifyStorageError(error), 'installed');
34
+ }
35
+ }
36
+ //# sourceMappingURL=capability.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability.js","sourceRoot":"","sources":["../../src/persist/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,OAAO,GAER,MAAM,aAAa,CAAC;AAoBrB,MAAM,SAAS,GAAG,IAAI,GAAG,EAA6B,CAAC;AAEvD,MAAM,UAAU,iBAAiB,CAC/B,IAAY,EACZ,SAAkC;IAElC,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAChC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,QAAQ;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;QAC5B,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACtC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,iBAAiB,CAAC,CAAC;IACtD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAChC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAC,eAAe,CAAC,CAAC;IAC/C,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,KAAK,CAAC,EAAE;YAAE,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACzD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { type IDBPDatabase } from 'idb';
2
+ import { type StorageResult } from './status.js';
3
+ /** Enough of an IndexedDB database to create stores during a version upgrade. */
4
+ export interface StoreMigration {
5
+ objectStoreNames: DOMStringList;
6
+ createObjectStore(name: string, options?: IDBObjectStoreParameters): unknown;
7
+ }
8
+ export interface OpenDatabaseOptions {
9
+ /** App segment. The database name is `fas:<namespace>` plus an optional suffix. */
10
+ namespace: string;
11
+ /** Extra name segment such as `:files`. Included in the database name. */
12
+ suffix?: string;
13
+ version: number;
14
+ /** Object stores that must exist. Missing stores are created before `upgrade`. */
15
+ stores: readonly string[];
16
+ upgrade?: ((database: StoreMigration, oldVersion: number) => void) | undefined;
17
+ }
18
+ export declare function databaseName(namespace: string, suffix?: string): StorageResult<string>;
19
+ export declare function idbAvailable(): boolean;
20
+ export declare function openFasDatabase(options: OpenDatabaseOptions): Promise<StorageResult<IDBPDatabase>>;
21
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/persist/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAU,MAAM,KAAK,CAAC;AAChD,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAErB,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,gBAAgB,EAAE,aAAa,CAAC;IAChC,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC;CAC9E;AAED,MAAM,WAAW,mBAAmB;IAClC,mFAAmF;IACnF,SAAS,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,kFAAkF;IAClF,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChF;AAED,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAIlF;AAED,wBAAgB,YAAY,IAAI,OAAO,CAMtC;AAED,wBAAsB,eAAe,CACnC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CA0BtC"}
@@ -0,0 +1,48 @@
1
+ import { openDB } from 'idb';
2
+ import { checkSegment, classifyStorageError, errorMessage, failure, } from './status.js';
3
+ export function databaseName(namespace, suffix = '') {
4
+ const checked = checkSegment(namespace, 'Namespace');
5
+ if (!checked.ok)
6
+ return checked;
7
+ return { ok: true, value: `fas:${checked.value}${suffix}` };
8
+ }
9
+ export function idbAvailable() {
10
+ try {
11
+ return typeof indexedDB !== 'undefined' && indexedDB !== null;
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ export async function openFasDatabase(options) {
18
+ if (!idbAvailable())
19
+ return failure('unavailable', 'IndexedDB is not available.');
20
+ const name = databaseName(options.namespace, options.suffix ?? '');
21
+ if (!name.ok)
22
+ return name;
23
+ if (!Number.isInteger(options.version) || options.version < 1) {
24
+ return failure('validation', 'Version must be an integer >= 1.');
25
+ }
26
+ let database;
27
+ try {
28
+ database = await openDB(name.value, options.version, {
29
+ upgrade(db, oldVersion) {
30
+ for (const store of options.stores) {
31
+ if (!db.objectStoreNames.contains(store))
32
+ db.createObjectStore(store);
33
+ }
34
+ options.upgrade?.(db, oldVersion);
35
+ },
36
+ blocking() {
37
+ // This connection is holding a version the caller wants to upgrade. Close
38
+ // it so the upgrade can proceed. Closing does not delete data.
39
+ database?.close();
40
+ },
41
+ });
42
+ return { ok: true, value: database };
43
+ }
44
+ catch (error) {
45
+ return failure(classifyStorageError(error), errorMessage(error));
46
+ }
47
+ }
48
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/persist/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,OAAO,GAER,MAAM,aAAa,CAAC;AAmBrB,MAAM,UAAU,YAAY,CAAC,SAAiB,EAAE,MAAM,GAAG,EAAE;IACzD,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAChC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,OAAO,CAAC,KAAK,GAAG,MAAM,EAAE,EAAE,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,IAAI,CAAC;QACH,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,KAAK,I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;QACf,OAAO,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { IDBPDatabase } from 'idb';
2
+ import { type StorageResult } from './status.js';
3
+ export interface FileMetadata {
4
+ id: string;
5
+ name: string;
6
+ contentType: string;
7
+ byteLength: number;
8
+ revision: number;
9
+ updatedAt: number;
10
+ }
11
+ export interface StoredFile<M extends FileMetadata = FileMetadata> {
12
+ metadata: M;
13
+ payload: Uint8Array;
14
+ }
15
+ export interface FileStore {
16
+ readonly namespace: string;
17
+ readonly database: IDBPDatabase;
18
+ close(): void;
19
+ }
20
+ export declare function openFileStore(options: {
21
+ namespace: string;
22
+ /** Integer schema version. Defaults to 1, which creates the two stores. */
23
+ version?: number;
24
+ upgrade?: ((database: {
25
+ objectStoreNames: DOMStringList;
26
+ createObjectStore(name: string, options?: IDBObjectStoreParameters): unknown;
27
+ }, oldVersion: number) => void) | undefined;
28
+ }): Promise<StorageResult<FileStore>>;
29
+ export declare function putFile<M extends FileMetadata>(store: FileStore, input: {
30
+ metadata: M;
31
+ payload: Blob | ArrayBuffer | Uint8Array;
32
+ /**
33
+ * Called only when this id is already stored. Return the record to commit,
34
+ * or null to leave the stored file untouched.
35
+ */
36
+ resolveConflict?: ((local: StoredFile<M>, incoming: StoredFile<M>) => StoredFile<M> | null) | undefined;
37
+ }): Promise<StorageResult<M>>;
38
+ export declare function getFile<M extends FileMetadata>(store: FileStore, id: string): Promise<StorageResult<StoredFile<M> | undefined>>;
39
+ export declare function getFileMetadata<M extends FileMetadata>(store: FileStore, id: string): Promise<StorageResult<M | undefined>>;
40
+ export declare function listFiles<M extends FileMetadata>(store: FileStore): Promise<StorageResult<M[]>>;
41
+ //# sourceMappingURL=file-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-store.d.ts","sourceRoot":"","sources":["../../src/persist/file-store.ts"],"names":[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AAC,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GACzE,SAAS,CAAC;CACf,GACA,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAuB3B;AA6CD,wBAAsB,OAAO,CAAC,CAAC,SAAS,YAAY,EAClD,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAenD;AAED,wBAAsB,eAAe,CAAC,CAAC,SAAS,YAAY,EAC1D,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CASvC;AAED,wBAAsB,SAAS,CAAC,CAAC,SAAS,YAAY,EACpD,KAAK,EAAE,SAAS,GACf,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAS7B"}
@@ -0,0 +1,142 @@
1
+ import { openFasDatabase } from './database.js';
2
+ import { failure, settleTransaction } from './status.js';
3
+ /**
4
+ * Large files split into a small metadata record and a separate payload.
5
+ *
6
+ * Both object stores live in one device-local IndexedDB database. Metadata
7
+ * reads do not load the payload. When a file id already exists, `putFile`
8
+ * does not overwrite it unless the caller supplies `resolveConflict`. That
9
+ * function is the app's merge policy. Returning null keeps both stored
10
+ * copies and reports `conflict`. A cross-tab preference notice is not this
11
+ * policy: notices only say that something changed.
12
+ */
13
+ const METADATA = 'metadata';
14
+ const PAYLOADS = 'payloads';
15
+ export async function openFileStore(options) {
16
+ const opened = await openFasDatabase({
17
+ namespace: options.namespace,
18
+ suffix: ':files',
19
+ version: options.version ?? 1,
20
+ stores: [METADATA, PAYLOADS],
21
+ upgrade: options.upgrade,
22
+ });
23
+ if (!opened.ok)
24
+ return opened;
25
+ const database = opened.value;
26
+ return {
27
+ ok: true,
28
+ value: {
29
+ namespace: options.namespace,
30
+ database,
31
+ close() {
32
+ database.close();
33
+ },
34
+ },
35
+ };
36
+ }
37
+ async function bytesOf(payload) {
38
+ if (payload instanceof Uint8Array)
39
+ return payload;
40
+ if (payload instanceof ArrayBuffer)
41
+ return new Uint8Array(payload);
42
+ return new Uint8Array(await payload.arrayBuffer());
43
+ }
44
+ function metadataError(metadata) {
45
+ if (typeof metadata.id !== 'string' || metadata.id.length === 0 || metadata.id.length > 128) {
46
+ return 'File id must be 1-128 characters.';
47
+ }
48
+ if (metadata.id.includes('\0'))
49
+ return 'File id is not valid.';
50
+ if (typeof metadata.name !== 'string' || typeof metadata.contentType !== 'string') {
51
+ return 'File name and content type must be strings.';
52
+ }
53
+ if (typeof metadata.revision !== 'number' || typeof metadata.updatedAt !== 'number') {
54
+ return 'File revision and updatedAt must be numbers.';
55
+ }
56
+ return undefined;
57
+ }
58
+ export async function putFile(store, input) {
59
+ const invalid = metadataError(input.metadata);
60
+ if (invalid)
61
+ return failure('validation', invalid);
62
+ let payload;
63
+ try {
64
+ payload = await bytesOf(input.payload);
65
+ }
66
+ catch (error) {
67
+ return failure('validation', error instanceof Error ? error.message : 'Unreadable payload.');
68
+ }
69
+ const tx = store.database.transaction([METADATA, PAYLOADS], 'readwrite');
70
+ const settled = await settleTransaction(tx.done, () => tx.abort(), async () => writeFile(tx, input.metadata, payload, input.resolveConflict));
71
+ if (!settled.ok)
72
+ return settled;
73
+ if (settled.value.type === 'conflict') {
74
+ return failure('conflict', 'A file with this id already exists.');
75
+ }
76
+ if (settled.value.type === 'rejected')
77
+ return failure('validation', settled.value.detail);
78
+ return { ok: true, value: settled.value.metadata };
79
+ }
80
+ async function writeFile(tx, metadata, payload, resolveConflict) {
81
+ const metaStore = tx.objectStore(METADATA);
82
+ const payloadStore = tx.objectStore(PAYLOADS);
83
+ const existing = (await metaStore.get(metadata.id));
84
+ let nextMetadata = { ...metadata, byteLength: payload.byteLength };
85
+ let nextPayload = payload;
86
+ if (existing !== undefined) {
87
+ if (!resolveConflict)
88
+ return { type: 'conflict' };
89
+ const storedPayload = (await payloadStore.get(metadata.id));
90
+ const local = {
91
+ metadata: existing,
92
+ payload: storedPayload ?? new Uint8Array(),
93
+ };
94
+ const incoming = { metadata: nextMetadata, payload: nextPayload };
95
+ let resolved;
96
+ try {
97
+ resolved = resolveConflict(local, incoming);
98
+ }
99
+ catch (error) {
100
+ return {
101
+ type: 'rejected',
102
+ detail: error instanceof Error ? error.message : 'Conflict policy failed.',
103
+ };
104
+ }
105
+ if (!resolved)
106
+ return { type: 'conflict' };
107
+ const resolvedError = metadataError(resolved.metadata);
108
+ if (resolvedError)
109
+ return { type: 'rejected', detail: resolvedError };
110
+ nextPayload = resolved.payload;
111
+ nextMetadata = { ...resolved.metadata, byteLength: nextPayload.byteLength };
112
+ }
113
+ await metaStore.put(nextMetadata, nextMetadata.id);
114
+ await payloadStore.put(nextPayload, nextMetadata.id);
115
+ return { type: 'written', metadata: nextMetadata };
116
+ }
117
+ export async function getFile(store, id) {
118
+ const tx = store.database.transaction([METADATA, PAYLOADS], 'readonly');
119
+ return settleTransaction(tx.done, () => tx.abort(), async () => {
120
+ const metadata = (await tx.objectStore(METADATA).get(id));
121
+ if (metadata === undefined)
122
+ return undefined;
123
+ const payload = (await tx.objectStore(PAYLOADS).get(id));
124
+ if (payload === undefined) {
125
+ throw new DOMException('File payload is missing.', 'DataError');
126
+ }
127
+ return { metadata, payload };
128
+ });
129
+ }
130
+ export async function getFileMetadata(store, id) {
131
+ const tx = store.database.transaction(METADATA, 'readonly');
132
+ return settleTransaction(tx.done, () => tx.abort(), async () => {
133
+ return (await tx.store.get(id));
134
+ });
135
+ }
136
+ export async function listFiles(store) {
137
+ const tx = store.database.transaction(METADATA, 'readonly');
138
+ return settleTransaction(tx.done, () => tx.abort(), async () => {
139
+ return (await tx.store.getAll());
140
+ });
141
+ }
142
+ //# sourceMappingURL=file-store.js.map
@@ -0,0 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,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC5D,OAAO,iBAAiB,CACtB,EAAE,CAAC,IAAI,EACP,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAChB,KAAK,IAAI,EAAE;QACT,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAQ,CAAC;IAC1C,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { IDBPDatabase } from 'idb';
2
+ import { type StoreMigration } from './database.js';
3
+ import { type StorageResult, type Validator } from './status.js';
4
+ export interface LocalStore {
5
+ readonly namespace: string;
6
+ readonly database: IDBPDatabase;
7
+ close(): void;
8
+ }
9
+ export interface OpenStoreOptions {
10
+ namespace: string;
11
+ /** Integer schema version, starting at 1. */
12
+ version: number;
13
+ /**
14
+ * Versioned migration. `oldVersion` is 0 the first time the database is
15
+ * created. The `records` store already exists. Do not delete stores that
16
+ * hold data you still need.
17
+ */
18
+ upgrade?: ((database: StoreMigration, oldVersion: number) => void) | undefined;
19
+ }
20
+ export declare function openStore(options: OpenStoreOptions): Promise<StorageResult<LocalStore>>;
21
+ export declare function getRecord<T>(store: LocalStore, key: string, validate?: Validator<T>): Promise<StorageResult<T | undefined>>;
22
+ export declare function putRecord<T>(store: LocalStore, key: string, value: T, validate?: Validator<T>): Promise<StorageResult<T>>;
23
+ export declare function deleteRecord(store: LocalStore, key: string): Promise<StorageResult<true>>;
24
+ export interface RecordTransaction {
25
+ get(key: string): Promise<unknown>;
26
+ put(key: string, value: unknown): Promise<void>;
27
+ delete(key: string): Promise<void>;
28
+ abort(): void;
29
+ }
30
+ /**
31
+ * Run several record operations in one transaction.
32
+ *
33
+ * The result is `{ ok: true }` only after the transaction commits. `put`
34
+ * inside the callback resolves when that request succeeds, which can be
35
+ * earlier; do not treat that request promise as a committed save.
36
+ */
37
+ export declare function withTransaction<T>(store: LocalStore, mode: 'readonly' | 'readwrite', run: (tx: RecordTransaction) => Promise<T> | T): Promise<StorageResult<T>>;
38
+ //# sourceMappingURL=idb-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idb-store.d.ts","sourceRoot":"","sources":["../../src/persist/idb-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,KAAK,CAAC;AACxC,OAAO,EAAmB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAerB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,6CAA6C;IAC7C,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CAChF;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAmB7F;AAMD,wBAAsB,SAAS,CAAC,CAAC,EAC/B,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAoBvC;AAED,wBAAsB,SAAS,CAAC,CAAC,EAC/B,KAAK,EAAE,UAAU,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,CAAC,EACR,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GACtB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAe3B;AAED,wBAAsB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAY/F;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,GAAG,EAAE,CAAC,EAAE,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAC7C,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAqC3B"}
@@ -0,0 +1,116 @@
1
+ import { openFasDatabase } from './database.js';
2
+ import { checkSegment, failure, settleTransaction, } from './status.js';
3
+ /**
4
+ * Recommended IndexedDB integration.
5
+ *
6
+ * The caller owns the record shape, the validator, and the version upgrade.
7
+ * `putRecord`, `deleteRecord`, and `withTransaction` resolve successfully only
8
+ * after the IndexedDB transaction completes (`tx.done`). There is no success
9
+ * toast here. A failed transaction leaves the previous record in place.
10
+ *
11
+ * Device-only. This database is not copied to `fas.kv`.
12
+ */
13
+ const RECORDS = 'records';
14
+ export async function openStore(options) {
15
+ const opened = await openFasDatabase({
16
+ namespace: options.namespace,
17
+ version: options.version,
18
+ stores: [RECORDS],
19
+ upgrade: options.upgrade,
20
+ });
21
+ if (!opened.ok)
22
+ return opened;
23
+ const database = opened.value;
24
+ return {
25
+ ok: true,
26
+ value: {
27
+ namespace: options.namespace,
28
+ database,
29
+ close() {
30
+ database.close();
31
+ },
32
+ },
33
+ };
34
+ }
35
+ function recordKey(key) {
36
+ return checkSegment(key, 'Key');
37
+ }
38
+ export async function getRecord(store, key, validate) {
39
+ const checked = recordKey(key);
40
+ if (!checked.ok)
41
+ return checked;
42
+ const tx = store.database.transaction(RECORDS, 'readonly');
43
+ const settled = await settleTransaction(tx.done, () => tx.abort(), async () => {
44
+ // idb resolves a missing key to undefined. The untyped database schema
45
+ // types that result as any, so the cast restores the caller's record type.
46
+ const raw = (await tx.store.get(checked.value));
47
+ return raw;
48
+ });
49
+ if (!settled.ok)
50
+ return settled;
51
+ if (settled.value === undefined)
52
+ return { ok: true, value: undefined };
53
+ if (validate && !validate(settled.value)) {
54
+ return failure('validation', 'Stored record did not match the validator.');
55
+ }
56
+ return { ok: true, value: settled.value };
57
+ }
58
+ export async function putRecord(store, key, value, validate) {
59
+ const checked = recordKey(key);
60
+ if (!checked.ok)
61
+ return checked;
62
+ if (validate && !validate(value)) {
63
+ return failure('validation', 'Value did not match the validator.');
64
+ }
65
+ const tx = store.database.transaction(RECORDS, 'readwrite');
66
+ return settleTransaction(tx.done, () => tx.abort(), async () => {
67
+ await tx.store.put(value, checked.value);
68
+ return value;
69
+ });
70
+ }
71
+ export async function deleteRecord(store, key) {
72
+ const checked = recordKey(key);
73
+ if (!checked.ok)
74
+ return checked;
75
+ const tx = store.database.transaction(RECORDS, 'readwrite');
76
+ return settleTransaction(tx.done, () => tx.abort(), async () => {
77
+ await tx.store.delete(checked.value);
78
+ return true;
79
+ });
80
+ }
81
+ /**
82
+ * Run several record operations in one transaction.
83
+ *
84
+ * The result is `{ ok: true }` only after the transaction commits. `put`
85
+ * inside the callback resolves when that request succeeds, which can be
86
+ * earlier; do not treat that request promise as a committed save.
87
+ */
88
+ export async function withTransaction(store, mode, run) {
89
+ // Split the mode so put and delete keep their receiver. A union mode types
90
+ // those methods as `function | undefined`, and detaching them drops `this`.
91
+ if (mode === 'readonly') {
92
+ const tx = store.database.transaction(RECORDS, 'readonly');
93
+ return settleTransaction(tx.done, () => tx.abort(), async () => run({
94
+ get: (key) => tx.store.get(key),
95
+ put: async () => {
96
+ throw new DOMException('This transaction is read-only.', 'ReadOnlyError');
97
+ },
98
+ delete: async () => {
99
+ throw new DOMException('This transaction is read-only.', 'ReadOnlyError');
100
+ },
101
+ abort: () => tx.abort(),
102
+ }));
103
+ }
104
+ const tx = store.database.transaction(RECORDS, 'readwrite');
105
+ return settleTransaction(tx.done, () => tx.abort(), async () => run({
106
+ get: (key) => tx.store.get(key),
107
+ put: async (key, value) => {
108
+ await tx.store.put(value, key);
109
+ },
110
+ delete: async (key) => {
111
+ await tx.store.delete(key);
112
+ },
113
+ abort: () => tx.abort(),
114
+ }));
115
+ }
116
+ //# sourceMappingURL=idb-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idb-store.js","sourceRoot":"","sources":["../../src/persist/idb-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAuB,MAAM,eAAe,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,OAAO,EAEP,iBAAiB,GAElB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;GASG;AAEH,MAAM,OAAO,GAAG,SAAS,CAAC;AAoB1B,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAyB;IACvD,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC;QACnC,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,CAAC,OAAO,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,MAAM,CAAC;IAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;IAC9B,OAAO;QACL,EAAE,EAAE,IAAI;QACR,KAAK,EAAE;YACL,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ;YACR,KAAK;gBAC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,KAAK,EAAE,GAAG,EAAE,EAAE;YACpB,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;QACD,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE;KACxB,CAAC,CACL,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Device-local persistence helpers.
3
+ *
4
+ * Data written here stays on this origin on this device. It is wiped when the
5
+ * user clears site data, and it is not a backup.
6
+ *
7
+ * Account-backed and shared data use different APIs:
8
+ * - Private account: `fas.kv` (the signed-in user's keys for this app, on the server).
9
+ * - Public shared: `fas.collections` (public read, owner writes).
10
+ * - Room fan-out: `fas.rooms` (ephemeral; not an access-control list).
11
+ *
12
+ * A failed save returns `{ ok: false, reason }` and must not be presented as
13
+ * saved. Corrupt preference JSON and unreadable records are left in place.
14
+ * `watchPreference` reports that another context changed a key. It does not
15
+ * merge and it does not resolve conflicts. File conflicts use the
16
+ * app-supplied `resolveConflict` policy.
17
+ */
18
+ export { getCapability, installCapability, type StorageCapability } from './capability.js';
19
+ export type { StoreMigration } from './database.js';
20
+ export type { FileMetadata, FileStore, StoredFile } from './file-store.js';
21
+ export { getFile, getFileMetadata, listFiles, openFileStore, putFile, } from './file-store.js';
22
+ export type { LocalStore, OpenStoreOptions, RecordTransaction } from './idb-store.js';
23
+ export { deleteRecord, getRecord, openStore, putRecord, withTransaction, } from './idb-store.js';
24
+ export type { PreferenceNotice } from './prefs.js';
25
+ export { getPreference, preferenceKey, removePreference, setPreference, watchPreference, } from './prefs.js';
26
+ export type { StorageFailure, StorageResult, Validator } from './status.js';
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/persist/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,YAAY,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EACL,OAAO,EACP,eAAe,EACf,SAAS,EACT,aAAa,EACb,OAAO,GACR,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EACL,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Device-local persistence helpers.
3
+ *
4
+ * Data written here stays on this origin on this device. It is wiped when the
5
+ * user clears site data, and it is not a backup.
6
+ *
7
+ * Account-backed and shared data use different APIs:
8
+ * - Private account: `fas.kv` (the signed-in user's keys for this app, on the server).
9
+ * - Public shared: `fas.collections` (public read, owner writes).
10
+ * - Room fan-out: `fas.rooms` (ephemeral; not an access-control list).
11
+ *
12
+ * A failed save returns `{ ok: false, reason }` and must not be presented as
13
+ * saved. Corrupt preference JSON and unreadable records are left in place.
14
+ * `watchPreference` reports that another context changed a key. It does not
15
+ * merge and it does not resolve conflicts. File conflicts use the
16
+ * app-supplied `resolveConflict` policy.
17
+ */
18
+ export { getCapability, installCapability } from './capability.js';
19
+ export { getFile, getFileMetadata, listFiles, openFileStore, putFile, } from './file-store.js';
20
+ export { deleteRecord, getRecord, openStore, putRecord, withTransaction, } from './idb-store.js';
21
+ export { getPreference, preferenceKey, removePreference, setPreference, watchPreference, } from './prefs.js';
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/persist/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAA0B,MAAM,iBAAiB,CAAC;AAG3F,OAAO,EACL,OAAO,EACP,eAAe,EACf,SAAS,EACT,aAAa,EACb,OAAO,GACR,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,eAAe,GAChB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type StorageResult, type Validator } from './status.js';
2
+ /**
3
+ * Safe preference storage on `localStorage`.
4
+ *
5
+ * Keys are `fas:<namespace>:<key>`. Values are JSON. A validator rejects a
6
+ * value without deleting the stored bytes. Cross-tab `watchPreference` events
7
+ * are notifications that a key changed. They are not a merge and not conflict
8
+ * resolution: the app reads the key and applies its own policy.
9
+ *
10
+ * Device-only. This is not `fas.kv` and not an account backup.
11
+ */
12
+ export interface PreferenceNotice {
13
+ namespace: string;
14
+ key: string;
15
+ kind: 'set' | 'remove';
16
+ /** Always this literal. The notice carries no merged value. */
17
+ notification: 'storage-changed';
18
+ }
19
+ export declare function preferenceKey(namespace: string, key: string): StorageResult<string>;
20
+ export declare function getPreference<T>(namespace: string, key: string, validate?: Validator<T>): StorageResult<T | undefined>;
21
+ export declare function setPreference<T>(namespace: string, key: string, value: T, validate?: Validator<T>): StorageResult<T>;
22
+ export declare function removePreference(namespace: string, key: string): StorageResult<true>;
23
+ /**
24
+ * Subscribe to preference changes.
25
+ *
26
+ * The `storage` event covers other tabs. `BroadcastChannel` covers other
27
+ * listeners, including this tab, after a successful write. Neither path
28
+ * merges values or picks a winner. Read the key again and apply an app-owned
29
+ * policy if two tabs disagree.
30
+ */
31
+ export declare function watchPreference(namespace: string, key: string, listener: (notice: PreferenceNotice) => void): () => void;
32
+ //# sourceMappingURL=prefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefs.d.ts","sourceRoot":"","sources":["../../src/persist/prefs.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,SAAS,EACf,MAAM,aAAa,CAAC;AAErB;;;;;;;;;GASG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,+DAA+D;IAC/D,YAAY,EAAE,iBAAiB,CAAC;CACjC;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAMnF;AAuBD,wBAAgB,aAAa,CAAC,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GACtB,aAAa,CAAC,CAAC,GAAG,SAAS,CAAC,CA0B9B;AAED,wBAAgB,aAAa,CAAC,CAAC,EAC7B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,CAAC,EACR,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GACtB,aAAa,CAAC,CAAC,CAAC,CAuBlB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,CAYpF;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAC3C,MAAM,IAAI,CA4CZ"}
@@ -0,0 +1,168 @@
1
+ import { checkSegment, classifyStorageError, errorMessage, failure, } from './status.js';
2
+ export function preferenceKey(namespace, key) {
3
+ const ns = checkSegment(namespace, 'Namespace');
4
+ if (!ns.ok)
5
+ return ns;
6
+ const segment = checkSegment(key, 'Key');
7
+ if (!segment.ok)
8
+ return segment;
9
+ return { ok: true, value: `fas:${ns.value}:${segment.value}` };
10
+ }
11
+ function storageArea() {
12
+ try {
13
+ if (typeof window === 'undefined' || window.localStorage == null)
14
+ return null;
15
+ return window.localStorage;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ function notify(namespace, key, kind) {
22
+ if (typeof BroadcastChannel === 'undefined')
23
+ return;
24
+ const notice = { namespace, key, kind, notification: 'storage-changed' };
25
+ try {
26
+ const channel = new BroadcastChannel(`fas:prefs:${namespace}`);
27
+ channel.postMessage(notice);
28
+ channel.close();
29
+ }
30
+ catch {
31
+ // The write already committed. A missing channel does not undo it.
32
+ }
33
+ }
34
+ export function getPreference(namespace, key, validate) {
35
+ const storageKey = preferenceKey(namespace, key);
36
+ if (!storageKey.ok)
37
+ return storageKey;
38
+ const area = storageArea();
39
+ if (!area)
40
+ return failure('unavailable', 'localStorage is not available.');
41
+ let raw;
42
+ try {
43
+ raw = area.getItem(storageKey.value);
44
+ }
45
+ catch (error) {
46
+ return failure(classifyStorageError(error), errorMessage(error));
47
+ }
48
+ if (raw === null)
49
+ return { ok: true, value: undefined };
50
+ let parsed;
51
+ try {
52
+ parsed = JSON.parse(raw);
53
+ }
54
+ catch {
55
+ // Leave the unreadable bytes in place. Callers decide whether to overwrite.
56
+ return failure('corrupt', 'Stored value is not valid JSON.');
57
+ }
58
+ if (validate) {
59
+ if (!validate(parsed)) {
60
+ return failure('validation', 'Stored value did not match the validator.');
61
+ }
62
+ return { ok: true, value: parsed };
63
+ }
64
+ return { ok: true, value: parsed };
65
+ }
66
+ export function setPreference(namespace, key, value, validate) {
67
+ const storageKey = preferenceKey(namespace, key);
68
+ if (!storageKey.ok)
69
+ return storageKey;
70
+ if (validate && !validate(value)) {
71
+ return failure('validation', 'Value did not match the validator.');
72
+ }
73
+ let encoded;
74
+ try {
75
+ const json = JSON.stringify(value);
76
+ if (typeof json !== 'string')
77
+ return failure('validation', 'Value is not JSON.');
78
+ encoded = json;
79
+ }
80
+ catch {
81
+ return failure('validation', 'Value is not JSON.');
82
+ }
83
+ const area = storageArea();
84
+ if (!area)
85
+ return failure('unavailable', 'localStorage is not available.');
86
+ try {
87
+ area.setItem(storageKey.value, encoded);
88
+ }
89
+ catch (error) {
90
+ return failure(classifyStorageError(error), errorMessage(error));
91
+ }
92
+ notify(namespace, key, 'set');
93
+ return { ok: true, value };
94
+ }
95
+ export function removePreference(namespace, key) {
96
+ const storageKey = preferenceKey(namespace, key);
97
+ if (!storageKey.ok)
98
+ return storageKey;
99
+ const area = storageArea();
100
+ if (!area)
101
+ return failure('unavailable', 'localStorage is not available.');
102
+ try {
103
+ area.removeItem(storageKey.value);
104
+ }
105
+ catch (error) {
106
+ return failure(classifyStorageError(error), errorMessage(error));
107
+ }
108
+ notify(namespace, key, 'remove');
109
+ return { ok: true, value: true };
110
+ }
111
+ /**
112
+ * Subscribe to preference changes.
113
+ *
114
+ * The `storage` event covers other tabs. `BroadcastChannel` covers other
115
+ * listeners, including this tab, after a successful write. Neither path
116
+ * merges values or picks a winner. Read the key again and apply an app-owned
117
+ * policy if two tabs disagree.
118
+ */
119
+ export function watchPreference(namespace, key, listener) {
120
+ const storageKey = preferenceKey(namespace, key);
121
+ if (!storageKey.ok || typeof window === 'undefined')
122
+ return () => undefined;
123
+ const onStorage = (event) => {
124
+ if (event.key !== null && event.key !== storageKey.value)
125
+ return;
126
+ try {
127
+ if (event.storageArea && event.storageArea !== window.localStorage)
128
+ return;
129
+ }
130
+ catch {
131
+ return;
132
+ }
133
+ listener({
134
+ namespace,
135
+ key,
136
+ kind: event.key !== null && event.newValue !== null ? 'set' : 'remove',
137
+ notification: 'storage-changed',
138
+ });
139
+ };
140
+ window.addEventListener('storage', onStorage);
141
+ let channel;
142
+ try {
143
+ if (typeof BroadcastChannel !== 'undefined') {
144
+ channel = new BroadcastChannel(`fas:prefs:${namespace}`);
145
+ channel.onmessage = (event) => {
146
+ const notice = event.data;
147
+ if (!notice || notice.namespace !== namespace || notice.key !== key)
148
+ return;
149
+ if (notice.notification !== 'storage-changed')
150
+ return;
151
+ listener({
152
+ namespace,
153
+ key,
154
+ kind: notice.kind === 'remove' ? 'remove' : 'set',
155
+ notification: 'storage-changed',
156
+ });
157
+ };
158
+ }
159
+ }
160
+ catch {
161
+ channel = undefined;
162
+ }
163
+ return () => {
164
+ window.removeEventListener('storage', onStorage);
165
+ channel?.close();
166
+ };
167
+ }
168
+ //# sourceMappingURL=prefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefs.js","sourceRoot":"","sources":["../../src/persist/prefs.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,OAAO,GAGR,MAAM,aAAa,CAAC;AAqBrB,MAAM,UAAU,aAAa,CAAC,SAAiB,EAAE,GAAW;IAC1D,MAAM,EAAE,GAAG,YAAY,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAChD,IAAI,CAAC,EAAE,CAAC,EAAE;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,OAAO,CAAC;IAChC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;AACjE,CAAC;AAED,SAAS,WAAW;IAClB,IAAI,CAAC;QACH,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,YA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AAK,iBAAiB;oBAAE,OAAO;gBACtD,QAAQ,CAAC;oBACP,SAAS;oBACT,GAAG;oBACH,IAAI,EAAE,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK;oBACjD,YAAY,EAAE,iBAAiB;iBAChC,CAAC,CAAC;YACL,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,SAAS,CAAC;IACtB,CAAC;IAED,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACjD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Device-local storage results.
3
+ *
4
+ * These helpers never report success before the write is committed, and they
5
+ * never delete unreadable data. Account-backed data is a different API:
6
+ * `fas.kv` stores the signed-in user's keys on the server. Public documents
7
+ * use `fas.collections`. Room messages are ephemeral. None of those are
8
+ * replaced by this module.
9
+ */
10
+ export type StorageFailure = 'unavailable' | 'corrupt' | 'quota' | 'validation' | 'aborted' | 'conflict' | 'not-installed';
11
+ export type StorageResult<T> = {
12
+ ok: true;
13
+ value: T;
14
+ } | {
15
+ ok: false;
16
+ reason: StorageFailure;
17
+ detail?: string;
18
+ };
19
+ export type Validator<T> = (value: unknown) => value is T;
20
+ export declare function failure(reason: StorageFailure, detail?: string): StorageResult<never>;
21
+ export declare function checkSegment(value: string, label: string): StorageResult<string>;
22
+ export declare function classifyStorageError(error: unknown): StorageFailure;
23
+ export declare function errorMessage(error: unknown): string | undefined;
24
+ /**
25
+ * Run `work`, then wait until `done` settles. Success is returned only after
26
+ * `done`. A rejection aborts the transaction and does not report success.
27
+ */
28
+ export declare function settleTransaction<T>(done: Promise<void>, abort: () => void, work: () => Promise<T>): Promise<StorageResult<T>>;
29
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/persist/status.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GACtB,aAAa,GACb,SAAS,GACT,OAAO,GACP,YAAY,GACZ,SAAS,GACT,UAAU,GACV,eAAe,CAAC;AAEpB,MAAM,MAAM,aAAa,CAAC,CAAC,IACvB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC;AAI1D,wBAAgB,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAGrF;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAQhF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAUnE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAG/D;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACvC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,EACnB,KAAK,EAAE,MAAM,IAAI,EACjB,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAc3B"}
@@ -0,0 +1,53 @@
1
+ const SEGMENT = /^[A-Za-z0-9._-]{1,64}$/;
2
+ export function failure(reason, detail) {
3
+ if (detail)
4
+ return { ok: false, reason, detail };
5
+ return { ok: false, reason };
6
+ }
7
+ export function checkSegment(value, label) {
8
+ if (!SEGMENT.test(value)) {
9
+ return failure('validation', `${label} must be 1-64 characters: letters, digits, ".", "_" or "-".`);
10
+ }
11
+ return { ok: true, value };
12
+ }
13
+ export function classifyStorageError(error) {
14
+ const name = error instanceof Error ? error.name : '';
15
+ const code = error instanceof DOMException ? error.code : 0;
16
+ if (name === 'QuotaExceededError' || name === 'NS_ERROR_DOM_QUOTA_REACHED' || code === 22) {
17
+ return 'quota';
18
+ }
19
+ if (name === 'AbortError' || name === 'TransactionInactiveError')
20
+ return 'aborted';
21
+ if (name === 'DataCloneError')
22
+ return 'validation';
23
+ if (name === 'DataError')
24
+ return 'corrupt';
25
+ return 'unavailable';
26
+ }
27
+ export function errorMessage(error) {
28
+ if (error instanceof Error && error.message)
29
+ return error.message;
30
+ return undefined;
31
+ }
32
+ /**
33
+ * Run `work`, then wait until `done` settles. Success is returned only after
34
+ * `done`. A rejection aborts the transaction and does not report success.
35
+ */
36
+ export async function settleTransaction(done, abort, work) {
37
+ try {
38
+ const value = await work();
39
+ await done;
40
+ return { ok: true, value };
41
+ }
42
+ catch (error) {
43
+ try {
44
+ abort();
45
+ }
46
+ catch {
47
+ // Already aborting or finished.
48
+ }
49
+ done.catch(() => undefined);
50
+ return failure(classifyStorageError(error), errorMessage(error));
51
+ }
52
+ }
53
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/persist/status.ts"],"names":[],"mappings":"AAwBA,MAAM,OAAO,GAAG,wBAAwB,CAAC;AAEzC,MAAM,UAAU,OAAO,CAAC,MAAsB,EAAE,MAAe;IAC7D,IAAI,MAAM;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KA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,KAAK,EAAE,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC;YACH,KAAK,EAAE,CAAC;QACV,CAAC;QAAC,MAAM,CAAC;YACP,gCAAgC;QAClC,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC5B,OAAO,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@freeappstore/sdk",
3
- "version": "0.16.17",
4
- "description": "Browser SDK for FreeAppStore — auth, KV, collections, counters, rooms, proxy, encrypted user keys, roles, friends, email, push reminders, React hooks, and UI components.",
3
+ "version": "0.16.18",
4
+ "description": "Browser SDK for FreeAppStore — auth, KV, collections, counters, rooms, proxy, encrypted user keys, roles, friends, email, push reminders, device-local persistence, React hooks, and UI components.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
@@ -30,6 +30,10 @@
30
30
  "./pwa-config": {
31
31
  "types": "./dist/pwa-config.d.ts",
32
32
  "import": "./dist/pwa-config.js"
33
+ },
34
+ "./persist": {
35
+ "types": "./dist/persist/index.d.ts",
36
+ "import": "./dist/persist/index.js"
33
37
  }
34
38
  },
35
39
  "homepage": "https://github.com/freeappstore-online/platform#readme",
@@ -72,6 +76,7 @@
72
76
  "devDependencies": {
73
77
  "@types/react": "^19.3.0",
74
78
  "@types/react-dom": "^19.3.0",
79
+ "fake-indexeddb": "^6.2.7",
75
80
  "happy-dom": "^20.14.5",
76
81
  "react": "^19.3.0",
77
82
  "react-dom": "^19.3.0",
@@ -79,6 +84,9 @@
79
84
  "vite-plugin-pwa": "^1.3.0"
80
85
  },
81
86
  "sideEffects": false,
87
+ "dependencies": {
88
+ "idb": "^8.0.4"
89
+ },
82
90
  "scripts": {
83
91
  "build": "tsc",
84
92
  "typecheck": "tsc --noEmit"