import { HealthStatus, HealthCheckResult } from '../types'; /** * Health check configuration */ export interface UseApiHealthConfig { /** Health check endpoint (default: /health) */ endpoint?: string; /** Check interval in milliseconds (default: 30000) */ interval?: number; /** Request timeout in milliseconds (default: 5000) */ timeout?: number; /** Number of failures before marking unhealthy (default: 3) */ failureThreshold?: number; /** Number of successes before marking healthy (default: 1) */ successThreshold?: number; /** Enable automatic health checks (default: true) */ autoCheck?: boolean; /** Callback on status change */ onStatusChange?: (status: HealthStatus, previous: HealthStatus) => void; /** Callback on health check complete */ onCheck?: (result: HealthCheckResult) => void; /** Custom health check function */ healthCheckFn?: () => Promise; } /** * Return type for useApiHealth */ export interface UseApiHealthResult { /** Current health status */ status: HealthStatus; /** Whether API is currently healthy */ isHealthy: boolean; /** Whether API is degraded */ isDegraded: boolean; /** Whether API is unhealthy */ isUnhealthy: boolean; /** Last recorded latency in ms */ latency: number | null; /** Average latency over recent checks */ averageLatency: number | null; /** Last check timestamp */ lastCheck: number | null; /** Last check error (if any) */ lastError: string | null; /** Number of consecutive failures */ consecutiveFailures: number; /** Number of consecutive successes */ consecutiveSuccesses: number; /** Whether currently checking */ isChecking: boolean; /** Trigger manual health check */ checkNow: () => Promise; /** Start automatic health checks */ startMonitoring: () => void; /** Stop automatic health checks */ stopMonitoring: () => void; /** Whether monitoring is active */ isMonitoring: boolean; /** Full health check history */ history: HealthCheckResult[]; /** Reset health state */ reset: () => void; } /** * Hook for monitoring API health and connectivity * * @param config - Health check configuration * @returns Health monitoring utilities and status * * @example * ```typescript * // Basic usage * const { status, isHealthy, latency } = useApiHealth(); * * // With configuration * const { status, checkNow, stopMonitoring } = useApiHealth({ * endpoint: '/api/health', * interval: 60000, * failureThreshold: 5, * onStatusChange: (newStatus, oldStatus) => { * if (newStatus === 'unhealthy') { * showErrorToast('API is currently unavailable'); * } * }, * }); * * // Manual checks only * const { checkNow } = useApiHealth({ * autoCheck: false, * }); * ``` */ export declare function useApiHealth(config?: UseApiHealthConfig): UseApiHealthResult; /** * Hook for simple connectivity check * * @example * ```typescript * const isOnline = useApiConnectivity(); * * if (!isOnline) { * return ; * } * ``` */ export declare function useApiConnectivity(): boolean; /** * Hook for network-aware operations * * @example * ```typescript * const { canMakeRequest, waitForConnectivity } = useNetworkAware(); * * const handleSubmit = async () => { * if (!canMakeRequest) { * await waitForConnectivity(); * } * // Proceed with request * }; * ``` */ export declare function useNetworkAware(): { canMakeRequest: boolean; isOnline: boolean; isBrowserOnline: boolean; waitForConnectivity: (timeout?: number) => Promise; }; /** * Hook for monitoring multiple API endpoints * * @example * ```typescript * const services = useMultiApiHealth([ * { name: 'Main API', endpoint: '/health' }, * { name: 'Auth Service', endpoint: '/auth/health' }, * { name: 'File Service', endpoint: '/files/health' }, * ]); * * return ( *
    * {services.map(s => ( *
  • * {s.name}: {s.status} ({s.latency}ms) *
  • * ))} *
* ); * ``` */ export declare function useMultiApiHealth(endpoints: Array<{ name: string; endpoint: string; interval?: number; }>): Array<{ name: string; endpoint: string; status: HealthStatus; latency: number | null; isHealthy: boolean; }>;