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