@hexclave/next 1.0.105 → 1.0.107

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 (181) hide show
  1. package/dist/{admin-app-impl-CMKoG26j.d.ts → admin-app-impl-BmZQrPYN.d.ts} +6 -5
  2. package/dist/admin-app-impl-BmZQrPYN.d.ts.map +1 -0
  3. package/dist/clickmap/clickmap-core.d.ts +1 -1
  4. package/dist/clickmap/index.d.ts +1 -1
  5. package/dist/{client-app-D84Jo2In.d.ts → client-app-BowxO_77.d.ts} +30 -3
  6. package/dist/client-app-BowxO_77.d.ts.map +1 -0
  7. package/dist/components/api-key-dialogs.js +4 -4
  8. package/dist/components/credential-sign-in.js +3 -3
  9. package/dist/components/credential-sign-up.js +5 -5
  10. package/dist/components/elements/sidebar-layout.js +1 -1
  11. package/dist/components/elements/user-avatar.js +1 -1
  12. package/dist/components/magic-link-sign-in.js +5 -5
  13. package/dist/components/message-cards/no-auth-methods-message-card.js +2 -2
  14. package/dist/components/message-cards/predefined-message-card.js +1 -1
  15. package/dist/components/passkey-button.js +1 -1
  16. package/dist/components/profile-image-editor.js +1 -1
  17. package/dist/components/selected-team-switcher.d.ts +1 -1
  18. package/dist/components/team-icon.d.ts +1 -1
  19. package/dist/components/team-icon.js +1 -1
  20. package/dist/components/team-switcher.d.ts +1 -1
  21. package/dist/components/team-switcher.js +1 -1
  22. package/dist/components/user-button.js +1 -1
  23. package/dist/components-page/account-settings/active-sessions/active-sessions-page.js +2 -2
  24. package/dist/components-page/account-settings/api-keys/api-keys-page.js +1 -1
  25. package/dist/components-page/account-settings/editable-text.js +1 -1
  26. package/dist/components-page/account-settings/email-and-auth/emails-section.js +5 -5
  27. package/dist/components-page/account-settings/email-and-auth/password-section.js +4 -4
  28. package/dist/components-page/account-settings/notifications/notifications-page.js +1 -1
  29. package/dist/components-page/account-settings/payments/payments-page.d.ts +1 -1
  30. package/dist/components-page/account-settings/payments/payments-page.js +1 -1
  31. package/dist/components-page/account-settings/profile-page/profile-page.js +1 -1
  32. package/dist/components-page/account-settings/teams/leave-team-section.d.ts +1 -1
  33. package/dist/components-page/account-settings/teams/team-api-keys-section.d.ts +1 -1
  34. package/dist/components-page/account-settings/teams/team-api-keys-section.js +1 -1
  35. package/dist/components-page/account-settings/teams/team-creation-page.js +5 -5
  36. package/dist/components-page/account-settings/teams/team-display-name-section.d.ts +1 -1
  37. package/dist/components-page/account-settings/teams/team-member-invitation-section.d.ts +1 -1
  38. package/dist/components-page/account-settings/teams/team-member-invitation-section.js +5 -5
  39. package/dist/components-page/account-settings/teams/team-member-list-section.d.ts +1 -1
  40. package/dist/components-page/account-settings/teams/team-page.d.ts +1 -1
  41. package/dist/components-page/account-settings/teams/team-profile-image-section.d.ts +1 -1
  42. package/dist/components-page/account-settings/teams/team-profile-user-section.d.ts +1 -1
  43. package/dist/components-page/account-settings.js +3 -3
  44. package/dist/components-page/auth-page.js +1 -1
  45. package/dist/components-page/cli-auth-confirm.js +1 -1
  46. package/dist/components-page/forgot-password.js +5 -5
  47. package/dist/components-page/hexclave-handler-client.d.ts +1 -1
  48. package/dist/components-page/hexclave-handler-client.js +1 -1
  49. package/dist/components-page/hexclave-handler.d.ts +1 -1
  50. package/dist/components-page/mfa.js +3 -3
  51. package/dist/components-page/oauth-callback.js +1 -1
  52. package/dist/components-page/onboarding.js +4 -4
  53. package/dist/components-page/password-reset.js +8 -8
  54. package/dist/components-page/team-creation.js +5 -5
  55. package/dist/dev-tool/dev-tool-core.d.ts +1 -1
  56. package/dist/dev-tool/index.d.ts +1 -1
  57. package/dist/esm/components/api-key-dialogs.js +4 -4
  58. package/dist/esm/components/credential-sign-in.js +3 -3
  59. package/dist/esm/components/credential-sign-up.js +5 -5
  60. package/dist/esm/components/elements/sidebar-layout.js +1 -1
  61. package/dist/esm/components/elements/user-avatar.js +1 -1
  62. package/dist/esm/components/magic-link-sign-in.js +5 -5
  63. package/dist/esm/components/message-cards/no-auth-methods-message-card.js +2 -2
  64. package/dist/esm/components/message-cards/predefined-message-card.js +1 -1
  65. package/dist/esm/components/passkey-button.js +1 -1
  66. package/dist/esm/components/profile-image-editor.js +1 -1
  67. package/dist/esm/components/team-icon.js +1 -1
  68. package/dist/esm/components/team-switcher.js +1 -1
  69. package/dist/esm/components/user-button.js +1 -1
  70. package/dist/esm/components-page/account-settings/active-sessions/active-sessions-page.js +2 -2
  71. package/dist/esm/components-page/account-settings/api-keys/api-keys-page.js +1 -1
  72. package/dist/esm/components-page/account-settings/editable-text.js +1 -1
  73. package/dist/esm/components-page/account-settings/email-and-auth/emails-section.js +5 -5
  74. package/dist/esm/components-page/account-settings/email-and-auth/password-section.js +4 -4
  75. package/dist/esm/components-page/account-settings/notifications/notifications-page.js +1 -1
  76. package/dist/esm/components-page/account-settings/payments/payments-page.js +1 -1
  77. package/dist/esm/components-page/account-settings/profile-page/profile-page.js +1 -1
  78. package/dist/esm/components-page/account-settings/teams/team-api-keys-section.js +1 -1
  79. package/dist/esm/components-page/account-settings/teams/team-creation-page.js +5 -5
  80. package/dist/esm/components-page/account-settings/teams/team-member-invitation-section.js +5 -5
  81. package/dist/esm/components-page/account-settings.js +3 -3
  82. package/dist/esm/components-page/auth-page.js +1 -1
  83. package/dist/esm/components-page/cli-auth-confirm.js +1 -1
  84. package/dist/esm/components-page/forgot-password.js +5 -5
  85. package/dist/esm/components-page/hexclave-handler-client.js +1 -1
  86. package/dist/esm/components-page/mfa.js +3 -3
  87. package/dist/esm/components-page/oauth-callback.js +1 -1
  88. package/dist/esm/components-page/onboarding.js +4 -4
  89. package/dist/esm/components-page/password-reset.js +7 -7
  90. package/dist/esm/components-page/team-creation.js +5 -5
  91. package/dist/esm/generated/quetzal-translations.d.ts +2 -2
  92. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +3 -3
  93. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
  94. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js +3 -0
  95. package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
  96. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +45 -7
  97. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  98. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +2 -1
  99. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
  100. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js +44 -9
  101. package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  102. package/dist/esm/lib/hexclave-app/apps/implementations/common.js +2 -2
  103. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.d.ts +1 -1
  104. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.d.ts.map +1 -1
  105. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.js +15 -9
  106. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.js.map +1 -1
  107. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js +4 -4
  108. package/dist/esm/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js.map +1 -1
  109. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
  110. package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.js +1 -1
  111. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts +6 -0
  112. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.d.ts.map +1 -1
  113. package/dist/esm/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
  114. package/dist/esm/lib/hexclave-app/apps/interfaces/server-app.d.ts +6 -0
  115. package/dist/esm/lib/hexclave-app/apps/interfaces/server-app.d.ts.map +1 -1
  116. package/dist/esm/lib/hexclave-app/apps/interfaces/server-app.js.map +1 -1
  117. package/dist/esm/lib/hexclave-app/index.d.ts +2 -2
  118. package/dist/esm/lib/hexclave-app/projects/index.d.ts +17 -2
  119. package/dist/esm/lib/hexclave-app/projects/index.d.ts.map +1 -1
  120. package/dist/esm/lib/hexclave-app/projects/index.js.map +1 -1
  121. package/dist/esm/lib/hexclave-app/users/index.d.ts +1 -1
  122. package/dist/generated/quetzal-translations.d.ts +1 -1
  123. package/dist/{hexclave-provider-osaUd2IG.d.ts → hexclave-provider-Ddm9gG_n.d.ts} +3 -3
  124. package/dist/{hexclave-provider-osaUd2IG.d.ts.map → hexclave-provider-Ddm9gG_n.d.ts.map} +1 -1
  125. package/dist/{hooks-DNH1nVku.d.ts → hooks-CVnAZQ6g.d.ts} +2 -2
  126. package/dist/{hooks-DNH1nVku.d.ts.map → hooks-CVnAZQ6g.d.ts.map} +1 -1
  127. package/dist/{index-CffsejeK.d.ts → index-DXeakUlR.d.ts} +2 -2
  128. package/dist/{index-CffsejeK.d.ts.map → index-DXeakUlR.d.ts.map} +1 -1
  129. package/dist/index.d.ts +5 -5
  130. package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -1
  131. package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js +3 -0
  132. package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
  133. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js +45 -7
  134. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
  135. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +1 -1
  136. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js +44 -9
  137. package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
  138. package/dist/lib/hexclave-app/apps/implementations/common.js +2 -2
  139. package/dist/lib/hexclave-app/apps/implementations/index.d.ts +1 -1
  140. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.d.ts +1 -1
  141. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.js +15 -9
  142. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.js.map +1 -1
  143. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js +4 -4
  144. package/dist/lib/hexclave-app/apps/implementations/redirect-page-urls.test.js.map +1 -1
  145. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
  146. package/dist/lib/hexclave-app/apps/implementations/server-app-impl.js +1 -1
  147. package/dist/lib/hexclave-app/apps/index.d.ts +1 -1
  148. package/dist/lib/hexclave-app/apps/interfaces/admin-app.d.ts +1 -1
  149. package/dist/lib/hexclave-app/apps/interfaces/client-app.d.ts +1 -1
  150. package/dist/lib/hexclave-app/apps/interfaces/client-app.js.map +1 -1
  151. package/dist/lib/hexclave-app/apps/interfaces/server-app.d.ts +1 -1
  152. package/dist/lib/hexclave-app/apps/interfaces/server-app.js.map +1 -1
  153. package/dist/lib/hexclave-app/index.d.ts +2 -2
  154. package/dist/lib/hexclave-app/projects/index.d.ts +2 -2
  155. package/dist/lib/hexclave-app/projects/index.js.map +1 -1
  156. package/dist/lib/hexclave-app/teams/index.d.ts +1 -1
  157. package/dist/lib/hexclave-app/users/index.d.ts +1 -1
  158. package/dist/lib/hooks.d.ts +1 -1
  159. package/dist/providers/hexclave-context.d.ts +1 -1
  160. package/dist/providers/hexclave-provider-client.d.ts +1 -1
  161. package/dist/providers/hexclave-provider.d.ts +1 -1
  162. package/dist/providers/translation-provider.d.ts +1 -1
  163. package/dist/pushed-config-error-overlay/index.d.ts +1 -1
  164. package/dist/{quetzal-translations-XeH3zQ9l.d.ts → quetzal-translations-CwNB-iql.d.ts} +3 -3
  165. package/dist/{quetzal-translations-XeH3zQ9l.d.ts.map → quetzal-translations-CwNB-iql.d.ts.map} +1 -1
  166. package/dist/{redirect-page-urls-Jfs_-wyq.d.ts → redirect-page-urls-ofcg3AYr.d.ts} +2 -2
  167. package/dist/{redirect-page-urls-Jfs_-wyq.d.ts.map → redirect-page-urls-ofcg3AYr.d.ts.map} +1 -1
  168. package/dist/{translation-provider-WOaZXqAz.d.ts → translation-provider-C0uPBd41.d.ts} +2 -2
  169. package/dist/{translation-provider-WOaZXqAz.d.ts.map → translation-provider-C0uPBd41.d.ts.map} +1 -1
  170. package/package.json +4 -4
  171. package/src/lib/hexclave-app/apps/implementations/admin-app-impl.ts +3 -0
  172. package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +64 -6
  173. package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +65 -15
  174. package/src/lib/hexclave-app/apps/implementations/redirect-page-urls.test.ts +4 -4
  175. package/src/lib/hexclave-app/apps/implementations/redirect-page-urls.ts +13 -10
  176. package/src/lib/hexclave-app/apps/interfaces/client-app.ts +6 -0
  177. package/src/lib/hexclave-app/apps/interfaces/server-app.ts +6 -0
  178. package/src/lib/hexclave-app/index.ts +1 -0
  179. package/src/lib/hexclave-app/projects/index.ts +19 -2
  180. package/dist/admin-app-impl-CMKoG26j.d.ts.map +0 -1
  181. package/dist/client-app-D84Jo2In.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"client-app-impl.cross-domain.test.js","names":["StackClientApp","hexclaveAppInternalsSymbol","AccessToken","Store","vi","HexclaveSetupError","expect"],"sources":["../../../../../src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\nimport { describe, expect, it, vi } from \"vitest\";\nimport { AccessToken } from \"@hexclave/shared/dist/sessions\";\nimport { HexclaveSetupError } from \"@hexclave/shared/dist/utils/errors\";\nimport { Store } from \"@hexclave/shared/dist/utils/stores\";\nimport { hexclaveAppInternalsSymbol } from \"../../common\";\nimport { StackClientApp } from \"../interfaces/client-app\";\nimport { planRedirectToHandler } from \"./redirect-page-urls\";\n\n// Every app in this file is constructed with `devTool: false`. The tests install a mock window and document, which makes\n// the SDK believe it is in a browser; mounting the dev tool would then start background requests against a backend that\n// does not exist here and leak that work across test cases.\nfunction createAccessTokenString(refreshTokenId: string): string {\n const encode = (value: unknown) => Buffer.from(JSON.stringify(value)).toString(\"base64url\");\n const nowSeconds = Math.floor(Date.now() / 1000);\n return [\n encode({ alg: \"none\", typ: \"JWT\" }),\n encode({\n sub: \"user-id\",\n exp: nowSeconds + 60,\n iat: nowSeconds,\n iss: \"https://api.example.test\",\n aud: \"project-id\",\n project_id: \"project-id\",\n branch_id: \"main\",\n refresh_token_id: refreshTokenId,\n role: \"authenticated\",\n name: null,\n email: null,\n email_verified: false,\n selected_team_id: null,\n signed_up_at: nowSeconds,\n is_anonymous: false,\n is_restricted: false,\n restricted_reason: null,\n requires_totp_mfa: false,\n }),\n \"\",\n ].join(\".\");\n}\n\nfunction createMockDocument(): Document {\n const cookieJar = new Map<string, string>();\n return {\n get cookie() {\n return [...cookieJar.entries()].map(([key, value]) => `${key}=${value}`).join(\"; \");\n },\n set cookie(str: string) {\n const [nameValue] = str.split(\";\");\n const eqIndex = nameValue.indexOf(\"=\");\n if (eqIndex < 0) return;\n cookieJar.set(nameValue.slice(0, eqIndex).trim(), nameValue.slice(eqIndex + 1).trim());\n },\n createElement: () => ({}),\n } as any;\n}\n\n/**\n * Installs a stand-in for `window` with only the parts the code under test touches. `globalThis.window` is typed as a\n * full `Window`, which a hand-written stub can never be, so the assignment goes through `Reflect.set` — the stub's own\n * shape stays checked, unlike with a cast on the object literal.\n */\nfunction setMockWindow(mockWindow: {\n location: { href: string, replace?: (url: string) => void },\n}): void {\n Reflect.set(globalThis, \"window\", mockWindow);\n}\n\n/**\n * Calls one of the app's `protected` methods, which are part of the flows under test but not of the public SDK surface.\n */\nfunction callProtectedMethod(app: StackClientApp<true>, methodName: string, ...args: unknown[]): Promise<unknown> {\n const method = Reflect.get(app, methodName);\n if (typeof method !== \"function\") {\n throw new Error(`Expected StackClientApp to have a ${methodName} method in tests.`);\n }\n return method.apply(app, args);\n}\n\ndescribe(\"StackClientApp cross-domain auth\", () => {\n it(\"keeps noRedirectBack same-domain redirects free of redirect-back state\", async () => {\n const redirectPlan = await planRedirectToHandler({\n handlerName: \"signIn\",\n rawHandlerUrl: \"/handler/sign-in\",\n noRedirectBack: true,\n currentUrl: new URL(\"https://app.example.test/settings?tab=profile\"),\n getLocalOAuthCallbackUrl: () => \"/handler/oauth-callback\",\n rawHomeUrl: \"/home\",\n getCrossDomainHandoffParams: async () => {\n throw new Error(\"Same-domain redirects must not create cross-domain handoff parameters.\");\n },\n });\n\n expect(redirectPlan).toEqual({\n type: \"redirect\",\n url: \"/handler/sign-in\",\n });\n });\n\n it(\"returns noRedirectBack cross-domain auth to the source app home\", async () => {\n const handoffState = \"no-redirect-back-state\";\n const handoffCodeChallenge = \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\";\n const currentUrl = new URL(\"https://app.example.test/settings?tab=profile\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_state\", handoffState);\n currentUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", handoffCodeChallenge);\n currentUrl.searchParams.set(\n \"hexclave_cross_domain_after_callback_redirect_url\",\n \"https://app.example.test/settings?tab=profile\",\n );\n\n const redirectPlan = await planRedirectToHandler({\n handlerName: \"signIn\",\n rawHandlerUrl: \"https://auth.example.test/handler/sign-in\",\n noRedirectBack: true,\n currentUrl,\n getLocalOAuthCallbackUrl: () => \"/handler/oauth-callback\",\n rawHomeUrl: \"/home\",\n getCrossDomainHandoffParams: async () => {\n throw new Error(\"Existing cross-domain handoff parameters must be reused.\");\n },\n });\n\n expect(redirectPlan.type).toBe(\"redirect\");\n if (redirectPlan.type !== \"redirect\") {\n throw new Error(\"Expected noRedirectBack sign-in to produce a redirect URL.\");\n }\n\n const hostedUrl = new URL(redirectPlan.url);\n expect(hostedUrl.origin).toBe(\"https://auth.example.test\");\n expect(hostedUrl.pathname).toBe(\"/handler/sign-in\");\n expect(hostedUrl.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\n \"https://app.example.test/home\",\n );\n\n const rawSourceCallbackUrl = hostedUrl.searchParams.get(\"after_auth_return_to\");\n if (rawSourceCallbackUrl == null) {\n throw new Error(\"Expected cross-domain noRedirectBack to include its internal source callback URL.\");\n }\n const sourceCallbackUrl = new URL(rawSourceCallbackUrl);\n expect(sourceCallbackUrl.origin).toBe(\"https://app.example.test\");\n expect(sourceCallbackUrl.pathname).toBe(\"/handler/oauth-callback\");\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_auth\")).toBe(\"1\");\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_state\")).toBe(handoffState);\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_code_challenge\")).toBe(handoffCodeChallenge);\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\n \"https://app.example.test/home\",\n );\n expect(sourceCallbackUrl.toString()).not.toContain(\"/settings\");\n });\n\n it(\"exposes redirect-back-aware handler URLs for devtool previews\", async () => {\n const previousWindow = Reflect.get(globalThis, \"window\");\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n Reflect.set(globalThis, \"window\", {\n location: {\n href: \"http://localhost/music?track=1#song\",\n },\n });\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n urls: {\n signIn: \"/handler/sign-in\",\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"signIn\");\n\n const resolved = new URL(redirectUrl, \"http://localhost\");\n expect(resolved.pathname).toBe(\"/handler/sign-in\");\n expect(resolved.searchParams.get(\"after_auth_return_to\")).toBe(\"/music?track=1#song\");\n } finally {\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n } else {\n Reflect.deleteProperty(globalThis, \"window\");\n }\n }\n });\n\n it(\"gets a hosted sign-in redirect without accessing window on the server\", async () => {\n const previousWindow = Reflect.get(globalThis, \"window\");\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n Reflect.deleteProperty(globalThis, \"window\");\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"signIn\");\n\n expect(new URL(redirectUrl).pathname).toContain(\"sign-in\");\n } finally {\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n }\n }\n });\n\n it(\"uses the fresh post-auth refresh token when minting a cross-domain handoff\", async () => {\n const freshAccessToken = createAccessTokenString(\"fresh-refresh-token-id\");\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: {\n accessToken: createAccessTokenString(\"stale-refresh-token-id\"),\n refreshToken: \"stale-refresh-token\",\n },\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalSendClientRequest = Reflect.get(clientInterface, \"sendClientRequest\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n const capturedRefreshTokens: string[] = [];\n const capturedAccessTokenRefreshTokenIds: string[] = [];\n const refreshedRawRefreshTokens: string[] = [];\n\n Reflect.set(clientInterface, \"sendClientRequest\", async (_path: unknown, _requestOptions: unknown, session: unknown) => {\n const getRefreshToken = Reflect.get(session ?? {}, \"getRefreshToken\");\n const getOrFetchLikelyValidTokens = Reflect.get(session ?? {}, \"getOrFetchLikelyValidTokens\");\n if (typeof getRefreshToken !== \"function\") {\n throw new Error(\"Expected cross-domain auth to pass a session to the client interface.\");\n }\n if (typeof getOrFetchLikelyValidTokens !== \"function\") {\n throw new Error(\"Expected cross-domain auth to pass a session with token accessors.\");\n }\n const refreshToken = getRefreshToken.call(session);\n const refreshTokenString = Reflect.get(refreshToken ?? {}, \"token\");\n if (typeof refreshTokenString !== \"string\") {\n throw new Error(\"Expected cross-domain auth to pass a refresh-token-backed session.\");\n }\n capturedRefreshTokens.push(refreshTokenString);\n const tokens = await getOrFetchLikelyValidTokens.call(session, 0, null);\n capturedAccessTokenRefreshTokenIds.push(tokens.accessToken.payload.refresh_token_id);\n return {\n ok: true,\n json: async () => ({ redirect_url: \"https://example.com/handler/oauth-callback?code=handoff-code&state=handoff-state\" }),\n };\n });\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async (refreshToken: unknown) => {\n const refreshTokenString = Reflect.get(refreshToken ?? {}, \"token\");\n if (typeof refreshTokenString !== \"string\") {\n throw new Error(\"Expected refresh token while fetching a new access token.\");\n }\n refreshedRawRefreshTokens.push(refreshTokenString);\n return AccessToken.createIfValid(freshAccessToken) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n\n try {\n const createCrossDomainAuthRedirectUrl = Reflect.get(clientApp, \"_createCrossDomainAuthRedirectUrl\");\n if (typeof createCrossDomainAuthRedirectUrl !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _createCrossDomainAuthRedirectUrl in tests.\");\n }\n\n await expect(createCrossDomainAuthRedirectUrl.call(clientApp, {\n redirectUri: \"https://example.com/handler/oauth-callback\",\n state: \"handoff-state\",\n codeChallenge: \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\",\n afterCallbackRedirectUrl: \"https://example.com/account-settings\",\n overrideTokenStoreInit: {\n accessToken: createAccessTokenString(\"fresh-stale-refresh-token-id\"),\n refreshToken: \"fresh-refresh-token\",\n },\n })).resolves.toBe(\"https://example.com/handler/oauth-callback?code=handoff-code&state=handoff-state\");\n } finally {\n Reflect.set(clientInterface, \"sendClientRequest\", originalSendClientRequest);\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n }\n\n expect(refreshedRawRefreshTokens).toEqual([\"fresh-refresh-token\"]);\n expect(capturedRefreshTokens).toEqual([\"fresh-refresh-token\"]);\n expect(capturedAccessTokenRefreshTokenIds).toEqual([\"fresh-refresh-token-id\"]);\n });\n\n it(\"uses a fresh nested OAuth state while preserving the outer cross-domain return state\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000002\";\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const outerState = \"outer-cross-domain-state\";\n const outerCodeChallenge = \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\";\n const currentUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n currentUrl.searchParams.set(\"after_auth_return_to\", `https://demo.stack-auth.com/?hexclave_cross_domain_auth=1&hexclave_cross_domain_state=${outerState}`);\n currentUrl.searchParams.set(\"hexclave_cross_domain_state\", outerState);\n currentUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", outerCodeChallenge);\n currentUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", \"https://demo.stack-auth.com/\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-session\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_callback_url\", \"https://demo.stack-auth.com/\");\n\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n let redirectedUrl = \"\";\n vi.spyOn(clientApp as any, \"_fetchCurrentRefreshTokenIdIfSignedIn\").mockResolvedValue(null);\n vi.spyOn(clientApp as any, \"_getCrossDomainHandoffParamsForRedirect\").mockResolvedValue({\n state: \"fresh-nested-state\",\n codeChallenge: \"fresh-nested-code-challenge\",\n });\n vi.spyOn(clientApp as any, \"_isTrusted\").mockResolvedValue(true);\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: currentUrl.toString(),\n replace: (url: string) => {\n redirectedUrl = url;\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n try {\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n const redirectUrl = new URL(redirectedUrl);\n expect(redirectUrl.searchParams.get(\"state\")).toBe(\"fresh-nested-state\");\n expect(redirectUrl.searchParams.get(\"code_challenge\")).toBe(\"fresh-nested-code-challenge\");\n const redirectUri = new URL(redirectUrl.searchParams.get(\"redirect_uri\") ?? \"\");\n expect(redirectUri.searchParams.get(\"hexclave_cross_domain_state\")).toBe(outerState);\n expect(redirectUri.searchParams.get(\"hexclave_cross_domain_code_challenge\")).toBe(outerCodeChallenge);\n expect(redirectUri.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\"https://demo.stack-auth.com/\");\n });\n\n it(\"clears a stale target-domain session before deferring to the source-domain session\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000006\";\n const hostedAccessToken = createAccessTokenString(\"hosted-old-refresh-token-id\");\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const tokenStore = Reflect.get(clientApp, \"_memoryTokenStore\");\n if (!(tokenStore instanceof Store)) {\n throw new Error(\"Expected StackClientApp to use a memory token store in this test.\");\n }\n tokenStore.set({\n refreshToken: \"hosted-old-refresh-token\",\n accessToken: hostedAccessToken,\n });\n\n const currentUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-anonymous-refresh-token-id\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_callback_url\", \"https://demo.stack-auth.com/handler/oauth-callback\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_state\", \"outer-state\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", \"outer-code-challenge\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", \"https://demo.stack-auth.com/app\");\n\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n let redirectedUrl = \"\";\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async () => {\n return AccessToken.createIfValid(hostedAccessToken) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n vi.spyOn(clientApp as any, \"_isTrusted\").mockResolvedValue(true);\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: currentUrl.toString(),\n replace: (url: string) => {\n redirectedUrl = url;\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n try {\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n } finally {\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n expect(tokenStore.get()).toEqual({\n refreshToken: null,\n accessToken: null,\n });\n expect(new URL(redirectedUrl).origin).toBe(\"https://demo.stack-auth.com\");\n });\n\n it(\"uses the latest browser refresh cookie before computing nested cross-domain session IDs\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000007\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: \"https://demo.stack-auth.com/\",\n protocol: \"https:\",\n hostname: \"demo.stack-auth.com\",\n },\n addEventListener: () => {},\n removeEventListener: () => {},\n } as any;\n\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"cookie\",\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n const refreshedRawRefreshTokens: string[] = [];\n\n // Cookie-store writes queue a background trusted-parent-domain lookup. Without this stub, that\n // lookup fetches the (unreachable) baseUrl with retries while holding the global store lock,\n // which starves any later test that needs the write lock (e.g. signOut). Not restored on\n // purpose: queued tasks can still run after this test body finishes.\n vi.spyOn(clientApp as any, \"_getTrustedParentDomain\").mockResolvedValue(null);\n\n try {\n const getBrowserCookieTokenStore = Reflect.get(clientApp, \"_getBrowserCookieTokenStore\");\n if (typeof getBrowserCookieTokenStore !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _getBrowserCookieTokenStore in tests.\");\n }\n const tokenStore = getBrowserCookieTokenStore.call(clientApp);\n tokenStore.set({\n refreshToken: \"old-refresh-token\",\n accessToken: createAccessTokenString(\"old-refresh-token-id\"),\n });\n\n document.cookie = `__Host-hexclave-refresh-${projectId}--default=${JSON.stringify({\n refresh_token: \"new-refresh-token\",\n updated_at_millis: 1,\n })}`;\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async (refreshToken: unknown) => {\n const refreshTokenString = Reflect.get(refreshToken ?? {}, \"token\");\n if (typeof refreshTokenString !== \"string\") {\n throw new Error(\"Expected refresh token while fetching a new access token.\");\n }\n refreshedRawRefreshTokens.push(refreshTokenString);\n return AccessToken.createIfValid(createAccessTokenString(\"new-refresh-token-id\")) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n\n const fetchCurrentRefreshTokenIdIfSignedIn = Reflect.get(clientApp, \"_fetchCurrentRefreshTokenIdIfSignedIn\");\n if (typeof fetchCurrentRefreshTokenIdIfSignedIn !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _fetchCurrentRefreshTokenIdIfSignedIn in tests.\");\n }\n await expect(fetchCurrentRefreshTokenIdIfSignedIn.call(clientApp, {\n awaitPendingAuthResolutions: false,\n })).resolves.toBe(\"new-refresh-token-id\");\n } finally {\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n expect(refreshedRawRefreshTokens).toEqual([\"new-refresh-token\"]);\n });\n\n it(\"stops polling the browser cookie store when browser globals are removed\", () => {\n vi.useFakeTimers();\n const clearIntervalSpy = vi.spyOn(globalThis, \"clearInterval\");\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: \"https://demo.stack-auth.com/\",\n protocol: \"https:\",\n hostname: \"demo.stack-auth.com\",\n },\n addEventListener: () => {},\n removeEventListener: () => {},\n } as any;\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000007\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"cookie\",\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n automaticSideEffects: false,\n devTool: false,\n });\n const getBrowserCookieTokenStore = Reflect.get(clientApp, \"_getBrowserCookieTokenStore\");\n if (typeof getBrowserCookieTokenStore !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _getBrowserCookieTokenStore in tests.\");\n }\n getBrowserCookieTokenStore.call(clientApp);\n\n Reflect.set(globalThis, \"window\", previousWindow);\n Reflect.set(globalThis, \"document\", previousDocument);\n\n expect(() => vi.advanceTimersByTime(100)).not.toThrow();\n expect(clearIntervalSpy).toHaveBeenCalledOnce();\n } finally {\n Reflect.set(globalThis, \"window\", previousWindow);\n Reflect.set(globalThis, \"document\", previousDocument);\n clearIntervalSpy.mockRestore();\n vi.useRealTimers();\n }\n });\n\n it(\"does not re-bounce nested cross-domain auth after the OAuth callback consumed code+state from the URL\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000008\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n const strippedUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n strippedUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-refresh-token-id\");\n strippedUrl.searchParams.set(\"stack_nested_cross_domain_auth_callback_url\", \"https://demo.stack-auth.com/\");\n const urlAtConstructionTime = new URL(strippedUrl);\n urlAtConstructionTime.searchParams.set(\"code\", \"one-time-code\");\n urlAtConstructionTime.searchParams.set(\"state\", \"nested-oauth-state\");\n\n // Construct before installing the window mock so the constructor does not schedule its own\n // nested-auth resolution; the assertions below drive the handler explicitly.\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: strippedUrl.toString(),\n replace: () => {\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n vi.spyOn(clientApp as any, \"_fetchCurrentRefreshTokenIdIfSignedIn\").mockResolvedValue(null);\n vi.spyOn(clientApp as any, \"_getCrossDomainHandoffParamsForRedirect\").mockResolvedValue({\n state: \"fresh-nested-state\",\n codeChallenge: \"fresh-nested-code-challenge\",\n });\n vi.spyOn(clientApp as any, \"_isTrusted\").mockResolvedValue(true);\n\n try {\n // Without the construction-time URL, the handler re-bounces (location.replace aborts).\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n // With it, the in-flight OAuth callback wins and the handler stands down.\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth(urlAtConstructionTime)).resolves.toBe(false);\n // The live-URL guard must also stand down on its own when code+state are still present.\n (globalThis.window as any).location.href = urlAtConstructionTime.toString();\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).resolves.toBe(false);\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"reports malformed nested cross-domain auth URLs as setup errors\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000012\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n globalThis.document = createMockDocument();\n\n // A URL the flow cannot even parse is as fatal as an untrusted one, so it has to reach the developer the same way\n // instead of escaping as a bare TypeError from `new URL()`, which the overlay only shows during development.\n // The two branches of the handler want opposite session states: on the provider side (a.com) a query-derived failure\n // only becomes a setup error when the handoff belongs to the current session, while the requesting side (b.com) only\n // bounces when the current session is *not* the one that was asked for.\n const malformedCases = [\n {\n description: \"redirect URI\",\n currentRefreshTokenId: \"source-refresh-token-id\",\n params: { redirect_uri: \"not-a-url\", state: \"nested-state\", code_challenge: \"nested-code-challenge\" },\n },\n {\n description: \"after-callback redirect URL\",\n currentRefreshTokenId: \"source-refresh-token-id\",\n params: {\n redirect_uri: \"https://source.example.test/handler/account-settings\",\n state: \"nested-state\",\n code_challenge: \"nested-code-challenge\",\n after_callback_redirect_url: \"http://[\",\n },\n },\n {\n description: \"callback URL\",\n currentRefreshTokenId: null,\n params: { stack_nested_cross_domain_auth_callback_url: \"http://[\" },\n },\n ];\n\n try {\n for (const malformedCase of malformedCases) {\n const currentUrl = new URL(\"https://target.example.test/nested-provider\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-refresh-token-id\");\n for (const [key, value] of Object.entries(malformedCase.params)) {\n currentUrl.searchParams.set(key, value);\n }\n // Each app is constructed with the mock window uninstalled: the constructor's automatic side effects expect a\n // real window, and a construction-time nested-auth URL would also schedule a second, unawaited run of the\n // handler that keeps failing in the background and leaks into whichever test runs next.\n globalThis.window = previousWindow;\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n setMockWindow({ location: { href: currentUrl.toString() } });\n Reflect.set(clientApp, \"_fetchCurrentRefreshTokenIdIfSignedIn\", async () => malformedCase.currentRefreshTokenId);\n Reflect.set(clientApp, \"_isTrusted\", async () => true);\n\n const nestedAuthPromise = callProtectedMethod(clientApp, \"_maybeHandleNestedCrossDomainAuth\");\n await expect(nestedAuthPromise).rejects.toThrowError(new RegExp(`${malformedCase.description} .* is not a valid absolute URL`));\n await expect(nestedAuthPromise).rejects.toSatisfy((error: unknown) => HexclaveSetupError.isSetupError(error));\n }\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"keeps nested cross-domain auth failures off the page for a handoff that does not own the session\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000013\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n globalThis.document = createMockDocument();\n\n // Setup errors are shown in production, so a link anybody can craft must not be able to put a card on a healthy\n // app's page: with a refresh-token ID that is not the current session's, every failure below stays an ordinary error\n // that only captureError sees, even though the same URL from the right session would render a card.\n const craftedRedirectUris = [\n \"https://evil.example.test/handler/account-settings\", // untrusted\n \"not-a-url\", // malformed\n ];\n\n try {\n for (const craftedRedirectUri of craftedRedirectUris) {\n const currentUrl = new URL(\"https://target.example.test/nested-provider\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"attacker-chosen-refresh-token-id\");\n currentUrl.searchParams.set(\"redirect_uri\", craftedRedirectUri);\n currentUrl.searchParams.set(\"state\", \"nested-state\");\n currentUrl.searchParams.set(\"code_challenge\", \"nested-code-challenge\");\n\n globalThis.window = previousWindow;\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n setMockWindow({ location: { href: currentUrl.toString() } });\n Reflect.set(clientApp, \"_fetchCurrentRefreshTokenIdIfSignedIn\", async () => \"this-apps-refresh-token-id\");\n Reflect.set(clientApp, \"_isTrusted\", async () => false);\n\n const nestedAuthPromise = callProtectedMethod(clientApp, \"_maybeHandleNestedCrossDomainAuth\");\n await expect(nestedAuthPromise).rejects.toThrowError(/does not match the requested refresh token ID/);\n await expect(nestedAuthPromise).rejects.toSatisfy(\n (error: unknown) => !HexclaveSetupError.isSetupError(error),\n );\n }\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"passes the construction-time URL to the nested cross-domain auth handler\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000009\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n const callbackUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n callbackUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-refresh-token-id\");\n callbackUrl.searchParams.set(\"code\", \"one-time-code\");\n callbackUrl.searchParams.set(\"state\", \"nested-oauth-state\");\n const strippedUrl = new URL(callbackUrl);\n strippedUrl.searchParams.delete(\"code\");\n strippedUrl.searchParams.delete(\"state\");\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: callbackUrl.toString(),\n },\n } as any;\n\n const nestedAuthSpy = vi.spyOn(StackClientApp.prototype as any, \"_maybeHandleNestedCrossDomainAuth\").mockResolvedValue(false);\n\n try {\n new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n // Simulate consumeOAuthCallbackQueryParams stripping code+state before microtasks run.\n (globalThis.window as any).location.href = strippedUrl.toString();\n await new Promise((resolve) => setTimeout(resolve, 0));\n\n expect(nestedAuthSpy).toHaveBeenCalledTimes(1);\n const urlArgument = nestedAuthSpy.mock.calls[0][0] as URL;\n expect(urlArgument).toBeInstanceOf(URL);\n expect(urlArgument.searchParams.get(\"code\")).toBe(\"one-time-code\");\n expect(urlArgument.searchParams.get(\"state\")).toBe(\"nested-oauth-state\");\n } finally {\n nestedAuthSpy.mockRestore();\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"redirects hosted current-page OAuth callback errors to the hosted error handler during startup\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000010\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n const callbackUrl = new URL(\"https://demo.stack-auth.com/dashboard\");\n callbackUrl.searchParams.set(\"errorCode\", \"SIGN_UP_REJECTED\");\n callbackUrl.searchParams.set(\"message\", \"Your sign up was rejected by an administrator's sign-up rule.\");\n callbackUrl.searchParams.set(\"details\", JSON.stringify({\n message: \"Your sign up was rejected by an administrator's sign-up rule.\",\n }));\n callbackUrl.searchParams.set(\"after_auth_return_to\", \"/dashboard\");\n callbackUrl.searchParams.set(\"after_callback_redirect_url\", \"https://customer.example.test/settings?tab=connected-accounts\");\n let currentHref = callbackUrl.toString();\n let redirectedUrl = \"\";\n const redirectSpy = vi.spyOn(StackClientApp.prototype as any, \"_redirectTo\").mockImplementation(async (...args: unknown[]) => {\n const options = args[0] as { url: string | URL };\n redirectedUrl = options.url.toString();\n });\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n get href() {\n return currentHref;\n },\n set href(value: string) {\n currentHref = value;\n },\n origin: callbackUrl.origin,\n },\n history: {\n replaceState: (_state: unknown, _title: string, url: string) => {\n currentHref = new URL(url, currentHref).toString();\n },\n },\n addEventListener: () => {},\n removeEventListener: () => {},\n } as any;\n\n try {\n new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n await new Promise((resolve) => setTimeout(resolve, 0));\n } finally {\n redirectSpy.mockRestore();\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n const errorUrl = new URL(redirectedUrl);\n expect(errorUrl.origin).toBe(`https://${projectId}.built-with-hexclave.com`);\n expect(errorUrl.pathname).toBe(\"/handler/error\");\n expect(errorUrl.searchParams.get(\"errorCode\")).toBe(\"SIGN_UP_REJECTED\");\n expect(errorUrl.searchParams.get(\"message\")).toBe(\"Your sign up was rejected by an administrator's sign-up rule.\");\n expect(errorUrl.searchParams.get(\"after_auth_return_to\")).toBe(\"/dashboard\");\n expect(errorUrl.searchParams.get(\"after_callback_redirect_url\")).toBe(\"https://customer.example.test/settings?tab=connected-accounts\");\n expect(new URL(currentHref).searchParams.has(\"errorCode\")).toBe(false);\n });\n\n it(\"uses direct sign-out instead of hosted sign-out redirects when code execution is available\", async () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000003\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n handler: \"/handler\",\n signOut: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const signOutSpy = vi.spyOn(clientApp, \"signOut\").mockRejectedValue(new Error(\"INTENTIONAL_TEST_ABORT\"));\n\n try {\n await expect(clientApp.redirectToSignOut()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n expect(signOutSpy).toHaveBeenCalledWith();\n } finally {\n signOutSpy.mockRestore();\n }\n });\n\n it(\"throws when public app.urls reads would return hosted component URLs\", () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000003\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n expect(() => clientApp.urls.signIn).toThrowError(/app\\.urls\\.signIn cannot be used when this app is configured to use hosted components.*Use app\\.redirectToSignIn\\(\\) instead/s);\n expect(() => clientApp.urls.signOut).toThrowError(/app\\.urls\\.signOut cannot be used when this app is configured to use hosted components.*Use app\\.redirectToSignOut\\(\\) instead/s);\n expect(clientApp.urls.afterSignIn).toBe(\"/\");\n });\n\n it(\"keeps public app.urls reads available for non-hosted targets\", () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000003\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n handler: \"/custom-handler\",\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n expect(clientApp.urls.signIn).toBe(\"/custom-handler/sign-in\");\n });\n\n it(\"keeps default hosted signOut() on the source domain when afterSignOut is not configured\", async () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000004\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const currentHref = \"https://demo.stack-auth.com/settings?tab=profile\";\n\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalSignOut = Reflect.get(clientInterface, \"signOut\");\n Reflect.set(clientInterface, \"signOut\", async () => {});\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n let redirectedUrl = \"\";\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: currentHref,\n replace: (url: string) => {\n redirectedUrl = url;\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n try {\n const signOut = Reflect.get(clientApp, \"_signOut\");\n if (typeof signOut !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _signOut in tests.\");\n }\n await expect(signOut.call(clientApp, Reflect.get(clientInterface, \"createSession\").call(clientInterface, {\n refreshToken: null,\n }))).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n } finally {\n Reflect.set(clientInterface, \"signOut\", originalSignOut);\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n expect(redirectedUrl).toBe(\"/settings?tab=profile\");\n });\n\n it(\"restores a dropped after_auth_return_to from the sessionStorage mirror when redirecting after sign-in\", async () => {\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n const sessionStorageMap = new Map<string, string>();\n const windowMock = {\n location: {\n href: \"https://demo.example.test/handler/sign-in?after_auth_return_to=%2Fmusic%3Ftrack%3D1\",\n },\n sessionStorage: {\n getItem: (key: string) => sessionStorageMap.get(key) ?? null,\n setItem: (key: string, value: string) => {\n sessionStorageMap.set(key, value);\n },\n removeItem: (key: string) => {\n sessionStorageMap.delete(key);\n },\n },\n };\n Reflect.set(globalThis, \"window\", windowMock);\n globalThis.document = createMockDocument();\n\n try {\n // The constructor mirrors the redirect-back state from the arrival URL into sessionStorage.\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000011\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n // Intermediate hops (MFA, magic link, OAuth round-trips, ...) dropped the query params.\n windowMock.location.href = \"https://demo.example.test/handler/mfa\";\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"afterSignIn\");\n expect(redirectUrl).toBe(\"/music?track=1\");\n\n // noRedirectBack opts out of the mirror just like it opts out of the query param.\n const noRedirectBackUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"afterSignIn\", { noRedirectBack: true });\n expect(new URL(noRedirectBackUrl, \"https://demo.example.test\").pathname).toBe(\"/\");\n } finally {\n globalThis.document = previousDocument;\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n } else {\n Reflect.deleteProperty(globalThis, \"window\");\n }\n }\n });\n\n it(\"restores dropped cross-domain handoff state from the sessionStorage mirror when redirecting after sign-in\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000012\";\n const previousWindow = globalThis.window;\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n const sessionStorageMap = new Map<string, string>();\n\n const handoffState = \"mirror-handoff-state\";\n const handoffCodeChallenge = \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\";\n const handoffAfterCallbackRedirect = \"https://demo.example.test/dashboard\";\n const redirectBackUrl = new URL(\"https://demo.example.test/handler/oauth-callback\");\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_auth\", \"1\");\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_state\", handoffState);\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", handoffCodeChallenge);\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", handoffAfterCallbackRedirect);\n\n const arrivalUrl = new URL(`https://${projectId}.built-with-hexclave.com/handler/sign-in`);\n arrivalUrl.searchParams.set(\"after_auth_return_to\", redirectBackUrl.toString());\n arrivalUrl.searchParams.set(\"hexclave_cross_domain_state\", handoffState);\n arrivalUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", handoffCodeChallenge);\n arrivalUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", handoffAfterCallbackRedirect);\n\n const previousDocument = globalThis.document;\n const windowMock = {\n location: {\n href: arrivalUrl.toString(),\n },\n sessionStorage: {\n getItem: (key: string) => sessionStorageMap.get(key) ?? null,\n setItem: (key: string, value: string) => {\n sessionStorageMap.set(key, value);\n },\n removeItem: (key: string) => {\n sessionStorageMap.delete(key);\n },\n },\n };\n Reflect.set(globalThis, \"window\", windowMock);\n globalThis.document = createMockDocument();\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const crossDomainAuthorizeRedirect = \"https://demo.example.test/handler/oauth-callback?code=minted-code&state=mirror-handoff-state\";\n const createCrossDomainAuthRedirectUrlSpy = vi\n .spyOn(clientApp as any, \"_createCrossDomainAuthRedirectUrl\")\n .mockResolvedValue(crossDomainAuthorizeRedirect);\n\n // All redirect-back query params were dropped before the after-sign-in redirect.\n windowMock.location.href = `https://${projectId}.built-with-hexclave.com/handler/sign-in`;\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"afterSignIn\");\n\n expect(createCrossDomainAuthRedirectUrlSpy).toHaveBeenCalledWith(expect.objectContaining({\n redirectUri: redirectBackUrl.toString(),\n state: handoffState,\n codeChallenge: handoffCodeChallenge,\n afterCallbackRedirectUrl: handoffAfterCallbackRedirect,\n }));\n expect(redirectUrl).toBe(crossDomainAuthorizeRedirect);\n } finally {\n globalThis.document = previousDocument;\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n } else {\n Reflect.deleteProperty(globalThis, \"window\");\n }\n }\n });\n\n it(\"ignores stale session callbacks after a newer refresh token owns the token store\", async () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000005\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const oldAccessToken = createAccessTokenString(\"old-refresh-token-id\");\n const refreshedOldAccessToken = createAccessTokenString(\"refreshed-old-refresh-token-id\");\n const newAccessToken = createAccessTokenString(\"new-refresh-token-id\");\n const tokenStore = new Store({\n refreshToken: \"old-refresh-token\",\n accessToken: oldAccessToken,\n });\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async () => {\n return AccessToken.createIfValid(refreshedOldAccessToken) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n\n try {\n const getSessionFromTokenStore = Reflect.get(clientApp, \"_getSessionFromTokenStore\");\n if (typeof getSessionFromTokenStore !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _getSessionFromTokenStore in tests.\");\n }\n const oldSession = getSessionFromTokenStore.call(clientApp, tokenStore);\n tokenStore.set({\n refreshToken: \"new-refresh-token\",\n accessToken: newAccessToken,\n });\n\n await oldSession.fetchNewTokens();\n expect(tokenStore.get()).toEqual({\n refreshToken: \"new-refresh-token\",\n accessToken: newAccessToken,\n });\n\n oldSession.markInvalid();\n expect(tokenStore.get()).toEqual({\n refreshToken: \"new-refresh-token\",\n accessToken: newAccessToken,\n });\n } finally {\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n }\n });\n});\n"],"mappings":";;;;;;;;AAeA,SAAS,wBAAwB,gBAAgC;CAC/D,MAAM,UAAU,UAAmB,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC,CAAC,CAAC,SAAS,WAAW;CAC1F,MAAM,aAAa,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;CAC/C,OAAO;EACL,OAAO;GAAE,KAAK;GAAQ,KAAK;EAAM,CAAC;EAClC,OAAO;GACL,KAAK;GACL,KAAK,aAAa;GAClB,KAAK;GACL,KAAK;GACL,KAAK;GACL,YAAY;GACZ,WAAW;GACX,kBAAkB;GAClB,MAAM;GACN,MAAM;GACN,OAAO;GACP,gBAAgB;GAChB,kBAAkB;GAClB,cAAc;GACd,cAAc;GACd,eAAe;GACf,mBAAmB;GACnB,mBAAmB;EACrB,CA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ACF,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"client-app-impl.cross-domain.test.js","names":["StackClientApp","hexclaveAppInternalsSymbol","AccessToken","Store","vi","HexclaveSetupError","expect"],"sources":["../../../../../src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts"],"sourcesContent":["\n//===========================================\n// THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template\n//===========================================\nimport { describe, expect, it, vi } from \"vitest\";\nimport { AccessToken } from \"@hexclave/shared/dist/sessions\";\nimport { HexclaveSetupError } from \"@hexclave/shared/dist/utils/errors\";\nimport { Store } from \"@hexclave/shared/dist/utils/stores\";\nimport { hexclaveAppInternalsSymbol } from \"../../common\";\nimport { StackClientApp } from \"../interfaces/client-app\";\nimport { planRedirectToHandler } from \"./redirect-page-urls\";\n\n// Every app in this file is constructed with `devTool: false`. The tests install a mock window and document, which makes\n// the SDK believe it is in a browser; mounting the dev tool would then start background requests against a backend that\n// does not exist here and leak that work across test cases.\nfunction createAccessTokenString(refreshTokenId: string): string {\n const encode = (value: unknown) => Buffer.from(JSON.stringify(value)).toString(\"base64url\");\n const nowSeconds = Math.floor(Date.now() / 1000);\n return [\n encode({ alg: \"none\", typ: \"JWT\" }),\n encode({\n sub: \"user-id\",\n exp: nowSeconds + 60,\n iat: nowSeconds,\n iss: \"https://api.example.test\",\n aud: \"project-id\",\n project_id: \"project-id\",\n branch_id: \"main\",\n refresh_token_id: refreshTokenId,\n role: \"authenticated\",\n name: null,\n email: null,\n email_verified: false,\n selected_team_id: null,\n signed_up_at: nowSeconds,\n is_anonymous: false,\n is_restricted: false,\n restricted_reason: null,\n requires_totp_mfa: false,\n }),\n \"\",\n ].join(\".\");\n}\n\nfunction createMockDocument(): Document {\n const cookieJar = new Map<string, string>();\n return {\n get cookie() {\n return [...cookieJar.entries()].map(([key, value]) => `${key}=${value}`).join(\"; \");\n },\n set cookie(str: string) {\n const [nameValue] = str.split(\";\");\n const eqIndex = nameValue.indexOf(\"=\");\n if (eqIndex < 0) return;\n cookieJar.set(nameValue.slice(0, eqIndex).trim(), nameValue.slice(eqIndex + 1).trim());\n },\n createElement: () => ({}),\n } as any;\n}\n\n/**\n * Installs a stand-in for `window` with only the parts the code under test touches. `globalThis.window` is typed as a\n * full `Window`, which a hand-written stub can never be, so the assignment goes through `Reflect.set` — the stub's own\n * shape stays checked, unlike with a cast on the object literal.\n */\nfunction setMockWindow(mockWindow: {\n location: { href: string, replace?: (url: string) => void },\n}): void {\n Reflect.set(globalThis, \"window\", mockWindow);\n}\n\n/**\n * Calls one of the app's `protected` methods, which are part of the flows under test but not of the public SDK surface.\n */\nfunction callProtectedMethod(app: StackClientApp<true>, methodName: string, ...args: unknown[]): Promise<unknown> {\n const method = Reflect.get(app, methodName);\n if (typeof method !== \"function\") {\n throw new Error(`Expected StackClientApp to have a ${methodName} method in tests.`);\n }\n return method.apply(app, args);\n}\n\ndescribe(\"StackClientApp cross-domain auth\", () => {\n it(\"keeps noRedirectBack same-domain redirects free of redirect-back state\", async () => {\n const redirectPlan = await planRedirectToHandler({\n handlerName: \"signIn\",\n rawHandlerUrl: \"/handler/sign-in\",\n noRedirectBack: true,\n currentUrl: new URL(\"https://app.example.test/settings?tab=profile\"),\n getLocalOAuthCallbackUrl: () => \"/handler/oauth-callback\",\n rawAfterSignInUrl: \"/home\",\n getCrossDomainHandoffParams: async () => {\n throw new Error(\"Same-domain redirects must not create cross-domain handoff parameters.\");\n },\n });\n\n expect(redirectPlan).toEqual({\n type: \"redirect\",\n url: \"/handler/sign-in\",\n });\n });\n\n it(\"returns noRedirectBack cross-domain auth to the configured after-sign-in page\", async () => {\n const handoffState = \"no-redirect-back-state\";\n const handoffCodeChallenge = \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\";\n const currentUrl = new URL(\"https://app.example.test/settings?tab=profile\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_state\", handoffState);\n currentUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", handoffCodeChallenge);\n currentUrl.searchParams.set(\n \"hexclave_cross_domain_after_callback_redirect_url\",\n \"https://app.example.test/settings?tab=profile\",\n );\n\n const redirectPlan = await planRedirectToHandler({\n handlerName: \"signIn\",\n rawHandlerUrl: \"https://auth.example.test/handler/sign-in\",\n noRedirectBack: true,\n currentUrl,\n getLocalOAuthCallbackUrl: () => \"/handler/oauth-callback\",\n rawAfterSignInUrl: \"/home\",\n getCrossDomainHandoffParams: async () => {\n throw new Error(\"Existing cross-domain handoff parameters must be reused.\");\n },\n });\n\n expect(redirectPlan.type).toBe(\"redirect\");\n if (redirectPlan.type !== \"redirect\") {\n throw new Error(\"Expected noRedirectBack sign-in to produce a redirect URL.\");\n }\n\n const hostedUrl = new URL(redirectPlan.url);\n expect(hostedUrl.origin).toBe(\"https://auth.example.test\");\n expect(hostedUrl.pathname).toBe(\"/handler/sign-in\");\n expect(hostedUrl.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\n \"https://app.example.test/home\",\n );\n\n const rawSourceCallbackUrl = hostedUrl.searchParams.get(\"after_auth_return_to\");\n if (rawSourceCallbackUrl == null) {\n throw new Error(\"Expected cross-domain noRedirectBack to include its internal source callback URL.\");\n }\n const sourceCallbackUrl = new URL(rawSourceCallbackUrl);\n expect(sourceCallbackUrl.origin).toBe(\"https://app.example.test\");\n expect(sourceCallbackUrl.pathname).toBe(\"/handler/oauth-callback\");\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_auth\")).toBe(\"1\");\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_state\")).toBe(handoffState);\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_code_challenge\")).toBe(handoffCodeChallenge);\n expect(sourceCallbackUrl.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\n \"https://app.example.test/home\",\n );\n expect(sourceCallbackUrl.toString()).not.toContain(\"/settings\");\n });\n\n it.each([\"signUp\", \"onboarding\"] as const)(\n \"keeps the source callback when hosted %s uses noRedirectBack\",\n async (handlerName) => {\n const currentUrl = new URL(\"https://app.example.test/settings?tab=profile\");\n const redirectPlan = await planRedirectToHandler({\n handlerName,\n rawHandlerUrl: `https://auth.example.test/handler/${handlerName === \"signUp\" ? \"sign-up\" : \"onboarding\"}`,\n noRedirectBack: true,\n currentUrl,\n getLocalOAuthCallbackUrl: () => \"/handler/oauth-callback\",\n rawAfterSignInUrl: \"/signed-in\",\n getCrossDomainHandoffParams: async () => ({\n state: \"no-redirect-back-state\",\n codeChallenge: \"no-redirect-back-code-challenge\",\n }),\n });\n\n expect(redirectPlan.type).toBe(\"redirect\");\n if (redirectPlan.type !== \"redirect\") {\n throw new Error(\"Expected a direct hosted redirect plan.\");\n }\n const hostedUrl = new URL(redirectPlan.url);\n expect(hostedUrl.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\n \"https://app.example.test/signed-in\",\n );\n expect(hostedUrl.searchParams.get(\"after_auth_return_to\")).not.toBeNull();\n },\n );\n\n it(\"exposes redirect-back-aware handler URLs for devtool previews\", async () => {\n const previousWindow = Reflect.get(globalThis, \"window\");\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n Reflect.set(globalThis, \"window\", {\n location: {\n href: \"http://localhost/music?track=1#song\",\n },\n });\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n urls: {\n signIn: \"/handler/sign-in\",\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"signIn\");\n\n const resolved = new URL(redirectUrl, \"http://localhost\");\n expect(resolved.pathname).toBe(\"/handler/sign-in\");\n expect(resolved.searchParams.get(\"after_auth_return_to\")).toBe(\"/music?track=1#song\");\n } finally {\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n } else {\n Reflect.deleteProperty(globalThis, \"window\");\n }\n }\n });\n\n it(\"rejects hosted sign-in redirects that cannot set the cross-domain verifier cookie\", async () => {\n const previousWindow = Reflect.get(globalThis, \"window\");\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n Reflect.deleteProperty(globalThis, \"window\");\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n await expect(\n clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"signIn\"),\n ).rejects.toThrowError(/Cannot redirect to the cross-origin signIn page from a server-rendered context/);\n } finally {\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n }\n }\n });\n\n it(\"rejects custom cross-origin sign-in redirects on the server too\", async () => {\n const previousWindow = Reflect.get(globalThis, \"window\");\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n Reflect.deleteProperty(globalThis, \"window\");\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n urls: {\n signIn: \"https://auth.example.test/sign-in\",\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n await expect(\n clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"signIn\"),\n ).rejects.toThrowError(/Cannot redirect to the cross-origin signIn page from a server-rendered context/);\n } finally {\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n }\n }\n });\n\n it(\"uses the fresh post-auth refresh token when minting a cross-domain handoff\", async () => {\n const freshAccessToken = createAccessTokenString(\"fresh-refresh-token-id\");\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000000\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: {\n accessToken: createAccessTokenString(\"stale-refresh-token-id\"),\n refreshToken: \"stale-refresh-token\",\n },\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalSendClientRequest = Reflect.get(clientInterface, \"sendClientRequest\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n const capturedRefreshTokens: string[] = [];\n const capturedAccessTokenRefreshTokenIds: string[] = [];\n const refreshedRawRefreshTokens: string[] = [];\n\n Reflect.set(clientInterface, \"sendClientRequest\", async (_path: unknown, _requestOptions: unknown, session: unknown) => {\n const getRefreshToken = Reflect.get(session ?? {}, \"getRefreshToken\");\n const getOrFetchLikelyValidTokens = Reflect.get(session ?? {}, \"getOrFetchLikelyValidTokens\");\n if (typeof getRefreshToken !== \"function\") {\n throw new Error(\"Expected cross-domain auth to pass a session to the client interface.\");\n }\n if (typeof getOrFetchLikelyValidTokens !== \"function\") {\n throw new Error(\"Expected cross-domain auth to pass a session with token accessors.\");\n }\n const refreshToken = getRefreshToken.call(session);\n const refreshTokenString = Reflect.get(refreshToken ?? {}, \"token\");\n if (typeof refreshTokenString !== \"string\") {\n throw new Error(\"Expected cross-domain auth to pass a refresh-token-backed session.\");\n }\n capturedRefreshTokens.push(refreshTokenString);\n const tokens = await getOrFetchLikelyValidTokens.call(session, 0, null);\n capturedAccessTokenRefreshTokenIds.push(tokens.accessToken.payload.refresh_token_id);\n return {\n ok: true,\n json: async () => ({ redirect_url: \"https://example.com/handler/oauth-callback?code=handoff-code&state=handoff-state\" }),\n };\n });\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async (refreshToken: unknown) => {\n const refreshTokenString = Reflect.get(refreshToken ?? {}, \"token\");\n if (typeof refreshTokenString !== \"string\") {\n throw new Error(\"Expected refresh token while fetching a new access token.\");\n }\n refreshedRawRefreshTokens.push(refreshTokenString);\n return AccessToken.createIfValid(freshAccessToken) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n\n try {\n const createCrossDomainAuthRedirectUrl = Reflect.get(clientApp, \"_createCrossDomainAuthRedirectUrl\");\n if (typeof createCrossDomainAuthRedirectUrl !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _createCrossDomainAuthRedirectUrl in tests.\");\n }\n\n await expect(createCrossDomainAuthRedirectUrl.call(clientApp, {\n redirectUri: \"https://example.com/handler/oauth-callback\",\n state: \"handoff-state\",\n codeChallenge: \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\",\n afterCallbackRedirectUrl: \"https://example.com/account-settings\",\n overrideTokenStoreInit: {\n accessToken: createAccessTokenString(\"fresh-stale-refresh-token-id\"),\n refreshToken: \"fresh-refresh-token\",\n },\n })).resolves.toBe(\"https://example.com/handler/oauth-callback?code=handoff-code&state=handoff-state\");\n } finally {\n Reflect.set(clientInterface, \"sendClientRequest\", originalSendClientRequest);\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n }\n\n expect(refreshedRawRefreshTokens).toEqual([\"fresh-refresh-token\"]);\n expect(capturedRefreshTokens).toEqual([\"fresh-refresh-token\"]);\n expect(capturedAccessTokenRefreshTokenIds).toEqual([\"fresh-refresh-token-id\"]);\n });\n\n it(\"uses a fresh nested OAuth state while preserving the outer cross-domain return state\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000002\";\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const outerState = \"outer-cross-domain-state\";\n const outerCodeChallenge = \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\";\n const currentUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n currentUrl.searchParams.set(\"after_auth_return_to\", `https://demo.stack-auth.com/?hexclave_cross_domain_auth=1&hexclave_cross_domain_state=${outerState}`);\n currentUrl.searchParams.set(\"hexclave_cross_domain_state\", outerState);\n currentUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", outerCodeChallenge);\n currentUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", \"https://demo.stack-auth.com/\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-session\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_callback_url\", \"https://demo.stack-auth.com/\");\n\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n let redirectedUrl = \"\";\n vi.spyOn(clientApp as any, \"_fetchCurrentRefreshTokenIdIfSignedIn\").mockResolvedValue(null);\n vi.spyOn(clientApp as any, \"_getCrossDomainHandoffParamsForRedirect\").mockResolvedValue({\n state: \"fresh-nested-state\",\n codeChallenge: \"fresh-nested-code-challenge\",\n });\n vi.spyOn(clientApp as any, \"_isTrusted\").mockResolvedValue(true);\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: currentUrl.toString(),\n replace: (url: string) => {\n redirectedUrl = url;\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n try {\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n const redirectUrl = new URL(redirectedUrl);\n expect(redirectUrl.searchParams.get(\"state\")).toBe(\"fresh-nested-state\");\n expect(redirectUrl.searchParams.get(\"code_challenge\")).toBe(\"fresh-nested-code-challenge\");\n const redirectUri = new URL(redirectUrl.searchParams.get(\"redirect_uri\") ?? \"\");\n expect(redirectUri.searchParams.get(\"hexclave_cross_domain_state\")).toBe(outerState);\n expect(redirectUri.searchParams.get(\"hexclave_cross_domain_code_challenge\")).toBe(outerCodeChallenge);\n expect(redirectUri.searchParams.get(\"hexclave_cross_domain_after_callback_redirect_url\")).toBe(\"https://demo.stack-auth.com/\");\n });\n\n it(\"clears a stale target-domain session before deferring to the source-domain session\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000006\";\n const hostedAccessToken = createAccessTokenString(\"hosted-old-refresh-token-id\");\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const tokenStore = Reflect.get(clientApp, \"_memoryTokenStore\");\n if (!(tokenStore instanceof Store)) {\n throw new Error(\"Expected StackClientApp to use a memory token store in this test.\");\n }\n tokenStore.set({\n refreshToken: \"hosted-old-refresh-token\",\n accessToken: hostedAccessToken,\n });\n\n const currentUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-anonymous-refresh-token-id\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_callback_url\", \"https://demo.stack-auth.com/handler/oauth-callback\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_state\", \"outer-state\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", \"outer-code-challenge\");\n currentUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", \"https://demo.stack-auth.com/app\");\n\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n let redirectedUrl = \"\";\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async () => {\n return AccessToken.createIfValid(hostedAccessToken) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n vi.spyOn(clientApp as any, \"_isTrusted\").mockResolvedValue(true);\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: currentUrl.toString(),\n replace: (url: string) => {\n redirectedUrl = url;\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n try {\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n } finally {\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n expect(tokenStore.get()).toEqual({\n refreshToken: null,\n accessToken: null,\n });\n expect(new URL(redirectedUrl).origin).toBe(\"https://demo.stack-auth.com\");\n });\n\n it(\"uses the latest browser refresh cookie before computing nested cross-domain session IDs\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000007\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: \"https://demo.stack-auth.com/\",\n protocol: \"https:\",\n hostname: \"demo.stack-auth.com\",\n },\n addEventListener: () => {},\n removeEventListener: () => {},\n } as any;\n\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"cookie\",\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n const refreshedRawRefreshTokens: string[] = [];\n\n // Cookie-store writes queue a background trusted-parent-domain lookup. Without this stub, that\n // lookup fetches the (unreachable) baseUrl with retries while holding the global store lock,\n // which starves any later test that needs the write lock (e.g. signOut). Not restored on\n // purpose: queued tasks can still run after this test body finishes.\n vi.spyOn(clientApp as any, \"_getTrustedParentDomain\").mockResolvedValue(null);\n\n try {\n const getBrowserCookieTokenStore = Reflect.get(clientApp, \"_getBrowserCookieTokenStore\");\n if (typeof getBrowserCookieTokenStore !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _getBrowserCookieTokenStore in tests.\");\n }\n const tokenStore = getBrowserCookieTokenStore.call(clientApp);\n tokenStore.set({\n refreshToken: \"old-refresh-token\",\n accessToken: createAccessTokenString(\"old-refresh-token-id\"),\n });\n\n document.cookie = `__Host-hexclave-refresh-${projectId}--default=${JSON.stringify({\n refresh_token: \"new-refresh-token\",\n updated_at_millis: 1,\n })}`;\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async (refreshToken: unknown) => {\n const refreshTokenString = Reflect.get(refreshToken ?? {}, \"token\");\n if (typeof refreshTokenString !== \"string\") {\n throw new Error(\"Expected refresh token while fetching a new access token.\");\n }\n refreshedRawRefreshTokens.push(refreshTokenString);\n return AccessToken.createIfValid(createAccessTokenString(\"new-refresh-token-id\")) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n\n const fetchCurrentRefreshTokenIdIfSignedIn = Reflect.get(clientApp, \"_fetchCurrentRefreshTokenIdIfSignedIn\");\n if (typeof fetchCurrentRefreshTokenIdIfSignedIn !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _fetchCurrentRefreshTokenIdIfSignedIn in tests.\");\n }\n await expect(fetchCurrentRefreshTokenIdIfSignedIn.call(clientApp, {\n awaitPendingAuthResolutions: false,\n })).resolves.toBe(\"new-refresh-token-id\");\n } finally {\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n expect(refreshedRawRefreshTokens).toEqual([\"new-refresh-token\"]);\n });\n\n it(\"stops polling the browser cookie store when browser globals are removed\", () => {\n vi.useFakeTimers();\n const clearIntervalSpy = vi.spyOn(globalThis, \"clearInterval\");\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: \"https://demo.stack-auth.com/\",\n protocol: \"https:\",\n hostname: \"demo.stack-auth.com\",\n },\n addEventListener: () => {},\n removeEventListener: () => {},\n } as any;\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000007\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"cookie\",\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n automaticSideEffects: false,\n devTool: false,\n });\n const getBrowserCookieTokenStore = Reflect.get(clientApp, \"_getBrowserCookieTokenStore\");\n if (typeof getBrowserCookieTokenStore !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _getBrowserCookieTokenStore in tests.\");\n }\n getBrowserCookieTokenStore.call(clientApp);\n\n Reflect.set(globalThis, \"window\", previousWindow);\n Reflect.set(globalThis, \"document\", previousDocument);\n\n expect(() => vi.advanceTimersByTime(100)).not.toThrow();\n expect(clearIntervalSpy).toHaveBeenCalledOnce();\n } finally {\n Reflect.set(globalThis, \"window\", previousWindow);\n Reflect.set(globalThis, \"document\", previousDocument);\n clearIntervalSpy.mockRestore();\n vi.useRealTimers();\n }\n });\n\n it(\"does not re-bounce nested cross-domain auth after the OAuth callback consumed code+state from the URL\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000008\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n const strippedUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n strippedUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-refresh-token-id\");\n strippedUrl.searchParams.set(\"stack_nested_cross_domain_auth_callback_url\", \"https://demo.stack-auth.com/\");\n const urlAtConstructionTime = new URL(strippedUrl);\n urlAtConstructionTime.searchParams.set(\"code\", \"one-time-code\");\n urlAtConstructionTime.searchParams.set(\"state\", \"nested-oauth-state\");\n\n // Construct before installing the window mock so the constructor does not schedule its own\n // nested-auth resolution; the assertions below drive the handler explicitly.\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: strippedUrl.toString(),\n replace: () => {\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n vi.spyOn(clientApp as any, \"_fetchCurrentRefreshTokenIdIfSignedIn\").mockResolvedValue(null);\n vi.spyOn(clientApp as any, \"_getCrossDomainHandoffParamsForRedirect\").mockResolvedValue({\n state: \"fresh-nested-state\",\n codeChallenge: \"fresh-nested-code-challenge\",\n });\n vi.spyOn(clientApp as any, \"_isTrusted\").mockResolvedValue(true);\n\n try {\n // Without the construction-time URL, the handler re-bounces (location.replace aborts).\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n // With it, the in-flight OAuth callback wins and the handler stands down.\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth(urlAtConstructionTime)).resolves.toBe(false);\n // The live-URL guard must also stand down on its own when code+state are still present.\n (globalThis.window as any).location.href = urlAtConstructionTime.toString();\n await expect((clientApp as any)._maybeHandleNestedCrossDomainAuth()).resolves.toBe(false);\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"reports malformed nested cross-domain auth URLs as setup errors\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000012\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n globalThis.document = createMockDocument();\n\n // A URL the flow cannot even parse is as fatal as an untrusted one, so it has to reach the developer the same way\n // instead of escaping as a bare TypeError from `new URL()`, which the overlay only shows during development.\n // The two branches of the handler want opposite session states: on the provider side (a.com) a query-derived failure\n // only becomes a setup error when the handoff belongs to the current session, while the requesting side (b.com) only\n // bounces when the current session is *not* the one that was asked for.\n const malformedCases = [\n {\n description: \"redirect URI\",\n currentRefreshTokenId: \"source-refresh-token-id\",\n params: { redirect_uri: \"not-a-url\", state: \"nested-state\", code_challenge: \"nested-code-challenge\" },\n },\n {\n description: \"after-callback redirect URL\",\n currentRefreshTokenId: \"source-refresh-token-id\",\n params: {\n redirect_uri: \"https://source.example.test/handler/account-settings\",\n state: \"nested-state\",\n code_challenge: \"nested-code-challenge\",\n after_callback_redirect_url: \"http://[\",\n },\n },\n {\n description: \"callback URL\",\n currentRefreshTokenId: null,\n params: { stack_nested_cross_domain_auth_callback_url: \"http://[\" },\n },\n ];\n\n try {\n for (const malformedCase of malformedCases) {\n const currentUrl = new URL(\"https://target.example.test/nested-provider\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-refresh-token-id\");\n for (const [key, value] of Object.entries(malformedCase.params)) {\n currentUrl.searchParams.set(key, value);\n }\n // Each app is constructed with the mock window uninstalled: the constructor's automatic side effects expect a\n // real window, and a construction-time nested-auth URL would also schedule a second, unawaited run of the\n // handler that keeps failing in the background and leaks into whichever test runs next.\n globalThis.window = previousWindow;\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n setMockWindow({ location: { href: currentUrl.toString() } });\n Reflect.set(clientApp, \"_fetchCurrentRefreshTokenIdIfSignedIn\", async () => malformedCase.currentRefreshTokenId);\n Reflect.set(clientApp, \"_isTrusted\", async () => true);\n\n const nestedAuthPromise = callProtectedMethod(clientApp, \"_maybeHandleNestedCrossDomainAuth\");\n await expect(nestedAuthPromise).rejects.toThrowError(new RegExp(`${malformedCase.description} .* is not a valid absolute URL`));\n await expect(nestedAuthPromise).rejects.toSatisfy((error: unknown) => HexclaveSetupError.isSetupError(error));\n }\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"keeps nested cross-domain auth failures off the page for a handoff that does not own the session\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000013\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n globalThis.document = createMockDocument();\n\n // Setup errors are shown in production, so a link anybody can craft must not be able to put a card on a healthy\n // app's page: with a refresh-token ID that is not the current session's, every failure below stays an ordinary error\n // that only captureError sees, even though the same URL from the right session would render a card.\n const craftedRedirectUris = [\n \"https://evil.example.test/handler/account-settings\", // untrusted\n \"not-a-url\", // malformed\n ];\n\n try {\n for (const craftedRedirectUri of craftedRedirectUris) {\n const currentUrl = new URL(\"https://target.example.test/nested-provider\");\n currentUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"attacker-chosen-refresh-token-id\");\n currentUrl.searchParams.set(\"redirect_uri\", craftedRedirectUri);\n currentUrl.searchParams.set(\"state\", \"nested-state\");\n currentUrl.searchParams.set(\"code_challenge\", \"nested-code-challenge\");\n\n globalThis.window = previousWindow;\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n setMockWindow({ location: { href: currentUrl.toString() } });\n Reflect.set(clientApp, \"_fetchCurrentRefreshTokenIdIfSignedIn\", async () => \"this-apps-refresh-token-id\");\n Reflect.set(clientApp, \"_isTrusted\", async () => false);\n\n const nestedAuthPromise = callProtectedMethod(clientApp, \"_maybeHandleNestedCrossDomainAuth\");\n await expect(nestedAuthPromise).rejects.toThrowError(/does not match the requested refresh token ID/);\n await expect(nestedAuthPromise).rejects.toSatisfy(\n (error: unknown) => !HexclaveSetupError.isSetupError(error),\n );\n }\n } finally {\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"passes the construction-time URL to the nested cross-domain auth handler\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000009\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n\n const callbackUrl = new URL(`https://${projectId}.example-stack-hosted.test/handler/sign-in`);\n callbackUrl.searchParams.set(\"stack_nested_cross_domain_auth_refresh_token_id\", \"source-refresh-token-id\");\n callbackUrl.searchParams.set(\"code\", \"one-time-code\");\n callbackUrl.searchParams.set(\"state\", \"nested-oauth-state\");\n const strippedUrl = new URL(callbackUrl);\n strippedUrl.searchParams.delete(\"code\");\n strippedUrl.searchParams.delete(\"state\");\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: callbackUrl.toString(),\n },\n } as any;\n\n const nestedAuthSpy = vi.spyOn(StackClientApp.prototype as any, \"_maybeHandleNestedCrossDomainAuth\").mockResolvedValue(false);\n\n try {\n new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n // Simulate consumeOAuthCallbackQueryParams stripping code+state before microtasks run.\n (globalThis.window as any).location.href = strippedUrl.toString();\n await new Promise((resolve) => setTimeout(resolve, 0));\n\n expect(nestedAuthSpy).toHaveBeenCalledTimes(1);\n const urlArgument = nestedAuthSpy.mock.calls[0][0] as URL;\n expect(urlArgument).toBeInstanceOf(URL);\n expect(urlArgument.searchParams.get(\"code\")).toBe(\"one-time-code\");\n expect(urlArgument.searchParams.get(\"state\")).toBe(\"nested-oauth-state\");\n } finally {\n nestedAuthSpy.mockRestore();\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n });\n\n it(\"redirects hosted current-page OAuth callback errors to the hosted error handler during startup\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000010\";\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n const callbackUrl = new URL(\"https://demo.stack-auth.com/dashboard\");\n callbackUrl.searchParams.set(\"errorCode\", \"SIGN_UP_REJECTED\");\n callbackUrl.searchParams.set(\"message\", \"Your sign up was rejected by an administrator's sign-up rule.\");\n callbackUrl.searchParams.set(\"details\", JSON.stringify({\n message: \"Your sign up was rejected by an administrator's sign-up rule.\",\n }));\n callbackUrl.searchParams.set(\"after_auth_return_to\", \"/dashboard\");\n callbackUrl.searchParams.set(\"after_callback_redirect_url\", \"https://customer.example.test/settings?tab=connected-accounts\");\n let currentHref = callbackUrl.toString();\n let redirectedUrl = \"\";\n const redirectSpy = vi.spyOn(StackClientApp.prototype as any, \"_redirectTo\").mockImplementation(async (...args: unknown[]) => {\n const options = args[0] as { url: string | URL };\n redirectedUrl = options.url.toString();\n });\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n get href() {\n return currentHref;\n },\n set href(value: string) {\n currentHref = value;\n },\n origin: callbackUrl.origin,\n },\n history: {\n replaceState: (_state: unknown, _title: string, url: string) => {\n currentHref = new URL(url, currentHref).toString();\n },\n },\n addEventListener: () => {},\n removeEventListener: () => {},\n } as any;\n\n try {\n new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n await new Promise((resolve) => setTimeout(resolve, 0));\n await new Promise((resolve) => setTimeout(resolve, 0));\n } finally {\n redirectSpy.mockRestore();\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n const errorUrl = new URL(redirectedUrl);\n expect(errorUrl.origin).toBe(`https://${projectId}.built-with-hexclave.com`);\n expect(errorUrl.pathname).toBe(\"/handler/error\");\n expect(errorUrl.searchParams.get(\"errorCode\")).toBe(\"SIGN_UP_REJECTED\");\n expect(errorUrl.searchParams.get(\"message\")).toBe(\"Your sign up was rejected by an administrator's sign-up rule.\");\n expect(errorUrl.searchParams.get(\"after_auth_return_to\")).toBe(\"/dashboard\");\n expect(errorUrl.searchParams.get(\"after_callback_redirect_url\")).toBe(\"https://customer.example.test/settings?tab=connected-accounts\");\n expect(new URL(currentHref).searchParams.has(\"errorCode\")).toBe(false);\n });\n\n it(\"uses direct sign-out instead of hosted sign-out redirects when code execution is available\", async () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000003\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n handler: \"/handler\",\n signOut: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const signOutSpy = vi.spyOn(clientApp, \"signOut\").mockRejectedValue(new Error(\"INTENTIONAL_TEST_ABORT\"));\n\n try {\n await expect(clientApp.redirectToSignOut()).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n expect(signOutSpy).toHaveBeenCalledWith();\n } finally {\n signOutSpy.mockRestore();\n }\n });\n\n it(\"throws when public app.urls reads would return hosted component URLs\", () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000003\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n expect(() => clientApp.urls.signIn).toThrowError(/app\\.urls\\.signIn cannot be used when this app is configured to use hosted components.*Use app\\.redirectToSignIn\\(\\) instead/s);\n expect(() => clientApp.urls.signOut).toThrowError(/app\\.urls\\.signOut cannot be used when this app is configured to use hosted components.*Use app\\.redirectToSignOut\\(\\) instead/s);\n expect(clientApp.urls.afterSignIn).toBe(\"/\");\n });\n\n it(\"keeps public app.urls reads available for non-hosted targets\", () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000003\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n handler: \"/custom-handler\",\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n expect(clientApp.urls.signIn).toBe(\"/custom-handler/sign-in\");\n });\n\n it(\"keeps default hosted signOut() on the source domain when afterSignOut is not configured\", async () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000004\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n urls: {\n default: { type: \"hosted\" },\n },\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const currentHref = \"https://demo.stack-auth.com/settings?tab=profile\";\n\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalSignOut = Reflect.get(clientInterface, \"signOut\");\n Reflect.set(clientInterface, \"signOut\", async () => {});\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n let redirectedUrl = \"\";\n\n globalThis.document = createMockDocument();\n globalThis.window = {\n location: {\n href: currentHref,\n replace: (url: string) => {\n redirectedUrl = url;\n throw new Error(\"INTENTIONAL_TEST_ABORT\");\n },\n },\n } as any;\n\n try {\n const signOut = Reflect.get(clientApp, \"_signOut\");\n if (typeof signOut !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _signOut in tests.\");\n }\n await expect(signOut.call(clientApp, Reflect.get(clientInterface, \"createSession\").call(clientInterface, {\n refreshToken: null,\n }))).rejects.toThrowError(\"INTENTIONAL_TEST_ABORT\");\n } finally {\n Reflect.set(clientInterface, \"signOut\", originalSignOut);\n globalThis.window = previousWindow;\n globalThis.document = previousDocument;\n }\n\n expect(redirectedUrl).toBe(\"/settings?tab=profile\");\n });\n\n it(\"restores a dropped after_auth_return_to from the sessionStorage mirror when redirecting after sign-in\", async () => {\n const previousWindow = globalThis.window;\n const previousDocument = globalThis.document;\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n const sessionStorageMap = new Map<string, string>();\n const windowMock = {\n location: {\n href: \"https://demo.example.test/handler/sign-in?after_auth_return_to=%2Fmusic%3Ftrack%3D1\",\n },\n sessionStorage: {\n getItem: (key: string) => sessionStorageMap.get(key) ?? null,\n setItem: (key: string, value: string) => {\n sessionStorageMap.set(key, value);\n },\n removeItem: (key: string) => {\n sessionStorageMap.delete(key);\n },\n },\n };\n Reflect.set(globalThis, \"window\", windowMock);\n globalThis.document = createMockDocument();\n\n try {\n // The constructor mirrors the redirect-back state from the arrival URL into sessionStorage.\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000011\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n\n // Intermediate hops (MFA, magic link, OAuth round-trips, ...) dropped the query params.\n windowMock.location.href = \"https://demo.example.test/handler/mfa\";\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"afterSignIn\");\n expect(redirectUrl).toBe(\"/music?track=1\");\n\n // noRedirectBack opts out of the mirror just like it opts out of the query param.\n const noRedirectBackUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"afterSignIn\", { noRedirectBack: true });\n expect(new URL(noRedirectBackUrl, \"https://demo.example.test\").pathname).toBe(\"/\");\n } finally {\n globalThis.document = previousDocument;\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n } else {\n Reflect.deleteProperty(globalThis, \"window\");\n }\n }\n });\n\n it(\"restores dropped cross-domain handoff state from the sessionStorage mirror when redirecting after sign-in\", async () => {\n const projectId = \"00000000-0000-4000-8000-000000000012\";\n const previousWindow = globalThis.window;\n const hadPreviousWindow = Reflect.has(globalThis, \"window\");\n const sessionStorageMap = new Map<string, string>();\n\n const handoffState = \"mirror-handoff-state\";\n const handoffCodeChallenge = \"abcdefghijklmnopqrstuvwxyzABCDEFG_0123456789-._~\";\n const handoffAfterCallbackRedirect = \"https://demo.example.test/dashboard\";\n const redirectBackUrl = new URL(\"https://demo.example.test/handler/oauth-callback\");\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_auth\", \"1\");\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_state\", handoffState);\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", handoffCodeChallenge);\n redirectBackUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", handoffAfterCallbackRedirect);\n\n const arrivalUrl = new URL(`https://${projectId}.built-with-hexclave.com/handler/sign-in`);\n arrivalUrl.searchParams.set(\"after_auth_return_to\", redirectBackUrl.toString());\n arrivalUrl.searchParams.set(\"hexclave_cross_domain_state\", handoffState);\n arrivalUrl.searchParams.set(\"hexclave_cross_domain_code_challenge\", handoffCodeChallenge);\n arrivalUrl.searchParams.set(\"hexclave_cross_domain_after_callback_redirect_url\", handoffAfterCallbackRedirect);\n\n const previousDocument = globalThis.document;\n const windowMock = {\n location: {\n href: arrivalUrl.toString(),\n },\n sessionStorage: {\n getItem: (key: string) => sessionStorageMap.get(key) ?? null,\n setItem: (key: string, value: string) => {\n sessionStorageMap.set(key, value);\n },\n removeItem: (key: string) => {\n sessionStorageMap.delete(key);\n },\n },\n };\n Reflect.set(globalThis, \"window\", windowMock);\n globalThis.document = createMockDocument();\n\n try {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId,\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"window\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const crossDomainAuthorizeRedirect = \"https://demo.example.test/handler/oauth-callback?code=minted-code&state=mirror-handoff-state\";\n const createCrossDomainAuthRedirectUrlSpy = vi\n .spyOn(clientApp as any, \"_createCrossDomainAuthRedirectUrl\")\n .mockResolvedValue(crossDomainAuthorizeRedirect);\n\n // All redirect-back query params were dropped before the after-sign-in redirect.\n windowMock.location.href = `https://${projectId}.built-with-hexclave.com/handler/sign-in`;\n\n const redirectUrl = await clientApp[hexclaveAppInternalsSymbol].getRedirectToHandlerUrl(\"afterSignIn\");\n\n expect(createCrossDomainAuthRedirectUrlSpy).toHaveBeenCalledWith(expect.objectContaining({\n redirectUri: redirectBackUrl.toString(),\n state: handoffState,\n codeChallenge: handoffCodeChallenge,\n afterCallbackRedirectUrl: handoffAfterCallbackRedirect,\n }));\n expect(redirectUrl).toBe(crossDomainAuthorizeRedirect);\n } finally {\n globalThis.document = previousDocument;\n if (hadPreviousWindow) {\n Reflect.set(globalThis, \"window\", previousWindow);\n } else {\n Reflect.deleteProperty(globalThis, \"window\");\n }\n }\n });\n\n it(\"ignores stale session callbacks after a newer refresh token owns the token store\", async () => {\n const clientApp = new StackClientApp({\n baseUrl: \"http://localhost:12345\",\n projectId: \"00000000-0000-4000-8000-000000000005\",\n publishableClientKey: \"stack-pk-test\",\n tokenStore: \"memory\",\n redirectMethod: \"none\",\n noAutomaticPrefetch: true,\n devTool: false,\n });\n const oldAccessToken = createAccessTokenString(\"old-refresh-token-id\");\n const refreshedOldAccessToken = createAccessTokenString(\"refreshed-old-refresh-token-id\");\n const newAccessToken = createAccessTokenString(\"new-refresh-token-id\");\n const tokenStore = new Store({\n refreshToken: \"old-refresh-token\",\n accessToken: oldAccessToken,\n });\n const clientInterface = Reflect.get(clientApp, \"_interface\");\n const originalFetchNewAccessToken = Reflect.get(clientInterface, \"fetchNewAccessToken\");\n Reflect.set(clientInterface, \"fetchNewAccessToken\", async () => {\n return AccessToken.createIfValid(refreshedOldAccessToken) ?? (() => {\n throw new Error(\"Expected test access token to be valid\");\n })();\n });\n\n try {\n const getSessionFromTokenStore = Reflect.get(clientApp, \"_getSessionFromTokenStore\");\n if (typeof getSessionFromTokenStore !== \"function\") {\n throw new Error(\"Expected StackClientApp to expose _getSessionFromTokenStore in tests.\");\n }\n const oldSession = getSessionFromTokenStore.call(clientApp, tokenStore);\n tokenStore.set({\n refreshToken: \"new-refresh-token\",\n accessToken: newAccessToken,\n });\n\n await oldSession.fetchNewTokens();\n expect(tokenStore.get()).toEqual({\n refreshToken: \"new-refresh-token\",\n accessToken: newAccessToken,\n });\n\n oldSession.markInvalid();\n expect(tokenStore.get()).toEqual({\n refreshToken: \"new-refresh-token\",\n accessToken: newAccessToken,\n });\n } finally {\n Reflect.set(clientInterface, \"fetchNewAccessToken\", originalFetchNewAccessToken);\n }\n });\n});\n"],"mappings":";;;;;;;;AAeA,SAAS,wBAAwB,gBAAgC;CAC/D,MAAM,UAAU,UAAmB,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC,CAAC,CAAC,SAAS,WAAW;CAC1F,MAAM,aAAa,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;CAC/C,OAAO;EACL,OAAO;GAAE,KAAK;GAAQ,KAAK;EAAM,CAAC;EAClC,OAAO;GACL,KAAK;GACL,KAAK,aAAa;GAClB,KAAK;GACL,KAAK;GACL,KAAK;GACL,YAAY;GACZ,WAAW;GACX,kBAAkB;GAClB,MAAM;GACN,MAAM;GACN,OAAO;GACP,gBAAgB;GAChB,kBAAkB;GAClB,cAAc;GACd,cAAc;GACd,eAAe;GACf,mBAAmB;GACnB,mBAAmB;EACrB,CAAC;EACD;CACF,CAAC,CAAC,KAAK,GAAG;AACZ;AAEA,SAAS,qBAA+B;CACtC,MAAM,4BAAY,IAAI,IAAoB;CAC1C,OAAO;EACL,IAAI,SAAS;GACX,OAAO,CAAC,GAAG,UAAU,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,KAAK,IAAI;EACpF;EACA,IAAI,OAAO,KAAa;GACtB,MAAM,CAAC,aAAa,IAAI,MAAM,GAAG;GACjC,MAAM,UAAU,UAAU,QAAQ,GAAG;GACrC,IAAI,UAAU,GAAG;GACjB,UAAU,IAAI,UAAU,MAAM,GAAG,OAAO,CAAC,CAAC,KAAK,GAAG,UAAU,MAAM,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC;EACvF;EACA,sBAAsB,CAAC;CACzB;AACF;;;;;;AAOA,SAAS,cAAc,YAEd;CACP,QAAQ,IAAI,YAAY,UAAU,UAAU;AAC9C;;;;AAKA,SAAS,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MAAM,wCAAwC;GAC1D,EAAA,CAAG;EACL,CAAC;EAED,IAAI;GACF,MAAM,2BAA2B,QAAQ,IAAI,WAAW,2BAA2B;GACnF,IAAI,OAAO,6BAA6B,YACtC,MAAM,IAAI,MAAM,uEAAuE;GAEzF,MAAM,aAAa,yBAAyB,KAAK,WAAW,UAAU;GACtE,WAAW,IAAI;IACb,cAAc;IACd,aAAa;GACf,CAAC;GAED,MAAM,WAAW,eAAe;GAChC,CAAA,GAAA,OAAA,OAAA,CAAO,WAAW,IAAI,CAAC,CAAC,CAAC,QAAQ;IAC/B,cAAc;IACd,aAAa;GACf,CAAC;GAED,WAAW,YAAY;GACvB,CAAA,GAAA,OAAA,OAAA,CAAO,WAAW,IAAI,CAAC,CAAC,CAAC,QAAQ;IAC/B,cAAc;IACd,aAAa;GACf,CAAC;EACH,UAAU;GACR,QAAQ,IAAI,iBAAiB,uBAAuB,2BAA2B;EACjF;CACF,CAAC;AACH,CAAC"}
