axios.js 95 KB

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