wp/wp-includes/js/dist/api-fetch.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 this["wp"] = this["wp"] || {}; this["wp"]["apiFetch"] =
     1 /******/ (function() { // webpackBootstrap
     2 /******/ (function(modules) { // webpackBootstrap
     2 /******/ 	"use strict";
     3 /******/ 	// The module cache
     3 /******/ 	// The require scope
     4 /******/ 	var installedModules = {};
     4 /******/ 	var __webpack_require__ = {};
     5 /******/
     5 /******/ 	
     6 /******/ 	// The require function
     6 /************************************************************************/
     7 /******/ 	function __webpack_require__(moduleId) {
     7 /******/ 	/* webpack/runtime/define property getters */
     8 /******/
     8 /******/ 	!function() {
     9 /******/ 		// Check if module is in cache
     9 /******/ 		// define getter functions for harmony exports
    10 /******/ 		if(installedModules[moduleId]) {
    10 /******/ 		__webpack_require__.d = function(exports, definition) {
    11 /******/ 			return installedModules[moduleId].exports;
    11 /******/ 			for(var key in definition) {
    12 /******/ 		}
    12 /******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
    13 /******/ 		// Create a new module (and put it into the cache)
    13 /******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
    14 /******/ 		var module = installedModules[moduleId] = {
    14 /******/ 				}
    15 /******/ 			i: moduleId,
    15 /******/ 			}
    16 /******/ 			l: false,
       
    17 /******/ 			exports: {}
       
    18 /******/ 		};
    16 /******/ 		};
    19 /******/
    17 /******/ 	}();
    20 /******/ 		// Execute the module function
    18 /******/ 	
    21 /******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
    19 /******/ 	/* webpack/runtime/hasOwnProperty shorthand */
    22 /******/
    20 /******/ 	!function() {
    23 /******/ 		// Flag the module as loaded
    21 /******/ 		__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
    24 /******/ 		module.l = true;
    22 /******/ 	}();
    25 /******/
    23 /******/ 	
    26 /******/ 		// Return the exports of the module
       
    27 /******/ 		return module.exports;
       
    28 /******/ 	}
       
    29 /******/
       
    30 /******/
       
    31 /******/ 	// expose the modules object (__webpack_modules__)
       
    32 /******/ 	__webpack_require__.m = modules;
       
    33 /******/
       
    34 /******/ 	// expose the module cache
       
    35 /******/ 	__webpack_require__.c = installedModules;
       
    36 /******/
       
    37 /******/ 	// define getter function for harmony exports
       
    38 /******/ 	__webpack_require__.d = function(exports, name, getter) {
       
    39 /******/ 		if(!__webpack_require__.o(exports, name)) {
       
    40 /******/ 			Object.defineProperty(exports, name, { enumerable: true, get: getter });
       
    41 /******/ 		}
       
    42 /******/ 	};
       
    43 /******/
       
    44 /******/ 	// define __esModule on exports
       
    45 /******/ 	__webpack_require__.r = function(exports) {
       
    46 /******/ 		if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
       
    47 /******/ 			Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
       
    48 /******/ 		}
       
    49 /******/ 		Object.defineProperty(exports, '__esModule', { value: true });
       
    50 /******/ 	};
       
    51 /******/
       
    52 /******/ 	// create a fake namespace object
       
    53 /******/ 	// mode & 1: value is a module id, require it
       
    54 /******/ 	// mode & 2: merge all properties of value into the ns
       
    55 /******/ 	// mode & 4: return value when already ns object
       
    56 /******/ 	// mode & 8|1: behave like require
       
    57 /******/ 	__webpack_require__.t = function(value, mode) {
       
    58 /******/ 		if(mode & 1) value = __webpack_require__(value);
       
    59 /******/ 		if(mode & 8) return value;
       
    60 /******/ 		if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
       
    61 /******/ 		var ns = Object.create(null);
       
    62 /******/ 		__webpack_require__.r(ns);
       
    63 /******/ 		Object.defineProperty(ns, 'default', { enumerable: true, value: value });
       
    64 /******/ 		if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
       
    65 /******/ 		return ns;
       
    66 /******/ 	};
       
    67 /******/
       
    68 /******/ 	// getDefaultExport function for compatibility with non-harmony modules
       
    69 /******/ 	__webpack_require__.n = function(module) {
       
    70 /******/ 		var getter = module && module.__esModule ?
       
    71 /******/ 			function getDefault() { return module['default']; } :
       
    72 /******/ 			function getModuleExports() { return module; };
       
    73 /******/ 		__webpack_require__.d(getter, 'a', getter);
       
    74 /******/ 		return getter;
       
    75 /******/ 	};
       
    76 /******/
       
    77 /******/ 	// Object.prototype.hasOwnProperty.call
       
    78 /******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
       
    79 /******/
       
    80 /******/ 	// __webpack_public_path__
       
    81 /******/ 	__webpack_require__.p = "";
       
    82 /******/
       
    83 /******/
       
    84 /******/ 	// Load entry module and return exports
       
    85 /******/ 	return __webpack_require__(__webpack_require__.s = "jqrR");
       
    86 /******/ })
       
    87 /************************************************************************/
    24 /************************************************************************/
    88 /******/ ({
    25 var __webpack_exports__ = {};
    89 
    26 
    90 /***/ "Mmq9":
    27 // EXPORTS
    91 /***/ (function(module, exports) {
    28 __webpack_require__.d(__webpack_exports__, {
    92 
    29   "default": function() { return /* binding */ build_module; }
    93 (function() { module.exports = window["wp"]["url"]; }());
    30 });
    94 
    31 
    95 /***/ }),
    32 ;// CONCATENATED MODULE: external ["wp","i18n"]
    96 
    33 var external_wp_i18n_namespaceObject = window["wp"]["i18n"];
    97 /***/ "jqrR":
    34 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
    98 /***/ (function(module, __webpack_exports__, __webpack_require__) {
       
    99 
       
   100 "use strict";
       
   101 // ESM COMPAT FLAG
       
   102 __webpack_require__.r(__webpack_exports__);
       
   103 
       
   104 // EXTERNAL MODULE: external ["wp","i18n"]
       
   105 var external_wp_i18n_ = __webpack_require__("l3Sj");
       
   106 
       
   107 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
       
   108 /**
    35 /**
   109  * @param {string} nonce
    36  * @param {string} nonce
   110  * @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce.
    37  * @return {import('../types').APIFetchMiddleware & { nonce: string }} A middleware to enhance a request with a nonce.
   111  */
    38  */
   112 function createNonceMiddleware(nonce) {
    39 function createNonceMiddleware(nonce) {
   136   return middleware;
    63   return middleware;
   137 }
    64 }
   138 
    65 
   139 /* harmony default export */ var nonce = (createNonceMiddleware);
    66 /* harmony default export */ var nonce = (createNonceMiddleware);
   140 
    67 
   141 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
    68 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
   142 /**
    69 /**
   143  * @type {import('../types').APIFetchMiddleware}
    70  * @type {import('../types').APIFetchMiddleware}
   144  */
    71  */
   145 const namespaceAndEndpointMiddleware = (options, next) => {
    72 const namespaceAndEndpointMiddleware = (options, next) => {
   146   let path = options.path;
    73   let path = options.path;
   164   });
    91   });
   165 };
    92 };
   166 
    93 
   167 /* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware);
    94 /* harmony default export */ var namespace_endpoint = (namespaceAndEndpointMiddleware);
   168 
    95 
   169 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
    96 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
   170 /**
    97 /**
   171  * Internal dependencies
    98  * Internal dependencies
   172  */
    99  */
   173 
   100 
   174 /**
   101 /**
   205   });
   132   });
   206 };
   133 };
   207 
   134 
   208 /* harmony default export */ var root_url = (createRootURLMiddleware);
   135 /* harmony default export */ var root_url = (createRootURLMiddleware);
   209 
   136 
   210 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
   137 ;// CONCATENATED MODULE: external ["wp","url"]
   211 /**
   138 var external_wp_url_namespaceObject = window["wp"]["url"];
   212  * Given a path, returns a normalized path where equal query parameter values
   139 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
   213  * will be treated as identical, regardless of order they appear in the original
   140 /**
   214  * text.
   141  * WordPress dependencies
   215  *
   142  */
   216  * @param {string} path Original path.
   143 
   217  *
       
   218  * @return {string} Normalized path.
       
   219  */
       
   220 function getStablePath(path) {
       
   221   const splitted = path.split('?');
       
   222   const query = splitted[1];
       
   223   const base = splitted[0];
       
   224 
       
   225   if (!query) {
       
   226     return base;
       
   227   } // 'b=1&c=2&a=5'
       
   228 
       
   229 
       
   230   return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
       
   231   .split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
       
   232   .map(entry => entry.split('=')) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
       
   233   .sort((a, b) => a[0].localeCompare(b[0])) // [ 'a=5', 'b=1', 'c=2' ]
       
   234   .map(pair => pair.join('=')) // 'a=5&b=1&c=2'
       
   235   .join('&');
       
   236 }
       
   237 /**
   144 /**
   238  * @param {Record<string, any>} preloadedData
   145  * @param {Record<string, any>} preloadedData
   239  * @return {import('../types').APIFetchMiddleware} Preloading middleware.
   146  * @return {import('../types').APIFetchMiddleware} Preloading middleware.
   240  */
   147  */
   241 
   148 
   242 function createPreloadingMiddleware(preloadedData) {
   149 function createPreloadingMiddleware(preloadedData) {
   243   const cache = Object.keys(preloadedData).reduce((result, path) => {
   150   const cache = Object.fromEntries(Object.entries(preloadedData).map(_ref => {
   244     result[getStablePath(path)] = preloadedData[path];
   151     let [path, data] = _ref;
   245     return result;
   152     return [(0,external_wp_url_namespaceObject.normalizePath)(path), data];
   246   },
   153   }));
   247   /** @type {Record<string, any>} */
       
   248   {});
       
   249   return (options, next) => {
   154   return (options, next) => {
   250     const {
   155     const {
   251       parse = true
   156       parse = true
   252     } = options;
   157     } = options;
   253 
   158     /** @type {string | void} */
   254     if (typeof options.path === 'string') {
   159 
   255       const method = options.method || 'GET';
   160     let rawPath = options.path;
   256       const path = getStablePath(options.path);
   161 
   257 
   162     if (!rawPath && options.url) {
   258       if ('GET' === method && cache[path]) {
   163       const {
   259         const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only preloaded a single time
   164         rest_route: pathFromQuery,
   260 
   165         ...queryArgs
   261         delete cache[path];
   166       } = (0,external_wp_url_namespaceObject.getQueryArgs)(options.url);
   262         return Promise.resolve(parse ? cacheData.body : new window.Response(JSON.stringify(cacheData.body), {
   167 
   263           status: 200,
   168       if (typeof pathFromQuery === 'string') {
   264           statusText: 'OK',
   169         rawPath = (0,external_wp_url_namespaceObject.addQueryArgs)(pathFromQuery, queryArgs);
   265           headers: cacheData.headers
       
   266         }));
       
   267       } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
       
   268         return Promise.resolve(parse ? cache[method][path].body : cache[method][path]);
       
   269       }
   170       }
       
   171     }
       
   172 
       
   173     if (typeof rawPath !== 'string') {
       
   174       return next(options);
       
   175     }
       
   176 
       
   177     const method = options.method || 'GET';
       
   178     const path = (0,external_wp_url_namespaceObject.normalizePath)(rawPath);
       
   179 
       
   180     if ('GET' === method && cache[path]) {
       
   181       const cacheData = cache[path]; // Unsetting the cache key ensures that the data is only used a single time.
       
   182 
       
   183       delete cache[path];
       
   184       return prepareResponse(cacheData, !!parse);
       
   185     } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
       
   186       const cacheData = cache[method][path]; // Unsetting the cache key ensures that the data is only used a single time.
       
   187 
       
   188       delete cache[method][path];
       
   189       return prepareResponse(cacheData, !!parse);
   270     }
   190     }
   271 
   191 
   272     return next(options);
   192     return next(options);
   273   };
   193   };
   274 }
   194 }
       
   195 /**
       
   196  * This is a helper function that sends a success response.
       
   197  *
       
   198  * @param {Record<string, any>} responseData
       
   199  * @param {boolean}             parse
       
   200  * @return {Promise<any>} Promise with the response.
       
   201  */
       
   202 
       
   203 
       
   204 function prepareResponse(responseData, parse) {
       
   205   return Promise.resolve(parse ? responseData.body : new window.Response(JSON.stringify(responseData.body), {
       
   206     status: 200,
       
   207     statusText: 'OK',
       
   208     headers: responseData.headers
       
   209   }));
       
   210 }
   275 
   211 
   276 /* harmony default export */ var preloading = (createPreloadingMiddleware);
   212 /* harmony default export */ var preloading = (createPreloadingMiddleware);
   277 
   213 
   278 // EXTERNAL MODULE: external ["wp","url"]
   214 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
   279 var external_wp_url_ = __webpack_require__("Mmq9");
       
   280 
       
   281 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
       
   282 /**
   215 /**
   283  * WordPress dependencies
   216  * WordPress dependencies
   284  */
   217  */
   285 
   218 
   286 /**
   219 /**
   290 
   223 
   291 /**
   224 /**
   292  * Apply query arguments to both URL and Path, whichever is present.
   225  * Apply query arguments to both URL and Path, whichever is present.
   293  *
   226  *
   294  * @param {import('../types').APIFetchOptions} props
   227  * @param {import('../types').APIFetchOptions} props
   295  * @param {Record<string, string | number>} queryArgs
   228  * @param {Record<string, string | number>}    queryArgs
   296  * @return {import('../types').APIFetchOptions} The request with the modified query args
   229  * @return {import('../types').APIFetchOptions} The request with the modified query args
   297  */
   230  */
   298 
   231 
   299 const modifyQuery = ({
   232 const modifyQuery = (_ref, queryArgs) => {
   300   path,
   233   let {
   301   url,
   234     path,
   302   ...options
   235     url,
   303 }, queryArgs) => ({ ...options,
   236     ...options
   304   url: url && Object(external_wp_url_["addQueryArgs"])(url, queryArgs),
   237   } = _ref;
   305   path: path && Object(external_wp_url_["addQueryArgs"])(path, queryArgs)
   238   return { ...options,
   306 });
   239     url: url && (0,external_wp_url_namespaceObject.addQueryArgs)(url, queryArgs),
       
   240     path: path && (0,external_wp_url_namespaceObject.addQueryArgs)(path, queryArgs)
       
   241   };
       
   242 };
   307 /**
   243 /**
   308  * Duplicates parsing functionality from apiFetch.
   244  * Duplicates parsing functionality from apiFetch.
   309  *
   245  *
   310  * @param {Response} response
   246  * @param {Response} response
   311  * @return {Promise<any>} Parsed response json.
   247  * @return {Promise<any>} Parsed response json.
   414   return mergedResults;
   350   return mergedResults;
   415 };
   351 };
   416 
   352 
   417 /* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware);
   353 /* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware);
   418 
   354 
   419 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
   355 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
   420 /**
   356 /**
   421  * Set of HTTP methods which are eligible to be overridden.
   357  * Set of HTTP methods which are eligible to be overridden.
   422  *
   358  *
   423  * @type {Set<string>}
   359  * @type {Set<string>}
   424  */
   360  */
   460   return next(options);
   396   return next(options);
   461 };
   397 };
   462 
   398 
   463 /* harmony default export */ var http_v1 = (httpV1Middleware);
   399 /* harmony default export */ var http_v1 = (httpV1Middleware);
   464 
   400 
   465 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
   401 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
   466 /**
   402 /**
   467  * WordPress dependencies
   403  * WordPress dependencies
   468  */
   404  */
   469 
   405 
   470 /**
   406 /**
   471  * @type {import('../types').APIFetchMiddleware}
   407  * @type {import('../types').APIFetchMiddleware}
   472  */
   408  */
   473 
   409 
   474 const userLocaleMiddleware = (options, next) => {
   410 const userLocaleMiddleware = (options, next) => {
   475   if (typeof options.url === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.url, '_locale')) {
   411   if (typeof options.url === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.url, '_locale')) {
   476     options.url = Object(external_wp_url_["addQueryArgs"])(options.url, {
   412     options.url = (0,external_wp_url_namespaceObject.addQueryArgs)(options.url, {
   477       _locale: 'user'
   413       _locale: 'user'
   478     });
   414     });
   479   }
   415   }
   480 
   416 
   481   if (typeof options.path === 'string' && !Object(external_wp_url_["hasQueryArg"])(options.path, '_locale')) {
   417   if (typeof options.path === 'string' && !(0,external_wp_url_namespaceObject.hasQueryArg)(options.path, '_locale')) {
   482     options.path = Object(external_wp_url_["addQueryArgs"])(options.path, {
   418     options.path = (0,external_wp_url_namespaceObject.addQueryArgs)(options.path, {
   483       _locale: 'user'
   419       _locale: 'user'
   484     });
   420     });
   485   }
   421   }
   486 
   422 
   487   return next(options);
   423   return next(options);
   488 };
   424 };
   489 
   425 
   490 /* harmony default export */ var user_locale = (userLocaleMiddleware);
   426 /* harmony default export */ var user_locale = (userLocaleMiddleware);
   491 
   427 
   492 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
   428 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
   493 /**
   429 /**
   494  * WordPress dependencies
   430  * WordPress dependencies
   495  */
   431  */
   496 
   432 
   497 /**
   433 /**
   501  * @param {boolean}  shouldParseResponse
   437  * @param {boolean}  shouldParseResponse
   502  *
   438  *
   503  * @return {Promise<any> | null | Response} Parsed response.
   439  * @return {Promise<any> | null | Response} Parsed response.
   504  */
   440  */
   505 
   441 
   506 const response_parseResponse = (response, shouldParseResponse = true) => {
   442 const response_parseResponse = function (response) {
       
   443   let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
       
   444 
   507   if (shouldParseResponse) {
   445   if (shouldParseResponse) {
   508     if (response.status === 204) {
   446     if (response.status === 204) {
   509       return null;
   447       return null;
   510     }
   448     }
   511 
   449 
   524 
   462 
   525 
   463 
   526 const parseJsonAndNormalizeError = response => {
   464 const parseJsonAndNormalizeError = response => {
   527   const invalidJsonError = {
   465   const invalidJsonError = {
   528     code: 'invalid_json',
   466     code: 'invalid_json',
   529     message: Object(external_wp_i18n_["__"])('The response is not a valid JSON response.')
   467     message: (0,external_wp_i18n_namespaceObject.__)('The response is not a valid JSON response.')
   530   };
   468   };
   531 
   469 
   532   if (!response || !response.json) {
   470   if (!response || !response.json) {
   533     throw invalidJsonError;
   471     throw invalidJsonError;
   534   }
   472   }
   545  *
   483  *
   546  * @return {Promise<any>} Parsed response.
   484  * @return {Promise<any>} Parsed response.
   547  */
   485  */
   548 
   486 
   549 
   487 
   550 const parseResponseAndNormalizeError = (response, shouldParseResponse = true) => {
   488 const parseResponseAndNormalizeError = function (response) {
       
   489   let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
   551   return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
   490   return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(res => parseAndThrowError(res, shouldParseResponse));
   552 };
   491 };
   553 /**
   492 /**
   554  * Parses a response, throwing an error if parsing the response fails.
   493  * Parses a response, throwing an error if parsing the response fails.
   555  *
   494  *
   556  * @param {Response} response
   495  * @param {Response} response
   557  * @param {boolean} shouldParseResponse
   496  * @param {boolean}  shouldParseResponse
   558  * @return {Promise<any>} Parsed response.
   497  * @return {Promise<any>} Parsed response.
   559  */
   498  */
   560 
   499 
   561 function parseAndThrowError(response, shouldParseResponse = true) {
   500 function parseAndThrowError(response) {
       
   501   let shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
       
   502 
   562   if (!shouldParseResponse) {
   503   if (!shouldParseResponse) {
   563     throw response;
   504     throw response;
   564   }
   505   }
   565 
   506 
   566   return parseJsonAndNormalizeError(response).then(error => {
   507   return parseJsonAndNormalizeError(response).then(error => {
   567     const unknownError = {
   508     const unknownError = {
   568       code: 'unknown_error',
   509       code: 'unknown_error',
   569       message: Object(external_wp_i18n_["__"])('An unknown error occurred.')
   510       message: (0,external_wp_i18n_namespaceObject.__)('An unknown error occurred.')
   570     };
   511     };
   571     throw error || unknownError;
   512     throw error || unknownError;
   572   });
   513   });
   573 }
   514 }
   574 
   515 
   575 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
   516 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
   576 /**
   517 /**
   577  * WordPress dependencies
   518  * WordPress dependencies
   578  */
   519  */
   579 
   520 
   580 /**
   521 /**
   581  * Internal dependencies
   522  * Internal dependencies
   582  */
   523  */
   583 
   524 
   584 
   525 
   585 /**
   526 /**
       
   527  * @param {import('../types').APIFetchOptions} options
       
   528  * @return {boolean} True if the request is for media upload.
       
   529  */
       
   530 
       
   531 function isMediaUploadRequest(options) {
       
   532   const isCreateMethod = !!options.method && options.method === 'POST';
       
   533   const isMediaEndpoint = !!options.path && options.path.indexOf('/wp/v2/media') !== -1 || !!options.url && options.url.indexOf('/wp/v2/media') !== -1;
       
   534   return isMediaEndpoint && isCreateMethod;
       
   535 }
       
   536 /**
   586  * Middleware handling media upload failures and retries.
   537  * Middleware handling media upload failures and retries.
   587  *
   538  *
   588  * @type {import('../types').APIFetchMiddleware}
   539  * @type {import('../types').APIFetchMiddleware}
   589  */
   540  */
   590 
   541 
       
   542 
   591 const mediaUploadMiddleware = (options, next) => {
   543 const mediaUploadMiddleware = (options, next) => {
   592   const isMediaUploadRequest = options.path && options.path.indexOf('/wp/v2/media') !== -1 || options.url && options.url.indexOf('/wp/v2/media') !== -1;
   544   if (!isMediaUploadRequest(options)) {
   593 
       
   594   if (!isMediaUploadRequest) {
       
   595     return next(options);
   545     return next(options);
   596   }
   546   }
   597 
   547 
   598   let retries = 0;
   548   let retries = 0;
   599   const maxRetries = 5;
   549   const maxRetries = 5;
   632     if (response.status >= 500 && response.status < 600 && attachmentId) {
   582     if (response.status >= 500 && response.status < 600 && attachmentId) {
   633       return postProcess(attachmentId).catch(() => {
   583       return postProcess(attachmentId).catch(() => {
   634         if (options.parse !== false) {
   584         if (options.parse !== false) {
   635           return Promise.reject({
   585           return Promise.reject({
   636             code: 'post_process',
   586             code: 'post_process',
   637             message: Object(external_wp_i18n_["__"])('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
   587             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.')
   638           });
   588           });
   639         }
   589         }
   640 
   590 
   641         return Promise.reject(response);
   591         return Promise.reject(response);
   642       });
   592       });
   646   }).then(response => parseResponseAndNormalizeError(response, options.parse));
   596   }).then(response => parseResponseAndNormalizeError(response, options.parse));
   647 };
   597 };
   648 
   598 
   649 /* harmony default export */ var media_upload = (mediaUploadMiddleware);
   599 /* harmony default export */ var media_upload = (mediaUploadMiddleware);
   650 
   600 
   651 // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
   601 ;// CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
   652 /**
   602 /**
   653  * WordPress dependencies
   603  * WordPress dependencies
   654  */
   604  */
   655 
   605 
   656 /**
   606 /**
   751   if (data) {
   701   if (data) {
   752     body = JSON.stringify(data);
   702     body = JSON.stringify(data);
   753     headers['Content-Type'] = 'application/json';
   703     headers['Content-Type'] = 'application/json';
   754   }
   704   }
   755 
   705 
   756   const responsePromise = window.fetch( // fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed
   706   const responsePromise = window.fetch( // Fall back to explicitly passing `window.location` which is the behavior if `undefined` is passed.
   757   url || path || window.location.href, { ...DEFAULT_OPTIONS,
   707   url || path || window.location.href, { ...DEFAULT_OPTIONS,
   758     ...remainingOptions,
   708     ...remainingOptions,
   759     body,
   709     body,
   760     headers
   710     headers
   761   });
   711   });
   762   return responsePromise // Return early if fetch errors. If fetch error, there is most likely no
   712   return responsePromise.then(value => Promise.resolve(value).then(checkStatus).catch(response => parseAndThrowError(response, parse)).then(response => parseResponseAndNormalizeError(response, parse)), err => {
   763   // network connection. Unfortunately fetch just throws a TypeError and
   713     // Re-throw AbortError for the users to handle it themselves.
   764   // the message might depend on the browser.
   714     if (err && err.name === 'AbortError') {
   765   .then(value => Promise.resolve(value).then(checkStatus).catch(response => parseAndThrowError(response, parse)).then(response => parseResponseAndNormalizeError(response, parse)), () => {
   715       throw err;
       
   716     } // Otherwise, there is most likely no network connection.
       
   717     // Unfortunately the message might depend on the browser.
       
   718 
       
   719 
   766     throw {
   720     throw {
   767       code: 'fetch_error',
   721       code: 'fetch_error',
   768       message: Object(external_wp_i18n_["__"])('You are probably offline.')
   722       message: (0,external_wp_i18n_namespaceObject.__)('You are probably offline.')
   769     };
   723     };
   770   });
   724   });
   771 };
   725 };
   772 /** @type {FetchHandler} */
   726 /** @type {FetchHandler} */
   773 
   727 
   821 apiFetch.createNonceMiddleware = nonce;
   775 apiFetch.createNonceMiddleware = nonce;
   822 apiFetch.createPreloadingMiddleware = preloading;
   776 apiFetch.createPreloadingMiddleware = preloading;
   823 apiFetch.createRootURLMiddleware = root_url;
   777 apiFetch.createRootURLMiddleware = root_url;
   824 apiFetch.fetchAllMiddleware = fetch_all_middleware;
   778 apiFetch.fetchAllMiddleware = fetch_all_middleware;
   825 apiFetch.mediaUploadMiddleware = media_upload;
   779 apiFetch.mediaUploadMiddleware = media_upload;
   826 /* harmony default export */ var build_module = __webpack_exports__["default"] = (apiFetch);
   780 /* harmony default export */ var build_module = (apiFetch);
   827 
   781 
   828 
   782 (window.wp = window.wp || {}).apiFetch = __webpack_exports__["default"];
   829 /***/ }),
   783 /******/ })()
   830 
   784 ;
   831 /***/ "l3Sj":
       
   832 /***/ (function(module, exports) {
       
   833 
       
   834 (function() { module.exports = window["wp"]["i18n"]; }());
       
   835 
       
   836 /***/ })
       
   837 
       
   838 /******/ })["default"];