/** * Webhook Service (F-011) * * General-purpose webhook notification system for external integrations. * * Features: * - Multiple endpoint support per tenant * - Event filtering by type, category, domain, severity * - HMAC-SHA256 signature verification * - Retry with exponential backoff * - Delivery tracking and health monitoring * - Circuit breaker pattern for unhealthy endpoints (timestamp-based, restart-resilient) * * Security: * - All payloads signed with HMAC-SHA256 * - Secrets stored securely (not logged) * - Rate limiting for outbound requests * - Idempotency keys prevent duplicate processing * * Current Limitations: * - Retry state is in-memory (pending retries lost on restart) * - For production reliability, consider: * - Persisting retry queue to database * - Using a job queue (e.g., BullMQ, Bee-Queue) * - Loading outstanding jobs on startup * * Note: Circuit breaker uses timestamp-based reset (circuitOpenedAt) rather than * setTimeout, making it resilient to server restarts. */ import { type WebhookEventType, type WebhookPayload, type WebhookEndpoint, type WebhookEndpointInput, type WebhookEndpointUpdate, type WebhookDelivery, type WebhookSendResult, type WebhookTestResult, type WebhookStats } from '../types/webhook.js'; /** * Default configuration for webhook service */ export interface WebhookServiceConfig { maxEndpointsPerTenant?: number; circuitBreakerThreshold?: number; circuitBreakerResetMs?: number; maxDeliveriesPerMinute?: number; defaultMaxRetries?: number; defaultInitialRetryDelayMs?: number; defaultMaxRetryDelayMs?: number; maxDeliveryHistoryPerEndpoint?: number; } export declare class WebhookService { private endpoints; private deliveries; private pendingRetries; private config; constructor(config?: WebhookServiceConfig); /** * Create a new webhook endpoint */ createEndpoint(tenantId: string, input: WebhookEndpointInput): WebhookEndpoint; /** * Update an existing webhook endpoint */ updateEndpoint(tenantId: string, endpointId: string, update: WebhookEndpointUpdate): WebhookEndpoint; /** * Delete a webhook endpoint */ deleteEndpoint(tenantId: string, endpointId: string): boolean; /** * Get a specific endpoint */ getEndpoint(tenantId: string, endpointId: string): WebhookEndpoint | undefined; /** * List all endpoints for a tenant */ listEndpoints(tenantId: string): WebhookEndpoint[]; /** * Enable/disable an endpoint */ setEndpointEnabled(tenantId: string, endpointId: string, enabled: boolean): boolean; /** * Dispatch an event to all matching endpoints */ dispatchEvent(tenantId: string, eventType: WebhookEventType, data: T, metadata?: WebhookPayload['metadata']): Promise; /** * Check if an endpoint should receive an event */ private shouldDeliverToEndpoint; /** * Send payload to a specific endpoint */ private sendToEndpoint; /** * Attempt to deliver a payload */ private attemptDelivery; /** * Schedule a retry delivery */ private scheduleRetry; /** * Calculate retry delay with exponential backoff */ private calculateRetryDelay; /** * Update health after successful delivery */ private updateHealthOnSuccess; /** * Update health after failed delivery */ private updateHealthOnFailure; /** * Generate HMAC-SHA256 signature for payload */ private generateSignature; /** * Verify a webhook signature (for testing endpoints) */ verifySignature(payload: string, signature: string, secret: string): boolean; /** * Send a test event to an endpoint */ testEndpoint(tenantId: string, endpointId: string): Promise; /** * Get delivery history for an endpoint */ getDeliveryHistory(tenantId: string, endpointId: string, limit?: number): WebhookDelivery[]; /** * Get webhook statistics for a tenant */ getStats(tenantId: string, periodHours?: number): WebhookStats; /** * Clear all data for a tenant */ clearTenant(tenantId: string): void; /** * Shutdown the service (cancel all pending retries) */ shutdown(): void; } /** * Create a new WebhookService instance */ export declare function createWebhookService(config?: WebhookServiceConfig): WebhookService; //# sourceMappingURL=webhook-service.d.ts.map