@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.
@@ -1,48 +1,68 @@
1
- import { f as MessageHandler } from './types-C7IKe67P.mjs';
1
+ import { M as MessageHandler, H as HandleCallbackOptions } from './callback-lq_sorrn.mjs';
2
2
 
3
- type CallbackHandlers = {
4
- [topicName: string]: {
5
- [consumerGroup: string]: MessageHandler;
6
- };
7
- };
3
+ /**
4
+ * Next.js Pages Router wrapper for queue callback handling.
5
+ *
6
+ * Provides a `handleCallback` that returns a standard Pages Router API
7
+ * handler `(req, res) => Promise<void>`, compatible with `pages/api/` routes.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // pages/api/queue/my-topic.ts
12
+ * import { handleCallback } from "@vercel/queue/nextjs/pages";
13
+ *
14
+ * export default handleCallback(async (message, metadata) => {
15
+ * console.log("Processing:", message);
16
+ * });
17
+ * ```
18
+ */
19
+
20
+ /**
21
+ * Minimal subset of Next.js `NextApiRequest` used by this wrapper.
22
+ */
8
23
  interface NextApiRequest {
9
24
  method?: string;
10
- url?: string;
11
25
  headers: Record<string, string | string[] | undefined>;
12
- body?: any;
13
- on(event: "data", listener: (chunk: Buffer) => void): void;
14
- on(event: "end", listener: () => void): void;
15
- on(event: "error", listener: (err: Error) => void): void;
26
+ body?: unknown;
16
27
  }
28
+ /**
29
+ * Minimal subset of Next.js `NextApiResponse` used by this wrapper.
30
+ */
17
31
  interface NextApiResponse {
18
32
  status(statusCode: number): NextApiResponse;
19
- setHeader(name: string, value: string): void;
20
- json(data: any): void;
21
- send(data: any): void;
33
+ json(data: unknown): void;
22
34
  end(): void;
23
35
  }
24
36
  /**
25
- * Queue callback handler for Next.js Pages Router
37
+ * Create a Next.js Pages Router API handler for processing queue callback messages.
26
38
  *
27
- * Automatically extracts queue information from CloudEvent format
28
- * and routes to the appropriate handler based on topic and consumer group.
39
+ * Parses `req.body` as a CloudEvent (Next.js auto-parses JSON bodies)
40
+ * and invokes the message handler.
41
+ * Non-POST requests are responded to with 200 OK (for health checks).
29
42
  *
30
- * @param handlers Object with topic-specific handlers organized by consumer groups
31
- * @returns A Next.js Pages Router handler function
43
+ * Response status codes:
44
+ * - **200** on success or non-POST requests
45
+ * - **400** for invalid CloudEvent payloads
46
+ * - **500** for unexpected processing errors
47
+ *
48
+ * @param handler - Function to process the message payload and metadata
49
+ * @param options - Optional configuration
50
+ * @param options.client - Custom QueueClient instance
51
+ * @param options.visibilityTimeoutSeconds - Message lock duration (default: 300, max: 3600)
52
+ * @returns A `(req, res) => Promise<void>` Pages Router API handler
32
53
  *
33
54
  * @example
34
55
  * ```typescript
35
- * // pages/api/queue.ts
36
56
  * import { handleCallback } from "@vercel/queue/nextjs/pages";
37
57
  *
38
- * export default handleCallback({
39
- * "image-processing": {
40
- * "compress": (message, metadata) => console.log("Compressing image", message),
41
- * "resize": (message, metadata) => console.log("Resizing image", message),
42
- * }
43
- * });
58
+ * export default handleCallback(
59
+ * async (order, metadata) => {
60
+ * await processOrder(order);
61
+ * },
62
+ * { visibilityTimeoutSeconds: 300 },
63
+ * );
44
64
  * ```
45
65
  */
46
- declare function handleCallback(handlers: CallbackHandlers): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
66
+ declare function handleCallback<T = unknown>(handler: MessageHandler<T>, options?: HandleCallbackOptions): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
47
67
 
48
68
  export { handleCallback };
@@ -1,48 +1,68 @@
1
- import { f as MessageHandler } from './types-C7IKe67P.js';
1
+ import { M as MessageHandler, H as HandleCallbackOptions } from './callback-lq_sorrn.js';
2
2
 
3
- type CallbackHandlers = {
4
- [topicName: string]: {
5
- [consumerGroup: string]: MessageHandler;
6
- };
7
- };
3
+ /**
4
+ * Next.js Pages Router wrapper for queue callback handling.
5
+ *
6
+ * Provides a `handleCallback` that returns a standard Pages Router API
7
+ * handler `(req, res) => Promise<void>`, compatible with `pages/api/` routes.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // pages/api/queue/my-topic.ts
12
+ * import { handleCallback } from "@vercel/queue/nextjs/pages";
13
+ *
14
+ * export default handleCallback(async (message, metadata) => {
15
+ * console.log("Processing:", message);
16
+ * });
17
+ * ```
18
+ */
19
+
20
+ /**
21
+ * Minimal subset of Next.js `NextApiRequest` used by this wrapper.
22
+ */
8
23
  interface NextApiRequest {
9
24
  method?: string;
10
- url?: string;
11
25
  headers: Record<string, string | string[] | undefined>;
12
- body?: any;
13
- on(event: "data", listener: (chunk: Buffer) => void): void;
14
- on(event: "end", listener: () => void): void;
15
- on(event: "error", listener: (err: Error) => void): void;
26
+ body?: unknown;
16
27
  }
28
+ /**
29
+ * Minimal subset of Next.js `NextApiResponse` used by this wrapper.
30
+ */
17
31
  interface NextApiResponse {
18
32
  status(statusCode: number): NextApiResponse;
19
- setHeader(name: string, value: string): void;
20
- json(data: any): void;
21
- send(data: any): void;
33
+ json(data: unknown): void;
22
34
  end(): void;
23
35
  }
24
36
  /**
25
- * Queue callback handler for Next.js Pages Router
37
+ * Create a Next.js Pages Router API handler for processing queue callback messages.
26
38
  *
27
- * Automatically extracts queue information from CloudEvent format
28
- * and routes to the appropriate handler based on topic and consumer group.
39
+ * Parses `req.body` as a CloudEvent (Next.js auto-parses JSON bodies)
40
+ * and invokes the message handler.
41
+ * Non-POST requests are responded to with 200 OK (for health checks).
29
42
  *
30
- * @param handlers Object with topic-specific handlers organized by consumer groups
31
- * @returns A Next.js Pages Router handler function
43
+ * Response status codes:
44
+ * - **200** on success or non-POST requests
45
+ * - **400** for invalid CloudEvent payloads
46
+ * - **500** for unexpected processing errors
47
+ *
48
+ * @param handler - Function to process the message payload and metadata
49
+ * @param options - Optional configuration
50
+ * @param options.client - Custom QueueClient instance
51
+ * @param options.visibilityTimeoutSeconds - Message lock duration (default: 300, max: 3600)
52
+ * @returns A `(req, res) => Promise<void>` Pages Router API handler
32
53
  *
33
54
  * @example
34
55
  * ```typescript
35
- * // pages/api/queue.ts
36
56
  * import { handleCallback } from "@vercel/queue/nextjs/pages";
37
57
  *
38
- * export default handleCallback({
39
- * "image-processing": {
40
- * "compress": (message, metadata) => console.log("Compressing image", message),
41
- * "resize": (message, metadata) => console.log("Resizing image", message),
42
- * }
43
- * });
58
+ * export default handleCallback(
59
+ * async (order, metadata) => {
60
+ * await processOrder(order);
61
+ * },
62
+ * { visibilityTimeoutSeconds: 300 },
63
+ * );
44
64
  * ```
45
65
  */
46
- declare function handleCallback(handlers: CallbackHandlers): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
66
+ declare function handleCallback<T = unknown>(handler: MessageHandler<T>, options?: HandleCallbackOptions): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
47
67
 
48
68
  export { handleCallback };