/** * SMI-645: WebhookHandler - Process incoming GitHub webhook events * * Provides: * - Secure HMAC-SHA256 signature verification * - Event type routing * - SKILL.md change detection * - Integration with WebhookQueue for processing */ import type { SignatureVerificationResult, SkillFileChange } from './WebhookPayload.js'; import type { WebhookQueue } from './WebhookQueue.js'; /** * Webhook handler options */ export interface WebhookHandlerOptions { /** * GitHub webhook secret for signature verification */ secret: string; /** * Queue for processing webhook events */ queue: WebhookQueue; /** * Optional callback when a skill change is detected */ onSkillChange?: (change: SkillFileChange) => void; /** * Optional callback for logging */ onLog?: (level: 'info' | 'warn' | 'error', message: string, data?: unknown) => void; } /** * Result of handling a webhook event */ export interface WebhookHandleResult { /** * Whether the webhook was handled successfully */ success: boolean; /** * Event type that was processed */ eventType: string; /** * Number of skill changes detected (for push events) */ changesDetected: number; /** * Number of items queued for processing */ itemsQueued: number; /** * Error message if processing failed */ error?: string; /** * Message describing what happened */ message: string; } /** * Delivery statistics for monitoring */ export interface DeliveryStats { trackedDeliveries: number; } /** * Webhook handler for GitHub events */ export declare class WebhookHandler { private secret; private queue; private onSkillChange?; private log; /** * Track processed delivery IDs for idempotency * Using a Set for O(1) lookups */ private processedDeliveries; constructor(options: WebhookHandlerOptions); /** * Get delivery tracking statistics */ getDeliveryStats(): DeliveryStats; /** * Verify webhook signature using HMAC-SHA256 * Uses timing-safe comparison to prevent timing attacks */ verifySignature(payload: string, signature: string): SignatureVerificationResult; /** * Handle an incoming webhook event * @param eventType - GitHub event type (push, repository, ping, etc.) * @param payload - Raw JSON payload string * @param signature - X-Hub-Signature-256 header value * @param deliveryId - X-GitHub-Delivery header value (optional, for idempotency) */ handleWebhook(eventType: string, payload: string, signature: string, deliveryId?: string): Promise; /** * Process a parsed webhook event */ private processEvent; /** * Handle push events - detect SKILL.md changes */ private handlePushEvent; /** * Handle repository events - handle deletion/archival */ private handleRepositoryEvent; /** * Calculate priority based on repository metrics */ private calculatePriority; } export default WebhookHandler; //# sourceMappingURL=WebhookHandler.d.ts.map