fix(client): remove trailing slash from url with params (#68)

This commit is contained in:
Daniel Rochetti 2024-06-05 09:53:58 -07:00 committed by GitHub
parent 8fc0b726c2
commit f7d9dec1aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 9 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "@fal-ai/serverless-client", "name": "@fal-ai/serverless-client",
"description": "The fal serverless JS/TS client", "description": "The fal serverless JS/TS client",
"version": "0.10.3", "version": "0.10.4",
"license": "MIT", "license": "MIT",
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -43,6 +43,11 @@ type ExtraOptions = {
* influences how the URL is built. * influences how the URL is built.
*/ */
readonly subdomain?: string; readonly subdomain?: string;
/**
* The query parameters to include in the URL.
*/
readonly query?: Record<string, string>;
}; };
/** /**
@ -61,10 +66,15 @@ export function buildUrl<Input>(
const method = (options.method ?? 'post').toLowerCase(); const method = (options.method ?? 'post').toLowerCase();
const path = (options.path ?? '').replace(/^\//, '').replace(/\/{2,}/, '/'); const path = (options.path ?? '').replace(/^\//, '').replace(/\/{2,}/, '/');
const input = options.input; const input = options.input;
const params = const params = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any ...(options.query || {}),
method === 'get' && input ? new URLSearchParams(input as any) : undefined; ...(method === 'get' ? input : {}),
const queryParams = params ? `?${params.toString()}` : ''; };
const queryParams =
Object.keys(params).length > 0
? `?${new URLSearchParams(params).toString()}`
: '';
const parts = id.split('/'); const parts = id.split('/');
// if a fal url is passed, just use it // if a fal url is passed, just use it
@ -276,14 +286,12 @@ export const queue: Queue = {
options: SubmitOptions<Input> options: SubmitOptions<Input>
): Promise<EnqueueResult> { ): Promise<EnqueueResult> {
const { webhookUrl, path = '', ...runOptions } = options; const { webhookUrl, path = '', ...runOptions } = options;
const query = webhookUrl
? '?' + new URLSearchParams({ fal_webhook: webhookUrl }).toString()
: '';
return send(id, { return send(id, {
...runOptions, ...runOptions,
subdomain: 'queue', subdomain: 'queue',
method: 'post', method: 'post',
path: path + query, path: path,
query: webhookUrl ? { fal_webhook: webhookUrl } : undefined,
}); });
}, },
async status( async status(