@abraca/dabra 2.35.0 → 2.35.1
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/dist/abracadabra-provider.cjs +20 -0
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +20 -0
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +15 -0
- package/package.json +2 -2
- package/src/AbracadabraBaseProvider.ts +22 -0
- package/src/E2EAbracadabraProvider.ts +37 -0
package/dist/index.d.ts
CHANGED
|
@@ -3263,6 +3263,16 @@ declare class E2EAbracadabraProvider extends AbracadabraProvider {
|
|
|
3263
3263
|
/** Quiescence debounce: reset on every update, fires the actual compaction. */
|
|
3264
3264
|
private compactionDebounceTimer;
|
|
3265
3265
|
private destroyed;
|
|
3266
|
+
/**
|
|
3267
|
+
* Plaintext local updates produced while this doc is not yet authenticated
|
|
3268
|
+
* on the connection. Unlike the plaintext provider, E2E does not convey
|
|
3269
|
+
* local state via SyncStep2 (it ships discrete encrypted update frames keyed
|
|
3270
|
+
* by server-assigned seq), so a pre-auth update that loses the AUTH race and
|
|
3271
|
+
* gets "not subscribed"-rejected would be lost. We queue them here and flush
|
|
3272
|
+
* (encrypt + send) once `authenticatedHandler` confirms the doc is
|
|
3273
|
+
* subscribed. Survives reconnects (only cleared on flush or destroy).
|
|
3274
|
+
*/
|
|
3275
|
+
private _pendingPreAuthUpdates;
|
|
3266
3276
|
constructor(configuration: E2EAbracadabraProviderConfiguration);
|
|
3267
3277
|
/** Fetch the doc key from the server (requires WebAuthn if not cached). */
|
|
3268
3278
|
private ensureDocKey;
|
|
@@ -3272,6 +3282,11 @@ declare class E2EAbracadabraProvider extends AbracadabraProvider {
|
|
|
3272
3282
|
private _decryptAndApply;
|
|
3273
3283
|
/** Encrypt local updates before sending over WebSocket. */
|
|
3274
3284
|
documentUpdateHandler(update: Uint8Array, origin: unknown): void;
|
|
3285
|
+
/**
|
|
3286
|
+
* Flush updates buffered while unauthenticated once the server confirms the
|
|
3287
|
+
* doc is subscribed, then resume normal live sends.
|
|
3288
|
+
*/
|
|
3289
|
+
authenticatedHandler(scope: string): void;
|
|
3275
3290
|
private _encryptAndSend;
|
|
3276
3291
|
/**
|
|
3277
3292
|
* Force an immediate compaction attempt, bypassing the threshold and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abraca/dabra",
|
|
3
|
-
"version": "2.35.
|
|
3
|
+
"version": "2.35.1",
|
|
4
4
|
"description": "abracadabra provider",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"abracadabra",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"yjs": "^13.6.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@abraca/schema": "2.35.
|
|
44
|
+
"@abraca/schema": "2.35.1"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"test": "node --no-warnings --conditions=source --experimental-transform-types --test 'tests/*.test.ts'"
|
|
@@ -414,11 +414,33 @@ export class AbracadabraBaseProvider extends EventEmitter {
|
|
|
414
414
|
return;
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
+
// Don't push live updates over a connection that hasn't authenticated this
|
|
418
|
+
// document yet. On the shared multiplexed socket, onOpen() does
|
|
419
|
+
// `await sendToken()` before the doc's AUTH frame actually goes out; an edit
|
|
420
|
+
// firing in that async window would race ahead of the AUTH frame and the
|
|
421
|
+
// server rejects it with "not subscribed: send AUTH for this document
|
|
422
|
+
// first". State is NOT lost: subclasses persist to the offline store before
|
|
423
|
+
// calling super (and re-flush pending updates on `synced`), and the
|
|
424
|
+
// post-AUTH SyncStep1/2 handshake conveys all local state regardless. So
|
|
425
|
+
// skipping the live wire-send here is safe — it only closes the race.
|
|
426
|
+
if (!this.isAuthenticated) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
417
430
|
this.incrementUnsyncedChanges();
|
|
418
431
|
this.send(UpdateMessage, { update, documentName: this.configuration.name });
|
|
419
432
|
}
|
|
420
433
|
|
|
421
434
|
awarenessUpdateHandler({ added, updated, removed }: any, origin: any) {
|
|
435
|
+
// Same AUTH-ordering guard as documentUpdateHandler. Awareness churn
|
|
436
|
+
// (cursor / presence / focus) during the connect AUTH window must not race
|
|
437
|
+
// ahead of the doc's AUTH frame. Awareness is ephemeral and re-sent in full
|
|
438
|
+
// by startSync() immediately after AUTH plus on the next local change, so
|
|
439
|
+
// dropping pre-auth awareness frames loses nothing.
|
|
440
|
+
if (!this.isAuthenticated) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
|
|
422
444
|
const changedClients = added.concat(updated).concat(removed);
|
|
423
445
|
|
|
424
446
|
this.send(AwarenessMessage, {
|
|
@@ -110,6 +110,16 @@ export class E2EAbracadabraProvider extends AbracadabraProvider {
|
|
|
110
110
|
/** Quiescence debounce: reset on every update, fires the actual compaction. */
|
|
111
111
|
private compactionDebounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
112
112
|
private destroyed = false;
|
|
113
|
+
/**
|
|
114
|
+
* Plaintext local updates produced while this doc is not yet authenticated
|
|
115
|
+
* on the connection. Unlike the plaintext provider, E2E does not convey
|
|
116
|
+
* local state via SyncStep2 (it ships discrete encrypted update frames keyed
|
|
117
|
+
* by server-assigned seq), so a pre-auth update that loses the AUTH race and
|
|
118
|
+
* gets "not subscribed"-rejected would be lost. We queue them here and flush
|
|
119
|
+
* (encrypt + send) once `authenticatedHandler` confirms the doc is
|
|
120
|
+
* subscribed. Survives reconnects (only cleared on flush or destroy).
|
|
121
|
+
*/
|
|
122
|
+
private _pendingPreAuthUpdates: Uint8Array[] = [];
|
|
113
123
|
|
|
114
124
|
constructor(configuration: E2EAbracadabraProviderConfiguration) {
|
|
115
125
|
// Disable the parent's offline store — E2E uses its own encrypted store.
|
|
@@ -245,12 +255,39 @@ export class E2EAbracadabraProvider extends AbracadabraProvider {
|
|
|
245
255
|
/** Encrypt local updates before sending over WebSocket. */
|
|
246
256
|
override documentUpdateHandler(update: Uint8Array, origin: unknown): void {
|
|
247
257
|
if (origin === this) return;
|
|
258
|
+
|
|
259
|
+
// AUTH-ordering guard (see _pendingPreAuthUpdates): until the doc is
|
|
260
|
+
// authenticated on the connection, an encrypted update would race ahead
|
|
261
|
+
// of the AUTH frame on the shared multiplexed socket and be rejected with
|
|
262
|
+
// "not subscribed". Queue it and flush on authenticatedHandler instead of
|
|
263
|
+
// racing (and losing) it.
|
|
264
|
+
if (!this.isAuthenticated) {
|
|
265
|
+
this._pendingPreAuthUpdates.push(update);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
248
269
|
// Don't call super (which would send plaintext); encrypt first
|
|
249
270
|
this._encryptAndSend(update).catch((e) => {
|
|
250
271
|
console.error("[E2EAbracadabraProvider] failed to encrypt update:", e);
|
|
251
272
|
});
|
|
252
273
|
}
|
|
253
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Flush updates buffered while unauthenticated once the server confirms the
|
|
277
|
+
* doc is subscribed, then resume normal live sends.
|
|
278
|
+
*/
|
|
279
|
+
override authenticatedHandler(scope: string): void {
|
|
280
|
+
super.authenticatedHandler(scope);
|
|
281
|
+
if (this._pendingPreAuthUpdates.length === 0) return;
|
|
282
|
+
const pending = this._pendingPreAuthUpdates;
|
|
283
|
+
this._pendingPreAuthUpdates = [];
|
|
284
|
+
for (const update of pending) {
|
|
285
|
+
this._encryptAndSend(update).catch((e) => {
|
|
286
|
+
console.error("[E2EAbracadabraProvider] failed to flush pre-auth update:", e);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
254
291
|
private async _encryptAndSend(update: Uint8Array): Promise<void> {
|
|
255
292
|
const key = await this.ensureDocKey();
|
|
256
293
|
if (!key) {
|