feat(client): allow custom fetch impl (#74)

* feat(client): allow custom fetch impl

* fix(samples): remove test call

* fix: proxy middleware order

* chore(demo): switch to queue polling by default
This commit is contained in:
Daniel Rochetti 2024-07-22 12:54:44 -07:00 committed by GitHub
parent cf300e9cc0
commit 2839e796db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 11 additions and 5 deletions

View File

@ -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);

View File

@ -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",

View File

@ -13,6 +13,7 @@ export type Config = {
proxyUrl?: string;
requestMiddleware?: RequestMiddleware;
responseHandler?: ResponseHandler<any>;
fetch?: typeof fetch;
};
export type RequiredConfig = Required<Config>;
@ -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
),
};
}

View File

@ -14,6 +14,7 @@ export async function dispatchRequest<Input, Output>(
credentials: credentialsValue,
requestMiddleware,
responseHandler,
fetch = global.fetch,
} = getConfig();
const userAgent = isBrowser() ? {} : { 'User-Agent': getUserAgent() };
const credentials =

View File

@ -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',

View File

@ -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<Input, Output> {
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(),