@vercel/queue 0.0.0-alpha.33 → 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,95 +1,33 @@
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-Dw29Fr9y.mjs';
2
- export { i as BadRequestError, B as BufferTransport, F as ForbiddenError, I as InternalServerError, j as InvalidLimitError, J as JsonTransport, k as MessageCorruptedError, p as MessageHandlerResult, l as MessageLockedError, q as MessageMetadata, m as MessageNotAvailableError, n as MessageNotFoundError, r as MessageTimeoutResult, o as QueueEmptyError, h as StreamTransport, U as UnauthorizedError } from './types-Dw29Fr9y.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
- * Internal client for interacting with the Vercel Queue Service API
6
- * Use Client for the public-facing wrapper with send/handleCallback methods
7
- */
8
4
  declare class QueueClient {
9
5
  private baseUrl;
10
6
  private basePath;
11
7
  private customHeaders;
12
8
  private providedToken?;
13
- /**
14
- * Create a new Vercel Queue Service client
15
- * @param options QueueClient configuration options
16
- */
9
+ private defaultDeploymentId?;
10
+ private pinToDeployment;
17
11
  constructor(options?: QueueClientOptions);
12
+ private getSendDeploymentId;
13
+ private getConsumeDeploymentId;
18
14
  private getToken;
19
- /**
20
- * Internal fetch wrapper that automatically handles debug logging
21
- * when VERCEL_QUEUE_DEBUG is enabled
22
- */
15
+ private buildUrl;
23
16
  private fetch;
24
- /**
25
- * Send a message to a queue
26
- * @param options Send message options
27
- * @param transport Serializer/deserializer for the payload
28
- * @returns Promise with the message ID
29
- * @throws {BadRequestError} When request parameters are invalid
30
- * @throws {UnauthorizedError} When authentication fails
31
- * @throws {ForbiddenError} When access is denied (environment mismatch)
32
- * @throws {InternalServerError} When server encounters an error
33
- */
34
17
  sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
35
- /**
36
- * Receive messages from a queue
37
- * @param options Receive messages options
38
- * @param transport Serializer/deserializer for the payload
39
- * @returns AsyncGenerator that yields messages as they arrive
40
- * @throws {InvalidLimitError} When limit parameter is not between 1 and 10
41
- * @throws {QueueEmptyError} When no messages are available (204)
42
- * @throws {MessageLockedError} When messages are temporarily locked (423)
43
- * @throws {BadRequestError} When request parameters are invalid
44
- * @throws {UnauthorizedError} When authentication fails
45
- * @throws {ForbiddenError} When access is denied (environment mismatch)
46
- * @throws {InternalServerError} When server encounters an error
47
- */
48
18
  receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
49
- /**
50
- * Receive a specific message by its ID from a queue
51
- * @param options Receive message by ID options
52
- * @param transport Serializer/deserializer for the payload
53
- * @returns Promise with the message or null if not found/available
54
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
55
- * @throws {MessageLockedError} When the message is temporarily locked (423)
56
- * @throws {MessageNotAvailableError} When message exists but isn't available (409)
57
- * @throws {MessageCorruptedError} When message data is corrupted
58
- * @throws {BadRequestError} When request parameters are invalid
59
- * @throws {UnauthorizedError} When authentication fails
60
- * @throws {ForbiddenError} When access is denied (environment mismatch)
61
- * @throws {InternalServerError} When server encounters an error
62
- */
63
- receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
64
- skipPayload: true;
65
- }, transport?: Transport<T>): Promise<ReceiveMessageByIdResponse<T, true>>;
66
- receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
67
- skipPayload?: false | undefined;
68
- }, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T, false>>;
69
- /**
70
- * Delete a message (acknowledge processing)
71
- * @param options Delete message options
72
- * @returns Promise with delete status
73
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
74
- * @throws {MessageNotAvailableError} When message can't be deleted (409)
75
- * @throws {BadRequestError} When ticket is missing or invalid (400)
76
- * @throws {UnauthorizedError} When authentication fails
77
- * @throws {ForbiddenError} When access is denied (environment mismatch)
78
- * @throws {InternalServerError} When server encounters an error
79
- */
19
+ receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T>>;
80
20
  deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
21
+ changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
81
22
  /**
82
- * Change the visibility timeout of a message
83
- * @param options Change visibility options
84
- * @returns Promise with update status
85
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
86
- * @throws {MessageNotAvailableError} When message can't be updated (409)
87
- * @throws {BadRequestError} When ticket is missing or visibility timeout invalid (400)
88
- * @throws {UnauthorizedError} When authentication fails
89
- * @throws {ForbiddenError} When access is denied (environment mismatch)
90
- * @throws {InternalServerError} When server encounters an error
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
91
29
  */
92
- changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
30
+ changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
93
31
  }
94
32
 
95
33
  /**
@@ -252,8 +190,6 @@ declare class Client {
252
190
  interface ConsumeOptions {
253
191
  /** The specific message ID to consume (if not provided, consumes next available message) */
254
192
  messageId?: string;
255
- /** Whether to skip downloading the payload (only allowed when messageId is provided) */
256
- skipPayload?: boolean;
257
193
  }
258
194
 
259
195
  /**
@@ -317,7 +253,7 @@ interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOp
317
253
  */
318
254
  declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
319
255
  /**
320
- * Receive a specific message by its ID with full payload
256
+ * Receive a specific message by its ID
321
257
  * @param topicName Name of the topic to receive from
322
258
  * @param consumerGroup Name of the consumer group
323
259
  * @param handler Function to process the message
@@ -327,20 +263,6 @@ declare function receive<T = unknown>(topicName: string, consumerGroup: string,
327
263
  */
328
264
  declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
329
265
  messageId: string;
330
- skipPayload?: false | undefined;
331
- }): Promise<void>;
332
- /**
333
- * Receive a specific message by its ID without downloading the payload (metadata only)
334
- * @param topicName Name of the topic to receive from
335
- * @param consumerGroup Name of the consumer group
336
- * @param handler Function to process the message metadata (payload will be void)
337
- * @param options Receive options with messageId and skipPayload specified
338
- * @returns Promise that resolves when the message is processed
339
- * @throws All the same errors as the underlying client methods
340
- */
341
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
342
- messageId: string;
343
- skipPayload: true;
344
266
  }): Promise<void>;
345
267
 
346
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,95 +1,33 @@
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-Dw29Fr9y.js';
2
- export { i as BadRequestError, B as BufferTransport, F as ForbiddenError, I as InternalServerError, j as InvalidLimitError, J as JsonTransport, k as MessageCorruptedError, p as MessageHandlerResult, l as MessageLockedError, q as MessageMetadata, m as MessageNotAvailableError, n as MessageNotFoundError, r as MessageTimeoutResult, o as QueueEmptyError, h as StreamTransport, U as UnauthorizedError } from './types-Dw29Fr9y.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
- * Internal client for interacting with the Vercel Queue Service API
6
- * Use Client for the public-facing wrapper with send/handleCallback methods
7
- */
8
4
  declare class QueueClient {
9
5
  private baseUrl;
10
6
  private basePath;
11
7
  private customHeaders;
12
8
  private providedToken?;
13
- /**
14
- * Create a new Vercel Queue Service client
15
- * @param options QueueClient configuration options
16
- */
9
+ private defaultDeploymentId?;
10
+ private pinToDeployment;
17
11
  constructor(options?: QueueClientOptions);
12
+ private getSendDeploymentId;
13
+ private getConsumeDeploymentId;
18
14
  private getToken;
19
- /**
20
- * Internal fetch wrapper that automatically handles debug logging
21
- * when VERCEL_QUEUE_DEBUG is enabled
22
- */
15
+ private buildUrl;
23
16
  private fetch;
24
- /**
25
- * Send a message to a queue
26
- * @param options Send message options
27
- * @param transport Serializer/deserializer for the payload
28
- * @returns Promise with the message ID
29
- * @throws {BadRequestError} When request parameters are invalid
30
- * @throws {UnauthorizedError} When authentication fails
31
- * @throws {ForbiddenError} When access is denied (environment mismatch)
32
- * @throws {InternalServerError} When server encounters an error
33
- */
34
17
  sendMessage<T = unknown>(options: SendMessageOptions<T>, transport: Transport<T>): Promise<SendMessageResponse>;
35
- /**
36
- * Receive messages from a queue
37
- * @param options Receive messages options
38
- * @param transport Serializer/deserializer for the payload
39
- * @returns AsyncGenerator that yields messages as they arrive
40
- * @throws {InvalidLimitError} When limit parameter is not between 1 and 10
41
- * @throws {QueueEmptyError} When no messages are available (204)
42
- * @throws {MessageLockedError} When messages are temporarily locked (423)
43
- * @throws {BadRequestError} When request parameters are invalid
44
- * @throws {UnauthorizedError} When authentication fails
45
- * @throws {ForbiddenError} When access is denied (environment mismatch)
46
- * @throws {InternalServerError} When server encounters an error
47
- */
48
18
  receiveMessages<T = unknown>(options: ReceiveMessagesOptions<T>, transport: Transport<T>): AsyncGenerator<Message<T>, void, unknown>;
49
- /**
50
- * Receive a specific message by its ID from a queue
51
- * @param options Receive message by ID options
52
- * @param transport Serializer/deserializer for the payload
53
- * @returns Promise with the message or null if not found/available
54
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
55
- * @throws {MessageLockedError} When the message is temporarily locked (423)
56
- * @throws {MessageNotAvailableError} When message exists but isn't available (409)
57
- * @throws {MessageCorruptedError} When message data is corrupted
58
- * @throws {BadRequestError} When request parameters are invalid
59
- * @throws {UnauthorizedError} When authentication fails
60
- * @throws {ForbiddenError} When access is denied (environment mismatch)
61
- * @throws {InternalServerError} When server encounters an error
62
- */
63
- receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
64
- skipPayload: true;
65
- }, transport?: Transport<T>): Promise<ReceiveMessageByIdResponse<T, true>>;
66
- receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T> & {
67
- skipPayload?: false | undefined;
68
- }, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T, false>>;
69
- /**
70
- * Delete a message (acknowledge processing)
71
- * @param options Delete message options
72
- * @returns Promise with delete status
73
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
74
- * @throws {MessageNotAvailableError} When message can't be deleted (409)
75
- * @throws {BadRequestError} When ticket is missing or invalid (400)
76
- * @throws {UnauthorizedError} When authentication fails
77
- * @throws {ForbiddenError} When access is denied (environment mismatch)
78
- * @throws {InternalServerError} When server encounters an error
79
- */
19
+ receiveMessageById<T = unknown>(options: ReceiveMessageByIdOptions<T>, transport: Transport<T>): Promise<ReceiveMessageByIdResponse<T>>;
80
20
  deleteMessage(options: DeleteMessageOptions): Promise<DeleteMessageResponse>;
21
+ changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
81
22
  /**
82
- * Change the visibility timeout of a message
83
- * @param options Change visibility options
84
- * @returns Promise with update status
85
- * @throws {MessageNotFoundError} When the message doesn't exist (404)
86
- * @throws {MessageNotAvailableError} When message can't be updated (409)
87
- * @throws {BadRequestError} When ticket is missing or visibility timeout invalid (400)
88
- * @throws {UnauthorizedError} When authentication fails
89
- * @throws {ForbiddenError} When access is denied (environment mismatch)
90
- * @throws {InternalServerError} When server encounters an error
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
91
29
  */
92
- changeVisibility(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
30
+ changeVisibilityAlt(options: ChangeVisibilityOptions): Promise<ChangeVisibilityResponse>;
93
31
  }
94
32
 
95
33
  /**
@@ -252,8 +190,6 @@ declare class Client {
252
190
  interface ConsumeOptions {
253
191
  /** The specific message ID to consume (if not provided, consumes next available message) */
254
192
  messageId?: string;
255
- /** Whether to skip downloading the payload (only allowed when messageId is provided) */
256
- skipPayload?: boolean;
257
193
  }
258
194
 
259
195
  /**
@@ -317,7 +253,7 @@ interface ReceiveOptions<T = unknown> extends ConsumerGroupOptions<T>, ConsumeOp
317
253
  */
318
254
  declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options?: ReceiveOptions<T>): Promise<void>;
319
255
  /**
320
- * Receive a specific message by its ID with full payload
256
+ * Receive a specific message by its ID
321
257
  * @param topicName Name of the topic to receive from
322
258
  * @param consumerGroup Name of the consumer group
323
259
  * @param handler Function to process the message
@@ -327,20 +263,6 @@ declare function receive<T = unknown>(topicName: string, consumerGroup: string,
327
263
  */
328
264
  declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<T>, options: ReceiveOptions<T> & {
329
265
  messageId: string;
330
- skipPayload?: false | undefined;
331
- }): Promise<void>;
332
- /**
333
- * Receive a specific message by its ID without downloading the payload (metadata only)
334
- * @param topicName Name of the topic to receive from
335
- * @param consumerGroup Name of the consumer group
336
- * @param handler Function to process the message metadata (payload will be void)
337
- * @param options Receive options with messageId and skipPayload specified
338
- * @returns Promise that resolves when the message is processed
339
- * @throws All the same errors as the underlying client methods
340
- */
341
- declare function receive<T = unknown>(topicName: string, consumerGroup: string, handler: MessageHandler<void>, options: ReceiveOptions<T> & {
342
- messageId: string;
343
- skipPayload: true;
344
266
  }): Promise<void>;
345
267
 
346
268
  export { type CallbackHandlers, Client, Message, MessageHandler, type ParsedCallbackRequest, PublishOptions, QueueClientOptions, type ReceiveOptions, SendMessageOptions, SendMessageResponse, type SendOptions, Transport, handleCallback, parseCallback, receive, send };