axios.cjs 108 KB

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