dexie-cloud-addon 4.0.1-beta.54 → 4.0.1-beta.56
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 +43 -11
- 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 +43 -11
- 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 +43 -11
- 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 +43 -11
- 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
|
@@ -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.56, Wed Jan 31 2024
|
|
12
12
|
*
|
|
13
13
|
* https://dexie.org
|
|
14
14
|
*
|
|
@@ -2019,7 +2019,28 @@
|
|
|
2019
2019
|
function promptForEmail(userInteraction, title, emailHint) {
|
|
2020
2020
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2021
2021
|
let email = emailHint || '';
|
|
2022
|
-
|
|
2022
|
+
// Regular expression for email validation
|
|
2023
|
+
// ^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$
|
|
2024
|
+
//
|
|
2025
|
+
// ^[\w-+.]+ : Matches the start of the string. Allows one or more word characters
|
|
2026
|
+
// (a-z, A-Z, 0-9, and underscore), hyphen, plus, or dot.
|
|
2027
|
+
//
|
|
2028
|
+
// @ : Matches the @ symbol.
|
|
2029
|
+
// ([\w-]+\.)+ : Matches one or more word characters or hyphens followed by a dot.
|
|
2030
|
+
// The plus sign outside the parentheses means this pattern can repeat one or more times,
|
|
2031
|
+
// allowing for subdomains.
|
|
2032
|
+
// [\w-]{2,10} : Matches between 2 and 10 word characters or hyphens. This is typically for
|
|
2033
|
+
// the domain extension like .com, .net, etc.
|
|
2034
|
+
// (\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$ : This part is optional (due to the ? at the end).
|
|
2035
|
+
// If present, it matches " as " followed by another valid email address. This allows for the
|
|
2036
|
+
// input to be either a single email address or two email addresses separated by " as ".
|
|
2037
|
+
//
|
|
2038
|
+
// The use case for "<email1> as <email2>"" is for when a database owner with full access to the
|
|
2039
|
+
// database needs to impersonate another user in the database in order to troubleshoot. This
|
|
2040
|
+
// format will only be possible to use when email1 is the owner of an API client with GLOBAL_READ
|
|
2041
|
+
// and GLOBAL_WRITE permissions on the database. The email will be checked on the server before
|
|
2042
|
+
// allowing it and giving out a token for email2, using the OTP sent to email1.
|
|
2043
|
+
while (!email || !/^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$/.test(email)) {
|
|
2023
2044
|
email = (yield interactWithUser(userInteraction, {
|
|
2024
2045
|
type: 'email',
|
|
2025
2046
|
title,
|
|
@@ -2431,6 +2452,19 @@
|
|
|
2431
2452
|
demo_user,
|
|
2432
2453
|
grant_type: 'demo',
|
|
2433
2454
|
scopes: ['ACCESS_DB'],
|
|
2455
|
+
public_key
|
|
2456
|
+
};
|
|
2457
|
+
}
|
|
2458
|
+
else if ((hints === null || hints === void 0 ? void 0 : hints.otpId) && hints.otp) {
|
|
2459
|
+
// User provided OTP ID and OTP code. This means that the OTP email
|
|
2460
|
+
// has already gone out and the user may have clicked a magic link
|
|
2461
|
+
// in the email with otp and otpId in query and the app has picked
|
|
2462
|
+
// up those values and passed them to db.cloud.login().
|
|
2463
|
+
tokenRequest = {
|
|
2464
|
+
grant_type: 'otp',
|
|
2465
|
+
otp_id: hints.otpId,
|
|
2466
|
+
otp: hints.otp,
|
|
2467
|
+
scopes: ['ACCESS_DB'],
|
|
2434
2468
|
public_key,
|
|
2435
2469
|
};
|
|
2436
2470
|
}
|
|
@@ -2440,7 +2474,6 @@
|
|
|
2440
2474
|
email,
|
|
2441
2475
|
grant_type: 'otp',
|
|
2442
2476
|
scopes: ['ACCESS_DB'],
|
|
2443
|
-
public_key,
|
|
2444
2477
|
};
|
|
2445
2478
|
}
|
|
2446
2479
|
const res1 = yield fetch(`${url}/token`, {
|
|
@@ -2464,28 +2497,27 @@
|
|
|
2464
2497
|
// Error can also be returned right away.
|
|
2465
2498
|
return response;
|
|
2466
2499
|
}
|
|
2467
|
-
else if (tokenRequest.grant_type === 'otp') {
|
|
2500
|
+
else if (tokenRequest.grant_type === 'otp' && 'email' in tokenRequest) {
|
|
2468
2501
|
if (response.type !== 'otp-sent')
|
|
2469
2502
|
throw new Error(`Unexpected response from ${url}/token`);
|
|
2470
2503
|
const otp = yield promptForOTP(userInteraction, tokenRequest.email);
|
|
2471
|
-
|
|
2472
|
-
tokenRequest.otp_id = response.otp_id;
|
|
2504
|
+
const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id });
|
|
2473
2505
|
let res2 = yield fetch(`${url}/token`, {
|
|
2474
|
-
body: JSON.stringify(
|
|
2506
|
+
body: JSON.stringify(tokenRequest2),
|
|
2475
2507
|
method: 'post',
|
|
2476
2508
|
headers: { 'Content-Type': 'application/json' },
|
|
2477
2509
|
mode: 'cors',
|
|
2478
2510
|
});
|
|
2479
2511
|
while (res2.status === 401) {
|
|
2480
2512
|
const errorText = yield res2.text();
|
|
2481
|
-
|
|
2513
|
+
tokenRequest2.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
|
|
2482
2514
|
type: 'error',
|
|
2483
2515
|
messageCode: 'INVALID_OTP',
|
|
2484
2516
|
message: errorText,
|
|
2485
2517
|
messageParams: {}
|
|
2486
2518
|
});
|
|
2487
2519
|
res2 = yield fetch(`${url}/token`, {
|
|
2488
|
-
body: JSON.stringify(
|
|
2520
|
+
body: JSON.stringify(tokenRequest2),
|
|
2489
2521
|
method: 'post',
|
|
2490
2522
|
headers: { 'Content-Type': 'application/json' },
|
|
2491
2523
|
mode: 'cors',
|
|
@@ -6235,7 +6267,7 @@
|
|
|
6235
6267
|
const syncComplete = new rxjs.Subject();
|
|
6236
6268
|
dexie.cloud = {
|
|
6237
6269
|
// @ts-ignore
|
|
6238
|
-
version: "4.0.1-beta.
|
|
6270
|
+
version: "4.0.1-beta.56",
|
|
6239
6271
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6240
6272
|
schema: null,
|
|
6241
6273
|
get currentUserId() {
|
|
@@ -6512,7 +6544,7 @@
|
|
|
6512
6544
|
}
|
|
6513
6545
|
}
|
|
6514
6546
|
// @ts-ignore
|
|
6515
|
-
dexieCloud.version = "4.0.1-beta.
|
|
6547
|
+
dexieCloud.version = "4.0.1-beta.56";
|
|
6516
6548
|
Dexie.Cloud = dexieCloud;
|
|
6517
6549
|
|
|
6518
6550
|
exports.default = dexieCloud;
|