axios.js 83 KB

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