2018-12-13 23:41:57 -05:00
|
|
|
this["wp"] = this["wp"] || {}; this["wp"]["apiFetch"] =
|
|
|
|
/******/ (function(modules) { // webpackBootstrap
|
|
|
|
/******/ // The module cache
|
|
|
|
/******/ var installedModules = {};
|
|
|
|
/******/
|
|
|
|
/******/ // The require function
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
|
|
|
/******/
|
|
|
|
/******/ // Check if module is in cache
|
|
|
|
/******/ if(installedModules[moduleId]) {
|
|
|
|
/******/ return installedModules[moduleId].exports;
|
|
|
|
/******/ }
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = installedModules[moduleId] = {
|
|
|
|
/******/ i: moduleId,
|
|
|
|
/******/ l: false,
|
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
|
|
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
|
|
/******/
|
|
|
|
/******/ // Flag the module as loaded
|
|
|
|
/******/ module.l = true;
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/******/
|
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
|
|
|
/******/ __webpack_require__.m = modules;
|
|
|
|
/******/
|
|
|
|
/******/ // expose the module cache
|
|
|
|
/******/ __webpack_require__.c = installedModules;
|
|
|
|
/******/
|
|
|
|
/******/ // define getter function for harmony exports
|
|
|
|
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
|
|
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
|
|
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // define __esModule on exports
|
|
|
|
/******/ __webpack_require__.r = function(exports) {
|
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // create a fake namespace object
|
|
|
|
/******/ // mode & 1: value is a module id, require it
|
|
|
|
/******/ // mode & 2: merge all properties of value into the ns
|
|
|
|
/******/ // mode & 4: return value when already ns object
|
|
|
|
/******/ // mode & 8|1: behave like require
|
|
|
|
/******/ __webpack_require__.t = function(value, mode) {
|
|
|
|
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
|
|
/******/ if(mode & 8) return value;
|
|
|
|
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
|
|
/******/ var ns = Object.create(null);
|
|
|
|
/******/ __webpack_require__.r(ns);
|
|
|
|
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
|
|
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
|
|
/******/ return ns;
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
|
|
/******/ __webpack_require__.n = function(module) {
|
|
|
|
/******/ var getter = module && module.__esModule ?
|
|
|
|
/******/ function getDefault() { return module['default']; } :
|
|
|
|
/******/ function getModuleExports() { return module; };
|
|
|
|
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
|
|
/******/ return getter;
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Object.prototype.hasOwnProperty.call
|
|
|
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
|
|
/******/
|
|
|
|
/******/ // __webpack_public_path__
|
|
|
|
/******/ __webpack_require__.p = "";
|
|
|
|
/******/
|
|
|
|
/******/
|
|
|
|
/******/ // Load entry module and return exports
|
2021-05-20 08:20:04 -04:00
|
|
|
/******/ return __webpack_require__(__webpack_require__.s = "jqrR");
|
2018-12-13 23:41:57 -05:00
|
|
|
/******/ })
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ ({
|
|
|
|
|
2021-05-20 08:20:04 -04:00
|
|
|
/***/ "Mmq9":
|
2019-04-22 08:40:04 -04:00
|
|
|
/***/ (function(module, exports) {
|
2019-03-21 08:48:00 -04:00
|
|
|
|
2021-01-27 21:04:13 -05:00
|
|
|
(function() { module.exports = window["wp"]["url"]; }());
|
2019-03-21 08:48:00 -04:00
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
2021-05-20 08:20:04 -04:00
|
|
|
/***/ "jqrR":
|
2018-12-13 23:41:57 -05:00
|
|
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
2020-06-29 07:50:29 -04:00
|
|
|
// ESM COMPAT FLAG
|
2018-12-13 23:41:57 -05:00
|
|
|
__webpack_require__.r(__webpack_exports__);
|
|
|
|
|
2021-01-27 21:04:13 -05:00
|
|
|
// EXTERNAL MODULE: external ["wp","i18n"]
|
2021-05-20 08:20:04 -04:00
|
|
|
var external_wp_i18n_ = __webpack_require__("l3Sj");
|
2020-01-08 06:57:23 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string} nonce
|
|
|
|
* @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce.
|
|
|
|
*/
|
2019-03-07 04:09:59 -05:00
|
|
|
function createNonceMiddleware(nonce) {
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware & { nonce: string }}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const middleware = (options, next) => {
|
|
|
|
const {
|
|
|
|
headers = {}
|
|
|
|
} = options; // If an 'X-WP-Nonce' header (or any case-insensitive variation
|
2018-12-17 22:14:52 -05:00
|
|
|
// thereof) was specified, no need to add a nonce header.
|
2018-12-16 23:52:00 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
for (const headerName in headers) {
|
2020-10-13 09:10:30 -04:00
|
|
|
if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) {
|
2019-03-07 04:09:59 -05:00
|
|
|
return next(options);
|
2018-12-17 22:14:52 -05:00
|
|
|
}
|
|
|
|
}
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
return next({ ...options,
|
|
|
|
headers: { ...headers,
|
2019-03-07 04:09:59 -05:00
|
|
|
'X-WP-Nonce': middleware.nonce
|
2021-05-19 11:09:27 -04:00
|
|
|
}
|
|
|
|
});
|
2021-04-15 11:19:43 -04:00
|
|
|
};
|
2019-03-07 04:09:59 -05:00
|
|
|
|
|
|
|
middleware.nonce = nonce;
|
|
|
|
return middleware;
|
|
|
|
}
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2020-02-06 16:03:31 -05:00
|
|
|
/* harmony default export */ var nonce = (createNonceMiddleware);
|
2018-12-15 06:00:40 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const namespaceAndEndpointMiddleware = (options, next) => {
|
|
|
|
let path = options.path;
|
|
|
|
let namespaceTrimmed, endpointTrimmed;
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
|
|
|
|
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
|
|
|
|
endpointTrimmed = options.endpoint.replace(/^\//, '');
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
if (endpointTrimmed) {
|
|
|
|
path = namespaceTrimmed + '/' + endpointTrimmed;
|
|
|
|
} else {
|
|
|
|
path = namespaceTrimmed;
|
|
|
|
}
|
|
|
|
}
|
2018-12-16 23:52:00 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
delete options.namespace;
|
|
|
|
delete options.endpoint;
|
2021-05-19 11:09:27 -04:00
|
|
|
return next({ ...options,
|
|
|
|
path
|
|
|
|
});
|
2018-12-17 22:14:52 -05:00
|
|
|
};
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2020-02-06 16:03:31 -05:00
|
|
|
/* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string} rootURL
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Root URL middleware.
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const createRootURLMiddleware = rootURL => (options, next) => {
|
|
|
|
return namespace_endpoint(options, optionsWithPath => {
|
|
|
|
let url = optionsWithPath.url;
|
|
|
|
let path = optionsWithPath.path;
|
|
|
|
let apiRoot;
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
if (typeof path === 'string') {
|
|
|
|
apiRoot = rootURL;
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
if (-1 !== rootURL.indexOf('?')) {
|
|
|
|
path = path.replace('?', '&');
|
|
|
|
}
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
path = path.replace(/^\//, ''); // API root may already include query parameter prefix if site is
|
|
|
|
// configured to use plain permalinks.
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
|
|
|
|
path = path.replace('?', '&');
|
2018-12-17 22:14:52 -05:00
|
|
|
}
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
url = apiRoot + path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next({ ...optionsWithPath,
|
|
|
|
url
|
2018-12-17 22:14:52 -05:00
|
|
|
});
|
2021-05-19 11:09:27 -04:00
|
|
|
});
|
2018-12-17 22:14:52 -05:00
|
|
|
};
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
/* harmony default export */ var root_url = (createRootURLMiddleware);
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2021-11-08 09:29:21 -05:00
|
|
|
// EXTERNAL MODULE: external ["wp","url"]
|
|
|
|
var external_wp_url_ = __webpack_require__("Mmq9");
|
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
|
2020-01-08 06:57:23 -05:00
|
|
|
/**
|
2021-11-08 09:29:21 -05:00
|
|
|
* WordPress dependencies
|
2020-01-08 06:57:23 -05:00
|
|
|
*/
|
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {Record<string, any>} preloadedData
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
|
|
|
|
*/
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2020-01-08 06:57:23 -05:00
|
|
|
function createPreloadingMiddleware(preloadedData) {
|
2021-05-19 11:09:27 -04:00
|
|
|
const cache = Object.keys(preloadedData).reduce((result, path) => {
|
2021-11-08 09:29:21 -05:00
|
|
|
result[Object(external_wp_url_["normalizePath"])(path)] = preloadedData[path];
|
2020-01-08 06:57:23 -05:00
|
|
|
return result;
|
2021-04-15 11:19:43 -04:00
|
|
|
},
|
|
|
|
/** @type {Record<string, any>} */
|
|
|
|
{});
|
2021-05-19 11:09:27 -04:00
|
|
|
return (options, next) => {
|
|
|
|
const {
|
|
|
|
parse = true
|
|
|
|
} = options;
|
2021-11-08 09:29:21 -05:00
|
|
|
/** @type {string | void} */
|
|
|
|
|
|
|
|
let rawPath = options.path;
|
|
|
|
|
|
|
|
if (!rawPath && options.url) {
|
|
|
|
const pathFromQuery = Object(external_wp_url_["getQueryArg"])(options.url, 'rest_route');
|
|
|
|
|
|
|
|
if (typeof pathFromQuery === 'string') {
|
|
|
|
rawPath = pathFromQuery;
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2021-11-08 09:29:21 -05:00
|
|
|
if (typeof rawPath === 'string') {
|
2021-05-19 11:09:27 -04:00
|
|
|
const method = options.method || 'GET';
|
2021-11-08 09:29:21 -05:00
|
|
|
const path = Object(external_wp_url_["normalizePath"])(rawPath);
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2020-10-13 09:10:30 -04:00
|
|
|
if ('GET' === method && cache[path]) {
|
2021-11-08 09:29:21 -05:00
|
|
|
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time
|
2020-10-13 09:10:30 -04:00
|
|
|
|
|
|
|
delete cache[path];
|
|
|
|
return Promise.resolve(parse ? cacheData.body : new window.Response(JSON.stringify(cacheData.body), {
|
|
|
|
status: 200,
|
|
|
|
statusText: 'OK',
|
|
|
|
headers: cacheData.headers
|
|
|
|
}));
|
2020-01-08 06:57:23 -05:00
|
|
|
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
|
2021-11-08 09:29:21 -05:00
|
|
|
const cacheData = cache[method][path]; // Unsetting the cache key ensures that the data is only used a single time
|
|
|
|
|
|
|
|
delete cache[method][path];
|
|
|
|
return Promise.resolve(parse ? cacheData.body : cacheData);
|
2018-12-17 22:14:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(options);
|
|
|
|
};
|
2020-01-08 06:57:23 -05:00
|
|
|
}
|
2018-12-17 22:14:52 -05:00
|
|
|
|
|
|
|
/* harmony default export */ var preloading = (createPreloadingMiddleware);
|
|
|
|
|
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
|
2018-12-13 23:53:54 -05:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2020-06-26 09:33:47 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply query arguments to both URL and Path, whichever is present.
|
|
|
|
*
|
|
|
|
* @param {import('../types').APIFetchOptions} props
|
2021-11-08 09:29:21 -05:00
|
|
|
* @param {Record<string, string | number>} queryArgs
|
2021-04-15 11:19:43 -04:00
|
|
|
* @return {import('../types').APIFetchOptions} The request with the modified query args
|
|
|
|
*/
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2021-11-15 07:50:17 -05:00
|
|
|
const modifyQuery = (_ref, queryArgs) => {
|
|
|
|
let {
|
|
|
|
path,
|
|
|
|
url,
|
|
|
|
...options
|
|
|
|
} = _ref;
|
|
|
|
return { ...options,
|
|
|
|
url: url && Object(external_wp_url_["addQueryArgs"])(url, queryArgs),
|
|
|
|
path: path && Object(external_wp_url_["addQueryArgs"])(path, queryArgs)
|
|
|
|
};
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Duplicates parsing functionality from apiFetch.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {Promise<any>} Parsed response json.
|
|
|
|
*/
|
2018-12-13 23:53:54 -05:00
|
|
|
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const parseResponse = response => response.json ? response.json() : Promise.reject(response);
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string | null} linkHeader
|
|
|
|
* @return {{ next?: string }} The parsed link header.
|
|
|
|
*/
|
|
|
|
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const parseLinkHeader = linkHeader => {
|
2018-12-13 23:53:54 -05:00
|
|
|
if (!linkHeader) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const match = linkHeader.match(/<([^>]+)>; rel="next"/);
|
2018-12-13 23:53:54 -05:00
|
|
|
return match ? {
|
|
|
|
next: match[1]
|
|
|
|
} : {};
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {string | undefined} The next page URL.
|
|
|
|
*/
|
|
|
|
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const getNextPageUrl = response => {
|
|
|
|
const {
|
|
|
|
next
|
|
|
|
} = parseLinkHeader(response.headers.get('link'));
|
2018-12-13 23:53:54 -05:00
|
|
|
return next;
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {import('../types').APIFetchOptions} options
|
|
|
|
* @return {boolean} True if the request contains an unbounded query.
|
|
|
|
*/
|
|
|
|
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const requestContainsUnboundedQuery = options => {
|
|
|
|
const pathIsUnbounded = !!options.path && options.path.indexOf('per_page=-1') !== -1;
|
|
|
|
const urlIsUnbounded = !!options.url && options.url.indexOf('per_page=-1') !== -1;
|
2018-12-13 23:53:54 -05:00
|
|
|
return pathIsUnbounded || urlIsUnbounded;
|
2021-04-15 11:19:43 -04:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* The REST API enforces an upper limit on the per_page option. To handle large
|
|
|
|
* collections, apiFetch consumers can pass `per_page=-1`; this middleware will
|
|
|
|
* then recursively assemble a full response array from all available pages.
|
|
|
|
*
|
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
|
|
*/
|
2018-12-13 23:53:54 -05:00
|
|
|
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const fetchAllMiddleware = async (options, next) => {
|
|
|
|
if (options.parse === false) {
|
|
|
|
// If a consumer has opted out of parsing, do not apply middleware.
|
|
|
|
return next(options);
|
|
|
|
}
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
if (!requestContainsUnboundedQuery(options)) {
|
|
|
|
// If neither url nor path is requesting all items, do not apply middleware.
|
|
|
|
return next(options);
|
|
|
|
} // Retrieve requested page of results.
|
2018-12-13 23:53:54 -05:00
|
|
|
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const response = await build_module({ ...modifyQuery(options, {
|
|
|
|
per_page: 100
|
|
|
|
}),
|
|
|
|
// Ensure headers are returned for page 1.
|
|
|
|
parse: false
|
|
|
|
});
|
|
|
|
const results = await parseResponse(response);
|
|
|
|
|
|
|
|
if (!Array.isArray(results)) {
|
|
|
|
// We have no reliable way of merging non-array results.
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
|
|
let nextPage = getNextPageUrl(response);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
if (!nextPage) {
|
|
|
|
// There are no further pages to request.
|
|
|
|
return results;
|
|
|
|
} // Iteratively fetch all remaining pages until no "next" header is found.
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2020-02-06 16:03:31 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
let mergedResults =
|
|
|
|
/** @type {any[]} */
|
|
|
|
[].concat(results);
|
|
|
|
|
|
|
|
while (nextPage) {
|
|
|
|
const nextResponse = await build_module({ ...options,
|
|
|
|
// Ensure the URL for the next page is used instead of any provided path.
|
|
|
|
path: undefined,
|
|
|
|
url: nextPage,
|
|
|
|
// Ensure we still get headers so we can identify the next page.
|
|
|
|
parse: false
|
|
|
|
});
|
|
|
|
const nextResults = await parseResponse(nextResponse);
|
|
|
|
mergedResults = mergedResults.concat(nextResults);
|
|
|
|
nextPage = getNextPageUrl(nextResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mergedResults;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware);
|
2020-02-06 16:03:31 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
|
2018-12-16 23:52:00 -05:00
|
|
|
/**
|
|
|
|
* Set of HTTP methods which are eligible to be overridden.
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @type {Set<string>}
|
2018-12-16 23:52:00 -05:00
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
|
2018-12-16 23:52:00 -05:00
|
|
|
/**
|
|
|
|
* Default request method.
|
|
|
|
*
|
|
|
|
* "A request has an associated method (a method). Unless stated otherwise it
|
|
|
|
* is `GET`."
|
|
|
|
*
|
|
|
|
* @see https://fetch.spec.whatwg.org/#requests
|
|
|
|
*
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const DEFAULT_METHOD = 'GET';
|
2018-12-16 23:52:00 -05:00
|
|
|
/**
|
|
|
|
* API Fetch middleware which overrides the request method for HTTP v1
|
|
|
|
* compatibility leveraging the REST API X-HTTP-Method-Override header.
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
2018-12-16 23:52:00 -05:00
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const httpV1Middleware = (options, next) => {
|
|
|
|
const {
|
|
|
|
method = DEFAULT_METHOD
|
|
|
|
} = options;
|
2018-12-16 23:52:00 -05:00
|
|
|
|
|
|
|
if (OVERRIDE_METHODS.has(method.toUpperCase())) {
|
2021-05-19 11:09:27 -04:00
|
|
|
options = { ...options,
|
|
|
|
headers: { ...options.headers,
|
2018-12-16 23:52:00 -05:00
|
|
|
'X-HTTP-Method-Override': method,
|
|
|
|
'Content-Type': 'application/json'
|
2021-05-19 11:09:27 -04:00
|
|
|
},
|
2018-12-16 23:52:00 -05:00
|
|
|
method: 'POST'
|
2021-05-19 11:09:27 -04:00
|
|
|
};
|
2018-12-13 23:41:57 -05:00
|
|
|
}
|
|
|
|
|
2020-10-13 09:10:30 -04:00
|
|
|
return next(options);
|
2021-04-15 11:19:43 -04:00
|
|
|
};
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
/* harmony default export */ var http_v1 = (httpV1Middleware);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const userLocaleMiddleware = (options, next) => {
|
2021-01-27 21:04:13 -05:00
|
|
|
if (typeof options.url === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.url, '_locale')) {
|
|
|
|
options.url = Object(external_wp_url_["addQueryArgs"])(options.url, {
|
2018-12-17 22:14:52 -05:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-01-27 21:04:13 -05:00
|
|
|
if (typeof options.path === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.path, '_locale')) {
|
|
|
|
options.path = Object(external_wp_url_["addQueryArgs"])(options.path, {
|
2018-12-17 22:14:52 -05:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2020-10-13 09:10:30 -04:00
|
|
|
return next(options);
|
2021-04-15 11:19:43 -04:00
|
|
|
};
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
/* harmony default export */ var user_locale = (userLocaleMiddleware);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the apiFetch response.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @param {boolean} shouldParseResponse
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @return {Promise<any> | null | Response} Parsed response.
|
2019-10-15 12:17:12 -04:00
|
|
|
*/
|
|
|
|
|
2021-11-15 07:50:17 -05:00
|
|
|
const response_parseResponse = function (response) {
|
|
|
|
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
if (shouldParseResponse) {
|
|
|
|
if (response.status === 204) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
return response.json ? response.json() : Promise.reject(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Calls the `json` function on the Response, throwing an error if the response
|
|
|
|
* doesn't have a json function or if parsing the json itself fails.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {Promise<any>} Parsed response.
|
|
|
|
*/
|
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const parseJsonAndNormalizeError = response => {
|
|
|
|
const invalidJsonError = {
|
2019-10-15 12:17:12 -04:00
|
|
|
code: 'invalid_json',
|
2021-01-27 21:04:13 -05:00
|
|
|
message: Object(external_wp_i18n_["__"])('The response is not a valid JSON response.')
|
2019-10-15 12:17:12 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!response || !response.json) {
|
|
|
|
throw invalidJsonError;
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
return response.json().catch(() => {
|
2019-10-15 12:17:12 -04:00
|
|
|
throw invalidJsonError;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Parses the apiFetch response properly and normalize response errors.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @param {boolean} shouldParseResponse
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @return {Promise<any>} Parsed response.
|
2019-10-15 12:17:12 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-11-15 07:50:17 -05:00
|
|
|
const parseResponseAndNormalizeError = function (response) {
|
|
|
|
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
2021-05-19 11:09:27 -04:00
|
|
|
return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
|
2019-10-15 12:17:12 -04:00
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Parses a response, throwing an error if parsing the response fails.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
2021-11-08 09:29:21 -05:00
|
|
|
* @param {boolean} shouldParseResponse
|
2021-04-15 11:19:43 -04:00
|
|
|
* @return {Promise<any>} Parsed response.
|
|
|
|
*/
|
|
|
|
|
2021-11-15 07:50:17 -05:00
|
|
|
function parseAndThrowError(response) {
|
|
|
|
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
if (!shouldParseResponse) {
|
|
|
|
throw response;
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
return parseJsonAndNormalizeError(response).then(error => {
|
|
|
|
const unknownError = {
|
2019-10-15 12:17:12 -04:00
|
|
|
code: 'unknown_error',
|
2021-01-27 21:04:13 -05:00
|
|
|
message: Object(external_wp_i18n_["__"])('An unknown error occurred.')
|
2019-10-15 12:17:12 -04:00
|
|
|
};
|
|
|
|
throw error || unknownError;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
|
2018-12-17 22:14:52 -05:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-11-08 09:29:21 -05:00
|
|
|
/**
|
|
|
|
* @param {import('../types').APIFetchOptions} options
|
|
|
|
* @return {boolean} True if the request is for media upload.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function isMediaUploadRequest(options) {
|
|
|
|
const isCreateMethod = !!options.method && options.method === 'POST';
|
|
|
|
const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
|
|
|
|
return isMediaEndpoint && isCreateMethod;
|
|
|
|
}
|
2019-10-15 12:17:12 -04:00
|
|
|
/**
|
|
|
|
* Middleware handling media upload failures and retries.
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
2019-10-15 12:17:12 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-11-08 09:29:21 -05:00
|
|
|
const mediaUploadMiddleware = (options, next) => {
|
|
|
|
if (!isMediaUploadRequest(options)) {
|
2021-04-15 11:19:43 -04:00
|
|
|
return next(options);
|
2019-10-15 12:17:12 -04:00
|
|
|
}
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
let retries = 0;
|
|
|
|
const maxRetries = 5;
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string} attachmentId
|
|
|
|
* @return {Promise<any>} Processed post response.
|
|
|
|
*/
|
2019-10-15 12:17:12 -04:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const postProcess = attachmentId => {
|
2019-10-15 12:17:12 -04:00
|
|
|
retries++;
|
|
|
|
return next({
|
2021-05-19 11:09:27 -04:00
|
|
|
path: `/wp/v2/media/${attachmentId}/post-process`,
|
2019-10-15 12:17:12 -04:00
|
|
|
method: 'POST',
|
|
|
|
data: {
|
|
|
|
action: 'create-image-subsizes'
|
|
|
|
},
|
|
|
|
parse: false
|
2021-05-19 11:09:27 -04:00
|
|
|
}).catch(() => {
|
2019-10-15 12:17:12 -04:00
|
|
|
if (retries < maxRetries) {
|
|
|
|
return postProcess(attachmentId);
|
|
|
|
}
|
|
|
|
|
|
|
|
next({
|
2021-05-19 11:09:27 -04:00
|
|
|
path: `/wp/v2/media/${attachmentId}?force=true`,
|
2019-10-15 12:17:12 -04:00
|
|
|
method: 'DELETE'
|
|
|
|
});
|
|
|
|
return Promise.reject();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
return next({ ...options,
|
2019-10-15 12:17:12 -04:00
|
|
|
parse: false
|
2021-05-19 11:09:27 -04:00
|
|
|
}).catch(response => {
|
|
|
|
const attachmentId = response.headers.get('x-wp-upload-attachment-id');
|
2019-10-15 12:17:12 -04:00
|
|
|
|
2019-10-28 10:13:09 -04:00
|
|
|
if (response.status >= 500 && response.status < 600 && attachmentId) {
|
2021-05-19 11:09:27 -04:00
|
|
|
return postProcess(attachmentId).catch(() => {
|
2019-10-15 12:17:12 -04:00
|
|
|
if (options.parse !== false) {
|
|
|
|
return Promise.reject({
|
|
|
|
code: 'post_process',
|
2021-01-27 21:04:13 -05:00
|
|
|
message: Object(external_wp_i18n_["__"])('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
|
2019-10-15 12:17:12 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseAndThrowError(response, options.parse);
|
2021-05-19 11:09:27 -04:00
|
|
|
}).then(response => parseResponseAndNormalizeError(response, options.parse));
|
2021-04-15 11:19:43 -04:00
|
|
|
};
|
2019-10-15 12:17:12 -04:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
/* harmony default export */ var media_upload = (mediaUploadMiddleware);
|
2019-10-15 12:17:12 -04:00
|
|
|
|
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
|
2020-01-08 06:57:23 -05:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-13 23:41:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 06:57:23 -05:00
|
|
|
|
2018-12-13 23:41:57 -05:00
|
|
|
/**
|
2018-12-17 22:14:52 -05:00
|
|
|
* Default set of header values which should be sent with every request unless
|
|
|
|
* explicitly provided through apiFetch options.
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @type {Record<string, string>}
|
2018-12-13 23:41:57 -05:00
|
|
|
*/
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const DEFAULT_HEADERS = {
|
2018-12-17 22:14:52 -05:00
|
|
|
// The backend uses the Accept header as a condition for considering an
|
|
|
|
// incoming request as a REST request.
|
|
|
|
//
|
|
|
|
// See: https://core.trac.wordpress.org/ticket/44534
|
|
|
|
Accept: 'application/json, */*;q=0.1'
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Default set of fetch option values which should be sent with every request
|
|
|
|
* unless explicitly provided through apiFetch options.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const DEFAULT_OPTIONS = {
|
2018-12-17 22:14:52 -05:00
|
|
|
credentials: 'include'
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */
|
|
|
|
|
|
|
|
/** @typedef {import('./types').APIFetchOptions} APIFetchOptions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {import('./types').APIFetchMiddleware[]}
|
|
|
|
*/
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware];
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Register a middleware
|
|
|
|
*
|
|
|
|
* @param {import('./types').APIFetchMiddleware} middleware
|
|
|
|
*/
|
2018-12-16 23:52:00 -05:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
function registerMiddleware(middleware) {
|
2019-03-07 04:09:59 -05:00
|
|
|
middlewares.unshift(middleware);
|
2018-12-17 22:14:52 -05:00
|
|
|
}
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Checks the status of a response, throwing the Response as an error if
|
|
|
|
* it is outside the 200 range.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {Response} The response if the status is in the 200 range.
|
|
|
|
*/
|
|
|
|
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const checkStatus = response => {
|
2019-09-19 11:19:18 -04:00
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw response;
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {FetchHandler}
|
|
|
|
*/
|
|
|
|
|
2019-09-19 11:19:18 -04:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const defaultFetchHandler = nextOptions => {
|
|
|
|
const {
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
data,
|
|
|
|
parse = true,
|
|
|
|
...remainingOptions
|
|
|
|
} = nextOptions;
|
|
|
|
let {
|
|
|
|
body,
|
|
|
|
headers
|
|
|
|
} = nextOptions; // Merge explicitly-provided headers with default values.
|
2019-03-07 04:09:59 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
headers = { ...DEFAULT_HEADERS,
|
|
|
|
...headers
|
|
|
|
}; // The `data` property is a shorthand for sending a JSON body.
|
2019-03-07 04:09:59 -05:00
|
|
|
|
|
|
|
if (data) {
|
|
|
|
body = JSON.stringify(data);
|
|
|
|
headers['Content-Type'] = 'application/json';
|
|
|
|
}
|
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
const responsePromise = window.fetch( // fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed
|
|
|
|
url || path || window.location.href, { ...DEFAULT_OPTIONS,
|
|
|
|
...remainingOptions,
|
|
|
|
body,
|
|
|
|
headers
|
|
|
|
});
|
2021-11-08 09:29:21 -05:00
|
|
|
return responsePromise.then(value => Promise.resolve(value).then(checkStatus).catch(response => parseAndThrowError(response, parse)).then(response => parseResponseAndNormalizeError(response, parse)), err => {
|
|
|
|
// Re-throw AbortError for the users to handle it themselves.
|
|
|
|
if (err && err.name === 'AbortError') {
|
|
|
|
throw err;
|
|
|
|
} // Otherwise, there is most likely no network connection.
|
|
|
|
// Unfortunately the message might depend on the browser.
|
|
|
|
|
|
|
|
|
2020-01-08 06:57:23 -05:00
|
|
|
throw {
|
|
|
|
code: 'fetch_error',
|
2021-01-27 21:04:13 -05:00
|
|
|
message: Object(external_wp_i18n_["__"])('You are probably offline.')
|
2020-01-08 06:57:23 -05:00
|
|
|
};
|
2019-03-07 04:09:59 -05:00
|
|
|
});
|
|
|
|
};
|
2021-04-15 11:19:43 -04:00
|
|
|
/** @type {FetchHandler} */
|
|
|
|
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2021-05-19 11:09:27 -04:00
|
|
|
let fetchHandler = defaultFetchHandler;
|
2019-03-07 04:09:59 -05:00
|
|
|
/**
|
|
|
|
* Defines a custom fetch handler for making the requests that will override
|
|
|
|
* the default one using window.fetch
|
|
|
|
*
|
2021-04-15 11:19:43 -04:00
|
|
|
* @param {FetchHandler} newFetchHandler The new fetch handler
|
2019-03-07 04:09:59 -05:00
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2019-03-07 04:09:59 -05:00
|
|
|
function setFetchHandler(newFetchHandler) {
|
|
|
|
fetchHandler = newFetchHandler;
|
|
|
|
}
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @template T
|
|
|
|
* @param {import('./types').APIFetchOptions} options
|
|
|
|
* @return {Promise<T>} A promise representing the request processed via the registered middlewares.
|
|
|
|
*/
|
|
|
|
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2019-03-07 04:09:59 -05:00
|
|
|
function apiFetch(options) {
|
2020-10-13 09:10:30 -04:00
|
|
|
// creates a nested function chain that calls all middlewares and finally the `fetchHandler`,
|
|
|
|
// converting `middlewares = [ m1, m2, m3 ]` into:
|
|
|
|
// ```
|
|
|
|
// opts1 => m1( opts1, opts2 => m2( opts2, opts3 => m3( opts3, fetchHandler ) ) );
|
|
|
|
// ```
|
2021-05-19 11:09:27 -04:00
|
|
|
const enhancedHandler = middlewares.reduceRight((
|
2021-04-15 11:19:43 -04:00
|
|
|
/** @type {FetchHandler} */
|
2021-05-19 11:09:27 -04:00
|
|
|
next, middleware) => {
|
|
|
|
return workingOptions => middleware(workingOptions, next);
|
2020-10-13 09:10:30 -04:00
|
|
|
}, fetchHandler);
|
2021-05-19 11:09:27 -04:00
|
|
|
return enhancedHandler(options).catch(error => {
|
2020-10-13 09:10:30 -04:00
|
|
|
if (error.code !== 'rest_cookie_invalid_nonce') {
|
|
|
|
return Promise.reject(error);
|
|
|
|
} // If the nonce is invalid, refresh it and try again.
|
|
|
|
|
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
return window // @ts-ignore
|
2021-05-19 11:09:27 -04:00
|
|
|
.fetch(apiFetch.nonceEndpoint).then(checkStatus).then(data => data.text()).then(text => {
|
2021-04-15 11:19:43 -04:00
|
|
|
// @ts-ignore
|
2020-10-13 09:10:30 -04:00
|
|
|
apiFetch.nonceMiddleware.nonce = text;
|
|
|
|
return apiFetch(options);
|
2019-09-19 11:19:18 -04:00
|
|
|
});
|
|
|
|
});
|
2018-12-17 22:14:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
apiFetch.use = registerMiddleware;
|
2019-03-07 04:09:59 -05:00
|
|
|
apiFetch.setFetchHandler = setFetchHandler;
|
2020-02-06 16:03:31 -05:00
|
|
|
apiFetch.createNonceMiddleware = nonce;
|
2018-12-17 22:14:52 -05:00
|
|
|
apiFetch.createPreloadingMiddleware = preloading;
|
|
|
|
apiFetch.createRootURLMiddleware = root_url;
|
|
|
|
apiFetch.fetchAllMiddleware = fetch_all_middleware;
|
2019-10-15 12:17:12 -04:00
|
|
|
apiFetch.mediaUploadMiddleware = media_upload;
|
2018-12-17 22:14:52 -05:00
|
|
|
/* harmony default export */ var build_module = __webpack_exports__["default"] = (apiFetch);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
|
|
|
|
2021-05-20 08:20:04 -04:00
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
/***/ "l3Sj":
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
(function() { module.exports = window["wp"]["i18n"]; }());
|
|
|
|
|
2018-12-13 23:41:57 -05:00
|
|
|
/***/ })
|
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
/******/ })["default"];
|