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

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
@@ -71,10 +71,44 @@ declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
71
71
  * Vercel Queue Service client types
72
72
  */
73
73
 
74
+ interface QueueClientOptions {
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
+ }
74
86
  /**
75
- * Shared options for publishing messages
87
+ * Callback configuration for a consumer group
76
88
  */
77
- interface PublishOptions {
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;
78
112
  /**
79
113
  * Unique key to prevent duplicate message submissions
80
114
  * @default random UUID
@@ -87,16 +121,11 @@ interface PublishOptions {
87
121
  * @max 86400
88
122
  */
89
123
  retentionSeconds?: number;
90
- }
91
- interface SendMessageOptions<T = unknown> extends PublishOptions {
92
- /**
93
- * The queue name to send the message to
94
- */
95
- queueName: string;
96
124
  /**
97
- * The message payload
125
+ * Consumer group callback configurations
126
+ * Format: { consumerGroup: { url, delay?, frequency? } }
98
127
  */
99
- payload: T;
128
+ callbacks?: Record<string, CallbackConfig>;
100
129
  }
101
130
  interface SendMessageResponse {
102
131
  /**
@@ -120,9 +149,9 @@ interface Message<T = unknown> {
120
149
  */
121
150
  deliveryCount: number;
122
151
  /**
123
- * When the message was created
152
+ * Timestamp when the message was created
124
153
  */
125
- createdAt: Date;
154
+ timestamp: string;
126
155
  /**
127
156
  * MIME type of the message content
128
157
  */
@@ -132,6 +161,80 @@ interface Message<T = unknown> {
132
161
  */
133
162
  ticket: string;
134
163
  }
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
+ }
135
238
  /**
136
239
  * Result indicating the message should be timed out for retry later
137
240
  */
@@ -145,18 +248,10 @@ interface MessageTimeoutResult {
145
248
  * Result returned by message handlers
146
249
  */
147
250
  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
- }
156
251
  /**
157
252
  * Message handler function type
158
253
  */
159
- type MessageHandler<T = unknown> = (message: T, metadata: MessageMetadata) => Promise<MessageHandlerResult> | MessageHandlerResult;
254
+ type MessageHandler<T = unknown> = (message: Message<T>) => Promise<MessageHandlerResult> | MessageHandlerResult;
160
255
  /**
161
256
  * Options for creating a ConsumerGroup instance
162
257
  */
@@ -177,6 +272,44 @@ interface ConsumerGroupOptions<T = unknown> {
177
272
  */
178
273
  refreshInterval?: number;
179
274
  }
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
+ }
180
313
  /**
181
314
  * Error thrown when a message is not found (404)
182
315
  */
@@ -190,6 +323,13 @@ declare class MessageNotFoundError extends Error {
190
323
  declare class MessageNotAvailableError extends Error {
191
324
  constructor(messageId: string, reason?: string);
192
325
  }
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
+ }
193
333
  /**
194
334
  * Error thrown when message data is corrupted or can't be parsed
195
335
  */
@@ -203,7 +343,7 @@ declare class QueueEmptyError extends Error {
203
343
  constructor(queueName: string, consumerGroup: string);
204
344
  }
205
345
  /**
206
- * Error thrown when a message is temporarily locked (423)
346
+ * Error thrown when a message is temporarily locked in a FIFO queue (423)
207
347
  */
208
348
  declare class MessageLockedError extends Error {
209
349
  readonly retryAfter?: number;
@@ -227,6 +367,13 @@ declare class ForbiddenError extends Error {
227
367
  declare class BadRequestError extends Error {
228
368
  constructor(message: string);
229
369
  }
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
+ }
230
377
  /**
231
378
  * Error thrown for internal server errors (500)
232
379
  */
@@ -239,124 +386,340 @@ declare class InternalServerError extends Error {
239
386
  declare class InvalidLimitError extends Error {
240
387
  constructor(limit: number, min?: number, max?: number);
241
388
  }
242
-
243
389
  /**
244
- * Options for the consume method
390
+ * Options extracted from a queue callback request
245
391
  */
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;
251
- }
252
-
253
- /**
254
- * Options for the send function
255
- */
256
- interface SendOptions<T = unknown> extends PublishOptions {
392
+ interface CallbackMessageOptions {
257
393
  /**
258
- * Serializer/deserializer for the payload
259
- * @default JsonTransport instance
394
+ * The queue name extracted from Vqs-Queue-Name header
260
395
  */
261
- transport?: Transport<T>;
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;
262
405
  }
263
406
  /**
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
407
+ * Error thrown when queue callback headers are missing or invalid
274
408
  */
275
- declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
276
- messageId: string;
277
- }>;
409
+ declare class InvalidCallbackError extends Error {
410
+ constructor(message: string);
411
+ }
412
+
278
413
  /**
279
- * Options for the receive function
414
+ * Client for interacting with the Vercel Queue Service API
280
415
  */
281
- interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
416
+ declare class QueueClient {
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: QueueClientOptions);
424
+ /**
425
+ * Create a QueueClient 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 QueueClient instance
430
+ */
431
+ static fromVercelFunction(baseUrl?: string): Promise<QueueClient>;
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>>;
479
+ /**
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
501
+ */
502
+ changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
282
503
  }
504
+
283
505
  /**
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
506
+ * A ConsumerGroup represents a named group of consumers that process messages from a topic
291
507
  */
292
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
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 QueueClient 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: QueueClient, 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
+
293
628
  /**
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
629
+ * A Topic represents a named channel for publishing messages in a pub/sub pattern
301
630
  */
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>;
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 QueueClient 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: QueueClient, 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>;
674
+ }
675
+
306
676
  /**
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
677
+ * Create a new Topic instance
678
+ * @param client QueueClient 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
314
682
  */
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>;
683
+ declare function createTopic<T = unknown>(client: QueueClient, topicName: string, transport?: Transport<T>): Topic<T>;
319
684
 
320
685
  /**
321
- * Configuration object with handlers for different topics and consumer groups
686
+ * Queue Callback utilities for handling incoming webhook payloads
322
687
  */
323
- type CallbackHandlers = {
324
- [topicName: string]: {
325
- [consumerGroup: string]: MessageHandler;
326
- };
327
- };
688
+
328
689
  /**
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.
690
+ * Parse a queue callback request and extract the required information for receiveMessageById
333
691
  *
334
- * @param handlers Object with topic-specific handlers organized by consumer groups
335
- * @returns A Next.js route handler function
692
+ * @param request The incoming Request object from the queue callback
693
+ * @returns CallbackMessageOptions that can be used with receiveMessageById
694
+ * @throws {InvalidCallbackError} When required queue headers are missing or invalid
336
695
  *
337
696
  * @example
338
697
  * ```typescript
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
- * });
698
+ * import { parseCallbackRequest } from '@vercel/queue';
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);
346
710
  *
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),
711
+ * // Process the message...
712
+ * } catch (error) {
713
+ * if (error instanceof InvalidCallbackError) {
714
+ * return new Response('Invalid callback', { status: 400 });
715
+ * }
716
+ * throw error;
356
717
  * }
357
- * });
718
+ * }
358
719
  * ```
359
720
  */
360
- declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
721
+ declare function parseCallbackRequest(request: Request): CallbackMessageOptions;
722
+
723
+ declare function getVercelOidcToken(): Promise<string>;
361
724
 
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 };
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, QueueClient, type QueueClientOptions, QueueEmptyError, type ReceiveMessageByIdOptions, type ReceiveMessageByIdResponse, type ReceiveMessagesOptions, type SendMessageOptions, type SendMessageResponse, StreamTransport, Topic, type Transport, UnauthorizedError, createTopic, getVercelOidcToken, parseCallbackRequest };