axios.cjs 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338
  1. /*! Axios v1.15.2 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. if (!thing) return false;
  243. if (FormDataCtor && thing instanceof FormDataCtor) return true;
  244. // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData (GHSA-6chq-wfr3-2hj9).
  245. const proto = getPrototypeOf(thing);
  246. if (!proto || proto === Object.prototype) return false;
  247. if (!isFunction$1(thing.append)) return false;
  248. const kind = kindOf(thing);
  249. return kind === 'formdata' ||
  250. // detect form-data instance
  251. (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]');
  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. AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
  908. // eslint-disable-next-line strict
  909. var httpAdapter = null;
  910. /**
  911. * Determines if the given thing is a array or js object.
  912. *
  913. * @param {string} thing - The object or array to be visited.
  914. *
  915. * @returns {boolean}
  916. */
  917. function isVisitable(thing) {
  918. return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
  919. }
  920. /**
  921. * It removes the brackets from the end of a string
  922. *
  923. * @param {string} key - The key of the parameter.
  924. *
  925. * @returns {string} the key without the brackets.
  926. */
  927. function removeBrackets(key) {
  928. return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
  929. }
  930. /**
  931. * It takes a path, a key, and a boolean, and returns a string
  932. *
  933. * @param {string} path - The path to the current key.
  934. * @param {string} key - The key of the current object being iterated over.
  935. * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
  936. *
  937. * @returns {string} The path to the current key.
  938. */
  939. function renderKey(path, key, dots) {
  940. if (!path) return key;
  941. return path
  942. .concat(key)
  943. .map(function each(token, i) {
  944. // eslint-disable-next-line no-param-reassign
  945. token = removeBrackets(token);
  946. return !dots && i ? '[' + token + ']' : token;
  947. })
  948. .join(dots ? '.' : '');
  949. }
  950. /**
  951. * If the array is an array and none of its elements are visitable, then it's a flat array.
  952. *
  953. * @param {Array<any>} arr - The array to check
  954. *
  955. * @returns {boolean}
  956. */
  957. function isFlatArray(arr) {
  958. return utils$1.isArray(arr) && !arr.some(isVisitable);
  959. }
  960. const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
  961. return /^is[A-Z]/.test(prop);
  962. });
  963. /**
  964. * Convert a data object to FormData
  965. *
  966. * @param {Object} obj
  967. * @param {?Object} [formData]
  968. * @param {?Object} [options]
  969. * @param {Function} [options.visitor]
  970. * @param {Boolean} [options.metaTokens = true]
  971. * @param {Boolean} [options.dots = false]
  972. * @param {?Boolean} [options.indexes = false]
  973. *
  974. * @returns {Object}
  975. **/
  976. /**
  977. * It converts an object into a FormData object
  978. *
  979. * @param {Object<any, any>} obj - The object to convert to form data.
  980. * @param {string} formData - The FormData object to append to.
  981. * @param {Object<string, any>} options
  982. *
  983. * @returns
  984. */
  985. function toFormData(obj, formData, options) {
  986. if (!utils$1.isObject(obj)) {
  987. throw new TypeError('target must be an object');
  988. }
  989. // eslint-disable-next-line no-param-reassign
  990. formData = formData || new (FormData)();
  991. // eslint-disable-next-line no-param-reassign
  992. options = utils$1.toFlatObject(
  993. options,
  994. {
  995. metaTokens: true,
  996. dots: false,
  997. indexes: false,
  998. },
  999. false,
  1000. function defined(option, source) {
  1001. // eslint-disable-next-line no-eq-null,eqeqeq
  1002. return !utils$1.isUndefined(source[option]);
  1003. }
  1004. );
  1005. const metaTokens = options.metaTokens;
  1006. // eslint-disable-next-line no-use-before-define
  1007. const visitor = options.visitor || defaultVisitor;
  1008. const dots = options.dots;
  1009. const indexes = options.indexes;
  1010. const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
  1011. const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
  1012. const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
  1013. if (!utils$1.isFunction(visitor)) {
  1014. throw new TypeError('visitor must be a function');
  1015. }
  1016. function convertValue(value) {
  1017. if (value === null) return '';
  1018. if (utils$1.isDate(value)) {
  1019. return value.toISOString();
  1020. }
  1021. if (utils$1.isBoolean(value)) {
  1022. return value.toString();
  1023. }
  1024. if (!useBlob && utils$1.isBlob(value)) {
  1025. throw new AxiosError('Blob is not supported. Use a Buffer instead.');
  1026. }
  1027. if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
  1028. return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
  1029. }
  1030. return value;
  1031. }
  1032. /**
  1033. * Default visitor.
  1034. *
  1035. * @param {*} value
  1036. * @param {String|Number} key
  1037. * @param {Array<String|Number>} path
  1038. * @this {FormData}
  1039. *
  1040. * @returns {boolean} return true to visit the each prop of the value recursively
  1041. */
  1042. function defaultVisitor(value, key, path) {
  1043. let arr = value;
  1044. if (utils$1.isReactNative(formData) && utils$1.isReactNativeBlob(value)) {
  1045. formData.append(renderKey(path, key, dots), convertValue(value));
  1046. return false;
  1047. }
  1048. if (value && !path && typeof value === 'object') {
  1049. if (utils$1.endsWith(key, '{}')) {
  1050. // eslint-disable-next-line no-param-reassign
  1051. key = metaTokens ? key : key.slice(0, -2);
  1052. // eslint-disable-next-line no-param-reassign
  1053. value = JSON.stringify(value);
  1054. } else if (
  1055. (utils$1.isArray(value) && isFlatArray(value)) ||
  1056. ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value)))
  1057. ) {
  1058. // eslint-disable-next-line no-param-reassign
  1059. key = removeBrackets(key);
  1060. arr.forEach(function each(el, index) {
  1061. !(utils$1.isUndefined(el) || el === null) &&
  1062. formData.append(
  1063. // eslint-disable-next-line no-nested-ternary
  1064. indexes === true
  1065. ? renderKey([key], index, dots)
  1066. : indexes === null
  1067. ? key
  1068. : key + '[]',
  1069. convertValue(el)
  1070. );
  1071. });
  1072. return false;
  1073. }
  1074. }
  1075. if (isVisitable(value)) {
  1076. return true;
  1077. }
  1078. formData.append(renderKey(path, key, dots), convertValue(value));
  1079. return false;
  1080. }
  1081. const stack = [];
  1082. const exposedHelpers = Object.assign(predicates, {
  1083. defaultVisitor,
  1084. convertValue,
  1085. isVisitable,
  1086. });
  1087. function build(value, path, depth = 0) {
  1088. if (utils$1.isUndefined(value)) return;
  1089. if (depth > maxDepth) {
  1090. throw new AxiosError(
  1091. 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
  1092. AxiosError.ERR_FORM_DATA_DEPTH_EXCEEDED
  1093. );
  1094. }
  1095. if (stack.indexOf(value) !== -1) {
  1096. throw Error('Circular reference detected in ' + path.join('.'));
  1097. }
  1098. stack.push(value);
  1099. utils$1.forEach(value, function each(el, key) {
  1100. const result =
  1101. !(utils$1.isUndefined(el) || el === null) &&
  1102. visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
  1103. if (result === true) {
  1104. build(el, path ? path.concat(key) : [key], depth + 1);
  1105. }
  1106. });
  1107. stack.pop();
  1108. }
  1109. if (!utils$1.isObject(obj)) {
  1110. throw new TypeError('data must be an object');
  1111. }
  1112. build(obj);
  1113. return formData;
  1114. }
  1115. /**
  1116. * It encodes a string by replacing all characters that are not in the unreserved set with
  1117. * their percent-encoded equivalents
  1118. *
  1119. * @param {string} str - The string to encode.
  1120. *
  1121. * @returns {string} The encoded string.
  1122. */
  1123. function encode$1(str) {
  1124. const charMap = {
  1125. '!': '%21',
  1126. "'": '%27',
  1127. '(': '%28',
  1128. ')': '%29',
  1129. '~': '%7E',
  1130. '%20': '+',
  1131. };
  1132. return encodeURIComponent(str).replace(/[!'()~]|%20/g, function replacer(match) {
  1133. return charMap[match];
  1134. });
  1135. }
  1136. /**
  1137. * It takes a params object and converts it to a FormData object
  1138. *
  1139. * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
  1140. * @param {Object<string, any>} options - The options object passed to the Axios constructor.
  1141. *
  1142. * @returns {void}
  1143. */
  1144. function AxiosURLSearchParams(params, options) {
  1145. this._pairs = [];
  1146. params && toFormData(params, this, options);
  1147. }
  1148. const prototype = AxiosURLSearchParams.prototype;
  1149. prototype.append = function append(name, value) {
  1150. this._pairs.push([name, value]);
  1151. };
  1152. prototype.toString = function toString(encoder) {
  1153. const _encode = encoder
  1154. ? function (value) {
  1155. return encoder.call(this, value, encode$1);
  1156. }
  1157. : encode$1;
  1158. return this._pairs
  1159. .map(function each(pair) {
  1160. return _encode(pair[0]) + '=' + _encode(pair[1]);
  1161. }, '')
  1162. .join('&');
  1163. };
  1164. /**
  1165. * It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
  1166. * their plain counterparts (`:`, `$`, `,`, `+`).
  1167. *
  1168. * @param {string} val The value to be encoded.
  1169. *
  1170. * @returns {string} The encoded value.
  1171. */
  1172. function encode(val) {
  1173. return encodeURIComponent(val)
  1174. .replace(/%3A/gi, ':')
  1175. .replace(/%24/g, '$')
  1176. .replace(/%2C/gi, ',')
  1177. .replace(/%20/g, '+');
  1178. }
  1179. /**
  1180. * Build a URL by appending params to the end
  1181. *
  1182. * @param {string} url The base of the url (e.g., http://www.google.com)
  1183. * @param {object} [params] The params to be appended
  1184. * @param {?(object|Function)} options
  1185. *
  1186. * @returns {string} The formatted url
  1187. */
  1188. function buildURL(url, params, options) {
  1189. if (!params) {
  1190. return url;
  1191. }
  1192. const _encode = (options && options.encode) || encode;
  1193. const _options = utils$1.isFunction(options)
  1194. ? {
  1195. serialize: options,
  1196. }
  1197. : options;
  1198. const serializeFn = _options && _options.serialize;
  1199. let serializedParams;
  1200. if (serializeFn) {
  1201. serializedParams = serializeFn(params, _options);
  1202. } else {
  1203. serializedParams = utils$1.isURLSearchParams(params)
  1204. ? params.toString()
  1205. : new AxiosURLSearchParams(params, _options).toString(_encode);
  1206. }
  1207. if (serializedParams) {
  1208. const hashmarkIndex = url.indexOf('#');
  1209. if (hashmarkIndex !== -1) {
  1210. url = url.slice(0, hashmarkIndex);
  1211. }
  1212. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  1213. }
  1214. return url;
  1215. }
  1216. class InterceptorManager {
  1217. constructor() {
  1218. this.handlers = [];
  1219. }
  1220. /**
  1221. * Add a new interceptor to the stack
  1222. *
  1223. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  1224. * @param {Function} rejected The function to handle `reject` for a `Promise`
  1225. * @param {Object} options The options for the interceptor, synchronous and runWhen
  1226. *
  1227. * @return {Number} An ID used to remove interceptor later
  1228. */
  1229. use(fulfilled, rejected, options) {
  1230. this.handlers.push({
  1231. fulfilled,
  1232. rejected,
  1233. synchronous: options ? options.synchronous : false,
  1234. runWhen: options ? options.runWhen : null,
  1235. });
  1236. return this.handlers.length - 1;
  1237. }
  1238. /**
  1239. * Remove an interceptor from the stack
  1240. *
  1241. * @param {Number} id The ID that was returned by `use`
  1242. *
  1243. * @returns {void}
  1244. */
  1245. eject(id) {
  1246. if (this.handlers[id]) {
  1247. this.handlers[id] = null;
  1248. }
  1249. }
  1250. /**
  1251. * Clear all interceptors from the stack
  1252. *
  1253. * @returns {void}
  1254. */
  1255. clear() {
  1256. if (this.handlers) {
  1257. this.handlers = [];
  1258. }
  1259. }
  1260. /**
  1261. * Iterate over all the registered interceptors
  1262. *
  1263. * This method is particularly useful for skipping over any
  1264. * interceptors that may have become `null` calling `eject`.
  1265. *
  1266. * @param {Function} fn The function to call for each interceptor
  1267. *
  1268. * @returns {void}
  1269. */
  1270. forEach(fn) {
  1271. utils$1.forEach(this.handlers, function forEachHandler(h) {
  1272. if (h !== null) {
  1273. fn(h);
  1274. }
  1275. });
  1276. }
  1277. }
  1278. var transitionalDefaults = {
  1279. silentJSONParsing: true,
  1280. forcedJSONParsing: true,
  1281. clarifyTimeoutError: false,
  1282. legacyInterceptorReqResOrdering: true,
  1283. };
  1284. var URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
  1285. var FormData$1 = typeof FormData !== 'undefined' ? FormData : null;
  1286. var Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
  1287. var platform$1 = {
  1288. isBrowser: true,
  1289. classes: {
  1290. URLSearchParams: URLSearchParams$1,
  1291. FormData: FormData$1,
  1292. Blob: Blob$1,
  1293. },
  1294. protocols: ['http', 'https', 'file', 'blob', 'url', 'data'],
  1295. };
  1296. const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
  1297. const _navigator = (typeof navigator === 'object' && navigator) || undefined;
  1298. /**
  1299. * Determine if we're running in a standard browser environment
  1300. *
  1301. * This allows axios to run in a web worker, and react-native.
  1302. * Both environments support XMLHttpRequest, but not fully standard globals.
  1303. *
  1304. * web workers:
  1305. * typeof window -> undefined
  1306. * typeof document -> undefined
  1307. *
  1308. * react-native:
  1309. * navigator.product -> 'ReactNative'
  1310. * nativescript
  1311. * navigator.product -> 'NativeScript' or 'NS'
  1312. *
  1313. * @returns {boolean}
  1314. */
  1315. const hasStandardBrowserEnv =
  1316. hasBrowserEnv &&
  1317. (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
  1318. /**
  1319. * Determine if we're running in a standard browser webWorker environment
  1320. *
  1321. * Although the `isStandardBrowserEnv` method indicates that
  1322. * `allows axios to run in a web worker`, the WebWorker will still be
  1323. * filtered out due to its judgment standard
  1324. * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
  1325. * This leads to a problem when axios post `FormData` in webWorker
  1326. */
  1327. const hasStandardBrowserWebWorkerEnv = (() => {
  1328. return (
  1329. typeof WorkerGlobalScope !== 'undefined' &&
  1330. // eslint-disable-next-line no-undef
  1331. self instanceof WorkerGlobalScope &&
  1332. typeof self.importScripts === 'function'
  1333. );
  1334. })();
  1335. const origin = (hasBrowserEnv && window.location.href) || 'http://localhost';
  1336. var utils = /*#__PURE__*/Object.freeze({
  1337. __proto__: null,
  1338. hasBrowserEnv: hasBrowserEnv,
  1339. hasStandardBrowserEnv: hasStandardBrowserEnv,
  1340. hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
  1341. navigator: _navigator,
  1342. origin: origin
  1343. });
  1344. var platform = {
  1345. ...utils,
  1346. ...platform$1,
  1347. };
  1348. function toURLEncodedForm(data, options) {
  1349. return toFormData(data, new platform.classes.URLSearchParams(), {
  1350. visitor: function (value, key, path, helpers) {
  1351. if (platform.isNode && utils$1.isBuffer(value)) {
  1352. this.append(key, value.toString('base64'));
  1353. return false;
  1354. }
  1355. return helpers.defaultVisitor.apply(this, arguments);
  1356. },
  1357. ...options,
  1358. });
  1359. }
  1360. /**
  1361. * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
  1362. *
  1363. * @param {string} name - The name of the property to get.
  1364. *
  1365. * @returns An array of strings.
  1366. */
  1367. function parsePropPath(name) {
  1368. // foo[x][y][z]
  1369. // foo.x.y.z
  1370. // foo-x-y-z
  1371. // foo x y z
  1372. return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
  1373. return match[0] === '[]' ? '' : match[1] || match[0];
  1374. });
  1375. }
  1376. /**
  1377. * Convert an array to an object.
  1378. *
  1379. * @param {Array<any>} arr - The array to convert to an object.
  1380. *
  1381. * @returns An object with the same keys and values as the array.
  1382. */
  1383. function arrayToObject(arr) {
  1384. const obj = {};
  1385. const keys = Object.keys(arr);
  1386. let i;
  1387. const len = keys.length;
  1388. let key;
  1389. for (i = 0; i < len; i++) {
  1390. key = keys[i];
  1391. obj[key] = arr[key];
  1392. }
  1393. return obj;
  1394. }
  1395. /**
  1396. * It takes a FormData object and returns a JavaScript object
  1397. *
  1398. * @param {string} formData The FormData object to convert to JSON.
  1399. *
  1400. * @returns {Object<string, any> | null} The converted object.
  1401. */
  1402. function formDataToJSON(formData) {
  1403. function buildPath(path, value, target, index) {
  1404. let name = path[index++];
  1405. if (name === '__proto__') return true;
  1406. const isNumericKey = Number.isFinite(+name);
  1407. const isLast = index >= path.length;
  1408. name = !name && utils$1.isArray(target) ? target.length : name;
  1409. if (isLast) {
  1410. if (utils$1.hasOwnProp(target, name)) {
  1411. target[name] = utils$1.isArray(target[name])
  1412. ? target[name].concat(value)
  1413. : [target[name], value];
  1414. } else {
  1415. target[name] = value;
  1416. }
  1417. return !isNumericKey;
  1418. }
  1419. if (!target[name] || !utils$1.isObject(target[name])) {
  1420. target[name] = [];
  1421. }
  1422. const result = buildPath(path, value, target[name], index);
  1423. if (result && utils$1.isArray(target[name])) {
  1424. target[name] = arrayToObject(target[name]);
  1425. }
  1426. return !isNumericKey;
  1427. }
  1428. if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
  1429. const obj = {};
  1430. utils$1.forEachEntry(formData, (name, value) => {
  1431. buildPath(parsePropPath(name), value, obj, 0);
  1432. });
  1433. return obj;
  1434. }
  1435. return null;
  1436. }
  1437. const own = (obj, key) => (obj != null && utils$1.hasOwnProp(obj, key) ? obj[key] : undefined);
  1438. /**
  1439. * It takes a string, tries to parse it, and if it fails, it returns the stringified version
  1440. * of the input
  1441. *
  1442. * @param {any} rawValue - The value to be stringified.
  1443. * @param {Function} parser - A function that parses a string into a JavaScript object.
  1444. * @param {Function} encoder - A function that takes a value and returns a string.
  1445. *
  1446. * @returns {string} A stringified version of the rawValue.
  1447. */
  1448. function stringifySafely(rawValue, parser, encoder) {
  1449. if (utils$1.isString(rawValue)) {
  1450. try {
  1451. (parser || JSON.parse)(rawValue);
  1452. return utils$1.trim(rawValue);
  1453. } catch (e) {
  1454. if (e.name !== 'SyntaxError') {
  1455. throw e;
  1456. }
  1457. }
  1458. }
  1459. return (encoder || JSON.stringify)(rawValue);
  1460. }
  1461. const defaults = {
  1462. transitional: transitionalDefaults,
  1463. adapter: ['xhr', 'http', 'fetch'],
  1464. transformRequest: [
  1465. function transformRequest(data, headers) {
  1466. const contentType = headers.getContentType() || '';
  1467. const hasJSONContentType = contentType.indexOf('application/json') > -1;
  1468. const isObjectPayload = utils$1.isObject(data);
  1469. if (isObjectPayload && utils$1.isHTMLForm(data)) {
  1470. data = new FormData(data);
  1471. }
  1472. const isFormData = utils$1.isFormData(data);
  1473. if (isFormData) {
  1474. return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
  1475. }
  1476. if (
  1477. utils$1.isArrayBuffer(data) ||
  1478. utils$1.isBuffer(data) ||
  1479. utils$1.isStream(data) ||
  1480. utils$1.isFile(data) ||
  1481. utils$1.isBlob(data) ||
  1482. utils$1.isReadableStream(data)
  1483. ) {
  1484. return data;
  1485. }
  1486. if (utils$1.isArrayBufferView(data)) {
  1487. return data.buffer;
  1488. }
  1489. if (utils$1.isURLSearchParams(data)) {
  1490. headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
  1491. return data.toString();
  1492. }
  1493. let isFileList;
  1494. if (isObjectPayload) {
  1495. const formSerializer = own(this, 'formSerializer');
  1496. if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
  1497. return toURLEncodedForm(data, formSerializer).toString();
  1498. }
  1499. if (
  1500. (isFileList = utils$1.isFileList(data)) ||
  1501. contentType.indexOf('multipart/form-data') > -1
  1502. ) {
  1503. const env = own(this, 'env');
  1504. const _FormData = env && env.FormData;
  1505. return toFormData(
  1506. isFileList ? { 'files[]': data } : data,
  1507. _FormData && new _FormData(),
  1508. formSerializer
  1509. );
  1510. }
  1511. }
  1512. if (isObjectPayload || hasJSONContentType) {
  1513. headers.setContentType('application/json', false);
  1514. return stringifySafely(data);
  1515. }
  1516. return data;
  1517. },
  1518. ],
  1519. transformResponse: [
  1520. function transformResponse(data) {
  1521. const transitional = own(this, 'transitional') || defaults.transitional;
  1522. const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
  1523. const responseType = own(this, 'responseType');
  1524. const JSONRequested = responseType === 'json';
  1525. if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
  1526. return data;
  1527. }
  1528. if (
  1529. data &&
  1530. utils$1.isString(data) &&
  1531. ((forcedJSONParsing && !responseType) || JSONRequested)
  1532. ) {
  1533. const silentJSONParsing = transitional && transitional.silentJSONParsing;
  1534. const strictJSONParsing = !silentJSONParsing && JSONRequested;
  1535. try {
  1536. return JSON.parse(data, own(this, 'parseReviver'));
  1537. } catch (e) {
  1538. if (strictJSONParsing) {
  1539. if (e.name === 'SyntaxError') {
  1540. throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, own(this, 'response'));
  1541. }
  1542. throw e;
  1543. }
  1544. }
  1545. }
  1546. return data;
  1547. },
  1548. ],
  1549. /**
  1550. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  1551. * timeout is not created.
  1552. */
  1553. timeout: 0,
  1554. xsrfCookieName: 'XSRF-TOKEN',
  1555. xsrfHeaderName: 'X-XSRF-TOKEN',
  1556. maxContentLength: -1,
  1557. maxBodyLength: -1,
  1558. env: {
  1559. FormData: platform.classes.FormData,
  1560. Blob: platform.classes.Blob,
  1561. },
  1562. validateStatus: function validateStatus(status) {
  1563. return status >= 200 && status < 300;
  1564. },
  1565. headers: {
  1566. common: {
  1567. Accept: 'application/json, text/plain, */*',
  1568. 'Content-Type': undefined,
  1569. },
  1570. },
  1571. };
  1572. utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
  1573. defaults.headers[method] = {};
  1574. });
  1575. // RawAxiosHeaders whose duplicates are ignored by node
  1576. // c.f. https://nodejs.org/api/http.html#http_message_headers
  1577. const ignoreDuplicateOf = utils$1.toObjectSet([
  1578. 'age',
  1579. 'authorization',
  1580. 'content-length',
  1581. 'content-type',
  1582. 'etag',
  1583. 'expires',
  1584. 'from',
  1585. 'host',
  1586. 'if-modified-since',
  1587. 'if-unmodified-since',
  1588. 'last-modified',
  1589. 'location',
  1590. 'max-forwards',
  1591. 'proxy-authorization',
  1592. 'referer',
  1593. 'retry-after',
  1594. 'user-agent',
  1595. ]);
  1596. /**
  1597. * Parse headers into an object
  1598. *
  1599. * ```
  1600. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  1601. * Content-Type: application/json
  1602. * Connection: keep-alive
  1603. * Transfer-Encoding: chunked
  1604. * ```
  1605. *
  1606. * @param {String} rawHeaders Headers needing to be parsed
  1607. *
  1608. * @returns {Object} Headers parsed into an object
  1609. */
  1610. var parseHeaders = (rawHeaders) => {
  1611. const parsed = {};
  1612. let key;
  1613. let val;
  1614. let i;
  1615. rawHeaders &&
  1616. rawHeaders.split('\n').forEach(function parser(line) {
  1617. i = line.indexOf(':');
  1618. key = line.substring(0, i).trim().toLowerCase();
  1619. val = line.substring(i + 1).trim();
  1620. if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
  1621. return;
  1622. }
  1623. if (key === 'set-cookie') {
  1624. if (parsed[key]) {
  1625. parsed[key].push(val);
  1626. } else {
  1627. parsed[key] = [val];
  1628. }
  1629. } else {
  1630. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  1631. }
  1632. });
  1633. return parsed;
  1634. };
  1635. const $internals = Symbol('internals');
  1636. const INVALID_HEADER_VALUE_CHARS_RE = /[^\x09\x20-\x7E\x80-\xFF]/g;
  1637. function trimSPorHTAB(str) {
  1638. let start = 0;
  1639. let end = str.length;
  1640. while (start < end) {
  1641. const code = str.charCodeAt(start);
  1642. if (code !== 0x09 && code !== 0x20) {
  1643. break;
  1644. }
  1645. start += 1;
  1646. }
  1647. while (end > start) {
  1648. const code = str.charCodeAt(end - 1);
  1649. if (code !== 0x09 && code !== 0x20) {
  1650. break;
  1651. }
  1652. end -= 1;
  1653. }
  1654. return start === 0 && end === str.length ? str : str.slice(start, end);
  1655. }
  1656. function normalizeHeader(header) {
  1657. return header && String(header).trim().toLowerCase();
  1658. }
  1659. function sanitizeHeaderValue(str) {
  1660. return trimSPorHTAB(str.replace(INVALID_HEADER_VALUE_CHARS_RE, ''));
  1661. }
  1662. function normalizeValue(value) {
  1663. if (value === false || value == null) {
  1664. return value;
  1665. }
  1666. return utils$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
  1667. }
  1668. function parseTokens(str) {
  1669. const tokens = Object.create(null);
  1670. const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
  1671. let match;
  1672. while ((match = tokensRE.exec(str))) {
  1673. tokens[match[1]] = match[2];
  1674. }
  1675. return tokens;
  1676. }
  1677. const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
  1678. function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
  1679. if (utils$1.isFunction(filter)) {
  1680. return filter.call(this, value, header);
  1681. }
  1682. if (isHeaderNameFilter) {
  1683. value = header;
  1684. }
  1685. if (!utils$1.isString(value)) return;
  1686. if (utils$1.isString(filter)) {
  1687. return value.indexOf(filter) !== -1;
  1688. }
  1689. if (utils$1.isRegExp(filter)) {
  1690. return filter.test(value);
  1691. }
  1692. }
  1693. function formatHeader(header) {
  1694. return header
  1695. .trim()
  1696. .toLowerCase()
  1697. .replace(/([a-z\d])(\w*)/g, (w, char, str) => {
  1698. return char.toUpperCase() + str;
  1699. });
  1700. }
  1701. function buildAccessors(obj, header) {
  1702. const accessorName = utils$1.toCamelCase(' ' + header);
  1703. ['get', 'set', 'has'].forEach((methodName) => {
  1704. Object.defineProperty(obj, methodName + accessorName, {
  1705. value: function (arg1, arg2, arg3) {
  1706. return this[methodName].call(this, header, arg1, arg2, arg3);
  1707. },
  1708. configurable: true,
  1709. });
  1710. });
  1711. }
  1712. class AxiosHeaders {
  1713. constructor(headers) {
  1714. headers && this.set(headers);
  1715. }
  1716. set(header, valueOrRewrite, rewrite) {
  1717. const self = this;
  1718. function setHeader(_value, _header, _rewrite) {
  1719. const lHeader = normalizeHeader(_header);
  1720. if (!lHeader) {
  1721. throw new Error('header name must be a non-empty string');
  1722. }
  1723. const key = utils$1.findKey(self, lHeader);
  1724. if (
  1725. !key ||
  1726. self[key] === undefined ||
  1727. _rewrite === true ||
  1728. (_rewrite === undefined && self[key] !== false)
  1729. ) {
  1730. self[key || _header] = normalizeValue(_value);
  1731. }
  1732. }
  1733. const setHeaders = (headers, _rewrite) =>
  1734. utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
  1735. if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
  1736. setHeaders(header, valueOrRewrite);
  1737. } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
  1738. setHeaders(parseHeaders(header), valueOrRewrite);
  1739. } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
  1740. let obj = {},
  1741. dest,
  1742. key;
  1743. for (const entry of header) {
  1744. if (!utils$1.isArray(entry)) {
  1745. throw TypeError('Object iterator must return a key-value pair');
  1746. }
  1747. obj[(key = entry[0])] = (dest = obj[key])
  1748. ? utils$1.isArray(dest)
  1749. ? [...dest, entry[1]]
  1750. : [dest, entry[1]]
  1751. : entry[1];
  1752. }
  1753. setHeaders(obj, valueOrRewrite);
  1754. } else {
  1755. header != null && setHeader(valueOrRewrite, header, rewrite);
  1756. }
  1757. return this;
  1758. }
  1759. get(header, parser) {
  1760. header = normalizeHeader(header);
  1761. if (header) {
  1762. const key = utils$1.findKey(this, header);
  1763. if (key) {
  1764. const value = this[key];
  1765. if (!parser) {
  1766. return value;
  1767. }
  1768. if (parser === true) {
  1769. return parseTokens(value);
  1770. }
  1771. if (utils$1.isFunction(parser)) {
  1772. return parser.call(this, value, key);
  1773. }
  1774. if (utils$1.isRegExp(parser)) {
  1775. return parser.exec(value);
  1776. }
  1777. throw new TypeError('parser must be boolean|regexp|function');
  1778. }
  1779. }
  1780. }
  1781. has(header, matcher) {
  1782. header = normalizeHeader(header);
  1783. if (header) {
  1784. const key = utils$1.findKey(this, header);
  1785. return !!(
  1786. key &&
  1787. this[key] !== undefined &&
  1788. (!matcher || matchHeaderValue(this, this[key], key, matcher))
  1789. );
  1790. }
  1791. return false;
  1792. }
  1793. delete(header, matcher) {
  1794. const self = this;
  1795. let deleted = false;
  1796. function deleteHeader(_header) {
  1797. _header = normalizeHeader(_header);
  1798. if (_header) {
  1799. const key = utils$1.findKey(self, _header);
  1800. if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
  1801. delete self[key];
  1802. deleted = true;
  1803. }
  1804. }
  1805. }
  1806. if (utils$1.isArray(header)) {
  1807. header.forEach(deleteHeader);
  1808. } else {
  1809. deleteHeader(header);
  1810. }
  1811. return deleted;
  1812. }
  1813. clear(matcher) {
  1814. const keys = Object.keys(this);
  1815. let i = keys.length;
  1816. let deleted = false;
  1817. while (i--) {
  1818. const key = keys[i];
  1819. if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
  1820. delete this[key];
  1821. deleted = true;
  1822. }
  1823. }
  1824. return deleted;
  1825. }
  1826. normalize(format) {
  1827. const self = this;
  1828. const headers = {};
  1829. utils$1.forEach(this, (value, header) => {
  1830. const key = utils$1.findKey(headers, header);
  1831. if (key) {
  1832. self[key] = normalizeValue(value);
  1833. delete self[header];
  1834. return;
  1835. }
  1836. const normalized = format ? formatHeader(header) : String(header).trim();
  1837. if (normalized !== header) {
  1838. delete self[header];
  1839. }
  1840. self[normalized] = normalizeValue(value);
  1841. headers[normalized] = true;
  1842. });
  1843. return this;
  1844. }
  1845. concat(...targets) {
  1846. return this.constructor.concat(this, ...targets);
  1847. }
  1848. toJSON(asStrings) {
  1849. const obj = Object.create(null);
  1850. utils$1.forEach(this, (value, header) => {
  1851. value != null &&
  1852. value !== false &&
  1853. (obj[header] = asStrings && utils$1.isArray(value) ? value.join(', ') : value);
  1854. });
  1855. return obj;
  1856. }
  1857. [Symbol.iterator]() {
  1858. return Object.entries(this.toJSON())[Symbol.iterator]();
  1859. }
  1860. toString() {
  1861. return Object.entries(this.toJSON())
  1862. .map(([header, value]) => header + ': ' + value)
  1863. .join('\n');
  1864. }
  1865. getSetCookie() {
  1866. return this.get('set-cookie') || [];
  1867. }
  1868. get [Symbol.toStringTag]() {
  1869. return 'AxiosHeaders';
  1870. }
  1871. static from(thing) {
  1872. return thing instanceof this ? thing : new this(thing);
  1873. }
  1874. static concat(first, ...targets) {
  1875. const computed = new this(first);
  1876. targets.forEach((target) => computed.set(target));
  1877. return computed;
  1878. }
  1879. static accessor(header) {
  1880. const internals =
  1881. (this[$internals] =
  1882. this[$internals] =
  1883. {
  1884. accessors: {},
  1885. });
  1886. const accessors = internals.accessors;
  1887. const prototype = this.prototype;
  1888. function defineAccessor(_header) {
  1889. const lHeader = normalizeHeader(_header);
  1890. if (!accessors[lHeader]) {
  1891. buildAccessors(prototype, _header);
  1892. accessors[lHeader] = true;
  1893. }
  1894. }
  1895. utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
  1896. return this;
  1897. }
  1898. }
  1899. AxiosHeaders.accessor([
  1900. 'Content-Type',
  1901. 'Content-Length',
  1902. 'Accept',
  1903. 'Accept-Encoding',
  1904. 'User-Agent',
  1905. 'Authorization',
  1906. ]);
  1907. // reserved names hotfix
  1908. utils$1.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
  1909. let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
  1910. return {
  1911. get: () => value,
  1912. set(headerValue) {
  1913. this[mapped] = headerValue;
  1914. },
  1915. };
  1916. });
  1917. utils$1.freezeMethods(AxiosHeaders);
  1918. /**
  1919. * Transform the data for a request or a response
  1920. *
  1921. * @param {Array|Function} fns A single function or Array of functions
  1922. * @param {?Object} response The response object
  1923. *
  1924. * @returns {*} The resulting transformed data
  1925. */
  1926. function transformData(fns, response) {
  1927. const config = this || defaults;
  1928. const context = response || config;
  1929. const headers = AxiosHeaders.from(context.headers);
  1930. let data = context.data;
  1931. utils$1.forEach(fns, function transform(fn) {
  1932. data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
  1933. });
  1934. headers.normalize();
  1935. return data;
  1936. }
  1937. function isCancel(value) {
  1938. return !!(value && value.__CANCEL__);
  1939. }
  1940. class CanceledError extends AxiosError {
  1941. /**
  1942. * A `CanceledError` is an object that is thrown when an operation is canceled.
  1943. *
  1944. * @param {string=} message The message.
  1945. * @param {Object=} config The config.
  1946. * @param {Object=} request The request.
  1947. *
  1948. * @returns {CanceledError} The created error.
  1949. */
  1950. constructor(message, config, request) {
  1951. super(message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
  1952. this.name = 'CanceledError';
  1953. this.__CANCEL__ = true;
  1954. }
  1955. }
  1956. /**
  1957. * Resolve or reject a Promise based on response status.
  1958. *
  1959. * @param {Function} resolve A function that resolves the promise.
  1960. * @param {Function} reject A function that rejects the promise.
  1961. * @param {object} response The response.
  1962. *
  1963. * @returns {object} The response.
  1964. */
  1965. function settle(resolve, reject, response) {
  1966. const validateStatus = response.config.validateStatus;
  1967. if (!response.status || !validateStatus || validateStatus(response.status)) {
  1968. resolve(response);
  1969. } else {
  1970. reject(
  1971. new AxiosError(
  1972. 'Request failed with status code ' + response.status,
  1973. [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][
  1974. Math.floor(response.status / 100) - 4
  1975. ],
  1976. response.config,
  1977. response.request,
  1978. response
  1979. )
  1980. );
  1981. }
  1982. }
  1983. function parseProtocol(url) {
  1984. const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
  1985. return (match && match[1]) || '';
  1986. }
  1987. /**
  1988. * Calculate data maxRate
  1989. * @param {Number} [samplesCount= 10]
  1990. * @param {Number} [min= 1000]
  1991. * @returns {Function}
  1992. */
  1993. function speedometer(samplesCount, min) {
  1994. samplesCount = samplesCount || 10;
  1995. const bytes = new Array(samplesCount);
  1996. const timestamps = new Array(samplesCount);
  1997. let head = 0;
  1998. let tail = 0;
  1999. let firstSampleTS;
  2000. min = min !== undefined ? min : 1000;
  2001. return function push(chunkLength) {
  2002. const now = Date.now();
  2003. const startedAt = timestamps[tail];
  2004. if (!firstSampleTS) {
  2005. firstSampleTS = now;
  2006. }
  2007. bytes[head] = chunkLength;
  2008. timestamps[head] = now;
  2009. let i = tail;
  2010. let bytesCount = 0;
  2011. while (i !== head) {
  2012. bytesCount += bytes[i++];
  2013. i = i % samplesCount;
  2014. }
  2015. head = (head + 1) % samplesCount;
  2016. if (head === tail) {
  2017. tail = (tail + 1) % samplesCount;
  2018. }
  2019. if (now - firstSampleTS < min) {
  2020. return;
  2021. }
  2022. const passed = startedAt && now - startedAt;
  2023. return passed ? Math.round((bytesCount * 1000) / passed) : undefined;
  2024. };
  2025. }
  2026. /**
  2027. * Throttle decorator
  2028. * @param {Function} fn
  2029. * @param {Number} freq
  2030. * @return {Function}
  2031. */
  2032. function throttle(fn, freq) {
  2033. let timestamp = 0;
  2034. let threshold = 1000 / freq;
  2035. let lastArgs;
  2036. let timer;
  2037. const invoke = (args, now = Date.now()) => {
  2038. timestamp = now;
  2039. lastArgs = null;
  2040. if (timer) {
  2041. clearTimeout(timer);
  2042. timer = null;
  2043. }
  2044. fn(...args);
  2045. };
  2046. const throttled = (...args) => {
  2047. const now = Date.now();
  2048. const passed = now - timestamp;
  2049. if (passed >= threshold) {
  2050. invoke(args, now);
  2051. } else {
  2052. lastArgs = args;
  2053. if (!timer) {
  2054. timer = setTimeout(() => {
  2055. timer = null;
  2056. invoke(lastArgs);
  2057. }, threshold - passed);
  2058. }
  2059. }
  2060. };
  2061. const flush = () => lastArgs && invoke(lastArgs);
  2062. return [throttled, flush];
  2063. }
  2064. const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
  2065. let bytesNotified = 0;
  2066. const _speedometer = speedometer(50, 250);
  2067. return throttle((e) => {
  2068. const rawLoaded = e.loaded;
  2069. const total = e.lengthComputable ? e.total : undefined;
  2070. const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
  2071. const progressBytes = Math.max(0, loaded - bytesNotified);
  2072. const rate = _speedometer(progressBytes);
  2073. bytesNotified = Math.max(bytesNotified, loaded);
  2074. const data = {
  2075. loaded,
  2076. total,
  2077. progress: total ? loaded / total : undefined,
  2078. bytes: progressBytes,
  2079. rate: rate ? rate : undefined,
  2080. estimated: rate && total ? (total - loaded) / rate : undefined,
  2081. event: e,
  2082. lengthComputable: total != null,
  2083. [isDownloadStream ? 'download' : 'upload']: true,
  2084. };
  2085. listener(data);
  2086. }, freq);
  2087. };
  2088. const progressEventDecorator = (total, throttled) => {
  2089. const lengthComputable = total != null;
  2090. return [
  2091. (loaded) =>
  2092. throttled[0]({
  2093. lengthComputable,
  2094. total,
  2095. loaded,
  2096. }),
  2097. throttled[1],
  2098. ];
  2099. };
  2100. const asyncDecorator =
  2101. (fn) =>
  2102. (...args) =>
  2103. utils$1.asap(() => fn(...args));
  2104. var isURLSameOrigin = platform.hasStandardBrowserEnv
  2105. ? ((origin, isMSIE) => (url) => {
  2106. url = new URL(url, platform.origin);
  2107. return (
  2108. origin.protocol === url.protocol &&
  2109. origin.host === url.host &&
  2110. (isMSIE || origin.port === url.port)
  2111. );
  2112. })(
  2113. new URL(platform.origin),
  2114. platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
  2115. )
  2116. : () => true;
  2117. var cookies = platform.hasStandardBrowserEnv
  2118. ? // Standard browser envs support document.cookie
  2119. {
  2120. write(name, value, expires, path, domain, secure, sameSite) {
  2121. if (typeof document === 'undefined') return;
  2122. const cookie = [`${name}=${encodeURIComponent(value)}`];
  2123. if (utils$1.isNumber(expires)) {
  2124. cookie.push(`expires=${new Date(expires).toUTCString()}`);
  2125. }
  2126. if (utils$1.isString(path)) {
  2127. cookie.push(`path=${path}`);
  2128. }
  2129. if (utils$1.isString(domain)) {
  2130. cookie.push(`domain=${domain}`);
  2131. }
  2132. if (secure === true) {
  2133. cookie.push('secure');
  2134. }
  2135. if (utils$1.isString(sameSite)) {
  2136. cookie.push(`SameSite=${sameSite}`);
  2137. }
  2138. document.cookie = cookie.join('; ');
  2139. },
  2140. read(name) {
  2141. if (typeof document === 'undefined') return null;
  2142. const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
  2143. return match ? decodeURIComponent(match[1]) : null;
  2144. },
  2145. remove(name) {
  2146. this.write(name, '', Date.now() - 86400000, '/');
  2147. },
  2148. }
  2149. : // Non-standard browser env (web workers, react-native) lack needed support.
  2150. {
  2151. write() {},
  2152. read() {
  2153. return null;
  2154. },
  2155. remove() {},
  2156. };
  2157. /**
  2158. * Determines whether the specified URL is absolute
  2159. *
  2160. * @param {string} url The URL to test
  2161. *
  2162. * @returns {boolean} True if the specified URL is absolute, otherwise false
  2163. */
  2164. function isAbsoluteURL(url) {
  2165. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  2166. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  2167. // by any combination of letters, digits, plus, period, or hyphen.
  2168. if (typeof url !== 'string') {
  2169. return false;
  2170. }
  2171. return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
  2172. }
  2173. /**
  2174. * Creates a new URL by combining the specified URLs
  2175. *
  2176. * @param {string} baseURL The base URL
  2177. * @param {string} relativeURL The relative URL
  2178. *
  2179. * @returns {string} The combined URL
  2180. */
  2181. function combineURLs(baseURL, relativeURL) {
  2182. return relativeURL
  2183. ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  2184. : baseURL;
  2185. }
  2186. /**
  2187. * Creates a new URL by combining the baseURL with the requestedURL,
  2188. * only when the requestedURL is not already an absolute URL.
  2189. * If the requestURL is absolute, this function returns the requestedURL untouched.
  2190. *
  2191. * @param {string} baseURL The base URL
  2192. * @param {string} requestedURL Absolute or relative URL to combine
  2193. *
  2194. * @returns {string} The combined full path
  2195. */
  2196. function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
  2197. let isRelativeUrl = !isAbsoluteURL(requestedURL);
  2198. if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
  2199. return combineURLs(baseURL, requestedURL);
  2200. }
  2201. return requestedURL;
  2202. }
  2203. const headersToObject = (thing) => (thing instanceof AxiosHeaders ? { ...thing } : thing);
  2204. /**
  2205. * Config-specific merge-function which creates a new config-object
  2206. * by merging two configuration objects together.
  2207. *
  2208. * @param {Object} config1
  2209. * @param {Object} config2
  2210. *
  2211. * @returns {Object} New object resulting from merging config2 to config1
  2212. */
  2213. function mergeConfig(config1, config2) {
  2214. // eslint-disable-next-line no-param-reassign
  2215. config2 = config2 || {};
  2216. // Use a null-prototype object so that downstream reads such as `config.auth`
  2217. // or `config.baseURL` cannot inherit polluted values from Object.prototype
  2218. // (see GHSA-q8qp-cvcw-x6jj). `hasOwnProperty` is restored as a non-enumerable
  2219. // own slot to preserve ergonomics for user code that relies on it.
  2220. const config = Object.create(null);
  2221. Object.defineProperty(config, 'hasOwnProperty', {
  2222. value: Object.prototype.hasOwnProperty,
  2223. enumerable: false,
  2224. writable: true,
  2225. configurable: true,
  2226. });
  2227. function getMergedValue(target, source, prop, caseless) {
  2228. if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
  2229. return utils$1.merge.call({ caseless }, target, source);
  2230. } else if (utils$1.isPlainObject(source)) {
  2231. return utils$1.merge({}, source);
  2232. } else if (utils$1.isArray(source)) {
  2233. return source.slice();
  2234. }
  2235. return source;
  2236. }
  2237. function mergeDeepProperties(a, b, prop, caseless) {
  2238. if (!utils$1.isUndefined(b)) {
  2239. return getMergedValue(a, b, prop, caseless);
  2240. } else if (!utils$1.isUndefined(a)) {
  2241. return getMergedValue(undefined, a, prop, caseless);
  2242. }
  2243. }
  2244. // eslint-disable-next-line consistent-return
  2245. function valueFromConfig2(a, b) {
  2246. if (!utils$1.isUndefined(b)) {
  2247. return getMergedValue(undefined, b);
  2248. }
  2249. }
  2250. // eslint-disable-next-line consistent-return
  2251. function defaultToConfig2(a, b) {
  2252. if (!utils$1.isUndefined(b)) {
  2253. return getMergedValue(undefined, b);
  2254. } else if (!utils$1.isUndefined(a)) {
  2255. return getMergedValue(undefined, a);
  2256. }
  2257. }
  2258. // eslint-disable-next-line consistent-return
  2259. function mergeDirectKeys(a, b, prop) {
  2260. if (utils$1.hasOwnProp(config2, prop)) {
  2261. return getMergedValue(a, b);
  2262. } else if (utils$1.hasOwnProp(config1, prop)) {
  2263. return getMergedValue(undefined, a);
  2264. }
  2265. }
  2266. const mergeMap = {
  2267. url: valueFromConfig2,
  2268. method: valueFromConfig2,
  2269. data: valueFromConfig2,
  2270. baseURL: defaultToConfig2,
  2271. transformRequest: defaultToConfig2,
  2272. transformResponse: defaultToConfig2,
  2273. paramsSerializer: defaultToConfig2,
  2274. timeout: defaultToConfig2,
  2275. timeoutMessage: defaultToConfig2,
  2276. withCredentials: defaultToConfig2,
  2277. withXSRFToken: defaultToConfig2,
  2278. adapter: defaultToConfig2,
  2279. responseType: defaultToConfig2,
  2280. xsrfCookieName: defaultToConfig2,
  2281. xsrfHeaderName: defaultToConfig2,
  2282. onUploadProgress: defaultToConfig2,
  2283. onDownloadProgress: defaultToConfig2,
  2284. decompress: defaultToConfig2,
  2285. maxContentLength: defaultToConfig2,
  2286. maxBodyLength: defaultToConfig2,
  2287. beforeRedirect: defaultToConfig2,
  2288. transport: defaultToConfig2,
  2289. httpAgent: defaultToConfig2,
  2290. httpsAgent: defaultToConfig2,
  2291. cancelToken: defaultToConfig2,
  2292. socketPath: defaultToConfig2,
  2293. allowedSocketPaths: defaultToConfig2,
  2294. responseEncoding: defaultToConfig2,
  2295. validateStatus: mergeDirectKeys,
  2296. headers: (a, b, prop) =>
  2297. mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true),
  2298. };
  2299. utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
  2300. if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
  2301. const merge = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
  2302. const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : undefined;
  2303. const b = utils$1.hasOwnProp(config2, prop) ? config2[prop] : undefined;
  2304. const configValue = merge(a, b, prop);
  2305. (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
  2306. });
  2307. return config;
  2308. }
  2309. var resolveConfig = (config) => {
  2310. const newConfig = mergeConfig({}, config);
  2311. // Read only own properties to prevent prototype pollution gadgets
  2312. // (e.g. Object.prototype.baseURL = 'https://evil.com'). See GHSA-q8qp-cvcw-x6jj.
  2313. const own = (key) => (utils$1.hasOwnProp(newConfig, key) ? newConfig[key] : undefined);
  2314. const data = own('data');
  2315. let withXSRFToken = own('withXSRFToken');
  2316. const xsrfHeaderName = own('xsrfHeaderName');
  2317. const xsrfCookieName = own('xsrfCookieName');
  2318. let headers = own('headers');
  2319. const auth = own('auth');
  2320. const baseURL = own('baseURL');
  2321. const allowAbsoluteUrls = own('allowAbsoluteUrls');
  2322. const url = own('url');
  2323. newConfig.headers = headers = AxiosHeaders.from(headers);
  2324. newConfig.url = buildURL(
  2325. buildFullPath(baseURL, url, allowAbsoluteUrls),
  2326. config.params,
  2327. config.paramsSerializer
  2328. );
  2329. // HTTP basic authentication
  2330. if (auth) {
  2331. headers.set(
  2332. 'Authorization',
  2333. 'Basic ' +
  2334. btoa(
  2335. (auth.username || '') +
  2336. ':' +
  2337. (auth.password ? unescape(encodeURIComponent(auth.password)) : '')
  2338. )
  2339. );
  2340. }
  2341. if (utils$1.isFormData(data)) {
  2342. if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
  2343. headers.setContentType(undefined); // browser handles it
  2344. } else if (utils$1.isFunction(data.getHeaders)) {
  2345. // Node.js FormData (like form-data package)
  2346. const formHeaders = data.getHeaders();
  2347. // Only set safe headers to avoid overwriting security headers
  2348. const allowedHeaders = ['content-type', 'content-length'];
  2349. Object.entries(formHeaders).forEach(([key, val]) => {
  2350. if (allowedHeaders.includes(key.toLowerCase())) {
  2351. headers.set(key, val);
  2352. }
  2353. });
  2354. }
  2355. }
  2356. // Add xsrf header
  2357. // This is only done if running in a standard browser environment.
  2358. // Specifically not if we're in a web worker, or react-native.
  2359. if (platform.hasStandardBrowserEnv) {
  2360. if (utils$1.isFunction(withXSRFToken)) {
  2361. withXSRFToken = withXSRFToken(newConfig);
  2362. }
  2363. // Strict boolean check — prevents proto-pollution gadgets (e.g. Object.prototype.withXSRFToken = 1)
  2364. // and misconfigurations (e.g. "false") from short-circuiting the same-origin check and leaking
  2365. // the XSRF token cross-origin. See GHSA-xx6v-rp6x-q39c.
  2366. const shouldSendXSRF =
  2367. withXSRFToken === true ||
  2368. (withXSRFToken == null && isURLSameOrigin(newConfig.url));
  2369. if (shouldSendXSRF) {
  2370. const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
  2371. if (xsrfValue) {
  2372. headers.set(xsrfHeaderName, xsrfValue);
  2373. }
  2374. }
  2375. }
  2376. return newConfig;
  2377. };
  2378. const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
  2379. var xhrAdapter = isXHRAdapterSupported &&
  2380. function (config) {
  2381. return new Promise(function dispatchXhrRequest(resolve, reject) {
  2382. const _config = resolveConfig(config);
  2383. let requestData = _config.data;
  2384. const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
  2385. let { responseType, onUploadProgress, onDownloadProgress } = _config;
  2386. let onCanceled;
  2387. let uploadThrottled, downloadThrottled;
  2388. let flushUpload, flushDownload;
  2389. function done() {
  2390. flushUpload && flushUpload(); // flush events
  2391. flushDownload && flushDownload(); // flush events
  2392. _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
  2393. _config.signal && _config.signal.removeEventListener('abort', onCanceled);
  2394. }
  2395. let request = new XMLHttpRequest();
  2396. request.open(_config.method.toUpperCase(), _config.url, true);
  2397. // Set the request timeout in MS
  2398. request.timeout = _config.timeout;
  2399. function onloadend() {
  2400. if (!request) {
  2401. return;
  2402. }
  2403. // Prepare the response
  2404. const responseHeaders = AxiosHeaders.from(
  2405. 'getAllResponseHeaders' in request && request.getAllResponseHeaders()
  2406. );
  2407. const responseData =
  2408. !responseType || responseType === 'text' || responseType === 'json'
  2409. ? request.responseText
  2410. : request.response;
  2411. const response = {
  2412. data: responseData,
  2413. status: request.status,
  2414. statusText: request.statusText,
  2415. headers: responseHeaders,
  2416. config,
  2417. request,
  2418. };
  2419. settle(
  2420. function _resolve(value) {
  2421. resolve(value);
  2422. done();
  2423. },
  2424. function _reject(err) {
  2425. reject(err);
  2426. done();
  2427. },
  2428. response
  2429. );
  2430. // Clean up request
  2431. request = null;
  2432. }
  2433. if ('onloadend' in request) {
  2434. // Use onloadend if available
  2435. request.onloadend = onloadend;
  2436. } else {
  2437. // Listen for ready state to emulate onloadend
  2438. request.onreadystatechange = function handleLoad() {
  2439. if (!request || request.readyState !== 4) {
  2440. return;
  2441. }
  2442. // The request errored out and we didn't get a response, this will be
  2443. // handled by onerror instead
  2444. // With one exception: request that using file: protocol, most browsers
  2445. // will return status as 0 even though it's a successful request
  2446. if (
  2447. request.status === 0 &&
  2448. !(request.responseURL && request.responseURL.indexOf('file:') === 0)
  2449. ) {
  2450. return;
  2451. }
  2452. // readystate handler is calling before onerror or ontimeout handlers,
  2453. // so we should call onloadend on the next 'tick'
  2454. setTimeout(onloadend);
  2455. };
  2456. }
  2457. // Handle browser request cancellation (as opposed to a manual cancellation)
  2458. request.onabort = function handleAbort() {
  2459. if (!request) {
  2460. return;
  2461. }
  2462. reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
  2463. // Clean up request
  2464. request = null;
  2465. };
  2466. // Handle low level network errors
  2467. request.onerror = function handleError(event) {
  2468. // Browsers deliver a ProgressEvent in XHR onerror
  2469. // (message may be empty; when present, surface it)
  2470. // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
  2471. const msg = event && event.message ? event.message : 'Network Error';
  2472. const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
  2473. // attach the underlying event for consumers who want details
  2474. err.event = event || null;
  2475. reject(err);
  2476. request = null;
  2477. };
  2478. // Handle timeout
  2479. request.ontimeout = function handleTimeout() {
  2480. let timeoutErrorMessage = _config.timeout
  2481. ? 'timeout of ' + _config.timeout + 'ms exceeded'
  2482. : 'timeout exceeded';
  2483. const transitional = _config.transitional || transitionalDefaults;
  2484. if (_config.timeoutErrorMessage) {
  2485. timeoutErrorMessage = _config.timeoutErrorMessage;
  2486. }
  2487. reject(
  2488. new AxiosError(
  2489. timeoutErrorMessage,
  2490. transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
  2491. config,
  2492. request
  2493. )
  2494. );
  2495. // Clean up request
  2496. request = null;
  2497. };
  2498. // Remove Content-Type if data is undefined
  2499. requestData === undefined && requestHeaders.setContentType(null);
  2500. // Add headers to the request
  2501. if ('setRequestHeader' in request) {
  2502. utils$1.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
  2503. request.setRequestHeader(key, val);
  2504. });
  2505. }
  2506. // Add withCredentials to request if needed
  2507. if (!utils$1.isUndefined(_config.withCredentials)) {
  2508. request.withCredentials = !!_config.withCredentials;
  2509. }
  2510. // Add responseType to request if needed
  2511. if (responseType && responseType !== 'json') {
  2512. request.responseType = _config.responseType;
  2513. }
  2514. // Handle progress if needed
  2515. if (onDownloadProgress) {
  2516. [downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
  2517. request.addEventListener('progress', downloadThrottled);
  2518. }
  2519. // Not all browsers support upload events
  2520. if (onUploadProgress && request.upload) {
  2521. [uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress);
  2522. request.upload.addEventListener('progress', uploadThrottled);
  2523. request.upload.addEventListener('loadend', flushUpload);
  2524. }
  2525. if (_config.cancelToken || _config.signal) {
  2526. // Handle cancellation
  2527. // eslint-disable-next-line func-names
  2528. onCanceled = (cancel) => {
  2529. if (!request) {
  2530. return;
  2531. }
  2532. reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
  2533. request.abort();
  2534. request = null;
  2535. };
  2536. _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
  2537. if (_config.signal) {
  2538. _config.signal.aborted
  2539. ? onCanceled()
  2540. : _config.signal.addEventListener('abort', onCanceled);
  2541. }
  2542. }
  2543. const protocol = parseProtocol(_config.url);
  2544. if (protocol && platform.protocols.indexOf(protocol) === -1) {
  2545. reject(
  2546. new AxiosError(
  2547. 'Unsupported protocol ' + protocol + ':',
  2548. AxiosError.ERR_BAD_REQUEST,
  2549. config
  2550. )
  2551. );
  2552. return;
  2553. }
  2554. // Send the request
  2555. request.send(requestData || null);
  2556. });
  2557. };
  2558. const composeSignals = (signals, timeout) => {
  2559. const { length } = (signals = signals ? signals.filter(Boolean) : []);
  2560. if (timeout || length) {
  2561. let controller = new AbortController();
  2562. let aborted;
  2563. const onabort = function (reason) {
  2564. if (!aborted) {
  2565. aborted = true;
  2566. unsubscribe();
  2567. const err = reason instanceof Error ? reason : this.reason;
  2568. controller.abort(
  2569. err instanceof AxiosError
  2570. ? err
  2571. : new CanceledError(err instanceof Error ? err.message : err)
  2572. );
  2573. }
  2574. };
  2575. let timer =
  2576. timeout &&
  2577. setTimeout(() => {
  2578. timer = null;
  2579. onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
  2580. }, timeout);
  2581. const unsubscribe = () => {
  2582. if (signals) {
  2583. timer && clearTimeout(timer);
  2584. timer = null;
  2585. signals.forEach((signal) => {
  2586. signal.unsubscribe
  2587. ? signal.unsubscribe(onabort)
  2588. : signal.removeEventListener('abort', onabort);
  2589. });
  2590. signals = null;
  2591. }
  2592. };
  2593. signals.forEach((signal) => signal.addEventListener('abort', onabort));
  2594. const { signal } = controller;
  2595. signal.unsubscribe = () => utils$1.asap(unsubscribe);
  2596. return signal;
  2597. }
  2598. };
  2599. const streamChunk = function* (chunk, chunkSize) {
  2600. let len = chunk.byteLength;
  2601. if (len < chunkSize) {
  2602. yield chunk;
  2603. return;
  2604. }
  2605. let pos = 0;
  2606. let end;
  2607. while (pos < len) {
  2608. end = pos + chunkSize;
  2609. yield chunk.slice(pos, end);
  2610. pos = end;
  2611. }
  2612. };
  2613. const readBytes = async function* (iterable, chunkSize) {
  2614. for await (const chunk of readStream(iterable)) {
  2615. yield* streamChunk(chunk, chunkSize);
  2616. }
  2617. };
  2618. const readStream = async function* (stream) {
  2619. if (stream[Symbol.asyncIterator]) {
  2620. yield* stream;
  2621. return;
  2622. }
  2623. const reader = stream.getReader();
  2624. try {
  2625. for (;;) {
  2626. const { done, value } = await reader.read();
  2627. if (done) {
  2628. break;
  2629. }
  2630. yield value;
  2631. }
  2632. } finally {
  2633. await reader.cancel();
  2634. }
  2635. };
  2636. const trackStream = (stream, chunkSize, onProgress, onFinish) => {
  2637. const iterator = readBytes(stream, chunkSize);
  2638. let bytes = 0;
  2639. let done;
  2640. let _onFinish = (e) => {
  2641. if (!done) {
  2642. done = true;
  2643. onFinish && onFinish(e);
  2644. }
  2645. };
  2646. return new ReadableStream(
  2647. {
  2648. async pull(controller) {
  2649. try {
  2650. const { done, value } = await iterator.next();
  2651. if (done) {
  2652. _onFinish();
  2653. controller.close();
  2654. return;
  2655. }
  2656. let len = value.byteLength;
  2657. if (onProgress) {
  2658. let loadedBytes = (bytes += len);
  2659. onProgress(loadedBytes);
  2660. }
  2661. controller.enqueue(new Uint8Array(value));
  2662. } catch (err) {
  2663. _onFinish(err);
  2664. throw err;
  2665. }
  2666. },
  2667. cancel(reason) {
  2668. _onFinish(reason);
  2669. return iterator.return();
  2670. },
  2671. },
  2672. {
  2673. highWaterMark: 2,
  2674. }
  2675. );
  2676. };
  2677. const DEFAULT_CHUNK_SIZE = 64 * 1024;
  2678. const { isFunction } = utils$1;
  2679. const globalFetchAPI = (({ Request, Response }) => ({
  2680. Request,
  2681. Response,
  2682. }))(utils$1.global);
  2683. const { ReadableStream: ReadableStream$1, TextEncoder } = utils$1.global;
  2684. const test = (fn, ...args) => {
  2685. try {
  2686. return !!fn(...args);
  2687. } catch (e) {
  2688. return false;
  2689. }
  2690. };
  2691. const factory = (env) => {
  2692. env = utils$1.merge.call(
  2693. {
  2694. skipUndefined: true,
  2695. },
  2696. globalFetchAPI,
  2697. env
  2698. );
  2699. const { fetch: envFetch, Request, Response } = env;
  2700. const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
  2701. const isRequestSupported = isFunction(Request);
  2702. const isResponseSupported = isFunction(Response);
  2703. if (!isFetchSupported) {
  2704. return false;
  2705. }
  2706. const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
  2707. const encodeText =
  2708. isFetchSupported &&
  2709. (typeof TextEncoder === 'function'
  2710. ? (
  2711. (encoder) => (str) =>
  2712. encoder.encode(str)
  2713. )(new TextEncoder())
  2714. : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
  2715. const supportsRequestStream =
  2716. isRequestSupported &&
  2717. isReadableStreamSupported &&
  2718. test(() => {
  2719. let duplexAccessed = false;
  2720. const request = new Request(platform.origin, {
  2721. body: new ReadableStream$1(),
  2722. method: 'POST',
  2723. get duplex() {
  2724. duplexAccessed = true;
  2725. return 'half';
  2726. },
  2727. });
  2728. const hasContentType = request.headers.has('Content-Type');
  2729. if (request.body != null) {
  2730. request.body.cancel();
  2731. }
  2732. return duplexAccessed && !hasContentType;
  2733. });
  2734. const supportsResponseStream =
  2735. isResponseSupported &&
  2736. isReadableStreamSupported &&
  2737. test(() => utils$1.isReadableStream(new Response('').body));
  2738. const resolvers = {
  2739. stream: supportsResponseStream && ((res) => res.body),
  2740. };
  2741. isFetchSupported &&
  2742. (() => {
  2743. ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach((type) => {
  2744. !resolvers[type] &&
  2745. (resolvers[type] = (res, config) => {
  2746. let method = res && res[type];
  2747. if (method) {
  2748. return method.call(res);
  2749. }
  2750. throw new AxiosError(
  2751. `Response type '${type}' is not supported`,
  2752. AxiosError.ERR_NOT_SUPPORT,
  2753. config
  2754. );
  2755. });
  2756. });
  2757. })();
  2758. const getBodyLength = async (body) => {
  2759. if (body == null) {
  2760. return 0;
  2761. }
  2762. if (utils$1.isBlob(body)) {
  2763. return body.size;
  2764. }
  2765. if (utils$1.isSpecCompliantForm(body)) {
  2766. const _request = new Request(platform.origin, {
  2767. method: 'POST',
  2768. body,
  2769. });
  2770. return (await _request.arrayBuffer()).byteLength;
  2771. }
  2772. if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
  2773. return body.byteLength;
  2774. }
  2775. if (utils$1.isURLSearchParams(body)) {
  2776. body = body + '';
  2777. }
  2778. if (utils$1.isString(body)) {
  2779. return (await encodeText(body)).byteLength;
  2780. }
  2781. };
  2782. const resolveBodyLength = async (headers, body) => {
  2783. const length = utils$1.toFiniteNumber(headers.getContentLength());
  2784. return length == null ? getBodyLength(body) : length;
  2785. };
  2786. return async (config) => {
  2787. let {
  2788. url,
  2789. method,
  2790. data,
  2791. signal,
  2792. cancelToken,
  2793. timeout,
  2794. onDownloadProgress,
  2795. onUploadProgress,
  2796. responseType,
  2797. headers,
  2798. withCredentials = 'same-origin',
  2799. fetchOptions,
  2800. } = resolveConfig(config);
  2801. let _fetch = envFetch || fetch;
  2802. responseType = responseType ? (responseType + '').toLowerCase() : 'text';
  2803. let composedSignal = composeSignals(
  2804. [signal, cancelToken && cancelToken.toAbortSignal()],
  2805. timeout
  2806. );
  2807. let request = null;
  2808. const unsubscribe =
  2809. composedSignal &&
  2810. composedSignal.unsubscribe &&
  2811. (() => {
  2812. composedSignal.unsubscribe();
  2813. });
  2814. let requestContentLength;
  2815. try {
  2816. if (
  2817. onUploadProgress &&
  2818. supportsRequestStream &&
  2819. method !== 'get' &&
  2820. method !== 'head' &&
  2821. (requestContentLength = await resolveBodyLength(headers, data)) !== 0
  2822. ) {
  2823. let _request = new Request(url, {
  2824. method: 'POST',
  2825. body: data,
  2826. duplex: 'half',
  2827. });
  2828. let contentTypeHeader;
  2829. if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
  2830. headers.setContentType(contentTypeHeader);
  2831. }
  2832. if (_request.body) {
  2833. const [onProgress, flush] = progressEventDecorator(
  2834. requestContentLength,
  2835. progressEventReducer(asyncDecorator(onUploadProgress))
  2836. );
  2837. data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
  2838. }
  2839. }
  2840. if (!utils$1.isString(withCredentials)) {
  2841. withCredentials = withCredentials ? 'include' : 'omit';
  2842. }
  2843. // Cloudflare Workers throws when credentials are defined
  2844. // see https://github.com/cloudflare/workerd/issues/902
  2845. const isCredentialsSupported = isRequestSupported && 'credentials' in Request.prototype;
  2846. // If data is FormData and Content-Type is multipart/form-data without boundary,
  2847. // delete it so fetch can set it correctly with the boundary
  2848. if (utils$1.isFormData(data)) {
  2849. const contentType = headers.getContentType();
  2850. if (
  2851. contentType &&
  2852. /^multipart\/form-data/i.test(contentType) &&
  2853. !/boundary=/i.test(contentType)
  2854. ) {
  2855. headers.delete('content-type');
  2856. }
  2857. }
  2858. const resolvedOptions = {
  2859. ...fetchOptions,
  2860. signal: composedSignal,
  2861. method: method.toUpperCase(),
  2862. headers: headers.normalize().toJSON(),
  2863. body: data,
  2864. duplex: 'half',
  2865. credentials: isCredentialsSupported ? withCredentials : undefined,
  2866. };
  2867. request = isRequestSupported && new Request(url, resolvedOptions);
  2868. let response = await (isRequestSupported
  2869. ? _fetch(request, fetchOptions)
  2870. : _fetch(url, resolvedOptions));
  2871. const isStreamResponse =
  2872. supportsResponseStream && (responseType === 'stream' || responseType === 'response');
  2873. if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
  2874. const options = {};
  2875. ['status', 'statusText', 'headers'].forEach((prop) => {
  2876. options[prop] = response[prop];
  2877. });
  2878. const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
  2879. const [onProgress, flush] =
  2880. (onDownloadProgress &&
  2881. progressEventDecorator(
  2882. responseContentLength,
  2883. progressEventReducer(asyncDecorator(onDownloadProgress), true)
  2884. )) ||
  2885. [];
  2886. response = new Response(
  2887. trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
  2888. flush && flush();
  2889. unsubscribe && unsubscribe();
  2890. }),
  2891. options
  2892. );
  2893. }
  2894. responseType = responseType || 'text';
  2895. let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](
  2896. response,
  2897. config
  2898. );
  2899. !isStreamResponse && unsubscribe && unsubscribe();
  2900. return await new Promise((resolve, reject) => {
  2901. settle(resolve, reject, {
  2902. data: responseData,
  2903. headers: AxiosHeaders.from(response.headers),
  2904. status: response.status,
  2905. statusText: response.statusText,
  2906. config,
  2907. request,
  2908. });
  2909. });
  2910. } catch (err) {
  2911. unsubscribe && unsubscribe();
  2912. if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
  2913. throw Object.assign(
  2914. new AxiosError(
  2915. 'Network Error',
  2916. AxiosError.ERR_NETWORK,
  2917. config,
  2918. request,
  2919. err && err.response
  2920. ),
  2921. {
  2922. cause: err.cause || err,
  2923. }
  2924. );
  2925. }
  2926. throw AxiosError.from(err, err && err.code, config, request, err && err.response);
  2927. }
  2928. };
  2929. };
  2930. const seedCache = new Map();
  2931. const getFetch = (config) => {
  2932. let env = (config && config.env) || {};
  2933. const { fetch, Request, Response } = env;
  2934. const seeds = [Request, Response, fetch];
  2935. let len = seeds.length,
  2936. i = len,
  2937. seed,
  2938. target,
  2939. map = seedCache;
  2940. while (i--) {
  2941. seed = seeds[i];
  2942. target = map.get(seed);
  2943. target === undefined && map.set(seed, (target = i ? new Map() : factory(env)));
  2944. map = target;
  2945. }
  2946. return target;
  2947. };
  2948. getFetch();
  2949. /**
  2950. * Known adapters mapping.
  2951. * Provides environment-specific adapters for Axios:
  2952. * - `http` for Node.js
  2953. * - `xhr` for browsers
  2954. * - `fetch` for fetch API-based requests
  2955. *
  2956. * @type {Object<string, Function|Object>}
  2957. */
  2958. const knownAdapters = {
  2959. http: httpAdapter,
  2960. xhr: xhrAdapter,
  2961. fetch: {
  2962. get: getFetch,
  2963. },
  2964. };
  2965. // Assign adapter names for easier debugging and identification
  2966. utils$1.forEach(knownAdapters, (fn, value) => {
  2967. if (fn) {
  2968. try {
  2969. Object.defineProperty(fn, 'name', { value });
  2970. } catch (e) {
  2971. // eslint-disable-next-line no-empty
  2972. }
  2973. Object.defineProperty(fn, 'adapterName', { value });
  2974. }
  2975. });
  2976. /**
  2977. * Render a rejection reason string for unknown or unsupported adapters
  2978. *
  2979. * @param {string} reason
  2980. * @returns {string}
  2981. */
  2982. const renderReason = (reason) => `- ${reason}`;
  2983. /**
  2984. * Check if the adapter is resolved (function, null, or false)
  2985. *
  2986. * @param {Function|null|false} adapter
  2987. * @returns {boolean}
  2988. */
  2989. const isResolvedHandle = (adapter) =>
  2990. utils$1.isFunction(adapter) || adapter === null || adapter === false;
  2991. /**
  2992. * Get the first suitable adapter from the provided list.
  2993. * Tries each adapter in order until a supported one is found.
  2994. * Throws an AxiosError if no adapter is suitable.
  2995. *
  2996. * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
  2997. * @param {Object} config - Axios request configuration
  2998. * @throws {AxiosError} If no suitable adapter is available
  2999. * @returns {Function} The resolved adapter function
  3000. */
  3001. function getAdapter(adapters, config) {
  3002. adapters = utils$1.isArray(adapters) ? adapters : [adapters];
  3003. const { length } = adapters;
  3004. let nameOrAdapter;
  3005. let adapter;
  3006. const rejectedReasons = {};
  3007. for (let i = 0; i < length; i++) {
  3008. nameOrAdapter = adapters[i];
  3009. let id;
  3010. adapter = nameOrAdapter;
  3011. if (!isResolvedHandle(nameOrAdapter)) {
  3012. adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
  3013. if (adapter === undefined) {
  3014. throw new AxiosError(`Unknown adapter '${id}'`);
  3015. }
  3016. }
  3017. if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
  3018. break;
  3019. }
  3020. rejectedReasons[id || '#' + i] = adapter;
  3021. }
  3022. if (!adapter) {
  3023. const reasons = Object.entries(rejectedReasons).map(
  3024. ([id, state]) =>
  3025. `adapter ${id} ` +
  3026. (state === false ? 'is not supported by the environment' : 'is not available in the build')
  3027. );
  3028. let s = length
  3029. ? reasons.length > 1
  3030. ? 'since :\n' + reasons.map(renderReason).join('\n')
  3031. : ' ' + renderReason(reasons[0])
  3032. : 'as no adapter specified';
  3033. throw new AxiosError(
  3034. `There is no suitable adapter to dispatch the request ` + s,
  3035. 'ERR_NOT_SUPPORT'
  3036. );
  3037. }
  3038. return adapter;
  3039. }
  3040. /**
  3041. * Exports Axios adapters and utility to resolve an adapter
  3042. */
  3043. var adapters = {
  3044. /**
  3045. * Resolve an adapter from a list of adapter names or functions.
  3046. * @type {Function}
  3047. */
  3048. getAdapter,
  3049. /**
  3050. * Exposes all known adapters
  3051. * @type {Object<string, Function|Object>}
  3052. */
  3053. adapters: knownAdapters,
  3054. };
  3055. /**
  3056. * Throws a `CanceledError` if cancellation has been requested.
  3057. *
  3058. * @param {Object} config The config that is to be used for the request
  3059. *
  3060. * @returns {void}
  3061. */
  3062. function throwIfCancellationRequested(config) {
  3063. if (config.cancelToken) {
  3064. config.cancelToken.throwIfRequested();
  3065. }
  3066. if (config.signal && config.signal.aborted) {
  3067. throw new CanceledError(null, config);
  3068. }
  3069. }
  3070. /**
  3071. * Dispatch a request to the server using the configured adapter.
  3072. *
  3073. * @param {object} config The config that is to be used for the request
  3074. *
  3075. * @returns {Promise} The Promise to be fulfilled
  3076. */
  3077. function dispatchRequest(config) {
  3078. throwIfCancellationRequested(config);
  3079. config.headers = AxiosHeaders.from(config.headers);
  3080. // Transform request data
  3081. config.data = transformData.call(config, config.transformRequest);
  3082. if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
  3083. config.headers.setContentType('application/x-www-form-urlencoded', false);
  3084. }
  3085. const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
  3086. return adapter(config).then(
  3087. function onAdapterResolution(response) {
  3088. throwIfCancellationRequested(config);
  3089. // Transform response data
  3090. response.data = transformData.call(config, config.transformResponse, response);
  3091. response.headers = AxiosHeaders.from(response.headers);
  3092. return response;
  3093. },
  3094. function onAdapterRejection(reason) {
  3095. if (!isCancel(reason)) {
  3096. throwIfCancellationRequested(config);
  3097. // Transform response data
  3098. if (reason && reason.response) {
  3099. reason.response.data = transformData.call(
  3100. config,
  3101. config.transformResponse,
  3102. reason.response
  3103. );
  3104. reason.response.headers = AxiosHeaders.from(reason.response.headers);
  3105. }
  3106. }
  3107. return Promise.reject(reason);
  3108. }
  3109. );
  3110. }
  3111. const VERSION = "1.15.2";
  3112. const validators$1 = {};
  3113. // eslint-disable-next-line func-names
  3114. ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
  3115. validators$1[type] = function validator(thing) {
  3116. return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
  3117. };
  3118. });
  3119. const deprecatedWarnings = {};
  3120. /**
  3121. * Transitional option validator
  3122. *
  3123. * @param {function|boolean?} validator - set to false if the transitional option has been removed
  3124. * @param {string?} version - deprecated version / removed since version
  3125. * @param {string?} message - some message with additional info
  3126. *
  3127. * @returns {function}
  3128. */
  3129. validators$1.transitional = function transitional(validator, version, message) {
  3130. function formatMessage(opt, desc) {
  3131. return (
  3132. '[Axios v' +
  3133. VERSION +
  3134. "] Transitional option '" +
  3135. opt +
  3136. "'" +
  3137. desc +
  3138. (message ? '. ' + message : '')
  3139. );
  3140. }
  3141. // eslint-disable-next-line func-names
  3142. return (value, opt, opts) => {
  3143. if (validator === false) {
  3144. throw new AxiosError(
  3145. formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
  3146. AxiosError.ERR_DEPRECATED
  3147. );
  3148. }
  3149. if (version && !deprecatedWarnings[opt]) {
  3150. deprecatedWarnings[opt] = true;
  3151. // eslint-disable-next-line no-console
  3152. console.warn(
  3153. formatMessage(
  3154. opt,
  3155. ' has been deprecated since v' + version + ' and will be removed in the near future'
  3156. )
  3157. );
  3158. }
  3159. return validator ? validator(value, opt, opts) : true;
  3160. };
  3161. };
  3162. validators$1.spelling = function spelling(correctSpelling) {
  3163. return (value, opt) => {
  3164. // eslint-disable-next-line no-console
  3165. console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
  3166. return true;
  3167. };
  3168. };
  3169. /**
  3170. * Assert object's properties type
  3171. *
  3172. * @param {object} options
  3173. * @param {object} schema
  3174. * @param {boolean?} allowUnknown
  3175. *
  3176. * @returns {object}
  3177. */
  3178. function assertOptions(options, schema, allowUnknown) {
  3179. if (typeof options !== 'object') {
  3180. throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
  3181. }
  3182. const keys = Object.keys(options);
  3183. let i = keys.length;
  3184. while (i-- > 0) {
  3185. const opt = keys[i];
  3186. // Use hasOwnProperty so a polluted Object.prototype.<opt> cannot supply
  3187. // a non-function validator and cause a TypeError. See GHSA-q8qp-cvcw-x6jj.
  3188. const validator = Object.prototype.hasOwnProperty.call(schema, opt) ? schema[opt] : undefined;
  3189. if (validator) {
  3190. const value = options[opt];
  3191. const result = value === undefined || validator(value, opt, options);
  3192. if (result !== true) {
  3193. throw new AxiosError(
  3194. 'option ' + opt + ' must be ' + result,
  3195. AxiosError.ERR_BAD_OPTION_VALUE
  3196. );
  3197. }
  3198. continue;
  3199. }
  3200. if (allowUnknown !== true) {
  3201. throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
  3202. }
  3203. }
  3204. }
  3205. var validator = {
  3206. assertOptions,
  3207. validators: validators$1,
  3208. };
  3209. const validators = validator.validators;
  3210. /**
  3211. * Create a new instance of Axios
  3212. *
  3213. * @param {Object} instanceConfig The default config for the instance
  3214. *
  3215. * @return {Axios} A new instance of Axios
  3216. */
  3217. class Axios {
  3218. constructor(instanceConfig) {
  3219. this.defaults = instanceConfig || {};
  3220. this.interceptors = {
  3221. request: new InterceptorManager(),
  3222. response: new InterceptorManager(),
  3223. };
  3224. }
  3225. /**
  3226. * Dispatch a request
  3227. *
  3228. * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
  3229. * @param {?Object} config
  3230. *
  3231. * @returns {Promise} The Promise to be fulfilled
  3232. */
  3233. async request(configOrUrl, config) {
  3234. try {
  3235. return await this._request(configOrUrl, config);
  3236. } catch (err) {
  3237. if (err instanceof Error) {
  3238. let dummy = {};
  3239. Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
  3240. // slice off the Error: ... line
  3241. const stack = (() => {
  3242. if (!dummy.stack) {
  3243. return '';
  3244. }
  3245. const firstNewlineIndex = dummy.stack.indexOf('\n');
  3246. return firstNewlineIndex === -1 ? '' : dummy.stack.slice(firstNewlineIndex + 1);
  3247. })();
  3248. try {
  3249. if (!err.stack) {
  3250. err.stack = stack;
  3251. // match without the 2 top stack lines
  3252. } else if (stack) {
  3253. const firstNewlineIndex = stack.indexOf('\n');
  3254. const secondNewlineIndex =
  3255. firstNewlineIndex === -1 ? -1 : stack.indexOf('\n', firstNewlineIndex + 1);
  3256. const stackWithoutTwoTopLines =
  3257. secondNewlineIndex === -1 ? '' : stack.slice(secondNewlineIndex + 1);
  3258. if (!String(err.stack).endsWith(stackWithoutTwoTopLines)) {
  3259. err.stack += '\n' + stack;
  3260. }
  3261. }
  3262. } catch (e) {
  3263. // ignore the case where "stack" is an un-writable property
  3264. }
  3265. }
  3266. throw err;
  3267. }
  3268. }
  3269. _request(configOrUrl, config) {
  3270. /*eslint no-param-reassign:0*/
  3271. // Allow for axios('example/url'[, config]) a la fetch API
  3272. if (typeof configOrUrl === 'string') {
  3273. config = config || {};
  3274. config.url = configOrUrl;
  3275. } else {
  3276. config = configOrUrl || {};
  3277. }
  3278. config = mergeConfig(this.defaults, config);
  3279. const { transitional, paramsSerializer, headers } = config;
  3280. if (transitional !== undefined) {
  3281. validator.assertOptions(
  3282. transitional,
  3283. {
  3284. silentJSONParsing: validators.transitional(validators.boolean),
  3285. forcedJSONParsing: validators.transitional(validators.boolean),
  3286. clarifyTimeoutError: validators.transitional(validators.boolean),
  3287. legacyInterceptorReqResOrdering: validators.transitional(validators.boolean),
  3288. },
  3289. false
  3290. );
  3291. }
  3292. if (paramsSerializer != null) {
  3293. if (utils$1.isFunction(paramsSerializer)) {
  3294. config.paramsSerializer = {
  3295. serialize: paramsSerializer,
  3296. };
  3297. } else {
  3298. validator.assertOptions(
  3299. paramsSerializer,
  3300. {
  3301. encode: validators.function,
  3302. serialize: validators.function,
  3303. },
  3304. true
  3305. );
  3306. }
  3307. }
  3308. // Set config.allowAbsoluteUrls
  3309. if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
  3310. config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
  3311. } else {
  3312. config.allowAbsoluteUrls = true;
  3313. }
  3314. validator.assertOptions(
  3315. config,
  3316. {
  3317. baseUrl: validators.spelling('baseURL'),
  3318. withXsrfToken: validators.spelling('withXSRFToken'),
  3319. },
  3320. true
  3321. );
  3322. // Set config.method
  3323. config.method = (config.method || this.defaults.method || 'get').toLowerCase();
  3324. // Flatten headers
  3325. let contextHeaders = headers && utils$1.merge(headers.common, headers[config.method]);
  3326. headers &&
  3327. utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], (method) => {
  3328. delete headers[method];
  3329. });
  3330. config.headers = AxiosHeaders.concat(contextHeaders, headers);
  3331. // filter out skipped interceptors
  3332. const requestInterceptorChain = [];
  3333. let synchronousRequestInterceptors = true;
  3334. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  3335. if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
  3336. return;
  3337. }
  3338. synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
  3339. const transitional = config.transitional || transitionalDefaults;
  3340. const legacyInterceptorReqResOrdering =
  3341. transitional && transitional.legacyInterceptorReqResOrdering;
  3342. if (legacyInterceptorReqResOrdering) {
  3343. requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
  3344. } else {
  3345. requestInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
  3346. }
  3347. });
  3348. const responseInterceptorChain = [];
  3349. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  3350. responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
  3351. });
  3352. let promise;
  3353. let i = 0;
  3354. let len;
  3355. if (!synchronousRequestInterceptors) {
  3356. const chain = [dispatchRequest.bind(this), undefined];
  3357. chain.unshift(...requestInterceptorChain);
  3358. chain.push(...responseInterceptorChain);
  3359. len = chain.length;
  3360. promise = Promise.resolve(config);
  3361. while (i < len) {
  3362. promise = promise.then(chain[i++], chain[i++]);
  3363. }
  3364. return promise;
  3365. }
  3366. len = requestInterceptorChain.length;
  3367. let newConfig = config;
  3368. while (i < len) {
  3369. const onFulfilled = requestInterceptorChain[i++];
  3370. const onRejected = requestInterceptorChain[i++];
  3371. try {
  3372. newConfig = onFulfilled(newConfig);
  3373. } catch (error) {
  3374. onRejected.call(this, error);
  3375. break;
  3376. }
  3377. }
  3378. try {
  3379. promise = dispatchRequest.call(this, newConfig);
  3380. } catch (error) {
  3381. return Promise.reject(error);
  3382. }
  3383. i = 0;
  3384. len = responseInterceptorChain.length;
  3385. while (i < len) {
  3386. promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
  3387. }
  3388. return promise;
  3389. }
  3390. getUri(config) {
  3391. config = mergeConfig(this.defaults, config);
  3392. const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
  3393. return buildURL(fullPath, config.params, config.paramsSerializer);
  3394. }
  3395. }
  3396. // Provide aliases for supported request methods
  3397. utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  3398. /*eslint func-names:0*/
  3399. Axios.prototype[method] = function (url, config) {
  3400. return this.request(
  3401. mergeConfig(config || {}, {
  3402. method,
  3403. url,
  3404. data: (config || {}).data,
  3405. })
  3406. );
  3407. };
  3408. });
  3409. utils$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  3410. function generateHTTPMethod(isForm) {
  3411. return function httpMethod(url, data, config) {
  3412. return this.request(
  3413. mergeConfig(config || {}, {
  3414. method,
  3415. headers: isForm
  3416. ? {
  3417. 'Content-Type': 'multipart/form-data',
  3418. }
  3419. : {},
  3420. url,
  3421. data,
  3422. })
  3423. );
  3424. };
  3425. }
  3426. Axios.prototype[method] = generateHTTPMethod();
  3427. Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
  3428. });
  3429. /**
  3430. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  3431. *
  3432. * @param {Function} executor The executor function.
  3433. *
  3434. * @returns {CancelToken}
  3435. */
  3436. class CancelToken {
  3437. constructor(executor) {
  3438. if (typeof executor !== 'function') {
  3439. throw new TypeError('executor must be a function.');
  3440. }
  3441. let resolvePromise;
  3442. this.promise = new Promise(function promiseExecutor(resolve) {
  3443. resolvePromise = resolve;
  3444. });
  3445. const token = this;
  3446. // eslint-disable-next-line func-names
  3447. this.promise.then((cancel) => {
  3448. if (!token._listeners) return;
  3449. let i = token._listeners.length;
  3450. while (i-- > 0) {
  3451. token._listeners[i](cancel);
  3452. }
  3453. token._listeners = null;
  3454. });
  3455. // eslint-disable-next-line func-names
  3456. this.promise.then = (onfulfilled) => {
  3457. let _resolve;
  3458. // eslint-disable-next-line func-names
  3459. const promise = new Promise((resolve) => {
  3460. token.subscribe(resolve);
  3461. _resolve = resolve;
  3462. }).then(onfulfilled);
  3463. promise.cancel = function reject() {
  3464. token.unsubscribe(_resolve);
  3465. };
  3466. return promise;
  3467. };
  3468. executor(function cancel(message, config, request) {
  3469. if (token.reason) {
  3470. // Cancellation has already been requested
  3471. return;
  3472. }
  3473. token.reason = new CanceledError(message, config, request);
  3474. resolvePromise(token.reason);
  3475. });
  3476. }
  3477. /**
  3478. * Throws a `CanceledError` if cancellation has been requested.
  3479. */
  3480. throwIfRequested() {
  3481. if (this.reason) {
  3482. throw this.reason;
  3483. }
  3484. }
  3485. /**
  3486. * Subscribe to the cancel signal
  3487. */
  3488. subscribe(listener) {
  3489. if (this.reason) {
  3490. listener(this.reason);
  3491. return;
  3492. }
  3493. if (this._listeners) {
  3494. this._listeners.push(listener);
  3495. } else {
  3496. this._listeners = [listener];
  3497. }
  3498. }
  3499. /**
  3500. * Unsubscribe from the cancel signal
  3501. */
  3502. unsubscribe(listener) {
  3503. if (!this._listeners) {
  3504. return;
  3505. }
  3506. const index = this._listeners.indexOf(listener);
  3507. if (index !== -1) {
  3508. this._listeners.splice(index, 1);
  3509. }
  3510. }
  3511. toAbortSignal() {
  3512. const controller = new AbortController();
  3513. const abort = (err) => {
  3514. controller.abort(err);
  3515. };
  3516. this.subscribe(abort);
  3517. controller.signal.unsubscribe = () => this.unsubscribe(abort);
  3518. return controller.signal;
  3519. }
  3520. /**
  3521. * Returns an object that contains a new `CancelToken` and a function that, when called,
  3522. * cancels the `CancelToken`.
  3523. */
  3524. static source() {
  3525. let cancel;
  3526. const token = new CancelToken(function executor(c) {
  3527. cancel = c;
  3528. });
  3529. return {
  3530. token,
  3531. cancel,
  3532. };
  3533. }
  3534. }
  3535. /**
  3536. * Syntactic sugar for invoking a function and expanding an array for arguments.
  3537. *
  3538. * Common use case would be to use `Function.prototype.apply`.
  3539. *
  3540. * ```js
  3541. * function f(x, y, z) {}
  3542. * const args = [1, 2, 3];
  3543. * f.apply(null, args);
  3544. * ```
  3545. *
  3546. * With `spread` this example can be re-written.
  3547. *
  3548. * ```js
  3549. * spread(function(x, y, z) {})([1, 2, 3]);
  3550. * ```
  3551. *
  3552. * @param {Function} callback
  3553. *
  3554. * @returns {Function}
  3555. */
  3556. function spread(callback) {
  3557. return function wrap(arr) {
  3558. return callback.apply(null, arr);
  3559. };
  3560. }
  3561. /**
  3562. * Determines whether the payload is an error thrown by Axios
  3563. *
  3564. * @param {*} payload The value to test
  3565. *
  3566. * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
  3567. */
  3568. function isAxiosError(payload) {
  3569. return utils$1.isObject(payload) && payload.isAxiosError === true;
  3570. }
  3571. const HttpStatusCode = {
  3572. Continue: 100,
  3573. SwitchingProtocols: 101,
  3574. Processing: 102,
  3575. EarlyHints: 103,
  3576. Ok: 200,
  3577. Created: 201,
  3578. Accepted: 202,
  3579. NonAuthoritativeInformation: 203,
  3580. NoContent: 204,
  3581. ResetContent: 205,
  3582. PartialContent: 206,
  3583. MultiStatus: 207,
  3584. AlreadyReported: 208,
  3585. ImUsed: 226,
  3586. MultipleChoices: 300,
  3587. MovedPermanently: 301,
  3588. Found: 302,
  3589. SeeOther: 303,
  3590. NotModified: 304,
  3591. UseProxy: 305,
  3592. Unused: 306,
  3593. TemporaryRedirect: 307,
  3594. PermanentRedirect: 308,
  3595. BadRequest: 400,
  3596. Unauthorized: 401,
  3597. PaymentRequired: 402,
  3598. Forbidden: 403,
  3599. NotFound: 404,
  3600. MethodNotAllowed: 405,
  3601. NotAcceptable: 406,
  3602. ProxyAuthenticationRequired: 407,
  3603. RequestTimeout: 408,
  3604. Conflict: 409,
  3605. Gone: 410,
  3606. LengthRequired: 411,
  3607. PreconditionFailed: 412,
  3608. PayloadTooLarge: 413,
  3609. UriTooLong: 414,
  3610. UnsupportedMediaType: 415,
  3611. RangeNotSatisfiable: 416,
  3612. ExpectationFailed: 417,
  3613. ImATeapot: 418,
  3614. MisdirectedRequest: 421,
  3615. UnprocessableEntity: 422,
  3616. Locked: 423,
  3617. FailedDependency: 424,
  3618. TooEarly: 425,
  3619. UpgradeRequired: 426,
  3620. PreconditionRequired: 428,
  3621. TooManyRequests: 429,
  3622. RequestHeaderFieldsTooLarge: 431,
  3623. UnavailableForLegalReasons: 451,
  3624. InternalServerError: 500,
  3625. NotImplemented: 501,
  3626. BadGateway: 502,
  3627. ServiceUnavailable: 503,
  3628. GatewayTimeout: 504,
  3629. HttpVersionNotSupported: 505,
  3630. VariantAlsoNegotiates: 506,
  3631. InsufficientStorage: 507,
  3632. LoopDetected: 508,
  3633. NotExtended: 510,
  3634. NetworkAuthenticationRequired: 511,
  3635. WebServerIsDown: 521,
  3636. ConnectionTimedOut: 522,
  3637. OriginIsUnreachable: 523,
  3638. TimeoutOccurred: 524,
  3639. SslHandshakeFailed: 525,
  3640. InvalidSslCertificate: 526,
  3641. };
  3642. Object.entries(HttpStatusCode).forEach(([key, value]) => {
  3643. HttpStatusCode[value] = key;
  3644. });
  3645. /**
  3646. * Create an instance of Axios
  3647. *
  3648. * @param {Object} defaultConfig The default config for the instance
  3649. *
  3650. * @returns {Axios} A new instance of Axios
  3651. */
  3652. function createInstance(defaultConfig) {
  3653. const context = new Axios(defaultConfig);
  3654. const instance = bind(Axios.prototype.request, context);
  3655. // Copy axios.prototype to instance
  3656. utils$1.extend(instance, Axios.prototype, context, { allOwnKeys: true });
  3657. // Copy context to instance
  3658. utils$1.extend(instance, context, null, { allOwnKeys: true });
  3659. // Factory for creating new instances
  3660. instance.create = function create(instanceConfig) {
  3661. return createInstance(mergeConfig(defaultConfig, instanceConfig));
  3662. };
  3663. return instance;
  3664. }
  3665. // Create the default instance to be exported
  3666. const axios = createInstance(defaults);
  3667. // Expose Axios class to allow class inheritance
  3668. axios.Axios = Axios;
  3669. // Expose Cancel & CancelToken
  3670. axios.CanceledError = CanceledError;
  3671. axios.CancelToken = CancelToken;
  3672. axios.isCancel = isCancel;
  3673. axios.VERSION = VERSION;
  3674. axios.toFormData = toFormData;
  3675. // Expose AxiosError class
  3676. axios.AxiosError = AxiosError;
  3677. // alias for CanceledError for backward compatibility
  3678. axios.Cancel = axios.CanceledError;
  3679. // Expose all/spread
  3680. axios.all = function all(promises) {
  3681. return Promise.all(promises);
  3682. };
  3683. axios.spread = spread;
  3684. // Expose isAxiosError
  3685. axios.isAxiosError = isAxiosError;
  3686. // Expose mergeConfig
  3687. axios.mergeConfig = mergeConfig;
  3688. axios.AxiosHeaders = AxiosHeaders;
  3689. axios.formToJSON = (thing) => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
  3690. axios.getAdapter = adapters.getAdapter;
  3691. axios.HttpStatusCode = HttpStatusCode;
  3692. axios.default = axios;
  3693. module.exports = axios;
  3694. //# sourceMappingURL=axios.cjs.map