@bernierllc/webhook-processor 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,224 @@
1
+ # @bernierllc/webhook-processor
2
+
3
+ Webhook event processing service with signature validation, retry logic, and event routing.
4
+
5
+ ## Overview
6
+
7
+ The `@bernierllc/webhook-processor` package provides a comprehensive service for processing webhook events from various sources (GitHub, Stripe, etc.). It handles webhook reception, validation, parsing, commit analysis, event routing, retry logic, and persistence.
8
+
9
+ ## Features
10
+
11
+ - **Webhook Reception**: Receive and validate webhooks from multiple sources
12
+ - **Signature Validation**: HMAC-SHA256 signature validation for secure webhooks
13
+ - **GitHub Integration**: Parse GitHub webhooks and analyze commits
14
+ - **Commit Analysis**: Determine if commits are "interesting" for content generation
15
+ - **Event Routing**: Route events to registered handlers based on source and event type
16
+ - **Retry Logic**: Automatic retry for failed webhook processing
17
+ - **Event Persistence**: Optional persistence to Supabase for audit trails
18
+ - **Event Broadcasting**: Emit events via event emitter for distributed systems
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install @bernierllc/webhook-processor
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```typescript
29
+ import { WebhookProcessor, createWebhookProcessor } from '@bernierllc/webhook-processor';
30
+ import type { WebhookRequest } from '@bernierllc/webhook-receiver';
31
+
32
+ // Create processor
33
+ const processor = createWebhookProcessor({
34
+ enableSignatureValidation: true,
35
+ secretKey: process.env.WEBHOOK_SECRET,
36
+ enableRetries: true,
37
+ maxRetries: 3,
38
+ enablePersistence: true,
39
+ supabaseUrl: process.env.SUPABASE_URL,
40
+ supabaseAnonKey: process.env.SUPABASE_ANON_KEY,
41
+ handlers: [
42
+ {
43
+ source: 'github',
44
+ eventType: 'push',
45
+ handler: async (event) => {
46
+ console.log('GitHub push received:', event.payload.id);
47
+ // Process the event
48
+ },
49
+ priority: 10
50
+ }
51
+ ]
52
+ });
53
+
54
+ // Process a webhook request
55
+ const request: WebhookRequest = {
56
+ method: 'POST',
57
+ headers: {
58
+ 'content-type': 'application/json',
59
+ 'x-github-signature': 'sha256=...'
60
+ },
61
+ body: Buffer.from(JSON.stringify(webhookPayload)),
62
+ url: '/webhook/github'
63
+ };
64
+
65
+ const result = await processor.process(request);
66
+
67
+ if (result.success) {
68
+ console.log('Webhook processed:', result.eventId);
69
+ console.log('Handlers executed:', result.processedEvent?.metadata.handlerCount);
70
+ } else {
71
+ console.error('Processing failed:', result.error);
72
+ if (result.retryCount !== undefined) {
73
+ console.log('Will retry at:', result.nextRetryAt);
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## API
79
+
80
+ ### `WebhookProcessor`
81
+
82
+ #### Constructor
83
+
84
+ ```typescript
85
+ new WebhookProcessor(config?: WebhookProcessorConfig)
86
+ ```
87
+
88
+ **Config Options:**
89
+ - `enableSignatureValidation` (optional) - Enable signature validation (default: true)
90
+ - `secretKey` (optional) - Secret key for signature validation
91
+ - `enableRetries` (optional) - Enable retry logic (default: true)
92
+ - `maxRetries` (optional) - Maximum retry attempts (default: 3)
93
+ - `retryDelay` (optional) - Retry delay in milliseconds (default: 1000)
94
+ - `enablePersistence` (optional) - Enable event persistence (default: false)
95
+ - `supabaseUrl` (optional) - Supabase project URL (required if persistence enabled)
96
+ - `supabaseAnonKey` (optional) - Supabase anonymous key (required if persistence enabled)
97
+ - `handlers` (optional) - Array of event handlers to register
98
+
99
+ #### Methods
100
+
101
+ - `registerHandler(handler: WebhookEventHandler): void` - Register an event handler
102
+ - `removeHandler(handler: WebhookEventHandler): void` - Remove an event handler
103
+ - `process(request: WebhookRequest): Promise<ProcessResult>` - Process a webhook request
104
+ - `validateSignature(payload: WebhookPayload): Promise<boolean>` - Validate webhook signature
105
+ - `getStats(): { totalProcessed: number; successCount: number; failureCount: number }` - Get processing statistics
106
+ - `shutdown(): Promise<void>` - Shutdown the processor gracefully
107
+
108
+ ### Event Handlers
109
+
110
+ Event handlers are functions that process webhook events:
111
+
112
+ ```typescript
113
+ interface WebhookEventHandler {
114
+ source: string; // Source to match (e.g., 'github', 'stripe')
115
+ eventType?: string; // Event type to match (e.g., 'push', 'payment.succeeded')
116
+ handler: (event: ProcessedWebhookEvent) => Promise<void>;
117
+ priority?: number; // Priority (higher = executed first)
118
+ }
119
+ ```
120
+
121
+ ## GitHub Webhook Processing
122
+
123
+ The processor automatically handles GitHub webhooks:
124
+
125
+ 1. **Parses** the webhook payload using `@bernierllc/github-parser`
126
+ 2. **Analyzes** commits using `@bernierllc/commit-analyzer` to determine if they're "interesting"
127
+ 3. **Routes** to handlers registered for `source: 'github'` and `eventType: 'push'`
128
+
129
+ ```typescript
130
+ processor.registerHandler({
131
+ source: 'github',
132
+ eventType: 'push',
133
+ handler: async (event) => {
134
+ if (event.commitAnalysis?.interesting) {
135
+ // Generate content from interesting commits
136
+ await generateContentFromCommit(event.parsed?.commits?.[0]);
137
+ }
138
+ }
139
+ });
140
+ ```
141
+
142
+ ## Retry Logic
143
+
144
+ When webhook processing fails, the processor can automatically retry:
145
+
146
+ ```typescript
147
+ const processor = createWebhookProcessor({
148
+ enableRetries: true,
149
+ maxRetries: 3,
150
+ retryDelay: 1000
151
+ });
152
+
153
+ // Failed webhooks are automatically queued for retry
154
+ const result = await processor.process(request);
155
+ if (!result.success && result.retryCount !== undefined) {
156
+ console.log(`Will retry (attempt ${result.retryCount}) at ${result.nextRetryAt}`);
157
+ }
158
+ ```
159
+
160
+ ## Event Persistence
161
+
162
+ Events can be persisted to Supabase for audit trails:
163
+
164
+ ```typescript
165
+ const processor = createWebhookProcessor({
166
+ enablePersistence: true,
167
+ supabaseUrl: process.env.SUPABASE_URL,
168
+ supabaseAnonKey: process.env.SUPABASE_ANON_KEY
169
+ });
170
+ ```
171
+
172
+ The processor expects a `webhook_events` table:
173
+
174
+ ```sql
175
+ CREATE TABLE webhook_events (
176
+ event_id TEXT PRIMARY KEY,
177
+ source TEXT NOT NULL,
178
+ event_type TEXT NOT NULL,
179
+ payload JSONB NOT NULL,
180
+ processed_at TIMESTAMPTZ NOT NULL,
181
+ processing_duration INTEGER,
182
+ handler_count INTEGER,
183
+ success_count INTEGER,
184
+ failure_count INTEGER
185
+ );
186
+ ```
187
+
188
+ ## Integration Status
189
+
190
+ - **Logger**: ✅ Integrated - Uses `@bernierllc/logger` for all logging operations
191
+ - **Docs-Suite**: ✅ Ready - Full TypeDoc API documentation available
192
+ - **NeverHub**: ⚠️ Optional - Can emit webhook events to NeverHub event bus for distributed observability
193
+
194
+ ## Dependencies
195
+
196
+ - `@bernierllc/webhook-receiver` - Webhook reception and validation
197
+ - `@bernierllc/github-parser` - GitHub webhook parsing
198
+ - `@bernierllc/commit-analyzer` - Commit interest analysis
199
+ - `@bernierllc/task-queue-core` - Background task processing for retries
200
+ - `@bernierllc/event-emitter` - Event broadcasting
201
+ - `@bernierllc/supabase-client` - Event persistence (optional)
202
+ - `@bernierllc/logger` - Logging
203
+
204
+ ## Testing
205
+
206
+ Run tests with:
207
+
208
+ ```bash
209
+ npm test
210
+ npm run test:coverage
211
+ ```
212
+
213
+ Target coverage: 85%+ (service package standard)
214
+
215
+ Current coverage: 97.82% statements, 88.67% branches, 92.85% functions, 97.8% lines
216
+
217
+ ## License
218
+
219
+ Copyright (c) 2025 Bernier LLC
220
+
221
+ This file is licensed to the client under a limited-use license.
222
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
223
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
224
+
@@ -0,0 +1,7 @@
1
+ import { WebhookProcessor } from './webhook-processor';
2
+ import type { WebhookProcessorConfig } from './types';
3
+ /**
4
+ * Create a new WebhookProcessor instance
5
+ */
6
+ export declare function createWebhookProcessor(config?: WebhookProcessorConfig): WebhookProcessor;
7
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,CAAC,EAAE,sBAAsB,GAAG,gBAAgB,CAExF"}
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ import { WebhookProcessor } from './webhook-processor';
9
+ /**
10
+ * Create a new WebhookProcessor instance
11
+ */
12
+ export function createWebhookProcessor(config) {
13
+ return new WebhookProcessor(config);
14
+ }
15
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAA+B;IACpE,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { WebhookProcessor } from './webhook-processor';
2
+ export { createWebhookProcessor } from './factory';
3
+ export type { WebhookProcessorConfig, WebhookEventHandler, ProcessedWebhookEvent, ProcessResult, EventRoutingConfig } from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,YAAY,EACV,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ export { WebhookProcessor } from './webhook-processor';
9
+ export { createWebhookProcessor } from './factory';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC"}
@@ -0,0 +1,78 @@
1
+ import type { WebhookPayload } from '@bernierllc/webhook-receiver';
2
+ import type { ParsedWebhookEvent } from '@bernierllc/github-parser';
3
+ import type { CommitAnalysisResult } from '@bernierllc/commit-analyzer';
4
+ /**
5
+ * Webhook processor configuration
6
+ */
7
+ export interface WebhookProcessorConfig {
8
+ /** Enable signature validation */
9
+ enableSignatureValidation?: boolean;
10
+ /** Enable retry logic */
11
+ enableRetries?: boolean;
12
+ /** Maximum retry attempts */
13
+ maxRetries?: number;
14
+ /** Retry delay in milliseconds */
15
+ retryDelay?: number;
16
+ /** Secret key for signature validation */
17
+ secretKey?: string;
18
+ /** Supabase configuration */
19
+ supabaseUrl?: string;
20
+ supabaseAnonKey?: string;
21
+ /** Enable event persistence */
22
+ enablePersistence?: boolean;
23
+ /** Event handlers */
24
+ handlers?: WebhookEventHandler[];
25
+ }
26
+ /**
27
+ * Webhook event handler
28
+ */
29
+ export interface WebhookEventHandler {
30
+ /** Source to match (e.g., 'github', 'stripe') */
31
+ source: string;
32
+ /** Event type to match (e.g., 'push', 'payment.succeeded') */
33
+ eventType?: string;
34
+ /** Handler function */
35
+ handler: (event: ProcessedWebhookEvent) => Promise<void>;
36
+ /** Priority (higher = executed first) */
37
+ priority?: number;
38
+ }
39
+ /**
40
+ * Processed webhook event
41
+ */
42
+ export interface ProcessedWebhookEvent {
43
+ /** Original webhook payload */
44
+ payload: WebhookPayload;
45
+ /** Parsed event data (if applicable) */
46
+ parsed?: ParsedWebhookEvent;
47
+ /** Commit analysis result (if applicable) */
48
+ commitAnalysis?: CommitAnalysisResult;
49
+ /** Processing metadata */
50
+ metadata: {
51
+ processedAt: Date;
52
+ processingDuration: number;
53
+ handlerCount: number;
54
+ successCount: number;
55
+ failureCount: number;
56
+ };
57
+ }
58
+ /**
59
+ * Processing result
60
+ */
61
+ export interface ProcessResult {
62
+ success: boolean;
63
+ eventId: string;
64
+ processedEvent?: ProcessedWebhookEvent;
65
+ error?: string;
66
+ retryCount?: number;
67
+ nextRetryAt?: Date;
68
+ }
69
+ /**
70
+ * Event routing configuration
71
+ */
72
+ export interface EventRoutingConfig {
73
+ /** Default handler for unmatched events */
74
+ defaultHandler?: (event: ProcessedWebhookEvent) => Promise<void>;
75
+ /** Enable event broadcasting */
76
+ enableBroadcasting?: boolean;
77
+ }
78
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,kCAAkC;IAClC,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yBAAyB;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,SA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AAC,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,gCAAgC;IAChC,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;EAME"}
@@ -0,0 +1,55 @@
1
+ import { type WebhookRequest, type WebhookPayload } from '@bernierllc/webhook-receiver';
2
+ import type { WebhookProcessorConfig, WebhookEventHandler, ProcessResult } from './types';
3
+ export declare class WebhookProcessor {
4
+ private logger;
5
+ private receiver;
6
+ private githubParser;
7
+ private commitAnalyzer;
8
+ private taskQueue;
9
+ private eventEmitter;
10
+ private supabase?;
11
+ private handlers;
12
+ private config;
13
+ constructor(config?: WebhookProcessorConfig);
14
+ /**
15
+ * Register an event handler
16
+ */
17
+ registerHandler(handler: WebhookEventHandler): void;
18
+ /**
19
+ * Remove an event handler
20
+ */
21
+ removeHandler(handler: WebhookEventHandler): void;
22
+ /**
23
+ * Process a webhook request
24
+ */
25
+ process(request: WebhookRequest): Promise<ProcessResult>;
26
+ /**
27
+ * Route event to appropriate handlers
28
+ */
29
+ private routeEvent;
30
+ /**
31
+ * Schedule retry for failed webhook
32
+ */
33
+ private scheduleRetry;
34
+ /**
35
+ * Persist event to database
36
+ */
37
+ private persistEvent;
38
+ /**
39
+ * Validate webhook signature
40
+ */
41
+ validateSignature(payload: WebhookPayload): Promise<boolean>;
42
+ /**
43
+ * Get processing statistics
44
+ */
45
+ getStats(): {
46
+ totalProcessed: number;
47
+ successCount: number;
48
+ failureCount: number;
49
+ };
50
+ /**
51
+ * Shutdown processor
52
+ */
53
+ shutdown(): Promise<void>;
54
+ }
55
+ //# sourceMappingURL=webhook-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-processor.d.ts","sourceRoot":"","sources":["../src/webhook-processor.ts"],"names":[],"mappings":"AASA,OAAO,EAAmB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAOzG,OAAO,KAAK,EACV,sBAAsB,EACtB,mBAAmB,EAEnB,aAAa,EACd,MAAM,SAAS,CAAC;AAEjB,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,CAAiB;IAClC,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,MAAM,CAA8K;gBAEhL,MAAM,GAAE,sBAA2B;IA0D/C;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAOnD;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAQjD;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAuH9D;;OAEG;YACW,UAAU;IAuCxB;;OAEG;YACW,aAAa;IAgB3B;;OAEG;YACW,YAAY;IAwB1B;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC;IASlE;;OAEG;IACH,QAAQ,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE;IASlF;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAIhC"}
@@ -0,0 +1,302 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ import { createLogger } from '@bernierllc/logger';
9
+ import { WebhookReceiver } from '@bernierllc/webhook-receiver';
10
+ import { GitHubParser } from '@bernierllc/github-parser';
11
+ import { CommitAnalyzer } from '@bernierllc/commit-analyzer';
12
+ // Retry policy is used via task queue configuration
13
+ import { TaskQueue, TaskPriority } from '@bernierllc/task-queue-core';
14
+ import { createEventEmitter } from '@bernierllc/event-emitter';
15
+ import { SupabaseClient } from '@bernierllc/supabase-client';
16
+ export class WebhookProcessor {
17
+ constructor(config = {}) {
18
+ this.handlers = [];
19
+ this.logger = createLogger({
20
+ context: {
21
+ service: '@bernierllc/webhook-processor'
22
+ }
23
+ });
24
+ this.config = {
25
+ enableSignatureValidation: config.enableSignatureValidation ?? true,
26
+ enableRetries: config.enableRetries ?? true,
27
+ maxRetries: config.maxRetries ?? 3,
28
+ retryDelay: config.retryDelay ?? 1000,
29
+ enablePersistence: config.enablePersistence ?? false,
30
+ ...config
31
+ };
32
+ // Initialize webhook receiver
33
+ this.receiver = new WebhookReceiver({
34
+ signatureSecret: this.config.secretKey,
35
+ signatureAlgorithm: 'hmac-sha256',
36
+ replayProtection: true
37
+ });
38
+ // Initialize parsers
39
+ this.githubParser = new GitHubParser();
40
+ this.commitAnalyzer = new CommitAnalyzer();
41
+ // Initialize task queue (retry policy configured via task queue)
42
+ this.taskQueue = new TaskQueue({
43
+ concurrency: 5,
44
+ enableEvents: true
45
+ });
46
+ // Initialize event emitter
47
+ this.eventEmitter = createEventEmitter();
48
+ // Initialize Supabase if persistence is enabled
49
+ if (this.config.enablePersistence && this.config.supabaseUrl && this.config.supabaseAnonKey) {
50
+ this.supabase = new SupabaseClient({
51
+ url: this.config.supabaseUrl,
52
+ anonKey: this.config.supabaseAnonKey
53
+ });
54
+ }
55
+ // Register handlers
56
+ if (config.handlers) {
57
+ for (const handler of config.handlers) {
58
+ this.registerHandler(handler);
59
+ }
60
+ }
61
+ this.logger.info('WebhookProcessor initialized', {
62
+ enableSignatureValidation: this.config.enableSignatureValidation,
63
+ enableRetries: this.config.enableRetries,
64
+ enablePersistence: this.config.enablePersistence
65
+ });
66
+ }
67
+ /**
68
+ * Register an event handler
69
+ */
70
+ registerHandler(handler) {
71
+ this.handlers.push(handler);
72
+ // Sort by priority (higher first)
73
+ this.handlers.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
74
+ this.logger.debug('Handler registered', { source: handler.source, eventType: handler.eventType });
75
+ }
76
+ /**
77
+ * Remove an event handler
78
+ */
79
+ removeHandler(handler) {
80
+ const index = this.handlers.indexOf(handler);
81
+ if (index > -1) {
82
+ this.handlers.splice(index, 1);
83
+ this.logger.debug('Handler removed', { source: handler.source, eventType: handler.eventType });
84
+ }
85
+ }
86
+ /**
87
+ * Process a webhook request
88
+ */
89
+ async process(request) {
90
+ const startTime = Date.now();
91
+ let payload;
92
+ let processedEvent;
93
+ try {
94
+ // 1. Receive and validate webhook
95
+ payload = await this.receiver.processRequest(request);
96
+ if (!payload) {
97
+ return {
98
+ success: false,
99
+ eventId: '',
100
+ error: 'Failed to process webhook request'
101
+ };
102
+ }
103
+ // 2. Parse webhook based on source
104
+ let parsed;
105
+ let commitAnalysis;
106
+ if (payload.source === 'github') {
107
+ parsed = this.githubParser.parse(payload.data);
108
+ // Analyze commits if this is a push event
109
+ if (parsed.type === 'push' && parsed.commits) {
110
+ for (const commit of parsed.commits) {
111
+ const analysis = this.commitAnalyzer.analyze({
112
+ sha: commit.sha,
113
+ message: commit.message,
114
+ author: commit.author,
115
+ branch: parsed.branch || 'main',
116
+ additions: commit.additions,
117
+ deletions: commit.deletions,
118
+ files: commit.files,
119
+ timestamp: commit.timestamp
120
+ });
121
+ if (analysis.interesting) {
122
+ commitAnalysis = analysis;
123
+ break; // Use first interesting commit
124
+ }
125
+ }
126
+ }
127
+ }
128
+ // 3. Create processed event
129
+ processedEvent = {
130
+ payload,
131
+ parsed,
132
+ commitAnalysis,
133
+ metadata: {
134
+ processedAt: new Date(),
135
+ processingDuration: Date.now() - startTime,
136
+ handlerCount: 0,
137
+ successCount: 0,
138
+ failureCount: 0
139
+ }
140
+ };
141
+ // 4. Persist event if enabled
142
+ if (this.config.enablePersistence && this.supabase) {
143
+ await this.persistEvent(processedEvent);
144
+ }
145
+ // 5. Route to handlers
146
+ const routingResult = await this.routeEvent(processedEvent);
147
+ processedEvent.metadata.handlerCount = routingResult.handlerCount;
148
+ processedEvent.metadata.successCount = routingResult.successCount;
149
+ processedEvent.metadata.failureCount = routingResult.failureCount;
150
+ // 6. Emit event
151
+ this.eventEmitter.emit('webhook.processed', {
152
+ eventId: payload.id,
153
+ source: payload.source,
154
+ eventType: payload.event,
155
+ success: routingResult.successCount > 0
156
+ });
157
+ this.logger.info('Webhook processed successfully', {
158
+ eventId: payload.id,
159
+ source: payload.source,
160
+ eventType: payload.event,
161
+ handlerCount: routingResult.handlerCount,
162
+ successCount: routingResult.successCount
163
+ });
164
+ return {
165
+ success: true,
166
+ eventId: payload.id,
167
+ processedEvent
168
+ };
169
+ }
170
+ catch (error) {
171
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
172
+ this.logger.error('Error processing webhook', error instanceof Error ? error : new Error(errorMessage), {
173
+ eventId: payload?.id
174
+ });
175
+ // Retry if enabled
176
+ if (this.config.enableRetries && payload) {
177
+ const retryResult = await this.scheduleRetry(payload, errorMessage);
178
+ return {
179
+ success: false,
180
+ eventId: payload.id,
181
+ error: errorMessage,
182
+ retryCount: retryResult.retryCount,
183
+ nextRetryAt: retryResult.nextRetryAt
184
+ };
185
+ }
186
+ return {
187
+ success: false,
188
+ eventId: payload?.id || '',
189
+ error: errorMessage
190
+ };
191
+ }
192
+ }
193
+ /**
194
+ * Route event to appropriate handlers
195
+ */
196
+ async routeEvent(event) {
197
+ const matchingHandlers = this.handlers.filter(handler => {
198
+ if (handler.source !== event.payload.source) {
199
+ return false;
200
+ }
201
+ if (handler.eventType && handler.eventType !== event.payload.event) {
202
+ return false;
203
+ }
204
+ return true;
205
+ });
206
+ let successCount = 0;
207
+ let failureCount = 0;
208
+ // Execute handlers in parallel
209
+ const handlerPromises = matchingHandlers.map(async (handler) => {
210
+ try {
211
+ await handler.handler(event);
212
+ successCount++;
213
+ return { success: true };
214
+ }
215
+ catch (error) {
216
+ failureCount++;
217
+ this.logger.error('Handler execution failed', error instanceof Error ? error : new Error(String(error)), {
218
+ source: handler.source,
219
+ eventType: handler.eventType
220
+ });
221
+ return { success: false, error };
222
+ }
223
+ });
224
+ await Promise.allSettled(handlerPromises);
225
+ return {
226
+ handlerCount: matchingHandlers.length,
227
+ successCount,
228
+ failureCount
229
+ };
230
+ }
231
+ /**
232
+ * Schedule retry for failed webhook
233
+ */
234
+ async scheduleRetry(payload, _error) {
235
+ // Add to task queue for retry
236
+ const retryCount = 0; // This would be tracked in a real implementation
237
+ const nextRetryAt = new Date(Date.now() + this.config.retryDelay);
238
+ await this.taskQueue.add({
239
+ id: `retry-${payload.id}-${Date.now()}`,
240
+ handler: async () => {
241
+ // Retry logic would go here
242
+ this.logger.debug('Retrying webhook', { eventId: payload.id, retryCount });
243
+ }
244
+ }, TaskPriority.LOW);
245
+ return { retryCount, nextRetryAt };
246
+ }
247
+ /**
248
+ * Persist event to database
249
+ */
250
+ async persistEvent(event) {
251
+ if (!this.supabase) {
252
+ return;
253
+ }
254
+ try {
255
+ await this.supabase.insert('webhook_events', {
256
+ event_id: event.payload.id,
257
+ source: event.payload.source,
258
+ event_type: event.payload.event,
259
+ payload: event.payload.data,
260
+ processed_at: event.metadata.processedAt.toISOString(),
261
+ processing_duration: event.metadata.processingDuration,
262
+ handler_count: event.metadata.handlerCount,
263
+ success_count: event.metadata.successCount,
264
+ failure_count: event.metadata.failureCount
265
+ });
266
+ }
267
+ catch (error) {
268
+ this.logger.error('Failed to persist event', error instanceof Error ? error : new Error(String(error)), {
269
+ eventId: event.payload.id
270
+ });
271
+ }
272
+ }
273
+ /**
274
+ * Validate webhook signature
275
+ */
276
+ async validateSignature(payload) {
277
+ if (!this.config.enableSignatureValidation || !this.config.secretKey) {
278
+ return true; // Skip validation if disabled
279
+ }
280
+ // Signature validation is handled by WebhookReceiver
281
+ return payload.signature !== undefined;
282
+ }
283
+ /**
284
+ * Get processing statistics
285
+ */
286
+ getStats() {
287
+ // This would track statistics in a real implementation
288
+ return {
289
+ totalProcessed: 0,
290
+ successCount: 0,
291
+ failureCount: 0
292
+ };
293
+ }
294
+ /**
295
+ * Shutdown processor
296
+ */
297
+ async shutdown() {
298
+ this.logger.info('Shutting down WebhookProcessor');
299
+ // Cleanup would go here
300
+ }
301
+ }
302
+ //# sourceMappingURL=webhook-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook-processor.js","sourceRoot":"","sources":["../src/webhook-processor.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,YAAY,EAAU,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAA4C,MAAM,8BAA8B,CAAC;AACzG,OAAO,EAAE,YAAY,EAA2B,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,cAAc,EAA6B,MAAM,6BAA6B,CAAC;AACxF,oDAAoD;AACpD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAgB,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAQ7D,MAAM,OAAO,gBAAgB;IAW3B,YAAY,SAAiC,EAAE;QAHvC,aAAQ,GAA0B,EAAE,CAAC;QAI3C,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;YACzB,OAAO,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,QAAQ,CAAC,YAAY;gBAC1C,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY;aAC3C,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;gBACtG,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE;aAC1B,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAAiB,CAAC,OAAuB;QAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACrE,OAAO,IAAI,CAAC,CAAC,8BAA8B;QAC7C,CAAC;QAED,qDAAqD;QACrD,OAAO,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,uDAAuD;QACvD,OAAO;YACL,cAAc,EAAE,CAAC;YACjB,YAAY,EAAE,CAAC;YACf,YAAY,EAAE,CAAC;SAChB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;QACnD,wBAAwB;IAC1B,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@bernierllc/webhook-processor",
3
+ "version": "1.0.0",
4
+ "description": "Webhook event processing service with signature validation, retry logic, and event routing",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist/**/*",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "keywords": [
14
+ "webhook",
15
+ "events",
16
+ "processing",
17
+ "validation",
18
+ "routing",
19
+ "service",
20
+ "bernierllc"
21
+ ],
22
+ "author": "Bernier LLC",
23
+ "license": "SEE LICENSE IN LICENSE",
24
+ "dependencies": {
25
+ "@bernierllc/logger": "1.0.3",
26
+ "@bernierllc/crypto-utils": "1.0.2",
27
+ "@bernierllc/retry-policy": "0.1.6",
28
+ "@bernierllc/task-queue-core": "1.0.0",
29
+ "@bernierllc/event-emitter": "1.0.1",
30
+ "@bernierllc/supabase-client": "1.0.2",
31
+ "@bernierllc/webhook-receiver": "1.0.1",
32
+ "@bernierllc/github-parser": "1.0.0",
33
+ "@bernierllc/commit-analyzer": "1.0.0",
34
+ "@bernierllc/neverhub-adapter": "0.1.2"
35
+ },
36
+ "devDependencies": {
37
+ "@types/jest": "^29.5.0",
38
+ "@types/node": "^20.0.0",
39
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
40
+ "@typescript-eslint/parser": "^6.0.0",
41
+ "eslint": "^8.0.0",
42
+ "jest": "^29.0.0",
43
+ "rimraf": "^5.0.0",
44
+ "ts-jest": "^29.0.0",
45
+ "typescript": "^5.0.0"
46
+ },
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "git+https://github.com/bernierllc/tools.git",
50
+ "directory": "packages/service/webhook-processor"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/bernierllc/tools/issues"
54
+ },
55
+ "homepage": "https://github.com/bernierllc/tools/tree/main/packages/service/webhook-processor#readme",
56
+ "publishConfig": {
57
+ "access": "public",
58
+ "registry": "https://registry.npmjs.org/"
59
+ },
60
+ "engines": {
61
+ "node": ">=18.0.0"
62
+ },
63
+ "bernierllc": {
64
+ "integration": {
65
+ "logger": "integrated",
66
+ "docsIntegration": "ready",
67
+ "neverhub": "required"
68
+ }
69
+ },
70
+ "scripts": {
71
+ "build": "tsc",
72
+ "prebuild": "npm run clean",
73
+ "clean": "rimraf dist",
74
+ "test": "jest",
75
+ "test:run": "jest --passWithNoTests",
76
+ "test:coverage": "jest --coverage",
77
+ "lint": "eslint src --ext .ts"
78
+ }
79
+ }