dexix-request 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors/DexiXError.ts","../src/errors/HTTPError.ts","../src/errors/NetworkError.ts","../src/errors/TimeoutError.ts","../src/utils/buildURL.ts","../src/utils/mergeHeaders.ts","../src/utils/mergeConfig.ts","../src/utils/isPlainObject.ts","../src/utils/serializeBody.ts","../src/errors/ParseError.ts","../src/utils/parseResponse.ts","../src/utils/combineSignals.ts","../src/core/dispatch.ts","../src/core/instance.ts","../src/index.ts"],"names":["DexiXError","message","request","response","HTTPError","NetworkError","cause","TimeoutError","timeout","isAbsoluteURL","url","joinURL","baseURL","trimmedBase","trimmedPath","appendQuery","query","path","existingSearch","params","key","value","item","search","buildURL","joined","mergeHeaders","sources","result","source","mergeConfig","parent","child","isPlainObject","prototype","isNativeBodyType","serializeBody","body","ParseError","EMPTY_STATUS_CODES","inferResponseType","contentType","parseResponse","responseType","type","text","failedResponse","combineSignals","userSignal","controller","timedOut","timer","onUserAbort","cancel","dispatch","config","headers","requestInfo","signal","didTimeout","init","errorResponse","defaults","method","resolved","requestWithBody","createInstance","instance","dx","index_default"],"mappings":"sEAOO,IAAMA,CAAAA,CAAN,cAAyB,KAAM,CAEpB,OAAA,CAEA,QAAA,CAEA,MAAA,CAEA,OAAA,CAEA,GAAA,CAET,WAAA,CACLC,CAAAA,CACAC,CAAAA,CACAC,EACA,CACA,KAAA,CAAMF,CAAO,CAAA,CACb,IAAA,CAAK,IAAA,CAAO,YAAA,CACZ,IAAA,CAAK,QAAUC,CAAAA,CACf,IAAA,CAAK,QAAA,CAAWC,CAAAA,CAChB,IAAA,CAAK,MAAA,CAASA,CAAAA,EAAU,MAAA,CACxB,KAAK,OAAA,CAAUA,CAAAA,EAAU,OAAA,CACzB,IAAA,CAAK,GAAA,CAAMD,CAAAA,CAAQ,GAAA,CAInB,MAAA,CA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C,CAAM,CAAA,CACtEY,CAAAA,CAAS,OAAA,CAAU,CAACzD,CAAAA,CAAK6C,CAAAA,GAAWrD,EAAQ4D,CAAAA,CAAU,SAAA,CAAWpD,CAAAA,CAAK6C,CAAM,CAAA,CAE5E,MAAA,CAAO,cAAA,CAAeY,CAAAA,CAAU,WAAY,CAC1C,KAAA,CAAOL,CAAAA,CACP,QAAA,CAAU,KAAA,CACV,UAAA,CAAY,IACd,CAAC,EAEDK,CAAAA,CAAS,MAAA,CAAUZ,CAAAA,EAA2BW,CAAAA,CAAepC,CAAAA,CAAYgC,CAAAA,CAAUP,CAAAA,EAAU,EAAE,CAAC,CAAA,CAEzFY,CACT,CChCA,IAAMC,CAAAA,CAAoBF,CAAAA,EAAe,KAGlCG,EAAAA,CAAQD","file":"index.cjs","sourcesContent":["import type { DexiXRequestInfo, DexiXResponse } from \"../types/index.js\";\n\n/**\n * Base class for every error thrown by DexiX Request.\n * All DexiX errors carry the originating request and, when available,\n * the response that was received.\n */\nexport class DexiXError extends Error {\n /** The request that caused this error. */\n public readonly request: DexiXRequestInfo;\n /** The response received, if any (absent for network/timeout errors). */\n public readonly response?: DexiXResponse;\n /** HTTP status code, if a response was received. */\n public readonly status?: number;\n /** Response headers, if a response was received. */\n public readonly headers?: Headers;\n /** The request URL. */\n public readonly url: string;\n\n public constructor(\n message: string,\n request: DexiXRequestInfo,\n response?: DexiXResponse,\n ) {\n super(message);\n this.name = \"DexiXError\";\n this.request = request;\n this.response = response;\n this.status = response?.status;\n this.headers = response?.headers;\n this.url = request.url;\n\n // Restore the correct prototype chain when compiled down to ES5-style\n // targets (not an issue at ES2022, but harmless and defensive).\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo, DexiXResponse } from \"../types/index.js\";\n\n/**\n * Thrown when the server responds with a non-2xx status code.\n * Always carries the full `response`, including any parsed body DexiX\n * Request was able to extract before raising the error.\n */\nexport class HTTPError extends DexiXError {\n public constructor(request: DexiXRequestInfo, response: DexiXResponse) {\n super(\n `Request failed with status ${response.status} (${response.statusText}) for ${request.url}`,\n request,\n response,\n );\n this.name = \"HTTPError\";\n }\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo } from \"../types/index.js\";\n\n/**\n * Thrown when the request could not be completed because of a network\n * failure (DNS resolution failure, connection refused, offline, CORS\n * rejection, etc). No response was ever received.\n */\nexport class NetworkError extends DexiXError {\n public constructor(message: string, request: DexiXRequestInfo, cause?: unknown) {\n super(message || \"Network request failed\", request);\n this.name = \"NetworkError\";\n if (cause !== undefined) {\n this.cause = cause;\n }\n }\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo } from \"../types/index.js\";\n\n/**\n * Thrown when a request exceeds its configured `timeout` before a\n * response is received.\n */\nexport class TimeoutError extends DexiXError {\n /** The timeout duration, in milliseconds, that was exceeded. */\n public readonly timeout: number;\n\n public constructor(request: DexiXRequestInfo, timeout: number) {\n super(`Request to ${request.url} timed out after ${timeout}ms`, request);\n this.name = \"TimeoutError\";\n this.timeout = timeout;\n }\n}\n","import type { QueryParams } from \"../types/index.js\";\n\n/**\n * Detects absolute URLs (has a scheme like `https://`, `http://`, or is\n * protocol-relative `//host`).\n */\nfunction isAbsoluteURL(url: string): boolean {\n return /^([a-z][a-z\\d+\\-.]*:)?\\/\\//i.test(url);\n}\n\n/**\n * Joins a base URL and a relative path without producing double slashes\n * or dropping a needed one.\n */\nfunction joinURL(baseURL: string, url: string): string {\n if (!baseURL) return url;\n if (isAbsoluteURL(url)) return url;\n\n const trimmedBase = baseURL.endsWith(\"/\") ? baseURL.slice(0, -1) : baseURL;\n const trimmedPath = url.startsWith(\"/\") ? url : `/${url}`;\n return `${trimmedBase}${trimmedPath}`;\n}\n\n/**\n * Appends query parameters to a URL, preserving any existing search\n * string already present on the URL. Array values become repeated keys.\n * `null`/`undefined` values are omitted entirely.\n */\nfunction appendQuery(url: string, query?: QueryParams): string {\n if (!query || Object.keys(query).length === 0) {\n return url;\n }\n\n const [path, existingSearch = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(existingSearch);\n\n for (const [key, value] of Object.entries(query)) {\n if (value === null || value === undefined) continue;\n\n if (Array.isArray(value)) {\n for (const item of value) {\n params.append(key, String(item));\n }\n } else {\n params.append(key, String(value));\n }\n }\n\n const search = params.toString();\n return search ? `${path}?${search}` : (path as string);\n}\n\n/**\n * Builds the final request URL from a base URL, a relative or absolute\n * URL, and an optional set of query parameters.\n */\nexport function buildURL(baseURL: string | undefined, url: string, query?: QueryParams): string {\n const joined = joinURL(baseURL ?? \"\", url);\n return appendQuery(joined, query);\n}\n","import type { HeadersInput } from \"../types/index.js\";\n\n/**\n * Merges any number of header sources into a single `Headers` instance.\n * Later sources override earlier ones for the same (case-insensitive) key.\n * A value of `undefined` in a plain-object source removes that header.\n */\nexport function mergeHeaders(...sources: Array<HeadersInput | undefined>): Headers {\n const result = new Headers();\n\n for (const source of sources) {\n if (!source) continue;\n\n if (source instanceof Headers) {\n source.forEach((value, key) => {\n result.set(key, value);\n });\n continue;\n }\n\n if (Array.isArray(source)) {\n for (const [key, value] of source) {\n result.set(key, value);\n }\n continue;\n }\n\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined) {\n result.delete(key);\n } else {\n result.set(key, value);\n }\n }\n }\n\n return result;\n}\n","import { mergeHeaders } from \"./mergeHeaders.js\";\nimport type { RequestConfig } from \"../types/index.js\";\n\n/**\n * Merges a child `RequestConfig` on top of a parent one. Headers and\n * query params are merged (child wins per-key); every other field is\n * simply overridden by the child when present.\n */\nexport function mergeConfig(parent: RequestConfig, child: RequestConfig): RequestConfig {\n return {\n ...parent,\n ...child,\n headers: mergeHeaders(parent.headers, child.headers),\n query: { ...parent.query, ...child.query },\n };\n}\n","/**\n * Returns `true` for plain JavaScript objects (object literals, or objects\n * with `Object.prototype` / `null` as their prototype). Returns `false`\n * for arrays, class instances, `FormData`, `Blob`, `File`, `URLSearchParams`,\n * `ReadableStream`, `Date`, `Map`, `Set`, and primitives.\n */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value) as unknown;\n return prototype === Object.prototype || prototype === null;\n}\n","import { isPlainObject } from \"./isPlainObject.js\";\nimport type { RequestBody } from \"../types/index.js\";\n\n/**\n * Result of serializing a request body: the value ready to hand to\n * `fetch`, and an optional `Content-Type` to apply when one wasn't\n * already set by the caller.\n */\nexport interface SerializedBody {\n body: BodyInit | null | undefined;\n contentType?: string;\n}\n\n/**\n * Determines whether a value is already a \"native\" body type that\n * `fetch` understands natively and should be passed through untouched.\n */\nfunction isNativeBodyType(value: unknown): value is BodyInit {\n return (\n typeof value === \"string\" ||\n value instanceof FormData ||\n value instanceof Blob ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value) ||\n value instanceof ReadableStream\n );\n}\n\n/**\n * Serializes a DexiX request body. Plain objects and arrays are\n * JSON-serialized automatically; every other supported `BodyInit` type is\n * passed through untouched so the caller retains full control when\n * needed (e.g. uploading a `FormData` or streaming a `ReadableStream`).\n */\nexport function serializeBody(body: RequestBody): SerializedBody {\n if (body === null || body === undefined) {\n return { body: undefined };\n }\n\n if (isNativeBodyType(body)) {\n // FormData sets its own multipart boundary; let the platform handle it.\n if (body instanceof FormData) {\n return { body };\n }\n if (body instanceof URLSearchParams) {\n return { body, contentType: \"application/x-www-form-urlencoded;charset=UTF-8\" };\n }\n if (typeof body === \"string\") {\n return { body, contentType: \"text/plain;charset=UTF-8\" };\n }\n return { body };\n }\n\n if (isPlainObject(body) || Array.isArray(body)) {\n return {\n body: JSON.stringify(body),\n contentType: \"application/json;charset=UTF-8\",\n };\n }\n\n // Fallback: best-effort JSON serialization for other serializable values.\n return {\n body: JSON.stringify(body),\n contentType: \"application/json;charset=UTF-8\",\n };\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo, DexiXResponse } from \"../types/index.js\";\n\n/**\n * Thrown when a response body could not be parsed according to the\n * requested (or inferred) `responseType`, e.g. invalid JSON.\n */\nexport class ParseError extends DexiXError {\n public constructor(request: DexiXRequestInfo, response: DexiXResponse, cause?: unknown) {\n super(`Failed to parse response body from ${request.url}`, request, response);\n this.name = \"ParseError\";\n if (cause !== undefined) {\n this.cause = cause;\n }\n }\n}\n","import { ParseError } from \"../errors/ParseError.js\";\nimport type { DexiXRequestInfo, DexiXResponse, ResponseType } from \"../types/index.js\";\n\nconst EMPTY_STATUS_CODES = new Set([204, 205, 304]);\n\n/**\n * Infers the best response type from the `Content-Type` header when the\n * caller didn't explicitly request one.\n */\nfunction inferResponseType(response: Response): ResponseType {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n\n if (contentType.includes(\"application/json\") || contentType.includes(\"+json\")) {\n return \"json\";\n }\n if (contentType.startsWith(\"text/\")) {\n return \"text\";\n }\n return \"json\";\n}\n\n/**\n * Parses a `Response` body according to `responseType` (or an inferred\n * type based on `Content-Type`), returning the parsed value. Throws\n * `ParseError` if parsing fails.\n */\nexport async function parseResponse<T>(\n response: Response,\n request: DexiXRequestInfo,\n responseType?: ResponseType,\n): Promise<T> {\n if (request.method === \"HEAD\" || EMPTY_STATUS_CODES.has(response.status)) {\n return undefined as T;\n }\n\n const type = responseType ?? inferResponseType(response);\n\n try {\n switch (type) {\n case \"json\": {\n const text = await response.text();\n if (text.length === 0) {\n return undefined as T;\n }\n return JSON.parse(text) as T;\n }\n case \"text\":\n return (await response.text()) as unknown as T;\n case \"blob\":\n return (await response.blob()) as unknown as T;\n case \"arrayBuffer\":\n return (await response.arrayBuffer()) as unknown as T;\n case \"stream\":\n return response.body as unknown as T;\n default:\n return (await response.text()) as unknown as T;\n }\n } catch (cause) {\n const failedResponse: DexiXResponse = {\n data: undefined,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n url: response.url || request.url,\n };\n throw new ParseError(request, failedResponse, cause);\n }\n}\n","/**\n * Combines an optional user-provided `AbortSignal` with an internal\n * timeout, producing a single signal that aborts when either source\n * aborts. Returns the combined signal along with a `cancel()` function\n * that must be called once the request settles to clear the timer, and\n * a `didTimeout()` predicate to distinguish a timeout abort from a\n * user-initiated abort.\n */\nexport function combineSignals(\n userSignal: AbortSignal | undefined,\n timeout: number | undefined,\n): {\n signal: AbortSignal | undefined;\n cancel: () => void;\n didTimeout: () => boolean;\n} {\n if (!timeout || timeout <= 0) {\n return {\n signal: userSignal,\n cancel: () => {},\n didTimeout: () => false,\n };\n }\n\n const controller = new AbortController();\n let timedOut = false;\n\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, timeout);\n\n const onUserAbort = () => controller.abort();\n userSignal?.addEventListener(\"abort\", onUserAbort, { once: true });\n\n const cancel = () => {\n clearTimeout(timer);\n userSignal?.removeEventListener(\"abort\", onUserAbort);\n };\n\n return {\n signal: controller.signal,\n cancel,\n didTimeout: () => timedOut,\n };\n}\n","import { HTTPError } from \"../errors/HTTPError.js\";\nimport { NetworkError } from \"../errors/NetworkError.js\";\nimport { TimeoutError } from \"../errors/TimeoutError.js\";\nimport { buildURL, combineSignals, mergeHeaders, parseResponse, serializeBody } from \"../utils/index.js\";\nimport type { DexiXRequestInfo, DexiXResponse, ResolvedRequestConfig } from \"../types/index.js\";\n\n/**\n * Executes a single HTTP request described by a fully-resolved config.\n * This is the single point in the library that calls `fetch`.\n *\n * @internal\n */\nexport async function dispatch<T>(config: ResolvedRequestConfig): Promise<T> {\n const { body, contentType } = serializeBody(config.body);\n\n const headers = mergeHeaders(\n contentType ? { \"content-type\": contentType } : undefined,\n config.headers,\n );\n\n const url = buildURL(config.baseURL, config.url, config.query);\n\n const requestInfo: DexiXRequestInfo = {\n url,\n method: config.method,\n headers,\n body: config.body,\n };\n\n const { signal, cancel, didTimeout } = combineSignals(config.signal, config.timeout);\n\n const init: RequestInit = {\n method: config.method,\n headers,\n body: config.method === \"GET\" || config.method === \"HEAD\" ? undefined : body,\n signal,\n credentials: config.credentials,\n cache: config.cache,\n redirect: config.redirect,\n referrerPolicy: config.referrerPolicy,\n mode: config.mode,\n };\n\n const request = new Request(url, init);\n\n if (config.onRequest) {\n await config.onRequest(request);\n }\n\n let response: Response;\n\n try {\n response = await fetch(request);\n } catch (cause) {\n cancel();\n\n if (cause instanceof DOMException && cause.name === \"AbortError\") {\n if (didTimeout()) {\n throw new TimeoutError(requestInfo, config.timeout ?? 0);\n }\n throw cause;\n }\n\n throw new NetworkError(\n cause instanceof Error ? cause.message : \"Network request failed\",\n requestInfo,\n cause,\n );\n }\n\n cancel();\n\n if (config.onResponse) {\n await config.onResponse(response);\n }\n\n if (!response.ok) {\n const data = await parseResponse<unknown>(response, requestInfo, config.responseType).catch(\n () => undefined,\n );\n\n const errorResponse: DexiXResponse = {\n data,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n url: response.url || url,\n };\n\n throw new HTTPError(requestInfo, errorResponse);\n }\n\n return parseResponse<T>(response, requestInfo, config.responseType);\n}\n","import { dispatch } from \"./dispatch.js\";\nimport { mergeConfig } from \"../utils/index.js\";\nimport type {\n DexiXInstance,\n HttpMethod,\n RequestBody,\n RequestConfig,\n ResolvedRequestConfig,\n} from \"../types/index.js\";\n\nfunction request<T>(\n defaults: RequestConfig,\n method: HttpMethod,\n url: string,\n config?: RequestConfig,\n): Promise<T> {\n const resolved: ResolvedRequestConfig = {\n ...mergeConfig(defaults, config ?? {}),\n method,\n url,\n };\n\n return dispatch<T>(resolved);\n}\n\nfunction requestWithBody<T>(\n defaults: RequestConfig,\n method: HttpMethod,\n url: string,\n body?: RequestBody,\n config?: RequestConfig,\n): Promise<T> {\n return request<T>(defaults, method, url, { ...config, body: body ?? config?.body });\n}\n\n/**\n * Creates a new DexiX Request instance. Calling the instance directly\n * performs a GET request; method-specific helpers (`get`, `post`, `put`,\n * `patch`, `delete`, `head`, `options`) are attached for convenience.\n */\nexport function createInstance(defaults: RequestConfig = {}): DexiXInstance {\n const instance = (<T>(url: string, config?: RequestConfig): Promise<T> =>\n request<T>(defaults, \"GET\", url, config)) as DexiXInstance;\n\n instance.get = (url, config) => request(defaults, \"GET\", url, config);\n instance.post = (url, body, config) => requestWithBody(defaults, \"POST\", url, body, config);\n instance.put = (url, body, config) => requestWithBody(defaults, \"PUT\", url, body, config);\n instance.patch = (url, body, config) => requestWithBody(defaults, \"PATCH\", url, body, config);\n instance.delete = (url, config) => request(defaults, \"DELETE\", url, config);\n instance.head = (url, config) => request(defaults, \"HEAD\", url, config);\n instance.options = (url, config) => request(defaults, \"OPTIONS\", url, config);\n\n Object.defineProperty(instance, \"defaults\", {\n value: defaults,\n writable: false,\n enumerable: true,\n });\n\n instance.create = (config?: RequestConfig) => createInstance(mergeConfig(defaults, config ?? {}));\n\n return instance;\n}\n","import { createInstance } from \"./core/index.js\";\nimport type { DexiXInstance } from \"./types/index.js\";\n\nexport type {\n DexiXInstance,\n RequestConfig,\n HttpMethod,\n QueryParams,\n RequestBody,\n HeadersInput,\n ResponseType,\n DexiXResponse,\n DexiXRequestInfo,\n} from \"./types/index.js\";\n\nexport { DexiXError, NetworkError, TimeoutError, HTTPError, ParseError } from \"./errors/index.js\";\n\n/**\n * The default DexiX Request instance.\n *\n * @example\n * ```ts\n * import dx from \"dexix-request\";\n *\n * const users = await dx(\"/users\");\n * const user = await dx.get<User>(\"/users/1\");\n * await dx.post(\"/posts\", { title: \"Hello\" });\n * ```\n */\nconst dx: DexiXInstance = createInstance();\n\nexport { createInstance };\nexport default dx;\n"]}
1
+ {"version":3,"sources":["../src/errors/DexiXError.ts","../src/errors/HTTPError.ts","../src/errors/NetworkError.ts","../src/errors/TimeoutError.ts","../src/utils/buildURL.ts","../src/utils/mergeHeaders.ts","../src/utils/mergeConfig.ts","../src/utils/isPlainObject.ts","../src/utils/serializeBody.ts","../src/errors/ParseError.ts","../src/utils/parseResponse.ts","../src/utils/combineSignals.ts","../src/core/dispatch.ts","../src/core/interceptors.ts","../src/core/instance.ts","../src/index.ts"],"names":["DexiXError","message","request","response","HTTPError","NetworkError","cause","TimeoutError","timeout","isAbsoluteURL","url","joinURL","baseURL","trimmedBase","trimmedPath","appendQuery","query","path","existingSearch","params","key","value","item","search","buildURL","joined","mergeHeaders","sources","result","source","mergeConfig","parent","child","isPlainObject","prototype","isNativeBodyType","serializeBody","body","ParseError","EMPTY_STATUS_CODES","inferResponseType","contentType","parseResponse","responseType","type","text","failedResponse","combineSignals","userSignal","controller","timedOut","timer","onUserAbort","cancel","attempt","config","headers","requestInfo","signal","didTimeout","init","errorResponse","sleep","ms","resolve","defaultRetryDelay","attemptIndex","defaultRetryOn","error","dispatch","retries","retryDelay","retryOn","delay","InterceptorManager","fulfilled","rejected","id","handler","runRequestChain","manager","current","runResponseChain","outcome","failed","caught","defaults","interceptors","method","merged","resolved","requestWithBody","createInstance","requestInterceptors","responseInterceptors","instance","onFulfilled","onRejected","dx","index_default"],"mappings":"sEAEO,IAAMA,EAAN,cAAyB,KAAM,CACpB,OAAA,CACA,QAAA,CACA,OACA,OAAA,CACA,GAAA,CAET,YACLC,CAAAA,CACAC,CAAAA,CACAC,EACA,CACA,KAAA,CAAMF,CAAO,CAAA,CACb,IAAA,CAAK,KAAO,YAAA,CACZ,IAAA,CAAK,QAAUC,CAAAA,CACf,IAAA,CAAK,SAAWC,CAAAA,CAChB,IAAA,CAAK,OAASA,CAAAA,EAAU,MAAA,CACxB,KAAK,OAAA,CAAUA,CAAAA,EAAU,QACzB,IAAA,CAAK,GAAA,CAAMD,EAAQ,GAAA,CAEnB,MAAA,CAAO,eAAe,IAAA,CAAM,GAAA,CAAA,MAAA,CAAW,SAAS,EAClD,CACF,ECrBO,IAAME,CAAAA,CAAN,cAAwBJ,CAAW,CACjC,YAAYE,CAAAA,CAA2BC,CAAAA,CAAyB,CACrE,KAAA,CACE,CAAA,2BAAA,EAA8BA,EAAS,MAAM,CAAA,EAAA,EAAKA,EAAS,UAAU,CAAA,MAAA,EAASD,EAAQ,GAAG,CAA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AS,MAAA,CAAUxC,GAAWqC,CAAAA,CAAe9D,CAAAA,CAAYwD,EAAU/B,CAAAA,EAAU,EAAE,CAAC,CAAA,CAEzEwC,CACT,CC3HA,IAAMG,EAAoBN,CAAAA,EAAe,KAGlCO,EAAAA,CAAQD","file":"index.cjs","sourcesContent":["import type { DexiXRequestInfo, DexiXResponse } from \"../types/index.js\";\n\nexport class DexiXError extends Error {\n public readonly request: DexiXRequestInfo;\n public readonly response?: DexiXResponse;\n public readonly status?: number;\n public readonly headers?: Headers;\n public readonly url: string;\n\n public constructor(\n message: string,\n request: DexiXRequestInfo,\n response?: DexiXResponse,\n ) {\n super(message);\n this.name = \"DexiXError\";\n this.request = request;\n this.response = response;\n this.status = response?.status;\n this.headers = response?.headers;\n this.url = request.url;\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo, DexiXResponse } from \"../types/index.js\";\n\nexport class HTTPError extends DexiXError {\n public constructor(request: DexiXRequestInfo, response: DexiXResponse) {\n super(\n `Request failed with status ${response.status} (${response.statusText}) for ${request.url}`,\n request,\n response,\n );\n this.name = \"HTTPError\";\n }\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo } from \"../types/index.js\";\n\nexport class NetworkError extends DexiXError {\n public constructor(message: string, request: DexiXRequestInfo, cause?: unknown) {\n super(message || \"Network request failed\", request);\n this.name = \"NetworkError\";\n if (cause !== undefined) {\n this.cause = cause;\n }\n }\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo } from \"../types/index.js\";\n\nexport class TimeoutError extends DexiXError {\n public readonly timeout: number;\n\n public constructor(request: DexiXRequestInfo, timeout: number) {\n super(`Request to ${request.url} timed out after ${timeout}ms`, request);\n this.name = \"TimeoutError\";\n this.timeout = timeout;\n }\n}\n","import type { QueryParams } from \"../types/index.js\";\n\nfunction isAbsoluteURL(url: string): boolean {\n return /^([a-z][a-z\\d+\\-.]*:)?\\/\\//i.test(url);\n}\n\nfunction joinURL(baseURL: string, url: string): string {\n if (!baseURL) return url;\n if (isAbsoluteURL(url)) return url;\n\n const trimmedBase = baseURL.endsWith(\"/\") ? baseURL.slice(0, -1) : baseURL;\n const trimmedPath = url.startsWith(\"/\") ? url : `/${url}`;\n return `${trimmedBase}${trimmedPath}`;\n}\n\nfunction appendQuery(url: string, query?: QueryParams): string {\n if (!query || Object.keys(query).length === 0) {\n return url;\n }\n\n const [path, existingSearch = \"\"] = url.split(\"?\");\n const params = new URLSearchParams(existingSearch);\n\n for (const [key, value] of Object.entries(query)) {\n if (value === null || value === undefined) continue;\n\n if (Array.isArray(value)) {\n for (const item of value) {\n params.append(key, String(item));\n }\n } else {\n params.append(key, String(value));\n }\n }\n\n const search = params.toString();\n return search ? `${path}?${search}` : (path as string);\n}\n\nexport function buildURL(baseURL: string | undefined, url: string, query?: QueryParams): string {\n const joined = joinURL(baseURL ?? \"\", url);\n return appendQuery(joined, query);\n}\n","import type { HeadersInput } from \"../types/index.js\";\n\nexport function mergeHeaders(...sources: Array<HeadersInput | undefined>): Headers {\n const result = new Headers();\n\n for (const source of sources) {\n if (!source) continue;\n\n if (source instanceof Headers) {\n source.forEach((value, key) => {\n result.set(key, value);\n });\n continue;\n }\n\n if (Array.isArray(source)) {\n for (const [key, value] of source) {\n result.set(key, value);\n }\n continue;\n }\n\n for (const [key, value] of Object.entries(source)) {\n if (value === undefined) {\n result.delete(key);\n } else {\n result.set(key, value);\n }\n }\n }\n\n return result;\n}\n","import { mergeHeaders } from \"./mergeHeaders.js\";\nimport type { RequestConfig } from \"../types/index.js\";\n\nexport function mergeConfig(parent: RequestConfig, child: RequestConfig): RequestConfig {\n return {\n ...parent,\n ...child,\n headers: mergeHeaders(parent.headers, child.headers),\n query: { ...parent.query, ...child.query },\n };\n}\n","export function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value) as unknown;\n return prototype === Object.prototype || prototype === null;\n}\n","import { isPlainObject } from \"./isPlainObject.js\";\nimport type { RequestBody } from \"../types/index.js\";\n\nexport interface SerializedBody {\n body: BodyInit | null | undefined;\n contentType?: string;\n}\n\nfunction isNativeBodyType(value: unknown): value is BodyInit {\n return (\n typeof value === \"string\" ||\n value instanceof FormData ||\n value instanceof Blob ||\n value instanceof URLSearchParams ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value) ||\n value instanceof ReadableStream\n );\n}\n\nexport function serializeBody(body: RequestBody): SerializedBody {\n if (body === null || body === undefined) {\n return { body: undefined };\n }\n\n if (isNativeBodyType(body)) {\n if (body instanceof FormData) {\n return { body };\n }\n if (body instanceof URLSearchParams) {\n return { body, contentType: \"application/x-www-form-urlencoded;charset=UTF-8\" };\n }\n if (typeof body === \"string\") {\n return { body, contentType: \"text/plain;charset=UTF-8\" };\n }\n return { body };\n }\n\n if (isPlainObject(body) || Array.isArray(body)) {\n return {\n body: JSON.stringify(body),\n contentType: \"application/json;charset=UTF-8\",\n };\n }\n\n return {\n body: JSON.stringify(body),\n contentType: \"application/json;charset=UTF-8\",\n };\n}\n","import { DexiXError } from \"./DexiXError.js\";\nimport type { DexiXRequestInfo, DexiXResponse } from \"../types/index.js\";\n\nexport class ParseError extends DexiXError {\n public constructor(request: DexiXRequestInfo, response: DexiXResponse, cause?: unknown) {\n super(`Failed to parse response body from ${request.url}`, request, response);\n this.name = \"ParseError\";\n if (cause !== undefined) {\n this.cause = cause;\n }\n }\n}\n","import { ParseError } from \"../errors/ParseError.js\";\nimport type { DexiXRequestInfo, DexiXResponse, ResponseType } from \"../types/index.js\";\n\nconst EMPTY_STATUS_CODES = new Set([204, 205, 304]);\n\nfunction inferResponseType(response: Response): ResponseType {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n\n if (contentType.includes(\"application/json\") || contentType.includes(\"+json\")) {\n return \"json\";\n }\n if (contentType.startsWith(\"text/\")) {\n return \"text\";\n }\n return \"json\";\n}\n\nexport async function parseResponse<T>(\n response: Response,\n request: DexiXRequestInfo,\n responseType?: ResponseType,\n): Promise<T> {\n if (request.method === \"HEAD\" || EMPTY_STATUS_CODES.has(response.status)) {\n return undefined as T;\n }\n\n const type = responseType ?? inferResponseType(response);\n\n try {\n switch (type) {\n case \"json\": {\n const text = await response.text();\n if (text.length === 0) {\n return undefined as T;\n }\n return JSON.parse(text) as T;\n }\n case \"text\":\n return (await response.text()) as unknown as T;\n case \"blob\":\n return (await response.blob()) as unknown as T;\n case \"arrayBuffer\":\n return (await response.arrayBuffer()) as unknown as T;\n case \"stream\":\n return response.body as unknown as T;\n default:\n return (await response.text()) as unknown as T;\n }\n } catch (cause) {\n const failedResponse: DexiXResponse = {\n data: undefined,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n url: response.url || request.url,\n };\n throw new ParseError(request, failedResponse, cause);\n }\n}\n","export function combineSignals(\n userSignal: AbortSignal | undefined,\n timeout: number | undefined,\n): {\n signal: AbortSignal | undefined;\n cancel: () => void;\n didTimeout: () => boolean;\n} {\n if (!timeout || timeout <= 0) {\n return {\n signal: userSignal,\n cancel: () => {},\n didTimeout: () => false,\n };\n }\n\n const controller = new AbortController();\n let timedOut = false;\n\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort();\n }, timeout);\n\n const onUserAbort = () => controller.abort();\n userSignal?.addEventListener(\"abort\", onUserAbort, { once: true });\n\n const cancel = () => {\n clearTimeout(timer);\n userSignal?.removeEventListener(\"abort\", onUserAbort);\n };\n\n return {\n signal: controller.signal,\n cancel,\n didTimeout: () => timedOut,\n };\n}\n","import { HTTPError } from \"../errors/HTTPError.js\";\nimport { NetworkError } from \"../errors/NetworkError.js\";\nimport { TimeoutError } from \"../errors/TimeoutError.js\";\nimport { buildURL, combineSignals, mergeHeaders, parseResponse, serializeBody } from \"../utils/index.js\";\nimport type { DexiXRequestInfo, DexiXResponse, ResolvedRequestConfig } from \"../types/index.js\";\n\nasync function attempt<T>(config: ResolvedRequestConfig): Promise<T> {\n const { body, contentType } = serializeBody(config.body);\n\n const headers = mergeHeaders(\n contentType ? { \"content-type\": contentType } : undefined,\n config.headers,\n );\n\n const url = buildURL(config.baseURL, config.url, config.query);\n\n const requestInfo: DexiXRequestInfo = {\n url,\n method: config.method,\n headers,\n body: config.body,\n };\n\n const { signal, cancel, didTimeout } = combineSignals(config.signal, config.timeout);\n\n const init: RequestInit = {\n method: config.method,\n headers,\n body: config.method === \"GET\" || config.method === \"HEAD\" ? undefined : body,\n signal,\n credentials: config.credentials,\n cache: config.cache,\n redirect: config.redirect,\n referrerPolicy: config.referrerPolicy,\n mode: config.mode,\n };\n\n const request = new Request(url, init);\n\n if (config.onRequest) {\n await config.onRequest(request);\n }\n\n let response: Response;\n\n try {\n response = await fetch(request);\n } catch (cause) {\n cancel();\n\n if (cause instanceof DOMException && cause.name === \"AbortError\") {\n if (didTimeout()) {\n throw new TimeoutError(requestInfo, config.timeout ?? 0);\n }\n throw cause;\n }\n\n throw new NetworkError(\n cause instanceof Error ? cause.message : \"Network request failed\",\n requestInfo,\n cause,\n );\n }\n\n cancel();\n\n if (config.onResponse) {\n await config.onResponse(response);\n }\n\n if (!response.ok) {\n const data = await parseResponse<unknown>(response, requestInfo, config.responseType).catch(\n () => undefined,\n );\n\n const errorResponse: DexiXResponse = {\n data,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n url: response.url || url,\n };\n\n throw new HTTPError(requestInfo, errorResponse);\n }\n\n return parseResponse<T>(response, requestInfo, config.responseType);\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nfunction defaultRetryDelay(attemptIndex: number): number {\n return Math.min(250 * 2 ** attemptIndex, 8000);\n}\n\nfunction defaultRetryOn(error: unknown): boolean {\n if (error instanceof HTTPError) {\n return error.status !== undefined && (error.status >= 500 || error.status === 429);\n }\n return error instanceof NetworkError || error instanceof TimeoutError;\n}\n\nexport async function dispatch<T>(config: ResolvedRequestConfig): Promise<T> {\n const retries = config.retries ?? 0;\n const retryDelay = config.retryDelay ?? defaultRetryDelay;\n const retryOn = config.retryOn ?? defaultRetryOn;\n\n for (let attemptIndex = 0; ; attemptIndex++) {\n try {\n return await attempt<T>(config);\n } catch (error) {\n const canRetry = attemptIndex < retries && retryOn(error, attemptIndex);\n if (!canRetry) throw error;\n\n const delay = typeof retryDelay === \"function\" ? retryDelay(attemptIndex, error) : retryDelay;\n if (delay > 0) await sleep(delay);\n }\n }\n}\n","import type { InterceptorFulfilled, InterceptorRejected } from \"../types/index.js\";\n\ninterface InterceptorHandler<V> {\n fulfilled: InterceptorFulfilled<V>;\n rejected?: InterceptorRejected;\n}\n\nexport class InterceptorManager<V> {\n private handlers: Array<InterceptorHandler<V> | null> = [];\n\n use(fulfilled: InterceptorFulfilled<V>, rejected?: InterceptorRejected): number {\n this.handlers.push({ fulfilled, rejected });\n return this.handlers.length - 1;\n }\n\n eject(id: number): void {\n if (this.handlers[id]) {\n this.handlers[id] = null;\n }\n }\n\n clear(): void {\n this.handlers = [];\n }\n\n list(): Array<InterceptorHandler<V>> {\n return this.handlers.filter((handler): handler is InterceptorHandler<V> => handler !== null);\n }\n}\n","import { dispatch } from \"./dispatch.js\";\nimport { InterceptorManager } from \"./interceptors.js\";\nimport { mergeConfig } from \"../utils/index.js\";\nimport type {\n DexiXInstance,\n DexiXInterceptors,\n HttpMethod,\n RequestBody,\n RequestConfig,\n ResolvedRequestConfig,\n} from \"../types/index.js\";\n\ninterface Interceptors {\n request: InterceptorManager<ResolvedRequestConfig>;\n response: InterceptorManager<unknown>;\n}\n\nasync function runRequestChain(\n manager: InterceptorManager<ResolvedRequestConfig>,\n config: ResolvedRequestConfig,\n): Promise<ResolvedRequestConfig> {\n let current = config;\n\n for (const handler of manager.list()) {\n try {\n current = await handler.fulfilled(current);\n } catch (error) {\n if (!handler.rejected) throw error;\n current = (await handler.rejected(error)) as ResolvedRequestConfig;\n }\n }\n\n return current;\n}\n\nasync function runResponseChain<T>(\n manager: InterceptorManager<unknown>,\n outcome: Promise<T>,\n): Promise<T> {\n let value: unknown;\n let error: unknown;\n let failed = false;\n\n try {\n value = await outcome;\n } catch (caught) {\n failed = true;\n error = caught;\n }\n\n for (const handler of manager.list()) {\n if (failed) {\n if (!handler.rejected) continue;\n try {\n value = await handler.rejected(error);\n failed = false;\n } catch (caught) {\n error = caught;\n }\n continue;\n }\n value = await handler.fulfilled(value);\n }\n\n if (failed) throw error;\n return value as T;\n}\n\nfunction request<T>(\n defaults: RequestConfig,\n interceptors: Interceptors,\n method: HttpMethod,\n url: string,\n config?: RequestConfig,\n): Promise<T> {\n const merged: ResolvedRequestConfig = {\n ...mergeConfig(defaults, config ?? {}),\n method,\n url,\n };\n\n const outcome = (async (): Promise<T> => {\n const resolved = await runRequestChain(interceptors.request, merged);\n return dispatch<T>(resolved);\n })();\n\n return runResponseChain(interceptors.response, outcome);\n}\n\nfunction requestWithBody<T>(\n defaults: RequestConfig,\n interceptors: Interceptors,\n method: HttpMethod,\n url: string,\n body?: RequestBody,\n config?: RequestConfig,\n): Promise<T> {\n return request<T>(defaults, interceptors, method, url, { ...config, body: body ?? config?.body });\n}\n\nexport function createInstance(defaults: RequestConfig = {}): DexiXInstance {\n const requestInterceptors = new InterceptorManager<ResolvedRequestConfig>();\n const responseInterceptors = new InterceptorManager<unknown>();\n const interceptors: Interceptors = { request: requestInterceptors, response: responseInterceptors };\n\n const instance = (<T>(url: string, config?: RequestConfig): Promise<T> =>\n request<T>(defaults, interceptors, \"GET\", url, config)) as DexiXInstance;\n\n instance.get = (url, config) => request(defaults, interceptors, \"GET\", url, config);\n instance.post = (url, body, config) => requestWithBody(defaults, interceptors, \"POST\", url, body, config);\n instance.put = (url, body, config) => requestWithBody(defaults, interceptors, \"PUT\", url, body, config);\n instance.patch = (url, body, config) => requestWithBody(defaults, interceptors, \"PATCH\", url, body, config);\n instance.delete = (url, config) => request(defaults, interceptors, \"DELETE\", url, config);\n instance.head = (url, config) => request(defaults, interceptors, \"HEAD\", url, config);\n instance.options = (url, config) => request(defaults, interceptors, \"OPTIONS\", url, config);\n\n Object.defineProperty(instance, \"defaults\", {\n value: defaults,\n writable: false,\n enumerable: true,\n });\n\n const publicInterceptors: DexiXInterceptors = {\n request: {\n use: (onFulfilled, onRejected) => requestInterceptors.use(onFulfilled, onRejected),\n eject: (id) => requestInterceptors.eject(id),\n clear: () => requestInterceptors.clear(),\n },\n response: {\n use: (onFulfilled, onRejected) => responseInterceptors.use(onFulfilled, onRejected),\n eject: (id) => responseInterceptors.eject(id),\n clear: () => responseInterceptors.clear(),\n },\n };\n\n Object.defineProperty(instance, \"interceptors\", {\n value: publicInterceptors,\n writable: false,\n enumerable: true,\n });\n\n instance.create = (config) => createInstance(mergeConfig(defaults, config ?? {}));\n\n return instance;\n}\n","import { createInstance } from \"./core/index.js\";\nimport type { DexiXInstance } from \"./types/index.js\";\n\nexport type {\n DexiXInstance,\n RequestConfig,\n HttpMethod,\n QueryParams,\n RequestBody,\n HeadersInput,\n ResponseType,\n DexiXResponse,\n DexiXRequestInfo,\n DexiXInterceptors,\n DexiXInterceptorManager,\n RetryDelay,\n RetryPredicate,\n} from \"./types/index.js\";\n\nexport { DexiXError, NetworkError, TimeoutError, HTTPError, ParseError } from \"./errors/index.js\";\n\nconst dx: DexiXInstance = createInstance();\n\nexport { createInstance };\nexport default dx;\n"]}
package/dist/index.d.cts CHANGED
@@ -1,81 +1,39 @@
1
- /**
2
- * HTTP methods supported by DexiX Request.
3
- */
4
1
  type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
