2022-04-11 14:04:30 +02:00
|
|
|
/******/ (function() { // webpackBootstrap
|
|
|
|
/******/ "use strict";
|
|
|
|
/******/ // The require scope
|
|
|
|
/******/ var __webpack_require__ = {};
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
|
|
|
/******/ !function() {
|
|
|
|
/******/ // define getter functions for harmony exports
|
|
|
|
/******/ __webpack_require__.d = function(exports, definition) {
|
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
2018-12-14 05:41:57 +01:00
|
|
|
/******/ };
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ }();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
|
|
/******/ !function() {
|
|
|
|
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
|
|
/******/ }();
|
|
|
|
/******/
|
2018-12-14 05:41:57 +01:00
|
|
|
/************************************************************************/
|
2022-04-11 14:04:30 +02:00
|
|
|
var __webpack_exports__ = {};
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
// EXPORTS
|
|
|
|
__webpack_require__.d(__webpack_exports__, {
|
|
|
|
"default": function() { return /* binding */ build_module; }
|
|
|
|
});
|
2020-01-08 12:57:23 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","i18n"]
|
|
|
|
var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
|
|
|
|
;// 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
|
|
|
|
2022-04-11 14:04:30 +02: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
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","url"]
|
|
|
|
var external_wp_url_namespaceObject = window["wp"]["url"];
|
|
|
|
;// 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) {
|
2022-04-12 17:12:47 +02:00
|
|
|
const cache = Object.fromEntries(Object.entries(preloadedData).map(_ref => {
|
|
|
|
let [path, data] = _ref;
|
|
|
|
return [(0,external_wp_url_namespaceObject.normalizePath)(path), data];
|
|
|
|
}));
|
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) {
|
2022-04-12 17:12:47 +02:00
|
|
|
const {
|
|
|
|
rest_route: pathFromQuery,
|
|
|
|
...queryArgs
|
|
|
|
} = (0,external_wp_url_namespaceObject.getQueryArgs)(options.url);
|
2021-11-08 15:29:21 +01:00
|
|
|
|
|
|
|
if (typeof pathFromQuery === 'string') {
|
2022-04-12 17:12:47 +02:00
|
|
|
rawPath = (0,external_wp_url_namespaceObject.addQueryArgs)(pathFromQuery, queryArgs);
|
2021-11-08 15:29:21 +01:00
|
|
|
}
|
|
|
|
}
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
if (typeof rawPath !== 'string') {
|
|
|
|
return next(options);
|
|
|
|
}
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
const method = options.method || 'GET';
|
|
|
|
const path = (0,external_wp_url_namespaceObject.normalizePath)(rawPath);
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
if ('GET' === method && cache[path]) {
|
|
|
|
const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time.
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
delete cache[path];
|
|
|
|
return prepareResponse(cacheData, !!parse);
|
|
|
|
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
|
|
|
|
const cacheData = cache[method][path]; // Unsetting the cache key ensures that the data is only used a single time.
|
|
|
|
|
|
|
|
delete cache[method][path];
|
|
|
|
return prepareResponse(cacheData, !!parse);
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(options);
|
|
|
|
};
|
2020-01-08 12:57:23 +01:00
|
|
|
}
|
2022-04-12 17:12:47 +02:00
|
|
|
/**
|
|
|
|
* This is a helper function that sends a success response.
|
|
|
|
*
|
|
|
|
* @param {Record<string, any>} responseData
|
|
|
|
* @param {boolean} parse
|
|
|
|
* @return {Promise<any>} Promise with the response.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
function prepareResponse(responseData, parse) {
|
|
|
|
return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
|
|
|
|
status: 200,
|
|
|
|
statusText: 'OK',
|
|
|
|
headers: responseData.headers
|
|
|
|
}));
|
|
|
|
}
|
2018-12-18 04:14:52 +01:00
|
|
|
|
|
|
|
/* harmony default export */ var preloading = (createPreloadingMiddleware);
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// 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,
|
2022-04-11 14:04:30 +02:00
|
|
|
url: url && (0,external_wp_url_namespaceObject.addQueryArgs)(url, queryArgs),
|
|
|
|
path: path && (0,external_wp_url_namespaceObject.addQueryArgs)(path, queryArgs)
|
2021-11-15 13:50:17 +01:00
|
|
|
};
|
|
|
|
};
|
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
|
|
|
|
2022-04-11 14:04:30 +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
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* 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) => {
|
2022-04-11 14:04:30 +02:00
|
|
|
if (typeof options.url === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.url, '_locale')) {
|
|
|
|
options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, {
|
2018-12-18 04:14:52 +01:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
if (typeof options.path === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.path, '_locale')) {
|
|
|
|
options.path = (0,external_wp_url_namespaceObject.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
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
|
2019-10-15 18:17:12 +02:00
|
|
|
/**
|
|
|
|
* 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',
|
2022-04-11 14:04:30 +02:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('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',
|
2022-04-11 14:04:30 +02:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('An unknown error occurred.')
|
2019-10-15 18:17:12 +02:00
|
|
|
};
|
|
|
|
throw error || unknownError;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// 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',
|
2022-04-11 14:04:30 +02:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('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
|
|
|
|
2022-04-11 14:04:30 +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';
|
|
|
|
}
|
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
const responsePromise = window.fetch( // Fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed.
|
2021-05-19 17:09:27 +02:00
|
|
|
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',
|
2022-04-11 14:04:30 +02:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('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;
|
2022-04-11 14:04:30 +02:00
|
|
|
/* harmony default export */ var build_module = (apiFetch);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
(window.wp = window.wp || {}).apiFetch = __webpack_exports__["default"];
|
|
|
|
/******/ })()
|
|
|
|
;
|