var e=`/api`,t=class extends Error{status;body;constructor(e,t,n){super(n),this.name=`AdminApiError`,this.status=e,this.body=t}};async function n(n,r){if(n.startsWith(`/api/`)){let e=n.slice(4);console.warn(`adminFetch: stripping redundant /api prefix from "${n}"`),n=e}let i={...r?.headers};r?.body&&(i[`Content-Type`]=`application/json`);let a=await fetch(`${e}${n}`,{...r,credentials:`include`,headers:i});if(a.status===401)throw window.location.href=`/admin/login`,Error(`Not authenticated`);if(!a.ok){let e=await a.json().catch(()=>({error:a.statusText})),n=typeof e.error==`string`?e.error:a.statusText;throw new t(a.status,e,n)}return a.json()}function r(e,t){return n(e,{method:`POST`,body:t?JSON.stringify(t):void 0})}function i(e,t){return n(e,{method:`PUT`,body:t?JSON.stringify(t):void 0})}function a(e,t){return n(e,{method:`PATCH`,body:t?JSON.stringify(t):void 0})}function o(e){return n(e,{method:`DELETE`})}export{r as a,a as i,o as n,i as o,n as r,t};