59178ba470d2e637f4b31dec095b95c539d78cd59460788be89165aa85b82dbd88a0155f8540ca8652f7158be88c8138cdec30933071ffd5e8b039f2c8d90d 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377
  1. // axios v0.28.1 Copyright (c) 2024 Matt Zabriskie
  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. var bind = function bind(fn, thisArg) {
  8. return function wrap() {
  9. return fn.apply(thisArg, arguments);
  10. };
  11. };
  12. // utils is a library of generic helper functions non-specific to axios
  13. var toString = Object.prototype.toString;
  14. // eslint-disable-next-line func-names
  15. var kindOf = (function(cache) {
  16. // eslint-disable-next-line func-names
  17. return function(thing) {
  18. var str = toString.call(thing);
  19. return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
  20. };
  21. })(Object.create(null));
  22. function kindOfTest(type) {
  23. type = type.toLowerCase();
  24. return function isKindOf(thing) {
  25. return kindOf(thing) === type;
  26. };
  27. }
  28. /**
  29. * Determine if a value is an Array
  30. *
  31. * @param {Object} val The value to test
  32. * @returns {boolean} True if value is an Array, otherwise false
  33. */
  34. function isArray(val) {
  35. return Array.isArray(val);
  36. }
  37. /**
  38. * Determine if a value is undefined
  39. *
  40. * @param {Object} val The value to test
  41. * @returns {boolean} True if the value is undefined, otherwise false
  42. */
  43. function isUndefined(val) {
  44. return typeof val === 'undefined';
  45. }
  46. /**
  47. * Determine if a value is a Buffer
  48. *
  49. * @param {Object} val The value to test
  50. * @returns {boolean} True if value is a Buffer, otherwise false
  51. */
  52. function isBuffer(val) {
  53. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  54. && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
  55. }
  56. /**
  57. * Determine if a value is an ArrayBuffer
  58. *
  59. * @function
  60. * @param {Object} val The value to test
  61. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  62. */
  63. var isArrayBuffer = kindOfTest('ArrayBuffer');
  64. /**
  65. * Determine if a value is a view on an ArrayBuffer
  66. *
  67. * @param {Object} val The value to test
  68. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  69. */
  70. function isArrayBufferView(val) {
  71. var result;
  72. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  73. result = ArrayBuffer.isView(val);
  74. } else {
  75. result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
  76. }
  77. return result;
  78. }
  79. /**
  80. * Determine if a value is a String
  81. *
  82. * @param {Object} val The value to test
  83. * @returns {boolean} True if value is a String, otherwise false
  84. */
  85. function isString(val) {
  86. return typeof val === 'string';
  87. }
  88. /**
  89. * Determine if a value is a Number
  90. *
  91. * @param {Object} val The value to test
  92. * @returns {boolean} True if value is a Number, otherwise false
  93. */
  94. function isNumber(val) {
  95. return typeof val === 'number';
  96. }
  97. /**
  98. * Determine if a value is an Object
  99. *
  100. * @param {Object} val The value to test
  101. * @returns {boolean} True if value is an Object, otherwise false
  102. */
  103. function isObject(val) {
  104. return val !== null && typeof val === 'object';
  105. }
  106. /**
  107. * Determine if a value is a plain Object
  108. *
  109. * @param {Object} val The value to test
  110. * @return {boolean} True if value is a plain Object, otherwise false
  111. */
  112. function isPlainObject(val) {
  113. if (kindOf(val) !== 'object') {
  114. return false;
  115. }
  116. var prototype = Object.getPrototypeOf(val);
  117. return prototype === null || prototype === Object.prototype;
  118. }
  119. /**
  120. * Determine if a value is a empty Object
  121. *
  122. * @param {Object} val The value to test
  123. * @return {boolean} True if value is a empty Object, otherwise false
  124. */
  125. function isEmptyObject(val) {
  126. return val && Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
  127. }
  128. /**
  129. * Determine if a value is a Date
  130. *
  131. * @function
  132. * @param {Object} val The value to test
  133. * @returns {boolean} True if value is a Date, otherwise false
  134. */
  135. var isDate = kindOfTest('Date');
  136. /**
  137. * Determine if a value is a File
  138. *
  139. * @function
  140. * @param {Object} val The value to test
  141. * @returns {boolean} True if value is a File, otherwise false
  142. */
  143. var isFile = kindOfTest('File');
  144. /**
  145. * Determine if a value is a Blob
  146. *
  147. * @function
  148. * @param {Object} val The value to test
  149. * @returns {boolean} True if value is a Blob, otherwise false
  150. */
  151. var isBlob = kindOfTest('Blob');
  152. /**
  153. * Determine if a value is a FileList
  154. *
  155. * @function
  156. * @param {Object} val The value to test
  157. * @returns {boolean} True if value is a File, otherwise false
  158. */
  159. var isFileList = kindOfTest('FileList');
  160. /**
  161. * Determine if a value is a Function
  162. *
  163. * @param {Object} val The value to test
  164. * @returns {boolean} True if value is a Function, otherwise false
  165. */
  166. function isFunction(val) {
  167. return toString.call(val) === '[object Function]';
  168. }
  169. /**
  170. * Determine if a value is a Stream
  171. *
  172. * @param {Object} val The value to test
  173. * @returns {boolean} True if value is a Stream, otherwise false
  174. */
  175. function isStream(val) {
  176. return isObject(val) && isFunction(val.pipe);
  177. }
  178. /**
  179. * Determine if a value is a FormData
  180. *
  181. * @param {Object} thing The value to test
  182. * @returns {boolean} True if value is an FormData, otherwise false
  183. */
  184. function isFormData(thing) {
  185. var pattern = '[object FormData]';
  186. return thing && (
  187. (typeof FormData === 'function' && thing instanceof FormData) ||
  188. toString.call(thing) === pattern ||
  189. (isFunction(thing.toString) && thing.toString() === pattern)
  190. );
  191. }
  192. /**
  193. * Determine if a value is a URLSearchParams object
  194. * @function
  195. * @param {Object} val The value to test
  196. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  197. */
  198. var isURLSearchParams = kindOfTest('URLSearchParams');
  199. /**
  200. * Trim excess whitespace off the beginning and end of a string
  201. *
  202. * @param {String} str The String to trim
  203. * @returns {String} The String freed of excess whitespace
  204. */
  205. function trim(str) {
  206. return str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  207. }
  208. /**
  209. * Determine if we're running in a standard browser environment
  210. *
  211. * This allows axios to run in a web worker, and react-native.
  212. * Both environments support XMLHttpRequest, but not fully standard globals.
  213. *
  214. * web workers:
  215. * typeof window -> undefined
  216. * typeof document -> undefined
  217. *
  218. * react-native:
  219. * navigator.product -> 'ReactNative'
  220. * nativescript
  221. * navigator.product -> 'NativeScript' or 'NS'
  222. */
  223. function isStandardBrowserEnv() {
  224. var product;
  225. if (typeof navigator !== 'undefined' && (
  226. (product = navigator.product) === 'ReactNative' ||
  227. product === 'NativeScript' ||
  228. product === 'NS')
  229. ) {
  230. return false;
  231. }
  232. return typeof window !== 'undefined' && typeof document !== 'undefined';
  233. }
  234. /**
  235. * Iterate over an Array or an Object invoking a function for each item.
  236. *
  237. * If `obj` is an Array callback will be called passing
  238. * the value, index, and complete array for each item.
  239. *
  240. * If 'obj' is an Object callback will be called passing
  241. * the value, key, and complete object for each property.
  242. *
  243. * @param {Object|Array} obj The object to iterate
  244. * @param {Function} fn The callback to invoke for each item
  245. */
  246. function forEach(obj, fn) {
  247. // Don't bother if no value provided
  248. if (obj === null || typeof obj === 'undefined') {
  249. return;
  250. }
  251. // Force an array if not already something iterable
  252. if (typeof obj !== 'object') {
  253. /*eslint no-param-reassign:0*/
  254. obj = [obj];
  255. }
  256. if (isArray(obj)) {
  257. // Iterate over array values
  258. for (var i = 0, l = obj.length; i < l; i++) {
  259. fn.call(null, obj[i], i, obj);
  260. }
  261. } else {
  262. // Iterate over object keys
  263. for (var key in obj) {
  264. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  265. fn.call(null, obj[key], key, obj);
  266. }
  267. }
  268. }
  269. }
  270. /**
  271. * Accepts varargs expecting each argument to be an object, then
  272. * immutably merges the properties of each object and returns result.
  273. *
  274. * When multiple objects contain the same key the later object in
  275. * the arguments list will take precedence.
  276. *
  277. * Example:
  278. *
  279. * ```js
  280. * var result = merge({foo: 123}, {foo: 456});
  281. * console.log(result.foo); // outputs 456
  282. * ```
  283. *
  284. * @param {Object} obj1 Object to merge
  285. * @returns {Object} Result of all merge properties
  286. */
  287. function merge(/* obj1, obj2, obj3, ... */) {
  288. var result = {};
  289. function assignValue(val, key) {
  290. if (isPlainObject(result[key]) && isPlainObject(val)) {
  291. result[key] = merge(result[key], val);
  292. } else if (isPlainObject(val)) {
  293. result[key] = merge({}, val);
  294. } else if (isArray(val)) {
  295. result[key] = val.slice();
  296. } else {
  297. result[key] = val;
  298. }
  299. }
  300. for (var i = 0, l = arguments.length; i < l; i++) {
  301. forEach(arguments[i], assignValue);
  302. }
  303. return result;
  304. }
  305. /**
  306. * Extends object a by mutably adding to it the properties of object b.
  307. *
  308. * @param {Object} a The object to be extended
  309. * @param {Object} b The object to copy properties from
  310. * @param {Object} thisArg The object to bind function to
  311. * @return {Object} The resulting value of object a
  312. */
  313. function extend(a, b, thisArg) {
  314. forEach(b, function assignValue(val, key) {
  315. if (thisArg && typeof val === 'function') {
  316. a[key] = bind(val, thisArg);
  317. } else {
  318. a[key] = val;
  319. }
  320. });
  321. return a;
  322. }
  323. /**
  324. * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  325. *
  326. * @param {string} content with BOM
  327. * @return {string} content value without BOM
  328. */
  329. function stripBOM(content) {
  330. if (content.charCodeAt(0) === 0xFEFF) {
  331. content = content.slice(1);
  332. }
  333. return content;
  334. }
  335. /**
  336. * Inherit the prototype methods from one constructor into another
  337. * @param {function} constructor
  338. * @param {function} superConstructor
  339. * @param {object} [props]
  340. * @param {object} [descriptors]
  341. */
  342. function inherits(constructor, superConstructor, props, descriptors) {
  343. constructor.prototype = Object.create(superConstructor.prototype, descriptors);
  344. constructor.prototype.constructor = constructor;
  345. props && Object.assign(constructor.prototype, props);
  346. }
  347. /**
  348. * Resolve object with deep prototype chain to a flat object
  349. * @param {Object} sourceObj source object
  350. * @param {Object} [destObj]
  351. * @param {Function|Boolean} [filter]
  352. * @param {Function} [propFilter]
  353. * @returns {Object}
  354. */
  355. function toFlatObject(sourceObj, destObj, filter, propFilter) {
  356. var props;
  357. var i;
  358. var prop;
  359. var merged = {};
  360. destObj = destObj || {};
  361. // eslint-disable-next-line no-eq-null,eqeqeq
  362. if (sourceObj == null) return destObj;
  363. do {
  364. props = Object.getOwnPropertyNames(sourceObj);
  365. i = props.length;
  366. while (i-- > 0) {
  367. prop = props[i];
  368. if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
  369. destObj[prop] = sourceObj[prop];
  370. merged[prop] = true;
  371. }
  372. }
  373. sourceObj = filter !== false && Object.getPrototypeOf(sourceObj);
  374. } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
  375. return destObj;
  376. }
  377. /*
  378. * determines whether a string ends with the characters of a specified string
  379. * @param {String} str
  380. * @param {String} searchString
  381. * @param {Number} [position= 0]
  382. * @returns {boolean}
  383. */
  384. function endsWith(str, searchString, position) {
  385. str = String(str);
  386. if (position === undefined || position > str.length) {
  387. position = str.length;
  388. }
  389. position -= searchString.length;
  390. var lastIndex = str.indexOf(searchString, position);
  391. return lastIndex !== -1 && lastIndex === position;
  392. }
  393. /**
  394. * Returns new array from array like object or null if failed
  395. * @param {*} [thing]
  396. * @returns {?Array}
  397. */
  398. function toArray(thing) {
  399. if (!thing) return null;
  400. if (isArray(thing)) return thing;
  401. var i = thing.length;
  402. if (!isNumber(i)) return null;
  403. var arr = new Array(i);
  404. while (i-- > 0) {
  405. arr[i] = thing[i];
  406. }
  407. return arr;
  408. }
  409. // eslint-disable-next-line func-names
  410. var isTypedArray = (function(TypedArray) {
  411. // eslint-disable-next-line func-names
  412. return function(thing) {
  413. return TypedArray && thing instanceof TypedArray;
  414. };
  415. })(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
  416. function forEachEntry(obj, fn) {
  417. var generator = obj && obj[Symbol.iterator];
  418. var iterator = generator.call(obj);
  419. var result;
  420. while ((result = iterator.next()) && !result.done) {
  421. var pair = result.value;
  422. fn.call(obj, pair[0], pair[1]);
  423. }
  424. }
  425. function matchAll(regExp, str) {
  426. var matches;
  427. var arr = [];
  428. while ((matches = regExp.exec(str)) !== null) {
  429. arr.push(matches);
  430. }
  431. return arr;
  432. }
  433. var isHTMLForm = kindOfTest('HTMLFormElement');
  434. var hasOwnProperty = (function resolver(_hasOwnProperty) {
  435. return function(obj, prop) {
  436. return _hasOwnProperty.call(obj, prop);
  437. };
  438. })(Object.prototype.hasOwnProperty);
  439. var utils = {
  440. isArray: isArray,
  441. isArrayBuffer: isArrayBuffer,
  442. isBuffer: isBuffer,
  443. isFormData: isFormData,
  444. isArrayBufferView: isArrayBufferView,
  445. isString: isString,
  446. isNumber: isNumber,
  447. isObject: isObject,
  448. isPlainObject: isPlainObject,
  449. isEmptyObject: isEmptyObject,
  450. isUndefined: isUndefined,
  451. isDate: isDate,
  452. isFile: isFile,
  453. isBlob: isBlob,
  454. isFunction: isFunction,
  455. isStream: isStream,
  456. isURLSearchParams: isURLSearchParams,
  457. isStandardBrowserEnv: isStandardBrowserEnv,
  458. forEach: forEach,
  459. merge: merge,
  460. extend: extend,
  461. trim: trim,
  462. stripBOM: stripBOM,
  463. inherits: inherits,
  464. toFlatObject: toFlatObject,
  465. kindOf: kindOf,
  466. kindOfTest: kindOfTest,
  467. endsWith: endsWith,
  468. toArray: toArray,
  469. isTypedArray: isTypedArray,
  470. isFileList: isFileList,
  471. forEachEntry: forEachEntry,
  472. matchAll: matchAll,
  473. isHTMLForm: isHTMLForm,
  474. hasOwnProperty: hasOwnProperty
  475. };
  476. /**
  477. * Create an Error with the specified message, config, error code, request and response.
  478. *
  479. * @param {string} message The error message.
  480. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  481. * @param {Object} [config] The config.
  482. * @param {Object} [request] The request.
  483. * @param {Object} [response] The response.
  484. * @returns {Error} The created error.
  485. */
  486. function AxiosError(message, code, config, request, response) {
  487. Error.call(this);
  488. if (Error.captureStackTrace) {
  489. Error.captureStackTrace(this, this.constructor);
  490. } else {
  491. this.stack = (new Error()).stack;
  492. }
  493. this.message = message;
  494. this.name = 'AxiosError';
  495. code && (this.code = code);
  496. config && (this.config = config);
  497. request && (this.request = request);
  498. response && (this.response = response);
  499. }
  500. utils.inherits(AxiosError, Error, {
  501. toJSON: function toJSON() {
  502. return {
  503. // Standard
  504. message: this.message,
  505. name: this.name,
  506. // Microsoft
  507. description: this.description,
  508. number: this.number,
  509. // Mozilla
  510. fileName: this.fileName,
  511. lineNumber: this.lineNumber,
  512. columnNumber: this.columnNumber,
  513. stack: this.stack,
  514. // Axios
  515. config: this.config,
  516. code: this.code,
  517. status: this.response && this.response.status ? this.response.status : null
  518. };
  519. }
  520. });
  521. var prototype$1 = AxiosError.prototype;
  522. var descriptors = {};
  523. [
  524. 'ERR_BAD_OPTION_VALUE',
  525. 'ERR_BAD_OPTION',
  526. 'ECONNABORTED',
  527. 'ETIMEDOUT',
  528. 'ERR_NETWORK',
  529. 'ERR_FR_TOO_MANY_REDIRECTS',
  530. 'ERR_DEPRECATED',
  531. 'ERR_BAD_RESPONSE',
  532. 'ERR_BAD_REQUEST',
  533. 'ERR_CANCELED',
  534. 'ERR_NOT_SUPPORT',
  535. 'ERR_INVALID_URL'
  536. // eslint-disable-next-line func-names
  537. ].forEach(function(code) {
  538. descriptors[code] = {value: code};
  539. });
  540. Object.defineProperties(AxiosError, descriptors);
  541. Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
  542. // eslint-disable-next-line func-names
  543. AxiosError.from = function(error, code, config, request, response, customProps) {
  544. var axiosError = Object.create(prototype$1);
  545. utils.toFlatObject(error, axiosError, function filter(obj) {
  546. return obj !== Error.prototype;
  547. });
  548. AxiosError.call(axiosError, error.message, code, config, request, response);
  549. axiosError.cause = error;
  550. axiosError.name = error.name;
  551. customProps && Object.assign(axiosError, customProps);
  552. return axiosError;
  553. };
  554. var AxiosError_1 = AxiosError;
  555. /* eslint-env browser */
  556. var browser$1 = typeof self == 'object' ? self.FormData : window.FormData;
  557. // eslint-disable-next-line strict
  558. var FormData$1 = browser$1;
  559. function isVisitable(thing) {
  560. return utils.isPlainObject(thing) || utils.isArray(thing);
  561. }
  562. function removeBrackets(key) {
  563. return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
  564. }
  565. function renderKey(path, key, dots) {
  566. if (!path) return key;
  567. return path.concat(key).map(function each(token, i) {
  568. // eslint-disable-next-line no-param-reassign
  569. token = removeBrackets(token);
  570. return !dots && i ? '[' + token + ']' : token;
  571. }).join(dots ? '.' : '');
  572. }
  573. function isFlatArray(arr) {
  574. return utils.isArray(arr) && !arr.some(isVisitable);
  575. }
  576. var predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
  577. return /^is[A-Z]/.test(prop);
  578. });
  579. function isSpecCompliant(thing) {
  580. return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
  581. }
  582. /**
  583. * Convert a data object to FormData
  584. * @param {Object} obj
  585. * @param {?Object} [formData]
  586. * @param {?Object} [options]
  587. * @param {Function} [options.visitor]
  588. * @param {Boolean} [options.metaTokens = true]
  589. * @param {Boolean} [options.dots = false]
  590. * @param {?Boolean} [options.indexes = false]
  591. * @returns {Object}
  592. **/
  593. function toFormData(obj, formData, options) {
  594. if (!utils.isObject(obj)) {
  595. throw new TypeError('target must be an object');
  596. }
  597. // eslint-disable-next-line no-param-reassign
  598. formData = formData || new (FormData$1 || FormData)();
  599. // eslint-disable-next-line no-param-reassign
  600. options = utils.toFlatObject(options, {
  601. metaTokens: true,
  602. dots: false,
  603. indexes: false
  604. }, false, function defined(option, source) {
  605. // eslint-disable-next-line no-eq-null,eqeqeq
  606. return !utils.isUndefined(source[option]);
  607. });
  608. var metaTokens = options.metaTokens;
  609. // eslint-disable-next-line no-use-before-define
  610. var visitor = options.visitor || defaultVisitor;
  611. var dots = options.dots;
  612. var indexes = options.indexes;
  613. var _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
  614. var useBlob = _Blob && isSpecCompliant(formData);
  615. if (!utils.isFunction(visitor)) {
  616. throw new TypeError('visitor must be a function');
  617. }
  618. function convertValue(value) {
  619. if (value === null) return '';
  620. if (utils.isDate(value)) {
  621. return value.toISOString();
  622. }
  623. if (!useBlob && utils.isBlob(value)) {
  624. throw new AxiosError_1('Blob is not supported. Use a Buffer instead.');
  625. }
  626. if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
  627. return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
  628. }
  629. return value;
  630. }
  631. /**
  632. *
  633. * @param {*} value
  634. * @param {String|Number} key
  635. * @param {Array<String|Number>} path
  636. * @this {FormData}
  637. * @returns {boolean} return true to visit the each prop of the value recursively
  638. */
  639. function defaultVisitor(value, key, path) {
  640. var arr = value;
  641. if (value && !path && typeof value === 'object') {
  642. if (utils.endsWith(key, '{}')) {
  643. // eslint-disable-next-line no-param-reassign
  644. key = metaTokens ? key : key.slice(0, -2);
  645. // eslint-disable-next-line no-param-reassign
  646. value = JSON.stringify(value);
  647. } else if (
  648. (utils.isArray(value) && isFlatArray(value)) ||
  649. (utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
  650. )) {
  651. // eslint-disable-next-line no-param-reassign
  652. key = removeBrackets(key);
  653. arr.forEach(function each(el, index) {
  654. !utils.isUndefined(el) && formData.append(
  655. // eslint-disable-next-line no-nested-ternary
  656. indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
  657. convertValue(el)
  658. );
  659. });
  660. return false;
  661. }
  662. }
  663. if (isVisitable(value)) {
  664. return true;
  665. }
  666. formData.append(renderKey(path, key, dots), convertValue(value));
  667. return false;
  668. }
  669. var stack = [];
  670. var exposedHelpers = Object.assign(predicates, {
  671. defaultVisitor: defaultVisitor,
  672. convertValue: convertValue,
  673. isVisitable: isVisitable
  674. });
  675. function build(value, path) {
  676. if (utils.isUndefined(value)) return;
  677. if (stack.indexOf(value) !== -1) {
  678. throw Error('Circular reference detected in ' + path.join('.'));
  679. }
  680. stack.push(value);
  681. utils.forEach(value, function each(el, key) {
  682. var result = !utils.isUndefined(el) && visitor.call(
  683. formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
  684. );
  685. if (result === true) {
  686. build(el, path ? path.concat(key) : [key]);
  687. }
  688. });
  689. stack.pop();
  690. }
  691. if (!utils.isObject(obj)) {
  692. throw new TypeError('data must be an object');
  693. }
  694. build(obj);
  695. return formData;
  696. }
  697. var toFormData_1 = toFormData;
  698. function encode$1(str) {
  699. var charMap = {
  700. '!': '%21',
  701. "'": '%27',
  702. '(': '%28',
  703. ')': '%29',
  704. '~': '%7E',
  705. '%20': '+',
  706. '%00': '\x00'
  707. };
  708. return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) {
  709. return charMap[match];
  710. });
  711. }
  712. function AxiosURLSearchParams(params, options) {
  713. this._pairs = [];
  714. params && toFormData_1(params, this, options);
  715. }
  716. var prototype = AxiosURLSearchParams.prototype;
  717. prototype.append = function append(name, value) {
  718. this._pairs.push([name, value]);
  719. };
  720. prototype.toString = function toString(encoder) {
  721. var _encode = encoder ? function(value) {
  722. return encoder.call(this, value, encode$1);
  723. } : encode$1;
  724. return this._pairs.map(function each(pair) {
  725. return _encode(pair[0]) + '=' + _encode(pair[1]);
  726. }, '').join('&');
  727. };
  728. var AxiosURLSearchParams_1 = AxiosURLSearchParams;
  729. function encode(val) {
  730. return encodeURIComponent(val).
  731. replace(/%3A/gi, ':').
  732. replace(/%24/g, '$').
  733. replace(/%2C/gi, ',').
  734. replace(/%20/g, '+').
  735. replace(/%5B/gi, '[').
  736. replace(/%5D/gi, ']');
  737. }
  738. /**
  739. * Build a URL by appending params to the end
  740. *
  741. * @param {string} url The base of the url (e.g., http://www.google.com)
  742. * @param {object} [params] The params to be appended
  743. * @param {?object} options
  744. * @returns {string} The formatted url
  745. */
  746. var buildURL = function buildURL(url, params, options) {
  747. /*eslint no-param-reassign:0*/
  748. if (!params) {
  749. return url;
  750. }
  751. var hashmarkIndex = url.indexOf('#');
  752. if (hashmarkIndex !== -1) {
  753. url = url.slice(0, hashmarkIndex);
  754. }
  755. var _encode = options && options.encode || encode;
  756. var serializeFn = options && options.serialize;
  757. var serializedParams;
  758. if (serializeFn) {
  759. serializedParams = serializeFn(params, options);
  760. } else {
  761. serializedParams = utils.isURLSearchParams(params) ?
  762. params.toString() :
  763. new AxiosURLSearchParams_1(params, options).toString(_encode);
  764. }
  765. if (serializedParams) {
  766. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  767. }
  768. return url;
  769. };
  770. function InterceptorManager() {
  771. this.handlers = [];
  772. }
  773. /**
  774. * Add a new interceptor to the stack
  775. *
  776. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  777. * @param {Function} rejected The function to handle `reject` for a `Promise`
  778. *
  779. * @return {Number} An ID used to remove interceptor later
  780. */
  781. InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
  782. this.handlers.push({
  783. fulfilled: fulfilled,
  784. rejected: rejected,
  785. synchronous: options ? options.synchronous : false,
  786. runWhen: options ? options.runWhen : null
  787. });
  788. return this.handlers.length - 1;
  789. };
  790. /**
  791. * Remove an interceptor from the stack
  792. *
  793. * @param {Number} id The ID that was returned by `use`
  794. */
  795. InterceptorManager.prototype.eject = function eject(id) {
  796. if (this.handlers[id]) {
  797. this.handlers[id] = null;
  798. }
  799. };
  800. /**
  801. * Clear all interceptors from the stack
  802. */
  803. InterceptorManager.prototype.clear = function clear() {
  804. if (this.handlers) {
  805. this.handlers = [];
  806. }
  807. };
  808. /**
  809. * Iterate over all the registered interceptors
  810. *
  811. * This method is particularly useful for skipping over any
  812. * interceptors that may have become `null` calling `eject`.
  813. *
  814. * @param {Function} fn The function to call for each interceptor
  815. */
  816. InterceptorManager.prototype.forEach = function forEach(fn) {
  817. utils.forEach(this.handlers, function forEachHandler(h) {
  818. if (h !== null) {
  819. fn(h);
  820. }
  821. });
  822. };
  823. var InterceptorManager_1 = InterceptorManager;
  824. var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) {
  825. utils.forEach(headers, function processHeader(value, name) {
  826. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  827. headers[normalizedName] = value;
  828. delete headers[name];
  829. }
  830. });
  831. };
  832. var transitional = {
  833. silentJSONParsing: true,
  834. forcedJSONParsing: true,
  835. clarifyTimeoutError: false
  836. };
  837. var URLSearchParams_1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams_1;
  838. var FormData_1 = FormData;
  839. var browser = {
  840. isBrowser: true,
  841. classes: {
  842. URLSearchParams: URLSearchParams_1,
  843. FormData: FormData_1,
  844. Blob: Blob
  845. },
  846. protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
  847. };
  848. var platform = browser;
  849. var toURLEncodedForm = function toURLEncodedForm(data, options) {
  850. return toFormData_1(data, new platform.classes.URLSearchParams(), Object.assign({
  851. visitor: function(value, key, path, helpers) {
  852. if (platform.isNode && utils.isBuffer(value)) {
  853. this.append(key, value.toString('base64'));
  854. return false;
  855. }
  856. return helpers.defaultVisitor.apply(this, arguments);
  857. }
  858. }, options));
  859. };
  860. function parsePropPath(name) {
  861. // foo[x][y][z]
  862. // foo.x.y.z
  863. // foo-x-y-z
  864. // foo x y z
  865. return utils.matchAll(/\w+|\[(\w*)]/g, name).map(function(match) {
  866. return match[0] === '[]' ? '' : match[1] || match[0];
  867. });
  868. }
  869. function arrayToObject(arr) {
  870. var obj = {};
  871. var keys = Object.keys(arr);
  872. var i;
  873. var len = keys.length;
  874. var key;
  875. for (i = 0; i < len; i++) {
  876. key = keys[i];
  877. obj[key] = arr[key];
  878. }
  879. return obj;
  880. }
  881. function formDataToJSON(formData) {
  882. function buildPath(path, value, target, index) {
  883. var name = path[index++];
  884. var isNumericKey = Number.isFinite(+name);
  885. var isLast = index >= path.length;
  886. name = !name && utils.isArray(target) ? target.length : name;
  887. if (isLast) {
  888. if (utils.hasOwnProperty(target, name)) {
  889. target[name] = [target[name], value];
  890. } else {
  891. target[name] = value;
  892. }
  893. return !isNumericKey;
  894. }
  895. if (!target[name] || !utils.isObject(target[name])) {
  896. target[name] = [];
  897. }
  898. var result = buildPath(path, value, target[name], index);
  899. if (result && utils.isArray(target[name])) {
  900. target[name] = arrayToObject(target[name]);
  901. }
  902. return !isNumericKey;
  903. }
  904. if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
  905. var obj = {};
  906. utils.forEachEntry(formData, function(name, value) {
  907. buildPath(parsePropPath(name), value, obj, 0);
  908. });
  909. return obj;
  910. }
  911. return null;
  912. }
  913. var formDataToJSON_1 = formDataToJSON;
  914. /**
  915. * Resolve or reject a Promise based on response status.
  916. *
  917. * @param {Function} resolve A function that resolves the promise.
  918. * @param {Function} reject A function that rejects the promise.
  919. * @param {object} response The response.
  920. */
  921. var settle = function settle(resolve, reject, response) {
  922. var validateStatus = response.config.validateStatus;
  923. if (!response.status || !validateStatus || validateStatus(response.status)) {
  924. resolve(response);
  925. } else {
  926. reject(new AxiosError_1(
  927. 'Request failed with status code ' + response.status,
  928. [AxiosError_1.ERR_BAD_REQUEST, AxiosError_1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
  929. response.config,
  930. response.request,
  931. response
  932. ));
  933. }
  934. };
  935. var cookies = (
  936. utils.isStandardBrowserEnv() ?
  937. // Standard browser envs support document.cookie
  938. (function standardBrowserEnv() {
  939. return {
  940. write: function write(name, value, expires, path, domain, secure) {
  941. var cookie = [];
  942. cookie.push(name + '=' + encodeURIComponent(value));
  943. if (utils.isNumber(expires)) {
  944. cookie.push('expires=' + new Date(expires).toGMTString());
  945. }
  946. if (utils.isString(path)) {
  947. cookie.push('path=' + path);
  948. }
  949. if (utils.isString(domain)) {
  950. cookie.push('domain=' + domain);
  951. }
  952. if (secure === true) {
  953. cookie.push('secure');
  954. }
  955. document.cookie = cookie.join('; ');
  956. },
  957. read: function read(name) {
  958. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  959. return (match ? decodeURIComponent(match[3]) : null);
  960. },
  961. remove: function remove(name) {
  962. this.write(name, '', Date.now() - 86400000);
  963. }
  964. };
  965. })() :
  966. // Non standard browser env (web workers, react-native) lack needed support.
  967. (function nonStandardBrowserEnv() {
  968. return {
  969. write: function write() {},
  970. read: function read() { return null; },
  971. remove: function remove() {}
  972. };
  973. })()
  974. );
  975. /**
  976. * Determines whether the specified URL is absolute
  977. *
  978. * @param {string} url The URL to test
  979. * @returns {boolean} True if the specified URL is absolute, otherwise false
  980. */
  981. var isAbsoluteURL = function isAbsoluteURL(url) {
  982. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  983. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  984. // by any combination of letters, digits, plus, period, or hyphen.
  985. return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
  986. };
  987. /**
  988. * Creates a new URL by combining the specified URLs
  989. *
  990. * @param {string} baseURL The base URL
  991. * @param {string} relativeURL The relative URL
  992. * @returns {string} The combined URL
  993. */
  994. var combineURLs = function combineURLs(baseURL, relativeURL) {
  995. return relativeURL
  996. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  997. : baseURL;
  998. };
  999. /**
  1000. * Creates a new URL by combining the baseURL with the requestedURL,
  1001. * only when the requestedURL is not already an absolute URL.
  1002. * If the requestURL is absolute, this function returns the requestedURL untouched.
  1003. *
  1004. * @param {string} baseURL The base URL
  1005. * @param {string} requestedURL Absolute or relative URL to combine
  1006. * @returns {string} The combined full path
  1007. */
  1008. var buildFullPath = function buildFullPath(baseURL, requestedURL) {
  1009. if (baseURL && !isAbsoluteURL(requestedURL)) {
  1010. return combineURLs(baseURL, requestedURL);
  1011. }
  1012. return requestedURL;
  1013. };
  1014. // Headers whose duplicates are ignored by node
  1015. // c.f. https://nodejs.org/api/http.html#http_message_headers
  1016. var ignoreDuplicateOf = [
  1017. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  1018. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  1019. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  1020. 'referer', 'retry-after', 'user-agent'
  1021. ];
  1022. /**
  1023. * Parse headers into an object
  1024. *
  1025. * ```
  1026. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  1027. * Content-Type: application/json
  1028. * Connection: keep-alive
  1029. * Transfer-Encoding: chunked
  1030. * ```
  1031. *
  1032. * @param {String} headers Headers needing to be parsed
  1033. * @returns {Object} Headers parsed into an object
  1034. */
  1035. var parseHeaders = function parseHeaders(headers) {
  1036. var parsed = {};
  1037. var key;
  1038. var val;
  1039. var i;
  1040. if (!headers) { return parsed; }
  1041. utils.forEach(headers.split('\n'), function parser(line) {
  1042. i = line.indexOf(':');
  1043. key = utils.trim(line.slice(0, i)).toLowerCase();
  1044. val = utils.trim(line.slice(i + 1));
  1045. if (key) {
  1046. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  1047. return;
  1048. }
  1049. if (key === 'set-cookie') {
  1050. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  1051. } else {
  1052. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  1053. }
  1054. }
  1055. });
  1056. return parsed;
  1057. };
  1058. var isURLSameOrigin = (
  1059. utils.isStandardBrowserEnv() ?
  1060. // Standard browser envs have full support of the APIs needed to test
  1061. // whether the request URL is of the same origin as current location.
  1062. (function standardBrowserEnv() {
  1063. var msie = /(msie|trident)/i.test(navigator.userAgent);
  1064. var urlParsingNode = document.createElement('a');
  1065. var originURL;
  1066. /**
  1067. * Parse a URL to discover it's components
  1068. *
  1069. * @param {String} url The URL to be parsed
  1070. * @returns {Object}
  1071. */
  1072. function resolveURL(url) {
  1073. var href = url;
  1074. if (msie) {
  1075. // IE needs attribute set twice to normalize properties
  1076. urlParsingNode.setAttribute('href', href);
  1077. href = urlParsingNode.href;
  1078. }
  1079. urlParsingNode.setAttribute('href', href);
  1080. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  1081. return {
  1082. href: urlParsingNode.href,
  1083. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  1084. host: urlParsingNode.host,
  1085. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  1086. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  1087. hostname: urlParsingNode.hostname,
  1088. port: urlParsingNode.port,
  1089. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  1090. urlParsingNode.pathname :
  1091. '/' + urlParsingNode.pathname
  1092. };
  1093. }
  1094. originURL = resolveURL(window.location.href);
  1095. /**
  1096. * Determine if a URL shares the same origin as the current location
  1097. *
  1098. * @param {String} requestURL The URL to test
  1099. * @returns {boolean} True if URL shares the same origin, otherwise false
  1100. */
  1101. return function isURLSameOrigin(requestURL) {
  1102. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  1103. return (parsed.protocol === originURL.protocol &&
  1104. parsed.host === originURL.host);
  1105. };
  1106. })() :
  1107. // Non standard browser envs (web workers, react-native) lack needed support.
  1108. (function nonStandardBrowserEnv() {
  1109. return function isURLSameOrigin() {
  1110. return true;
  1111. };
  1112. })()
  1113. );
  1114. /**
  1115. * A `CanceledError` is an object that is thrown when an operation is canceled.
  1116. *
  1117. * @class
  1118. * @param {string=} message The message.
  1119. * @param {Object=} config The config.
  1120. * @param {Object=} request The request.
  1121. */
  1122. function CanceledError(message, config, request) {
  1123. // eslint-disable-next-line no-eq-null,eqeqeq
  1124. AxiosError_1.call(this, message == null ? 'canceled' : message, AxiosError_1.ERR_CANCELED, config, request);
  1125. this.name = 'CanceledError';
  1126. }
  1127. utils.inherits(CanceledError, AxiosError_1, {
  1128. __CANCEL__: true
  1129. });
  1130. var CanceledError_1 = CanceledError;
  1131. var parseProtocol = function parseProtocol(url) {
  1132. var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
  1133. return match && match[1] || '';
  1134. };
  1135. var xhr = function xhrAdapter(config) {
  1136. return new Promise(function dispatchXhrRequest(resolve, reject) {
  1137. var requestData = config.data;
  1138. var requestHeaders = config.headers;
  1139. var responseType = config.responseType;
  1140. var withXSRFToken = config.withXSRFToken;
  1141. var onCanceled;
  1142. function done() {
  1143. if (config.cancelToken) {
  1144. config.cancelToken.unsubscribe(onCanceled);
  1145. }
  1146. if (config.signal) {
  1147. config.signal.removeEventListener('abort', onCanceled);
  1148. }
  1149. }
  1150. if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
  1151. delete requestHeaders['Content-Type']; // Let the browser set it
  1152. }
  1153. var request = new XMLHttpRequest();
  1154. // HTTP basic authentication
  1155. if (config.auth) {
  1156. var username = config.auth.username || '';
  1157. var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
  1158. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  1159. }
  1160. var fullPath = buildFullPath(config.baseURL, config.url);
  1161. request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
  1162. // Set the request timeout in MS
  1163. request.timeout = config.timeout;
  1164. function onloadend() {
  1165. if (!request) {
  1166. return;
  1167. }
  1168. // Prepare the response
  1169. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  1170. var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
  1171. request.responseText : request.response;
  1172. var response = {
  1173. data: responseData,
  1174. status: request.status,
  1175. statusText: request.statusText,
  1176. headers: responseHeaders,
  1177. config: config,
  1178. request: request
  1179. };
  1180. settle(function _resolve(value) {
  1181. resolve(value);
  1182. done();
  1183. }, function _reject(err) {
  1184. reject(err);
  1185. done();
  1186. }, response);
  1187. // Clean up request
  1188. request = null;
  1189. }
  1190. if ('onloadend' in request) {
  1191. // Use onloadend if available
  1192. request.onloadend = onloadend;
  1193. } else {
  1194. // Listen for ready state to emulate onloadend
  1195. request.onreadystatechange = function handleLoad() {
  1196. if (!request || request.readyState !== 4) {
  1197. return;
  1198. }
  1199. // The request errored out and we didn't get a response, this will be
  1200. // handled by onerror instead
  1201. // With one exception: request that using file: protocol, most browsers
  1202. // will return status as 0 even though it's a successful request
  1203. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  1204. return;
  1205. }
  1206. // readystate handler is calling before onerror or ontimeout handlers,
  1207. // so we should call onloadend on the next 'tick'
  1208. setTimeout(onloadend);
  1209. };
  1210. }
  1211. // Handle browser request cancellation (as opposed to a manual cancellation)
  1212. request.onabort = function handleAbort() {
  1213. if (!request) {
  1214. return;
  1215. }
  1216. reject(new AxiosError_1('Request aborted', AxiosError_1.ECONNABORTED, config, request));
  1217. // Clean up request
  1218. request = null;
  1219. };
  1220. // Handle low level network errors
  1221. request.onerror = function handleError() {
  1222. // Real errors are hidden from us by the browser
  1223. // onerror should only fire if it's a network error
  1224. reject(new AxiosError_1('Network Error', AxiosError_1.ERR_NETWORK, config, request));
  1225. // Clean up request
  1226. request = null;
  1227. };
  1228. // Handle timeout
  1229. request.ontimeout = function handleTimeout() {
  1230. var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
  1231. var transitional$1 = config.transitional || transitional;
  1232. if (config.timeoutErrorMessage) {
  1233. timeoutErrorMessage = config.timeoutErrorMessage;
  1234. }
  1235. reject(new AxiosError_1(
  1236. timeoutErrorMessage,
  1237. transitional$1.clarifyTimeoutError ? AxiosError_1.ETIMEDOUT : AxiosError_1.ECONNABORTED,
  1238. config,
  1239. request));
  1240. // Clean up request
  1241. request = null;
  1242. };
  1243. // Add xsrf header
  1244. // This is only done if running in a standard browser environment.
  1245. // Specifically not if we're in a web worker, or react-native.
  1246. if (utils.isStandardBrowserEnv()) {
  1247. // Add xsrf header
  1248. withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
  1249. if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
  1250. // Add xsrf header
  1251. var xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
  1252. if (xsrfValue) {
  1253. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  1254. }
  1255. }
  1256. }
  1257. // Add headers to the request
  1258. if ('setRequestHeader' in request) {
  1259. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  1260. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  1261. // Remove Content-Type if data is undefined
  1262. delete requestHeaders[key];
  1263. } else {
  1264. // Otherwise add header to the request
  1265. request.setRequestHeader(key, val);
  1266. }
  1267. });
  1268. }
  1269. // Add withCredentials to request if needed
  1270. if (!utils.isUndefined(config.withCredentials)) {
  1271. request.withCredentials = !!config.withCredentials;
  1272. }
  1273. // Add responseType to request if needed
  1274. if (responseType && responseType !== 'json') {
  1275. request.responseType = config.responseType;
  1276. }
  1277. // Handle progress if needed
  1278. if (typeof config.onDownloadProgress === 'function') {
  1279. request.addEventListener('progress', config.onDownloadProgress);
  1280. }
  1281. // Not all browsers support upload events
  1282. if (typeof config.onUploadProgress === 'function' && request.upload) {
  1283. request.upload.addEventListener('progress', config.onUploadProgress);
  1284. }
  1285. if (config.cancelToken || config.signal) {
  1286. // Handle cancellation
  1287. // eslint-disable-next-line func-names
  1288. onCanceled = function(cancel) {
  1289. if (!request) {
  1290. return;
  1291. }
  1292. reject(!cancel || cancel.type ? new CanceledError_1(null, config, request) : cancel);
  1293. request.abort();
  1294. request = null;
  1295. };
  1296. config.cancelToken && config.cancelToken.subscribe(onCanceled);
  1297. if (config.signal) {
  1298. config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
  1299. }
  1300. }
  1301. // false, 0 (zero number), and '' (empty string) are valid JSON values
  1302. if (!requestData && requestData !== false && requestData !== 0 && requestData !== '') {
  1303. requestData = null;
  1304. }
  1305. var protocol = parseProtocol(fullPath);
  1306. if (protocol && platform.protocols.indexOf(protocol) === -1) {
  1307. reject(new AxiosError_1('Unsupported protocol ' + protocol + ':', AxiosError_1.ERR_BAD_REQUEST, config));
  1308. return;
  1309. }
  1310. // Send the request
  1311. request.send(requestData);
  1312. });
  1313. };
  1314. var DEFAULT_CONTENT_TYPE = {
  1315. 'Content-Type': 'application/x-www-form-urlencoded'
  1316. };
  1317. function setContentTypeIfUnset(headers, value) {
  1318. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  1319. headers['Content-Type'] = value;
  1320. }
  1321. }
  1322. function getDefaultAdapter() {
  1323. var adapter;
  1324. if (typeof XMLHttpRequest !== 'undefined') {
  1325. // For browsers use XHR adapter
  1326. adapter = xhr;
  1327. } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  1328. // For node use HTTP adapter
  1329. adapter = xhr;
  1330. }
  1331. return adapter;
  1332. }
  1333. function stringifySafely(rawValue, parser, encoder) {
  1334. if (utils.isString(rawValue)) {
  1335. try {
  1336. (parser || JSON.parse)(rawValue);
  1337. return utils.trim(rawValue);
  1338. } catch (e) {
  1339. if (e.name !== 'SyntaxError') {
  1340. throw e;
  1341. }
  1342. }
  1343. }
  1344. return (encoder || JSON.stringify)(rawValue);
  1345. }
  1346. var defaults = {
  1347. transitional: transitional,
  1348. adapter: getDefaultAdapter(),
  1349. transformRequest: [function transformRequest(data, headers) {
  1350. normalizeHeaderName(headers, 'Accept');
  1351. normalizeHeaderName(headers, 'Content-Type');
  1352. var contentType = headers && headers['Content-Type'] || '';
  1353. var hasJSONContentType = contentType.indexOf('application/json') > -1;
  1354. var isObjectPayload = utils.isObject(data);
  1355. if (isObjectPayload && utils.isHTMLForm(data)) {
  1356. data = new FormData(data);
  1357. }
  1358. var isFormData = utils.isFormData(data);
  1359. if (isFormData) {
  1360. return hasJSONContentType ? JSON.stringify(formDataToJSON_1(data)) : data;
  1361. }
  1362. if (utils.isArrayBuffer(data) ||
  1363. utils.isBuffer(data) ||
  1364. utils.isStream(data) ||
  1365. utils.isFile(data) ||
  1366. utils.isBlob(data)
  1367. ) {
  1368. return data;
  1369. }
  1370. if (utils.isArrayBufferView(data)) {
  1371. return data.buffer;
  1372. }
  1373. if (utils.isURLSearchParams(data)) {
  1374. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  1375. return data.toString();
  1376. }
  1377. var isFileList;
  1378. if (isObjectPayload) {
  1379. if (contentType.indexOf('application/x-www-form-urlencoded') !== -1) {
  1380. return toURLEncodedForm(data, this.formSerializer).toString();
  1381. }
  1382. if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
  1383. var _FormData = this.env && this.env.FormData;
  1384. return toFormData_1(
  1385. isFileList ? {'files[]': data} : data,
  1386. _FormData && new _FormData(),
  1387. this.formSerializer
  1388. );
  1389. }
  1390. }
  1391. if (isObjectPayload || hasJSONContentType ) {
  1392. setContentTypeIfUnset(headers, 'application/json');
  1393. return stringifySafely(data);
  1394. }
  1395. return data;
  1396. }],
  1397. transformResponse: [function transformResponse(data) {
  1398. var transitional = this.transitional || defaults.transitional;
  1399. var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
  1400. var JSONRequested = this.responseType === 'json';
  1401. if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
  1402. var silentJSONParsing = transitional && transitional.silentJSONParsing;
  1403. var strictJSONParsing = !silentJSONParsing && JSONRequested;
  1404. try {
  1405. return JSON.parse(data);
  1406. } catch (e) {
  1407. if (strictJSONParsing) {
  1408. if (e.name === 'SyntaxError') {
  1409. throw AxiosError_1.from(e, AxiosError_1.ERR_BAD_RESPONSE, this, null, this.response);
  1410. }
  1411. throw e;
  1412. }
  1413. }
  1414. }
  1415. return data;
  1416. }],
  1417. /**
  1418. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  1419. * timeout is not created.
  1420. */
  1421. timeout: 0,
  1422. xsrfCookieName: 'XSRF-TOKEN',
  1423. xsrfHeaderName: 'X-XSRF-TOKEN',
  1424. maxContentLength: -1,
  1425. maxBodyLength: -1,
  1426. env: {
  1427. FormData: platform.classes.FormData,
  1428. Blob: platform.classes.Blob
  1429. },
  1430. validateStatus: function validateStatus(status) {
  1431. return status >= 200 && status < 300;
  1432. },
  1433. headers: {
  1434. common: {
  1435. 'Accept': 'application/json, text/plain, */*'
  1436. }
  1437. }
  1438. };
  1439. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  1440. defaults.headers[method] = {};
  1441. });
  1442. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  1443. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  1444. });
  1445. var defaults_1 = defaults;
  1446. /**
  1447. * Transform the data for a request or a response
  1448. *
  1449. * @param {Object|String} data The data to be transformed
  1450. * @param {Array} headers The headers for the request or response
  1451. * @param {Number} status HTTP status code
  1452. * @param {Array|Function} fns A single function or Array of functions
  1453. * @returns {*} The resulting transformed data
  1454. */
  1455. var transformData = function transformData(data, headers, status, fns) {
  1456. var context = this || defaults_1;
  1457. /*eslint no-param-reassign:0*/
  1458. utils.forEach(fns, function transform(fn) {
  1459. data = fn.call(context, data, headers, status);
  1460. });
  1461. return data;
  1462. };
  1463. var isCancel = function isCancel(value) {
  1464. return !!(value && value.__CANCEL__);
  1465. };
  1466. /**
  1467. * Throws a `CanceledError` if cancellation has been requested.
  1468. */
  1469. function throwIfCancellationRequested(config) {
  1470. if (config.cancelToken) {
  1471. config.cancelToken.throwIfRequested();
  1472. }
  1473. if (config.signal && config.signal.aborted) {
  1474. throw new CanceledError_1();
  1475. }
  1476. }
  1477. /**
  1478. * Dispatch a request to the server using the configured adapter.
  1479. *
  1480. * @param {object} config The config that is to be used for the request
  1481. * @returns {Promise} The Promise to be fulfilled
  1482. */
  1483. var dispatchRequest = function dispatchRequest(config) {
  1484. throwIfCancellationRequested(config);
  1485. // Ensure headers exist
  1486. config.headers = config.headers || {};
  1487. // Transform request data
  1488. config.data = transformData.call(
  1489. config,
  1490. config.data,
  1491. config.headers,
  1492. null,
  1493. config.transformRequest
  1494. );
  1495. normalizeHeaderName(config.headers, 'Accept');
  1496. normalizeHeaderName(config.headers, 'Content-Type');
  1497. // Flatten headers
  1498. config.headers = utils.merge(
  1499. config.headers.common || {},
  1500. config.headers[config.method] || {},
  1501. config.headers
  1502. );
  1503. utils.forEach(
  1504. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  1505. function cleanHeaderConfig(method) {
  1506. delete config.headers[method];
  1507. }
  1508. );
  1509. var adapter = config.adapter || defaults_1.adapter;
  1510. return adapter(config).then(function onAdapterResolution(response) {
  1511. throwIfCancellationRequested(config);
  1512. // Transform response data
  1513. response.data = transformData.call(
  1514. config,
  1515. response.data,
  1516. response.headers,
  1517. response.status,
  1518. config.transformResponse
  1519. );
  1520. return response;
  1521. }, function onAdapterRejection(reason) {
  1522. if (!isCancel(reason)) {
  1523. throwIfCancellationRequested(config);
  1524. // Transform response data
  1525. if (reason && reason.response) {
  1526. reason.response.data = transformData.call(
  1527. config,
  1528. reason.response.data,
  1529. reason.response.headers,
  1530. reason.response.status,
  1531. config.transformResponse
  1532. );
  1533. }
  1534. }
  1535. return Promise.reject(reason);
  1536. });
  1537. };
  1538. /**
  1539. * Config-specific merge-function which creates a new config-object
  1540. * by merging two configuration objects together.
  1541. *
  1542. * @param {Object} config1
  1543. * @param {Object} config2
  1544. * @returns {Object} New object resulting from merging config2 to config1
  1545. */
  1546. var mergeConfig = function mergeConfig(config1, config2) {
  1547. // eslint-disable-next-line no-param-reassign
  1548. config2 = config2 || {};
  1549. var config = {};
  1550. function getMergedValue(target, source) {
  1551. if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
  1552. return utils.merge(target, source);
  1553. } else if (utils.isEmptyObject(source)) {
  1554. return utils.merge({}, target);
  1555. } else if (utils.isPlainObject(source)) {
  1556. return utils.merge({}, source);
  1557. } else if (utils.isArray(source)) {
  1558. return source.slice();
  1559. }
  1560. return source;
  1561. }
  1562. // eslint-disable-next-line consistent-return
  1563. function mergeDeepProperties(prop) {
  1564. if (!utils.isUndefined(config2[prop])) {
  1565. return getMergedValue(config1[prop], config2[prop]);
  1566. } else if (!utils.isUndefined(config1[prop])) {
  1567. return getMergedValue(undefined, config1[prop]);
  1568. }
  1569. }
  1570. // eslint-disable-next-line consistent-return
  1571. function valueFromConfig2(prop) {
  1572. if (!utils.isUndefined(config2[prop])) {
  1573. return getMergedValue(undefined, config2[prop]);
  1574. }
  1575. }
  1576. // eslint-disable-next-line consistent-return
  1577. function defaultToConfig2(prop) {
  1578. if (!utils.isUndefined(config2[prop])) {
  1579. return getMergedValue(undefined, config2[prop]);
  1580. } else if (!utils.isUndefined(config1[prop])) {
  1581. return getMergedValue(undefined, config1[prop]);
  1582. }
  1583. }
  1584. // eslint-disable-next-line consistent-return
  1585. function mergeDirectKeys(prop) {
  1586. if (prop in config2) {
  1587. return getMergedValue(config1[prop], config2[prop]);
  1588. } else if (prop in config1) {
  1589. return getMergedValue(undefined, config1[prop]);
  1590. }
  1591. }
  1592. var mergeMap = {
  1593. 'url': valueFromConfig2,
  1594. 'method': valueFromConfig2,
  1595. 'data': valueFromConfig2,
  1596. 'baseURL': defaultToConfig2,
  1597. 'transformRequest': defaultToConfig2,
  1598. 'transformResponse': defaultToConfig2,
  1599. 'paramsSerializer': defaultToConfig2,
  1600. 'timeout': defaultToConfig2,
  1601. 'timeoutMessage': defaultToConfig2,
  1602. 'withCredentials': defaultToConfig2,
  1603. 'withXSRFToken': defaultToConfig2,
  1604. 'adapter': defaultToConfig2,
  1605. 'responseType': defaultToConfig2,
  1606. 'xsrfCookieName': defaultToConfig2,
  1607. 'xsrfHeaderName': defaultToConfig2,
  1608. 'onUploadProgress': defaultToConfig2,
  1609. 'onDownloadProgress': defaultToConfig2,
  1610. 'decompress': defaultToConfig2,
  1611. 'maxContentLength': defaultToConfig2,
  1612. 'maxBodyLength': defaultToConfig2,
  1613. 'beforeRedirect': defaultToConfig2,
  1614. 'transport': defaultToConfig2,
  1615. 'httpAgent': defaultToConfig2,
  1616. 'httpsAgent': defaultToConfig2,
  1617. 'cancelToken': defaultToConfig2,
  1618. 'socketPath': defaultToConfig2,
  1619. 'responseEncoding': defaultToConfig2,
  1620. 'validateStatus': mergeDirectKeys
  1621. };
  1622. utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
  1623. var merge = mergeMap[prop] || mergeDeepProperties;
  1624. var configValue = merge(prop);
  1625. (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
  1626. });
  1627. return config;
  1628. };
  1629. var data = {
  1630. "version": "0.28.1"
  1631. };
  1632. var VERSION = data.version;
  1633. var validators$1 = {};
  1634. // eslint-disable-next-line func-names
  1635. ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
  1636. validators$1[type] = function validator(thing) {
  1637. return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
  1638. };
  1639. });
  1640. var deprecatedWarnings = {};
  1641. /**
  1642. * Transitional option validator
  1643. * @param {function|boolean?} validator - set to false if the transitional option has been removed
  1644. * @param {string?} version - deprecated version / removed since version
  1645. * @param {string?} message - some message with additional info
  1646. * @returns {function}
  1647. */
  1648. validators$1.transitional = function transitional(validator, version, message) {
  1649. function formatMessage(opt, desc) {
  1650. return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
  1651. }
  1652. // eslint-disable-next-line func-names
  1653. return function(value, opt, opts) {
  1654. if (validator === false) {
  1655. throw new AxiosError_1(
  1656. formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
  1657. AxiosError_1.ERR_DEPRECATED
  1658. );
  1659. }
  1660. if (version && !deprecatedWarnings[opt]) {
  1661. deprecatedWarnings[opt] = true;
  1662. // eslint-disable-next-line no-console
  1663. console.warn(
  1664. formatMessage(
  1665. opt,
  1666. ' has been deprecated since v' + version + ' and will be removed in the near future'
  1667. )
  1668. );
  1669. }
  1670. return validator ? validator(value, opt, opts) : true;
  1671. };
  1672. };
  1673. /**
  1674. * Assert object's properties type
  1675. * @param {object} options
  1676. * @param {object} schema
  1677. * @param {boolean?} allowUnknown
  1678. */
  1679. function assertOptions(options, schema, allowUnknown) {
  1680. if (typeof options !== 'object') {
  1681. throw new AxiosError_1('options must be an object', AxiosError_1.ERR_BAD_OPTION_VALUE);
  1682. }
  1683. var keys = Object.keys(options);
  1684. var i = keys.length;
  1685. while (i-- > 0) {
  1686. var opt = keys[i];
  1687. var validator = schema[opt];
  1688. if (validator) {
  1689. var value = options[opt];
  1690. var result = value === undefined || validator(value, opt, options);
  1691. if (result !== true) {
  1692. throw new AxiosError_1('option ' + opt + ' must be ' + result, AxiosError_1.ERR_BAD_OPTION_VALUE);
  1693. }
  1694. continue;
  1695. }
  1696. if (allowUnknown !== true) {
  1697. throw new AxiosError_1('Unknown option ' + opt, AxiosError_1.ERR_BAD_OPTION);
  1698. }
  1699. }
  1700. }
  1701. var validator = {
  1702. assertOptions: assertOptions,
  1703. validators: validators$1
  1704. };
  1705. var validators = validator.validators;
  1706. /**
  1707. * Create a new instance of Axios
  1708. *
  1709. * @param {Object} instanceConfig The default config for the instance
  1710. */
  1711. function Axios(instanceConfig) {
  1712. this.defaults = instanceConfig;
  1713. this.interceptors = {
  1714. request: new InterceptorManager_1(),
  1715. response: new InterceptorManager_1()
  1716. };
  1717. }
  1718. /**
  1719. * Dispatch a request
  1720. *
  1721. * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
  1722. * @param {?Object} config
  1723. */
  1724. Axios.prototype.request = function request(configOrUrl, config) {
  1725. /*eslint no-param-reassign:0*/
  1726. // Allow for axios('example/url'[, config]) a la fetch API
  1727. if (typeof configOrUrl === 'string') {
  1728. config = config || {};
  1729. config.url = configOrUrl;
  1730. } else {
  1731. config = configOrUrl || {};
  1732. }
  1733. config = mergeConfig(this.defaults, config);
  1734. // Set config.method
  1735. if (config.method) {
  1736. config.method = config.method.toLowerCase();
  1737. } else if (this.defaults.method) {
  1738. config.method = this.defaults.method.toLowerCase();
  1739. } else {
  1740. config.method = 'get';
  1741. }
  1742. var transitional = config.transitional;
  1743. if (transitional !== undefined) {
  1744. validator.assertOptions(transitional, {
  1745. silentJSONParsing: validators.transitional(validators.boolean),
  1746. forcedJSONParsing: validators.transitional(validators.boolean),
  1747. clarifyTimeoutError: validators.transitional(validators.boolean)
  1748. }, false);
  1749. }
  1750. var paramsSerializer = config.paramsSerializer;
  1751. if (paramsSerializer !== undefined) {
  1752. validator.assertOptions(paramsSerializer, {
  1753. encode: validators.function,
  1754. serialize: validators.function
  1755. }, true);
  1756. }
  1757. utils.isFunction(paramsSerializer) && (config.paramsSerializer = {serialize: paramsSerializer});
  1758. // filter out skipped interceptors
  1759. var requestInterceptorChain = [];
  1760. var synchronousRequestInterceptors = true;
  1761. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  1762. if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
  1763. return;
  1764. }
  1765. synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
  1766. requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
  1767. });
  1768. var responseInterceptorChain = [];
  1769. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  1770. responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
  1771. });
  1772. var promise;
  1773. if (!synchronousRequestInterceptors) {
  1774. var chain = [dispatchRequest, undefined];
  1775. Array.prototype.unshift.apply(chain, requestInterceptorChain);
  1776. chain = chain.concat(responseInterceptorChain);
  1777. promise = Promise.resolve(config);
  1778. while (chain.length) {
  1779. promise = promise.then(chain.shift(), chain.shift());
  1780. }
  1781. return promise;
  1782. }
  1783. var newConfig = config;
  1784. while (requestInterceptorChain.length) {
  1785. var onFulfilled = requestInterceptorChain.shift();
  1786. var onRejected = requestInterceptorChain.shift();
  1787. try {
  1788. newConfig = onFulfilled(newConfig);
  1789. } catch (error) {
  1790. onRejected(error);
  1791. break;
  1792. }
  1793. }
  1794. try {
  1795. promise = dispatchRequest(newConfig);
  1796. } catch (error) {
  1797. return Promise.reject(error);
  1798. }
  1799. while (responseInterceptorChain.length) {
  1800. promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
  1801. }
  1802. return promise;
  1803. };
  1804. Axios.prototype.getUri = function getUri(config) {
  1805. config = mergeConfig(this.defaults, config);
  1806. var fullPath = buildFullPath(config.baseURL, config.url);
  1807. return buildURL(fullPath, config.params, config.paramsSerializer);
  1808. };
  1809. // Provide aliases for supported request methods
  1810. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  1811. /*eslint func-names:0*/
  1812. Axios.prototype[method] = function(url, config) {
  1813. return this.request(mergeConfig(config || {}, {
  1814. method: method,
  1815. url: url,
  1816. data: (config || {}).data
  1817. }));
  1818. };
  1819. });
  1820. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  1821. /*eslint func-names:0*/
  1822. function generateHTTPMethod(isForm) {
  1823. return function httpMethod(url, data, config) {
  1824. return this.request(mergeConfig(config || {}, {
  1825. method: method,
  1826. headers: isForm ? {
  1827. 'Content-Type': 'multipart/form-data'
  1828. } : {},
  1829. url: url,
  1830. data: data
  1831. }));
  1832. };
  1833. }
  1834. Axios.prototype[method] = generateHTTPMethod();
  1835. Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
  1836. });
  1837. var Axios_1 = Axios;
  1838. /**
  1839. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  1840. *
  1841. * @class
  1842. * @param {Function} executor The executor function.
  1843. */
  1844. function CancelToken(executor) {
  1845. if (typeof executor !== 'function') {
  1846. throw new TypeError('executor must be a function.');
  1847. }
  1848. var resolvePromise;
  1849. this.promise = new Promise(function promiseExecutor(resolve) {
  1850. resolvePromise = resolve;
  1851. });
  1852. var token = this;
  1853. // eslint-disable-next-line func-names
  1854. this.promise.then(function(cancel) {
  1855. if (!token._listeners) return;
  1856. var i = token._listeners.length;
  1857. while (i-- > 0) {
  1858. token._listeners[i](cancel);
  1859. }
  1860. token._listeners = null;
  1861. });
  1862. // eslint-disable-next-line func-names
  1863. this.promise.then = function(onfulfilled) {
  1864. var _resolve;
  1865. // eslint-disable-next-line func-names
  1866. var promise = new Promise(function(resolve) {
  1867. token.subscribe(resolve);
  1868. _resolve = resolve;
  1869. }).then(onfulfilled);
  1870. promise.cancel = function reject() {
  1871. token.unsubscribe(_resolve);
  1872. };
  1873. return promise;
  1874. };
  1875. executor(function cancel(message, config, request) {
  1876. if (token.reason) {
  1877. // Cancellation has already been requested
  1878. return;
  1879. }
  1880. token.reason = new CanceledError_1(message, config, request);
  1881. resolvePromise(token.reason);
  1882. });
  1883. }
  1884. /**
  1885. * Throws a `CanceledError` if cancellation has been requested.
  1886. */
  1887. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  1888. if (this.reason) {
  1889. throw this.reason;
  1890. }
  1891. };
  1892. /**
  1893. * Subscribe to the cancel signal
  1894. */
  1895. CancelToken.prototype.subscribe = function subscribe(listener) {
  1896. if (this.reason) {
  1897. listener(this.reason);
  1898. return;
  1899. }
  1900. if (this._listeners) {
  1901. this._listeners.push(listener);
  1902. } else {
  1903. this._listeners = [listener];
  1904. }
  1905. };
  1906. /**
  1907. * Unsubscribe from the cancel signal
  1908. */
  1909. CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
  1910. if (!this._listeners) {
  1911. return;
  1912. }
  1913. var index = this._listeners.indexOf(listener);
  1914. if (index !== -1) {
  1915. this._listeners.splice(index, 1);
  1916. }
  1917. };
  1918. /**
  1919. * Returns an object that contains a new `CancelToken` and a function that, when called,
  1920. * cancels the `CancelToken`.
  1921. */
  1922. CancelToken.source = function source() {
  1923. var cancel;
  1924. var token = new CancelToken(function executor(c) {
  1925. cancel = c;
  1926. });
  1927. return {
  1928. token: token,
  1929. cancel: cancel
  1930. };
  1931. };
  1932. var CancelToken_1 = CancelToken;
  1933. /**
  1934. * Syntactic sugar for invoking a function and expanding an array for arguments.
  1935. *
  1936. * Common use case would be to use `Function.prototype.apply`.
  1937. *
  1938. * ```js
  1939. * function f(x, y, z) {}
  1940. * var args = [1, 2, 3];
  1941. * f.apply(null, args);
  1942. * ```
  1943. *
  1944. * With `spread` this example can be re-written.
  1945. *
  1946. * ```js
  1947. * spread(function(x, y, z) {})([1, 2, 3]);
  1948. * ```
  1949. *
  1950. * @param {Function} callback
  1951. * @returns {Function}
  1952. */
  1953. var spread = function spread(callback) {
  1954. return function wrap(arr) {
  1955. return callback.apply(null, arr);
  1956. };
  1957. };
  1958. /**
  1959. * Determines whether the payload is an error thrown by Axios
  1960. *
  1961. * @param {*} payload The value to test
  1962. * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
  1963. */
  1964. var isAxiosError = function isAxiosError(payload) {
  1965. return utils.isObject(payload) && (payload.isAxiosError === true);
  1966. };
  1967. /**
  1968. * Create an instance of Axios
  1969. *
  1970. * @param {Object} defaultConfig The default config for the instance
  1971. * @return {Axios} A new instance of Axios
  1972. */
  1973. function createInstance(defaultConfig) {
  1974. var context = new Axios_1(defaultConfig);
  1975. var instance = bind(Axios_1.prototype.request, context);
  1976. // Copy axios.prototype to instance
  1977. utils.extend(instance, Axios_1.prototype, context);
  1978. // Copy context to instance
  1979. utils.extend(instance, context);
  1980. // Factory for creating new instances
  1981. instance.create = function create(instanceConfig) {
  1982. return createInstance(mergeConfig(defaultConfig, instanceConfig));
  1983. };
  1984. return instance;
  1985. }
  1986. // Create the default instance to be exported
  1987. var axios = createInstance(defaults_1);
  1988. // Expose Axios class to allow class inheritance
  1989. axios.Axios = Axios_1;
  1990. // Expose Cancel & CancelToken
  1991. axios.CanceledError = CanceledError_1;
  1992. axios.CancelToken = CancelToken_1;
  1993. axios.isCancel = isCancel;
  1994. axios.VERSION = data.version;
  1995. axios.toFormData = toFormData_1;
  1996. // Expose AxiosError class
  1997. axios.AxiosError = AxiosError_1;
  1998. // alias for CanceledError for backward compatibility
  1999. axios.Cancel = axios.CanceledError;
  2000. // Expose all/spread
  2001. axios.all = function all(promises) {
  2002. return Promise.all(promises);
  2003. };
  2004. axios.spread = spread;
  2005. // Expose isAxiosError
  2006. axios.isAxiosError = isAxiosError;
  2007. axios.formToJSON = function(thing) {
  2008. return formDataToJSON_1(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
  2009. };
  2010. var axios_1 = axios;
  2011. // Allow use of default import syntax in TypeScript
  2012. var _default = axios;
  2013. axios_1.default = _default;
  2014. return axios_1;
  2015. }));
  2016. //# sourceMappingURL=axios.js.map