axios.js 82 KB

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