@abraca/dabra 2.18.0 → 2.20.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.
@@ -3063,6 +3063,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3063
3063
  }
3064
3064
  super(resolved);
3065
3065
  this.effectiveRole = null;
3066
+ this._writeDropWarned = false;
3066
3067
  this.childProviders = /* @__PURE__ */ new Map();
3067
3068
  this.pendingLoads = /* @__PURE__ */ new Map();
3068
3069
  this.childAccessTimes = /* @__PURE__ */ new Map();
@@ -3119,7 +3120,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3119
3120
  }
3120
3121
  authenticatedHandler(scope) {
3121
3122
  super.authenticatedHandler(scope);
3122
- this.effectiveRole = {
3123
+ const roleMap = {
3123
3124
  service: "service",
3124
3125
  admin: "admin",
3125
3126
  owner: "owner",
@@ -3128,8 +3129,16 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3128
3129
  observer: "observer",
3129
3130
  "read-write": "editor",
3130
3131
  readonly: "viewer"
3131
- }[scope] ?? "observer";
3132
+ };
3133
+ const couldWrite = this.canWrite;
3134
+ this.effectiveRole = roleMap[scope] ?? "observer";
3132
3135
  this.offlineStore?.savePermissionSnapshot(this.effectiveRole);
3136
+ if (this.canWrite) this._writeDropWarned = false;
3137
+ this.emit("roleChanged", {
3138
+ role: this.effectiveRole,
3139
+ canWrite: this.canWrite
3140
+ });
3141
+ if (!couldWrite && this.canWrite && this.isSynced) this.flushPendingUpdates().catch(() => null);
3133
3142
  }
3134
3143
  /**
3135
3144
  * Override sendToken to send a pubkey-only identity declaration instead of a
@@ -3180,7 +3189,13 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3180
3189
  async restorePermissionSnapshot() {
3181
3190
  if (!this.offlineStore) return;
3182
3191
  const role = await this.offlineStore.getPermissionSnapshot();
3183
- if (role && !this.effectiveRole) this.effectiveRole = role;
3192
+ if (role && !this.effectiveRole) {
3193
+ this.effectiveRole = role;
3194
+ this.emit("roleChanged", {
3195
+ role: this.effectiveRole,
3196
+ canWrite: this.canWrite
3197
+ });
3198
+ }
3184
3199
  }
3185
3200
  get canWrite() {
3186
3201
  return this.effectiveRole != null && this.effectiveRole !== "viewer" && this.effectiveRole !== "observer";
@@ -3387,7 +3402,19 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3387
3402
  if (origin === this) return;
3388
3403
  if (this.offlineStore !== null && origin === this.offlineStore) return;
3389
3404
  this.offlineStore?.persistUpdate(update).catch(() => null);
3390
- if (!this.canWrite) return;
3405
+ if (!this.canWrite) {
3406
+ if (!this._writeDropWarned) {
3407
+ this._writeDropWarned = true;
3408
+ try {
3409
+ console.warn(`[abra:write-drop] dropping wire-send for doc "${this.configuration?.name}" — effectiveRole=${this.effectiveRole ?? "null"} (canWrite=false). Edits are persisted to IndexedDB only; the server will NOT receive them until this doc regains write access.`);
3410
+ } catch {}
3411
+ }
3412
+ this.emit("writeDropped", {
3413
+ name: this.configuration?.name,
3414
+ role: this.effectiveRole ?? null
3415
+ });
3416
+ return;
3417
+ }
3391
3418
  super.documentUpdateHandler(update, origin);
3392
3419
  }
3393
3420
  /**