2018-12-14 05:41:57 +01: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 14:20:04 +02:00
|
|
|
/******/ return __webpack_require__(__webpack_require__.s = "jqrR");
|
2018-12-14 05:41:57 +01:00
|
|
|
/******/ })
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ ({
|
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/***/ "Mmq9":
|
2019-04-22 14:40:04 +02:00
|
|
|
/***/ (function(module, exports) {
|
2019-03-21 13:48:00 +01:00
|
|
|
|
2021-01-28 03:04:13 +01:00
|
|
|
(function() { module.exports = window["wp"]["url"]; }());
|
2019-03-21 13:48:00 +01:00
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/***/ "jqrR":
|
2018-12-14 05:41:57 +01:00
|
|
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
|
|
|
|
|
|
"use strict";
|
2020-06-29 13:50:29 +02:00
|
|
|
// ESM COMPAT FLAG
|
2018-12-14 05:41:57 +01:00
|
|
|
__webpack_require__.r(__webpack_exports__);
|
|
|
|
|
2021-01-28 03:04:13 +01:00
|
|
|
// EXTERNAL MODULE: external ["wp","i18n"]
|
2021-05-20 14:20:04 +02:00
|
|
|
var external_wp_i18n_ = __webpack_require__("l3Sj");
|
2020-01-08 12:57:23 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {string} nonce
|
|
|
|
* @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce.
|
|
|
|
*/
|
2019-03-07 10:09:59 +01:00
|
|
|
function createNonceMiddleware(nonce) {
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware & { nonce: string }}
|
|
|
|
*/
|
2021-05-19 17:09:27 +02:00
|
|
|
const middleware = (options, next) => {
|
|
|
|
const {
|
|
|
|
headers = {}
|
|
|
|
} = options; // If an 'X-WP-Nonce' header (or any case-insensitive variation
|
2018-12-18 04:14:52 +01:00
|
|
|
// thereof) was specified, no need to add a nonce header.
|
2018-12-17 05:52:00 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
for (const headerName in headers) {
|
2020-10-13 15:10:30 +02:00
|
|
|
if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) {
|
2019-03-07 10:09:59 +01:00
|
|
|
return next(options);
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
return next({ ...options,
|
|
|
|
headers: { ...headers,
|
2019-03-07 10:09:59 +01:00
|
|
|
'X-WP-Nonce': middleware.nonce
|
2021-05-19 17:09:27 +02:00
|
|
|
}
|
|
|
|
});
|
2021-04-15 17:19:43 +02:00
|
|
|
};
|
2019-03-07 10:09:59 +01:00
|
|
|
|
|
|
|
middleware.nonce = nonce;
|
|
|
|
return middleware;
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2020-02-06 22:03:31 +01:00
|
|
|
/* harmony default export */ var nonce = (createNonceMiddleware);
|
2018-12-15 12:00:40 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
|
|
*/
|
2021-05-19 17:09:27 +02:00
|
|
|
const namespaceAndEndpointMiddleware = (options, next) => {
|
|
|
|
let path = options.path;
|
|
|
|
let namespaceTrimmed, endpointTrimmed;
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
|
|
|
|
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
|
|
|
|
endpointTrimmed = options.endpoint.replace(/^\//, '');
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
if (endpointTrimmed) {
|
|
|
|
path = namespaceTrimmed + '/' + endpointTrimmed;
|
|
|
|
} else {
|
|
|
|
path = namespaceTrimmed;
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 05:52:00 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
delete options.namespace;
|
|
|
|
delete options.endpoint;
|
2021-05-19 17:09:27 +02:00
|
|
|
return next({ ...options,
|
|
|
|
path
|
|
|
|
});
|
2018-12-18 04:14:52 +01:00
|
|
|
};
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2020-02-06 22:03:31 +01:00
|
|
|
/* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {string} rootURL
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Root URL middleware.
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const createRootURLMiddleware = rootURL => (options, next) => {
|
|
|
|
return namespace_endpoint(options, optionsWithPath => {
|
|
|
|
let url = optionsWithPath.url;
|
|
|
|
let path = optionsWithPath.path;
|
|
|
|
let apiRoot;
|
2018-12-14 05:53:54 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
if (typeof path === 'string') {
|
|
|
|
apiRoot = rootURL;
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
if (-1 !== rootURL.indexOf('?')) {
|
|
|
|
path = path.replace('?', '&');
|
|
|
|
}
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
path = path.replace(/^\//, ''); // API root may already include query parameter prefix if site is
|
|
|
|
// configured to use plain permalinks.
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
|
|
|
|
path = path.replace('?', '&');
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
url = apiRoot + path;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next({ ...optionsWithPath,
|
|
|
|
url
|
2018-12-18 04:14:52 +01:00
|
|
|
});
|
2021-05-19 17:09:27 +02:00
|
|
|
});
|
2018-12-18 04:14:52 +01:00
|
|
|
};
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
/* harmony default export */ var root_url = (createRootURLMiddleware);
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
// EXTERNAL MODULE: external ["wp","url"]
|
|
|
|
var external_wp_url_ = __webpack_require__("Mmq9");
|
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
|
2020-01-08 12:57:23 +01:00
|
|
|
/**
|
2021-11-08 15:29:21 +01:00
|
|
|
* WordPress dependencies
|
2020-01-08 12:57:23 +01:00
|
|
|
*/
|
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {Record<string, any>} preloadedData
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
|
|
|
|
*/
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2020-01-08 12:57:23 +01:00
|
|
|
function createPreloadingMiddleware(preloadedData) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const cache = Object.keys(preloadedData).reduce((result, path) => {
|
2021-11-08 15:29:21 +01:00
|
|
|
result[Object(external_wp_url_["normalizePath"])(path)] = preloadedData[path];
|
2020-01-08 12:57:23 +01:00
|
|
|
return result;
|
2021-04-15 17:19:43 +02:00
|
|
|
},
|
|
|
|
/** @type {Record<string, any>} */
|
|
|
|
{});
|
2021-05-19 17:09:27 +02:00
|
|
|
return (options, next) => {
|
|
|
|
const {
|
|
|
|
parse = true
|
|
|
|
} = options;
|
2021-11-08 15:29:21 +01: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-18 04:14:52 +01:00
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
if (typeof rawPath === 'string') {
|
2021-05-19 17:09:27 +02:00
|
|
|
const method = options.method || 'GET';
|
2021-11-08 15:29:21 +01:00
|
|
|
const path = Object(external_wp_url_["normalizePath"])(rawPath);
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
if ('GET' === method && cache[path]) {
|
2021-11-08 15:29:21 +01:00
|
|
|
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time
|
2020-10-13 15:10:30 +02: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 12:57:23 +01:00
|
|
|
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
|
2021-11-08 15:29:21 +01: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-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(options);
|
|
|
|
};
|
2020-01-08 12:57:23 +01:00
|
|
|
}
|
2018-12-18 04:14:52 +01:00
|
|
|
|
|
|
|
/* harmony default export */ var preloading = (createPreloadingMiddleware);
|
|
|
|
|
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
|
2018-12-14 05:53:54 +01:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2020-06-26 15:33:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply query arguments to both URL and Path, whichever is present.
|
|
|
|
*
|
|
|
|
* @param {import('../types').APIFetchOptions} props
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {Record<string, string | number>} queryArgs
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {import('../types').APIFetchOptions} The request with the modified query args
|
|
|
|
*/
|
2018-12-14 05:53:54 +01:00
|
|
|
|
2021-11-15 13:50:17 +01: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 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Duplicates parsing functionality from apiFetch.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {Promise<any>} Parsed response json.
|
|
|
|
*/
|
2018-12-14 05:53:54 +01:00
|
|
|
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const parseResponse = response => response.json ? response.json() : Promise.reject(response);
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {string | null} linkHeader
|
|
|
|
* @return {{ next?: string }} The parsed link header.
|
|
|
|
*/
|
|
|
|
|
2018-12-14 05:53:54 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const parseLinkHeader = linkHeader => {
|
2018-12-14 05:53:54 +01:00
|
|
|
if (!linkHeader) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const match = linkHeader.match(/<([^>]+)>; rel="next"/);
|
2018-12-14 05:53:54 +01:00
|
|
|
return match ? {
|
|
|
|
next: match[1]
|
|
|
|
} : {};
|
|
|
|
};
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {string | undefined} The next page URL.
|
|
|
|
*/
|
|
|
|
|
2018-12-14 05:53:54 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const getNextPageUrl = response => {
|
|
|
|
const {
|
|
|
|
next
|
|
|
|
} = parseLinkHeader(response.headers.get('link'));
|
2018-12-14 05:53:54 +01:00
|
|
|
return next;
|
|
|
|
};
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {import('../types').APIFetchOptions} options
|
|
|
|
* @return {boolean} True if the request contains an unbounded query.
|
|
|
|
*/
|
|
|
|
|
2018-12-14 05:53:54 +01:00
|
|
|
|
2021-05-19 17:09:27 +02: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-14 05:53:54 +01:00
|
|
|
return pathIsUnbounded || urlIsUnbounded;
|
2021-04-15 17:19:43 +02: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-14 05:53:54 +01:00
|
|
|
|
|
|
|
|
2021-05-19 17:09:27 +02: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-14 05:53:54 +01:00
|
|
|
|
2021-05-19 17:09:27 +02: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-14 05:53:54 +01:00
|
|
|
|
|
|
|
|
2021-05-19 17:09:27 +02: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-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02: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-14 05:41:57 +01:00
|
|
|
|
2020-02-06 22:03:31 +01:00
|
|
|
|
2021-05-19 17:09:27 +02: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 22:03:31 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
|
2018-12-17 05:52:00 +01:00
|
|
|
/**
|
|
|
|
* Set of HTTP methods which are eligible to be overridden.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @type {Set<string>}
|
2018-12-17 05:52:00 +01:00
|
|
|
*/
|
2021-05-19 17:09:27 +02:00
|
|
|
const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
|
2018-12-17 05:52:00 +01: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-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const DEFAULT_METHOD = 'GET';
|
2018-12-17 05:52:00 +01: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 17:19:43 +02:00
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
2018-12-17 05:52:00 +01:00
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const httpV1Middleware = (options, next) => {
|
|
|
|
const {
|
|
|
|
method = DEFAULT_METHOD
|
|
|
|
} = options;
|
2018-12-17 05:52:00 +01:00
|
|
|
|
|
|
|
if (OVERRIDE_METHODS.has(method.toUpperCase())) {
|
2021-05-19 17:09:27 +02:00
|
|
|
options = { ...options,
|
|
|
|
headers: { ...options.headers,
|
2018-12-17 05:52:00 +01:00
|
|
|
'X-HTTP-Method-Override': method,
|
|
|
|
'Content-Type': 'application/json'
|
2021-05-19 17:09:27 +02:00
|
|
|
},
|
2018-12-17 05:52:00 +01:00
|
|
|
method: 'POST'
|
2021-05-19 17:09:27 +02:00
|
|
|
};
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
return next(options);
|
2021-04-15 17:19:43 +02:00
|
|
|
};
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/* harmony default export */ var http_v1 = (httpV1Middleware);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const userLocaleMiddleware = (options, next) => {
|
2021-01-28 03:04:13 +01: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-18 04:14:52 +01:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-01-28 03:04:13 +01: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-18 04:14:52 +01:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
return next(options);
|
2021-04-15 17:19:43 +02:00
|
|
|
};
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
/* harmony default export */ var user_locale = (userLocaleMiddleware);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2019-10-15 18:17:12 +02: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 17:19:43 +02:00
|
|
|
* @return {Promise<any> | null | Response} Parsed response.
|
2019-10-15 18:17:12 +02:00
|
|
|
*/
|
|
|
|
|
2021-11-15 13:50:17 +01:00
|
|
|
const response_parseResponse = function (response) {
|
|
|
|
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
|
|
|
2019-10-15 18:17:12 +02:00
|
|
|
if (shouldParseResponse) {
|
|
|
|
if (response.status === 204) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2019-10-15 18:17:12 +02:00
|
|
|
return response.json ? response.json() : Promise.reject(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
return response;
|
|
|
|
};
|
2021-04-15 17:19:43 +02: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 18:17:12 +02:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const parseJsonAndNormalizeError = response => {
|
|
|
|
const invalidJsonError = {
|
2019-10-15 18:17:12 +02:00
|
|
|
code: 'invalid_json',
|
2021-01-28 03:04:13 +01:00
|
|
|
message: Object(external_wp_i18n_["__"])('The response is not a valid JSON response.')
|
2019-10-15 18:17:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!response || !response.json) {
|
|
|
|
throw invalidJsonError;
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
return response.json().catch(() => {
|
2019-10-15 18:17:12 +02:00
|
|
|
throw invalidJsonError;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Parses the apiFetch response properly and normalize response errors.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @param {boolean} shouldParseResponse
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {Promise<any>} Parsed response.
|
2019-10-15 18:17:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-11-15 13:50:17 +01:00
|
|
|
const parseResponseAndNormalizeError = function (response) {
|
|
|
|
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
2021-05-19 17:09:27 +02:00
|
|
|
return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
|
2019-10-15 18:17:12 +02:00
|
|
|
};
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Parses a response, throwing an error if parsing the response fails.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {boolean} shouldParseResponse
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {Promise<any>} Parsed response.
|
|
|
|
*/
|
|
|
|
|
2021-11-15 13:50:17 +01:00
|
|
|
function parseAndThrowError(response) {
|
|
|
|
let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
|
|
|
2019-10-15 18:17:12 +02:00
|
|
|
if (!shouldParseResponse) {
|
|
|
|
throw response;
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
return parseJsonAndNormalizeError(response).then(error => {
|
|
|
|
const unknownError = {
|
2019-10-15 18:17:12 +02:00
|
|
|
code: 'unknown_error',
|
2021-01-28 03:04:13 +01:00
|
|
|
message: Object(external_wp_i18n_["__"])('An unknown error occurred.')
|
2019-10-15 18:17:12 +02:00
|
|
|
};
|
|
|
|
throw error || unknownError;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-11-08 15:29:21 +01: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 18:17:12 +02:00
|
|
|
/**
|
|
|
|
* Middleware handling media upload failures and retries.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
2019-10-15 18:17:12 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
const mediaUploadMiddleware = (options, next) => {
|
|
|
|
if (!isMediaUploadRequest(options)) {
|
2021-04-15 17:19:43 +02:00
|
|
|
return next(options);
|
2019-10-15 18:17:12 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
let retries = 0;
|
|
|
|
const maxRetries = 5;
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {string} attachmentId
|
|
|
|
* @return {Promise<any>} Processed post response.
|
|
|
|
*/
|
2019-10-15 18:17:12 +02:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const postProcess = attachmentId => {
|
2019-10-15 18:17:12 +02:00
|
|
|
retries++;
|
|
|
|
return next({
|
2021-05-19 17:09:27 +02:00
|
|
|
path: `/wp/v2/media/${attachmentId}/post-process`,
|
2019-10-15 18:17:12 +02:00
|
|
|
method: 'POST',
|
|
|
|
data: {
|
|
|
|
action: 'create-image-subsizes'
|
|
|
|
},
|
|
|
|
parse: false
|
2021-05-19 17:09:27 +02:00
|
|
|
}).catch(() => {
|
2019-10-15 18:17:12 +02:00
|
|
|
if (retries < maxRetries) {
|
|
|
|
return postProcess(attachmentId);
|
|
|
|
}
|
|
|
|
|
|
|
|
next({
|
2021-05-19 17:09:27 +02:00
|
|
|
path: `/wp/v2/media/${attachmentId}?force=true`,
|
2019-10-15 18:17:12 +02:00
|
|
|
method: 'DELETE'
|
|
|
|
});
|
|
|
|
return Promise.reject();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
return next({ ...options,
|
2019-10-15 18:17:12 +02:00
|
|
|
parse: false
|
2021-05-19 17:09:27 +02:00
|
|
|
}).catch(response => {
|
|
|
|
const attachmentId = response.headers.get('x-wp-upload-attachment-id');
|
2019-10-15 18:17:12 +02:00
|
|
|
|
2019-10-28 15:13:09 +01:00
|
|
|
if (response.status >= 500 && response.status < 600 && attachmentId) {
|
2021-05-19 17:09:27 +02:00
|
|
|
return postProcess(attachmentId).catch(() => {
|
2019-10-15 18:17:12 +02:00
|
|
|
if (options.parse !== false) {
|
|
|
|
return Promise.reject({
|
|
|
|
code: 'post_process',
|
2021-01-28 03:04:13 +01: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 18:17:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(response);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseAndThrowError(response, options.parse);
|
2021-05-19 17:09:27 +02:00
|
|
|
}).then(response => parseResponseAndNormalizeError(response, options.parse));
|
2021-04-15 17:19:43 +02:00
|
|
|
};
|
2019-10-15 18:17:12 +02:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
/* harmony default export */ var media_upload = (mediaUploadMiddleware);
|
2019-10-15 18:17:12 +02:00
|
|
|
|
|
|
|
// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
|
2020-01-08 12:57:23 +01:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2019-10-15 18:17:12 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-08 12:57:23 +01:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2018-12-18 04:14:52 +01:00
|
|
|
* Default set of header values which should be sent with every request unless
|
|
|
|
* explicitly provided through apiFetch options.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @type {Record<string, string>}
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const DEFAULT_HEADERS = {
|
2018-12-18 04:14:52 +01: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-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const DEFAULT_OPTIONS = {
|
2018-12-18 04:14:52 +01:00
|
|
|
credentials: 'include'
|
|
|
|
};
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */
|
|
|
|
|
|
|
|
/** @typedef {import('./types').APIFetchOptions} APIFetchOptions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {import('./types').APIFetchMiddleware[]}
|
|
|
|
*/
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware];
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Register a middleware
|
|
|
|
*
|
|
|
|
* @param {import('./types').APIFetchMiddleware} middleware
|
|
|
|
*/
|
2018-12-17 05:52:00 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
function registerMiddleware(middleware) {
|
2019-03-07 10:09:59 +01:00
|
|
|
middlewares.unshift(middleware);
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02: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-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
const checkStatus = response => {
|
2019-09-19 17:19:18 +02:00
|
|
|
if (response.status >= 200 && response.status < 300) {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw response;
|
|
|
|
};
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {FetchHandler}
|
|
|
|
*/
|
|
|
|
|
2019-09-19 17:19:18 +02:00
|
|
|
|
2021-05-19 17:09:27 +02: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 10:09:59 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
headers = { ...DEFAULT_HEADERS,
|
|
|
|
...headers
|
|
|
|
}; // The `data` property is a shorthand for sending a JSON body.
|
2019-03-07 10:09:59 +01:00
|
|
|
|
|
|
|
if (data) {
|
|
|
|
body = JSON.stringify(data);
|
|
|
|
headers['Content-Type'] = 'application/json';
|
|
|
|
}
|
|
|
|
|
2021-05-19 17:09:27 +02: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 15:29:21 +01: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 12:57:23 +01:00
|
|
|
throw {
|
|
|
|
code: 'fetch_error',
|
2021-01-28 03:04:13 +01:00
|
|
|
message: Object(external_wp_i18n_["__"])('You are probably offline.')
|
2020-01-08 12:57:23 +01:00
|
|
|
};
|
2019-03-07 10:09:59 +01:00
|
|
|
});
|
|
|
|
};
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @type {FetchHandler} */
|
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
let fetchHandler = defaultFetchHandler;
|
2019-03-07 10:09:59 +01:00
|
|
|
/**
|
|
|
|
* Defines a custom fetch handler for making the requests that will override
|
|
|
|
* the default one using window.fetch
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {FetchHandler} newFetchHandler The new fetch handler
|
2019-03-07 10:09:59 +01:00
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2019-03-07 10:09:59 +01:00
|
|
|
function setFetchHandler(newFetchHandler) {
|
|
|
|
fetchHandler = newFetchHandler;
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @template T
|
|
|
|
* @param {import('./types').APIFetchOptions} options
|
|
|
|
* @return {Promise<T>} A promise representing the request processed via the registered middlewares.
|
|
|
|
*/
|
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2019-03-07 10:09:59 +01:00
|
|
|
function apiFetch(options) {
|
2020-10-13 15:10:30 +02: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 17:09:27 +02:00
|
|
|
const enhancedHandler = middlewares.reduceRight((
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @type {FetchHandler} */
|
2021-05-19 17:09:27 +02:00
|
|
|
next, middleware) => {
|
|
|
|
return workingOptions => middleware(workingOptions, next);
|
2020-10-13 15:10:30 +02:00
|
|
|
}, fetchHandler);
|
2021-05-19 17:09:27 +02:00
|
|
|
return enhancedHandler(options).catch(error => {
|
2020-10-13 15:10:30 +02: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 17:19:43 +02:00
|
|
|
return window // @ts-ignore
|
2021-05-19 17:09:27 +02:00
|
|
|
.fetch(apiFetch.nonceEndpoint).then(checkStatus).then(data => data.text()).then(text => {
|
2021-04-15 17:19:43 +02:00
|
|
|
// @ts-ignore
|
2020-10-13 15:10:30 +02:00
|
|
|
apiFetch.nonceMiddleware.nonce = text;
|
|
|
|
return apiFetch(options);
|
2019-09-19 17:19:18 +02:00
|
|
|
});
|
|
|
|
});
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
apiFetch.use = registerMiddleware;
|
2019-03-07 10:09:59 +01:00
|
|
|
apiFetch.setFetchHandler = setFetchHandler;
|
2020-02-06 22:03:31 +01:00
|
|
|
apiFetch.createNonceMiddleware = nonce;
|
2018-12-18 04:14:52 +01:00
|
|
|
apiFetch.createPreloadingMiddleware = preloading;
|
|
|
|
apiFetch.createRootURLMiddleware = root_url;
|
|
|
|
apiFetch.fetchAllMiddleware = fetch_all_middleware;
|
2019-10-15 18:17:12 +02:00
|
|
|
apiFetch.mediaUploadMiddleware = media_upload;
|
2018-12-18 04:14:52 +01:00
|
|
|
/* harmony default export */ var build_module = __webpack_exports__["default"] = (apiFetch);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
|
|
|
|
2021-05-20 14:20:04 +02:00
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
/***/ "l3Sj":
|
|
|
|
/***/ (function(module, exports) {
|
|
|
|
|
|
|
|
(function() { module.exports = window["wp"]["i18n"]; }());
|
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/***/ })
|
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/******/ })["default"];
|