| @@ -1,783 +1 @@ | ||
| 1 | -/******/ (function() { // webpackBootstrap | |
| 2 | -/******/ "use strict"; | |
| 3 | -/******/ // The require scope | |
| 4 | -/******/ var __webpack_require__ = {}; | |
| 5 | -/******/ | |
| 6 | -/************************************************************************/ | |
| 7 | -/******/ /* webpack/runtime/define property getters */ | |
| 8 | -/******/ !function() { | |
| 9 | -/******/ // define getter functions for harmony exports | |
| 10 | -/******/ __webpack_require__.d = function(exports, definition) { | |
| 11 | -/******/ for(var key in definition) { | |
| 12 | -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { | |
| 13 | -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); | |
| 14 | -/******/ } | |
| 15 | -/******/ } | |
| 16 | -/******/ }; | |
| 17 | -/******/ }(); | |
| 18 | -/******/ | |
| 19 | -/******/ /* webpack/runtime/hasOwnProperty shorthand */ | |
| 20 | -/******/ !function() { | |
| 21 | -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } | |
| 22 | -/******/ }(); | |
| 23 | -/******/ | |
| 24 | -/************************************************************************/ | |
| 25 | -var __webpack_exports__ = {}; | |
| 26 | - | |
| 27 | -// EXPORTS | |
| 28 | -__webpack_require__.d(__webpack_exports__, { | |
| 29 | - "default": function() { return /* binding */ build_module; } | |
| 30 | -}); | |
| 31 | - | |
| 32 | -;// CONCATENATED MODULE: external ["wp","i18n"] | |
| 33 | -var external_wp_i18n_namespaceObject = window["wp"]["i18n"]; | |
| 34 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/nonce.js | |
| 35 | -/** | |
| 36 | - * @param {string} nonce | |
| 37 | - * @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce. | |
| 38 | - */ | |
| 39 | -function createNonceMiddleware(nonce) { | |
| 40 | - /** | |
| 41 | - * @type {import('../types').APIFetchMiddleware & { nonce: string }} | |
| 42 | - */ | |
| 43 | - const middleware = (options, next) => { | |
| 44 | - const { | |
| 45 | - headers = {} | |
| 46 | - } = options; // If an 'X-WP-Nonce' header (or any case-insensitive variation | |
| 47 | - // thereof) was specified, no need to add a nonce header. | |
| 48 | - | |
| 49 | - for (const headerName in headers) { | |
| 50 | - if (headerName.toLowerCase() === 'x-wp-nonce' && headers[headerName] === middleware.nonce) { | |
| 51 | - return next(options); | |
| 52 | - } | |
| 53 | - } | |
| 54 | - | |
| 55 | - return next({ ...options, | |
| 56 | - headers: { ...headers, | |
| 57 | - 'X-WP-Nonce': middleware.nonce | |
| 58 | - } | |
| 59 | - }); | |
| 60 | - }; | |
| 61 | - | |
| 62 | - middleware.nonce = nonce; | |
| 63 | - return middleware; | |
| 64 | -} | |
| 65 | - | |
| 66 | -/* harmony default export */ var nonce = (createNonceMiddleware); | |
| 67 | -//# sourceMappingURL=nonce.js.map | |
| 68 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/namespace-endpoint.js | |
| 69 | -/** | |
| 70 | - * @type {import('../types').APIFetchMiddleware} | |
| 71 | - */ | |
| 72 | -const namespaceAndEndpointMiddleware = (options, next) => { | |
| 73 | - let path = options.path; | |
| 74 | - let namespaceTrimmed, endpointTrimmed; | |
| 75 | - | |
| 76 | - if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') { | |
| 77 | - namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, ''); | |
| 78 | - endpointTrimmed = options.endpoint.replace(/^\//, ''); | |
| 79 | - | |
| 80 | - if (endpointTrimmed) { | |
| 81 | - path = namespaceTrimmed + '/' + endpointTrimmed; | |
| 82 | - } else { | |
| 83 | - path = namespaceTrimmed; | |
| 84 | - } | |
| 85 | - } | |
| 86 | - | |
| 87 | - delete options.namespace; | |
| 88 | - delete options.endpoint; | |
| 89 | - return next({ ...options, | |
| 90 | - path | |
| 91 | - }); | |
| 92 | -}; | |
| 93 | - | |
| 94 | -/* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware); | |
| 95 | -//# sourceMappingURL=namespace-endpoint.js.map | |
| 96 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/root-url.js | |
| 97 | -/** | |
| 98 | - * Internal dependencies | |
| 99 | - */ | |
| 100 | - | |
| 101 | -/** | |
| 102 | - * @param {string} rootURL | |
| 103 | - * @return {import('../types').APIFetchMiddleware} Root URL middleware. | |
| 104 | - */ | |
| 105 | - | |
| 106 | -const createRootURLMiddleware = rootURL => (options, next) => { | |
| 107 | - return namespace_endpoint(options, optionsWithPath => { | |
| 108 | - let url = optionsWithPath.url; | |
| 109 | - let path = optionsWithPath.path; | |
| 110 | - let apiRoot; | |
| 111 | - | |
| 112 | - if (typeof path === 'string') { | |
| 113 | - apiRoot = rootURL; | |
| 114 | - | |
| 115 | - if (-1 !== rootURL.indexOf('?')) { | |
| 116 | - path = path.replace('?', '&'); | |
| 117 | - } | |
| 118 | - | |
| 119 | - path = path.replace(/^\//, ''); // API root may already include query parameter prefix if site is | |
| 120 | - // configured to use plain permalinks. | |
| 121 | - | |
| 122 | - if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) { | |
| 123 | - path = path.replace('?', '&'); | |
| 124 | - } | |
| 125 | - | |
| 126 | - url = apiRoot + path; | |
| 127 | - } | |
| 128 | - | |
| 129 | - return next({ ...optionsWithPath, | |
| 130 | - url | |
| 131 | - }); | |
| 132 | - }); | |
| 133 | -}; | |
| 134 | - | |
| 135 | -/* harmony default export */ var root_url = (createRootURLMiddleware); | |
| 136 | -//# sourceMappingURL=root-url.js.map | |
| 137 | -;// CONCATENATED MODULE: external ["wp","url"] | |
| 138 | -var external_wp_url_namespaceObject = window["wp"]["url"]; | |
| 139 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/preloading.js | |
| 140 | -/** | |
| 141 | - * WordPress dependencies | |
| 142 | - */ | |
| 143 | - | |
| 144 | -/** | |
| 145 | - * @param {Record<string, any>} preloadedData | |
| 146 | - * @return {import('../types').APIFetchMiddleware} Preloading middleware. | |
| 147 | - */ | |
| 148 | - | |
| 149 | -function createPreloadingMiddleware(preloadedData) { | |
| 150 | - const cache = Object.keys(preloadedData).reduce((result, path) => { | |
| 151 | - result[(0,external_wp_url_namespaceObject.normalizePath)(path)] = preloadedData[path]; | |
| 152 | - return result; | |
| 153 | - }, | |
| 154 | - /** @type {Record<string, any>} */ | |
| 155 | - {}); | |
| 156 | - return (options, next) => { | |
| 157 | - const { | |
| 158 | - parse = true | |
| 159 | - } = options; | |
| 160 | - /** @type {string | void} */ | |
| 161 | - | |
| 162 | - let rawPath = options.path; | |
| 163 | - | |
| 164 | - if (!rawPath && options.url) { | |
| 165 | - const pathFromQuery = (0,external_wp_url_namespaceObject.getQueryArg)(options.url, 'rest_route'); | |
| 166 | - | |
| 167 | - if (typeof pathFromQuery === 'string') { | |
| 168 | - rawPath = pathFromQuery; | |
| 169 | - } | |
| 170 | - } | |
| 171 | - | |
| 172 | - if (typeof rawPath !== 'string') { | |
| 173 | - return next(options); | |
| 174 | - } | |
| 175 | - | |
| 176 | - const method = options.method || 'GET'; | |
| 177 | - const path = (0,external_wp_url_namespaceObject.normalizePath)(rawPath); | |
| 178 | - | |
| 179 | - if ('GET' === method && cache[path]) { | |
| 180 | - const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time | |
| 181 | - | |
| 182 | - delete cache[path]; | |
| 183 | - return prepareResponse(cacheData, !!parse); | |
| 184 | - } else if ('OPTIONS' === method && cache[method] && cache[method][path]) { | |
| 185 | - const cacheData = cache[method][path]; // Unsetting the cache key ensures that the data is only used a single time | |
| 186 | - | |
| 187 | - delete cache[method][path]; | |
| 188 | - return prepareResponse(cacheData, !!parse); | |
| 189 | - } | |
| 190 | - | |
| 191 | - return next(options); | |
| 192 | - }; | |
| 193 | -} | |
| 194 | -/** | |
| 195 | - * This is a helper function that sends a success response. | |
| 196 | - * | |
| 197 | - * @param {Record<string, any>} responseData | |
| 198 | - * @param {boolean} parse | |
| 199 | - * @return {Promise<any>} Promise with the response. | |
| 200 | - */ | |
| 201 | - | |
| 202 | - | |
| 203 | -function prepareResponse(responseData, parse) { | |
| 204 | - return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), { | |
| 205 | - status: 200, | |
| 206 | - statusText: 'OK', | |
| 207 | - headers: responseData.headers | |
| 208 | - })); | |
| 209 | -} | |
| 210 | - | |
| 211 | -/* harmony default export */ var preloading = (createPreloadingMiddleware); | |
| 212 | -//# sourceMappingURL=preloading.js.map | |
| 213 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/fetch-all-middleware.js | |
| 214 | -/** | |
| 215 | - * WordPress dependencies | |
| 216 | - */ | |
| 217 | - | |
| 218 | -/** | |
| 219 | - * Internal dependencies | |
| 220 | - */ | |
| 221 | - | |
| 222 | - | |
| 223 | -/** | |
| 224 | - * Apply query arguments to both URL and Path, whichever is present. | |
| 225 | - * | |
| 226 | - * @param {import('../types').APIFetchOptions} props | |
| 227 | - * @param {Record<string, string | number>} queryArgs | |
| 228 | - * @return {import('../types').APIFetchOptions} The request with the modified query args | |
| 229 | - */ | |
| 230 | - | |
| 231 | -const modifyQuery = (_ref, queryArgs) => { | |
| 232 | - let { | |
| 233 | - path, | |
| 234 | - url, | |
| 235 | - ...options | |
| 236 | - } = _ref; | |
| 237 | - return { ...options, | |
| 238 | - url: url && (0,external_wp_url_namespaceObject.addQueryArgs)(url, queryArgs), | |
| 239 | - path: path && (0,external_wp_url_namespaceObject.addQueryArgs)(path, queryArgs) | |
| 240 | - }; | |
| 241 | -}; | |
| 242 | -/** | |
| 243 | - * Duplicates parsing functionality from apiFetch. | |
| 244 | - * | |
| 245 | - * @param {Response} response | |
| 246 | - * @return {Promise<any>} Parsed response json. | |
| 247 | - */ | |
| 248 | - | |
| 249 | - | |
| 250 | -const parseResponse = response => response.json ? response.json() : Promise.reject(response); | |
| 251 | -/** | |
| 252 | - * @param {string | null} linkHeader | |
| 253 | - * @return {{ next?: string }} The parsed link header. | |
| 254 | - */ | |
| 255 | - | |
| 256 | - | |
| 257 | -const parseLinkHeader = linkHeader => { | |
| 258 | - if (!linkHeader) { | |
| 259 | - return {}; | |
| 260 | - } | |
| 261 | - | |
| 262 | - const match = linkHeader.match(/<([^>]+)>; rel="next"/); | |
| 263 | - return match ? { | |
| 264 | - next: match[1] | |
| 265 | - } : {}; | |
| 266 | -}; | |
| 267 | -/** | |
| 268 | - * @param {Response} response | |
| 269 | - * @return {string | undefined} The next page URL. | |
| 270 | - */ | |
| 271 | - | |
| 272 | - | |
| 273 | -const getNextPageUrl = response => { | |
| 274 | - const { | |
| 275 | - next | |
| 276 | - } = parseLinkHeader(response.headers.get('link')); | |
| 277 | - return next; | |
| 278 | -}; | |
| 279 | -/** | |
| 280 | - * @param {import('../types').APIFetchOptions} options | |
| 281 | - * @return {boolean} True if the request contains an unbounded query. | |
| 282 | - */ | |
| 283 | - | |
| 284 | - | |
| 285 | -const requestContainsUnboundedQuery = options => { | |
| 286 | - const pathIsUnbounded = !!options.path && options.path.indexOf('per_page=-1') !== -1; | |
| 287 | - const urlIsUnbounded = !!options.url && options.url.indexOf('per_page=-1') !== -1; | |
| 288 | - return pathIsUnbounded || urlIsUnbounded; | |
| 289 | -}; | |
| 290 | -/** | |
| 291 | - * The REST API enforces an upper limit on the per_page option. To handle large | |
| 292 | - * collections, apiFetch consumers can pass `per_page=-1`; this middleware will | |
| 293 | - * then recursively assemble a full response array from all available pages. | |
| 294 | - * | |
| 295 | - * @type {import('../types').APIFetchMiddleware} | |
| 296 | - */ | |
| 297 | - | |
| 298 | - | |
| 299 | -const fetchAllMiddleware = async (options, next) => { | |
| 300 | - if (options.parse === false) { | |
| 301 | - // If a consumer has opted out of parsing, do not apply middleware. | |
| 302 | - return next(options); | |
| 303 | - } | |
| 304 | - | |
| 305 | - if (!requestContainsUnboundedQuery(options)) { | |
| 306 | - // If neither url nor path is requesting all items, do not apply middleware. | |
| 307 | - return next(options); | |
| 308 | - } // Retrieve requested page of results. | |
| 309 | - | |
| 310 | - | |
| 311 | - const response = await build_module({ ...modifyQuery(options, { | |
| 312 | - per_page: 100 | |
| 313 | - }), | |
| 314 | - // Ensure headers are returned for page 1. | |
| 315 | - parse: false | |
| 316 | - }); | |
| 317 | - const results = await parseResponse(response); | |
| 318 | - | |
| 319 | - if (!Array.isArray(results)) { | |
| 320 | - // We have no reliable way of merging non-array results. | |
| 321 | - return results; | |
| 322 | - } | |
| 323 | - | |
| 324 | - let nextPage = getNextPageUrl(response); | |
| 325 | - | |
| 326 | - if (!nextPage) { | |
| 327 | - // There are no further pages to request. | |
| 328 | - return results; | |
| 329 | - } // Iteratively fetch all remaining pages until no "next" header is found. | |
| 330 | - | |
| 331 | - | |
| 332 | - let mergedResults = | |
| 333 | - /** @type {any[]} */ | |
| 334 | - [].concat(results); | |
| 335 | - | |
| 336 | - while (nextPage) { | |
| 337 | - const nextResponse = await build_module({ ...options, | |
| 338 | - // Ensure the URL for the next page is used instead of any provided path. | |
| 339 | - path: undefined, | |
| 340 | - url: nextPage, | |
| 341 | - // Ensure we still get headers so we can identify the next page. | |
| 342 | - parse: false | |
| 343 | - }); | |
| 344 | - const nextResults = await parseResponse(nextResponse); | |
| 345 | - mergedResults = mergedResults.concat(nextResults); | |
| 346 | - nextPage = getNextPageUrl(nextResponse); | |
| 347 | - } | |
| 348 | - | |
| 349 | - return mergedResults; | |
| 350 | -}; | |
| 351 | - | |
| 352 | -/* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware); | |
| 353 | -//# sourceMappingURL=fetch-all-middleware.js.map | |
| 354 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/http-v1.js | |
| 355 | -/** | |
| 356 | - * Set of HTTP methods which are eligible to be overridden. | |
| 357 | - * | |
| 358 | - * @type {Set<string>} | |
| 359 | - */ | |
| 360 | -const OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']); | |
| 361 | -/** | |
| 362 | - * Default request method. | |
| 363 | - * | |
| 364 | - * "A request has an associated method (a method). Unless stated otherwise it | |
| 365 | - * is `GET`." | |
| 366 | - * | |
| 367 | - * @see https://fetch.spec.whatwg.org/#requests | |
| 368 | - * | |
| 369 | - * @type {string} | |
| 370 | - */ | |
| 371 | - | |
| 372 | -const DEFAULT_METHOD = 'GET'; | |
| 373 | -/** | |
| 374 | - * API Fetch middleware which overrides the request method for HTTP v1 | |
| 375 | - * compatibility leveraging the REST API X-HTTP-Method-Override header. | |
| 376 | - * | |
| 377 | - * @type {import('../types').APIFetchMiddleware} | |
| 378 | - */ | |
| 379 | - | |
| 380 | -const httpV1Middleware = (options, next) => { | |
| 381 | - const { | |
| 382 | - method = DEFAULT_METHOD | |
| 383 | - } = options; | |
| 384 | - | |
| 385 | - if (OVERRIDE_METHODS.has(method.toUpperCase())) { | |
| 386 | - options = { ...options, | |
| 387 | - headers: { ...options.headers, | |
| 388 | - 'X-HTTP-Method-Override': method, | |
| 389 | - 'Content-Type': 'application/json' | |
| 390 | - }, | |
| 391 | - method: 'POST' | |
| 392 | - }; | |
| 393 | - } | |
| 394 | - | |
| 395 | - return next(options); | |
| 396 | -}; | |
| 397 | - | |
| 398 | -/* harmony default export */ var http_v1 = (httpV1Middleware); | |
| 399 | -//# sourceMappingURL=http-v1.js.map | |
| 400 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/user-locale.js | |
| 401 | -/** | |
| 402 | - * WordPress dependencies | |
| 403 | - */ | |
| 404 | - | |
| 405 | -/** | |
| 406 | - * @type {import('../types').APIFetchMiddleware} | |
| 407 | - */ | |
| 408 | - | |
| 409 | -const userLocaleMiddleware = (options, next) => { | |
| 410 | - if (typeof options.url === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.url, '_locale')) { | |
| 411 | - options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, { | |
| 412 | - _locale: 'user' | |
| 413 | - }); | |
| 414 | - } | |
| 415 | - | |
| 416 | - if (typeof options.path === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.path, '_locale')) { | |
| 417 | - options.path = (0,external_wp_url_namespaceObject.addQueryArgs)(options.path, { | |
| 418 | - _locale: 'user' | |
| 419 | - }); | |
| 420 | - } | |
| 421 | - | |
| 422 | - return next(options); | |
| 423 | -}; | |
| 424 | - | |
| 425 | -/* harmony default export */ var user_locale = (userLocaleMiddleware); | |
| 426 | -//# sourceMappingURL=user-locale.js.map | |
| 427 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/utils/response.js | |
| 428 | -/** | |
| 429 | - * WordPress dependencies | |
| 430 | - */ | |
| 431 | - | |
| 432 | -/** | |
| 433 | - * Parses the apiFetch response. | |
| 434 | - * | |
| 435 | - * @param {Response} response | |
| 436 | - * @param {boolean} shouldParseResponse | |
| 437 | - * | |
| 438 | - * @return {Promise<any> | null | Response} Parsed response. | |
| 439 | - */ | |
| 440 | - | |
| 441 | -const response_parseResponse = function (response) { | |
| 442 | - let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | |
| 443 | - | |
| 444 | - if (shouldParseResponse) { | |
| 445 | - if (response.status === 204) { | |
| 446 | - return null; | |
| 447 | - } | |
| 448 | - | |
| 449 | - return response.json ? response.json() : Promise.reject(response); | |
| 450 | - } | |
| 451 | - | |
| 452 | - return response; | |
| 453 | -}; | |
| 454 | -/** | |
| 455 | - * Calls the `json` function on the Response, throwing an error if the response | |
| 456 | - * doesn't have a json function or if parsing the json itself fails. | |
| 457 | - * | |
| 458 | - * @param {Response} response | |
| 459 | - * @return {Promise<any>} Parsed response. | |
| 460 | - */ | |
| 461 | - | |
| 462 | - | |
| 463 | -const parseJsonAndNormalizeError = response => { | |
| 464 | - const invalidJsonError = { | |
| 465 | - code: 'invalid_json', | |
| 466 | - message: (0,external_wp_i18n_namespaceObject.__)('The response is not a valid JSON response.') | |
| 467 | - }; | |
| 468 | - | |
| 469 | - if (!response || !response.json) { | |
| 470 | - throw invalidJsonError; | |
| 471 | - } | |
| 472 | - | |
| 473 | - return response.json().catch(() => { | |
| 474 | - throw invalidJsonError; | |
| 475 | - }); | |
| 476 | -}; | |
| 477 | -/** | |
| 478 | - * Parses the apiFetch response properly and normalize response errors. | |
| 479 | - * | |
| 480 | - * @param {Response} response | |
| 481 | - * @param {boolean} shouldParseResponse | |
| 482 | - * | |
| 483 | - * @return {Promise<any>} Parsed response. | |
| 484 | - */ | |
| 485 | - | |
| 486 | - | |
| 487 | -const parseResponseAndNormalizeError = function (response) { | |
| 488 | - let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | |
| 489 | - return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse)); | |
| 490 | -}; | |
| 491 | -/** | |
| 492 | - * Parses a response, throwing an error if parsing the response fails. | |
| 493 | - * | |
| 494 | - * @param {Response} response | |
| 495 | - * @param {boolean} shouldParseResponse | |
| 496 | - * @return {Promise<any>} Parsed response. | |
| 497 | - */ | |
| 498 | - | |
| 499 | -function parseAndThrowError(response) { | |
| 500 | - let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | |
| 501 | - | |
| 502 | - if (!shouldParseResponse) { | |
| 503 | - throw response; | |
| 504 | - } | |
| 505 | - | |
| 506 | - return parseJsonAndNormalizeError(response).then(error => { | |
| 507 | - const unknownError = { | |
| 508 | - code: 'unknown_error', | |
| 509 | - message: (0,external_wp_i18n_namespaceObject.__)('An unknown error occurred.') | |
| 510 | - }; | |
| 511 | - throw error || unknownError; | |
| 512 | - }); | |
| 513 | -} | |
| 514 | -//# sourceMappingURL=response.js.map | |
| 515 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/middlewares/media-upload.js | |
| 516 | -/** | |
| 517 | - * WordPress dependencies | |
| 518 | - */ | |
| 519 | - | |
| 520 | -/** | |
| 521 | - * Internal dependencies | |
| 522 | - */ | |
| 523 | - | |
| 524 | - | |
| 525 | -/** | |
| 526 | - * @param {import('../types').APIFetchOptions} options | |
| 527 | - * @return {boolean} True if the request is for media upload. | |
| 528 | - */ | |
| 529 | - | |
| 530 | -function isMediaUploadRequest(options) { | |
| 531 | - const isCreateMethod = !!options.method && options.method === 'POST'; | |
| 532 | - const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1; | |
| 533 | - return isMediaEndpoint && isCreateMethod; | |
| 534 | -} | |
| 535 | -/** | |
| 536 | - * Middleware handling media upload failures and retries. | |
| 537 | - * | |
| 538 | - * @type {import('../types').APIFetchMiddleware} | |
| 539 | - */ | |
| 540 | - | |
| 541 | - | |
| 542 | -const mediaUploadMiddleware = (options, next) => { | |
| 543 | - if (!isMediaUploadRequest(options)) { | |
| 544 | - return next(options); | |
| 545 | - } | |
| 546 | - | |
| 547 | - let retries = 0; | |
| 548 | - const maxRetries = 5; | |
| 549 | - /** | |
| 550 | - * @param {string} attachmentId | |
| 551 | - * @return {Promise<any>} Processed post response. | |
| 552 | - */ | |
| 553 | - | |
| 554 | - const postProcess = attachmentId => { | |
| 555 | - retries++; | |
| 556 | - return next({ | |
| 557 | - path: `/wp/v2/media/${attachmentId}/post-process`, | |
| 558 | - method: 'POST', | |
| 559 | - data: { | |
| 560 | - action: 'create-image-subsizes' | |
| 561 | - }, | |
| 562 | - parse: false | |
| 563 | - }).catch(() => { | |
| 564 | - if (retries < maxRetries) { | |
| 565 | - return postProcess(attachmentId); | |
| 566 | - } | |
| 567 | - | |
| 568 | - next({ | |
| 569 | - path: `/wp/v2/media/${attachmentId}?force=true`, | |
| 570 | - method: 'DELETE' | |
| 571 | - }); | |
| 572 | - return Promise.reject(); | |
| 573 | - }); | |
| 574 | - }; | |
| 575 | - | |
| 576 | - return next({ ...options, | |
| 577 | - parse: false | |
| 578 | - }).catch(response => { | |
| 579 | - const attachmentId = response.headers.get('x-wp-upload-attachment-id'); | |
| 580 | - | |
| 581 | - if (response.status >= 500 && response.status < 600 && attachmentId) { | |
| 582 | - return postProcess(attachmentId).catch(() => { | |
| 583 | - if (options.parse !== false) { | |
| 584 | - return Promise.reject({ | |
| 585 | - code: 'post_process', | |
| 586 | - 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.') | |
| 587 | - }); | |
| 588 | - } | |
| 589 | - | |
| 590 | - return Promise.reject(response); | |
| 591 | - }); | |
| 592 | - } | |
| 593 | - | |
| 594 | - return parseAndThrowError(response, options.parse); | |
| 595 | - }).then(response => parseResponseAndNormalizeError(response, options.parse)); | |
| 596 | -}; | |
| 597 | - | |
| 598 | -/* harmony default export */ var media_upload = (mediaUploadMiddleware); | |
| 599 | -//# sourceMappingURL=media-upload.js.map | |
| 600 | -;// CONCATENATED MODULE: ./packages/api-fetch/build-module/index.js | |
| 601 | -/** | |
| 602 | - * WordPress dependencies | |
| 603 | - */ | |
| 604 | - | |
| 605 | -/** | |
| 606 | - * Internal dependencies | |
| 607 | - */ | |
| 608 | - | |
| 609 | - | |
| 610 | - | |
| 611 | - | |
| 612 | - | |
| 613 | - | |
| 614 | - | |
| 615 | - | |
| 616 | - | |
| 617 | - | |
| 618 | -/** | |
| 619 | - * Default set of header values which should be sent with every request unless | |
| 620 | - * explicitly provided through apiFetch options. | |
| 621 | - * | |
| 622 | - * @type {Record<string, string>} | |
| 623 | - */ | |
| 624 | - | |
| 625 | -const DEFAULT_HEADERS = { | |
| 626 | - // The backend uses the Accept header as a condition for considering an | |
| 627 | - // incoming request as a REST request. | |
| 628 | - // | |
| 629 | - // See: https://core.trac.wordpress.org/ticket/44534 | |
| 630 | - Accept: 'application/json, */*;q=0.1' | |
| 631 | -}; | |
| 632 | -/** | |
| 633 | - * Default set of fetch option values which should be sent with every request | |
| 634 | - * unless explicitly provided through apiFetch options. | |
| 635 | - * | |
| 636 | - * @type {Object} | |
| 637 | - */ | |
| 638 | - | |
| 639 | -const DEFAULT_OPTIONS = { | |
| 640 | - credentials: 'include' | |
| 641 | -}; | |
| 642 | -/** @typedef {import('./types').APIFetchMiddleware} APIFetchMiddleware */ | |
| 643 | - | |
| 644 | -/** @typedef {import('./types').APIFetchOptions} APIFetchOptions */ | |
| 645 | - | |
| 646 | -/** | |
| 647 | - * @type {import('./types').APIFetchMiddleware[]} | |
| 648 | - */ | |
| 649 | - | |
| 650 | -const middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware]; | |
| 651 | -/** | |
| 652 | - * Register a middleware | |
| 653 | - * | |
| 654 | - * @param {import('./types').APIFetchMiddleware} middleware | |
| 655 | - */ | |
| 656 | - | |
| 657 | -function registerMiddleware(middleware) { | |
| 658 | - middlewares.unshift(middleware); | |
| 659 | -} | |
| 660 | -/** | |
| 661 | - * Checks the status of a response, throwing the Response as an error if | |
| 662 | - * it is outside the 200 range. | |
| 663 | - * | |
| 664 | - * @param {Response} response | |
| 665 | - * @return {Response} The response if the status is in the 200 range. | |
| 666 | - */ | |
| 667 | - | |
| 668 | - | |
| 669 | -const checkStatus = response => { | |
| 670 | - if (response.status >= 200 && response.status < 300) { | |
| 671 | - return response; | |
| 672 | - } | |
| 673 | - | |
| 674 | - throw response; | |
| 675 | -}; | |
| 676 | -/** @typedef {(options: import('./types').APIFetchOptions) => Promise<any>} FetchHandler*/ | |
| 677 | - | |
| 678 | -/** | |
| 679 | - * @type {FetchHandler} | |
| 680 | - */ | |
| 681 | - | |
| 682 | - | |
| 683 | -const defaultFetchHandler = nextOptions => { | |
| 684 | - const { | |
| 685 | - url, | |
| 686 | - path, | |
| 687 | - data, | |
| 688 | - parse = true, | |
| 689 | - ...remainingOptions | |
| 690 | - } = nextOptions; | |
| 691 | - let { | |
| 692 | - body, | |
| 693 | - headers | |
| 694 | - } = nextOptions; // Merge explicitly-provided headers with default values. | |
| 695 | - | |
| 696 | - headers = { ...DEFAULT_HEADERS, | |
| 697 | - ...headers | |
| 698 | - }; // The `data` property is a shorthand for sending a JSON body. | |
| 699 | - | |
| 700 | - if (data) { | |
| 701 | - body = JSON.stringify(data); | |
| 702 | - headers['Content-Type'] = 'application/json'; | |
| 703 | - } | |
| 704 | - | |
| 705 | - const responsePromise = window.fetch( // fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed | |
| 706 | - url || path || window.location.href, { ...DEFAULT_OPTIONS, | |
| 707 | - ...remainingOptions, | |
| 708 | - body, | |
| 709 | - headers | |
| 710 | - }); | |
| 711 | - return responsePromise.then(value => Promise.resolve(value).then(checkStatus).catch(response => parseAndThrowError(response, parse)).then(response => parseResponseAndNormalizeError(response, parse)), err => { | |
| 712 | - // Re-throw AbortError for the users to handle it themselves. | |
| 713 | - if (err && err.name === 'AbortError') { | |
| 714 | - throw err; | |
| 715 | - } // Otherwise, there is most likely no network connection. | |
| 716 | - // Unfortunately the message might depend on the browser. | |
| 717 | - | |
| 718 | - | |
| 719 | - throw { | |
| 720 | - code: 'fetch_error', | |
| 721 | - message: (0,external_wp_i18n_namespaceObject.__)('You are probably offline.') | |
| 722 | - }; | |
| 723 | - }); | |
| 724 | -}; | |
| 725 | -/** @type {FetchHandler} */ | |
| 726 | - | |
| 727 | - | |
| 728 | -let fetchHandler = defaultFetchHandler; | |
| 729 | -/** | |
| 730 | - * Defines a custom fetch handler for making the requests that will override | |
| 731 | - * the default one using window.fetch | |
| 732 | - * | |
| 733 | - * @param {FetchHandler} newFetchHandler The new fetch handler | |
| 734 | - */ | |
| 735 | - | |
| 736 | -function setFetchHandler(newFetchHandler) { | |
| 737 | - fetchHandler = newFetchHandler; | |
| 738 | -} | |
| 739 | -/** | |
| 740 | - * @template T | |
| 741 | - * @param {import('./types').APIFetchOptions} options | |
| 742 | - * @return {Promise<T>} A promise representing the request processed via the registered middlewares. | |
| 743 | - */ | |
| 744 | - | |
| 745 | - | |
| 746 | -function apiFetch(options) { | |
| 747 | - // creates a nested function chain that calls all middlewares and finally the `fetchHandler`, | |
| 748 | - // converting `middlewares = [ m1, m2, m3 ]` into: | |
| 749 | - // ``` | |
| 750 | - // opts1 => m1( opts1, opts2 => m2( opts2, opts3 => m3( opts3, fetchHandler ) ) ); | |
| 751 | - // ``` | |
| 752 | - const enhancedHandler = middlewares.reduceRight(( | |
| 753 | - /** @type {FetchHandler} */ | |
| 754 | - next, middleware) => { | |
| 755 | - return workingOptions => middleware(workingOptions, next); | |
| 756 | - }, fetchHandler); | |
| 757 | - return enhancedHandler(options).catch(error => { | |
| 758 | - if (error.code !== 'rest_cookie_invalid_nonce') { | |
| 759 | - return Promise.reject(error); | |
| 760 | - } // If the nonce is invalid, refresh it and try again. | |
| 761 | - | |
| 762 | - | |
| 763 | - return window // @ts-ignore | |
| 764 | - .fetch(apiFetch.nonceEndpoint).then(checkStatus).then(data => data.text()).then(text => { | |
| 765 | - // @ts-ignore | |
| 766 | - apiFetch.nonceMiddleware.nonce = text; | |
| 767 | - return apiFetch(options); | |
| 768 | - }); | |
| 769 | - }); | |
| 770 | -} | |
| 771 | - | |
| 772 | -apiFetch.use = registerMiddleware; | |
| 773 | -apiFetch.setFetchHandler = setFetchHandler; | |
| 774 | -apiFetch.createNonceMiddleware = nonce; | |
| 775 | -apiFetch.createPreloadingMiddleware = preloading; | |
| 776 | -apiFetch.createRootURLMiddleware = root_url; | |
| 777 | -apiFetch.fetchAllMiddleware = fetch_all_middleware; | |
| 778 | -apiFetch.mediaUploadMiddleware = media_upload; | |
| 779 | -/* harmony default export */ var build_module = (apiFetch); | |
| 780 | -//# sourceMappingURL=index.js.map | |
| 781 | -(window.wp = window.wp || {}).apiFetch = __webpack_exports__["default"]; | |
| 782 | -/******/ })() | |
| 783 | -; | |
| 1 | +this.wp=this.wp||{},this.wp.apiFetch=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=394)}({1:function(e,t){!function(){e.exports=this.wp.i18n}()},14:function(e,t,r){"use strict";r.d(t,"a",(function(){return o}));var n=r(41);function o(e,t){if(null==e)return{};var r,o,c=Object(n.a)(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(c[r]=e[r])}return c}},22:function(e,t){!function(){e.exports=this.regeneratorRuntime}()},28:function(e,t){!function(){e.exports=this.wp.url}()},394:function(e,t,r){"use strict";r.r(t);var n=r(5),o=r(14),c=r(1);function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var u=function(e){function t(e,r){var n=e.headers,o=void 0===n?{}:n;for(var c in o)if("x-wp-nonce"===c.toLowerCase())return r(e);return r(a({},e,{headers:a({},o,{"X-WP-Nonce":t.nonce})}))}return t.nonce=e,t};function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var p=function(e,t){var r,o,c=e.path;return"string"==typeof e.namespace&&"string"==typeof e.endpoint&&(r=e.namespace.replace(/^\/|\/$/g,""),c=(o=e.endpoint.replace(/^\//,""))?r+"/"+o:r),delete e.namespace,delete e.endpoint,t(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?s(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},e,{path:c}))};function f(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var l=function(e){return function(t,r){return p(t,(function(t){var o,c=t.url,i=t.path;return"string"==typeof i&&(o=e,-1!==e.indexOf("?")&&(i=i.replace("?","&")),i=i.replace(/^\//,""),"string"==typeof o&&-1!==o.indexOf("?")&&(i=i.replace("?","&")),c=o+i),r(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?f(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):f(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},t,{url:c}))}))}};function O(e){var t=e.split("?"),r=t[1],n=t[0];return r?n+"?"+r.split("&").map((function(e){return e.split("=")})).sort((function(e,t){return e[0].localeCompare(t[0])})).map((function(e){return e.join("=")})).join("&"):n}var b=function(e){var t=Object.keys(e).reduce((function(t,r){return t[O(r)]=e[r],t}),{});return function(e,r){var n=e.parse,o=void 0===n||n;if("string"==typeof e.path){var c=e.method||"GET",i=O(e.path);if(o&&"GET"===c&&t[i])return Promise.resolve(t[i].body);if("OPTIONS"===c&&t[c]&&t[c][i])return Promise.resolve(t[c][i])}return r(e)}},d=r(22),j=r.n(d),y=r(43),h=r(28);function v(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function g(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var P=function(e){return e.json?e.json():Promise.reject(e)},w=function(e){return function(e){if(!e)return{};var t=e.match(/<([^>]+)>; rel="next"/);return t?{next:t[1]}:{}}(e.headers.get("link")).next},m=function(e){var t=e.path&&-1!==e.path.indexOf("per_page=-1"),r=e.url&&-1!==e.url.indexOf("per_page=-1");return t||r},x=function(){var e=Object(y.a)(j.a.mark((function e(t,r){var n,c,i,a,u,s;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!1!==t.parse){e.next=2;break}return e.abrupt("return",r(t));case 2:if(m(t)){e.next=4;break}return e.abrupt("return",r(t));case 4:return e.next=6,F(g({},(f={per_page:100},l=void 0,O=void 0,l=(p=t).path,O=p.url,g({},Object(o.a)(p,["path","url"]),{url:O&&Object(h.addQueryArgs)(O,f),path:l&&Object(h.addQueryArgs)(l,f)})),{parse:!1}));case 6:return n=e.sent,e.next=9,P(n);case 9:if(c=e.sent,Array.isArray(c)){e.next=12;break}return e.abrupt("return",c);case 12:if(i=w(n)){e.next=15;break}return e.abrupt("return",c);case 15:a=[].concat(c);case 16:if(!i){e.next=27;break}return e.next=19,F(g({},t,{path:void 0,url:i,parse:!1}));case 19:return u=e.sent,e.next=22,P(u);case 22:s=e.sent,a=a.concat(s),i=w(u),e.next=16;break;case 27:return e.abrupt("return",a);case 28:case"end":return e.stop()}var p,f,l,O}),e)})));return function(t,r){return e.apply(this,arguments)}}();function D(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?D(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):D(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var S=new Set(["PATCH","PUT","DELETE"]);var E=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t?204===e.status?null:e.json?e.json():Promise.reject(e):e},k=function(e){var t={code:"invalid_json",message:Object(c.__)("The response is not a valid JSON response.")};if(!e||!e.json)throw t;return e.json().catch((function(){throw t}))},T=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return Promise.resolve(E(e,t)).catch((function(e){return A(e,t)}))};function A(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!t)throw e;return k(e).then((function(e){var t={code:"unknown_error",message:Object(c.__)("An unknown error occurred.")};throw e||t}))}function M(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}var C=function(e,t){if(!(e.path&&-1!==e.path.indexOf("/wp/v2/media")||e.url&&-1!==e.url.indexOf("/wp/v2/media")))return t(e,t);var r=0;return t(function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?M(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):M(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({},e,{parse:!1})).catch((function(n){var o=n.headers.get("x-wp-upload-attachment-id");return n.status>=500&&n.status<600&&o?function e(n){return r++,t({path:"/wp/v2/media/".concat(n,"/post-process"),method:"POST",data:{action:"create-image-subsizes"},parse:!1}).catch((function(){return r<5?e(n):(t({path:"/wp/v2/media/".concat(n,"?force=true"),method:"DELETE"}),Promise.reject())}))}(o).catch((function(){return!1!==e.parse?Promise.reject({code:"post_process",message:Object(c.__)("Media upload failed. If this is a photo or a large image, please scale it down and try again.")}):Promise.reject(n)})):A(n,e.parse)})).then((function(t){return T(t,e.parse)}))};function Q(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function N(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Q(Object(r),!0).forEach((function(t){Object(n.a)(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Q(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var L={Accept:"application/json, */*;q=0.1"},U={credentials:"include"},G=[function(e,t){return"string"!=typeof e.url||Object(h.hasQueryArg)(e.url,"_locale")||(e.url=Object(h.addQueryArgs)(e.url,{_locale:"user"})),"string"!=typeof e.path||Object(h.hasQueryArg)(e.path,"_locale")||(e.path=Object(h.addQueryArgs)(e.path,{_locale:"user"})),t(e,t)},p,function(e,t){var r=e.method,n=void 0===r?"GET":r;return S.has(n.toUpperCase())&&(e=_({},e,{headers:_({},e.headers,{"X-HTTP-Method-Override":n,"Content-Type":"application/json"}),method:"POST"})),t(e,t)},x];var H=function(e){if(e.status>=200&&e.status<300)return e;throw e},I=function(e){var t=e.url,r=e.path,n=e.data,i=e.parse,a=void 0===i||i,u=Object(o.a)(e,["url","path","data","parse"]),s=e.body,p=e.headers;return p=N({},L,{},p),n&&(s=JSON.stringify(n),p["Content-Type"]="application/json"),window.fetch(t||r,N({},U,{},u,{body:s,headers:p})).then((function(e){return Promise.resolve(e).then(H).catch((function(e){return A(e,a)})).then((function(e){return T(e,a)}))}),(function(){throw{code:"fetch_error",message:Object(c.__)("You are probably offline.")}}))};function R(e){var t=[].concat(G,[I]);return new Promise((function(r,n){(function e(r){return function(n){var o=t[r];return r===t.length-1?o(n):o(n,e(r+1))}})(0)(e).then(r).catch((function(t){if("rest_cookie_invalid_nonce"!==t.code)return n(t);window.fetch(R.nonceEndpoint).then(H).then((function(e){return e.text()})).then((function(t){R.nonceMiddleware.nonce=t,R(e).then(r).catch(n)})).catch(n)}))}))}R.use=function(e){G.unshift(e)},R.setFetchHandler=function(e){I=e},R.createNonceMiddleware=u,R.createPreloadingMiddleware=b,R.createRootURLMiddleware=l,R.fetchAllMiddleware=x,R.mediaUploadMiddleware=C;var F=t.default=R},41:function(e,t,r){"use strict";function n(e,t){if(null==e)return{};var r,n,o={},c=Object.keys(e);for(n=0;n<c.length;n++)r=c[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}r.d(t,"a",(function(){return n}))},43:function(e,t,r){"use strict";function n(e,t,r,n,o,c,i){try{var a=e[c](i),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).then(n,o)}function o(e){return function(){var t=this,r=arguments;return new Promise((function(o,c){var i=e.apply(t,r);function a(e){n(i,o,c,a,u,"next",e)}function u(e){n(i,o,c,a,u,"throw",e)}a(void 0)}))}}r.d(t,"a",(function(){return o}))},5:function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}r.d(t,"a",(function(){return n}))}}).default; | |