voice-router-dev 0.8.2 → 0.8.3

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.
@@ -1,7 +1,237 @@
1
- import { fF as TranscriptionStatus, fC as Speaker, fD as Word, fE as Utterance, Q as CallbackTranscriptionSuccessPayload, J as CallbackTranscriptionErrorPayload, cf as TranscriptWebhookNotification, d2 as ListenV1Response, ep as SpeechToTextChunkResponseModel } from './speechToTextChunkResponseModel-3IUnJXKx.mjs';
2
- import { T as TranscriptionProvider } from './provider-metadata-BnkedpXm.mjs';
1
+ import { gH as TranscriptionStatus, gE as Speaker, gF as Word, gG as Utterance, Q as CallbackTranscriptionSuccessPayload, J as CallbackTranscriptionErrorPayload, cf as TranscriptWebhookNotification, d2 as ListenV1Response, eR as RetrieveTranscriptResponse, fr as SpeechToTextChunkResponseModel } from './speechToTextChunkResponseModel-DvIT4xai.mjs';
2
+ import { T as TranscriptionProvider } from './provider-metadata-MDUUEuqF.mjs';
3
3
  import './constants.mjs';
4
4
 
5
+ /**
6
+ * Base webhook handler interface
7
+ * All provider-specific webhook handlers must implement this
8
+ */
9
+
10
+ /**
11
+ * Abstract base class for webhook handlers
12
+ *
13
+ * Each provider implements this to parse and normalize their webhook payloads
14
+ */
15
+ declare abstract class BaseWebhookHandler {
16
+ /** Provider name */
17
+ abstract readonly provider: TranscriptionProvider;
18
+ /**
19
+ * Check if this payload matches this provider's webhook format
20
+ *
21
+ * Used for auto-detection of webhook provider
22
+ *
23
+ * @param payload - Raw webhook payload
24
+ * @param options - Optional context (query params, headers, etc.)
25
+ * @returns true if this handler can process the payload
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * matches(payload, options) {
30
+ * return typeof payload === 'object' &&
31
+ * 'event' in payload &&
32
+ * 'payload' in payload
33
+ * }
34
+ * ```
35
+ */
36
+ abstract matches(payload: unknown, options?: {
37
+ queryParams?: Record<string, string>;
38
+ userAgent?: string;
39
+ }): boolean;
40
+ /**
41
+ * Parse and normalize webhook payload
42
+ *
43
+ * Converts provider-specific webhook format to UnifiedWebhookEvent
44
+ *
45
+ * @param payload - Raw webhook payload
46
+ * @param options - Optional context (query params, headers, etc.)
47
+ * @returns Normalized webhook event
48
+ * @throws Error if payload cannot be parsed
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * parse(payload, options) {
53
+ * const typed = payload as ProviderWebhookPayload
54
+ * return {
55
+ * success: true,
56
+ * provider: this.provider,
57
+ * eventType: 'transcription.completed',
58
+ * data: { id: typed.job_id, ... },
59
+ * timestamp: new Date().toISOString(),
60
+ * raw: payload
61
+ * }
62
+ * }
63
+ * ```
64
+ */
65
+ abstract parse(payload: unknown, options?: {
66
+ queryParams?: Record<string, string>;
67
+ }): UnifiedWebhookEvent;
68
+ /**
69
+ * Verify webhook signature (if provider supports it)
70
+ *
71
+ * Optional method - implement if provider supports webhook signature verification
72
+ *
73
+ * @param payload - Raw webhook payload
74
+ * @param options - Verification options (signature, secret, etc.)
75
+ * @returns true if signature is valid
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * verify(payload, options) {
80
+ * if (!options.signature || !options.secret) return false
81
+ *
82
+ * const computed = crypto
83
+ * .createHmac('sha256', options.secret)
84
+ * .update(JSON.stringify(payload))
85
+ * .digest('hex')
86
+ *
87
+ * return computed === options.signature
88
+ * }
89
+ * ```
90
+ */
91
+ verify?(payload: unknown, options: WebhookVerificationOptions): boolean;
92
+ /**
93
+ * Validate webhook payload structure
94
+ *
95
+ * Checks if payload has required fields and correct types
96
+ *
97
+ * @param payload - Raw webhook payload
98
+ * @param options - Optional context (query params, headers, etc.)
99
+ * @returns Validation result with details
100
+ */
101
+ validate(payload: unknown, options?: {
102
+ queryParams?: Record<string, string>;
103
+ userAgent?: string;
104
+ }): WebhookValidation;
105
+ /**
106
+ * Helper method to create error response
107
+ */
108
+ protected createErrorEvent(payload: unknown, errorMessage: string): UnifiedWebhookEvent;
109
+ }
110
+
111
+ /**
112
+ * Azure Speech-to-Text webhook handler
113
+ * Parses and normalizes Azure STT webhook callbacks
114
+ */
115
+
116
+ /**
117
+ * Azure webhook event payload structure
118
+ * Based on Azure Speech Services v3.1 webhook format
119
+ */
120
+ interface AzureWebhookPayload {
121
+ /** Event action (e.g., "TranscriptionCreated", "TranscriptionSucceeded", "TranscriptionFailed") */
122
+ action: string;
123
+ /** Timestamp of the event */
124
+ timestamp: string;
125
+ /** Self-link to the resource */
126
+ self?: string;
127
+ /** Additional properties */
128
+ properties?: Record<string, unknown>;
129
+ /** Error details (for failed events) */
130
+ error?: {
131
+ code: string;
132
+ message: string;
133
+ };
134
+ }
135
+ /**
136
+ * Azure webhook handler
137
+ *
138
+ * Handles webhook callbacks from Azure Speech Services API:
139
+ * - TranscriptionCreated - Transcription job created
140
+ * - TranscriptionRunning - Transcription is processing
141
+ * - TranscriptionSucceeded - Transcription completed successfully
142
+ * - TranscriptionFailed - Transcription failed with error
143
+ *
144
+ * Azure supports optional webhook signature verification using a shared secret.
145
+ *
146
+ * @example Basic usage
147
+ * ```typescript
148
+ * import { AzureWebhookHandler } from '@meeting-baas/sdk';
149
+ *
150
+ * const handler = new AzureWebhookHandler();
151
+ *
152
+ * // Validate webhook
153
+ * const validation = handler.validate(req.body);
154
+ * if (!validation.valid) {
155
+ * return res.status(400).json({ error: validation.error });
156
+ * }
157
+ *
158
+ * // Parse webhook
159
+ * const event = handler.parse(req.body);
160
+ * console.log('Event type:', event.eventType);
161
+ * console.log('Action:', event.raw.action);
162
+ * ```
163
+ *
164
+ * @example With signature verification
165
+ * ```typescript
166
+ * // Verify webhook signature (if configured in Azure)
167
+ * const isValid = handler.verify(req.body, {
168
+ * signature: req.headers['x-azure-signature'],
169
+ * secret: process.env.AZURE_WEBHOOK_SECRET,
170
+ * rawBody: req.rawBody
171
+ * });
172
+ *
173
+ * if (!isValid) {
174
+ * return res.status(401).json({ error: 'Invalid signature' });
175
+ * }
176
+ * ```
177
+ *
178
+ * @example Processing completed transcription
179
+ * ```typescript
180
+ * const event = handler.parse(req.body);
181
+ *
182
+ * if (event.eventType === 'transcription.completed') {
183
+ * // Extract transcription ID from self link
184
+ * const transcriptionId = event.data?.id;
185
+ *
186
+ * // Fetch full transcript using AzureAdapter.getTranscript(transcriptionId)
187
+ * console.log('Transcription completed:', transcriptionId);
188
+ * }
189
+ * ```
190
+ */
191
+ declare class AzureWebhookHandler extends BaseWebhookHandler {
192
+ readonly provider: TranscriptionProvider;
193
+ /**
194
+ * Check if payload matches Azure webhook format
195
+ */
196
+ matches(payload: unknown, _options?: {
197
+ queryParams?: Record<string, string>;
198
+ userAgent?: string;
199
+ }): boolean;
200
+ /**
201
+ * Parse Azure webhook payload to unified format
202
+ */
203
+ parse(payload: unknown, _options?: {
204
+ queryParams?: Record<string, string>;
205
+ }): UnifiedWebhookEvent;
206
+ /**
207
+ * Verify Azure webhook signature
208
+ *
209
+ * Azure can optionally sign webhooks using HMAC-SHA256.
210
+ * The signature is sent in the X-Azure-Signature header.
211
+ *
212
+ * Note: Signature verification is optional in Azure and must be
213
+ * configured when creating the webhook.
214
+ *
215
+ * @param payload - Webhook payload
216
+ * @param options - Verification options with signature and secret
217
+ * @returns true if signature is valid or no signature provided
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const isValid = handler.verify(req.body, {
222
+ * signature: req.headers['x-azure-signature'],
223
+ * secret: process.env.AZURE_WEBHOOK_SECRET,
224
+ * rawBody: req.rawBody
225
+ * });
226
+ * ```
227
+ */
228
+ verify(payload: unknown, options: WebhookVerificationOptions): boolean;
229
+ }
230
+ /**
231
+ * Factory function to create an Azure webhook handler
232
+ */
233
+ declare function createAzureWebhookHandler(): AzureWebhookHandler;
234
+
5
235
  /**
6
236
  * Unified webhook types for transcription providers
7
237
  * Normalizes webhook callbacks from different providers to a common format
@@ -18,9 +248,9 @@ type ProviderWebhookPayloadMap = {
18
248
  gladia: GladiaWebhookPayload;
19
249
  assemblyai: TranscriptWebhookNotification;
20
250
  deepgram: ListenV1Response;
21
- "azure-stt": unknown;
251
+ "azure-stt": AzureWebhookPayload;
22
252
  "openai-whisper": never;
23
- speechmatics: unknown;
253
+ speechmatics: RetrieveTranscriptResponse;
24
254
  elevenlabs: SpeechToTextChunkResponseModel;
25
255
  };
26
256
  /**
@@ -123,112 +353,6 @@ interface WebhookVerificationOptions {
123
353
  headers?: Record<string, string>;
124
354
  }
125
355
 
126
- /**
127
- * Base webhook handler interface
128
- * All provider-specific webhook handlers must implement this
129
- */
130
-
131
- /**
132
- * Abstract base class for webhook handlers
133
- *
134
- * Each provider implements this to parse and normalize their webhook payloads
135
- */
136
- declare abstract class BaseWebhookHandler {
137
- /** Provider name */
138
- abstract readonly provider: TranscriptionProvider;
139
- /**
140
- * Check if this payload matches this provider's webhook format
141
- *
142
- * Used for auto-detection of webhook provider
143
- *
144
- * @param payload - Raw webhook payload
145
- * @param options - Optional context (query params, headers, etc.)
146
- * @returns true if this handler can process the payload
147
- *
148
- * @example
149
- * ```typescript
150
- * matches(payload, options) {
151
- * return typeof payload === 'object' &&
152
- * 'event' in payload &&
153
- * 'payload' in payload
154
- * }
155
- * ```
156
- */
157
- abstract matches(payload: unknown, options?: {
158
- queryParams?: Record<string, string>;
159
- userAgent?: string;
160
- }): boolean;
161
- /**
162
- * Parse and normalize webhook payload
163
- *
164
- * Converts provider-specific webhook format to UnifiedWebhookEvent
165
- *
166
- * @param payload - Raw webhook payload
167
- * @param options - Optional context (query params, headers, etc.)
168
- * @returns Normalized webhook event
169
- * @throws Error if payload cannot be parsed
170
- *
171
- * @example
172
- * ```typescript
173
- * parse(payload, options) {
174
- * const typed = payload as ProviderWebhookPayload
175
- * return {
176
- * success: true,
177
- * provider: this.provider,
178
- * eventType: 'transcription.completed',
179
- * data: { id: typed.job_id, ... },
180
- * timestamp: new Date().toISOString(),
181
- * raw: payload
182
- * }
183
- * }
184
- * ```
185
- */
186
- abstract parse(payload: unknown, options?: {
187
- queryParams?: Record<string, string>;
188
- }): UnifiedWebhookEvent;
189
- /**
190
- * Verify webhook signature (if provider supports it)
191
- *
192
- * Optional method - implement if provider supports webhook signature verification
193
- *
194
- * @param payload - Raw webhook payload
195
- * @param options - Verification options (signature, secret, etc.)
196
- * @returns true if signature is valid
197
- *
198
- * @example
199
- * ```typescript
200
- * verify(payload, options) {
201
- * if (!options.signature || !options.secret) return false
202
- *
203
- * const computed = crypto
204
- * .createHmac('sha256', options.secret)
205
- * .update(JSON.stringify(payload))
206
- * .digest('hex')
207
- *
208
- * return computed === options.signature
209
- * }
210
- * ```
211
- */
212
- verify?(payload: unknown, options: WebhookVerificationOptions): boolean;
213
- /**
214
- * Validate webhook payload structure
215
- *
216
- * Checks if payload has required fields and correct types
217
- *
218
- * @param payload - Raw webhook payload
219
- * @param options - Optional context (query params, headers, etc.)
220
- * @returns Validation result with details
221
- */
222
- validate(payload: unknown, options?: {
223
- queryParams?: Record<string, string>;
224
- userAgent?: string;
225
- }): WebhookValidation;
226
- /**
227
- * Helper method to create error response
228
- */
229
- protected createErrorEvent(payload: unknown, errorMessage: string): UnifiedWebhookEvent;
230
- }
231
-
232
356
  /**
233
357
  * Gladia webhook handler
234
358
  * Parses and normalizes Gladia webhook callbacks
@@ -514,111 +638,6 @@ declare class DeepgramWebhookHandler extends BaseWebhookHandler {
514
638
  */
