UNPKG

hook-engine

Version:

Production-grade webhook engine with comprehensive adapter support, security, reliability, structured logging, and CLI tools.

118 lines (117 loc) 2.99 kB
import { EventEmitter } from 'events'; import { WebhookEvent, BatchWebhookEvent, EventFilter, EventRoute, ProcessingResult, BatchProcessingResult, EventTransformation } from '../types/webhook'; import { WebhookAdapter } from '../types/adapter'; export interface EventProcessorConfig { maxConcurrency?: number; defaultTimeout?: number; enableMetrics?: boolean; enableDeadLetterQueue?: boolean; retryFailedEvents?: boolean; maxRetries?: number; } export interface ProcessingPipeline { id: string; name: string; filters: EventFilter[]; transformations: EventTransformation[]; routes: EventRoute[]; enabled: boolean; priority: number; } export interface TenantConfig { tenantId: string; pipelines: ProcessingPipeline[]; rateLimits?: { eventsPerSecond: number; burstSize: number; windowSize: number; }; allowedSources?: string[]; blockedSources?: string[]; } export declare class EventProcessor extends EventEmitter { private config; private pipelines; private tenantConfigs; private processingQueue; private isProcessing; private metrics; constructor(config?: EventProcessorConfig); /** * Add processing pipeline */ addPipeline(pipeline: ProcessingPipeline): void; /** * Remove processing pipeline */ removePipeline(pipelineId: string): boolean; /** * Add tenant configuration */ addTenantConfig(tenantConfig: TenantConfig): void; /** * Process single event */ processEvent(event: WebhookEvent, adapter?: WebhookAdapter): Promise<ProcessingResult>; /** * Process batch of events */ processBatch(batch: BatchWebhookEvent, adapter?: WebhookAdapter): Promise<BatchProcessingResult>; /** * Get applicable pipelines for event */ private getApplicablePipelines; /** * Apply filters to events */ private applyFilters; /** * Filter events based on criteria */ private filterEvents; /** * Apply transformations to events */ private applyTransformations; /** * Apply single transformation */ private applyTransformation; /** * Apply JavaScript transformation */ private applyJavaScriptTransformation; /** * Get matching routes for event */ private getMatchingRoutes; /** * Execute route */ private executeRoute; /** * Execute destination */ private executeDestination; /** * Validate tenant access */ private validateTenantAccess; /** * Update processing metrics */ private updateMetrics; /** * Get processing metrics */ getMetrics(): { totalProcessed: number; totalFailed: number; averageProcessingTime: number; lastProcessedAt: number; }; /** * Utility: Chunk array into smaller arrays */ private chunkArray; }