@fal-ai/client
Version:
The fal.ai client for JavaScript and TypeScript
78 lines (77 loc) • 2.97 kB
TypeScript
import { RequiredConfig } from "./config";
type ObjectExpiration = "never" | "immediate" | "1h" | "1d" | "7d" | "30d" | "1y" | number;
type StorageACLDecision = "hide" | "forbid" | "allow";
export interface StorageACLRule {
user: string;
decision: StorageACLDecision;
}
export interface StorageACL {
default?: StorageACLDecision;
rules?: StorageACLRule[];
}
export declare const OBJECT_LIFECYCYLE_PREFERENCE_HEADER = "x-fal-object-lifecycle-preference";
/**
* Configuration for object lifecycle and storage behavior.
*/
export interface StorageSettings {
/**
* The expiration time for the stored files (images, videos, etc.). You can specify one of the enumerated values or a number of seconds.
*/
expiresIn?: ObjectExpiration;
/**
* Optional ACL configuration applied to the uploaded object.
*/
initialAcl?: StorageACL;
}
/**
* Converts an `StorageSettings` to the expiration duration in seconds.
* @param lifecycle the lifecycle preference
* @returns the expiration duration in seconds, or undefined if not applicable
*/
export declare function getExpirationDurationSeconds(lifecycle: StorageSettings): number | undefined;
/**
* Builds the headers for the Object Lifecycle preference to be used in API requests.
* This is used by the queue and run APIs to control the lifecycle of generated objects.
*
* @param lifecycle the lifecycle preference
* @returns a record with the `X-Fal-Object-Lifecycle-Preference` header
*/
export declare function buildObjectLifecycleHeaders(lifecycle: StorageSettings | undefined): Record<string, string>;
/**
* Options for uploading a file.
*/
export type UploadOptions = {
/**
* Custom lifecycle configuration for the uploaded file.
* This object will be sent as the X-Fal-Object-Lifecycle header.
*/
lifecycle?: StorageSettings;
};
/**
* File support for the client. This interface establishes the contract for
* uploading files to the server and transforming the input to replace file
* objects with URLs.
*/
export interface StorageClient {
/**
* Upload a file to the server. Returns the URL of the uploaded file.
* @param file the file to upload
* @param options optional parameters, such as lifecycle configuration
* @returns the URL of the uploaded file
*/
upload: (file: Blob, options?: UploadOptions) => Promise<string>;
/**
* Transform the input to replace file objects with URLs. This is used
* to transform the input before sending it to the server and ensures
* that the server receives URLs instead of file objects.
*
* @param input the input to transform.
* @returns the transformed input.
*/
transformInput: (input: Record<string, any>) => Promise<Record<string, any>>;
}
type StorageClientDependencies = {
config: RequiredConfig;
};
export declare function createStorageClient({ config, }: StorageClientDependencies): StorageClient;
export {};