@interop/was-react 0.13.1 → 0.15.0
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 +70 -29
- package/dist/auth/walletRequestTypes.d.ts +30 -47
- package/dist/auth/walletRequestTypes.d.ts.map +1 -1
- package/dist/config.d.ts +28 -18
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +0 -0
- package/dist/config.js.map +1 -1
- package/dist/dev/provisionDevGrants.d.ts +7 -3
- package/dist/dev/provisionDevGrants.d.ts.map +1 -1
- package/dist/dev/provisionDevGrants.js +19 -7
- package/dist/dev/provisionDevGrants.js.map +1 -1
- package/dist/identity/seedCredential.d.ts +15 -13
- package/dist/identity/seedCredential.d.ts.map +1 -1
- package/dist/identity/seedCredential.js +15 -16
- package/dist/identity/seedCredential.js.map +1 -1
- package/dist/identity/seedStore.d.ts.map +1 -1
- package/dist/identity/seedStore.js +4 -3
- package/dist/identity/seedStore.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react/documentApp.d.ts +5 -5
- package/dist/react/documentApp.d.ts.map +1 -1
- package/dist/react/documentApp.js +14 -17
- package/dist/react/documentApp.js.map +1 -1
- package/dist/session/authStore.d.ts +4 -3
- package/dist/session/authStore.d.ts.map +1 -1
- package/dist/session/authStore.js +89 -55
- package/dist/session/authStore.js.map +1 -1
- package/dist/storage/adopt.d.ts +6 -5
- package/dist/storage/adopt.d.ts.map +1 -1
- package/dist/storage/adopt.js +22 -10
- package/dist/storage/adopt.js.map +1 -1
- package/dist/storage/entityStore.d.ts +37 -9
- package/dist/storage/entityStore.d.ts.map +1 -1
- package/dist/storage/entityStore.js +19 -9
- package/dist/storage/entityStore.js.map +1 -1
- package/dist/storage/localStore.d.ts.map +1 -1
- package/dist/storage/localStore.js +51 -61
- package/dist/storage/localStore.js.map +1 -1
- package/dist/storage/sharedCollectionReader.d.ts.map +1 -1
- package/dist/storage/sharedCollectionReader.js +15 -14
- package/dist/storage/sharedCollectionReader.js.map +1 -1
- package/dist/storage/storageManager.d.ts +30 -0
- package/dist/storage/storageManager.d.ts.map +1 -1
- package/dist/storage/storageManager.js +46 -0
- package/dist/storage/storageManager.js.map +1 -1
- package/dist/storage/wasRemoteStore.d.ts +99 -28
- package/dist/storage/wasRemoteStore.d.ts.map +1 -1
- package/dist/storage/wasRemoteStore.js +205 -30
- package/dist/storage/wasRemoteStore.js.map +1 -1
- package/dist/storage/wasSync.d.ts +17 -6
- package/dist/storage/wasSync.d.ts.map +1 -1
- package/dist/storage/wasSync.js +39 -9
- package/dist/storage/wasSync.js.map +1 -1
- package/package.json +4 -4
|
@@ -61,9 +61,10 @@ export function createSeedStore({ dbName, idb = indexedDB }) {
|
|
|
61
61
|
return stored ?? null;
|
|
62
62
|
},
|
|
63
63
|
async clearSeedStore() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
// The object store holds exactly the seed, the session record, and the
|
|
65
|
+
// descriptor cache, so one `clear()` is the whole wipe in one
|
|
66
|
+
// transaction.
|
|
67
|
+
await withSessionStore('readwrite', store => store.clear());
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seedStore.js","sourceRoot":"","sources":["../../src/identity/seedStore.ts"],"names":[],"mappings":"AAqBA,MAAM,aAAa,GAAG,SAAS,CAAA;AAC/B,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,MAAM,cAAc,GAAG,QAAQ,CAAA;AAC/B,MAAM,kBAAkB,GAAG,aAAa,CAAA;AAuCxC;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,GAAG,GAAG,SAAS,EAIhB;IACC,KAAK,UAAU,aAAa;QAC1B,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;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EAAE;gBAClC,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAA;gBACnC,WAAW,CAAC,YAAY,CAAC,GAAG,UAAU,CAAA;gBACtC,MAAM,KAAK,CAAC,eAAe,CAAC,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAA;YAC1D,CAAC,CAAC,CAAA;YACF,MAAM,GAAG,IAAI,CAAC,IAAI,CAChB,GAAG,EAAE,GAAE,CAAC,EACR,GAAG,EAAE,GAAE,CAAC,CACT,CAAA;YACD,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* `@interop/was-react/mui`; the Node-only dev-grant provisioner lives at
|
|
11
11
|
* `@interop/was-react/dev`. Neither is re-exported here.
|
|
12
12
|
*/
|
|
13
|
-
export { DEFAULT_DB_NAME, DEFAULT_STORAGE_KEY_PREFIX, DEFAULT_SYNC_POLL_MS, DEFAULT_EXPIRY_WARNING_MS, DEFAULT_EXPIRY_WATCH_MS,
|
|
13
|
+
export { DEFAULT_DB_NAME, DEFAULT_STORAGE_KEY_PREFIX, DEFAULT_SYNC_POLL_MS, DEFAULT_EXPIRY_WARNING_MS, DEFAULT_EXPIRY_WATCH_MS, validateCollections, validateSharedCollections, type WasCollectionConfig, type SharedCollectionConfig, type WasSyncConfig, type WasExpiryConfig, type WasAppConfig, type StoreRegistryEntry, type StoreRegistry } from './config.js';
|
|
14
14
|
export { parseInvocationTarget, parseGrants, type ParsedGrants } from './grants.js';
|
|
15
15
|
export { deriveIdentity, DEFAULT_IDENTITY_HANDLE, type IdentityAgents } from './identity/agents.js';
|
|
16
16
|
export { createDocumentLoader, type DocumentLoader } from './identity/documentLoader.js';
|
|
@@ -24,7 +24,7 @@ export { loginWithWallet, requestGrants, LoginCancelledError, WalletUnsupportedE
|
|
|
24
24
|
export type { IVPRDetails, IVPRQuery, IDIDAuthenticationQuery, IAppConnectQuery, IAppConnectCapabilityQuery, ICapabilityQueryDetail, IVerifiableCredential, IVerifiablePresentation, IZcap } from './auth/walletRequestTypes.js';
|
|
25
25
|
export * from './sync/index.js';
|
|
26
26
|
export { LocalStore } from './storage/localStore.js';
|
|
27
|
-
export { setLocalStore, requireStore, hasStore, clearLocalStore, setRemoteStore, requireRemoteStore, hasRemoteStore, clearRemoteStore, getWriterId } from './storage/storageManager.js';
|
|
27
|
+
export { setLocalStore, requireStore, hasStore, clearLocalStore, setRemoteStore, requireRemoteStore, hasRemoteStore, clearRemoteStore, getWriterId, setWriterId, requireWriterId, stampLww } from './storage/storageManager.js';
|
|
28
28
|
export { createEntityStore, type EntityStore } from './storage/entityStore.js';
|
|
29
29
|
export { WasRemoteStore, remoteDescriptorSource, type DeclarationResult, type EqualityQueryPage } from './storage/wasRemoteStore.js';
|
|
30
30
|
export { SharedCollectionReader, SharedCollectionUnavailableError, SHARED_CHANGES_PAGE_SIZE, type SharedResource } from './storage/sharedCollectionReader.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;GAQG;AAGH,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;GAQG;AAGH,OAAO,EACL,eAAe,EACf,0BAA0B,EAC1B,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACnB,yBAAyB,EACzB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,aAAa,CAAA;AAGpB,O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A"}
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* `@interop/was-react/dev`. Neither is re-exported here.
|
|
12
12
|
*/
|
|
13
13
|
// Configuration contract.
|
|
14
|
-
export { DEFAULT_DB_NAME, DEFAULT_STORAGE_KEY_PREFIX, DEFAULT_SYNC_POLL_MS, DEFAULT_EXPIRY_WARNING_MS, DEFAULT_EXPIRY_WATCH_MS,
|
|
14
|
+
export { DEFAULT_DB_NAME, DEFAULT_STORAGE_KEY_PREFIX, DEFAULT_SYNC_POLL_MS, DEFAULT_EXPIRY_WARNING_MS, DEFAULT_EXPIRY_WATCH_MS, validateCollections, validateSharedCollections } from './config.js';
|
|
15
15
|
// Grant parsing / topology routing.
|
|
16
16
|
export { parseInvocationTarget, parseGrants } from './grants.js';
|
|
17
17
|
// Identity: the seed-derived agents, including the identity key-agreement key
|
|
@@ -32,7 +32,7 @@ export * from './sync/index.js';
|
|
|
32
32
|
// stores, the delegated remote store, sync status, rehydrate mechanism, and the
|
|
33
33
|
// replication controller.
|
|
34
34
|
export { LocalStore } from './storage/localStore.js';
|
|
35
|
-
export { setLocalStore, requireStore, hasStore, clearLocalStore, setRemoteStore, requireRemoteStore, hasRemoteStore, clearRemoteStore, getWriterId } from './storage/storageManager.js';
|
|
35
|
+
export { setLocalStore, requireStore, hasStore, clearLocalStore, setRemoteStore, requireRemoteStore, hasRemoteStore, clearRemoteStore, getWriterId, setWriterId, requireWriterId, stampLww } from './storage/storageManager.js';
|
|
36
36
|
export { createEntityStore } from './storage/entityStore.js';
|
|
37
37
|
export { WasRemoteStore, remoteDescriptorSource } from './storage/wasRemoteStore.js';
|
|
38
38
|
export { SharedCollectionReader, SharedCollectionUnavailableError, SHARED_CHANGES_PAGE_SIZE } from './storage/sharedCollectionReader.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;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@@
|
|
|
13
13
|
* The facade is a degenerate entity store: one collection (the app-named
|
|
14
14
|
* sandbox collection) holding one logical document under a fixed id. The
|
|
15
15
|
* stored row wraps the app's data (`{ id, updatedAt, writerId, data }`) so app
|
|
16
|
-
* fields can never collide with the LWW fields the sync layer requires
|
|
17
|
-
*
|
|
16
|
+
* fields can never collide with the LWW fields the sync layer requires; the
|
|
17
|
+
* entity store's write verbs stamp those fields on every write. Hydration
|
|
18
18
|
* goes through `LocalStore.hydrateSingleton`, which LWW-reconciles the
|
|
19
19
|
* duplicate envelope rows two devices can mint for the same logical document.
|
|
20
20
|
*
|
|
@@ -63,9 +63,9 @@ export interface DocumentApp<T extends object> {
|
|
|
63
63
|
doc: T | undefined;
|
|
64
64
|
/**
|
|
65
65
|
* Merge a partial patch (or apply an updater function) onto the current
|
|
66
|
-
* document and persist it
|
|
67
|
-
* encrypted local replica first and replicates in the
|
|
68
|
-
* connected.
|
|
66
|
+
* document and persist it (the write verb stamps the LWW fields). The write
|
|
67
|
+
* lands in the encrypted local replica first and replicates in the
|
|
68
|
+
* background when connected.
|
|
69
69
|
*/
|
|
70
70
|
update: (patch: Partial<T> | ((prev: T) => T)) => Promise<void>;
|
|
71
71
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentApp.d.ts","sourceRoot":"","sources":["../../src/react/documentApp.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,eAAe,EACf,aAAa,EACd,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAG5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAG/D;;GAEG;AACH,eAAO,MAAM,uBAAuB,aAAa,CAAA;AAOjD;;GAEG;AACH,eAAO,MAAM,sBAAsB,oBAAoB,CAAA;AAavD;;;GAGG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CAAA;QAChB;;WAEG;QACH,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;QAC/B;;;WAGG;QACH,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;QACzC;;;;;;;WAOG;QACH,OAAO,EAAE,MAAM,OAAO,CAAC;YAAE,QAAQ,EAAE,OAAO,CAAA;SAAE,GAAG,IAAI,CAAC,CAAA;QACpD;;;WAGG;QACH,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;QAC/B;;WAEG;QACH,UAAU,EAAE,OAAO,CAAA;QACnB;;WAEG;QACH,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;KACrB,CAAA;CACF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAAE,EAClD,OAAO,EACP,SAAS,EACT,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,gBAAgB,EAChB,IAAI,EACJ,MAAM,EACP,EAAE;IACD,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC,CAAA;KAAE,CAAA;IAC9C,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,MAAM,CAAC,EAAE,eAAe,CAAA;CACzB,GAAG,WAAW,CAAC,CAAC,CAAC,CA+HjB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEntityStore } from '../storage/entityStore.js';
|
|
2
|
-
import {
|
|
2
|
+
import { requireStore } from '../storage/storageManager.js';
|
|
3
3
|
import { useLogin, useLogout, useSyncStatus } from './hooks.js';
|
|
4
4
|
/**
|
|
5
5
|
* The localStore / RxDB collection key the facade's one collection uses.
|
|
@@ -35,11 +35,6 @@ export const DOCUMENT_EXPORT_FORMAT = 'was-document/v1';
|
|
|
35
35
|
export function defineDocumentApp({ appName, appOrigin, appUrl, mediatorBase, document, dbName, storageKeyPrefix, sync, expiry }) {
|
|
36
36
|
const { collectionId, initial } = document;
|
|
37
37
|
const docStore = createEntityStore(DOCUMENT_COLLECTION_KEY);
|
|
38
|
-
// Resolved once, under the same prefix the config hands the session layer,
|
|
39
|
-
// so the facade's stamps and the adoption repair share one identity.
|
|
40
|
-
const writerId = getWriterId({
|
|
41
|
-
...(storageKeyPrefix !== undefined && { storageKeyPrefix })
|
|
42
|
-
});
|
|
43
38
|
const config = {
|
|
44
39
|
appName,
|
|
45
40
|
appOrigin,
|
|
@@ -65,23 +60,26 @@ export function defineDocumentApp({ appName, appOrigin, appUrl, mediatorBase, do
|
|
|
65
60
|
clear: () => docStore.getState().replaceAll([])
|
|
66
61
|
}
|
|
67
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* The current document data -- `initial` until the first write lands. The
|
|
65
|
+
* imperative twin of the hook's reactive selector.
|
|
66
|
+
*
|
|
67
|
+
* @returns {T}
|
|
68
|
+
*/
|
|
69
|
+
function currentData() {
|
|
70
|
+
return docStore.getState().byId.get(DOCUMENT_ID)?.data ?? initial;
|
|
71
|
+
}
|
|
68
72
|
/**
|
|
69
73
|
* Merges the patch (or applies the updater) and persists the result under
|
|
70
|
-
* the fixed document id
|
|
74
|
+
* the fixed document id; the entity store's `upsert` stamps the LWW fields.
|
|
71
75
|
*
|
|
72
76
|
* @param patch {Partial<T> | ((prev: T) => T)}
|
|
73
77
|
* @returns {Promise<void>}
|
|
74
78
|
*/
|
|
75
79
|
async function update(patch) {
|
|
76
|
-
const
|
|
77
|
-
const prev = held?.data ?? initial;
|
|
80
|
+
const prev = currentData();
|
|
78
81
|
const data = typeof patch === 'function' ? patch(prev) : { ...prev, ...patch };
|
|
79
|
-
await docStore.getState().upsert({
|
|
80
|
-
id: DOCUMENT_ID,
|
|
81
|
-
updatedAt: new Date().toISOString(),
|
|
82
|
-
writerId,
|
|
83
|
-
data
|
|
84
|
-
});
|
|
82
|
+
await docStore.getState().upsert({ id: DOCUMENT_ID, data });
|
|
85
83
|
}
|
|
86
84
|
/**
|
|
87
85
|
* Serializes the current document (or `initial` before any write) into a
|
|
@@ -90,12 +88,11 @@ export function defineDocumentApp({ appName, appOrigin, appUrl, mediatorBase, do
|
|
|
90
88
|
* @returns {Promise<Blob>}
|
|
91
89
|
*/
|
|
92
90
|
async function exportFile() {
|
|
93
|
-
const held = docStore.getState().byId.get(DOCUMENT_ID);
|
|
94
91
|
const body = {
|
|
95
92
|
format: DOCUMENT_EXPORT_FORMAT,
|
|
96
93
|
app: appName,
|
|
97
94
|
exportedAt: new Date().toISOString(),
|
|
98
|
-
document:
|
|
95
|
+
document: currentData()
|
|
99
96
|
};
|
|
100
97
|
return new Blob([JSON.stringify(body, null, 2)], {
|
|
101
98
|
type: 'application/json'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentApp.js","sourceRoot":"","sources":["../../src/react/documentApp.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"documentApp.js","sourceRoot":"","sources":["../../src/react/documentApp.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAE3D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/D;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAA;AAEjD;;GAEG;AACH,MAAM,WAAW,GAAG,MAAM,CAAA;AAE1B;;GAEG;AACH,MAAM,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,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE;YACtB,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE;YAC1B,UAAU,EAAE,cAAc;YAC1B,KAAK;SACN,CAAA;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAA;AAC7C,CAAC"}
|
|
@@ -61,9 +61,10 @@ export interface AuthState {
|
|
|
61
61
|
onboarding: 'local-first' | 'login-gated';
|
|
62
62
|
/**
|
|
63
63
|
* The per-install LWW attribution id, resolved once at store creation from
|
|
64
|
-
* `WasAppConfig.storageKeyPrefix
|
|
65
|
-
*
|
|
66
|
-
*
|
|
64
|
+
* `WasAppConfig.storageKeyPrefix` and exposed for display and debugging. The
|
|
65
|
+
* entity-store write verbs and the adoption repair stamp it automatically, so
|
|
66
|
+
* an app never has to: one install writes under one identity either way. It
|
|
67
|
+
* is an attribution label, never an identity.
|
|
67
68
|
*/
|
|
68
69
|
writerId: string;
|
|
69
70
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authStore.d.ts","sourceRoot":"","sources":["../../src/session/authStore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AAIzD,OAAO,
|
|
1
|
+
{"version":3,"file":"authStore.d.ts","sourceRoot":"","sources":["../../src/session/authStore.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAAe,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;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UAAU,CAAA;QAChB,MAAM,EAAE,KAAK,EAAE,CAAA;QACf,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;KAC1B,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACnB;;OAEG;IACH,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B;;;;;;;OAOG;IACH,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvD;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC;;;;OAIG;IACH,YAAY,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IACpC,mBAAmB,EAAE,MAAM,IAAI,CAAA;IAC/B;;;;;;;;OAQG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAA;AAE9C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,QAAQ,EACR,SAAS,EACT,OAAO,EACR,EAAE;IACD,MAAM,EAAE,YAAY,CAAA;IACpB,QAAQ,EAAE,aAAa,CAAA;IACvB,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;CACtC,GAAG,YAAY,CAymCf"}
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
import { createStore } from 'zustand/vanilla';
|
|
37
37
|
import { acquireDescriptors } from '@interop/wallet-core/descriptors';
|
|
38
38
|
import { mintRecordEncryption } from '@interop/wallet-core/keyring';
|
|
39
|
-
import { DEFAULT_DB_NAME, DEFAULT_EXPIRY_WARNING_MS, DEFAULT_EXPIRY_WATCH_MS, DEFAULT_ONBOARDING } from '../config.js';
|
|
39
|
+
import { DEFAULT_DB_NAME, DEFAULT_EXPIRY_WARNING_MS, DEFAULT_EXPIRY_WATCH_MS, DEFAULT_ONBOARDING, isPublicCollection } from '../config.js';
|
|
40
40
|
import { createDocumentLoader } from '../identity/documentLoader.js';
|
|
41
41
|
import { deriveIdentity } from '../identity/agents.js';
|
|
42
42
|
import { createDescriptorCache, createSeedStore } from '../identity/seedStore.js';
|
|
@@ -44,7 +44,7 @@ import { clearAppSession, peekAppSession, persistAppSession, restoreAppSession,
|
|
|
44
44
|
import { loginWithWallet, requestGrants, LoginCancelledError } from '../auth/loginFlow.js';
|
|
45
45
|
import { parseGrants } from '../grants.js';
|
|
46
46
|
import { LocalStore, dbNameForController } from '../storage/localStore.js';
|
|
47
|
-
import { clearLocalStore, clearRemoteStore, getWriterId, hasStore, requireStore, setLocalStore, setRemoteStore } from '../storage/storageManager.js';
|
|
47
|
+
import { clearLocalStore, clearRemoteStore, getWriterId, hasStore, requireStore, setLocalStore, setRemoteStore, setWriterId } from '../storage/storageManager.js';
|
|
48
48
|
import { cancelScheduledRehydrates, clearAllEntityStores, hydrateAll, patchFromChange } from '../storage/rehydrate.js';
|
|
49
49
|
import { mergeAdopted } from '../storage/adopt.js';
|
|
50
50
|
import { readRemoteDescriptors, startWasSync } from '../storage/wasSync.js';
|
|
@@ -71,12 +71,14 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
71
71
|
const onboarding = config.onboarding ?? DEFAULT_ONBOARDING;
|
|
72
72
|
// Resolve the per-install LWW writer id ONCE, honoring the configured
|
|
73
73
|
// localStorage prefix, so every stamp -- the app's own writes and the
|
|
74
|
-
// adoption repair -- carries the same attribution identity.
|
|
74
|
+
// adoption repair -- carries the same attribution identity. Installing it
|
|
75
|
+
// here, before any replica opens, is what lets the write verbs stamp.
|
|
75
76
|
const writerId = getWriterId({
|
|
76
77
|
...(config.storageKeyPrefix !== undefined && {
|
|
77
78
|
storageKeyPrefix: config.storageKeyPrefix
|
|
78
79
|
})
|
|
79
80
|
});
|
|
81
|
+
setWriterId(writerId);
|
|
80
82
|
const sessionStore = seedStore ?? createSeedStore({ dbName: `${dbName}-session` });
|
|
81
83
|
// The offline encryption-descriptor cache, presented as the seam
|
|
82
84
|
// `@interop/wallet-core/descriptors` acquires through. Reads serve the
|
|
@@ -202,7 +204,7 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
202
204
|
* entity-store verbs that need the server (e.g. `query`) can reach it;
|
|
203
205
|
* `stopController` clears it.
|
|
204
206
|
*/
|
|
205
|
-
async function beginSync({ parsed, identity }) {
|
|
207
|
+
async function beginSync({ parsed, identity, knownDescriptors }) {
|
|
206
208
|
const { controllerDid, zcapClient, keyAgreementKey, keyResolver } = identity;
|
|
207
209
|
controller = new SyncController({
|
|
208
210
|
collections: config.collections,
|
|
@@ -220,11 +222,11 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
220
222
|
}),
|
|
221
223
|
identityKeys: { keyAgreementKey, keyResolver },
|
|
222
224
|
onAuthError: () => store.getState().notifyAccessExpired(),
|
|
223
|
-
onDescriptorsFetched: descriptors => void cacheDescriptors({ descriptors, controllerDid }).catch(err => console.warn('Failed to cache encryption descriptors:', err))
|
|
225
|
+
onDescriptorsFetched: descriptors => void cacheDescriptors({ descriptors, controllerDid }).catch(err => console.warn('Failed to cache encryption descriptors:', err)),
|
|
226
|
+
...(knownDescriptors && { knownDescriptors })
|
|
224
227
|
});
|
|
225
228
|
setRemoteStore(remoteStore);
|
|
226
229
|
store.setState({ sharedCollections });
|
|
227
|
-
return remoteStore;
|
|
228
230
|
}
|
|
229
231
|
/**
|
|
230
232
|
* Persists the session record, kicks off background replication, and arms the
|
|
@@ -237,9 +239,12 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
237
239
|
* @param options.parsed {ParsedGrants}
|
|
238
240
|
* @param options.grants {IZcap[]}
|
|
239
241
|
* @param options.expires {string}
|
|
242
|
+
* @param [options.knownDescriptors] {Record<string, CollectionEncryption>}
|
|
243
|
+
* encryption descriptors already read live during this bring-up, for the
|
|
244
|
+
* sync bootstrap to reuse instead of re-reading
|
|
240
245
|
* @returns {Promise<void>}
|
|
241
246
|
*/
|
|
242
|
-
async function persistAndStartSync({ seed, identity, parsed, grants, expires }) {
|
|
247
|
+
async function persistAndStartSync({ seed, identity, parsed, grants, expires, knownDescriptors }) {
|
|
243
248
|
await persistAppSession({
|
|
244
249
|
session: {
|
|
245
250
|
seed,
|
|
@@ -252,7 +257,11 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
252
257
|
store: sessionStore
|
|
253
258
|
});
|
|
254
259
|
// Replication starts in the background; a down server never blocks entry.
|
|
255
|
-
pendingSync = beginSync({
|
|
260
|
+
pendingSync = beginSync({
|
|
261
|
+
parsed,
|
|
262
|
+
identity,
|
|
263
|
+
...(knownDescriptors && { knownDescriptors })
|
|
264
|
+
});
|
|
256
265
|
// A failed bootstrap must not resolve silently: surface it on the session
|
|
257
266
|
// `error` (the sync rollup shows the per-collection error statuses the
|
|
258
267
|
// controller leaves behind). The session stays usable -- local-first --
|
|
@@ -327,7 +336,7 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
327
336
|
});
|
|
328
337
|
setLocalStore(local);
|
|
329
338
|
if (adopt) {
|
|
330
|
-
await mergeAdopted({ store: local, entities: adopt.entities
|
|
339
|
+
await mergeAdopted({ store: local, entities: adopt.entities });
|
|
331
340
|
}
|
|
332
341
|
await hydrateAll(registry);
|
|
333
342
|
}
|
|
@@ -370,10 +379,11 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
370
379
|
controller: identity.controllerDid
|
|
371
380
|
});
|
|
372
381
|
const descriptors = {};
|
|
373
|
-
for (const
|
|
374
|
-
if (
|
|
382
|
+
for (const collection of config.collections) {
|
|
383
|
+
if (isPublicCollection(collection)) {
|
|
375
384
|
continue;
|
|
376
385
|
}
|
|
386
|
+
const { id } = collection;
|
|
377
387
|
let descriptor = await cache.readDescriptor({ collectionId: id });
|
|
378
388
|
if (!descriptor) {
|
|
379
389
|
descriptor = await mintRecordEncryption({
|
|
@@ -465,20 +475,24 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
465
475
|
* leaves no single-key fallback to write under. Best-effort: a failed read
|
|
466
476
|
* leaves those collections fail-closed until the sync bootstrap's own
|
|
467
477
|
* descriptor read lands. Freshly fetched descriptors enter the offline cache
|
|
468
|
-
* immediately
|
|
478
|
+
* immediately, and come back separately as `fresh` so the sync bootstrap can
|
|
479
|
+
* reuse them instead of re-issuing the same reads seconds later (cached
|
|
480
|
+
* descriptors are NOT passed on -- the bootstrap read is their freshness
|
|
481
|
+
* refresh).
|
|
469
482
|
*
|
|
470
483
|
* @param options {object}
|
|
471
484
|
* @param [options.cached] {Record<string, CollectionEncryption>}
|
|
472
485
|
* @param options.identity {IdentityAgents}
|
|
473
486
|
* @param options.parsed {ParsedGrants}
|
|
474
|
-
* @returns {Promise<
|
|
487
|
+
* @returns {Promise<object>} `descriptors` (the completed set, or
|
|
488
|
+
* undefined when there are none) and `fresh` (the live-read subset)
|
|
475
489
|
*/
|
|
476
490
|
async function completeDescriptors({ cached, identity, parsed }) {
|
|
477
|
-
const missing = config.collections.filter(
|
|
478
|
-
parsed.byCollectionId[id] !== undefined &&
|
|
479
|
-
!cached?.[id]);
|
|
491
|
+
const missing = config.collections.filter(collection => !isPublicCollection(collection) &&
|
|
492
|
+
parsed.byCollectionId[collection.id] !== undefined &&
|
|
493
|
+
!cached?.[collection.id]);
|
|
480
494
|
if (missing.length === 0) {
|
|
481
|
-
return cached;
|
|
495
|
+
return { descriptors: cached, fresh: {} };
|
|
482
496
|
}
|
|
483
497
|
try {
|
|
484
498
|
const fetched = await readRemoteDescriptors({
|
|
@@ -491,13 +505,13 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
491
505
|
descriptors: fetched,
|
|
492
506
|
controllerDid: identity.controllerDid
|
|
493
507
|
});
|
|
494
|
-
return { ...fetched, ...cached };
|
|
508
|
+
return { descriptors: { ...fetched, ...cached }, fresh: fetched };
|
|
495
509
|
}
|
|
496
510
|
}
|
|
497
511
|
catch (err) {
|
|
498
512
|
console.warn('Failed to read encryption descriptors at login:', err);
|
|
499
513
|
}
|
|
500
|
-
return cached;
|
|
514
|
+
return { descriptors: cached, fresh: {} };
|
|
501
515
|
}
|
|
502
516
|
async function activateConnected(session) {
|
|
503
517
|
try {
|
|
@@ -505,7 +519,7 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
505
519
|
// epoch-aware: an offline hot restore then decrypts multi-recipient
|
|
506
520
|
// envelopes with no live description read, while a first login (no cache
|
|
507
521
|
// yet) completes the set with live reads before the replica opens.
|
|
508
|
-
const descriptors = await completeDescriptors({
|
|
522
|
+
const { descriptors, fresh } = await completeDescriptors({
|
|
509
523
|
cached: await loadCachedDescriptors({
|
|
510
524
|
controllerDid: session.identity.controllerDid
|
|
511
525
|
}),
|
|
@@ -522,7 +536,8 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
522
536
|
identity: session.identity,
|
|
523
537
|
parsed: session.parsed,
|
|
524
538
|
grants: session.grants,
|
|
525
|
-
expires: session.expires
|
|
539
|
+
expires: session.expires,
|
|
540
|
+
knownDescriptors: fresh
|
|
526
541
|
});
|
|
527
542
|
}
|
|
528
543
|
catch (err) {
|
|
@@ -711,6 +726,50 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
711
726
|
console.warn('Failed to delete the adopted anonymous replica:', err);
|
|
712
727
|
}
|
|
713
728
|
}
|
|
729
|
+
/**
|
|
730
|
+
* The connect epilogue shared by `login` and `connectWithGrants`, sequenced
|
|
731
|
+
* once so the load-bearing ordering lives in one place: tear the anonymous
|
|
732
|
+
* holder down and collect its payloads ({@link detachAndCollect}, merge
|
|
733
|
+
* only), activate the connected replica, write the connected status, and
|
|
734
|
+
* only THEN discard the adopted anonymous replica. The anonymous seed and
|
|
735
|
+
* database are deleted only after the activation lands, so a failure at any
|
|
736
|
+
* earlier step still falls back to an intact `local`; the cleanup itself is
|
|
737
|
+
* best-effort ({@link discardAnonReplica}) and runs after the status write
|
|
738
|
+
* so its failure can never leave the session reporting `local` over a live,
|
|
739
|
+
* syncing connected session.
|
|
740
|
+
*
|
|
741
|
+
* @param options {object}
|
|
742
|
+
* @param options.seed {Uint8Array}
|
|
743
|
+
* @param options.identity {IdentityAgents}
|
|
744
|
+
* @param options.parsed {ParsedGrants}
|
|
745
|
+
* @param options.grants {IZcap[]}
|
|
746
|
+
* @param options.expires {string}
|
|
747
|
+
* @param options.adopt {'merge' | 'leave'}
|
|
748
|
+
* @param options.snapshot {object} the caller's pre-flow
|
|
749
|
+
* `{ status, controllerDid }` snapshot (see {@link collectAdoptable})
|
|
750
|
+
* @returns {Promise<void>}
|
|
751
|
+
*/
|
|
752
|
+
async function completeConnect({ seed, identity, parsed, grants, expires, adopt, snapshot }) {
|
|
753
|
+
const source = await detachAndCollect(adopt, snapshot);
|
|
754
|
+
await activateConnected({
|
|
755
|
+
seed,
|
|
756
|
+
identity,
|
|
757
|
+
parsed,
|
|
758
|
+
grants,
|
|
759
|
+
expires,
|
|
760
|
+
...(source && { adopt: source })
|
|
761
|
+
});
|
|
762
|
+
store.setState({
|
|
763
|
+
status: 'connected',
|
|
764
|
+
controllerDid: identity.controllerDid,
|
|
765
|
+
expires,
|
|
766
|
+
phase: null,
|
|
767
|
+
error: null
|
|
768
|
+
});
|
|
769
|
+
if (source) {
|
|
770
|
+
await discardAnonReplica(source.controllerDid);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
714
773
|
// Declared last so `prefer-const` is satisfied; the lifecycle closures above
|
|
715
774
|
// only dereference `store` at call time, by which point it is assigned.
|
|
716
775
|
const store = createStore()((set, get) => {
|
|
@@ -816,33 +875,18 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
816
875
|
config: loginConfig,
|
|
817
876
|
onPhase: phase => set({ phase })
|
|
818
877
|
});
|
|
819
|
-
// The wallet succeeded:
|
|
820
|
-
//
|
|
821
|
-
//
|
|
822
|
-
|
|
823
|
-
// `local`.
|
|
824
|
-
const source = await detachAndCollect(adopt, preLogin);
|
|
825
|
-
await activateConnected({
|
|
878
|
+
// The wallet succeeded: run the shared connect epilogue (a cancel
|
|
879
|
+
// above leaves `local` intact, and a failure inside it still falls
|
|
880
|
+
// back to an intact `local` -- see `completeConnect`).
|
|
881
|
+
await completeConnect({
|
|
826
882
|
seed: outcome.seed,
|
|
827
883
|
identity: outcome.identity,
|
|
828
884
|
parsed: outcome.parsed,
|
|
829
885
|
grants: outcome.grants,
|
|
830
886
|
expires: outcome.expires,
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
set({
|
|
834
|
-
status: 'connected',
|
|
835
|
-
controllerDid: outcome.identity.controllerDid,
|
|
836
|
-
expires: outcome.expires,
|
|
837
|
-
phase: null,
|
|
838
|
-
error: null
|
|
887
|
+
adopt,
|
|
888
|
+
snapshot: preLogin
|
|
839
889
|
});
|
|
840
|
-
// Adopted-replica cleanup runs AFTER the connected status lands (and
|
|
841
|
-
// is best-effort): a cleanup failure must not leave the session
|
|
842
|
-
// reporting `local` over a live, syncing connected session.
|
|
843
|
-
if (source) {
|
|
844
|
-
await discardAnonReplica(source.controllerDid);
|
|
845
|
-
}
|
|
846
890
|
return { firstRun: outcome.firstRun };
|
|
847
891
|
}
|
|
848
892
|
catch (err) {
|
|
@@ -886,25 +930,15 @@ export function createAuthStore({ config, registry, seedStore, storage }) {
|
|
|
886
930
|
const parsed = parseGrants(grants);
|
|
887
931
|
const expires = earliestExpiry(grants) ??
|
|
888
932
|
new Date(Date.now() + NO_EXPIRY_MS).toISOString();
|
|
889
|
-
|
|
890
|
-
await activateConnected({
|
|
933
|
+
await completeConnect({
|
|
891
934
|
seed,
|
|
892
935
|
identity,
|
|
893
936
|
parsed,
|
|
894
937
|
grants,
|
|
895
938
|
expires,
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
set({
|
|
899
|
-
status: 'connected',
|
|
900
|
-
controllerDid: identity.controllerDid,
|
|
901
|
-
expires,
|
|
902
|
-
error: null
|
|
939
|
+
adopt,
|
|
940
|
+
snapshot: preConnect
|
|
903
941
|
});
|
|
904
|
-
// After the status lands, and best-effort (see `discardAnonReplica`).
|
|
905
|
-
if (source) {
|
|
906
|
-
await discardAnonReplica(source.controllerDid);
|
|
907
|
-
}
|
|
908
942
|
});
|
|
909
943
|
},
|
|
910
944
|
reconnect: async () => {
|