axios.js 82 KB

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