@vercel/queue 0.0.0-alpha.1

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.
@@ -0,0 +1,725 @@
1
+ /**
2
+ * Serializer/Deserializer interface for message payloads
3
+ */
4
+ interface Transport<T = unknown> {
5
+ /**
6
+ * Serialize a value to a buffer or stream for transmission
7
+ */
8
+ serialize(value: T): Buffer | ReadableStream<Uint8Array>;
9
+ /**
10
+ * Deserialize a readable stream back to the original value
11
+ */
12
+ deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
13
+ /**
14
+ * Optional cleanup method for deserialized payloads that may contain resources
15
+ * Should be called when the payload is no longer needed, especially in error cases
16
+ * @param payload The deserialized payload to clean up
17
+ */
18
+ finalize?(payload: T): Promise<void>;
19
+ /**
20
+ * MIME type for this serialization format
21
+ */
22
+ contentType: string;
23
+ }
24
+ /**
25
+ * Built-in JSON serializer/deserializer
26
+ * This implementation reads the entire stream into memory for JSON parsing
27
+ */
28
+ declare class JsonTransport<T = unknown> implements Transport<T> {
29
+ readonly contentType = "application/json";
30
+ serialize(value: T): Buffer;
31
+ deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
32
+ }
33
+ /**
34
+ * Built-in Buffer serializer/deserializer (reads entire stream into a Buffer)
35
+ */
36
+ declare class BufferTransport implements Transport<Buffer> {
37
+ readonly contentType = "application/octet-stream";
38
+ serialize(value: Buffer): Buffer;
39
+ deserialize(stream: ReadableStream<Uint8Array>): Promise<Buffer>;
40
+ }
41
+ /**
42
+ * Stream serializer/deserializer (pass-through for streaming binary data)
43
+ * This is ideal for large payloads that don't need to be buffered in memory
44
+ *
45
+ * IMPORTANT: When using StreamTransport, you must call finalize(payload) when done
46
+ * processing the message to prevent resource leaks, especially in error cases.
47
+ * ConsumerGroup handles this automatically, but direct VQSClient usage requires manual cleanup.
48
+ *
49
+ * Example usage:
50
+ * ```typescript
51
+ * const transport = new StreamTransport();
52
+ * try {
53
+ * for await (const message of client.receiveMessages(options, transport)) {
54
+ * // Process the stream...
55
+ * const reader = message.payload.getReader();
56
+ * // ... handle stream data
57
+ * }
58
+ * } catch (error) {
59
+ * // Cleanup is handled automatically by ConsumerGroup
60
+ * // or manually: await transport.finalize(message.payload);
61
+ * }
62
+ */
63
+ declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
64
+ readonly contentType = "application/octet-stream";
65
+ serialize(value: ReadableStream<Uint8Array>): ReadableStream<Uint8Array>;
66
+ deserialize(stream: ReadableStream<Uint8Array>): Promise<ReadableStream<Uint8Array>>;
67
+ finalize(payload: ReadableStream<Uint8Array>): Promise<void>;
68
+ }
69
+
70
+ /**
71
+ * Vercel Queue Service client types
72
+ */
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
+ /**
87
+ * Callback configuration for a consumer group
88
+ */
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;
112
+ /**
113
+ * Unique key to prevent duplicate message submissions
114
+ * @default random UUID
115
+ */
116
+ idempotencyKey?: string;
117
+ /**
118
+ * Message retention time in seconds
119
+ * @default 86400 (24 hours)
120
+ * @min 60
121
+ * @max 86400
122
+ */
123
+ retentionSeconds?: number;
124
+ /**
125
+ * Consumer group callback configurations
126
+ * Format: { consumerGroup: { url, delay?, frequency? } }
127
+ */
128
+ callbacks?: Record<string, CallbackConfig>;
129
+ }
130
+ interface SendMessageResponse {
131
+ /**
132
+ * The generated message ID
133
+ */
134
+ messageId: string;
135
+ }
136
+ interface Message<T = unknown> {
137
+ /**
138
+ * The message ID
139
+ */
140
+ messageId: string;
141
+ /**
142
+ * The deserialized message payload
143
+ * Note: If using streaming transports, ensure proper cleanup by calling transport.finalize(payload)
144
+ * when done processing, especially in error cases
145
+ */
146
+ payload: T;
147
+ /**
148
+ * Number of times this message has been delivered
149
+ */
150
+ deliveryCount: number;
151
+ /**
152
+ * Timestamp when the message was created
153
+ */
154
+ timestamp: string;
155
+ /**
156
+ * MIME type of the message content
157
+ */
158
+ contentType: string;
159
+ /**
160
+ * Unique ticket for this message delivery (required for delete/patch operations)
161
+ */
162
+ ticket: string;
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
+ }
238
+ /**
239
+ * Result indicating the message should be timed out for retry later
240
+ */
241
+ interface MessageTimeoutResult {
242
+ /**
243
+ * Time in seconds before the message becomes visible again
244
+ */
245
+ timeoutSeconds: number;
246
+ }
247
+ /**
248
+ * Result returned by message handlers
249
+ */
250
+ type MessageHandlerResult = void | MessageTimeoutResult;
251
+ /**
252
+ * Message handler function type
253
+ */
254
+ type MessageHandler<T = unknown> = (message: Message<T>) => Promise<MessageHandlerResult> | MessageHandlerResult;
255
+ /**
256
+ * Options for creating a ConsumerGroup instance
257
+ */
258
+ interface ConsumerGroupOptions<T = unknown> {
259
+ /**
260
+ * Serializer/deserializer for the payload
261
+ * @default JsonTransport instance
262
+ */
263
+ transport?: Transport<T>;
264
+ /**
265
+ * Time in seconds that messages will be invisible to other consumers
266
+ * @default 30
267
+ */
268
+ visibilityTimeoutSeconds?: number;
269
+ /**
270
+ * How often to refresh the visibility timeout during processing (in seconds)
271
+ * @default 10
272
+ */
273
+ refreshInterval?: number;
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
+ }
313
+ /**
314
+ * Error thrown when a message is not found (404)
315
+ */
316
+ declare class MessageNotFoundError extends Error {
317
+ constructor(messageId: string);
318
+ }
319
+ /**
320
+ * Error thrown when a message is not available for processing (409)
321
+ * This can happen when the message is in the wrong state, already claimed, etc.
322
+ */
323
+ declare class MessageNotAvailableError extends Error {
324
+ constructor(messageId: string, reason?: string);
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
+ }
333
+ /**
334
+ * Error thrown when message data is corrupted or can't be parsed
335
+ */
336
+ declare class MessageCorruptedError extends Error {
337
+ constructor(messageId: string, reason: string);
338
+ }
339
+ /**
340
+ * Error thrown when there are no messages available in the queue (204)
341
+ */
342
+ declare class QueueEmptyError extends Error {
343
+ constructor(queueName: string, consumerGroup: string);
344
+ }
345
+ /**
346
+ * Error thrown when a message is temporarily locked in a FIFO queue (423)
347
+ */
348
+ declare class MessageLockedError extends Error {
349
+ readonly retryAfter?: number;
350
+ constructor(messageId: string, retryAfter?: number);
351
+ }
352
+ /**
353
+ * Error thrown when authentication fails (401)
354
+ */
355
+ declare class UnauthorizedError extends Error {
356
+ constructor(message?: string);
357
+ }
358
+ /**
359
+ * Error thrown when access is forbidden (403)
360
+ */
361
+ declare class ForbiddenError extends Error {
362
+ constructor(message?: string);
363
+ }
364
+ /**
365
+ * Error thrown for bad requests (400)
366
+ */
367
+ declare class BadRequestError extends Error {
368
+ constructor(message: string);
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
+ }
377
+ /**
378
+ * Error thrown for internal server errors (500)
379
+ */
380
+ declare class InternalServerError extends Error {
381
+ constructor(message?: string);
382
+ }
383
+ /**
384
+ * Error thrown when batch limit parameter is invalid
385
+ */
386
+ declare class InvalidLimitError extends Error {
387
+ constructor(limit: number, min?: number, max?: number);
388
+ }
389
+ /**
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
408
+ */
409
+ declare class InvalidCallbackError extends Error {
410
+ constructor(message: string);
411
+ }
412
+
413
+ /**
414
+ * Client for interacting with the Vercel Queue Service API
415
+ */
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>>;
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
+
505
+ /**
506
+ * A ConsumerGroup represents a named group of consumers that process messages from a topic
507
+ */
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
+
628
+ /**
629
+ * A Topic represents a named channel for publishing messages in a pub/sub pattern
630
+ */
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>;
674
+ }
675
+
676
+ /**
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
682
+ */
683
+ declare function createTopic<T = unknown>(client: VQSClient, topicName: string, transport?: Transport<T>): Topic<T>;
684
+
685
+ /**
686
+ * VQS Callback utilities for handling incoming webhook payloads
687
+ */
688
+
689
+ /**
690
+ * Parse a VQS callback request and extract the required information for receiveMessageById
691
+ *
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
695
+ *
696
+ * @example
697
+ * ```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);
710
+ *
711
+ * // Process the message...
712
+ * } catch (error) {
713
+ * if (error instanceof InvalidCallbackError) {
714
+ * return new Response('Invalid callback', { status: 400 });
715
+ * }
716
+ * throw error;
717
+ * }
718
+ * }
719
+ * ```
720
+ */
721
+ declare function parseCallbackRequest(request: Request): CallbackMessageOptions;
722
+
723
+ declare function getVercelOidcToken(): Promise<string>;
724
+
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 };