From dfac0eaa647eefcd3001fdeecd6bdb03eabea52d Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Mon, 31 Oct 2022 11:41:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E7=BC=96=E5=86=99=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=8A=E4=BC=A0=E7=9A=84=E5=89=8D=E5=90=8E=E7=AB=AF?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/importer/CarDealerDataImport.java | 36 + .../data/importer/ImportRequest.java | 56 + .../data/importer/ImportResult.java | 86 + .../data/importer/RecordErrorMessage.java | 100 + .../fileupload/FileUploadController.java | 2 +- code/web/car_dealer/js/axios/1.1.3/axios.js | 2723 +++++++++++++++++ 6 files changed, 3002 insertions(+), 1 deletion(-) create mode 100644 code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/CarDealerDataImport.java create mode 100644 code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportRequest.java create mode 100644 code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportResult.java create mode 100644 code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/RecordErrorMessage.java create mode 100644 code/web/car_dealer/js/axios/1.1.3/axios.js diff --git a/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/CarDealerDataImport.java b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/CarDealerDataImport.java new file mode 100644 index 0000000..cd6efcf --- /dev/null +++ b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/CarDealerDataImport.java @@ -0,0 +1,36 @@ +/* + * @Author: Kane + * @Date: 2022-10-31 10:23:32 + * @LastEditors: Kane + * @LastEditTime: 2022-10-31 11:40:21 + * @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\data\importer\CarDealerDataImport.java + * @Description: + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ + +package com.cpic.xim.car_dealer.controllers.data.importer; + +import java.util.ArrayList; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@ResponseBody +@RequestMapping( path = "data/import/") +public class CarDealerDataImport +{ + + public ImportResult importCarDealer( @RequestBody ImportRequest importRequest ) + { + ArrayList recordErrorMessages = new ArrayList(); + ImportResult result = new ImportResult(); + + result.setRecordErrorMessages( recordErrorMessages ); + + return result; + } +} + diff --git a/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportRequest.java b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportRequest.java new file mode 100644 index 0000000..a44a4aa --- /dev/null +++ b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportRequest.java @@ -0,0 +1,56 @@ +/* + * @Author: Kane + * @Date: 2022-10-31 11:16:22 + * @LastEditors: Kane + * @LastEditTime: 2022-10-31 11:28:00 + * @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\data\importer\importRequest.java + * @Description: + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ + +package com.cpic.xim.car_dealer.controllers.data.importer; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ImportRequest +{ + + public ImportRequest( String filePath, String tableName) + { + this.filePath = filePath; + this.tableName = tableName; + } + + public String getFilePath() + { + return filePath; + } + + public void setFilePath( String filePath ) + { + this.filePath = filePath; + } + + public String getTableName() + { + return tableName; + } + + public void setTableName( String tableName ) + { + this.tableName = tableName; + } + + @Override + public String toString() + { + return "{ \"file_path\":\"" + filePath + "\", \"table_name\":\"" + tableName + "\"}"; + } + + @JsonProperty( "file_path") + private String filePath; + + @JsonProperty( "table_name") + private String tableName; +} diff --git a/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportResult.java b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportResult.java new file mode 100644 index 0000000..e8c4557 --- /dev/null +++ b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/ImportResult.java @@ -0,0 +1,86 @@ +/* + * @Author: Kane + * @Date: 2022-10-31 10:31:35 + * @LastEditors: Kane + * @LastEditTime: 2022-10-31 10:43:12 + * @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\data\importer\ImportResult.java + * @Description: + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ + +package com.cpic.xim.car_dealer.controllers.data.importer; + +import java.util.ArrayList; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ImportResult +{ + ImportResult() + {} + + public String getFileName() + { + return fileName; + } + + public void setFileName( String fileName ) + { + this.fileName = fileName; + } + + public String getFilePath() + { + return filePath; + } + + public void setFilePath( String filePath ) + { + this.filePath = filePath; + } + + public boolean isSuccess() + { + return success; + } + + public void setSuccess( boolean success ) + { + this.success = success; + } + + public String getMessage() + { + return message; + } + + public void setMessage( String message ) + { + this.message = message; + } + + public ArrayList getRecordErrorMessages() + { + return recordErrorMessages; + } + + public void setRecordErrorMessages( ArrayList recordErrorMessages ) + { + this.recordErrorMessages = recordErrorMessages; + } + + @JsonProperty( "file_name") + private String fileName; + + @JsonProperty( "file_path") + private String filePath; + + @JsonProperty( "success") + private boolean success; + + @JsonProperty( "message") + private String message; + + @JsonProperty( "record_error_messages") + private ArrayList recordErrorMessages; +} diff --git a/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/RecordErrorMessage.java b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/RecordErrorMessage.java new file mode 100644 index 0000000..96a2f3d --- /dev/null +++ b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/data/importer/RecordErrorMessage.java @@ -0,0 +1,100 @@ +/* + * @Author: Kane + * @Date: 2022-10-31 10:48:29 + * @LastEditors: Kane + * @LastEditTime: 2022-10-31 11:01:28 + * @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\data\importer\importRecordErrorMessage.java + * @Description: 存放导入数据记录结果的对象. + * + * Copyright (c) ${2022} by Kane, All Rights Reserved. + */ +package com.cpic.xim.car_dealer.controllers.data.importer; + +import com.fasterxml.jackson.annotation.*;; + +/***************************************************** + * 存放导入数据记录结果的对象. + *****************************************************/ +public class RecordErrorMessage +{ + + public RecordErrorMessage( int rowIndex, String message) + { + this.rowIndex = rowIndex; + this.message = message; + } + + + public int getRowIndex() + { + return rowIndex; + } + + public void setRowIndex( int rowIndex ) + { + this.rowIndex = rowIndex; + } + + public String getMessage() + { + return message; + } + + public void setMessage( String message ) + { + this.message = message; + } + + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + rowIndex; + result = prime * result + ((message == null) ? 0 : message.hashCode()); + return result; + } + + + @Override + public boolean equals( Object obj ) + { + if ( this == obj) + return true; + if ( obj == null) + return false; + if ( getClass() != obj.getClass()) + return false; + RecordErrorMessage other = (RecordErrorMessage) obj; + if ( rowIndex != other.rowIndex) + return false; + if ( message == null) + { + if ( other.message != null) + return false; + } else if ( !message.equals( other.message )) + return false; + return true; + } + + + @Override + public String toString() + { + return "importRecordErrorMessage [rowIndex=" + rowIndex + ", message=" + message + "]"; + } + + + /** + * 数据的行id。 + */ + @JsonProperty( "row_index") + private int rowIndex; + + /** + * 导入时的错误信息。 + */ + @JsonProperty( "message") + private String message; +} diff --git a/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/fileupload/FileUploadController.java b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/fileupload/FileUploadController.java index 67334ad..a8a6464 100644 --- a/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/fileupload/FileUploadController.java +++ b/code/java/car_dealer/src/main/java/com/cpic/xim/car_dealer/controllers/fileupload/FileUploadController.java @@ -2,7 +2,7 @@ * @Author: Kane * @Date: 2022-09-28 15:47:02 * @LastEditors: Kane - * @LastEditTime: 2022-10-19 16:19:01 + * @LastEditTime: 2022-10-31 11:08:29 * @FilePath: \car_dealer\src\main\java\com\cpic\xim\car_dealer\controllers\fileupload\FileUploadController.java * @Description: 用于实现跨域功能的过滤器对象。 * Copyright (c) ${2022} by Kane, All Rights Reserved. diff --git a/code/web/car_dealer/js/axios/1.1.3/axios.js b/code/web/car_dealer/js/axios/1.1.3/axios.js new file mode 100644 index 0000000..d4b1b5f --- /dev/null +++ b/code/web/car_dealer/js/axios/1.1.3/axios.js @@ -0,0 +1,2723 @@ +UNPKG - axios

UNPKG

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

Build: a7ebffa

© 2022 UNPKG

\ No newline at end of file