diff --git a/apps/demo-nextjs-app-router/app/queue/page.tsx b/apps/demo-nextjs-app-router/app/queue/page.tsx index e663a3b..e979728 100644 --- a/apps/demo-nextjs-app-router/app/queue/page.tsx +++ b/apps/demo-nextjs-app-router/app/queue/page.tsx @@ -52,8 +52,9 @@ export default function Home() { const result: any = await fal.subscribe(endpointId, { input: JSON.parse(input), logs: true, - mode: 'streaming', - // pollInterval: 1000, + // mode: "streaming", + mode: 'polling', + pollInterval: 1000, onQueueUpdate(update) { console.log('queue update'); console.log(update); diff --git a/libs/client/package.json b/libs/client/package.json index 608083e..e7a4831 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.13.0", + "version": "0.14.0-alpha.1", "license": "MIT", "repository": { "type": "git", diff --git a/libs/client/src/config.ts b/libs/client/src/config.ts index 5395082..00315bf 100644 --- a/libs/client/src/config.ts +++ b/libs/client/src/config.ts @@ -13,6 +13,7 @@ export type Config = { proxyUrl?: string; requestMiddleware?: RequestMiddleware; responseHandler?: ResponseHandler; + fetch?: typeof fetch; }; export type RequiredConfig = Required; @@ -64,8 +65,8 @@ export function config(config: Config) { configuration = { ...configuration, requestMiddleware: withMiddleware( - configuration.requestMiddleware, - withProxy({ targetUrl: config.proxyUrl }) + withProxy({ targetUrl: config.proxyUrl }), + configuration.requestMiddleware ), }; } diff --git a/libs/client/src/request.ts b/libs/client/src/request.ts index 19af2a2..618eb7f 100644 --- a/libs/client/src/request.ts +++ b/libs/client/src/request.ts @@ -14,6 +14,7 @@ export async function dispatchRequest( credentials: credentialsValue, requestMiddleware, responseHandler, + fetch = global.fetch, } = getConfig(); const userAgent = isBrowser() ? {} : { 'User-Agent': getUserAgent() }; const credentials = diff --git a/libs/client/src/storage.ts b/libs/client/src/storage.ts index 1388823..3544815 100644 --- a/libs/client/src/storage.ts +++ b/libs/client/src/storage.ts @@ -76,6 +76,7 @@ type KeyValuePair = [string, any]; export const storageImpl: StorageSupport = { upload: async (file: Blob) => { + const { fetch = global.fetch } = getConfig(); const { upload_url: uploadUrl, file_url: url } = await initiateUpload(file); const response = await fetch(uploadUrl, { method: 'PUT', diff --git a/libs/client/src/streaming.ts b/libs/client/src/streaming.ts index 6dd7aa9..1ee1df4 100644 --- a/libs/client/src/streaming.ts +++ b/libs/client/src/streaming.ts @@ -1,5 +1,6 @@ import { createParser } from 'eventsource-parser'; import { getTemporaryAuthToken } from './auth'; +import { getConfig } from './config'; import { buildUrl } from './function'; import { ApiError, defaultResponseHandler } from './response'; import { storageImpl } from './storage'; @@ -83,6 +84,7 @@ export class FalStream { private start = async () => { const { url, options } = this; const { input, method = 'post' } = options; + const { fetch = global.fetch } = getConfig(); try { const response = await fetch(url, { method: method.toUpperCase(),