@abraca/dabra 2.90.0 → 2.91.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 (71) hide show
  1. package/package.json +5 -11
  2. package/src/AbracadabraBaseProvider.ts +0 -963
  3. package/src/AbracadabraClient.ts +0 -1960
  4. package/src/AbracadabraProvider.ts +0 -915
  5. package/src/AbracadabraWS.ts +0 -695
  6. package/src/BackgroundSyncManager.ts +0 -856
  7. package/src/BackgroundSyncPersistence.ts +0 -140
  8. package/src/ChatClient.ts +0 -314
  9. package/src/CloseEvents.ts +0 -49
  10. package/src/ContentManager.ts +0 -246
  11. package/src/CoverReconcile.ts +0 -168
  12. package/src/CryptoIdentityKeystore.ts +0 -754
  13. package/src/DeviceRegistrationService.ts +0 -257
  14. package/src/DocConverters.ts +0 -1859
  15. package/src/DocKeyManager.ts +0 -163
  16. package/src/DocTypes.ts +0 -628
  17. package/src/DocUtils.ts +0 -251
  18. package/src/DocumentCache.ts +0 -210
  19. package/src/DocumentManager.ts +0 -410
  20. package/src/E2EAbracadabraProvider.ts +0 -426
  21. package/src/E2EOfflineStore.ts +0 -55
  22. package/src/EncryptedChatClient.ts +0 -173
  23. package/src/EncryptedY.ts +0 -145
  24. package/src/EventEmitter.ts +0 -59
  25. package/src/FileBlobStore.ts +0 -569
  26. package/src/IdentityDoc.ts +0 -711
  27. package/src/IncomingMessage.ts +0 -63
  28. package/src/MessageReceiver.ts +0 -151
  29. package/src/MessageSender.ts +0 -22
  30. package/src/MetaManager.ts +0 -194
  31. package/src/MnemonicKeyDerivation.ts +0 -171
  32. package/src/NodeConnect.ts +0 -63
  33. package/src/NodeIdentity.ts +0 -378
  34. package/src/NotificationsClient.ts +0 -207
  35. package/src/OfflineStore.ts +0 -294
  36. package/src/OutgoingMessage.ts +0 -25
  37. package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
  38. package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
  39. package/src/OutgoingMessages/CloseMessage.ts +0 -17
  40. package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
  41. package/src/OutgoingMessages/StatelessMessage.ts +0 -18
  42. package/src/OutgoingMessages/SubdocMessage.ts +0 -35
  43. package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
  44. package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
  45. package/src/OutgoingMessages/UpdateMessage.ts +0 -20
  46. package/src/QueryClient.ts +0 -209
  47. package/src/RpcClient.ts +0 -659
  48. package/src/SchemaTypes.ts +0 -179
  49. package/src/SearchIndex.ts +0 -250
  50. package/src/ServerRegistry.ts +0 -220
  51. package/src/ServerReset.ts +0 -222
  52. package/src/TokenManager.ts +0 -337
  53. package/src/TreeManager.ts +0 -894
  54. package/src/TreeTimestamps.ts +0 -101
  55. package/src/auth.ts +0 -62
  56. package/src/awarenessStatesToArray.ts +0 -10
  57. package/src/index.ts +0 -219
  58. package/src/messageRecord.ts +0 -121
  59. package/src/sync/BroadcastChannelSync.ts +0 -235
  60. package/src/types.ts +0 -790
  61. package/src/webrtc/AbracadabraWebRTC.ts +0 -683
  62. package/src/webrtc/DataChannelRouter.ts +0 -179
  63. package/src/webrtc/DevicePairingChannel.ts +0 -496
  64. package/src/webrtc/E2EEChannel.ts +0 -195
  65. package/src/webrtc/FileTransferChannel.ts +0 -367
  66. package/src/webrtc/ManualSignaling.ts +0 -204
  67. package/src/webrtc/PeerConnection.ts +0 -133
  68. package/src/webrtc/SignalingSocket.ts +0 -378
  69. package/src/webrtc/YjsDataChannel.ts +0 -203
  70. package/src/webrtc/index.ts +0 -26
  71. package/src/webrtc/types.ts +0 -177
