1- import { handleCallback , send } from '@vercel/queue' ;
1+ import { Client } from '@vercel/queue' ;
22import {
33 MessageId ,
44 type Queue ,
@@ -18,21 +18,12 @@ const VERCEL_QUEUE_MAX_VISIBILITY = 82800; // 23 hours in seconds
1818export function createQueue ( config ?: APIConfig ) : Queue {
1919 const { baseUrl, usingProxy } = getHttpUrl ( config ) ;
2020 const headers = getHeaders ( config ) ;
21- if ( usingProxy ) {
22- // If we're using a proxy for the Workflow API, we should also go
23- // through the proxy for the queues API.
24- process . env . VERCEL_QUEUE_BASE_URL = `${ baseUrl } ` ;
25- process . env . VERCEL_QUEUE_BASE_PATH = '/queues/v2/messages' ;
26- if ( config ?. token ) {
27- process . env . VERCEL_QUEUE_TOKEN = config . token ;
28- }
29- if ( headers ) {
30- headers . forEach ( ( value , key ) => {
31- const sanitizedKey = key . replaceAll ( '-' , '__' ) ;
32- process . env [ `VERCEL_QUEUE_HEADER_${ sanitizedKey } ` ] = value ;
33- } ) ;
34- }
35- }
21+ const queueClient = new Client ( {
22+ baseUrl : usingProxy ? baseUrl : undefined ,
23+ basePath : usingProxy ? '/queues/v2/messages' : undefined ,
24+ token : usingProxy ? config ?. token : undefined ,
25+ headers : Object . fromEntries ( headers . entries ( ) ) ,
26+ } ) ;
3627
3728 const queue : Queue [ 'queue' ] = async ( queueName , x , opts ) => {
3829 // zod v3 doesn't have the `encode` method. We only support zod v4 officially,
@@ -51,12 +42,16 @@ export function createQueue(config?: APIConfig): Queue {
5142 queueName,
5243 } ) ;
5344 const sanitizedQueueName = queueName . replace ( / [ ^ A - Z a - z 0 - 9 - _ ] / g, '-' ) ;
54- const { messageId } = await send ( sanitizedQueueName , encoded , opts ) ;
45+ const { messageId } = await queueClient . send (
46+ sanitizedQueueName ,
47+ encoded ,
48+ opts
49+ ) ;
5550 return { messageId : MessageId . parse ( messageId ) } ;
5651 } ;
5752
5853 const createQueueHandler : Queue [ 'createQueueHandler' ] = ( prefix , handler ) => {
59- return handleCallback ( {
54+ return queueClient . handleCallback ( {
6055 [ `${ prefix } *` ] : {
6156 default : async ( body , meta ) => {
6257 const { payload, queueName } = MessageWrapper . parse ( body ) ;
0 commit comments