dexie-cloud-addon 4.0.1-beta.55 → 4.0.1-beta.57
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/DexieCloudAPI.d.ts +8 -5
- package/dist/modern/authentication/authenticate.d.ts +3 -10
- package/dist/modern/authentication/login.d.ts +2 -5
- package/dist/modern/dexie-cloud-addon.js +23 -12
- 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 +23 -12
- 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/DexieCloudAPI.d.ts +8 -5
- package/dist/umd/authentication/authenticate.d.ts +3 -10
- package/dist/umd/authentication/login.d.ts +2 -5
- package/dist/umd/dexie-cloud-addon.js +23 -12
- 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 +23 -12
- 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 +2 -2
|
@@ -11,6 +11,13 @@ import { Invite } from './Invite';
|
|
|
11
11
|
import { BehaviorSubject, Observable } from 'rxjs';
|
|
12
12
|
/** The API of db.cloud, where `db` is an instance of Dexie with dexie-cloud-addon active.
|
|
13
13
|
*/
|
|
14
|
+
export interface LoginHints {
|
|
15
|
+
email?: string;
|
|
16
|
+
userId?: string;
|
|
17
|
+
grant_type?: 'demo' | 'otp';
|
|
18
|
+
otpId?: string;
|
|
19
|
+
otp?: string;
|
|
20
|
+
}
|
|
14
21
|
export interface DexieCloudAPI {
|
|
15
22
|
version: string;
|
|
16
23
|
options: DexieCloudOptions | null;
|
|
@@ -36,11 +43,7 @@ export interface DexieCloudAPI {
|
|
|
36
43
|
* @param userId Optional userId to authenticate
|
|
37
44
|
* @param grant_type requested grant type
|
|
38
45
|
*/
|
|
39
|
-
login(hint?:
|
|
40
|
-
email?: string;
|
|
41
|
-
userId?: string;
|
|
42
|
-
grant_type?: 'demo' | 'otp';
|
|
43
|
-
}): Promise<void>;
|
|
46
|
+
login(hint?: LoginHints): Promise<void>;
|
|
44
47
|
logout(options?: {
|
|
45
48
|
force?: boolean;
|
|
46
49
|
}): Promise<void>;
|
|
@@ -3,18 +3,11 @@ import { BehaviorSubject } from 'rxjs';
|
|
|
3
3
|
import { DexieCloudDB } from '../db/DexieCloudDB';
|
|
4
4
|
import { UserLogin } from '../db/entities/UserLogin';
|
|
5
5
|
import { DXCUserInteraction } from '../types/DXCUserInteraction';
|
|
6
|
+
import { LoginHints } from '../DexieCloudAPI';
|
|
6
7
|
export type FetchTokenCallback = (tokenParams: {
|
|
7
8
|
public_key: string;
|
|
8
|
-
hints?:
|
|
9
|
-
userId?: string;
|
|
10
|
-
email?: string;
|
|
11
|
-
grant_type?: string;
|
|
12
|
-
};
|
|
9
|
+
hints?: LoginHints;
|
|
13
10
|
}) => Promise<TokenFinalResponse | TokenErrorResponse>;
|
|
14
11
|
export declare function loadAccessToken(db: DexieCloudDB): Promise<UserLogin | null>;
|
|
15
|
-
export declare function authenticate(url: string, context: UserLogin, fetchToken: FetchTokenCallback, userInteraction: BehaviorSubject<DXCUserInteraction | undefined>, hints?:
|
|
16
|
-
userId?: string;
|
|
17
|
-
email?: string;
|
|
18
|
-
grant_type?: string;
|
|
19
|
-
}): Promise<UserLogin>;
|
|
12
|
+
export declare function authenticate(url: string, context: UserLogin, fetchToken: FetchTokenCallback, userInteraction: BehaviorSubject<DXCUserInteraction | undefined>, hints?: LoginHints): Promise<UserLogin>;
|
|
20
13
|
export declare function refreshAccessToken(url: string, login: UserLogin): Promise<UserLogin>;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
import { DexieCloudDB } from '../db/DexieCloudDB';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
userId?: string;
|
|
5
|
-
grant_type?: string;
|
|
6
|
-
}): Promise<boolean>;
|
|
2
|
+
import { LoginHints } from '../DexieCloudAPI';
|
|
3
|
+
export declare function login(db: DexieCloudDB, hints?: LoginHints): Promise<boolean>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* ==========================================================================
|
|
10
10
|
*
|
|
11
|
-
* Version 4.0.1-beta.
|
|
11
|
+
* Version 4.0.1-beta.57, Wed Feb 14 2024
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -2449,6 +2449,19 @@ function otpFetchTokenCallback(db) {
|
|
|
2449
2449
|
demo_user,
|
|
2450
2450
|
grant_type: 'demo',
|
|
2451
2451
|
scopes: ['ACCESS_DB'],
|
|
2452
|
+
public_key
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
else if ((hints === null || hints === void 0 ? void 0 : hints.otpId) && hints.otp) {
|
|
2456
|
+
// User provided OTP ID and OTP code. This means that the OTP email
|
|
2457
|
+
// has already gone out and the user may have clicked a magic link
|
|
2458
|
+
// in the email with otp and otpId in query and the app has picked
|
|
2459
|
+
// up those values and passed them to db.cloud.login().
|
|
2460
|
+
tokenRequest = {
|
|
2461
|
+
grant_type: 'otp',
|
|
2462
|
+
otp_id: hints.otpId,
|
|
2463
|
+
otp: hints.otp,
|
|
2464
|
+
scopes: ['ACCESS_DB'],
|
|
2452
2465
|
public_key,
|
|
2453
2466
|
};
|
|
2454
2467
|
}
|
|
@@ -2458,7 +2471,6 @@ function otpFetchTokenCallback(db) {
|
|
|
2458
2471
|
email,
|
|
2459
2472
|
grant_type: 'otp',
|
|
2460
2473
|
scopes: ['ACCESS_DB'],
|
|
2461
|
-
public_key,
|
|
2462
2474
|
};
|
|
2463
2475
|
}
|
|
2464
2476
|
const res1 = yield fetch(`${url}/token`, {
|
|
@@ -2482,28 +2494,27 @@ function otpFetchTokenCallback(db) {
|
|
|
2482
2494
|
// Error can also be returned right away.
|
|
2483
2495
|
return response;
|
|
2484
2496
|
}
|
|
2485
|
-
else if (tokenRequest.grant_type === 'otp') {
|
|
2497
|
+
else if (tokenRequest.grant_type === 'otp' && 'email' in tokenRequest) {
|
|
2486
2498
|
if (response.type !== 'otp-sent')
|
|
2487
2499
|
throw new Error(`Unexpected response from ${url}/token`);
|
|
2488
2500
|
const otp = yield promptForOTP(userInteraction, tokenRequest.email);
|
|
2489
|
-
|
|
2490
|
-
tokenRequest.otp_id = response.otp_id;
|
|
2501
|
+
const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id, public_key });
|
|
2491
2502
|
let res2 = yield fetch(`${url}/token`, {
|
|
2492
|
-
body: JSON.stringify(
|
|
2503
|
+
body: JSON.stringify(tokenRequest2),
|
|
2493
2504
|
method: 'post',
|
|
2494
2505
|
headers: { 'Content-Type': 'application/json' },
|
|
2495
2506
|
mode: 'cors',
|
|
2496
2507
|
});
|
|
2497
2508
|
while (res2.status === 401) {
|
|
2498
2509
|
const errorText = yield res2.text();
|
|
2499
|
-
|
|
2510
|
+
tokenRequest2.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
|
|
2500
2511
|
type: 'error',
|
|
2501
2512
|
messageCode: 'INVALID_OTP',
|
|
2502
2513
|
message: errorText,
|
|
2503
2514
|
messageParams: {}
|
|
2504
2515
|
});
|
|
2505
2516
|
res2 = yield fetch(`${url}/token`, {
|
|
2506
|
-
body: JSON.stringify(
|
|
2517
|
+
body: JSON.stringify(tokenRequest2),
|
|
2507
2518
|
method: 'post',
|
|
2508
2519
|
headers: { 'Content-Type': 'application/json' },
|
|
2509
2520
|
mode: 'cors',
|
|
@@ -3608,7 +3619,7 @@ function syncWithServer(changes, syncState, baseRevs, db, databaseUrl, schema, c
|
|
|
3608
3619
|
const res = yield fetch(`${databaseUrl}/sync`, {
|
|
3609
3620
|
method: 'post',
|
|
3610
3621
|
headers,
|
|
3611
|
-
credentials: 'include',
|
|
3622
|
+
credentials: 'include', // For Arr Affinity cookie only, for better Rate-Limit counting only.
|
|
3612
3623
|
body: TSON.stringify(syncRequest),
|
|
3613
3624
|
});
|
|
3614
3625
|
//const contentLength = Number(res.headers.get('content-length'));
|
|
@@ -5572,7 +5583,7 @@ function LocalSyncWorker(db, cloudOptions, cloudSchema) {
|
|
|
5572
5583
|
retryPurpose = null;
|
|
5573
5584
|
syncIfPossible(db, cloudOptions, cloudSchema, {
|
|
5574
5585
|
cancelToken,
|
|
5575
|
-
retryImmediatelyOnFetchError: true,
|
|
5586
|
+
retryImmediatelyOnFetchError: true, // workaround for "net::ERR_NETWORK_CHANGED" in chrome.
|
|
5576
5587
|
purpose: combPurpose,
|
|
5577
5588
|
}).catch((e) => {
|
|
5578
5589
|
console.error('error in syncIfPossible()', e);
|
|
@@ -6253,7 +6264,7 @@ function dexieCloud(dexie) {
|
|
|
6253
6264
|
const syncComplete = new Subject();
|
|
6254
6265
|
dexie.cloud = {
|
|
6255
6266
|
// @ts-ignore
|
|
6256
|
-
version: "4.0.1-beta.
|
|
6267
|
+
version: "4.0.1-beta.57",
|
|
6257
6268
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6258
6269
|
schema: null,
|
|
6259
6270
|
get currentUserId() {
|
|
@@ -6530,7 +6541,7 @@ function dexieCloud(dexie) {
|
|
|
6530
6541
|
}
|
|
6531
6542
|
}
|
|
6532
6543
|
// @ts-ignore
|
|
6533
|
-
dexieCloud.version = "4.0.1-beta.
|
|
6544
|
+
dexieCloud.version = "4.0.1-beta.57";
|
|
6534
6545
|
Dexie.Cloud = dexieCloud;
|
|
6535
6546
|
|
|
6536
6547
|
export { dexieCloud as default, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };
|