axios.js 95 KB

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