WordPress/wp-includes/js/dist/api-fetch.min.js
gziolo 2ec4c366e6 Build: Update webpack to v5.x
Update webpack version to latest version https://www.npmjs.com/package/webpack. This aligns closer with how the Gutenberg plugin handles WordPress packages. Related update in Gutenberg from August 2021: https://github.com/WordPress/gutenberg/pull/33818.

Props walbo, desrosj, mukesh27.
Fixes #51750.



Built from https://develop.svn.wordpress.org/trunk@53135


git-svn-id: http://core.svn.wordpress.org/trunk@52724 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-04-11 12:04:30 +00:00

2 lines
5.1 KiB
JavaScript

/*! This file is auto-generated */
!function(){"use strict";var e={d:function(t,r){for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}},t={};e.d(t,{default:function(){return A}});var r=window.wp.i18n;var n=function(e){const t=(e,r)=>{const{headers:n={}}=e;for(const o in n)if("x-wp-nonce"===o.toLowerCase()&&n[o]===t.nonce)return r(e);return r({...e,headers:{...n,"X-WP-Nonce":t.nonce}})};return t.nonce=e,t};var o=(e,t)=>{let r,n,o=e.path;return"string"==typeof e.namespace&&"string"==typeof e.endpoint&&(r=e.namespace.replace(/^\/|\/$/g,""),n=e.endpoint.replace(/^\//,""),o=n?r+"/"+n:r),delete e.namespace,delete e.endpoint,t({...e,path:o})};var a=e=>(t,r)=>o(t,(t=>{let n,o=t.url,a=t.path;return"string"==typeof a&&(n=e,-1!==e.indexOf("?")&&(a=a.replace("?","&")),a=a.replace(/^\//,""),"string"==typeof n&&-1!==n.indexOf("?")&&(a=a.replace("?","&")),o=n+a),r({...t,url:o})})),s=window.wp.url;var i=function(e){const t=Object.keys(e).reduce(((t,r)=>(t[(0,s.normalizePath)(r)]=e[r],t)),{});return(e,r)=>{const{parse:n=!0}=e;let o=e.path;if(!o&&e.url){const t=(0,s.getQueryArg)(e.url,"rest_route");"string"==typeof t&&(o=t)}if("string"==typeof o){const r=e.method||"GET",a=(0,s.normalizePath)(o);if("GET"===r&&t[a]){const e=t[a];return delete t[a],Promise.resolve(n?e.body:new window.Response(JSON.stringify(e.body),{status:200,statusText:"OK",headers:e.headers}))}if("OPTIONS"===r&&t[r]&&t[r][a]){const e=t[r][a];return delete t[r][a],Promise.resolve(n?e.body:e)}}return r(e)}};const c=(e,t)=>{let{path:r,url:n,...o}=e;return{...o,url:n&&(0,s.addQueryArgs)(n,t),path:r&&(0,s.addQueryArgs)(r,t)}},d=e=>e.json?e.json():Promise.reject(e),u=e=>{const{next:t}=(e=>{if(!e)return{};const t=e.match(/<([^>]+)>; rel="next"/);return t?{next:t[1]}:{}})(e.headers.get("link"));return t};var p=async(e,t)=>{if(!1===e.parse)return t(e);if(!(e=>{const t=!!e.path&&-1!==e.path.indexOf("per_page=-1"),r=!!e.url&&-1!==e.url.indexOf("per_page=-1");return t||r})(e))return t(e);const r=await A({...c(e,{per_page:100}),parse:!1}),n=await d(r);if(!Array.isArray(n))return n;let o=u(r);if(!o)return n;let a=[].concat(n);for(;o;){const t=await A({...e,path:void 0,url:o,parse:!1}),r=await d(t);a=a.concat(r),o=u(t)}return a};const l=new Set(["PATCH","PUT","DELETE"]),h="GET";const f=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return t?204===e.status?null:e.json?e.json():Promise.reject(e):e},w=e=>{const t={code:"invalid_json",message:(0,r.__)("The response is not a valid JSON response.")};if(!e||!e.json)throw t;return e.json().catch((()=>{throw t}))},g=function(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return Promise.resolve(f(e,t)).catch((e=>m(e,t)))};function m(e){let t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!t)throw e;return w(e).then((e=>{const t={code:"unknown_error",message:(0,r.__)("An unknown error occurred.")};throw e||t}))}var y=(e,t)=>{if(!function(e){const t=!!e.method&&"POST"===e.method;return(!!e.path&&-1!==e.path.indexOf("/wp/v2/media")||!!e.url&&-1!==e.url.indexOf("/wp/v2/media"))&&t}(e))return t(e);let n=0;const o=e=>(n++,t({path:`/wp/v2/media/${e}/post-process`,method:"POST",data:{action:"create-image-subsizes"},parse:!1}).catch((()=>n<5?o(e):(t({path:`/wp/v2/media/${e}?force=true`,method:"DELETE"}),Promise.reject()))));return t({...e,parse:!1}).catch((t=>{const n=t.headers.get("x-wp-upload-attachment-id");return t.status>=500&&t.status<600&&n?o(n).catch((()=>!1!==e.parse?Promise.reject({code:"post_process",message:(0,r.__)("Media upload failed. If this is a photo or a large image, please scale it down and try again.")}):Promise.reject(t))):m(t,e.parse)})).then((t=>g(t,e.parse)))};const v={Accept:"application/json, */*;q=0.1"},P={credentials:"include"},_=[(e,t)=>("string"!=typeof e.url||(0,s.hasQueryArg)(e.url,"_locale")||(e.url=(0,s.addQueryArgs)(e.url,{_locale:"user"})),"string"!=typeof e.path||(0,s.hasQueryArg)(e.path,"_locale")||(e.path=(0,s.addQueryArgs)(e.path,{_locale:"user"})),t(e)),o,(e,t)=>{const{method:r=h}=e;return l.has(r.toUpperCase())&&(e={...e,headers:{...e.headers,"X-HTTP-Method-Override":r,"Content-Type":"application/json"},method:"POST"}),t(e)},p];const O=e=>{if(e.status>=200&&e.status<300)return e;throw e};let j=e=>{const{url:t,path:n,data:o,parse:a=!0,...s}=e;let{body:i,headers:c}=e;c={...v,...c},o&&(i=JSON.stringify(o),c["Content-Type"]="application/json");return window.fetch(t||n||window.location.href,{...P,...s,body:i,headers:c}).then((e=>Promise.resolve(e).then(O).catch((e=>m(e,a))).then((e=>g(e,a)))),(e=>{if(e&&"AbortError"===e.name)throw e;throw{code:"fetch_error",message:(0,r.__)("You are probably offline.")}}))};function T(e){return _.reduceRight(((e,t)=>r=>t(r,e)),j)(e).catch((t=>"rest_cookie_invalid_nonce"!==t.code?Promise.reject(t):window.fetch(T.nonceEndpoint).then(O).then((e=>e.text())).then((t=>(T.nonceMiddleware.nonce=t,T(e))))))}T.use=function(e){_.unshift(e)},T.setFetchHandler=function(e){j=e},T.createNonceMiddleware=n,T.createPreloadingMiddleware=i,T.createRootURLMiddleware=a,T.fetchAllMiddleware=p,T.mediaUploadMiddleware=y;var A=T;(window.wp=window.wp||{}).apiFetch=t.default}();