axios.js 93 KB

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