@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.
@@ -3033,6 +3033,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3033
3033
  }
3034
3034
  super(resolved);
3035
3035
  this.effectiveRole = null;
3036
+ this._writeDropWarned = false;
3036
3037
  this.childProviders = /* @__PURE__ */ new Map();
3037
3038
  this.pendingLoads = /* @__PURE__ */ new Map();
3038
3039
  this.childAccessTimes = /* @__PURE__ */ new Map();
@@ -3089,7 +3090,7 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3089
3090
  }
3090
3091
  authenticatedHandler(scope) {
3091
3092
  super.authenticatedHandler(scope);
3092
- this.effectiveRole = {
3093
+ const roleMap = {
3093
3094
  service: "service",
3094
3095
  admin: "admin",
3095
3096
  owner: "owner",
@@ -3098,8 +3099,16 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3098
3099
  observer: "observer",
3099
3100
  "read-write": "editor",
3100
3101
  readonly: "viewer"
3101
- }[scope] ?? "observer";
3102
+ };
3103
+ const couldWrite = this.canWrite;
3104
+ this.effectiveRole = roleMap[scope] ?? "observer";
3102
3105
  this.offlineStore?.savePermissionSnapshot(this.effectiveRole);
3106
+ if (this.canWrite) this._writeDropWarned = false;
3107
+ this.emit("roleChanged", {
3108
+ role: this.effectiveRole,
3109
+ canWrite: this.canWrite
3110
+ });
3111
+ if (!couldWrite && this.canWrite && this.isSynced) this.flushPendingUpdates().catch(() => null);
3103
3112
  }
3104
3113
  /**
3105
3114
  * Override sendToken to send a pubkey-only identity declaration instead of a
@@ -3150,7 +3159,13 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3150
3159
  async restorePermissionSnapshot() {
3151
3160
  if (!this.offlineStore) return;
3152
3161
  const role = await this.offlineStore.getPermissionSnapshot();
3153
- if (role && !this.effectiveRole) this.effectiveRole = role;
3162
+ if (role && !this.effectiveRole) {
3163
+ this.effectiveRole = role;
3164
+ this.emit("roleChanged", {
3165
+ role: this.effectiveRole,
3166
+ canWrite: this.canWrite
3167
+ });
3168
+ }
3154
3169
  }
3155
3170
  get canWrite() {
3156
3171
  return this.effectiveRole != null && this.effectiveRole !== "viewer" && this.effectiveRole !== "observer";
@@ -3357,7 +3372,19 @@ var AbracadabraProvider = class AbracadabraProvider extends AbracadabraBaseProvi
3357
3372
  if (origin === this) return;
3358
3373
  if (this.offlineStore !== null && origin === this.offlineStore) return;
3359
3374
  this.offlineStore?.persistUpdate(update).catch(() => null);
3360
- if (!this.canWrite) return;
3375
+ if (!this.canWrite) {
3376
+ if (!this._writeDropWarned) {
3377
+ this._writeDropWarned = true;
3378
+ try {
3379
+ 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.`);
3380
+ } catch {}
3381
+ }
3382
+ this.emit("writeDropped", {
3383
+ name: this.configuration?.name,
3384
+ role: this.effectiveRole ?? null
3385
+ });
3386
+ return;
3387
+ }
3361
3388
  super.documentUpdateHandler(update, origin);
3362
3389
  }
3363
3390
  /**