PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / assets / chunks / Rest.js

Rest.js in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at assets/chunks/Rest.js

2 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function E(t,s=""){let n={};return Object.keys(t).forEach(e=>{t[e]===null||t[e]===!1?delete t[e]:typeof t[e]=="object"?n=Object.assign(n,E(t[e],`${s}[${e}]`)):n[`${s}[${e}]`]=t[e]}),n}const l=function(t=null,s,n,e={},d={}){const c=n.startsWith("/")?n.slice(1):n,a=`${t||window.fluentCartRestVars.rest.url}/${c}`,i={"X-WP-Nonce":window.fluentCartRestVars.rest.nonce};return["PUT","PATCH","DELETE"].indexOf(s.toUpperCase())!==-1&&(i["X-HTTP-Method-Override"]=s,s="POST"),e.query_timestamp=Date.now(),new Promise((O,p)=>{const o=new XMLHttpRequest,w=d.signal;let f=a;if(s.toUpperCase()==="GET"){let r={};Object.keys(e).forEach(u=>{e[u]===null||e[u]===!1?delete e[u]:typeof e[u]=="object"?r=Object.assign(r,E(e[u],u)):r[u]=e[u]});let T=new URLSearchParams(r).toString();f.indexOf("?")!==-1?f+="&"+T:f+="?"+T}if(o.open(s,f,!0),Object.keys(i).forEach(r=>{o.setRequestHeader(r,i[r])}),o.onload=function(){let r;try{r=JSON.parse(o.responseText)}catch{r=null}this.status>=200&&this.status<300?O(r):(r&&(r.code==="rest_cookie_invalid_nonce"||r.code==="rest_cookie_invalid")&&document.dispatchEvent(new CustomEvent("fcart_renew_rest_nonce",{detail:r})),p({data:r,status_code:o.status}))},o.onerror=function(){p({status:o.status,statusText:o.statusText})},o.onabort=function(){p(new DOMException("The request was aborted.","AbortError"))},w){if(w.aborted){o.abort();return}w.addEventListener("abort",()=>o.abort(),{once:!0})}s.toUpperCase()==="GET"?o.send():(o.setRequestHeader("Content-Type","application/json;charset=UTF-8"),o.send(JSON.stringify(e)))})},R={get(t,s={},n=null){return l(n,"GET",t,s)},post(t,s={},n=null,e={}){return l(n,"POST",t,s,e)},delete(t,s={},n=null){return l(n,"DELETE",t,s)},put(t,s={},n=null){return l(n,"PUT",t,s)},patch(t,s={},n=null){return l(n,"PATCH",t,s)},upload(t,s={}){const n=`${window.fluentCartRestVars.rest.url}/${t}`,e={"X-WP-Nonce":window.fluentCartRestVars.rest.nonce};return new Promise((d,c)=>{const a=new XMLHttpRequest;a.open("POST",n,!0),Object.keys(e).forEach(i=>{a.setRequestHeader(i,e[i])}),a.onload=function(){this.status>=200&&this.status<300?d(JSON.parse(a.responseText)):c(JSON.parse(a.responseText))},a.onerror=function(){c({status:a.status,statusText:a.statusText})},a.send(s)})},getNonce(){return window.fluentCartRestVars.rest.nonce}};window.jQuery!==void 0&&jQuery(document).ajaxSuccess((t,s,n)=>{const e=s.getResponseHeader("X-WP-Nonce");e&&(window.fluentCartRestVars,window.fluentCartRestVars.rest_nonce=e)});export{R};
2