interface SearchParams extends Record { } interface OptionsPayload { json?: unknown; params?: SearchParams | URLSearchParams | string; } interface Response extends globalThis.Response { options: RequestOptions; } interface BodyMethods { json(): Promise; text(): Promise; blob(): Promise; arrayBuffer(): Promise; formData(): Promise; void(): Promise; } interface ResponsePromise extends Promise>, BodyMethods { } interface Serialize { (params: SearchParams): URLSearchParams | string; } interface RequestMethod { (resource?: string | RequestMethodOptions, options?: RequestMethodOptions): ResponsePromise; } interface RequiredOptions extends RequestInit { /** * Base of the request URL, default to `location.origin` if available. * Provide a valid url if you want to use relative `resource` path * when module loaded in `file://`, `about:blank` or Node.js environment. */ base?: URL | string; /** * Part of the request URL */ resource?: string; /** * Request headers */ headers?: HeadersInit; /** * Body for `application/json` type requests, stringified with `JSON.stringify`. */ json?: Payload['json']; /** * Search params to append to a request URL. */ params?: Payload['params']; /** * Custom search params serializer when `object` passed to `params`. * Defaults to internal implementation based on `URLSearchParams` * with better handling of array values. */ serialize?: Serialize; /** * If specified `TimeoutError` will be thrown and the request will be * cancelled after a specified duration. */ timeout?: number; /** * `node-fetch` v3 option, default is 10mb.\ * @see {@link https://github.com/exah/ya-fetch#node-js-support} */ highWaterMark?: number; /** * Use the callback to modify options before a request */ onRequest(url: URL, options: RequestOptions): Promise | void; /** * Response handler, must handle status codes or throw `ResponseError` */ onResponse(response: Response): Promise> | Response; /** * Success response handler (usually codes 200-299). */ onSuccess?(response: Response): Promise> | Response; /** * Instance error handler. Use it to throw custom errors * or to send information to error tracking service. */ onFailure?(error: unknown): Promise> | Response; /** * Transform parsed JSON from response. */ onJSON(input: Input): Promise | Data; } interface RequestMethodOptions extends Omit, 'resource' | 'method'> { } interface RequestOptions extends RequiredOptions { resource: string; headers: Headers; params: URLSearchParams; } interface Options extends Partial> { } interface Instance { get: RequestMethod; post: RequestMethod; patch: RequestMethod; put: RequestMethod; delete: RequestMethod; head: RequestMethod; extend(options?: Options): Instance; } declare function serialize(input: SearchParams): URLSearchParams; declare class ResponseError

extends Error { name: string; status: number; response: Response

; constructor(response: Response

, message?: string); } declare class TimeoutError extends Error { name: string; constructor(); } declare function request(baseOptions: Options): ResponsePromise; declare function create(baseOptions?: Options): Instance; declare const get: RequestMethod, post: RequestMethod, put: RequestMethod, patch: RequestMethod, head: RequestMethod, _delete: RequestMethod; export { type ResponsePromise, type OptionsPayload as Payload, type Options, type Instance, type Response, type Serialize, ResponseError, TimeoutError, serialize, request, create, get, post, put, patch, head, _delete as delete, };