UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

317 lines โ€ข 9.45 kB
/** * ๐Ÿ”ง UNIFIED Page Analysis Event System * * โœจ MAIN EVENT SYSTEM - Replaces multiple parallel event systems * * Event-driven system where analyzers attach to page load events * and contribute their data to a unified result structure. * * ๐ŸŽฏ CONSOLIDATES: * - AccessibilityChecker event callbacks * - EventDrivenQueue callbacks * - ParallelTestManager events * - Direct callback patterns in bin/audit.js * * ๐Ÿ“‹ BACKWARD COMPATIBILITY: * - Supports all existing callback patterns via adapters * - Maintains existing APIs while using unified backend * * ๐Ÿš€ FEATURES: * - Parallel analyzer execution * - Resource monitoring integration * - Backpressure control integration * - Progress tracking * - Error handling & fallbacks * - State persistence */ import { EventEmitter } from 'events'; import { Page } from 'playwright'; import { AccessibilityResult, TestOptions } from '../../types'; export interface PageAnalysisContext { url: string; page: Page; options: TestOptions; result: PageAnalysisResult; startTime: number; retryCount?: number; maxRetries?: number; sessionId?: string; batchId?: string; priority?: number; memoryUsageMB?: number; cpuUsagePercent?: number; backpressureActive?: boolean; } /** * ๐ŸŽฏ UNIFIED Event Callbacks - Supports ALL existing callback patterns * * This interface consolidates all event patterns from: * - TestOptions.eventCallbacks * - EventDrivenQueueOptions.eventCallbacks * - ParallelTestManager callbacks * - bin/audit.js direct callbacks */ export interface UnifiedEventCallbacks { onUrlAdded?: (url: string, priority?: number) => void; onUrlStarted?: (url: string) => void; onUrlCompleted?: (url: string, result: AccessibilityResult, duration: number) => void; onUrlFailed?: (url: string, error: string, attempts: number) => void; onUrlRetrying?: (url: string, attempts: number) => void; onProgressUpdate?: (stats: ProgressStats) => void; onQueueEmpty?: () => void; onBatchComplete?: (results: PageAnalysisResult[]) => void; onError?: (error: string, context?: any) => void; onResourceWarning?: (usage: number, limit: number, type: 'memory' | 'cpu') => void; onResourceCritical?: (usage: number, limit: number, type: 'memory' | 'cpu') => void; onBackpressureActivated?: (reason: string) => void; onBackpressureDeactivated?: () => void; onGarbageCollection?: (beforeMB: number, afterMB?: number) => void; onAnalyzerStart?: (analyzerName: string, url: string) => void; onAnalyzerComplete?: (analyzerName: string, url: string, result: any) => void; onAnalyzerError?: (analyzerName: string, url: string, error: string) => void; onShortStatus?: (status: string) => void; onSystemMetrics?: (metrics: SystemMetrics) => void; } /** * ๐Ÿ“ˆ Unified progress statistics */ export interface ProgressStats { total: number; pending: number; inProgress: number; completed: number; failed: number; retrying: number; progress: number; averageDuration: number; estimatedTimeRemaining: number; activeWorkers: number; memoryUsage: number; cpuUsage: number; batchId?: string; batchSize?: number; currentBatch?: number; totalBatches?: number; } /** * ๐Ÿš€ System metrics for monitoring */ export interface SystemMetrics { memoryUsageMB: number; heapUsedMB: number; cpuUsagePercent: number; eventLoopDelayMs: number; activeHandles: number; gcCount: number; uptimeSeconds: number; } export interface PageAnalysisResult { url: string; title: string; status: 'success' | 'failed' | 'crashed'; duration: number; accessibility: { passed: boolean; score: number; errors: Array<{ code: string; message: string; type: 'error' | 'warning' | 'notice'; }>; warnings: Array<{ code: string; message: string; type: 'error' | 'warning' | 'notice'; }>; issues: Array<{ code: string; message: string; type: 'error' | 'warning' | 'notice'; selector?: string; context?: string; impact?: string; }>; basicChecks: { imagesWithoutAlt: number; buttonsWithoutLabel: number; headingsCount: number; }; }; performance?: { score: number; grade: string; coreWebVitals: { lcp: number; fcp: number; cls: number; inp: number; ttfb: number; }; timing: { loadTime: number; domContentLoaded: number; renderTime: number; }; }; seo?: { score: number; grade: string; metaTags: { title?: { content: string; length: number; optimal: boolean; }; description?: { content: string; length: number; optimal: boolean; }; keywords?: string[]; openGraph: Record<string, any>; twitterCard: Record<string, any>; }; headings: { h1: string[]; h2: string[]; h3: string[]; issues: string[]; }; images: { total: number; missingAlt: number; emptyAlt: number; }; }; contentWeight?: { score: number; grade: string; totalSize: number; resources: { html: { size: number; }; css: { size: number; files: number; }; javascript: { size: number; files: number; }; images: { size: number; files: number; }; other: { size: number; files: number; }; }; optimizations: string[]; }; mobileFriendliness?: { score: number; grade: string; viewport: { hasViewportMeta: boolean; width?: string; initialScale?: number; }; touchTargets: { tooSmall: number; overlapping: number; }; textReadability: { tooSmall: number; }; contentFit: { horizontalScrolling: boolean; }; }; } /** * ๐ŸŽฏ UNIFIED PAGE ANALYSIS EMITTER - Main Event System * * Replaces multiple parallel event systems with a single, comprehensive solution. * Maintains backward compatibility while providing enhanced features. */ export declare class PageAnalysisEmitter extends EventEmitter { private analyzers; private callbacks; private backpressureController?; private resourceMonitor?; private stats; private systemMetrics; private sessionId; private isInitialized; private options; constructor(options?: Partial<{ enableResourceMonitoring: boolean; enableBackpressure: boolean; maxConcurrent: number; maxRetries: number; retryDelay: number; verbose: boolean; callbacks: UnifiedEventCallbacks; }>); /** * ๐Ÿš€ Initialize the unified event system with integrated monitoring */ initialize(): Promise<void>; /** * ๐Ÿ“‹ Register an analyzer that will run when a page is loaded * * BACKWARD COMPATIBLE: Maintains existing analyzer registration pattern */ registerAnalyzer(name: string, analyzer: AnalyzerFunction): void; /** * ๐ŸŽฏ Set unified event callbacks * * This replaces/consolidates: * - TestOptions.eventCallbacks * - EventDrivenQueueOptions.eventCallbacks * - Direct callback patterns */ setEventCallbacks(callbacks: UnifiedEventCallbacks): void; /** * ๐Ÿ“Š Setup resource monitoring integration */ private setupResourceMonitoring; /** * ๐Ÿƒ Setup backpressure control integration */ private setupBackpressureControl; /** * ๐Ÿ“ˆ Update and emit progress statistics */ private updateProgress; /** * ๐ŸŽฏ Get current progress statistics */ getProgressStats(): ProgressStats; /** * ๐Ÿš€ Get system metrics */ getSystemMetrics(): SystemMetrics; /** * ๐Ÿงช Cleanup resources (enhanced version) */ cleanup(): Promise<void>; /** * ๐ŸŽฏ UNIFIED PAGE ANALYSIS - Enhanced version with all features * * BACKWARD COMPATIBLE: Maintains existing analyzePage signature * ENHANCED: Integrates resource monitoring, backpressure, progress tracking */ analyzePage(url: string, page: Page, options?: TestOptions, contextOptions?: Partial<PageAnalysisContext>): Promise<PageAnalysisResult>; /** * Get list of registered analyzers */ getRegisteredAnalyzers(): string[]; } export type AnalyzerFunction = (context: PageAnalysisContext) => Promise<void>; export declare const accessibilityAnalyzer: AnalyzerFunction; export declare const performanceAnalyzer: AnalyzerFunction; export declare const seoAnalyzer: AnalyzerFunction; //# sourceMappingURL=page-analysis-emitter.d.ts.map