@vercel/queue 0.0.0-alpha.12 → 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.ts 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,20 +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
- topicName: string;
156
- consumerGroup: string;
157
- }
158
251
  /**
159
252
  * Message handler function type
160
253
  */
161
- type MessageHandler<T = unknown> = (message: T, metadata: MessageMetadata) => Promise<MessageHandlerResult> | MessageHandlerResult;
254
+ type MessageHandler<T = unknown> = (message: Message<T>) => Promise<MessageHandlerResult> | MessageHandlerResult;
162
255
  /**
163
256
  * Options for creating a ConsumerGroup instance
164
257
  */
@@ -179,6 +272,44 @@ interface ConsumerGroupOptions<T = unknown> {
179
272
  */
180
273
  refreshInterval?: number;
181
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
+ }
182
313
  /**
183
314
  * Error thrown when a message is not found (404)
184
315
  */
@@ -192,6 +323,13 @@ declare class MessageNotFoundError extends Error {
192
323
  declare class MessageNotAvailableError extends Error {
193
324
  constructor(messageId: string, reason?: string);
194
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
+ }
195
333
  /**
196
334
  * Error thrown when message data is corrupted or can't be parsed
197
335
  */
@@ -205,7 +343,7 @@ declare class QueueEmptyError extends Error {
205
343
  constructor(queueName: string, consumerGroup: string);
206
344
  }
207
345
  /**
208
- * Error thrown when a message is temporarily locked (423)
346
+ * Error thrown when a message is temporarily locked in a FIFO queue (423)
209
347
  */
210
348
  declare class MessageLockedError extends Error {
211
349
  readonly retryAfter?: number;
@@ -229,6 +367,13 @@ declare class ForbiddenError extends Error {
229
367
  declare class BadRequestError extends Error {
230
368
  constructor(message: string);
231
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
+ }
232
377
  /**
233
378
  * Error thrown for internal server errors (500)
234
379
  */
@@ -241,160 +386,340 @@ declare class InternalServerError extends Error {
241
386
  declare class InvalidLimitError extends Error {
242
387
  constructor(limit: number, min?: number, max?: number);
243
388
  }
244
-
245
389
  /**
246
- * Options for the consume method
390
+ * Options extracted from a queue callback request
247
391
  */
248
- interface ConsumeOptions {
249
- /** The specific message ID to consume (if not provided, consumes next available message) */
250
- messageId?: string;
251
- /** Whether to skip downloading the payload (only allowed when messageId is provided) */
252
- skipPayload?: boolean;
253
- }
254
-
255
- /**
256
- * Options for the send function
257
- */
258
- interface SendOptions<T = unknown> extends PublishOptions {
392
+ interface CallbackMessageOptions {
259
393
  /**
260
- * Serializer/deserializer for the payload
261
- * @default JsonTransport instance
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
262
403
  */
263
- transport?: Transport<T>;
264
- }
265
- /**
266
- * Send a message to a topic (shorthand for topic creation and publishing)
267
- * Uses the default QueueClient with automatic OIDC token detection
268
- * @param topicName Name of the topic to send to
269
- * @param payload The data to send
270
- * @param options Optional send options including transport and publish settings
271
- * @returns Promise with the message ID
272
- * @throws {BadRequestError} When request parameters are invalid
273
- * @throws {UnauthorizedError} When authentication fails
274
- * @throws {ForbiddenError} When access is denied (environment mismatch)
275
- * @throws {InternalServerError} When server encounters an error
276
- */
277
- declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
278
404
  messageId: string;
279
- }>;
405
+ }
280
406
  /**
281
- * Options for the receive function
407
+ * Error thrown when queue callback headers are missing or invalid
282
408
  */
283
- interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
409
+ declare class InvalidCallbackError extends Error {
410
+ constructor(message: string);
284
411
  }
412
+
285
413
  /**
286
- * Receive a message from a topic (shorthand for topic and consumer group creation)
287
- * Uses the default QueueClient with automatic OIDC token detection
288
- * @param topicName Name of the topic to receive from
289
- * @param consumerGroup Name of the consumer group
290
- * @param handler Function to process the message
291
- * @returns Promise that resolves when the message is processed
292
- * @throws All the same errors as the underlying client methods
414
+ * Client for interacting with the Vercel Queue Service API
293
415
  */
294
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
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>;
503
+ }
504
+
295
505
  /**
296
- * Receive a specific message by its ID with full payload
297
- * @param topicName Name of the topic to receive from
298
- * @param consumerGroup Name of the consumer group
299
- * @param handler Function to process the message
300
- * @param options Receive options with messageId specified
301
- * @returns Promise that resolves when the message is processed
302
- * @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
303
507
  */
304
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
305
- messageId: string;
306
- skipPayload?: false | undefined;
307
- }): 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
+
308
628
  /**
309
- * Receive a specific message by its ID without downloading the payload (metadata only)
310
- * @param topicName Name of the topic to receive from
311
- * @param consumerGroup Name of the consumer group
312
- * @param handler Function to process the message metadata (payload will be void)
313
- * @param options Receive options with messageId and skipPayload specified
314
- * @returns Promise that resolves when the message is processed
315
- * @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
316
630
  */
317
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
318
- messageId: string;
319
- skipPayload: true;
320
- }): 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
+ }
321
675
 
322
676
  /**
323
- * Configuration object with handlers for different topics and consumer groups
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
324
682
  */
325
- type CallbackHandlers = {
326
- [topicName: string]: {
327
- [consumerGroup: string]: MessageHandler;
328
- };
329
- };
683
+ declare function createTopic<T = unknown>(client: QueueClient, topicName: string, transport?: Transport<T>): Topic<T>;
684
+
330
685
  /**
331
- * Parsed callback request information
686
+ * Queue Callback utilities for handling incoming webhook payloads
332
687
  */
333
- type ParsedCallbackRequest = {
334
- queueName: string;
335
- consumerGroup: string;
336
- messageId: string;
337
- };
688
+
338
689
  /**
339
- * Parse and validate callback request using CloudEvent specification
340
- *
341
- * Extracts queue information from CloudEvent format and validates
342
- * that all required fields are present.
690
+ * Parse a queue callback request and extract the required information for receiveMessageById
343
691
  *
344
- * @param request The incoming webhook request
345
- * @returns Parsed queue information
346
- * @throws Error if required fields are missing
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
347
695
  *
348
696
  * @example
349
697
  * ```typescript
350
- * // In Next.js API route
698
+ * import { parseCallbackRequest } from '@vercel/queue';
699
+ *
700
+ * // In your webhook handler
351
701
  * export async function POST(request: Request) {
352
702
  * try {
353
- * const { queueName, consumerGroup, messageId } = parseCallback(request);
703
+ * const callbackOptions = parseCallbackRequest(request);
354
704
  *
355
- * // Use the parsed information...
356
- * await myWorkflow.handleWebhook(queueName, consumerGroup, messageId);
705
+ * // Use with receiveMessageById
706
+ * const message = await client.receiveMessageById({
707
+ * ...callbackOptions,
708
+ * visibilityTimeoutSeconds: 30
709
+ * }, transport);
357
710
  *
358
- * return Response.json({ status: "success" });
711
+ * // Process the message...
359
712
  * } catch (error) {
360
- * return Response.json({ error: error.message }, { status: 400 });
713
+ * if (error instanceof InvalidCallbackError) {
714
+ * return new Response('Invalid callback', { status: 400 });
715
+ * }
716
+ * throw error;
361
717
  * }
362
718
  * }
363
719
  * ```
364
720
  */
365
- declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>;
366
- /**
367
- * Simplified queue callback handler for Next.js route handlers
368
- *
369
- * Automatically extracts queue information from CloudEvent format
370
- * and routes to the appropriate handler based on topic and consumer group.
371
- *
372
- * @param handlers Object with topic-specific handlers organized by consumer groups
373
- * @returns A Next.js route handler function
374
- *
375
- * @example
376
- * ```typescript
377
- * // Single topic with multiple consumer groups
378
- * export const POST = handleCallback({
379
- * "image-processing": {
380
- * "compress": (message, metadata) => console.log("Compressing image", message),
381
- * "resize": (message, metadata) => console.log("Resizing image", message),
382
- * }
383
- * });
384
- *
385
- * // Multiple topics with consumer groups
386
- * export const POST = handleCallback({
387
- * "user-events": {
388
- * "welcome": (user, metadata) => console.log("Welcoming user", user),
389
- * "analytics": (user, metadata) => console.log("Tracking user", user),
390
- * },
391
- * "order-events": {
392
- * "fulfillment": (order, metadata) => console.log("Fulfilling order", order),
393
- * "notifications": (order, metadata) => console.log("Notifying order", order),
394
- * }
395
- * });
396
- * ```
397
- */
398
- declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
721
+ declare function parseCallbackRequest(request: Request): CallbackMessageOptions;
722
+
723
+ declare function getVercelOidcToken(): Promise<string>;
399
724
 
400
- export { BadRequestError, BufferTransport, ForbiddenError, InternalServerError, InvalidLimitError, JsonTransport, type Message, MessageCorruptedError, type MessageHandler, type MessageHandlerResult, MessageLockedError, type MessageMetadata, MessageNotAvailableError, MessageNotFoundError, type MessageTimeoutResult, type ParsedCallbackRequest, type PublishOptions, QueueEmptyError, type ReceiveOptions, type SendMessageOptions, type SendMessageResponse, type SendOptions, StreamTransport, type Transport, UnauthorizedError, handleCallback, parseCallback, 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 };