axios.cjs 81 KB

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