@vercel/queue 0.0.0-alpha.1 → 0.0.0-alpha.11

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/dist/index.d.mts CHANGED
@@ -44,7 +44,7 @@ declare class BufferTransport implements Transport<Buffer> {
44
44
  *
45
45
  * IMPORTANT: When using StreamTransport, you must call finalize(payload) when done
46
46
  * processing the message to prevent resource leaks, especially in error cases.
47
- * ConsumerGroup handles this automatically, but direct VQSClient usage requires manual cleanup.
47
+ * ConsumerGroup handles this automatically, but direct QueueClient usage requires manual cleanup.
48
48
  *
49
49
  * Example usage:
50
50
  * ```typescript
@@ -71,44 +71,10 @@ declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
71
71
  * Vercel Queue Service client types
72
72
  */
73
73
 
74
- interface VQSClientOptions {
75
- /**
76
- * Base URL for the Vercel Queue Service API
77
- * @default "https://vqs.vercel.sh"
78
- */
79
- baseUrl?: string;
80
- /**
81
- * Vercel function OIDC token
82
- * Can be obtained from x-vercel-oidc-token header in Vercel Serverless Functions
83
- */
84
- token: string;
85
- }
86
74
  /**
87
- * Callback configuration for a consumer group
75
+ * Shared options for publishing messages
88
76
  */
89
- interface CallbackConfig {
90
- /**
91
- * Webhook URL to notify when messages are available
92
- */
93
- url: string;
94
- /**
95
- * Delay in seconds before sending the first callback
96
- */
97
- delay?: number;
98
- /**
99
- * Delay in seconds between retry attempts when the callback fails
100
- */
101
- frequency?: number;
102
- }
103
- interface SendMessageOptions<T = unknown> {
104
- /**
105
- * The queue name to send the message to
106
- */
107
- queueName: string;
108
- /**
109
- * The message payload
110
- */
111
- payload: T;
77
+ interface PublishOptions {
112
78
  /**
113
79
  * Unique key to prevent duplicate message submissions
114
80
  * @default random UUID
@@ -121,11 +87,16 @@ interface SendMessageOptions<T = unknown> {
121
87
  * @max 86400
122
88
  */
123
89
  retentionSeconds?: number;
90
+ }
91
+ interface SendMessageOptions<T = unknown> extends PublishOptions {
92
+ /**
93
+ * The queue name to send the message to
94
+ */
95
+ queueName: string;
124
96
  /**
125
- * Consumer group callback configurations
126
- * Format: { consumerGroup: { url, delay?, frequency? } }
97
+ * The message payload
127
98
  */
128
- callbacks?: Record<string, CallbackConfig>;
99
+ payload: T;
129
100
  }
130
101
  interface SendMessageResponse {
131
102
  /**
@@ -149,9 +120,9 @@ interface Message<T = unknown> {
149
120
  */
150
121
  deliveryCount: number;
151
122
  /**
152
- * Timestamp when the message was created
123
+ * When the message was created
153
124
  */
154
- timestamp: string;
125
+ createdAt: Date;
155
126
  /**
156
127
  * MIME type of the message content
157
128
  */
@@ -161,80 +132,6 @@ interface Message<T = unknown> {
161
132
  */
162
133
  ticket: string;
163
134
  }
164
- interface ReceiveMessagesOptions<T = unknown> {
165
- /**
166
- * The queue name to receive messages from
167
- */
168
- queueName: string;
169
- /**
170
- * Consumer group name
171
- */
172
- consumerGroup: string;
173
- /**
174
- * Time in seconds that messages will be invisible to other consumers
175
- * @default 900 (15 minutes)
176
- */
177
- visibilityTimeoutSeconds?: number;
178
- /**
179
- * Maximum number of messages to retrieve
180
- * @default 10
181
- * @max 10
182
- * @note FIFO queues must use limit=1
183
- */
184
- limit?: number;
185
- }
186
- interface DeleteMessageOptions {
187
- /**
188
- * The queue name the message belongs to
189
- */
190
- queueName: string;
191
- /**
192
- * Consumer group name
193
- */
194
- consumerGroup: string;
195
- /**
196
- * The message ID to delete
197
- */
198
- messageId: string;
199
- /**
200
- * Ticket received from the message
201
- */
202
- ticket: string;
203
- }
204
- interface DeleteMessageResponse {
205
- /**
206
- * Whether the message was successfully deleted
207
- */
208
- deleted: boolean;
209
- }
210
- interface ChangeVisibilityOptions {
211
- /**
212
- * The queue name the message belongs to
213
- */
214
- queueName: string;
215
- /**
216
- * Consumer group name
217
- */
218
- consumerGroup: string;
219
- /**
220
- * The message ID to update
221
- */
222
- messageId: string;
223
- /**
224
- * Ticket received from the message
225
- */
226
- ticket: string;
227
- /**
228
- * New visibility timeout in seconds
229
- */
230
- visibilityTimeoutSeconds: number;
231
- }
232
- interface ChangeVisibilityResponse {
233
- /**
234
- * Whether the visibility was successfully updated
235
- */
236
- updated: boolean;
237
- }
238
135
  /**
239
136
  * Result indicating the message should be timed out for retry later
240
137
  */
@@ -248,10 +145,18 @@ interface MessageTimeoutResult {
248
145
  * Result returned by message handlers
249
146
  */
250
147
  type MessageHandlerResult = void | MessageTimeoutResult;
148
+ /**
149
+ * Message metadata provided to handlers
150
+ */
151
+ interface MessageMetadata {
152
+ messageId: string;
153
+ deliveryCount: number;
154
+ createdAt: Date;
155
+ }
251
156
  /**
252
157
  * Message handler function type
253
158
  */
254
- type MessageHandler<T = unknown> = (message: Message<T>) => Promise<MessageHandlerResult> | MessageHandlerResult;
159
+ type MessageHandler<T = unknown> = (message: T, metadata: MessageMetadata) => Promise<MessageHandlerResult> | MessageHandlerResult;
255
160
  /**
256
161
  * Options for creating a ConsumerGroup instance
257
162
  */
@@ -272,44 +177,6 @@ interface ConsumerGroupOptions<T = unknown> {
272
177
  */
273
178
  refreshInterval?: number;
274
179
  }
275
- interface ReceiveMessageByIdOptions<T = unknown> {
276
- /**
277
- * The queue name to receive the message from
278
- */
279
- queueName: string;
280
- /**
281
- * Consumer group name
282
- */
283
- consumerGroup: string;
284
- /**
285
- * The message ID to retrieve
286
- */
287
- messageId: string;
288
- /**
289
- * Time in seconds that the message will be invisible to other consumers
290
- * @default 900 (15 minutes)
291
- */
292
- visibilityTimeoutSeconds?: number;
293
- /**
294
- * Skip payload content and only return message metadata
295
- * When true, the server returns a 204 status with headers containing message metadata
296
- * @default false
297
- */
298
- skipPayload?: boolean;
299
- }
300
- interface ReceiveMessageByIdResponse<T = unknown, TSkipPayload extends boolean = false> {
301
- message: TSkipPayload extends true ? Message<void> : Message<T>;
302
- }
303
- interface FifoOrderingError {
304
- /**
305
- * Error message describing the FIFO ordering violation
306
- */
307
- error: string;
308
- /**
309
- * The message ID that must be processed first
310
- */
311
- nextMessageId: string;
312
- }
313
180
  /**
314
181
  * Error thrown when a message is not found (404)
315
182
  */
@@ -323,13 +190,6 @@ declare class MessageNotFoundError extends Error {
323
190
  declare class MessageNotAvailableError extends Error {
324
191
  constructor(messageId: string, reason?: string);
325
192
  }
326
- /**
327
- * Error thrown when there's a FIFO ordering violation (409 with nextMessageId)
328
- */
329
- declare class FifoOrderingViolationError extends Error {
330
- readonly nextMessageId: string;
331
- constructor(messageId: string, nextMessageId: string, reason: string);
332
- }
333
193
  /**
334
194
  * Error thrown when message data is corrupted or can't be parsed
335
195
  */
@@ -343,7 +203,7 @@ declare class QueueEmptyError extends Error {
343
203
  constructor(queueName: string, consumerGroup: string);
344
204
  }
345
205
  /**
346
- * Error thrown when a message is temporarily locked in a FIFO queue (423)
206
+ * Error thrown when a message is temporarily locked (423)
347
207
  */
348
208
  declare class MessageLockedError extends Error {
349
209
  readonly retryAfter?: number;
@@ -367,13 +227,6 @@ declare class ForbiddenError extends Error {
367
227
  declare class BadRequestError extends Error {
368
228
  constructor(message: string);
369
229
  }
370
- /**
371
- * Error thrown when there's a failed dependency (424) - FIFO ordering violation in receive by ID
372
- */
373
- declare class FailedDependencyError extends Error {
374
- readonly nextMessageId: string;
375
- constructor(messageId: string, nextMessageId: string);
376
- }
377
230
  /**
378
231
  * Error thrown for internal server errors (500)
379
232
  */
@@ -386,340 +239,124 @@ declare class InternalServerError extends Error {
386
239
  declare class InvalidLimitError extends Error {
387
240
  constructor(limit: number, min?: number, max?: number);
388
241
  }
242
+
389
243
  /**
390
- * Options extracted from a VQS callback request
391
- */
392
- interface CallbackMessageOptions {
393
- /**
394
- * The queue name extracted from Vqs-Queue-Name header
395
- */
396
- queueName: string;
397
- /**
398
- * The consumer group extracted from Vqs-Consumer-Group header
399
- */
400
- consumerGroup: string;
401
- /**
402
- * The message ID extracted from Vqs-Message-Id header
403
- */
404
- messageId: string;
405
- }
406
- /**
407
- * Error thrown when VQS callback headers are missing or invalid
244
+ * Options for the consume method
408
245
  */
409
- declare class InvalidCallbackError extends Error {
410
- constructor(message: string);
246
+ interface ConsumeOptions {
247
+ /** The specific message ID to consume (if not provided, consumes next available message) */
248
+ messageId?: string;
249
+ /** Whether to skip downloading the payload (only allowed when messageId is provided) */
250
+ skipPayload?: boolean;
411
251
  }
412
252
 
413
253
  /**
414
- * Client for interacting with the Vercel Queue Service API
254
+ * Options for the send function
415
255
  */
416
- declare class VQSClient {
417
- private baseUrl;
418
- private token;
419
- /**
420
- * Create a new Vercel Queue Service client
421
- * @param options Client configuration options
422
- */
423
- constructor(options: VQSClientOptions);
424
- /**
425
- * Create a VQSClient automatically configured for Vercel Functions
426
- * This method automatically retrieves the OIDC token from the Vercel Function environment
427
- * Always creates a fresh instance since OIDC tokens expire after 15 minutes
428
- * @param baseUrl Optional base URL override
429
- * @returns Promise resolving to a new VQSClient instance
430
- */
431
- static fromVercelFunction(baseUrl?: string): Promise<VQSClient>;
432
- /**
433
- * Send a message to a queue
434
- * @param options Send message options
435
- * @param transport Serializer/deserializer for the payload
436
- * @returns Promise with the message ID
437
- * @throws {BadRequestError} When request parameters are invalid
438
- * @throws {UnauthorizedError} When authentication fails
439
- * @throws {ForbiddenError} When access is denied (environment mismatch)
440
- * @throws {InternalServerError} When server encounters an error
441
- */
442
- sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
443
- /**
444
- * Receive messages from a queue
445
- * @param options Receive messages options
446
- * @param transport Serializer/deserializer for the payload
447
- * @returns AsyncGenerator that yields messages as they arrive
448
- * @throws {InvalidLimitError} When limit parameter is not between 1 and 10
449
- * @throws {QueueEmptyError} When no messages are available (204)
450
- * @throws {MessageLockedError} When FIFO queue has locked messages (423)
451
- * @throws {BadRequestError} When request parameters are invalid
452
- * @throws {UnauthorizedError} When authentication fails
453
- * @throws {ForbiddenError} When access is denied (environment mismatch)
454
- * @throws {InternalServerError} When server encounters an error
455
- */
456
- receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
457
- /**
458
- * Receive a specific message by its ID from a queue
459
- * @param options Receive message by ID options
460
- * @param transport Serializer/deserializer for the payload
461
- * @returns Promise with the message or null if not found/available
462
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
463
- * @throws {MessageLockedError} When the message is temporarily locked (423)
464
- * @throws {FailedDependencyError} When FIFO ordering is violated (424)
465
- * @throws {MessageNotAvailableError} When message exists but isn't available (409)
466
- * @throws {FifoOrderingViolationError} When FIFO ordering is violated (409 with nextMessageId)
467
- * @throws {MessageCorruptedError} When message data is corrupted
468
- * @throws {BadRequestError} When request parameters are invalid
469
- * @throws {UnauthorizedError} When authentication fails
470
- * @throws {ForbiddenError} When access is denied (environment mismatch)
471
- * @throws {InternalServerError} When server encounters an error
472
- */
473
- receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
474
- skipPayload: true;
475
- }, transport?: Transport<T>): Promise<ReceiveMessageByIdResponse<T, true>>;
476
- receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
477
- skipPayload?: false | undefined;
478
- }, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T, false>>;
256
+ interface SendOptions<T = unknown> extends PublishOptions {
479
257
  /**
480
- * Delete a message (acknowledge processing)
481
- * @param options Delete message options
482
- * @returns Promise with delete status
483
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
484
- * @throws {MessageNotAvailableError} When message can't be deleted (409)
485
- * @throws {BadRequestError} When ticket is missing or invalid (400)
486
- * @throws {UnauthorizedError} When authentication fails
487
- * @throws {ForbiddenError} When access is denied (environment mismatch)
488
- * @throws {InternalServerError} When server encounters an error
489
- */
490
- deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
491
- /**
492
- * Change the visibility timeout of a message
493
- * @param options Change visibility options
494
- * @returns Promise with update status
495
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
496
- * @throws {MessageNotAvailableError} When message can't be updated (409)
497
- * @throws {BadRequestError} When ticket is missing or visibility timeout invalid (400)
498
- * @throws {UnauthorizedError} When authentication fails
499
- * @throws {ForbiddenError} When access is denied (environment mismatch)
500
- * @throws {InternalServerError} When server encounters an error
258
+ * Serializer/deserializer for the payload
259
+ * @default JsonTransport instance
501
260
  */
502
- changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
261
+ transport?: Transport<T>;
503
262
  }
504
-
505
263
  /**
506
- * A ConsumerGroup represents a named group of consumers that process messages from a topic
264
+ * Send a message to a topic (shorthand for topic creation and publishing)
265
+ * Uses the default QueueClient with automatic OIDC token detection
266
+ * @param topicName Name of the topic to send to
267
+ * @param payload The data to send
268
+ * @param options Optional send options including transport and publish settings
269
+ * @returns Promise with the message ID
270
+ * @throws {BadRequestError} When request parameters are invalid
271
+ * @throws {UnauthorizedError} When authentication fails
272
+ * @throws {ForbiddenError} When access is denied (environment mismatch)
273
+ * @throws {InternalServerError} When server encounters an error
507
274
  */
508
- declare class ConsumerGroup<T = unknown> {
509
- private client;
510
- private topicName;
511
- private consumerGroupName;
512
- private visibilityTimeout;
513
- private refreshInterval;
514
- private transport;
515
- /**
516
- * Create a new ConsumerGroup instance
517
- * @param client VQSClient instance to use for API calls
518
- * @param topicName Name of the topic to consume from
519
- * @param consumerGroupName Name of the consumer group
520
- * @param options Optional configuration
521
- */
522
- constructor(client: VQSClient, topicName: string, consumerGroupName: string, options?: ConsumerGroupOptions<T>);
523
- /**
524
- * Starts a background loop that periodically extends the visibility timeout for a message.
525
- * This prevents the message from becoming visible to other consumers while it's being processed.
526
- *
527
- * The extension loop runs every `refreshInterval` seconds and updates the message's
528
- * visibility timeout to `visibilityTimeout` seconds from the current time.
529
- *
530
- * @param messageId - The unique identifier of the message to extend visibility for
531
- * @param ticket - The receipt ticket that proves ownership of the message
532
- * @returns A function that when called will stop the extension loop
533
- *
534
- * @remarks
535
- * - The first extension attempt occurs after `refreshInterval` seconds, not immediately
536
- * - If an extension fails, the loop terminates with an error logged to console
537
- * - The returned stop function is idempotent - calling it multiple times is safe
538
- * - By default, the stop function returns immediately without waiting for in-flight
539
- * - Pass `true` to the stop function to wait for any in-flight extension to complete
540
- */
541
- private startVisibilityExtension;
542
- /**
543
- * Process a single message with the given handler
544
- * @param message The message to process
545
- * @param handler Function to process the message
546
- */
547
- private processMessage;
548
- /**
549
- * Start continuous processing of messages from the topic
550
- * @param signal AbortSignal to control when to stop processing
551
- * @param handler Function to process each message
552
- * @param options Processing options
553
- * @returns Promise that resolves when processing stops (due to signal or error)
554
- */
555
- subscribe(signal: AbortSignal, handler: MessageHandler<T>, options?: {
556
- pollingInterval?: number;
557
- }): Promise<void>;
558
- /**
559
- * Receive and process a specific message by its ID with full payload
560
- * @param messageId The ID of the message to receive and process
561
- * @param handler Function to process the message with full payload
562
- * @returns Promise that resolves when the message is processed or rejects with specific errors
563
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
564
- * @throws {MessageNotAvailableError} When the message exists but isn't available for processing (409)
565
- * @throws {MessageLockedError} When the message is temporarily locked (423)
566
- * @throws {FifoOrderingViolationError} When there's a FIFO ordering violation (409 with nextMessageId)
567
- * @throws {FailedDependencyError} When FIFO ordering is violated (424)
568
- * @throws {MessageCorruptedError} When the message data is corrupted
569
- * @throws {BadRequestError} When request parameters are invalid
570
- * @throws {UnauthorizedError} When authentication fails
571
- * @throws {ForbiddenError} When access is denied
572
- * @throws {InternalServerError} When server encounters an error
573
- */
574
- receiveMessage(messageId: string, handler: MessageHandler<T>): Promise<void>;
575
- /**
576
- * Receive and process the next available message from the queue
577
- * @param handler Function to process the message
578
- * @returns Promise that resolves when the message is processed or rejects with specific errors
579
- * @throws {QueueEmptyError} When no messages are available in the queue (204)
580
- * @throws {MessageLockedError} When the next message in a FIFO queue is locked (423)
581
- * @throws {BadRequestError} When request parameters are invalid
582
- * @throws {UnauthorizedError} When authentication fails
583
- * @throws {ForbiddenError} When access is denied
584
- * @throws {InternalServerError} When server encounters an error
585
- */
586
- receiveNextMessage(handler: MessageHandler<T>): Promise<void>;
587
- /**
588
- * Receive and process multiple next available messages from the queue
589
- * @param limit Number of messages to process (1-10)
590
- * @param handler Function to process each message
591
- * @returns Promise that resolves to an array of PromiseSettledResult (same as Promise.allSettled)
592
- * @throws {InvalidLimitError} When limit parameter is not between 1 and 10
593
- * @throws {QueueEmptyError} When no messages are available in the queue (204)
594
- * @throws {MessageLockedError} When the next message in a FIFO queue is locked (423)
595
- * @throws {BadRequestError} When request parameters are invalid
596
- * @throws {UnauthorizedError} When authentication fails
597
- * @throws {ForbiddenError} When access is denied
598
- * @throws {InternalServerError} When server encounters an error
599
- */
600
- receiveNextMessages(limit: number, handler: MessageHandler<T>): Promise<PromiseSettledResult<void>[]>;
601
- /**
602
- * Handle a specific message by its ID without downloading the payload (metadata only)
603
- * @param messageId The ID of the message to handle
604
- * @param handler Function to process the message metadata (payload will be void)
605
- * @returns Promise that resolves when the message is handled or rejects with specific errors
606
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
607
- * @throws {MessageNotAvailableError} When the message exists but isn't available for processing (409)
608
- * @throws {MessageLockedError} When the message is temporarily locked (423)
609
- * @throws {FifoOrderingViolationError} When there's a FIFO ordering violation (409 with nextMessageId)
610
- * @throws {FailedDependencyError} When FIFO ordering is violated (424)
611
- * @throws {MessageCorruptedError} When the message data is corrupted
612
- * @throws {BadRequestError} When request parameters are invalid
613
- * @throws {UnauthorizedError} When authentication fails
614
- * @throws {ForbiddenError} When access is denied
615
- * @throws {InternalServerError} When server encounters an error
616
- */
617
- handleMessage(messageId: string, handler: MessageHandler<void>): Promise<void>;
618
- /**
619
- * Get the consumer group name
620
- */
621
- get name(): string;
622
- /**
623
- * Get the topic name this consumer group is subscribed to
624
- */
625
- get topic(): string;
626
- }
627
-
275
+ declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
276
+ messageId: string;
277
+ }>;
628
278
  /**
629
- * A Topic represents a named channel for publishing messages in a pub/sub pattern
279
+ * Options for the receive function
630
280
  */
631
- declare class Topic<T = unknown> {
632
- private client;
633
- private topicName;
634
- private transport;
635
- /**
636
- * Create a new Topic instance
637
- * @param client VQSClient instance to use for API calls
638
- * @param topicName Name of the topic to work with
639
- * @param transport Optional serializer/deserializer for the payload (defaults to JSON)
640
- */
641
- constructor(client: VQSClient, topicName: string, transport?: Transport<T>);
642
- /**
643
- * Publish a message to the topic
644
- * @param payload The data to publish
645
- * @param options Optional publish options
646
- * @returns An object containing the message ID
647
- * @throws {BadRequestError} When request parameters are invalid
648
- * @throws {UnauthorizedError} When authentication fails
649
- * @throws {ForbiddenError} When access is denied (environment mismatch)
650
- * @throws {InternalServerError} When server encounters an error
651
- */
652
- publish(payload: T, options?: {
653
- idempotencyKey?: string;
654
- retentionSeconds?: number;
655
- callbacks?: Record<string, CallbackConfig>;
656
- }): Promise<{
657
- messageId: string;
658
- }>;
659
- /**
660
- * Create a consumer group for this topic
661
- * @param consumerGroupName Name of the consumer group
662
- * @param options Optional configuration for the consumer group
663
- * @returns A ConsumerGroup instance
664
- */
665
- consumerGroup<U = T>(consumerGroupName: string, options?: ConsumerGroupOptions<U>): ConsumerGroup<U>;
666
- /**
667
- * Get the topic name
668
- */
669
- get name(): string;
670
- /**
671
- * Get the transport used by this topic
672
- */
673
- get serializer(): Transport<T>;
281
+ interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
674
282
  }
675
-
676
283
  /**
677
- * Create a new Topic instance
678
- * @param client VQSClient instance to use for API calls
679
- * @param topicName Name of the topic
680
- * @param transport Optional serializer/deserializer for the payload (defaults to JSON)
681
- * @returns A Topic instance
284
+ * Receive a message from a topic (shorthand for topic and consumer group creation)
285
+ * Uses the default QueueClient with automatic OIDC token detection
286
+ * @param topicName Name of the topic to receive from
287
+ * @param consumerGroup Name of the consumer group
288
+ * @param handler Function to process the message
289
+ * @returns Promise that resolves when the message is processed
290
+ * @throws All the same errors as the underlying client methods
682
291
  */
683
- declare function createTopic<T = unknown>(client: VQSClient, topicName: string, transport?: Transport<T>): Topic<T>;
684
-
292
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
293
+ /**
294
+ * Receive a specific message by its ID with full payload
295
+ * @param topicName Name of the topic to receive from
296
+ * @param consumerGroup Name of the consumer group
297
+ * @param handler Function to process the message
298
+ * @param options Receive options with messageId specified
299
+ * @returns Promise that resolves when the message is processed
300
+ * @throws All the same errors as the underlying client methods
301
+ */
302
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
303
+ messageId: string;
304
+ skipPayload?: false | undefined;
305
+ }): Promise<void>;
685
306
  /**
686
- * VQS Callback utilities for handling incoming webhook payloads
307
+ * Receive a specific message by its ID without downloading the payload (metadata only)
308
+ * @param topicName Name of the topic to receive from
309
+ * @param consumerGroup Name of the consumer group
310
+ * @param handler Function to process the message metadata (payload will be void)
311
+ * @param options Receive options with messageId and skipPayload specified
312
+ * @returns Promise that resolves when the message is processed
313
+ * @throws All the same errors as the underlying client methods
687
314
  */
315
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
316
+ messageId: string;
317
+ skipPayload: true;
318
+ }): Promise<void>;
688
319
 
689
320
  /**
690
- * Parse a VQS callback request and extract the required information for receiveMessageById
321
+ * Configuration object with handlers for different topics and consumer groups
322
+ */
323
+ type CallbackHandlers = {
324
+ [topicName: string]: {
325
+ [consumerGroup: string]: MessageHandler;
326
+ };
327
+ };
328
+ /**
329
+ * Simplified queue callback handler for Next.js route handlers
330
+ *
331
+ * Automatically extracts queue information from CloudEvent format
332
+ * and routes to the appropriate handler based on topic and consumer group.
691
333
  *
692
- * @param request The incoming Request object from the VQS callback
693
- * @returns CallbackMessageOptions that can be used with receiveMessageById
694
- * @throws {InvalidCallbackError} When required VQS headers are missing or invalid
334
+ * @param handlers Object with topic-specific handlers organized by consumer groups
335
+ * @returns A Next.js route handler function
695
336
  *
696
337
  * @example
697
338
  * ```typescript
698
- * import { parseCallbackRequest } from 'vqs';
699
- *
700
- * // In your webhook handler
701
- * export async function POST(request: Request) {
702
- * try {
703
- * const callbackOptions = parseCallbackRequest(request);
704
- *
705
- * // Use with receiveMessageById
706
- * const message = await client.receiveMessageById({
707
- * ...callbackOptions,
708
- * visibilityTimeoutSeconds: 30
709
- * }, transport);
339
+ * // Single topic with multiple consumer groups
340
+ * export const POST = handleCallback({
341
+ * "image-processing": {
342
+ * "compress": (message, metadata) => console.log("Compressing image", message),
343
+ * "resize": (message, metadata) => console.log("Resizing image", message),
344
+ * }
345
+ * });
710
346
  *
711
- * // Process the message...
712
- * } catch (error) {
713
- * if (error instanceof InvalidCallbackError) {
714
- * return new Response('Invalid callback', { status: 400 });
715
- * }
716
- * throw error;
347
+ * // Multiple topics with consumer groups
348
+ * export const POST = handleCallback({
349
+ * "user-events": {
350
+ * "welcome": (user, metadata) => console.log("Welcoming user", user),
351
+ * "analytics": (user, metadata) => console.log("Tracking user", user),
352
+ * },
353
+ * "order-events": {
354
+ * "fulfillment": (order, metadata) => console.log("Fulfilling order", order),
355
+ * "notifications": (order, metadata) => console.log("Notifying order", order),
717
356
  * }
718
- * }
357
+ * });
719
358
  * ```
720
359
  */
721
- declare function parseCallbackRequest(request: Request): CallbackMessageOptions;
722
-
723
- declare function getVercelOidcToken(): Promise<string>;
360
+ declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
724
361
 
725
- export { BadRequestError, BufferTransport, type CallbackConfig, type CallbackMessageOptions, type ChangeVisibilityOptions, type ChangeVisibilityResponse, ConsumerGroup, type ConsumerGroupOptions, type DeleteMessageOptions, type DeleteMessageResponse, FailedDependencyError, type FifoOrderingError, FifoOrderingViolationError, ForbiddenError, InternalServerError, InvalidCallbackError, InvalidLimitError, JsonTransport, type Message, MessageCorruptedError, type MessageHandler, type MessageHandlerResult, MessageLockedError, MessageNotAvailableError, MessageNotFoundError, type MessageTimeoutResult, QueueEmptyError, type ReceiveMessageByIdOptions, type ReceiveMessageByIdResponse, type ReceiveMessagesOptions, type SendMessageOptions, type SendMessageResponse, StreamTransport, Topic, type Transport, UnauthorizedError, VQSClient, type VQSClientOptions, createTopic, getVercelOidcToken, parseCallbackRequest };
362
+ export { BadRequestError, BufferTransport, ForbiddenError, InternalServerError, InvalidLimitError, JsonTransport, type Message, MessageCorruptedError, type MessageHandler, type MessageHandlerResult, MessageLockedError, type MessageMetadata, MessageNotAvailableError, MessageNotFoundError, type MessageTimeoutResult, type PublishOptions, QueueEmptyError, type ReceiveOptions, type SendMessageOptions, type SendMessageResponse, type SendOptions, StreamTransport, type Transport, UnauthorizedError, handleCallback, receive, send };