import{i as e}from"./jsx-runtime-CutOxEx1.js";import{r as t}from"./norm-f7iXVy-b.js";import{n,t as r}from"./cloudWorkspaceClient-CCTm89GG.js";var i=e({cloudWorkspaceCreateShare:()=>s,cloudWorkspaceDeleteShare:()=>d,cloudWorkspaceGetSharePublic:()=>c,cloudWorkspaceGetSharePublicPayload:()=>l,cloudWorkspaceListShares:()=>u}),a=e=>new Promise(t=>setTimeout(t,e)),o=e=>{let n=t(e).toLowerCase();return n?n===`http_502`||n===`http_503`||n===`http_504`||n.includes(`failed to fetch`)||n.includes(`networkerror`)||n.includes(`network error`)||n.includes(`timeout`):!1},s=async e=>{let r=t(e.kind).slice(0,32),i=e.payload&&typeof e.payload==`object`&&!Array.isArray(e.payload)?e.payload:null;if(!r||!i)return{ok:!1,error:`invalid_args`,id:``};let a=await n({op:`create_share`,kind:r,payload:i,expiresAt:t(e.expiresAt)||void 0});if(!a.ok)return{ok:!1,error:a.error,id:``};let o=t(a.data?.id);return o?{ok:!0,id:o}:{ok:!1,error:`empty_id`,id:``}},c=async e=>{let n=t(e);if(!n)return{ok:!1,error:`missing_id`,share:null};let i=await r({op:`get_share`,id:n});return i.ok?!i.data?.ok||!i.data?.share?{ok:!1,error:`not_found`,share:null}:{ok:!0,error:``,share:i.data.share}:{ok:!1,error:i.error,share:null}},l=async e=>{let n=await c(e);if(!n.ok)return{ok:!1,error:t(n.error)||`not_found`,share:null};let r=n.share&&typeof n.share==`object`?n.share:null;return r?{ok:!0,error:``,share:r}:{ok:!1,error:`not_found`,share:null}},u=async(e=40,r)=>{let i={op:`list_shares`,limit:Math.max(1,Math.min(80,Math.floor(e||40))),kind:t(r)||void 0},s=``;for(let e=0;e<3;e++){let t=await n(i);if(t.ok)return{ok:!0,error:``,items:Array.isArray(t.data?.items)?t.data.items:[]};if(e<2&&o(t.error)){s=t.error,await a(200*(e+1));continue}return{ok:!1,error:t.error,items:[]}}return{ok:!1,error:s||`list_failed`,items:[]}},d=async e=>{let r=t(e);if(!r)return{ok:!1,error:`missing_id`};let i=await n({op:`delete_share`,id:r});return i.ok?{ok:!0,error:``}:{ok:!1,error:i.error}};export{u as a,l as i,d as n,i as o,c as r,s as t};