@@ -1,235 +0,0 @@
1
- import * as Y from "yjs";
2
- import * as syncProtocol from "y-protocols/sync";
3
- import {
4
- encodeAwarenessUpdate,
5
- applyAwarenessUpdate,
6
- type Awareness,
7
- } from "y-protocols/awareness";
8
- import * as encoding from "lib0/encoding";
9
- import * as decoding from "lib0/decoding";
10
- import EventEmitter from "../EventEmitter.ts";
11
-
12
- /**
13
- * Cross-tab Y.js document and awareness sync via the BroadcastChannel API.
14
- *
15
- * Opens a BroadcastChannel per document, relays Y.js updates and awareness
16
- * state between tabs on the same origin. No server, no WebRTC — just same-device
17
- * multi-tab sync. Same-origin means same trust boundary, so no encryption needed.
18
- *
19
- * Uses the same y-protocols/sync encoding as `YjsDataChannel` for consistency.
20
- */
21
-
22
- const CHANNEL_PREFIX = "abra:sync:";
23
-
24
- /** Message type discriminators (first byte). */
25
- const MSG = {
26
- SYNC: 0x00,
27
- UPDATE: 0x01,
28
- AWARENESS: 0x02,
29
- /** Request all tabs to respond with SyncStep1. */
30
- QUERY_PEERS: 0x03,
31
- } as const;
32
-
33
- export class BroadcastChannelSync extends EventEmitter {
34
- private channel: BroadcastChannel | null = null;
35
- private docUpdateHandler: ((update: Uint8Array, origin: any) => void) | null =
36
- null;
37
- private awarenessUpdateHandler:
38
- | ((
39
- changes: { added: number[]; updated: number[]; removed: number[] },
40
- origin: any,
41
- ) => void)
42
- | null = null;
43
- private destroyed = false;
44
-
45
- constructor(
46
- private readonly document: Y.Doc,
47
- private readonly awareness: Awareness | null,
48
- private readonly channelName: string,
49
- ) {
50
- super();
51
- }
52
-
53
- /** Convenience factory using standard channel naming. */
54
- static forDoc(
55
- document: Y.Doc,
56
- docId: string,
57
- awareness?: Awareness | null,
58
- ): BroadcastChannelSync {
59
- return new BroadcastChannelSync(
60
- document,
61
- awareness ?? null,
62
- `${CHANNEL_PREFIX}${docId}`,
63
- );
64
- }
65
-
66
- /** Start syncing. Opens the BroadcastChannel and initiates a sync handshake. */
67
- connect(): void {
68
- if (this.destroyed || this.channel) return;
69
-
70
- if (typeof globalThis.BroadcastChannel === "undefined") {
71
- // Environment doesn't support BroadcastChannel (e.g. some Node.js builds).
72
- return;
73
- }
74
-
75
- this.channel = new BroadcastChannel(this.channelName);
76
- this.channel.onmessage = (event) => this.handleMessage(event.data);
77
-
78
- // Listen for local doc updates → broadcast to other tabs.
79
- this.docUpdateHandler = (update: Uint8Array, origin: any) => {
80
- if (origin === this) return; // Don't echo.
81
- this.broadcastUpdate(update);
82
- };
83
- this.document.on("update", this.docUpdateHandler);
84
-
85
- // Listen for local awareness changes → broadcast to other tabs.
86
- if (this.awareness) {
87
- this.awarenessUpdateHandler = (
88
- {
89
- added,
90
- updated,
91
- removed,
92
- }: { added: number[]; updated: number[]; removed: number[] },
93
- _origin: any,
94
- ) => {
95
- const changedClients = added.concat(updated).concat(removed);
96
- const update = encodeAwarenessUpdate(this.awareness!, changedClients);
97
- this.broadcastAwareness(update);
98
- };
99
- this.awareness.on("update", this.awarenessUpdateHandler);
100
- }
101
-
102
- // Announce presence — other tabs reply with SyncStep1.
103
- this.broadcastQueryPeers();
104
-
105
- // Send our SyncStep1 to trigger state exchange.
106
- this.sendSyncStep1();
107
-
108
- this.emit("connected");
109
- }
110
-
111
- /** Stop syncing and close the BroadcastChannel. */
112
- disconnect(): void {
113
- if (this.docUpdateHandler) {
114
- this.document.off("update", this.docUpdateHandler);
115
- this.docUpdateHandler = null;
116
- }
117
- if (this.awarenessUpdateHandler && this.awareness) {
118
- this.awareness.off("update", this.awarenessUpdateHandler);
119
- this.awarenessUpdateHandler = null;
120
- }
121
- if (this.channel) {
122
- this.channel.close();
123
- this.channel = null;
124
- }
125
- this.emit("disconnected");
126
- }
127
-
128
- /** Disconnect and prevent reconnection. */
129
- destroy(): void {
130
- this.disconnect();
131
- this.destroyed = true;
132
- this.removeAllListeners();
133
- }
134
-
135
- // ── Outgoing ────────────────────────────────────────────────────────────
136
-
137
- private broadcastUpdate(update: Uint8Array): void {
138
- if (!this.channel) return;
139
- const encoder = encoding.createEncoder();
140
- encoding.writeVarUint(encoder, MSG.UPDATE);
141
- encoding.writeVarUint8Array(encoder, update);
142
- this.channel.postMessage(encoding.toUint8Array(encoder));
143
- }
144
-
145
- private broadcastAwareness(update: Uint8Array): void {
146
- if (!this.channel) return;
147
- const encoder = encoding.createEncoder();
148
- encoding.writeVarUint(encoder, MSG.AWARENESS);
149
- encoding.writeVarUint8Array(encoder, update);
150
- this.channel.postMessage(encoding.toUint8Array(encoder));
151
- }
152
-
153
- private sendSyncStep1(): void {
154
- if (!this.channel) return;
155
- const encoder = encoding.createEncoder();
156
- encoding.writeVarUint(encoder, MSG.SYNC);
157
- syncProtocol.writeSyncStep1(encoder, this.document);
158
- this.channel.postMessage(encoding.toUint8Array(encoder));
159
- }
160
-
161
- private broadcastQueryPeers(): void {
162
- if (!this.channel) return;
163
- const encoder = encoding.createEncoder();
164
- encoding.writeVarUint(encoder, MSG.QUERY_PEERS);
165
- this.channel.postMessage(encoding.toUint8Array(encoder));
166
- }
167
-
168
- // ── Incoming ────────────────────────────────────────────────────────────
169
-
170
- private handleMessage(data: any): void {
171
- if (!(data instanceof ArrayBuffer || data instanceof Uint8Array)) return;
172
- const buf = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
173
- const decoder = decoding.createDecoder(buf);
174
- const msgType = decoding.readVarUint(decoder);
175
-
176
- switch (msgType) {
177
- case MSG.SYNC:
178
- this.handleSyncMessage(decoder);
179
- break;
180
- case MSG.UPDATE:
181
- this.handleUpdateMessage(decoder);
182
- break;
183
- case MSG.AWARENESS:
184
- this.handleAwarenessMessage(decoder);
185
- break;
186
- case MSG.QUERY_PEERS:
187
- // Another tab joined — respond with our SyncStep1.
188
- this.sendSyncStep1();
189
- if (this.awareness) {
190
- const update = encodeAwarenessUpdate(
191
- this.awareness,
192
- Array.from(this.awareness.getStates().keys()),
193
- );
194
- this.broadcastAwareness(update);
195
- }
196
- break;
197
- }
198
- }
199
-
200
- private handleSyncMessage(decoder: decoding.Decoder): void {
201
- const encoder = encoding.createEncoder();
202
- const syncMessageType = syncProtocol.readSyncMessage(
203
- decoder,
204
- encoder,
205
- this.document,
206
- this,
207
- );
208
-
209
- // If the sync protocol generated a response (SyncStep2), broadcast it.
210
- if (encoding.length(encoder) > 0) {
211
- const responseEncoder = encoding.createEncoder();
212
- encoding.writeVarUint(responseEncoder, MSG.SYNC);
213
- encoding.writeUint8Array(
214
- responseEncoder,
215
- encoding.toUint8Array(encoder),
216
- );
217
- this.channel?.postMessage(encoding.toUint8Array(responseEncoder));
218
- }
219
-
220
- if (syncMessageType === syncProtocol.messageYjsSyncStep2) {
221
- this.emit("synced");
222
- }
223
- }
224
-
225
- private handleUpdateMessage(decoder: decoding.Decoder): void {
226
- const update = decoding.readVarUint8Array(decoder);
227
- Y.applyUpdate(this.document, update, this);
228
- }
229
-
230
- private handleAwarenessMessage(decoder: decoding.Decoder): void {
231
- if (!this.awareness) return;
232
- const update = decoding.readVarUint8Array(decoder);
233
- applyAwarenessUpdate(this.awareness, update, this);
234
- }
235
- }