@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
68 lines (65 loc) • 3.15 kB
text/typescript
import { ComposeManifest, ComposeCompileRequest, ComposeCompileResult } from '@lifi/compose-spec';
import { GetZapPacksOptions, ZapPackOverview } from './discovery.cjs';
/**
* Configuration for creating a low-level Compose API client.
*/
interface ComposeClientOptions {
/** Base URL of the Compose API. */
readonly baseUrl: string;
/** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
readonly fetch?: typeof globalThis.fetch;
/** Optional LI.FI API key. When set, sent as the `x-lifi-api-key` header on every request. */
readonly apiKey?: string;
}
/**
* Low-level HTTP client for the Compose API.
*
* Handles request serialization, SDK version headers, and error mapping.
* Prefer using {@link ComposeSdk} for the full builder experience. Use this
* directly when you need to decouple request building from submission — e.g.
* build via `sdk.request()` then submit via `client.compile()` with custom
* retry logic or request inspection.
*/
interface ComposeClient {
/**
* Fetches the server's operation manifest describing all supported operations,
* guards, materialisers, and preconditions.
* @returns The manifest document.
* @throws {@link ComposeError} on network, validation, or server errors.
*/
readonly getManifest: () => Promise<ComposeManifest>;
/**
* Submits a compile request and returns the result.
*
* When the caller passes `simulationPolicy: 'allow-revert'` and the transaction
* reverts in simulation, the server responds with HTTP 206 and the SDK returns a
* partial result (`status: 'partial'`) instead of throwing. The partial result
* includes the transaction (without `gasLimit`) and revert diagnostics.
*
* @param request - The full compile request including flow and run inputs.
* @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
* @throws {@link ComposeError} on network, validation, or server errors.
*/
readonly compile: (request: ComposeCompileRequest) => Promise<ComposeCompileResult>;
/**
* Fetches the available routing edges grouped by protocol.
*
* The edge catalog is dynamic — it reflects the current state of the
* backend's routing snapshot (protocols, chains, token blacklists).
* Results are not cached by the SDK; callers should cache as appropriate.
*
* @param options - Optional filter to restrict results to specific protocols.
* @returns An array of {@link ZapPackOverview} objects, one per protocol.
* @throws {@link ComposeError} on network or server errors (503 when the
* routing catalog is not yet initialized).
*/
readonly getZapPacks: (options?: GetZapPacksOptions) => Promise<readonly ZapPackOverview[]>;
}
/**
* Creates a low-level Compose API client.
*
* @param options - Client configuration including the API base URL.
* @returns A {@link ComposeClient} instance.
*/
declare const createComposeClient: (options: ComposeClientOptions) => ComposeClient;
export { type ComposeClient, type ComposeClientOptions, createComposeClient };