axios.cjs 95 KB

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