@vercel/queue 0.0.0-alpha.39 → 0.0.0-alpha.40
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/README.md +367 -375
- package/dist/index.d.mts +603 -111
- package/dist/index.d.ts +603 -111
- package/dist/index.js +370 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +369 -234
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -21
- package/dist/callback-lq_sorrn.d.mts +0 -718
- package/dist/callback-lq_sorrn.d.ts +0 -718
- package/dist/nextjs-pages.d.mts +0 -68
- package/dist/nextjs-pages.d.ts +0 -68
- package/dist/nextjs-pages.js +0 -1438
- package/dist/nextjs-pages.js.map +0 -1
- package/dist/nextjs-pages.mjs +0 -1401
- package/dist/nextjs-pages.mjs.map +0 -1
- package/dist/web.d.mts +0 -60
- package/dist/web.d.ts +0 -60
- package/dist/web.js +0 -1457
- package/dist/web.js.map +0 -1
- package/dist/web.mjs +0 -1420
- package/dist/web.mjs.map +0 -1
|
@@ -1,718 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serializer/Deserializer interface for message payloads.
|
|
3
|
-
*
|
|
4
|
-
* Built-in implementations:
|
|
5
|
-
* - `JsonTransport` - JSON serialization (default, buffers entire payload)
|
|
6
|
-
* - `BufferTransport` - Binary data (buffers entire payload)
|
|
7
|
-
* - `StreamTransport` - Pass-through streaming (no buffering, ideal for large payloads)
|
|
8
|
-
*/
|
|
9
|
-
interface Transport<T = unknown> {
|
|
10
|
-
/**
|
|
11
|
-
* Serialize a value to a buffer or stream for transmission.
|
|
12
|
-
* The result is sent as the request body with the `contentType` header.
|
|
13
|
-
*/
|
|
14
|
-
serialize(value: T): Buffer | ReadableStream<Uint8Array>;
|
|
15
|
-
/**
|
|
16
|
-
* Deserialize a readable stream back to the original value.
|
|
17
|
-
* Called when receiving messages from the queue.
|
|
18
|
-
*/
|
|
19
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
20
|
-
/**
|
|
21
|
-
* Optional cleanup method for deserialized payloads that may contain resources.
|
|
22
|
-
* Called automatically by ConsumerGroup on error; manual cleanup required for direct client usage.
|
|
23
|
-
* @param payload The deserialized payload to clean up
|
|
24
|
-
*/
|
|
25
|
-
finalize?(payload: T): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* MIME type for this serialization format.
|
|
28
|
-
* Sent as the Content-Type header when publishing messages.
|
|
29
|
-
*/
|
|
30
|
-
contentType: string;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* JSON serializer/deserializer (default transport).
|
|
34
|
-
*
|
|
35
|
-
* Ideal for structured data. Buffers the entire payload in memory for parsing.
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* // Default usage
|
|
40
|
-
* await send("topic", { data: "example" });
|
|
41
|
-
*
|
|
42
|
-
* // With custom serialization
|
|
43
|
-
* const transport = new JsonTransport({
|
|
44
|
-
* replacer: (key, value) => key === "password" ? undefined : value,
|
|
45
|
-
* reviver: (key, value) => key === "date" ? new Date(value) : value,
|
|
46
|
-
* });
|
|
47
|
-
* await send("topic", { data: "example" }, { transport });
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
declare class JsonTransport<T = unknown> implements Transport<T> {
|
|
51
|
-
readonly contentType = "application/json";
|
|
52
|
-
readonly replacer?: Parameters<typeof JSON.stringify>[1];
|
|
53
|
-
readonly reviver?: Parameters<typeof JSON.parse>[1];
|
|
54
|
-
/**
|
|
55
|
-
* Create a new JsonTransport.
|
|
56
|
-
* @param options - Optional JSON serialization options
|
|
57
|
-
* @param options.replacer - Custom replacer for JSON.stringify
|
|
58
|
-
* @param options.reviver - Custom reviver for JSON.parse
|
|
59
|
-
*/
|
|
60
|
-
constructor(options?: {
|
|
61
|
-
replacer?: Parameters<typeof JSON.stringify>[1];
|
|
62
|
-
reviver?: Parameters<typeof JSON.parse>[1];
|
|
63
|
-
});
|
|
64
|
-
serialize(value: T): Buffer;
|
|
65
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Binary data serializer/deserializer.
|
|
69
|
-
*
|
|
70
|
-
* Ideal for binary data that fits in memory. Buffers the entire payload.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* const transport = new BufferTransport();
|
|
75
|
-
* await send("binary-topic", myBuffer, { transport });
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
declare class BufferTransport implements Transport<Buffer> {
|
|
79
|
-
readonly contentType = "application/octet-stream";
|
|
80
|
-
serialize(value: Buffer): Buffer;
|
|
81
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<Buffer>;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Pass-through stream serializer/deserializer.
|
|
85
|
-
*
|
|
86
|
-
* Ideal for large files and real-time streams. Does not buffer data in memory.
|
|
87
|
-
*
|
|
88
|
-
* **Important:** When using StreamTransport, you must call `finalize(payload)` when done
|
|
89
|
-
* processing to prevent resource leaks. ConsumerGroup handles this automatically;
|
|
90
|
-
* direct client usage requires manual cleanup.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* const transport = new StreamTransport();
|
|
95
|
-
*
|
|
96
|
-
* // Sending a stream
|
|
97
|
-
* await send("large-file", myReadableStream, { transport });
|
|
98
|
-
*
|
|
99
|
-
* // Receiving - cleanup handled by ConsumerGroup
|
|
100
|
-
* await receive("large-file", "processor", async (stream, meta) => {
|
|
101
|
-
* const reader = stream.getReader();
|
|
102
|
-
* // Process chunks...
|
|
103
|
-
* }, { transport });
|
|
104
|
-
*
|
|
105
|
-
* // Direct client usage - manual cleanup required
|
|
106
|
-
* try {
|
|
107
|
-
* for await (const msg of client.receiveMessages(options, transport)) {
|
|
108
|
-
* // Process stream...
|
|
109
|
-
* }
|
|
110
|
-
* } catch (error) {
|
|
111
|
-
* await transport.finalize(msg.payload); // Manual cleanup
|
|
112
|
-
* }
|
|
113
|
-
* ```
|
|
114
|
-
*/
|
|
115
|
-
declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
|
|
116
|
-
readonly contentType = "application/octet-stream";
|
|
117
|
-
serialize(value: ReadableStream<Uint8Array>): ReadableStream<Uint8Array>;
|
|
118
|
-
deserialize(stream: ReadableStream<Uint8Array>): Promise<ReadableStream<Uint8Array>>;
|
|
119
|
-
/**
|
|
120
|
-
* Consume any remaining stream data to prevent resource leaks.
|
|
121
|
-
* Called automatically by ConsumerGroup; manual call required for direct client usage.
|
|
122
|
-
*/
|
|
123
|
-
finalize(payload: ReadableStream<Uint8Array>): Promise<void>;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Vercel Queue Service client types
|
|
128
|
-
*/
|
|
129
|
-
|
|
130
|
-
interface QueueClientOptions {
|
|
131
|
-
/**
|
|
132
|
-
* Base URL for the Vercel Queue Service API.
|
|
133
|
-
* Can also be set via VERCEL_QUEUE_BASE_URL environment variable.
|
|
134
|
-
* @default "https://vercel-queue.com"
|
|
135
|
-
*/
|
|
136
|
-
baseUrl?: string;
|
|
137
|
-
/**
|
|
138
|
-
* Base path for API endpoints.
|
|
139
|
-
* Can also be set via VERCEL_QUEUE_BASE_PATH environment variable.
|
|
140
|
-
* @default "/api/v3/topic"
|
|
141
|
-
*/
|
|
142
|
-
basePath?: string;
|
|
143
|
-
/**
|
|
144
|
-
* Authentication token for the Vercel Queue Service API.
|
|
145
|
-
* If not provided, the client will attempt to get a token via OIDC
|
|
146
|
-
* when running in a Vercel Function environment.
|
|
147
|
-
*/
|
|
148
|
-
token?: string;
|
|
149
|
-
/**
|
|
150
|
-
* Custom headers to include in all requests.
|
|
151
|
-
*/
|
|
152
|
-
headers?: Record<string, string>;
|
|
153
|
-
/**
|
|
154
|
-
* Deployment ID to include in requests.
|
|
155
|
-
* Used for message routing and lease validation.
|
|
156
|
-
* @default process.env.VERCEL_DEPLOYMENT_ID if pinToDeployment is true
|
|
157
|
-
*/
|
|
158
|
-
deploymentId?: string;
|
|
159
|
-
/**
|
|
160
|
-
* Whether to pin messages to the current deployment when publishing.
|
|
161
|
-
* When true, sends VERCEL_DEPLOYMENT_ID from environment, ensuring
|
|
162
|
-
* messages are routed to consumers on the same deployment.
|
|
163
|
-
*
|
|
164
|
-
* - Only affects send/publish operations
|
|
165
|
-
* - Consume operations always send deployment ID in production
|
|
166
|
-
* - Ignored in development mode (deployment ID is never sent locally)
|
|
167
|
-
* @default true
|
|
168
|
-
*/
|
|
169
|
-
pinToDeployment?: boolean;
|
|
170
|
-
/**
|
|
171
|
-
* Serializer/deserializer for message payloads.
|
|
172
|
-
* Used for all send and receive operations.
|
|
173
|
-
* @default JsonTransport
|
|
174
|
-
*/
|
|
175
|
-
transport?: Transport;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Options for publishing messages to a topic.
|
|
179
|
-
*/
|
|
180
|
-
interface PublishOptions {
|
|
181
|
-
/**
|
|
182
|
-
* Unique key to prevent duplicate message submissions.
|
|
183
|
-
* Deduplication window: `min(message retention, 24 hours)`.
|
|
184
|
-
*/
|
|
185
|
-
idempotencyKey?: string;
|
|
186
|
-
/**
|
|
187
|
-
* Message retention time in seconds. After this period, the message expires.
|
|
188
|
-
* @default 86400 (24 hours)
|
|
189
|
-
* @minimum 60 (1 minute)
|
|
190
|
-
* @maximum 86400 (24 hours)
|
|
191
|
-
*/
|
|
192
|
-
retentionSeconds?: number;
|
|
193
|
-
/**
|
|
194
|
-
* Delay delivery of the message by this many seconds.
|
|
195
|
-
* The message will not be visible to consumers until the delay has passed.
|
|
196
|
-
* @default 0
|
|
197
|
-
* @minimum 0
|
|
198
|
-
* @maximum Value of retentionSeconds (delay cannot exceed retention)
|
|
199
|
-
*/
|
|
200
|
-
delaySeconds?: number;
|
|
201
|
-
/**
|
|
202
|
-
* Custom headers to include with this message.
|
|
203
|
-
* These headers are passed through to the VQS server.
|
|
204
|
-
*/
|
|
205
|
-
headers?: Record<string, string>;
|
|
206
|
-
}
|
|
207
|
-
interface SendMessageOptions<T = unknown> extends PublishOptions {
|
|
208
|
-
/**
|
|
209
|
-
* The topic/queue name to send the message to.
|
|
210
|
-
* Must match pattern: `[A-Za-z0-9_-]+`
|
|
211
|
-
*/
|
|
212
|
-
queueName: string;
|
|
213
|
-
/**
|
|
214
|
-
* The message payload. Will be serialized using the provided transport.
|
|
215
|
-
*/
|
|
216
|
-
payload: T;
|
|
217
|
-
}
|
|
218
|
-
interface SendMessageResponse {
|
|
219
|
-
/**
|
|
220
|
-
* The generated message ID
|
|
221
|
-
*/
|
|
222
|
-
messageId: string;
|
|
223
|
-
}
|
|
224
|
-
interface Message<T = unknown> {
|
|
225
|
-
/**
|
|
226
|
-
* Unique message identifier. Used for receive-by-ID operations.
|
|
227
|
-
*/
|
|
228
|
-
messageId: string;
|
|
229
|
-
/**
|
|
230
|
-
* The deserialized message payload.
|
|
231
|
-
* Note: If using StreamTransport, ensure proper cleanup by calling
|
|
232
|
-
* `transport.finalize(payload)` when done processing, especially in error cases.
|
|
233
|
-
*/
|
|
234
|
-
payload: T;
|
|
235
|
-
/**
|
|
236
|
-
* Number of times this message has been delivered.
|
|
237
|
-
* Starts at 1 for the first delivery, increments on each retry.
|
|
238
|
-
*/
|
|
239
|
-
deliveryCount: number;
|
|
240
|
-
/**
|
|
241
|
-
* Timestamp when the message was created/published.
|
|
242
|
-
*/
|
|
243
|
-
createdAt: Date;
|
|
244
|
-
/**
|
|
245
|
-
* MIME type of the message content.
|
|
246
|
-
* Set by the transport's `contentType` property during publish.
|
|
247
|
-
*/
|
|
248
|
-
contentType: string;
|
|
249
|
-
/**
|
|
250
|
-
* Receipt handle (lease token) for this message delivery.
|
|
251
|
-
* Required for delete and visibility extension operations.
|
|
252
|
-
* Valid only until the visibility timeout expires.
|
|
253
|
-
*/
|
|
254
|
-
receiptHandle: string;
|
|
255
|
-
}
|
|
256
|
-
interface ReceiveMessagesOptions<T = unknown> {
|
|
257
|
-
/**
|
|
258
|
-
* The topic/queue name to receive messages from.
|
|
259
|
-
* Must match pattern: `[A-Za-z0-9_-]+`
|
|
260
|
-
*/
|
|
261
|
-
queueName: string;
|
|
262
|
-
/**
|
|
263
|
-
* Consumer group name. Each consumer group maintains independent message state.
|
|
264
|
-
* Must match pattern: `[A-Za-z0-9_-]+`
|
|
265
|
-
*/
|
|
266
|
-
consumerGroup: string;
|
|
267
|
-
/**
|
|
268
|
-
* Time in seconds that messages will be invisible to other consumers after receipt.
|
|
269
|
-
* Set to 0 for immediate re-visibility (useful for peeking).
|
|
270
|
-
* @default 30
|
|
271
|
-
* @minimum 0
|
|
272
|
-
* @maximum 3600 (1 hour)
|
|
273
|
-
*/
|
|
274
|
-
visibilityTimeoutSeconds?: number;
|
|
275
|
-
/**
|
|
276
|
-
* Maximum number of messages to retrieve in a single request.
|
|
277
|
-
* @default 1
|
|
278
|
-
* @minimum 1
|
|
279
|
-
* @maximum 10
|
|
280
|
-
*/
|
|
281
|
-
limit?: number;
|
|
282
|
-
}
|
|
283
|
-
interface DeleteMessageOptions {
|
|
284
|
-
/**
|
|
285
|
-
* The topic/queue name the message belongs to.
|
|
286
|
-
*/
|
|
287
|
-
queueName: string;
|
|
288
|
-
/**
|
|
289
|
-
* Consumer group name.
|
|
290
|
-
*/
|
|
291
|
-
consumerGroup: string;
|
|
292
|
-
/**
|
|
293
|
-
* Receipt handle received when the message was consumed.
|
|
294
|
-
*/
|
|
295
|
-
receiptHandle: string;
|
|
296
|
-
}
|
|
297
|
-
interface DeleteMessageResponse {
|
|
298
|
-
/**
|
|
299
|
-
* Whether the message was successfully deleted
|
|
300
|
-
*/
|
|
301
|
-
deleted: boolean;
|
|
302
|
-
}
|
|
303
|
-
interface ChangeVisibilityOptions {
|
|
304
|
-
/**
|
|
305
|
-
* The topic/queue name the message belongs to.
|
|
306
|
-
*/
|
|
307
|
-
queueName: string;
|
|
308
|
-
/**
|
|
309
|
-
* Consumer group name.
|
|
310
|
-
*/
|
|
311
|
-
consumerGroup: string;
|
|
312
|
-
/**
|
|
313
|
-
* Receipt handle received when the message was consumed.
|
|
314
|
-
*/
|
|
315
|
-
receiptHandle: string;
|
|
316
|
-
/**
|
|
317
|
-
* New visibility timeout in seconds.
|
|
318
|
-
* Cannot extend beyond the message's original expiration time.
|
|
319
|
-
* @minimum 0
|
|
320
|
-
* @maximum 3600 (1 hour)
|
|
321
|
-
*/
|
|
322
|
-
visibilityTimeoutSeconds: number;
|
|
323
|
-
}
|
|
324
|
-
interface ChangeVisibilityResponse {
|
|
325
|
-
/**
|
|
326
|
-
* Whether the visibility was successfully updated
|
|
327
|
-
*/
|
|
328
|
-
success: boolean;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Message metadata provided to handlers
|
|
332
|
-
*/
|
|
333
|
-
interface MessageMetadata {
|
|
334
|
-
messageId: string;
|
|
335
|
-
deliveryCount: number;
|
|
336
|
-
createdAt: Date;
|
|
337
|
-
topicName: string;
|
|
338
|
-
consumerGroup: string;
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Message handler function type
|
|
342
|
-
*
|
|
343
|
-
* When a message is available, both `message` and `metadata` are provided.
|
|
344
|
-
* When the queue is empty, both `message` and `metadata` are `null`.
|
|
345
|
-
* This allows handlers to gracefully handle the empty queue case without
|
|
346
|
-
* catching exceptions.
|
|
347
|
-
*/
|
|
348
|
-
type MessageHandler<T = unknown> = (message: T | null, metadata: MessageMetadata | null) => Promise<void> | void;
|
|
349
|
-
/**
|
|
350
|
-
* Options for creating a ConsumerGroup instance.
|
|
351
|
-
*/
|
|
352
|
-
interface ConsumerGroupOptions<T = unknown> {
|
|
353
|
-
/**
|
|
354
|
-
* Time in seconds that messages will be invisible to other consumers after receipt.
|
|
355
|
-
* The ConsumerGroup will automatically extend this timeout during processing.
|
|
356
|
-
* @default 300 (5 minutes)
|
|
357
|
-
* @minimum 30
|
|
358
|
-
* @maximum 3600 (1 hour)
|
|
359
|
-
*/
|
|
360
|
-
visibilityTimeoutSeconds?: number;
|
|
361
|
-
}
|
|
362
|
-
interface ReceiveMessageByIdOptions<T = unknown> {
|
|
363
|
-
/**
|
|
364
|
-
* The topic/queue name to receive the message from.
|
|
365
|
-
* Must match pattern: `[A-Za-z0-9_-]+`
|
|
366
|
-
*/
|
|
367
|
-
queueName: string;
|
|
368
|
-
/**
|
|
369
|
-
* Consumer group name.
|
|
370
|
-
* Must match pattern: `[A-Za-z0-9_-]+`
|
|
371
|
-
*/
|
|
372
|
-
consumerGroup: string;
|
|
373
|
-
/**
|
|
374
|
-
* The specific message ID to retrieve.
|
|
375
|
-
*/
|
|
376
|
-
messageId: string;
|
|
377
|
-
/**
|
|
378
|
-
* Time in seconds that the message will be invisible to other consumers after receipt.
|
|
379
|
-
* @default 30
|
|
380
|
-
* @minimum 0
|
|
381
|
-
* @maximum 3600 (1 hour)
|
|
382
|
-
*/
|
|
383
|
-
visibilityTimeoutSeconds?: number;
|
|
384
|
-
}
|
|
385
|
-
interface ReceiveMessageByIdResponse<T = unknown> {
|
|
386
|
-
message: Message<T>;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Error thrown when a message does not exist or has expired.
|
|
390
|
-
*/
|
|
391
|
-
declare class MessageNotFoundError extends Error {
|
|
392
|
-
constructor(messageId: string);
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Error thrown when a message exists but cannot be processed.
|
|
396
|
-
* This can happen when the message is in the wrong state or already claimed by another consumer.
|
|
397
|
-
*/
|
|
398
|
-
declare class MessageNotAvailableError extends Error {
|
|
399
|
-
constructor(messageId: string, reason?: string);
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* Error thrown when message data is corrupted or can't be parsed
|
|
403
|
-
*/
|
|
404
|
-
declare class MessageCorruptedError extends Error {
|
|
405
|
-
constructor(messageId: string, reason: string);
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Error thrown when there are no messages available in the queue.
|
|
409
|
-
*/
|
|
410
|
-
declare class QueueEmptyError extends Error {
|
|
411
|
-
constructor(queueName: string, consumerGroup: string);
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Error thrown when a message is temporarily locked by another consumer.
|
|
415
|
-
* The message is currently being processed and cannot be claimed.
|
|
416
|
-
*/
|
|
417
|
-
declare class MessageLockedError extends Error {
|
|
418
|
-
/** Suggested retry delay in seconds, if provided by the server. */
|
|
419
|
-
readonly retryAfter?: number;
|
|
420
|
-
constructor(messageId: string, retryAfter?: number);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Error thrown when authentication fails.
|
|
424
|
-
* This typically means the token is missing, invalid, or expired.
|
|
425
|
-
*/
|
|
426
|
-
declare class UnauthorizedError extends Error {
|
|
427
|
-
constructor(message?: string);
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Error thrown when access is forbidden.
|
|
431
|
-
* This typically means the queue belongs to a different environment or project.
|
|
432
|
-
*/
|
|
433
|
-
declare class ForbiddenError extends Error {
|
|
434
|
-
constructor(message?: string);
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* Error thrown when request parameters are invalid.
|
|
438
|
-
*/
|
|
439
|
-
declare class BadRequestError extends Error {
|
|
440
|
-
constructor(message: string);
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Error thrown when the server encounters an unexpected error.
|
|
444
|
-
*/
|
|
445
|
-
declare class InternalServerError extends Error {
|
|
446
|
-
constructor(message?: string);
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Error thrown when the batch limit parameter is outside the valid range.
|
|
450
|
-
* The limit must be between 1 and 10 (inclusive).
|
|
451
|
-
*/
|
|
452
|
-
declare class InvalidLimitError extends Error {
|
|
453
|
-
constructor(limit: number, min?: number, max?: number);
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Error thrown when attempting to process a message that has already been successfully processed.
|
|
457
|
-
*/
|
|
458
|
-
declare class MessageAlreadyProcessedError extends Error {
|
|
459
|
-
constructor(messageId: string);
|
|
460
|
-
}
|
|
461
|
-
/**
|
|
462
|
-
* Error thrown when a duplicate idempotency key is detected.
|
|
463
|
-
* The message was already sent within the deduplication window.
|
|
464
|
-
*/
|
|
465
|
-
declare class DuplicateMessageError extends Error {
|
|
466
|
-
readonly idempotencyKey?: string;
|
|
467
|
-
constructor(message: string, idempotencyKey?: string);
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* Error thrown when consumer discovery fails.
|
|
471
|
-
* This typically means the deployment could not be reached or is not configured correctly.
|
|
472
|
-
*/
|
|
473
|
-
declare class ConsumerDiscoveryError extends Error {
|
|
474
|
-
readonly deploymentId?: string;
|
|
475
|
-
constructor(message: string, deploymentId?: string);
|
|
476
|
-
}
|
|
477
|
-
/**
|
|
478
|
-
* Error thrown when the consumer registry is not configured for the project.
|
|
479
|
-
*/
|
|
480
|
-
declare class ConsumerRegistryNotConfiguredError extends Error {
|
|
481
|
-
constructor(message?: string);
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
declare class QueueClient {
|
|
485
|
-
private baseUrl;
|
|
486
|
-
private basePath;
|
|
487
|
-
private customHeaders;
|
|
488
|
-
private providedToken?;
|
|
489
|
-
private defaultDeploymentId?;
|
|
490
|
-
private pinToDeployment;
|
|
491
|
-
private transport;
|
|
492
|
-
constructor(options?: QueueClientOptions);
|
|
493
|
-
getTransport(): Transport;
|
|
494
|
-
private getSendDeploymentId;
|
|
495
|
-
private getConsumeDeploymentId;
|
|
496
|
-
private getToken;
|
|
497
|
-
private buildUrl;
|
|
498
|
-
private fetch;
|
|
499
|
-
/**
|
|
500
|
-
* Send a message to a topic.
|
|
501
|
-
*
|
|
502
|
-
* @param options - Message options including queue name, payload, and optional settings
|
|
503
|
-
* @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
|
|
504
|
-
* @param options.payload - Message payload
|
|
505
|
-
* @param options.idempotencyKey - Optional deduplication key (dedup window: min(retention, 24h))
|
|
506
|
-
* @param options.retentionSeconds - Message TTL (default: 86400, min: 60, max: 86400)
|
|
507
|
-
* @param options.delaySeconds - Delivery delay (default: 0, max: retentionSeconds)
|
|
508
|
-
* @returns Promise with the generated messageId
|
|
509
|
-
* @throws {DuplicateMessageError} When idempotency key was already used
|
|
510
|
-
* @throws {ConsumerDiscoveryError} When consumer discovery fails
|
|
511
|
-
* @throws {ConsumerRegistryNotConfiguredError} When registry not configured
|
|
512
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
513
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
514
|
-
* @throws {ForbiddenError} When access is denied
|
|
515
|
-
* @throws {InternalServerError} When server encounters an error
|
|
516
|
-
*/
|
|
517
|
-
sendMessage<T = unknown>(options: SendMessageOptions<T>): Promise<SendMessageResponse>;
|
|
518
|
-
/**
|
|
519
|
-
* Receive messages from a topic as an async generator.
|
|
520
|
-
*
|
|
521
|
-
* When the queue is empty, the generator completes without yielding any
|
|
522
|
-
* messages. Callers should handle the case where no messages are yielded.
|
|
523
|
-
*
|
|
524
|
-
* @param options - Receive options
|
|
525
|
-
* @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
|
|
526
|
-
* @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
|
|
527
|
-
* @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
|
|
528
|
-
* @param options.limit - Max messages to retrieve (default: 1, min: 1, max: 10)
|
|
529
|
-
* @yields Message objects with payload, messageId, receiptHandle, etc.
|
|
530
|
-
* Yields nothing if queue is empty.
|
|
531
|
-
* @throws {InvalidLimitError} When limit is outside 1-10 range
|
|
532
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
533
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
534
|
-
* @throws {ForbiddenError} When access is denied
|
|
535
|
-
* @throws {InternalServerError} When server encounters an error
|
|
536
|
-
*/
|
|
537
|
-
receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>): AsyncGenerator<Message<T>, void, unknown>;
|
|
538
|
-
/**
|
|
539
|
-
* Receive a specific message by its ID.
|
|
540
|
-
*
|
|
541
|
-
* @param options - Receive options
|
|
542
|
-
* @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
|
|
543
|
-
* @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
|
|
544
|
-
* @param options.messageId - Message ID to retrieve
|
|
545
|
-
* @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
|
|
546
|
-
* @returns Promise with the message
|
|
547
|
-
* @throws {MessageNotFoundError} When message doesn't exist
|
|
548
|
-
* @throws {MessageNotAvailableError} When message is in wrong state or was a duplicate
|
|
549
|
-
* @throws {MessageAlreadyProcessedError} When message was already processed
|
|
550
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
551
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
552
|
-
* @throws {ForbiddenError} When access is denied
|
|
553
|
-
* @throws {InternalServerError} When server encounters an error
|
|
554
|
-
*/
|
|
555
|
-
receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>): Promise<ReceiveMessageByIdResponse<T>>;
|
|
556
|
-
/**
|
|
557
|
-
* Delete (acknowledge) a message after successful processing.
|
|
558
|
-
*
|
|
559
|
-
* @param options - Delete options
|
|
560
|
-
* @param options.queueName - Topic name
|
|
561
|
-
* @param options.consumerGroup - Consumer group name
|
|
562
|
-
* @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)
|
|
563
|
-
* @returns Promise indicating deletion success
|
|
564
|
-
* @throws {MessageNotFoundError} When receipt handle not found
|
|
565
|
-
* @throws {MessageNotAvailableError} When receipt handle invalid or message already processed
|
|
566
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
567
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
568
|
-
* @throws {ForbiddenError} When access is denied
|
|
569
|
-
* @throws {InternalServerError} When server encounters an error
|
|
570
|
-
*/
|
|
571
|
-
deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
|
|
572
|
-
/**
|
|
573
|
-
* Extend or change the visibility timeout of a message.
|
|
574
|
-
* Used to prevent message redelivery while still processing.
|
|
575
|
-
*
|
|
576
|
-
* @param options - Visibility options
|
|
577
|
-
* @param options.queueName - Topic name
|
|
578
|
-
* @param options.consumerGroup - Consumer group name
|
|
579
|
-
* @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)
|
|
580
|
-
* @param options.visibilityTimeoutSeconds - New timeout (min: 0, max: 3600, cannot exceed message expiration)
|
|
581
|
-
* @returns Promise indicating success
|
|
582
|
-
* @throws {MessageNotFoundError} When receipt handle not found
|
|
583
|
-
* @throws {MessageNotAvailableError} When receipt handle invalid or message already processed
|
|
584
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
585
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
586
|
-
* @throws {ForbiddenError} When access is denied
|
|
587
|
-
* @throws {InternalServerError} When server encounters an error
|
|
588
|
-
*/
|
|
589
|
-
changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
590
|
-
/**
|
|
591
|
-
* Alternative endpoint for changing message visibility timeout.
|
|
592
|
-
* Uses the /visibility path suffix and expects visibilityTimeoutSeconds in the body.
|
|
593
|
-
* Functionally equivalent to changeVisibility but follows an alternative API pattern.
|
|
594
|
-
*
|
|
595
|
-
* @param options - Options for changing visibility
|
|
596
|
-
* @returns Promise resolving to change visibility response
|
|
597
|
-
*/
|
|
598
|
-
changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* Core queue callback utilities for handling incoming webhook payloads
|
|
603
|
-
* from Vercel triggers using the CloudEvent specification.
|
|
604
|
-
*
|
|
605
|
-
* This module provides the framework-agnostic core. For framework-specific
|
|
606
|
-
* wrappers, see `@vercel/queue/web` and `@vercel/queue/nextjs/pages`.
|
|
607
|
-
*/
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Options for configuring `handleCallback` behavior.
|
|
611
|
-
*/
|
|
612
|
-
interface HandleCallbackOptions {
|
|
613
|
-
/**
|
|
614
|
-
* QueueClient instance to use for processing messages.
|
|
615
|
-
* If not provided, a default client is created with OIDC authentication
|
|
616
|
-
* and JsonTransport.
|
|
617
|
-
*/
|
|
618
|
-
client?: QueueClient;
|
|
619
|
-
/**
|
|
620
|
-
* Time in seconds that messages will be invisible to other consumers
|
|
621
|
-
* during processing. The handler will automatically extend this timeout
|
|
622
|
-
* while processing.
|
|
623
|
-
*
|
|
624
|
-
* @default 300 (5 minutes)
|
|
625
|
-
* @minimum 30
|
|
626
|
-
* @maximum 3600 (1 hour)
|
|
627
|
-
*/
|
|
628
|
-
visibilityTimeoutSeconds?: number;
|
|
629
|
-
}
|
|
630
|
-
declare const CLOUD_EVENT_TYPE_V1BETA = "com.vercel.queue.v1beta";
|
|
631
|
-
declare const CLOUD_EVENT_TYPE_V2BETA = "com.vercel.queue.v2beta";
|
|
632
|
-
/**
|
|
633
|
-
* Routing-only callback: the SDK must fetch the message by ID.
|
|
634
|
-
* Produced by v1beta structured mode and v2beta large-body mode.
|
|
635
|
-
*/
|
|
636
|
-
type ParsedCallbackV1 = {
|
|
637
|
-
queueName: string;
|
|
638
|
-
consumerGroup: string;
|
|
639
|
-
messageId: string;
|
|
640
|
-
};
|
|
641
|
-
/**
|
|
642
|
-
* Full-message callback: payload and receipt handle are inlined,
|
|
643
|
-
* so the SDK can process directly without an extra fetch.
|
|
644
|
-
* Produced by v2beta small-body mode.
|
|
645
|
-
*/
|
|
646
|
-
type ParsedCallbackV2 = {
|
|
647
|
-
queueName: string;
|
|
648
|
-
consumerGroup: string;
|
|
649
|
-
messageId: string;
|
|
650
|
-
receiptHandle: string;
|
|
651
|
-
deliveryCount?: number;
|
|
652
|
-
createdAt?: string;
|
|
653
|
-
contentType?: string;
|
|
654
|
-
visibilityDeadline?: string;
|
|
655
|
-
rawBody?: ReadableStream<Uint8Array>;
|
|
656
|
-
parsedPayload?: unknown;
|
|
657
|
-
};
|
|
658
|
-
type ParsedCallbackRequest = ParsedCallbackV1 | ParsedCallbackV2;
|
|
659
|
-
/**
|
|
660
|
-
* Parse a callback from a pre-parsed body and headers.
|
|
661
|
-
*
|
|
662
|
-
* For frameworks like Next.js Pages Router where the body has already been
|
|
663
|
-
* parsed, use this instead of {@link parseCallback}.
|
|
664
|
-
*
|
|
665
|
-
* Detects the CloudEvent version from the `ce-type` header:
|
|
666
|
-
* - `com.vercel.queue.v2beta`: binary content mode (metadata in headers,
|
|
667
|
-
* payload in body). For small messages, the body is attached as `parsedPayload`.
|
|
668
|
-
* - Otherwise: structured content mode (v1beta, entire CloudEvent in JSON body)
|
|
669
|
-
*
|
|
670
|
-
* @param body - The framework-parsed request body. Type depends on Content-Type
|
|
671
|
-
* and framework configuration:
|
|
672
|
-
* - v1beta: parsed CloudEvent JSON object
|
|
673
|
-
* - v2beta: the message payload as parsed by the framework (object, Buffer, or string)
|
|
674
|
-
* @param headers - HTTP headers
|
|
675
|
-
* @returns Parsed callback request with routing metadata and optional payload
|
|
676
|
-
*/
|
|
677
|
-
declare function parseRawCallback(body: unknown, headers: Record<string, string | string[] | undefined>): ParsedCallbackRequest;
|
|
678
|
-
/**
|
|
679
|
-
* Parse and validate a CloudEvent callback from a Web API `Request` object.
|
|
680
|
-
*
|
|
681
|
-
* Detects the CloudEvent version from the `ce-type` header:
|
|
682
|
-
* - `com.vercel.queue.v2beta`: binary content mode (metadata in headers,
|
|
683
|
-
* payload in body). For v2beta, the body is attached as `rawBody` (a
|
|
684
|
-
* ReadableStream) rather than being parsed.
|
|
685
|
-
* - Otherwise: structured content mode (v1beta, entire CloudEvent in JSON body)
|
|
686
|
-
*
|
|
687
|
-
* For frameworks that pre-parse the body (e.g. Next.js Pages Router),
|
|
688
|
-
* use {@link parseRawCallback} instead.
|
|
689
|
-
*/
|
|
690
|
-
declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>;
|
|
691
|
-
/**
|
|
692
|
-
* Core queue callback handler. Processes the message using the provided handler.
|
|
693
|
-
*
|
|
694
|
-
* This is the framework-agnostic core — it takes already-parsed request data
|
|
695
|
-
* and throws on errors. Framework-specific wrappers (in `@vercel/queue/web`
|
|
696
|
-
* and `@vercel/queue/nextjs/pages`) compose around this function to handle
|
|
697
|
-
* request parsing and response formatting.
|
|
698
|
-
*
|
|
699
|
-
* @param handler - Function to process the message payload and metadata
|
|
700
|
-
* @param request - A {@link ParsedCallbackV1} (routing metadata only, message
|
|
701
|
-
* fetched by ID) or {@link ParsedCallbackV2} (full message inlined, no fetch).
|
|
702
|
-
* @param options - Optional configuration (client, visibilityTimeoutSeconds)
|
|
703
|
-
* @throws {Error} If binary mode request has a receipt handle but no payload
|
|
704
|
-
* @throws {Error} If message processing fails
|
|
705
|
-
*
|
|
706
|
-
* @example
|
|
707
|
-
* ```typescript
|
|
708
|
-
* import { handleCallback, parseRawCallback } from "@vercel/queue";
|
|
709
|
-
*
|
|
710
|
-
* const parsed = parseRawCallback(body, headers);
|
|
711
|
-
* await handleCallback(async (message, metadata) => {
|
|
712
|
-
* console.log("Processing:", message);
|
|
713
|
-
* }, parsed);
|
|
714
|
-
* ```
|
|
715
|
-
*/
|
|
716
|
-
declare function handleCallback<T = unknown>(handler: MessageHandler<T>, request: ParsedCallbackRequest, options?: HandleCallbackOptions): Promise<void>;
|
|
717
|
-
|
|
718
|
-
export { BufferTransport as B, type ConsumerGroupOptions as C, DuplicateMessageError as D, ForbiddenError as F, type HandleCallbackOptions as H, InternalServerError as I, JsonTransport as J, type MessageHandler as M, type PublishOptions as P, QueueClient as Q, StreamTransport as S, type Transport as T, UnauthorizedError as U, CLOUD_EVENT_TYPE_V1BETA as a, CLOUD_EVENT_TYPE_V2BETA as b, parseRawCallback as c, type ParsedCallbackRequest as d, type ParsedCallbackV1 as e, type ParsedCallbackV2 as f, BadRequestError as g, handleCallback as h, ConsumerDiscoveryError as i, ConsumerRegistryNotConfiguredError as j, InvalidLimitError as k, MessageAlreadyProcessedError as l, MessageCorruptedError as m, MessageLockedError as n, MessageNotAvailableError as o, parseCallback as p, MessageNotFoundError as q, QueueEmptyError as r, type Message as s, type MessageMetadata as t, type QueueClientOptions as u, type SendMessageOptions as v, type SendMessageResponse as w };
|