axios.cjs 96 KB

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