@vercel/queue 0.0.0-alpha.34 → 0.0.0-alpha.35

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
@@ -1,5 +1,5 @@
1
- import { Q as QueueClientOptions, S as SendMessageOptions, T as Transport, a as SendMessageResponse, R as ReceiveMessagesOptions, M as Message, b as ReceiveMessageByIdOptions, c as ReceiveMessageByIdResponse, D as DeleteMessageOptions, d as DeleteMessageResponse, C as ChangeVisibilityOptions, e as ChangeVisibilityResponse, f as MessageHandler, P as PublishOptions, g as ConsumerGroupOptions } from './types-BHtRP_i_.mjs';
2
- export { i as BadRequestError, B as BufferTransport, j as ConcurrencyLimitError, k as ConsumerDiscoveryError, l as ConsumerRegistryNotConfiguredError, m as DuplicateMessageError, F as ForbiddenError, I as InternalServerError, n as InvalidLimitError, J as JsonTransport, o as MessageAlreadyProcessedError, p as MessageCorruptedError, q as MessageLockedError, u as MessageMetadata, r as MessageNotAvailableError, s as MessageNotFoundError, t as QueueEmptyError, h as StreamTransport, U as UnauthorizedError } from './types-BHtRP_i_.mjs';
1
+ import { Q as QueueClientOptions, S as SendMessageOptions, T as Transport, a as SendMessageResponse, R as ReceiveMessagesOptions, M as Message, b as ReceiveMessageByIdOptions, c as ReceiveMessageByIdResponse, D as DeleteMessageOptions, d as DeleteMessageResponse, C as ChangeVisibilityOptions, e as ChangeVisibilityResponse, f as MessageHandler, P as PublishOptions, g as ConsumerGroupOptions } from './types-BLG4ASI_.mjs';
2
+ export { i as BadRequestError, B as BufferTransport, j as ConcurrencyLimitError, k as ConsumerDiscoveryError, l as ConsumerRegistryNotConfiguredError, m as DuplicateMessageError, F as ForbiddenError, I as InternalServerError, n as InvalidLimitError, J as JsonTransport, o as MessageAlreadyProcessedError, p as MessageCorruptedError, q as MessageLockedError, u as MessageMetadata, r as MessageNotAvailableError, s as MessageNotFoundError, t as QueueEmptyError, h as StreamTransport, U as UnauthorizedError } from './types-BLG4ASI_.mjs';
3
3
 
4
4
  declare class QueueClient {
5
5
  private baseUrl;
@@ -14,10 +14,100 @@ declare class QueueClient {
14
14
  private getToken;
15
15
  private buildUrl;
16
16
  private fetch;
17
+ /**
18
+ * Send a message to a topic.
19
+ *
20
+ * @param options - Message options including queue name, payload, and optional settings
21
+ * @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
22
+ * @param options.payload - Message payload
23
+ * @param options.idempotencyKey - Optional deduplication key (dedup window: min(retention, 24h))
24
+ * @param options.retentionSeconds - Message TTL (default: 86400, min: 60, max: 86400)
25
+ * @param options.delaySeconds - Delivery delay (default: 0, max: retentionSeconds)
26
+ * @param transport - Serializer for the payload
27
+ * @returns Promise with the generated messageId
28
+ * @throws {DuplicateMessageError} When idempotency key was already used
29
+ * @throws {ConsumerDiscoveryError} When consumer discovery fails
30
+ * @throws {ConsumerRegistryNotConfiguredError} When registry not configured
31
+ * @throws {BadRequestError} When parameters are invalid
32
+ * @throws {UnauthorizedError} When authentication fails
33
+ * @throws {ForbiddenError} When access is denied
34
+ * @throws {InternalServerError} When server encounters an error
35
+ */
17
36
  sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
37
+ /**
38
+ * Receive messages from a topic as an async generator.
39
+ *
40
+ * @param options - Receive options
41
+ * @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
42
+ * @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
43
+ * @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
44
+ * @param options.limit - Max messages to retrieve (default: 1, min: 1, max: 10)
45
+ * @param options.maxConcurrency - Max in-flight messages (default: unlimited, min: 1)
46
+ * @param transport - Deserializer for message payloads
47
+ * @yields Message objects with payload, messageId, receiptHandle, etc.
48
+ * @throws {QueueEmptyError} When no messages available
49
+ * @throws {InvalidLimitError} When limit is outside 1-10 range
50
+ * @throws {ConcurrencyLimitError} When maxConcurrency exceeded
51
+ * @throws {BadRequestError} When parameters are invalid
52
+ * @throws {UnauthorizedError} When authentication fails
53
+ * @throws {ForbiddenError} When access is denied
54
+ * @throws {InternalServerError} When server encounters an error
55
+ */
18
56
  receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
57
+ /**
58
+ * Receive a specific message by its ID.
59
+ *
60
+ * @param options - Receive options
61
+ * @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
62
+ * @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
63
+ * @param options.messageId - Message ID to retrieve
64
+ * @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
65
+ * @param options.maxConcurrency - Max in-flight messages (default: unlimited, min: 1)
66
+ * @param transport - Deserializer for the message payload
67
+ * @returns Promise with the message
68
+ * @throws {MessageNotFoundError} When message doesn't exist
69
+ * @throws {MessageNotAvailableError} When message is in wrong state or was a duplicate
70
+ * @throws {MessageAlreadyProcessedError} When message was already processed
71
+ * @throws {ConcurrencyLimitError} When maxConcurrency exceeded
72
+ * @throws {BadRequestError} When parameters are invalid
73
+ * @throws {UnauthorizedError} When authentication fails
74
+ * @throws {ForbiddenError} When access is denied
75
+ * @throws {InternalServerError} When server encounters an error
76
+ */
19
77
  receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T>>;
78
+ /**
79
+ * Delete (acknowledge) a message after successful processing.
80
+ *
81
+ * @param options - Delete options
82
+ * @param options.queueName - Topic name
83
+ * @param options.consumerGroup - Consumer group name
84
+ * @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)
85
+ * @returns Promise indicating deletion success
86
+ * @throws {MessageNotFoundError} When receipt handle not found
87
+ * @throws {MessageNotAvailableError} When receipt handle invalid or message already processed
88
+ * @throws {BadRequestError} When parameters are invalid
89
+ * @throws {UnauthorizedError} When authentication fails
90
+ * @throws {ForbiddenError} When access is denied
91
+ * @throws {InternalServerError} When server encounters an error
92
+ */
20
93
  deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
94
+ /**
95
+ * Extend or change the visibility timeout of a message.
96
+ * Used to prevent message redelivery while still processing.
97
+ *
98
+ * @param options - Visibility options
99
+ * @param options.queueName - Topic name
100
+ * @param options.consumerGroup - Consumer group name
101
+ * @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)
102
+ * @param options.visibilityTimeoutSeconds - New timeout (min: 0, max: 3600, cannot exceed message expiration)
103
+ * @returns Promise indicating success
104
+ * @throws {MessageNotFoundError} When receipt handle not found
105
+ * @throws {MessageNotAvailableError} When receipt handle invalid or message already processed
106
+ * @throws {BadRequestError} When parameters are invalid
107
+ * @throws {UnauthorizedError} When authentication fails
108
+ * @throws {ForbiddenError} When access is denied
109
+ * @throws {InternalServerError} When server encounters an error
110
+ */
21
111
  changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
22
112
  /**
23
113
  * Alternative endpoint for changing message visibility timeout.
@@ -42,6 +132,24 @@ type CallbackHandlers = {
42
132
  [consumerGroup: string]: MessageHandler;
43
133
  };
44
134
  };
135
+ /**
136
+ * Options for handleCallback.
137
+ */
138
+ interface HandleCallbackOptions {
139
+ /**
140
+ * QueueClient instance to use for processing messages.
141
+ * If not provided, a default client is created with OIDC authentication.
142
+ */
143
+ client?: QueueClient;
144
+ /**
145
+ * Time in seconds that messages will be invisible to other consumers during processing.
146
+ * The handler will automatically extend this timeout while processing.
147
+ * @default 30
148
+ * @minimum 0
149
+ * @maximum 3600 (1 hour)
150
+ */
151
+ visibilityTimeoutSeconds?: number;
152
+ }
45
153
  /**
46
154
  * Parsed callback request information
47
155
  */
@@ -79,39 +187,41 @@ type ParsedCallbackRequest = {
79
187
  */
80
188
  declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>;
81
189
  /**
82
- * Simplified queue callback handler for Next.js route handlers
190
+ * Simplified queue callback handler for Next.js route handlers.
83
191
  *
84
192
  * Automatically extracts queue information from CloudEvent format
85
193
  * and routes to the appropriate handler based on topic and consumer group.
86
194
  *
87
- * @param handlers Object with topic-specific handlers organized by consumer groups
88
- * @param client Optional QueueClient instance to use. If not provided, a default client is created.
195
+ * @param handlers - Object with topic-specific handlers organized by consumer groups
196
+ * @param options - Optional configuration
197
+ * @param options.client - QueueClient instance (default: new client with OIDC auth)
198
+ * @param options.visibilityTimeoutSeconds - Message lock duration (default: 30, max: 3600)
89
199
  * @returns A Next.js route handler function
90
200
  *
91
201
  * @example
92
202
  * ```typescript
93
- * // Single topic with multiple consumer groups
203
+ * // Basic usage
94
204
  * export const POST = handleCallback({
95
205
  * "image-processing": {
96
- * "compress": (message, metadata) => console.log("Compressing image", message),
97
- * "resize": (message, metadata) => console.log("Resizing image", message),
206
+ * "compress": (message, metadata) => console.log("Compressing", message),
207
+ * "resize": (message, metadata) => console.log("Resizing", message),
98
208
  * }
99
209
  * });
100
210
  *
101
- * // Multiple topics with consumer groups
211
+ * // With custom visibility timeout for long-running handlers
102
212
  * export const POST = handleCallback({
103
- * "user-events": {
104
- * "welcome": (user, metadata) => console.log("Welcoming user", user),
105
- * "analytics": (user, metadata) => console.log("Tracking user", user),
106
- * },
107
- * "order-events": {
108
- * "fulfillment": (order, metadata) => console.log("Fulfilling order", order),
109
- * "notifications": (order, metadata) => console.log("Notifying order", order),
213
+ * "video-processing": {
214
+ * "transcode": async (video, metadata) => {
215
+ * // Long-running transcoding operation
216
+ * await transcodeVideo(video);
217
+ * },
110
218
  * }
219
+ * }, {
220
+ * visibilityTimeoutSeconds: 300, // 5 minutes
111
221
  * });
112
222
  * ```
113
223
  */
114
- declare function handleCallback(handlers: CallbackHandlers, client?: QueueClient): (request: Request) => Promise<Response>;
224
+ declare function handleCallback(handlers: CallbackHandlers, options?: HandleCallbackOptions): (request: Request) => Promise<Response>;
115
225
 
116
226
  /**
117
227
  * Client - User-facing wrapper for the Vercel Queue Service
@@ -166,22 +276,35 @@ declare class Client {
166
276
  messageId: string;
167
277
  }>;
168
278
  /**
169
- * Create a callback handler for processing queue messages
170
- * Returns a Next.js route handler function that routes messages to appropriate handlers
171
- * @param handlers Object with topic-specific handlers organized by consumer groups
279
+ * Create a callback handler for processing queue messages.
280
+ * Returns a Next.js route handler function that routes messages to appropriate handlers.
281
+ *
282
+ * @param handlers - Object with topic-specific handlers organized by consumer groups
283
+ * @param options - Optional configuration
284
+ * @param options.visibilityTimeoutSeconds - Message lock duration (default: 30, max: 3600)
172
285
  * @returns A Next.js route handler function
173
286
  *
174
287
  * @example
175
288
  * ```typescript
289
+ * // Basic usage
176
290
  * export const POST = client.handleCallback({
177
291
  * "user-events": {
178
292
  * "welcome": (user, metadata) => console.log("Welcoming user", user),
179
293
  * "analytics": (user, metadata) => console.log("Tracking user", user),
180
294
  * },
181
295
  * });
296
+ *
297
+ * // With custom visibility timeout
298
+ * export const POST = client.handleCallback({
299
+ * "video-processing": {
300
+ * "transcode": async (video) => await transcodeVideo(video),
301
+ * },
302
+ * }, {
303
+ * visibilityTimeoutSeconds: 300, // 5 minutes for long operations
304
+ * });
182
305
  * ```
183
306
  */
184
- handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
307
+ handleCallback(handlers: CallbackHandlers, options?: Omit<HandleCallbackOptions, "client">): (request: Request) => Promise<Response>;
185
308
  }
186
309
 
187
310
  /**
@@ -193,76 +316,107 @@ interface ConsumeOptions {
193
316
  }
194
317
 
195
318
  /**
196
- * Options for the send function
319
+ * Options for the send function.
197
320
  */
198
321
  interface SendOptions<T = unknown> extends PublishOptions {
199
322
  /**
200
- * Serializer/deserializer for the payload
201
- * @default JsonTransport instance
323
+ * Serializer for the payload.
324
+ * @default JsonTransport
202
325
  */
203
326
  transport?: Transport<T>;
204
327
  /**
205
- * QueueClient instance to use for sending the message
206
- * If not provided, a default client is created
328
+ * QueueClient instance to use for sending the message.
329
+ * If not provided, a default client is created with OIDC authentication.
207
330
  */
208
331
  client?: QueueClient;
209
332
  }
210
333
  /**
211
- * Send a message to a topic (shorthand for topic creation and publishing)
212
- * Uses the default QueueClient with automatic OIDC token detection, or a provided client
213
- * @param topicName Name of the topic to send to
214
- * @param payload The data to send
215
- * @param options Optional send options including transport, publish settings, and client
216
- * @returns Promise with the message ID
217
- * @throws {BadRequestError} When request parameters are invalid
334
+ * Send a message to a topic.
335
+ *
336
+ * Uses the default QueueClient with automatic OIDC token detection, or a provided client.
337
+ *
338
+ * @param topicName - Name of the topic (pattern: `[A-Za-z0-9_-]+`)
339
+ * @param payload - The data to send
340
+ * @param options - Optional send options
341
+ * @param options.idempotencyKey - Deduplication key (dedup window: min(retention, 24h))
342
+ * @param options.retentionSeconds - Message TTL (default: 86400, min: 60, max: 86400)
343
+ * @param options.delaySeconds - Delivery delay (default: 0, max: retentionSeconds)
344
+ * @param options.transport - Payload serializer (default: JsonTransport)
345
+ * @param options.client - Custom QueueClient instance
346
+ * @returns Promise with the generated messageId
347
+ * @throws {DuplicateMessageError} When idempotency key was already used
348
+ * @throws {BadRequestError} When parameters are invalid
218
349
  * @throws {UnauthorizedError} When authentication fails
219
- * @throws {ForbiddenError} When access is denied (environment mismatch)
350
+ * @throws {ForbiddenError} When access is denied
220
351
  * @throws {InternalServerError} When server encounters an error
221
352
  *
222
353
  * @example
223
354
  * ```typescript
224
- * // Using default client (OIDC token)
355
+ * // Basic usage (OIDC auth)
225
356
  * await send("my-topic", { hello: "world" });
226
357
  *
358
+ * // With options
359
+ * await send("my-topic", payload, {
360
+ * idempotencyKey: "unique-key",
361
+ * retentionSeconds: 3600, // 1 hour TTL
362
+ * delaySeconds: 60, // Delay 1 minute
363
+ * });
364
+ *
227
365
  * // Using custom client
228
366
  * const client = new QueueClient({ token: "my-token" });
229
- * await send("my-topic", { hello: "world" }, { client });
367
+ * await send("my-topic", payload, { client });
230
368
  * ```
231
369
  */
232
370
  declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
233
371
  messageId: string;
234
372
  }>;
235
373
  /**
236
- * Options for the receive function
374
+ * Options for the receive function.
237
375
  */
238
376
  interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
239
377
  /**
240
- * QueueClient instance to use for receiving the message
241
- * If not provided, a default client is created
378
+ * QueueClient instance to use for receiving the message.
379
+ * If not provided, a default client is created with OIDC authentication.
242
380
  */
243
381
  client?: QueueClient;
244
382
  }
245
383
  /**
246
- * Receive a message from a topic (shorthand for topic and consumer group creation)
247
- * Uses the default QueueClient with automatic OIDC token detection
248
- * @param topicName Name of the topic to receive from
249
- * @param consumerGroup Name of the consumer group
250
- * @param handler Function to process the message
251
- * @returns Promise that resolves when the message is processed
252
- * @throws All the same errors as the underlying client methods
384
+ * Receive a message from a topic.
385
+ *
386
+ * Shorthand for creating a topic and consumer group. The message is automatically:
387
+ * - Locked with the configured visibility timeout
388
+ * - Kept alive via periodic visibility extensions during processing
389
+ * - Deleted upon successful handler completion
390
+ *
391
+ * @param topicName - Name of the topic (pattern: `[A-Za-z0-9_-]+`)
392
+ * @param consumerGroup - Name of the consumer group (pattern: `[A-Za-z0-9_-]+`)
393
+ * @param handler - Function to process the message payload and metadata
394
+ * @param options - Optional receive options
395
+ * @param options.visibilityTimeoutSeconds - Message lock duration (default: 30, max: 3600)
396
+ * @param options.visibilityRefreshInterval - Lock refresh interval (default: visibilityTimeout / 3)
397
+ * @param options.transport - Payload deserializer (default: JsonTransport)
398
+ * @returns Promise that resolves when the message is processed and deleted
399
+ * @throws {QueueEmptyError} When no messages available
400
+ * @throws {ConcurrencyLimitError} When maxConcurrency exceeded
253
401
  */
254
402
  declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
255
403
  /**
256
- * Receive a specific message by its ID
257
- * @param topicName Name of the topic to receive from
258
- * @param consumerGroup Name of the consumer group
259
- * @param handler Function to process the message
260
- * @param options Receive options with messageId specified
261
- * @returns Promise that resolves when the message is processed
262
- * @throws All the same errors as the underlying client methods
404
+ * Receive a specific message by its ID.
405
+ *
406
+ * Used for targeted message processing, typically from webhook callbacks.
407
+ *
408
+ * @param topicName - Name of the topic (pattern: `[A-Za-z0-9_-]+`)
409
+ * @param consumerGroup - Name of the consumer group (pattern: `[A-Za-z0-9_-]+`)
410
+ * @param handler - Function to process the message payload and metadata
411
+ * @param options - Receive options with messageId
412
+ * @param options.messageId - Specific message ID to consume
413
+ * @returns Promise that resolves when the message is processed and deleted
414
+ * @throws {MessageNotFoundError} When message doesn't exist
415
+ * @throws {MessageNotAvailableError} When message in wrong state
416
+ * @throws {MessageAlreadyProcessedError} When already processed
263
417
  */
264
418
  declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
265
419
  messageId: string;
266
420
  }): Promise<void>;
267
421
 
268
- export { type CallbackHandlers, Client, Message, MessageHandler, type ParsedCallbackRequest, PublishOptions, QueueClientOptions, type ReceiveOptions, SendMessageOptions, SendMessageResponse, type SendOptions, Transport, handleCallback, parseCallback, receive, send };
422
+ export { type CallbackHandlers, Client, type HandleCallbackOptions, Message, MessageHandler, type ParsedCallbackRequest, PublishOptions, QueueClientOptions, type ReceiveOptions, SendMessageOptions, SendMessageResponse, type SendOptions, Transport, handleCallback, parseCallback, receive, send };