5
- /**
6
- * Plain object of query parameters. Array values are serialized as
7
- * repeated keys (e.g. `{ tag: ["a", "b"] }` -> `?tag=a&tag=b`).
8
- */
9
2
  type QueryParams = Record<string, string | number | boolean | null | undefined | Array<string | number | boolean>>;
10
- /**
11
- * Anything that can be sent as a request body.
12
- * Plain objects and arrays are automatically JSON-serialized.
13
- */
14
3
  type RequestBody = BodyInit | Record<string, unknown> | unknown[] | null | undefined;
15
- /**
16
- * Headers accepted by DexiX Request. Accepts a plain object, a `Headers`
17
- * instance, or an array of key/value pairs (same as the `HeadersInit` type).
18
- */
19
4
  type HeadersInput = HeadersInit | Record<string, string | undefined>;
20
- /**
21
- * Response type hint. DexiX Request defaults to `"json"` and falls back
22
- * gracefully when the response has no JSON body.
23
- */
24
5
  type ResponseType = "json" | "text" | "blob" | "arrayBuffer" | "stream";
25
- /**
26
- * Configuration accepted by every request call, and by `dx.create()`.
27
- */
6
+ type RetryDelay = number | ((attemptIndex: number, error: unknown) => number);
7
+ type RetryPredicate = (error: unknown, attemptIndex: number) => boolean;
28
8
  interface RequestConfig {
29
- /** Base URL prepended to every relative request URL. */
30
9
  baseURL?: string;
31
- /** Headers merged into every request. */
32
10
  headers?: HeadersInput;
33
- /** Query parameters appended to the URL's search string. */
34
11
  query?: QueryParams;
35
- /** Request body. Objects/arrays are JSON-serialized automatically. */
36
12
  body?: RequestBody;
37
- /** Timeout in milliseconds. `0` or `undefined` disables the timeout. */
38
13
  timeout?: number;
39
- /** An `AbortSignal` to cancel the request. Composable with `timeout`. */
40
14
  signal?: AbortSignal;
41
- /** How to parse the response body. Defaults to `"json"`. */
42
15
  responseType?: ResponseType;
43
- /** Credentials mode, forwarded to `fetch`. */
44
16
  credentials?: RequestCredentials;
45
- /** Cache mode, forwarded to `fetch`. */
46
17
  cache?: RequestCache;
47
- /** Redirect mode, forwarded to `fetch`. */
48
18
  redirect?: RequestRedirect;
49
- /** Referrer policy, forwarded to `fetch`. */
50
19
  referrerPolicy?: ReferrerPolicy;
51
- /** Mode, forwarded to `fetch`. */
52
20
  mode?: RequestMode;
53
- /**
54
- * Called once per request with the fully-resolved `Request` before it is
55
- * sent. Useful for logging or attaching auth tokens dynamically.
56
- */
21
+ retries?: number;
22
+ retryDelay?: RetryDelay;
23
+ retryOn?: RetryPredicate;
57
24
  onRequest?: (request: Request) => void | Promise<void>;
58
- /**
59
- * Called once per request with the raw `Response`, before the body is
60
- * parsed.
61
- */
62
25
  onResponse?: (response: Response) => void | Promise<void>;
63
26
  }
