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:
parent
cf300e9cc0
commit
2839e796db
@ -52,8 +52,9 @@ export default function Home() {
|
|||||||
const result: any = await fal.subscribe(endpointId, {
|
const result: any = await fal.subscribe(endpointId, {
|
||||||
input: JSON.parse(input),
|
input: JSON.parse(input),
|
||||||
logs: true,
|
logs: true,
|
||||||
mode: 'streaming',
|
// mode: "streaming",
|
||||||
// pollInterval: 1000,
|
mode: 'polling',
|
||||||
|
pollInterval: 1000,
|
||||||
onQueueUpdate(update) {
|
onQueueUpdate(update) {
|
||||||
console.log('queue update');
|
console.log('queue update');
|
||||||
console.log(update);
|
console.log(update);
|
||||||
|
|||||||
@ -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.13.0",
|
"version": "0.14.0-alpha.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@ -13,6 +13,7 @@ export type Config = {
|
|||||||
proxyUrl?: string;
|
proxyUrl?: string;
|
||||||
requestMiddleware?: RequestMiddleware;
|
requestMiddleware?: RequestMiddleware;
|
||||||
responseHandler?: ResponseHandler<any>;
|
responseHandler?: ResponseHandler<any>;
|
||||||
|
fetch?: typeof fetch;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RequiredConfig = Required<Config>;
|
export type RequiredConfig = Required<Config>;
|
||||||
@ -64,8 +65,8 @@ export function config(config: Config) {
|
|||||||
configuration = {
|
configuration = {
|
||||||
...configuration,
|
...configuration,
|
||||||
requestMiddleware: withMiddleware(
|
requestMiddleware: withMiddleware(
|
||||||
configuration.requestMiddleware,
|
withProxy({ targetUrl: config.proxyUrl }),
|
||||||
withProxy({ targetUrl: config.proxyUrl })
|
configuration.requestMiddleware
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@ export async function dispatchRequest<Input, Output>(
|
|||||||
credentials: credentialsValue,
|
credentials: credentialsValue,
|
||||||
requestMiddleware,
|
requestMiddleware,
|
||||||
responseHandler,
|
responseHandler,
|
||||||
|
fetch = global.fetch,
|
||||||
} = getConfig();
|
} = getConfig();
|
||||||
const userAgent = isBrowser() ? {} : { 'User-Agent': getUserAgent() };
|
const userAgent = isBrowser() ? {} : { 'User-Agent': getUserAgent() };
|
||||||
const credentials =
|
const credentials =
|
||||||
|
|||||||
@ -76,6 +76,7 @@ type KeyValuePair = [string, any];
|
|||||||
|
|
||||||
export const storageImpl: StorageSupport = {
|
export const storageImpl: StorageSupport = {
|
||||||
upload: async (file: Blob) => {
|
upload: async (file: Blob) => {
|
||||||
|
const { fetch = global.fetch } = getConfig();
|
||||||
const { upload_url: uploadUrl, file_url: url } = await initiateUpload(file);
|
const { upload_url: uploadUrl, file_url: url } = await initiateUpload(file);
|
||||||
const response = await fetch(uploadUrl, {
|
const response = await fetch(uploadUrl, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { createParser } from 'eventsource-parser';
|
import { createParser } from 'eventsource-parser';
|
||||||
import { getTemporaryAuthToken } from './auth';
|
import { getTemporaryAuthToken } from './auth';
|
||||||
|
import { getConfig } from './config';
|
||||||
import { buildUrl } from './function';
|
import { buildUrl } from './function';
|
||||||
import { ApiError, defaultResponseHandler } from './response';
|
import { ApiError, defaultResponseHandler } from './response';
|
||||||
import { storageImpl } from './storage';
|
import { storageImpl } from './storage';
|
||||||
@ -83,6 +84,7 @@ export class FalStream<Input, Output> {
|
|||||||
private start = async () => {
|
private start = async () => {
|
||||||
const { url, options } = this;
|
const { url, options } = this;
|
||||||
const { input, method = 'post' } = options;
|
const { input, method = 'post' } = options;
|
||||||
|
const { fetch = global.fetch } = getConfig();
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
method: method.toUpperCase(),
|
method: method.toUpperCase(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user