| 1 |
function d(e,s=""){let o={};return Object.keys(e).forEach(l=>{typeof e[l]=="object"?o=Object.assign(o,d(e[l],`${s}[${l}]`)):o[`${s}[${l}]`]=e[l]}),o}const a=function(e,s,o={}){const l=`${window.fluentComAdmin.rest.url}/${s}`,u={"X-WP-Nonce":window.fluentComAdmin.rest.nonce};return["PUT","PATCH","DELETE"].indexOf(e.toUpperCase())!==-1&&(u["X-HTTP-Method-Override"]=e,e="POST"),o.query_timestamp=Date.now(),new Promise((c,r)=>{const t=new XMLHttpRequest;let f=l;if(e.toUpperCase()==="GET"){let n={};Object.keys(o).forEach(i=>{o[i]===null||o[i]===!1?delete o[i]:typeof o[i]=="object"?n=Object.assign(n,d(o[i],i)):n[i]=o[i]});let p=new URLSearchParams(n).toString();f.indexOf("?")!==-1?f+="&"+p:f+="?"+p}t.open(e,f,!0),Object.keys(u).forEach(n=>{t.setRequestHeader(n,u[n])}),t.onload=function(){if(this.status>=200&&this.status<300)c(JSON.parse(t.responseText));else{let n;try{n=JSON.parse(t.responseText)}catch{n=null}n?(typeof n=="object"&&(n.xhr_status=t.status),n.code=="rest_cookie_invalid_nonce"&&window.fluentFrameworkApp.$messageBox.alert("Your session has expired due to inactivity. Please refresh the page to continue.","Session Expired",{confirmButtonText:"Refresh",callback:p=>{location.reload()}}),r(n)):(window.fluentFrameworkApp.$notify({message:'Unexpected error from server. Please check browser console. <button class="el-button el-button--small el-button--danger">Click to view details.</button>',type:"error",dangerouslyUseHTMLString:!0,customClass:"fc_bottom-right",position:"bottom-right",onClick:()=>{window.fluentFrameworkApp.$messageBox(t.responseText)},duration:1e4}),console.info("Your server firewall blocked the request or it's a plugin conflict. Please check the detailed error."),console.log({status:t.status,statusText:t.statusText,responseText:t.responseText}))}},t.onerror=function(){console.info("Your server firewall blocked the request or it's a plugin conflict. Please check the detailed error."),console.log({status:t.status,statusText:t.statusText,responseText:t.responseText}),r({status:t.status,statusText:t.statusText})},e.toUpperCase()==="GET"?t.send():(t.setRequestHeader("Content-Type","application/json;charset=UTF-8"),t.send(JSON.stringify(o)))})},T={get(e,s={}){return a("GET",e,s)},post(e,s={}){return a("POST",e,s)},delete(e,s={}){return a("DELETE",e,s)},put(e,s={}){return a("PUT",e,s)},patch(e,s={}){return a("PATCH",e,s)},uploadFile(e,s={}){const o=`${window.fluentComAdmin.rest.url}/${e}`,l={"X-WP-Nonce":window.fluentComAdmin.rest.nonce};return new Promise((u,c)=>{const r=new XMLHttpRequest;r.open("POST",o,!0),Object.keys(l).forEach(t=>{r.setRequestHeader(t,l[t])}),r.onload=function(){this.status>=200&&this.status<300?u(JSON.parse(r.responseText)):c(JSON.parse(r.responseText))},r.onerror=function(){c({status:r.status,statusText:r.statusText})},r.send(s)})}};var w=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function h(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}export{T as R,w as c,h as g}; |