64
- /**
65
- * Metadata attached to every DexiX error, describing the request that
66
- * produced it.
67
- */
27
+ interface ResolvedRequestConfig extends RequestConfig {
28
+ method: HttpMethod;
29
+ url: string;
30
+ }
68
31
  interface DexiXRequestInfo {
69
32
  url: string;
70
33
  method: HttpMethod;
71
34
  headers: Headers;
72
35
  body?: RequestBody;
73
36
  }
74
- /**
75
- * The shape of a successful DexiX Request response before unwrapping.
76
- * Consumers normally never see this directly, since `dx()` resolves to
77
- * the parsed body, but it's available via `HTTPError.response`.
78
- */
79
37
  interface DexiXResponse<T = unknown> {
80
38
  data: T;
81
39
  status: number;
@@ -83,10 +41,17 @@ interface DexiXResponse<T = unknown> {
83
41
  headers: Headers;
84
42
  url: string;
85
43
  }
86
- /**
87
- * A callable DexiX Request instance. Calling it directly performs a GET
88
- * request. Method-specific helpers are attached for convenience.
89
- */
44
+ type InterceptorFulfilled<V> = (value: V) => V | Promise<V>;
45
+ type InterceptorRejected = (error: unknown) => unknown;
46
+ interface DexiXInterceptorManager<V> {
47
+ use(onFulfilled: InterceptorFulfilled<V>, onRejected?: InterceptorRejected): number;
48
+ eject(id: number): void;
49
+ clear(): void;
50
+ }
51
+ interface DexiXInterceptors {
52
+ request: DexiXInterceptorManager<ResolvedRequestConfig>;
53
+ response: DexiXInterceptorManager<unknown>;
54
+ }
90
55
  interface DexiXInstance {
91
56
  <T = unknown>(url: string, config?: RequestConfig): Promise<T>;
92
57
  get<T = unknown>(url: string, config?: RequestConfig): Promise<T>;
@@ -96,89 +61,39 @@ interface DexiXInstance {
96
61
  delete<T = unknown>(url: string, config?: RequestConfig): Promise<T>;
97
62
  head(url: string, config?: RequestConfig): Promise<void>;
98
63
  options<T = unknown>(url: string, config?: RequestConfig): Promise<T>;
99
- /** The base configuration this instance was created with. */
100
64
  readonly defaults: RequestConfig;
101
- /**
102
- * Create a new, independent DexiX Request instance. Config is merged
103
- * with the parent instance's defaults (child config wins).
104
- */
65
+ readonly interceptors: DexiXInterceptors;
105
66
  create(config?: RequestConfig): DexiXInstance;
106
67
  }
107
68
 
108
- /**
109
- * Creates a new DexiX Request instance. Calling the instance directly
110
- * performs a GET request; method-specific helpers (`get`, `post`, `put`,
111
- * `patch`, `delete`, `head`, `options`) are attached for convenience.
112
- */
113
69
  declare function createInstance(defaults?: RequestConfig): DexiXInstance;
114
70
 
115
- /**
116
- * Base class for every error thrown by DexiX Request.
117
- * All DexiX errors carry the originating request and, when available,
118
- * the response that was received.
119
- */
120
71
  declare class DexiXError extends Error {
121
- /** The request that caused this error. */
122
72
  readonly request: DexiXRequestInfo;
123
- /** The response received, if any (absent for network/timeout errors). */
124
73
  readonly response?: DexiXResponse;
125
- /** HTTP status code, if a response was received. */
126
74
  readonly status?: number;
127
- /** Response headers, if a response was received. */
128
75
  readonly headers?: Headers;
129
- /** The request URL. */
130
76
  readonly url: string;
131
77
  constructor(message: string, request: DexiXRequestInfo, response?: DexiXResponse);
132
78
  }
133
79
 
134
- /**
135
- * Thrown when the request could not be completed because of a network
136
- * failure (DNS resolution failure, connection refused, offline, CORS
137
- * rejection, etc). No response was ever received.
138
- */
139
80
  declare class NetworkError extends DexiXError {
140
81
  constructor(message: string, request: DexiXRequestInfo, cause?: unknown);
141
82
  }
142
83
 
143
- /**
144
- * Thrown when a request exceeds its configured `timeout` before a
145
- * response is received.
146
- */
147
84
  declare class TimeoutError extends DexiXError {
148
- /** The timeout duration, in milliseconds, that was exceeded. */
149
85
  readonly timeout: number;
150
86
  constructor(request: DexiXRequestInfo, timeout: number);
151
87
  }
152
88
 
153
- /**
154
- * Thrown when the server responds with a non-2xx status code.
155
- * Always carries the full `response`, including any parsed body DexiX
156
- * Request was able to extract before raising the error.
157
- */
158
89
  declare class HTTPError extends DexiXError {
159
90
  constructor(request: DexiXRequestInfo, response: DexiXResponse);
160
91
  }
161
92
 
162
- /**
163
- * Thrown when a response body could not be parsed according to the
164
- * requested (or inferred) `responseType`, e.g. invalid JSON.
165
- */
166
93
  declare class ParseError extends DexiXError {
167
94
  constructor(request: DexiXRequestInfo, response: DexiXResponse, cause?: unknown);
168
95
  }
169
96
 
170
- /**
171
- * The default DexiX Request instance.
172
- *
173
- * @example
174
- * ```ts
175
- * import dx from "dexix-request";
176
- *
177
- * const users = await dx("/users");
178
- * const user = await dx.get<User>("/users/1");
179
- * await dx.post("/posts", { title: "Hello" });
180
- * ```
181
- */
182
97
  declare const dx: DexiXInstance;
183
98
 
184
- export { DexiXError, type DexiXInstance, type DexiXRequestInfo, type DexiXResponse, HTTPError, type HeadersInput, type HttpMethod, NetworkError, ParseError, type QueryParams, type RequestBody, type RequestConfig, type ResponseType, TimeoutError, createInstance, dx as default };
99
+ export { DexiXError, type DexiXInstance, type DexiXInterceptorManager, type DexiXInterceptors, type DexiXRequestInfo, type DexiXResponse, HTTPError, type HeadersInput, type HttpMethod, NetworkError, ParseError, type QueryParams, type RequestBody, type RequestConfig, type ResponseType, type RetryDelay, type RetryPredicate, TimeoutError, createInstance, dx as default };
package/dist/index.d.ts CHANGED
@@ -1,81 +1,39 @@
1
- /**
2
- * HTTP methods supported by DexiX Request.
3
- */
4
1
  type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
5
- /**
6
- * Plain object of query parameters. Array values are serialized as
7
- * repeated keys (e.g. `{ tag: ["a", "b"] }` -> `?tag=a&tag=b`).
8
- */
9
2
  type QueryParams = Record<string, string | number | boolean | null | undefined | Array<string | number | boolean>>;
10
- /**
11
- * Anything that can be sent as a request body.
12
- * Plain objects and arrays are automatically JSON-serialized.
13
- */
14
3
  type RequestBody = BodyInit | Record<string, unknown> | unknown[] | null | undefined;
15
- /**
16
- * Headers accepted by DexiX Request. Accepts a plain object, a `Headers`
17
- * instance, or an array of key/value pairs (same as the `HeadersInit` type).
18
- */
19
4
  type HeadersInput = HeadersInit | Record<string, string | undefined>;
20
- /**
21
- * Response type hint. DexiX Request defaults to `"json"` and falls back
22
- * gracefully when the response has no JSON body.
23
- */
24
5
  type ResponseType = "json" | "text" | "blob" | "arrayBuffer" | "stream";
25
- /**
26
- * Configuration accepted by every request call, and by `dx.create()`.
27
- */
6
+ type RetryDelay = number | ((attemptIndex: number, error: unknown) => number);
7
+ type RetryPredicate = (error: unknown, attemptIndex: number) => boolean;
28
8
  interface RequestConfig {
29
- /** Base URL prepended to every relative request URL. */
30
9
  baseURL?: string;
31
- /** Headers merged into every request. */
32
10
  headers?: HeadersInput;
33
- /** Query parameters appended to the URL's search string. */
34
11
  query?: QueryParams;
35
- /** Request body. Objects/arrays are JSON-serialized automatically. */
36
12
  body?: RequestBody;
37
- /** Timeout in milliseconds. `0` or `undefined` disables the timeout. */
38
13
  timeout?: number;
39
- /** An `AbortSignal` to cancel the request. Composable with `timeout`. */
40
14
  signal?: AbortSignal;
41
- /** How to parse the response body. Defaults to `"json"`. */
42
15
  responseType?: ResponseType;
43
- /** Credentials mode, forwarded to `fetch`. */
44
16
  credentials?: RequestCredentials;
45
- /** Cache mode, forwarded to `fetch`. */
46
17
  cache?: RequestCache;
47
- /** Redirect mode, forwarded to `fetch`. */
48
18
  redirect?: RequestRedirect;
49
- /** Referrer policy, forwarded to `fetch`. */
50
19
  referrerPolicy?: ReferrerPolicy;
51
- /** Mode, forwarded to `fetch`. */
52
20
  mode?: RequestMode;
53
- /**
54
- * Called once per request with the fully-resolved `Request` before it is
55
- * sent. Useful for logging or attaching auth tokens dynamically.
56
- */
21
+ retries?: number;
22
+ retryDelay?: RetryDelay;
23
+ retryOn?: RetryPredicate;
57
24
  onRequest?: (request: Request) => void | Promise<void>;
58
- /**
59
- * Called once per request with the raw `Response`, before the body is
60
- * parsed.
61
- */
62
25
  onResponse?: (response: Response) => void | Promise<void>;
63
26
  }
64
- /**
65
- * Metadata attached to every DexiX error, describing the request that
66
- * produced it.
67
- */
27
+ interface ResolvedRequestConfig extends RequestConfig {
28
+ method: HttpMethod;
29
+ url: string;
30
+ }
68
31
  interface DexiXRequestInfo {
69
32
  url: string;
70
33
  method: HttpMethod;
71
34
  headers: Headers;
72
35
  body?: RequestBody;
73
36
  }
74
- /**
75
- * The shape of a successful DexiX Request response before unwrapping.
76
- * Consumers normally never see this directly, since `dx()` resolves to
77
- * the parsed body, but it's available via `HTTPError.response`.
78
- */
79
37
  interface DexiXResponse<T = unknown> {
80
38
  data: T;
81
39
  status: number;
@@ -83,10 +41,17 @@ interface DexiXResponse<T = unknown> {
83
41
  headers: Headers;
84
42
  url: string;
85
43
  }
86
- /**
87
- * A callable DexiX Request instance. Calling it directly performs a GET
88
- * request. Method-specific helpers are attached for convenience.
89
- */
44
+ type InterceptorFulfilled<V> = (value: V) => V | Promise<V>;
45
+ type InterceptorRejected = (error: unknown) => unknown;
46
+ interface DexiXInterceptorManager<V> {
47
+ use(onFulfilled: InterceptorFulfilled<V>, onRejected?: InterceptorRejected): number;
48
+ eject(id: number): void;
49
+ clear(): void;
50
+ }
51
+ interface DexiXInterceptors {
52
+ request: DexiXInterceptorManager<ResolvedRequestConfig>;
53
+ response: DexiXInterceptorManager<unknown>;
54
+ }
90
55
  interface DexiXInstance {
91
56
  <T = unknown>(url: string, config?: RequestConfig): Promise<T>;
92
57
  get<T = unknown>(url: string, config?: RequestConfig): Promise<T>;
@@ -96,89 +61,39 @@ interface DexiXInstance {
96
61
  delete<T = unknown>(url: string, config?: RequestConfig): Promise<T>;
97
62
  head(url: string, config?: RequestConfig): Promise<void>;
98
63
  options<T = unknown>(url: string, config?: RequestConfig): Promise<T>;
99
- /** The base configuration this instance was created with. */
100
64
  readonly defaults: RequestConfig;
101
- /**
102
- * Create a new, independent DexiX Request instance. Config is merged
103
- * with the parent instance's defaults (child config wins).
104
- */
65
+ readonly interceptors: DexiXInterceptors;
105
66
  create(config?: RequestConfig): DexiXInstance;
106
67
  }
107
68
 
108
- /**
109
- * Creates a new DexiX Request instance. Calling the instance directly
110
- * performs a GET request; method-specific helpers (`get`, `post`, `put`,
111
- * `patch`, `delete`, `head`, `options`) are attached for convenience.
112
- */
113
69
  declare function createInstance(defaults?: RequestConfig): DexiXInstance;
114
70
 
115
- /**
116
- * Base class for every error thrown by DexiX Request.
117
- * All DexiX errors carry the originating request and, when available,
118
- * the response that was received.
119
- */
120
71
  declare class DexiXError extends Error {
121
- /** The request that caused this error. */
122
72
  readonly request: DexiXRequestInfo;
123
- /** The response received, if any (absent for network/timeout errors). */
124
73
  readonly response?: DexiXResponse;
125
- /** HTTP status code, if a response was received. */
126
74
  readonly status?: number;
127
- /** Response headers, if a response was received. */
128
75
  readonly headers?: Headers;
129
- /** The request URL. */
130
76
  readonly url: string;
131
77
  constructor(message: string, request: DexiXRequestInfo, response?: DexiXResponse);
132
78
  }
133
79
 
134
- /**
135
- * Thrown when the request could not be completed because of a network
136
- * failure (DNS resolution failure, connection refused, offline, CORS
137
- * rejection, etc). No response was ever received.
138
- */
139
80
  declare class NetworkError extends DexiXError {
140
81
  constructor(message: string, request: DexiXRequestInfo, cause?: unknown);
141
82
  }
142
83
 
143
- /**
144
- * Thrown when a request exceeds its configured `timeout` before a
145
- * response is received.
146
- */
147
84
  declare class TimeoutError extends DexiXError {
148
- /** The timeout duration, in milliseconds, that was exceeded. */
149
85
  readonly timeout: number;
150
86
  constructor(request: DexiXRequestInfo, timeout: number);
151
87
  }
152
88
 
153
- /**
154
- * Thrown when the server responds with a non-2xx status code.
155
- * Always carries the full `response`, including any parsed body DexiX
156
- * Request was able to extract before raising the error.
157
- */
158
89
  declare class HTTPError extends DexiXError {
159
90
  constructor(request: DexiXRequestInfo, response: DexiXResponse);
160
91
  }
161
92
 
162
- /**
163
- * Thrown when a response body could not be parsed according to the
164
- * requested (or inferred) `responseType`, e.g. invalid JSON.
165
- */
166
93
  declare class ParseError extends DexiXError {
167
94
  constructor(request: DexiXRequestInfo, response: DexiXResponse, cause?: unknown);
168
95
  }
169
96
 
170
- /**
171
- * The default DexiX Request instance.
172
- *
173
- * @example
174
- * ```ts
175
- * import dx from "dexix-request";
176
- *
177
- * const users = await dx("/users");
178
- * const user = await dx.get<User>("/users/1");
179
- * await dx.post("/posts", { title: "Hello" });
180
- * ```
181
- */
182
97
  declare const dx: DexiXInstance;
183
98
 
184
- export { DexiXError, type DexiXInstance, type DexiXRequestInfo, type DexiXResponse, HTTPError, type HeadersInput, type HttpMethod, NetworkError, ParseError, type QueryParams, type RequestBody, type RequestConfig, type ResponseType, TimeoutError, createInstance, dx as default };
99
+ export { DexiXError, type DexiXInstance, type DexiXInterceptorManager, type DexiXInterceptors, type DexiXRequestInfo, type DexiXResponse, HTTPError, type HeadersInput, type HttpMethod, NetworkError, ParseError, type QueryParams, type RequestBody, type RequestConfig, type ResponseType, type RetryDelay, type RetryPredicate, TimeoutError, createInstance, dx as default };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- var i=class extends Error{request;response;status;headers;url;constructor(t,r,n){super(t),this.name="DexiXError",this.request=r,this.response=n,this.status=n?.status,this.headers=n?.headers,this.url=r.url,Object.setPrototypeOf(this,new.target.prototype);}};var c=class extends i{constructor(t,r){super(`Request failed with status ${r.status} (${r.statusText}) for ${t.url}`,t,r),this.name="HTTPError";}};var d=class extends i{constructor(t,r,n){super(t||"Network request failed",r),this.name="NetworkError",n!==void 0&&(this.cause=n);}};var m=class extends i{timeout;constructor(t,r){super(`Request to ${t.url} timed out after ${r}ms`,t),this.name="TimeoutError",this.timeout=r;}};function C(e){return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function k(e,t){if(!e||C(t))return t;let r=e.endsWith("/")?e.slice(0,-1):e,n=t.startsWith("/")?t:`/${t}`;return `${r}${n}`}function H(e,t){if(!t||Object.keys(t).length===0)return e;let[r,n=""]=e.split("?"),o=new URLSearchParams(n);for(let[f,u]of Object.entries(t))if(u!=null)if(Array.isArray(u))for(let b of u)o.append(f,String(b));else o.append(f,String(u));let s=o.toString();return s?`${r}?${s}`:r}function q(e,t,r){let n=k(e??"",t);return H(n,r)}function l(...e){let t=new Headers;for(let r of e)if(r){if(r instanceof Headers){r.forEach((n,o)=>{t.set(o,n);});continue}if(Array.isArray(r)){for(let[n,o]of r)t.set(n,o);continue}for(let[n,o]of Object.entries(r))o===void 0?t.delete(n):t.set(n,o);}return t}function R(e,t){return {...e,...t,headers:l(e.headers,t.headers),query:{...e.query,...t.query}}}function E(e){if(typeof e!="object"||e===null)return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function S(e){return typeof e=="string"||e instanceof FormData||e instanceof Blob||e instanceof URLSearchParams||e instanceof ArrayBuffer||ArrayBuffer.isView(e)||e instanceof ReadableStream}function w(e){return e==null?{body:void 0}:S(e)?e instanceof FormData?{body:e}:e instanceof URLSearchParams?{body:e,contentType:"application/x-www-form-urlencoded;charset=UTF-8"}:typeof e=="string"?{body:e,contentType:"text/plain;charset=UTF-8"}:{body:e}:E(e)||Array.isArray(e)?{body:JSON.stringify(e),contentType:"application/json;charset=UTF-8"}:{body:JSON.stringify(e),contentType:"application/json;charset=UTF-8"}}var x=class extends i{constructor(t,r,n){super(`Failed to parse response body from ${t.url}`,t,r),this.name="ParseError",n!==void 0&&(this.cause=n);}};var O=new Set([204,205,304]);function A(e){let t=e.headers.get("content-type")??"";return t.includes("application/json")||t.includes("+json")?"json":t.startsWith("text/")?"text":"json"}async function h(e,t,r){if(t.method==="HEAD"||O.has(e.status))return;let n=r??A(e);try{switch(n){case "json":{let o=await e.text();return o.length===0?void 0:JSON.parse(o)}case "text":return await e.text();case "blob":return await e.blob();case "arrayBuffer":return await e.arrayBuffer();case "stream":return e.body;default:return await e.text()}}catch(o){let s={data:void 0,status:e.status,statusText:e.statusText,headers:e.headers,url:e.url||t.url};throw new x(t,s,o)}}function D(e,t){if(!t||t<=0)return {signal:e,cancel:()=>{},didTimeout:()=>false};let r=new AbortController,n=false,o=setTimeout(()=>{n=true,r.abort();},t),s=()=>r.abort();e?.addEventListener("abort",s,{once:true});let f=()=>{clearTimeout(o),e?.removeEventListener("abort",s);};return {signal:r.signal,cancel:f,didTimeout:()=>n}}async function j(e){let{body:t,contentType:r}=w(e.body),n=l(r?{"content-type":r}:void 0,e.headers),o=q(e.baseURL,e.url,e.query),s={url:o,method:e.method,headers:n,body:e.body},{signal:f,cancel:u,didTimeout:b}=D(e.signal,e.timeout),I={method:e.method,headers:n,body:e.method==="GET"||e.method==="HEAD"?void 0:t,signal:f,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrerPolicy:e.referrerPolicy,mode:e.mode},X=new Request(o,I);e.onRequest&&await e.onRequest(X);let a;try{a=await fetch(X);}catch(p){throw u(),p instanceof DOMException&&p.name==="AbortError"?b()?new m(s,e.timeout??0):p:new d(p instanceof Error?p.message:"Network request failed",s,p)}if(u(),e.onResponse&&await e.onResponse(a),!a.ok){let P={data:await h(a,s,e.responseType).catch(()=>{}),status:a.status,statusText:a.statusText,headers:a.headers,url:a.url||o};throw new c(s,P)}return h(a,s,e.responseType)}function y(e,t,r,n){let o={...R(e,n??{}),method:t,url:r};return j(o)}function g(e,t,r,n,o){return y(e,t,r,{...o,body:n??o?.body})}function T(e={}){let t=((r,n)=>y(e,"GET",r,n));return t.get=(r,n)=>y(e,"GET",r,n),t.post=(r,n,o)=>g(e,"POST",r,n,o),t.put=(r,n,o)=>g(e,"PUT",r,n,o),t.patch=(r,n,o)=>g(e,"PATCH",r,n,o),t.delete=(r,n)=>y(e,"DELETE",r,n),t.head=(r,n)=>y(e,"HEAD",r,n),t.options=(r,n)=>y(e,"OPTIONS",r,n),Object.defineProperty(t,"defaults",{value:e,writable:false,enumerable:true}),t.create=r=>T(R(e,r??{})),t}var B=T();var Ee=B;
2
- export{i as DexiXError,c as HTTPError,d as NetworkError,x as ParseError,m as TimeoutError,T as createInstance,Ee as default};//# sourceMappingURL=index.js.map
1
+ var u=class extends Error{request;response;status;headers;url;constructor(t,r,n){super(t),this.name="DexiXError",this.request=r,this.response=n,this.status=n?.status,this.headers=n?.headers,this.url=r.url,Object.setPrototypeOf(this,new.target.prototype);}};var d=class extends u{constructor(t,r){super(`Request failed with status ${r.status} (${r.statusText}) for ${t.url}`,t,r),this.name="HTTPError";}};var l=class extends u{constructor(t,r,n){super(t||"Network request failed",r),this.name="NetworkError",n!==void 0&&(this.cause=n);}};var m=class extends u{timeout;constructor(t,r){super(`Request to ${t.url} timed out after ${r}ms`,t),this.name="TimeoutError",this.timeout=r;}};function k(e){return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function H(e,t){if(!e||k(t))return t;let r=e.endsWith("/")?e.slice(0,-1):e,n=t.startsWith("/")?t:`/${t}`;return `${r}${n}`}function O(e,t){if(!t||Object.keys(t).length===0)return e;let[r,n=""]=e.split("?"),s=new URLSearchParams(n);for(let[o,i]of Object.entries(t))if(i!=null)if(Array.isArray(i))for(let c of i)s.append(o,String(c));else s.append(o,String(i));let a=s.toString();return a?`${r}?${a}`:r}function q(e,t,r){let n=H(e??"",t);return O(n,r)}function R(...e){let t=new Headers;for(let r of e)if(r){if(r instanceof Headers){r.forEach((n,s)=>{t.set(s,n);});continue}if(Array.isArray(r)){for(let[n,s]of r)t.set(n,s);continue}for(let[n,s]of Object.entries(r))s===void 0?t.delete(n):t.set(n,s);}return t}function T(e,t){return {...e,...t,headers:R(e.headers,t.headers),query:{...e.query,...t.query}}}function X(e){if(typeof e!="object"||e===null)return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function A(e){return typeof e=="string"||e instanceof FormData||e instanceof Blob||e instanceof URLSearchParams||e instanceof ArrayBuffer||ArrayBuffer.isView(e)||e instanceof ReadableStream}function I(e){return e==null?{body:void 0}:A(e)?e instanceof FormData?{body:e}:e instanceof URLSearchParams?{body:e,contentType:"application/x-www-form-urlencoded;charset=UTF-8"}:typeof e=="string"?{body:e,contentType:"text/plain;charset=UTF-8"}:{body:e}:X(e)||Array.isArray(e)?{body:JSON.stringify(e),contentType:"application/json;charset=UTF-8"}:{body:JSON.stringify(e),contentType:"application/json;charset=UTF-8"}}var y=class extends u{constructor(t,r,n){super(`Failed to parse response body from ${t.url}`,t,r),this.name="ParseError",n!==void 0&&(this.cause=n);}};var S=new Set([204,205,304]);function v(e){let t=e.headers.get("content-type")??"";return t.includes("application/json")||t.includes("+json")?"json":t.startsWith("text/")?"text":"json"}async function w(e,t,r){if(t.method==="HEAD"||S.has(e.status))return;let n=r??v(e);try{switch(n){case "json":{let s=await e.text();return s.length===0?void 0:JSON.parse(s)}case "text":return await e.text();case "blob":return await e.blob();case "arrayBuffer":return await e.arrayBuffer();case "stream":return e.body;default:return await e.text()}}catch(s){let a={data:void 0,status:e.status,statusText:e.statusText,headers:e.headers,url:e.url||t.url};throw new y(t,a,s)}}function g(e,t){if(!t||t<=0)return {signal:e,cancel:()=>{},didTimeout:()=>false};let r=new AbortController,n=false,s=setTimeout(()=>{n=true,r.abort();},t),a=()=>r.abort();e?.addEventListener("abort",a,{once:true});let o=()=>{clearTimeout(s),e?.removeEventListener("abort",a);};return {signal:r.signal,cancel:o,didTimeout:()=>n}}async function B(e){let{body:t,contentType:r}=I(e.body),n=R(r?{"content-type":r}:void 0,e.headers),s=q(e.baseURL,e.url,e.query),a={url:s,method:e.method,headers:n,body:e.body},{signal:o,cancel:i,didTimeout:c}=g(e.signal,e.timeout),E={method:e.method,headers:n,body:e.method==="GET"||e.method==="HEAD"?void 0:t,signal:o,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrerPolicy:e.referrerPolicy,mode:e.mode},j=new Request(s,E);e.onRequest&&await e.onRequest(j);let p;try{p=await fetch(j);}catch(f){throw i(),f instanceof DOMException&&f.name==="AbortError"?c()?new m(a,e.timeout??0):f:new l(f instanceof Error?f.message:"Network request failed",a,f)}if(i(),e.onResponse&&await e.onResponse(p),!p.ok){let C={data:await w(p,a,e.responseType).catch(()=>{}),status:p.status,statusText:p.statusText,headers:p.headers,url:p.url||s};throw new d(a,C)}return w(p,a,e.responseType)}function U(e){return new Promise(t=>setTimeout(t,e))}function M(e){return Math.min(250*2**e,8e3)}function $(e){return e instanceof d?e.status!==void 0&&(e.status>=500||e.status===429):e instanceof l||e instanceof m}async function P(e){let t=e.retries??0,r=e.retryDelay??M,n=e.retryOn??$;for(let s=0;;s++)try{return await B(e)}catch(a){if(!(s<t&&n(a,s)))throw a;let i=typeof r=="function"?r(s,a):r;i>0&&await U(i);}}var h=class{handlers=[];use(t,r){return this.handlers.push({fulfilled:t,rejected:r}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null);}clear(){this.handlers=[];}list(){return this.handlers.filter(t=>t!==null)}};async function F(e,t){let r=t;for(let n of e.list())try{r=await n.fulfilled(r);}catch(s){if(!n.rejected)throw s;r=await n.rejected(s);}return r}async function N(e,t){let r,n,s=false;try{r=await t;}catch(a){s=true,n=a;}for(let a of e.list()){if(s){if(!a.rejected)continue;try{r=await a.rejected(n),s=!1;}catch(o){n=o;}continue}r=await a.fulfilled(r);}if(s)throw n;return r}function x(e,t,r,n,s){let a={...T(e,s??{}),method:r,url:n},o=(async()=>{let i=await F(t.request,a);return P(i)})();return N(t.response,o)}function D(e,t,r,n,s,a){return x(e,t,r,n,{...a,body:s??a?.body})}function b(e={}){let t=new h,r=new h,n={request:t,response:r},s=((o,i)=>x(e,n,"GET",o,i));return s.get=(o,i)=>x(e,n,"GET",o,i),s.post=(o,i,c)=>D(e,n,"POST",o,i,c),s.put=(o,i,c)=>D(e,n,"PUT",o,i,c),s.patch=(o,i,c)=>D(e,n,"PATCH",o,i,c),s.delete=(o,i)=>x(e,n,"DELETE",o,i),s.head=(o,i)=>x(e,n,"HEAD",o,i),s.options=(o,i)=>x(e,n,"OPTIONS",o,i),Object.defineProperty(s,"defaults",{value:e,writable:false,enumerable:true}),Object.defineProperty(s,"interceptors",{value:{request:{use:(o,i)=>t.use(o,i),eject:o=>t.eject(o),clear:()=>t.clear()},response:{use:(o,i)=>r.use(o,i),eject:o=>r.eject(o),clear:()=>r.clear()}},writable:false,enumerable:true}),s.create=o=>b(T(e,o??{})),s}var L=b();var Se=L;
2
+ export{u as DexiXError,d as HTTPError,l as NetworkError,y as ParseError,m as TimeoutError,b as createInstance,Se as default};//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map