axios.cjs 81 KB

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