/** * Hook function executed after a response is received, but before its body is parsed. * It can modify the `Response` object (e.g., to transform headers or status). * @param response - The raw `Response` object received from the fetch call. * @param options - The `RequestInit` object used for the fetch call. * @returns The (potentially modified) `Response` object, or a Promise resolving to it. */ declare type AfterHook = (response: Response, options: RequestInit) => Response | Promise; /** * Hook function executed before a request is made. * It can modify `RequestInit` options or the URL. * @param url - The URL to `fetch`. * @param query - SearchParam in the URL to `fetch`. * @param options - The `RequestInit` object that will be passed to `fetch`. * @returns The (potentially modified) `RequestInit` object, or a Promise resolving to it. */ declare type BeforeHook = (params: BeforeHookParams) => void | Promise; /** * Interface for the parameters passed to the beforeHook. * This encapsulates all the mutable parts of the request to allow * the hook to modify them. */ declare interface BeforeHookParams { query?: QueryParams; headers?: HeadersInit; } /** * Represents the progress of a download. */ declare interface DownloadProgress { /** Bytes loaded so far. */ loaded: number; /** Total bytes to load, if available (e.g., from Content-Length header). */ total: number | undefined; /** Progress percentage (0-1), calculated as loaded / total. Undefined if total is unknown. */ progress: number | undefined; } /** * Options specific to a single fetch request. * These extend the standard `RequestInit` interface and add custom functionalities. */ declare interface FetchOptions extends Omit { /** The request payload (body). Can be an object (for JSON), FormData, etc. */ body?: RequestBody; /** * An external `AbortSignal` to control the request lifecycle. * If provided, your internal timeout will not use this signal; it will create its own * `AbortController` if `timeout` is also set. */ signal?: AbortSignal; /** * You explicitly destructure headers and use `new Headers(headers)`. * `HeadersInit` allows string[][], Record, or Headers. */ headers?: HeadersInit; /** Query parameters to append to the URL. */ query?: QueryParams; /** * The desired format for the response body. If provided, the function returns the parsed data. * If not provided, the function returns the raw Response object. */ responseType?: ResponseType_2; /** * Request timeout in milliseconds. If the request takes longer than this, it will be aborted * and an `AbortError` will be thrown. A value of `0` or `undefined` means no timeout. */ timeout?: number; /** * A hook function executed before this specific request is made. * Can modify request options. */ beforeHook?: BeforeHook; /** * A hook function executed after the response for this specific request is received, * but before its body is parsed. Can modify the response. */ afterHook?: AfterHook; /** * Callback function for download progress updates. * This is active only if the response has a `Content-Length` header. */ onProgress?: OnProgressCallback; } /** * Callback function for download progress updates. * @param progress - An object containing loaded, total, and progress percentage. */ declare type OnProgressCallback = (progress: DownloadProgress) => void; /** * Type for query parameters. Supports a plain object where keys are strings * and values can be strings, numbers, booleans, or arrays of strings. */ declare type QueryParams = Record; /** * A highly configurable fetch wrapper that simplifies making HTTP requests. * It supports query parameters, a request timeout, and a flexible hook system. * The function can either return the parsed response data directly or the raw Response object, * depending on the 'responseType' option. * * @param {string} url The URL of the resource to fetch. * @param {FetchOptions} [options={}] An object containing custom and standard fetch options. * @param {object} [options.headers={}] Headers to be included in the request. * @param {AbortSignal} [options.signal] An AbortSignal instance for canceling the request. * @param {ResponseType} [options.responseType] The desired format for the response body. If omitted, returns the raw Response object. * @param {object} [options.query={}] Query parameters to be appended to the URL. * @param {number} [options.timeout] The request timeout in milliseconds. * @param {BeforeHook} [options.beforeHook] A hook executed before the request is made. * @param {OnProgressCallback} [options.onProgress] A callback for monitoring download progress. * @param {object} options.body The request body. * @param {string} options.method The request method. * @returns {Promise} A Promise that resolves to the parsed response data if `responseType` is provided, * otherwise, it resolves to the raw `Response` object. * @throws {FetchError} Throws a `FetchError` for HTTP status codes outside of the 200-299 range, * or for network failures. The error object includes status and parsed error data. */ export declare const request: (url: string, { signal: externalSignal, headers, query, responseType, timeout, beforeHook, afterHook, onProgress, ...options }?: FetchOptions) => Promise; /** * Type for request payload (body). * It can be an object (for JSON), FormData, URLSearchParams, binary data (Blob, ArrayBuffer), * or a plain string. */ declare type RequestBody = object | FormData | URLSearchParams | Blob | ArrayBuffer | string | null | undefined; /** * Represents the different types of response parsing methods. * This is used to automatically parse the response body. */ declare type ResponseType_2 = 'json' | 'text' | 'blob' | 'formData' | 'arrayBuffer'; export { }