axios.js 96 KB

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