Skip to content

Commit

Permalink
fix(client): remove trailing slash from url with params (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
drochetti authored Jun 5, 2024
1 parent 8fc0b72 commit f7d9dec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libs/client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 16 additions & 8 deletions libs/client/src/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
};

/**
Expand All @@ -61,10 +66,15 @@ export function buildUrl<Input>(
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
Expand Down Expand Up @@ -276,14 +286,12 @@ export const queue: Queue = {
options: SubmitOptions<Input>
): Promise<EnqueueResult> {
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(
Expand Down

0 comments on commit f7d9dec

Please sign in to comment.