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.
@@ -21,6 +21,8 @@ export interface LoginHints {
21
21
  provider?: string;
22
22
  /** Dexie Cloud authorization code received from OAuth callback */
23
23
  oauthCode?: string;
24
+ /** Optional redirect path (relative or absolute) to use for OAuth redirect URI. */
25
+ redirectPath?: string;
24
26
  }
25
27
  export interface DexieCloudAPI {
26
28
  version: string;
@@ -20,4 +20,5 @@ export interface UserLogin {
20
20
  publicKey?: CryptoKey;
21
21
  isLoggedIn?: boolean;
22
22
  data?: any;
23
+ oauthInProgress?: boolean;
23
24
  }
@@ -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
  *
@@ -1517,7 +1517,21 @@ function otpFetchTokenCallback(db) {
1517
1517
  }
1518
1518
  // Handle OAuth provider login via redirect
1519
1519
  if (hints === null || hints === void 0 ? void 0 : hints.provider) {
1520
- initiateOAuthRedirect(db, hints.provider);
1520
+ let resolvedRedirectUri = undefined;
1521
+ if (hints.redirectPath) {
1522
+ // If redirectPath is absolute, use as is. If relative, resolve against current location
1523
+ if (/^https?:\/\//i.test(hints.redirectPath)) {
1524
+ resolvedRedirectUri = hints.redirectPath;
1525
+ }
1526
+ else if (typeof window !== 'undefined' && window.location) {
1527
+ // Use URL constructor to resolve relative path
1528
+ resolvedRedirectUri = new URL(hints.redirectPath, window.location.href).toString();
1529
+ }
1530
+ else if (typeof location !== 'undefined' && location.href) {
1531
+ resolvedRedirectUri = new URL(hints.redirectPath, location.href).toString();
1532
+ }
1533
+ }
1534
+ initiateOAuthRedirect(db, hints.provider, resolvedRedirectUri);
1521
1535
  // This function never returns - page navigates away
1522
1536
  throw new OAuthRedirectError(hints.provider);
1523
1537
  }
@@ -1662,12 +1676,13 @@ function otpFetchTokenCallback(db) {
1662
1676
  * the user is redirected back with a dxc-auth query parameter that is
1663
1677
  * automatically detected by db.cloud.configure().
1664
1678
  */
1665
- function initiateOAuthRedirect(db, provider) {
1679
+ function initiateOAuthRedirect(db, provider, redirectUriOverride) {
1666
1680
  var _a, _b;
1667
1681
  const url = (_a = db.cloud.options) === null || _a === void 0 ? void 0 : _a.databaseUrl;
1668
1682
  if (!url)
1669
1683
  throw new Error(`No database URL given.`);
1670
- const redirectUri = ((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.oauthRedirectUri) ||
1684
+ const redirectUri = redirectUriOverride ||
1685
+ ((_b = db.cloud.options) === null || _b === void 0 ? void 0 : _b.oauthRedirectUri) ||
1671
1686
  (typeof location !== 'undefined' ? location.href : undefined);
1672
1687
  // CodeRabbit suggested to fail fast here, but the only situation where
1673
1688
  // 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;
@@ -6859,7 +6876,7 @@ function dexieCloud(dexie) {
6859
6876
  const syncComplete = new Subject();
6860
6877
  dexie.cloud = {
6861
6878
  // @ts-ignore
6862
- version: "4.3.6",
6879
+ version: "4.3.8",
6863
6880
  options: Object.assign({}, DEFAULT_OPTIONS),
6864
6881
  schema: null,
6865
6882
  get currentUserId() {
@@ -6900,8 +6917,6 @@ function dexieCloud(dexie) {
6900
6917
  try {
6901
6918
  const callback = parseOAuthCallback();
6902
6919
  if (callback) {
6903
- // Clean up URL immediately (remove dxc-auth param)
6904
- cleanupOAuthUrl();
6905
6920
  // Store the pending auth code for processing when db is ready
6906
6921
  pendingOAuthCode = { code: callback.code, provider: callback.provider };
6907
6922
  console.debug('[dexie-cloud] OAuth callback detected, auth code stored for processing');
@@ -6909,7 +6924,6 @@ function dexieCloud(dexie) {
6909
6924
  }
6910
6925
  catch (error) {
6911
6926
  // parseOAuthCallback throws OAuthError on error callbacks
6912
- cleanupOAuthUrl();
6913
6927
  if (error instanceof OAuthError) {
6914
6928
  pendingOAuthError = error;
6915
6929
  console.error('[dexie-cloud] OAuth callback error:', error.message);
@@ -7137,6 +7151,9 @@ function dexieCloud(dexie) {
7137
7151
  message: error.message,
7138
7152
  messageParams: { provider: error.provider || 'unknown' }
7139
7153
  });
7154
+ // Clean up URL (remove dxc-auth param)
7155
+ cleanupOAuthUrl();
7156
+ currentUserEmitter.next(Object.assign(Object.assign({}, currentUserEmitter.value), { oauthInProgress: false }));
7140
7157
  }
7141
7158
  catch (uiError) {
7142
7159
  console.error('[dexie-cloud] Failed to show OAuth error alert:', uiError);
@@ -7150,6 +7167,8 @@ function dexieCloud(dexie) {
7150
7167
  try {
7151
7168
  changedUser = yield login(db, { oauthCode: code, provider });
7152
7169
  user = yield db.getCurrentUser();
7170
+ // Clean up URL (remove dxc-auth param)
7171
+ cleanupOAuthUrl();
7153
7172
  }
7154
7173
  catch (error) {
7155
7174
  console.error('[dexie-cloud] OAuth login failed:', error);
@@ -7244,7 +7263,7 @@ function dexieCloud(dexie) {
7244
7263
  }
7245
7264
  }
7246
7265
  // @ts-ignore
7247
- dexieCloud.version = "4.3.6";
7266
+ dexieCloud.version = "4.3.8";
7248
7267
  Dexie.Cloud = dexieCloud;
7249
7268
 
7250
7269
  export { dexieCloud as default, defineYDocTrigger, dexieCloud, getTiedObjectId, getTiedRealmId, resolveText };