515
639
  declare function createDeepgramWebhookHandler(): DeepgramWebhookHandler;
516
640
 
517
- /**
518
- * Azure Speech-to-Text webhook handler
519
- * Parses and normalizes Azure STT webhook callbacks
520
- */
521
-
522
- /**
523
- * Azure webhook handler
524
- *
525
- * Handles webhook callbacks from Azure Speech Services API:
526
- * - TranscriptionCreated - Transcription job created
527
- * - TranscriptionRunning - Transcription is processing
528
- * - TranscriptionSucceeded - Transcription completed successfully
529
- * - TranscriptionFailed - Transcription failed with error
530
- *
531
- * Azure supports optional webhook signature verification using a shared secret.
532
- *
533
- * @example Basic usage
534
- * ```typescript
535
- * import { AzureWebhookHandler } from '@meeting-baas/sdk';
536
- *
537
- * const handler = new AzureWebhookHandler();
538
- *
539
- * // Validate webhook
540
- * const validation = handler.validate(req.body);
541
- * if (!validation.valid) {
542
- * return res.status(400).json({ error: validation.error });
543
- * }
544
- *
545
- * // Parse webhook
546
- * const event = handler.parse(req.body);
547
- * console.log('Event type:', event.eventType);
548
- * console.log('Action:', event.raw.action);
549
- * ```
550
- *
551
- * @example With signature verification
552
- * ```typescript
553
- * // Verify webhook signature (if configured in Azure)
554
- * const isValid = handler.verify(req.body, {
555
- * signature: req.headers['x-azure-signature'],
556
- * secret: process.env.AZURE_WEBHOOK_SECRET,
557
- * rawBody: req.rawBody
558
- * });
559
- *
560
- * if (!isValid) {
561
- * return res.status(401).json({ error: 'Invalid signature' });
562
- * }
563
- * ```
564
- *
565
- * @example Processing completed transcription
566
- * ```typescript
567
- * const event = handler.parse(req.body);
568
- *
569
- * if (event.eventType === 'transcription.completed') {
570
- * // Extract transcription ID from self link
571
- * const transcriptionId = event.data?.id;
572
- *
573
- * // Fetch full transcript using AzureAdapter.getTranscript(transcriptionId)
574
- * console.log('Transcription completed:', transcriptionId);
575
- * }
576
- * ```
577
- */
578
- declare class AzureWebhookHandler extends BaseWebhookHandler {
579
- readonly provider: TranscriptionProvider;
580
- /**
581
- * Check if payload matches Azure webhook format
582
- */
583
- matches(payload: unknown, _options?: {
584
- queryParams?: Record<string, string>;
585
- userAgent?: string;
586
- }): boolean;
587
- /**
588
- * Parse Azure webhook payload to unified format
589
- */
590
- parse(payload: unknown, _options?: {
591
- queryParams?: Record<string, string>;
592
- }): UnifiedWebhookEvent;
593
- /**
594
- * Verify Azure webhook signature
595
- *
596
- * Azure can optionally sign webhooks using HMAC-SHA256.
597
- * The signature is sent in the X-Azure-Signature header.
598
- *
599
- * Note: Signature verification is optional in Azure and must be
600
- * configured when creating the webhook.
601
- *
602
- * @param payload - Webhook payload
603
- * @param options - Verification options with signature and secret
604
- * @returns true if signature is valid or no signature provided
605
- *
606
- * @example
607
- * ```typescript
608
- * const isValid = handler.verify(req.body, {
609
- * signature: req.headers['x-azure-signature'],
610
- * secret: process.env.AZURE_WEBHOOK_SECRET,
611
- * rawBody: req.rawBody
612
- * });
613
- * ```
614
- */
615
- verify(payload: unknown, options: WebhookVerificationOptions): boolean;
616
- }
617
- /**
618
- * Factory function to create an Azure webhook handler
619
- */
620
- declare function createAzureWebhookHandler(): AzureWebhookHandler;
621
-
622
641
  /**
623
642
  * Speechmatics webhook handler
624
643
  * Parses and normalizes Speechmatics webhook callbacks