axios.js 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661
  1. // Axios v1.7.2 Copyright (c) 2024 Matt Zabriskie and contributors
  2. function bind(fn, thisArg) {
  3. return function wrap() {
  4. return fn.apply(thisArg, arguments);
  5. };
  6. }
  7. // utils is a library of generic helper functions non-specific to axios
  8. const {toString} = Object.prototype;
  9. const {getPrototypeOf} = Object;
  10. const kindOf = (cache => thing => {
  11. const str = toString.call(thing);
  12. return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
  13. })(Object.create(null));
  14. const kindOfTest = (type) => {
  15. type = type.toLowerCase();
  16. return (thing) => kindOf(thing) === type
  17. };
  18. const typeOfTest = type => thing => typeof thing === type;
  19. /**
  20. * Determine if a value is an Array
  21. *
  22. * @param {Object} val The value to test
  23. *
  24. * @returns {boolean} True if value is an Array, otherwise false
  25. */
  26. const {isArray} = Array;
  27. /**
  28. * Determine if a value is undefined
  29. *
  30. * @param {*} val The value to test
  31. *
  32. * @returns {boolean} True if the value is undefined, otherwise false
  33. */
  34. const isUndefined = typeOfTest('undefined');
  35. /**
  36. * Determine if a value is a Buffer
  37. *
  38. * @param {*} val The value to test
  39. *
  40. * @returns {boolean} True if value is a Buffer, otherwise false
  41. */
  42. function isBuffer(val) {
  43. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  44. && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
  45. }
  46. /**
  47. * Determine if a value is an ArrayBuffer
  48. *
  49. * @param {*} val The value to test
  50. *
  51. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  52. */
  53. const isArrayBuffer = kindOfTest('ArrayBuffer');
  54. /**
  55. * Determine if a value is a view on an ArrayBuffer
  56. *
  57. * @param {*} val The value to test
  58. *
  59. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  60. */
  61. function isArrayBufferView(val) {
  62. let result;
  63. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  64. result = ArrayBuffer.isView(val);
  65. } else {
  66. result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
  67. }
  68. return result;
  69. }
  70. /**
  71. * Determine if a value is a String
  72. *
  73. * @param {*} val The value to test
  74. *
  75. * @returns {boolean} True if value is a String, otherwise false
  76. */
  77. const isString = typeOfTest('string');
  78. /**
  79. * Determine if a value is a Function
  80. *
  81. * @param {*} val The value to test
  82. * @returns {boolean} True if value is a Function, otherwise false
  83. */
  84. const isFunction = typeOfTest('function');
  85. /**
  86. * Determine if a value is a Number
  87. *
  88. * @param {*} val The value to test
  89. *
  90. * @returns {boolean} True if value is a Number, otherwise false
  91. */
  92. const isNumber = typeOfTest('number');
  93. /**
  94. * Determine if a value is an Object
  95. *
  96. * @param {*} thing The value to test
  97. *
  98. * @returns {boolean} True if value is an Object, otherwise false
  99. */
  100. const isObject = (thing) => thing !== null && typeof thing === 'object';
  101. /**
  102. * Determine if a value is a Boolean
  103. *
  104. * @param {*} thing The value to test
  105. * @returns {boolean} True if value is a Boolean, otherwise false
  106. */
  107. const isBoolean = thing => thing === true || thing === false;
  108. /**
  109. * Determine if a value is a plain Object
  110. *
  111. * @param {*} val The value to test
  112. *
  113. * @returns {boolean} True if value is a plain Object, otherwise false
  114. */
  115. const isPlainObject = (val) => {
  116. if (kindOf(val) !== 'object') {
  117. return false;
  118. }
  119. const prototype = getPrototypeOf(val);
  120. return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
  121. };
  122. /**
  123. * Determine if a value is a Date
  124. *
  125. * @param {*} val The value to test
  126. *
  127. * @returns {boolean} True if value is a Date, otherwise false
  128. */
  129. const isDate = kindOfTest('Date');
  130. /**
  131. * Determine if a value is a File
  132. *
  133. * @param {*} val The value to test
  134. *
  135. * @returns {boolean} True if value is a File, otherwise false
  136. */
  137. const isFile = kindOfTest('File');
  138. /**
  139. * Determine if a value is a Blob
  140. *
  141. * @param {*} val The value to test
  142. *
  143. * @returns {boolean} True if value is a Blob, otherwise false
  144. */
  145. const isBlob = kindOfTest('Blob');
  146. /**
  147. * Determine if a value is a FileList
  148. *
  149. * @param {*} val The value to test
  150. *
  151. * @returns {boolean} True if value is a File, otherwise false
  152. */
  153. const isFileList = kindOfTest('FileList');
  154. /**
  155. * Determine if a value is a Stream
  156. *
  157. * @param {*} val The value to test
  158. *
  159. * @returns {boolean} True if value is a Stream, otherwise false
  160. */
  161. const isStream = (val) => isObject(val) && isFunction(val.pipe);
  162. /**
  163. * Determine if a value is a FormData
  164. *
  165. * @param {*} thing The value to test
  166. *
  167. * @returns {boolean} True if value is an FormData, otherwise false
  168. */
  169. const isFormData = (thing) => {
  170. let kind;
  171. return thing && (
  172. (typeof FormData === 'function' && thing instanceof FormData) || (
  173. isFunction(thing.append) && (
  174. (kind = kindOf(thing)) === 'formdata' ||
  175. // detect form-data instance
  176. (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
  177. )
  178. )
  179. )
  180. };
  181. /**
  182. * Determine if a value is a URLSearchParams object
  183. *
  184. * @param {*} val The value to test
  185. *
  186. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  187. */
  188. const isURLSearchParams = kindOfTest('URLSearchParams');
  189. const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
  190. /**
  191. * Trim excess whitespace off the beginning and end of a string
  192. *
  193. * @param {String} str The String to trim
  194. *
  195. * @returns {String} The String freed of excess whitespace
  196. */
  197. const trim = (str) => str.trim ?
  198. str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  199. /**
  200. * Iterate over an Array or an Object invoking a function for each item.
  201. *
  202. * If `obj` is an Array callback will be called passing
  203. * the value, index, and complete array for each item.
  204. *
  205. * If 'obj' is an Object callback will be called passing
  206. * the value, key, and complete object for each property.
  207. *
  208. * @param {Object|Array} obj The object to iterate
  209. * @param {Function} fn The callback to invoke for each item
  210. *
  211. * @param {Boolean} [allOwnKeys = false]
  212. * @returns {any}
  213. */
  214. function forEach(obj, fn, {allOwnKeys = false} = {}) {
  215. // Don't bother if no value provided
  216. if (obj === null || typeof obj === 'undefined') {
  217. return;
  218. }
  219. let i;
  220. let l;
  221. // Force an array if not already something iterable
  222. if (typeof obj !== 'object') {
  223. /*eslint no-param-reassign:0*/
  224. obj = [obj];
  225. }
  226. if (isArray(obj)) {
  227. // Iterate over array values
  228. for (i = 0, l = obj.length; i < l; i++) {
  229. fn.call(null, obj[i], i, obj);
  230. }
  231. } else {
  232. // Iterate over object keys
  233. const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
  234. const len = keys.length;
  235. let key;
  236. for (i = 0; i < len; i++) {
  237. key = keys[i];
  238. fn.call(null, obj[key], key, obj);
  239. }
  240. }
  241. }
  242. function findKey(obj, key) {
  243. key = key.toLowerCase();
  244. const keys = Object.keys(obj);
  245. let i = keys.length;
  246. let _key;
  247. while (i-- > 0) {
  248. _key = keys[i];
  249. if (key === _key.toLowerCase()) {
  250. return _key;
  251. }
  252. }
  253. return null;
  254. }
  255. const _global = (() => {
  256. /*eslint no-undef:0*/
  257. if (typeof globalThis !== "undefined") return globalThis;
  258. return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)
  259. })();
  260. const isContextDefined = (context) => !isUndefined(context) && context !== _global;
  261. /**
  262. * Accepts varargs expecting each argument to be an object, then
  263. * immutably merges the properties of each object and returns result.
  264. *
  265. * When multiple objects contain the same key the later object in
  266. * the arguments list will take precedence.
  267. *
  268. * Example:
  269. *
  270. * ```js
  271. * var result = merge({foo: 123}, {foo: 456});
  272. * console.log(result.foo); // outputs 456
  273. * ```
  274. *
  275. * @param {Object} obj1 Object to merge
  276. *
  277. * @returns {Object} Result of all merge properties
  278. */
  279. function merge(/* obj1, obj2, obj3, ... */) {
  280. const {caseless} = isContextDefined(this) && this || {};
  281. const result = {};
  282. const assignValue = (val, key) => {
  283. const targetKey = caseless && findKey(result, key) || key;
  284. if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
  285. result[targetKey] = merge(result[targetKey], val);
  286. } else if (isPlainObject(val)) {
  287. result[targetKey] = merge({}, val);
  288. } else if (isArray(val)) {
  289. result[targetKey] = val.slice();
  290. } else {
  291. result[targetKey] = val;
  292. }
  293. };
  294. for (let i = 0, l = arguments.length; i < l; i++) {
  295. arguments[i] && forEach(arguments[i], assignValue);
  296. }
  297. return result;
  298. }
  299. /**
  300. * Extends object a by mutably adding to it the properties of object b.
  301. *
  302. * @param {Object} a The object to be extended
  303. * @param {Object} b The object to copy properties from
  304. * @param {Object} thisArg The object to bind function to
  305. *
  306. * @param {Boolean} [allOwnKeys]
  307. * @returns {Object} The resulting value of object a
  308. */
  309. const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
  310. forEach(b, (val, key) => {
  311. if (thisArg && isFunction(val)) {
  312. a[key] = bind(val, thisArg);
  313. } else {
  314. a[key] = val;
  315. }
  316. }, {allOwnKeys});
  317. return a;
  318. };
  319. /**
  320. * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  321. *
  322. * @param {string} content with BOM
  323. *
  324. * @returns {string} content value without BOM
  325. */
  326. const stripBOM = (content) => {
  327. if (content.charCodeAt(0) === 0xFEFF) {
  328. content = content.slice(1);
  329. }
  330. return content;
  331. };
  332. /**
  333. * Inherit the prototype methods from one constructor into another
  334. * @param {function} constructor
  335. * @param {function} superConstructor
  336. * @param {object} [props]
  337. * @param {object} [descriptors]
  338. *
  339. * @returns {void}
  340. */
  341. const inherits = (constructor, superConstructor, props, descriptors) => {
  342. constructor.prototype = Object.create(superConstructor.prototype, descriptors);
  343. constructor.prototype.constructor = constructor;
  344. Object.defineProperty(constructor, 'super', {
  345. value: superConstructor.prototype
  346. });
  347. props && Object.assign(constructor.prototype, props);
  348. };
  349. /**
  350. * Resolve object with deep prototype chain to a flat object
  351. * @param {Object} sourceObj source object
  352. * @param {Object} [destObj]
  353. * @param {Function|Boolean} [filter]
  354. * @param {Function} [propFilter]
  355. *
  356. * @returns {Object}
  357. */
  358. const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
  359. let props;
  360. let i;
  361. let prop;
  362. const merged = {};
  363. destObj = destObj || {};
  364. // eslint-disable-next-line no-eq-null,eqeqeq
  365. if (sourceObj == null) return destObj;
  366. do {
  367. props = Object.getOwnPropertyNames(sourceObj);
  368. i = props.length;
  369. while (i-- > 0) {
  370. prop = props[i];
  371. if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
  372. destObj[prop] = sourceObj[prop];
  373. merged[prop] = true;
  374. }
  375. }
  376. sourceObj = filter !== false && getPrototypeOf(sourceObj);
  377. } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
  378. return destObj;
  379. };
  380. /**
  381. * Determines whether a string ends with the characters of a specified string
  382. *
  383. * @param {String} str
  384. * @param {String} searchString
  385. * @param {Number} [position= 0]
  386. *
  387. * @returns {boolean}
  388. */
  389. const endsWith = (str, searchString, position) => {
  390. str = String(str);
  391. if (position === undefined || position > str.length) {
  392. position = str.length;
  393. }
  394. position -= searchString.length;
  395. const lastIndex = str.indexOf(searchString, position);
  396. return lastIndex !== -1 && lastIndex === position;
  397. };
  398. /**
  399. * Returns new array from array like object or null if failed
  400. *
  401. * @param {*} [thing]
  402. *
  403. * @returns {?Array}
  404. */
  405. const toArray = (thing) => {
  406. if (!thing) return null;
  407. if (isArray(thing)) return thing;
  408. let i = thing.length;
  409. if (!isNumber(i)) return null;
  410. const arr = new Array(i);
  411. while (i-- > 0) {
  412. arr[i] = thing[i];
  413. }
  414. return arr;
  415. };
  416. /**
  417. * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
  418. * thing passed in is an instance of Uint8Array
  419. *
  420. * @param {TypedArray}
  421. *
  422. * @returns {Array}
  423. */
  424. // eslint-disable-next-line func-names
  425. const isTypedArray = (TypedArray => {
  426. // eslint-disable-next-line func-names
  427. return thing => {
  428. return TypedArray && thing instanceof TypedArray;
  429. };
  430. })(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
  431. /**
  432. * For each entry in the object, call the function with the key and value.
  433. *
  434. * @param {Object<any, any>} obj - The object to iterate over.
  435. * @param {Function} fn - The function to call for each entry.
  436. *
  437. * @returns {void}
  438. */
  439. const forEachEntry = (obj, fn) => {
  440. const generator = obj && obj[Symbol.iterator];
  441. const iterator = generator.call(obj);
  442. let result;
  443. while ((result = iterator.next()) && !result.done) {
  444. const pair = result.value;
  445. fn.call(obj, pair[0], pair[1]);
  446. }
  447. };
  448. /**
  449. * It takes a regular expression and a string, and returns an array of all the matches
  450. *
  451. * @param {string} regExp - The regular expression to match against.
  452. * @param {string} str - The string to search.
  453. *
  454. * @returns {Array<boolean>}
  455. */
  456. const matchAll = (regExp, str) => {
  457. let matches;
  458. const arr = [];
  459. while ((matches = regExp.exec(str)) !== null) {
  460. arr.push(matches);
  461. }
  462. return arr;
  463. };
  464. /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
  465. const isHTMLForm = kindOfTest('HTMLFormElement');
  466. const toCamelCase = str => {
  467. return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,
  468. function replacer(m, p1, p2) {
  469. return p1.toUpperCase() + p2;
  470. }
  471. );
  472. };
  473. /* Creating a function that will check if an object has a property. */
  474. const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
  475. /**
  476. * Determine if a value is a RegExp object
  477. *
  478. * @param {*} val The value to test
  479. *
  480. * @returns {boolean} True if value is a RegExp object, otherwise false
  481. */
  482. const isRegExp = kindOfTest('RegExp');
  483. const reduceDescriptors = (obj, reducer) => {
  484. const descriptors = Object.getOwnPropertyDescriptors(obj);
  485. const reducedDescriptors = {};
  486. forEach(descriptors, (descriptor, name) => {
  487. let ret;
  488. if ((ret = reducer(descriptor, name, obj)) !== false) {
  489. reducedDescriptors[name] = ret || descriptor;
  490. }
  491. });
  492. Object.defineProperties(obj, reducedDescriptors);
  493. };
  494. /**
  495. * Makes all methods read-only
  496. * @param {Object} obj
  497. */
  498. const freezeMethods = (obj) => {
  499. reduceDescriptors(obj, (descriptor, name) => {
  500. // skip restricted props in strict mode
  501. if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
  502. return false;
  503. }
  504. const value = obj[name];
  505. if (!isFunction(value)) return;
  506. descriptor.enumerable = false;
  507. if ('writable' in descriptor) {
  508. descriptor.writable = false;
  509. return;
  510. }
  511. if (!descriptor.set) {
  512. descriptor.set = () => {
  513. throw Error('Can not rewrite read-only method \'' + name + '\'');
  514. };
  515. }
  516. });
  517. };
  518. const toObjectSet = (arrayOrString, delimiter) => {
  519. const obj = {};
  520. const define = (arr) => {
  521. arr.forEach(value => {
  522. obj[value] = true;
  523. });
  524. };
  525. isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
  526. return obj;
  527. };
  528. const noop = () => {};
  529. const toFiniteNumber = (value, defaultValue) => {
  530. return value != null && Number.isFinite(value = +value) ? value : defaultValue;
  531. };
  532. const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
  533. const DIGIT = '0123456789';
  534. const ALPHABET = {
  535. DIGIT,
  536. ALPHA,
  537. ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
  538. };
  539. const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
  540. let str = '';
  541. const {length} = alphabet;
  542. while (size--) {
  543. str += alphabet[Math.random() * length|0];
  544. }
  545. return str;
  546. };
  547. /**
  548. * If the thing is a FormData object, return true, otherwise return false.
  549. *
  550. * @param {unknown} thing - The thing to check.
  551. *
  552. * @returns {boolean}
  553. */
  554. function isSpecCompliantForm(thing) {
  555. return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
  556. }
  557. const toJSONObject = (obj) => {
  558. const stack = new Array(10);
  559. const visit = (source, i) => {
  560. if (isObject(source)) {
  561. if (stack.indexOf(source) >= 0) {
  562. return;
  563. }
  564. if(!('toJSON' in source)) {
  565. stack[i] = source;
  566. const target = isArray(source) ? [] : {};
  567. forEach(source, (value, key) => {
  568. const reducedValue = visit(value, i + 1);
  569. !isUndefined(reducedValue) && (target[key] = reducedValue);
  570. });
  571. stack[i] = undefined;
  572. return target;
  573. }
  574. }
  575. return source;
  576. };
  577. return visit(obj, 0);
  578. };
  579. const isAsyncFn = kindOfTest('AsyncFunction');
  580. const isThenable = (thing) =>
  581. thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
  582. const utils$1 = {
  583. isArray,
  584. isArrayBuffer,
  585. isBuffer,
  586. isFormData,
  587. isArrayBufferView,
  588. isString,
  589. isNumber,
  590. isBoolean,
  591. isObject,
  592. isPlainObject,
  593. isReadableStream,
  594. isRequest,
  595. isResponse,
  596. isHeaders,
  597. isUndefined,
  598. isDate,
  599. isFile,
  600. isBlob,
  601. isRegExp,
  602. isFunction,
  603. isStream,
  604. isURLSearchParams,
  605. isTypedArray,
  606. isFileList,
  607. forEach,
  608. merge,
  609. extend,
  610. trim,
  611. stripBOM,
  612. inherits,
  613. toFlatObject,
  614. kindOf,
  615. kindOfTest,
  616. endsWith,
  617. toArray,
  618. forEachEntry,
  619. matchAll,
  620. isHTMLForm,
  621. hasOwnProperty,
  622. hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
  623. reduceDescriptors,
  624. freezeMethods,
  625. toObjectSet,
  626. toCamelCase,
  627. noop,
  628. toFiniteNumber,
  629. findKey,
  630. global: _global,
  631. isContextDefined,
  632. ALPHABET,
  633. generateString,
  634. isSpecCompliantForm,
  635. toJSONObject,
  636. isAsyncFn,
  637. isThenable
  638. };
  639. /**
  640. * Create an Error with the specified message, config, error code, request and response.
  641. *
  642. * @param {string} message The error message.
  643. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  644. * @param {Object} [config] The config.
  645. * @param {Object} [request] The request.
  646. * @param {Object} [response] The response.
  647. *
  648. * @returns {Error} The created error.
  649. */
  650. function AxiosError$1(message, code, config, request, response) {
  651. Error.call(this);
  652. if (Error.captureStackTrace) {
  653. Error.captureStackTrace(this, this.constructor);
  654. } else {
  655. this.stack = (new Error()).stack;
  656. }
  657. this.message = message;
  658. this.name = 'AxiosError';
  659. code && (this.code = code);
  660. config && (this.config = config);
  661. request && (this.request = request);
  662. response && (this.response = response);
  663. }
  664. utils$1.inherits(AxiosError$1, Error, {
  665. toJSON: function toJSON() {
  666. return {
  667. // Standard
  668. message: this.message,
  669. name: this.name,
  670. // Microsoft
  671. description: this.description,
  672. number: this.number,
  673. // Mozilla
  674. fileName: this.fileName,
  675. lineNumber: this.lineNumber,
  676. columnNumber: this.columnNumber,
  677. stack: this.stack,
  678. // Axios
  679. config: utils$1.toJSONObject(this.config),
  680. code: this.code,
  681. status: this.response && this.response.status ? this.response.status : null
  682. };
  683. }
  684. });
  685. const prototype$1 = AxiosError$1.prototype;
  686. const descriptors = {};
  687. [
  688. 'ERR_BAD_OPTION_VALUE',
  689. 'ERR_BAD_OPTION',
  690. 'ECONNABORTED',
  691. 'ETIMEDOUT',
  692. 'ERR_NETWORK',
  693. 'ERR_FR_TOO_MANY_REDIRECTS',
  694. 'ERR_DEPRECATED',
  695. 'ERR_BAD_RESPONSE',
  696. 'ERR_BAD_REQUEST',
  697. 'ERR_CANCELED',
  698. 'ERR_NOT_SUPPORT',
  699. 'ERR_INVALID_URL'
  700. // eslint-disable-next-line func-names
  701. ].forEach(code => {
  702. descriptors[code] = {value: code};
  703. });
  704. Object.defineProperties(AxiosError$1, descriptors);
  705. Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
  706. // eslint-disable-next-line func-names
  707. AxiosError$1.from = (error, code, config, request, response, customProps) => {
  708. const axiosError = Object.create(prototype$1);
  709. utils$1.toFlatObject(error, axiosError, function filter(obj) {
  710. return obj !== Error.prototype;
  711. }, prop => {
  712. return prop !== 'isAxiosError';
  713. });
  714. AxiosError$1.call(axiosError, error.message, code, config, request, response);
  715. axiosError.cause = error;
  716. axiosError.name = error.name;
  717. customProps && Object.assign(axiosError, customProps);
  718. return axiosError;
  719. };
  720. // eslint-disable-next-line strict
  721. const httpAdapter = null;
  722. /**
  723. * Determines if the given thing is a array or js object.
  724. *
  725. * @param {string} thing - The object or array to be visited.
  726. *
  727. * @returns {boolean}
  728. */
  729. function isVisitable(thing) {
  730. return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
  731. }
  732. /**
  733. * It removes the brackets from the end of a string
  734. *
  735. * @param {string} key - The key of the parameter.
  736. *
  737. * @returns {string} the key without the brackets.
  738. */
  739. function removeBrackets(key) {
  740. return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
  741. }
  742. /**
  743. * It takes a path, a key, and a boolean, and returns a string
  744. *
  745. * @param {string} path - The path to the current key.
  746. * @param {string} key - The key of the current object being iterated over.
  747. * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
  748. *
  749. * @returns {string} The path to the current key.
  750. */
  751. function renderKey(path, key, dots) {
  752. if (!path) return key;
  753. return path.concat(key).map(function each(token, i) {
  754. // eslint-disable-next-line no-param-reassign
  755. token = removeBrackets(token);
  756. return !dots && i ? '[' + token + ']' : token;
  757. }).join(dots ? '.' : '');
  758. }
  759. /**
  760. * If the array is an array and none of its elements are visitable, then it's a flat array.
  761. *
  762. * @param {Array<any>} arr - The array to check
  763. *
  764. * @returns {boolean}
  765. */
  766. function isFlatArray(arr) {
  767. return utils$1.isArray(arr) && !arr.some(isVisitable);
  768. }
  769. const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
  770. return /^is[A-Z]/.test(prop);
  771. });
  772. /**
  773. * Convert a data object to FormData
  774. *
  775. * @param {Object} obj
  776. * @param {?Object} [formData]
  777. * @param {?Object} [options]
  778. * @param {Function} [options.visitor]
  779. * @param {Boolean} [options.metaTokens = true]
  780. * @param {Boolean} [options.dots = false]
  781. * @param {?Boolean} [options.indexes = false]
  782. *
  783. * @returns {Object}
  784. **/
  785. /**
  786. * It converts an object into a FormData object
  787. *
  788. * @param {Object<any, any>} obj - The object to convert to form data.
  789. * @param {string} formData - The FormData object to append to.
  790. * @param {Object<string, any>} options
  791. *
  792. * @returns
  793. */
  794. function toFormData$1(obj, formData, options) {
  795. if (!utils$1.isObject(obj)) {
  796. throw new TypeError('target must be an object');
  797. }
  798. // eslint-disable-next-line no-param-reassign
  799. formData = formData || new (FormData)();
  800. // eslint-disable-next-line no-param-reassign
  801. options = utils$1.toFlatObject(options, {
  802. metaTokens: true,
  803. dots: false,
  804. indexes: false
  805. }, false, function defined(option, source) {
  806. // eslint-disable-next-line no-eq-null,eqeqeq
  807. return !utils$1.isUndefined(source[option]);
  808. });
  809. const metaTokens = options.metaTokens;
  810. // eslint-disable-next-line no-use-before-define
  811. const visitor = options.visitor || defaultVisitor;
  812. const dots = options.dots;
  813. const indexes = options.indexes;
  814. const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
  815. const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
  816. if (!utils$1.isFunction(visitor)) {
  817. throw new TypeError('visitor must be a function');
  818. }
  819. function convertValue(value) {
  820. if (value === null) return '';
  821. if (utils$1.isDate(value)) {
  822. return value.toISOString();
  823. }
  824. if (!useBlob && utils$1.isBlob(value)) {
  825. throw new AxiosError$1('Blob is not supported. Use a Buffer instead.');
  826. }
  827. if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
  828. return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
  829. }
  830. return value;
  831. }
  832. /**
  833. * Default visitor.
  834. *
  835. * @param {*} value
  836. * @param {String|Number} key
  837. * @param {Array<String|Number>} path
  838. * @this {FormData}
  839. *
  840. * @returns {boolean} return true to visit the each prop of the value recursively
  841. */
  842. function defaultVisitor(value, key, path) {
  843. let arr = value;
  844. if (value && !path && typeof value === 'object') {
  845. if (utils$1.endsWith(key, '{}')) {
  846. // eslint-disable-next-line no-param-reassign
  847. key = metaTokens ? key : key.slice(0, -2);
  848. // eslint-disable-next-line no-param-reassign
  849. value = JSON.stringify(value);
  850. } else if (
  851. (utils$1.isArray(value) && isFlatArray(value)) ||
  852. ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value))
  853. )) {
  854. // eslint-disable-next-line no-param-reassign
  855. key = removeBrackets(key);
  856. arr.forEach(function each(el, index) {
  857. !(utils$1.isUndefined(el) || el === null) && formData.append(
  858. // eslint-disable-next-line no-nested-ternary
  859. indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
  860. convertValue(el)
  861. );
  862. });
  863. return false;
  864. }
  865. }
  866. if (isVisitable(value)) {
  867. return true;
  868. }
  869. formData.append(renderKey(path, key, dots), convertValue(value));
  870. return false;
  871. }
  872. const stack = [];
  873. const exposedHelpers = Object.assign(predicates, {
  874. defaultVisitor,
  875. convertValue,
  876. isVisitable
  877. });
  878. function build(value, path) {
  879. if (utils$1.isUndefined(value)) return;
  880. if (stack.indexOf(value) !== -1) {
  881. throw Error('Circular reference detected in ' + path.join('.'));
  882. }
  883. stack.push(value);
  884. utils$1.forEach(value, function each(el, key) {
  885. const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(
  886. formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers
  887. );
  888. if (result === true) {
  889. build(el, path ? path.concat(key) : [key]);
  890. }
  891. });
  892. stack.pop();
  893. }
  894. if (!utils$1.isObject(obj)) {
  895. throw new TypeError('data must be an object');
  896. }
  897. build(obj);
  898. return formData;
  899. }
  900. /**
  901. * It encodes a string by replacing all characters that are not in the unreserved set with
  902. * their percent-encoded equivalents
  903. *
  904. * @param {string} str - The string to encode.
  905. *
  906. * @returns {string} The encoded string.
  907. */
  908. function encode$1(str) {
  909. const charMap = {
  910. '!': '%21',
  911. "'": '%27',
  912. '(': '%28',
  913. ')': '%29',
  914. '~': '%7E',
  915. '%20': '+',
  916. '%00': '\x00'
  917. };
  918. return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
  919. return charMap[match];
  920. });
  921. }
  922. /**
  923. * It takes a params object and converts it to a FormData object
  924. *
  925. * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
  926. * @param {Object<string, any>} options - The options object passed to the Axios constructor.
  927. *
  928. * @returns {void}
  929. */
  930. function AxiosURLSearchParams(params, options) {
  931. this._pairs = [];
  932. params && toFormData$1(params, this, options);
  933. }
  934. const prototype = AxiosURLSearchParams.prototype;
  935. prototype.append = function append(name, value) {
  936. this._pairs.push([name, value]);
  937. };
  938. prototype.toString = function toString(encoder) {
  939. const _encode = encoder ? function(value) {
  940. return encoder.call(this, value, encode$1);
  941. } : encode$1;
  942. return this._pairs.map(function each(pair) {
  943. return _encode(pair[0]) + '=' + _encode(pair[1]);
  944. }, '').join('&');
  945. };
  946. /**
  947. * It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
  948. * URI encoded counterparts
  949. *
  950. * @param {string} val The value to be encoded.
  951. *
  952. * @returns {string} The encoded value.
  953. */
  954. function encode(val) {
  955. return encodeURIComponent(val).
  956. replace(/%3A/gi, ':').
  957. replace(/%24/g, '$').
  958. replace(/%2C/gi, ',').
  959. replace(/%20/g, '+').
  960. replace(/%5B/gi, '[').
  961. replace(/%5D/gi, ']');
  962. }
  963. /**
  964. * Build a URL by appending params to the end
  965. *
  966. * @param {string} url The base of the url (e.g., http://www.google.com)
  967. * @param {object} [params] The params to be appended
  968. * @param {?object} options
  969. *
  970. * @returns {string} The formatted url
  971. */
  972. function buildURL(url, params, options) {
  973. /*eslint no-param-reassign:0*/
  974. if (!params) {
  975. return url;
  976. }
  977. const _encode = options && options.encode || encode;
  978. const serializeFn = options && options.serialize;
  979. let serializedParams;
  980. if (serializeFn) {
  981. serializedParams = serializeFn(params, options);
  982. } else {
  983. serializedParams = utils$1.isURLSearchParams(params) ?
  984. params.toString() :
  985. new AxiosURLSearchParams(params, options).toString(_encode);
  986. }
  987. if (serializedParams) {
  988. const hashmarkIndex = url.indexOf("#");
  989. if (hashmarkIndex !== -1) {
  990. url = url.slice(0, hashmarkIndex);
  991. }
  992. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  993. }
  994. return url;
  995. }
  996. class InterceptorManager {
  997. constructor() {
  998. this.handlers = [];
  999. }
  1000. /**
  1001. * Add a new interceptor to the stack
  1002. *
  1003. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  1004. * @param {Function} rejected The function to handle `reject` for a `Promise`
  1005. *
  1006. * @return {Number} An ID used to remove interceptor later
  1007. */
  1008. use(fulfilled, rejected, options) {
  1009. this.handlers.push({
  1010. fulfilled,
  1011. rejected,
  1012. synchronous: options ? options.synchronous : false,
  1013. runWhen: options ? options.runWhen : null
  1014. });
  1015. return this.handlers.length - 1;
  1016. }
  1017. /**
  1018. * Remove an interceptor from the stack
  1019. *
  1020. * @param {Number} id The ID that was returned by `use`
  1021. *
  1022. * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
  1023. */
  1024. eject(id) {
  1025. if (this.handlers[id]) {
  1026. this.handlers[id] = null;
  1027. }
  1028. }
  1029. /**
  1030. * Clear all interceptors from the stack
  1031. *
  1032. * @returns {void}
  1033. */
  1034. clear() {
  1035. if (this.handlers) {
  1036. this.handlers = [];
  1037. }
  1038. }
  1039. /**
  1040. * Iterate over all the registered interceptors
  1041. *
  1042. * This method is particularly useful for skipping over any
  1043. * interceptors that may have become `null` calling `eject`.
  1044. *
  1045. * @param {Function} fn The function to call for each interceptor
  1046. *
  1047. * @returns {void}
  1048. */
  1049. forEach(fn) {
  1050. utils$1.forEach(this.handlers, function forEachHandler(h) {
  1051. if (h !== null) {
  1052. fn(h);
  1053. }
  1054. });
  1055. }
  1056. }
  1057. const InterceptorManager$1 = InterceptorManager;
  1058. const transitionalDefaults = {
  1059. silentJSONParsing: true,
  1060. forcedJSONParsing: true,
  1061. clarifyTimeoutError: false
  1062. };
  1063. const URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
  1064. const FormData$1 = typeof FormData !== 'undefined' ? FormData : null;
  1065. const Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
  1066. const platform$1 = {
  1067. isBrowser: true,
  1068. classes: {
  1069. URLSearchParams: URLSearchParams$1,
  1070. FormData: FormData$1,
  1071. Blob: Blob$1
  1072. },
  1073. protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
  1074. };
  1075. const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
  1076. /**
  1077. * Determine if we're running in a standard browser environment
  1078. *
  1079. * This allows axios to run in a web worker, and react-native.
  1080. * Both environments support XMLHttpRequest, but not fully standard globals.
  1081. *
  1082. * web workers:
  1083. * typeof window -> undefined
  1084. * typeof document -> undefined
  1085. *
  1086. * react-native:
  1087. * navigator.product -> 'ReactNative'
  1088. * nativescript
  1089. * navigator.product -> 'NativeScript' or 'NS'
  1090. *
  1091. * @returns {boolean}
  1092. */
  1093. const hasStandardBrowserEnv = (
  1094. (product) => {
  1095. return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
  1096. })(typeof navigator !== 'undefined' && navigator.product);
  1097. /**
  1098. * Determine if we're running in a standard browser webWorker environment
  1099. *
  1100. * Although the `isStandardBrowserEnv` method indicates that
  1101. * `allows axios to run in a web worker`, the WebWorker will still be
  1102. * filtered out due to its judgment standard
  1103. * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
  1104. * This leads to a problem when axios post `FormData` in webWorker
  1105. */
  1106. const hasStandardBrowserWebWorkerEnv = (() => {
  1107. return (
  1108. typeof WorkerGlobalScope !== 'undefined' &&
  1109. // eslint-disable-next-line no-undef
  1110. self instanceof WorkerGlobalScope &&
  1111. typeof self.importScripts === 'function'
  1112. );
  1113. })();
  1114. const origin = hasBrowserEnv && window.location.href || 'http://localhost';
  1115. const utils = /*#__PURE__*/Object.freeze({
  1116. __proto__: null,
  1117. hasBrowserEnv: hasBrowserEnv,
  1118. hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
  1119. hasStandardBrowserEnv: hasStandardBrowserEnv,
  1120. origin: origin
  1121. });
  1122. const platform = {
  1123. ...utils,
  1124. ...platform$1
  1125. };
  1126. function toURLEncodedForm(data, options) {
  1127. return toFormData$1(data, new platform.classes.URLSearchParams(), Object.assign({
  1128. visitor: function(value, key, path, helpers) {
  1129. if (platform.isNode && utils$1.isBuffer(value)) {
  1130. this.append(key, value.toString('base64'));
  1131. return false;
  1132. }
  1133. return helpers.defaultVisitor.apply(this, arguments);
  1134. }
  1135. }, options));
  1136. }
  1137. /**
  1138. * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
  1139. *
  1140. * @param {string} name - The name of the property to get.
  1141. *
  1142. * @returns An array of strings.
  1143. */
  1144. function parsePropPath(name) {
  1145. // foo[x][y][z]
  1146. // foo.x.y.z
  1147. // foo-x-y-z
  1148. // foo x y z
  1149. return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
  1150. return match[0] === '[]' ? '' : match[1] || match[0];
  1151. });
  1152. }
  1153. /**
  1154. * Convert an array to an object.
  1155. *
  1156. * @param {Array<any>} arr - The array to convert to an object.
  1157. *
  1158. * @returns An object with the same keys and values as the array.
  1159. */
  1160. function arrayToObject(arr) {
  1161. const obj = {};
  1162. const keys = Object.keys(arr);
  1163. let i;
  1164. const len = keys.length;
  1165. let key;
  1166. for (i = 0; i < len; i++) {
  1167. key = keys[i];
  1168. obj[key] = arr[key];
  1169. }
  1170. return obj;
  1171. }
  1172. /**
  1173. * It takes a FormData object and returns a JavaScript object
  1174. *
  1175. * @param {string} formData The FormData object to convert to JSON.
  1176. *
  1177. * @returns {Object<string, any> | null} The converted object.
  1178. */
  1179. function formDataToJSON(formData) {
  1180. function buildPath(path, value, target, index) {
  1181. let name = path[index++];
  1182. if (name === '__proto__') return true;
  1183. const isNumericKey = Number.isFinite(+name);
  1184. const isLast = index >= path.length;
  1185. name = !name && utils$1.isArray(target) ? target.length : name;
  1186. if (isLast) {
  1187. if (utils$1.hasOwnProp(target, name)) {
  1188. target[name] = [target[name], value];
  1189. } else {
  1190. target[name] = value;
  1191. }
  1192. return !isNumericKey;
  1193. }
  1194. if (!target[name] || !utils$1.isObject(target[name])) {
  1195. target[name] = [];
  1196. }
  1197. const result = buildPath(path, value, target[name], index);
  1198. if (result && utils$1.isArray(target[name])) {
  1199. target[name] = arrayToObject(target[name]);
  1200. }
  1201. return !isNumericKey;
  1202. }
  1203. if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
  1204. const obj = {};
  1205. utils$1.forEachEntry(formData, (name, value) => {
  1206. buildPath(parsePropPath(name), value, obj, 0);
  1207. });
  1208. return obj;
  1209. }
  1210. return null;
  1211. }
  1212. /**
  1213. * It takes a string, tries to parse it, and if it fails, it returns the stringified version
  1214. * of the input
  1215. *
  1216. * @param {any} rawValue - The value to be stringified.
  1217. * @param {Function} parser - A function that parses a string into a JavaScript object.
  1218. * @param {Function} encoder - A function that takes a value and returns a string.
  1219. *
  1220. * @returns {string} A stringified version of the rawValue.
  1221. */
  1222. function stringifySafely(rawValue, parser, encoder) {
  1223. if (utils$1.isString(rawValue)) {
  1224. try {
  1225. (parser || JSON.parse)(rawValue);
  1226. return utils$1.trim(rawValue);
  1227. } catch (e) {
  1228. if (e.name !== 'SyntaxError') {
  1229. throw e;
  1230. }
  1231. }
  1232. }
  1233. return (encoder || JSON.stringify)(rawValue);
  1234. }
  1235. const defaults = {
  1236. transitional: transitionalDefaults,
  1237. adapter: ['xhr', 'http', 'fetch'],
  1238. transformRequest: [function transformRequest(data, headers) {
  1239. const contentType = headers.getContentType() || '';
  1240. const hasJSONContentType = contentType.indexOf('application/json') > -1;
  1241. const isObjectPayload = utils$1.isObject(data);
  1242. if (isObjectPayload && utils$1.isHTMLForm(data)) {
  1243. data = new FormData(data);
  1244. }
  1245. const isFormData = utils$1.isFormData(data);
  1246. if (isFormData) {
  1247. return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
  1248. }
  1249. if (utils$1.isArrayBuffer(data) ||
  1250. utils$1.isBuffer(data) ||
  1251. utils$1.isStream(data) ||
  1252. utils$1.isFile(data) ||
  1253. utils$1.isBlob(data) ||
  1254. utils$1.isReadableStream(data)
  1255. ) {
  1256. return data;
  1257. }
  1258. if (utils$1.isArrayBufferView(data)) {
  1259. return data.buffer;
  1260. }
  1261. if (utils$1.isURLSearchParams(data)) {
  1262. headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
  1263. return data.toString();
  1264. }
  1265. let isFileList;
  1266. if (isObjectPayload) {
  1267. if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
  1268. return toURLEncodedForm(data, this.formSerializer).toString();
  1269. }
  1270. if ((isFileList = utils$1.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
  1271. const _FormData = this.env && this.env.FormData;
  1272. return toFormData$1(
  1273. isFileList ? {'files[]': data} : data,
  1274. _FormData && new _FormData(),
  1275. this.formSerializer
  1276. );
  1277. }
  1278. }
  1279. if (isObjectPayload || hasJSONContentType ) {
  1280. headers.setContentType('application/json', false);
  1281. return stringifySafely(data);
  1282. }
  1283. return data;
  1284. }],
  1285. transformResponse: [function transformResponse(data) {
  1286. const transitional = this.transitional || defaults.transitional;
  1287. const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
  1288. const JSONRequested = this.responseType === 'json';
  1289. if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
  1290. return data;
  1291. }
  1292. if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
  1293. const silentJSONParsing = transitional && transitional.silentJSONParsing;
  1294. const strictJSONParsing = !silentJSONParsing && JSONRequested;
  1295. try {
  1296. return JSON.parse(data);
  1297. } catch (e) {
  1298. if (strictJSONParsing) {
  1299. if (e.name === 'SyntaxError') {
  1300. throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
  1301. }
  1302. throw e;
  1303. }
  1304. }
  1305. }
  1306. return data;
  1307. }],
  1308. /**
  1309. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  1310. * timeout is not created.
  1311. */
  1312. timeout: 0,
  1313. xsrfCookieName: 'XSRF-TOKEN',
  1314. xsrfHeaderName: 'X-XSRF-TOKEN',
  1315. maxContentLength: -1,
  1316. maxBodyLength: -1,
  1317. env: {
  1318. FormData: platform.classes.FormData,
  1319. Blob: platform.classes.Blob
  1320. },
  1321. validateStatus: function validateStatus(status) {
  1322. return status >= 200 && status < 300;
  1323. },
  1324. headers: {
  1325. common: {
  1326. 'Accept': 'application/json, text/plain, */*',
  1327. 'Content-Type': undefined
  1328. }
  1329. }
  1330. };
  1331. utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
  1332. defaults.headers[method] = {};
  1333. });
  1334. const defaults$1 = defaults;
  1335. // RawAxiosHeaders whose duplicates are ignored by node
  1336. // c.f. https://nodejs.org/api/http.html#http_message_headers
  1337. const ignoreDuplicateOf = utils$1.toObjectSet([
  1338. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  1339. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  1340. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  1341. 'referer', 'retry-after', 'user-agent'
  1342. ]);
  1343. /**
  1344. * Parse headers into an object
  1345. *
  1346. * ```
  1347. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  1348. * Content-Type: application/json
  1349. * Connection: keep-alive
  1350. * Transfer-Encoding: chunked
  1351. * ```
  1352. *
  1353. * @param {String} rawHeaders Headers needing to be parsed
  1354. *
  1355. * @returns {Object} Headers parsed into an object
  1356. */
  1357. const parseHeaders = rawHeaders => {
  1358. const parsed = {};
  1359. let key;
  1360. let val;
  1361. let i;
  1362. rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
  1363. i = line.indexOf(':');
  1364. key = line.substring(0, i).trim().toLowerCase();
  1365. val = line.substring(i + 1).trim();
  1366. if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
  1367. return;
  1368. }
  1369. if (key === 'set-cookie') {
  1370. if (parsed[key]) {
  1371. parsed[key].push(val);
  1372. } else {
  1373. parsed[key] = [val];
  1374. }
  1375. } else {
  1376. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  1377. }
  1378. });
  1379. return parsed;
  1380. };
  1381. const $internals = Symbol('internals');
  1382. function normalizeHeader(header) {
  1383. return header && String(header).trim().toLowerCase();
  1384. }
  1385. function normalizeValue(value) {
  1386. if (value === false || value == null) {
  1387. return value;
  1388. }
  1389. return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
  1390. }
  1391. function parseTokens(str) {
  1392. const tokens = Object.create(null);
  1393. const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
  1394. let match;
  1395. while ((match = tokensRE.exec(str))) {
  1396. tokens[match[1]] = match[2];
  1397. }
  1398. return tokens;
  1399. }
  1400. const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
  1401. function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
  1402. if (utils$1.isFunction(filter)) {
  1403. return filter.call(this, value, header);
  1404. }
  1405. if (isHeaderNameFilter) {
  1406. value = header;
  1407. }
  1408. if (!utils$1.isString(value)) return;
  1409. if (utils$1.isString(filter)) {
  1410. return value.indexOf(filter) !== -1;
  1411. }
  1412. if (utils$1.isRegExp(filter)) {
  1413. return filter.test(value);
  1414. }
  1415. }
  1416. function formatHeader(header) {
  1417. return header.trim()
  1418. .toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
  1419. return char.toUpperCase() + str;
  1420. });
  1421. }
  1422. function buildAccessors(obj, header) {
  1423. const accessorName = utils$1.toCamelCase(' ' + header);
  1424. ['get', 'set', 'has'].forEach(methodName => {
  1425. Object.defineProperty(obj, methodName + accessorName, {
  1426. value: function(arg1, arg2, arg3) {
  1427. return this[methodName].call(this, header, arg1, arg2, arg3);
  1428. },
  1429. configurable: true
  1430. });
  1431. });
  1432. }
  1433. class AxiosHeaders$1 {
  1434. constructor(headers) {
  1435. headers && this.set(headers);
  1436. }
  1437. set(header, valueOrRewrite, rewrite) {
  1438. const self = this;
  1439. function setHeader(_value, _header, _rewrite) {
  1440. const lHeader = normalizeHeader(_header);
  1441. if (!lHeader) {
  1442. throw new Error('header name must be a non-empty string');
  1443. }
  1444. const key = utils$1.findKey(self, lHeader);
  1445. if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
  1446. self[key || _header] = normalizeValue(_value);
  1447. }
  1448. }
  1449. const setHeaders = (headers, _rewrite) =>
  1450. utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
  1451. if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
  1452. setHeaders(header, valueOrRewrite);
  1453. } else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
  1454. setHeaders(parseHeaders(header), valueOrRewrite);
  1455. } else if (utils$1.isHeaders(header)) {
  1456. for (const [key, value] of header.entries()) {
  1457. setHeader(value, key, rewrite);
  1458. }
  1459. } else {
  1460. header != null && setHeader(valueOrRewrite, header, rewrite);
  1461. }
  1462. return this;
  1463. }
  1464. get(header, parser) {
  1465. header = normalizeHeader(header);
  1466. if (header) {
  1467. const key = utils$1.findKey(this, header);
  1468. if (key) {
  1469. const value = this[key];
  1470. if (!parser) {
  1471. return value;
  1472. }
  1473. if (parser === true) {
  1474. return parseTokens(value);
  1475. }
  1476. if (utils$1.isFunction(parser)) {
  1477. return parser.call(this, value, key);
  1478. }
  1479. if (utils$1.isRegExp(parser)) {
  1480. return parser.exec(value);
  1481. }
  1482. throw new TypeError('parser must be boolean|regexp|function');
  1483. }
  1484. }
  1485. }
  1486. has(header, matcher) {
  1487. header = normalizeHeader(header);
  1488. if (header) {
  1489. const key = utils$1.findKey(this, header);
  1490. return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
  1491. }
  1492. return false;
  1493. }
  1494. delete(header, matcher) {
  1495. const self = this;
  1496. let deleted = false;
  1497. function deleteHeader(_header) {
  1498. _header = normalizeHeader(_header);
  1499. if (_header) {
  1500. const key = utils$1.findKey(self, _header);
  1501. if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
  1502. delete self[key];
  1503. deleted = true;
  1504. }
  1505. }
  1506. }
  1507. if (utils$1.isArray(header)) {
  1508. header.forEach(deleteHeader);
  1509. } else {
  1510. deleteHeader(header);
  1511. }
  1512. return deleted;
  1513. }
  1514. clear(matcher) {
  1515. const keys = Object.keys(this);
  1516. let i = keys.length;
  1517. let deleted = false;
  1518. while (i--) {
  1519. const key = keys[i];
  1520. if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
  1521. delete this[key];
  1522. deleted = true;
  1523. }
  1524. }
  1525. return deleted;
  1526. }
  1527. normalize(format) {
  1528. const self = this;
  1529. const headers = {};
  1530. utils$1.forEach(this, (value, header) => {
  1531. const key = utils$1.findKey(headers, header);
  1532. if (key) {
  1533. self[key] = normalizeValue(value);
  1534. delete self[header];
  1535. return;
  1536. }
  1537. const normalized = format ? formatHeader(header) : String(header).trim();
  1538. if (normalized !== header) {
  1539. delete self[header];
  1540. }
  1541. self[normalized] = normalizeValue(value);
  1542. headers[normalized] = true;
  1543. });
  1544. return this;
  1545. }
  1546. concat(...targets) {
  1547. return this.constructor.concat(this, ...targets);
  1548. }
  1549. toJSON(asStrings) {
  1550. const obj = Object.create(null);
  1551. utils$1.forEach(this, (value, header) => {
  1552. value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(', ') : value);
  1553. });
  1554. return obj;
  1555. }
  1556. [Symbol.iterator]() {
  1557. return Object.entries(this.toJSON())[Symbol.iterator]();
  1558. }
  1559. toString() {
  1560. return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
  1561. }
  1562. get [Symbol.toStringTag]() {
  1563. return 'AxiosHeaders';
  1564. }
  1565. static from(thing) {
  1566. return thing instanceof this ? thing : new this(thing);
  1567. }
  1568. static concat(first, ...targets) {
  1569. const computed = new this(first);
  1570. targets.forEach((target) => computed.set(target));
  1571. return computed;
  1572. }
  1573. static accessor(header) {
  1574. const internals = this[$internals] = (this[$internals] = {
  1575. accessors: {}
  1576. });
  1577. const accessors = internals.accessors;
  1578. const prototype = this.prototype;
  1579. function defineAccessor(_header) {
  1580. const lHeader = normalizeHeader(_header);
  1581. if (!accessors[lHeader]) {
  1582. buildAccessors(prototype, _header);
  1583. accessors[lHeader] = true;
  1584. }
  1585. }
  1586. utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
  1587. return this;
  1588. }
  1589. }
  1590. AxiosHeaders$1.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
  1591. // reserved names hotfix
  1592. utils$1.reduceDescriptors(AxiosHeaders$1.prototype, ({value}, key) => {
  1593. let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
  1594. return {
  1595. get: () => value,
  1596. set(headerValue) {
  1597. this[mapped] = headerValue;
  1598. }
  1599. }
  1600. });
  1601. utils$1.freezeMethods(AxiosHeaders$1);
  1602. const AxiosHeaders$2 = AxiosHeaders$1;
  1603. /**
  1604. * Transform the data for a request or a response
  1605. *
  1606. * @param {Array|Function} fns A single function or Array of functions
  1607. * @param {?Object} response The response object
  1608. *
  1609. * @returns {*} The resulting transformed data
  1610. */
  1611. function transformData(fns, response) {
  1612. const config = this || defaults$1;
  1613. const context = response || config;
  1614. const headers = AxiosHeaders$2.from(context.headers);
  1615. let data = context.data;
  1616. utils$1.forEach(fns, function transform(fn) {
  1617. data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
  1618. });
  1619. headers.normalize();
  1620. return data;
  1621. }
  1622. function isCancel$1(value) {
  1623. return !!(value && value.__CANCEL__);
  1624. }
  1625. /**
  1626. * A `CanceledError` is an object that is thrown when an operation is canceled.
  1627. *
  1628. * @param {string=} message The message.
  1629. * @param {Object=} config The config.
  1630. * @param {Object=} request The request.
  1631. *
  1632. * @returns {CanceledError} The created error.
  1633. */
  1634. function CanceledError$1(message, config, request) {
  1635. // eslint-disable-next-line no-eq-null,eqeqeq
  1636. AxiosError$1.call(this, message == null ? 'canceled' : message, AxiosError$1.ERR_CANCELED, config, request);
  1637. this.name = 'CanceledError';
  1638. }
  1639. utils$1.inherits(CanceledError$1, AxiosError$1, {
  1640. __CANCEL__: true
  1641. });
  1642. /**
  1643. * Resolve or reject a Promise based on response status.
  1644. *
  1645. * @param {Function} resolve A function that resolves the promise.
  1646. * @param {Function} reject A function that rejects the promise.
  1647. * @param {object} response The response.
  1648. *
  1649. * @returns {object} The response.
  1650. */
  1651. function settle(resolve, reject, response) {
  1652. const validateStatus = response.config.validateStatus;
  1653. if (!response.status || !validateStatus || validateStatus(response.status)) {
  1654. resolve(response);
  1655. } else {
  1656. reject(new AxiosError$1(
  1657. 'Request failed with status code ' + response.status,
  1658. [AxiosError$1.ERR_BAD_REQUEST, AxiosError$1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
  1659. response.config,
  1660. response.request,
  1661. response
  1662. ));
  1663. }
  1664. }
  1665. function parseProtocol(url) {
  1666. const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
  1667. return match && match[1] || '';
  1668. }
  1669. /**
  1670. * Calculate data maxRate
  1671. * @param {Number} [samplesCount= 10]
  1672. * @param {Number} [min= 1000]
  1673. * @returns {Function}
  1674. */
  1675. function speedometer(samplesCount, min) {
  1676. samplesCount = samplesCount || 10;
  1677. const bytes = new Array(samplesCount);
  1678. const timestamps = new Array(samplesCount);
  1679. let head = 0;
  1680. let tail = 0;
  1681. let firstSampleTS;
  1682. min = min !== undefined ? min : 1000;
  1683. return function push(chunkLength) {
  1684. const now = Date.now();
  1685. const startedAt = timestamps[tail];
  1686. if (!firstSampleTS) {
  1687. firstSampleTS = now;
  1688. }
  1689. bytes[head] = chunkLength;
  1690. timestamps[head] = now;
  1691. let i = tail;
  1692. let bytesCount = 0;
  1693. while (i !== head) {
  1694. bytesCount += bytes[i++];
  1695. i = i % samplesCount;
  1696. }
  1697. head = (head + 1) % samplesCount;
  1698. if (head === tail) {
  1699. tail = (tail + 1) % samplesCount;
  1700. }
  1701. if (now - firstSampleTS < min) {
  1702. return;
  1703. }
  1704. const passed = startedAt && now - startedAt;
  1705. return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
  1706. };
  1707. }
  1708. /**
  1709. * Throttle decorator
  1710. * @param {Function} fn
  1711. * @param {Number} freq
  1712. * @return {Function}
  1713. */
  1714. function throttle(fn, freq) {
  1715. let timestamp = 0;
  1716. const threshold = 1000 / freq;
  1717. let timer = null;
  1718. return function throttled() {
  1719. const force = this === true;
  1720. const now = Date.now();
  1721. if (force || now - timestamp > threshold) {
  1722. if (timer) {
  1723. clearTimeout(timer);
  1724. timer = null;
  1725. }
  1726. timestamp = now;
  1727. return fn.apply(null, arguments);
  1728. }
  1729. if (!timer) {
  1730. timer = setTimeout(() => {
  1731. timer = null;
  1732. timestamp = Date.now();
  1733. return fn.apply(null, arguments);
  1734. }, threshold - (now - timestamp));
  1735. }
  1736. };
  1737. }
  1738. const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
  1739. let bytesNotified = 0;
  1740. const _speedometer = speedometer(50, 250);
  1741. return throttle(e => {
  1742. const loaded = e.loaded;
  1743. const total = e.lengthComputable ? e.total : undefined;
  1744. const progressBytes = loaded - bytesNotified;
  1745. const rate = _speedometer(progressBytes);
  1746. const inRange = loaded <= total;
  1747. bytesNotified = loaded;
  1748. const data = {
  1749. loaded,
  1750. total,
  1751. progress: total ? (loaded / total) : undefined,
  1752. bytes: progressBytes,
  1753. rate: rate ? rate : undefined,
  1754. estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
  1755. event: e,
  1756. lengthComputable: total != null
  1757. };
  1758. data[isDownloadStream ? 'download' : 'upload'] = true;
  1759. listener(data);
  1760. }, freq);
  1761. };
  1762. const isURLSameOrigin = platform.hasStandardBrowserEnv ?
  1763. // Standard browser envs have full support of the APIs needed to test
  1764. // whether the request URL is of the same origin as current location.
  1765. (function standardBrowserEnv() {
  1766. const msie = /(msie|trident)/i.test(navigator.userAgent);
  1767. const urlParsingNode = document.createElement('a');
  1768. let originURL;
  1769. /**
  1770. * Parse a URL to discover its components
  1771. *
  1772. * @param {String} url The URL to be parsed
  1773. * @returns {Object}
  1774. */
  1775. function resolveURL(url) {
  1776. let href = url;
  1777. if (msie) {
  1778. // IE needs attribute set twice to normalize properties
  1779. urlParsingNode.setAttribute('href', href);
  1780. href = urlParsingNode.href;
  1781. }
  1782. urlParsingNode.setAttribute('href', href);
  1783. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  1784. return {
  1785. href: urlParsingNode.href,
  1786. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  1787. host: urlParsingNode.host,
  1788. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  1789. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  1790. hostname: urlParsingNode.hostname,
  1791. port: urlParsingNode.port,
  1792. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  1793. urlParsingNode.pathname :
  1794. '/' + urlParsingNode.pathname
  1795. };
  1796. }
  1797. originURL = resolveURL(window.location.href);
  1798. /**
  1799. * Determine if a URL shares the same origin as the current location
  1800. *
  1801. * @param {String} requestURL The URL to test
  1802. * @returns {boolean} True if URL shares the same origin, otherwise false
  1803. */
  1804. return function isURLSameOrigin(requestURL) {
  1805. const parsed = (utils$1.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  1806. return (parsed.protocol === originURL.protocol &&
  1807. parsed.host === originURL.host);
  1808. };
  1809. })() :
  1810. // Non standard browser envs (web workers, react-native) lack needed support.
  1811. (function nonStandardBrowserEnv() {
  1812. return function isURLSameOrigin() {
  1813. return true;
  1814. };
  1815. })();
  1816. const cookies = platform.hasStandardBrowserEnv ?
  1817. // Standard browser envs support document.cookie
  1818. {
  1819. write(name, value, expires, path, domain, secure) {
  1820. const cookie = [name + '=' + encodeURIComponent(value)];
  1821. utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
  1822. utils$1.isString(path) && cookie.push('path=' + path);
  1823. utils$1.isString(domain) && cookie.push('domain=' + domain);
  1824. secure === true && cookie.push('secure');
  1825. document.cookie = cookie.join('; ');
  1826. },
  1827. read(name) {
  1828. const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  1829. return (match ? decodeURIComponent(match[3]) : null);
  1830. },
  1831. remove(name) {
  1832. this.write(name, '', Date.now() - 86400000);
  1833. }
  1834. }
  1835. :
  1836. // Non-standard browser env (web workers, react-native) lack needed support.
  1837. {
  1838. write() {},
  1839. read() {
  1840. return null;
  1841. },
  1842. remove() {}
  1843. };
  1844. /**
  1845. * Determines whether the specified URL is absolute
  1846. *
  1847. * @param {string} url The URL to test
  1848. *
  1849. * @returns {boolean} True if the specified URL is absolute, otherwise false
  1850. */
  1851. function isAbsoluteURL(url) {
  1852. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  1853. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  1854. // by any combination of letters, digits, plus, period, or hyphen.
  1855. return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
  1856. }
  1857. /**
  1858. * Creates a new URL by combining the specified URLs
  1859. *
  1860. * @param {string} baseURL The base URL
  1861. * @param {string} relativeURL The relative URL
  1862. *
  1863. * @returns {string} The combined URL
  1864. */
  1865. function combineURLs(baseURL, relativeURL) {
  1866. return relativeURL
  1867. ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  1868. : baseURL;
  1869. }
  1870. /**
  1871. * Creates a new URL by combining the baseURL with the requestedURL,
  1872. * only when the requestedURL is not already an absolute URL.
  1873. * If the requestURL is absolute, this function returns the requestedURL untouched.
  1874. *
  1875. * @param {string} baseURL The base URL
  1876. * @param {string} requestedURL Absolute or relative URL to combine
  1877. *
  1878. * @returns {string} The combined full path
  1879. */
  1880. function buildFullPath(baseURL, requestedURL) {
  1881. if (baseURL && !isAbsoluteURL(requestedURL)) {
  1882. return combineURLs(baseURL, requestedURL);
  1883. }
  1884. return requestedURL;
  1885. }
  1886. const headersToObject = (thing) => thing instanceof AxiosHeaders$2 ? { ...thing } : thing;
  1887. /**
  1888. * Config-specific merge-function which creates a new config-object
  1889. * by merging two configuration objects together.
  1890. *
  1891. * @param {Object} config1
  1892. * @param {Object} config2
  1893. *
  1894. * @returns {Object} New object resulting from merging config2 to config1
  1895. */
  1896. function mergeConfig$1(config1, config2) {
  1897. // eslint-disable-next-line no-param-reassign
  1898. config2 = config2 || {};
  1899. const config = {};
  1900. function getMergedValue(target, source, caseless) {
  1901. if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
  1902. return utils$1.merge.call({caseless}, target, source);
  1903. } else if (utils$1.isPlainObject(source)) {
  1904. return utils$1.merge({}, source);
  1905. } else if (utils$1.isArray(source)) {
  1906. return source.slice();
  1907. }
  1908. return source;
  1909. }
  1910. // eslint-disable-next-line consistent-return
  1911. function mergeDeepProperties(a, b, caseless) {
  1912. if (!utils$1.isUndefined(b)) {
  1913. return getMergedValue(a, b, caseless);
  1914. } else if (!utils$1.isUndefined(a)) {
  1915. return getMergedValue(undefined, a, caseless);
  1916. }
  1917. }
  1918. // eslint-disable-next-line consistent-return
  1919. function valueFromConfig2(a, b) {
  1920. if (!utils$1.isUndefined(b)) {
  1921. return getMergedValue(undefined, b);
  1922. }
  1923. }
  1924. // eslint-disable-next-line consistent-return
  1925. function defaultToConfig2(a, b) {
  1926. if (!utils$1.isUndefined(b)) {
  1927. return getMergedValue(undefined, b);
  1928. } else if (!utils$1.isUndefined(a)) {
  1929. return getMergedValue(undefined, a);
  1930. }
  1931. }
  1932. // eslint-disable-next-line consistent-return
  1933. function mergeDirectKeys(a, b, prop) {
  1934. if (prop in config2) {
  1935. return getMergedValue(a, b);
  1936. } else if (prop in config1) {
  1937. return getMergedValue(undefined, a);
  1938. }
  1939. }
  1940. const mergeMap = {
  1941. url: valueFromConfig2,
  1942. method: valueFromConfig2,
  1943. data: valueFromConfig2,
  1944. baseURL: defaultToConfig2,
  1945. transformRequest: defaultToConfig2,
  1946. transformResponse: defaultToConfig2,
  1947. paramsSerializer: defaultToConfig2,
  1948. timeout: defaultToConfig2,
  1949. timeoutMessage: defaultToConfig2,
  1950. withCredentials: defaultToConfig2,
  1951. withXSRFToken: defaultToConfig2,
  1952. adapter: defaultToConfig2,
  1953. responseType: defaultToConfig2,
  1954. xsrfCookieName: defaultToConfig2,
  1955. xsrfHeaderName: defaultToConfig2,
  1956. onUploadProgress: defaultToConfig2,
  1957. onDownloadProgress: defaultToConfig2,
  1958. decompress: defaultToConfig2,
  1959. maxContentLength: defaultToConfig2,
  1960. maxBodyLength: defaultToConfig2,
  1961. beforeRedirect: defaultToConfig2,
  1962. transport: defaultToConfig2,
  1963. httpAgent: defaultToConfig2,
  1964. httpsAgent: defaultToConfig2,
  1965. cancelToken: defaultToConfig2,
  1966. socketPath: defaultToConfig2,
  1967. responseEncoding: defaultToConfig2,
  1968. validateStatus: mergeDirectKeys,
  1969. headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
  1970. };
  1971. utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
  1972. const merge = mergeMap[prop] || mergeDeepProperties;
  1973. const configValue = merge(config1[prop], config2[prop], prop);
  1974. (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
  1975. });
  1976. return config;
  1977. }
  1978. const resolveConfig = (config) => {
  1979. const newConfig = mergeConfig$1({}, config);
  1980. let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
  1981. newConfig.headers = headers = AxiosHeaders$2.from(headers);
  1982. newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
  1983. // HTTP basic authentication
  1984. if (auth) {
  1985. headers.set('Authorization', 'Basic ' +
  1986. btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
  1987. );
  1988. }
  1989. let contentType;
  1990. if (utils$1.isFormData(data)) {
  1991. if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
  1992. headers.setContentType(undefined); // Let the browser set it
  1993. } else if ((contentType = headers.getContentType()) !== false) {
  1994. // fix semicolon duplication issue for ReactNative FormData implementation
  1995. const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
  1996. headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
  1997. }
  1998. }
  1999. // Add xsrf header
  2000. // This is only done if running in a standard browser environment.
  2001. // Specifically not if we're in a web worker, or react-native.
  2002. if (platform.hasStandardBrowserEnv) {
  2003. withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
  2004. if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
  2005. // Add xsrf header
  2006. const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
  2007. if (xsrfValue) {
  2008. headers.set(xsrfHeaderName, xsrfValue);
  2009. }
  2010. }
  2011. }
  2012. return newConfig;
  2013. };
  2014. const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
  2015. const xhrAdapter = isXHRAdapterSupported && function (config) {
  2016. return new Promise(function dispatchXhrRequest(resolve, reject) {
  2017. const _config = resolveConfig(config);
  2018. let requestData = _config.data;
  2019. const requestHeaders = AxiosHeaders$2.from(_config.headers).normalize();
  2020. let {responseType} = _config;
  2021. let onCanceled;
  2022. function done() {
  2023. if (_config.cancelToken) {
  2024. _config.cancelToken.unsubscribe(onCanceled);
  2025. }
  2026. if (_config.signal) {
  2027. _config.signal.removeEventListener('abort', onCanceled);
  2028. }
  2029. }
  2030. let request = new XMLHttpRequest();
  2031. request.open(_config.method.toUpperCase(), _config.url, true);
  2032. // Set the request timeout in MS
  2033. request.timeout = _config.timeout;
  2034. function onloadend() {
  2035. if (!request) {
  2036. return;
  2037. }
  2038. // Prepare the response
  2039. const responseHeaders = AxiosHeaders$2.from(
  2040. 'getAllResponseHeaders' in request && request.getAllResponseHeaders()
  2041. );
  2042. const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
  2043. request.responseText : request.response;
  2044. const response = {
  2045. data: responseData,
  2046. status: request.status,
  2047. statusText: request.statusText,
  2048. headers: responseHeaders,
  2049. config,
  2050. request
  2051. };
  2052. settle(function _resolve(value) {
  2053. resolve(value);
  2054. done();
  2055. }, function _reject(err) {
  2056. reject(err);
  2057. done();
  2058. }, response);
  2059. // Clean up request
  2060. request = null;
  2061. }
  2062. if ('onloadend' in request) {
  2063. // Use onloadend if available
  2064. request.onloadend = onloadend;
  2065. } else {
  2066. // Listen for ready state to emulate onloadend
  2067. request.onreadystatechange = function handleLoad() {
  2068. if (!request || request.readyState !== 4) {
  2069. return;
  2070. }
  2071. // The request errored out and we didn't get a response, this will be
  2072. // handled by onerror instead
  2073. // With one exception: request that using file: protocol, most browsers
  2074. // will return status as 0 even though it's a successful request
  2075. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  2076. return;
  2077. }
  2078. // readystate handler is calling before onerror or ontimeout handlers,
  2079. // so we should call onloadend on the next 'tick'
  2080. setTimeout(onloadend);
  2081. };
  2082. }
  2083. // Handle browser request cancellation (as opposed to a manual cancellation)
  2084. request.onabort = function handleAbort() {
  2085. if (!request) {
  2086. return;
  2087. }
  2088. reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, _config, request));
  2089. // Clean up request
  2090. request = null;
  2091. };
  2092. // Handle low level network errors
  2093. request.onerror = function handleError() {
  2094. // Real errors are hidden from us by the browser
  2095. // onerror should only fire if it's a network error
  2096. reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, _config, request));
  2097. // Clean up request
  2098. request = null;
  2099. };
  2100. // Handle timeout
  2101. request.ontimeout = function handleTimeout() {
  2102. let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
  2103. const transitional = _config.transitional || transitionalDefaults;
  2104. if (_config.timeoutErrorMessage) {
  2105. timeoutErrorMessage = _config.timeoutErrorMessage;
  2106. }
  2107. reject(new AxiosError$1(
  2108. timeoutErrorMessage,
  2109. transitional.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
  2110. _config,
  2111. request));
  2112. // Clean up request
  2113. request = null;
  2114. };
  2115. // Remove Content-Type if data is undefined
  2116. requestData === undefined && requestHeaders.setContentType(null);
  2117. // Add headers to the request
  2118. if ('setRequestHeader' in request) {
  2119. utils$1.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
  2120. request.setRequestHeader(key, val);
  2121. });
  2122. }
  2123. // Add withCredentials to request if needed
  2124. if (!utils$1.isUndefined(_config.withCredentials)) {
  2125. request.withCredentials = !!_config.withCredentials;
  2126. }
  2127. // Add responseType to request if needed
  2128. if (responseType && responseType !== 'json') {
  2129. request.responseType = _config.responseType;
  2130. }
  2131. // Handle progress if needed
  2132. if (typeof _config.onDownloadProgress === 'function') {
  2133. request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
  2134. }
  2135. // Not all browsers support upload events
  2136. if (typeof _config.onUploadProgress === 'function' && request.upload) {
  2137. request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
  2138. }
  2139. if (_config.cancelToken || _config.signal) {
  2140. // Handle cancellation
  2141. // eslint-disable-next-line func-names
  2142. onCanceled = cancel => {
  2143. if (!request) {
  2144. return;
  2145. }
  2146. reject(!cancel || cancel.type ? new CanceledError$1(null, config, request) : cancel);
  2147. request.abort();
  2148. request = null;
  2149. };
  2150. _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
  2151. if (_config.signal) {
  2152. _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
  2153. }
  2154. }
  2155. const protocol = parseProtocol(_config.url);
  2156. if (protocol && platform.protocols.indexOf(protocol) === -1) {
  2157. reject(new AxiosError$1('Unsupported protocol ' + protocol + ':', AxiosError$1.ERR_BAD_REQUEST, config));
  2158. return;
  2159. }
  2160. // Send the request
  2161. request.send(requestData || null);
  2162. });
  2163. };
  2164. const composeSignals = (signals, timeout) => {
  2165. let controller = new AbortController();
  2166. let aborted;
  2167. const onabort = function (cancel) {
  2168. if (!aborted) {
  2169. aborted = true;
  2170. unsubscribe();
  2171. const err = cancel instanceof Error ? cancel : this.reason;
  2172. controller.abort(err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err));
  2173. }
  2174. };
  2175. let timer = timeout && setTimeout(() => {
  2176. onabort(new AxiosError$1(`timeout ${timeout} of ms exceeded`, AxiosError$1.ETIMEDOUT));
  2177. }, timeout);
  2178. const unsubscribe = () => {
  2179. if (signals) {
  2180. timer && clearTimeout(timer);
  2181. timer = null;
  2182. signals.forEach(signal => {
  2183. signal &&
  2184. (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
  2185. });
  2186. signals = null;
  2187. }
  2188. };
  2189. signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
  2190. const {signal} = controller;
  2191. signal.unsubscribe = unsubscribe;
  2192. return [signal, () => {
  2193. timer && clearTimeout(timer);
  2194. timer = null;
  2195. }];
  2196. };
  2197. const composeSignals$1 = composeSignals;
  2198. const streamChunk = function* (chunk, chunkSize) {
  2199. let len = chunk.byteLength;
  2200. if (!chunkSize || len < chunkSize) {
  2201. yield chunk;
  2202. return;
  2203. }
  2204. let pos = 0;
  2205. let end;
  2206. while (pos < len) {
  2207. end = pos + chunkSize;
  2208. yield chunk.slice(pos, end);
  2209. pos = end;
  2210. }
  2211. };
  2212. const readBytes = async function* (iterable, chunkSize, encode) {
  2213. for await (const chunk of iterable) {
  2214. yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
  2215. }
  2216. };
  2217. const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
  2218. const iterator = readBytes(stream, chunkSize, encode);
  2219. let bytes = 0;
  2220. return new ReadableStream({
  2221. type: 'bytes',
  2222. async pull(controller) {
  2223. const {done, value} = await iterator.next();
  2224. if (done) {
  2225. controller.close();
  2226. onFinish();
  2227. return;
  2228. }
  2229. let len = value.byteLength;
  2230. onProgress && onProgress(bytes += len);
  2231. controller.enqueue(new Uint8Array(value));
  2232. },
  2233. cancel(reason) {
  2234. onFinish(reason);
  2235. return iterator.return();
  2236. }
  2237. }, {
  2238. highWaterMark: 2
  2239. })
  2240. };
  2241. const fetchProgressDecorator = (total, fn) => {
  2242. const lengthComputable = total != null;
  2243. return (loaded) => setTimeout(() => fn({
  2244. lengthComputable,
  2245. total,
  2246. loaded
  2247. }));
  2248. };
  2249. const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
  2250. const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
  2251. // used only inside the fetch adapter
  2252. const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
  2253. ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
  2254. async (str) => new Uint8Array(await new Response(str).arrayBuffer())
  2255. );
  2256. const supportsRequestStream = isReadableStreamSupported && (() => {
  2257. let duplexAccessed = false;
  2258. const hasContentType = new Request(platform.origin, {
  2259. body: new ReadableStream(),
  2260. method: 'POST',
  2261. get duplex() {
  2262. duplexAccessed = true;
  2263. return 'half';
  2264. },
  2265. }).headers.has('Content-Type');
  2266. return duplexAccessed && !hasContentType;
  2267. })();
  2268. const DEFAULT_CHUNK_SIZE = 64 * 1024;
  2269. const supportsResponseStream = isReadableStreamSupported && !!(()=> {
  2270. try {
  2271. return utils$1.isReadableStream(new Response('').body);
  2272. } catch(err) {
  2273. // return undefined
  2274. }
  2275. })();
  2276. const resolvers = {
  2277. stream: supportsResponseStream && ((res) => res.body)
  2278. };
  2279. isFetchSupported && (((res) => {
  2280. ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
  2281. !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
  2282. (_, config) => {
  2283. throw new AxiosError$1(`Response type '${type}' is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
  2284. });
  2285. });
  2286. })(new Response));
  2287. const getBodyLength = async (body) => {
  2288. if (body == null) {
  2289. return 0;
  2290. }
  2291. if(utils$1.isBlob(body)) {
  2292. return body.size;
  2293. }
  2294. if(utils$1.isSpecCompliantForm(body)) {
  2295. return (await new Request(body).arrayBuffer()).byteLength;
  2296. }
  2297. if(utils$1.isArrayBufferView(body)) {
  2298. return body.byteLength;
  2299. }
  2300. if(utils$1.isURLSearchParams(body)) {
  2301. body = body + '';
  2302. }
  2303. if(utils$1.isString(body)) {
  2304. return (await encodeText(body)).byteLength;
  2305. }
  2306. };
  2307. const resolveBodyLength = async (headers, body) => {
  2308. const length = utils$1.toFiniteNumber(headers.getContentLength());
  2309. return length == null ? getBodyLength(body) : length;
  2310. };
  2311. const fetchAdapter = isFetchSupported && (async (config) => {
  2312. let {
  2313. url,
  2314. method,
  2315. data,
  2316. signal,
  2317. cancelToken,
  2318. timeout,
  2319. onDownloadProgress,
  2320. onUploadProgress,
  2321. responseType,
  2322. headers,
  2323. withCredentials = 'same-origin',
  2324. fetchOptions
  2325. } = resolveConfig(config);
  2326. responseType = responseType ? (responseType + '').toLowerCase() : 'text';
  2327. let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
  2328. composeSignals$1([signal, cancelToken], timeout) : [];
  2329. let finished, request;
  2330. const onFinish = () => {
  2331. !finished && setTimeout(() => {
  2332. composedSignal && composedSignal.unsubscribe();
  2333. });
  2334. finished = true;
  2335. };
  2336. let requestContentLength;
  2337. try {
  2338. if (
  2339. onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
  2340. (requestContentLength = await resolveBodyLength(headers, data)) !== 0
  2341. ) {
  2342. let _request = new Request(url, {
  2343. method: 'POST',
  2344. body: data,
  2345. duplex: "half"
  2346. });
  2347. let contentTypeHeader;
  2348. if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
  2349. headers.setContentType(contentTypeHeader);
  2350. }
  2351. if (_request.body) {
  2352. data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
  2353. requestContentLength,
  2354. progressEventReducer(onUploadProgress)
  2355. ), null, encodeText);
  2356. }
  2357. }
  2358. if (!utils$1.isString(withCredentials)) {
  2359. withCredentials = withCredentials ? 'cors' : 'omit';
  2360. }
  2361. request = new Request(url, {
  2362. ...fetchOptions,
  2363. signal: composedSignal,
  2364. method: method.toUpperCase(),
  2365. headers: headers.normalize().toJSON(),
  2366. body: data,
  2367. duplex: "half",
  2368. withCredentials
  2369. });
  2370. let response = await fetch(request);
  2371. const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
  2372. if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
  2373. const options = {};
  2374. ['status', 'statusText', 'headers'].forEach(prop => {
  2375. options[prop] = response[prop];
  2376. });
  2377. const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
  2378. response = new Response(
  2379. trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(
  2380. responseContentLength,
  2381. progressEventReducer(onDownloadProgress, true)
  2382. ), isStreamResponse && onFinish, encodeText),
  2383. options
  2384. );
  2385. }
  2386. responseType = responseType || 'text';
  2387. let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
  2388. !isStreamResponse && onFinish();
  2389. stopTimeout && stopTimeout();
  2390. return await new Promise((resolve, reject) => {
  2391. settle(resolve, reject, {
  2392. data: responseData,
  2393. headers: AxiosHeaders$2.from(response.headers),
  2394. status: response.status,
  2395. statusText: response.statusText,
  2396. config,
  2397. request
  2398. });
  2399. })
  2400. } catch (err) {
  2401. onFinish();
  2402. if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
  2403. throw Object.assign(
  2404. new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request),
  2405. {
  2406. cause: err.cause || err
  2407. }
  2408. )
  2409. }
  2410. throw AxiosError$1.from(err, err && err.code, config, request);
  2411. }
  2412. });
  2413. const knownAdapters = {
  2414. http: httpAdapter,
  2415. xhr: xhrAdapter,
  2416. fetch: fetchAdapter
  2417. };
  2418. utils$1.forEach(knownAdapters, (fn, value) => {
  2419. if (fn) {
  2420. try {
  2421. Object.defineProperty(fn, 'name', {value});
  2422. } catch (e) {
  2423. // eslint-disable-next-line no-empty
  2424. }
  2425. Object.defineProperty(fn, 'adapterName', {value});
  2426. }
  2427. });
  2428. const renderReason = (reason) => `- ${reason}`;
  2429. const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
  2430. const adapters = {
  2431. getAdapter: (adapters) => {
  2432. adapters = utils$1.isArray(adapters) ? adapters : [adapters];
  2433. const {length} = adapters;
  2434. let nameOrAdapter;
  2435. let adapter;
  2436. const rejectedReasons = {};
  2437. for (let i = 0; i < length; i++) {
  2438. nameOrAdapter = adapters[i];
  2439. let id;
  2440. adapter = nameOrAdapter;
  2441. if (!isResolvedHandle(nameOrAdapter)) {
  2442. adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
  2443. if (adapter === undefined) {
  2444. throw new AxiosError$1(`Unknown adapter '${id}'`);
  2445. }
  2446. }
  2447. if (adapter) {
  2448. break;
  2449. }
  2450. rejectedReasons[id || '#' + i] = adapter;
  2451. }
  2452. if (!adapter) {
  2453. const reasons = Object.entries(rejectedReasons)
  2454. .map(([id, state]) => `adapter ${id} ` +
  2455. (state === false ? 'is not supported by the environment' : 'is not available in the build')
  2456. );
  2457. let s = length ?
  2458. (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
  2459. 'as no adapter specified';
  2460. throw new AxiosError$1(
  2461. `There is no suitable adapter to dispatch the request ` + s,
  2462. 'ERR_NOT_SUPPORT'
  2463. );
  2464. }
  2465. return adapter;
  2466. },
  2467. adapters: knownAdapters
  2468. };
  2469. /**
  2470. * Throws a `CanceledError` if cancellation has been requested.
  2471. *
  2472. * @param {Object} config The config that is to be used for the request
  2473. *
  2474. * @returns {void}
  2475. */
  2476. function throwIfCancellationRequested(config) {
  2477. if (config.cancelToken) {
  2478. config.cancelToken.throwIfRequested();
  2479. }
  2480. if (config.signal && config.signal.aborted) {
  2481. throw new CanceledError$1(null, config);
  2482. }
  2483. }
  2484. /**
  2485. * Dispatch a request to the server using the configured adapter.
  2486. *
  2487. * @param {object} config The config that is to be used for the request
  2488. *
  2489. * @returns {Promise} The Promise to be fulfilled
  2490. */
  2491. function dispatchRequest(config) {
  2492. throwIfCancellationRequested(config);
  2493. config.headers = AxiosHeaders$2.from(config.headers);
  2494. // Transform request data
  2495. config.data = transformData.call(
  2496. config,
  2497. config.transformRequest
  2498. );
  2499. if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
  2500. config.headers.setContentType('application/x-www-form-urlencoded', false);
  2501. }
  2502. const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
  2503. return adapter(config).then(function onAdapterResolution(response) {
  2504. throwIfCancellationRequested(config);
  2505. // Transform response data
  2506. response.data = transformData.call(
  2507. config,
  2508. config.transformResponse,
  2509. response
  2510. );
  2511. response.headers = AxiosHeaders$2.from(response.headers);
  2512. return response;
  2513. }, function onAdapterRejection(reason) {
  2514. if (!isCancel$1(reason)) {
  2515. throwIfCancellationRequested(config);
  2516. // Transform response data
  2517. if (reason && reason.response) {
  2518. reason.response.data = transformData.call(
  2519. config,
  2520. config.transformResponse,
  2521. reason.response
  2522. );
  2523. reason.response.headers = AxiosHeaders$2.from(reason.response.headers);
  2524. }
  2525. }
  2526. return Promise.reject(reason);
  2527. });
  2528. }
  2529. const VERSION$1 = "1.7.2";
  2530. const validators$1 = {};
  2531. // eslint-disable-next-line func-names
  2532. ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
  2533. validators$1[type] = function validator(thing) {
  2534. return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
  2535. };
  2536. });
  2537. const deprecatedWarnings = {};
  2538. /**
  2539. * Transitional option validator
  2540. *
  2541. * @param {function|boolean?} validator - set to false if the transitional option has been removed
  2542. * @param {string?} version - deprecated version / removed since version
  2543. * @param {string?} message - some message with additional info
  2544. *
  2545. * @returns {function}
  2546. */
  2547. validators$1.transitional = function transitional(validator, version, message) {
  2548. function formatMessage(opt, desc) {
  2549. return '[Axios v' + VERSION$1 + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
  2550. }
  2551. // eslint-disable-next-line func-names
  2552. return (value, opt, opts) => {
  2553. if (validator === false) {
  2554. throw new AxiosError$1(
  2555. formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
  2556. AxiosError$1.ERR_DEPRECATED
  2557. );
  2558. }
  2559. if (version && !deprecatedWarnings[opt]) {
  2560. deprecatedWarnings[opt] = true;
  2561. // eslint-disable-next-line no-console
  2562. console.warn(
  2563. formatMessage(
  2564. opt,
  2565. ' has been deprecated since v' + version + ' and will be removed in the near future'
  2566. )
  2567. );
  2568. }
  2569. return validator ? validator(value, opt, opts) : true;
  2570. };
  2571. };
  2572. /**
  2573. * Assert object's properties type
  2574. *
  2575. * @param {object} options
  2576. * @param {object} schema
  2577. * @param {boolean?} allowUnknown
  2578. *
  2579. * @returns {object}
  2580. */
  2581. function assertOptions(options, schema, allowUnknown) {
  2582. if (typeof options !== 'object') {
  2583. throw new AxiosError$1('options must be an object', AxiosError$1.ERR_BAD_OPTION_VALUE);
  2584. }
  2585. const keys = Object.keys(options);
  2586. let i = keys.length;
  2587. while (i-- > 0) {
  2588. const opt = keys[i];
  2589. const validator = schema[opt];
  2590. if (validator) {
  2591. const value = options[opt];
  2592. const result = value === undefined || validator(value, opt, options);
  2593. if (result !== true) {
  2594. throw new AxiosError$1('option ' + opt + ' must be ' + result, AxiosError$1.ERR_BAD_OPTION_VALUE);
  2595. }
  2596. continue;
  2597. }
  2598. if (allowUnknown !== true) {
  2599. throw new AxiosError$1('Unknown option ' + opt, AxiosError$1.ERR_BAD_OPTION);
  2600. }
  2601. }
  2602. }
  2603. const validator = {
  2604. assertOptions,
  2605. validators: validators$1
  2606. };
  2607. const validators = validator.validators;
  2608. /**
  2609. * Create a new instance of Axios
  2610. *
  2611. * @param {Object} instanceConfig The default config for the instance
  2612. *
  2613. * @return {Axios} A new instance of Axios
  2614. */
  2615. class Axios$1 {
  2616. constructor(instanceConfig) {
  2617. this.defaults = instanceConfig;
  2618. this.interceptors = {
  2619. request: new InterceptorManager$1(),
  2620. response: new InterceptorManager$1()
  2621. };
  2622. }
  2623. /**
  2624. * Dispatch a request
  2625. *
  2626. * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
  2627. * @param {?Object} config
  2628. *
  2629. * @returns {Promise} The Promise to be fulfilled
  2630. */
  2631. async request(configOrUrl, config) {
  2632. try {
  2633. return await this._request(configOrUrl, config);
  2634. } catch (err) {
  2635. if (err instanceof Error) {
  2636. let dummy;
  2637. Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
  2638. // slice off the Error: ... line
  2639. const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
  2640. try {
  2641. if (!err.stack) {
  2642. err.stack = stack;
  2643. // match without the 2 top stack lines
  2644. } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
  2645. err.stack += '\n' + stack;
  2646. }
  2647. } catch (e) {
  2648. // ignore the case where "stack" is an un-writable property
  2649. }
  2650. }
  2651. throw err;
  2652. }
  2653. }
  2654. _request(configOrUrl, config) {
  2655. /*eslint no-param-reassign:0*/
  2656. // Allow for axios('example/url'[, config]) a la fetch API
  2657. if (typeof configOrUrl === 'string') {
  2658. config = config || {};
  2659. config.url = configOrUrl;
  2660. } else {
  2661. config = configOrUrl || {};
  2662. }
  2663. config = mergeConfig$1(this.defaults, config);
  2664. const {transitional, paramsSerializer, headers} = config;
  2665. if (transitional !== undefined) {
  2666. validator.assertOptions(transitional, {
  2667. silentJSONParsing: validators.transitional(validators.boolean),
  2668. forcedJSONParsing: validators.transitional(validators.boolean),
  2669. clarifyTimeoutError: validators.transitional(validators.boolean)
  2670. }, false);
  2671. }
  2672. if (paramsSerializer != null) {
  2673. if (utils$1.isFunction(paramsSerializer)) {
  2674. config.paramsSerializer = {
  2675. serialize: paramsSerializer
  2676. };
  2677. } else {
  2678. validator.assertOptions(paramsSerializer, {
  2679. encode: validators.function,
  2680. serialize: validators.function
  2681. }, true);
  2682. }
  2683. }
  2684. // Set config.method
  2685. config.method = (config.method || this.defaults.method || 'get').toLowerCase();
  2686. // Flatten headers
  2687. let contextHeaders = headers && utils$1.merge(
  2688. headers.common,
  2689. headers[config.method]
  2690. );
  2691. headers && utils$1.forEach(
  2692. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  2693. (method) => {
  2694. delete headers[method];
  2695. }
  2696. );
  2697. config.headers = AxiosHeaders$2.concat(contextHeaders, headers);
  2698. // filter out skipped interceptors
  2699. const requestInterceptorChain = [];
  2700. let synchronousRequestInterceptors = true;
  2701. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  2702. if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
  2703. return;
  2704. }
  2705. synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
  2706. requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
  2707. });
  2708. const responseInterceptorChain = [];
  2709. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  2710. responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
  2711. });
  2712. let promise;
  2713. let i = 0;
  2714. let len;
  2715. if (!synchronousRequestInterceptors) {
  2716. const chain = [dispatchRequest.bind(this), undefined];
  2717. chain.unshift.apply(chain, requestInterceptorChain);
  2718. chain.push.apply(chain, responseInterceptorChain);
  2719. len = chain.length;
  2720. promise = Promise.resolve(config);
  2721. while (i < len) {
  2722. promise = promise.then(chain[i++], chain[i++]);
  2723. }
  2724. return promise;
  2725. }
  2726. len = requestInterceptorChain.length;
  2727. let newConfig = config;
  2728. i = 0;
  2729. while (i < len) {
  2730. const onFulfilled = requestInterceptorChain[i++];
  2731. const onRejected = requestInterceptorChain[i++];
  2732. try {
  2733. newConfig = onFulfilled(newConfig);
  2734. } catch (error) {
  2735. onRejected.call(this, error);
  2736. break;
  2737. }
  2738. }
  2739. try {
  2740. promise = dispatchRequest.call(this, newConfig);
  2741. } catch (error) {
  2742. return Promise.reject(error);
  2743. }
  2744. i = 0;
  2745. len = responseInterceptorChain.length;
  2746. while (i < len) {
  2747. promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
  2748. }
  2749. return promise;
  2750. }
  2751. getUri(config) {
  2752. config = mergeConfig$1(this.defaults, config);
  2753. const fullPath = buildFullPath(config.baseURL, config.url);
  2754. return buildURL(fullPath, config.params, config.paramsSerializer);
  2755. }
  2756. }
  2757. // Provide aliases for supported request methods
  2758. utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  2759. /*eslint func-names:0*/
  2760. Axios$1.prototype[method] = function(url, config) {
  2761. return this.request(mergeConfig$1(config || {}, {
  2762. method,
  2763. url,
  2764. data: (config || {}).data
  2765. }));
  2766. };
  2767. });
  2768. utils$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  2769. /*eslint func-names:0*/
  2770. function generateHTTPMethod(isForm) {
  2771. return function httpMethod(url, data, config) {
  2772. return this.request(mergeConfig$1(config || {}, {
  2773. method,
  2774. headers: isForm ? {
  2775. 'Content-Type': 'multipart/form-data'
  2776. } : {},
  2777. url,
  2778. data
  2779. }));
  2780. };
  2781. }
  2782. Axios$1.prototype[method] = generateHTTPMethod();
  2783. Axios$1.prototype[method + 'Form'] = generateHTTPMethod(true);
  2784. });
  2785. const Axios$2 = Axios$1;
  2786. /**
  2787. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  2788. *
  2789. * @param {Function} executor The executor function.
  2790. *
  2791. * @returns {CancelToken}
  2792. */
  2793. class CancelToken$1 {
  2794. constructor(executor) {
  2795. if (typeof executor !== 'function') {
  2796. throw new TypeError('executor must be a function.');
  2797. }
  2798. let resolvePromise;
  2799. this.promise = new Promise(function promiseExecutor(resolve) {
  2800. resolvePromise = resolve;
  2801. });
  2802. const token = this;
  2803. // eslint-disable-next-line func-names
  2804. this.promise.then(cancel => {
  2805. if (!token._listeners) return;
  2806. let i = token._listeners.length;
  2807. while (i-- > 0) {
  2808. token._listeners[i](cancel);
  2809. }
  2810. token._listeners = null;
  2811. });
  2812. // eslint-disable-next-line func-names
  2813. this.promise.then = onfulfilled => {
  2814. let _resolve;
  2815. // eslint-disable-next-line func-names
  2816. const promise = new Promise(resolve => {
  2817. token.subscribe(resolve);
  2818. _resolve = resolve;
  2819. }).then(onfulfilled);
  2820. promise.cancel = function reject() {
  2821. token.unsubscribe(_resolve);
  2822. };
  2823. return promise;
  2824. };
  2825. executor(function cancel(message, config, request) {
  2826. if (token.reason) {
  2827. // Cancellation has already been requested
  2828. return;
  2829. }
  2830. token.reason = new CanceledError$1(message, config, request);
  2831. resolvePromise(token.reason);
  2832. });
  2833. }
  2834. /**
  2835. * Throws a `CanceledError` if cancellation has been requested.
  2836. */
  2837. throwIfRequested() {
  2838. if (this.reason) {
  2839. throw this.reason;
  2840. }
  2841. }
  2842. /**
  2843. * Subscribe to the cancel signal
  2844. */
  2845. subscribe(listener) {
  2846. if (this.reason) {
  2847. listener(this.reason);
  2848. return;
  2849. }
  2850. if (this._listeners) {
  2851. this._listeners.push(listener);
  2852. } else {
  2853. this._listeners = [listener];
  2854. }
  2855. }
  2856. /**
  2857. * Unsubscribe from the cancel signal
  2858. */
  2859. unsubscribe(listener) {
  2860. if (!this._listeners) {
  2861. return;
  2862. }
  2863. const index = this._listeners.indexOf(listener);
  2864. if (index !== -1) {
  2865. this._listeners.splice(index, 1);
  2866. }
  2867. }
  2868. /**
  2869. * Returns an object that contains a new `CancelToken` and a function that, when called,
  2870. * cancels the `CancelToken`.
  2871. */
  2872. static source() {
  2873. let cancel;
  2874. const token = new CancelToken$1(function executor(c) {
  2875. cancel = c;
  2876. });
  2877. return {
  2878. token,
  2879. cancel
  2880. };
  2881. }
  2882. }
  2883. const CancelToken$2 = CancelToken$1;
  2884. /**
  2885. * Syntactic sugar for invoking a function and expanding an array for arguments.
  2886. *
  2887. * Common use case would be to use `Function.prototype.apply`.
  2888. *
  2889. * ```js
  2890. * function f(x, y, z) {}
  2891. * var args = [1, 2, 3];
  2892. * f.apply(null, args);
  2893. * ```
  2894. *
  2895. * With `spread` this example can be re-written.
  2896. *
  2897. * ```js
  2898. * spread(function(x, y, z) {})([1, 2, 3]);
  2899. * ```
  2900. *
  2901. * @param {Function} callback
  2902. *
  2903. * @returns {Function}
  2904. */
  2905. function spread$1(callback) {
  2906. return function wrap(arr) {
  2907. return callback.apply(null, arr);
  2908. };
  2909. }
  2910. /**
  2911. * Determines whether the payload is an error thrown by Axios
  2912. *
  2913. * @param {*} payload The value to test
  2914. *
  2915. * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
  2916. */
  2917. function isAxiosError$1(payload) {
  2918. return utils$1.isObject(payload) && (payload.isAxiosError === true);
  2919. }
  2920. const HttpStatusCode$1 = {
  2921. Continue: 100,
  2922. SwitchingProtocols: 101,
  2923. Processing: 102,
  2924. EarlyHints: 103,
  2925. Ok: 200,
  2926. Created: 201,
  2927. Accepted: 202,
  2928. NonAuthoritativeInformation: 203,
  2929. NoContent: 204,
  2930. ResetContent: 205,
  2931. PartialContent: 206,
  2932. MultiStatus: 207,
  2933. AlreadyReported: 208,
  2934. ImUsed: 226,
  2935. MultipleChoices: 300,
  2936. MovedPermanently: 301,
  2937. Found: 302,
  2938. SeeOther: 303,
  2939. NotModified: 304,
  2940. UseProxy: 305,
  2941. Unused: 306,
  2942. TemporaryRedirect: 307,
  2943. PermanentRedirect: 308,
  2944. BadRequest: 400,
  2945. Unauthorized: 401,
  2946. PaymentRequired: 402,
  2947. Forbidden: 403,
  2948. NotFound: 404,
  2949. MethodNotAllowed: 405,
  2950. NotAcceptable: 406,
  2951. ProxyAuthenticationRequired: 407,
  2952. RequestTimeout: 408,
  2953. Conflict: 409,
  2954. Gone: 410,
  2955. LengthRequired: 411,
  2956. PreconditionFailed: 412,
  2957. PayloadTooLarge: 413,
  2958. UriTooLong: 414,
  2959. UnsupportedMediaType: 415,
  2960. RangeNotSatisfiable: 416,
  2961. ExpectationFailed: 417,
  2962. ImATeapot: 418,
  2963. MisdirectedRequest: 421,
  2964. UnprocessableEntity: 422,
  2965. Locked: 423,
  2966. FailedDependency: 424,
  2967. TooEarly: 425,
  2968. UpgradeRequired: 426,
  2969. PreconditionRequired: 428,
  2970. TooManyRequests: 429,
  2971. RequestHeaderFieldsTooLarge: 431,
  2972. UnavailableForLegalReasons: 451,
  2973. InternalServerError: 500,
  2974. NotImplemented: 501,
  2975. BadGateway: 502,
  2976. ServiceUnavailable: 503,
  2977. GatewayTimeout: 504,
  2978. HttpVersionNotSupported: 505,
  2979. VariantAlsoNegotiates: 506,
  2980. InsufficientStorage: 507,
  2981. LoopDetected: 508,
  2982. NotExtended: 510,
  2983. NetworkAuthenticationRequired: 511,
  2984. };
  2985. Object.entries(HttpStatusCode$1).forEach(([key, value]) => {
  2986. HttpStatusCode$1[value] = key;
  2987. });
  2988. const HttpStatusCode$2 = HttpStatusCode$1;
  2989. /**
  2990. * Create an instance of Axios
  2991. *
  2992. * @param {Object} defaultConfig The default config for the instance
  2993. *
  2994. * @returns {Axios} A new instance of Axios
  2995. */
  2996. function createInstance(defaultConfig) {
  2997. const context = new Axios$2(defaultConfig);
  2998. const instance = bind(Axios$2.prototype.request, context);
  2999. // Copy axios.prototype to instance
  3000. utils$1.extend(instance, Axios$2.prototype, context, {allOwnKeys: true});
  3001. // Copy context to instance
  3002. utils$1.extend(instance, context, null, {allOwnKeys: true});
  3003. // Factory for creating new instances
  3004. instance.create = function create(instanceConfig) {
  3005. return createInstance(mergeConfig$1(defaultConfig, instanceConfig));
  3006. };
  3007. return instance;
  3008. }
  3009. // Create the default instance to be exported
  3010. const axios = createInstance(defaults$1);
  3011. // Expose Axios class to allow class inheritance
  3012. axios.Axios = Axios$2;
  3013. // Expose Cancel & CancelToken
  3014. axios.CanceledError = CanceledError$1;
  3015. axios.CancelToken = CancelToken$2;
  3016. axios.isCancel = isCancel$1;
  3017. axios.VERSION = VERSION$1;
  3018. axios.toFormData = toFormData$1;
  3019. // Expose AxiosError class
  3020. axios.AxiosError = AxiosError$1;
  3021. // alias for CanceledError for backward compatibility
  3022. axios.Cancel = axios.CanceledError;
  3023. // Expose all/spread
  3024. axios.all = function all(promises) {
  3025. return Promise.all(promises);
  3026. };
  3027. axios.spread = spread$1;
  3028. // Expose isAxiosError
  3029. axios.isAxiosError = isAxiosError$1;
  3030. // Expose mergeConfig
  3031. axios.mergeConfig = mergeConfig$1;
  3032. axios.AxiosHeaders = AxiosHeaders$2;
  3033. axios.formToJSON = thing => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
  3034. axios.getAdapter = adapters.getAdapter;
  3035. axios.HttpStatusCode = HttpStatusCode$2;
  3036. axios.default = axios;
  3037. // this module should only have a default export
  3038. const axios$1 = axios;
  3039. // This module is intended to unwrap Axios default export as named.
  3040. // Keep top-level export same with static properties
  3041. // so that it can keep same with es module or cjs
  3042. const {
  3043. Axios,
  3044. AxiosError,
  3045. CanceledError,
  3046. isCancel,
  3047. CancelToken,
  3048. VERSION,
  3049. all,
  3050. Cancel,
  3051. isAxiosError,
  3052. spread,
  3053. toFormData,
  3054. AxiosHeaders,
  3055. HttpStatusCode,
  3056. formToJSON,
  3057. getAdapter,
  3058. mergeConfig
  3059. } = axios$1;
  3060. export { Axios, AxiosError, AxiosHeaders, Cancel, CancelToken, CanceledError, HttpStatusCode, VERSION, all, axios$1 as default, formToJSON, getAdapter, isAxiosError, isCancel, mergeConfig, spread, toFormData };
  3061. //# sourceMappingURL=axios.js.map