dexie-cloud-addon 4.0.1-beta.55 → 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.55, Tue Jan 02 2024
11
+ * Version 4.0.1-beta.56, Wed Jan 31 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -4238,6 +4238,19 @@ function otpFetchTokenCallback(db) {
4238
4238
  demo_user,
4239
4239
  grant_type: 'demo',
4240
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'],
4241
4254
  public_key,
4242
4255
  };
4243
4256
  }
@@ -4247,7 +4260,6 @@ function otpFetchTokenCallback(db) {
4247
4260
  email,
4248
4261
  grant_type: 'otp',
4249
4262
  scopes: ['ACCESS_DB'],
4250
- public_key,
4251
4263
  };
4252
4264
  }
4253
4265
  const res1 = yield fetch(`${url}/token`, {
@@ -4271,28 +4283,27 @@ function otpFetchTokenCallback(db) {
4271
4283
  // Error can also be returned right away.
4272
4284
  return response;
4273
4285
  }
4274
- else if (tokenRequest.grant_type === 'otp') {
4286
+ else if (tokenRequest.grant_type === 'otp' && 'email' in tokenRequest) {
4275
4287
  if (response.type !== 'otp-sent')
4276
4288
  throw new Error(`Unexpected response from ${url}/token`);
4277
4289
  const otp = yield promptForOTP(userInteraction, tokenRequest.email);
4278
- tokenRequest.otp = otp || '';
4279
- tokenRequest.otp_id = response.otp_id;
4290
+ const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id });
4280
4291
  let res2 = yield fetch(`${url}/token`, {
4281
- body: JSON.stringify(tokenRequest),
4292
+ body: JSON.stringify(tokenRequest2),
4282
4293
  method: 'post',
4283
4294
  headers: { 'Content-Type': 'application/json' },
4284
4295
  mode: 'cors',
4285
4296
  });
4286
4297
  while (res2.status === 401) {
4287
4298
  const errorText = yield res2.text();
4288
- tokenRequest.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
4299
+ tokenRequest2.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
4289
4300
  type: 'error',
4290
4301
  messageCode: 'INVALID_OTP',
4291
4302
  message: errorText,
4292
4303
  messageParams: {}
4293
4304
  });
4294
4305
  res2 = yield fetch(`${url}/token`, {
4295
- body: JSON.stringify(tokenRequest),
4306
+ body: JSON.stringify(tokenRequest2),
4296
4307
  method: 'post',
4297
4308
  headers: { 'Content-Type': 'application/json' },
4298
4309
  mode: 'cors',
@@ -6246,7 +6257,7 @@ function dexieCloud(dexie) {
6246
6257
  const syncComplete = new Subject();
6247
6258
  dexie.cloud = {
6248
6259
  // @ts-ignore
6249
- version: "4.0.1-beta.55",
6260
+ version: "4.0.1-beta.56",
6250
6261
  options: Object.assign({}, DEFAULT_OPTIONS),
6251
6262
  schema: null,
6252
6263
  get currentUserId() {
@@ -6523,7 +6534,7 @@ function dexieCloud(dexie) {
6523
6534
  }
6524
6535
  }
6525
6536
  // @ts-ignore
6526
- dexieCloud.version = "4.0.1-beta.55";
6537
+ dexieCloud.version = "4.0.1-beta.56";
6527
6538
  Dexie.Cloud = dexieCloud;
6528
6539
 
6529
6540
  // In case the SW lives for a while, let it reuse already opened connections: