axios.cjs 95 KB

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