@enbox/agent 0.1.9 → 0.2.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.
Files changed (37) hide show
  1. package/dist/browser.mjs +8 -8
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/connect.js +2 -1
  4. package/dist/esm/connect.js.map +1 -1
  5. package/dist/esm/hd-identity-vault.js +6 -3
  6. package/dist/esm/hd-identity-vault.js.map +1 -1
  7. package/dist/esm/oidc.js +2 -1
  8. package/dist/esm/oidc.js.map +1 -1
  9. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js +1 -1
  10. package/dist/esm/prototyping/crypto/jose/jwe-flattened.js.map +1 -1
  11. package/dist/esm/prototyping/crypto/jose/jwe.js +11 -3
  12. package/dist/esm/prototyping/crypto/jose/jwe.js.map +1 -1
  13. package/dist/esm/sync-api.js +3 -0
  14. package/dist/esm/sync-api.js.map +1 -1
  15. package/dist/esm/sync-engine-level.js +447 -29
  16. package/dist/esm/sync-engine-level.js.map +1 -1
  17. package/dist/types/connect.d.ts.map +1 -1
  18. package/dist/types/hd-identity-vault.d.ts.map +1 -1
  19. package/dist/types/oidc.d.ts.map +1 -1
  20. package/dist/types/prototyping/crypto/jose/jwe-flattened.d.ts.map +1 -1
  21. package/dist/types/prototyping/crypto/jose/jwe.d.ts +12 -2
  22. package/dist/types/prototyping/crypto/jose/jwe.d.ts.map +1 -1
  23. package/dist/types/sync-api.d.ts +3 -4
  24. package/dist/types/sync-api.d.ts.map +1 -1
  25. package/dist/types/sync-engine-level.d.ts +63 -5
  26. package/dist/types/sync-engine-level.d.ts.map +1 -1
  27. package/dist/types/types/sync.d.ts +47 -5
  28. package/dist/types/types/sync.d.ts.map +1 -1
  29. package/package.json +6 -6
  30. package/src/connect.ts +2 -1
  31. package/src/hd-identity-vault.ts +6 -3
  32. package/src/oidc.ts +2 -1
  33. package/src/prototyping/crypto/jose/jwe-flattened.ts +4 -1
  34. package/src/prototyping/crypto/jose/jwe.ts +24 -2
  35. package/src/sync-api.ts +7 -3
  36. package/src/sync-engine-level.ts +509 -32
  37. package/src/types/sync.ts +56 -5
package/src/types/sync.ts CHANGED
@@ -11,13 +11,62 @@ export type SyncIdentityOptions = {
11
11
  /**
12
12
  * The protocols that should be synced for this identity, if an empty array is provided, all messages for all protocols will be synced.
13
13
  */
14
- protocols: string[]
14
+ protocols: string[];
15
15
  };
16
+
17
+ /**
18
+ * Connectivity state of the sync engine.
19
+ */
20
+ export type SyncConnectivityState = 'online' | 'offline' | 'unknown';
21
+
22
+ /**
23
+ * Describes the sync mode: `'poll'` for periodic SMT reconciliation,
24
+ * `'live'` for `MessagesSubscribe`-based real-time sync with SMT fallback.
25
+ */
26
+ export type SyncMode = 'poll' | 'live';
27
+
28
+ /**
29
+ * Parameters for {@link SyncEngine.startSync}.
30
+ */
31
+ export type StartSyncParams = {
32
+ /**
33
+ * The sync mode to use. Default: `'poll'`.
34
+ *
35
+ * - `'live'`: Opens `MessagesSubscribe` WebSocket subscriptions to remote
36
+ * DWNs for real-time pull, and listens to the local EventLog for immediate
37
+ * push. Falls back to SMT reconciliation on cold start or long disconnect.
38
+ * An infrequent SMT integrity check still runs at `interval`.
39
+ *
40
+ * - `'poll'`: Legacy mode. Performs a full SMT set-reconciliation sync on a
41
+ * fixed interval. No WebSocket subscriptions are used.
42
+ */
43
+ mode?: SyncMode;
44
+
45
+ /**
46
+ * The interval at which the sync operation should be performed.
47
+ * Accepts any value recognised by `ms()`, e.g. `'30s'`, `'2m'`, `'10m'`.
48
+ *
49
+ * In `'live'` mode this controls the frequency of the SMT integrity check.
50
+ * In `'poll'` mode this controls the polling frequency.
51
+ *
52
+ * Default: `'2m'` (in poll mode), `'5m'` (in live mode).
53
+ */
54
+ interval?: string;
55
+ };
56
+
16
57
  export interface SyncEngine {
17
58
  /**
18
59
  * The agent that the SyncEngine is attached to.
19
60
  */
20
61
  agent: Web5PlatformAgent;
62
+
63
+ /**
64
+ * Current connectivity state as observed by the sync engine.
65
+ * Updated when WebSocket subscriptions connect/disconnect or when the
66
+ * browser `online`/`offline` events fire.
67
+ */
68
+ readonly connectivityState: SyncConnectivityState;
69
+
21
70
  /**
22
71
  * Register an identity to be managed by the SyncEngine for syncing.
23
72
  * The options can define specific protocols that should only be synced, or a delegate DID that should be used to sign the sync messages.
@@ -43,11 +92,13 @@ export interface SyncEngine {
43
92
  */
44
93
  sync(direction?: 'push' | 'pull'): Promise<void>;
45
94
  /**
46
- * Starts a periodic sync that runs at an interval. Subsequent calls to startSync will update the interval.
95
+ * Starts sync. In `'live'` mode opens real-time subscriptions with SMT
96
+ * fallback; in `'poll'` mode uses periodic SMT reconciliation.
47
97
  *
48
- * @param params { interval: string } the interval at which the sync operation should be performed. ex: '30s', '1m', '10m'
98
+ * Subsequent calls update the mode/interval. Calling with a different mode
99
+ * tears down the previous mode's resources before starting the new one.
49
100
  */
50
- startSync(params: { interval: string }): Promise<void>;
101
+ startSync(params: StartSyncParams): Promise<void>;
51
102
  /**
52
103
  * Stops the periodic sync operation, will complete the current sync operation if one is already in progress.
53
104
  *
@@ -55,4 +106,4 @@ export interface SyncEngine {
55
106
  * @throws {Error} if the sync operation fails to stop before the timeout.
56
107
  */
57
108
  stopSync(timeout?: number): Promise<void>;
58
- }
109
+ }