import { ErrorContext } from "../middleware/error-handler.js"; export interface ServiceConfig { timeout?: number; retries?: number; retryDelay?: number; circuitBreakerThreshold?: number; circuitBreakerTimeout?: number; } export interface ServiceMetrics { totalRequests: number; successCount: number; errorCount: number; averageResponseTime: number; lastError?: Date; circuitBreakerState: 'CLOSED' | 'OPEN' | 'HALF_OPEN'; } export interface ServiceResponse { success: boolean; data?: T; error?: string; metadata?: { responseTime: number; retryCount?: number; cached?: boolean; }; } export declare abstract class BaseService { protected config: Required; protected metrics: ServiceMetrics; protected circuitBreakerFailureCount: number; protected circuitBreakerLastFailure?: Date; constructor(config?: ServiceConfig); /** * Execute a service operation with retry logic, circuit breaker, and metrics */ protected executeWithResilience(operation: () => Promise, context?: ErrorContext): Promise>; /** * Add timeout to promise */ private withTimeout; /** * Check if operation should not be retried */ private shouldNotRetry; /** * Sleep for specified milliseconds */ private sleep; /** * Update service metrics */ private updateMetrics; /** * Check if circuit breaker should be open */ private isCircuitBreakerOpen; /** * Update circuit breaker state on failure */ private updateCircuitBreaker; /** * Reset circuit breaker on success */ private resetCircuitBreaker; /** * Get service health status */ getHealth(): { status: 'healthy' | 'degraded' | 'unhealthy'; metrics: ServiceMetrics; uptime: number; }; /** * Reset service metrics (useful for testing) */ resetMetrics(): void; /** * Abstract method for service-specific health checks */ abstract healthCheck(): Promise; }