{"version":3,"file":"fetch.mjs","names":["undiciFetch"],"sources":["../src/fetch.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n                       ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website:                  https://stormsoftware.com\n Repository:               https://github.com/storm-software/stryke\n Documentation:            https://docs.stormsoftware.com/projects/stryke\n Contact:                  https://stormsoftware.com/contact\n\n SPDX-License-Identifier:  Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isValidURL } from \"@stryke/url/helpers\";\nimport { defu } from \"defu\";\nimport type { RequestInfo } from \"undici\";\nimport { fetch as undiciFetch } from \"undici\";\nimport { getProxyAgent } from \"./proxy-agent\";\n\nexport type FetchRequestOptions = RequestInit & {\n  /**\n   * Timeout in milliseconds\n   *\n   * @defaultValue 5000\n   */\n  timeout?: number;\n};\n\n/**\n * Fetches a resource from a URL.\n *\n * @param input - The URL to fetch.\n * @param options - Additional fetch options.\n * @returns The fetched response.\n */\nexport async function fetchRequest(\n  input: RequestInfo,\n  options: FetchRequestOptions = {}\n) {\n  if (isSetString(input) && !isValidURL(input)) {\n    throw new Error(`Invalid URL format provided: ${input}`);\n  }\n\n  const abort = new AbortController();\n  setTimeout(() => abort.abort(), options.timeout ?? 5000);\n\n  return undiciFetch(\n    input,\n    defu(options, {\n      agent: getProxyAgent(),\n      signal: abort.signal,\n      headers: {\n        // The file format is based off of the user agent, make sure woff2 files are fetched\n        \"User-Agent\":\n          \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) \" +\n          \"AppleWebKit/537.36 (KHTML, like Gecko) \" +\n          \"Chrome/104.0.0.0 Safari/537.36\"\n      }\n    })\n  );\n}\n\nexport const fetch = fetchRequest;\n"],"mappings":";;;;;;;;;;;;;;AAyCA,eAAsB,aACpB,OACA,UAA+B,EAAE,EACjC;AACA,KAAI,YAAY,MAAM,IAAI,CAAC,WAAW,MAAM,CAC1C,OAAM,IAAI,MAAM,gCAAgC,QAAQ;CAG1D,MAAM,QAAQ,IAAI,iBAAiB;AACnC,kBAAiB,MAAM,OAAO,EAAE,QAAQ,WAAW,IAAK;AAExD,QAAOA,QACL,OACA,KAAK,SAAS;EACZ,OAAO,eAAe;EACtB,QAAQ,MAAM;EACd,SAAS,EAEP,cACE,yHAGH;EACF,CAAC,CACH;;AAGH,MAAa,QAAQ"}