From f7d9dec1aae227522735d16b0dd5c4154bbc4fb5 Mon Sep 17 00:00:00 2001 From: Daniel Rochetti Date: Wed, 5 Jun 2024 09:53:58 -0700 Subject: [PATCH] fix(client): remove trailing slash from url with params (#68) --- libs/client/package.json | 2 +- libs/client/src/function.ts | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/libs/client/package.json b/libs/client/package.json index cc266f1..34cb4a0 100644 --- a/libs/client/package.json +++ b/libs/client/package.json @@ -1,7 +1,7 @@ { "name": "@fal-ai/serverless-client", "description": "The fal serverless JS/TS client", - "version": "0.10.3", + "version": "0.10.4", "license": "MIT", "repository": { "type": "git", diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts index 434ae9b..a464a4b 100644 --- a/libs/client/src/function.ts +++ b/libs/client/src/function.ts @@ -43,6 +43,11 @@ type ExtraOptions = { * influences how the URL is built. */ readonly subdomain?: string; + + /** + * The query parameters to include in the URL. + */ + readonly query?: Record; }; /** @@ -61,10 +66,15 @@ export function buildUrl( const method = (options.method ?? 'post').toLowerCase(); const path = (options.path ?? '').replace(/^\//, '').replace(/\/{2,}/, '/'); const input = options.input; - const params = - // eslint-disable-next-line @typescript-eslint/no-explicit-any - method === 'get' && input ? new URLSearchParams(input as any) : undefined; - const queryParams = params ? `?${params.toString()}` : ''; + const params = { + ...(options.query || {}), + ...(method === 'get' ? input : {}), + }; + + const queryParams = + Object.keys(params).length > 0 + ? `?${new URLSearchParams(params).toString()}` + : ''; const parts = id.split('/'); // if a fal url is passed, just use it @@ -276,14 +286,12 @@ export const queue: Queue = { options: SubmitOptions ): Promise { const { webhookUrl, path = '', ...runOptions } = options; - const query = webhookUrl - ? '?' + new URLSearchParams({ fal_webhook: webhookUrl }).toString() - : ''; return send(id, { ...runOptions, subdomain: 'queue', method: 'post', - path: path + query, + path: path, + query: webhookUrl ? { fal_webhook: webhookUrl } : undefined, }); }, async status(