/** * Turnstile — shared Cloudflare bot-check helpers. * * Originally lived inline in ChatAssistantLit. Extracted so the new * ChatTransport adapter can use the same managed-challenge flow * without duplicating the panel-portal logic. * * Verify-panel is mounted to `document.body` (NOT into the calling * widget's shadow-rooted container). Cloudflare Turnstile crashes * with `Cannot read properties of undefined (reading 'toLowerCase')` * when its host element lives inside a shadow root (verified on * healthmaxxer 2026-05-22 — chat tile inside ``'s open * shadow root). So we portal the host out and position it as a fixed * overlay at the bottom-center of the viewport. * * The panel is ALWAYS mounted (CF needs a DOM target in case it * decides to challenge) but is off-screen by default. For clean * traffic, CF passive-grades silently with * `appearance: 'interaction-only'` — nothing is ever visible. For * flagged sessions, CF's `before-interactive-callback` fires and the * orchestration helper reveals the panel. * * Copy is intentionally generic — customer end-users see this when CF * flags their session, regardless of customer. */ export declare const TURNSTILE_SITEKEY = "0x4AAAAAADSzPbGWxeguF4YJ"; export interface AcquireTurnstileOptions { /** Widget size. `flexible` (default for managed-mode sitekeys). */ size?: 'flexible' | 'normal' | 'compact' | 'invisible'; /** `interaction-only` keeps the widget invisible during passive grading. */ appearance?: 'always' | 'execute' | 'interaction-only'; /** Where to mount the widget. Off-screen host created when omitted. */ host?: HTMLElement; /** Fires when CF decides a challenge is needed — surface "verifying" copy. */ onBeforeInteractive?: () => void; /** Cancels an in-flight acquisition. Required for clean unmount-during-challenge. */ signal?: AbortSignal; } /** * Acquire a Cloudflare Turnstile token. Returns null when: * • TURNSTILE_SITEKEY is empty (Turnstile disabled at build time) * • the script fails to load (customer CSP blocks Cloudflare, etc.) * • the render callback doesn't fire within TURNSTILE_ACQUIRE_TIMEOUT_MS * • Cloudflare returns an error-callback (e.g., rate-limited, bad sitekey) * * Calls `turnstile.remove(widgetId)` on settle so CF's internal widget * registry doesn't leak across re-mounts. * * Exported for tests and for the higher-level acquireTokenWithChallenge * helper below. */ export declare function acquireTurnstileToken(opts?: AcquireTurnstileOptions): Promise; /** * Mount the off-screen verify-panel that hosts the managed Turnstile * widget. Returns the panel element; callers MUST call panel.remove() * when done (the panel is mounted on document.body and won't be * garbage-collected with their widget). */ export declare function renderVerifyPanel(): HTMLElement; /** * Move the verify panel on-screen when CF signals via * `before-interactive-callback` that the checkbox is about to appear. * No-op if the panel was already torn down (race with token resolution). */ export declare function revealVerifyPanel(panel: HTMLElement | null): void; export interface AcquireWithChallengeResult { token: string | null; outcome: 'disabled' | 'silent_succeeded' | 'interactive_succeeded' | 'acquisition_failed'; } /** * Orchestrated acquire: mount the verify panel, ask CF for a token, * reveal the panel if CF decides to challenge interactively, then * clean up regardless of outcome. * * `outcome` is set so callers can distinguish silent-pass from * interactive-pass from failure — useful telemetry for "how many * sessions actually saw the checkbox?". `disabled` means * TURNSTILE_SITEKEY was empty at build time. */ export declare function acquireTokenWithChallenge(options?: { signal?: AbortSignal; }): Promise; export type BotCheckMode = 'off' | 'soft' | 'hard'; /** Test seam: forget cached modes (the cache is per page load). */ export declare function resetBotCheckModeCache(): void; /** * The backend's bot-check mode, read once per backend per page load. * `null` means it could not be read. */ export declare function fetchBotCheckMode(backendUrl: string): Promise; /** * Acquire a bot-check token for a visitor SEND. Call this from the send path * only — never from mount, configure, or a passive stream. * * Resolves `{ token: null, outcome: 'disabled' }` without touching Cloudflare * when the build has no sitekey or the backend reports `off`. */ export declare function acquireBotCheckTokenForSend(backendUrl: string, options?: { signal?: AbortSignal; }): Promise; //# sourceMappingURL=Turnstile.d.ts.map