@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/web.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/web.ts","../src/client.ts","../src/dev.ts","../src/types.ts","../src/oidc.ts","../src/transports.ts","../src/consumer-group.ts","../src/topic.ts","../src/callback.ts"],"sourcesContent":["/**\n * Web API (App Router / Hono) wrapper for queue callback handling.\n *\n * Provides a `handleCallback` that returns a standard `(Request) => Promise<Response>`\n * handler, compatible with Next.js App Router route handlers, Hono, and any\n * framework that uses the Web API `Request`/`Response` types.\n *\n * @example\n * ```typescript\n * // Next.js App Router — app/api/queue/route.ts\n * import { handleCallback } from \"@vercel/queue/web\";\n *\n * export const POST = handleCallback(async (message, metadata) => {\n * console.log(\"Processing:\", message);\n * });\n * ```\n *\n * @example\n * ```typescript\n * // Hono\n * import { Hono } from \"hono\";\n * import { handleCallback } from \"@vercel/queue/web\";\n *\n * const app = new Hono();\n * app.post(\"/api/queue\", handleCallback(handler));\n * ```\n */\nimport {\n handleCallback as coreHandleCallback,\n parseCallback,\n type HandleCallbackOptions,\n} from \"./callback\";\nimport type { MessageHandler } from \"./types\";\n\n/**\n * Create a Web API route handler for processing queue callback messages.\n *\n * Parses the incoming `Request` as a CloudEvent and invokes the message handler.\n * Returns appropriate HTTP responses:\n * - **200** on success\n * - **400** for invalid CloudEvent payloads\n * - **500** for unexpected processing errors\n *\n * @param handler - Function to process the message payload and metadata\n * @param options - Optional configuration\n * @param options.client - Custom QueueClient instance\n * @param options.visibilityTimeoutSeconds - Message lock duration (default: 300, max: 3600)\n * @returns A `(request: Request) => Promise<Response>` route handler\n *\n * @example\n * ```typescript\n * import { handleCallback } from \"@vercel/queue/web\";\n *\n * export const POST = handleCallback(\n * async (order, metadata) => {\n * await processOrder(order);\n * },\n * { visibilityTimeoutSeconds: 300 },\n * );\n * ```\n */\nexport function handleCallback<T = unknown>(\n handler: MessageHandler<T>,\n options?: HandleCallbackOptions,\n): (request: Request) => Promise<Response> {\n return async (request: Request): Promise<Response> => {\n try {\n const parsed = await parseCallback(request);\n await coreHandleCallback(handler, parsed, options);\n return Response.json({ status: \"success\" });\n } catch (error) {\n console.error(\"Queue callback error:\", error);\n\n if (\n error instanceof Error &&\n (error.message.includes(\"Invalid content type\") ||\n error.message.includes(\"Invalid CloudEvent\") ||\n error.message.includes(\"Missing required CloudEvent\") ||\n error.message.includes(\"Failed to parse CloudEvent\") ||\n error.message.includes(\"Binary mode callback\"))\n ) {\n return Response.json({ error: error.message }, { status: 400 });\n }\n\n return Response.json(\n { error: \"Failed to process queue message\" },\n { status: 500 },\n );\n }\n };\n}\n","declare const __PACKAGE_VERSION__: string;\n\nimport { parseMultipartStream } from \"mixpart\";\nimport { isDevMode } from \"./dev\";\nimport { getVercelOidcToken } from \"./oidc\";\nimport { JsonTransport } from \"./transports\";\nimport type { Transport } from \"./transports\";\nimport type {\n ChangeVisibilityOptions,\n ChangeVisibilityResponse,\n DeleteMessageOptions,\n DeleteMessageResponse,\n Message,\n QueueClientOptions,\n ReceiveMessageByIdOptions,\n ReceiveMessageByIdResponse,\n ReceiveMessagesOptions,\n SendMessageOptions,\n SendMessageResponse,\n} from \"./types\";\nimport {\n BadRequestError,\n ConsumerDiscoveryError,\n ConsumerRegistryNotConfiguredError,\n DuplicateMessageError,\n ForbiddenError,\n InternalServerError,\n InvalidLimitError,\n MessageAlreadyProcessedError,\n MessageCorruptedError,\n MessageNotAvailableError,\n MessageNotFoundError,\n QueueEmptyError,\n UnauthorizedError,\n} from \"./types\";\n\nfunction isDebugEnabled(): boolean {\n return (\n process.env.VERCEL_QUEUE_DEBUG === \"1\" ||\n process.env.VERCEL_QUEUE_DEBUG === \"true\"\n );\n}\n\nasync function consumeStream(\n stream: ReadableStream<Uint8Array>,\n): Promise<void> {\n const reader = stream.getReader();\n try {\n while (true) {\n const { done } = await reader.read();\n if (done) break;\n }\n } finally {\n reader.releaseLock();\n }\n}\n\nfunction throwCommonHttpError(\n status: number,\n statusText: string,\n errorText: string,\n operation: string,\n badRequestDefault: string = \"Invalid parameters\",\n): never {\n if (status === 400) {\n throw new BadRequestError(errorText || badRequestDefault);\n }\n if (status === 401) {\n throw new UnauthorizedError(errorText || undefined);\n }\n if (status === 403) {\n throw new ForbiddenError(errorText || undefined);\n }\n if (status >= 500) {\n throw new InternalServerError(\n errorText || `Server error: ${status} ${statusText}`,\n );\n }\n throw new Error(`Failed to ${operation}: ${status} ${statusText}`);\n}\n\nfunction parseQueueHeaders(\n headers: Headers,\n): Omit<Message<unknown>, \"payload\"> | null {\n const messageId = headers.get(\"Vqs-Message-Id\");\n const deliveryCountStr = headers.get(\"Vqs-Delivery-Count\") || \"0\";\n const timestamp = headers.get(\"Vqs-Timestamp\");\n const contentType = headers.get(\"Content-Type\") || \"application/octet-stream\";\n const receiptHandle = headers.get(\"Vqs-Receipt-Handle\");\n\n if (!messageId || !timestamp || !receiptHandle) {\n return null;\n }\n\n const deliveryCount = parseInt(deliveryCountStr, 10);\n if (Number.isNaN(deliveryCount)) {\n return null;\n }\n\n return {\n messageId,\n deliveryCount,\n createdAt: new Date(timestamp),\n contentType,\n receiptHandle,\n };\n}\n\nexport class QueueClient {\n private baseUrl: string;\n private basePath: string;\n private customHeaders: Record<string, string>;\n private providedToken?: string;\n private defaultDeploymentId?: string;\n private pinToDeployment: boolean;\n private transport: Transport;\n\n constructor(options: QueueClientOptions = {}) {\n this.baseUrl =\n options.baseUrl ||\n process.env.VERCEL_QUEUE_BASE_URL ||\n \"https://vercel-queue.com\";\n this.basePath =\n options.basePath || process.env.VERCEL_QUEUE_BASE_PATH || \"/api/v3/topic\";\n this.customHeaders = options.headers || {};\n this.providedToken = options.token;\n this.defaultDeploymentId =\n options.deploymentId || process.env.VERCEL_DEPLOYMENT_ID;\n this.pinToDeployment = options.pinToDeployment ?? true;\n this.transport = options.transport || new JsonTransport();\n }\n\n getTransport(): Transport {\n return this.transport;\n }\n\n private getSendDeploymentId(): string | undefined {\n if (isDevMode()) {\n return undefined;\n }\n if (this.pinToDeployment) {\n return this.defaultDeploymentId;\n }\n return undefined;\n }\n\n private getConsumeDeploymentId(): string | undefined {\n if (isDevMode()) {\n return undefined;\n }\n return this.defaultDeploymentId;\n }\n\n private async getToken(): Promise<string> {\n if (this.providedToken) {\n return this.providedToken;\n }\n\n const token = await getVercelOidcToken();\n if (!token) {\n throw new Error(\n \"Failed to get OIDC token from Vercel Functions. \" +\n \"Make sure you are running in a Vercel Function environment, or provide a token explicitly.\\n\\n\" +\n \"To set up your environment:\\n\" +\n \"1. Link your project: 'vercel link'\\n\" +\n \"2. Pull environment variables: 'vercel env pull'\\n\" +\n \"3. Run with environment: 'dotenv -e .env.local -- your-command'\",\n );\n }\n return token;\n }\n\n private buildUrl(queueName: string, ...pathSegments: string[]): string {\n const encodedQueue = encodeURIComponent(queueName);\n const segments = pathSegments.map((s) => encodeURIComponent(s));\n const path = segments.length > 0 ? \"/\" + segments.join(\"/\") : \"\";\n return `${this.baseUrl}${this.basePath}/${encodedQueue}${path}`;\n }\n\n private async fetch(\n url: string,\n init: RequestInit & { headers: Headers },\n ): Promise<Response> {\n const method = init.method || \"GET\";\n\n if (isDebugEnabled()) {\n const logData: Record<string, unknown> = {\n method,\n url,\n headers: init.headers,\n };\n\n const body = init.body;\n if (body !== undefined && body !== null) {\n if (body instanceof ArrayBuffer) {\n logData.bodySize = body.byteLength;\n } else if (body instanceof Uint8Array) {\n logData.bodySize = body.byteLength;\n } else if (typeof body === \"string\") {\n logData.bodySize = body.length;\n } else {\n logData.bodyType = typeof body;\n }\n }\n\n console.debug(\"[VQS Debug] Request:\", JSON.stringify(logData, null, 2));\n }\n\n init.headers.set(\"User-Agent\", `@vercel/queue/${__PACKAGE_VERSION__}`);\n init.headers.set(\"Vqs-Client-Ts\", new Date().toISOString());\n\n const response = await fetch(url, init);\n\n if (isDebugEnabled()) {\n const logData: Record<string, unknown> = {\n method,\n url,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n };\n\n console.debug(\"[VQS Debug] Response:\", JSON.stringify(logData, null, 2));\n }\n\n return response;\n }\n\n /**\n * Send a message to a topic.\n *\n * @param options - Message options including queue name, payload, and optional settings\n * @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)\n * @param options.payload - Message payload\n * @param options.idempotencyKey - Optional deduplication key (dedup window: min(retention, 24h))\n * @param options.retentionSeconds - Message TTL (default: 86400, min: 60, max: 86400)\n * @param options.delaySeconds - Delivery delay (default: 0, max: retentionSeconds)\n * @returns Promise with the generated messageId\n * @throws {DuplicateMessageError} When idempotency key was already used\n * @throws {ConsumerDiscoveryError} When consumer discovery fails\n * @throws {ConsumerRegistryNotConfiguredError} When registry not configured\n * @throws {BadRequestError} When parameters are invalid\n * @throws {UnauthorizedError} When authentication fails\n * @throws {ForbiddenError} When access is denied\n * @throws {InternalServerError} When server encounters an error\n */\n async sendMessage<T = unknown>(\n options: SendMessageOptions<T>,\n ): Promise<SendMessageResponse> {\n const transport = this.transport as Transport<T>;\n const {\n queueName,\n payload,\n idempotencyKey,\n retentionSeconds,\n delaySeconds,\n headers: optionHeaders,\n } = options;\n\n const headers = new Headers();\n\n // Add custom headers first\n if (this.customHeaders) {\n for (const [name, value] of Object.entries(this.customHeaders)) {\n headers.append(name, value);\n }\n }\n\n // Add per-message headers, excluding protected ones\n if (optionHeaders) {\n const protectedHeaderNames = new Set([\"authorization\", \"content-type\"]);\n const isProtectedHeader = (name: string): boolean => {\n const lower = name.toLowerCase();\n if (protectedHeaderNames.has(lower)) return true;\n return lower.startsWith(\"vqs-\");\n };\n\n for (const [name, value] of Object.entries(optionHeaders)) {\n if (!isProtectedHeader(name) && value !== undefined) {\n headers.append(name, value);\n }\n }\n }\n\n // Set critical headers last so they cannot be overridden\n headers.set(\"Authorization\", `Bearer ${await this.getToken()}`);\n headers.set(\"Content-Type\", transport.contentType);\n\n const deploymentId = this.getSendDeploymentId();\n if (deploymentId) {\n headers.set(\"Vqs-Deployment-Id\", deploymentId);\n }\n\n if (idempotencyKey) {\n headers.set(\"Vqs-Idempotency-Key\", idempotencyKey);\n }\n\n if (retentionSeconds !== undefined) {\n headers.set(\"Vqs-Retention-Seconds\", retentionSeconds.toString());\n }\n\n if (delaySeconds !== undefined) {\n headers.set(\"Vqs-Delay-Seconds\", delaySeconds.toString());\n }\n\n const serialized = transport.serialize(payload);\n const body = Buffer.isBuffer(serialized)\n ? new Uint8Array(serialized)\n : serialized;\n\n const response = await this.fetch(this.buildUrl(queueName), {\n method: \"POST\",\n body,\n headers,\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n if (response.status === 409) {\n throw new DuplicateMessageError(\n errorText || \"Duplicate idempotency key detected\",\n idempotencyKey,\n );\n }\n if (response.status === 502) {\n throw new ConsumerDiscoveryError(\n errorText || \"Consumer discovery failed\",\n deploymentId,\n );\n }\n if (response.status === 503) {\n throw new ConsumerRegistryNotConfiguredError(\n errorText || \"Consumer registry not configured\",\n );\n }\n throwCommonHttpError(\n response.status,\n response.statusText,\n errorText,\n \"send message\",\n );\n }\n\n const responseData = (await response.json()) as SendMessageResponse;\n\n return responseData;\n }\n\n /**\n * Receive messages from a topic as an async generator.\n *\n * When the queue is empty, the generator completes without yielding any\n * messages. Callers should handle the case where no messages are yielded.\n *\n * @param options - Receive options\n * @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)\n * @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)\n * @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)\n * @param options.limit - Max messages to retrieve (default: 1, min: 1, max: 10)\n * @yields Message objects with payload, messageId, receiptHandle, etc.\n * Yields nothing if queue is empty.\n * @throws {InvalidLimitError} When limit is outside 1-10 range\n * @throws {BadRequestError} When parameters are invalid\n * @throws {UnauthorizedError} When authentication fails\n * @throws {ForbiddenError} When access is denied\n * @throws {InternalServerError} When server encounters an error\n */\n async *receiveMessages<T = unknown>(\n options: ReceiveMessagesOptions<T>,\n ): AsyncGenerator<Message<T>, void, unknown> {\n const transport = this.transport as Transport<T>;\n const { queueName, consumerGroup, visibilityTimeoutSeconds, limit } =\n options;\n\n if (limit !== undefined && (limit < 1 || limit > 10)) {\n throw new InvalidLimitError(limit);\n }\n\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n Accept: \"multipart/mixed\",\n ...this.customHeaders,\n });\n\n if (visibilityTimeoutSeconds !== undefined) {\n headers.set(\n \"Vqs-Visibility-Timeout-Seconds\",\n visibilityTimeoutSeconds.toString(),\n );\n }\n\n if (limit !== undefined) {\n headers.set(\"Vqs-Max-Messages\", limit.toString());\n }\n\n const effectiveDeploymentId = this.getConsumeDeploymentId();\n if (effectiveDeploymentId) {\n headers.set(\"Vqs-Deployment-Id\", effectiveDeploymentId);\n }\n\n const response = await this.fetch(\n this.buildUrl(queueName, \"consumer\", consumerGroup),\n {\n method: \"POST\",\n headers,\n },\n );\n\n if (response.status === 204) {\n // Queue is empty - return without yielding any messages\n // Callers should handle the case where no messages are yielded\n return;\n }\n\n if (!response.ok) {\n const errorText = await response.text();\n throwCommonHttpError(\n response.status,\n response.statusText,\n errorText,\n \"receive messages\",\n );\n }\n\n for await (const multipartMessage of parseMultipartStream(response)) {\n try {\n const parsedHeaders = parseQueueHeaders(multipartMessage.headers);\n\n if (!parsedHeaders) {\n console.warn(\"Missing required queue headers in multipart part\");\n await consumeStream(multipartMessage.payload);\n continue;\n }\n\n const deserializedPayload = await transport.deserialize(\n multipartMessage.payload,\n );\n\n const message: Message<T> = {\n ...parsedHeaders,\n payload: deserializedPayload,\n };\n\n yield message;\n } catch (error) {\n console.warn(\"Failed to process multipart message:\", error);\n await consumeStream(multipartMessage.payload);\n }\n }\n }\n\n /**\n * Receive a specific message by its ID.\n *\n * @param options - Receive options\n * @param options.queueName - Topic name (pattern: `[A-Za-z0-9_-]+`)\n * @param options.consumerGroup - Consumer group name (pattern: `[A-Za-z0-9_-]+`)\n * @param options.messageId - Message ID to retrieve\n * @param options.visibilityTimeoutSeconds - Lock duration (default: 30, min: 0, max: 3600)\n * @returns Promise with the message\n * @throws {MessageNotFoundError} When message doesn't exist\n * @throws {MessageNotAvailableError} When message is in wrong state or was a duplicate\n * @throws {MessageAlreadyProcessedError} When message was already processed\n * @throws {BadRequestError} When parameters are invalid\n * @throws {UnauthorizedError} When authentication fails\n * @throws {ForbiddenError} When access is denied\n * @throws {InternalServerError} When server encounters an error\n */\n async receiveMessageById<T = unknown>(\n options: ReceiveMessageByIdOptions<T>,\n ): Promise<ReceiveMessageByIdResponse<T>> {\n const transport = this.transport as Transport<T>;\n const { queueName, consumerGroup, messageId, visibilityTimeoutSeconds } =\n options;\n\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n Accept: \"multipart/mixed\",\n ...this.customHeaders,\n });\n\n if (visibilityTimeoutSeconds !== undefined) {\n headers.set(\n \"Vqs-Visibility-Timeout-Seconds\",\n visibilityTimeoutSeconds.toString(),\n );\n }\n\n const effectiveDeploymentId = this.getConsumeDeploymentId();\n if (effectiveDeploymentId) {\n headers.set(\"Vqs-Deployment-Id\", effectiveDeploymentId);\n }\n\n const response = await this.fetch(\n this.buildUrl(queueName, \"consumer\", consumerGroup, \"id\", messageId),\n {\n method: \"POST\",\n headers,\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n if (response.status === 404) {\n throw new MessageNotFoundError(messageId);\n }\n if (response.status === 409) {\n let errorData: { error?: string; originalMessageId?: string } = {};\n try {\n errorData = JSON.parse(errorText);\n } catch {\n // ignore parse errors\n }\n\n if (errorData.originalMessageId) {\n throw new MessageNotAvailableError(\n messageId,\n `This message was a duplicate - use originalMessageId: ${errorData.originalMessageId}`,\n );\n }\n throw new MessageNotAvailableError(messageId);\n }\n if (response.status === 410) {\n throw new MessageAlreadyProcessedError(messageId);\n }\n throwCommonHttpError(\n response.status,\n response.statusText,\n errorText,\n \"receive message by ID\",\n );\n }\n\n for await (const multipartMessage of parseMultipartStream(response)) {\n const parsedHeaders = parseQueueHeaders(multipartMessage.headers);\n\n if (!parsedHeaders) {\n await consumeStream(multipartMessage.payload);\n throw new MessageCorruptedError(\n messageId,\n \"Missing required queue headers in response\",\n );\n }\n\n const deserializedPayload = await transport.deserialize(\n multipartMessage.payload,\n );\n\n const message: Message<T> = {\n ...parsedHeaders,\n payload: deserializedPayload,\n };\n\n return { message };\n }\n\n throw new MessageNotFoundError(messageId);\n }\n\n /**\n * Delete (acknowledge) a message after successful processing.\n *\n * @param options - Delete options\n * @param options.queueName - Topic name\n * @param options.consumerGroup - Consumer group name\n * @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)\n * @returns Promise indicating deletion success\n * @throws {MessageNotFoundError} When receipt handle not found\n * @throws {MessageNotAvailableError} When receipt handle invalid or message already processed\n * @throws {BadRequestError} When parameters are invalid\n * @throws {UnauthorizedError} When authentication fails\n * @throws {ForbiddenError} When access is denied\n * @throws {InternalServerError} When server encounters an error\n */\n async deleteMessage(\n options: DeleteMessageOptions,\n ): Promise<DeleteMessageResponse> {\n const { queueName, consumerGroup, receiptHandle } = options;\n\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n ...this.customHeaders,\n });\n\n const effectiveDeploymentId = this.getConsumeDeploymentId();\n if (effectiveDeploymentId) {\n headers.set(\"Vqs-Deployment-Id\", effectiveDeploymentId);\n }\n\n const response = await this.fetch(\n this.buildUrl(\n queueName,\n \"consumer\",\n consumerGroup,\n \"lease\",\n receiptHandle,\n ),\n {\n method: \"DELETE\",\n headers,\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n if (response.status === 404) {\n throw new MessageNotFoundError(receiptHandle);\n }\n if (response.status === 409) {\n throw new MessageNotAvailableError(\n receiptHandle,\n errorText ||\n \"Invalid receipt handle, message not in correct state, or already processed\",\n );\n }\n throwCommonHttpError(\n response.status,\n response.statusText,\n errorText,\n \"delete message\",\n \"Missing or invalid receipt handle\",\n );\n }\n\n return { deleted: true };\n }\n\n /**\n * Extend or change the visibility timeout of a message.\n * Used to prevent message redelivery while still processing.\n *\n * @param options - Visibility options\n * @param options.queueName - Topic name\n * @param options.consumerGroup - Consumer group name\n * @param options.receiptHandle - Receipt handle from the received message (must use same deployment ID as receive)\n * @param options.visibilityTimeoutSeconds - New timeout (min: 0, max: 3600, cannot exceed message expiration)\n * @returns Promise indicating success\n * @throws {MessageNotFoundError} When receipt handle not found\n * @throws {MessageNotAvailableError} When receipt handle invalid or message already processed\n * @throws {BadRequestError} When parameters are invalid\n * @throws {UnauthorizedError} When authentication fails\n * @throws {ForbiddenError} When access is denied\n * @throws {InternalServerError} When server encounters an error\n */\n async changeVisibility(\n options: ChangeVisibilityOptions,\n ): Promise<ChangeVisibilityResponse> {\n const {\n queueName,\n consumerGroup,\n receiptHandle,\n visibilityTimeoutSeconds,\n } = options;\n\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n \"Content-Type\": \"application/json\",\n ...this.customHeaders,\n });\n\n const effectiveDeploymentId = this.getConsumeDeploymentId();\n if (effectiveDeploymentId) {\n headers.set(\"Vqs-Deployment-Id\", effectiveDeploymentId);\n }\n\n const response = await this.fetch(\n this.buildUrl(\n queueName,\n \"consumer\",\n consumerGroup,\n \"lease\",\n receiptHandle,\n ),\n {\n method: \"PATCH\",\n headers,\n body: JSON.stringify({ visibilityTimeoutSeconds }),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n if (response.status === 404) {\n throw new MessageNotFoundError(receiptHandle);\n }\n if (response.status === 409) {\n throw new MessageNotAvailableError(\n receiptHandle,\n errorText ||\n \"Invalid receipt handle, message not in correct state, or already processed\",\n );\n }\n throwCommonHttpError(\n response.status,\n response.statusText,\n errorText,\n \"change visibility\",\n \"Missing receipt handle or invalid visibility timeout\",\n );\n }\n\n return { success: true };\n }\n\n /**\n * Alternative endpoint for changing message visibility timeout.\n * Uses the /visibility path suffix and expects visibilityTimeoutSeconds in the body.\n * Functionally equivalent to changeVisibility but follows an alternative API pattern.\n *\n * @param options - Options for changing visibility\n * @returns Promise resolving to change visibility response\n */\n async changeVisibilityAlt(\n options: ChangeVisibilityOptions,\n ): Promise<ChangeVisibilityResponse> {\n const {\n queueName,\n consumerGroup,\n receiptHandle,\n visibilityTimeoutSeconds,\n } = options;\n\n const headers = new Headers({\n Authorization: `Bearer ${await this.getToken()}`,\n \"Content-Type\": \"application/json\",\n ...this.customHeaders,\n });\n\n const effectiveDeploymentId = this.getConsumeDeploymentId();\n if (effectiveDeploymentId) {\n headers.set(\"Vqs-Deployment-Id\", effectiveDeploymentId);\n }\n\n const response = await this.fetch(\n this.buildUrl(\n queueName,\n \"consumer\",\n consumerGroup,\n \"lease\",\n receiptHandle,\n \"visibility\",\n ),\n {\n method: \"PATCH\",\n headers,\n body: JSON.stringify({ visibilityTimeoutSeconds }),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n if (response.status === 404) {\n throw new MessageNotFoundError(receiptHandle);\n }\n if (response.status === 409) {\n throw new MessageNotAvailableError(\n receiptHandle,\n errorText ||\n \"Invalid receipt handle, message not in correct state, or already processed\",\n );\n }\n throwCommonHttpError(\n response.status,\n response.statusText,\n errorText,\n \"change visibility (alt)\",\n \"Missing receipt handle or invalid visibility timeout\",\n );\n }\n\n return { success: true };\n }\n}\n","/**\n * Development mode utilities for local queue compatibility\n * This file contains helpers that enable local callback triggering in development mode\n *\n * Key behaviors:\n * - Discovers queue routes from vercel.json experimentalTriggers config\n * - Makes HTTP requests to trigger callbacks instead of calling registered handlers\n * - Supports wildcard topic patterns\n * - V3 compatibility: Polls for message visibility before triggering callbacks\n */\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { CLOUD_EVENT_TYPE_V2BETA, matchesWildcardPattern } from \"./callback\";\nimport { QueueClient } from \"./client\";\nimport { MessageNotFoundError, MessageAlreadyProcessedError } from \"./types\";\n\n/**\n * Global key for cached route mappings from vercel.json\n */\nconst ROUTE_MAPPINGS_KEY = Symbol.for(\"@vercel/queue.devRouteMappings\");\n\n/**\n * Route mapping from vercel.json experimentalTriggers\n */\ninterface DevRouteMapping {\n urlPath: string;\n topic: string;\n consumer: string;\n}\n\n/**\n * Convert a file path from vercel.json to a URL path\n * e.g., \"app/api/vm/queue/route.ts\" → \"/api/vm/queue\"\n */\nfunction filePathToUrlPath(filePath: string): string {\n let urlPath = filePath\n .replace(/^app\\//, \"/\")\n .replace(/^pages\\//, \"/\")\n .replace(/\\/route\\.(ts|mts|js|mjs|tsx|jsx)$/, \"\")\n .replace(/\\.(ts|mts|js|mjs|tsx|jsx)$/, \"\");\n\n if (!urlPath.startsWith(\"/\")) {\n urlPath = \"/\" + urlPath;\n }\n\n return urlPath;\n}\n\n/**\n * Convert a file path to a consumer group name using mnemonic escapes\n * Escapes: _ → __, / → _S, . → _D\n * e.g., \"app/api/simple-queue/route.ts\" → \"app_Sapi_Ssimple-queue_Sroute_Dts\"\n */\nfunction filePathToConsumerGroup(filePath: string): string {\n return filePath.replace(/_/g, \"__\").replace(/\\//g, \"_S\").replace(/\\./g, \"_D\");\n}\n\n/**\n * Read and cache route mappings from vercel.json\n * Returns null if vercel.json doesn't exist or has no queue triggers\n */\nfunction getDevRouteMappings(): DevRouteMapping[] | null {\n const g = globalThis as typeof globalThis & {\n [ROUTE_MAPPINGS_KEY]?: DevRouteMapping[] | null;\n };\n\n if (ROUTE_MAPPINGS_KEY in g) {\n return g[ROUTE_MAPPINGS_KEY] ?? null;\n }\n\n try {\n const vercelJsonPath = path.join(process.cwd(), \"vercel.json\");\n if (!fs.existsSync(vercelJsonPath)) {\n g[ROUTE_MAPPINGS_KEY] = null;\n return null;\n }\n\n const vercelJson = JSON.parse(fs.readFileSync(vercelJsonPath, \"utf-8\")) as {\n functions?: {\n [filePath: string]: {\n experimentalTriggers?: Array<{\n type: string;\n topic?: string;\n }>;\n };\n };\n };\n\n if (!vercelJson.functions) {\n g[ROUTE_MAPPINGS_KEY] = null;\n return null;\n }\n\n const mappings: DevRouteMapping[] = [];\n\n for (const [filePath, config] of Object.entries(vercelJson.functions)) {\n if (!config.experimentalTriggers) continue;\n\n for (const trigger of config.experimentalTriggers) {\n if (trigger.type?.startsWith(\"queue/\") && trigger.topic) {\n mappings.push({\n urlPath: filePathToUrlPath(filePath),\n topic: trigger.topic,\n consumer: filePathToConsumerGroup(filePath),\n });\n }\n }\n }\n\n g[ROUTE_MAPPINGS_KEY] = mappings.length > 0 ? mappings : null;\n return g[ROUTE_MAPPINGS_KEY];\n } catch (error) {\n console.warn(\"[Dev Mode] Failed to read vercel.json:\", error);\n g[ROUTE_MAPPINGS_KEY] = null;\n return null;\n }\n}\n\n/**\n * Find routes that match a topic name (supports wildcards)\n */\nfunction findMatchingRoutes(topicName: string): DevRouteMapping[] {\n const mappings = getDevRouteMappings();\n if (!mappings) {\n return [];\n }\n\n return mappings.filter((mapping) => {\n if (mapping.topic.includes(\"*\")) {\n return matchesWildcardPattern(topicName, mapping.topic);\n }\n return mapping.topic === topicName;\n });\n}\n\n/**\n * Check if running in development mode\n */\nexport function isDevMode(): boolean {\n return process.env.NODE_ENV === \"development\";\n}\n\n/**\n * Configuration for visibility polling in V3\n */\nconst DEV_VISIBILITY_POLL_INTERVAL = 50;\nconst DEV_VISIBILITY_MAX_WAIT = 5000;\nconst DEV_VISIBILITY_BACKOFF_MULTIPLIER = 2;\n\n/**\n * Wait for a message to become visible in the queue (V3 eventual consistency)\n * Polls receiveMessageById with visibilityTimeoutSeconds=0 until the message is available\n * @returns true if message became visible, false if timed out\n * @internal\n */\nasync function waitForMessageVisibility(\n topicName: string,\n consumerGroup: string,\n messageId: string,\n): Promise<boolean> {\n const client = new QueueClient();\n\n let elapsed = 0;\n let interval = DEV_VISIBILITY_POLL_INTERVAL;\n\n while (elapsed < DEV_VISIBILITY_MAX_WAIT) {\n try {\n await client.receiveMessageById({\n queueName: topicName,\n consumerGroup,\n messageId,\n visibilityTimeoutSeconds: 0,\n });\n return true;\n } catch (error) {\n if (error instanceof MessageNotFoundError) {\n await new Promise((resolve) => setTimeout(resolve, interval));\n elapsed += interval;\n interval = Math.min(\n interval * DEV_VISIBILITY_BACKOFF_MULTIPLIER,\n DEV_VISIBILITY_MAX_WAIT - elapsed,\n );\n continue;\n }\n if (error instanceof MessageAlreadyProcessedError) {\n console.log(\n `[Dev Mode] Message already processed: topic=\"${topicName}\" messageId=\"${messageId}\"`,\n );\n return false;\n }\n console.error(\n `[Dev Mode] Error polling for message visibility: topic=\"${topicName}\" messageId=\"${messageId}\"`,\n error,\n );\n return false;\n }\n }\n\n console.warn(\n `[Dev Mode] Message visibility timeout after ${DEV_VISIBILITY_MAX_WAIT}ms: topic=\"${topicName}\" messageId=\"${messageId}\"`,\n );\n return false;\n}\n\n/**\n * Trigger development mode callbacks for a topic\n * Discovers routes from vercel.json and makes HTTP requests to trigger callbacks\n * Waits for message visibility in V3 before making requests\n * @internal\n */\nexport function triggerDevCallbacks(\n topicName: string,\n messageId: string,\n delaySeconds?: number,\n): void {\n if (delaySeconds && delaySeconds > 0) {\n console.log(\n `[Dev Mode] Message sent with delay: topic=\"${topicName}\" messageId=\"${messageId}\" delay=${delaySeconds}s`,\n );\n setTimeout(() => {\n triggerDevCallbacks(topicName, messageId);\n }, delaySeconds * 1000);\n return;\n }\n\n console.log(\n `[Dev Mode] Message sent: topic=\"${topicName}\" messageId=\"${messageId}\"`,\n );\n\n const matchingRoutes = findMatchingRoutes(topicName);\n\n if (matchingRoutes.length === 0) {\n console.log(\n `[Dev Mode] No matching routes in vercel.json for topic \"${topicName}\"`,\n );\n return;\n }\n\n const consumerGroups = matchingRoutes.map((r) => r.consumer);\n\n console.log(\n `[Dev Mode] Scheduling callbacks for topic=\"${topicName}\" messageId=\"${messageId}\" → consumers: [${consumerGroups.join(\", \")}]`,\n );\n\n (async () => {\n const firstRoute = matchingRoutes[0];\n const isVisible = await waitForMessageVisibility(\n topicName,\n firstRoute.consumer,\n messageId,\n );\n\n if (!isVisible) {\n console.warn(\n `[Dev Mode] Skipping callbacks - message not visible: topic=\"${topicName}\" messageId=\"${messageId}\"`,\n );\n return;\n }\n\n const port = process.env.PORT || 3000;\n const baseUrl = `http://localhost:${port}`;\n\n for (const route of matchingRoutes) {\n const url = `${baseUrl}${route.urlPath}`;\n\n console.log(\n `[Dev Mode] Invoking handler: topic=\"${topicName}\" consumer=\"${route.consumer}\" messageId=\"${messageId}\" url=\"${url}\"`,\n );\n\n try {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"ce-type\": CLOUD_EVENT_TYPE_V2BETA,\n \"ce-vqsqueuename\": topicName,\n \"ce-vqsconsumergroup\": route.consumer,\n \"ce-vqsmessageid\": messageId,\n },\n });\n\n if (response.ok) {\n try {\n const responseData = (await response.json()) as {\n status?: string;\n };\n if (responseData.status === \"success\") {\n console.log(\n `[Dev Mode] ✓ Message processed successfully: topic=\"${topicName}\" consumer=\"${route.consumer}\" messageId=\"${messageId}\"`,\n );\n }\n } catch {\n console.warn(\n `[Dev Mode] Handler returned OK but response was not JSON: topic=\"${topicName}\" consumer=\"${route.consumer}\"`,\n );\n }\n } else {\n try {\n const errorData = (await response.json()) as { error?: string };\n console.error(\n `[Dev Mode] ✗ Handler failed: topic=\"${topicName}\" consumer=\"${route.consumer}\" messageId=\"${messageId}\" error=\"${errorData.error || response.statusText}\"`,\n );\n } catch {\n console.error(\n `[Dev Mode] ✗ Handler failed: topic=\"${topicName}\" consumer=\"${route.consumer}\" messageId=\"${messageId}\" status=${response.status}`,\n );\n }\n }\n } catch (error) {\n console.error(\n `[Dev Mode] ✗ HTTP request failed: topic=\"${topicName}\" consumer=\"${route.consumer}\" messageId=\"${messageId}\" url=\"${url}\"`,\n error,\n );\n }\n }\n })();\n}\n\n/**\n * Clear cached route mappings - for testing only\n * @internal\n */\nfunction clearDevRouteMappings(): void {\n const g = globalThis as typeof globalThis & {\n [ROUTE_MAPPINGS_KEY]?: DevRouteMapping[] | null;\n };\n delete g[ROUTE_MAPPINGS_KEY];\n}\n\n// Export for testing\nif (process.env.NODE_ENV === \"test\" || process.env.VITEST) {\n (globalThis as any).__clearDevRouteMappings = clearDevRouteMappings;\n}\n","/**\n * Vercel Queue Service client types\n */\nimport type { Transport } from \"./transports\";\n\n// Re-export transport interface for convenience\nexport type { Transport };\n\nexport interface QueueClientOptions {\n /**\n * Base URL for the Vercel Queue Service API.\n * Can also be set via VERCEL_QUEUE_BASE_URL environment variable.\n * @default \"https://vercel-queue.com\"\n */\n baseUrl?: string;\n\n /**\n * Base path for API endpoints.\n * Can also be set via VERCEL_QUEUE_BASE_PATH environment variable.\n * @default \"/api/v3/topic\"\n */\n basePath?: string;\n\n /**\n * Authentication token for the Vercel Queue Service API.\n * If not provided, the client will attempt to get a token via OIDC\n * when running in a Vercel Function environment.\n */\n token?: string;\n\n /**\n * Custom headers to include in all requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Deployment ID to include in requests.\n * Used for message routing and lease validation.\n * @default process.env.VERCEL_DEPLOYMENT_ID if pinToDeployment is true\n */\n deploymentId?: string;\n\n /**\n * Whether to pin messages to the current deployment when publishing.\n * When true, sends VERCEL_DEPLOYMENT_ID from environment, ensuring\n * messages are routed to consumers on the same deployment.\n *\n * - Only affects send/publish operations\n * - Consume operations always send deployment ID in production\n * - Ignored in development mode (deployment ID is never sent locally)\n * @default true\n */\n pinToDeployment?: boolean;\n\n /**\n * Serializer/deserializer for message payloads.\n * Used for all send and receive operations.\n * @default JsonTransport\n */\n transport?: Transport;\n}\n\n/**\n * Options for publishing messages to a topic.\n */\nexport interface PublishOptions {\n /**\n * Unique key to prevent duplicate message submissions.\n * Deduplication window: `min(message retention, 24 hours)`.\n */\n idempotencyKey?: string;\n\n /**\n * Message retention time in seconds. After this period, the message expires.\n * @default 86400 (24 hours)\n * @minimum 60 (1 minute)\n * @maximum 86400 (24 hours)\n */\n retentionSeconds?: number;\n\n /**\n * Delay delivery of the message by this many seconds.\n * The message will not be visible to consumers until the delay has passed.\n * @default 0\n * @minimum 0\n * @maximum Value of retentionSeconds (delay cannot exceed retention)\n */\n delaySeconds?: number;\n\n /**\n * Custom headers to include with this message.\n * These headers are passed through to the VQS server.\n */\n headers?: Record<string, string>;\n}\n\nexport interface SendMessageOptions<T = unknown> extends PublishOptions {\n /**\n * The topic/queue name to send the message to.\n * Must match pattern: `[A-Za-z0-9_-]+`\n */\n queueName: string;\n\n /**\n * The message payload. Will be serialized using the provided transport.\n */\n payload: T;\n}\n\nexport interface SendMessageResponse {\n /**\n * The generated message ID\n */\n messageId: string;\n}\n\nexport interface Message<T = unknown> {\n /**\n * Unique message identifier. Used for receive-by-ID operations.\n */\n messageId: string;\n\n /**\n * The deserialized message payload.\n * Note: If using StreamTransport, ensure proper cleanup by calling\n * `transport.finalize(payload)` when done processing, especially in error cases.\n */\n payload: T;\n\n /**\n * Number of times this message has been delivered.\n * Starts at 1 for the first delivery, increments on each retry.\n */\n deliveryCount: number;\n\n /**\n * Timestamp when the message was created/published.\n */\n createdAt: Date;\n\n /**\n * MIME type of the message content.\n * Set by the transport's `contentType` property during publish.\n */\n contentType: string;\n\n /**\n * Receipt handle (lease token) for this message delivery.\n * Required for delete and visibility extension operations.\n * Valid only until the visibility timeout expires.\n */\n receiptHandle: string;\n}\n\nexport interface ReceiveMessagesOptions<T = unknown> {\n /**\n * The topic/queue name to receive messages from.\n * Must match pattern: `[A-Za-z0-9_-]+`\n */\n queueName: string;\n\n /**\n * Consumer group name. Each consumer group maintains independent message state.\n * Must match pattern: `[A-Za-z0-9_-]+`\n */\n consumerGroup: string;\n\n /**\n * Time in seconds that messages will be invisible to other consumers after receipt.\n * Set to 0 for immediate re-visibility (useful for peeking).\n * @default 30\n * @minimum 0\n * @maximum 3600 (1 hour)\n */\n visibilityTimeoutSeconds?: number;\n\n /**\n * Maximum number of messages to retrieve in a single request.\n * @default 1\n * @minimum 1\n * @maximum 10\n */\n limit?: number;\n}\n\nexport interface DeleteMessageOptions {\n /**\n * The topic/queue name the message belongs to.\n */\n queueName: string;\n\n /**\n * Consumer group name.\n */\n consumerGroup: string;\n\n /**\n * Receipt handle received when the message was consumed.\n */\n receiptHandle: string;\n}\n\nexport interface DeleteMessageResponse {\n /**\n * Whether the message was successfully deleted\n */\n deleted: boolean;\n}\n\nexport interface ChangeVisibilityOptions {\n /**\n * The topic/queue name the message belongs to.\n */\n queueName: string;\n\n /**\n * Consumer group name.\n */\n consumerGroup: string;\n\n /**\n * Receipt handle received when the message was consumed.\n */\n receiptHandle: string;\n\n /**\n * New visibility timeout in seconds.\n * Cannot extend beyond the message's original expiration time.\n * @minimum 0\n * @maximum 3600 (1 hour)\n */\n visibilityTimeoutSeconds: number;\n}\n\nexport interface ChangeVisibilityResponse {\n /**\n * Whether the visibility was successfully updated\n */\n success: boolean;\n}\n\n/**\n * Message metadata provided to handlers\n */\nexport interface MessageMetadata {\n messageId: string;\n deliveryCount: number;\n createdAt: Date;\n topicName: string;\n consumerGroup: string;\n}\n\n/**\n * Message handler function type\n *\n * When a message is available, both `message` and `metadata` are provided.\n * When the queue is empty, both `message` and `metadata` are `null`.\n * This allows handlers to gracefully handle the empty queue case without\n * catching exceptions.\n */\nexport type MessageHandler<T = unknown> = (\n message: T | null,\n metadata: MessageMetadata | null,\n) => Promise<void> | void;\n\n/**\n * Options for creating a ConsumerGroup instance.\n */\nexport interface ConsumerGroupOptions<T = unknown> {\n /**\n * Time in seconds that messages will be invisible to other consumers after receipt.\n * The ConsumerGroup will automatically extend this timeout during processing.\n * @default 300 (5 minutes)\n * @minimum 30\n * @maximum 3600 (1 hour)\n */\n visibilityTimeoutSeconds?: number;\n}\n\nexport interface ReceiveMessageByIdOptions<T = unknown> {\n /**\n * The topic/queue name to receive the message from.\n * Must match pattern: `[A-Za-z0-9_-]+`\n */\n queueName: string;\n\n /**\n * Consumer group name.\n * Must match pattern: `[A-Za-z0-9_-]+`\n */\n consumerGroup: string;\n\n /**\n * The specific message ID to retrieve.\n */\n messageId: string;\n\n /**\n * Time in seconds that the message will be invisible to other consumers after receipt.\n * @default 30\n * @minimum 0\n * @maximum 3600 (1 hour)\n */\n visibilityTimeoutSeconds?: number;\n}\n\nexport interface ReceiveMessageByIdResponse<T = unknown> {\n message: Message<T>;\n}\n\n/**\n * Error thrown when a message does not exist or has expired.\n */\nexport class MessageNotFoundError extends Error {\n constructor(messageId: string) {\n super(`Message ${messageId} not found`);\n this.name = \"MessageNotFoundError\";\n }\n}\n\n/**\n * Error thrown when a message exists but cannot be processed.\n * This can happen when the message is in the wrong state or already claimed by another consumer.\n */\nexport class MessageNotAvailableError extends Error {\n constructor(messageId: string, reason?: string) {\n super(\n `Message ${messageId} not available for processing${reason ? `: ${reason}` : \"\"}`,\n );\n this.name = \"MessageNotAvailableError\";\n }\n}\n\n/**\n * Error thrown when message data is corrupted or can't be parsed\n */\nexport class MessageCorruptedError extends Error {\n constructor(messageId: string, reason: string) {\n super(`Message ${messageId} is corrupted: ${reason}`);\n this.name = \"MessageCorruptedError\";\n }\n}\n\n/**\n * Error thrown when there are no messages available in the queue.\n */\nexport class QueueEmptyError extends Error {\n constructor(queueName: string, consumerGroup: string) {\n super(\n `No messages available in queue \"${queueName}\" for consumer group \"${consumerGroup}\"`,\n );\n this.name = \"QueueEmptyError\";\n }\n}\n\n/**\n * Error thrown when a message is temporarily locked by another consumer.\n * The message is currently being processed and cannot be claimed.\n */\nexport class MessageLockedError extends Error {\n /** Suggested retry delay in seconds, if provided by the server. */\n public readonly retryAfter?: number;\n\n constructor(messageId: string, retryAfter?: number) {\n const retryMessage = retryAfter\n ? ` Retry after ${retryAfter} seconds.`\n : \" Try again later.\";\n super(`Message ${messageId} is temporarily locked.${retryMessage}`);\n this.name = \"MessageLockedError\";\n this.retryAfter = retryAfter;\n }\n}\n\n/**\n * Error thrown when authentication fails.\n * This typically means the token is missing, invalid, or expired.\n */\nexport class UnauthorizedError extends Error {\n constructor(message: string = \"Missing or invalid authentication token\") {\n super(message);\n this.name = \"UnauthorizedError\";\n }\n}\n\n/**\n * Error thrown when access is forbidden.\n * This typically means the queue belongs to a different environment or project.\n */\nexport class ForbiddenError extends Error {\n constructor(\n message: string = \"Queue environment doesn't match token environment\",\n ) {\n super(message);\n this.name = \"ForbiddenError\";\n }\n}\n\n/**\n * Error thrown when request parameters are invalid.\n */\nexport class BadRequestError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"BadRequestError\";\n }\n}\n\n/**\n * Error thrown when the server encounters an unexpected error.\n */\nexport class InternalServerError extends Error {\n constructor(message: string = \"Unexpected server error\") {\n super(message);\n this.name = \"InternalServerError\";\n }\n}\n\n/**\n * Error thrown when the batch limit parameter is outside the valid range.\n * The limit must be between 1 and 10 (inclusive).\n */\nexport class InvalidLimitError extends Error {\n constructor(limit: number, min: number = 1, max: number = 10) {\n super(`Invalid limit: ${limit}. Limit must be between ${min} and ${max}.`);\n this.name = \"InvalidLimitError\";\n }\n}\n\n/**\n * Error thrown when attempting to process a message that has already been successfully processed.\n */\nexport class MessageAlreadyProcessedError extends Error {\n constructor(messageId: string) {\n super(`Message ${messageId} has already been processed`);\n this.name = \"MessageAlreadyProcessedError\";\n }\n}\n\n/**\n * Error thrown when a duplicate idempotency key is detected.\n * The message was already sent within the deduplication window.\n */\nexport class DuplicateMessageError extends Error {\n public readonly idempotencyKey?: string;\n\n constructor(message: string, idempotencyKey?: string) {\n super(message);\n this.name = \"DuplicateMessageError\";\n this.idempotencyKey = idempotencyKey;\n }\n}\n\n/**\n * Error thrown when consumer discovery fails.\n * This typically means the deployment could not be reached or is not configured correctly.\n */\nexport class ConsumerDiscoveryError extends Error {\n public readonly deploymentId?: string;\n\n constructor(message: string, deploymentId?: string) {\n super(message);\n this.name = \"ConsumerDiscoveryError\";\n this.deploymentId = deploymentId;\n }\n}\n\n/**\n * Error thrown when the consumer registry is not configured for the project.\n */\nexport class ConsumerRegistryNotConfiguredError extends Error {\n constructor(message: string = \"Consumer registry not configured\") {\n super(message);\n this.name = \"ConsumerRegistryNotConfiguredError\";\n }\n}\n","export { getVercelOidcToken } from \"@vercel/oidc\";\n","/**\n * Serializer/Deserializer interface for message payloads.\n *\n * Built-in implementations:\n * - `JsonTransport` - JSON serialization (default, buffers entire payload)\n * - `BufferTransport` - Binary data (buffers entire payload)\n * - `StreamTransport` - Pass-through streaming (no buffering, ideal for large payloads)\n */\nexport interface Transport<T = unknown> {\n /**\n * Serialize a value to a buffer or stream for transmission.\n * The result is sent as the request body with the `contentType` header.\n */\n serialize(value: T): Buffer | ReadableStream<Uint8Array>;\n\n /**\n * Deserialize a readable stream back to the original value.\n * Called when receiving messages from the queue.\n */\n deserialize(stream: ReadableStream<Uint8Array>): Promise<T>;\n\n /**\n * Optional cleanup method for deserialized payloads that may contain resources.\n * Called automatically by ConsumerGroup on error; manual cleanup required for direct client usage.\n * @param payload The deserialized payload to clean up\n */\n finalize?(payload: T): Promise<void>;\n\n /**\n * MIME type for this serialization format.\n * Sent as the Content-Type header when publishing messages.\n */\n contentType: string;\n}\n\nasync function streamToBuffer(\n stream: ReadableStream<Uint8Array>,\n): Promise<Buffer> {\n let totalLength = 0;\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n totalLength += value.length;\n }\n } finally {\n reader.releaseLock();\n }\n\n // Combine chunks into a single buffer\n return Buffer.concat(chunks, totalLength);\n}\n\n/**\n * JSON serializer/deserializer (default transport).\n *\n * Ideal for structured data. Buffers the entire payload in memory for parsing.\n *\n * @example\n * ```typescript\n * // Default usage\n * await send(\"topic\", { data: \"example\" });\n *\n * // With custom serialization\n * const transport = new JsonTransport({\n * replacer: (key, value) => key === \"password\" ? undefined : value,\n * reviver: (key, value) => key === \"date\" ? new Date(value) : value,\n * });\n * await send(\"topic\", { data: \"example\" }, { transport });\n * ```\n */\nexport class JsonTransport<T = unknown> implements Transport<T> {\n readonly contentType = \"application/json\";\n readonly replacer?: Parameters<typeof JSON.stringify>[1];\n readonly reviver?: Parameters<typeof JSON.parse>[1];\n\n /**\n * Create a new JsonTransport.\n * @param options - Optional JSON serialization options\n * @param options.replacer - Custom replacer for JSON.stringify\n * @param options.reviver - Custom reviver for JSON.parse\n */\n constructor(\n options: {\n replacer?: Parameters<typeof JSON.stringify>[1];\n reviver?: Parameters<typeof JSON.parse>[1];\n } = {},\n ) {\n this.replacer = options.replacer;\n this.reviver = options.reviver;\n }\n\n serialize(value: T): Buffer {\n return Buffer.from(JSON.stringify(value, this.replacer), \"utf8\");\n }\n\n async deserialize(stream: ReadableStream<Uint8Array>): Promise<T> {\n const buffer = await streamToBuffer(stream);\n return JSON.parse(buffer.toString(\"utf8\"), this.reviver);\n }\n}\n\n/**\n * Binary data serializer/deserializer.\n *\n * Ideal for binary data that fits in memory. Buffers the entire payload.\n *\n * @example\n * ```typescript\n * const transport = new BufferTransport();\n * await send(\"binary-topic\", myBuffer, { transport });\n * ```\n */\nexport class BufferTransport implements Transport<Buffer> {\n readonly contentType = \"application/octet-stream\";\n\n serialize(value: Buffer): Buffer {\n return value;\n }\n\n async deserialize(stream: ReadableStream<Uint8Array>): Promise<Buffer> {\n return await streamToBuffer(stream);\n }\n}\n\n/**\n * Pass-through stream serializer/deserializer.\n *\n * Ideal for large files and real-time streams. Does not buffer data in memory.\n *\n * **Important:** When using StreamTransport, you must call `finalize(payload)` when done\n * processing to prevent resource leaks. ConsumerGroup handles this automatically;\n * direct client usage requires manual cleanup.\n *\n * @example\n * ```typescript\n * const transport = new StreamTransport();\n *\n * // Sending a stream\n * await send(\"large-file\", myReadableStream, { transport });\n *\n * // Receiving - cleanup handled by ConsumerGroup\n * await receive(\"large-file\", \"processor\", async (stream, meta) => {\n * const reader = stream.getReader();\n * // Process chunks...\n * }, { transport });\n *\n * // Direct client usage - manual cleanup required\n * try {\n * for await (const msg of client.receiveMessages(options, transport)) {\n * // Process stream...\n * }\n * } catch (error) {\n * await transport.finalize(msg.payload); // Manual cleanup\n * }\n * ```\n */\nexport class StreamTransport implements Transport<ReadableStream<Uint8Array>> {\n readonly contentType = \"application/octet-stream\";\n\n serialize(value: ReadableStream<Uint8Array>): ReadableStream<Uint8Array> {\n return value;\n }\n\n async deserialize(\n stream: ReadableStream<Uint8Array>,\n ): Promise<ReadableStream<Uint8Array>> {\n return stream;\n }\n\n /**\n * Consume any remaining stream data to prevent resource leaks.\n * Called automatically by ConsumerGroup; manual call required for direct client usage.\n */\n async finalize(payload: ReadableStream<Uint8Array>): Promise<void> {\n const reader = payload.getReader();\n try {\n while (true) {\n const { done } = await reader.read();\n if (done) break;\n }\n } finally {\n reader.releaseLock();\n }\n }\n}\n","import { QueueClient } from \"./client\";\nimport type { ConsumerGroupOptions, Message, MessageHandler } from \"./types\";\nimport {\n BadRequestError,\n ForbiddenError,\n MessageNotAvailableError,\n MessageNotFoundError,\n UnauthorizedError,\n} from \"./types\";\n\n/**\n * Default visibility timeout in seconds (5 minutes).\n * This is the initial lock duration requested when receiving messages.\n */\nconst DEFAULT_VISIBILITY_TIMEOUT_SECONDS = 300;\n\n/**\n * Minimum visibility timeout in seconds.\n * Ensures auto-extension has enough time to renew before the lease expires.\n */\nconst MIN_VISIBILITY_TIMEOUT_SECONDS = 30;\n\n/**\n * Maximum renewal interval in seconds.\n * Even for very long visibility timeouts, we renew at least this often.\n */\nconst MAX_RENEWAL_INTERVAL_SECONDS = 60;\n\n/**\n * Minimum renewal interval in seconds.\n * Even for very short visibility timeouts, we don't renew more frequently than this.\n */\nconst MIN_RENEWAL_INTERVAL_SECONDS = 10;\n\n/**\n * Interval in milliseconds between retry attempts when extension fails.\n * On transient failures, retry every 3 seconds.\n */\nconst RETRY_INTERVAL_MS = 3000;\n\n/**\n * Calculate the renewal interval based on visibility timeout.\n * Formula: min(60, max(10, visibilityTimeout / 5))\n *\n * Examples:\n * - 300s visibility → 60s interval (300/5 = 60, capped at 60)\n * - 200s visibility → 40s interval (200/5 = 40)\n * - 100s visibility → 20s interval (100/5 = 20)\n * - 30s visibility → 10s interval (30/5 = 6, floored at 10)\n */\nfunction calculateRenewalInterval(visibilityTimeoutSeconds: number): number {\n return Math.min(\n MAX_RENEWAL_INTERVAL_SECONDS,\n Math.max(MIN_RENEWAL_INTERVAL_SECONDS, visibilityTimeoutSeconds / 5),\n );\n}\n\n/**\n * Options for consuming a specific message by ID.\n */\nexport interface ConsumeByIdOptions {\n /** The specific message ID to consume */\n messageId: string;\n}\n\n/**\n * Options for consuming messages from the queue.\n */\nexport interface ConsumeBatchOptions {\n /**\n * Maximum number of messages to retrieve in a single request.\n * @default 1\n * @minimum 1\n * @maximum 10\n */\n limit?: number;\n}\n\n/**\n * Options for the consume method. Either consume by message ID or consume\n * from the queue with an optional limit. These options are mutually exclusive.\n */\nexport type ConsumeOptions = ConsumeByIdOptions | ConsumeBatchOptions;\n\n/**\n * A ConsumerGroup processes messages from a topic with automatic lifecycle management.\n *\n * Features:\n * - Independent message state per group (each group receives a copy of every message)\n * - Automatic visibility timeout extension during processing\n * - Automatic message deletion on successful handler completion\n */\nexport class ConsumerGroup<T = unknown> {\n private client: QueueClient;\n private topicName: string;\n private consumerGroupName: string;\n private visibilityTimeout: number;\n\n /**\n * Create a new ConsumerGroup instance.\n *\n * @param client - QueueClient instance to use for API calls (transport is configured on the client)\n * @param topicName - Name of the topic to consume from (pattern: `[A-Za-z0-9_-]+`)\n * @param consumerGroupName - Name of the consumer group (pattern: `[A-Za-z0-9_-]+`)\n * @param options - Optional configuration\n * @param options.visibilityTimeoutSeconds - Message lock duration (default: 300, max: 3600)\n */\n constructor(\n client: QueueClient,\n topicName: string,\n consumerGroupName: string,\n options: ConsumerGroupOptions<T> = {},\n ) {\n this.client = client;\n this.topicName = topicName;\n this.consumerGroupName = consumerGroupName;\n this.visibilityTimeout = Math.max(\n MIN_VISIBILITY_TIMEOUT_SECONDS,\n options.visibilityTimeoutSeconds ?? DEFAULT_VISIBILITY_TIMEOUT_SECONDS,\n );\n }\n\n /**\n * Check if an error is a 4xx client error that should stop retries.\n * 4xx errors indicate the request is fundamentally invalid and retrying won't help.\n * - 409: Ticket mismatch (lost ownership to another consumer)\n * - 404: Message/receipt handle not found\n * - 400, 401, 403: Other client errors\n */\n private isClientError(error: unknown): boolean {\n return (\n error instanceof MessageNotAvailableError || // 409 - ticket mismatch, lost ownership\n error instanceof MessageNotFoundError || // 404 - receipt handle not found\n error instanceof BadRequestError || // 400 - invalid parameters\n error instanceof UnauthorizedError || // 401 - auth failed\n error instanceof ForbiddenError // 403 - access denied\n );\n }\n\n /**\n * Starts a background loop that periodically extends the visibility timeout for a message.\n *\n * Timing strategy:\n * - Renewal interval: min(60s, max(10s, visibilityTimeout/5))\n * - Extensions request the same duration as the initial visibility timeout\n * - When `visibilityDeadline` is provided (binary mode small body), the first\n * extension delay is calculated from the time remaining until the deadline\n * using the same renewal formula, ensuring the first extension fires before\n * the server-assigned lease expires. Subsequent renewals use the standard interval.\n *\n * Retry strategy:\n * - On transient failures (5xx, network errors): retry every 3 seconds\n * - On 4xx client errors: stop retrying (the lease is lost or invalid)\n *\n * @param receiptHandle - The receipt handle to extend visibility for\n * @param options - Optional configuration\n * @param options.visibilityDeadline - Absolute deadline (from server's `ce-vqsvisibilitydeadline`)\n * when the current visibility timeout expires. Used to calculate the first extension delay.\n */\n private startVisibilityExtension(\n receiptHandle: string,\n options?: { visibilityDeadline?: Date },\n ): (waitForCompletion?: boolean) => Promise<void> {\n let isRunning = true;\n let isResolved = false;\n let resolveLifecycle: () => void;\n let timeoutId: NodeJS.Timeout | null = null;\n\n const renewalIntervalMs =\n calculateRenewalInterval(this.visibilityTimeout) * 1000;\n\n let firstDelayMs = renewalIntervalMs;\n if (options?.visibilityDeadline) {\n const timeRemainingMs = options.visibilityDeadline.getTime() - Date.now();\n if (timeRemainingMs > 0) {\n const timeRemainingSeconds = timeRemainingMs / 1000;\n firstDelayMs = calculateRenewalInterval(timeRemainingSeconds) * 1000;\n } else {\n firstDelayMs = 0;\n }\n }\n\n // Promise that tracks the actual termination of the extension loop\n const lifecyclePromise = new Promise<void>((resolve) => {\n resolveLifecycle = resolve;\n });\n\n const safeResolve = () => {\n if (!isResolved) {\n isResolved = true;\n resolveLifecycle();\n }\n };\n\n const extend = async (): Promise<void> => {\n // Check if we should stop before attempting extension\n if (!isRunning) {\n safeResolve();\n return;\n }\n\n try {\n await this.client.changeVisibility({\n queueName: this.topicName,\n consumerGroup: this.consumerGroupName,\n receiptHandle,\n visibilityTimeoutSeconds: this.visibilityTimeout,\n });\n\n // Successfully extended - schedule next extension\n if (isRunning) {\n timeoutId = setTimeout(() => extend(), renewalIntervalMs);\n } else {\n safeResolve();\n }\n } catch (error) {\n // Check if this is a 4xx client error - stop retrying\n if (this.isClientError(error)) {\n console.error(\n `Visibility extension failed with client error for receipt handle ${receiptHandle} (stopping retries):`,\n error,\n );\n safeResolve();\n return;\n }\n\n // Transient error - log and schedule retry\n console.error(\n `Failed to extend visibility for receipt handle ${receiptHandle} (will retry in ${RETRY_INTERVAL_MS / 1000}s):`,\n error,\n );\n\n // Retry after RETRY_INTERVAL_MS if still running\n if (isRunning) {\n timeoutId = setTimeout(() => extend(), RETRY_INTERVAL_MS);\n } else {\n safeResolve();\n }\n }\n };\n\n timeoutId = setTimeout(() => extend(), firstDelayMs);\n\n // Return a function to stop the extension loop\n return async (waitForCompletion: boolean = false) => {\n // Signal the loop to stop\n isRunning = false;\n\n // Cancel any pending timeout to avoid unnecessary waiting\n if (timeoutId) {\n clearTimeout(timeoutId);\n timeoutId = null;\n }\n\n // Only wait for in-flight operations if explicitly requested\n if (waitForCompletion) {\n // Wait for the loop to actually terminate\n // This ensures any in-progress extension completes or fails\n await lifecyclePromise;\n } else {\n safeResolve();\n }\n };\n }\n\n private async processMessage<TPayload>(\n message: Message<TPayload>,\n handler: MessageHandler<TPayload>,\n options?: { visibilityDeadline?: Date },\n ): Promise<void> {\n const stopExtension = this.startVisibilityExtension(\n message.receiptHandle,\n options,\n );\n\n try {\n await handler(message.payload, {\n messageId: message.messageId,\n deliveryCount: message.deliveryCount,\n createdAt: message.createdAt,\n topicName: this.topicName,\n consumerGroup: this.consumerGroupName,\n });\n // Stop extensions immediately - we don't need to wait for in-flight extensions\n // since we're about to delete the message anyway\n await stopExtension();\n\n await this.client.deleteMessage({\n queueName: this.topicName,\n consumerGroup: this.consumerGroupName,\n receiptHandle: message.receiptHandle,\n });\n } catch (error) {\n // Stop extensions immediately on error - fail fast without waiting\n // for any in-flight extension attempts\n await stopExtension();\n\n // Clean up the message payload if the transport supports it and payload exists\n const transport = this.client.getTransport();\n if (\n transport.finalize &&\n message.payload !== undefined &&\n message.payload !== null\n ) {\n try {\n await transport.finalize(message.payload);\n } catch (finalizeError) {\n console.warn(\"Failed to finalize message payload:\", finalizeError);\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Process a pre-fetched message directly, without calling `receiveMessageById`.\n *\n * Used by the binary mode (v2beta) small body fast path, where the server\n * pushes the full message payload in the callback request. The message is\n * processed with the same lifecycle guarantees as `consume()`:\n * - Visibility timeout is extended periodically during processing\n * - Message is deleted on successful handler completion\n * - Payload is finalized on error if the transport supports it\n *\n * @param handler - Function to process the message payload and metadata\n * @param message - The complete message including payload and receipt handle\n * @param options - Optional configuration\n * @param options.visibilityDeadline - Absolute deadline when the server-assigned\n * visibility timeout expires (from `ce-vqsvisibilitydeadline`). Used to\n * schedule the first visibility extension before the lease expires.\n */\n async consumeMessage(\n handler: MessageHandler<T>,\n message: Message<T>,\n options?: { visibilityDeadline?: Date },\n ): Promise<void> {\n await this.processMessage(message, handler, options);\n }\n\n /**\n * Consume the next available message from the queue.\n *\n * The message is automatically:\n * - Locked with the configured visibility timeout\n * - Kept alive via periodic visibility extensions during processing\n * - Deleted upon successful handler completion\n * - Released for retry if the handler throws an error\n *\n * When the queue is empty, the handler is called with `null` for both\n * message and metadata, allowing graceful handling without exceptions.\n *\n * @param handler - Function to process the message payload and metadata.\n * Receives (null, null) when queue is empty.\n * @returns Promise that resolves when the message is processed and deleted,\n * or when the handler returns after receiving null (empty queue)\n * @throws Handler errors are re-thrown after cleanup\n */\n async consume(handler: MessageHandler<T>): Promise<void>;\n\n /**\n * Consume a specific message by its ID.\n *\n * Used for targeted message processing, typically from webhook callbacks.\n *\n * @param handler - Function to process the message payload and metadata\n * @param options - Options containing the messageId to consume\n * @param options.messageId - Specific message ID to consume\n * @returns Promise that resolves when the message is processed and deleted\n * @throws {MessageNotFoundError} When message doesn't exist\n * @throws {MessageNotAvailableError} When message in wrong state\n * @throws {MessageAlreadyProcessedError} When already processed\n * @throws Handler errors are re-thrown after cleanup\n */\n async consume(\n handler: MessageHandler<T>,\n options: ConsumeByIdOptions,\n ): Promise<void>;\n\n /**\n * Consume messages from the queue with an optional batch limit.\n *\n * Fetches up to `limit` messages in a single request and processes them\n * sequentially with the provided handler.\n *\n * @param handler - Function to process each message payload and metadata.\n * Receives (null, null) when queue is empty.\n * @param options - Options containing the limit\n * @param options.limit - Maximum messages to retrieve (default: 1, min: 1, max: 10)\n * @returns Promise that resolves when all messages are processed\n * @throws Handler errors are re-thrown after cleanup\n */\n async consume(\n handler: MessageHandler<T>,\n options: ConsumeBatchOptions,\n ): Promise<void>;\n\n async consume(\n handler: MessageHandler<T>,\n options?: ConsumeOptions,\n ): Promise<void> {\n if (options && \"messageId\" in options) {\n const response = await this.client.receiveMessageById<T>({\n queueName: this.topicName,\n consumerGroup: this.consumerGroupName,\n messageId: options.messageId,\n visibilityTimeoutSeconds: this.visibilityTimeout,\n });\n await this.processMessage<T>(response.message, handler);\n } else {\n const limit = options && \"limit\" in options ? options.limit : 1;\n let messageFound = false;\n\n for await (const message of this.client.receiveMessages<T>({\n queueName: this.topicName,\n consumerGroup: this.consumerGroupName,\n visibilityTimeoutSeconds: this.visibilityTimeout,\n limit,\n })) {\n messageFound = true;\n await this.processMessage<T>(message, handler);\n }\n\n if (!messageFound) {\n await handler(null, null);\n }\n }\n }\n\n /**\n * Get the consumer group name\n */\n get name(): string {\n return this.consumerGroupName;\n }\n\n /**\n * Get the topic name this consumer group is subscribed to\n */\n get topic(): string {\n return this.topicName;\n }\n}\n","import { QueueClient } from \"./client\";\nimport { ConsumerGroup } from \"./consumer-group\";\nimport type { ConsumerGroupOptions, PublishOptions } from \"./types\";\nimport { isDevMode, triggerDevCallbacks } from \"./dev\";\n\n/**\n * A Topic represents a named channel for publishing messages in a pub/sub pattern\n */\nexport class Topic<T = unknown> {\n private client: QueueClient;\n private topicName: string;\n\n /**\n * Create a new Topic instance\n * @param client QueueClient instance to use for API calls (transport is configured on the client)\n * @param topicName Name of the topic to work with\n */\n constructor(client: QueueClient, topicName: string) {\n this.client = client;\n this.topicName = topicName;\n }\n\n /**\n * Publish a message to the topic\n * @param payload The data to publish\n * @param options Optional publish options\n * @returns An object containing the message ID\n * @throws {BadRequestError} When request parameters are invalid\n * @throws {UnauthorizedError} When authentication fails\n * @throws {ForbiddenError} When access is denied (environment mismatch)\n * @throws {InternalServerError} When server encounters an error\n */\n async publish(\n payload: T,\n options?: PublishOptions,\n ): Promise<{ messageId: string }> {\n const result = await this.client.sendMessage<T>({\n queueName: this.topicName,\n payload,\n idempotencyKey: options?.idempotencyKey,\n retentionSeconds: options?.retentionSeconds,\n delaySeconds: options?.delaySeconds,\n headers: options?.headers,\n });\n\n // In development mode, automatically trigger registered callbacks after 1s\n if (isDevMode()) {\n triggerDevCallbacks(this.topicName, result.messageId);\n }\n\n return { messageId: result.messageId };\n }\n\n /**\n * Create a consumer group for this topic\n * @param consumerGroupName Name of the consumer group\n * @param options Optional configuration for the consumer group\n * @returns A ConsumerGroup instance\n */\n consumerGroup<U = T>(\n consumerGroupName: string,\n options?: ConsumerGroupOptions<U>,\n ): ConsumerGroup<U> {\n return new ConsumerGroup<U>(\n this.client,\n this.topicName,\n consumerGroupName,\n options,\n );\n }\n\n /**\n * Get the topic name\n */\n get name(): string {\n return this.topicName;\n }\n}\n","/**\n * Core queue callback utilities for handling incoming webhook payloads\n * from Vercel triggers using the CloudEvent specification.\n *\n * This module provides the framework-agnostic core. For framework-specific\n * wrappers, see `@vercel/queue/web` and `@vercel/queue/nextjs/pages`.\n */\nimport { QueueClient } from \"./client\";\nimport { Topic } from \"./topic\";\nimport type { Message, MessageHandler } from \"./types\";\nimport type { Transport } from \"./transports\";\n\n/**\n * CloudEvent specification for queue callbacks.\n *\n * Incoming webhook payloads from Vercel follow the CloudEvents v1.0 spec\n * with queue-specific data fields.\n *\n * @see https://cloudevents.io/\n */\nexport interface CloudEvent<T = unknown> {\n /** Event type identifier, e.g. `\"com.vercel.queue.v1beta\"` (structured) or `\"com.vercel.queue.v2beta\"` (binary) */\n type: string;\n /** Event source URI, e.g. `\"/topic/my-topic/consumer/my-group\"` */\n source: string;\n /** Unique event identifier */\n id: string;\n /** MIME type of the `data` field */\n datacontenttype: string;\n /** Event payload containing queue message metadata */\n data: T;\n /** ISO 8601 timestamp of when the event was produced */\n time?: string;\n /** CloudEvents specification version */\n specversion?: string;\n}\n\n/**\n * Options for configuring `handleCallback` behavior.\n */\nexport interface HandleCallbackOptions {\n /**\n * QueueClient instance to use for processing messages.\n * If not provided, a default client is created with OIDC authentication\n * and JsonTransport.\n */\n client?: QueueClient;\n\n /**\n * Time in seconds that messages will be invisible to other consumers\n * during processing. The handler will automatically extend this timeout\n * while processing.\n *\n * @default 300 (5 minutes)\n * @minimum 30\n * @maximum 3600 (1 hour)\n */\n visibilityTimeoutSeconds?: number;\n}\n\nexport const CLOUD_EVENT_TYPE_V1BETA = \"com.vercel.queue.v1beta\";\nexport const CLOUD_EVENT_TYPE_V2BETA = \"com.vercel.queue.v2beta\";\n\n/**\n * Routing-only callback: the SDK must fetch the message by ID.\n * Produced by v1beta structured mode and v2beta large-body mode.\n */\nexport type ParsedCallbackV1 = {\n queueName: string;\n consumerGroup: string;\n messageId: string;\n};\n\n/**\n * Full-message callback: payload and receipt handle are inlined,\n * so the SDK can process directly without an extra fetch.\n * Produced by v2beta small-body mode.\n */\nexport type ParsedCallbackV2 = {\n queueName: string;\n consumerGroup: string;\n messageId: string;\n receiptHandle: string;\n deliveryCount?: number;\n createdAt?: string;\n contentType?: string;\n visibilityDeadline?: string;\n rawBody?: ReadableStream<Uint8Array>;\n parsedPayload?: unknown;\n};\n\nexport type ParsedCallbackRequest = ParsedCallbackV1 | ParsedCallbackV2;\n\n/**\n * Check if a topic name matches a wildcard pattern.\n * Used by dev mode for route discovery from vercel.json.\n *\n * @param topicName - The topic name to test\n * @param pattern - A wildcard pattern ending with `*`\n * @returns `true` if topicName starts with the pattern prefix\n */\nexport function matchesWildcardPattern(\n topicName: string,\n pattern: string,\n): boolean {\n // Remove the trailing *\n const prefix = pattern.slice(0, -1);\n return topicName.startsWith(prefix);\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Parse and validate a v1beta structured CloudEvent body.\n *\n * @internal\n */\nfunction parseV1StructuredBody(\n body: unknown,\n contentType: string | null,\n): ParsedCallbackRequest {\n if (!contentType || !contentType.includes(\"application/cloudevents+json\")) {\n throw new Error(\n \"Invalid content type: expected 'application/cloudevents+json'\",\n );\n }\n\n if (\n !isRecord(body) ||\n !body.type ||\n !body.source ||\n !body.id ||\n !isRecord(body.data)\n ) {\n throw new Error(\"Invalid CloudEvent: missing required fields\");\n }\n\n if (body.type !== CLOUD_EVENT_TYPE_V1BETA) {\n throw new Error(\n `Invalid CloudEvent type: expected '${CLOUD_EVENT_TYPE_V1BETA}', got '${String(body.type)}'`,\n );\n }\n\n const { data } = body;\n const missingFields: string[] = [];\n if (!(\"queueName\" in data)) missingFields.push(\"queueName\");\n if (!(\"consumerGroup\" in data)) missingFields.push(\"consumerGroup\");\n if (!(\"messageId\" in data)) missingFields.push(\"messageId\");\n if (missingFields.length > 0) {\n throw new Error(\n `Missing required CloudEvent data fields: ${missingFields.join(\", \")}`,\n );\n }\n\n return {\n queueName: String(data.queueName),\n consumerGroup: String(data.consumerGroup),\n messageId: String(data.messageId),\n };\n}\n\ntype HeaderSource = Headers | Record<string, string | string[] | undefined>;\n\nfunction getHeader(headers: HeaderSource, name: string): string | null {\n if (headers instanceof Headers) {\n return headers.get(name);\n }\n const value = headers[name];\n if (Array.isArray(value)) return value[0] ?? null;\n return (value as string) ?? null;\n}\n\nfunction parseBinaryHeaders(headers: HeaderSource): ParsedCallbackRequest {\n const ceType = getHeader(headers, \"ce-type\");\n if (ceType !== CLOUD_EVENT_TYPE_V2BETA) {\n throw new Error(\n `Invalid CloudEvent type: expected '${CLOUD_EVENT_TYPE_V2BETA}', got '${ceType}'`,\n );\n }\n\n const queueName = getHeader(headers, \"ce-vqsqueuename\");\n const consumerGroup = getHeader(headers, \"ce-vqsconsumergroup\");\n const messageId = getHeader(headers, \"ce-vqsmessageid\");\n\n const missingFields: string[] = [];\n if (!queueName) missingFields.push(\"ce-vqsqueuename\");\n if (!consumerGroup) missingFields.push(\"ce-vqsconsumergroup\");\n if (!messageId) missingFields.push(\"ce-vqsmessageid\");\n if (missingFields.length > 0) {\n throw new Error(\n `Missing required CloudEvent headers: ${missingFields.join(\", \")}`,\n );\n }\n\n const base = {\n queueName: queueName!,\n consumerGroup: consumerGroup!,\n messageId: messageId!,\n };\n\n const receiptHandle = getHeader(headers, \"ce-vqsreceipthandle\");\n if (!receiptHandle) {\n return base;\n }\n\n const result: ParsedCallbackV2 = { ...base, receiptHandle };\n\n const deliveryCount = getHeader(headers, \"ce-vqsdeliverycount\");\n if (deliveryCount) {\n result.deliveryCount = parseInt(deliveryCount, 10);\n }\n\n const createdAt = getHeader(headers, \"ce-vqscreatedat\");\n if (createdAt) {\n result.createdAt = createdAt;\n }\n\n const contentType = getHeader(headers, \"content-type\");\n if (contentType) {\n result.contentType = contentType;\n }\n\n const visibilityDeadline = getHeader(headers, \"ce-vqsvisibilitydeadline\");\n if (visibilityDeadline) {\n result.visibilityDeadline = visibilityDeadline;\n }\n\n return result;\n}\n\n/**\n * Parse a callback from a pre-parsed body and headers.\n *\n * For frameworks like Next.js Pages Router where the body has already been\n * parsed, use this instead of {@link parseCallback}.\n *\n * Detects the CloudEvent version from the `ce-type` header:\n * - `com.vercel.queue.v2beta`: binary content mode (metadata in headers,\n * payload in body). For small messages, the body is attached as `parsedPayload`.\n * - Otherwise: structured content mode (v1beta, entire CloudEvent in JSON body)\n *\n * @param body - The framework-parsed request body. Type depends on Content-Type\n * and framework configuration:\n * - v1beta: parsed CloudEvent JSON object\n * - v2beta: the message payload as parsed by the framework (object, Buffer, or string)\n * @param headers - HTTP headers\n * @returns Parsed callback request with routing metadata and optional payload\n */\nexport function parseRawCallback(\n body: unknown,\n headers: Record<string, string | string[] | undefined>,\n): ParsedCallbackRequest {\n const ceType = getHeader(headers, \"ce-type\");\n\n if (ceType === CLOUD_EVENT_TYPE_V2BETA) {\n const result = parseBinaryHeaders(headers);\n if (\"receiptHandle\" in result) {\n result.parsedPayload = body;\n }\n return result;\n }\n\n return parseV1StructuredBody(body, getHeader(headers, \"content-type\"));\n}\n\n/**\n * Parse and validate a CloudEvent callback from a Web API `Request` object.\n *\n * Detects the CloudEvent version from the `ce-type` header:\n * - `com.vercel.queue.v2beta`: binary content mode (metadata in headers,\n * payload in body). For v2beta, the body is attached as `rawBody` (a\n * ReadableStream) rather than being parsed.\n * - Otherwise: structured content mode (v1beta, entire CloudEvent in JSON body)\n *\n * For frameworks that pre-parse the body (e.g. Next.js Pages Router),\n * use {@link parseRawCallback} instead.\n */\nexport async function parseCallback(\n request: Request,\n): Promise<ParsedCallbackRequest> {\n const ceType = request.headers.get(\"ce-type\");\n\n if (ceType === CLOUD_EVENT_TYPE_V2BETA) {\n const result = parseBinaryHeaders(request.headers);\n if (\"receiptHandle\" in result && request.body) {\n result.rawBody = request.body;\n }\n return result;\n }\n\n let body: unknown;\n try {\n body = await request.json();\n } catch {\n throw new Error(\"Failed to parse CloudEvent from request body\");\n }\n\n const headers: Record<string, string> = {};\n request.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n return parseRawCallback(body, headers);\n}\n\n/**\n * Core queue callback handler. Processes the message using the provided handler.\n *\n * This is the framework-agnostic core — it takes already-parsed request data\n * and throws on errors. Framework-specific wrappers (in `@vercel/queue/web`\n * and `@vercel/queue/nextjs/pages`) compose around this function to handle\n * request parsing and response formatting.\n *\n * @param handler - Function to process the message payload and metadata\n * @param request - A {@link ParsedCallbackV1} (routing metadata only, message\n * fetched by ID) or {@link ParsedCallbackV2} (full message inlined, no fetch).\n * @param options - Optional configuration (client, visibilityTimeoutSeconds)\n * @throws {Error} If binary mode request has a receipt handle but no payload\n * @throws {Error} If message processing fails\n *\n * @example\n * ```typescript\n * import { handleCallback, parseRawCallback } from \"@vercel/queue\";\n *\n * const parsed = parseRawCallback(body, headers);\n * await handleCallback(async (message, metadata) => {\n * console.log(\"Processing:\", message);\n * }, parsed);\n * ```\n */\nexport async function handleCallback<T = unknown>(\n handler: MessageHandler<T>,\n request: ParsedCallbackRequest,\n options?: HandleCallbackOptions,\n): Promise<void> {\n const { queueName, consumerGroup, messageId } = request;\n\n const client = options?.client || new QueueClient();\n const topic = new Topic<T>(client, queueName);\n const cg = topic.consumerGroup(\n consumerGroup,\n options?.visibilityTimeoutSeconds !== undefined\n ? { visibilityTimeoutSeconds: options.visibilityTimeoutSeconds }\n : undefined,\n );\n\n if (\"receiptHandle\" in request) {\n const transport = client.getTransport() as Transport<T>;\n\n let payload: T;\n if (request.rawBody) {\n payload = await transport.deserialize(request.rawBody);\n } else if (request.parsedPayload !== undefined) {\n payload = request.parsedPayload as T;\n } else {\n throw new Error(\n \"Binary mode callback with receipt handle is missing payload\",\n );\n }\n\n const message: Message<T> = {\n messageId,\n payload,\n deliveryCount: request.deliveryCount ?? 1,\n createdAt: request.createdAt ? new Date(request.createdAt) : new Date(),\n contentType: request.contentType ?? transport.contentType,\n receiptHandle: request.receiptHandle,\n };\n\n const visibilityDeadline = request.visibilityDeadline\n ? new Date(request.visibilityDeadline)\n : undefined;\n\n await cg.consumeMessage(handler, message, { visibilityDeadline });\n } else {\n await cg.consume(handler, { messageId });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAAA;AAAA;AAAA;;;ACEA,qBAAqC;;;ACQrC,SAAoB;AACpB,WAAsB;;;AC8Sf,IAAM,uBAAN,cAAmC,MAAM;AAAA,EAC9C,YAAY,WAAmB;AAC7B,UAAM,WAAW,SAAS,YAAY;AACtC,SAAK,OAAO;AAAA,EACd;AACF;AAMO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,WAAmB,QAAiB;AAC9C;AAAA,MACE,WAAW,SAAS,gCAAgC,SAAS,KAAK,MAAM,KAAK,EAAE;AAAA,IACjF;AACA,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAC/C,YAAY,WAAmB,QAAgB;AAC7C,UAAM,WAAW,SAAS,kBAAkB,MAAM,EAAE;AACpD,SAAK,OAAO;AAAA,EACd;AACF;AAoCO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YAAY,UAAkB,2CAA2C;AACvE,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAMO,IAAM,iBAAN,cAA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