axios.js 94 KB

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