axios.cjs 112 KB

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