import { type ApiContract, type ClientRequestParams, type DefaultStreaming, type InferNonSseClientResponse, type InferSseClientResponse, type SuccessfulHttpStatusCode } from '@lokalise/api-contracts'; import type { WretchInstance } from '../types.ts'; import { UnexpectedResponseError } from './UnexpectedResponseError.ts'; export type ContractRequestOptions = { /** * Controls how non-2xx responses defined in the contract are surfaced. * * - `true` (default): error status codes are returned as `Either.error`, and the result type is * narrowed to success status codes only. * - `false`: all status codes defined in `responsesByStatusCode` are returned as `Either.result`. * * Status codes absent from the contract surface as `Either.error` regardless of this option. */ captureAsError?: DoCaptureAsError; /** * When `true` (default), returns an error if the response `content-type` doesn't match the contract entry. * When `false`, falls back to the entry's kind for single-entry responses. */ strictContentType?: boolean; /** * An `AbortSignal` to cancel the in-flight request. */ signal?: AbortSignal; }; type Either = { error: TError; result?: never; } | { error?: never; result: TResult; }; type AllContractResponses = TIsStreaming extends true ? InferSseClientResponse : InferNonSseClientResponse; type ContractResultType = TDoCaptureAsError extends true ? Extract, { statusCode: SuccessfulHttpStatusCode; }> : AllContractResponses; type ContractErrorType = TDoCaptureAsError extends true ? UnexpectedResponseError | Exclude, { statusCode: SuccessfulHttpStatusCode; }> : UnexpectedResponseError; type ReturnTypeForContract = Either, ContractResultType>; /** * Executes an HTTP request described by `apiContract` and returns a type-safe `Either`. * * Response bodies are parsed and validated against the schema defined in * `responsesByStatusCode`. Status codes absent from the contract are returned as * `Either.error` with an {@link UnexpectedResponseError}. * * By default (`captureAsError: true`), non-2xx responses defined in the contract are * also returned as `Either.error`; pass `captureAsError: false` to receive all * contract-defined responses as `Either.result`. * * Rethrows anything but a wretch HTTP error or a `Response`, including a catcher's own error. * * @see {@link ContractRequestOptions} for cancellation and other options. */ export declare function sendByApiContract, TCaptureAsError extends boolean = true>(wretch: WretchInstance, apiContract: TApiContract, params: ClientRequestParams & ContractRequestOptions): Promise>; export {};