/** * Session management for authenticated crawl sessions. * Detects auth expiry via HTTP status codes and login-page redirects, * then attempts recovery via a token refresh endpoint or re-login flow. * Designed to keep long-running crawls alive without manual intervention. */ import type { Page } from 'playwright'; export interface SessionConfig { loginUrl?: string; email?: string; password?: string; healthCheckUrl?: string; refreshEndpoint?: string; tokenLocalStorageKey?: string; maxRefreshAttempts?: number; } export type SessionEventType = 'HEALTHY' | 'EXPIRY_DETECTED' | 'REFRESH_ATTEMPT' | 'REFRESH_SUCCESS' | 'REFRESH_FAILED' | 'AUTH_FAILURE'; export interface SessionEvent { type: SessionEventType; isoTimestamp: string; url?: string; strategy?: string; attemptCount?: number; } export interface SessionManager { onResponse(url: string, status: number): void; onNavigation(url: string): void; isHealthy(): boolean; needsRefresh(): boolean; markHealthy(isoTimestamp: string): void; refresh(page: Page, isoTimestamp: string): Promise; getEvents(): SessionEvent[]; getStats(): { healthy: boolean; refreshAttempts: number; authFailure: boolean; }; } export declare function createSessionManager(config: SessionConfig): SessionManager; /** * Attaches a Playwright response listener to feed HTTP status codes into the * session manager. Returns a cleanup function to remove the listener. */ export declare function attachSessionWatcher(page: Page, manager: SessionManager): () => void;