{"version":3,"file":"index.cjs","sources":["../node_modules/@ungap/global-this/esm/index.js","../index.js","../custom-fetch.js"],"sourcesContent":["(function (Object) {\n  typeof globalThis !== 'object' && (\n    this ?\n      get() :\n      (Object.defineProperty(Object.prototype, '_T_', {\n        configurable: true,\n        get: get\n      }), _T_)\n  );\n  function get() {\n    var global = this || self;\n    global.globalThis = global;\n    delete Object.prototype._T_;\n  }\n}(Object));\nexport default globalThis;\n","import fetch from 'node-fetch';\nimport abortController from 'abort-controller';\n\nimport customFetch from './custom-fetch';\n\nexport default function(endpoint, config, options = {}) {\n  return customFetch(endpoint, config, {\n    ...options,\n    fetch,\n    AbortController: globalThis.AbortController || abortController\n  });\n}\n","import '@ungap/global-this';\n\nexport default function customFetch(\n  endpoint,\n  {\n    body,\n    ...customConfig\n  } = {},\n  {\n    fetch = globalThis.fetch,\n    AbortController = globalThis.AbortController,\n    responseType = 'text',\n    timeout\n  } = {},\n) {\n  let timeoutSignal = undefined;\n  if (timeout) {\n    timeoutSignal = createTimeoutSignal(AbortController, timeout);\n  }\n  const config = {\n    method: body ? 'POST' : 'GET',\n    ...customConfig\n  }\n  // from here: https://github.com/developit/redaxios/blob/ab73a298ba9849c59d670230a9d24fd7b329fb4d/src/index.js#L171\n  if (body && typeof body === 'object' && typeof body.append !== 'function') {\n    config.body = JSON.stringify(body);\n    config.headers = {\n      ...config.headers,\n      'content-type': 'application/json'\n    };\n  } else if (body) {\n    config.body = body;\n  }\n  if (timeoutSignal) {\n    config.signal = timeoutSignal.signal;\n  }\n  return fetch(endpoint, config).then(async (response) => {\n    if (timeoutSignal) {\n      timeoutSignal.clear();\n    }\n    if (!response.ok) {\n      const errorMessage = await response.text();\n      return Promise.reject(new Error(errorMessage));\n    }\n    const result = {};\n    // see https://github.com/developit/redaxios/blob/ab73a298ba9849c59d670230a9d24fd7b329fb4d/src/index.js#L204-L213\n    for (const i in response) {\n      if (typeof response[i] !== 'function') result[i] = response[i];\n    }\n    const data = await response[responseType]();\n    result.data = data;\n    try {\n      // just in case we can parse the result\n      result.data = JSON.parse(data);\n    } catch(error) {\n      // ignore\n    }\n    return result;\n  });\n}\n\nfunction createTimeoutSignal(AbortController, timeout) {\n  const controller = new AbortController();\n  const timeoutId = globalThis.setTimeout(() => {\n    controller.abort();\n  }, timeout);\n  return {\n    signal: controller.signal,\n    clear: () => {\n      globalThis.clearTimeout(timeoutId);\n    }\n  };\n}\n"],"names":["Object","get","global","this","self","globalThis","prototype","_T_","defineProperty","configurable","endpoint","config","options","body","customConfig","fetch","AbortController","responseType","timeout","timeoutSignal","undefined","controller","timeoutId","setTimeout","abort","signal","clear","clearTimeout","createTimeoutSignal","method","append","JSON","stringify","headers","then","response","result","i","data","parse","error","ok","text","errorMessage","Promise","reject","Error","customFetch","abortController"],"mappings":"+XAAC,SAAUA,GAST,SAASC,IACP,IAAIC,EAASC,MAAQC,KACrBF,EAAOG,WAAaH,SACbF,EAAOM,UAAUC,IAXJ,iBAAfF,aACLF,KACEF,KACCD,EAAOQ,eAAeR,EAAOM,UAAW,MAAO,CAC9CG,cAAc,EACdR,IAAKA,IACHM,MAPV,CAcEP,+CCTsBU,EAAUC,EAAQC,GACxC,gBADwCA,IAAAA,EAAU,aCFlDF,wBAII,KAFFG,IAAAA,KACGC,uJAOD,SAJFC,MAAAA,aAAQV,WAAWU,YACnBC,gBAAAA,aAAkBX,WAAWW,sBAC7BC,aAAAA,aAAe,SACfC,IAAAA,QAGEC,OAAgBC,EAChBF,IACFC,EA4CJ,SAA6BH,EAAiBE,GAC5C,IAAMG,EAAa,IAAIL,EACjBM,EAAYjB,WAAWkB,WAAW,WACtCF,EAAWG,SACVN,GACH,MAAO,CACLO,OAAQJ,EAAWI,OACnBC,MAAO,WACLrB,WAAWsB,aAAaL,KApDVM,CAAoBZ,EAAiBE,IAEvD,IAAMP,KACJkB,OAAQhB,EAAO,OAAS,OACrBC,GAeL,OAZID,GAAwB,iBAATA,GAA4C,mBAAhBA,EAAKiB,QAClDnB,EAAOE,KAAO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