import { type CookieJar, type ExtraCookies } from "../cookies/index.js"; /** * Simple cookie-aware HTTP client. * * Wraps the global `fetch` (Bun's native one) with two extras: * - Attaches a `Cookie:` header from a CookieJar before the request. * - Persists `Set-Cookie` responses back into the same jar. * * Used by the `fetch` command and other tooling that wants to share session * state with `browse`. */ export type FetchResponseType = "text" | "bytes"; export interface FetchOptions { /** HTTP method. Default GET. */ method?: string; /** Request body. Strings/Buffers/Streams pass through to fetch directly. */ body?: BodyInit | null; /** Extra headers (merged with auto-added Cookie). */ headers?: Record; /** * Optional CookieJar. When provided: * - Matching cookies become a Cookie header. * - Set-Cookie response headers are parsed and merged into the jar. * Pass `null` (or omit) to disable. */ jar?: CookieJar | null; /** Optional override for redirect handling. Default `'follow'`. */ redirect?: RequestRedirect; /** AbortSignal for timeout/cancel control. */ signal?: AbortSignal; /** * Optional callback that returns extra headers to attach based on the * target URL. Consumers can inject extra HTTP headers per-URL via this * callback (e.g., a Cloudflare-bypass header for specific zones). * Caller-provided explicit headers always win; auto-attached values * only land when the key isn't already set. */ extraHeaders?: (url: string) => Record; /** * Optional callback that returns extra cookies to persist into `jar` * before the Cookie header is built. Ignored when no jar is passed * (`--no-cookies`). Must stay synchronous. */ extraCookies?: ExtraCookies; /** Response body representation. Default `text`; use `bytes` for lossless file output. */ responseType?: TResponseType; } type FetchBody = TResponseType extends "bytes" ? Uint8Array : string; export interface FetchResult { status: number; statusText: string; url: string; headers: Record; body: TBody; /** Number of cookies persisted back into the jar (0 if no jar passed). */ cookiesSaved: number; } /** * Fetch a URL with optional cookie-jar attach + persist. * * Returns the response body as text by default (callers handle JSON parsing). * Pass `responseType: "bytes"` when the caller must preserve the body exactly. * Streams aren't supported; this is a CLI helper, not a streaming HTTP * client. Use Bun's `fetch` directly for streaming workloads. */ export declare function fetchWithJar(url: string, opts?: FetchOptions): Promise>>; export {}; //# sourceMappingURL=client.d.ts.map