dexie-cloud-addon 4.4.7 → 4.4.9

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.
@@ -50,7 +50,7 @@ export interface DexieCloudOptions {
50
50
  * Best for apps with large media that may not all be needed offline.
51
51
  */
52
52
  blobMode?: 'eager' | 'lazy';
53
- /** Maximum string length (in characters) before offloading to blob storage during sync.
53
+ /** String length threshold (in characters) for offloading to blob storage during sync.
54
54
  *
55
55
  * Strings longer than this threshold are uploaded as blobs during sync,
56
56
  * reducing sync payload size. The original string is kept intact in IndexedDB.
@@ -61,5 +61,9 @@ export interface DexieCloudOptions {
61
61
  *
62
62
  * @default 32768
63
63
  */
64
+ largeStringThreshold?: number;
65
+ /**
66
+ * @deprecated Use `largeStringThreshold` instead.
67
+ */
64
68
  maxStringLength?: number;
65
69
  }
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.4.7, Fri Mar 27 2026
11
+ * Version 4.4.9, Tue Mar 31 2026
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -4569,6 +4569,14 @@ function loadCachedAccessToken(db) {
4569
4569
  });
4570
4570
  return Promise.resolve(currentUser.accessToken);
4571
4571
  }
4572
+ // If the current user is not logged in (no isLoggedIn flag), there's no
4573
+ // token to load from the database — skip the Dexie.ignoreTransaction() call.
4574
+ // This avoids a crash in service worker context where Dexie's Promise zone
4575
+ // (PSD.transless.env) may be undefined when called from within an active
4576
+ // rw transaction (e.g. during applyServerChanges).
4577
+ if (!(currentUser === null || currentUser === void 0 ? void 0 : currentUser.isLoggedIn)) {
4578
+ return Promise.resolve(null);
4579
+ }
4572
4580
  return Dexie.ignoreTransaction(() => loadAccessToken(db).then((user) => {
4573
4581
  var _a, _b;
4574
4582
  if (user === null || user === void 0 ? void 0 : user.accessToken) {
@@ -4630,7 +4638,7 @@ function _sync(db_1, options_1, schema_1) {
4630
4638
  return __awaiter(this, arguments, void 0, function* (db, options, schema, { isInitialSync, cancelToken, justCheckIfNeeded, purpose } = {
4631
4639
  isInitialSync: false,
4632
4640
  }) {
4633
- var _a, _b, _c;
4641
+ var _a, _b, _c, _d, _e;
4634
4642
  if (!justCheckIfNeeded) {
4635
4643
  console.debug('SYNC STARTED', { isInitialSync, purpose });
4636
4644
  }
@@ -4704,7 +4712,7 @@ function _sync(db_1, options_1, schema_1) {
4704
4712
  // Offload large blobs to blob storage before sync
4705
4713
  //
4706
4714
  let processedChangeSet = clientChangeSet;
4707
- const maxStringLength = (_c = (_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.maxStringLength) !== null && _c !== void 0 ? _c : 32768;
4715
+ const maxStringLength = (_e = (_c = (_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.largeStringThreshold) !== null && _c !== void 0 ? _c : (_d = db.cloud.options) === null || _d === void 0 ? void 0 : _d.maxStringLength) !== null && _e !== void 0 ? _e : 32768;
4708
4716
  const hasLargeBlobs = hasLargeBlobsInOperations(clientChangeSet, maxStringLength);
4709
4717
  if (hasLargeBlobs) {
4710
4718
  processedChangeSet = yield offloadBlobsInOperations(clientChangeSet, databaseUrl, () => loadCachedAccessToken(db), maxStringLength);
@@ -5150,8 +5158,9 @@ class BlobDownloadTracker {
5150
5158
  if (!promise) {
5151
5159
  promise = loadCachedAccessToken(this.db)
5152
5160
  .then((accessToken) => {
5153
- if (!accessToken)
5154
- throw new Error('No access token available for blob download');
5161
+ // accessToken may be null for anonymous/unauthenticated users.
5162
+ // Public realm blobs (rlm-public) are accessible without auth.
5163
+ // downloadBlob will omit the Authorization header when token is null.
5155
5164
  return downloadBlob(blobRef, dbUrl, accessToken);
5156
5165
  })
5157
5166
  .finally(() => this.inFlight.delete(blobRef.ref));
@@ -5164,19 +5173,22 @@ class BlobDownloadTracker {
5164
5173
  /**
5165
5174
  * Download blob data from server via proxy endpoint.
5166
5175
  * Uses auth header for authentication (same as sync).
5176
+ * When accessToken is null, the request is made without Authorization header —
5177
+ * this allows downloading blobs from public realms (rlm-public) for
5178
+ * unauthenticated users.
5167
5179
  *
5168
5180
  * @param blobRef - The BlobRef to download
5169
5181
  * @param dbUrl - Base URL for the database (e.g., 'https://mydb.dexie.cloud')
5170
- * @param accessToken - Access token for authentication
5182
+ * @param accessToken - Access token for authentication, or null for anonymous access
5171
5183
  */
5172
5184
  function downloadBlob(blobRef, dbUrl, accessToken) {
5173
5185
  return __awaiter(this, void 0, void 0, function* () {
5174
5186
  const downloadUrl = `${dbUrl}/blob/${blobRef.ref}`;
5175
- const response = yield fetch(downloadUrl, {
5176
- headers: {
5177
- Authorization: `Bearer ${accessToken}`,
5178
- },
5179
- });
5187
+ const headers = {};
5188
+ if (accessToken) {
5189
+ headers['Authorization'] = `Bearer ${accessToken}`;
5190
+ }
5191
+ const response = yield fetch(downloadUrl, { headers });
5180
5192
  if (!response.ok) {
5181
5193
  throw new Error(`Failed to download blob ${blobRef.ref}: ${response.status} ${response.statusText}`);
5182
5194
  }
@@ -8488,7 +8500,7 @@ function dexieCloud(dexie) {
8488
8500
  const downloading$ = createDownloadingState();
8489
8501
  dexie.cloud = {
8490
8502
  // @ts-ignore
8491
- version: "4.4.7",
8503
+ version: "4.4.9",
8492
8504
  options: Object.assign({}, DEFAULT_OPTIONS),
8493
8505
  schema: null,
8494
8506
  get currentUserId() {
@@ -8516,18 +8528,27 @@ function dexieCloud(dexie) {
8516
8528
  invites: getInvitesObservable(dexie),
8517
8529
  roles: getGlobalRolesObservable(dexie),
8518
8530
  configure(options) {
8519
- // Validate maxStringLength Infinity disables offloading, otherwise must be
8520
- // a finite number between 100 and the server limit (32768).
8531
+ // Validate largeStringThreshold (preferred) or maxStringLength (deprecated)
8532
+ // Infinity disables offloading, otherwise must be a finite number between 100
8533
+ // and the server limit (32768).
8521
8534
  // Minimum 100 prevents accidental offloading of primary keys and short strings
8522
8535
  // that would break sync.
8523
8536
  const MIN_STRING_LENGTH = 100;
8524
8537
  const MAX_SERVER_STRING_LENGTH = 32768;
8525
- if (options.maxStringLength !== undefined &&
8526
- options.maxStringLength !== Infinity &&
8527
- (!Number.isFinite(options.maxStringLength) ||
8528
- options.maxStringLength < MIN_STRING_LENGTH ||
8529
- options.maxStringLength > MAX_SERVER_STRING_LENGTH)) {
8530
- throw new Error(`maxStringLength must be Infinity or a finite number in [${MIN_STRING_LENGTH}, ${MAX_SERVER_STRING_LENGTH}]. Got: ${options.maxStringLength}`);
8538
+ if (options.maxStringLength !== undefined) {
8539
+ console.warn('maxStringLength is deprecated, use largeStringThreshold instead');
8540
+ // If largeStringThreshold is not explicitly set, migrate to new name
8541
+ if (options.largeStringThreshold === undefined) {
8542
+ options = Object.assign(Object.assign({}, options), { largeStringThreshold: options.maxStringLength });
8543
+ }
8544
+ }
8545
+ const thresholdValue = options.largeStringThreshold;
8546
+ if (thresholdValue !== undefined &&
8547
+ thresholdValue !== Infinity &&
8548
+ (!Number.isFinite(thresholdValue) ||
8549
+ thresholdValue < MIN_STRING_LENGTH ||
8550
+ thresholdValue > MAX_SERVER_STRING_LENGTH)) {
8551
+ throw new Error(`largeStringThreshold must be Infinity or a finite number in [${MIN_STRING_LENGTH}, ${MAX_SERVER_STRING_LENGTH}]. Got: ${thresholdValue}`);
8531
8552
  }
8532
8553
  options = dexie.cloud.options = Object.assign(Object.assign({}, dexie.cloud.options), options);
8533
8554
  configuredProgramatically = true;
@@ -8924,7 +8945,7 @@ function dexieCloud(dexie) {
8924
8945
  }
8925
8946
  }
8926
8947
  // @ts-ignore
8927
- dexieCloud.version = "4.4.7";
8948
+ dexieCloud.version = "4.4.9";
8928
8949
  Dexie.Cloud = dexieCloud;
8929
8950
 
8930
8951
  export { dexieCloud as default, defineYDocTrigger, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };