dexie-cloud-addon 4.3.2 → 4.3.3

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.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Error thrown when initiating an OAuth redirect.
3
+ *
4
+ * This is not a real error - it's used to signal that the page is
5
+ * navigating away to an OAuth provider. It should be caught and
6
+ * silently ignored at the appropriate level.
7
+ */
8
+ export declare class OAuthRedirectError extends Error {
9
+ readonly provider: string;
10
+ constructor(provider: string);
11
+ }
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * ==========================================================================
10
10
  *
11
- * Version 4.3.2, Thu Jan 22 2026
11
+ * Version 4.3.3, Thu Jan 22 2026
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -1409,6 +1409,21 @@ function promptForProvider(userInteraction_1, providers_1, otpEnabled_1) {
1409
1409
  });
1410
1410
  }
1411
1411
 
1412
+ /**
1413
+ * Error thrown when initiating an OAuth redirect.
1414
+ *
1415
+ * This is not a real error - it's used to signal that the page is
1416
+ * navigating away to an OAuth provider. It should be caught and
1417
+ * silently ignored at the appropriate level.
1418
+ */
1419
+ class OAuthRedirectError extends Error {
1420
+ constructor(provider) {
1421
+ super(`OAuth redirect initiated for provider: ${provider}`);
1422
+ this.name = 'OAuthRedirectError';
1423
+ this.provider = provider;
1424
+ }
1425
+ }
1426
+
1412
1427
  function loadAccessToken(db) {
1413
1428
  return __awaiter(this, void 0, void 0, function* () {
1414
1429
  var _a, _b, _c;
@@ -1576,6 +1591,10 @@ function userAuthenticate(context, fetchToken, userInteraction, hints) {
1576
1591
  return context;
1577
1592
  }
1578
1593
  catch (error) {
1594
+ // OAuth redirect is not an error - page is navigating away
1595
+ if (error instanceof OAuthRedirectError || (error === null || error === void 0 ? void 0 : error.name) === 'OAuthRedirectError') {
1596
+ throw error; // Re-throw without logging
1597
+ }
1579
1598
  if (error instanceof TokenErrorResponseError) {
1580
1599
  yield alertUser(userInteraction, error.title, {
1581
1600
  type: 'error',
@@ -3878,7 +3897,7 @@ function otpFetchTokenCallback(db) {
3878
3897
  if (hints === null || hints === void 0 ? void 0 : hints.provider) {
3879
3898
  initiateOAuthRedirect(db, hints.provider);
3880
3899
  // This function never returns - page navigates away
3881
- throw new Error('OAuth redirect initiated');
3900
+ throw new OAuthRedirectError(hints.provider);
3882
3901
  }
3883
3902
  if ((hints === null || hints === void 0 ? void 0 : hints.grant_type) === 'demo') {
3884
3903
  const demo_user = yield promptForEmail(userInteraction, 'Enter a demo user email', (hints === null || hints === void 0 ? void 0 : hints.email) || (hints === null || hints === void 0 ? void 0 : hints.userId));
@@ -3913,7 +3932,7 @@ function otpFetchTokenCallback(db) {
3913
3932
  // User selected an OAuth provider - initiate redirect
3914
3933
  initiateOAuthRedirect(db, selection.provider);
3915
3934
  // This function never returns - page navigates away
3916
- throw new Error('OAuth redirect initiated');
3935
+ throw new OAuthRedirectError(selection.provider);
3917
3936
  }
3918
3937
  // User chose OTP - continue with email prompt below
3919
3938
  }
@@ -4102,7 +4121,15 @@ function login(db, hints) {
4102
4121
  claims: {},
4103
4122
  lastLogin: new Date(0),
4104
4123
  });
4105
- yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4124
+ try {
4125
+ yield authenticate(db.cloud.options.databaseUrl, context, db.cloud.options.fetchTokens || otpFetchTokenCallback(db), db.cloud.userInteraction, hints);
4126
+ }
4127
+ catch (err) {
4128
+ if (err.name === 'OAuthRedirectError') {
4129
+ return false; // Page is redirecting for OAuth login
4130
+ }
4131
+ throw err;
4132
+ }
4106
4133
  if (origUserId !== UNAUTHORIZED_USER.userId &&
4107
4134
  context.userId !== origUserId) {
4108
4135
  // User was logged in before, but now logged in as another user.
@@ -6004,7 +6031,7 @@ function LoginDialog({ title, alerts, fields, options, submitLabel, cancelLabel,
6004
6031
  } }))))))),
6005
6032
  _$1("div", { style: Styles.ButtonsDiv },
6006
6033
  _$1(k$1, null,
6007
- hasFields && submitLabel && (_$1("button", { type: "submit", style: Styles.PrimaryButton, onClick: () => onSubmit(params) }, submitLabel)),
6034
+ submitLabel && (hasFields || (!hasOptions && !hasFields)) && (_$1("button", { type: "submit", style: Styles.PrimaryButton, onClick: () => onSubmit(params) }, submitLabel)),
6008
6035
  cancelLabel && (_$1("button", { style: Styles.Button, onClick: onCancel }, cancelLabel))))));
6009
6036
  }
6010
6037
  function valueTransformer(type, value) {
@@ -6686,6 +6713,8 @@ function dexieCloud(dexie) {
6686
6713
  let configuredProgramatically = false;
6687
6714
  // Pending OAuth auth code from dxc-auth redirect (detected in configure())
6688
6715
  let pendingOAuthCode = null;
6716
+ // Pending OAuth error from dxc-auth redirect (detected in configure())
6717
+ let pendingOAuthError = null;
6689
6718
  // local sync worker - used when there's no service worker.
6690
6719
  let localSyncWorker = null;
6691
6720
  dexie.on('ready', (dexie) => __awaiter(this, void 0, void 0, function* () {
@@ -6715,7 +6744,7 @@ function dexieCloud(dexie) {
6715
6744
  const syncComplete = new Subject();
6716
6745
  dexie.cloud = {
6717
6746
  // @ts-ignore
6718
- version: "4.3.2",
6747
+ version: "4.3.3",
6719
6748
  options: Object.assign({}, DEFAULT_OPTIONS),
6720
6749
  schema: null,
6721
6750
  get currentUserId() {
@@ -6765,9 +6794,14 @@ function dexieCloud(dexie) {
6765
6794
  }
6766
6795
  catch (error) {
6767
6796
  // parseOAuthCallback throws OAuthError on error callbacks
6768
- // Store null for code but log the error
6769
- console.warn('[dexie-cloud] OAuth callback error:', error);
6770
6797
  cleanupOAuthUrl();
6798
+ if (error instanceof OAuthError) {
6799
+ pendingOAuthError = error;
6800
+ console.error('[dexie-cloud] OAuth callback error:', error.message);
6801
+ }
6802
+ else {
6803
+ console.error('[dexie-cloud] OAuth callback error:', error);
6804
+ }
6771
6805
  }
6772
6806
  }
6773
6807
  },
@@ -6963,7 +6997,20 @@ function dexieCloud(dexie) {
6963
6997
  }
6964
6998
  // HERE: If requireAuth, do athentication now.
6965
6999
  let changedUser = false;
6966
- const user = yield db.getCurrentUser();
7000
+ let user = yield db.getCurrentUser();
7001
+ // Show pending OAuth error if present (from dxc-auth redirect)
7002
+ if (pendingOAuthError && !db.cloud.isServiceWorkerDB) {
7003
+ const error = pendingOAuthError;
7004
+ pendingOAuthError = null; // Clear pending error
7005
+ console.debug('[dexie-cloud] Showing OAuth error:', error.message);
7006
+ // Show alert to user about the OAuth error
7007
+ yield alertUser(db.cloud.userInteraction, 'Authentication Error', {
7008
+ type: 'error',
7009
+ messageCode: 'GENERIC_ERROR',
7010
+ message: error.message,
7011
+ messageParams: { provider: error.provider || 'unknown' }
7012
+ });
7013
+ }
6967
7014
  // Process pending OAuth callback if present (from dxc-auth redirect)
6968
7015
  if (pendingOAuthCode && !db.cloud.isServiceWorkerDB) {
6969
7016
  const { code, provider } = pendingOAuthCode;
@@ -6971,6 +7018,7 @@ function dexieCloud(dexie) {
6971
7018
  console.debug('[dexie-cloud] Processing OAuth callback, provider:', provider);
6972
7019
  try {
6973
7020
  changedUser = yield login(db, { oauthCode: code, provider });
7021
+ user = yield db.getCurrentUser();
6974
7022
  }
6975
7023
  catch (error) {
6976
7024
  console.error('[dexie-cloud] OAuth login failed:', error);
@@ -7065,7 +7113,7 @@ function dexieCloud(dexie) {
7065
7113
  }
7066
7114
  }
7067
7115
  // @ts-ignore
7068
- dexieCloud.version = "4.3.2";
7116
+ dexieCloud.version = "4.3.3";
7069
7117
  Dexie.Cloud = dexieCloud;
7070
7118
 
7071
7119
  // In case the SW lives for a while, let it reuse already opened connections: