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