import type { RetryOptions } from '../promise'; type HeaderValue = string | undefined; export type HeadersInput = [string, HeaderValue][] | Record | Headers; export type QueryValue = string | number | boolean | undefined; export type QueryInput = Record; /** Merges header-shaped sources into a new `Headers`, skipping undefined values. Later sources win. */ export declare function mergeHeaders(...sources: (HeadersInput | undefined)[]): Headers; export declare class FetchError extends Error { readonly status: number; readonly statusText: string; readonly url: string; readonly body?: string | undefined; /** * The body parsed as JSON, when it is one. A caller wanting to read a refusal rather than * only report it - a 422's problems, a 409's roster - narrows this instead of reparsing * `body` or forking the fetcher to keep it. */ readonly data?: unknown; /** * The api's own word for the refusal, off the body's `error`, `message` or `detail`, and * undefined where it wrote none. What a toast shows, where `message` is the `HTTP 422 - url` * line a log wants. A body that is not JSON says nothing here rather than handing a page of * HTML to whatever renders it. */ readonly said: string | undefined; constructor(status: number, statusText: string, url: string, body?: string | undefined, /** * The body parsed as JSON, when it is one. A caller wanting to read a refusal rather than * only report it - a 422's problems, a 409's roster - narrows this instead of reparsing * `body` or forking the fetcher to keep it. */ data?: unknown); } /** Builds a `FetchError` from a non-ok response, best-effort reading its body for context. */ export declare function toFetchError(res: Response, fallbackUrl: string): Promise; /** Thrown when a 2xx response body is not valid JSON. */ export declare class FetchParseError extends Error { readonly url: string; readonly body: string; constructor(url: string, body: string, cause?: unknown); } export interface FetchJsonOptions extends Omit { /** Overrides the URL base. */ baseUrl?: string | undefined; /** Adds `Authorization: Bearer ` header. */ token?: string | undefined; /** Query params appended to the URL; undefined values are skipped, arrays repeat the key. */ query?: QueryInput | undefined; /** Plain objects/arrays are JSON-encoded (with a JSON content type); `BodyInit` values pass through. */ body?: BodyInit | Record | unknown[] | null | undefined; /** Header-shaped input merged over the defaults; undefined values are skipped. */ headers?: HeadersInput | undefined; /** Aborts the request after this many milliseconds, combined with any caller `signal`. */ timeout?: number | undefined; /** * Every response, ok or not, before it is read. Where a session that has expired under the * page is noticed once rather than at each call site - the body is still untouched here. */ onResponse?: ((res: Response) => void) | undefined; /** Gets the error `fetchJson` is about to throw, after any retries. */ onError?: ((error: unknown) => void) | undefined; /** The `fetch` to call, for tests, SSR or a runtime-specific client. Defaults to the global `fetch`. */ fetch?: typeof fetch | undefined; /** Reads a non-empty response body. Defaults to `JSON.parse`. */ parse?: ((text: string) => unknown) | undefined; /** Writes a plain object or array body. Defaults to `JSON.stringify`. */ serialize?: ((body: Record | unknown[]) => string) | undefined; /** Retries a failed request, a count or `retry`'s options; by default network errors, timeouts, 408, 429 and 5xx, whatever the method, so mind a POST that is not idempotent, and a stream body cannot be sent twice. Off by default. */ retry?: number | Omit | undefined; } /** Fetches JSON from `url`, throwing `FetchError` on non-2xx responses. An empty body resolves to `null`. */ export declare function fetchJson(url: string, options?: FetchJsonOptions): Promise; /** Returns a `fetchJson` with `defaults` applied; per-call options win, headers merge. */ export declare function createFetcher(defaults: string | FetchJsonOptions): (url: string, options?: FetchJsonOptions) => Promise; /** Yields each non-empty line of an NDJSON body parsed as JSON. Throws a `SyntaxError` naming the line on one that is not JSON, and cancels the body when the consumer stops early. */ export declare function readNdjson(body: NonNullable): AsyncGenerator; export {}; //# sourceMappingURL=fetch.d.ts.map