import PulseReporter from "./pulse"; import { DeflectExtraArgs } from "./scriptClient"; export interface DeflectConfig { /** The action ID to fetch the script for. */ actionId: string; /** Override URL for the script. For staging/enterprise customers */ scriptUrl?: string; /** Enable/disable automatic warmup/prefetch. Defaults to true. */ prefetch?: boolean; /** Additional query params to append to the JS fetch */ extraArgs?: DeflectExtraArgs; } declare global { interface Window { Deflect: any; } } /** * Instance-based Deflect client. Use `Deflect.createClient()` to create instances. * Each client manages its own actionId, caching, and rate limiting state. */ export declare class DeflectClient { private readonly config; private scriptCache; private isWarmupInProgress; private hasWarmupError; private warmupPromise; private scriptFetchPromise; private pulseReporter; private getTokenPromise; private lastErrorTime; private consecutiveErrorCount; private fetchCountInWindow; private fetchWindowStart; constructor(config: DeflectConfig, pulseReporter?: PulseReporter); /** Get the actionId this client is configured for */ getActionId(): string; private scheduleWarmup; private static resolvePulseConfig; private reportError; private isInErrorCooldown; private isRateLimited; private hasExceededMaxErrors; private recordFetchSuccess; private recordFetchError; private incrementFetchCount; private tryWarmup; private validateActionId; private prefetchNextScript; private fetchScriptOnce; private isTestMode; /** Get a challenge token for this client's actionId */ getToken(): Promise; private getTokenInternal; private executeScript; /** Manually trigger warmup/prefetch */ warmup(): Promise; /** Clear the cached script */ clearCache(): void; /** Reset error state to allow retries */ resetErrorState(): void; /** Get current rate limit and error status for debugging */ getStatus(): { actionId: string; isRateLimited: boolean; isInCooldown: boolean; consecutiveErrors: number; fetchesInWindow: number; canFetch: boolean; }; /** Inject token into a form and submit */ injectToken(event: SubmitEvent): Promise; } declare class Deflect { private config; private scriptCache; private isWarmupInProgress; private hasWarmupError; private warmupPromise; private pulseReporter; private getTokenPromise; private lastErrorTime; private consecutiveErrorCount; private fetchCountInWindow; private fetchWindowStart; constructor(); private initializeGlobalState; private setupAutomaticWarmup; private resolvePulseConfig; private reportError; /** Check if we're in error cooldown period */ private isInErrorCooldown; /** Check if we've exceeded the rate limit */ private isRateLimited; /** Check if we've hit max consecutive errors */ private hasExceededMaxErrors; /** Record a successful fetch - resets error state */ private recordFetchSuccess; /** Record a failed fetch - increments error tracking */ private recordFetchError; /** Increment fetch counter for rate limiting */ private incrementFetchCount; private tryWarmup; private validateActionId; private prefetchNextScript; private isTestMode; configure(params: DeflectConfig): void; getToken(): Promise; private getTokenInternal; private executeScript; warmup(): Promise; clearCache(): void; /** Reset error state to allow retries. Use after fixing configuration issues. */ resetErrorState(): void; /** Get current rate limit and error status for debugging */ getStatus(): { isRateLimited: boolean; isInCooldown: boolean; consecutiveErrors: number; fetchesInWindow: number; canFetch: boolean; }; injectToken(event: SubmitEvent): Promise; /** * Create a new Deflect client instance with its own configuration. * Use this when you need multiple actionIds on the same page. * * @example * const loginClient = Deflect.createClient({ actionId: 'login-form' }); * const signupClient = Deflect.createClient({ actionId: 'signup-form' }); * * // Each client manages its own state * const loginToken = await loginClient.getToken(); * const signupToken = await signupClient.getToken(); */ createClient(config: DeflectConfig): DeflectClient; } declare const DeflectInstance: Deflect; export default DeflectInstance;