@hexclave/tanstack-start 1.0.5 → 1.0.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.
Files changed (108) hide show
  1. package/dist/components-page/account-settings/email-and-auth/mfa-section.js +1 -1
  2. package/dist/components-page/account-settings/email-and-auth/passkey-section.js +1 -1
  3. package/dist/components-page/account-settings/email-and-auth/password-section.js +2 -2
  4. package/dist/components-page/account-settings/payments/payments-panel.js +4 -4
  5. package/dist/components-page/account-settings/payments/payments-panel.js.map +1 -1
  6. package/dist/components-page/account-settings/teams/team-creation-page.js +1 -1
  7. package/dist/components-page/account-settings/teams/team-member-invitation-section.js +1 -1
  8. package/dist/components-page/hexclave-handler-client.d.ts +13 -1
  9. package/dist/components-page/hexclave-handler-client.d.ts.map +1 -1
  10. package/dist/components-page/hexclave-handler-client.js +44 -9
  11. package/dist/components-page/hexclave-handler-client.js.map +1 -1
  12. package/dist/components-page/hexclave-handler-client.test.d.ts +1 -0
  13. package/dist/components-page/hexclave-handler-client.test.js +51 -0
  14. package/dist/components-page/hexclave-handler-client.test.js.map +1 -0
  15. package/dist/dev-tool/dev-tool-core.js +2 -2
  16. package/dist/dev-tool/dev-tool-core.js.map +1 -1
  17. package/dist/esm/components-page/account-settings/email-and-auth/mfa-section.js +1 -1
  18. package/dist/esm/components-page/account-settings/email-and-auth/passkey-section.js +1 -1
  19. package/dist/esm/components-page/account-settings/email-and-auth/password-section.js +2 -2
  20. package/dist/esm/components-page/account-settings/payments/payments-panel.js +3 -3
  21. package/dist/esm/components-page/account-settings/payments/payments-panel.js.map +1 -1
  22. package/dist/esm/components-page/account-settings/teams/team-creation-page.js +1 -1
  23. package/dist/esm/components-page/account-settings/teams/team-member-invitation-section.js +1 -1
  24. package/dist/esm/components-page/hexclave-handler-client.d.ts +12 -1
  25. package/dist/esm/components-page/hexclave-handler-client.d.ts.map +1 -1
  26. package/dist/esm/components-page/hexclave-handler-client.js +46 -12
  27. package/dist/esm/components-page/hexclave-handler-client.js.map +1 -1
  28. package/dist/esm/components-page/hexclave-handler-client.test.d.ts +1 -0
  29. package/dist/esm/components-page/hexclave-handler-client.test.js +51 -0
  30. package/dist/esm/components-page/hexclave-handler-client.test.js.map +1 -0
  31. package/dist/esm/dev-tool/dev-tool-core.js +2 -2
  32. package/dist/esm/dev-tool/dev-tool-core.js.map +1 -1
  33. package/dist/esm/generated/env.d.ts +26 -0
  34. package/dist/esm/{lib → generated}/env.d.ts.map +1 -1
  35. package/dist/esm/generated/env.js +67 -0
  36. package/dist/esm/generated/env.js.map +1 -0
  37. package/dist/esm/global.d.ts +8 -1
  38. package/dist/esm/global.d.ts.map +1 -0
  39. package/dist/esm/lib/auth.js +1 -1
  40. package/dist/esm/lib/cookie.d.ts +0 -8
  41. package/dist/esm/lib/cookie.d.ts.map +1 -1
  42. package/dist/esm/lib/cookie.js +2 -2
  43. package/dist/esm/lib/cookie.js.map +1 -1
  44. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  45. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +263 -3
  46. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  47. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +3 -1
  48. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  49. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js +54 -27
  50. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  51. package/dist/esm/lib/hexclave-app/apps/implementations/common.d.ts +8 -8
  52. package/dist/esm/lib/hexclave-app/apps/implementations/common.d.ts.map +1 -1
  53. package/dist/esm/lib/hexclave-app/apps/implementations/common.js +29 -15
  54. package/dist/esm/lib/hexclave-app/apps/implementations/common.js.map +1 -1
  55. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.js +1 -1
  56. package/dist/esm/lib/hexclave-app/url-targets.d.ts.map +1 -1
  57. package/dist/esm/lib/hexclave-app/url-targets.js +25 -11
  58. package/dist/esm/lib/hexclave-app/url-targets.js.map +1 -1
  59. package/dist/esm/lib/hexclave-app/url-targets.test.js +12 -0
  60. package/dist/esm/lib/hexclave-app/url-targets.test.js.map +1 -1
  61. package/dist/generated/env.d.ts +26 -0
  62. package/dist/{lib → generated}/env.d.ts.map +1 -1
  63. package/dist/generated/env.js +69 -0
  64. package/dist/generated/env.js.map +1 -0
  65. package/dist/global.d.ts +8 -1
  66. package/dist/global.d.ts.map +1 -0
  67. package/dist/lib/auth.js +1 -1
  68. package/dist/lib/cookie.d.ts +0 -8
  69. package/dist/lib/cookie.d.ts.map +1 -1
  70. package/dist/lib/cookie.js +2 -2
  71. package/dist/lib/cookie.js.map +1 -1
  72. package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  73. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +263 -3
  74. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  75. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +3 -1
  76. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  77. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js +53 -26
  78. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  79. package/dist/lib/hexclave-app/apps/implementations/common.d.ts +8 -8
  80. package/dist/lib/hexclave-app/apps/implementations/common.d.ts.map +1 -1
  81. package/dist/lib/hexclave-app/apps/implementations/common.js +29 -15
  82. package/dist/lib/hexclave-app/apps/implementations/common.js.map +1 -1
  83. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.js +1 -1
  84. package/dist/lib/hexclave-app/url-targets.d.ts.map +1 -1
  85. package/dist/lib/hexclave-app/url-targets.js +25 -11
  86. package/dist/lib/hexclave-app/url-targets.js.map +1 -1
  87. package/dist/lib/hexclave-app/url-targets.test.js +12 -0
  88. package/dist/lib/hexclave-app/url-targets.test.js.map +1 -1
  89. package/package.json +13 -6
  90. package/src/components-page/account-settings/payments/payments-panel.tsx +2 -2
  91. package/src/components-page/hexclave-handler-client.test.tsx +64 -0
  92. package/src/components-page/hexclave-handler-client.tsx +51 -12
  93. package/src/dev-tool/dev-tool-core.ts +2 -2
  94. package/src/generated/.gitignore +1 -1
  95. package/src/global.d.ts +8 -1
  96. package/src/lib/cookie.ts +2 -15
  97. package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +316 -3
  98. package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +69 -25
  99. package/src/lib/hexclave-app/apps/implementations/common.ts +34 -14
  100. package/src/lib/hexclave-app/url-targets.test.ts +17 -0
  101. package/src/lib/hexclave-app/url-targets.ts +25 -7
  102. package/dist/esm/lib/env.d.ts +0 -42
  103. package/dist/esm/lib/env.js +0 -93
  104. package/dist/esm/lib/env.js.map +0 -1
  105. package/dist/lib/env.d.ts +0 -42
  106. package/dist/lib/env.js +0 -95
  107. package/dist/lib/env.js.map +0 -1
  108. package/src/lib/env.ts +0 -93
@@ -8,8 +8,8 @@ let _hexclave_shared = require("@hexclave/shared");
8
8
  let _hexclave_shared_dist_utils_react = require("@hexclave/shared/dist/utils/react");
9
9
  let _hexclave_shared_dist_utils_objects = require("@hexclave/shared/dist/utils/objects");
10
10
  let _hexclave_shared_dist_utils_urls = require("@hexclave/shared/dist/utils/urls");
11
- let _hexclave_shared_dist_utils_strings = require("@hexclave/shared/dist/utils/strings");
12
11
  let _hexclave_shared_dist_utils_results = require("@hexclave/shared/dist/utils/results");
12
+ let _hexclave_shared_dist_utils_strings = require("@hexclave/shared/dist/utils/strings");
13
13
  let _hexclave_shared_dist_utils_env = require("@hexclave/shared/dist/utils/env");
14
14
  let _hexclave_tanstack_start_tanstack_start_server_context = require("@hexclave/tanstack-start/tanstack-start-server-context");
15
15
  _hexclave_tanstack_start_tanstack_start_server_context = require_chunk.__toESM(_hexclave_tanstack_start_tanstack_start_server_context);
@@ -18,11 +18,11 @@ let _hexclave_shared_dist_utils_redirect_urls = require("@hexclave/shared/dist/u
18
18
  let _hexclave_shared_dist_utils_bytes = require("@hexclave/shared/dist/utils/bytes");
19
19
  let ______common_js = require("../../common.js");
20
20
  let ______projects_index_js = require("../../projects/index.js");
21
- let _simplewebauthn_browser = require("@simplewebauthn/browser");
22
21
  let _hexclave_shared_dist_sessions = require("@hexclave/shared/dist/sessions");
22
+ let _hexclave_shared_dist_utils_stores = require("@hexclave/shared/dist/utils/stores");
23
+ let _simplewebauthn_browser = require("@simplewebauthn/browser");
23
24
  let _hexclave_shared_dist_utils_json = require("@hexclave/shared/dist/utils/json");
24
25
  let _hexclave_shared_dist_utils_maps = require("@hexclave/shared/dist/utils/maps");
25
- let _hexclave_shared_dist_utils_stores = require("@hexclave/shared/dist/utils/stores");
26
26
  let _hexclave_shared_dist_utils_turnstile_flow = require("@hexclave/shared/dist/utils/turnstile-flow");
27
27
  let _hexclave_shared_dist_utils_uuids = require("@hexclave/shared/dist/utils/uuids");
28
28
  let _tanstack_react_router = require("@tanstack/react-router");
@@ -32,7 +32,7 @@ cookie = require_chunk.__toESM(cookie);
32
32
  let ____________utils_url_js = require("../../../../utils/url.js");
33
33
  let _________auth_js = require("../../../auth.js");
34
34
  let _________cookie_js = require("../../../cookie.js");
35
- let _________env_js = require("../../../env.js");
35
+ let ____________generated_env_js = require("../../../../generated/env.js");
36
36
  let ______api_keys_index_js = require("../../api-keys/index.js");
37
37
  let ______contact_channels_index_js = require("../../contact-channels/index.js");
38
38
  let ______teams_index_js = require("../../teams/index.js");
@@ -509,15 +509,15 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
509
509
  for (const param of oauthCallbackResponseQueryParams) currentUrl.searchParams.delete(param);
510
510
  return currentUrl.toString();
511
511
  }
512
- async _getCurrentRefreshTokenIdIfSignedIn(options) {
513
- const tokens = await (await this._getSession(options?.overrideTokenStoreInit, options)).getOrFetchLikelyValidTokens(0, null);
512
+ async _fetchCurrentRefreshTokenIdIfSignedIn(options) {
513
+ const tokens = await (await this._getSession(options?.overrideTokenStoreInit, options)).fetchNewTokens();
514
514
  if (tokens?.refreshToken == null) return null;
515
515
  return tokens.accessToken.payload.refresh_token_id;
516
516
  }
517
517
  async _addNestedCrossDomainAuthParamsToRedirectUrl(options) {
518
518
  const targetUrl = new URL(options.url, options.currentUrl);
519
519
  if (targetUrl.origin === options.currentUrl.origin) return options.url;
520
- const refreshTokenId = await this._getCurrentRefreshTokenIdIfSignedIn({
520
+ const refreshTokenId = await this._fetchCurrentRefreshTokenIdIfSignedIn({
521
521
  awaitPendingAuthResolutions: options.awaitPendingAuthResolutions,
522
522
  overrideTokenStoreInit: options.overrideTokenStoreInit
523
523
  });
@@ -548,7 +548,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
548
548
  const afterCallbackRedirectUrlString = currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.afterCallbackRedirectUrl);
549
549
  const afterCallbackRedirectUrl = afterCallbackRedirectUrlString == null ? redirectUriUrl : new URL(afterCallbackRedirectUrlString, redirectUriUrl);
550
550
  if (!await this._isTrusted(afterCallbackRedirectUrl.toString())) throw new Error(`Nested cross-domain auth after-callback redirect URL ${afterCallbackRedirectUrlString} is not trusted.`);
551
- if (await this._getCurrentRefreshTokenIdIfSignedIn({ awaitPendingAuthResolutions: false }) !== refreshTokenId) throw new Error("Nested cross-domain auth source session does not match the requested refresh token ID.");
551
+ if (await this._fetchCurrentRefreshTokenIdIfSignedIn({ awaitPendingAuthResolutions: false }) !== refreshTokenId) throw new Error("Nested cross-domain auth source session does not match the requested refresh token ID.");
552
552
  await this._redirectTo({
553
553
  url: await this._createCrossDomainAuthRedirectUrl({
554
554
  redirectUri: redirectUriUrl.toString(),
@@ -561,7 +561,9 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
561
561
  });
562
562
  return true;
563
563
  }
564
- if (await this._getCurrentRefreshTokenIdIfSignedIn({ awaitPendingAuthResolutions: false }) === refreshTokenId) return false;
564
+ const currentRefreshTokenId = await this._fetchCurrentRefreshTokenIdIfSignedIn({ awaitPendingAuthResolutions: false });
565
+ if (currentRefreshTokenId === refreshTokenId) return false;
566
+ if (currentRefreshTokenId != null) (await this._getSession(void 0, { awaitPendingAuthResolutions: false })).markInvalid();
565
567
  const callbackUrlString = currentUrl.searchParams.get(nestedCrossDomainAuthQueryParams.callbackUrl);
566
568
  if (callbackUrlString == null) throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("Nested cross-domain auth URL is missing callback URL");
567
569
  if ((0, _hexclave_shared_dist_utils_urls.isRelative)(callbackUrlString)) throw new Error("Nested cross-domain auth callback URL must be absolute.");
@@ -714,6 +716,13 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
714
716
  accessToken
715
717
  };
716
718
  }
719
+ _getCurrentBrowserCookieTokenStoreValue(old) {
720
+ const tokens = this._getTokensFromCookies(this._getAllBrowserCookies());
721
+ return {
722
+ refreshToken: tokens.refreshToken,
723
+ accessToken: tokens.accessToken ?? (old?.refreshToken === tokens.refreshToken ? old.accessToken : null)
724
+ };
725
+ }
717
726
  get _accessTokenCookieName() {
718
727
  return `hexclave-access`;
719
728
  }
@@ -818,19 +827,12 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
818
827
  _getBrowserCookieTokenStore() {
819
828
  if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) throw new Error("Cannot use cookie token store on the server!");
820
829
  if (this._storedBrowserCookieTokenStore === null) {
821
- const getCurrentValue = (old) => {
822
- const tokens = this._getTokensFromCookies(this._getAllBrowserCookies());
823
- return {
824
- refreshToken: tokens.refreshToken,
825
- accessToken: tokens.accessToken ?? (old?.refreshToken === tokens.refreshToken ? old.accessToken : null)
826
- };
827
- };
828
- this._storedBrowserCookieTokenStore = new _hexclave_shared_dist_utils_stores.Store(getCurrentValue(null));
830
+ this._storedBrowserCookieTokenStore = new _hexclave_shared_dist_utils_stores.Store(this._getCurrentBrowserCookieTokenStoreValue(null));
829
831
  let hasSucceededInWriting = true;
830
832
  setInterval(() => {
831
833
  if (hasSucceededInWriting) {
832
834
  const oldValue = this._storedBrowserCookieTokenStore.get();
833
- const currentValue = getCurrentValue(oldValue);
835
+ const currentValue = this._getCurrentBrowserCookieTokenStoreValue(oldValue);
834
836
  if (!(0, _hexclave_shared_dist_utils_objects.deepPlainEquals)(currentValue, oldValue)) this._storedBrowserCookieTokenStore.set(currentValue);
835
837
  }
836
838
  }, 100);
@@ -856,6 +858,10 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
856
858
  else throw e;
857
859
  }
858
860
  });
861
+ } else {
862
+ const oldValue = this._storedBrowserCookieTokenStore.get();
863
+ const currentValue = this._getCurrentBrowserCookieTokenStoreValue(oldValue);
864
+ if (!(0, _hexclave_shared_dist_utils_objects.deepPlainEquals)(currentValue, oldValue)) this._storedBrowserCookieTokenStore.set(currentValue);
859
865
  }
860
866
  return this._storedBrowserCookieTokenStore;
861
867
  }
@@ -953,17 +959,17 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
953
959
  accessToken: tokenObj.accessToken
954
960
  });
955
961
  session.onAccessTokenChange((newAccessToken) => {
956
- tokenStore.update((old) => ({
962
+ tokenStore.update((old) => _hexclave_shared_dist_sessions.InternalSession.calculateSessionKey(old) === sessionKey ? {
957
963
  ...old,
958
964
  accessToken: newAccessToken?.token ?? null
959
- }));
965
+ } : old);
960
966
  });
961
967
  session.onInvalidate(() => {
962
- tokenStore.update((old) => ({
968
+ tokenStore.update((old) => _hexclave_shared_dist_sessions.InternalSession.calculateSessionKey(old) === sessionKey ? {
963
969
  ...old,
964
970
  accessToken: null,
965
971
  refreshToken: null
966
- }));
972
+ } : old);
967
973
  });
