import{l as c}from"./vendor.Cge7vpB3.js";class d{protocol;host;port;path;queryString}const h=e=>{if(!e)return console.error("Failed to convert input string to uri segments: "+e),null;const a=e.split("?"),r=a.length==2?a[1]:"";r&&(e=a[0]);const n=e.split("/");if(!Array.isArray(n)||n.length==0)return console.error("Failed to convert input string to uri segments: "+e),null;if(!/^(http:|https:)/i.test(n[0]))return console.error("Uri did not start with supported protocol: "+e),null;if(n.length<3)return console.error("Could not determine valid host: "+e),null;const t=new d;t.protocol=n[0].replace(":","");const o=n[2].split(":");return t.host=o[0],t.port=o.length==2?o[1]:"",n.length==3||(n.splice(0,3),t.queryString=r,t.path=[...n]),t},i=e=>e.slice(-1)=="/"?e:`${e}/`;var l=(e=>(e.delete="delete",e.get="get",e.patch="patch",e.post="post",e.put="put",e))(l||{});const g=async e=>{let a="",r="",n=!1;try{a=window.wpo365.blocks.nonce,r=window.wpo365.blocks.apiUrl,n=!0}catch(t){throw new Error(`[FetchUtil::fromGraph] Cannot continue because prerequistes nonce and / or apiUrl are undefined [${t.message}]`)}try{return(await c.post(`${i(r)}${e.endpoint}`,{method:e.method||l.get,query:e.query,scope:e.scope,application:e.application,binary:!!e.binary,data:e.data?e.data:"",headers:e.headers||{}},{headers:{Accept:"application/json",ContentType:"application/json; odata=verbose","X-WP-Nonce":a}})).data||null}catch(t){const o=new Error(t.response?.data?.message||t.message);throw o.raw=t.response?.data?.data?.raw,o}},y=async e=>{let a="",r="",n=!1;try{a=window.wpo365.blocks.nonce,r=window.wpo365.blocks.apiUrl,n=!0}catch(t){throw new Error(`[FetchUtil::fromProxy] Cannot continue because prerequistes nonce and / or apiUrl are undefined [${t.message}]`)}try{return(await c.post(`${i(r)}${e.endpoint}`,{application:e.application,url:e.url,scope:e.scope,binary:!!e.binary,data:e.data??"",method:e.method??l.get,headers:e.headers??{Accept:"application/json","Content-Type":"application/json; odata=verbose"}},{headers:{"X-WP-Nonce":a}})).data||null}catch(t){const o=new Error(t.response?.data?.message||t.message);throw o.raw=t.response?.data?.data?.raw,o}},u=async e=>{let a="",r="",n=!1;try{a=window.wpo365.blocks.nonce,r=window.wpo365.blocks.apiUrl,n=!0}catch(o){throw new Error(`[FetchUtil::uploadFile] Cannot continue because prerequistes nonce and / or apiUrl are undefined [${o.message}]`)}const t=new FormData;t.append("application",String(e.application)),t.append("url",e.url),t.append("scope",e.scope),t.append("data",e.data?e.data:""),t.append("headers",JSON.stringify(e.headers?e.headers:{}));try{return(await c.post(`${i(r)}${e.endpoint}`,t,{headers:{"X-WP-Nonce":a,"Content-Type":"multipart/form-data"}})).data||null}catch(o){const s=new Error(o.response?.data?.message||o.message);throw s.raw=o.response?.data?.data?.raw,s}},f=async e=>{let a="",r="",n=!1;try{a=window.wpo365.blocks.nonce,r=window.wpo365.blocks.apiUrl,n=!0}catch(t){throw new Error(`[FetchUtil::getToken] Cannot continue because prerequistes nonce and / or apiUrl are undefined [${t.message}]`)}try{const t=await c.post(`${i(r)}token`,{scope:e.scope},{headers:{Accept:"application/json",ContentType:"application/json; odata=verbose","X-WP-Nonce":a}});if(!t.data||typeof t.data!="object"||!("access_token"in t.data)||!("scope"in t.data))throw new Error("Unexpected: Response from WPO365 Proxy API does not has data or data does not include an access token");return t.data}catch(t){const o=new Error(t.response?.data?.message||t.message);throw o.raw=t.response?.data?.data?.raw,o}},m=(e,a,r=!1,n=!1)=>{const t=e.split("/");t.splice(0,4),t[t.length-1]||t.pop();let o="",s="";try{if(t.length>1)o=t.shift()??"",s=t.join("/");else{const p=t[0].split("?");o=p[0],s=p.length==2?`?${p[1]}`:""}}catch{console.error(`Unexpected: Could not convert URL into IGraphRequest [url -> ${e}]`)}return{endpoint:o,query:s,scope:a,application:r,binary:n}},U=e=>e?e==="1"||e.toString().toLowerCase()==="true"||e.toString().toLowerCase()==="yes":!1,b=(e,a)=>e&&typeof e=="string"?e:a,S=(e,a)=>e&&!isNaN(parseInt(e))?parseInt(e):a;export{l as F,U as a,S as b,y as c,i as d,b as e,g as f,h as g,f as h,m as t,u};
//# sourceMappingURL=typeHelpers.DyGGaxEg.js.map