@@ -1,2 +1,2 @@
1
- import { i as stripBrowserActionQueryParam, r as _HexclaveClientAppImplIncomplete } from "../../../../admin-app-impl-CMKoG26j.js";
1
+ import { i as stripBrowserActionQueryParam, r as _HexclaveClientAppImplIncomplete } from "../../../../admin-app-impl-BmZQrPYN.js";
2
2
  export { _HexclaveClientAppImplIncomplete, stripBrowserActionQueryParam };
@@ -21,11 +21,11 @@ let ______projects_index_js = require("../../projects/index.js");
21
21
  let _hexclave_shared_dist_sessions = require("@hexclave/shared/dist/sessions");
22
22
  let _hexclave_shared_dist_utils_stores = require("@hexclave/shared/dist/utils/stores");
23
23
  let __redirect_page_urls_js = require("./redirect-page-urls.js");
24
+ let _hexclave_shared_dist_utils_browser_action_snippets = require("@hexclave/shared/dist/utils/browser-action-snippets");
24
25
  let _hexclave_shared_dist_utils_compile_time = require("@hexclave/shared/dist/utils/compile-time");
25
26
  let _hexclave_shared_dist_utils_json = require("@hexclave/shared/dist/utils/json");
26
27
  let _hexclave_shared_dist_utils_maps = require("@hexclave/shared/dist/utils/maps");
27
28
  let _hexclave_shared_dist_utils_turnstile_flow = require("@hexclave/shared/dist/utils/turnstile-flow");
28
- let _hexclave_shared_dist_utils_browser_action_snippets = require("@hexclave/shared/dist/utils/browser-action-snippets");
29
29
  let _hexclave_shared_dist_utils_uuids = require("@hexclave/shared/dist/utils/uuids");
30
30
  let _simplewebauthn_browser = require("@simplewebauthn/browser");
31
31
  let cookie = require("cookie");
@@ -37,13 +37,13 @@ let _________auth_js = require("../../../auth.js");
37
37
  let _________cookie_js = require("../../../cookie.js");
38
38
  let ______api_keys_index_js = require("../../api-keys/index.js");
39
39
  let ______contact_channels_index_js = require("../../contact-channels/index.js");
40
+ let ______passkey_rp_id_js = require("../../passkey-rp-id.js");
40
41
  let ______teams_index_js = require("../../teams/index.js");
41
42
  let ______url_targets_js = require("../../url-targets.js");
42
- let __redirect_back_state_js = require("./redirect-back-state.js");
43
- let __redirect_loop_breaker_js = require("./redirect-loop-breaker.js");
44
- let ______passkey_rp_id_js = require("../../passkey-rp-id.js");
45
43
  let ______users_index_js = require("../../users/index.js");
46
44
  let __event_tracker_js = require("./event-tracker.js");
45
+ let __redirect_back_state_js = require("./redirect-back-state.js");
46
+ let __redirect_loop_breaker_js = require("./redirect-loop-breaker.js");
47
47
  let __session_refresh_subscription_js = require("./session-refresh-subscription.js");
48
48
  let __session_replay_js = require("./session-replay.js");
49
49
  let ____________clickmap_index_js = require("../../../../clickmap/index.js");
@@ -104,6 +104,18 @@ function createUntrustedUrlError(options) {
104
104
  }
105
105
  });
106
106
  }
107
+ function createServerCrossOriginRedirectError(options) {
108
+ return new _hexclave_shared_dist_utils_errors.HexclaveSetupError({
109
+ title: "Cross-origin authentication redirects must start in the browser",
110
+ message: `Cannot redirect to the cross-origin ${options.handlerName} page from a server-rendered context.`,
111
+ howToFix: ["Use useUser({ or: \"redirect\" }) in a Client Component so Hexclave can read the current URL and set the PKCE verifier cookie before redirecting.", "For server-side authorization, call getUser() and handle a null result, or use getUser({ or: \"throw\" })."],
112
+ extraData: {
113
+ handlerName: options.handlerName,
114
+ url: options.url,
115
+ projectId: options.projectId
116
+ }
117
+ });
118
+ }
107
119
  function createUntrustedNestedCrossDomainUrlError(options) {
108
120
  return createUntrustedUrlError({
109
121
  message: `Nested cross-domain auth ${options.urlDescription} ${options.url} is not trusted.`,
@@ -202,6 +214,13 @@ function getHeaderValueFromRequestLikeHeaders(headers, name) {
202
214
  async function getServerRequestHost() {
203
215
  return (await _hexclave_sc.headers?.())?.get("host") ?? null;
204
216
  }
217
+ async function isServerRedirectTargetCrossOrigin(url) {
218
+ if ((0, _hexclave_shared_dist_utils_urls.isRelative)(url)) return false;
219
+ const host = await getServerRequestHost();
220
+ if (host == null) return true;
221
+ const protocol = await (0, _________cookie_js.isSecure)() ? "https:" : "http:";
222
+ return new URL(url).origin !== new URL(`${protocol}//${host}`).origin;
223
+ }
205
224
  var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
206
225
  static {
207
226
  this.LazyStackAdminAppImpl = { value: void 0 };
@@ -2362,6 +2381,14 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2362
2381
  const rawHandlerUrl = rawUrls[handlerName];
2363
2382
  if (!rawHandlerUrl) throw new Error(`No URL for handler name ${handlerName}`);
2364
2383
  let currentUrl = isReactServer || typeof window === "undefined" ? null : new URL(window.location.href);
2384
+ if (currentUrl == null && ((0, ______url_targets_js.isHostedHandlerUrlForProject)({
2385
+ url: rawHandlerUrl,
2386
+ projectId: this.projectId
2387
+ }) || await isServerRedirectTargetCrossOrigin(rawHandlerUrl))) throwSetupError(createServerCrossOriginRedirectError({
2388
+ handlerName,
2389
+ url: rawHandlerUrl,
2390
+ projectId: this.projectId
2391
+ }));
2365
2392
  const shouldRestorePersistedRedirectBackState = options?.noRedirectBack !== true && (handlerName === "afterSignIn" || handlerName === "afterSignUp") || handlerName === "forgotPassword" || handlerName === "passwordReset" || handlerName === "signIn" && options?.noRedirectBack === true;
2366
2393
  if (currentUrl != null && shouldRestorePersistedRedirectBackState) currentUrl = (0, __redirect_back_state_js.augmentUrlWithPersistedRedirectBackState)({
2367
2394
  currentUrl,
@@ -2373,7 +2400,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2373
2400
  noRedirectBack: options?.noRedirectBack === true,
2374
2401
  currentUrl,
2375
2402
  getLocalOAuthCallbackUrl: () => this._getLocalOAuthCallbackHandlerUrl(),
2376
- rawHomeUrl: rawUrls.home,
2403
+ rawAfterSignInUrl: rawUrls.afterSignIn,
2377
2404
  getCrossDomainHandoffParams: async (href) => await this._getCrossDomainHandoffParamsForRedirect(href)
2378
2405
  });
2379
2406
  if (plan.type === "cross-domain-authorize") return await this._createCrossDomainAuthRedirectUrl({
@@ -2397,6 +2424,13 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2397
2424
  }));
2398
2425
  return redirectUrl;
2399
2426
  }
2427
+ _isHandlerRedirectBrowserOnly(handlerName) {
2428
+ const rawHandlerUrl = (0, __common_js.getUrls)(this._urlOptions, { projectId: this.projectId })[handlerName];
2429
+ return (0, ______url_targets_js.isHostedHandlerUrlForProject)({
2430
+ url: rawHandlerUrl,
2431
+ projectId: this.projectId
2432
+ }) || !(0, _hexclave_shared_dist_utils_urls.isRelative)(rawHandlerUrl);
2433
+ }
2400
2434
  _redirectToHandlerDuringRender(handlerName, options) {
2401
2435
  return false;
2402
2436
  }
@@ -2544,12 +2578,13 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
2544
2578
  const pendingSignOut = this._pendingSignOut;
2545
2579
  if (pendingSignOut != null) (0, _hexclave_shared_dist_utils_react.use)(pendingSignOut);
2546
2580
  if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) switch (options?.or) {
2547
- case "redirect":
2548
- if (!crud?.is_anonymous && crud?.is_restricted) {
2549
- if (!this._redirectToHandlerDuringRender("onboarding", { replace: true })) (0, _hexclave_shared_dist_utils_promises.runAsynchronously)(this.redirectToOnboarding({ replace: true }));
2550
- } else if (!this._redirectToHandlerDuringRender("signIn", { replace: true })) (0, _hexclave_shared_dist_utils_promises.runAsynchronously)(this.redirectToSignIn({ replace: true }));
2581
+ case "redirect": {
2582
+ const handlerName = !crud?.is_anonymous && crud?.is_restricted ? "onboarding" : "signIn";
2583
+ if (!(0, _hexclave_shared_dist_utils_env.isBrowserLike)() && this._isHandlerRedirectBrowserOnly(handlerName)) (0, ____________utils_react_js.suspendIfSsr)("useUser({ or: \"redirect\" })");
2584
+ if (!this._redirectToHandlerDuringRender(handlerName, { replace: true })) (0, _hexclave_shared_dist_utils_promises.runAsynchronously)(this._redirectToHandler(handlerName, { replace: true }));
2551
2585
  (0, _hexclave_shared_dist_utils_react.suspend)();
2552
2586
  throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError("suspend should never return");
2587
+ }
2553
2588
  case "throw": throw new Error("User is not signed in but useUser was called with { or: 'throw' }");
2554
2589
  case "anonymous":
2555
2590
  (0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {