import{w as n,c as o}from"./p-DVJaoI_m.js";import{g as t}from"./p-BXrbGZ_R.js";const a=()=>{async function a(a){var e,s;const{authToken:r,endpoint:i,method:d,params:u,body:p,signal:c,headers:h}=a;await n();const l=`${o.apiOrigin}/v1/${i}`,m=u?`${l}?${new URLSearchParams(u)}`:l,y=await async function(n){return n?{Authorization:`Bearer ${n}`,"Idempotency-Key":t(),"Content-Type":"application/json"}:{"Content-Type":"application/json"}}(r),f=Object.assign(Object.assign({},y),h),T=await fetch(m,{method:d,headers:f,body:p,signal:c});if(!T)return void function(n){console.error(`Error fetching from ${n}`)}(m);if(204===T.status)return{};const g=await T.json().catch((()=>({})));if(!T.ok){const n=new Error((null===(e=null==g?void 0:g.error)||void 0===e?void 0:e.message)||("string"==typeof(null==g?void 0:g.error)?g.error:null)||(null==g?void 0:g.message)||`Request failed: ${T.status}`);throw n.code=null===(s=null==g?void 0:g.error)||void 0===s?void 0:s.code,n.status=T.status,n.body=g,n}return g}return{get:async function(n){const{authToken:o,endpoint:t,params:e,signal:s,headers:r}=n;return a({authToken:o,endpoint:t,method:"GET",params:e,signal:s,headers:r})},post:async function(n){const{authToken:o,endpoint:t,body:e,params:s,signal:r,headers:i}=n;return a({authToken:o,endpoint:t,method:"POST",params:s,body:JSON.stringify(e),signal:r,headers:i})},put:async function(n){const{authToken:o,endpoint:t,body:e,params:s,signal:r}=n;return a({authToken:o,endpoint:t,method:"PUT",params:s,body:JSON.stringify(e),signal:r})},patch:async function(n){const{authToken:o,endpoint:t,body:e,params:s,signal:r}=n;return a({authToken:o,endpoint:t,method:"PATCH",params:s,body:JSON.stringify(e),signal:r})},destroy:async function(n){const{authToken:o,endpoint:t,params:e,signal:s}=n;return a({authToken:o,endpoint:t,method:"DELETE",params:e,signal:s})}}};export{a as A}