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
|
*
|
|
@@ -3906,9 +3906,7 @@
|
|
|
3906
3906
|
// If the sync worker or service worker is syncing, wait 'til thei're done.
|
|
3907
3907
|
// It's no need to have two channels at the same time - even though it wouldnt
|
|
3908
3908
|
// be a problem - this is an optimization.
|
|
3909
|
-
yield db.cloud.syncState
|
|
3910
|
-
.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error'), take(1))
|
|
3911
|
-
.toPromise();
|
|
3909
|
+
yield rxjs.firstValueFrom(db.cloud.syncState.pipe(filter(({ phase }) => phase === 'in-sync' || phase === 'error')));
|
|
3912
3910
|
console.debug('processing msg', msg);
|
|
3913
3911
|
const persistedSyncState = db.cloud.persistedSyncState.value;
|
|
3914
3912
|
//syncState.
|
|
@@ -4430,11 +4428,16 @@
|
|
|
4430
4428
|
const origUserId = currentUser.userId;
|
|
4431
4429
|
if (currentUser.isLoggedIn && (!hints || (!hints.email && !hints.userId))) {
|
|
4432
4430
|
const licenseStatus = ((_a = currentUser.license) === null || _a === void 0 ? void 0 : _a.status) || 'ok';
|
|
4433
|
-
if (licenseStatus === 'ok' &&
|
|
4431
|
+
if (licenseStatus === 'ok' &&
|
|
4432
|
+
currentUser.accessToken &&
|
|
4433
|
+
(!currentUser.accessTokenExpiration ||
|
|
4434
|
+
currentUser.accessTokenExpiration.getTime() > Date.now())) {
|
|
4434
4435
|
// Already authenticated according to given hints. And license is valid.
|
|
4435
4436
|
return false;
|
|
4436
4437
|
}
|
|
4437
|
-
if (currentUser.refreshToken &&
|
|
4438
|
+
if (currentUser.refreshToken &&
|
|
4439
|
+
(!currentUser.refreshTokenExpiration ||
|
|
4440
|
+
currentUser.refreshTokenExpiration.getTime() > Date.now())) {
|
|
4438
4441
|
// Refresh the token
|
|
4439
4442
|
yield loadAccessToken(db);
|
|
4440
4443
|
return false;
|
|
@@ -4446,7 +4449,8 @@
|
|
|
4446
4449
|
lastLogin: new Date(0),
|
|
4447
4450
|
});
|
|
4448
4451
|
yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
|
|
4449
|
-
if (origUserId !== UNAUTHORIZED_USER.userId &&
|
|
4452
|
+
if (origUserId !== UNAUTHORIZED_USER.userId &&
|
|
4453
|
+
context.userId !== origUserId) {
|
|
4450
4454
|
// User was logged in before, but now logged in as another user.
|
|
4451
4455
|
yield logout(db);
|
|
4452
4456
|
}
|
|
@@ -4465,7 +4469,7 @@
|
|
|
4465
4469
|
yield setCurrentUser(db, context);
|
|
4466
4470
|
// Make sure to resync as the new login will be authorized
|
|
4467
4471
|
// for new realms.
|
|
4468
|
-
triggerSync(db,
|
|
4472
|
+
triggerSync(db, 'pull');
|
|
4469
4473
|
return context.userId !== origUserId;
|
|
4470
4474
|
});
|
|
4471
4475
|
}
|
|
@@ -5411,7 +5415,7 @@
|
|
|
5411
5415
|
yield sleep$1(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
|
}
|
|
@@ -6302,7 +6306,7 @@
|
|
|
6302
6306
|
const syncComplete = new rxjs.Subject();
|
|
6303
6307
|
dexie.cloud = {
|
|
6304
6308
|
// @ts-ignore
|
|
6305
|
-
version: "4.0.
|
|
6309
|
+
version: "4.0.5",
|
|
6306
6310
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6307
6311
|
schema: null,
|
|
6308
6312
|
get currentUserId() {
|
|
@@ -6360,10 +6364,8 @@
|
|
|
6360
6364
|
const syncState = db.cloud.persistedSyncState.value;
|
|
6361
6365
|
triggerSync(db, purpose);
|
|
6362
6366
|
if (wait) {
|
|
6363
|
-
const newSyncState = yield db.cloud.persistedSyncState
|
|
6364
|
-
|
|
6365
|
-
(!syncState || newSyncState.timestamp > syncState.timestamp)), take(1))
|
|
6366
|
-
.toPromise();
|
|
6367
|
+
const newSyncState = yield rxjs.firstValueFrom(db.cloud.persistedSyncState.pipe(filter((newSyncState) => (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) != null &&
|
|
6368
|
+
(!syncState || newSyncState.timestamp > syncState.timestamp))));
|
|
6367
6369
|
if (newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error) {
|
|
6368
6370
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6369
6371
|
}
|
|
@@ -6374,16 +6376,14 @@
|
|
|
6374
6376
|
triggerSync(db, purpose);
|
|
6375
6377
|
if (wait) {
|
|
6376
6378
|
console.debug('db.cloud.login() is waiting for sync completion...');
|
|
6377
|
-
yield rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6379
|
+
yield rxjs.firstValueFrom(rxjs.from(Dexie.liveQuery(() => __awaiter(this, void 0, void 0, function* () {
|
|
6378
6380
|
const syncNeeded = yield isSyncNeeded(db);
|
|
6379
6381
|
const newSyncState = yield db.getPersistedSyncState();
|
|
6380
6382
|
if ((newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.timestamp) !== (syncState === null || syncState === void 0 ? void 0 : syncState.timestamp) &&
|
|
6381
6383
|
(newSyncState === null || newSyncState === void 0 ? void 0 : newSyncState.error))
|
|
6382
6384
|
throw new Error(`Sync error: ` + newSyncState.error);
|
|
6383
6385
|
return syncNeeded;
|
|
6384
|
-
})))
|
|
6385
|
-
.pipe(filter((isNeeded) => !isNeeded), take(1))
|
|
6386
|
-
.toPromise();
|
|
6386
|
+
}))).pipe(filter((isNeeded) => !isNeeded)));
|
|
6387
6387
|
console.debug('Done waiting for sync completion because we have nothing to push anymore');
|
|
6388
6388
|
}
|
|
6389
6389
|
}
|
|
@@ -6432,7 +6432,7 @@
|
|
|
6432
6432
|
const swRegistrations = 'serviceWorker' in navigator
|
|
6433
6433
|
? yield navigator.serviceWorker.getRegistrations()
|
|
6434
6434
|
: [];
|
|
6435
|
-
const initiallySynced = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6435
|
+
const [initiallySynced, lastSyncedRealms] = yield db.transaction('rw', db.$syncState, () => __awaiter(this, void 0, void 0, function* () {
|
|
6436
6436
|
var _h, _j;
|
|
6437
6437
|
const { options, schema } = db.cloud;
|
|
6438
6438
|
const [persistedOptions, persistedSchema, persistedSyncState] = yield Promise.all([
|
|
@@ -6505,7 +6505,7 @@
|
|
|
6505
6505
|
// Let's assign all props as the newPersistedSchems should be what we should be working with.
|
|
6506
6506
|
Object.assign(schema, newPersistedSchema);
|
|
6507
6507
|
}
|
|
6508
|
-
return persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced;
|
|
6508
|
+
return [persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.initiallySynced, persistedSyncState === null || persistedSyncState === void 0 ? void 0 : persistedSyncState.realms];
|
|
6509
6509
|
}));
|
|
6510
6510
|
if (initiallySynced) {
|
|
6511
6511
|
db.setInitiallySynced(true);
|
|
@@ -6525,15 +6525,26 @@
|
|
|
6525
6525
|
// with things from the database and not just the default values.
|
|
6526
6526
|
// This is so that when db.open() completes, user should be safe
|
|
6527
6527
|
// to subscribe to these observables and get actual data.
|
|
6528
|
-
yield rxjs.combineLatest([
|
|
6528
|
+
yield rxjs.firstValueFrom(rxjs.combineLatest([
|
|
6529
6529
|
currentUserEmitter.pipe(skip(1), take(1)),
|
|
6530
6530
|
db.cloud.persistedSyncState.pipe(skip(1), take(1)),
|
|
6531
|
-
])
|
|
6531
|
+
]));
|
|
6532
6532
|
}
|
|
6533
6533
|
// HERE: If requireAuth, do athentication now.
|
|
6534
6534
|
let changedUser = false;
|
|
6535
|
+
const user = yield db.getCurrentUser();
|
|
6535
6536
|
if ((_c = db.cloud.options) === null || _c === void 0 ? void 0 : _c.requireAuth) {
|
|
6536
|
-
|
|
6537
|
+
if (!user.isLoggedIn) {
|
|
6538
|
+
changedUser = yield login(db);
|
|
6539
|
+
}
|
|
6540
|
+
}
|
|
6541
|
+
if (user.isLoggedIn && (!lastSyncedRealms || !lastSyncedRealms.includes(user.userId))) {
|
|
6542
|
+
// User has been logged in but this is not reflected in the sync state.
|
|
6543
|
+
// This can happen if page is reloaded after login but before the sync call following
|
|
6544
|
+
// the login was complete.
|
|
6545
|
+
// The user is to be viewed as changed becuase current syncState does not reflect the presence
|
|
6546
|
+
// of the logged-in user.
|
|
6547
|
+
changedUser = true; // Set changedUser to true to trigger a pull-sync later down.
|
|
6537
6548
|
}
|
|
6538
6549
|
if (localSyncWorker)
|
|
6539
6550
|
localSyncWorker.stop();
|
|
@@ -6579,7 +6590,7 @@
|
|
|
6579
6590
|
}
|
|
6580
6591
|
}
|
|
6581
6592
|
// @ts-ignore
|
|
6582
|
-
dexieCloud.version = "4.0.
|
|
6593
|
+
dexieCloud.version = "4.0.5";
|
|
6583
6594
|
Dexie.Cloud = dexieCloud;
|
|
6584
6595
|
|
|
6585
6596
|
// In case the SW lives for a while, let it reuse already opened connections:
|