[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/dist/ -> api-fetch.js (source)

   1  this["wp"] = this["wp"] || {}; this["wp"]["apiFetch"] =
   2  /******/ (function(modules) { // webpackBootstrap
   3  /******/     // The module cache
   4  /******/     var installedModules = {};
   5  /******/
   6  /******/     // The require function
   7  /******/ 	function __webpack_require__(moduleId) {
   8  /******/
   9  /******/         // Check if module is in cache
  10  /******/         if(installedModules[moduleId]) {
  11  /******/             return installedModules[moduleId].exports;
  12  /******/         }
  13  /******/         // Create a new module (and put it into the cache)
  14  /******/         var module = installedModules[moduleId] = {
  15  /******/             i: moduleId,
  16  /******/             l: false,
  17  /******/             exports: {}
  18  /******/         };
  19  /******/
  20  /******/         // Execute the module function
  21  /******/         modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22  /******/
  23  /******/         // Flag the module as loaded
  24  /******/         module.l = true;
  25  /******/
  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 = 375);
  86  /******/ })
  87  /************************************************************************/
  88  /******/ ({
  89  
  90  /***/ 1:
  91  /***/ (function(module, exports) {
  92  
  93  (function() { module.exports = this["wp"]["i18n"]; }());
  94  
  95  /***/ }),
  96  
  97  /***/ 21:
  98  /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99  
 100  "use strict";
 101  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectWithoutProperties; });
 102  /* harmony import */ var _objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(40);
 103  
 104  function _objectWithoutProperties(source, excluded) {
 105    if (source == null) return {};
 106    var target = Object(_objectWithoutPropertiesLoose__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(source, excluded);
 107    var key, i;
 108  
 109    if (Object.getOwnPropertySymbols) {
 110      var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
 111  
 112      for (i = 0; i < sourceSymbolKeys.length; i++) {
 113        key = sourceSymbolKeys[i];
 114        if (excluded.indexOf(key) >= 0) continue;
 115        if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
 116        target[key] = source[key];
 117      }
 118    }
 119  
 120    return target;
 121  }
 122  
 123  /***/ }),
 124  
 125  /***/ 23:
 126  /***/ (function(module, exports) {
 127  
 128  (function() { module.exports = this["regeneratorRuntime"]; }());
 129  
 130  /***/ }),
 131  
 132  /***/ 25:
 133  /***/ (function(module, exports) {
 134  
 135  (function() { module.exports = this["wp"]["url"]; }());
 136  
 137  /***/ }),
 138  
 139  /***/ 375:
 140  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 141  
 142  "use strict";
 143  __webpack_require__.r(__webpack_exports__);
 144  
 145  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectSpread.js
 146  var objectSpread = __webpack_require__(7);
 147  
 148  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/objectWithoutProperties.js
 149  var objectWithoutProperties = __webpack_require__(21);
 150  
 151  // EXTERNAL MODULE: external {"this":["wp","i18n"]}
 152  var external_this_wp_i18n_ = __webpack_require__(1);
 153  
 154  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/nonce.js
 155  
 156  
 157  function createNonceMiddleware(nonce) {
 158    function middleware(options, next) {
 159      var _options$headers = options.headers,
 160          headers = _options$headers === void 0 ? {} : _options$headers; // If an 'X-WP-Nonce' header (or any case-insensitive variation
 161      // thereof) was specified, no need to add a nonce header.
 162  
 163      for (var headerName in headers) {
 164        if (headerName.toLowerCase() === 'x-wp-nonce') {
 165          return next(options);
 166        }
 167      }
 168  
 169      return next(Object(objectSpread["a" /* default */])({}, options, {
 170        headers: Object(objectSpread["a" /* default */])({}, headers, {
 171          'X-WP-Nonce': middleware.nonce
 172        })
 173      }));
 174    }
 175  
 176    middleware.nonce = nonce;
 177    return middleware;
 178  }
 179  
 180  /* harmony default export */ var middlewares_nonce = (createNonceMiddleware);
 181  
 182  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/namespace-endpoint.js
 183  
 184  
 185  var namespace_endpoint_namespaceAndEndpointMiddleware = function namespaceAndEndpointMiddleware(options, next) {
 186    var path = options.path;
 187    var namespaceTrimmed, endpointTrimmed;
 188  
 189    if (typeof options.namespace === 'string' && typeof options.endpoint === 'string') {
 190      namespaceTrimmed = options.namespace.replace(/^\/|\/$/g, '');
 191      endpointTrimmed = options.endpoint.replace(/^\//, '');
 192  
 193      if (endpointTrimmed) {
 194        path = namespaceTrimmed + '/' + endpointTrimmed;
 195      } else {
 196        path = namespaceTrimmed;
 197      }
 198    }
 199  
 200    delete options.namespace;
 201    delete options.endpoint;
 202    return next(Object(objectSpread["a" /* default */])({}, options, {
 203      path: path
 204    }));
 205  };
 206  
 207  /* harmony default export */ var namespace_endpoint = (namespace_endpoint_namespaceAndEndpointMiddleware);
 208  
 209  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/root-url.js
 210  
 211  
 212  /**
 213   * Internal dependencies
 214   */
 215  
 216  
 217  var root_url_createRootURLMiddleware = function createRootURLMiddleware(rootURL) {
 218    return function (options, next) {
 219      return namespace_endpoint(options, function (optionsWithPath) {
 220        var url = optionsWithPath.url;
 221        var path = optionsWithPath.path;
 222        var apiRoot;
 223  
 224        if (typeof path === 'string') {
 225          apiRoot = rootURL;
 226  
 227          if (-1 !== rootURL.indexOf('?')) {
 228            path = path.replace('?', '&');
 229          }
 230  
 231          path = path.replace(/^\//, ''); // API root may already include query parameter prefix if site is
 232          // configured to use plain permalinks.
 233  
 234          if ('string' === typeof apiRoot && -1 !== apiRoot.indexOf('?')) {
 235            path = path.replace('?', '&');
 236          }
 237  
 238          url = apiRoot + path;
 239        }
 240  
 241        return next(Object(objectSpread["a" /* default */])({}, optionsWithPath, {
 242          url: url
 243        }));
 244      });
 245    };
 246  };
 247  
 248  /* harmony default export */ var root_url = (root_url_createRootURLMiddleware);
 249  
 250  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/preloading.js
 251  /**
 252   * Given a path, returns a normalized path where equal query parameter values
 253   * will be treated as identical, regardless of order they appear in the original
 254   * text.
 255   *
 256   * @param {string} path Original path.
 257   *
 258   * @return {string} Normalized path.
 259   */
 260  function getStablePath(path) {
 261    var splitted = path.split('?');
 262    var query = splitted[1];
 263    var base = splitted[0];
 264  
 265    if (!query) {
 266      return base;
 267    } // 'b=1&c=2&a=5'
 268  
 269  
 270    return base + '?' + query // [ 'b=1', 'c=2', 'a=5' ]
 271    .split('&') // [ [ 'b, '1' ], [ 'c', '2' ], [ 'a', '5' ] ]
 272    .map(function (entry) {
 273      return entry.split('=');
 274    }) // [ [ 'a', '5' ], [ 'b, '1' ], [ 'c', '2' ] ]
 275    .sort(function (a, b) {
 276      return a[0].localeCompare(b[0]);
 277    }) // [ 'a=5', 'b=1', 'c=2' ]
 278    .map(function (pair) {
 279      return pair.join('=');
 280    }) // 'a=5&b=1&c=2'
 281    .join('&');
 282  }
 283  
 284  function createPreloadingMiddleware(preloadedData) {
 285    var cache = Object.keys(preloadedData).reduce(function (result, path) {
 286      result[getStablePath(path)] = preloadedData[path];
 287      return result;
 288    }, {});
 289    return function (options, next) {
 290      var _options$parse = options.parse,
 291          parse = _options$parse === void 0 ? true : _options$parse;
 292  
 293      if (typeof options.path === 'string') {
 294        var method = options.method || 'GET';
 295        var path = getStablePath(options.path);
 296  
 297        if (parse && 'GET' === method && cache[path]) {
 298          return Promise.resolve(cache[path].body);
 299        } else if ('OPTIONS' === method && cache[method] && cache[method][path]) {
 300          return Promise.resolve(cache[method][path]);
 301        }
 302      }
 303  
 304      return next(options);
 305    };
 306  }
 307  
 308  /* harmony default export */ var preloading = (createPreloadingMiddleware);
 309  
 310  // EXTERNAL MODULE: external {"this":"regeneratorRuntime"}
 311  var external_this_regeneratorRuntime_ = __webpack_require__(23);
 312  var external_this_regeneratorRuntime_default = /*#__PURE__*/__webpack_require__.n(external_this_regeneratorRuntime_);
 313  
 314  // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js
 315  var asyncToGenerator = __webpack_require__(43);
 316  
 317  // EXTERNAL MODULE: external {"this":["wp","url"]}
 318  var external_this_wp_url_ = __webpack_require__(25);
 319  
 320  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/fetch-all-middleware.js
 321  
 322  
 323  
 324  
 325  
 326  /**
 327   * WordPress dependencies
 328   */
 329   // Apply query arguments to both URL and Path, whichever is present.
 330  
 331  var fetch_all_middleware_modifyQuery = function modifyQuery(_ref, queryArgs) {
 332    var path = _ref.path,
 333        url = _ref.url,
 334        options = Object(objectWithoutProperties["a" /* default */])(_ref, ["path", "url"]);
 335  
 336    return Object(objectSpread["a" /* default */])({}, options, {
 337      url: url && Object(external_this_wp_url_["addQueryArgs"])(url, queryArgs),
 338      path: path && Object(external_this_wp_url_["addQueryArgs"])(path, queryArgs)
 339    });
 340  }; // Duplicates parsing functionality from apiFetch.
 341  
 342  
 343  var parseResponse = function parseResponse(response) {
 344    return response.json ? response.json() : Promise.reject(response);
 345  };
 346  
 347  var parseLinkHeader = function parseLinkHeader(linkHeader) {
 348    if (!linkHeader) {
 349      return {};
 350    }
 351  
 352    var match = linkHeader.match(/<([^>]+)>; rel="next"/);
 353    return match ? {
 354      next: match[1]
 355    } : {};
 356  };
 357  
 358  var getNextPageUrl = function getNextPageUrl(response) {
 359    var _parseLinkHeader = parseLinkHeader(response.headers.get('link')),
 360        next = _parseLinkHeader.next;
 361  
 362    return next;
 363  };
 364  
 365  var requestContainsUnboundedQuery = function requestContainsUnboundedQuery(options) {
 366    var pathIsUnbounded = options.path && options.path.indexOf('per_page=-1') !== -1;
 367    var urlIsUnbounded = options.url && options.url.indexOf('per_page=-1') !== -1;
 368    return pathIsUnbounded || urlIsUnbounded;
 369  }; // The REST API enforces an upper limit on the per_page option. To handle large
 370  // collections, apiFetch consumers can pass `per_page=-1`; this middleware will
 371  // then recursively assemble a full response array from all available pages.
 372  
 373  
 374  var fetchAllMiddleware =
 375  /*#__PURE__*/
 376  function () {
 377    var _ref2 = Object(asyncToGenerator["a" /* default */])(
 378    /*#__PURE__*/
 379    external_this_regeneratorRuntime_default.a.mark(function _callee(options, next) {
 380      var response, results, nextPage, mergedResults, nextResponse, nextResults;
 381      return external_this_regeneratorRuntime_default.a.wrap(function _callee$(_context) {
 382        while (1) {
 383          switch (_context.prev = _context.next) {
 384            case 0:
 385              if (!(options.parse === false)) {
 386                _context.next = 2;
 387                break;
 388              }
 389  
 390              return _context.abrupt("return", next(options));
 391  
 392            case 2:
 393              if (requestContainsUnboundedQuery(options)) {
 394                _context.next = 4;
 395                break;
 396              }
 397  
 398              return _context.abrupt("return", next(options));
 399  
 400            case 4:
 401              _context.next = 6;
 402              return next(Object(objectSpread["a" /* default */])({}, fetch_all_middleware_modifyQuery(options, {
 403                per_page: 100
 404              }), {
 405                // Ensure headers are returned for page 1.
 406                parse: false
 407              }));
 408  
 409            case 6:
 410              response = _context.sent;
 411              _context.next = 9;
 412              return parseResponse(response);
 413  
 414            case 9:
 415              results = _context.sent;
 416  
 417              if (Array.isArray(results)) {
 418                _context.next = 12;
 419                break;
 420              }
 421  
 422              return _context.abrupt("return", results);
 423  
 424            case 12:
 425              nextPage = getNextPageUrl(response);
 426  
 427              if (nextPage) {
 428                _context.next = 15;
 429                break;
 430              }
 431  
 432              return _context.abrupt("return", results);
 433  
 434            case 15:
 435              // Iteratively fetch all remaining pages until no "next" header is found.
 436              mergedResults = [].concat(results);
 437  
 438            case 16:
 439              if (!nextPage) {
 440                _context.next = 27;
 441                break;
 442              }
 443  
 444              _context.next = 19;
 445              return next(Object(objectSpread["a" /* default */])({}, options, {
 446                // Ensure the URL for the next page is used instead of any provided path.
 447                path: undefined,
 448                url: nextPage,
 449                // Ensure we still get headers so we can identify the next page.
 450                parse: false
 451              }));
 452  
 453            case 19:
 454              nextResponse = _context.sent;
 455              _context.next = 22;
 456              return parseResponse(nextResponse);
 457  
 458            case 22:
 459              nextResults = _context.sent;
 460              mergedResults = mergedResults.concat(nextResults);
 461              nextPage = getNextPageUrl(nextResponse);
 462              _context.next = 16;
 463              break;
 464  
 465            case 27:
 466              return _context.abrupt("return", mergedResults);
 467  
 468            case 28:
 469            case "end":
 470              return _context.stop();
 471          }
 472        }
 473      }, _callee);
 474    }));
 475  
 476    return function fetchAllMiddleware(_x, _x2) {
 477      return _ref2.apply(this, arguments);
 478    };
 479  }();
 480  
 481  /* harmony default export */ var fetch_all_middleware = (fetchAllMiddleware);
 482  
 483  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/http-v1.js
 484  
 485  
 486  /**
 487   * Set of HTTP methods which are eligible to be overridden.
 488   *
 489   * @type {Set}
 490   */
 491  var OVERRIDE_METHODS = new Set(['PATCH', 'PUT', 'DELETE']);
 492  /**
 493   * Default request method.
 494   *
 495   * "A request has an associated method (a method). Unless stated otherwise it
 496   * is `GET`."
 497   *
 498   * @see  https://fetch.spec.whatwg.org/#requests
 499   *
 500   * @type {string}
 501   */
 502  
 503  var DEFAULT_METHOD = 'GET';
 504  /**
 505   * API Fetch middleware which overrides the request method for HTTP v1
 506   * compatibility leveraging the REST API X-HTTP-Method-Override header.
 507   *
 508   * @param {Object}   options Fetch options.
 509   * @param {Function} next    [description]
 510   *
 511   * @return {*} The evaluated result of the remaining middleware chain.
 512   */
 513  
 514  function httpV1Middleware(options, next) {
 515    var _options = options,
 516        _options$method = _options.method,
 517        method = _options$method === void 0 ? DEFAULT_METHOD : _options$method;
 518  
 519    if (OVERRIDE_METHODS.has(method.toUpperCase())) {
 520      options = Object(objectSpread["a" /* default */])({}, options, {
 521        headers: Object(objectSpread["a" /* default */])({}, options.headers, {
 522          'X-HTTP-Method-Override': method,
 523          'Content-Type': 'application/json'
 524        }),
 525        method: 'POST'
 526      });
 527    }
 528  
 529    return next(options, next);
 530  }
 531  
 532  /* harmony default export */ var http_v1 = (httpV1Middleware);
 533  
 534  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/user-locale.js
 535  /**
 536   * WordPress dependencies
 537   */
 538  
 539  
 540  function userLocaleMiddleware(options, next) {
 541    if (typeof options.url === 'string' && !Object(external_this_wp_url_["hasQueryArg"])(options.url, '_locale')) {
 542      options.url = Object(external_this_wp_url_["addQueryArgs"])(options.url, {
 543        _locale: 'user'
 544      });
 545    }
 546  
 547    if (typeof options.path === 'string' && !Object(external_this_wp_url_["hasQueryArg"])(options.path, '_locale')) {
 548      options.path = Object(external_this_wp_url_["addQueryArgs"])(options.path, {
 549        _locale: 'user'
 550      });
 551    }
 552  
 553    return next(options, next);
 554  }
 555  
 556  /* harmony default export */ var user_locale = (userLocaleMiddleware);
 557  
 558  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/utils/response.js
 559  /**
 560   * WordPress dependencies
 561   */
 562  
 563  /**
 564   * Parses the apiFetch response.
 565   *
 566   * @param {Response} response
 567   * @param {boolean}  shouldParseResponse
 568   *
 569   * @return {Promise} Parsed response
 570   */
 571  
 572  var response_parseResponse = function parseResponse(response) {
 573    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 574  
 575    if (shouldParseResponse) {
 576      if (response.status === 204) {
 577        return null;
 578      }
 579  
 580      return response.json ? response.json() : Promise.reject(response);
 581    }
 582  
 583    return response;
 584  };
 585  
 586  var response_parseJsonAndNormalizeError = function parseJsonAndNormalizeError(response) {
 587    var invalidJsonError = {
 588      code: 'invalid_json',
 589      message: Object(external_this_wp_i18n_["__"])('The response is not a valid JSON response.')
 590    };
 591  
 592    if (!response || !response.json) {
 593      throw invalidJsonError;
 594    }
 595  
 596    return response.json().catch(function () {
 597      throw invalidJsonError;
 598    });
 599  };
 600  /**
 601   * Parses the apiFetch response properly and normalize response errors.
 602   *
 603   * @param {Response} response
 604   * @param {boolean}  shouldParseResponse
 605   *
 606   * @return {Promise} Parsed response.
 607   */
 608  
 609  
 610  var parseResponseAndNormalizeError = function parseResponseAndNormalizeError(response) {
 611    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 612    return Promise.resolve(response_parseResponse(response, shouldParseResponse)).catch(function (res) {
 613      return parseAndThrowError(res, shouldParseResponse);
 614    });
 615  };
 616  function parseAndThrowError(response) {
 617    var shouldParseResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
 618  
 619    if (!shouldParseResponse) {
 620      throw response;
 621    }
 622  
 623    return response_parseJsonAndNormalizeError(response).then(function (error) {
 624      var unknownError = {
 625        code: 'unknown_error',
 626        message: Object(external_this_wp_i18n_["__"])('An unknown error occurred.')
 627      };
 628      throw error || unknownError;
 629    });
 630  }
 631  
 632  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/middlewares/media-upload.js
 633  
 634  
 635  /**
 636   * WordPress dependencies
 637   */
 638  
 639  /**
 640   * Internal dependencies
 641   */
 642  
 643  
 644  /**
 645   * Middleware handling media upload failures and retries.
 646   *
 647   * @param {Object}   options Fetch options.
 648   * @param {Function} next    [description]
 649   *
 650   * @return {*} The evaluated result of the remaining middleware chain.
 651   */
 652  
 653  function mediaUploadMiddleware(options, next) {
 654    var isMediaUploadRequest = options.path && options.path.indexOf('/wp/v2/media') !== -1 || options.url && options.url.indexOf('/wp/v2/media') !== -1;
 655  
 656    if (!isMediaUploadRequest) {
 657      return next(options, next);
 658    }
 659  
 660    var retries = 0;
 661    var maxRetries = 5;
 662  
 663    var postProcess = function postProcess(attachmentId) {
 664      retries++;
 665      return next({
 666        path: "/wp/v2/media/".concat(attachmentId, "/post-process"),
 667        method: 'POST',
 668        data: {
 669          action: 'create-image-subsizes'
 670        },
 671        parse: false
 672      }).catch(function () {
 673        if (retries < maxRetries) {
 674          return postProcess(attachmentId);
 675        }
 676  
 677        next({
 678          path: "/wp/v2/media/".concat(attachmentId, "?force=true"),
 679          method: 'DELETE'
 680        });
 681        return Promise.reject();
 682      });
 683    };
 684  
 685    return next(Object(objectSpread["a" /* default */])({}, options, {
 686      parse: false
 687    })).catch(function (response) {
 688      var attachmentId = response.headers.get('x-wp-upload-attachment-id');
 689  
 690      if (response.status >= 500 && response.status < 600 && attachmentId) {
 691        return postProcess(attachmentId).catch(function () {
 692          if (options.parse !== false) {
 693            return Promise.reject({
 694              code: 'post_process',
 695              message: Object(external_this_wp_i18n_["__"])('Media upload failed. If this is a photo or a large image, please scale it down and try again.')
 696            });
 697          }
 698  
 699          return Promise.reject(response);
 700        });
 701      }
 702  
 703      return parseAndThrowError(response, options.parse);
 704    }).then(function (response) {
 705      return parseResponseAndNormalizeError(response, options.parse);
 706    });
 707  }
 708  
 709  /* harmony default export */ var media_upload = (mediaUploadMiddleware);
 710  
 711  // CONCATENATED MODULE: ./node_modules/@wordpress/api-fetch/build-module/index.js
 712  
 713  
 714  
 715  /**
 716   * WordPress dependencies
 717   */
 718  
 719  /**
 720   * Internal dependencies
 721   */
 722  
 723  
 724  
 725  
 726  
 727  
 728  
 729  
 730  
 731  
 732  /**
 733   * Default set of header values which should be sent with every request unless
 734   * explicitly provided through apiFetch options.
 735   *
 736   * @type {Object}
 737   */
 738  
 739  var DEFAULT_HEADERS = {
 740    // The backend uses the Accept header as a condition for considering an
 741    // incoming request as a REST request.
 742    //
 743    // See: https://core.trac.wordpress.org/ticket/44534
 744    Accept: 'application/json, */*;q=0.1'
 745  };
 746  /**
 747   * Default set of fetch option values which should be sent with every request
 748   * unless explicitly provided through apiFetch options.
 749   *
 750   * @type {Object}
 751   */
 752  
 753  var DEFAULT_OPTIONS = {
 754    credentials: 'include'
 755  };
 756  var middlewares = [user_locale, namespace_endpoint, http_v1, fetch_all_middleware];
 757  
 758  function registerMiddleware(middleware) {
 759    middlewares.unshift(middleware);
 760  }
 761  
 762  var checkStatus = function checkStatus(response) {
 763    if (response.status >= 200 && response.status < 300) {
 764      return response;
 765    }
 766  
 767    throw response;
 768  };
 769  
 770  var build_module_defaultFetchHandler = function defaultFetchHandler(nextOptions) {
 771    var url = nextOptions.url,
 772        path = nextOptions.path,
 773        data = nextOptions.data,
 774        _nextOptions$parse = nextOptions.parse,
 775        parse = _nextOptions$parse === void 0 ? true : _nextOptions$parse,
 776        remainingOptions = Object(objectWithoutProperties["a" /* default */])(nextOptions, ["url", "path", "data", "parse"]);
 777  
 778    var body = nextOptions.body,
 779        headers = nextOptions.headers; // Merge explicitly-provided headers with default values.
 780  
 781    headers = Object(objectSpread["a" /* default */])({}, DEFAULT_HEADERS, headers); // The `data` property is a shorthand for sending a JSON body.
 782  
 783    if (data) {
 784      body = JSON.stringify(data);
 785      headers['Content-Type'] = 'application/json';
 786    }
 787  
 788    var responsePromise = window.fetch(url || path, Object(objectSpread["a" /* default */])({}, DEFAULT_OPTIONS, remainingOptions, {
 789      body: body,
 790      headers: headers
 791    }));
 792    return responsePromise // Return early if fetch errors. If fetch error, there is most likely no
 793    // network connection. Unfortunately fetch just throws a TypeError and
 794    // the message might depend on the browser.
 795    .then(function (value) {
 796      return Promise.resolve(value).then(checkStatus).catch(function (response) {
 797        return parseAndThrowError(response, parse);
 798      }).then(function (response) {
 799        return parseResponseAndNormalizeError(response, parse);
 800      });
 801    }, function () {
 802      throw {
 803        code: 'fetch_error',
 804        message: Object(external_this_wp_i18n_["__"])('You are probably offline.')
 805      };
 806    });
 807  };
 808  
 809  var fetchHandler = build_module_defaultFetchHandler;
 810  /**
 811   * Defines a custom fetch handler for making the requests that will override
 812   * the default one using window.fetch
 813   *
 814   * @param {Function} newFetchHandler The new fetch handler
 815   */
 816  
 817  function setFetchHandler(newFetchHandler) {
 818    fetchHandler = newFetchHandler;
 819  }
 820  
 821  function apiFetch(options) {
 822    var steps = [].concat(middlewares, [fetchHandler]);
 823  
 824    var createRunStep = function createRunStep(index) {
 825      return function (workingOptions) {
 826        var step = steps[index];
 827  
 828        if (index === steps.length - 1) {
 829          return step(workingOptions);
 830        }
 831  
 832        var next = createRunStep(index + 1);
 833        return step(workingOptions, next);
 834      };
 835    };
 836  
 837    return new Promise(function (resolve, reject) {
 838      createRunStep(0)(options).then(resolve).catch(function (error) {
 839        if (error.code !== 'rest_cookie_invalid_nonce') {
 840          return reject(error);
 841        } // If the nonce is invalid, refresh it and try again.
 842  
 843  
 844        window.fetch(apiFetch.nonceEndpoint).then(checkStatus).then(function (data) {
 845          return data.text();
 846        }).then(function (text) {
 847          apiFetch.nonceMiddleware.nonce = text;
 848          apiFetch(options).then(resolve).catch(reject);
 849        }).catch(reject);
 850      });
 851    });
 852  }
 853  
 854  apiFetch.use = registerMiddleware;
 855  apiFetch.setFetchHandler = setFetchHandler;
 856  apiFetch.createNonceMiddleware = middlewares_nonce;
 857  apiFetch.createPreloadingMiddleware = preloading;
 858  apiFetch.createRootURLMiddleware = root_url;
 859  apiFetch.fetchAllMiddleware = fetch_all_middleware;
 860  apiFetch.mediaUploadMiddleware = media_upload;
 861  /* harmony default export */ var build_module = __webpack_exports__["default"] = (apiFetch);
 862  
 863  
 864  /***/ }),
 865  
 866  /***/ 40:
 867  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 868  
 869  "use strict";
 870  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectWithoutPropertiesLoose; });
 871  function _objectWithoutPropertiesLoose(source, excluded) {
 872    if (source == null) return {};
 873    var target = {};
 874    var sourceKeys = Object.keys(source);
 875    var key, i;
 876  
 877    for (i = 0; i < sourceKeys.length; i++) {
 878      key = sourceKeys[i];
 879      if (excluded.indexOf(key) >= 0) continue;
 880      target[key] = source[key];
 881    }
 882  
 883    return target;
 884  }
 885  
 886  /***/ }),
 887  
 888  /***/ 43:
 889  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 890  
 891  "use strict";
 892  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _asyncToGenerator; });
 893  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
 894    try {
 895      var info = gen[key](arg);
 896      var value = info.value;
 897    } catch (error) {
 898      reject(error);
 899      return;
 900    }
 901  
 902    if (info.done) {
 903      resolve(value);
 904    } else {
 905      Promise.resolve(value).then(_next, _throw);
 906    }
 907  }
 908  
 909  function _asyncToGenerator(fn) {
 910    return function () {
 911      var self = this,
 912          args = arguments;
 913      return new Promise(function (resolve, reject) {
 914        var gen = fn.apply(self, args);
 915  
 916        function _next(value) {
 917          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
 918        }
 919  
 920        function _throw(err) {
 921          asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
 922        }
 923  
 924        _next(undefined);
 925      });
 926    };
 927  }
 928  
 929  /***/ }),
 930  
 931  /***/ 7:
 932  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 933  
 934  "use strict";
 935  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _objectSpread; });
 936  /* harmony import */ var _defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9);
 937  
 938  function _objectSpread(target) {
 939    for (var i = 1; i < arguments.length; i++) {
 940      var source = arguments[i] != null ? arguments[i] : {};
 941      var ownKeys = Object.keys(Object(source));
 942  
 943      if (typeof Object.getOwnPropertySymbols === 'function') {
 944        ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
 945          return Object.getOwnPropertyDescriptor(source, sym).enumerable;
 946        }));
 947      }
 948  
 949      ownKeys.forEach(function (key) {
 950        Object(_defineProperty__WEBPACK_IMPORTED_MODULE_0__[/* default */ "a"])(target, key, source[key]);
 951      });
 952    }
 953  
 954    return target;
 955  }
 956  
 957  /***/ }),
 958  
 959  /***/ 9:
 960  /***/ (function(module, __webpack_exports__, __webpack_require__) {
 961  
 962  "use strict";
 963  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _defineProperty; });
 964  function _defineProperty(obj, key, value) {
 965    if (key in obj) {
 966      Object.defineProperty(obj, key, {
 967        value: value,
 968        enumerable: true,
 969        configurable: true,
 970        writable: true
 971      });
 972    } else {
 973      obj[key] = value;
 974    }
 975  
 976    return obj;
 977  }
 978  
 979  /***/ })
 980  
 981  /******/ })["default"];


Generated: Sun Jan 19 01:00:03 2020 Cross-referenced by PHPXref 0.7.1