const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/hostPermissions-Daz5S2M5.js","assets/jsx-runtime-CutOxEx1.js"])))=>i.map(i=>d[i]);
import{t as e}from"./preload-helper-DzyYoeor.js";import{r as t}from"./authSession-Dulxhbeq.js";import{r as n}from"./norm-f7iXVy-b.js";var r=`https://api2.bysjob.com`.replace(/\/+$/g,``),i=`/api/workspace`,a=async e=>{let t=await e.text().catch(()=>``),n=null;try{n=t?JSON.parse(t):null}catch{}return{data:n,text:t}},o=async()=>{let e=await t(),r=n(e?.token);if(!r)return{ok:!1,error:`not_logged_in`};let i={"Content-Type":`application/json`,"x-auth-token":r,"x-client-id":`u:${n(e?.user?.id)||`public`}`.slice(0,120)},a=n(e?.accessToken);return a&&(i.Authorization=`Bearer ${a}`),{ok:!0,headers:i}},s=async t=>{let s=await o();if(!s.ok)throw Error(s.error);let c=`${r}${i}`,{ensureHostPermissionForUrl:l}=await e(async()=>{let{ensureHostPermissionForUrl:e}=await import(`./hostPermissions-Daz5S2M5.js`).then(e=>e.n);return{ensureHostPermissionForUrl:e}},__vite__mapDeps([0,1]));if(!await l(c))throw Error(`未授予访问该地址的权限`);let u=await fetch(c,{method:`POST`,headers:s.headers,body:JSON.stringify(t||{})}),{data:d,text:f}=await a(u);if(!u.ok){let e=n(d?.message||d?.error||f||`http_${u.status}`),t=Error(e);throw t.status=u.status,t.payload=d,t}return d},c=async t=>{let o=`${r}${i}`,{ensureHostPermissionForUrl:s}=await e(async()=>{let{ensureHostPermissionForUrl:e}=await import(`./hostPermissions-Daz5S2M5.js`).then(e=>e.n);return{ensureHostPermissionForUrl:e}},__vite__mapDeps([0,1]));if(!await s(o))throw Error(`未授予访问该地址的权限`);let c=await fetch(o,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t||{})}),{data:l,text:u}=await a(c);if(!c.ok){let e=n(l?.message||l?.error||u||`http_${c.status}`),t=Error(e);throw t.status=c.status,t.payload=l,t}return l},l=async e=>{try{return{ok:!0,data:await s(e),status:200}}catch(e){return{ok:!1,error:n(e?.message)||`workspace_api_failed`,status:Number(e?.status||0),data:e?.payload}}},u=async e=>{try{return{ok:!0,data:await c(e),status:200}}catch(e){return{ok:!1,error:n(e?.message)||`workspace_api_failed`,status:Number(e?.status||0),data:e?.payload}}};export{l as n,u as t};