{"version":3,"sources":["jsdelivr-header.js","/npm/@toruslabs/http-helpers@9.0.0/dist/lib.esm/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCNO,kBAAmB,8CACnB,UAAW,mBACX,UAAY,WAAc,WAEjC,MAAM,IAAM,SAAS,UAAU,gBAC/B,IAAI,SAAS,OAAO,MAIpB,IAAI,OAAS,gBACT,UAAY,GAGhB,MAAM,kBAAoB,YACpB,uBAAyB,eAC/B,IAAI,OAAS,KACb,MAAM,eAAiB,GACjB,aAAe,GACrB,SAAS,oBAAoB,EAAS,EAAiB,GACrD,OAAS,EACT,eAAe,QAAQ,GACvB,aAAa,QAAQ,EACvB,CACA,SAAS,aAAa,GACpB,UAAY,CACd,CACA,SAAS,iBACP,UAAY,EACd,CACA,SAAS,eACP,OAAO,SACT,CACA,SAAS,UAAU,GACjB,OAAS,CACX,CACA,SAAS,cACP,OAAS,eACX,CACA,SAAS,YACP,OAAO,MACT,CAIA,SAAS,YAAY,GACnB,IAAI,SAAS,EACf,CACA,eAAe,cAAc,EAAK,GAChC,IAAI,EAAO,KACX,IACE,EAAO,IAAI,IAAI,EACjB,CAAE,MAEF,CACA,GAAI,QAAU,IAAS,eAAe,SAAS,EAAK,SAAW,aAAa,SAAS,EAAK,WAAY,CAQpG,aAPqB,OAAO,UAAU,CACpC,KAAM,EACN,GAAI,gBACH,eACsB,MAAM,EAAK,IAItC,CACA,OAAO,MAAM,EAAK,EACpB,CACA,SAAS,mBACP,MAAM,EAAU,CAAC,EAGjB,OAFI,SAAQ,EAvDY,aAuDiB,QACrC,YAAW,EAvDc,gBAuDoB,WAC1C,CACT,CACA,SAAS,iBAAiB,GACxB,IAAI,KAAK,aAAa,EAAS,UAAU,EAAS,cAClD,IAAI,KAAK,QAAQ,EAAS,MAC5B,CACA,SAAS,iBAAiB,GACxB,MAAM,EAAgB,EAAS,QAAQ,IAAI,yBACvC,GAAe,IAAI,KAAK,kCAAkC,IAChE,CACA,MAAM,eA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,EAAG,EAAW,CAAC,EAAG,EAAgB,CAAC,KACpE,MAAM,EAAiB,CACrB,KAAM,OACN,QAAS,CACP,eAAgB,oCAMhB,EAAc,YAChB,EAAe,QAAU,cAAc,cAAc,CAAC,EAAG,EAAe,SAAU,qBAEpF,EAAS,OAAS,SAClB,MAAM,EAAU,MAAM,EAAgB,GAClC,EAAc,kBAIhB,EAAQ,KAAO,EAEyB,oCAApC,EAAQ,QAAQ,wBAA8D,EAAQ,QAAQ,iBAElG,EAAQ,KAAO,KAAK,UAAU,GAEhC,MAAM,QAAiB,cAAc,EAAK,GAC1C,GAAI,EAAS,GAAI,CACf,MAAM,EAAsB,EAAS,QAAQ,IAAI,gBACjD,OAAI,SAAkE,EAAoB,SAAS,oBAC1F,EAAS,OAEX,EAAS,MAClB,CAEA,MADA,iBAAiB,GACX,CAAQ,EAEV,sBAAwB,CAAC,EAAQ,KAAe,CACpD,QAAS,MACT,SACA,GAAI,GACJ,OAAQ,IAEJ,YAAc,CAAC,EAAK,EAAS,EAAU,MAAU,QAAQ,KAAK,CAAC,IAAI,EAAK,GAAU,IAAI,SAAQ,CAAC,EAAU,KAC7G,YAAW,KACT,EAAO,IAAI,MAAM,aAAa,GAC7B,EAAQ,aAGJ,YAAa,eAAgB,oBAAqB,kBAAmB,uBAAwB,sBAAuB,IAAK,UAAW,aAAc,MAAO,KAAM,YAAa,eAAgB,IAAK,OAAQ,UAAW,aAAc","file":"/npm/@toruslabs/http-helpers@9.0.0/dist/lib.esm/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@toruslabs/http-helpers@9.0.0/dist/lib.esm/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import _objectSpread from '@babel/runtime/helpers/objectSpread2';\nimport merge from 'deepmerge';\nimport logLevel, { levels } from 'loglevel';\n\nconst log = logLevel.getLogger(\"http-helpers\");\nlog.setLevel(levels.INFO);\n\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\n\nlet apiKey = \"torus-default\";\nlet embedHost = \"\";\n\n// #region API Keys\nconst gatewayAuthHeader = \"x-api-key\";\nconst gatewayEmbedHostHeader = \"x-embed-host\";\nlet sentry = null;\nconst tracingOrigins = [];\nconst tracingPaths = [];\nfunction enableSentryTracing(_sentry, _tracingOrigins, _tracingPaths) {\n  sentry = _sentry;\n  tracingOrigins.push(..._tracingOrigins);\n  tracingPaths.push(..._tracingPaths);\n}\nfunction setEmbedHost(embedHost_) {\n  embedHost = embedHost_;\n}\nfunction clearEmbedHost() {\n  embedHost = \"\";\n}\nfunction getEmbedHost() {\n  return embedHost;\n}\nfunction setAPIKey(apiKey_) {\n  apiKey = apiKey_;\n}\nfunction clearAPIKey() {\n  apiKey = \"torus-default\";\n}\nfunction getAPIKey() {\n  return apiKey;\n}\n\n// #endregion\n\nfunction setLogLevel(level) {\n  log.setLevel(level);\n}\nasync function fetchAndTrace(url, init) {\n  let _url = null;\n  try {\n    _url = new URL(url);\n  } catch {\n    // ignore\n  }\n  if (sentry && _url && (tracingOrigins.includes(_url.origin) || tracingPaths.includes(_url.pathname))) {\n    const result = await sentry.startSpan({\n      name: url,\n      op: \"http.client\"\n    }, async () => {\n      const response = await fetch(url, init);\n      return response;\n    });\n    return result;\n  }\n  return fetch(url, init);\n}\nfunction getApiKeyHeaders() {\n  const headers = {};\n  if (apiKey) headers[gatewayAuthHeader] = apiKey;\n  if (embedHost) headers[gatewayEmbedHostHeader] = embedHost;\n  return headers;\n}\nfunction debugLogResponse(response) {\n  log.info(`Response: ${response.status} ${response.statusText}`);\n  log.info(`Url: ${response.url}`);\n}\nfunction logTracingHeader(response) {\n  const tracingHeader = response.headers.get(\"x-web3-correlation-id\");\n  if (tracingHeader) log.info(`Request tracing with traceID = ${tracingHeader}`);\n}\nconst promiseTimeout = async (ms, promise) => {\n  let timeoutFunc = null;\n  try {\n    const timeout = new Promise((_resolve, reject) => {\n      timeoutFunc = setTimeout(() => {\n        reject(new Error(`Timed out in ${ms}ms`));\n      }, ms);\n    });\n    const result = await Promise.race([promise, timeout]);\n    // promise.race will return the first resolved promise\n    // then we clear the timeout\n    if (timeoutFunc != null) {\n      clearTimeout(timeoutFunc);\n    }\n    return result;\n  } catch (err) {\n    // clear the timeout\n    if (timeoutFunc != null) {\n      clearTimeout(timeoutFunc);\n    }\n    // rethrow the original error\n    throw err;\n  }\n};\nconst get = async (url, options_ = {}, customOptions = {}) => {\n  const defaultOptions = {\n    mode: \"cors\",\n    headers: {}\n  };\n  if (customOptions.useAPIKey) {\n    defaultOptions.headers = _objectSpread(_objectSpread({}, defaultOptions.headers), getApiKeyHeaders());\n  }\n  options_.method = \"GET\";\n  const options = merge(defaultOptions, options_);\n  const response = await fetchAndTrace(url, options);\n  if (response.ok) {\n    const responseContentType = response.headers.get(\"content-type\");\n    if (responseContentType !== null && responseContentType !== void 0 && responseContentType.includes(\"application/json\")) {\n      return response.json();\n    }\n    return response.text();\n  }\n  debugLogResponse(response);\n  throw response;\n};\nconst post = (url, data = {}, options_ = {}, customOptions = {}) => {\n  const defaultOptions = {\n    mode: \"cors\",\n    headers: {\n      \"Content-Type\": \"application/json; charset=utf-8\"\n    }\n  };\n  if (customOptions.useAPIKey) {\n    defaultOptions.headers = _objectSpread(_objectSpread({}, defaultOptions.headers), getApiKeyHeaders());\n  }\n  options_.method = \"POST\";\n  const options = merge(defaultOptions, options_);\n\n  // deep merge changes the structure of form data and url encoded data ,\n  // so we should not deepmerge body data\n  if (customOptions.isUrlEncodedData) {\n    // for multipart request browser/client will add multipart content type\n    // along with multipart boundary , so for multipart request send\n    // content-type: undefined or send with multipart boundary if already known\n    options.body = data;\n    // If url encoded data, this must not be the content type\n    if (options.headers[\"Content-Type\"] === \"application/json; charset=utf-8\") delete options.headers[\"Content-Type\"];\n  } else {\n    options.body = JSON.stringify(data);\n  }\n  return promiseTimeout(customOptions.timeout || 60000, fetchAndTrace(url, options).then(response => {\n    if (customOptions.logTracingHeader) {\n      logTracingHeader(response);\n    }\n    if (response.ok) {\n      const responseContentType = response.headers.get(\"content-type\");\n      if (responseContentType !== null && responseContentType !== void 0 && responseContentType.includes(\"application/json\")) {\n        return response.json();\n      }\n      return response.text();\n    }\n    debugLogResponse(response);\n    throw response;\n  }));\n};\nconst patch = async (url, data = {}, options_ = {}, customOptions = {}) => {\n  const defaultOptions = {\n    mode: \"cors\",\n    headers: {\n      \"Content-Type\": \"application/json; charset=utf-8\"\n    }\n  };\n  // for multipart request browser/client will add multipart content type\n  // along with multipart boundary , so for multipart request send\n  // content-type: undefined or send with multipart boundary if already known\n  if (customOptions.useAPIKey) {\n    defaultOptions.headers = _objectSpread(_objectSpread({}, defaultOptions.headers), getApiKeyHeaders());\n  }\n  options_.method = \"PATCH\";\n  const options = merge(defaultOptions, options_);\n  // deep merge changes the structure of form data and url encoded data ,\n  // so we should not deepmerge body data\n  if (customOptions.isUrlEncodedData) {\n    // for multipart request browser/client will add multipart content type\n    // along with multipart boundary , so for multipart request send\n    // content-type: undefined or send with multipart boundary if already known\n    options.body = data;\n    // If url encoded data, this must not be the content type\n    if (options.headers[\"Content-Type\"] === \"application/json; charset=utf-8\") delete options.headers[\"Content-Type\"];\n  } else {\n    options.body = JSON.stringify(data);\n  }\n  const response = await fetchAndTrace(url, options);\n  if (response.ok) {\n    const responseContentType = response.headers.get(\"content-type\");\n    if (responseContentType !== null && responseContentType !== void 0 && responseContentType.includes(\"application/json\")) {\n      return response.json();\n    }\n    return response.text();\n  }\n  debugLogResponse(response);\n  throw response;\n};\nconst put = async (url, data = {}, options_ = {}, customOptions = {}) => {\n  const defaultOptions = {\n    mode: \"cors\",\n    headers: {\n      \"Content-Type\": \"application/json; charset=utf-8\"\n    }\n  };\n  // for multipart request browser/client will add multipart content type\n  // along with multipart boundary , so for multipart request send\n  // content-type: undefined or send with multipart boundary if already known\n  if (customOptions.useAPIKey) {\n    defaultOptions.headers = _objectSpread(_objectSpread({}, defaultOptions.headers), getApiKeyHeaders());\n  }\n  options_.method = \"PUT\";\n  const options = merge(defaultOptions, options_);\n  // deep merge changes the structure of form data and url encoded data ,\n  // so we should not deepmerge body data\n  if (customOptions.isUrlEncodedData) {\n    // for multipart request browser/client will add multipart content type\n    // along with multipart boundary , so for multipart request send\n    // content-type: undefined or send with multipart boundary if already known\n    options.body = data;\n    // If url encoded data, this must not be the content type\n    if (options.headers[\"Content-Type\"] === \"application/json; charset=utf-8\") delete options.headers[\"Content-Type\"];\n  } else {\n    options.body = JSON.stringify(data);\n  }\n  const response = await fetchAndTrace(url, options);\n  if (response.ok) {\n    const responseContentType = response.headers.get(\"content-type\");\n    if (responseContentType !== null && responseContentType !== void 0 && responseContentType.includes(\"application/json\")) {\n      return response.json();\n    }\n    return response.text();\n  }\n  debugLogResponse(response);\n  throw response;\n};\nconst remove = async (url, data = {}, options_ = {}, customOptions = {}) => {\n  const defaultOptions = {\n    mode: \"cors\",\n    headers: {\n      \"Content-Type\": \"application/json; charset=utf-8\"\n    }\n  };\n  // for multipart request browser/client will add multipart content type\n  // along with multipart boundary , so for multipart request send\n  // content-type: undefined or send with multipart boundary if already known\n  if (customOptions.useAPIKey) {\n    defaultOptions.headers = _objectSpread(_objectSpread({}, defaultOptions.headers), getApiKeyHeaders());\n  }\n  options_.method = \"DELETE\";\n  const options = merge(defaultOptions, options_);\n  if (customOptions.isUrlEncodedData) {\n    // for multipart request browser/client will add multipart content type\n    // along with multipart boundary , so for multipart request send\n    // content-type: undefined or send with multipart boundary if already known\n    options.body = data;\n    // If url encoded data, this must not be the content type\n    if (options.headers[\"Content-Type\"] === \"application/json; charset=utf-8\") delete options.headers[\"Content-Type\"];\n  } else {\n    options.body = JSON.stringify(data);\n  }\n  const response = await fetchAndTrace(url, options);\n  if (response.ok) {\n    const responseContentType = response.headers.get(\"content-type\");\n    if (responseContentType !== null && responseContentType !== void 0 && responseContentType.includes(\"application/json\")) {\n      return response.json();\n    }\n    return response.text();\n  }\n  debugLogResponse(response);\n  throw response;\n};\nconst generateJsonRPCObject = (method, parameters) => ({\n  jsonrpc: \"2.0\",\n  method,\n  id: 10,\n  params: parameters\n});\nconst promiseRace = (url, options, timeout = 60000) => Promise.race([get(url, options), new Promise((_resolve, reject) => {\n  setTimeout(() => {\n    reject(new Error(\"timed out\"));\n  }, timeout);\n})]);\n\nexport { clearAPIKey, clearEmbedHost, enableSentryTracing, gatewayAuthHeader, gatewayEmbedHostHeader, generateJsonRPCObject, get, getAPIKey, getEmbedHost, patch, post, promiseRace, promiseTimeout, put, remove, setAPIKey, setEmbedHost, setLogLevel };\n"]}