{"version":3,"file":"wretch.all.min.mjs","sources":["../../src/constants.ts","../../src/utils.ts","../../src/config.ts","../../src/resolver.ts","../../src/middleware.ts","../../src/core.ts","../../src/addons/abort.ts","../../src/addons/formData.ts","../../src/addons/formUrl.ts","../../src/addons/perfs.ts","../../src/addons/queryString.ts","../../src/addons/progress.ts","../../src/index.all.ts"],"sourcesContent":["export const JSON_MIME = \"application/json\"\nexport const CONTENT_TYPE_HEADER = \"Content-Type\"\nexport const FETCH_ERROR = Symbol()","import { CONTENT_TYPE_HEADER } from \"./constants.js\"\n\nexport function extractContentType(headers: HeadersInit = {}): string | undefined {\n  return Object.entries(headers).find(([k]) =>\n    k.toLowerCase() === CONTENT_TYPE_HEADER.toLowerCase()\n  )?.[1]\n}\n\nexport function isLikelyJsonMime(value: string): boolean {\n  return /^application\\/.*json.*/.test(value)\n}\n\nexport const mix = function (one: object, two: object, mergeArrays: boolean = false) {\n  return Object.entries(two).reduce((acc, [key, newValue]) => {\n    const value = one[key]\n    if (Array.isArray(value) && Array.isArray(newValue)) {\n      acc[key] = mergeArrays ? [...value, ...newValue] : newValue\n    } else if (typeof value === \"object\" && typeof newValue === \"object\") {\n      acc[key] = mix(value, newValue, mergeArrays)\n    } else {\n      acc[key] = newValue\n    }\n\n    return acc\n  }, { ...one })\n}\n","import { mix } from \"./utils.js\"\nimport type { Config } from \"./types.js\"\n\ndeclare const global\n\nconst config: Config = {\n  // Default options\n  options: {},\n  // Error type\n  errorType: \"text\",\n  // Polyfills\n  polyfills: {\n    // fetch: null,\n    // FormData: null,\n    // URLSearchParams: null,\n    // performance: null,\n    // PerformanceObserver: null,\n    // AbortController: null\n  },\n  polyfill(p: string, doThrow: boolean = true, instance: boolean = false, ...args: any[]) {\n    const res = this.polyfills[p] ||\n      (typeof self !== \"undefined\" ? self[p] : null) ||\n      (typeof global !== \"undefined\" ? global[p] : null)\n    if (doThrow && !res) throw new Error(p + \" is not defined\")\n    return instance && res ? new res(...args) : res\n  }\n}\n\n/**\n * Sets the default fetch options that will be stored internally when instantiating wretch objects.\n *\n * ```js\n * import wretch from \"wretch\"\n *\n * wretch.options({ headers: { \"Accept\": \"application/json\" } });\n *\n * // The fetch request is sent with both headers.\n * wretch(\"...\", { headers: { \"X-Custom\": \"Header\" } }).get().res();\n * ```\n *\n * @param options Default options\n * @param replace If true, completely replaces the existing options instead of mixing in\n */\nexport function setOptions(options: object, replace = false) {\n  config.options = replace ? options : mix(config.options, options)\n}\n\n/**\n * Sets the default polyfills that will be stored internally when instantiating wretch objects.\n * Useful for browserless environments like `node.js`.\n *\n * Needed for libraries like [fetch-ponyfill](https://github.com/qubyte/fetch-ponyfill).\n *\n * ```js\n * import wretch from \"wretch\"\n *\n * wretch.polyfills({\n *   fetch: require(\"node-fetch\"),\n *   FormData: require(\"form-data\"),\n *   URLSearchParams: require(\"url\").URLSearchParams,\n * });\n *\n * // Uses the above polyfills.\n * wretch(\"...\").get().res();\n * ```\n *\n * @param polyfills An object containing the polyfills\n * @param replace If true, replaces the current polyfills instead of mixing in\n */\nexport function setPolyfills(polyfills: object, replace = false) {\n  config.polyfills = replace ? polyfills : mix(config.polyfills, polyfills)\n}\n\n/**\n * Sets the default method (text, json, …) used to parse the data contained in the response body in case of an HTTP error.\n * As with other static methods, it will affect wretch instances created after calling this function.\n *\n * ```js\n * import wretch from \"wretch\"\n *\n * wretch.errorType(\"json\")\n *\n * wretch(\"http://server/which/returns/an/error/with/a/json/body\")\n *   .get()\n *   .res()\n *   .catch(error => {\n *     // error[errorType] (here, json) contains the parsed body\n *     console.log(error.json)\n *   })\n * ```\n *\n * If null, defaults to \"text\".\n */\nexport function setErrorType(errorType: string) {\n  config.errorType = errorType\n}\n\nexport default config\n","import { middlewareHelper } from \"./middleware.js\"\nimport { mix } from \"./utils.js\"\nimport type { Wretch, WretchResponse, WretchResponseChain, WretchError as WretchErrorType } from \"./types.js\"\nimport { FETCH_ERROR } from \"./constants.js\"\n\n/**\n * This class inheriting from Error is thrown when the fetch response is not \"ok\".\n * It extends Error and adds status, text and body fields.\n */\nexport class WretchError extends Error implements WretchErrorType {\n  status: number\n  response: WretchResponse\n  text?: string\n  json?: any\n}\n\nexport const resolver = <T, Chain, R>(wretch: T & Wretch<T, Chain, R>) => {\n  const {\n    _url: url,\n    _options: opts,\n    _config: config,\n    _catchers: _catchers,\n    _resolvers: resolvers,\n    _middlewares: middlewares,\n    _addons: addons\n  } = wretch\n\n  const catchers = new Map(_catchers)\n  const finalOptions = mix(config.options, opts)\n  addons.forEach(addon => addon.beforeRequest && addon.beforeRequest(wretch, finalOptions))\n  // The generated fetch request\n  const _fetchReq = middlewareHelper(middlewares)(config.polyfill(\"fetch\"))(url, finalOptions)\n  // Throws on an http error\n  const referenceError = new Error()\n  const throwingPromise: Promise<void | WretchResponse> = _fetchReq\n    .catch(error => {\n      throw { __wrap: error }\n    })\n    .then(response => {\n      if (!response.ok) {\n        const err = new WretchError()\n        // Enhance the error object\n        err[\"cause\"] = referenceError\n        err.stack = err.stack + \"\\nCAUSE: \" + referenceError.stack\n        err.response = response\n        if (response.type === \"opaque\") {\n          throw err\n        }\n        return response[config.errorType]().then((body: string) => {\n          err.message = body\n          err[config.errorType] = body\n          err[\"status\"] = response.status\n          throw err\n        })\n      }\n      return response\n    })\n  // Wraps the Promise in order to dispatch the error to a matching catcher\n  const catchersWrapper = <T>(promise: Promise<T>): Promise<void | T> => {\n    return promise.catch(err => {\n      const error = err.__wrap || err\n\n      const catcher =\n        err.__wrap && catchers.has(FETCH_ERROR) ? catchers.get(FETCH_ERROR) :\n          (catchers.get(error.status) || catchers.get(error.name))\n\n      if (catcher)\n        return catcher(error, wretch)\n\n      throw error\n    })\n  }\n  // Enforces the proper promise type when a body parsing method is called.\n  type BodyParser = <Type>(funName: string | null) => <Result = void>(cb?: (type: Type) => Result) => Promise<Awaited<Result>>\n  const bodyParser: BodyParser = funName => cb => funName ?\n    // If a callback is provided, then callback with the body result otherwise return the parsed body itself.\n    catchersWrapper(throwingPromise.then(_ => _ && _[funName]()).then(_ => cb ? cb(_) : _)) :\n    // No body parsing method - return the response\n    catchersWrapper(throwingPromise.then(_ => cb ? cb(_ as any) : _))\n\n  const responseChain: WretchResponseChain<T, Chain, R> = {\n    _wretchReq: wretch,\n    _fetchReq,\n    res: bodyParser<WretchResponse>(null),\n    json: bodyParser<any>(\"json\"),\n    blob: bodyParser<Blob>(\"blob\"),\n    formData: bodyParser<FormData>(\"formData\"),\n    arrayBuffer: bodyParser<ArrayBuffer>(\"arrayBuffer\"),\n    text: bodyParser<string>(\"text\"),\n    error(errorId, cb) {\n      catchers.set(errorId, cb)\n      return this\n    },\n    badRequest(cb) { return this.error(400, cb) },\n    unauthorized(cb) { return this.error(401, cb) },\n    forbidden(cb) { return this.error(403, cb) },\n    notFound(cb) { return this.error(404, cb) },\n    timeout(cb) { return this.error(408, cb) },\n    internalError(cb) { return this.error(500, cb) },\n    fetchError(cb) { return this.error(FETCH_ERROR, cb) },\n  }\n\n  const enhancedResponseChain: R extends undefined ? Chain & WretchResponseChain<T, Chain, undefined> : R = addons.reduce((chain, addon) => ({\n    ...chain,\n    ...(addon.resolver as any)\n  }), responseChain)\n\n  return resolvers.reduce((chain, r) => r(chain, wretch), enhancedResponseChain)\n}\n","import type { ConfiguredMiddleware, FetchLike } from \"./types.js\"\n\n/**\n * @private @internal\n */\nexport const middlewareHelper = (middlewares: ConfiguredMiddleware[]) => (fetchFunction: FetchLike): FetchLike => {\n  return middlewares.reduceRight((acc, curr) => curr(acc), fetchFunction) || fetchFunction\n}\n","import { mix, extractContentType, isLikelyJsonMime } from \"./utils.js\"\nimport { JSON_MIME, CONTENT_TYPE_HEADER } from \"./constants.js\"\nimport { resolver } from \"./resolver.js\"\nimport config from \"./config.js\"\nimport type { Wretch } from \"./types.js\"\n\nexport const core: Wretch = {\n  _url: \"\",\n  _options: {},\n  _config: config,\n  _catchers: new Map(),\n  _resolvers: [],\n  _deferred: [],\n  _middlewares: [],\n  _addons: [],\n  addon(addon) {\n    return { ...this, _addons: [...this._addons, addon], ...addon.wretch }\n  },\n  errorType(errorType: string) {\n    return {\n      ...this,\n      _config: {\n        ...this._config,\n        errorType\n      }\n    }\n  },\n  polyfills(polyfills, replace = false) {\n    return {\n      ...this,\n      _config: {\n        ...this._config,\n        polyfills: replace ? polyfills : mix(this._config.polyfills, polyfills)\n      }\n    }\n  },\n  url(_url, replace = false) {\n    if (replace)\n      return { ...this, _url }\n    const split = this._url.split(\"?\")\n    return {\n      ...this,\n      _url: split.length > 1 ?\n        split[0] + _url + \"?\" + split[1] :\n        this._url + _url\n    }\n  },\n  options(options, replace = false) {\n    return { ...this, _options: replace ? options : mix(this._options, options) }\n  },\n  headers(headerValues) {\n    return { ...this, _options: mix(this._options, { headers: headerValues || {} }) }\n  },\n  accept(headerValue) {\n    return this.headers({ Accept: headerValue })\n  },\n  content(headerValue) {\n    return this.headers({ [CONTENT_TYPE_HEADER]: headerValue })\n  },\n  auth(headerValue) {\n    return this.headers({ Authorization: headerValue })\n  },\n  catcher(errorId, catcher) {\n    const newMap = new Map(this._catchers)\n    newMap.set(errorId, catcher)\n    return { ...this, _catchers: newMap }\n  },\n  resolve<R = unknown>(resolver, clear: boolean = false) {\n    return { ...this, _resolvers: clear ? [resolver] : [...this._resolvers, resolver] }\n  },\n  defer(callback, clear: boolean = false) {\n    return {\n      ...this,\n      _deferred: clear ? [callback] : [...this._deferred, callback]\n    }\n  },\n  middlewares(middlewares, clear = false) {\n    return {\n      ...this,\n      _middlewares: clear ? middlewares : [...this._middlewares, ...middlewares]\n    }\n  },\n  fetch(method: string = this._options.method, url = \"\", body = null) {\n    let base = this.url(url).options({ method })\n    // \"Jsonify\" the body if it is an object and if it is likely that the content type targets json.\n    const contentType = extractContentType(base._options.headers)\n    const jsonify = typeof body === \"object\" && (!base._options.headers || !contentType || isLikelyJsonMime(contentType))\n    base =\n      !body ? base :\n        jsonify ? base.json(body, contentType) :\n          base.body(body)\n    return resolver(\n      base\n        ._deferred\n        .reduce((acc: Wretch, curr) => curr(acc, acc._url, acc._options), base)\n    )\n  },\n  get(url = \"\") {\n    return this.fetch(\"GET\", url)\n  },\n  delete(url = \"\") {\n    return this.fetch(\"DELETE\", url)\n  },\n  put(body, url = \"\") {\n    return this.fetch(\"PUT\", url, body)\n  },\n  post(body, url = \"\") {\n    return this.fetch(\"POST\", url, body)\n  },\n  patch(body, url = \"\") {\n    return this.fetch(\"PATCH\", url, body)\n  },\n  head(url = \"\") {\n    return this.fetch(\"HEAD\", url)\n  },\n  opts(url = \"\") {\n    return this.fetch(\"OPTIONS\", url)\n  },\n  body(contents) {\n    return { ...this, _options: { ...this._options, body: contents } }\n  },\n  json(jsObject, contentType) {\n    const currentContentType = extractContentType(this._options.headers)\n    return this.content(\n      contentType ||\n      isLikelyJsonMime(currentContentType) && currentContentType ||\n      JSON_MIME\n    ).body(JSON.stringify(jsObject))\n  }\n}\n","import type { Wretch, WretchAddon, WretchErrorCallback, WretchResponseChain } from \"../types.js\"\n\nexport interface AbortWretch {\n  /**\n   * Associates a custom controller with the request.\n   *\n   * Useful when you need to use\n   * your own AbortController, otherwise wretch will create a new controller itself.\n   *\n   * ```js\n   * const controller = new AbortController()\n   *\n   * // Associates the same controller with multiple requests\n   * wretch(\"url1\")\n   *   .addon(AbortAddon())\n   *   .signal(controller)\n   *   .get()\n   *   .json()\n   * wretch(\"url2\")\n   *   .addon(AbortAddon())\n   *   .signal(controller)\n   *   .get()\n   *   .json()\n   *\n   * // Aborts both requests\n   * controller.abort()\n   * ```\n   *\n   * @param controller - An instance of AbortController\n   */\n  signal: <T extends AbortWretch, C, R>(this: T & Wretch<T, C, R>, controller: AbortController) => this\n}\n\nexport interface AbortResolver {\n  /**\n   * Aborts the request after a fixed time.\n   *\n   * If you use a custom AbortController associated with the request, pass it as the second argument.\n   *\n   * ```js\n   * // 1 second timeout\n   * wretch(\"...\").addon(AbortAddon()).get().setTimeout(1000).json(_ =>\n   *   // will not be called if the request timeouts\n   * )\n   * ```\n   *\n   * @param time - Time in milliseconds\n   * @param controller - An instance of AbortController\n   */\n  setTimeout: <T, C extends AbortResolver, R>(this: C & WretchResponseChain<T, C, R>, time: number, controller?: AbortController) => this\n  /**\n   * Returns the provided or generated AbortController plus the wretch response chain as a pair.\n   *\n   * ```js\n   * // We need the controller outside the chain\n   * const [c, w] = wretch(\"url\")\n   *   .addon(AbortAddon())\n   *   .get()\n   *   .controller()\n   *\n   * // Resume with the chain\n   * w.onAbort(_ => console.log(\"ouch\")).json()\n   *\n   * // Later on…\n   * c.abort()\n   * ```\n   */\n  controller: <T, C extends AbortResolver, R>(this: C & WretchResponseChain<T, C, R>) => [any, this]\n  /**\n   * Catches an AbortError and performs a callback.\n   */\n  onAbort: <T, C extends AbortResolver, R>(this: C & WretchResponseChain<T, C, R>, cb: WretchErrorCallback<T, C, R>) => this\n}\n\n/**\n * Adds the ability to abort requests using AbortController and signals under the hood.\n *\n *\n * _Only compatible with browsers that support\n * [AbortControllers](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).\n * Otherwise, you could use a (partial)\n * [polyfill](https://www.npmjs.com/package/abortcontroller-polyfill)._\n *\n * ```js\n * import AbortAddon from \"wretch/addons/abort\"\n *\n * const [c, w] = wretch(\"...\")\n *   .addon(AbortAddon())\n *   .get()\n *   .onAbort((_) => console.log(\"Aborted !\"))\n *   .controller();\n *\n * w.text((_) => console.log(\"should never be called\"));\n * c.abort();\n *\n * // Or :\n *\n * const controller = new AbortController();\n *\n * wretch(\"...\")\n *   .addon(AbortAddon())\n *   .signal(controller)\n *   .get()\n *   .onAbort((_) => console.log(\"Aborted !\"))\n *   .text((_) => console.log(\"should never be called\"));\n *\n * controller.abort();\n * ```\n */\nconst abort: () => WretchAddon<AbortWretch, AbortResolver> = () => {\n  let timeout = null\n  let fetchController = null\n  return {\n    beforeRequest(wretch, options) {\n      fetchController = wretch._config.polyfill(\"AbortController\", false, true)\n      if (!options[\"signal\"] && fetchController) {\n        options[\"signal\"] = fetchController.signal\n      }\n      timeout = {\n        ref: null,\n        clear() {\n          if (timeout.ref) {\n            clearTimeout(timeout.ref)\n            timeout.ref = null\n          }\n        }\n      }\n    },\n    wretch: {\n      signal(controller) {\n        return { ...this, _options: { ...this._options, signal: controller.signal } }\n      },\n    },\n    resolver: {\n      setTimeout(time, controller = fetchController) {\n        timeout.clear()\n        timeout.ref = setTimeout(() => controller.abort(), time)\n        return this\n      },\n      controller() { return [fetchController, this] },\n      onAbort(cb) { return this.error(\"AbortError\", cb) }\n    },\n  }\n}\n\nexport default abort\n","import type { Wretch, Config, WretchAddon } from \"../types.js\"\n\nfunction convertFormData(\n  formObject: object,\n  recursive: string[] | boolean = false,\n  config: Config,\n  formData = config.polyfill(\"FormData\", true, true),\n  ancestors = [],\n) {\n  Object.entries(formObject).forEach(([key, value]) => {\n    let formKey = ancestors.reduce((acc, ancestor) => (\n      acc ? `${acc}[${ancestor}]` : ancestor\n    ), null)\n    formKey = formKey ? `${formKey}[${key}]` : key\n    if (value instanceof Array) {\n      for (const item of value)\n        formData.append(formKey, item)\n    } else if (\n      recursive &&\n      typeof value === \"object\" &&\n      (\n        !(recursive instanceof Array) ||\n        !recursive.includes(key)\n      )\n    ) {\n      if (value !== null) {\n        convertFormData(value, recursive, config, formData, [...ancestors, key])\n      }\n    } else {\n      formData.append(formKey, value)\n    }\n  })\n\n  return formData\n}\n\nexport interface FormDataAddon {\n  /**\n   * Converts the javascript object to a FormData and sets the request body.\n   *\n   * ```js\n   * const form = {\n   *   hello: \"world\",\n   *   duck: \"Muscovy\",\n   * };\n   *\n   * wretch(\"...\").addons(FormDataAddon).formData(form).post();\n   * ```\n   *\n   * The `recursive` argument when set to `true` will enable recursion through all\n   * nested objects and produce `object[key]` keys. It can be set to an array of\n   * string to exclude specific keys.\n   *\n   * > Warning: Be careful to exclude `Blob` instances in the Browser, and\n   * > `ReadableStream` and `Buffer` instances when using the node.js compatible\n   * > `form-data` package.\n   *\n   * ```js\n   * const form = {\n   *   duck: \"Muscovy\",\n   *   duckProperties: {\n   *     beak: {\n   *       color: \"yellow\",\n   *     },\n   *     legs: 2,\n   *   },\n   *   ignored: {\n   *     key: 0,\n   *   },\n   * };\n   *\n   * // Will append the following keys to the FormData payload:\n   * // \"duck\", \"duckProperties[beak][color]\", \"duckProperties[legs]\"\n   * wretch(\"...\").addons(FormDataAddon).formData(form, [\"ignored\"]).post();\n   * ```\n   *\n   * @param formObject - An object which will be converted to a FormData\n   * @param recursive - If `true`, will recurse through all nested objects. Can be set as an array of string to exclude specific keys.\n   */\n  formData<T extends FormDataAddon, C, R>(this: T & Wretch<T, C, R>, formObject: object, recursive?: string[] | boolean): this\n}\n\n/**\n * Adds the ability to convert a an object to a FormData and use it as a request body.\n *\n * ```js\n * import FormDataAddon from \"wretch/addons/formData\"\n *\n * wretch().addon(FormDataAddon)\n * ```\n */\nconst formData: WretchAddon<FormDataAddon> = {\n  wretch: {\n    formData(formObject, recursive = false) {\n      return this.body(convertFormData(formObject, recursive, this._config))\n    }\n  }\n}\n\nexport default formData\n","import type { Wretch, WretchAddon } from \"../types.js\"\n\nfunction encodeQueryValue(key: string, value: unknown) {\n  return encodeURIComponent(key) +\n    \"=\" +\n    encodeURIComponent(\n      typeof value === \"object\" ?\n        JSON.stringify(value) :\n        \"\" + value\n    )\n}\nfunction convertFormUrl(formObject: object) {\n  return Object.keys(formObject)\n    .map(key => {\n      const value = formObject[key]\n      if (value instanceof Array) {\n        return value.map(v => encodeQueryValue(key, v)).join(\"&\")\n      }\n      return encodeQueryValue(key, value)\n    })\n    .join(\"&\")\n}\n\nexport interface FormUrlAddon {\n  /**\n   * Converts the input parameter to an url encoded string and sets the content-type\n   * header and body. If the input argument is already a string, skips the conversion\n   * part.\n   *\n   * ```js\n   * const form = { a: 1, b: { c: 2 } };\n   * const alreadyEncodedForm = \"a=1&b=%7B%22c%22%3A2%7D\";\n   *\n   * // Automatically sets the content-type header to \"application/x-www-form-urlencoded\"\n   * wretch(\"...\").addon(FormUrlAddon).formUrl(form).post();\n   * wretch(\"...\").addon(FormUrlAddon).formUrl(alreadyEncodedForm).post();\n   * ```\n   *\n   * @param input - An object to convert into an url encoded string or an already encoded string\n   */\n  formUrl<T extends FormUrlAddon, C, R>(this: T & Wretch<T, C, R>, input: (object | string)): this\n}\n\n/**\n * Adds the ability to convert a an object to a FormUrl and use it as a request body.\n *\n * ```js\n * import FormUrlAddon from \"wretch/addons/formUrl\"\n *\n * wretch().addon(FormUrlAddon)\n * ```\n */\nconst formUrl: WretchAddon<FormUrlAddon> = {\n  wretch: {\n    formUrl(input) {\n      return this\n        .body(typeof input === \"string\" ? input : convertFormUrl(input))\n        .content(\"application/x-www-form-urlencoded\")\n    }\n  }\n}\n\nexport default formUrl\n","import type { WretchResponseChain, WretchAddon } from \"../types.js\"\n\nconst onMatch = (entries, name, callback, _performance) => {\n  if (!entries.getEntriesByName)\n    return false\n  const matches = entries.getEntriesByName(name)\n  if (matches && matches.length > 0) {\n    callback(matches.reverse()[0])\n    if (_performance.clearMeasures)\n      _performance.clearMeasures(name)\n    utils.callbacks.delete(name)\n\n    if (utils.callbacks.size < 1) {\n      utils.observer.disconnect()\n      if (_performance.clearResourceTimings) {\n        _performance.clearResourceTimings()\n      }\n    }\n    return true\n  }\n  return false\n}\n\nconst lazyObserver = (_performance, _observer) => {\n  if (!utils.observer && _performance && _observer) {\n    utils.observer = new _observer(entries => {\n      utils.callbacks.forEach((callback, name) => {\n        onMatch(entries, name, callback, _performance)\n      })\n    })\n    if (_performance.clearResourceTimings)\n      _performance.clearResourceTimings()\n  }\n  return utils.observer\n}\n\nconst utils = {\n  callbacks: new Map(),\n  observer: null,\n  observe: (name, callback, config) => {\n    if (!name || !callback)\n      return\n\n    const _performance = config.polyfill(\"performance\", false)\n    const _observer = config.polyfill(\"PerformanceObserver\", false)\n\n    if (!lazyObserver(_performance, _observer))\n      return\n\n    if (!onMatch(_performance, name, callback, _performance)) {\n      if (utils.callbacks.size < 1)\n        utils.observer.observe({ entryTypes: [\"resource\", \"measure\"] })\n      utils.callbacks.set(name, callback)\n    }\n\n  }\n}\n\nexport interface PerfsAddon {\n  /**\n   * Performs a callback on the API performance timings of the request.\n   *\n   * Warning: Still experimental on browsers and node.js\n   */\n  perfs: <T, C extends PerfsAddon, R>(this: C & WretchResponseChain<T, C, R>, cb?: (timing: any) => void) => this,\n}\n\n/**\n * Adds the ability to measure requests using the Performance Timings API.\n *\n * Uses the Performance API\n * ([browsers](https://developer.mozilla.org/en-US/docs/Web/API/Performance_API) &\n * [node.js](https://nodejs.org/api/perf_hooks.html)) to expose timings related to\n * the underlying request.\n *\n * Browser timings are very accurate, node.js only contains raw measures.\n *\n * ```js\n * import PerfsAddon from \"wretch/addons/perfs\"\n *\n * // Use perfs() before the response types (text, json, ...)\n * wretch(\"...\")\n *   .addon(PerfsAddon())\n *   .get()\n *   .perfs((timings) => {\n *     // Will be called when the timings are ready.\n * console.log(timings.startTime);\n *   })\n *   .res();\n *\n * ```\n *\n * For node.js, there is a little extra work to do :\n *\n * ```js\n * // Node.js only\n * const { performance, PerformanceObserver } = require(\"perf_hooks\");\n *\n * wretch.polyfills({\n *   fetch: function (url, opts) {\n *     performance.mark(url + \" - begin\");\n *     return fetch(url, opts).then(res => {\n *       performance.mark(url + \" - end\");\n *       setTimeout(() => performance.measure(res.url, url + \" - begin\", url + \" - end\"), 0);\n *       return res;\n *     });\n *   },\n *   // other polyfills…\n *   performance: performance,\n *   PerformanceObserver: PerformanceObserver,\n * });\n * ```\n */\nconst perfs: () => WretchAddon<unknown, PerfsAddon> = () => ({\n  resolver: {\n    perfs(cb) {\n      this._fetchReq.then(res => utils.observe(res.url, cb, this._wretchReq._config)).catch(() => {/* swallow */ })\n      return this\n    },\n  }\n})\n\nexport default perfs\n","import type { Wretch, Config, WretchAddon } from \"../types.js\"\n\nfunction stringify(value?: string | null): string | null {\n  return typeof value !== \"undefined\" ? value : \"\"\n}\n\nconst appendQueryParams = (url: string, qp: object | string, replace: boolean, config: Config) => {\n  let queryString: string\n\n  if (typeof qp === \"string\") {\n    queryString = qp\n  } else {\n    const usp = config.polyfill(\"URLSearchParams\", true, true)\n    for (const key in qp) {\n      const value = qp[key]\n      if (qp[key] instanceof Array) {\n        for (const val of value)\n          usp.append(key, stringify(val))\n      } else {\n        usp.append(key, stringify(value))\n      }\n    }\n    queryString = usp.toString()\n  }\n\n  const split = url.split(\"?\")\n\n  if (!queryString)\n    return replace ? split[0] : url\n\n  if (replace || split.length < 2)\n    return split[0] + \"?\" + queryString\n\n  return url + \"&\" + queryString\n}\n\nexport interface QueryStringAddon {\n  /**\n   * Converts a javascript object to query parameters, then appends this query string\n   * to the current url. String values are used as the query string verbatim.\n   *\n   * Pass `true` as the second argument to replace existing query parameters.\n   *\n   * ```\n   * import QueryAddon from \"wretch/addons/queryString\"\n   *\n   * let w = wretch(\"http://example.com\").addon(QueryStringAddon);\n   * // url is http://example.com\n   * w = w.query({ a: 1, b: 2 });\n   * // url is now http://example.com?a=1&b=2\n   * w = w.query({ c: 3, d: [4, 5] });\n   * // url is now http://example.com?a=1&b=2c=3&d=4&d=5\n   * w = w.query(\"five&six&seven=eight\");\n   * // url is now http://example.com?a=1&b=2c=3&d=4&d=5&five&six&seven=eight\n   * w = w.query({ reset: true }, true);\n   * // url is now  http://example.com?reset=true\n   * ```\n   *\n   * ##### **Note that .query is not meant to handle complex cases with nested objects.**\n   *\n   * For this kind of usage, you can use `wretch` in conjunction with other libraries\n   * (like [`qs`](https://github.com/ljharb/qs)).\n   *\n   * ```js\n   * // Using wretch with qs\n   *\n   * const queryObject = { some: { nested: \"objects\" } };\n   * const w = wretch(\"https://example.com/\").addon(QueryStringAddon)\n   *\n   * // Use .qs inside .query :\n   *\n   * w.query(qs.stringify(queryObject));\n   *\n   * // Use .defer :\n   *\n   * const qsWretch = w.defer((w, url, { qsQuery, qsOptions }) => (\n   *   qsQuery ? w.query(qs.stringify(qsQuery, qsOptions)) : w\n   * ));\n   *\n   * qsWretch\n   *   .url(\"https://example.com/\")\n   *   .options({ qs: { query: queryObject } });\n   * ```\n   *\n   * @param qp - An object which will be converted, or a string which will be used verbatim.\n   */\n  query<T extends QueryStringAddon, C, R>(this: T & Wretch<T, C, R>, qp: object | string, replace?: boolean): this\n}\n\n/**\n * Adds the ability to append query parameters from a javascript object.\n *\n * ```js\n * import QueryAddon from \"wretch/addons/queryString\"\n *\n * wretch().addon(QueryAddon)\n * ```\n */\nconst queryString: WretchAddon<QueryStringAddon> = {\n  wretch: {\n    query(qp, replace = false) {\n      return { ...this, _url: appendQueryParams(this._url, qp, replace, this._config) }\n    }\n  }\n}\n\nexport default queryString\n","import type { ConfiguredMiddleware, WretchAddon, WretchResponseChain } from \"../types.js\"\n\nexport interface ProgressResolver {\n  /**\n   * Provides a way to register a callback to be invoked one or multiple times during the download.\n   * The callback receives the current progress as two arguments, the number of bytes loaded and the total number of bytes to load.\n   *\n   * _Under the hood: this method adds a middleware to the chain that will intercept the response and replace the body with a new one that will emit the progress event._\n   *\n   * ```js\n   * import ProgressAddon from \"wretch/addons/progress\"\n   *\n   * wretch(\"some_url\")\n   *   // Register the addon\n   *   .addon(ProgressAddon())\n   *   .get()\n   *   // Log the progress as a percentage of completion\n   *   .progress((loaded, total) => console.log(`${(loaded / total * 100).toFixed(0)}%`))\n   * ```\n   *\n   * @param onProgress - A callback that will be called one or multiple times with the number of bytes loaded and the total number of bytes to load.\n   */\n  progress: <T, C extends ProgressResolver, R>(\n    this: C & WretchResponseChain<T, C, R>,\n    onProgress: (loaded: number, total: number) => void\n  ) => this\n}\n\n/**\n * Adds the ability to monitor progress when downloading a response.\n *\n * _Compatible with all platforms implementing the [TransformStream WebAPI](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream#browser_compatibility)._\n *\n * ```js\n * import ProgressAddon from \"wretch/addons/progress\"\n *\n * wretch(\"some_url\")\n *   // Register the addon\n *   .addon(ProgressAddon())\n *   .get()\n *   // Log the progress as a percentage of completion\n *   .progress((loaded, total) => console.log(`${(loaded / total * 100).toFixed(0)}%`))\n * ```\n */\nconst progress: () => WretchAddon<unknown, ProgressResolver> = () => {\n  const cb = {\n    ref: null\n  }\n\n  const transformMiddleware: ConfiguredMiddleware = next => (url, opts) => {\n    let loaded = 0\n    let total = 0\n    return next(url, opts).then(response => {\n      try {\n        const contentLength = response.headers.get(\"content-length\")\n        total = contentLength ? +contentLength : null\n        const transform = new TransformStream({\n          transform(chunk, controller) {\n            loaded += chunk.length\n            if (total < loaded) {\n              total = loaded\n            }\n            if (cb.ref) {\n              cb.ref(loaded, total)\n            }\n            controller.enqueue(chunk)\n          }\n        })\n        return new Response(response.body.pipeThrough(transform), response)\n      } catch (e) {\n        return response\n      }\n    })\n  }\n\n  return {\n    beforeRequest(wretch) {\n      return wretch._middlewares.push(transformMiddleware)\n    },\n    resolver: {\n      progress(onProgress: (loaded: number, total: number) => void) {\n        cb.ref = onProgress\n        return this\n      }\n    },\n  }\n}\n\nexport default progress\n","import { setOptions, setErrorType, setPolyfills } from \"./config.js\"\nimport { core } from \"./core.js\"\nimport * as Addons from \"./addons/index.js\"\nimport { WretchError } from \"./resolver.js\"\n\nfunction factory(_url = \"\", _options = {}) {\n  return { ...core, _url, _options }\n    .addon(Addons.abortAddon())\n    .addon(Addons.formDataAddon)\n    .addon(Addons.formUrlAddon)\n    .addon(Addons.perfsAddon())\n    .addon(Addons.queryStringAddon)\n    .addon(Addons.progressAddon())\n}\n\nfactory[\"default\"] = factory\nfactory.options = setOptions\nfactory.errorType = setErrorType\nfactory.polyfills = setPolyfills\nfactory.WretchError = WretchError\n\nexport default factory\n"],"names":["FETCH_ERROR","Symbol","extractContentType","headers","_a","Object","entries","find","k","toLowerCase","isLikelyJsonMime","value","test","mix","one","two","mergeArrays","reduce","acc","key","newValue","Array","isArray","config","options","errorType","polyfills","polyfill","p","doThrow","instance","args","res","this","self","global","Error","WretchError","resolver","wretch","_url","url","_options","opts","_config","_catchers","_resolvers","resolvers","_middlewares","middlewares","_addons","addons","catchers","Map","finalOptions","forEach","addon","beforeRequest","_fetchReq","fetchFunction","reduceRight","curr","middlewareHelper","referenceError","throwingPromise","catch","error","__wrap","then","response","ok","err","stack","type","body","message","status","bodyParser","funName","cb","_","catcher","has","get","name","responseChain","_wretchReq","json","blob","formData","arrayBuffer","text","errorId","set","badRequest","unauthorized","forbidden","notFound","timeout","internalError","fetchError","enhancedResponseChain","chain","r","core","_deferred","replace","split","length","headerValues","accept","headerValue","Accept","content","auth","Authorization","newMap","resolve","clear","defer","callback","fetch","method","base","contentType","jsonify","delete","put","post","patch","head","contents","jsObject","currentContentType","JSON","stringify","abort","fetchController","signal","ref","clearTimeout","controller","setTimeout","time","onAbort","convertFormData","formObject","recursive","ancestors","formKey","ancestor","item","append","includes","encodeQueryValue","encodeURIComponent","formUrl","input","keys","map","v","join","onMatch","_performance","getEntriesByName","matches","reverse","clearMeasures","utils","callbacks","size","observer","disconnect","clearResourceTimings","observe","_observer","lazyObserver","entryTypes","perfs","appendQueryParams","qp","queryString","usp","val","toString","query","progress","transformMiddleware","next","loaded","total","contentLength","transform","TransformStream","chunk","enqueue","Response","pipeThrough","e","push","onProgress","factory","Addons.abortAddon","Addons.formDataAddon","Addons.formUrlAddon","Addons.perfsAddon","Addons.queryStringAddon","Addons.progressAddon"],"mappings":"AAAO,MAEMA,EAAcC,SCAX,SAAAC,EAAmBC,EAAuB,UACxD,OAEI,QAFGC,EAAAC,OAAOC,QAAQH,GAASI,MAAK,EAAEC,KACpCA,EAAEC,gBDH6B,eCGSA,uBACtC,IAAAL,OAAA,EAAAA,EAAA,EACN,CAEM,SAAUM,EAAiBC,GAC/B,MAAO,yBAAyBC,KAAKD,EACvC,CAEO,MAAME,EAAM,SAAUC,EAAaC,EAAaC,EAAuB,GAC5E,OAAOX,OAAOC,QAAQS,GAAKE,QAAO,CAACC,GAAMC,EAAKC,MAC5C,MAAMT,EAAQG,EAAIK,GASlB,OARIE,MAAMC,QAAQX,IAAUU,MAAMC,QAAQF,GACxCF,EAAIC,GAAOH,EAAc,IAAIL,KAAUS,GAAYA,EAEnDF,EAAIC,G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