dexie-cloud-addon 4.3.6 → 4.3.8

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.3.6, Wed Jan 28 2026
11
+ * Version 4.3.8, Thu Jan 29 2026
12
12
  *
13
13
  * https://dexie.org
14
14
  *
@@ -3841,7 +3841,21 @@ function otpFetchTokenCallback(db) {
3841
3841
  }
3842
3842
  // Handle OAuth provider login via redirect
3843
3843
  if (hints === null || hints === void 0 ? void 0 : hints.provider) {
3844
- initiateOAuthRedirect(db, hints.provider);
3844
+ let resolvedRedirectUri = undefined;
3845
+ if (hints.redirectPath) {
3846
+ // If redirectPath is absolute, use as is. If relative, resolve against current location
3847
+ if (/^https?:\/\//i.test(hints.redirectPath)) {
3848
+ resolvedRedirectUri = hints.redirectPath;
3849
+ }
3850
+ else if (typeof window !== 'undefined' && window.location) {
3851
+ // Use URL constructor to resolve relative path
3852
+ resolvedRedirectUri = new URL(hints.redirectPath, window.location.href).toString();
3853
+ }
3854
+ else if (typeof location !== 'undefined' && location.href) {
3855
+ resolvedRedirectUri = new URL(hints.redirectPath, location.href).toString();
3856
+ }
3857
+ }
3858
+ initiateOAuthRedirect(db, hints.provider, resolvedRedirectUri);
3845
3859
  // This function never returns - page navigates away
3846
3860
  throw new OAuthRedirectError(hints.provider);
3847
3861
  }
@@ -3986,12 +4000,13 @@ function otpFetchTokenCallback(db) {
3986
4000
  * the user is redirected back with a dxc-auth query parameter that is
3987
4001
  * automatically detected by db.cloud.configure().
3988
4002
  */
3989
- function initiateOAuthRedirect(db, provider) {
4003
+ function initiateOAuthRedirect(db, provider, redirectUriOverride) {
3990
4004
  var _a, _b;
3991
4005
  const url = (_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl;
3992
4006
  if (!url)
3993
4007
  throw new Error(`No database URL given.`);
3994
- const redirectUri = ((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.oauthRedirectUri) ||
4008
+ const redirectUri = redirectUriOverride ||
4009
+ ((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.oauthRedirectUri) ||
3995
4010
  (typeof location !== 'undefined' ? location.href : undefined);
3996
4011
  // CodeRabbit suggested to fail fast here, but the only situation where
3997
4012
  // redirectUri would be undefined is in non-browser environments, and
@@ -6053,7 +6068,9 @@ function associate(factory) {
6053
6068
  };
6054
6069
  }
6055
6070
 
6056
- const getCurrentUserEmitter = associate((db) => new BehaviorSubject(UNAUTHORIZED_USER));
6071
+ const isOathCallback = typeof location !== 'undefined' && !!(new URL(location.href)).searchParams.get('dxc-auth');
6072
+ const getCurrentUserEmitter = associate((db) => new BehaviorSubject(isOathCallback
6073
+ ? Object.assign(Object.assign({}, UNAUTHORIZED_USER), { oauthInProgress: true }) : UNAUTHORIZED_USER));
6057
6074
 
6058
6075
  function computeSyncState(db) {
6059
6076
  let _prevStatus = db.cloud.webSocketStatus.value;
@@ -6688,7 +6705,7 @@ function dexieCloud(dexie) {
6688
6705
  const syncComplete = new Subject();
6689
6706
  dexie.cloud = {
6690
6707
  // @ts-ignore
6691
- version: "4.3.6",
6708
+ version: "4.3.8",
6692
6709
  options: Object.assign({}, DEFAULT_OPTIONS),
6693
6710
  schema: null,
6694
6711
  get currentUserId() {
@@ -6729,8 +6746,6 @@ function dexieCloud(dexie) {
6729
6746
  try {
6730
6747
  const callback = parseOAuthCallback();
6731
6748
  if (callback) {
6732
- // Clean up URL immediately (remove dxc-auth param)
6733
- cleanupOAuthUrl();
6734
6749
  // Store the pending auth code for processing when db is ready
6735
6750
  pendingOAuthCode = { code: callback.code, provider: callback.provider };
6736
6751
  console.debug('[dexie-cloud] OAuth callback detected, auth code stored for processing');
@@ -6738,7 +6753,6 @@ function dexieCloud(dexie) {
6738
6753
  }
6739
6754
  catch (error) {
6740
6755
  // parseOAuthCallback throws OAuthError on error callbacks
6741
- cleanupOAuthUrl();
6742
6756
  if (error instanceof OAuthError) {
6743
6757
  pendingOAuthError = error;
6744
6758
  console.error('[dexie-cloud] OAuth callback error:', error.message);
@@ -6966,6 +6980,9 @@ function dexieCloud(dexie) {
6966
6980
  message: error.message,
6967
6981
  messageParams: { provider: error.provider || 'unknown' }
6968
6982
  });
6983
+ // Clean up URL (remove dxc-auth param)
6984
+ cleanupOAuthUrl();
6985
+ currentUserEmitter.next(Object.assign(Object.assign({}, currentUserEmitter.value), { oauthInProgress: false }));
6969
6986
  }
6970
6987
  catch (uiError) {
6971
6988
  console.error('[dexie-cloud] Failed to show OAuth error alert:', uiError);
@@ -6979,6 +6996,8 @@ function dexieCloud(dexie) {
6979
6996
  try {
6980
6997
  changedUser = yield login(db, { oauthCode: code, provider });
6981
6998
  user = yield db.getCurrentUser();
6999
+ // Clean up URL (remove dxc-auth param)
7000
+ cleanupOAuthUrl();
6982
7001
  }
6983
7002
  catch (error) {
6984
7003
  console.error('[dexie-cloud] OAuth login failed:', error);
@@ -7073,7 +7092,7 @@ function dexieCloud(dexie) {
7073
7092
  }
7074
7093
  }
7075
7094
  // @ts-ignore
7076
- dexieCloud.version = "4.3.6";
7095
+ dexieCloud.version = "4.3.8";
7077
7096
  Dexie.Cloud = dexieCloud;
7078
7097
 
7079
7098
  // In case the SW lives for a while, let it reuse already opened connections: