@vercel/queue 0.0.0-alpha.2 → 0.0.0-alpha.22
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 +236 -754
- package/bin/local-discover.js +188 -0
- package/dist/index.d.mts +153 -472
- package/dist/index.d.ts +153 -472
- package/dist/index.js +513 -535
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +509 -526
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -5
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ interface Transport<T = unknown> {
|
|
|
27
27
|
*/
|
|
28
28
|
declare class JsonTransport<T = unknown> implements Transport<T> {
|
|
29
29
|
readonly contentType = "application/json";
|
|
30
|
+
readonly replacer?: Parameters<typeof JSON.parse>[1];
|
|
31
|
+
readonly reviver?: Parameters<typeof JSON.parse>[1];
|
|
32
|
+
constructor(options?: {
|
|
33
|
+
replacer?: Parameters<typeof JSON.parse>[1];
|
|
34
|
+
reviver?: Parameters<typeof JSON.parse>[1];
|
|
35
|
+
});
|
|
30
36
|
serialize(value: T): Buffer;
|
|
31
37
|
deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;
|
|
32
38
|
}
|
|
@@ -71,44 +77,10 @@ declare class StreamTransport implements Transport<ReadableStream<Uint8Array>> {
|
|
|
71
77
|
* Vercel Queue Service client types
|
|
72
78
|
*/
|
|
73
79
|
|
|
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
|
-
}
|
|
86
80
|
/**
|
|
87
|
-
*
|
|
81
|
+
* Shared options for publishing messages
|
|
88
82
|
*/
|
|
89
|
-
interface
|
|
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;
|
|
83
|
+
interface PublishOptions {
|
|
112
84
|
/**
|
|
113
85
|
* Unique key to prevent duplicate message submissions
|
|
114
86
|
* @default random UUID
|
|
@@ -121,11 +93,16 @@ interface SendMessageOptions<T = unknown> {
|
|
|
121
93
|
* @max 86400
|
|
122
94
|
*/
|
|
123
95
|
retentionSeconds?: number;
|
|
96
|
+
}
|
|
97
|
+
interface SendMessageOptions<T = unknown> extends PublishOptions {
|
|
98
|
+
/**
|
|
99
|
+
* The queue name to send the message to
|
|
100
|
+
*/
|
|
101
|
+
queueName: string;
|
|
124
102
|
/**
|
|
125
|
-
*
|
|
126
|
-
* Format: { consumerGroup: { url, delay?, frequency? } }
|
|
103
|
+
* The message payload
|
|
127
104
|
*/
|
|
128
|
-
|
|
105
|
+
payload: T;
|
|
129
106
|
}
|
|
130
107
|
interface SendMessageResponse {
|
|
131
108
|
/**
|
|
@@ -149,9 +126,9 @@ interface Message<T = unknown> {
|
|
|
149
126
|
*/
|
|
150
127
|
deliveryCount: number;
|
|
151
128
|
/**
|
|
152
|
-
*
|
|
129
|
+
* When the message was created
|
|
153
130
|
*/
|
|
154
|
-
|
|
131
|
+
createdAt: Date;
|
|
155
132
|
/**
|
|
156
133
|
* MIME type of the message content
|
|
157
134
|
*/
|
|
@@ -161,80 +138,6 @@ interface Message<T = unknown> {
|
|
|
161
138
|
*/
|
|
162
139
|
ticket: string;
|
|
163
140
|
}
|
|
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
141
|
/**
|
|
239
142
|
* Result indicating the message should be timed out for retry later
|
|
240
143
|
*/
|
|
@@ -248,10 +151,20 @@ interface MessageTimeoutResult {
|
|
|
248
151
|
* Result returned by message handlers
|
|
249
152
|
*/
|
|
250
153
|
type MessageHandlerResult = void | MessageTimeoutResult;
|
|
154
|
+
/**
|
|
155
|
+
* Message metadata provided to handlers
|
|
156
|
+
*/
|
|
157
|
+
interface MessageMetadata {
|
|
158
|
+
messageId: string;
|
|
159
|
+
deliveryCount: number;
|
|
160
|
+
createdAt: Date;
|
|
161
|
+
topicName: string;
|
|
162
|
+
consumerGroup: string;
|
|
163
|
+
}
|
|
251
164
|
/**
|
|
252
165
|
* Message handler function type
|
|
253
166
|
*/
|
|
254
|
-
type MessageHandler<T = unknown> = (message:
|
|
167
|
+
type MessageHandler<T = unknown> = (message: T, metadata: MessageMetadata) => Promise<MessageHandlerResult> | MessageHandlerResult;
|
|
255
168
|
/**
|
|
256
169
|
* Options for creating a ConsumerGroup instance
|
|
257
170
|
*/
|
|
@@ -272,44 +185,6 @@ interface ConsumerGroupOptions<T = unknown> {
|
|
|
272
185
|
*/
|
|
273
186
|
refreshInterval?: number;
|
|
274
187
|
}
|
|
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
188
|
/**
|
|
314
189
|
* Error thrown when a message is not found (404)
|
|
315
190
|
*/
|
|
@@ -323,13 +198,6 @@ declare class MessageNotFoundError extends Error {
|
|
|
323
198
|
declare class MessageNotAvailableError extends Error {
|
|
324
199
|
constructor(messageId: string, reason?: string);
|
|
325
200
|
}
|
|
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
201
|
/**
|
|
334
202
|
* Error thrown when message data is corrupted or can't be parsed
|
|
335
203
|
*/
|
|
@@ -343,7 +211,7 @@ declare class QueueEmptyError extends Error {
|
|
|
343
211
|
constructor(queueName: string, consumerGroup: string);
|
|
344
212
|
}
|
|
345
213
|
/**
|
|
346
|
-
* Error thrown when a message is temporarily locked
|
|
214
|
+
* Error thrown when a message is temporarily locked (423)
|
|
347
215
|
*/
|
|
348
216
|
declare class MessageLockedError extends Error {
|
|
349
217
|
readonly retryAfter?: number;
|
|
@@ -367,13 +235,6 @@ declare class ForbiddenError extends Error {
|
|
|
367
235
|
declare class BadRequestError extends Error {
|
|
368
236
|
constructor(message: string);
|
|
369
237
|
}
|
|
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
238
|
/**
|
|
378
239
|
* Error thrown for internal server errors (500)
|
|
379
240
|
*/
|
|
@@ -386,340 +247,160 @@ declare class InternalServerError extends Error {
|
|
|
386
247
|
declare class InvalidLimitError extends Error {
|
|
387
248
|
constructor(limit: number, min?: number, max?: number);
|
|
388
249
|
}
|
|
250
|
+
|
|
389
251
|
/**
|
|
390
|
-
* Options
|
|
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 queue callback headers are missing or invalid
|
|
252
|
+
* Options for the consume method
|
|
408
253
|
*/
|
|
409
|
-
|
|
410
|
-
|
|
254
|
+
interface ConsumeOptions {
|
|
255
|
+
/** The specific message ID to consume (if not provided, consumes next available message) */
|
|
256
|
+
messageId?: string;
|
|
257
|
+
/** Whether to skip downloading the payload (only allowed when messageId is provided) */
|
|
258
|
+
skipPayload?: boolean;
|
|
411
259
|
}
|
|
412
260
|
|
|
413
261
|
/**
|
|
414
|
-
*
|
|
262
|
+
* Options for the send function
|
|
415
263
|
*/
|
|
416
|
-
|
|
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>;
|
|
264
|
+
interface SendOptions<T = unknown> extends PublishOptions {
|
|
457
265
|
/**
|
|
458
|
-
*
|
|
459
|
-
* @
|
|
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
|
|
266
|
+
* Serializer/deserializer for the payload
|
|
267
|
+
* @default JsonTransport instance
|
|
501
268
|
*/
|
|
502
|
-
|
|
269
|
+
transport?: Transport<T>;
|
|
503
270
|
}
|
|
504
|
-
|
|
505
271
|
/**
|
|
506
|
-
*
|
|
272
|
+
* Send a message to a topic (shorthand for topic creation and publishing)
|
|
273
|
+
* Uses the default QueueClient with automatic OIDC token detection
|
|
274
|
+
* @param topicName Name of the topic to send to
|
|
275
|
+
* @param payload The data to send
|
|
276
|
+
* @param options Optional send options including transport and publish settings
|
|
277
|
+
* @returns Promise with the message ID
|
|
278
|
+
* @throws {BadRequestError} When request parameters are invalid
|
|
279
|
+
* @throws {UnauthorizedError} When authentication fails
|
|
280
|
+
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
281
|
+
* @throws {InternalServerError} When server encounters an error
|
|
507
282
|
*/
|
|
508
|
-
declare
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
283
|
+
declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
|
|
284
|
+
messageId: string;
|
|
285
|
+
}>;
|
|
628
286
|
/**
|
|
629
|
-
*
|
|
287
|
+
* Options for the receive function
|
|
630
288
|
*/
|
|
631
|
-
|
|
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>;
|
|
289
|
+
interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
|
|
674
290
|
}
|
|
675
|
-
|
|
676
291
|
/**
|
|
677
|
-
*
|
|
678
|
-
*
|
|
679
|
-
* @param topicName Name of the topic
|
|
680
|
-
* @param
|
|
681
|
-
* @
|
|
292
|
+
* Receive a message from a topic (shorthand for topic and consumer group creation)
|
|
293
|
+
* Uses the default QueueClient with automatic OIDC token detection
|
|
294
|
+
* @param topicName Name of the topic to receive from
|
|
295
|
+
* @param consumerGroup Name of the consumer group
|
|
296
|
+
* @param handler Function to process the message
|
|
297
|
+
* @returns Promise that resolves when the message is processed
|
|
298
|
+
* @throws All the same errors as the underlying client methods
|
|
682
299
|
*/
|
|
683
|
-
declare function
|
|
684
|
-
|
|
300
|
+
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
|
|
685
301
|
/**
|
|
686
|
-
*
|
|
302
|
+
* Receive a specific message by its ID with full payload
|
|
303
|
+
* @param topicName Name of the topic to receive from
|
|
304
|
+
* @param consumerGroup Name of the consumer group
|
|
305
|
+
* @param handler Function to process the message
|
|
306
|
+
* @param options Receive options with messageId specified
|
|
307
|
+
* @returns Promise that resolves when the message is processed
|
|
308
|
+
* @throws All the same errors as the underlying client methods
|
|
687
309
|
*/
|
|
310
|
+
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
|
|
311
|
+
messageId: string;
|
|
312
|
+
skipPayload?: false | undefined;
|
|
313
|
+
}): Promise<void>;
|
|
314
|
+
/**
|
|
315
|
+
* Receive a specific message by its ID without downloading the payload (metadata only)
|
|
316
|
+
* @param topicName Name of the topic to receive from
|
|
317
|
+
* @param consumerGroup Name of the consumer group
|
|
318
|
+
* @param handler Function to process the message metadata (payload will be void)
|
|
319
|
+
* @param options Receive options with messageId and skipPayload specified
|
|
320
|
+
* @returns Promise that resolves when the message is processed
|
|
321
|
+
* @throws All the same errors as the underlying client methods
|
|
322
|
+
*/
|
|
323
|
+
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
|
|
324
|
+
messageId: string;
|
|
325
|
+
skipPayload: true;
|
|
326
|
+
}): Promise<void>;
|
|
688
327
|
|
|
689
328
|
/**
|
|
690
|
-
*
|
|
329
|
+
* Configuration object with handlers for different topics and consumer groups
|
|
330
|
+
*/
|
|
331
|
+
type CallbackHandlers = {
|
|
332
|
+
[topicName: string]: {
|
|
333
|
+
[consumerGroup: string]: MessageHandler;
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Parsed callback request information
|
|
338
|
+
*/
|
|
339
|
+
type ParsedCallbackRequest = {
|
|
340
|
+
queueName: string;
|
|
341
|
+
consumerGroup: string;
|
|
342
|
+
messageId: string;
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* Parse and validate callback request using CloudEvent specification
|
|
346
|
+
*
|
|
347
|
+
* Extracts queue information from CloudEvent format and validates
|
|
348
|
+
* that all required fields are present.
|
|
691
349
|
*
|
|
692
|
-
* @param request The incoming
|
|
693
|
-
* @returns
|
|
694
|
-
* @throws
|
|
350
|
+
* @param request The incoming webhook request
|
|
351
|
+
* @returns Parsed queue information
|
|
352
|
+
* @throws Error if required fields are missing
|
|
695
353
|
*
|
|
696
354
|
* @example
|
|
697
355
|
* ```typescript
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* // In your webhook handler
|
|
356
|
+
* // In Next.js API route
|
|
701
357
|
* export async function POST(request: Request) {
|
|
702
358
|
* try {
|
|
703
|
-
* const
|
|
359
|
+
* const { queueName, consumerGroup, messageId } = parseCallback(request);
|
|
704
360
|
*
|
|
705
|
-
* // Use
|
|
706
|
-
*
|
|
707
|
-
* ...callbackOptions,
|
|
708
|
-
* visibilityTimeoutSeconds: 30
|
|
709
|
-
* }, transport);
|
|
361
|
+
* // Use the parsed information...
|
|
362
|
+
* await myWorkflow.handleWebhook(queueName, consumerGroup, messageId);
|
|
710
363
|
*
|
|
711
|
-
*
|
|
364
|
+
* return Response.json({ status: "success" });
|
|
712
365
|
* } catch (error) {
|
|
713
|
-
*
|
|
714
|
-
* return new Response('Invalid callback', { status: 400 });
|
|
715
|
-
* }
|
|
716
|
-
* throw error;
|
|
366
|
+
* return Response.json({ error: error.message }, { status: 400 });
|
|
717
367
|
* }
|
|
718
368
|
* }
|
|
719
369
|
* ```
|
|
720
370
|
*/
|
|
721
|
-
declare function
|
|
722
|
-
|
|
723
|
-
|
|
371
|
+
declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>;
|
|
372
|
+
/**
|
|
373
|
+
* Simplified queue callback handler for Next.js route handlers
|
|
374
|
+
*
|
|
375
|
+
* Automatically extracts queue information from CloudEvent format
|
|
376
|
+
* and routes to the appropriate handler based on topic and consumer group.
|
|
377
|
+
*
|
|
378
|
+
* @param handlers Object with topic-specific handlers organized by consumer groups
|
|
379
|
+
* @returns A Next.js route handler function
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```typescript
|
|
383
|
+
* // Single topic with multiple consumer groups
|
|
384
|
+
* export const POST = handleCallback({
|
|
385
|
+
* "image-processing": {
|
|
386
|
+
* "compress": (message, metadata) => console.log("Compressing image", message),
|
|
387
|
+
* "resize": (message, metadata) => console.log("Resizing image", message),
|
|
388
|
+
* }
|
|
389
|
+
* });
|
|
390
|
+
*
|
|
391
|
+
* // Multiple topics with consumer groups
|
|
392
|
+
* export const POST = handleCallback({
|
|
393
|
+
* "user-events": {
|
|
394
|
+
* "welcome": (user, metadata) => console.log("Welcoming user", user),
|
|
395
|
+
* "analytics": (user, metadata) => console.log("Tracking user", user),
|
|
396
|
+
* },
|
|
397
|
+
* "order-events": {
|
|
398
|
+
* "fulfillment": (order, metadata) => console.log("Fulfilling order", order),
|
|
399
|
+
* "notifications": (order, metadata) => console.log("Notifying order", order),
|
|
400
|
+
* }
|
|
401
|
+
* });
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
|
|
724
405
|
|
|
725
|
-
export { BadRequestError, BufferTransport,
|
|
406
|
+
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 };
|