@vercel/queue 0.0.0-alpha.36 → 0.0.0-alpha.38
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 +212 -182
- package/dist/{types-C7IKe67P.d.mts → callback-lq_sorrn.d.mts} +249 -40
- package/dist/{types-C7IKe67P.d.ts → callback-lq_sorrn.d.ts} +249 -40
- package/dist/index.d.mts +74 -338
- package/dist/index.d.ts +74 -338
- package/dist/index.js +904 -930
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +900 -928
- package/dist/index.mjs.map +1 -1
- package/dist/nextjs-pages.d.mts +47 -27
- package/dist/nextjs-pages.d.ts +47 -27
- package/dist/nextjs-pages.js +322 -373
- package/dist/nextjs-pages.js.map +1 -1
- package/dist/nextjs-pages.mjs +322 -373
- package/dist/nextjs-pages.mjs.map +1 -1
- package/dist/web.d.mts +60 -0
- package/dist/web.d.ts +60 -0
- package/dist/web.js +1457 -0
- package/dist/web.js.map +1 -0
- package/dist/web.mjs +1420 -0
- package/dist/web.mjs.map +1 -0
- package/package.json +11 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,332 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { M as MessageHandler, C as ConsumerGroupOptions, Q as QueueClient, P as PublishOptions } from './callback-lq_sorrn.js';
|
|
2
|
+
export { g as BadRequestError, B as BufferTransport, a as CLOUD_EVENT_TYPE_V1BETA, b as CLOUD_EVENT_TYPE_V2BETA, i as ConsumerDiscoveryError, j as ConsumerRegistryNotConfiguredError, D as DuplicateMessageError, F as ForbiddenError, H as HandleCallbackOptions, I as InternalServerError, k as InvalidLimitError, J as JsonTransport, s as Message, l as MessageAlreadyProcessedError, m as MessageCorruptedError, n as MessageLockedError, t as MessageMetadata, o as MessageNotAvailableError, q as MessageNotFoundError, d as ParsedCallbackRequest, e as ParsedCallbackV1, f as ParsedCallbackV2, u as QueueClientOptions, r as QueueEmptyError, v as SendMessageOptions, w as SendMessageResponse, S as StreamTransport, T as Transport, U as UnauthorizedError, h as handleCallback, p as parseCallback, c as parseRawCallback } from './callback-lq_sorrn.js';
|
|
3
3
|
|
|
4
|
-
declare class QueueClient {
|
|
5
|
-
private baseUrl;
|
|
6
|
-
private basePath;
|
|
7
|
-
private customHeaders;
|
|
8
|
-
private providedToken?;
|
|
9
|
-
private defaultDeploymentId?;
|
|
10
|
-
private pinToDeployment;
|
|
11
|
-
constructor(options?: QueueClientOptions);
|
|
12
|
-
private getSendDeploymentId;
|
|
13
|
-
private getConsumeDeploymentId;
|
|
14
|
-
private getToken;
|
|
15
|
-
private buildUrl;
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
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
|
-
*/
|
|
111
|
-
changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
112
|
-
/**
|
|
113
|
-
* Alternative endpoint for changing message visibility timeout.
|
|
114
|
-
* Uses the /visibility path suffix and expects visibilityTimeoutSeconds in the body.
|
|
115
|
-
* Functionally equivalent to changeVisibility but follows an alternative API pattern.
|
|
116
|
-
*
|
|
117
|
-
* @param options - Options for changing visibility
|
|
118
|
-
* @returns Promise resolving to change visibility response
|
|
119
|
-
*/
|
|
120
|
-
changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Queue Callback utilities for handling incoming webhook payloads from Vercel triggers
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Configuration object with handlers for different topics and consumer groups
|
|
129
|
-
*/
|
|
130
|
-
type CallbackHandlers = {
|
|
131
|
-
[topicName: string]: {
|
|
132
|
-
[consumerGroup: string]: MessageHandler;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
4
|
/**
|
|
136
|
-
* Options for
|
|
5
|
+
* Options for consuming a specific message by ID.
|
|
137
6
|
*/
|
|
138
|
-
interface
|
|
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
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Parsed callback request information
|
|
155
|
-
*/
|
|
156
|
-
type ParsedCallbackRequest = {
|
|
157
|
-
queueName: string;
|
|
158
|
-
consumerGroup: string;
|
|
7
|
+
interface ConsumeByIdOptions {
|
|
8
|
+
/** The specific message ID to consume */
|
|
159
9
|
messageId: string;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Parse and validate callback request using CloudEvent specification
|
|
163
|
-
*
|
|
164
|
-
* Extracts queue information from CloudEvent format and validates
|
|
165
|
-
* that all required fields are present.
|
|
166
|
-
*
|
|
167
|
-
* @param request The incoming webhook request
|
|
168
|
-
* @returns Parsed queue information
|
|
169
|
-
* @throws Error if required fields are missing
|
|
170
|
-
*
|
|
171
|
-
* @example
|
|
172
|
-
* ```typescript
|
|
173
|
-
* // In Next.js API route
|
|
174
|
-
* export async function POST(request: Request) {
|
|
175
|
-
* try {
|
|
176
|
-
* const { queueName, consumerGroup, messageId } = parseCallback(request);
|
|
177
|
-
*
|
|
178
|
-
* // Use the parsed information...
|
|
179
|
-
* await myWorkflow.handleWebhook(queueName, consumerGroup, messageId);
|
|
180
|
-
*
|
|
181
|
-
* return Response.json({ status: "success" });
|
|
182
|
-
* } catch (error) {
|
|
183
|
-
* return Response.json({ error: error.message }, { status: 400 });
|
|
184
|
-
* }
|
|
185
|
-
* }
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>;
|
|
189
|
-
/**
|
|
190
|
-
* Simplified queue callback handler for Next.js route handlers.
|
|
191
|
-
*
|
|
192
|
-
* Automatically extracts queue information from CloudEvent format
|
|
193
|
-
* and routes to the appropriate handler based on topic and consumer group.
|
|
194
|
-
*
|
|
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)
|
|
199
|
-
* @returns A Next.js route handler function
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```typescript
|
|
203
|
-
* // Basic usage
|
|
204
|
-
* export const POST = handleCallback({
|
|
205
|
-
* "image-processing": {
|
|
206
|
-
* "compress": (message, metadata) => console.log("Compressing", message),
|
|
207
|
-
* "resize": (message, metadata) => console.log("Resizing", message),
|
|
208
|
-
* }
|
|
209
|
-
* });
|
|
210
|
-
*
|
|
211
|
-
* // With custom visibility timeout for long-running handlers
|
|
212
|
-
* export const POST = handleCallback({
|
|
213
|
-
* "video-processing": {
|
|
214
|
-
* "transcode": async (video, metadata) => {
|
|
215
|
-
* // Long-running transcoding operation
|
|
216
|
-
* await transcodeVideo(video);
|
|
217
|
-
* },
|
|
218
|
-
* }
|
|
219
|
-
* }, {
|
|
220
|
-
* visibilityTimeoutSeconds: 300, // 5 minutes
|
|
221
|
-
* });
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
declare function handleCallback(handlers: CallbackHandlers, options?: HandleCallbackOptions): (request: Request) => Promise<Response>;
|
|
225
|
-
|
|
10
|
+
}
|
|
226
11
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* This provides a simple interface with send() and handleCallback() methods
|
|
230
|
-
* while delegating to the internal QueueClient and factory functions.
|
|
12
|
+
* Options for consuming messages from the queue.
|
|
231
13
|
*/
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Client provides a simple interface to the Vercel Queue Service.
|
|
235
|
-
*
|
|
236
|
-
* @example
|
|
237
|
-
* ```typescript
|
|
238
|
-
* // Create a client with custom options
|
|
239
|
-
* const client = new Client({
|
|
240
|
-
* token: "my-token",
|
|
241
|
-
* headers: { "X-Custom": "header" },
|
|
242
|
-
* });
|
|
243
|
-
*
|
|
244
|
-
* // Send a message
|
|
245
|
-
* await client.send("my-topic", { hello: "world" });
|
|
246
|
-
*
|
|
247
|
-
* // Handle callbacks
|
|
248
|
-
* export const POST = client.handleCallback({
|
|
249
|
-
* "my-topic": {
|
|
250
|
-
* "my-group": async (msg, meta) => console.log(msg),
|
|
251
|
-
* },
|
|
252
|
-
* });
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
declare class Client {
|
|
256
|
-
private client;
|
|
257
|
-
/**
|
|
258
|
-
* Create a new Client
|
|
259
|
-
* @param options QueueClient configuration options
|
|
260
|
-
*/
|
|
261
|
-
constructor(options?: QueueClientOptions);
|
|
14
|
+
interface ConsumeBatchOptions {
|
|
262
15
|
/**
|
|
263
|
-
*
|
|
264
|
-
* @
|
|
265
|
-
* @
|
|
266
|
-
* @
|
|
267
|
-
* @returns Promise with the message ID
|
|
268
|
-
* @throws {BadRequestError} When request parameters are invalid
|
|
269
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
270
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
271
|
-
* @throws {InternalServerError} When server encounters an error
|
|
16
|
+
* Maximum number of messages to retrieve in a single request.
|
|
17
|
+
* @default 1
|
|
18
|
+
* @minimum 1
|
|
19
|
+
* @maximum 10
|
|
272
20
|
*/
|
|
273
|
-
|
|
274
|
-
transport?: Transport<T>;
|
|
275
|
-
}): Promise<{
|
|
276
|
-
messageId: string;
|
|
277
|
-
}>;
|
|
278
|
-
/**
|
|
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)
|
|
285
|
-
* @returns A Next.js route handler function
|
|
286
|
-
*
|
|
287
|
-
* @example
|
|
288
|
-
* ```typescript
|
|
289
|
-
* // Basic usage
|
|
290
|
-
* export const POST = client.handleCallback({
|
|
291
|
-
* "user-events": {
|
|
292
|
-
* "welcome": (user, metadata) => console.log("Welcoming user", user),
|
|
293
|
-
* "analytics": (user, metadata) => console.log("Tracking user", user),
|
|
294
|
-
* },
|
|
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
|
-
* });
|
|
305
|
-
* ```
|
|
306
|
-
*/
|
|
307
|
-
handleCallback(handlers: CallbackHandlers, options?: Omit<HandleCallbackOptions, "client">): (request: Request) => Promise<Response>;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Options for the consume method
|
|
312
|
-
*/
|
|
313
|
-
interface ConsumeOptions {
|
|
314
|
-
/** The specific message ID to consume (if not provided, consumes next available message) */
|
|
315
|
-
messageId?: string;
|
|
21
|
+
limit?: number;
|
|
316
22
|
}
|
|
317
23
|
|
|
318
24
|
/**
|
|
319
25
|
* Options for the send function.
|
|
320
26
|
*/
|
|
321
|
-
interface SendOptions
|
|
322
|
-
/**
|
|
323
|
-
* Serializer for the payload.
|
|
324
|
-
* @default JsonTransport
|
|
325
|
-
*/
|
|
326
|
-
transport?: Transport<T>;
|
|
27
|
+
interface SendOptions extends PublishOptions {
|
|
327
28
|
/**
|
|
328
29
|
* QueueClient instance to use for sending the message.
|
|
329
|
-
*
|
|
30
|
+
* Configure transport on the client if you need custom serialization.
|
|
31
|
+
* If not provided, a default client is created with OIDC authentication and JsonTransport.
|
|
330
32
|
*/
|
|
331
33
|
client?: QueueClient;
|
|
332
34
|
}
|
|
@@ -341,8 +43,7 @@ interface SendOptions<T = unknown> extends PublishOptions {
|
|
|
341
43
|
* @param options.idempotencyKey - Deduplication key (dedup window: min(retention, 24h))
|
|
342
44
|
* @param options.retentionSeconds - Message TTL (default: 86400, min: 60, max: 86400)
|
|
343
45
|
* @param options.delaySeconds - Delivery delay (default: 0, max: retentionSeconds)
|
|
344
|
-
* @param options.
|
|
345
|
-
* @param options.client - Custom QueueClient instance
|
|
46
|
+
* @param options.client - Custom QueueClient instance (configure transport on the client)
|
|
346
47
|
* @returns Promise with the generated messageId
|
|
347
48
|
* @throws {DuplicateMessageError} When idempotency key was already used
|
|
348
49
|
* @throws {BadRequestError} When parameters are invalid
|
|
@@ -352,7 +53,7 @@ interface SendOptions<T = unknown> extends PublishOptions {
|
|
|
352
53
|
*
|
|
353
54
|
* @example
|
|
354
55
|
* ```typescript
|
|
355
|
-
* // Basic usage (OIDC auth)
|
|
56
|
+
* // Basic usage (OIDC auth, JSON serialization)
|
|
356
57
|
* await send("my-topic", { hello: "world" });
|
|
357
58
|
*
|
|
358
59
|
* // With options
|
|
@@ -362,44 +63,81 @@ interface SendOptions<T = unknown> extends PublishOptions {
|
|
|
362
63
|
* delaySeconds: 60, // Delay 1 minute
|
|
363
64
|
* });
|
|
364
65
|
*
|
|
365
|
-
* // Using custom client
|
|
366
|
-
* const client = new QueueClient({
|
|
367
|
-
*
|
|
66
|
+
* // Using custom client with custom transport
|
|
67
|
+
* const client = new QueueClient({
|
|
68
|
+
* token: "my-token",
|
|
69
|
+
* transport: new BufferTransport(),
|
|
70
|
+
* });
|
|
71
|
+
* await send("my-topic", myBuffer, { client });
|
|
368
72
|
* ```
|
|
369
73
|
*/
|
|
370
|
-
declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions
|
|
74
|
+
declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions): Promise<{
|
|
371
75
|
messageId: string;
|
|
372
76
|
}>;
|
|
373
77
|
/**
|
|
374
|
-
*
|
|
78
|
+
* Base options shared by all receive variants.
|
|
375
79
|
*/
|
|
376
|
-
interface
|
|
80
|
+
interface ReceiveBaseOptions extends ConsumerGroupOptions {
|
|
377
81
|
/**
|
|
378
82
|
* QueueClient instance to use for receiving the message.
|
|
379
|
-
*
|
|
83
|
+
* Configure transport on the client if you need custom deserialization.
|
|
84
|
+
* If not provided, a default client is created with OIDC authentication and JsonTransport.
|
|
380
85
|
*/
|
|
381
86
|
client?: QueueClient;
|
|
382
87
|
}
|
|
383
88
|
/**
|
|
384
|
-
*
|
|
89
|
+
* Options for receiving a specific message by ID.
|
|
90
|
+
*/
|
|
91
|
+
type ReceiveByIdOptions = ReceiveBaseOptions & ConsumeByIdOptions;
|
|
92
|
+
/**
|
|
93
|
+
* Options for receiving messages from the queue with an optional batch limit.
|
|
94
|
+
*/
|
|
95
|
+
type ReceiveBatchOptions = ReceiveBaseOptions & ConsumeBatchOptions;
|
|
96
|
+
/**
|
|
97
|
+
* Options for the receive function. Either receive by message ID or receive
|
|
98
|
+
* from the queue with an optional limit. These options are mutually exclusive.
|
|
99
|
+
*/
|
|
100
|
+
type ReceiveOptions = ReceiveByIdOptions | ReceiveBatchOptions;
|
|
101
|
+
/**
|
|
102
|
+
* Receive messages from a topic.
|
|
385
103
|
*
|
|
386
|
-
* Shorthand for creating a topic and consumer group.
|
|
104
|
+
* Shorthand for creating a topic and consumer group. Each message is automatically:
|
|
387
105
|
* - Locked with the configured visibility timeout
|
|
388
106
|
* - Kept alive via periodic visibility extensions during processing
|
|
389
107
|
* - Deleted upon successful handler completion
|
|
390
108
|
*
|
|
109
|
+
* When the queue is empty, the handler is called with `null` for both
|
|
110
|
+
* message and metadata, allowing graceful handling without exceptions.
|
|
111
|
+
*
|
|
391
112
|
* @param topicName - Name of the topic (pattern: `[A-Za-z0-9_-]+`)
|
|
392
113
|
* @param consumerGroup - Name of the consumer group (pattern: `[A-Za-z0-9_-]+`)
|
|
393
|
-
* @param handler - Function to process
|
|
114
|
+
* @param handler - Function to process each message payload and metadata.
|
|
115
|
+
* Receives (null, null) when queue is empty.
|
|
394
116
|
* @param options - Optional receive options
|
|
395
|
-
* @param options.visibilityTimeoutSeconds - Message lock duration (default:
|
|
396
|
-
* @param options.
|
|
397
|
-
* @param options.
|
|
398
|
-
* @returns Promise that resolves when
|
|
399
|
-
*
|
|
400
|
-
*
|
|
117
|
+
* @param options.visibilityTimeoutSeconds - Message lock duration (default: 300, max: 3600)
|
|
118
|
+
* @param options.limit - Maximum messages to retrieve (default: 1, min: 1, max: 10)
|
|
119
|
+
* @param options.client - Custom QueueClient instance (configure transport on the client)
|
|
120
|
+
* @returns Promise that resolves when all messages are processed and deleted,
|
|
121
|
+
* or when the handler returns after receiving null (empty queue)
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* // Basic usage (OIDC auth, JSON deserialization)
|
|
126
|
+
* await receive("my-topic", "my-group", async (payload, metadata) => {
|
|
127
|
+
* console.log("Received:", payload);
|
|
128
|
+
* });
|
|
129
|
+
*
|
|
130
|
+
* // Batch processing - fetch up to 10 messages in one request
|
|
131
|
+
* await receive("my-topic", "my-group", handler, { limit: 10 });
|
|
132
|
+
*
|
|
133
|
+
* // Using custom client with custom transport
|
|
134
|
+
* const client = new QueueClient({
|
|
135
|
+
* transport: new BufferTransport(),
|
|
136
|
+
* });
|
|
137
|
+
* await receive("my-topic", "my-group", handler, { client });
|
|
138
|
+
* ```
|
|
401
139
|
*/
|
|
402
|
-
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?:
|
|
140
|
+
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveBatchOptions): Promise<void>;
|
|
403
141
|
/**
|
|
404
142
|
* Receive a specific message by its ID.
|
|
405
143
|
*
|
|
@@ -415,8 +153,6 @@ declare function receive<T = unknown>(topicName: string, consumerGroup: string,
|
|
|
415
153
|
* @throws {MessageNotAvailableError} When message in wrong state
|
|
416
154
|
* @throws {MessageAlreadyProcessedError} When already processed
|
|
417
155
|
*/
|
|
418
|
-
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options:
|
|
419
|
-
messageId: string;
|
|
420
|
-
}): Promise<void>;
|
|
156
|
+
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveByIdOptions): Promise<void>;
|
|
421
157
|
|
|
422
|
-
export {
|
|
158
|
+
export { MessageHandler, PublishOptions, QueueClient, type ReceiveBatchOptions, type ReceiveByIdOptions, type ReceiveOptions, type SendOptions, receive, send };
|