1(function () { 2 'use strict'; 3 4 window.ppaccessCore = window.ppaccessCore || {}; 5 6 window.ppaccessCore.api = { 7 postJSON: function (cfg, path, payload, opts) { 8 var rest = String((cfg && cfg.rest) || '').replace(/\/$/, ''); 9 // When a checkout or account token is present, omit X-WP-Nonce entirely. 10 // WP core's rest_cookie_check_errors hook rejects requests where 11 // X-WP-Nonce is present but fails verification â it fires before our 12 // permission_callback, so we must not send a stale nonce alongside 13 // the token or WP will 403 before we can validate the token ourselves. 14 var skipToken = (opts && opts.skipToken) || false; // set true for public endpoints that must not consume the checkout token 15 var preserveToken = (opts && opts.preserveToken) || false; // send token but keep it in cfg for a subsequent call 16 var checkoutToken = !skipToken && cfg && cfg.checkoutToken; 17 if (checkoutToken && !preserveToken) { delete cfg.checkoutToken; } // consume: send once only 18 var accountToken = (opts && opts.accountToken) || null; // per-request only 19 var headers = { 'Content-Type': 'application/json' }; 20 if (checkoutToken) { 21 headers['X-PPAccess-Checkout-Token'] = checkoutToken; 22 } else if (accountToken) { 23 headers['X-PPAccess-Account-Token'] = accountToken; 24 } else { 25 headers['X-WP-Nonce'] = (cfg && cfg.nonce) || ''; 26 } 27 return fetch(rest + path, { 28 method: 'POST', 29 headers: headers, 30 credentials: 'same-origin', 31 body: JSON.stringify(payload || {}) 32 }).then(function (response) { 33 return response.json().catch(function () { return {}; }).then(function (body) { 34 return { ok: response.ok, body: body }; 35 }); 36 }); 37 }, 38 39 postJSONOrThrow: function (cfg, path, payload) { 40 return this.postJSON(cfg, path, payload).then(function (result) { 41 if (result.ok) { 42 return result.body; 43 } 44 var message = result.body && result.body.message ? result.body.message : 'Request failed.'; 45 var error = new Error(message); 46 error.data = result.body || {}; 47 throw error; 48 }); 49 } 50 }; 51})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.