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
  *
@@ -3332,7 +3332,7 @@
3332
3332
  const res = yield fetch(`${databaseUrl}/sync`, {
3333
3333
  method: 'post',
3334
3334
  headers,
3335
- credentials: 'include',
3335
+ credentials: 'include', // For Arr Affinity cookie only, for better Rate-Limit counting only.
3336
3336
  body: TSON.stringify(syncRequest),
3337
3337
  });
3338
3338
  //const contentLength = Number(res.headers.get('content-length'));
@@ -4290,7 +4290,7 @@
4290
4290
  if (response.type !== 'otp-sent')
4291
4291
  throw new Error(`Unexpected response from ${url}/token`);
4292
4292
  const otp = yield promptForOTP(userInteraction, tokenRequest.email);
4293
- const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id });
4293
+ const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id, public_key });
4294
4294
  let res2 = yield fetch(`${url}/token`, {
4295
4295
  body: JSON.stringify(tokenRequest2),
4296
4296
  method: 'post',
@@ -4394,11 +4394,16 @@
4394
4394
  const origUserId = currentUser.userId;
4395
4395
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
4396
4396
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
4397
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
4397
+ if (licenseStatus === 'ok' &&
4398
+ currentUser.accessToken &&
4399
+ (!currentUser.accessTokenExpiration ||
4400
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
4398
4401
  // Already authenticated according to given hints. And license is valid.
4399
4402
  return false;
4400
4403
  }
4401
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4404
+ if (currentUser.refreshToken &&
4405
+ (!currentUser.refreshTokenExpiration ||
4406
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4402
4407
  // Refresh the token
4403
4408
  yield loadAccessToken(db);
4404
4409
  return false;
@@ -4410,7 +4415,8 @@
4410
4415
  lastLogin: new Date(0),
4411
4416
  });
4412
4417
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4413
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
4418
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
4419
+ context.userId !== origUserId) {
4414
4420
  // User was logged in before, but now logged in as another user.
4415
4421
  yield logout(db);
4416
4422
  }
@@ -4429,7 +4435,7 @@
4429
4435
  yield setCurrentUser(db, context);
4430
4436
  // Make sure to resync as the new login will be authorized
4431
4437
  // for new realms.
4432
- triggerSync(db, "pull");
4438
+ triggerSync(db, 'pull');
4433
4439
  return context.userId !== origUserId;
4434
4440
  });
4435
4441
  }
@@ -5586,7 +5592,7 @@
5586
5592
  retryPurpose = null;
5587
5593
  syncIfPossible(db, cloudOptions, cloudSchema, {
5588
5594
  cancelToken,
5589
- retryImmediatelyOnFetchError: true,
5595
+ retryImmediatelyOnFetchError: true, // workaround for "net::ERR_NETWORK_CHANGED" in chrome.
5590
5596
  purpose: combPurpose,
5591
5597
  }).catch((e) => {
5592
5598
  console.error('error in syncIfPossible()', e);
@@ -6260,7 +6266,7 @@
6260
6266
  const syncComplete = new rxjs.Subject();
6261
6267
  dexie.cloud = {
6262
6268
  // @ts-ignore
6263
- version: "4.0.1-beta.56",
6269
+ version: "4.0.1-beta.58",
6264
6270
  options: Object.assign({}, DEFAULT_OPTIONS),
6265
6271
  schema: null,
6266
6272
  get currentUserId() {
@@ -6491,7 +6497,10 @@
6491
6497
  // HERE: If requireAuth, do athentication now.
6492
6498
  let changedUser = false;
6493
6499
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6494
- changedUser = yield login(db);
6500
+ const user = yield db.getCurrentUser();
6501
+ if (!user.isLoggedIn) {
6502
+ changedUser = yield login(db);
6503
+ }
6495
6504
  }
6496
6505
  if (localSyncWorker)
6497
6506
  localSyncWorker.stop();
@@ -6537,7 +6546,7 @@
6537
6546
  }
6538
6547
  }
6539
6548
  // @ts-ignore
6540
- dexieCloud.version = "4.0.1-beta.56";
6549
+ dexieCloud.version = "4.0.1-beta.58";
6541
6550
  Dexie.Cloud = dexieCloud;
6542
6551
 
6543
6552
  // In case the SW lives for a while, let it reuse already opened connections: