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