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
  *
@@ -2498,7 +2498,7 @@ function otpFetchTokenCallback(db) {
2498
2498
  if (response.type !== 'otp-sent')
2499
2499
  throw new Error(`Unexpected response from ${url}/token`);
2500
2500
  const otp = yield promptForOTP(userInteraction, tokenRequest.email);
2501
- const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id });
2501
+ const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id, public_key });
2502
2502
  let res2 = yield fetch(`${url}/token`, {
2503
2503
  body: JSON.stringify(tokenRequest2),
2504
2504
  method: 'post',
@@ -2602,11 +2602,16 @@ function login(db, hints) {
2602
2602
  const origUserId = currentUser.userId;
2603
2603
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
2604
2604
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
2605
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
2605
+ if (licenseStatus === 'ok' &&
2606
+ currentUser.accessToken &&
2607
+ (!currentUser.accessTokenExpiration ||
2608
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
2606
2609
  // Already authenticated according to given hints. And license is valid.
2607
2610
  return false;
2608
2611
  }
2609
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2612
+ if (currentUser.refreshToken &&
2613
+ (!currentUser.refreshTokenExpiration ||
2614
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2610
2615
  // Refresh the token
2611
2616
  yield loadAccessToken(db);
2612
2617
  return false;
@@ -2618,7 +2623,8 @@ function login(db, hints) {
2618
2623
  lastLogin: new Date(0),
2619
2624
  });
2620
2625
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
2621
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
2626
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
2627
+ context.userId !== origUserId) {
2622
2628
  // User was logged in before, but now logged in as another user.
2623
2629
  yield logout(db);
2624
2630
  }
@@ -2637,7 +2643,7 @@ function login(db, hints) {
2637
2643
  yield setCurrentUser(db, context);
2638
2644
  // Make sure to resync as the new login will be authorized
2639
2645
  // for new realms.
2640
- triggerSync(db, "pull");
2646
+ triggerSync(db, 'pull');
2641
2647
  return context.userId !== origUserId;
2642
2648
  });
2643
2649
  }
@@ -3619,7 +3625,7 @@ function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, c
3619
3625
  const res = yield fetch(`${databaseUrl}/sync`, {
3620
3626
  method: 'post',
3621
3627
  headers,
3622
- credentials: 'include',
3628
+ credentials: 'include', // For Arr Affinity cookie only, for better Rate-Limit counting only.
3623
3629
  body: TSON.stringify(syncRequest),
3624
3630
  });
3625
3631
  //const contentLength = Number(res.headers.get('content-length'));
@@ -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);
@@ -6264,7 +6270,7 @@ function dexieCloud(dexie) {
6264
6270
  const syncComplete = new Subject();
6265
6271
  dexie.cloud = {
6266
6272
  // @ts-ignore
6267
- version: "4.0.1-beta.56",
6273
+ version: "4.0.1-beta.58",
6268
6274
  options: Object.assign({}, DEFAULT_OPTIONS),
6269
6275
  schema: null,
6270
6276
  get currentUserId() {
@@ -6495,7 +6501,10 @@ function dexieCloud(dexie) {
6495
6501
  // HERE: If requireAuth, do athentication now.
6496
6502
  let changedUser = false;
6497
6503
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6498
- changedUser = yield login(db);
6504
+ const user = yield db.getCurrentUser();
6505
+ if (!user.isLoggedIn) {
6506
+ changedUser = yield login(db);
6507
+ }
6499
6508
  }
6500
6509
  if (localSyncWorker)
6501
6510
  localSyncWorker.stop();
@@ -6541,7 +6550,7 @@ function dexieCloud(dexie) {
6541
6550
  }
6542
6551
  }
6543
6552
  // @ts-ignore
6544
- dexieCloud.version = "4.0.1-beta.56";
6553
+ dexieCloud.version = "4.0.1-beta.58";
6545
6554
  Dexie.Cloud = dexieCloud;
6546
6555
 
6547
6556
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };