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


Generated: Sat Jul 4 01:00:03 2020 Cross-referenced by PHPXref 0.7.1