@abraca/dabra 1.0.16 → 1.0.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/dist/abracadabra-provider.cjs +72 -6
- package/dist/abracadabra-provider.cjs.map +1 -1
- package/dist/abracadabra-provider.esm.js +72 -6
- package/dist/abracadabra-provider.esm.js.map +1 -1
- package/dist/index.d.ts +47 -4
- package/package.json +1 -1
- package/src/AbracadabraClient.ts +32 -0
- package/src/AbracadabraProvider.ts +21 -2
- package/src/BackgroundSyncManager.ts +59 -9
- package/src/types.ts +16 -4
|
@@ -2865,9 +2865,10 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
2865
2865
|
owner: "owner",
|
|
2866
2866
|
editor: "editor",
|
|
2867
2867
|
viewer: "viewer",
|
|
2868
|
+
observer: "observer",
|
|
2868
2869
|
"read-write": "editor",
|
|
2869
2870
|
readonly: "viewer"
|
|
2870
|
-
}[scope] ?? "
|
|
2871
|
+
}[scope] ?? "observer";
|
|
2871
2872
|
this.offlineStore?.savePermissionSnapshot(this.effectiveRole);
|
|
2872
2873
|
}
|
|
2873
2874
|
/**
|
|
@@ -2922,7 +2923,10 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
2922
2923
|
if (role && !this.effectiveRole) this.effectiveRole = role;
|
|
2923
2924
|
}
|
|
2924
2925
|
get canWrite() {
|
|
2925
|
-
return this.effectiveRole != null && this.effectiveRole !== "viewer";
|
|
2926
|
+
return this.effectiveRole != null && this.effectiveRole !== "viewer" && this.effectiveRole !== "observer";
|
|
2927
|
+
}
|
|
2928
|
+
get canAwareness() {
|
|
2929
|
+
return this.effectiveRole != null && this.effectiveRole !== "observer";
|
|
2926
2930
|
}
|
|
2927
2931
|
/** The AbracadabraClient instance for REST API access, if configured. */
|
|
2928
2932
|
get client() {
|
|
@@ -3096,8 +3100,11 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
|
|
|
3096
3100
|
}
|
|
3097
3101
|
destroy() {
|
|
3098
3102
|
this.document.off("subdocs", this.boundHandleYSubdocsChange);
|
|
3103
|
+
const childIds = [...this.childProviders.keys()];
|
|
3099
3104
|
for (const provider of this.childProviders.values()) provider.destroy();
|
|
3100
3105
|
this.childProviders.clear();
|
|
3106
|
+
const wsProviderMap = this.configuration.websocketProvider?.configuration?.providerMap;
|
|
3107
|
+
if (wsProviderMap) for (const childId of childIds) wsProviderMap.delete(childId);
|
|
3101
3108
|
this.offlineStore?.destroy();
|
|
3102
3109
|
this.offlineStore = null;
|
|
3103
3110
|
super.destroy();
|
|
@@ -3305,6 +3312,10 @@ var AbracadabraClient = class {
|
|
|
3305
3312
|
async createChild(docId, opts) {
|
|
3306
3313
|
return this.request("POST", `/docs/${encodeURIComponent(docId)}/children`, { body: opts ?? {} });
|
|
3307
3314
|
}
|
|
3315
|
+
/** Broadcast a stateless message to all connected clients on a document (requires manage permission). */
|
|
3316
|
+
async broadcast(docId, payload) {
|
|
3317
|
+
await this.request("POST", `/docs/${encodeURIComponent(docId)}/broadcast`, { body: { payload } });
|
|
3318
|
+
}
|
|
3308
3319
|
/** List all permissions for a document (requires read access). */
|
|
3309
3320
|
async listPermissions(docId) {
|
|
3310
3321
|
if (this.cache) {
|
|
@@ -3420,6 +3431,26 @@ var AbracadabraClient = class {
|
|
|
3420
3431
|
async deleteSpace(spaceId) {
|
|
3421
3432
|
await this.request("DELETE", `/spaces/${encodeURIComponent(spaceId)}`);
|
|
3422
3433
|
}
|
|
3434
|
+
/** List all users (requires elevated role: admin or service). */
|
|
3435
|
+
async adminListUsers() {
|
|
3436
|
+
return this.request("GET", "/admin/users");
|
|
3437
|
+
}
|
|
3438
|
+
/** Promote a user to admin (requires service role). */
|
|
3439
|
+
async adminPromote(userId) {
|
|
3440
|
+
await this.request("POST", `/admin/users/${encodeURIComponent(userId)}/admin`);
|
|
3441
|
+
}
|
|
3442
|
+
/** Demote an admin user back to regular (requires service role). */
|
|
3443
|
+
async adminDemote(userId) {
|
|
3444
|
+
await this.request("DELETE", `/admin/users/${encodeURIComponent(userId)}/admin`);
|
|
3445
|
+
}
|
|
3446
|
+
/** Sweep orphaned file blobs from storage (requires elevated role). */
|
|
3447
|
+
async adminStorageSweep() {
|
|
3448
|
+
return this.request("POST", "/admin/storage/sweep");
|
|
3449
|
+
}
|
|
3450
|
+
/** Repair blob ref-counts and sweep orphans (requires elevated role). */
|
|
3451
|
+
async adminStorageRepair() {
|
|
3452
|
+
return this.request("POST", "/admin/storage/repair");
|
|
3453
|
+
}
|
|
3423
3454
|
/** Health check — no auth required. */
|
|
3424
3455
|
async health() {
|
|
3425
3456
|
return this.request("GET", "/health", { auth: false });
|
|
@@ -8391,7 +8422,9 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
8391
8422
|
this.opts = {
|
|
8392
8423
|
concurrency: opts?.concurrency ?? 2,
|
|
8393
8424
|
syncTimeout: opts?.syncTimeout ?? 15e3,
|
|
8394
|
-
prefetchFiles: opts?.prefetchFiles ?? true
|
|
8425
|
+
prefetchFiles: opts?.prefetchFiles ?? true,
|
|
8426
|
+
throttleMs: opts?.throttleMs ?? 50,
|
|
8427
|
+
maxRetries: opts?.maxRetries ?? 2
|
|
8395
8428
|
};
|
|
8396
8429
|
let serverOrigin = "default";
|
|
8397
8430
|
try {
|
|
@@ -8425,7 +8458,38 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
8425
8458
|
for (const [docId, v] of entries) updatedAtMap.set(docId, v?.updatedAt ?? v?.createdAt ?? 0);
|
|
8426
8459
|
this._prefetchCovers(entries).catch(() => null);
|
|
8427
8460
|
const queue = this._buildQueue(entries);
|
|
8428
|
-
|
|
8461
|
+
const failed = [];
|
|
8462
|
+
let idx = 0;
|
|
8463
|
+
const next = async () => {
|
|
8464
|
+
while (idx < queue.length) {
|
|
8465
|
+
if (this._destroyed) return;
|
|
8466
|
+
const docId = queue[idx++];
|
|
8467
|
+
const updatedAt = updatedAtMap.get(docId) ?? 0;
|
|
8468
|
+
if (!await this._syncWithSemaphore(docId, updatedAt)) failed.push(docId);
|
|
8469
|
+
if (this.opts.throttleMs > 0 && idx < queue.length) await new Promise((r) => setTimeout(r, this.opts.throttleMs));
|
|
8470
|
+
}
|
|
8471
|
+
};
|
|
8472
|
+
const workers = Array.from({ length: this.opts.concurrency }, () => next());
|
|
8473
|
+
await Promise.all(workers);
|
|
8474
|
+
for (let retry = 0; retry < this.opts.maxRetries && failed.length > 0; retry++) {
|
|
8475
|
+
if (this._destroyed) return;
|
|
8476
|
+
const batch = failed.splice(0, failed.length);
|
|
8477
|
+
const backoff = 2e3 * 2 ** retry;
|
|
8478
|
+
await new Promise((r) => setTimeout(r, backoff));
|
|
8479
|
+
idx = 0;
|
|
8480
|
+
const retryQueue = batch;
|
|
8481
|
+
const retryNext = async () => {
|
|
8482
|
+
while (idx < retryQueue.length) {
|
|
8483
|
+
if (this._destroyed) return;
|
|
8484
|
+
const docId = retryQueue[idx++];
|
|
8485
|
+
const updatedAt = updatedAtMap.get(docId) ?? 0;
|
|
8486
|
+
if (!await this._syncWithSemaphore(docId, updatedAt)) failed.push(docId);
|
|
8487
|
+
if (this.opts.throttleMs > 0 && idx < retryQueue.length) await new Promise((r) => setTimeout(r, this.opts.throttleMs));
|
|
8488
|
+
}
|
|
8489
|
+
};
|
|
8490
|
+
const retryWorkers = Array.from({ length: this.opts.concurrency }, () => retryNext());
|
|
8491
|
+
await Promise.all(retryWorkers);
|
|
8492
|
+
}
|
|
8429
8493
|
}
|
|
8430
8494
|
/** Sync a single document by ID. */
|
|
8431
8495
|
async syncDoc(docId) {
|
|
@@ -8506,15 +8570,16 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
8506
8570
|
items.sort((a, b) => b.priority - a.priority);
|
|
8507
8571
|
return items.map((i) => i.docId);
|
|
8508
8572
|
}
|
|
8573
|
+
/** Returns true on success (or skip), false on error. */
|
|
8509
8574
|
async _syncWithSemaphore(docId, updatedAt) {
|
|
8510
|
-
if (this._destroyed) return;
|
|
8575
|
+
if (this._destroyed) return true;
|
|
8511
8576
|
const existing = this.syncStates.get(docId);
|
|
8512
8577
|
if (existing && existing.status === "synced" && existing.lastSynced !== null && existing.lastSynced >= updatedAt) {
|
|
8513
8578
|
this.emit("stateChanged", {
|
|
8514
8579
|
docId,
|
|
8515
8580
|
state: existing
|
|
8516
8581
|
});
|
|
8517
|
-
return;
|
|
8582
|
+
return true;
|
|
8518
8583
|
}
|
|
8519
8584
|
await this.semaphore.acquire();
|
|
8520
8585
|
try {
|
|
@@ -8525,6 +8590,7 @@ var BackgroundSyncManager = class extends EventEmitter {
|
|
|
8525
8590
|
docId,
|
|
8526
8591
|
state
|
|
8527
8592
|
});
|
|
8593
|
+
return state.status !== "error";
|
|
8528
8594
|
} finally {
|
|
8529
8595
|
this.semaphore.release();
|
|
8530
8596
|
}
|