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
|
@@ -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
|
*
|
|
@@ -2333,7 +2333,28 @@ function alertUser(userInteraction, title, ...alerts) {
|
|
|
2333
2333
|
function promptForEmail(userInteraction, title, emailHint) {
|
|
2334
2334
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2335
2335
|
let email = emailHint || '';
|
|
2336
|
-
|
|
2336
|
+
// Regular expression for email validation
|
|
2337
|
+
// ^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$
|
|
2338
|
+
//
|
|
2339
|
+
// ^[\w-+.]+ : Matches the start of the string. Allows one or more word characters
|
|
2340
|
+
// (a-z, A-Z, 0-9, and underscore), hyphen, plus, or dot.
|
|
2341
|
+
//
|
|
2342
|
+
// @ : Matches the @ symbol.
|
|
2343
|
+
// ([\w-]+\.)+ : Matches one or more word characters or hyphens followed by a dot.
|
|
2344
|
+
// The plus sign outside the parentheses means this pattern can repeat one or more times,
|
|
2345
|
+
// allowing for subdomains.
|
|
2346
|
+
// [\w-]{2,10} : Matches between 2 and 10 word characters or hyphens. This is typically for
|
|
2347
|
+
// the domain extension like .com, .net, etc.
|
|
2348
|
+
// (\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$ : This part is optional (due to the ? at the end).
|
|
2349
|
+
// If present, it matches " as " followed by another valid email address. This allows for the
|
|
2350
|
+
// input to be either a single email address or two email addresses separated by " as ".
|
|
2351
|
+
//
|
|
2352
|
+
// The use case for "<email1> as <email2>"" is for when a database owner with full access to the
|
|
2353
|
+
// database needs to impersonate another user in the database in order to troubleshoot. This
|
|
2354
|
+
// format will only be possible to use when email1 is the owner of an API client with GLOBAL_READ
|
|
2355
|
+
// and GLOBAL_WRITE permissions on the database. The email will be checked on the server before
|
|
2356
|
+
// allowing it and giving out a token for email2, using the OTP sent to email1.
|
|
2357
|
+
while (!email || !/^[\w-+.]+@([\w-]+\.)+[\w-]{2,10}(\sas\s[\w-+.]+@([\w-]+\.)+[\w-]{2,10})?$/.test(email)) {
|
|
2337
2358
|
email = (yield interactWithUser(userInteraction, {
|
|
2338
2359
|
type: 'email',
|
|
2339
2360
|
title,
|
|
@@ -4217,6 +4238,19 @@ function otpFetchTokenCallback(db) {
|
|
|
4217
4238
|
demo_user,
|
|
4218
4239
|
grant_type: 'demo',
|
|
4219
4240
|
scopes: ['ACCESS_DB'],
|
|
4241
|
+
public_key
|
|
4242
|
+
};
|
|
4243
|
+
}
|
|
4244
|
+
else if ((hints === null || hints === void 0 ? void 0 : hints.otpId) && hints.otp) {
|
|
4245
|
+
// User provided OTP ID and OTP code. This means that the OTP email
|
|
4246
|
+
// has already gone out and the user may have clicked a magic link
|
|
4247
|
+
// in the email with otp and otpId in query and the app has picked
|
|
4248
|
+
// up those values and passed them to db.cloud.login().
|
|
4249
|
+
tokenRequest = {
|
|
4250
|
+
grant_type: 'otp',
|
|
4251
|
+
otp_id: hints.otpId,
|
|
4252
|
+
otp: hints.otp,
|
|
4253
|
+
scopes: ['ACCESS_DB'],
|
|
4220
4254
|
public_key,
|
|
4221
4255
|
};
|
|
4222
4256
|
}
|
|
@@ -4226,7 +4260,6 @@ function otpFetchTokenCallback(db) {
|
|
|
4226
4260
|
email,
|
|
4227
4261
|
grant_type: 'otp',
|
|
4228
4262
|
scopes: ['ACCESS_DB'],
|
|
4229
|
-
public_key,
|
|
4230
4263
|
};
|
|
4231
4264
|
}
|
|
4232
4265
|
const res1 = yield fetch(`${url}/token`, {
|
|
@@ -4250,28 +4283,27 @@ function otpFetchTokenCallback(db) {
|
|
|
4250
4283
|
// Error can also be returned right away.
|
|
4251
4284
|
return response;
|
|
4252
4285
|
}
|
|
4253
|
-
else if (tokenRequest.grant_type === 'otp') {
|
|
4286
|
+
else if (tokenRequest.grant_type === 'otp' && 'email' in tokenRequest) {
|
|
4254
4287
|
if (response.type !== 'otp-sent')
|
|
4255
4288
|
throw new Error(`Unexpected response from ${url}/token`);
|
|
4256
4289
|
const otp = yield promptForOTP(userInteraction, tokenRequest.email);
|
|
4257
|
-
|
|
4258
|
-
tokenRequest.otp_id = response.otp_id;
|
|
4290
|
+
const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id });
|
|
4259
4291
|
let res2 = yield fetch(`${url}/token`, {
|
|
4260
|
-
body: JSON.stringify(
|
|
4292
|
+
body: JSON.stringify(tokenRequest2),
|
|
4261
4293
|
method: 'post',
|
|
4262
4294
|
headers: { 'Content-Type': 'application/json' },
|
|
4263
4295
|
mode: 'cors',
|
|
4264
4296
|
});
|
|
4265
4297
|
while (res2.status === 401) {
|
|
4266
4298
|
const errorText = yield res2.text();
|
|
4267
|
-
|
|
4299
|
+
tokenRequest2.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
|
|
4268
4300
|
type: 'error',
|
|
4269
4301
|
messageCode: 'INVALID_OTP',
|
|
4270
4302
|
message: errorText,
|
|
4271
4303
|
messageParams: {}
|
|
4272
4304
|
});
|
|
4273
4305
|
res2 = yield fetch(`${url}/token`, {
|
|
4274
|
-
body: JSON.stringify(
|
|
4306
|
+
body: JSON.stringify(tokenRequest2),
|
|
4275
4307
|
method: 'post',
|
|
4276
4308
|
headers: { 'Content-Type': 'application/json' },
|
|
4277
4309
|
mode: 'cors',
|
|
@@ -6225,7 +6257,7 @@ function dexieCloud(dexie) {
|
|
|
6225
6257
|
const syncComplete = new Subject();
|
|
6226
6258
|
dexie.cloud = {
|
|
6227
6259
|
// @ts-ignore
|
|
6228
|
-
version: "4.0.1-beta.
|
|
6260
|
+
version: "4.0.1-beta.56",
|
|
6229
6261
|
options: Object.assign({}, DEFAULT_OPTIONS),
|
|
6230
6262
|
schema: null,
|
|
6231
6263
|
get currentUserId() {
|
|
@@ -6502,7 +6534,7 @@ function dexieCloud(dexie) {
|
|
|
6502
6534
|
}
|
|
6503
6535
|
}
|
|
6504
6536
|
// @ts-ignore
|
|
6505
|
-
dexieCloud.version = "4.0.1-beta.
|
|
6537
|
+
dexieCloud.version = "4.0.1-beta.56";
|
|
6506
6538
|
Dexie.Cloud = dexieCloud;
|
|
6507
6539
|
|
|
6508
6540
|
// In case the SW lives for a while, let it reuse already opened connections:
|