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.
@@ -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.57, Wed Feb 14 2024
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -3332,7 +3332,7 @@
3332
3332
  const res = yield fetch(`${databaseUrl}/sync`, {
3333
3333
  method: 'post',
3334
3334
  headers,
3335
- credentials: 'include',
3335
+ credentials: 'include', // For Arr Affinity cookie only, for better Rate-Limit counting only.
3336
3336
  body: TSON.stringify(syncRequest),
3337
3337
  });
3338
3338
  //const contentLength = Number(res.headers.get('content-length'));
@@ -4241,6 +4241,19 @@
4241
4241
  demo_user,
4242
4242
  grant_type: 'demo',
4243
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'],
4244
4257
  public_key,
4245
4258
  };
4246
4259
  }
@@ -4250,7 +4263,6 @@
4250
4263
  email,
4251
4264
  grant_type: 'otp',
4252
4265
  scopes: ['ACCESS_DB'],
4253
- public_key,
4254
4266
  };
4255
4267
  }
4256
4268
  const res1 = yield fetch(`${url}/token`, {
@@ -4274,28 +4286,27 @@
4274
4286
  // Error can also be returned right away.
4275
4287
  return response;
4276
4288
  }
4277
- else if (tokenRequest.grant_type === 'otp') {
4289
+ else if (tokenRequest.grant_type === 'otp' && 'email' in tokenRequest) {
4278
4290
  if (response.type !== 'otp-sent')
4279
4291
  throw new Error(`Unexpected response from ${url}/token`);
4280
4292
  const otp = yield promptForOTP(userInteraction, tokenRequest.email);
4281
- tokenRequest.otp = otp || '';
4282
- tokenRequest.otp_id = response.otp_id;
4293
+ const tokenRequest2 = Object.assign(Object.assign({}, tokenRequest), { otp: otp || '', otp_id: response.otp_id, public_key });
4283
4294
  let res2 = yield fetch(`${url}/token`, {
4284
- body: JSON.stringify(tokenRequest),
4295
+ body: JSON.stringify(tokenRequest2),
4285
4296
  method: 'post',
4286
4297
  headers: { 'Content-Type': 'application/json' },
4287
4298
  mode: 'cors',
4288
4299
  });
4289
4300
  while (res2.status === 401) {
4290
4301
  const errorText = yield res2.text();
4291
- tokenRequest.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
4302
+ tokenRequest2.otp = yield promptForOTP(userInteraction, tokenRequest.email, {
4292
4303
  type: 'error',
4293
4304
  messageCode: 'INVALID_OTP',
4294
4305
  message: errorText,
4295
4306
  messageParams: {}
4296
4307
  });
4297
4308
  res2 = yield fetch(`${url}/token`, {
4298
- body: JSON.stringify(tokenRequest),
4309
+ body: JSON.stringify(tokenRequest2),
4299
4310
  method: 'post',
4300
4311
  headers: { 'Content-Type': 'application/json' },
4301
4312
  mode: 'cors',
@@ -5575,7 +5586,7 @@
5575
5586
  retryPurpose = null;
5576
5587
  syncIfPossible(db, cloudOptions, cloudSchema, {
5577
5588
  cancelToken,
5578
- retryImmediatelyOnFetchError: true,
5589
+ retryImmediatelyOnFetchError: true, // workaround for "net::ERR_NETWORK_CHANGED" in chrome.
5579
5590
  purpose: combPurpose,
5580
5591
  }).catch((e) => {
5581
5592
  console.error('error in syncIfPossible()', e);
@@ -6249,7 +6260,7 @@
6249
6260
  const syncComplete = new rxjs.Subject();
6250
6261
  dexie.cloud = {
6251
6262
  // @ts-ignore
6252
- version: "4.0.1-beta.55",
6263
+ version: "4.0.1-beta.57",
6253
6264
  options: Object.assign({}, DEFAULT_OPTIONS),
6254
6265
  schema: null,
6255
6266
  get currentUserId() {
@@ -6526,7 +6537,7 @@
6526
6537
  }
6527
6538
  }
6528
6539
  // @ts-ignore
6529
- dexieCloud.version = "4.0.1-beta.55";
6540
+ dexieCloud.version = "4.0.1-beta.57";
6530
6541
  Dexie.Cloud = dexieCloud;
6531
6542
 
6532
6543
  // In case the SW lives for a while, let it reuse already opened connections: