export interface ObservabilityEvent { event_id: string; app_id: string; session_id: string; visitor_id: string; user_id?: string; user_email?: string; event_type: 'pageview' | 'session_start' | 'session_end' | 'error_frontend' | 'error_backend' | 'error_api' | 'custom'; event_name?: string; timestamp: string; url?: string; page_path?: string; referrer?: string; user_agent?: string; pageview_count?: number; geo?: { country: string; lat?: number; lng?: number; } | null; error?: { message?: string; stack?: string; component?: string; endpoint?: string; severity?: string; status_code?: number; }; properties?: Record; } export interface AnalyticsConfig { flushIntervalMs?: number; maxBufferSize?: number; enabled?: boolean; } export declare class AnalyticsBufferManager { private eventBuffer; private sessionMap; private flushTimer; private sessionCleanupTimer; private isShuttingDown; private isFlushing; private shutdownHandlerRegistered; private db; private schema; private eventCountLastMinute; private lastMinuteReset; private static readonly MAX_EVENTS_PER_MINUTE; private static readonly SESSION_TIMEOUT_MS; private static readonly MAX_STACK_LENGTH; private config; constructor(config?: AnalyticsConfig); /** * Initialize with Drizzle database and schema */ initialize(db: any, schema: any): void; /** * Start timer to cleanup stale sessions (every 5 minutes) */ private startSessionCleanupTimer; /** * Remove sessions older than SESSION_TIMEOUT_MS */ private cleanupStaleSessions; /** * Add event to buffer with rate limiting and validation */ addEvent(event: ObservabilityEvent): void; /** * Validate event has required fields */ private validateEvent; /** * Add multiple events to buffer */ addEvents(events: ObservabilityEvent[]): void; /** * Start the periodic flush timer */ private startFlushTimer; /** * Setup graceful shutdown handler (only once) */ private setupShutdownHandler; /** * Flush buffered events to database (with concurrency protection) */ flush(): Promise<{ analytics: number; errors: number; }>; /** * Process events and aggregate into database */ private processEvents; /** * Extract path from URL */ private extractPath; /** * Upsert analytics daily record (with table existence check) */ private upsertAnalyticsDaily; /** * Limit number of keys in a JSON object to prevent unbounded growth */ private limitJsonKeys; /** * Merge existing analytics with new stats */ private mergeAnalytics; /** * Upsert error record (with table existence check) */ private upsertError; /** * Get current buffer size (for monitoring) */ getBufferSize(): number; /** * Destroy the manager */ destroy(): Promise; } /** * Initialize analytics buffer manager */ export declare function initializeAnalytics(db: any, schema: any, config?: AnalyticsConfig): AnalyticsBufferManager; /** * Get the analytics buffer manager instance */ export declare function getAnalyticsManager(): AnalyticsBufferManager | null; /** * Add events to the analytics buffer */ export declare function trackEvents(events: ObservabilityEvent[]): void; /** * Force flush analytics buffer */ export declare function flushAnalytics(): Promise<{ analytics: number; errors: number; }>; //# sourceMappingURL=analytics.d.ts.map