dexie-cloud-addon 4.0.3 → 4.0.5
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.
- package/dist/modern/dexie-cloud-addon.js +35 -24
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/service-worker.js +36 -25
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.js +35 -24
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/service-worker.js +35 -24
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.0.
|
|
11
|
+
* Version 4.0.5, Sat May 04 2024
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -2631,11 +2631,16 @@
|
|
|
2631
2631
|
const origUserId = currentUser.userId;
|
|
2632
2632
|
if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
|
|
2633
2633
|
const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
|
|
2634
|
-
if (licenseStatus === 'ok' &&
|
|
2634
|
+
if (licenseStatus === 'ok' &&
|
|
2635
|
+
currentUser.accessToken &&
|
|
2636
|
+
(!currentUser.accessTokenExpiration ||
|
|
2637
|
+
currentUser.accessTokenExpiration.getTime() > Date.now())) {
|
|
2635
2638
|
// Already authenticated according to given hints. And license is valid.
|
|
2636
2639
|
return false;
|
|
2637
2640
|
}
|
|
2638
|
-
if (currentUser.refreshToken &&
|
|
2641
|
+
if (currentUser.refreshToken &&
|
|
2642
|
+
(!currentUser.refreshTokenExpiration ||
|
|
2643
|
+
currentUser.refreshTokenExpiration.getTime() > Date.now())) {
|
|
2639
2644
|
// Refresh the token
|
|
2640
2645
|
yield loadAccessToken(db);
|
|
2641
2646
|
return false;
|
|
@@ -2647,7 +2652,8 @@
|
|
|
2647
2652
|
lastLogin: new Date(0),
|
|
2648
2653
|
});
|
|
2649
2654
|
yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
|
|
2650
|
-
if (origUserId !== UNAUTHORIZED_USER.userId &&
|
|
2655
|
+
if (origUserId !== UNAUTHORIZED_USER.userId &&
|
|
2656
|
+
context.userId !== origUserId) {
|
|
2651
2657
|
// User was logged in before, but now logged in as another user.
|
|
2652
2658
|
yield logout(db);
|
|
2653
2659
|
}
|
|
@@ -2666,7 +2672,7 @@
|
|
|
2666
2672
|
yield setCurrentUser(db, context);
|
|
2667
2673
|
// Make sure to resync as the new login will be authorized
|
|
2668
2674
|
// for new realms.
|
|
2669
|
-
triggerSync(db,
|
|
2675
|
+
triggerSync(db, 'pull');
|
|
2670
2676
|
return context.userId !== origUserId;
|
|
2671
2677
|
});
|
|
2672
2678
|
}
|
|
@@ -4206,9 +4212,7 @@
|
|
|
4206
4212
|
// If the sync worker or service worker is syncing, wait 'til thei're done.
|
|
4207
4213
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
4208
4214
|
// be a problem - this is an optimization.
|
|
4209
|
-
yield db.cloud.syncState
|
|
4210
|
-
.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error'), take(1))
|
|
4211
|
-
.toPromise();
|
|
4215
|
+
yield rxjs.firstValueFrom(db.cloud.syncState.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
4212
4216
|
console.debug('processing msg', msg);
|
|
4213
4217
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
4214
4218
|
//syncState.
|
|
@@ -5411,7 +5415,7 @@
|
|
|
5411
5415
|
yield sleep(3000);
|
|
5412
5416
|
// Wait til user does something (move mouse, tap, scroll, click etc)
|
|
5413
5417
|
console.debug('waiting for someone to do something');
|
|
5414
|
-
yield
|
|
5418
|
+
yield rxjs.firstValueFrom(userDoesSomething);
|
|
5415
5419
|
console.debug('someone did something!');
|
|
5416
5420
|
});
|
|
5417
5421
|
}
|
|
@@ -6309,7 +6313,7 @@
|
|
|
6309
6313
|
const syncComplete = new rxjs.Subject();
|
|
6310
6314
|
dexie.cloud = {
|
|
6311
6315
|
// @ts-ignore
|
|
6312
|
-
version: "4.0.
|
|
6316
|
+
version: "4.0.5",
|
|
6313
6317
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6314
6318
|
schema: null,
|
|
6315
6319
|
get currentUserId() {
|
|
@@ -6367,10 +6371,8 @@
|
|
|
6367
6371
|
const syncState = db.cloud.persistedSyncState.value;
|
|
6368
6372
|
triggerSync(db, purpose);
|
|
6369
6373
|
if (wait) {
|
|
6370
|
-
const newSyncState = yield db.cloud.persistedSyncState
|
|
6371
|
-
|
|
6372
|
-
(!syncState || newSyncState.timestamp > syncState.timestamp)), take(1))
|
|
6373
|
-
.toPromise();
|
|
6374
|
+
const newSyncState = yield rxjs.firstValueFrom(db.cloud.persistedSyncState.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6375
|
+
(!syncState || newSyncState.timestamp > syncState.timestamp))));
|
|
6374
6376
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
6375
6377
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6376
6378
|
}
|
|
@@ -6381,16 +6383,14 @@
|
|
|
6381
6383
|
triggerSync(db, purpose);
|
|
6382
6384
|
if (wait) {
|
|
6383
6385
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
6384
|
-
yield rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6386
|
+
yield rxjs.firstValueFrom(rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6385
6387
|
const syncNeeded = yield isSyncNeeded(db);
|
|
6386
6388
|
const newSyncState = yield db.getPersistedSyncState();
|
|
6387
6389
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
6388
6390
|
(newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error))
|
|
6389
6391
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6390
6392
|
return syncNeeded;
|
|
6391
|
-
})))
|
|
6392
|
-
.pipe(filter((isNeeded) => !isNeeded), take(1))
|
|
6393
|
-
.toPromise();
|
|
6393
|
+
}))).pipe(filter((isNeeded) => !isNeeded)));
|
|
6394
6394
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
6395
6395
|
}
|
|
6396
6396
|
}
|
|
@@ -6439,7 +6439,7 @@
|
|
|
6439
6439
|
const swRegistrations = 'serviceWorker' in navigator
|
|
6440
6440
|
? yield navigator.serviceWorker.getRegistrations()
|
|
6441
6441
|
: [];
|
|
6442
|
-
const initiallySynced = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6442
|
+
const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6443
6443
|
var _h, _j;
|
|
6444
6444
|
const { options, schema } = db.cloud;
|
|
6445
6445
|
const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
|
|
@@ -6512,7 +6512,7 @@
|
|
|
6512
6512
|
// Let's assign all props as the newPersistedSchems should be what we should be working with.
|
|
6513
6513
|
Object.assign(schema, newPersistedSchema);
|
|
6514
6514
|
}
|
|
6515
|
-
return persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced;
|
|
6515
|
+
return [persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced, persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms];
|
|
6516
6516
|
}));
|
|
6517
6517
|
if (initiallySynced) {
|
|
6518
6518
|
db.setInitiallySynced(true);
|
|
@@ -6532,15 +6532,26 @@
|
|
|
6532
6532
|
// with things from the database and not just the default values.
|
|
6533
6533
|
// This is so that when db.open() completes, user should be safe
|
|
6534
6534
|
// to subscribe to these observables and get actual data.
|
|
6535
|
-
yield rxjs.combineLatest([
|
|
6535
|
+
yield rxjs.firstValueFrom(rxjs.combineLatest([
|
|
6536
6536
|
currentUserEmitter.pipe(skip(1), take(1)),
|
|
6537
6537
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
6538
|
-
])
|
|
6538
|
+
]));
|
|
6539
6539
|
}
|
|
6540
6540
|
// HERE: If requireAuth, do athentication now.
|
|
6541
6541
|
let changedUser = false;
|
|
6542
|
+
const user = yield db.getCurrentUser();
|
|
6542
6543
|
if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
|
|
6543
|
-
|
|
6544
|
+
if (!user.isLoggedIn) {
|
|
6545
|
+
changedUser = yield login(db);
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
if (user.isLoggedIn && (!lastSyncedRealms || !lastSyncedRealms.includes(user.userId))) {
|
|
6549
|
+
// User has been logged in but this is not reflected in the sync state.
|
|
6550
|
+
// This can happen if page is reloaded after login but before the sync call following
|
|
6551
|
+
// the login was complete.
|
|
6552
|
+
// The user is to be viewed as changed becuase current syncState does not reflect the presence
|
|
6553
|
+
// of the logged-in user.
|
|
6554
|
+
changedUser = true; // Set changedUser to true to trigger a pull-sync later down.
|
|
6544
6555
|
}
|
|
6545
6556
|
if (localSyncWorker)
|
|
6546
6557
|
localSyncWorker.stop();
|
|
@@ -6586,7 +6597,7 @@
|
|
|
6586
6597
|
}
|
|
6587
6598
|
}
|
|
6588
6599
|
// @ts-ignore
|
|
6589
|
-
dexieCloud.version = "4.0.
|
|
6600
|
+
dexieCloud.version = "4.0.5";
|
|
6590
6601
|
Dexie.Cloud = dexieCloud;
|
|
6591
6602
|
|
|
6592
6603
|
exports.default = dexieCloud;
|