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.
@@ -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
  *
@@ -2537,6 +2537,9 @@ function refreshAccessToken(url, login) {
2537
2537
  if (response.userValidUntil != null) {
2538
2538
  login.license.validUntil = new Date(response.userValidUntil);
2539
2539
  }
2540
+ if (response.data) {
2541
+ login.data = response.data;
2542
+ }
2540
2543
  return login;
2541
2544
  });
2542
2545
  }
@@ -2591,6 +2594,7 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
2591
2594
  type: response2.userType,
2592
2595
  status: response2.claims.license || 'ok',
2593
2596
  };
2597
+ context.data = response2.data;
2594
2598
  if (response2.evalDaysLeft != null) {
2595
2599
  context.license.evalDaysLeft = response2.evalDaysLeft;
2596
2600
  }
@@ -3919,6 +3923,7 @@ function MessagesFromServerConsumer(db) {
3919
3923
  accessTokenExpiration: refreshedLogin.accessTokenExpiration,
3920
3924
  claims: refreshedLogin.claims,
3921
3925
  license: refreshedLogin.license,
3926
+ data: refreshedLogin.data,
3922
3927
  });
3923
3928
  // Updating $logins will trigger emission of db.cloud.currentUser observable, which
3924
3929
  // in turn will lead to that connectWebSocket.ts will reconnect the socket with the
@@ -4422,11 +4427,16 @@ function login(db, hints) {
4422
4427
  const origUserId = currentUser.userId;
4423
4428
  if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
4424
4429
  const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
4425
- if (licenseStatus === 'ok' && currentUser.accessToken && (!currentUser.accessTokenExpiration || currentUser.accessTokenExpiration.getTime() > Date.now())) {
4430
+ if (licenseStatus === 'ok' &&
4431
+ currentUser.accessToken &&
4432
+ (!currentUser.accessTokenExpiration ||
4433
+ currentUser.accessTokenExpiration.getTime() > Date.now())) {
4426
4434
  // Already authenticated according to given hints. And license is valid.
4427
4435
  return false;
4428
4436
  }
4429
- if (currentUser.refreshToken && (!currentUser.refreshTokenExpiration || currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4437
+ if (currentUser.refreshToken &&
4438
+ (!currentUser.refreshTokenExpiration ||
4439
+ currentUser.refreshTokenExpiration.getTime() > Date.now())) {
4430
4440
  // Refresh the token
4431
4441
  yield loadAccessToken(db);
4432
4442
  return false;
@@ -4438,7 +4448,8 @@ function login(db, hints) {
4438
4448
  lastLogin: new Date(0),
4439
4449
  });
4440
4450
  yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4441
- if (origUserId !== UNAUTHORIZED_USER.userId && context.userId !== origUserId) {
4451
+ if (origUserId !== UNAUTHORIZED_USER.userId &&
4452
+ context.userId !== origUserId) {
4442
4453
  // User was logged in before, but now logged in as another user.
4443
4454
  yield logout(db);
4444
4455
  }
@@ -4457,7 +4468,7 @@ function login(db, hints) {
4457
4468
  yield setCurrentUser(db, context);
4458
4469
  // Make sure to resync as the new login will be authorized
4459
4470
  // for new realms.
4460
- triggerSync(db, "pull");
4471
+ triggerSync(db, 'pull');
4461
4472
  return context.userId !== origUserId;
4462
4473
  });
4463
4474
  }
@@ -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
  }
@@ -6293,7 +6305,7 @@ function dexieCloud(dexie) {
6293
6305
  const syncComplete = new Subject();
6294
6306
  dexie.cloud = {
6295
6307
  // @ts-ignore
6296
- version: "4.0.2",
6308
+ version: "4.0.4",
6297
6309
  options: Object.assign({}, DEFAULT_OPTIONS),
6298
6310
  schema: null,
6299
6311
  get currentUserId() {
@@ -6524,7 +6536,10 @@ function dexieCloud(dexie) {
6524
6536
  // HERE: If requireAuth, do athentication now.
6525
6537
  let changedUser = false;
6526
6538
  if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
6527
- changedUser = yield login(db);
6539
+ const user = yield db.getCurrentUser();
6540
+ if (!user.isLoggedIn) {
6541
+ changedUser = yield login(db);
6542
+ }
6528
6543
  }
6529
6544
  if (localSyncWorker)
6530
6545
  localSyncWorker.stop();
@@ -6570,7 +6585,7 @@ function dexieCloud(dexie) {
6570
6585
  }
6571
6586
  }
6572
6587
  // @ts-ignore
6573
- dexieCloud.version = "4.0.2";
6588
+ dexieCloud.version = "4.0.4";
6574
6589
  Dexie.Cloud = dexieCloud;
6575
6590
 
6576
6591
  // In case the SW lives for a while, let it reuse already opened connections: