axios.cjs 107 KB

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