2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => { // webpackBootstrap
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ "use strict";
|
|
|
|
/******/ // The require scope
|
|
|
|
/******/ var __webpack_require__ = {};
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ // define getter functions for harmony exports
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ __webpack_require__.d = (exports, definition) => {
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/ 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-13 23:41:57 -05:00
|
|
|
/******/ };
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ })();
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
2024-01-31 07:59:56 -05:00
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
|
|
/******/ })();
|
2022-04-11 08:04:30 -04:00
|
|
|
/******/
|
2018-12-13 23:41:57 -05:00
|
|
|
/************************************************************************/
|
2022-04-11 08:04:30 -04:00
|
|
|
var __webpack_exports__ = {};
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
// EXPORTS
|
|
|
|
__webpack_require__.d(__webpack_exports__, {
|
2024-01-31 07:59:56 -05:00
|
|
|
"default": () => (/* binding */ build_module)
|
2022-04-11 08:04:30 -04:00
|
|
|
});
|
2020-01-08 06:57:23 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: external ["wp","i18n"]
|
2024-01-31 07:59:56 -05:00
|
|
|
const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
|
2022-04-11 08:04:30 -04: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 = {}
|
2023-09-26 10:23:26 -04:00
|
|
|
} = options;
|
2018-12-16 23:52:00 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// If an 'X-WP-Nonce' header (or any case-insensitive variation
|
|
|
|
// thereof) was specified, no need to add a nonce header.
|
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
|
|
|
}
|
|
|
|
}
|
2023-09-26 10:23:26 -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;
|
|
|
|
}
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const nonce = (createNonceMiddleware);
|
2018-12-15 06:00:40 -05:00
|
|
|
|
2022-04-11 08:04:30 -04: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-17 22:14:52 -05:00
|
|
|
if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
|
|
|
|
namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
|
|
|
|
endpointTrimmed = options.endpoint.replace(/^\//, '');
|
|
|
|
if (endpointTrimmed) {
|
|
|
|
path = namespaceTrimmed + '/' + endpointTrimmed;
|
|
|
|
} else {
|
|
|
|
path = namespaceTrimmed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete options.namespace;
|
|
|
|
delete options.endpoint;
|
2023-09-26 10:23:26 -04:00
|
|
|
return next({
|
|
|
|
...options,
|
2021-05-19 11:09:27 -04:00
|
|
|
path
|
|
|
|
});
|
2018-12-17 22:14:52 -05:00
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const namespace_endpoint = (namespaceAndEndpointMiddleware);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
|
2018-12-17 22:14:52 -05:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string} rootURL
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Root URL middleware.
|
|
|
|
*/
|
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;
|
|
|
|
if (typeof path === 'string') {
|
|
|
|
apiRoot = rootURL;
|
|
|
|
if (-1 !== rootURL.indexOf('?')) {
|
|
|
|
path = path.replace('?', '&');
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
path = path.replace(/^\//, '');
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// API root may already include query parameter prefix if site is
|
2021-05-19 11:09:27 -04:00
|
|
|
// configured to use plain permalinks.
|
|
|
|
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;
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
return next({
|
|
|
|
...optionsWithPath,
|
2021-05-19 11:09:27 -04:00
|
|
|
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
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const root_url = (createRootURLMiddleware);
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: external ["wp","url"]
|
2024-01-31 07:59:56 -05:00
|
|
|
const external_wp_url_namespaceObject = window["wp"]["url"];
|
2022-04-11 08:04:30 -04: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
|
|
|
*/
|
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {Record<string, any>} preloadedData
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
|
|
|
|
*/
|
2020-01-08 06:57:23 -05:00
|
|
|
function createPreloadingMiddleware(preloadedData) {
|
2023-06-27 10:24:19 -04:00
|
|
|
const cache = Object.fromEntries(Object.entries(preloadedData).map(([path, data]) => [(0,external_wp_url_namespaceObject.normalizePath)(path), data]));
|
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) {
|
2022-04-12 11:12:47 -04:00
|
|
|
const {
|
|
|
|
rest_route: pathFromQuery,
|
|
|
|
...queryArgs
|
|
|
|
} = (0,external_wp_url_namespaceObject.getQueryArgs)(options.url);
|
2021-11-08 09:29:21 -05:00
|
|
|
if (typeof pathFromQuery === 'string') {
|
2022-04-12 11:12:47 -04:00
|
|
|
rawPath = (0,external_wp_url_namespaceObject.addQueryArgs)(pathFromQuery, queryArgs);
|
2021-11-08 09:29:21 -05:00
|
|
|
}
|
|
|
|
}
|
2022-04-12 11:12:47 -04:00
|
|
|
if (typeof rawPath !== 'string') {
|
|
|
|
return next(options);
|
|
|
|
}
|
|
|
|
const method = options.method || 'GET';
|
|
|
|
const path = (0,external_wp_url_namespaceObject.normalizePath)(rawPath);
|
|
|
|
if ('GET' === method && cache[path]) {
|
2023-09-26 10:23:26 -04:00
|
|
|
const cacheData = cache[path];
|
2021-11-08 09:29:21 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Unsetting the cache key ensures that the data is only used a single time.
|
2022-04-12 11:12:47 -04:00
|
|
|
delete cache[path];
|
|
|
|
return prepareResponse(cacheData, !!parse);
|
|
|
|
} else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
|
2023-09-26 10:23:26 -04:00
|
|
|
const cacheData = cache[method][path];
|
2022-04-12 11:12:47 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Unsetting the cache key ensures that the data is only used a single time.
|
2022-04-12 11:12:47 -04:00
|
|
|
delete cache[method][path];
|
|
|
|
return prepareResponse(cacheData, !!parse);
|
2018-12-17 22:14:52 -05:00
|
|
|
}
|
|
|
|
return next(options);
|
|
|
|
};
|
2020-01-08 06:57:23 -05:00
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2022-04-12 11:12:47 -04: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
|
|
|
|
}));
|
|
|
|
}
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const preloading = (createPreloadingMiddleware);
|
2018-12-17 22:14:52 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// 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
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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
|
|
|
|
*/
|
2023-06-27 10:24:19 -04:00
|
|
|
const modifyQuery = ({
|
|
|
|
path,
|
|
|
|
url,
|
|
|
|
...options
|
2023-09-26 10:23:26 -04:00
|
|
|
}, queryArgs) => ({
|
|
|
|
...options,
|
2023-06-27 10:24:19 -04:00
|
|
|
url: url && (0,external_wp_url_namespaceObject.addQueryArgs)(url, queryArgs),
|
|
|
|
path: path && (0,external_wp_url_namespaceObject.addQueryArgs)(path, queryArgs)
|
|
|
|
});
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Duplicates parsing functionality from apiFetch.
|
|
|
|
*
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {Promise<any>} Parsed response json.
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const parseResponse = response => response.json ? response.json() : Promise.reject(response);
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string | null} linkHeader
|
|
|
|
* @return {{ next?: string }} The parsed link header.
|
|
|
|
*/
|
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]
|
|
|
|
} : {};
|
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {Response} response
|
|
|
|
* @return {string | undefined} The next page URL.
|
|
|
|
*/
|
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;
|
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {import('../types').APIFetchOptions} options
|
|
|
|
* @return {boolean} True if the request contains an unbounded query.
|
|
|
|
*/
|
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
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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}
|
|
|
|
*/
|
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);
|
|
|
|
}
|
|
|
|
if (!requestContainsUnboundedQuery(options)) {
|
|
|
|
// If neither url nor path is requesting all items, do not apply middleware.
|
|
|
|
return next(options);
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2018-12-13 23:53:54 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Retrieve requested page of results.
|
|
|
|
const response = await build_module({
|
|
|
|
...modifyQuery(options, {
|
2021-05-19 11:09:27 -04:00
|
|
|
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);
|
|
|
|
if (!nextPage) {
|
|
|
|
// There are no further pages to request.
|
|
|
|
return results;
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2021-05-19 11:09:27 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Iteratively fetch all remaining pages until no "next" header is found.
|
|
|
|
let mergedResults = /** @type {any[]} */[].concat(results);
|
2021-05-19 11:09:27 -04:00
|
|
|
while (nextPage) {
|
2023-09-26 10:23:26 -04:00
|
|
|
const nextResponse = await build_module({
|
|
|
|
...options,
|
2021-05-19 11:09:27 -04:00
|
|
|
// 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;
|
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const fetch_all_middleware = (fetchAllMiddleware);
|
2020-02-06 16:03:31 -05:00
|
|
|
|
2022-04-11 08:04:30 -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']);
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const DEFAULT_METHOD = 'GET';
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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
|
|
|
*/
|
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())) {
|
2023-09-26 10:23:26 -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
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const http_v1 = (httpV1Middleware);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
|
2018-12-17 22:14:52 -05:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @type {import('../types').APIFetchMiddleware}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const userLocaleMiddleware = (options, next) => {
|
2022-04-11 08:04:30 -04: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-17 22:14:52 -05:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2022-04-11 08:04:30 -04: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-17 22:14:52 -05:00
|
|
|
_locale: 'user'
|
|
|
|
});
|
|
|
|
}
|
2020-10-13 09:10:30 -04:00
|
|
|
return next(options);
|
2021-04-15 11:19:43 -04:00
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const user_locale = (userLocaleMiddleware);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
|
2019-10-15 12:17:12 -04:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2023-06-27 10:24:19 -04:00
|
|
|
const response_parseResponse = (response, shouldParseResponse = true) => {
|
2019-10-15 12:17:12 -04:00
|
|
|
if (shouldParseResponse) {
|
|
|
|
if (response.status === 204) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return response.json ? response.json() : Promise.reject(response);
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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.
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const parseJsonAndNormalizeError = response => {
|
|
|
|
const invalidJsonError = {
|
2019-10-15 12:17:12 -04:00
|
|
|
code: 'invalid_json',
|
2022-04-11 08:04:30 -04:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('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;
|
|
|
|
});
|
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2019-10-15 12:17:12 -04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2023-06-27 10:24:19 -04:00
|
|
|
const parseResponseAndNormalizeError = (response, shouldParseResponse = 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
|
|
|
};
|
2023-09-26 10:23:26 -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.
|
|
|
|
*/
|
2023-06-27 10:24:19 -04:00
|
|
|
function parseAndThrowError(response, shouldParseResponse = 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',
|
2022-04-11 08:04:30 -04:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('An unknown error occurred.')
|
2019-10-15 12:17:12 -04:00
|
|
|
};
|
|
|
|
throw error || unknownError;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
|
2018-12-17 22:14:52 -05:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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;
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* @param {string} attachmentId
|
|
|
|
* @return {Promise<any>} Processed post response.
|
|
|
|
*/
|
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();
|
|
|
|
});
|
|
|
|
};
|
2023-09-26 10:23:26 -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-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',
|
2022-04-11 08:04:30 -04: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 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
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const media_upload = (mediaUploadMiddleware);
|
2019-10-15 12:17:12 -04:00
|
|
|
|
2023-06-27 10:24:19 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/theme-preview.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2023-06-27 10:24:19 -04:00
|
|
|
/**
|
|
|
|
* This appends a `wp_theme_preview` parameter to the REST API request URL if
|
|
|
|
* the admin URL contains a `theme` GET parameter.
|
|
|
|
*
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
* If the REST API request URL has contained the `wp_theme_preview` parameter as `''`,
|
|
|
|
* then bypass this middleware.
|
|
|
|
*
|
2023-06-27 10:24:19 -04:00
|
|
|
* @param {Record<string, any>} themePath
|
|
|
|
* @return {import('../types').APIFetchMiddleware} Preloading middleware.
|
|
|
|
*/
|
|
|
|
const createThemePreviewMiddleware = themePath => (options, next) => {
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
if (typeof options.url === 'string') {
|
|
|
|
const wpThemePreview = (0,external_wp_url_namespaceObject.getQueryArg)(options.url, 'wp_theme_preview');
|
|
|
|
if (wpThemePreview === undefined) {
|
|
|
|
options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, {
|
|
|
|
wp_theme_preview: themePath
|
|
|
|
});
|
|
|
|
} else if (wpThemePreview === '') {
|
|
|
|
options.url = (0,external_wp_url_namespaceObject.removeQueryArgs)(options.url, 'wp_theme_preview');
|
|
|
|
}
|
2023-06-27 10:24:19 -04:00
|
|
|
}
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 16:07:12 -05:00
|
|
|
if (typeof options.path === 'string') {
|
|
|
|
const wpThemePreview = (0,external_wp_url_namespaceObject.getQueryArg)(options.path, 'wp_theme_preview');
|
|
|
|
if (wpThemePreview === undefined) {
|
|
|
|
options.path = (0,external_wp_url_namespaceObject.addQueryArgs)(options.path, {
|
|
|
|
wp_theme_preview: themePath
|
|
|
|
});
|
|
|
|
} else if (wpThemePreview === '') {
|
|
|
|
options.path = (0,external_wp_url_namespaceObject.removeQueryArgs)(options.path, 'wp_theme_preview');
|
|
|
|
}
|
2023-06-27 10:24:19 -04:00
|
|
|
}
|
|
|
|
return next(options);
|
|
|
|
};
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const theme_preview = (createThemePreviewMiddleware);
|
2023-06-27 10:24:19 -04:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
|
2020-01-08 06:57:23 -05:00
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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
|
|
|
|
2023-06-27 10:24:19 -04: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'
|
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2018-12-17 22:14:52 -05:00
|
|
|
/**
|
|
|
|
* Default set of fetch option values which should be sent with every request
|
|
|
|
* unless explicitly provided through apiFetch options.
|
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
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
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
/** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */
|
2021-04-15 11:19:43 -04:00
|
|
|
/** @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];
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/**
|
|
|
|
* Register a middleware
|
|
|
|
*
|
|
|
|
* @param {import('./types').APIFetchMiddleware} middleware
|
|
|
|
*/
|
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
|
|
|
}
|
2023-09-26 10:23:26 -04: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.
|
|
|
|
*/
|
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;
|
|
|
|
};
|
2023-09-26 10:23:26 -04:00
|
|
|
|
2021-04-15 11:19:43 -04:00
|
|
|
/** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {FetchHandler}
|
|
|
|
*/
|
2021-05-19 11:09:27 -04:00
|
|
|
const defaultFetchHandler = nextOptions => {
|
|
|
|
const {
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
data,
|
|
|
|
parse = true,
|
|
|
|
...remainingOptions
|
|
|
|
} = nextOptions;
|
|
|
|
let {
|
|
|
|
body,
|
|
|
|
headers
|
2023-09-26 10:23:26 -04:00
|
|
|
} = nextOptions;
|
2019-03-07 04:09:59 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// Merge explicitly-provided headers with default values.
|
|
|
|
headers = {
|
|
|
|
...DEFAULT_HEADERS,
|
2021-05-19 11:09:27 -04:00
|
|
|
...headers
|
2023-09-26 10:23:26 -04:00
|
|
|
};
|
2019-03-07 04:09:59 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// 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';
|
|
|
|
}
|
2023-09-26 10:23:26 -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,
|
2021-05-19 11:09:27 -04:00
|
|
|
...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;
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2021-11-08 09:29:21 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// 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',
|
2022-04-11 08:04:30 -04:00
|
|
|
message: (0,external_wp_i18n_namespaceObject.__)('You are probably offline.')
|
2020-01-08 06:57:23 -05:00
|
|
|
};
|
2019-03-07 04:09:59 -05:00
|
|
|
});
|
|
|
|
};
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
/** @type {FetchHandler} */
|
2021-05-19 11:09:27 -04:00
|
|
|
let fetchHandler = defaultFetchHandler;
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
function setFetchHandler(newFetchHandler) {
|
|
|
|
fetchHandler = newFetchHandler;
|
|
|
|
}
|
2023-09-26 10:23:26 -04:00
|
|
|
|
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.
|
|
|
|
*/
|
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 ) ) );
|
|
|
|
// ```
|
2023-09-26 10:23:26 -04:00
|
|
|
const enhancedHandler = middlewares.reduceRight(( /** @type {FetchHandler} */next, middleware) => {
|
2021-05-19 11:09:27 -04:00
|
|
|
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);
|
2023-09-26 10:23:26 -04:00
|
|
|
}
|
2020-10-13 09:10:30 -04:00
|
|
|
|
2023-09-26 10:23:26 -04:00
|
|
|
// If the nonce is invalid, refresh it and try again.
|
|
|
|
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;
|
2023-06-27 10:24:19 -04:00
|
|
|
apiFetch.createThemePreviewMiddleware = theme_preview;
|
2024-01-31 07:59:56 -05:00
|
|
|
/* harmony default export */ const build_module = (apiFetch);
|
2018-12-13 23:41:57 -05:00
|
|
|
|
2022-04-11 08:04:30 -04:00
|
|
|
(window.wp = window.wp || {}).apiFetch = __webpack_exports__["default"];
|
|
|
|
/******/ })()
|
|
|
|
;
|