968
974
  let sessionsBySessionKey = this._sessionsByTokenStoreAndSessionKey.get(tokenStore) ?? /* @__PURE__ */ new Map();
969
975
  this._sessionsByTokenStoreAndSessionKey.set(tokenStore, sessionsBySessionKey);
@@ -1912,17 +1918,17 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
1912
1918
  }
1913
1919
  _getBotChallengeSiteKeys() {
1914
1920
  if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)()) return null;
1915
- const visibleSiteKey = _________env_js.envVars.NEXT_PUBLIC_STACK_BOT_CHALLENGE_SITE_KEY;
1921
+ const visibleSiteKey = ____________generated_env_js.envVars.HEXCLAVE_BOT_CHALLENGE_SITE_KEY;
1916
1922
  if (!visibleSiteKey) {
1917
1923
  if (!this._botChallengeSiteKeysWarned) {
1918
1924
  this._botChallengeSiteKeysWarned = true;
1919
- console.warn("[stack-auth] NEXT_PUBLIC_STACK_BOT_CHALLENGE_SITE_KEY is not set — bot challenge fraud protection is disabled. Set the env variable to enable it.");
1925
+ console.warn("[stack-auth] HEXCLAVE_BOT_CHALLENGE_SITE_KEY is not set — bot challenge fraud protection is disabled. Set the env variable to enable it.");
1920
1926
  }
1921
1927
  return null;
1922
1928
  }
1923
1929
  return {
1924
1930
  visibleSiteKey,
1925
- invisibleSiteKey: _________env_js.envVars.NEXT_PUBLIC_STACK_BOT_CHALLENGE_INVISIBLE_SITE_KEY ?? visibleSiteKey
1931
+ invisibleSiteKey: ____________generated_env_js.envVars.HEXCLAVE_BOT_CHALLENGE_INVISIBLE_SITE_KEY ?? visibleSiteKey
1926
1932
  };
1927
1933
  }
1928
1934
  _getBotChallengeFlowFailure(error) {
@@ -2044,6 +2050,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2044
2050
  }
2045
2051
  async _createCrossDomainAuthRedirectUrl(options) {
2046
2052
  const session = await this._getSession(options.overrideTokenStoreInit, { awaitPendingAuthResolutions: options.awaitPendingAuthResolutions });
2053
+ await session.fetchNewTokens();
2047
2054
  const response = await this._interface.sendClientRequest("/auth/oauth/cross-domain/authorize", {
2048
2055
  method: "POST",
2049
2056
  headers: { "Content-Type": "application/json" },
@@ -2153,6 +2160,8 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2153
2160
  return await this._redirectToHandler("signUp", options);
2154
2161
  }
2155
2162
  async redirectToSignOut(options) {
2163
+ const configuredSignOutTarget = this._urlOptions.signOut ?? this._urlOptions.default;
2164
+ if (typeof configuredSignOutTarget !== "string" && configuredSignOutTarget?.type === "hosted") return await this.signOut();
2156
2165
  return await this._redirectToHandler("signOut", options);
2157
2166
  }
2158
2167
  async redirectToEmailVerification(options) {
@@ -2690,9 +2699,27 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2690
2699
  url: options.redirectUrl,
2691
2700
  replace: true
2692
2701
  });
2693
- else await this.redirectToAfterSignOut();
2702
+ else await this._redirectToDefaultAfterSignOut();
2694
2703
  });
2695
2704
  }
2705
+ async _redirectToDefaultAfterSignOut() {
2706
+ if (this._urlOptions.afterSignOut != null) {
2707
+ await this.redirectToAfterSignOut({ replace: true });
2708
+ return;
2709
+ }
2710
+ if (this._urlOptions.home != null) {
2711
+ await this.redirectToHome({ replace: true });
2712
+ return;
2713
+ }
2714
+ if (this._urlOptions.default?.type === "hosted" && typeof window !== "undefined") {
2715
+ await this._redirectTo({
2716
+ url: (0, _hexclave_shared_dist_utils_urls.getRelativePart)(new URL(window.location.href)),
2717
+ replace: true
2718
+ });
2719
+ return;
2720
+ }
2721
+ await this.redirectToAfterSignOut({ replace: true });
2722
+ }
2696
2723
  async signOut(options) {
2697
2724
  const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
2698
2725
  if (user) await user.signOut({ redirectUrl: options?.redirectUrl });