WordPress/wp-includes/js/dist/api-fetch.min.js
gziolo 6e4458c935 Build: Use hashed/deterministic moduleIDs in webpack config
Props peterwilsoncc, desrosj.
Fixes #53192.


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


git-svn-id: http://core.svn.wordpress.org/trunk@50549 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-05-20 12:20:04 +00:00

2 lines
5.8 KiB
JavaScript

/*! This file is auto-generated */
this.wp=this.wp||{},this.wp.apiFetch=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s="./node_modules/@wordpress/api-fetch/build-module/index.js")}({"./node_modules/@wordpress/api-fetch/build-module/index.js":function(e,t,r){"use strict";r.r(t);var n=r("@wordpress/i18n");var o=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 a=(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 s=e=>(t,r)=>a(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})});function i(e){const t=e.split("?"),r=t[1],n=t[0];return r?n+"?"+r.split("&").map(e=>e.split("=")).sort((e,t)=>e[0].localeCompare(t[0])).map(e=>e.join("=")).join("&"):n}var c=function(e){const t=Object.keys(e).reduce((t,r)=>(t[i(r)]=e[r],t),{});return(e,r)=>{const{parse:n=!0}=e;if("string"==typeof e.path){const r=e.method||"GET",o=i(e.path);if("GET"===r&&t[o]){const e=t[o];return delete t[o],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][o])return Promise.resolve(n?t[r][o].body:t[r][o])}return r(e)}},u=r("@wordpress/url");const d=({path:e,url:t,...r},n)=>({...r,url:t&&Object(u.addQueryArgs)(t,n),path:e&&Object(u.addQueryArgs)(e,n)}),p=e=>e.json?e.json():Promise.reject(e),l=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 f=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 x({...d(e,{per_page:100}),parse:!1}),n=await p(r);if(!Array.isArray(n))return n;let o=l(r);if(!o)return n;let a=[].concat(n);for(;o;){const t=await x({...e,path:void 0,url:o,parse:!1}),r=await p(t);a=a.concat(r),o=l(t)}return a};const h=new Set(["PATCH","PUT","DELETE"]),w="GET";const m=(e,t=!0)=>Promise.resolve(((e,t=!0)=>t?204===e.status?null:e.json?e.json():Promise.reject(e):e)(e,t)).catch(e=>y(e,t));function y(e,t=!0){if(!t)throw e;return(e=>{const t={code:"invalid_json",message:Object(n.__)("The response is not a valid JSON response.")};if(!e||!e.json)throw t;return e.json().catch(()=>{throw t})})(e).then(e=>{const t={code:"unknown_error",message:Object(n.__)("An unknown error occurred.")};throw e||t})}var j=(e,t)=>{if(!(e.path&&-1!==e.path.indexOf("/wp/v2/media")||e.url&&-1!==e.url.indexOf("/wp/v2/media")))return t(e);let r=0;const o=e=>(r++,t({path:`/wp/v2/media/${e}/post-process`,method:"POST",data:{action:"create-image-subsizes"},parse:!1}).catch(()=>r<5?o(e):(t({path:`/wp/v2/media/${e}?force=true`,method:"DELETE"}),Promise.reject())));return t({...e,parse:!1}).catch(t=>{const r=t.headers.get("x-wp-upload-attachment-id");return t.status>=500&&t.status<600&&r?o(r).catch(()=>!1!==e.parse?Promise.reject({code:"post_process",message:Object(n.__)("Media upload failed. If this is a photo or a large image, please scale it down and try again.")}):Promise.reject(t)):y(t,e.parse)}).then(t=>m(t,e.parse))};const g={Accept:"application/json, */*;q=0.1"},b={credentials:"include"},O=[(e,t)=>("string"!=typeof e.url||Object(u.hasQueryArg)(e.url,"_locale")||(e.url=Object(u.addQueryArgs)(e.url,{_locale:"user"})),"string"!=typeof e.path||Object(u.hasQueryArg)(e.path,"_locale")||(e.path=Object(u.addQueryArgs)(e.path,{_locale:"user"})),t(e)),a,(e,t)=>{const{method:r=w}=e;return h.has(r.toUpperCase())&&(e={...e,headers:{...e.headers,"X-HTTP-Method-Override":r,"Content-Type":"application/json"},method:"POST"}),t(e)},f];const _=e=>{if(e.status>=200&&e.status<300)return e;throw e};let v=e=>{const{url:t,path:r,data:o,parse:a=!0,...s}=e;let{body:i,headers:c}=e;c={...g,...c},o&&(i=JSON.stringify(o),c["Content-Type"]="application/json");return window.fetch(t||r||window.location.href,{...b,...s,body:i,headers:c}).then(e=>Promise.resolve(e).then(_).catch(e=>y(e,a)).then(e=>m(e,a)),()=>{throw{code:"fetch_error",message:Object(n.__)("You are probably offline.")}})};function P(e){return O.reduceRight((e,t)=>r=>t(r,e),v)(e).catch(t=>"rest_cookie_invalid_nonce"!==t.code?Promise.reject(t):window.fetch(P.nonceEndpoint).then(_).then(e=>e.text()).then(t=>(P.nonceMiddleware.nonce=t,P(e))))}P.use=function(e){O.unshift(e)},P.setFetchHandler=function(e){v=e},P.createNonceMiddleware=o,P.createPreloadingMiddleware=c,P.createRootURLMiddleware=s,P.fetchAllMiddleware=f,P.mediaUploadMiddleware=j;var x=t.default=P},"@wordpress/i18n":function(e,t){e.exports=window.wp.i18n},"@wordpress/url":function(e,t){e.exports=window.wp.url}}).default;