/** * @file Performance Reporter * @description Comprehensive performance reporting with multiple output formats, * destinations, and customizable reports. * * Features: * - Multiple report formats (JSON, console, analytics) * - Configurable destinations * - Report aggregation * - Threshold-based alerting * - Historical comparison * - Custom report builders */ /** * Report format */ export type ReportFormat = 'json' | 'console' | 'analytics' | 'custom'; /** * Report destination */ export type ReportDestination = 'console' | 'endpoint' | 'localStorage' | 'callback'; /** * Metric data for reporting */ export interface ReportMetric { name: string; value: number; rating: 'good' | 'needs-improvement' | 'poor'; target?: number; delta?: number; timestamp: number; } /** * Performance report */ export interface PerformanceReport { id: string; timestamp: number; url: string; metrics: ReportMetric[]; score: number; rating: 'good' | 'needs-improvement' | 'poor'; summary: ReportSummary; context: ReportContext; recommendations: string[]; } /** * Report summary */ export interface ReportSummary { totalMetrics: number; goodMetrics: number; poorMetrics: number; needsImprovementMetrics: number; criticalIssues: string[]; } /** * Report context */ export interface ReportContext { userAgent: string; connection?: { effectiveType?: string; downlink?: number; rtt?: number; saveData?: boolean; }; viewport: { width: number; height: number; }; deviceMemory?: number; hardwareConcurrency?: number; sessionId?: string; userId?: string; } /** * Reporter configuration */ export interface PerformanceReporterConfig { /** Enable reporting */ enabled: boolean; /** Report format */ format: ReportFormat; /** Report destination */ destination: ReportDestination; /** Endpoint URL for endpoint destination */ endpointUrl?: string; /** Local storage key */ storageKey?: string; /** Custom callback */ callback?: (report: PerformanceReport) => void | Promise; /** Enable alerting */ alerting: boolean; /** Alert threshold (score below this triggers alert) */ alertThreshold: number; /** Alert callback */ onAlert?: (report: PerformanceReport, issues: string[]) => void; /** Include recommendations */ includeRecommendations: boolean; /** Session ID */ sessionId?: string; /** User ID */ userId?: string; /** Debug mode */ debug: boolean; } /** * Alert rule */ export interface AlertRule { metric: string; condition: 'above' | 'below'; threshold: number; severity: 'warning' | 'critical'; message: string; } /** * Performance reporting manager */ export declare class PerformanceReporter { private config; private alertRules; private reportHistory; private idCounter; constructor(config?: Partial); /** * Generate and send a performance report */ report(metrics: ReportMetric[]): Promise; /** * Add custom alert rule */ addAlertRule(rule: AlertRule): void; /** * Remove alert rule */ removeAlertRule(metric: string): void; /** * Get report history */ getHistory(): PerformanceReport[]; /** * Get latest report */ getLatestReport(): PerformanceReport | null; /** * Clear report history */ clearHistory(): void; /** * Compare two reports */ compareReports(report1: PerformanceReport, report2: PerformanceReport): { improved: string[]; regressed: string[]; unchanged: string[]; scoreDelta: number; }; /** * Generate console report */ generateConsoleReport(report: PerformanceReport): string; private createReport; private calculateScore; private createSummary; private generateRecommendations; private getContext; private checkAlerts; private sendReport; /** * Send performance report to endpoint. * * Note: This method intentionally uses raw fetch/sendBeacon because: * 1. Performance reporting should be independent of the main API client * 2. Uses keepalive/sendBeacon for reliability when page is unloading * 3. Reporting endpoints may be third-party analytics services * * @see {@link @/lib/api/api-client} for application API calls */ private sendToEndpoint; private saveToLocalStorage; private formatReport; private formatValue; private ratingToScore; private scoreToRating; private createEmptyReport; private generateId; private log; } /** * Get or create the global performance reporter */ export declare function getPerformanceReporter(config?: Partial): PerformanceReporter; /** * Reset the reporter instance */ export declare function resetPerformanceReporter(): void;