@fal-ai/client
Version:
The fal.ai client for JavaScript and TypeScript
43 lines (42 loc) • 1.68 kB
TypeScript
/**
* A request configuration object.
*
* **Note:** This is a simplified version of the `RequestConfig` type from the
* `fetch` API. It contains only the properties that are relevant for the
* fal client. It also works around the fact that the `fetch` API `Request`
* does not support mutability, its clone method has critical limitations
* to our use case.
*/
export type RequestConfig = {
url: string;
method: string;
headers?: Record<string, string | string[]>;
};
export type RequestMiddleware = (request: RequestConfig) => Promise<RequestConfig>;
/**
* Setup a execution chain of middleware functions.
*
* @param middlewares one or more middleware functions.
* @returns a middleware function that executes the given middlewares in order.
*/
export declare function withMiddleware(...middlewares: RequestMiddleware[]): RequestMiddleware;
/**
* Runtime information passed to a user-provided {@link ProxyRuntimeGate}
* predicate so it can decide whether the proxy middleware should apply.
*/
export type ProxyRuntimeEnv = {
isBrowser: boolean;
};
/**
* Controls when the proxy middleware applies:
* - `"browser"` — only when a DOM `window` is available (default).
* - `"always"` — in every runtime (Node, Electron, Bun, workers, etc.).
* - A predicate receiving {@link ProxyRuntimeEnv} — full control per call.
*/
export type ProxyRuntimeGate = "browser" | "always" | ((env: ProxyRuntimeEnv) => boolean);
export type RequestProxyConfig = {
targetUrl: string;
when?: ProxyRuntimeGate;
};
export declare const TARGET_URL_HEADER = "x-fal-target-url";
export declare function withProxy(config: RequestProxyConfig): RequestMiddleware;