dexie-cloud-addon 4.0.1-beta.56 → 4.0.1-beta.58

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.
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.1-beta.56, Wed Jan 31 2024
11
+ * Version 4.0.1-beta.58, Tue Feb 20 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -3329,7 +3329,7 @@ function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, c
3329
3329
  const res = yield fetch(`${databaseUrl}/sync`, {
3330
3330
  method: 'post',
3331
3331
  headers,
3332
- credentials: 'include',
3332
+ credentials: 'include', // For Arr Affinity cookie only, for better Rate-Limit counting only.
3333
3333
  body: TSON.stringify(syncRequest),
3334
3334
  });
3335
3335
  //const contentLength = Number(res.headers.get('content-length'));
@@ -4287,7 +4287,7 @@ function otpFetchTokenCallback(db) {
4287
4287
  if (response.type !== 'otp-sent')
4288
4288
  throw new Error(`Unexpected response from ${url}/token`);
4289
4289
  const otp = yield promptForOTP(userInteraction, tokenRequest.email);
4290
- const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id });
4290
+ const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id, public_key });
4291
4291
  let res2 = yield fetch(`${url}/token`, {
4292
4292
  body: JSON.stringify(tokenRequest2),
4293
4293
  method: 'post',
@@ -4391,11 +4391,16 @@ function login(db, hints) {
4391
4391
  const origUserId = currentUser.userId;
4392
4392
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
4393
4393
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
4394
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
4394
+ if (licenseStatus === 'ok' &&
4395
+ currentUser.accessToken &&
4396
+ (!currentUser.accessTokenExpiration ||
4397
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
4395
4398
  // Already authenticated according to given hints. And license is valid.
4396
4399
  return false;
4397
4400
  }
4398
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4401
+ if (currentUser.refreshToken &&
4402
+ (!currentUser.refreshTokenExpiration ||
4403
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4399
4404
  // Refresh the token
4400
4405
  yield loadAccessToken(db);
4401
4406
  return false;
@@ -4407,7 +4412,8 @@ function login(db, hints) {
4407
4412
  lastLogin: new Date(0),
4408
4413
  });
4409
4414
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4410
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
4415
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
4416
+ context.userId !== origUserId) {
4411
4417
  // User was logged in before, but now logged in as another user.
4412
4418
  yield logout(db);
4413
4419
  }
@@ -4426,7 +4432,7 @@ function login(db, hints) {
4426
4432
  yield setCurrentUser(db, context);
4427
4433
  // Make sure to resync as the new login will be authorized
4428
4434
  // for new realms.
4429
- triggerSync(db, "pull");
4435
+ triggerSync(db, 'pull');
4430
4436
  return context.userId !== origUserId;
4431
4437
  });
4432
4438
  }
@@ -5583,7 +5589,7 @@ function LocalSyncWorker(db, cloudOptions, cloudSchema) {
5583
5589
  retryPurpose = null;
5584
5590
  syncIfPossible(db, cloudOptions, cloudSchema, {
5585
5591
  cancelToken,
5586
- retryImmediatelyOnFetchError: true,
5592
+ retryImmediatelyOnFetchError: true, // workaround for "net::ERR_NETWORK_CHANGED" in chrome.
5587
5593
  purpose: combPurpose,
5588
5594
  }).catch((e) => {
5589
5595
  console.error('error in syncIfPossible()', e);
@@ -6257,7 +6263,7 @@ function dexieCloud(dexie) {
6257
6263
  const syncComplete = new Subject();
6258
6264
  dexie.cloud = {
6259
6265
  // @ts-ignore
6260
- version: "4.0.1-beta.56",
6266
+ version: "4.0.1-beta.58",
6261
6267
  options: Object.assign({}, DEFAULT_OPTIONS),
6262
6268
  schema: null,
6263
6269
  get currentUserId() {
@@ -6488,7 +6494,10 @@ function dexieCloud(dexie) {
6488
6494
  // HERE: If requireAuth, do athentication now.
6489
6495
  let changedUser = false;
6490
6496
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6491
- changedUser = yield login(db);
6497
+ const user = yield db.getCurrentUser();
6498
+ if (!user.isLoggedIn) {
6499
+ changedUser = yield login(db);
6500
+ }
6492
6501
  }
6493
6502
  if (localSyncWorker)
6494
6503
  localSyncWorker.stop();
@@ -6534,7 +6543,7 @@ function dexieCloud(dexie) {
6534
6543
  }
6535
6544
  }
6536
6545
  // @ts-ignore
6537
- dexieCloud.version = "4.0.1-beta.56";
6546
+ dexieCloud.version = "4.0.1-beta.58";
6538
6547
  Dexie.Cloud = dexieCloud;
6539
6548
 
6540
6549
  // In case the SW lives for a while, let it reuse already opened connections: