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

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 CHANGED
@@ -18,11 +18,6 @@ A TypeScript client library for interacting with the Vercel Queue Service API, d
18
18
  npm install @vercel/queue
19
19
  ```
20
20
 
21
- The package includes:
22
-
23
- - **Main Library**: Queue client and utilities for production and development
24
- - **CLI Tool**: `npx vercel-queue-local-init` for local development handler initialization
25
-
26
21
  ## Quick Start
27
22
 
28
23
  For local development, you'll need to set up your Vercel project:
@@ -42,15 +37,7 @@ vc env pull
42
37
 
43
38
  **Queues just work locally.** After you have setup your Vercel project, when you `send()` messages in development mode, they automatically trigger your handlers locally - no external queue infrastructure needed.
44
39
 
45
- ### Next.js Lazy Loading
46
-
47
- For Next.js API routes (or others that are lazy-loaded), run this simple command to initialize handlers:
48
-
49
- ```bash
50
- npx vercel-queue-local-init
51
- ```
52
-
53
- That's it! The script reads your `vercel.json`, finds your queue handlers, and triggers Next.js to load them.
40
+ The library reads your `vercel.json` configuration, discovers your queue handlers, and triggers them automatically when messages are sent.
54
41
 
55
42
  ### Example Workflow
56
43
 
@@ -58,22 +45,9 @@ That's it! The script reads your `vercel.json`, finds your queue handlers, and t
58
45
  # Start your dev server
59
46
  npm run dev
60
47
 
61
- # Initialize handlers (only needed for frameworks that lazy load routes in dev)
62
- npx vercel-queue-local-init
63
-
64
48
  # Send messages - they process locally automatically!
65
49
  ```
66
50
 
67
- ### CLI Options
68
-
69
- ```bash
70
- # Custom port
71
- npx vercel-queue-local-init --port 3001
72
-
73
- # Different config file
74
- npx vercel-queue-local-init --config ./my-vercel.json
75
- ```
76
-
77
51
  ### TypeScript Configuration
78
52
 
79
53
  Update your `tsconfig.json` to use `"bundler"` module resolution for proper package export resolution:
@@ -157,23 +131,10 @@ export const POST = handleCallback({
157
131
  // Multiple consumers for different purposes
158
132
  "order-events": {
159
133
  fulfillment: async (order, metadata) => {
160
- // By default, errors will trigger automatic retries
161
- // But you can control retry timing if needed:
162
- if (!isSystemReady()) {
163
- // Override default retry with a 5 minute delay
164
- return { timeoutSeconds: 300 };
165
- }
166
-
167
134
  await processOrder(order);
168
135
  },
169
136
  analytics: async (order, metadata) => {
170
- try {
171
- await trackOrder(order);
172
- } catch (error) {
173
- // Optional: Custom exponential backoff instead of default retry timing
174
- const timeoutSeconds = Math.pow(2, metadata.deliveryCount) * 60;
175
- return { timeoutSeconds };
176
- }
137
+ await trackOrder(order);
177
138
  },
178
139
  },
179
140
  });
@@ -198,9 +159,6 @@ export default handleCallback({
198
159
  },
199
160
  "order-events": {
200
161
  fulfillment: async (order, metadata) => {
201
- if (!isSystemReady()) {
202
- return { timeoutSeconds: 300 };
203
- }
204
162
  await processOrder(order);
205
163
  },
206
164
  analytics: async (order, metadata) => {
@@ -392,14 +350,7 @@ await receive<T>(topicName, consumerGroup, handler, {
392
350
  type MessageHandler<T = unknown> = (
393
351
  message: T,
394
352
  metadata: MessageMetadata
395
- ) => Promise<MessageHandlerResult> | MessageHandlerResult;
396
-
397
- // Handler result types
398
- type MessageHandlerResult = void | MessageTimeoutResult;
399
-
400
- interface MessageTimeoutResult {
401
- timeoutSeconds: number; // seconds before message becomes available again
402
- }
353
+ ) => Promise<void> | void;
403
354
  ```
404
355
 
405
356
  ## Limits
package/dist/index.d.mts CHANGED
@@ -1,82 +1,38 @@
1
- import { M as MessageHandler, C as ConsumerGroupOptions, P as PublishOptions, T as Transport } from './types-JvOenjfT.mjs';
2
- export { a as BadRequestError, B as BufferTransport, F as ForbiddenError, I as InternalServerError, b as InvalidLimitError, J as JsonTransport, g as Message, c as MessageCorruptedError, h as MessageHandlerResult, d as MessageLockedError, i as MessageMetadata, e as MessageNotAvailableError, f as MessageNotFoundError, j as MessageTimeoutResult, Q as QueueEmptyError, k as SendMessageOptions, l as SendMessageResponse, S as StreamTransport, U as UnauthorizedError } from './types-JvOenjfT.mjs';
1
+ import { Q as QueueClientOptions, S as SendMessageOptions, T as Transport, a as SendMessageResponse, R as ReceiveMessagesOptions, M as Message, b as ReceiveMessageByIdOptions, c as ReceiveMessageByIdResponse, D as DeleteMessageOptions, d as DeleteMessageResponse, C as ChangeVisibilityOptions, e as ChangeVisibilityResponse, f as MessageHandler, P as PublishOptions, g as ConsumerGroupOptions } from './types-BHtRP_i_.mjs';
2
+ export { i as BadRequestError, B as BufferTransport, j as ConcurrencyLimitError, k as ConsumerDiscoveryError, l as ConsumerRegistryNotConfiguredError, m as DuplicateMessageError, F as ForbiddenError, I as InternalServerError, n as InvalidLimitError, J as JsonTransport, o as MessageAlreadyProcessedError, p as MessageCorruptedError, q as MessageLockedError, u as MessageMetadata, r as MessageNotAvailableError, s as MessageNotFoundError, t as QueueEmptyError, h as StreamTransport, U as UnauthorizedError } from './types-BHtRP_i_.mjs';
3
3
 
4
- /**
5
- * Options for the consume method
6
- */
7
- interface ConsumeOptions {
8
- /** The specific message ID to consume (if not provided, consumes next available message) */
9
- messageId?: string;
10
- /** Whether to skip downloading the payload (only allowed when messageId is provided) */
11
- skipPayload?: boolean;
12
- }
13
-
14
- /**
15
- * Options for the send function
16
- */
17
- interface SendOptions<T = unknown> extends PublishOptions {
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
+ sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
18
+ receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
19
+ receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T>>;
20
+ deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
21
+ changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
18
22
  /**
19
- * Serializer/deserializer for the payload
20
- * @default JsonTransport instance
23
+ * Alternative endpoint for changing message visibility timeout.
24
+ * Uses the /visibility path suffix and expects visibilityTimeoutSeconds in the body.
25
+ * Functionally equivalent to changeVisibility but follows an alternative API pattern.
26
+ *
27
+ * @param options - Options for changing visibility
28
+ * @returns Promise resolving to change visibility response
21
29
  */
22
- transport?: Transport<T>;
23
- }
24
- /**
25
- * Send a message to a topic (shorthand for topic creation and publishing)
26
- * Uses the default QueueClient with automatic OIDC token detection
27
- * @param topicName Name of the topic to send to
28
- * @param payload The data to send
29
- * @param options Optional send options including transport and publish settings
30
- * @returns Promise with the message ID
31
- * @throws {BadRequestError} When request parameters are invalid
32
- * @throws {UnauthorizedError} When authentication fails
33
- * @throws {ForbiddenError} When access is denied (environment mismatch)
34
- * @throws {InternalServerError} When server encounters an error
35
- */
36
- declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
37
- messageId: string;
38
- }>;
39
- /**
40
- * Options for the receive function
41
- */
42
- interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
30
+ changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
43
31
  }
32
+
44
33
  /**
45
- * Receive a message from a topic (shorthand for topic and consumer group creation)
46
- * Uses the default QueueClient with automatic OIDC token detection
47
- * @param topicName Name of the topic to receive from
48
- * @param consumerGroup Name of the consumer group
49
- * @param handler Function to process the message
50
- * @returns Promise that resolves when the message is processed
51
- * @throws All the same errors as the underlying client methods
52
- */
53
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
54
- /**
55
- * Receive a specific message by its ID with full payload
56
- * @param topicName Name of the topic to receive from
57
- * @param consumerGroup Name of the consumer group
58
- * @param handler Function to process the message
59
- * @param options Receive options with messageId specified
60
- * @returns Promise that resolves when the message is processed
61
- * @throws All the same errors as the underlying client methods
62
- */
63
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
64
- messageId: string;
65
- skipPayload?: false | undefined;
66
- }): Promise<void>;
67
- /**
68
- * Receive a specific message by its ID without downloading the payload (metadata only)
69
- * @param topicName Name of the topic to receive from
70
- * @param consumerGroup Name of the consumer group
71
- * @param handler Function to process the message metadata (payload will be void)
72
- * @param options Receive options with messageId and skipPayload specified
73
- * @returns Promise that resolves when the message is processed
74
- * @throws All the same errors as the underlying client methods
34
+ * Queue Callback utilities for handling incoming webhook payloads from Vercel triggers
75
35
  */
76
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
77
- messageId: string;
78
- skipPayload: true;
79
- }): Promise<void>;
80
36
 
81
37
  /**
82
38
  * Configuration object with handlers for different topics and consumer groups
@@ -129,6 +85,7 @@ declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>
129
85
  * and routes to the appropriate handler based on topic and consumer group.
130
86
  *
131
87
  * @param handlers Object with topic-specific handlers organized by consumer groups
88
+ * @param client Optional QueueClient instance to use. If not provided, a default client is created.
132
89
  * @returns A Next.js route handler function
133
90
  *
134
91
  * @example
@@ -154,6 +111,158 @@ declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>
154
111
  * });
155
112
  * ```
156
113
  */
157
- declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
114
+ declare function handleCallback(handlers: CallbackHandlers, client?: QueueClient): (request: Request) => Promise<Response>;
115
+
116
+ /**
117
+ * Client - User-facing wrapper for the Vercel Queue Service
118
+ *
119
+ * This provides a simple interface with send() and handleCallback() methods
120
+ * while delegating to the internal QueueClient and factory functions.
121
+ */
122
+
123
+ /**
124
+ * Client provides a simple interface to the Vercel Queue Service.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Create a client with custom options
129
+ * const client = new Client({
130
+ * token: "my-token",
131
+ * headers: { "X-Custom": "header" },
132
+ * });
133
+ *
134
+ * // Send a message
135
+ * await client.send("my-topic", { hello: "world" });
136
+ *
137
+ * // Handle callbacks
138
+ * export const POST = client.handleCallback({
139
+ * "my-topic": {
140
+ * "my-group": async (msg, meta) => console.log(msg),
141
+ * },
142
+ * });
143
+ * ```
144
+ */
145
+ declare class Client {
146
+ private client;
147
+ /**
148
+ * Create a new Client
149
+ * @param options QueueClient configuration options
150
+ */
151
+ constructor(options?: QueueClientOptions);
152
+ /**
153
+ * Send a message to a topic
154
+ * @param topicName Name of the topic to send to
155
+ * @param payload The data to send
156
+ * @param options Optional publish options and transport
157
+ * @returns Promise with the message ID
158
+ * @throws {BadRequestError} When request parameters are invalid
159
+ * @throws {UnauthorizedError} When authentication fails
160
+ * @throws {ForbiddenError} When access is denied (environment mismatch)
161
+ * @throws {InternalServerError} When server encounters an error
162
+ */
163
+ send<T = unknown>(topicName: string, payload: T, options?: PublishOptions & {
164
+ transport?: Transport<T>;
165
+ }): Promise<{
166
+ messageId: string;
167
+ }>;
168
+ /**
169
+ * Create a callback handler for processing queue messages
170
+ * Returns a Next.js route handler function that routes messages to appropriate handlers
171
+ * @param handlers Object with topic-specific handlers organized by consumer groups
172
+ * @returns A Next.js route handler function
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * export const POST = client.handleCallback({
177
+ * "user-events": {
178
+ * "welcome": (user, metadata) => console.log("Welcoming user", user),
179
+ * "analytics": (user, metadata) => console.log("Tracking user", user),
180
+ * },
181
+ * });
182
+ * ```
183
+ */
184
+ handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
185
+ }
186
+
187
+ /**
188
+ * Options for the consume method
189
+ */
190
+ interface ConsumeOptions {
191
+ /** The specific message ID to consume (if not provided, consumes next available message) */
192
+ messageId?: string;
193
+ }
194
+
195
+ /**
196
+ * Options for the send function
197
+ */
198
+ interface SendOptions<T = unknown> extends PublishOptions {
199
+ /**
200
+ * Serializer/deserializer for the payload
201
+ * @default JsonTransport instance
202
+ */
203
+ transport?: Transport<T>;
204
+ /**
205
+ * QueueClient instance to use for sending the message
206
+ * If not provided, a default client is created
207
+ */
208
+ client?: QueueClient;
209
+ }
210
+ /**
211
+ * Send a message to a topic (shorthand for topic creation and publishing)
212
+ * Uses the default QueueClient with automatic OIDC token detection, or a provided client
213
+ * @param topicName Name of the topic to send to
214
+ * @param payload The data to send
215
+ * @param options Optional send options including transport, publish settings, and client
216
+ * @returns Promise with the message ID
217
+ * @throws {BadRequestError} When request parameters are invalid
218
+ * @throws {UnauthorizedError} When authentication fails
219
+ * @throws {ForbiddenError} When access is denied (environment mismatch)
220
+ * @throws {InternalServerError} When server encounters an error
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * // Using default client (OIDC token)
225
+ * await send("my-topic", { hello: "world" });
226
+ *
227
+ * // Using custom client
228
+ * const client = new QueueClient({ token: "my-token" });
229
+ * await send("my-topic", { hello: "world" }, { client });
230
+ * ```
231
+ */
232
+ declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
233
+ messageId: string;
234
+ }>;
235
+ /**
236
+ * Options for the receive function
237
+ */
238
+ interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
239
+ /**
240
+ * QueueClient instance to use for receiving the message
241
+ * If not provided, a default client is created
242
+ */
243
+ client?: QueueClient;
244
+ }
245
+ /**
246
+ * Receive a message from a topic (shorthand for topic and consumer group creation)
247
+ * Uses the default QueueClient with automatic OIDC token detection
248
+ * @param topicName Name of the topic to receive from
249
+ * @param consumerGroup Name of the consumer group
250
+ * @param handler Function to process the message
251
+ * @returns Promise that resolves when the message is processed
252
+ * @throws All the same errors as the underlying client methods
253
+ */
254
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
255
+ /**
256
+ * Receive a specific message by its ID
257
+ * @param topicName Name of the topic to receive from
258
+ * @param consumerGroup Name of the consumer group
259
+ * @param handler Function to process the message
260
+ * @param options Receive options with messageId specified
261
+ * @returns Promise that resolves when the message is processed
262
+ * @throws All the same errors as the underlying client methods
263
+ */
264
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
265
+ messageId: string;
266
+ }): Promise<void>;
158
267
 
159
- export { MessageHandler, type ParsedCallbackRequest, PublishOptions, type ReceiveOptions, type SendOptions, Transport, handleCallback, parseCallback, receive, send };
268
+ export { type CallbackHandlers, Client, Message, MessageHandler, type ParsedCallbackRequest, PublishOptions, QueueClientOptions, type ReceiveOptions, SendMessageOptions, SendMessageResponse, type SendOptions, Transport, handleCallback, parseCallback, receive, send };
package/dist/index.d.ts CHANGED
@@ -1,82 +1,38 @@
1
- import { M as MessageHandler, C as ConsumerGroupOptions, P as PublishOptions, T as Transport } from './types-JvOenjfT.js';
2
- export { a as BadRequestError, B as BufferTransport, F as ForbiddenError, I as InternalServerError, b as InvalidLimitError, J as JsonTransport, g as Message, c as MessageCorruptedError, h as MessageHandlerResult, d as MessageLockedError, i as MessageMetadata, e as MessageNotAvailableError, f as MessageNotFoundError, j as MessageTimeoutResult, Q as QueueEmptyError, k as SendMessageOptions, l as SendMessageResponse, S as StreamTransport, U as UnauthorizedError } from './types-JvOenjfT.js';
1
+ import { Q as QueueClientOptions, S as SendMessageOptions, T as Transport, a as SendMessageResponse, R as ReceiveMessagesOptions, M as Message, b as ReceiveMessageByIdOptions, c as ReceiveMessageByIdResponse, D as DeleteMessageOptions, d as DeleteMessageResponse, C as ChangeVisibilityOptions, e as ChangeVisibilityResponse, f as MessageHandler, P as PublishOptions, g as ConsumerGroupOptions } from './types-BHtRP_i_.js';
2
+ export { i as BadRequestError, B as BufferTransport, j as ConcurrencyLimitError, k as ConsumerDiscoveryError, l as ConsumerRegistryNotConfiguredError, m as DuplicateMessageError, F as ForbiddenError, I as InternalServerError, n as InvalidLimitError, J as JsonTransport, o as MessageAlreadyProcessedError, p as MessageCorruptedError, q as MessageLockedError, u as MessageMetadata, r as MessageNotAvailableError, s as MessageNotFoundError, t as QueueEmptyError, h as StreamTransport, U as UnauthorizedError } from './types-BHtRP_i_.js';
3
3
 
4
- /**
5
- * Options for the consume method
6
- */
7
- interface ConsumeOptions {
8
- /** The specific message ID to consume (if not provided, consumes next available message) */
9
- messageId?: string;
10
- /** Whether to skip downloading the payload (only allowed when messageId is provided) */
11
- skipPayload?: boolean;
12
- }
13
-
14
- /**
15
- * Options for the send function
16
- */
17
- interface SendOptions<T = unknown> extends PublishOptions {
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
+ sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
18
+ receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
19
+ receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T>>;
20
+ deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
21
+ changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
18
22
  /**
19
- * Serializer/deserializer for the payload
20
- * @default JsonTransport instance
23
+ * Alternative endpoint for changing message visibility timeout.
24
+ * Uses the /visibility path suffix and expects visibilityTimeoutSeconds in the body.
25
+ * Functionally equivalent to changeVisibility but follows an alternative API pattern.
26
+ *
27
+ * @param options - Options for changing visibility
28
+ * @returns Promise resolving to change visibility response
21
29
  */
22
- transport?: Transport<T>;
23
- }
24
- /**
25
- * Send a message to a topic (shorthand for topic creation and publishing)
26
- * Uses the default QueueClient with automatic OIDC token detection
27
- * @param topicName Name of the topic to send to
28
- * @param payload The data to send
29
- * @param options Optional send options including transport and publish settings
30
- * @returns Promise with the message ID
31
- * @throws {BadRequestError} When request parameters are invalid
32
- * @throws {UnauthorizedError} When authentication fails
33
- * @throws {ForbiddenError} When access is denied (environment mismatch)
34
- * @throws {InternalServerError} When server encounters an error
35
- */
36
- declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
37
- messageId: string;
38
- }>;
39
- /**
40
- * Options for the receive function
41
- */
42
- interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
30
+ changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
43
31
  }
32
+
44
33
  /**
45
- * Receive a message from a topic (shorthand for topic and consumer group creation)
46
- * Uses the default QueueClient with automatic OIDC token detection
47
- * @param topicName Name of the topic to receive from
48
- * @param consumerGroup Name of the consumer group
49
- * @param handler Function to process the message
50
- * @returns Promise that resolves when the message is processed
51
- * @throws All the same errors as the underlying client methods
52
- */
53
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
54
- /**
55
- * Receive a specific message by its ID with full payload
56
- * @param topicName Name of the topic to receive from
57
- * @param consumerGroup Name of the consumer group
58
- * @param handler Function to process the message
59
- * @param options Receive options with messageId specified
60
- * @returns Promise that resolves when the message is processed
61
- * @throws All the same errors as the underlying client methods
62
- */
63
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
64
- messageId: string;
65
- skipPayload?: false | undefined;
66
- }): Promise<void>;
67
- /**
68
- * Receive a specific message by its ID without downloading the payload (metadata only)
69
- * @param topicName Name of the topic to receive from
70
- * @param consumerGroup Name of the consumer group
71
- * @param handler Function to process the message metadata (payload will be void)
72
- * @param options Receive options with messageId and skipPayload specified
73
- * @returns Promise that resolves when the message is processed
74
- * @throws All the same errors as the underlying client methods
34
+ * Queue Callback utilities for handling incoming webhook payloads from Vercel triggers
75
35
  */
76
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
77
- messageId: string;
78
- skipPayload: true;
79
- }): Promise<void>;
80
36
 
81
37
  /**
82
38
  * Configuration object with handlers for different topics and consumer groups
@@ -129,6 +85,7 @@ declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>
129
85
  * and routes to the appropriate handler based on topic and consumer group.
130
86
  *
131
87
  * @param handlers Object with topic-specific handlers organized by consumer groups
88
+ * @param client Optional QueueClient instance to use. If not provided, a default client is created.
132
89
  * @returns A Next.js route handler function
133
90
  *
134
91
  * @example
@@ -154,6 +111,158 @@ declare function parseCallback(request: Request): Promise<ParsedCallbackRequest>
154
111
  * });
155
112
  * ```
156
113
  */
157
- declare function handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
114
+ declare function handleCallback(handlers: CallbackHandlers, client?: QueueClient): (request: Request) => Promise<Response>;
115
+
116
+ /**
117
+ * Client - User-facing wrapper for the Vercel Queue Service
118
+ *
119
+ * This provides a simple interface with send() and handleCallback() methods
120
+ * while delegating to the internal QueueClient and factory functions.
121
+ */
122
+
123
+ /**
124
+ * Client provides a simple interface to the Vercel Queue Service.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Create a client with custom options
129
+ * const client = new Client({
130
+ * token: "my-token",
131
+ * headers: { "X-Custom": "header" },
132
+ * });
133
+ *
134
+ * // Send a message
135
+ * await client.send("my-topic", { hello: "world" });
136
+ *
137
+ * // Handle callbacks
138
+ * export const POST = client.handleCallback({
139
+ * "my-topic": {
140
+ * "my-group": async (msg, meta) => console.log(msg),
141
+ * },
142
+ * });
143
+ * ```
144
+ */
145
+ declare class Client {
146
+ private client;
147
+ /**
148
+ * Create a new Client
149
+ * @param options QueueClient configuration options
150
+ */
151
+ constructor(options?: QueueClientOptions);
152
+ /**
153
+ * Send a message to a topic
154
+ * @param topicName Name of the topic to send to
155
+ * @param payload The data to send
156
+ * @param options Optional publish options and transport
157
+ * @returns Promise with the message ID
158
+ * @throws {BadRequestError} When request parameters are invalid
159
+ * @throws {UnauthorizedError} When authentication fails
160
+ * @throws {ForbiddenError} When access is denied (environment mismatch)
161
+ * @throws {InternalServerError} When server encounters an error
162
+ */
163
+ send<T = unknown>(topicName: string, payload: T, options?: PublishOptions & {
164
+ transport?: Transport<T>;
165
+ }): Promise<{
166
+ messageId: string;
167
+ }>;
168
+ /**
169
+ * Create a callback handler for processing queue messages
170
+ * Returns a Next.js route handler function that routes messages to appropriate handlers
171
+ * @param handlers Object with topic-specific handlers organized by consumer groups
172
+ * @returns A Next.js route handler function
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * export const POST = client.handleCallback({
177
+ * "user-events": {
178
+ * "welcome": (user, metadata) => console.log("Welcoming user", user),
179
+ * "analytics": (user, metadata) => console.log("Tracking user", user),
180
+ * },
181
+ * });
182
+ * ```
183
+ */
184
+ handleCallback(handlers: CallbackHandlers): (request: Request) => Promise<Response>;
185
+ }
186
+
187
+ /**
188
+ * Options for the consume method
189
+ */
190
+ interface ConsumeOptions {
191
+ /** The specific message ID to consume (if not provided, consumes next available message) */
192
+ messageId?: string;
193
+ }
194
+
195
+ /**
196
+ * Options for the send function
197
+ */
198
+ interface SendOptions<T = unknown> extends PublishOptions {
199
+ /**
200
+ * Serializer/deserializer for the payload
201
+ * @default JsonTransport instance
202
+ */
203
+ transport?: Transport<T>;
204
+ /**
205
+ * QueueClient instance to use for sending the message
206
+ * If not provided, a default client is created
207
+ */
208
+ client?: QueueClient;
209
+ }
210
+ /**
211
+ * Send a message to a topic (shorthand for topic creation and publishing)
212
+ * Uses the default QueueClient with automatic OIDC token detection, or a provided client
213
+ * @param topicName Name of the topic to send to
214
+ * @param payload The data to send
215
+ * @param options Optional send options including transport, publish settings, and client
216
+ * @returns Promise with the message ID
217
+ * @throws {BadRequestError} When request parameters are invalid
218
+ * @throws {UnauthorizedError} When authentication fails
219
+ * @throws {ForbiddenError} When access is denied (environment mismatch)
220
+ * @throws {InternalServerError} When server encounters an error
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * // Using default client (OIDC token)
225
+ * await send("my-topic", { hello: "world" });
226
+ *
227
+ * // Using custom client
228
+ * const client = new QueueClient({ token: "my-token" });
229
+ * await send("my-topic", { hello: "world" }, { client });
230
+ * ```
231
+ */
232
+ declare function send<T = unknown>(topicName: string, payload: T, options?: SendOptions<T>): Promise<{
233
+ messageId: string;
234
+ }>;
235
+ /**
236
+ * Options for the receive function
237
+ */
238
+ interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOptions {
239
+ /**
240
+ * QueueClient instance to use for receiving the message
241
+ * If not provided, a default client is created
242
+ */
243
+ client?: QueueClient;
244
+ }
245
+ /**
246
+ * Receive a message from a topic (shorthand for topic and consumer group creation)
247
+ * Uses the default QueueClient with automatic OIDC token detection
248
+ * @param topicName Name of the topic to receive from
249
+ * @param consumerGroup Name of the consumer group
250
+ * @param handler Function to process the message
251
+ * @returns Promise that resolves when the message is processed
252
+ * @throws All the same errors as the underlying client methods
253
+ */
254
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
255
+ /**
256
+ * Receive a specific message by its ID
257
+ * @param topicName Name of the topic to receive from
258
+ * @param consumerGroup Name of the consumer group
259
+ * @param handler Function to process the message
260
+ * @param options Receive options with messageId specified
261
+ * @returns Promise that resolves when the message is processed
262
+ * @throws All the same errors as the underlying client methods
263
+ */
264
+ declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
265
+ messageId: string;
266
+ }): Promise<void>;
158
267
 
159
- export { MessageHandler, type ParsedCallbackRequest, PublishOptions, type ReceiveOptions, type SendOptions, Transport, handleCallback, parseCallback, receive, send };
268
+ export { type CallbackHandlers, Client, Message, MessageHandler, type ParsedCallbackRequest, PublishOptions, QueueClientOptions, type ReceiveOptions, SendMessageOptions, SendMessageResponse, type SendOptions, Transport, handleCallback, parseCallback, receive, send };