@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
54 lines (51 loc) • 2.25 kB
TypeScript
import { SimulationRevert, SimulateResult } from '@lifi/compose-spec';
/**
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
* when the body does not match the `ok`/`revert`/`error` union, letting the
* caller raise a transport-level error.
*/
declare const parseSimulateResult: (body: unknown) => SimulateResult | null;
/**
* The validated members of an HTTP 206 partial compile envelope. `data` is
* verified to be an object at runtime but left `unknown` here — compose-spec
* owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so
* the caller narrows it in one step. `error` is fully validated.
*/
interface CompilePartialEnvelope {
readonly data: unknown;
readonly error: {
readonly kind: string;
readonly message: string;
};
}
/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
/**
* A single prepared-op failure inside a `preparation_error` envelope. `kind` is
* kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in
* `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.
*/
interface ServerFailedPreparedOp {
readonly callId: string;
readonly op: string;
readonly kind: string;
readonly message: string;
readonly path?: string;
}
/** Error envelope returned on non-2xx responses. */
interface ServerErrorBody {
readonly error?: {
readonly kind?: string;
readonly message?: string;
readonly path?: string;
readonly sdkVersion?: string;
readonly serverVersion?: string;
readonly minimumSdkVersion?: string;
readonly details?: SimulationRevert;
readonly failedOps?: readonly ServerFailedPreparedOp[];
readonly succeededOps?: readonly string[];
};
}
/** Validates an already-parsed error envelope; `null` when it does not match. */
declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
export { type CompilePartialEnvelope, type ServerErrorBody, type ServerFailedPreparedOp, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };