@vercel/queue 0.0.0-alpha.37 → 0.0.0-alpha.39
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 +210 -174
- package/dist/{types-CAA8nT8x.d.mts → callback-lq_sorrn.d.mts} +249 -16
- package/dist/{types-CAA8nT8x.d.ts → callback-lq_sorrn.d.ts} +249 -16
- package/dist/index.d.mts +74 -333
- package/dist/index.d.ts +74 -333
- package/dist/index.js +713 -679
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +709 -678
- 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 +320 -313
- package/dist/nextjs-pages.js.map +1 -1
- package/dist/nextjs-pages.mjs +320 -313
- 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,328 +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 transport - Deserializer for message payloads
|
|
46
|
-
* @yields Message objects with payload, messageId, receiptHandle, etc.
|
|
47
|
-
* @throws {QueueEmptyError} When no messages available
|
|
48
|
-
* @throws {InvalidLimitError} When limit is outside 1-10 range
|
|
49
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
50
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
51
|
-
* @throws {ForbiddenError} When access is denied
|
|
52
|
-
* @throws {InternalServerError} When server encounters an error
|
|
53
|
-
*/
|
|
54
|
-
receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
|
|
55
|
-
/**
|
|
56
|
-
* Receive a specific message by its ID.
|
|
57
|
-
*
|
|
58
|
-
* @param options - Receive options
|
|
59
|
-
* @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)
|
|
60
|
-
* @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)
|
|
61
|
-
* @param options.messageId - Message ID to retrieve
|
|
62
|
-
* @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)
|
|
63
|
-
* @param transport - Deserializer for the message payload
|
|
64
|
-
* @returns Promise with the message
|
|
65
|
-
* @throws {MessageNotFoundError} When message doesn't exist
|
|
66
|
-
* @throws {MessageNotAvailableError} When message is in wrong state or was a duplicate
|
|
67
|
-
* @throws {MessageAlreadyProcessedError} When message was already processed
|
|
68
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
69
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
70
|
-
* @throws {ForbiddenError} When access is denied
|
|
71
|
-
* @throws {InternalServerError} When server encounters an error
|
|
72
|
-
*/
|
|
73
|
-
receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T>>;
|
|
74
|
-
/**
|
|
75
|
-
* Delete (acknowledge) a message after successful processing.
|
|
76
|
-
*
|
|
77
|
-
* @param options - Delete options
|
|
78
|
-
* @param options.queueName - Topic name
|
|
79
|
-
* @param options.consumerGroup - Consumer group name
|
|
80
|
-
* @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)
|
|
81
|
-
* @returns Promise indicating deletion success
|
|
82
|
-
* @throws {MessageNotFoundError} When receipt handle not found
|
|
83
|
-
* @throws {MessageNotAvailableError} When receipt handle invalid or message already processed
|
|
84
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
85
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
86
|
-
* @throws {ForbiddenError} When access is denied
|
|
87
|
-
* @throws {InternalServerError} When server encounters an error
|
|
88
|
-
*/
|
|
89
|
-
deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
|
|
90
|
-
/**
|
|
91
|
-
* Extend or change the visibility timeout of a message.
|
|
92
|
-
* Used to prevent message redelivery while still processing.
|
|
93
|
-
*
|
|
94
|
-
* @param options - Visibility options
|
|
95
|
-
* @param options.queueName - Topic name
|
|
96
|
-
* @param options.consumerGroup - Consumer group name
|
|
97
|
-
* @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)
|
|
98
|
-
* @param options.visibilityTimeoutSeconds - New timeout (min: 0, max: 3600, cannot exceed message expiration)
|
|
99
|
-
* @returns Promise indicating success
|
|
100
|
-
* @throws {MessageNotFoundError} When receipt handle not found
|
|
101
|
-
* @throws {MessageNotAvailableError} When receipt handle invalid or message already processed
|
|
102
|
-
* @throws {BadRequestError} When parameters are invalid
|
|
103
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
104
|
-
* @throws {ForbiddenError} When access is denied
|
|
105
|
-
* @throws {InternalServerError} When server encounters an error
|
|
106
|
-
*/
|
|
107
|
-
changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
108
|
-
/**
|
|
109
|
-
* Alternative endpoint for changing message visibility timeout.
|
|
110
|
-
* Uses the /visibility path suffix and expects visibilityTimeoutSeconds in the body.
|
|
111
|
-
* Functionally equivalent to changeVisibility but follows an alternative API pattern.
|
|
112
|
-
*
|
|
113
|
-
* @param options - Options for changing visibility
|
|
114
|
-
* @returns Promise resolving to change visibility response
|
|
115
|
-
*/
|
|
116
|
-
changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Queue Callback utilities for handling incoming webhook payloads from Vercel triggers
|
|
121
|
-
*/
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Configuration object with handlers for different topics and consumer groups
|
|
125
|
-
*/
|
|
126
|
-
type CallbackHandlers = {
|
|
127
|
-
[topicName: string]: {
|
|
128
|
-
[consumerGroup: string]: MessageHandler;
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
4
|
/**
|
|
132
|
-
* Options for
|
|
5
|
+
* Options for consuming a specific message by ID.
|
|
133
6
|
*/
|
|
134
|
-
interface
|
|
135
|
-
/**
|
|
136
|
-
* QueueClient instance to use for processing messages.
|
|
137
|
-
* If not provided, a default client is created with OIDC authentication.
|
|
138
|
-
*/
|
|
139
|
-
client?: QueueClient;
|
|
140
|
-
/**
|
|
141
|
-
* Time in seconds that messages will be invisible to other consumers during processing.
|
|
142
|
-
* The handler will automatically extend this timeout while processing.
|
|
143
|
-
* @default 30
|
|
144
|
-
* @minimum 0
|
|
145
|
-
* @maximum 3600 (1 hour)
|
|
146
|
-
*/
|
|
147
|
-
visibilityTimeoutSeconds?: number;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Parsed callback request information
|
|
151
|
-
*/
|
|
152
|
-
type ParsedCallbackRequest = {
|
|
153
|
-
queueName: string;
|
|
154
|
-
consumerGroup: string;
|
|
7
|
+
interface ConsumeByIdOptions {
|
|
8
|
+
/** The specific message ID to consume */
|
|
155
9
|
messageId: string;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Parse and validate callback request using CloudEvent specification
|
|
159
|
-
*
|
|
160
|
-
* Extracts queue information from CloudEvent format and validates
|
|
161
|
-
* that all required fields are present.
|
|
162
|
-
*
|
|
163
|
-
* @param request The incoming webhook request
|
|
164
|
-
* @returns Parsed queue information
|
|
165
|
-
* @throws Error if required fields are missing
|
|
166
|
-
*
|
|
167
|
-
* @example
|
|
168
|
-
* ```typescript
|
|
169
|
-
* // In Next.js API route
|
|
170
|
-
* export async function POST(request: Request) {
|
|
171
|
-
* try {
|
|
172
|
-
* const { queueName, consumerGroup, messageId } = parseCallback(request);
|
|
173
|
-
*
|
|
174
|
-
* // Use the parsed information...
|
|
175
|
-
* await myWorkflow.handleWebhook(queueName, consumerGroup, messageId);
|
|
176
|
-
*
|
|
177
|
-
* return Response.json({ status: "success" });
|
|
178
|
-
* } catch (error) {
|
|
179
|
-
* return Response.json({ error: error.message }, { status: 400 });
|
|
180
|
-
* }
|
|
181
|
-
* }
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>;
|
|
185
|
-
/**
|
|
186
|
-
* Simplified queue callback handler for Next.js route handlers.
|
|
187
|
-
*
|
|
188
|
-
* Automatically extracts queue information from CloudEvent format
|
|
189
|
-
* and routes to the appropriate handler based on topic and consumer group.
|
|
190
|
-
*
|
|
191
|
-
* @param handlers - Object with topic-specific handlers organized by consumer groups
|
|
192
|
-
* @param options - Optional configuration
|
|
193
|
-
* @param options.client - QueueClient instance (default: new client with OIDC auth)
|
|
194
|
-
* @param options.visibilityTimeoutSeconds - Message lock duration (default: 30, max: 3600)
|
|
195
|
-
* @returns A Next.js route handler function
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* // Basic usage
|
|
200
|
-
* export const POST = handleCallback({
|
|
201
|
-
* "image-processing": {
|
|
202
|
-
* "compress": (message, metadata) => console.log("Compressing", message),
|
|
203
|
-
* "resize": (message, metadata) => console.log("Resizing", message),
|
|
204
|
-
* }
|
|
205
|
-
* });
|
|
206
|
-
*
|
|
207
|
-
* // With custom visibility timeout for long-running handlers
|
|
208
|
-
* export const POST = handleCallback({
|
|
209
|
-
* "video-processing": {
|
|
210
|
-
* "transcode": async (video, metadata) => {
|
|
211
|
-
* // Long-running transcoding operation
|
|
212
|
-
* await transcodeVideo(video);
|
|
213
|
-
* },
|
|
214
|
-
* }
|
|
215
|
-
* }, {
|
|
216
|
-
* visibilityTimeoutSeconds: 300, // 5 minutes
|
|
217
|
-
* });
|
|
218
|
-
* ```
|
|
219
|
-
*/
|
|
220
|
-
declare function handleCallback(handlers: CallbackHandlers, options?: HandleCallbackOptions): (request: Request) => Promise<Response>;
|
|
221
|
-
|
|
10
|
+
}
|
|
222
11
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* This provides a simple interface with send() and handleCallback() methods
|
|
226
|
-
* while delegating to the internal QueueClient and factory functions.
|
|
12
|
+
* Options for consuming messages from the queue.
|
|
227
13
|
*/
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Client provides a simple interface to the Vercel Queue Service.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```typescript
|
|
234
|
-
* // Create a client with custom options
|
|
235
|
-
* const client = new Client({
|
|
236
|
-
* token: "my-token",
|
|
237
|
-
* headers: { "X-Custom": "header" },
|
|
238
|
-
* });
|
|
239
|
-
*
|
|
240
|
-
* // Send a message
|
|
241
|
-
* await client.send("my-topic", { hello: "world" });
|
|
242
|
-
*
|
|
243
|
-
* // Handle callbacks
|
|
244
|
-
* export const POST = client.handleCallback({
|
|
245
|
-
* "my-topic": {
|
|
246
|
-
* "my-group": async (msg, meta) => console.log(msg),
|
|
247
|
-
* },
|
|
248
|
-
* });
|
|
249
|
-
* ```
|
|
250
|
-
*/
|
|
251
|
-
declare class Client {
|
|
252
|
-
private client;
|
|
253
|
-
/**
|
|
254
|
-
* Create a new Client
|
|
255
|
-
* @param options QueueClient configuration options
|
|
256
|
-
*/
|
|
257
|
-
constructor(options?: QueueClientOptions);
|
|
14
|
+
interface ConsumeBatchOptions {
|
|
258
15
|
/**
|
|
259
|
-
*
|
|
260
|
-
* @
|
|
261
|
-
* @
|
|
262
|
-
* @
|
|
263
|
-
* @returns Promise with the message ID
|
|
264
|
-
* @throws {BadRequestError} When request parameters are invalid
|
|
265
|
-
* @throws {UnauthorizedError} When authentication fails
|
|
266
|
-
* @throws {ForbiddenError} When access is denied (environment mismatch)
|
|
267
|
-
* @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
|
|
268
20
|
*/
|
|
269
|
-
|
|
270
|
-
transport?: Transport<T>;
|
|
271
|
-
}): Promise<{
|
|
272
|
-
messageId: string;
|
|
273
|
-
}>;
|
|
274
|
-
/**
|
|
275
|
-
* Create a callback handler for processing queue messages.
|
|
276
|
-
* Returns a Next.js route handler function that routes messages to appropriate handlers.
|
|
277
|
-
*
|
|
278
|
-
* @param handlers - Object with topic-specific handlers organized by consumer groups
|
|
279
|
-
* @param options - Optional configuration
|
|
280
|
-
* @param options.visibilityTimeoutSeconds - Message lock duration (default: 30, max: 3600)
|
|
281
|
-
* @returns A Next.js route handler function
|
|
282
|
-
*
|
|
283
|
-
* @example
|
|
284
|
-
* ```typescript
|
|
285
|
-
* // Basic usage
|
|
286
|
-
* export const POST = client.handleCallback({
|
|
287
|
-
* "user-events": {
|
|
288
|
-
* "welcome": (user, metadata) => console.log("Welcoming user", user),
|
|
289
|
-
* "analytics": (user, metadata) => console.log("Tracking user", user),
|
|
290
|
-
* },
|
|
291
|
-
* });
|
|
292
|
-
*
|
|
293
|
-
* // With custom visibility timeout
|
|
294
|
-
* export const POST = client.handleCallback({
|
|
295
|
-
* "video-processing": {
|
|
296
|
-
* "transcode": async (video) => await transcodeVideo(video),
|
|
297
|
-
* },
|
|
298
|
-
* }, {
|
|
299
|
-
* visibilityTimeoutSeconds: 300, // 5 minutes for long operations
|
|
300
|
-
* });
|
|
301
|
-
* ```
|
|
302
|
-
*/
|
|
303
|
-
handleCallback(handlers: CallbackHandlers, options?: Omit<HandleCallbackOptions, "client">): (request: Request) => Promise<Response>;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Options for the consume method
|
|
308
|
-
*/
|
|
309
|
-
interface ConsumeOptions {
|
|
310
|
-
/** The specific message ID to consume (if not provided, consumes next available message) */
|
|
311
|
-
messageId?: string;
|
|
21
|
+
limit?: number;
|
|
312
22
|
}
|
|
313
23
|
|
|
314
24
|
/**
|
|
315
25
|
* Options for the send function.
|
|
316
26
|
*/
|
|
317
|
-
interface SendOptions
|
|
318
|
-
/**
|
|
319
|
-
* Serializer for the payload.
|
|
320
|
-
* @default JsonTransport
|
|
321
|
-
*/
|
|
322
|
-
transport?: Transport<T>;
|
|
27
|
+
interface SendOptions extends PublishOptions {
|
|
323
28
|
/**
|
|
324
29
|
* QueueClient instance to use for sending the message.
|
|
325
|
-
*
|
|
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.
|
|
326
32
|
*/
|
|
327
33
|
client?: QueueClient;
|
|
328
34
|
}
|
|
@@ -337,8 +43,7 @@ interface SendOptions<T = unknown> extends PublishOptions {
|
|
|
337
43
|
* @param options.idempotencyKey - Deduplication key (dedup window: min(retention, 24h))
|
|
338
44
|
* @param options.retentionSeconds - Message TTL (default: 86400, min: 60, max: 86400)
|
|
339
45
|
* @param options.delaySeconds - Delivery delay (default: 0, max: retentionSeconds)
|
|
340
|
-
* @param options.
|
|
341
|
-
* @param options.client - Custom QueueClient instance
|
|
46
|
+
* @param options.client - Custom QueueClient instance (configure transport on the client)
|
|
342
47
|
* @returns Promise with the generated messageId
|
|
343
48
|
* @throws {DuplicateMessageError} When idempotency key was already used
|
|
344
49
|
* @throws {BadRequestError} When parameters are invalid
|
|
@@ -348,7 +53,7 @@ interface SendOptions<T = unknown> extends PublishOptions {
|
|
|
348
53
|
*
|
|
349
54
|
* @example
|
|
350
55
|
* ```typescript
|
|
351
|
-
* // Basic usage (OIDC auth)
|
|
56
|
+
* // Basic usage (OIDC auth, JSON serialization)
|
|
352
57
|
* await send("my-topic", { hello: "world" });
|
|
353
58
|
*
|
|
354
59
|
* // With options
|
|
@@ -358,43 +63,81 @@ interface SendOptions<T = unknown> extends PublishOptions {
|
|
|
358
63
|
* delaySeconds: 60, // Delay 1 minute
|
|
359
64
|
* });
|
|
360
65
|
*
|
|
361
|
-
* // Using custom client
|
|
362
|
-
* const client = new QueueClient({
|
|
363
|
-
*
|
|
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 });
|
|
364
72
|
* ```
|
|
365
73
|
*/
|
|
366
|
-
declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions
|
|
74
|
+
declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions): Promise<{
|
|
367
75
|
messageId: string;
|
|
368
76
|
}>;
|
|
369
77
|
/**
|
|
370
|
-
*
|
|
78
|
+
* Base options shared by all receive variants.
|
|
371
79
|
*/
|
|
372
|
-
interface
|
|
80
|
+
interface ReceiveBaseOptions extends ConsumerGroupOptions {
|
|
373
81
|
/**
|
|
374
82
|
* QueueClient instance to use for receiving the message.
|
|
375
|
-
*
|
|
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.
|
|
376
85
|
*/
|
|
377
86
|
client?: QueueClient;
|
|
378
87
|
}
|
|
379
88
|
/**
|
|
380
|
-
*
|
|
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.
|
|
381
103
|
*
|
|
382
|
-
* Shorthand for creating a topic and consumer group.
|
|
104
|
+
* Shorthand for creating a topic and consumer group. Each message is automatically:
|
|
383
105
|
* - Locked with the configured visibility timeout
|
|
384
106
|
* - Kept alive via periodic visibility extensions during processing
|
|
385
107
|
* - Deleted upon successful handler completion
|
|
386
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
|
+
*
|
|
387
112
|
* @param topicName - Name of the topic (pattern: `[A-Za-z0-9_-]+`)
|
|
388
113
|
* @param consumerGroup - Name of the consumer group (pattern: `[A-Za-z0-9_-]+`)
|
|
389
|
-
* @param handler - Function to process
|
|
114
|
+
* @param handler - Function to process each message payload and metadata.
|
|
115
|
+
* Receives (null, null) when queue is empty.
|
|
390
116
|
* @param options - Optional receive options
|
|
391
|
-
* @param options.visibilityTimeoutSeconds - Message lock duration (default:
|
|
392
|
-
* @param options.
|
|
393
|
-
* @param options.
|
|
394
|
-
* @returns Promise that resolves when
|
|
395
|
-
*
|
|
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
|
+
* ```
|
|
396
139
|
*/
|
|
397
|
-
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>;
|
|
398
141
|
/**
|
|
399
142
|
* Receive a specific message by its ID.
|
|
400
143
|
*
|
|
@@ -410,8 +153,6 @@ declare function receive<T = unknown>(topicName: string, consumerGroup: string,
|
|
|
410
153
|
* @throws {MessageNotAvailableError} When message in wrong state
|
|
411
154
|
* @throws {MessageAlreadyProcessedError} When already processed
|
|
412
155
|
*/
|
|
413
|
-
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options:
|
|
414
|
-
messageId: string;
|
|
415
|
-
}): Promise<void>;
|
|
156
|
+
declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveByIdOptions): Promise<void>;
|
|
416
157
|
|
|
417
|
-
export {
|
|
158
|
+
export { MessageHandler, PublishOptions, QueueClient, type ReceiveBatchOptions, type ReceiveByIdOptions, type ReceiveOptions, type SendOptions, receive, send };
|