axios.cjs 83 KB

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