@hexclave/next 1.0.76 → 1.0.78
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.
- package/dist/{admin-app-impl-CsH-gVGz.d.ts → admin-app-impl-DAXv7icw.d.ts} +7 -5
- package/dist/admin-app-impl-DAXv7icw.d.ts.map +1 -0
- package/dist/clickmap/clickmap-core.d.ts +1 -1
- package/dist/clickmap/index.d.ts +1 -1
- package/dist/{client-app-BCT5p_70.d.ts → client-app-g3gQ078Q.d.ts} +5 -2
- package/dist/client-app-g3gQ078Q.d.ts.map +1 -0
- package/dist/common-BK_sydxF.d.ts.map +1 -1
- package/dist/components/api-key-dialogs.d.ts +1 -1
- package/dist/components/elements/sidebar-layout.d.ts.map +1 -1
- package/dist/components/elements/sidebar-layout.js +12 -2
- package/dist/components/elements/sidebar-layout.js.map +1 -1
- package/dist/components/selected-team-switcher.d.ts +1 -1
- package/dist/components/team-icon.d.ts +1 -1
- package/dist/components/team-switcher.d.ts +1 -1
- package/dist/components-page/account-settings/payments/payments-page.d.ts +1 -1
- package/dist/components-page/account-settings/teams/leave-team-section.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-api-keys-section.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-display-name-section.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-member-invitation-section.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-member-list-section.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-page.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-profile-image-section.d.ts +1 -1
- package/dist/components-page/account-settings/teams/team-profile-user-section.d.ts +1 -1
- package/dist/components-page/hexclave-handler-client.d.ts +1 -1
- package/dist/components-page/hexclave-handler.d.ts +1 -1
- package/dist/components-page/team-invitation-cache.d.ts +5 -0
- package/dist/components-page/team-invitation-cache.d.ts.map +1 -0
- package/dist/components-page/team-invitation-cache.js +12 -0
- package/dist/components-page/team-invitation-cache.js.map +1 -0
- package/dist/components-page/team-invitation-cache.test.d.ts +1 -0
- package/dist/components-page/team-invitation-cache.test.js +23 -0
- package/dist/components-page/team-invitation-cache.test.js.map +1 -0
- package/dist/components-page/team-invitation.js +8 -7
- package/dist/components-page/team-invitation.js.map +1 -1
- package/dist/dev-tool/dev-tool-core.d.ts +1 -1
- package/dist/dev-tool/index.d.ts +1 -1
- package/dist/esm/components/api-key-dialogs.d.ts +1 -1
- package/dist/esm/components/elements/sidebar-layout.d.ts.map +1 -1
- package/dist/esm/components/elements/sidebar-layout.js +12 -2
- package/dist/esm/components/elements/sidebar-layout.js.map +1 -1
- package/dist/esm/components-page/team-invitation-cache.d.ts +5 -0
- package/dist/esm/components-page/team-invitation-cache.d.ts.map +1 -0
- package/dist/esm/components-page/team-invitation-cache.js +11 -0
- package/dist/esm/components-page/team-invitation-cache.js.map +1 -0
- package/dist/esm/components-page/team-invitation-cache.test.d.ts +1 -0
- package/dist/esm/components-page/team-invitation-cache.test.js +24 -0
- package/dist/esm/components-page/team-invitation-cache.test.js.map +1 -0
- package/dist/esm/components-page/team-invitation.d.ts.map +1 -1
- package/dist/esm/components-page/team-invitation.js +8 -7
- package/dist/esm/components-page/team-invitation.js.map +1 -1
- package/dist/esm/generated/quetzal-translations.d.ts +2 -2
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js +2 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js +30 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +3 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js +94 -21
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.d.ts +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.js +83 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.js.map +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.d.ts +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.js +120 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.js.map +1 -0
- package/dist/esm/lib/hexclave-app/apps/implementations/common.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/common.js +4 -3
- package/dist/esm/lib/hexclave-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/index.d.ts +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/index.js +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
- package/dist/esm/lib/hexclave-app/apps/implementations/server-app-impl.js +1 -1
- package/dist/esm/lib/hexclave-app/session-replays/index.d.ts +2 -1
- package/dist/esm/lib/hexclave-app/session-replays/index.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/teams/index.d.ts +3 -0
- package/dist/esm/lib/hexclave-app/teams/index.d.ts.map +1 -1
- package/dist/esm/lib/hexclave-app/teams/index.js.map +1 -1
- package/dist/esm/utils/monkey-patch.d.ts +7 -0
- package/dist/esm/utils/monkey-patch.d.ts.map +1 -0
- package/dist/esm/utils/monkey-patch.js +20 -0
- package/dist/esm/utils/monkey-patch.js.map +1 -0
- package/dist/esm/utils/react.d.ts +17 -0
- package/dist/esm/utils/react.d.ts.map +1 -0
- package/dist/esm/utils/react.js +60 -0
- package/dist/esm/utils/react.js.map +1 -0
- package/dist/generated/quetzal-translations.d.ts +1 -1
- package/dist/{hexclave-provider-BA97jMlx.d.ts → hexclave-provider-Bh_Bp-8K.d.ts} +3 -3
- package/dist/{hexclave-provider-BA97jMlx.d.ts.map → hexclave-provider-Bh_Bp-8K.d.ts.map} +1 -1
- package/dist/{hooks-CUe5bc3s.d.ts → hooks-DhDTiWnb.d.ts} +2 -2
- package/dist/{hooks-CUe5bc3s.d.ts.map → hooks-DhDTiWnb.d.ts.map} +1 -1
- package/dist/{index-hYjsGKNc.d.ts → index-Cf1wOohp.d.ts} +3 -2
- package/dist/index-Cf1wOohp.d.ts.map +1 -0
- package/dist/{index-CvB7XacB.d.ts → index-DXWuA5Zu.d.ts} +2 -2
- package/dist/{index-CvB7XacB.d.ts.map → index-DXWuA5Zu.d.ts.map} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.d.ts +1 -1
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js +2 -0
- package/dist/lib/hexclave-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js +29 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.d.ts +2 -2
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js +93 -19
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.d.ts +1 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.js +82 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.js.map +1 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.d.ts +1 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.js +119 -0
- package/dist/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.js.map +1 -0
- package/dist/lib/hexclave-app/apps/implementations/common.js +4 -3
- package/dist/lib/hexclave-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/hexclave-app/apps/implementations/index.d.ts +1 -1
- package/dist/lib/hexclave-app/apps/implementations/index.js +1 -1
- package/dist/lib/hexclave-app/apps/implementations/server-app-impl.d.ts +1 -1
- package/dist/lib/hexclave-app/apps/implementations/server-app-impl.js +1 -1
- package/dist/lib/hexclave-app/apps/index.d.ts +1 -1
- package/dist/lib/hexclave-app/apps/interfaces/admin-app.d.ts +2 -2
- package/dist/lib/hexclave-app/apps/interfaces/client-app.d.ts +1 -1
- package/dist/lib/hexclave-app/apps/interfaces/server-app.d.ts +1 -1
- package/dist/lib/hexclave-app/index.d.ts +1 -1
- package/dist/lib/hexclave-app/projects/index.d.ts +1 -1
- package/dist/lib/hexclave-app/session-replays/index.d.ts +1 -1
- package/dist/lib/hexclave-app/teams/index.d.ts +1 -1
- package/dist/lib/hexclave-app/teams/index.js.map +1 -1
- package/dist/lib/hexclave-app/users/index.d.ts +1 -1
- package/dist/lib/hooks.d.ts +1 -1
- package/dist/providers/hexclave-context.d.ts +1 -1
- package/dist/providers/hexclave-provider-client.d.ts +1 -1
- package/dist/providers/hexclave-provider.d.ts +1 -1
- package/dist/providers/translation-provider.d.ts +1 -1
- package/dist/pushed-config-error-overlay/index.d.ts +1 -1
- package/dist/{quetzal-translations-CK45_4Dm.d.ts → quetzal-translations-XeH3zQ9l.d.ts} +3 -3
- package/dist/{quetzal-translations-CK45_4Dm.d.ts.map → quetzal-translations-XeH3zQ9l.d.ts.map} +1 -1
- package/dist/team-invitation-B5Ol7vdd.d.ts.map +1 -1
- package/dist/{translation-provider-DQ3BJepJ.d.ts → translation-provider-WOaZXqAz.d.ts} +2 -2
- package/dist/{translation-provider-DQ3BJepJ.d.ts.map → translation-provider-WOaZXqAz.d.ts.map} +1 -1
- package/dist/utils/monkey-patch.d.ts +7 -0
- package/dist/utils/monkey-patch.d.ts.map +1 -0
- package/dist/utils/monkey-patch.js +23 -0
- package/dist/utils/monkey-patch.js.map +1 -0
- package/dist/utils/react.d.ts +17 -0
- package/dist/utils/react.d.ts.map +1 -0
- package/dist/utils/react.js +63 -0
- package/dist/utils/react.js.map +1 -0
- package/package.json +4 -4
- package/src/components/elements/sidebar-layout.tsx +16 -1
- package/src/components-page/team-invitation-cache.test.ts +25 -0
- package/src/components-page/team-invitation-cache.ts +13 -0
- package/src/components-page/team-invitation.tsx +16 -7
- package/src/lib/hexclave-app/apps/implementations/admin-app-impl.ts +2 -0
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.automatic-side-effects.test.ts +38 -1
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.cross-domain.test.ts +2 -3
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.sign-out.test.ts +96 -0
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.ts +134 -24
- package/src/lib/hexclave-app/apps/implementations/client-app-impl.untrusted-redirect-card.test.ts +146 -0
- package/src/lib/hexclave-app/apps/implementations/common.ts +2 -1
- package/src/lib/hexclave-app/session-replays/index.ts +2 -0
- package/src/lib/hexclave-app/teams/index.ts +3 -0
- package/src/utils/monkey-patch.tsx +31 -0
- package/src/utils/react.tsx +93 -0
- package/dist/admin-app-impl-CsH-gVGz.d.ts.map +0 -1
- package/dist/client-app-BCT5p_70.d.ts.map +0 -1
- package/dist/index-hYjsGKNc.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-app-impl.cross-domain.test.js","names":["StackClientApp","hexclaveAppInternalsSymbol","AccessToken","Store","HexclaveSetupError","vi","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, and mounting the dev tool kicks off a background `getProject()` against a backend\n// that does not exist here. That fetch never settles, and because it runs inside the global store lock, it blocks every\n// later `withWriteLock` caller (`_signOut`, most visibly) for the rest of the test file.\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 localOAuthCallbackUrl: \"/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 localOAuthCallbackUrl: \"/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(\"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(\"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":";;;;;;;;AAgBA,SAAS,wBAAwB,gBAAgC;CAC/D,MAAM,UAAU,UAAmB,OAAO,KAAK,KAAK,UAAU,KAAK,CAAC,CAAC,CAAC,SAAS,WAAW;CAC1F,MAAM,aAAa,KAAK,MAAM,KAAK,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ientApp","hexclaveAppInternalsSymbol","AccessToken","Store","HexclaveSetupError","vi","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 localOAuthCallbackUrl: \"/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 localOAuthCallbackUrl: \"/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(\"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(\"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;CA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,2 @@
|
|
|
1
|
-
import { r as _HexclaveClientAppImplIncomplete } from "../../../../admin-app-impl-
|
|
2
|
-
export { _HexclaveClientAppImplIncomplete };
|
|
1
|
+
import { i as stripBrowserActionQueryParam, r as _HexclaveClientAppImplIncomplete } from "../../../../admin-app-impl-DAXv7icw.js";
|
|
2
|
+
export { _HexclaveClientAppImplIncomplete, stripBrowserActionQueryParam };
|
|
@@ -25,11 +25,13 @@ let _hexclave_shared_dist_utils_compile_time = require("@hexclave/shared/dist/ut
|
|
|
25
25
|
let _hexclave_shared_dist_utils_json = require("@hexclave/shared/dist/utils/json");
|
|
26
26
|
let _hexclave_shared_dist_utils_maps = require("@hexclave/shared/dist/utils/maps");
|
|
27
27
|
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");
|
|
28
29
|
let _hexclave_shared_dist_utils_uuids = require("@hexclave/shared/dist/utils/uuids");
|
|
29
30
|
let _simplewebauthn_browser = require("@simplewebauthn/browser");
|
|
30
31
|
let cookie = require("cookie");
|
|
31
32
|
cookie = require_rolldown_runtime.__toESM(cookie);
|
|
32
33
|
let ____________generated_env_js = require("../../../../generated/env.js");
|
|
34
|
+
let ____________utils_react_js = require("../../../../utils/react.js");
|
|
33
35
|
let ____________utils_url_js = require("../../../../utils/url.js");
|
|
34
36
|
let _________auth_js = require("../../../auth.js");
|
|
35
37
|
let _________cookie_js = require("../../../cookie.js");
|
|
@@ -51,6 +53,21 @@ let ____________setup_error_overlay_index_js = require("../../../../setup-error-
|
|
|
51
53
|
let _hexclave_sc = require("@hexclave/sc");
|
|
52
54
|
_hexclave_sc = require_rolldown_runtime.__toESM(_hexclave_sc);
|
|
53
55
|
//#region src/lib/hexclave-app/apps/implementations/client-app-impl.ts
|
|
56
|
+
function stripBrowserActionQueryParam() {
|
|
57
|
+
let stripAttemptsRemaining = 20;
|
|
58
|
+
const stripActionId = () => {
|
|
59
|
+
const currentUrl = new URL(window.location.href);
|
|
60
|
+
if (currentUrl.searchParams.has(_hexclave_shared_dist_utils_browser_action_snippets.BROWSER_ACTION_QUERY_PARAM)) {
|
|
61
|
+
currentUrl.searchParams.delete(_hexclave_shared_dist_utils_browser_action_snippets.BROWSER_ACTION_QUERY_PARAM);
|
|
62
|
+
window.history.replaceState(window.history.state, "", currentUrl);
|
|
63
|
+
}
|
|
64
|
+
if (stripAttemptsRemaining > 0) {
|
|
65
|
+
stripAttemptsRemaining -= 1;
|
|
66
|
+
window.setTimeout(stripActionId, 0);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
stripActionId();
|
|
70
|
+
}
|
|
54
71
|
let isReactServer = false;
|
|
55
72
|
isReactServer = _hexclave_sc.isReactServer;
|
|
56
73
|
const NextNavigation = (0, _hexclave_shared_dist_utils_compile_time.scrambleDuringCompileTime)(next_navigation);
|
|
@@ -82,7 +99,8 @@ function createUntrustedUrlError(options) {
|
|
|
82
99
|
],
|
|
83
100
|
extraData: {
|
|
84
101
|
url: options.url,
|
|
85
|
-
projectId: options.projectId
|
|
102
|
+
projectId: options.projectId,
|
|
103
|
+
...options.cause === void 0 ? {} : { cause: options.cause }
|
|
86
104
|
}
|
|
87
105
|
});
|
|
88
106
|
}
|
|
@@ -109,6 +127,17 @@ function createMalformedNestedCrossDomainUrlError(options) {
|
|
|
109
127
|
extraData: { url: options.url }
|
|
110
128
|
});
|
|
111
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Setup errors kill the flow they are thrown in, and the code that started that flow routinely catches redirect failures
|
|
132
|
+
* to render its own "please try again" UI (the hosted auth pages do exactly that), which buries the explanation the one
|
|
133
|
+
* person who can act on it never gets to see. Rendering the card at the throw site keeps the error loud regardless of
|
|
134
|
+
* what the caller does with the exception; the overlay only ever shows one card, so a second attempt from, say, the
|
|
135
|
+
* pending-auth-resolution tracker is a no-op.
|
|
136
|
+
*/
|
|
137
|
+
function throwSetupError(error) {
|
|
138
|
+
(0, ____________setup_error_overlay_index_js.showSetupErrorOverlay)(error);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
112
141
|
function getRedirectHelperInstruction(handlerName) {
|
|
113
142
|
if (handlerName === "handler") return "Use a page-specific redirect helper such as app.redirectToSignIn() instead.";
|
|
114
143
|
return `Use app.${`redirectTo${handlerName.slice(0, 1).toUpperCase()}${handlerName.slice(1)}`}() instead.`;
|
|
@@ -262,6 +291,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
262
291
|
this._uniqueIdentifier = void 0;
|
|
263
292
|
this._sessionRecorder = null;
|
|
264
293
|
this._eventTracker = null;
|
|
294
|
+
this._pendingSignOut = null;
|
|
265
295
|
this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
|
|
266
296
|
this._ownedAdminApps = new _hexclave_shared_dist_utils_maps.DependenciesMap();
|
|
267
297
|
this._currentUserCache = (0, __common_js.createCacheBySession)(async (session) => {
|
|
@@ -515,6 +545,19 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
515
545
|
});
|
|
516
546
|
if ((0, _hexclave_shared_dist_utils_env.isBrowserLike)()) {
|
|
517
547
|
const urlAtConstructionTime = new URL(window.location.href);
|
|
548
|
+
const actionId = urlAtConstructionTime.searchParams.get(_hexclave_shared_dist_utils_browser_action_snippets.BROWSER_ACTION_QUERY_PARAM);
|
|
549
|
+
if (actionId != null) {
|
|
550
|
+
stripBrowserActionQueryParam();
|
|
551
|
+
(0, _hexclave_shared_dist_utils_promises.runAsynchronously)(async () => {
|
|
552
|
+
try {
|
|
553
|
+
const result = await this._interface.consumeBrowserAction(actionId, null);
|
|
554
|
+
Reflect.get(globalThis, ["Fun", "ction"].join(""))(result.javascript)();
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (_hexclave_shared.KnownErrors.VerificationCodeAlreadyUsed.isInstance(error) || _hexclave_shared.KnownErrors.VerificationCodeExpired.isInstance(error)) return;
|
|
557
|
+
throw error;
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
}
|
|
518
561
|
this._trackPendingAuthResolution(async () => {
|
|
519
562
|
await this._maybeHandleNestedCrossDomainAuth(urlAtConstructionTime);
|
|
520
563
|
});
|
|
@@ -1091,7 +1134,7 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
1091
1134
|
}
|
|
1092
1135
|
}
|
|
1093
1136
|
_useTokenStore(overrideTokenStoreInit) {
|
|
1094
|
-
(0,
|
|
1137
|
+
(0, ____________utils_react_js.suspendIfSsr)();
|
|
1095
1138
|
const cookieHelper = (0, _________cookie_js.createBrowserCookieHelper)();
|
|
1096
1139
|
return this._getOrCreateTokenStore(cookieHelper, overrideTokenStoreInit);
|
|
1097
1140
|
}
|
|
@@ -2217,17 +2260,32 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
2217
2260
|
async _createCrossDomainAuthRedirectUrl(options) {
|
|
2218
2261
|
const session = await this._getSession(options.overrideTokenStoreInit, { awaitPendingAuthResolutions: options.awaitPendingAuthResolutions });
|
|
2219
2262
|
await session.fetchNewTokens();
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2263
|
+
let response;
|
|
2264
|
+
try {
|
|
2265
|
+
response = await this._interface.sendClientRequest("/auth/oauth/cross-domain/authorize", {
|
|
2266
|
+
method: "POST",
|
|
2267
|
+
headers: { "Content-Type": "application/json" },
|
|
2268
|
+
body: JSON.stringify({
|
|
2269
|
+
redirect_uri: options.redirectUri,
|
|
2270
|
+
state: options.state,
|
|
2271
|
+
code_challenge: options.codeChallenge,
|
|
2272
|
+
code_challenge_method: "S256",
|
|
2273
|
+
after_callback_redirect_url: options.afterCallbackRedirectUrl
|
|
2274
|
+
})
|
|
2275
|
+
}, session);
|
|
2276
|
+
} catch (error) {
|
|
2277
|
+
if (_hexclave_shared.KnownErrors.RedirectUrlNotWhitelisted.isInstance(error)) {
|
|
2278
|
+
const untrustedUrl = error.constructorArgs[0] ?? options.redirectUri;
|
|
2279
|
+
const untrustedUrlObject = (0, _hexclave_shared_dist_utils_urls.createUrlIfValid)(untrustedUrl);
|
|
2280
|
+
throwSetupError(createUntrustedUrlError({
|
|
2281
|
+
message: `Cross-domain auth redirect URL ${untrustedUrlObject == null ? untrustedUrl : `${untrustedUrlObject.origin}${untrustedUrlObject.pathname}`} is not trusted.`,
|
|
2282
|
+
url: untrustedUrl,
|
|
2283
|
+
projectId: this.projectId,
|
|
2284
|
+
cause: error
|
|
2285
|
+
}));
|
|
2286
|
+
}
|
|
2287
|
+
throw error;
|
|
2288
|
+
}
|
|
2231
2289
|
if (!response.ok) {
|
|
2232
2290
|
const responseBody = await response.text();
|
|
2233
2291
|
throw new _hexclave_shared_dist_utils_errors.HexclaveAssertionError(`Cross-domain authorization endpoint failed: ${response.status} ${responseBody}`);
|
|
@@ -2278,11 +2336,11 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
2278
2336
|
} else return (to) => {};
|
|
2279
2337
|
}
|
|
2280
2338
|
async _redirectIfTrusted(url, options) {
|
|
2281
|
-
if (!await this._isTrusted(url))
|
|
2339
|
+
if (!await this._isTrusted(url)) throwSetupError(createUntrustedUrlError({
|
|
2282
2340
|
message: `Redirect URL ${url} is not trusted; should be relative.`,
|
|
2283
2341
|
url,
|
|
2284
2342
|
projectId: this.projectId
|
|
2285
|
-
});
|
|
2343
|
+
}));
|
|
2286
2344
|
return await this._redirectTo({
|
|
2287
2345
|
url,
|
|
2288
2346
|
...options
|
|
@@ -2327,11 +2385,11 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
2327
2385
|
awaitPendingAuthResolutions: internalOptions?.awaitPendingAuthResolutions,
|
|
2328
2386
|
overrideTokenStoreInit: internalOptions?.overrideTokenStoreInit
|
|
2329
2387
|
}) : plan.url;
|
|
2330
|
-
if (!await this._isTrusted(redirectUrl))
|
|
2388
|
+
if (!await this._isTrusted(redirectUrl)) throwSetupError(createUntrustedUrlError({
|
|
2331
2389
|
message: `Redirect URL ${redirectUrl} is not trusted; should be relative.`,
|
|
2332
2390
|
url: redirectUrl,
|
|
2333
2391
|
projectId: this.projectId
|
|
2334
|
-
});
|
|
2392
|
+
}));
|
|
2335
2393
|
return redirectUrl;
|
|
2336
2394
|
}
|
|
2337
2395
|
_redirectToHandlerDuringRender(handlerName, options) {
|
|
@@ -2444,6 +2502,8 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
2444
2502
|
}
|
|
2445
2503
|
async getUser(options) {
|
|
2446
2504
|
if (options?.or === "anonymous" && options.includeRestricted === false) throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
|
|
2505
|
+
const pendingSignOut = this._pendingSignOut;
|
|
2506
|
+
if (pendingSignOut != null) await pendingSignOut;
|
|
2447
2507
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
2448
2508
|
const session = await this._getSession(options?.tokenStore);
|
|
2449
2509
|
let crud = _hexclave_shared_dist_utils_results.Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
@@ -2476,6 +2536,8 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
2476
2536
|
let crud = (0, __common_js.useAsyncCache)(this._currentUserCache, [session], "clientApp.useUser()");
|
|
2477
2537
|
const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
|
|
2478
2538
|
const includeRestricted = options?.includeRestricted === true || includeAnonymous;
|
|
2539
|
+
const pendingSignOut = this._pendingSignOut;
|
|
2540
|
+
if (pendingSignOut != null) (0, _hexclave_shared_dist_utils_react.use)(pendingSignOut);
|
|
2479
2541
|
if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) switch (options?.or) {
|
|
2480
2542
|
case "redirect":
|
|
2481
2543
|
if (!crud?.is_anonymous && crud?.is_restricted) {
|
|
@@ -2876,14 +2938,25 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
2876
2938
|
async _signOut(session, options) {
|
|
2877
2939
|
this._eventTracker?.clearBuffer();
|
|
2878
2940
|
this._sessionRecorder?.clearBuffer();
|
|
2879
|
-
|
|
2941
|
+
const previousSignOut = this._pendingSignOut;
|
|
2942
|
+
const signOutOperation = (async () => {
|
|
2943
|
+
await previousSignOut;
|
|
2880
2944
|
await this._interface.signOut(session);
|
|
2881
2945
|
if (options?.redirectUrl) await this._redirectTo({
|
|
2882
2946
|
url: options.redirectUrl,
|
|
2883
2947
|
replace: true
|
|
2884
2948
|
});
|
|
2885
2949
|
else await this._redirectToDefaultAfterSignOut();
|
|
2886
|
-
});
|
|
2950
|
+
})();
|
|
2951
|
+
const signOutBarrier = (async () => {
|
|
2952
|
+
await _hexclave_shared_dist_utils_results.Result.fromPromise(signOutOperation);
|
|
2953
|
+
})();
|
|
2954
|
+
this._pendingSignOut = signOutBarrier;
|
|
2955
|
+
try {
|
|
2956
|
+
await signOutOperation;
|
|
2957
|
+
} finally {
|
|
2958
|
+
if (this._pendingSignOut === signOutBarrier) this._pendingSignOut = null;
|
|
2959
|
+
}
|
|
2887
2960
|
}
|
|
2888
2961
|
async _redirectToDefaultAfterSignOut() {
|
|
2889
2962
|
if (this._urlOptions.afterSignOut != null) {
|
|
@@ -3093,5 +3166,6 @@ var _HexclaveClientAppImplIncomplete = class _HexclaveClientAppImplIncomplete {
|
|
|
3093
3166
|
};
|
|
3094
3167
|
//#endregion
|
|
3095
3168
|
exports._HexclaveClientAppImplIncomplete = _HexclaveClientAppImplIncomplete;
|
|
3169
|
+
exports.stripBrowserActionQueryParam = stripBrowserActionQueryParam;
|
|
3096
3170
|
|
|
3097
3171
|
//# sourceMappingURL=client-app-impl.js.map
|