UNPKG

wizinsight

Version:

A lightweight performance monitoring & health tracking library for hyperwiz with Discord alerts and smart request optimization. Track API requests, monitor endpoint health, and get instant alerts when issues arise.

90 lines (85 loc) 2.71 kB
interface RequestMetrics { url: string; method: string; duration: number; status?: number; error?: string; } interface MetricsInterceptorOptions { onRequestStart?: (metrics: RequestMetrics) => void; onRequestEnd?: (metrics: RequestMetrics) => void; onRequestError?: (metrics: RequestMetrics) => void; unhealthyStrategy?: 'skip_body' | 'skip_request' | 'fallback'; fallbackUrl?: string; } interface HyperwizClient { [key: string]: any; } interface HealthTarget { name: string; url: string; method?: string; body?: any; headers?: Record<string, string>; expectedStatus?: number; timeout?: number; } interface HealthStatus { lastChecked: number; lastStatus: number; isHealthy: boolean; lastError?: string; } interface HealthMonitorOptions { targets: HealthTarget[]; interval?: number; discordWebhook?: string; alertCooldown?: number; } interface HealthState { [url: string]: HealthStatus; } /** * Creates a lightweight metrics interceptor for hyperwiz client */ declare function createMetricsInterceptor(options?: MetricsInterceptorOptions): (client: HyperwizClient) => HyperwizClient; /** * Initialize health monitoring */ declare function initHealthMonitor(options: HealthMonitorOptions): void; /** * Get current health status */ declare function getHealthStatus(): HealthState; /** * Stop health monitoring */ declare function stopHealthMonitor(): void; /** * Initialize lightweight metrics interceptor for a hyperwiz client * * @param client - The hyperwiz client instance * @param options - Configuration options for metrics collection * @returns The modified client with metrics interception * * @example * ```ts * import { createClient } from 'hyperwiz' * import { initMetricsInterceptor } from 'wizinsight' * * const client = createClient('https://api.example.com') * * // Basic usage * initMetricsInterceptor(client) * * // With health-based optimization * initMetricsInterceptor(client, { * onRequestStart: (metrics) => console.log('Request started:', metrics), * onRequestEnd: (metrics) => console.log('Request completed:', metrics), * unhealthyStrategy: 'skip_body', // Remove body for unhealthy APIs * fallbackUrl: 'https://backup-api.example.com' * }) * ``` */ declare function initMetricsInterceptor(client: any, options?: MetricsInterceptorOptions): HyperwizClient; export { type HealthMonitorOptions, type HealthState, type HealthStatus, type HealthTarget, type HyperwizClient, type MetricsInterceptorOptions, type RequestMetrics, createMetricsInterceptor, getHealthStatus, initHealthMonitor, initMetricsInterceptor, stopHealthMonitor };