/** * Webhook Trigger * * HTTP-based workflow triggers with authentication, * rate limiting, payload validation, and deduplication. */ import type { WebhookTriggerConfig, TriggerContext, WorkflowTrigger } from '@cogitator-ai/types'; /** * Incoming webhook request */ export interface WebhookRequest { method: string; path: string; headers: Record; body?: unknown; rawBody?: string | Buffer; query?: Record; ip?: string; } /** * Webhook response */ export interface WebhookResponse { status: number; headers?: Record; body?: unknown; } /** * Webhook trigger state */ export interface WebhookTriggerState { triggerId: string; workflowName: string; config: WebhookTriggerConfig; triggerCount: number; errorCount: number; lastTriggered?: number; lastError?: string; enabled: boolean; createdAt: number; } /** * Webhook handler result */ export interface WebhookHandlerResult { triggered: boolean; runId?: string; response: WebhookResponse; } /** * Authentication error */ export declare class WebhookAuthError extends Error { constructor(message: string); } /** * Rate limit error */ export declare class WebhookRateLimitError extends Error { readonly retryAfter: number; readonly remaining: number; readonly resetAt: number; constructor(retryAfter: number, remaining: number, resetAt: number); } /** * Webhook trigger executor */ export declare class WebhookTriggerExecutor { private triggers; private triggersByPath; private rateLimiters; private deduplicationCache; private cleanupInterval?; private onFire?; constructor(options?: { onFire?: (trigger: WorkflowTrigger, context: TriggerContext) => Promise; cleanupIntervalMs?: number; }); /** * Register a webhook trigger */ register(workflowName: string, config: WebhookTriggerConfig, externalId?: string): string; /** * Unregister a trigger */ unregister(triggerId: string): void; /** * Enable a trigger */ enable(triggerId: string): void; /** * Disable a trigger */ disable(triggerId: string): void; /** * Handle an incoming webhook request */ handle(request: WebhookRequest): Promise; /** * Handle a specific trigger */ handleTrigger(state: WebhookTriggerState, request: WebhookRequest): Promise; /** * Get trigger state */ getState(triggerId: string): WebhookTriggerState | undefined; /** * Get all triggers for a workflow */ getTriggersForWorkflow(workflowName: string): WebhookTriggerState[]; /** * Get all enabled triggers */ getEnabledTriggers(): WebhookTriggerState[]; /** * Get all triggers */ getAll(): WebhookTriggerState[]; /** * Get registered paths */ getRegisteredPaths(): { path: string; method: string; triggerId: string; }[]; /** * Dispose the executor */ dispose(): void; private authenticate; private checkRateLimit; private isDuplicate; private cleanupDeduplicationCache; private normalizePathKey; private getClientKey; private timingSafeCompare; private getHeader; private normalizeHeaders; private toWorkflowTrigger; } /** * Create a webhook trigger executor */ export declare function createWebhookTrigger(options?: { onFire?: (trigger: WorkflowTrigger, context: TriggerContext) => Promise; }): WebhookTriggerExecutor; /** * Validate a webhook trigger config */ export declare function validateWebhookTriggerConfig(config: WebhookTriggerConfig): string[]; //# sourceMappingURL=webhook-trigger.d.ts.map