axios.js 95 KB

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