dexie-cloud-addon 4.0.2 → 4.0.4

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.
@@ -19,4 +19,5 @@ export interface UserLogin {
19
19
  nonExportablePrivateKey?: CryptoKey;
20
20
  publicKey?: CryptoKey;
21
21
  isLoggedIn?: boolean;
22
+ data?: any;
22
23
  }
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.0.2, Wed Apr 10 2024
11
+ * Version 4.0.4, Mon Apr 29 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -2220,6 +2220,9 @@ function refreshAccessToken(url, login) {
2220
2220
  if (response.userValidUntil != null) {
2221
2221
  login.license.validUntil = new Date(response.userValidUntil);
2222
2222
  }
2223
+ if (response.data) {
2224
+ login.data = response.data;
2225
+ }
2223
2226
  return login;
2224
2227
  });
2225
2228
  }
@@ -2274,6 +2277,7 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
2274
2277
  type: response2.userType,
2275
2278
  status: response2.claims.license || 'ok',
2276
2279
  };
2280
+ context.data = response2.data;
2277
2281
  if (response2.evalDaysLeft != null) {
2278
2282
  context.license.evalDaysLeft = response2.evalDaysLeft;
2279
2283
  }
@@ -2624,11 +2628,16 @@ function login(db, hints) {
2624
2628
  const origUserId = currentUser.userId;
2625
2629
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
2626
2630
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
2627
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
2631
+ if (licenseStatus === 'ok' &&
2632
+ currentUser.accessToken &&
2633
+ (!currentUser.accessTokenExpiration ||
2634
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
2628
2635
  // Already authenticated according to given hints. And license is valid.
2629
2636
  return false;
2630
2637
  }
2631
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2638
+ if (currentUser.refreshToken &&
2639
+ (!currentUser.refreshTokenExpiration ||
2640
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
2632
2641
  // Refresh the token
2633
2642
  yield loadAccessToken(db);
2634
2643
  return false;
@@ -2640,7 +2649,8 @@ function login(db, hints) {
2640
2649
  lastLogin: new Date(0),
2641
2650
  });
2642
2651
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
2643
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
2652
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
2653
+ context.userId !== origUserId) {
2644
2654
  // User was logged in before, but now logged in as another user.
2645
2655
  yield logout(db);
2646
2656
  }
@@ -2659,7 +2669,7 @@ function login(db, hints) {
2659
2669
  yield setCurrentUser(db, context);
2660
2670
  // Make sure to resync as the new login will be authorized
2661
2671
  // for new realms.
2662
- triggerSync(db, "pull");
2672
+ triggerSync(db, 'pull');
2663
2673
  return context.userId !== origUserId;
2664
2674
  });
2665
2675
  }
@@ -4219,6 +4229,7 @@ function MessagesFromServerConsumer(db) {
4219
4229
  accessTokenExpiration: refreshedLogin.accessTokenExpiration,
4220
4230
  claims: refreshedLogin.claims,
4221
4231
  license: refreshedLogin.license,
4232
+ data: refreshedLogin.data,
4222
4233
  });
4223
4234
  // Updating $logins will trigger emission of db.cloud.currentUser observable, which
4224
4235
  // in turn will lead to that connectWebSocket.ts will reconnect the socket with the
@@ -5467,6 +5478,7 @@ function connectWebSocket(db) {
5467
5478
  accessTokenExpiration: refreshedLogin.accessTokenExpiration,
5468
5479
  claims: refreshedLogin.claims,
5469
5480
  license: refreshedLogin.license,
5481
+ data: refreshedLogin.data
5470
5482
  });
5471
5483
  })), switchMap(() => createObservable()));
5472
5484
  }
@@ -6300,7 +6312,7 @@ function dexieCloud(dexie) {
6300
6312
  const syncComplete = new Subject();
6301
6313
  dexie.cloud = {
6302
6314
  // @ts-ignore
6303
- version: "4.0.2",
6315
+ version: "4.0.4",
6304
6316
  options: Object.assign({}, DEFAULT_OPTIONS),
6305
6317
  schema: null,
6306
6318
  get currentUserId() {
@@ -6531,7 +6543,10 @@ function dexieCloud(dexie) {
6531
6543
  // HERE: If requireAuth, do athentication now.
6532
6544
  let changedUser = false;
6533
6545
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6534
- changedUser = yield login(db);
6546
+ const user = yield db.getCurrentUser();
6547
+ if (!user.isLoggedIn) {
6548
+ changedUser = yield login(db);
6549
+ }
6535
6550
  }
6536
6551
  if (localSyncWorker)
6537
6552
  localSyncWorker.stop();
@@ -6577,7 +6592,7 @@ function dexieCloud(dexie) {
6577
6592
  }
6578
6593
  }
6579
6594
  // @ts-ignore
6580
- dexieCloud.version = "4.0.2";
6595
+ dexieCloud.version = "4.0.4";
6581
6596
  Dexie.Cloud = dexieCloud;
6582
6597
 
6583
6598
  export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };