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