@xchainjs/xchain-thorchain-amm 2.0.23 → 2.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +68 -4477
- package/lib/index.js +57 -4466
- package/package.json +4 -3
package/lib/index.esm.js
CHANGED
|
@@ -1,3745 +1,19 @@
|
|
|
1
|
-
import { AssetAVAX, AVAXChain
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { BCHChain, Client as Client$7, defaultBchParams } from '@xchainjs/xchain-bitcoincash';
|
|
8
|
-
import { AssetBSC, BSCChain, Client as Client$2, defaultBscParams } from '@xchainjs/xchain-bsc';
|
|
1
|
+
import { AssetAVAX, AVAXChain, Client as Client$4, defaultAvaxParams } from '@xchainjs/xchain-avax';
|
|
2
|
+
import { AssetBETH, BASEChain, Client as Client$2, defaultBaseParams } from '@xchainjs/xchain-base';
|
|
3
|
+
import { BTCChain, Client as Client$9, defaultBTCParams } from '@xchainjs/xchain-bitcoin';
|
|
4
|
+
import { BCHChain, Client as Client$8, defaultBchParams } from '@xchainjs/xchain-bitcoincash';
|
|
5
|
+
import { AssetBSC, BSCChain, Client as Client$3, defaultBscParams } from '@xchainjs/xchain-bsc';
|
|
6
|
+
import { Protocol, Network } from '@xchainjs/xchain-client';
|
|
9
7
|
import { GAIAChain, Client as Client$1, AssetATOM } from '@xchainjs/xchain-cosmos';
|
|
10
|
-
import { DOGEChain, Client as Client$
|
|
11
|
-
import { AssetETH, ETHChain, Client as Client$
|
|
12
|
-
import {
|
|
8
|
+
import { DOGEChain, Client as Client$6, defaultDogeParams } from '@xchainjs/xchain-doge';
|
|
9
|
+
import { AssetETH, ETHChain, Client as Client$5, defaultEthParams } from '@xchainjs/xchain-ethereum';
|
|
10
|
+
import { abi, MAX_APPROVAL } from '@xchainjs/xchain-evm';
|
|
11
|
+
import { LTCChain, Client as Client$7, defaultLtcParams } from '@xchainjs/xchain-litecoin';
|
|
13
12
|
import { THORChain, Client, defaultClientConfig, AssetRuneNative, RUNE_DECIMAL } from '@xchainjs/xchain-thorchain';
|
|
14
13
|
import { ThorchainQuery, ThorchainCache, Thornode } from '@xchainjs/xchain-thorchain-query';
|
|
14
|
+
import { eqAsset, isSynthAsset, getContractAddressFromAsset, baseAmount, isTradeAsset, isSecuredAsset, assetToString, AssetCryptoAmount, CryptoAmount } from '@xchainjs/xchain-util';
|
|
15
15
|
import { Wallet } from '@xchainjs/xchain-wallet';
|
|
16
|
-
|
|
17
|
-
/******************************************************************************
|
|
18
|
-
Copyright (c) Microsoft Corporation.
|
|
19
|
-
|
|
20
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
21
|
-
purpose with or without fee is hereby granted.
|
|
22
|
-
|
|
23
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
24
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
25
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
26
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
27
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
28
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
29
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
30
|
-
***************************************************************************** */
|
|
31
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
35
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
36
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
37
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
38
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
39
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
40
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
45
|
-
var e = new Error(message);
|
|
46
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
function bind(fn, thisArg) {
|
|
50
|
-
return function wrap() {
|
|
51
|
-
return fn.apply(thisArg, arguments);
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// utils is a library of generic helper functions non-specific to axios
|
|
56
|
-
|
|
57
|
-
const {toString} = Object.prototype;
|
|
58
|
-
const {getPrototypeOf} = Object;
|
|
59
|
-
|
|
60
|
-
const kindOf = (cache => thing => {
|
|
61
|
-
const str = toString.call(thing);
|
|
62
|
-
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
|
63
|
-
})(Object.create(null));
|
|
64
|
-
|
|
65
|
-
const kindOfTest = (type) => {
|
|
66
|
-
type = type.toLowerCase();
|
|
67
|
-
return (thing) => kindOf(thing) === type
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const typeOfTest = type => thing => typeof thing === type;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Determine if a value is an Array
|
|
74
|
-
*
|
|
75
|
-
* @param {Object} val The value to test
|
|
76
|
-
*
|
|
77
|
-
* @returns {boolean} True if value is an Array, otherwise false
|
|
78
|
-
*/
|
|
79
|
-
const {isArray} = Array;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Determine if a value is undefined
|
|
83
|
-
*
|
|
84
|
-
* @param {*} val The value to test
|
|
85
|
-
*
|
|
86
|
-
* @returns {boolean} True if the value is undefined, otherwise false
|
|
87
|
-
*/
|
|
88
|
-
const isUndefined = typeOfTest('undefined');
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Determine if a value is a Buffer
|
|
92
|
-
*
|
|
93
|
-
* @param {*} val The value to test
|
|
94
|
-
*
|
|
95
|
-
* @returns {boolean} True if value is a Buffer, otherwise false
|
|
96
|
-
*/
|
|
97
|
-
function isBuffer(val) {
|
|
98
|
-
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
99
|
-
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Determine if a value is an ArrayBuffer
|
|
104
|
-
*
|
|
105
|
-
* @param {*} val The value to test
|
|
106
|
-
*
|
|
107
|
-
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
|
108
|
-
*/
|
|
109
|
-
const isArrayBuffer = kindOfTest('ArrayBuffer');
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Determine if a value is a view on an ArrayBuffer
|
|
114
|
-
*
|
|
115
|
-
* @param {*} val The value to test
|
|
116
|
-
*
|
|
117
|
-
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
|
118
|
-
*/
|
|
119
|
-
function isArrayBufferView(val) {
|
|
120
|
-
let result;
|
|
121
|
-
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
|
122
|
-
result = ArrayBuffer.isView(val);
|
|
123
|
-
} else {
|
|
124
|
-
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
|
|
125
|
-
}
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Determine if a value is a String
|
|
131
|
-
*
|
|
132
|
-
* @param {*} val The value to test
|
|
133
|
-
*
|
|
134
|
-
* @returns {boolean} True if value is a String, otherwise false
|
|
135
|
-
*/
|
|
136
|
-
const isString = typeOfTest('string');
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Determine if a value is a Function
|
|
140
|
-
*
|
|
141
|
-
* @param {*} val The value to test
|
|
142
|
-
* @returns {boolean} True if value is a Function, otherwise false
|
|
143
|
-
*/
|
|
144
|
-
const isFunction = typeOfTest('function');
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Determine if a value is a Number
|
|
148
|
-
*
|
|
149
|
-
* @param {*} val The value to test
|
|
150
|
-
*
|
|
151
|
-
* @returns {boolean} True if value is a Number, otherwise false
|
|
152
|
-
*/
|
|
153
|
-
const isNumber = typeOfTest('number');
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Determine if a value is an Object
|
|
157
|
-
*
|
|
158
|
-
* @param {*} thing The value to test
|
|
159
|
-
*
|
|
160
|
-
* @returns {boolean} True if value is an Object, otherwise false
|
|
161
|
-
*/
|
|
162
|
-
const isObject = (thing) => thing !== null && typeof thing === 'object';
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Determine if a value is a Boolean
|
|
166
|
-
*
|
|
167
|
-
* @param {*} thing The value to test
|
|
168
|
-
* @returns {boolean} True if value is a Boolean, otherwise false
|
|
169
|
-
*/
|
|
170
|
-
const isBoolean = thing => thing === true || thing === false;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Determine if a value is a plain Object
|
|
174
|
-
*
|
|
175
|
-
* @param {*} val The value to test
|
|
176
|
-
*
|
|
177
|
-
* @returns {boolean} True if value is a plain Object, otherwise false
|
|
178
|
-
*/
|
|
179
|
-
const isPlainObject = (val) => {
|
|
180
|
-
if (kindOf(val) !== 'object') {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const prototype = getPrototypeOf(val);
|
|
185
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Determine if a value is a Date
|
|
190
|
-
*
|
|
191
|
-
* @param {*} val The value to test
|
|
192
|
-
*
|
|
193
|
-
* @returns {boolean} True if value is a Date, otherwise false
|
|
194
|
-
*/
|
|
195
|
-
const isDate = kindOfTest('Date');
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Determine if a value is a File
|
|
199
|
-
*
|
|
200
|
-
* @param {*} val The value to test
|
|
201
|
-
*
|
|
202
|
-
* @returns {boolean} True if value is a File, otherwise false
|
|
203
|
-
*/
|
|
204
|
-
const isFile = kindOfTest('File');
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Determine if a value is a Blob
|
|
208
|
-
*
|
|
209
|
-
* @param {*} val The value to test
|
|
210
|
-
*
|
|
211
|
-
* @returns {boolean} True if value is a Blob, otherwise false
|
|
212
|
-
*/
|
|
213
|
-
const isBlob = kindOfTest('Blob');
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Determine if a value is a FileList
|
|
217
|
-
*
|
|
218
|
-
* @param {*} val The value to test
|
|
219
|
-
*
|
|
220
|
-
* @returns {boolean} True if value is a File, otherwise false
|
|
221
|
-
*/
|
|
222
|
-
const isFileList = kindOfTest('FileList');
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Determine if a value is a Stream
|
|
226
|
-
*
|
|
227
|
-
* @param {*} val The value to test
|
|
228
|
-
*
|
|
229
|
-
* @returns {boolean} True if value is a Stream, otherwise false
|
|
230
|
-
*/
|
|
231
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Determine if a value is a FormData
|
|
235
|
-
*
|
|
236
|
-
* @param {*} thing The value to test
|
|
237
|
-
*
|
|
238
|
-
* @returns {boolean} True if value is an FormData, otherwise false
|
|
239
|
-
*/
|
|
240
|
-
const isFormData = (thing) => {
|
|
241
|
-
let kind;
|
|
242
|
-
return thing && (
|
|
243
|
-
(typeof FormData === 'function' && thing instanceof FormData) || (
|
|
244
|
-
isFunction(thing.append) && (
|
|
245
|
-
(kind = kindOf(thing)) === 'formdata' ||
|
|
246
|
-
// detect form-data instance
|
|
247
|
-
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
|
|
248
|
-
)
|
|
249
|
-
)
|
|
250
|
-
)
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Determine if a value is a URLSearchParams object
|
|
255
|
-
*
|
|
256
|
-
* @param {*} val The value to test
|
|
257
|
-
*
|
|
258
|
-
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
|
259
|
-
*/
|
|
260
|
-
const isURLSearchParams = kindOfTest('URLSearchParams');
|
|
261
|
-
|
|
262
|
-
const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Trim excess whitespace off the beginning and end of a string
|
|
266
|
-
*
|
|
267
|
-
* @param {String} str The String to trim
|
|
268
|
-
*
|
|
269
|
-
* @returns {String} The String freed of excess whitespace
|
|
270
|
-
*/
|
|
271
|
-
const trim = (str) => str.trim ?
|
|
272
|
-
str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Iterate over an Array or an Object invoking a function for each item.
|
|
276
|
-
*
|
|
277
|
-
* If `obj` is an Array callback will be called passing
|
|
278
|
-
* the value, index, and complete array for each item.
|
|
279
|
-
*
|
|
280
|
-
* If 'obj' is an Object callback will be called passing
|
|
281
|
-
* the value, key, and complete object for each property.
|
|
282
|
-
*
|
|
283
|
-
* @param {Object|Array} obj The object to iterate
|
|
284
|
-
* @param {Function} fn The callback to invoke for each item
|
|
285
|
-
*
|
|
286
|
-
* @param {Boolean} [allOwnKeys = false]
|
|
287
|
-
* @returns {any}
|
|
288
|
-
*/
|
|
289
|
-
function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
290
|
-
// Don't bother if no value provided
|
|
291
|
-
if (obj === null || typeof obj === 'undefined') {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
let i;
|
|
296
|
-
let l;
|
|
297
|
-
|
|
298
|
-
// Force an array if not already something iterable
|
|
299
|
-
if (typeof obj !== 'object') {
|
|
300
|
-
/*eslint no-param-reassign:0*/
|
|
301
|
-
obj = [obj];
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (isArray(obj)) {
|
|
305
|
-
// Iterate over array values
|
|
306
|
-
for (i = 0, l = obj.length; i < l; i++) {
|
|
307
|
-
fn.call(null, obj[i], i, obj);
|
|
308
|
-
}
|
|
309
|
-
} else {
|
|
310
|
-
// Iterate over object keys
|
|
311
|
-
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
312
|
-
const len = keys.length;
|
|
313
|
-
let key;
|
|
314
|
-
|
|
315
|
-
for (i = 0; i < len; i++) {
|
|
316
|
-
key = keys[i];
|
|
317
|
-
fn.call(null, obj[key], key, obj);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function findKey(obj, key) {
|
|
323
|
-
key = key.toLowerCase();
|
|
324
|
-
const keys = Object.keys(obj);
|
|
325
|
-
let i = keys.length;
|
|
326
|
-
let _key;
|
|
327
|
-
while (i-- > 0) {
|
|
328
|
-
_key = keys[i];
|
|
329
|
-
if (key === _key.toLowerCase()) {
|
|
330
|
-
return _key;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return null;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const _global = (() => {
|
|
337
|
-
/*eslint no-undef:0*/
|
|
338
|
-
if (typeof globalThis !== "undefined") return globalThis;
|
|
339
|
-
return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)
|
|
340
|
-
})();
|
|
341
|
-
|
|
342
|
-
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Accepts varargs expecting each argument to be an object, then
|
|
346
|
-
* immutably merges the properties of each object and returns result.
|
|
347
|
-
*
|
|
348
|
-
* When multiple objects contain the same key the later object in
|
|
349
|
-
* the arguments list will take precedence.
|
|
350
|
-
*
|
|
351
|
-
* Example:
|
|
352
|
-
*
|
|
353
|
-
* ```js
|
|
354
|
-
* var result = merge({foo: 123}, {foo: 456});
|
|
355
|
-
* console.log(result.foo); // outputs 456
|
|
356
|
-
* ```
|
|
357
|
-
*
|
|
358
|
-
* @param {Object} obj1 Object to merge
|
|
359
|
-
*
|
|
360
|
-
* @returns {Object} Result of all merge properties
|
|
361
|
-
*/
|
|
362
|
-
function merge(/* obj1, obj2, obj3, ... */) {
|
|
363
|
-
const {caseless} = isContextDefined(this) && this || {};
|
|
364
|
-
const result = {};
|
|
365
|
-
const assignValue = (val, key) => {
|
|
366
|
-
const targetKey = caseless && findKey(result, key) || key;
|
|
367
|
-
if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
|
|
368
|
-
result[targetKey] = merge(result[targetKey], val);
|
|
369
|
-
} else if (isPlainObject(val)) {
|
|
370
|
-
result[targetKey] = merge({}, val);
|
|
371
|
-
} else if (isArray(val)) {
|
|
372
|
-
result[targetKey] = val.slice();
|
|
373
|
-
} else {
|
|
374
|
-
result[targetKey] = val;
|
|
375
|
-
}
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
for (let i = 0, l = arguments.length; i < l; i++) {
|
|
379
|
-
arguments[i] && forEach(arguments[i], assignValue);
|
|
380
|
-
}
|
|
381
|
-
return result;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Extends object a by mutably adding to it the properties of object b.
|
|
386
|
-
*
|
|
387
|
-
* @param {Object} a The object to be extended
|
|
388
|
-
* @param {Object} b The object to copy properties from
|
|
389
|
-
* @param {Object} thisArg The object to bind function to
|
|
390
|
-
*
|
|
391
|
-
* @param {Boolean} [allOwnKeys]
|
|
392
|
-
* @returns {Object} The resulting value of object a
|
|
393
|
-
*/
|
|
394
|
-
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
|
395
|
-
forEach(b, (val, key) => {
|
|
396
|
-
if (thisArg && isFunction(val)) {
|
|
397
|
-
a[key] = bind(val, thisArg);
|
|
398
|
-
} else {
|
|
399
|
-
a[key] = val;
|
|
400
|
-
}
|
|
401
|
-
}, {allOwnKeys});
|
|
402
|
-
return a;
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
|
407
|
-
*
|
|
408
|
-
* @param {string} content with BOM
|
|
409
|
-
*
|
|
410
|
-
* @returns {string} content value without BOM
|
|
411
|
-
*/
|
|
412
|
-
const stripBOM = (content) => {
|
|
413
|
-
if (content.charCodeAt(0) === 0xFEFF) {
|
|
414
|
-
content = content.slice(1);
|
|
415
|
-
}
|
|
416
|
-
return content;
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Inherit the prototype methods from one constructor into another
|
|
421
|
-
* @param {function} constructor
|
|
422
|
-
* @param {function} superConstructor
|
|
423
|
-
* @param {object} [props]
|
|
424
|
-
* @param {object} [descriptors]
|
|
425
|
-
*
|
|
426
|
-
* @returns {void}
|
|
427
|
-
*/
|
|
428
|
-
const inherits = (constructor, superConstructor, props, descriptors) => {
|
|
429
|
-
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
|
430
|
-
constructor.prototype.constructor = constructor;
|
|
431
|
-
Object.defineProperty(constructor, 'super', {
|
|
432
|
-
value: superConstructor.prototype
|
|
433
|
-
});
|
|
434
|
-
props && Object.assign(constructor.prototype, props);
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Resolve object with deep prototype chain to a flat object
|
|
439
|
-
* @param {Object} sourceObj source object
|
|
440
|
-
* @param {Object} [destObj]
|
|
441
|
-
* @param {Function|Boolean} [filter]
|
|
442
|
-
* @param {Function} [propFilter]
|
|
443
|
-
*
|
|
444
|
-
* @returns {Object}
|
|
445
|
-
*/
|
|
446
|
-
const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
|
|
447
|
-
let props;
|
|
448
|
-
let i;
|
|
449
|
-
let prop;
|
|
450
|
-
const merged = {};
|
|
451
|
-
|
|
452
|
-
destObj = destObj || {};
|
|
453
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
454
|
-
if (sourceObj == null) return destObj;
|
|
455
|
-
|
|
456
|
-
do {
|
|
457
|
-
props = Object.getOwnPropertyNames(sourceObj);
|
|
458
|
-
i = props.length;
|
|
459
|
-
while (i-- > 0) {
|
|
460
|
-
prop = props[i];
|
|
461
|
-
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
|
462
|
-
destObj[prop] = sourceObj[prop];
|
|
463
|
-
merged[prop] = true;
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
sourceObj = filter !== false && getPrototypeOf(sourceObj);
|
|
467
|
-
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
|
468
|
-
|
|
469
|
-
return destObj;
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Determines whether a string ends with the characters of a specified string
|
|
474
|
-
*
|
|
475
|
-
* @param {String} str
|
|
476
|
-
* @param {String} searchString
|
|
477
|
-
* @param {Number} [position= 0]
|
|
478
|
-
*
|
|
479
|
-
* @returns {boolean}
|
|
480
|
-
*/
|
|
481
|
-
const endsWith = (str, searchString, position) => {
|
|
482
|
-
str = String(str);
|
|
483
|
-
if (position === undefined || position > str.length) {
|
|
484
|
-
position = str.length;
|
|
485
|
-
}
|
|
486
|
-
position -= searchString.length;
|
|
487
|
-
const lastIndex = str.indexOf(searchString, position);
|
|
488
|
-
return lastIndex !== -1 && lastIndex === position;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Returns new array from array like object or null if failed
|
|
494
|
-
*
|
|
495
|
-
* @param {*} [thing]
|
|
496
|
-
*
|
|
497
|
-
* @returns {?Array}
|
|
498
|
-
*/
|
|
499
|
-
const toArray = (thing) => {
|
|
500
|
-
if (!thing) return null;
|
|
501
|
-
if (isArray(thing)) return thing;
|
|
502
|
-
let i = thing.length;
|
|
503
|
-
if (!isNumber(i)) return null;
|
|
504
|
-
const arr = new Array(i);
|
|
505
|
-
while (i-- > 0) {
|
|
506
|
-
arr[i] = thing[i];
|
|
507
|
-
}
|
|
508
|
-
return arr;
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Checking if the Uint8Array exists and if it does, it returns a function that checks if the
|
|
513
|
-
* thing passed in is an instance of Uint8Array
|
|
514
|
-
*
|
|
515
|
-
* @param {TypedArray}
|
|
516
|
-
*
|
|
517
|
-
* @returns {Array}
|
|
518
|
-
*/
|
|
519
|
-
// eslint-disable-next-line func-names
|
|
520
|
-
const isTypedArray = (TypedArray => {
|
|
521
|
-
// eslint-disable-next-line func-names
|
|
522
|
-
return thing => {
|
|
523
|
-
return TypedArray && thing instanceof TypedArray;
|
|
524
|
-
};
|
|
525
|
-
})(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* For each entry in the object, call the function with the key and value.
|
|
529
|
-
*
|
|
530
|
-
* @param {Object<any, any>} obj - The object to iterate over.
|
|
531
|
-
* @param {Function} fn - The function to call for each entry.
|
|
532
|
-
*
|
|
533
|
-
* @returns {void}
|
|
534
|
-
*/
|
|
535
|
-
const forEachEntry = (obj, fn) => {
|
|
536
|
-
const generator = obj && obj[Symbol.iterator];
|
|
537
|
-
|
|
538
|
-
const iterator = generator.call(obj);
|
|
539
|
-
|
|
540
|
-
let result;
|
|
541
|
-
|
|
542
|
-
while ((result = iterator.next()) && !result.done) {
|
|
543
|
-
const pair = result.value;
|
|
544
|
-
fn.call(obj, pair[0], pair[1]);
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* It takes a regular expression and a string, and returns an array of all the matches
|
|
550
|
-
*
|
|
551
|
-
* @param {string} regExp - The regular expression to match against.
|
|
552
|
-
* @param {string} str - The string to search.
|
|
553
|
-
*
|
|
554
|
-
* @returns {Array<boolean>}
|
|
555
|
-
*/
|
|
556
|
-
const matchAll = (regExp, str) => {
|
|
557
|
-
let matches;
|
|
558
|
-
const arr = [];
|
|
559
|
-
|
|
560
|
-
while ((matches = regExp.exec(str)) !== null) {
|
|
561
|
-
arr.push(matches);
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
return arr;
|
|
565
|
-
};
|
|
566
|
-
|
|
567
|
-
/* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
|
|
568
|
-
const isHTMLForm = kindOfTest('HTMLFormElement');
|
|
569
|
-
|
|
570
|
-
const toCamelCase = str => {
|
|
571
|
-
return str.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,
|
|
572
|
-
function replacer(m, p1, p2) {
|
|
573
|
-
return p1.toUpperCase() + p2;
|
|
574
|
-
}
|
|
575
|
-
);
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
/* Creating a function that will check if an object has a property. */
|
|
579
|
-
const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Determine if a value is a RegExp object
|
|
583
|
-
*
|
|
584
|
-
* @param {*} val The value to test
|
|
585
|
-
*
|
|
586
|
-
* @returns {boolean} True if value is a RegExp object, otherwise false
|
|
587
|
-
*/
|
|
588
|
-
const isRegExp = kindOfTest('RegExp');
|
|
589
|
-
|
|
590
|
-
const reduceDescriptors = (obj, reducer) => {
|
|
591
|
-
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
592
|
-
const reducedDescriptors = {};
|
|
593
|
-
|
|
594
|
-
forEach(descriptors, (descriptor, name) => {
|
|
595
|
-
let ret;
|
|
596
|
-
if ((ret = reducer(descriptor, name, obj)) !== false) {
|
|
597
|
-
reducedDescriptors[name] = ret || descriptor;
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
Object.defineProperties(obj, reducedDescriptors);
|
|
602
|
-
};
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* Makes all methods read-only
|
|
606
|
-
* @param {Object} obj
|
|
607
|
-
*/
|
|
608
|
-
|
|
609
|
-
const freezeMethods = (obj) => {
|
|
610
|
-
reduceDescriptors(obj, (descriptor, name) => {
|
|
611
|
-
// skip restricted props in strict mode
|
|
612
|
-
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
const value = obj[name];
|
|
617
|
-
|
|
618
|
-
if (!isFunction(value)) return;
|
|
619
|
-
|
|
620
|
-
descriptor.enumerable = false;
|
|
621
|
-
|
|
622
|
-
if ('writable' in descriptor) {
|
|
623
|
-
descriptor.writable = false;
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
if (!descriptor.set) {
|
|
628
|
-
descriptor.set = () => {
|
|
629
|
-
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
};
|
|
634
|
-
|
|
635
|
-
const toObjectSet = (arrayOrString, delimiter) => {
|
|
636
|
-
const obj = {};
|
|
637
|
-
|
|
638
|
-
const define = (arr) => {
|
|
639
|
-
arr.forEach(value => {
|
|
640
|
-
obj[value] = true;
|
|
641
|
-
});
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
|
|
645
|
-
|
|
646
|
-
return obj;
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
const noop = () => {};
|
|
650
|
-
|
|
651
|
-
const toFiniteNumber = (value, defaultValue) => {
|
|
652
|
-
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|
656
|
-
|
|
657
|
-
const DIGIT = '0123456789';
|
|
658
|
-
|
|
659
|
-
const ALPHABET = {
|
|
660
|
-
DIGIT,
|
|
661
|
-
ALPHA,
|
|
662
|
-
ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
|
|
663
|
-
};
|
|
664
|
-
|
|
665
|
-
const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
666
|
-
let str = '';
|
|
667
|
-
const {length} = alphabet;
|
|
668
|
-
while (size--) {
|
|
669
|
-
str += alphabet[Math.random() * length|0];
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
return str;
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
/**
|
|
676
|
-
* If the thing is a FormData object, return true, otherwise return false.
|
|
677
|
-
*
|
|
678
|
-
* @param {unknown} thing - The thing to check.
|
|
679
|
-
*
|
|
680
|
-
* @returns {boolean}
|
|
681
|
-
*/
|
|
682
|
-
function isSpecCompliantForm(thing) {
|
|
683
|
-
return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
const toJSONObject = (obj) => {
|
|
687
|
-
const stack = new Array(10);
|
|
688
|
-
|
|
689
|
-
const visit = (source, i) => {
|
|
690
|
-
|
|
691
|
-
if (isObject(source)) {
|
|
692
|
-
if (stack.indexOf(source) >= 0) {
|
|
693
|
-
return;
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
if(!('toJSON' in source)) {
|
|
697
|
-
stack[i] = source;
|
|
698
|
-
const target = isArray(source) ? [] : {};
|
|
699
|
-
|
|
700
|
-
forEach(source, (value, key) => {
|
|
701
|
-
const reducedValue = visit(value, i + 1);
|
|
702
|
-
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
|
703
|
-
});
|
|
704
|
-
|
|
705
|
-
stack[i] = undefined;
|
|
706
|
-
|
|
707
|
-
return target;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
return source;
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
return visit(obj, 0);
|
|
715
|
-
};
|
|
716
|
-
|
|
717
|
-
const isAsyncFn = kindOfTest('AsyncFunction');
|
|
718
|
-
|
|
719
|
-
const isThenable = (thing) =>
|
|
720
|
-
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
|
721
|
-
|
|
722
|
-
// original code
|
|
723
|
-
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|
724
|
-
|
|
725
|
-
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
726
|
-
if (setImmediateSupported) {
|
|
727
|
-
return setImmediate;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
return postMessageSupported ? ((token, callbacks) => {
|
|
731
|
-
_global.addEventListener("message", ({source, data}) => {
|
|
732
|
-
if (source === _global && data === token) {
|
|
733
|
-
callbacks.length && callbacks.shift()();
|
|
734
|
-
}
|
|
735
|
-
}, false);
|
|
736
|
-
|
|
737
|
-
return (cb) => {
|
|
738
|
-
callbacks.push(cb);
|
|
739
|
-
_global.postMessage(token, "*");
|
|
740
|
-
}
|
|
741
|
-
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
742
|
-
})(
|
|
743
|
-
typeof setImmediate === 'function',
|
|
744
|
-
isFunction(_global.postMessage)
|
|
745
|
-
);
|
|
746
|
-
|
|
747
|
-
const asap = typeof queueMicrotask !== 'undefined' ?
|
|
748
|
-
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
|
749
|
-
|
|
750
|
-
// *********************
|
|
751
|
-
|
|
752
|
-
var utils$1 = {
|
|
753
|
-
isArray,
|
|
754
|
-
isArrayBuffer,
|
|
755
|
-
isBuffer,
|
|
756
|
-
isFormData,
|
|
757
|
-
isArrayBufferView,
|
|
758
|
-
isString,
|
|
759
|
-
isNumber,
|
|
760
|
-
isBoolean,
|
|
761
|
-
isObject,
|
|
762
|
-
isPlainObject,
|
|
763
|
-
isReadableStream,
|
|
764
|
-
isRequest,
|
|
765
|
-
isResponse,
|
|
766
|
-
isHeaders,
|
|
767
|
-
isUndefined,
|
|
768
|
-
isDate,
|
|
769
|
-
isFile,
|
|
770
|
-
isBlob,
|
|
771
|
-
isRegExp,
|
|
772
|
-
isFunction,
|
|
773
|
-
isStream,
|
|
774
|
-
isURLSearchParams,
|
|
775
|
-
isTypedArray,
|
|
776
|
-
isFileList,
|
|
777
|
-
forEach,
|
|
778
|
-
merge,
|
|
779
|
-
extend,
|
|
780
|
-
trim,
|
|
781
|
-
stripBOM,
|
|
782
|
-
inherits,
|
|
783
|
-
toFlatObject,
|
|
784
|
-
kindOf,
|
|
785
|
-
kindOfTest,
|
|
786
|
-
endsWith,
|
|
787
|
-
toArray,
|
|
788
|
-
forEachEntry,
|
|
789
|
-
matchAll,
|
|
790
|
-
isHTMLForm,
|
|
791
|
-
hasOwnProperty,
|
|
792
|
-
hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
|
|
793
|
-
reduceDescriptors,
|
|
794
|
-
freezeMethods,
|
|
795
|
-
toObjectSet,
|
|
796
|
-
toCamelCase,
|
|
797
|
-
noop,
|
|
798
|
-
toFiniteNumber,
|
|
799
|
-
findKey,
|
|
800
|
-
global: _global,
|
|
801
|
-
isContextDefined,
|
|
802
|
-
ALPHABET,
|
|
803
|
-
generateString,
|
|
804
|
-
isSpecCompliantForm,
|
|
805
|
-
toJSONObject,
|
|
806
|
-
isAsyncFn,
|
|
807
|
-
isThenable,
|
|
808
|
-
setImmediate: _setImmediate,
|
|
809
|
-
asap
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
/**
|
|
813
|
-
* Create an Error with the specified message, config, error code, request and response.
|
|
814
|
-
*
|
|
815
|
-
* @param {string} message The error message.
|
|
816
|
-
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
817
|
-
* @param {Object} [config] The config.
|
|
818
|
-
* @param {Object} [request] The request.
|
|
819
|
-
* @param {Object} [response] The response.
|
|
820
|
-
*
|
|
821
|
-
* @returns {Error} The created error.
|
|
822
|
-
*/
|
|
823
|
-
function AxiosError(message, code, config, request, response) {
|
|
824
|
-
Error.call(this);
|
|
825
|
-
|
|
826
|
-
if (Error.captureStackTrace) {
|
|
827
|
-
Error.captureStackTrace(this, this.constructor);
|
|
828
|
-
} else {
|
|
829
|
-
this.stack = (new Error()).stack;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
this.message = message;
|
|
833
|
-
this.name = 'AxiosError';
|
|
834
|
-
code && (this.code = code);
|
|
835
|
-
config && (this.config = config);
|
|
836
|
-
request && (this.request = request);
|
|
837
|
-
response && (this.response = response);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
utils$1.inherits(AxiosError, Error, {
|
|
841
|
-
toJSON: function toJSON() {
|
|
842
|
-
return {
|
|
843
|
-
// Standard
|
|
844
|
-
message: this.message,
|
|
845
|
-
name: this.name,
|
|
846
|
-
// Microsoft
|
|
847
|
-
description: this.description,
|
|
848
|
-
number: this.number,
|
|
849
|
-
// Mozilla
|
|
850
|
-
fileName: this.fileName,
|
|
851
|
-
lineNumber: this.lineNumber,
|
|
852
|
-
columnNumber: this.columnNumber,
|
|
853
|
-
stack: this.stack,
|
|
854
|
-
// Axios
|
|
855
|
-
config: utils$1.toJSONObject(this.config),
|
|
856
|
-
code: this.code,
|
|
857
|
-
status: this.response && this.response.status ? this.response.status : null
|
|
858
|
-
};
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
const prototype$1 = AxiosError.prototype;
|
|
863
|
-
const descriptors = {};
|
|
864
|
-
|
|
865
|
-
[
|
|
866
|
-
'ERR_BAD_OPTION_VALUE',
|
|
867
|
-
'ERR_BAD_OPTION',
|
|
868
|
-
'ECONNABORTED',
|
|
869
|
-
'ETIMEDOUT',
|
|
870
|
-
'ERR_NETWORK',
|
|
871
|
-
'ERR_FR_TOO_MANY_REDIRECTS',
|
|
872
|
-
'ERR_DEPRECATED',
|
|
873
|
-
'ERR_BAD_RESPONSE',
|
|
874
|
-
'ERR_BAD_REQUEST',
|
|
875
|
-
'ERR_CANCELED',
|
|
876
|
-
'ERR_NOT_SUPPORT',
|
|
877
|
-
'ERR_INVALID_URL'
|
|
878
|
-
// eslint-disable-next-line func-names
|
|
879
|
-
].forEach(code => {
|
|
880
|
-
descriptors[code] = {value: code};
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
Object.defineProperties(AxiosError, descriptors);
|
|
884
|
-
Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
|
|
885
|
-
|
|
886
|
-
// eslint-disable-next-line func-names
|
|
887
|
-
AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
888
|
-
const axiosError = Object.create(prototype$1);
|
|
889
|
-
|
|
890
|
-
utils$1.toFlatObject(error, axiosError, function filter(obj) {
|
|
891
|
-
return obj !== Error.prototype;
|
|
892
|
-
}, prop => {
|
|
893
|
-
return prop !== 'isAxiosError';
|
|
894
|
-
});
|
|
895
|
-
|
|
896
|
-
AxiosError.call(axiosError, error.message, code, config, request, response);
|
|
897
|
-
|
|
898
|
-
axiosError.cause = error;
|
|
899
|
-
|
|
900
|
-
axiosError.name = error.name;
|
|
901
|
-
|
|
902
|
-
customProps && Object.assign(axiosError, customProps);
|
|
903
|
-
|
|
904
|
-
return axiosError;
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
// eslint-disable-next-line strict
|
|
908
|
-
var httpAdapter = null;
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* Determines if the given thing is a array or js object.
|
|
912
|
-
*
|
|
913
|
-
* @param {string} thing - The object or array to be visited.
|
|
914
|
-
*
|
|
915
|
-
* @returns {boolean}
|
|
916
|
-
*/
|
|
917
|
-
function isVisitable(thing) {
|
|
918
|
-
return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
/**
|
|
922
|
-
* It removes the brackets from the end of a string
|
|
923
|
-
*
|
|
924
|
-
* @param {string} key - The key of the parameter.
|
|
925
|
-
*
|
|
926
|
-
* @returns {string} the key without the brackets.
|
|
927
|
-
*/
|
|
928
|
-
function removeBrackets(key) {
|
|
929
|
-
return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
/**
|
|
933
|
-
* It takes a path, a key, and a boolean, and returns a string
|
|
934
|
-
*
|
|
935
|
-
* @param {string} path - The path to the current key.
|
|
936
|
-
* @param {string} key - The key of the current object being iterated over.
|
|
937
|
-
* @param {string} dots - If true, the key will be rendered with dots instead of brackets.
|
|
938
|
-
*
|
|
939
|
-
* @returns {string} The path to the current key.
|
|
940
|
-
*/
|
|
941
|
-
function renderKey(path, key, dots) {
|
|
942
|
-
if (!path) return key;
|
|
943
|
-
return path.concat(key).map(function each(token, i) {
|
|
944
|
-
// eslint-disable-next-line no-param-reassign
|
|
945
|
-
token = removeBrackets(token);
|
|
946
|
-
return !dots && i ? '[' + token + ']' : token;
|
|
947
|
-
}).join(dots ? '.' : '');
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
/**
|
|
951
|
-
* If the array is an array and none of its elements are visitable, then it's a flat array.
|
|
952
|
-
*
|
|
953
|
-
* @param {Array<any>} arr - The array to check
|
|
954
|
-
*
|
|
955
|
-
* @returns {boolean}
|
|
956
|
-
*/
|
|
957
|
-
function isFlatArray(arr) {
|
|
958
|
-
return utils$1.isArray(arr) && !arr.some(isVisitable);
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
|
|
962
|
-
return /^is[A-Z]/.test(prop);
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
/**
|
|
966
|
-
* Convert a data object to FormData
|
|
967
|
-
*
|
|
968
|
-
* @param {Object} obj
|
|
969
|
-
* @param {?Object} [formData]
|
|
970
|
-
* @param {?Object} [options]
|
|
971
|
-
* @param {Function} [options.visitor]
|
|
972
|
-
* @param {Boolean} [options.metaTokens = true]
|
|
973
|
-
* @param {Boolean} [options.dots = false]
|
|
974
|
-
* @param {?Boolean} [options.indexes = false]
|
|
975
|
-
*
|
|
976
|
-
* @returns {Object}
|
|
977
|
-
**/
|
|
978
|
-
|
|
979
|
-
/**
|
|
980
|
-
* It converts an object into a FormData object
|
|
981
|
-
*
|
|
982
|
-
* @param {Object<any, any>} obj - The object to convert to form data.
|
|
983
|
-
* @param {string} formData - The FormData object to append to.
|
|
984
|
-
* @param {Object<string, any>} options
|
|
985
|
-
*
|
|
986
|
-
* @returns
|
|
987
|
-
*/
|
|
988
|
-
function toFormData(obj, formData, options) {
|
|
989
|
-
if (!utils$1.isObject(obj)) {
|
|
990
|
-
throw new TypeError('target must be an object');
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
// eslint-disable-next-line no-param-reassign
|
|
994
|
-
formData = formData || new (FormData)();
|
|
995
|
-
|
|
996
|
-
// eslint-disable-next-line no-param-reassign
|
|
997
|
-
options = utils$1.toFlatObject(options, {
|
|
998
|
-
metaTokens: true,
|
|
999
|
-
dots: false,
|
|
1000
|
-
indexes: false
|
|
1001
|
-
}, false, function defined(option, source) {
|
|
1002
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
1003
|
-
return !utils$1.isUndefined(source[option]);
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
const metaTokens = options.metaTokens;
|
|
1007
|
-
// eslint-disable-next-line no-use-before-define
|
|
1008
|
-
const visitor = options.visitor || defaultVisitor;
|
|
1009
|
-
const dots = options.dots;
|
|
1010
|
-
const indexes = options.indexes;
|
|
1011
|
-
const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
|
1012
|
-
const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
|
|
1013
|
-
|
|
1014
|
-
if (!utils$1.isFunction(visitor)) {
|
|
1015
|
-
throw new TypeError('visitor must be a function');
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
function convertValue(value) {
|
|
1019
|
-
if (value === null) return '';
|
|
1020
|
-
|
|
1021
|
-
if (utils$1.isDate(value)) {
|
|
1022
|
-
return value.toISOString();
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
if (!useBlob && utils$1.isBlob(value)) {
|
|
1026
|
-
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
|
|
1030
|
-
return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
return value;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
/**
|
|
1037
|
-
* Default visitor.
|
|
1038
|
-
*
|
|
1039
|
-
* @param {*} value
|
|
1040
|
-
* @param {String|Number} key
|
|
1041
|
-
* @param {Array<String|Number>} path
|
|
1042
|
-
* @this {FormData}
|
|
1043
|
-
*
|
|
1044
|
-
* @returns {boolean} return true to visit the each prop of the value recursively
|
|
1045
|
-
*/
|
|
1046
|
-
function defaultVisitor(value, key, path) {
|
|
1047
|
-
let arr = value;
|
|
1048
|
-
|
|
1049
|
-
if (value && !path && typeof value === 'object') {
|
|
1050
|
-
if (utils$1.endsWith(key, '{}')) {
|
|
1051
|
-
// eslint-disable-next-line no-param-reassign
|
|
1052
|
-
key = metaTokens ? key : key.slice(0, -2);
|
|
1053
|
-
// eslint-disable-next-line no-param-reassign
|
|
1054
|
-
value = JSON.stringify(value);
|
|
1055
|
-
} else if (
|
|
1056
|
-
(utils$1.isArray(value) && isFlatArray(value)) ||
|
|
1057
|
-
((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value))
|
|
1058
|
-
)) {
|
|
1059
|
-
// eslint-disable-next-line no-param-reassign
|
|
1060
|
-
key = removeBrackets(key);
|
|
1061
|
-
|
|
1062
|
-
arr.forEach(function each(el, index) {
|
|
1063
|
-
!(utils$1.isUndefined(el) || el === null) && formData.append(
|
|
1064
|
-
// eslint-disable-next-line no-nested-ternary
|
|
1065
|
-
indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
|
|
1066
|
-
convertValue(el)
|
|
1067
|
-
);
|
|
1068
|
-
});
|
|
1069
|
-
return false;
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
if (isVisitable(value)) {
|
|
1074
|
-
return true;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
formData.append(renderKey(path, key, dots), convertValue(value));
|
|
1078
|
-
|
|
1079
|
-
return false;
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
const stack = [];
|
|
1083
|
-
|
|
1084
|
-
const exposedHelpers = Object.assign(predicates, {
|
|
1085
|
-
defaultVisitor,
|
|
1086
|
-
convertValue,
|
|
1087
|
-
isVisitable
|
|
1088
|
-
});
|
|
1089
|
-
|
|
1090
|
-
function build(value, path) {
|
|
1091
|
-
if (utils$1.isUndefined(value)) return;
|
|
1092
|
-
|
|
1093
|
-
if (stack.indexOf(value) !== -1) {
|
|
1094
|
-
throw Error('Circular reference detected in ' + path.join('.'));
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
stack.push(value);
|
|
1098
|
-
|
|
1099
|
-
utils$1.forEach(value, function each(el, key) {
|
|
1100
|
-
const result = !(utils$1.isUndefined(el) || el === null) && visitor.call(
|
|
1101
|
-
formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers
|
|
1102
|
-
);
|
|
1103
|
-
|
|
1104
|
-
if (result === true) {
|
|
1105
|
-
build(el, path ? path.concat(key) : [key]);
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
|
-
|
|
1109
|
-
stack.pop();
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
if (!utils$1.isObject(obj)) {
|
|
1113
|
-
throw new TypeError('data must be an object');
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
build(obj);
|
|
1117
|
-
|
|
1118
|
-
return formData;
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* It encodes a string by replacing all characters that are not in the unreserved set with
|
|
1123
|
-
* their percent-encoded equivalents
|
|
1124
|
-
*
|
|
1125
|
-
* @param {string} str - The string to encode.
|
|
1126
|
-
*
|
|
1127
|
-
* @returns {string} The encoded string.
|
|
1128
|
-
*/
|
|
1129
|
-
function encode$1(str) {
|
|
1130
|
-
const charMap = {
|
|
1131
|
-
'!': '%21',
|
|
1132
|
-
"'": '%27',
|
|
1133
|
-
'(': '%28',
|
|
1134
|
-
')': '%29',
|
|
1135
|
-
'~': '%7E',
|
|
1136
|
-
'%20': '+',
|
|
1137
|
-
'%00': '\x00'
|
|
1138
|
-
};
|
|
1139
|
-
return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
|
|
1140
|
-
return charMap[match];
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
/**
|
|
1145
|
-
* It takes a params object and converts it to a FormData object
|
|
1146
|
-
*
|
|
1147
|
-
* @param {Object<string, any>} params - The parameters to be converted to a FormData object.
|
|
1148
|
-
* @param {Object<string, any>} options - The options object passed to the Axios constructor.
|
|
1149
|
-
*
|
|
1150
|
-
* @returns {void}
|
|
1151
|
-
*/
|
|
1152
|
-
function AxiosURLSearchParams(params, options) {
|
|
1153
|
-
this._pairs = [];
|
|
1154
|
-
|
|
1155
|
-
params && toFormData(params, this, options);
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
const prototype = AxiosURLSearchParams.prototype;
|
|
1159
|
-
|
|
1160
|
-
prototype.append = function append(name, value) {
|
|
1161
|
-
this._pairs.push([name, value]);
|
|
1162
|
-
};
|
|
1163
|
-
|
|
1164
|
-
prototype.toString = function toString(encoder) {
|
|
1165
|
-
const _encode = encoder ? function(value) {
|
|
1166
|
-
return encoder.call(this, value, encode$1);
|
|
1167
|
-
} : encode$1;
|
|
1168
|
-
|
|
1169
|
-
return this._pairs.map(function each(pair) {
|
|
1170
|
-
return _encode(pair[0]) + '=' + _encode(pair[1]);
|
|
1171
|
-
}, '').join('&');
|
|
1172
|
-
};
|
|
1173
|
-
|
|
1174
|
-
/**
|
|
1175
|
-
* It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
|
|
1176
|
-
* URI encoded counterparts
|
|
1177
|
-
*
|
|
1178
|
-
* @param {string} val The value to be encoded.
|
|
1179
|
-
*
|
|
1180
|
-
* @returns {string} The encoded value.
|
|
1181
|
-
*/
|
|
1182
|
-
function encode(val) {
|
|
1183
|
-
return encodeURIComponent(val).
|
|
1184
|
-
replace(/%3A/gi, ':').
|
|
1185
|
-
replace(/%24/g, '$').
|
|
1186
|
-
replace(/%2C/gi, ',').
|
|
1187
|
-
replace(/%20/g, '+').
|
|
1188
|
-
replace(/%5B/gi, '[').
|
|
1189
|
-
replace(/%5D/gi, ']');
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
/**
|
|
1193
|
-
* Build a URL by appending params to the end
|
|
1194
|
-
*
|
|
1195
|
-
* @param {string} url The base of the url (e.g., http://www.google.com)
|
|
1196
|
-
* @param {object} [params] The params to be appended
|
|
1197
|
-
* @param {?object} options
|
|
1198
|
-
*
|
|
1199
|
-
* @returns {string} The formatted url
|
|
1200
|
-
*/
|
|
1201
|
-
function buildURL(url, params, options) {
|
|
1202
|
-
/*eslint no-param-reassign:0*/
|
|
1203
|
-
if (!params) {
|
|
1204
|
-
return url;
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
const _encode = options && options.encode || encode;
|
|
1208
|
-
|
|
1209
|
-
const serializeFn = options && options.serialize;
|
|
1210
|
-
|
|
1211
|
-
let serializedParams;
|
|
1212
|
-
|
|
1213
|
-
if (serializeFn) {
|
|
1214
|
-
serializedParams = serializeFn(params, options);
|
|
1215
|
-
} else {
|
|
1216
|
-
serializedParams = utils$1.isURLSearchParams(params) ?
|
|
1217
|
-
params.toString() :
|
|
1218
|
-
new AxiosURLSearchParams(params, options).toString(_encode);
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
if (serializedParams) {
|
|
1222
|
-
const hashmarkIndex = url.indexOf("#");
|
|
1223
|
-
|
|
1224
|
-
if (hashmarkIndex !== -1) {
|
|
1225
|
-
url = url.slice(0, hashmarkIndex);
|
|
1226
|
-
}
|
|
1227
|
-
url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
return url;
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
class InterceptorManager {
|
|
1234
|
-
constructor() {
|
|
1235
|
-
this.handlers = [];
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
/**
|
|
1239
|
-
* Add a new interceptor to the stack
|
|
1240
|
-
*
|
|
1241
|
-
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
|
1242
|
-
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
|
1243
|
-
*
|
|
1244
|
-
* @return {Number} An ID used to remove interceptor later
|
|
1245
|
-
*/
|
|
1246
|
-
use(fulfilled, rejected, options) {
|
|
1247
|
-
this.handlers.push({
|
|
1248
|
-
fulfilled,
|
|
1249
|
-
rejected,
|
|
1250
|
-
synchronous: options ? options.synchronous : false,
|
|
1251
|
-
runWhen: options ? options.runWhen : null
|
|
1252
|
-
});
|
|
1253
|
-
return this.handlers.length - 1;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
/**
|
|
1257
|
-
* Remove an interceptor from the stack
|
|
1258
|
-
*
|
|
1259
|
-
* @param {Number} id The ID that was returned by `use`
|
|
1260
|
-
*
|
|
1261
|
-
* @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
|
|
1262
|
-
*/
|
|
1263
|
-
eject(id) {
|
|
1264
|
-
if (this.handlers[id]) {
|
|
1265
|
-
this.handlers[id] = null;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
/**
|
|
1270
|
-
* Clear all interceptors from the stack
|
|
1271
|
-
*
|
|
1272
|
-
* @returns {void}
|
|
1273
|
-
*/
|
|
1274
|
-
clear() {
|
|
1275
|
-
if (this.handlers) {
|
|
1276
|
-
this.handlers = [];
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
/**
|
|
1281
|
-
* Iterate over all the registered interceptors
|
|
1282
|
-
*
|
|
1283
|
-
* This method is particularly useful for skipping over any
|
|
1284
|
-
* interceptors that may have become `null` calling `eject`.
|
|
1285
|
-
*
|
|
1286
|
-
* @param {Function} fn The function to call for each interceptor
|
|
1287
|
-
*
|
|
1288
|
-
* @returns {void}
|
|
1289
|
-
*/
|
|
1290
|
-
forEach(fn) {
|
|
1291
|
-
utils$1.forEach(this.handlers, function forEachHandler(h) {
|
|
1292
|
-
if (h !== null) {
|
|
1293
|
-
fn(h);
|
|
1294
|
-
}
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
|
|
1299
|
-
var transitionalDefaults = {
|
|
1300
|
-
silentJSONParsing: true,
|
|
1301
|
-
forcedJSONParsing: true,
|
|
1302
|
-
clarifyTimeoutError: false
|
|
1303
|
-
};
|
|
1304
|
-
|
|
1305
|
-
var URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
|
|
1306
|
-
|
|
1307
|
-
var FormData$1 = typeof FormData !== 'undefined' ? FormData : null;
|
|
1308
|
-
|
|
1309
|
-
var Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
|
|
1310
|
-
|
|
1311
|
-
var platform$1 = {
|
|
1312
|
-
isBrowser: true,
|
|
1313
|
-
classes: {
|
|
1314
|
-
URLSearchParams: URLSearchParams$1,
|
|
1315
|
-
FormData: FormData$1,
|
|
1316
|
-
Blob: Blob$1
|
|
1317
|
-
},
|
|
1318
|
-
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
|
1319
|
-
};
|
|
1320
|
-
|
|
1321
|
-
const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
1322
|
-
|
|
1323
|
-
/**
|
|
1324
|
-
* Determine if we're running in a standard browser environment
|
|
1325
|
-
*
|
|
1326
|
-
* This allows axios to run in a web worker, and react-native.
|
|
1327
|
-
* Both environments support XMLHttpRequest, but not fully standard globals.
|
|
1328
|
-
*
|
|
1329
|
-
* web workers:
|
|
1330
|
-
* typeof window -> undefined
|
|
1331
|
-
* typeof document -> undefined
|
|
1332
|
-
*
|
|
1333
|
-
* react-native:
|
|
1334
|
-
* navigator.product -> 'ReactNative'
|
|
1335
|
-
* nativescript
|
|
1336
|
-
* navigator.product -> 'NativeScript' or 'NS'
|
|
1337
|
-
*
|
|
1338
|
-
* @returns {boolean}
|
|
1339
|
-
*/
|
|
1340
|
-
const hasStandardBrowserEnv = (
|
|
1341
|
-
(product) => {
|
|
1342
|
-
return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
|
|
1343
|
-
})(typeof navigator !== 'undefined' && navigator.product);
|
|
1344
|
-
|
|
1345
|
-
/**
|
|
1346
|
-
* Determine if we're running in a standard browser webWorker environment
|
|
1347
|
-
*
|
|
1348
|
-
* Although the `isStandardBrowserEnv` method indicates that
|
|
1349
|
-
* `allows axios to run in a web worker`, the WebWorker will still be
|
|
1350
|
-
* filtered out due to its judgment standard
|
|
1351
|
-
* `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
|
1352
|
-
* This leads to a problem when axios post `FormData` in webWorker
|
|
1353
|
-
*/
|
|
1354
|
-
const hasStandardBrowserWebWorkerEnv = (() => {
|
|
1355
|
-
return (
|
|
1356
|
-
typeof WorkerGlobalScope !== 'undefined' &&
|
|
1357
|
-
// eslint-disable-next-line no-undef
|
|
1358
|
-
self instanceof WorkerGlobalScope &&
|
|
1359
|
-
typeof self.importScripts === 'function'
|
|
1360
|
-
);
|
|
1361
|
-
})();
|
|
1362
|
-
|
|
1363
|
-
const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
|
1364
|
-
|
|
1365
|
-
var utils = /*#__PURE__*/Object.freeze({
|
|
1366
|
-
__proto__: null,
|
|
1367
|
-
hasBrowserEnv: hasBrowserEnv,
|
|
1368
|
-
hasStandardBrowserEnv: hasStandardBrowserEnv,
|
|
1369
|
-
hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
|
|
1370
|
-
origin: origin
|
|
1371
|
-
});
|
|
1372
|
-
|
|
1373
|
-
var platform = {
|
|
1374
|
-
...utils,
|
|
1375
|
-
...platform$1
|
|
1376
|
-
};
|
|
1377
|
-
|
|
1378
|
-
function toURLEncodedForm(data, options) {
|
|
1379
|
-
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
|
1380
|
-
visitor: function(value, key, path, helpers) {
|
|
1381
|
-
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
1382
|
-
this.append(key, value.toString('base64'));
|
|
1383
|
-
return false;
|
|
1384
|
-
}
|
|
1385
|
-
|
|
1386
|
-
return helpers.defaultVisitor.apply(this, arguments);
|
|
1387
|
-
}
|
|
1388
|
-
}, options));
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
/**
|
|
1392
|
-
* It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
|
|
1393
|
-
*
|
|
1394
|
-
* @param {string} name - The name of the property to get.
|
|
1395
|
-
*
|
|
1396
|
-
* @returns An array of strings.
|
|
1397
|
-
*/
|
|
1398
|
-
function parsePropPath(name) {
|
|
1399
|
-
// foo[x][y][z]
|
|
1400
|
-
// foo.x.y.z
|
|
1401
|
-
// foo-x-y-z
|
|
1402
|
-
// foo x y z
|
|
1403
|
-
return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
|
|
1404
|
-
return match[0] === '[]' ? '' : match[1] || match[0];
|
|
1405
|
-
});
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
/**
|
|
1409
|
-
* Convert an array to an object.
|
|
1410
|
-
*
|
|
1411
|
-
* @param {Array<any>} arr - The array to convert to an object.
|
|
1412
|
-
*
|
|
1413
|
-
* @returns An object with the same keys and values as the array.
|
|
1414
|
-
*/
|
|
1415
|
-
function arrayToObject(arr) {
|
|
1416
|
-
const obj = {};
|
|
1417
|
-
const keys = Object.keys(arr);
|
|
1418
|
-
let i;
|
|
1419
|
-
const len = keys.length;
|
|
1420
|
-
let key;
|
|
1421
|
-
for (i = 0; i < len; i++) {
|
|
1422
|
-
key = keys[i];
|
|
1423
|
-
obj[key] = arr[key];
|
|
1424
|
-
}
|
|
1425
|
-
return obj;
|
|
1426
|
-
}
|
|
1427
|
-
|
|
1428
|
-
/**
|
|
1429
|
-
* It takes a FormData object and returns a JavaScript object
|
|
1430
|
-
*
|
|
1431
|
-
* @param {string} formData The FormData object to convert to JSON.
|
|
1432
|
-
*
|
|
1433
|
-
* @returns {Object<string, any> | null} The converted object.
|
|
1434
|
-
*/
|
|
1435
|
-
function formDataToJSON(formData) {
|
|
1436
|
-
function buildPath(path, value, target, index) {
|
|
1437
|
-
let name = path[index++];
|
|
1438
|
-
|
|
1439
|
-
if (name === '__proto__') return true;
|
|
1440
|
-
|
|
1441
|
-
const isNumericKey = Number.isFinite(+name);
|
|
1442
|
-
const isLast = index >= path.length;
|
|
1443
|
-
name = !name && utils$1.isArray(target) ? target.length : name;
|
|
1444
|
-
|
|
1445
|
-
if (isLast) {
|
|
1446
|
-
if (utils$1.hasOwnProp(target, name)) {
|
|
1447
|
-
target[name] = [target[name], value];
|
|
1448
|
-
} else {
|
|
1449
|
-
target[name] = value;
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
return !isNumericKey;
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
if (!target[name] || !utils$1.isObject(target[name])) {
|
|
1456
|
-
target[name] = [];
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
const result = buildPath(path, value, target[name], index);
|
|
1460
|
-
|
|
1461
|
-
if (result && utils$1.isArray(target[name])) {
|
|
1462
|
-
target[name] = arrayToObject(target[name]);
|
|
1463
|
-
}
|
|
1464
|
-
|
|
1465
|
-
return !isNumericKey;
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
|
|
1469
|
-
const obj = {};
|
|
1470
|
-
|
|
1471
|
-
utils$1.forEachEntry(formData, (name, value) => {
|
|
1472
|
-
buildPath(parsePropPath(name), value, obj, 0);
|
|
1473
|
-
});
|
|
1474
|
-
|
|
1475
|
-
return obj;
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
return null;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
/**
|
|
1482
|
-
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
|
1483
|
-
* of the input
|
|
1484
|
-
*
|
|
1485
|
-
* @param {any} rawValue - The value to be stringified.
|
|
1486
|
-
* @param {Function} parser - A function that parses a string into a JavaScript object.
|
|
1487
|
-
* @param {Function} encoder - A function that takes a value and returns a string.
|
|
1488
|
-
*
|
|
1489
|
-
* @returns {string} A stringified version of the rawValue.
|
|
1490
|
-
*/
|
|
1491
|
-
function stringifySafely(rawValue, parser, encoder) {
|
|
1492
|
-
if (utils$1.isString(rawValue)) {
|
|
1493
|
-
try {
|
|
1494
|
-
(parser || JSON.parse)(rawValue);
|
|
1495
|
-
return utils$1.trim(rawValue);
|
|
1496
|
-
} catch (e) {
|
|
1497
|
-
if (e.name !== 'SyntaxError') {
|
|
1498
|
-
throw e;
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
return (0, JSON.stringify)(rawValue);
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
const defaults$1 = {
|
|
1507
|
-
|
|
1508
|
-
transitional: transitionalDefaults,
|
|
1509
|
-
|
|
1510
|
-
adapter: ['xhr', 'http', 'fetch'],
|
|
1511
|
-
|
|
1512
|
-
transformRequest: [function transformRequest(data, headers) {
|
|
1513
|
-
const contentType = headers.getContentType() || '';
|
|
1514
|
-
const hasJSONContentType = contentType.indexOf('application/json') > -1;
|
|
1515
|
-
const isObjectPayload = utils$1.isObject(data);
|
|
1516
|
-
|
|
1517
|
-
if (isObjectPayload && utils$1.isHTMLForm(data)) {
|
|
1518
|
-
data = new FormData(data);
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
const isFormData = utils$1.isFormData(data);
|
|
1522
|
-
|
|
1523
|
-
if (isFormData) {
|
|
1524
|
-
return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
if (utils$1.isArrayBuffer(data) ||
|
|
1528
|
-
utils$1.isBuffer(data) ||
|
|
1529
|
-
utils$1.isStream(data) ||
|
|
1530
|
-
utils$1.isFile(data) ||
|
|
1531
|
-
utils$1.isBlob(data) ||
|
|
1532
|
-
utils$1.isReadableStream(data)
|
|
1533
|
-
) {
|
|
1534
|
-
return data;
|
|
1535
|
-
}
|
|
1536
|
-
if (utils$1.isArrayBufferView(data)) {
|
|
1537
|
-
return data.buffer;
|
|
1538
|
-
}
|
|
1539
|
-
if (utils$1.isURLSearchParams(data)) {
|
|
1540
|
-
headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
|
|
1541
|
-
return data.toString();
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
let isFileList;
|
|
1545
|
-
|
|
1546
|
-
if (isObjectPayload) {
|
|
1547
|
-
if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
|
|
1548
|
-
return toURLEncodedForm(data, this.formSerializer).toString();
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
if ((isFileList = utils$1.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
|
|
1552
|
-
const _FormData = this.env && this.env.FormData;
|
|
1553
|
-
|
|
1554
|
-
return toFormData(
|
|
1555
|
-
isFileList ? {'files[]': data} : data,
|
|
1556
|
-
_FormData && new _FormData(),
|
|
1557
|
-
this.formSerializer
|
|
1558
|
-
);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1562
|
-
if (isObjectPayload || hasJSONContentType ) {
|
|
1563
|
-
headers.setContentType('application/json', false);
|
|
1564
|
-
return stringifySafely(data);
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
return data;
|
|
1568
|
-
}],
|
|
1569
|
-
|
|
1570
|
-
transformResponse: [function transformResponse(data) {
|
|
1571
|
-
const transitional = this.transitional || defaults$1.transitional;
|
|
1572
|
-
const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
|
1573
|
-
const JSONRequested = this.responseType === 'json';
|
|
1574
|
-
|
|
1575
|
-
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
|
1576
|
-
return data;
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
|
|
1580
|
-
const silentJSONParsing = transitional && transitional.silentJSONParsing;
|
|
1581
|
-
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1582
|
-
|
|
1583
|
-
try {
|
|
1584
|
-
return JSON.parse(data);
|
|
1585
|
-
} catch (e) {
|
|
1586
|
-
if (strictJSONParsing) {
|
|
1587
|
-
if (e.name === 'SyntaxError') {
|
|
1588
|
-
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
|
|
1589
|
-
}
|
|
1590
|
-
throw e;
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
return data;
|
|
1596
|
-
}],
|
|
1597
|
-
|
|
1598
|
-
/**
|
|
1599
|
-
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
1600
|
-
* timeout is not created.
|
|
1601
|
-
*/
|
|
1602
|
-
timeout: 0,
|
|
1603
|
-
|
|
1604
|
-
xsrfCookieName: 'XSRF-TOKEN',
|
|
1605
|
-
xsrfHeaderName: 'X-XSRF-TOKEN',
|
|
1606
|
-
|
|
1607
|
-
maxContentLength: -1,
|
|
1608
|
-
maxBodyLength: -1,
|
|
1609
|
-
|
|
1610
|
-
env: {
|
|
1611
|
-
FormData: platform.classes.FormData,
|
|
1612
|
-
Blob: platform.classes.Blob
|
|
1613
|
-
},
|
|
1614
|
-
|
|
1615
|
-
validateStatus: function validateStatus(status) {
|
|
1616
|
-
return status >= 200 && status < 300;
|
|
1617
|
-
},
|
|
1618
|
-
|
|
1619
|
-
headers: {
|
|
1620
|
-
common: {
|
|
1621
|
-
'Accept': 'application/json, text/plain, */*',
|
|
1622
|
-
'Content-Type': undefined
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
|
|
1628
|
-
defaults$1.headers[method] = {};
|
|
1629
|
-
});
|
|
1630
|
-
|
|
1631
|
-
// RawAxiosHeaders whose duplicates are ignored by node
|
|
1632
|
-
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
|
1633
|
-
const ignoreDuplicateOf = utils$1.toObjectSet([
|
|
1634
|
-
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
|
1635
|
-
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
|
1636
|
-
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
|
1637
|
-
'referer', 'retry-after', 'user-agent'
|
|
1638
|
-
]);
|
|
1639
|
-
|
|
1640
|
-
/**
|
|
1641
|
-
* Parse headers into an object
|
|
1642
|
-
*
|
|
1643
|
-
* ```
|
|
1644
|
-
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
|
1645
|
-
* Content-Type: application/json
|
|
1646
|
-
* Connection: keep-alive
|
|
1647
|
-
* Transfer-Encoding: chunked
|
|
1648
|
-
* ```
|
|
1649
|
-
*
|
|
1650
|
-
* @param {String} rawHeaders Headers needing to be parsed
|
|
1651
|
-
*
|
|
1652
|
-
* @returns {Object} Headers parsed into an object
|
|
1653
|
-
*/
|
|
1654
|
-
var parseHeaders = rawHeaders => {
|
|
1655
|
-
const parsed = {};
|
|
1656
|
-
let key;
|
|
1657
|
-
let val;
|
|
1658
|
-
let i;
|
|
1659
|
-
|
|
1660
|
-
rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
|
|
1661
|
-
i = line.indexOf(':');
|
|
1662
|
-
key = line.substring(0, i).trim().toLowerCase();
|
|
1663
|
-
val = line.substring(i + 1).trim();
|
|
1664
|
-
|
|
1665
|
-
if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
|
|
1666
|
-
return;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
if (key === 'set-cookie') {
|
|
1670
|
-
if (parsed[key]) {
|
|
1671
|
-
parsed[key].push(val);
|
|
1672
|
-
} else {
|
|
1673
|
-
parsed[key] = [val];
|
|
1674
|
-
}
|
|
1675
|
-
} else {
|
|
1676
|
-
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
|
1677
|
-
}
|
|
1678
|
-
});
|
|
1679
|
-
|
|
1680
|
-
return parsed;
|
|
1681
|
-
};
|
|
1682
|
-
|
|
1683
|
-
const $internals = Symbol('internals');
|
|
1684
|
-
|
|
1685
|
-
function normalizeHeader(header) {
|
|
1686
|
-
return header && String(header).trim().toLowerCase();
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
function normalizeValue(value) {
|
|
1690
|
-
if (value === false || value == null) {
|
|
1691
|
-
return value;
|
|
1692
|
-
}
|
|
1693
|
-
|
|
1694
|
-
return utils$1.isArray(value) ? value.map(normalizeValue) : String(value);
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
function parseTokens(str) {
|
|
1698
|
-
const tokens = Object.create(null);
|
|
1699
|
-
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
1700
|
-
let match;
|
|
1701
|
-
|
|
1702
|
-
while ((match = tokensRE.exec(str))) {
|
|
1703
|
-
tokens[match[1]] = match[2];
|
|
1704
|
-
}
|
|
1705
|
-
|
|
1706
|
-
return tokens;
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|
1710
|
-
|
|
1711
|
-
function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
|
|
1712
|
-
if (utils$1.isFunction(filter)) {
|
|
1713
|
-
return filter.call(this, value, header);
|
|
1714
|
-
}
|
|
1715
|
-
|
|
1716
|
-
if (isHeaderNameFilter) {
|
|
1717
|
-
value = header;
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
if (!utils$1.isString(value)) return;
|
|
1721
|
-
|
|
1722
|
-
if (utils$1.isString(filter)) {
|
|
1723
|
-
return value.indexOf(filter) !== -1;
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
if (utils$1.isRegExp(filter)) {
|
|
1727
|
-
return filter.test(value);
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
function formatHeader(header) {
|
|
1732
|
-
return header.trim()
|
|
1733
|
-
.toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
|
1734
|
-
return char.toUpperCase() + str;
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
|
|
1738
|
-
function buildAccessors(obj, header) {
|
|
1739
|
-
const accessorName = utils$1.toCamelCase(' ' + header);
|
|
1740
|
-
|
|
1741
|
-
['get', 'set', 'has'].forEach(methodName => {
|
|
1742
|
-
Object.defineProperty(obj, methodName + accessorName, {
|
|
1743
|
-
value: function(arg1, arg2, arg3) {
|
|
1744
|
-
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
1745
|
-
},
|
|
1746
|
-
configurable: true
|
|
1747
|
-
});
|
|
1748
|
-
});
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
class AxiosHeaders {
|
|
1752
|
-
constructor(headers) {
|
|
1753
|
-
headers && this.set(headers);
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
set(header, valueOrRewrite, rewrite) {
|
|
1757
|
-
const self = this;
|
|
1758
|
-
|
|
1759
|
-
function setHeader(_value, _header, _rewrite) {
|
|
1760
|
-
const lHeader = normalizeHeader(_header);
|
|
1761
|
-
|
|
1762
|
-
if (!lHeader) {
|
|
1763
|
-
throw new Error('header name must be a non-empty string');
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
const key = utils$1.findKey(self, lHeader);
|
|
1767
|
-
|
|
1768
|
-
if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
|
|
1769
|
-
self[key || _header] = normalizeValue(_value);
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
const setHeaders = (headers, _rewrite) =>
|
|
1774
|
-
utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
1775
|
-
|
|
1776
|
-
if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
|
|
1777
|
-
setHeaders(header, valueOrRewrite);
|
|
1778
|
-
} else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1779
|
-
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1780
|
-
} else if (utils$1.isHeaders(header)) {
|
|
1781
|
-
for (const [key, value] of header.entries()) {
|
|
1782
|
-
setHeader(value, key, rewrite);
|
|
1783
|
-
}
|
|
1784
|
-
} else {
|
|
1785
|
-
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
return this;
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
get(header, parser) {
|
|
1792
|
-
header = normalizeHeader(header);
|
|
1793
|
-
|
|
1794
|
-
if (header) {
|
|
1795
|
-
const key = utils$1.findKey(this, header);
|
|
1796
|
-
|
|
1797
|
-
if (key) {
|
|
1798
|
-
const value = this[key];
|
|
1799
|
-
|
|
1800
|
-
if (!parser) {
|
|
1801
|
-
return value;
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
if (parser === true) {
|
|
1805
|
-
return parseTokens(value);
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
if (utils$1.isFunction(parser)) {
|
|
1809
|
-
return parser.call(this, value, key);
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
if (utils$1.isRegExp(parser)) {
|
|
1813
|
-
return parser.exec(value);
|
|
1814
|
-
}
|
|
1815
|
-
|
|
1816
|
-
throw new TypeError('parser must be boolean|regexp|function');
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
|
|
1821
|
-
has(header, matcher) {
|
|
1822
|
-
header = normalizeHeader(header);
|
|
1823
|
-
|
|
1824
|
-
if (header) {
|
|
1825
|
-
const key = utils$1.findKey(this, header);
|
|
1826
|
-
|
|
1827
|
-
return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
|
1828
|
-
}
|
|
1829
|
-
|
|
1830
|
-
return false;
|
|
1831
|
-
}
|
|
1832
|
-
|
|
1833
|
-
delete(header, matcher) {
|
|
1834
|
-
const self = this;
|
|
1835
|
-
let deleted = false;
|
|
1836
|
-
|
|
1837
|
-
function deleteHeader(_header) {
|
|
1838
|
-
_header = normalizeHeader(_header);
|
|
1839
|
-
|
|
1840
|
-
if (_header) {
|
|
1841
|
-
const key = utils$1.findKey(self, _header);
|
|
1842
|
-
|
|
1843
|
-
if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
|
1844
|
-
delete self[key];
|
|
1845
|
-
|
|
1846
|
-
deleted = true;
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
|
|
1851
|
-
if (utils$1.isArray(header)) {
|
|
1852
|
-
header.forEach(deleteHeader);
|
|
1853
|
-
} else {
|
|
1854
|
-
deleteHeader(header);
|
|
1855
|
-
}
|
|
1856
|
-
|
|
1857
|
-
return deleted;
|
|
1858
|
-
}
|
|
1859
|
-
|
|
1860
|
-
clear(matcher) {
|
|
1861
|
-
const keys = Object.keys(this);
|
|
1862
|
-
let i = keys.length;
|
|
1863
|
-
let deleted = false;
|
|
1864
|
-
|
|
1865
|
-
while (i--) {
|
|
1866
|
-
const key = keys[i];
|
|
1867
|
-
if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
1868
|
-
delete this[key];
|
|
1869
|
-
deleted = true;
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
|
|
1873
|
-
return deleted;
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
normalize(format) {
|
|
1877
|
-
const self = this;
|
|
1878
|
-
const headers = {};
|
|
1879
|
-
|
|
1880
|
-
utils$1.forEach(this, (value, header) => {
|
|
1881
|
-
const key = utils$1.findKey(headers, header);
|
|
1882
|
-
|
|
1883
|
-
if (key) {
|
|
1884
|
-
self[key] = normalizeValue(value);
|
|
1885
|
-
delete self[header];
|
|
1886
|
-
return;
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
1890
|
-
|
|
1891
|
-
if (normalized !== header) {
|
|
1892
|
-
delete self[header];
|
|
1893
|
-
}
|
|
1894
|
-
|
|
1895
|
-
self[normalized] = normalizeValue(value);
|
|
1896
|
-
|
|
1897
|
-
headers[normalized] = true;
|
|
1898
|
-
});
|
|
1899
|
-
|
|
1900
|
-
return this;
|
|
1901
|
-
}
|
|
1902
|
-
|
|
1903
|
-
concat(...targets) {
|
|
1904
|
-
return this.constructor.concat(this, ...targets);
|
|
1905
|
-
}
|
|
1906
|
-
|
|
1907
|
-
toJSON(asStrings) {
|
|
1908
|
-
const obj = Object.create(null);
|
|
1909
|
-
|
|
1910
|
-
utils$1.forEach(this, (value, header) => {
|
|
1911
|
-
value != null && value !== false && (obj[header] = asStrings && utils$1.isArray(value) ? value.join(', ') : value);
|
|
1912
|
-
});
|
|
1913
|
-
|
|
1914
|
-
return obj;
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
[Symbol.iterator]() {
|
|
1918
|
-
return Object.entries(this.toJSON())[Symbol.iterator]();
|
|
1919
|
-
}
|
|
1920
|
-
|
|
1921
|
-
toString() {
|
|
1922
|
-
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
get [Symbol.toStringTag]() {
|
|
1926
|
-
return 'AxiosHeaders';
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
static from(thing) {
|
|
1930
|
-
return thing instanceof this ? thing : new this(thing);
|
|
1931
|
-
}
|
|
1932
|
-
|
|
1933
|
-
static concat(first, ...targets) {
|
|
1934
|
-
const computed = new this(first);
|
|
1935
|
-
|
|
1936
|
-
targets.forEach((target) => computed.set(target));
|
|
1937
|
-
|
|
1938
|
-
return computed;
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
static accessor(header) {
|
|
1942
|
-
const internals = this[$internals] = (this[$internals] = {
|
|
1943
|
-
accessors: {}
|
|
1944
|
-
});
|
|
1945
|
-
|
|
1946
|
-
const accessors = internals.accessors;
|
|
1947
|
-
const prototype = this.prototype;
|
|
1948
|
-
|
|
1949
|
-
function defineAccessor(_header) {
|
|
1950
|
-
const lHeader = normalizeHeader(_header);
|
|
1951
|
-
|
|
1952
|
-
if (!accessors[lHeader]) {
|
|
1953
|
-
buildAccessors(prototype, _header);
|
|
1954
|
-
accessors[lHeader] = true;
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
|
|
1958
|
-
utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
1959
|
-
|
|
1960
|
-
return this;
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
|
1965
|
-
|
|
1966
|
-
// reserved names hotfix
|
|
1967
|
-
utils$1.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
|
|
1968
|
-
let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
|
|
1969
|
-
return {
|
|
1970
|
-
get: () => value,
|
|
1971
|
-
set(headerValue) {
|
|
1972
|
-
this[mapped] = headerValue;
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1975
|
-
});
|
|
1976
|
-
|
|
1977
|
-
utils$1.freezeMethods(AxiosHeaders);
|
|
1978
|
-
|
|
1979
|
-
/**
|
|
1980
|
-
* Transform the data for a request or a response
|
|
1981
|
-
*
|
|
1982
|
-
* @param {Array|Function} fns A single function or Array of functions
|
|
1983
|
-
* @param {?Object} response The response object
|
|
1984
|
-
*
|
|
1985
|
-
* @returns {*} The resulting transformed data
|
|
1986
|
-
*/
|
|
1987
|
-
function transformData(fns, response) {
|
|
1988
|
-
const config = this || defaults$1;
|
|
1989
|
-
const context = response || config;
|
|
1990
|
-
const headers = AxiosHeaders.from(context.headers);
|
|
1991
|
-
let data = context.data;
|
|
1992
|
-
|
|
1993
|
-
utils$1.forEach(fns, function transform(fn) {
|
|
1994
|
-
data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
|
|
1995
|
-
});
|
|
1996
|
-
|
|
1997
|
-
headers.normalize();
|
|
1998
|
-
|
|
1999
|
-
return data;
|
|
2000
|
-
}
|
|
2001
|
-
|
|
2002
|
-
function isCancel(value) {
|
|
2003
|
-
return !!(value && value.__CANCEL__);
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
/**
|
|
2007
|
-
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
|
2008
|
-
*
|
|
2009
|
-
* @param {string=} message The message.
|
|
2010
|
-
* @param {Object=} config The config.
|
|
2011
|
-
* @param {Object=} request The request.
|
|
2012
|
-
*
|
|
2013
|
-
* @returns {CanceledError} The created error.
|
|
2014
|
-
*/
|
|
2015
|
-
function CanceledError(message, config, request) {
|
|
2016
|
-
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
2017
|
-
AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
|
|
2018
|
-
this.name = 'CanceledError';
|
|
2019
|
-
}
|
|
2020
|
-
|
|
2021
|
-
utils$1.inherits(CanceledError, AxiosError, {
|
|
2022
|
-
__CANCEL__: true
|
|
2023
|
-
});
|
|
2024
|
-
|
|
2025
|
-
/**
|
|
2026
|
-
* Resolve or reject a Promise based on response status.
|
|
2027
|
-
*
|
|
2028
|
-
* @param {Function} resolve A function that resolves the promise.
|
|
2029
|
-
* @param {Function} reject A function that rejects the promise.
|
|
2030
|
-
* @param {object} response The response.
|
|
2031
|
-
*
|
|
2032
|
-
* @returns {object} The response.
|
|
2033
|
-
*/
|
|
2034
|
-
function settle(resolve, reject, response) {
|
|
2035
|
-
const validateStatus = response.config.validateStatus;
|
|
2036
|
-
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
2037
|
-
resolve(response);
|
|
2038
|
-
} else {
|
|
2039
|
-
reject(new AxiosError(
|
|
2040
|
-
'Request failed with status code ' + response.status,
|
|
2041
|
-
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
|
2042
|
-
response.config,
|
|
2043
|
-
response.request,
|
|
2044
|
-
response
|
|
2045
|
-
));
|
|
2046
|
-
}
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
function parseProtocol(url) {
|
|
2050
|
-
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
|
2051
|
-
return match && match[1] || '';
|
|
2052
|
-
}
|
|
2053
|
-
|
|
2054
|
-
/**
|
|
2055
|
-
* Calculate data maxRate
|
|
2056
|
-
* @param {Number} [samplesCount= 10]
|
|
2057
|
-
* @param {Number} [min= 1000]
|
|
2058
|
-
* @returns {Function}
|
|
2059
|
-
*/
|
|
2060
|
-
function speedometer(samplesCount, min) {
|
|
2061
|
-
samplesCount = samplesCount || 10;
|
|
2062
|
-
const bytes = new Array(samplesCount);
|
|
2063
|
-
const timestamps = new Array(samplesCount);
|
|
2064
|
-
let head = 0;
|
|
2065
|
-
let tail = 0;
|
|
2066
|
-
let firstSampleTS;
|
|
2067
|
-
|
|
2068
|
-
min = min !== undefined ? min : 1000;
|
|
2069
|
-
|
|
2070
|
-
return function push(chunkLength) {
|
|
2071
|
-
const now = Date.now();
|
|
2072
|
-
|
|
2073
|
-
const startedAt = timestamps[tail];
|
|
2074
|
-
|
|
2075
|
-
if (!firstSampleTS) {
|
|
2076
|
-
firstSampleTS = now;
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
bytes[head] = chunkLength;
|
|
2080
|
-
timestamps[head] = now;
|
|
2081
|
-
|
|
2082
|
-
let i = tail;
|
|
2083
|
-
let bytesCount = 0;
|
|
2084
|
-
|
|
2085
|
-
while (i !== head) {
|
|
2086
|
-
bytesCount += bytes[i++];
|
|
2087
|
-
i = i % samplesCount;
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
head = (head + 1) % samplesCount;
|
|
2091
|
-
|
|
2092
|
-
if (head === tail) {
|
|
2093
|
-
tail = (tail + 1) % samplesCount;
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
if (now - firstSampleTS < min) {
|
|
2097
|
-
return;
|
|
2098
|
-
}
|
|
2099
|
-
|
|
2100
|
-
const passed = startedAt && now - startedAt;
|
|
2101
|
-
|
|
2102
|
-
return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
|
|
2103
|
-
};
|
|
2104
|
-
}
|
|
2105
|
-
|
|
2106
|
-
/**
|
|
2107
|
-
* Throttle decorator
|
|
2108
|
-
* @param {Function} fn
|
|
2109
|
-
* @param {Number} freq
|
|
2110
|
-
* @return {Function}
|
|
2111
|
-
*/
|
|
2112
|
-
function throttle(fn, freq) {
|
|
2113
|
-
let timestamp = 0;
|
|
2114
|
-
let threshold = 1000 / freq;
|
|
2115
|
-
let lastArgs;
|
|
2116
|
-
let timer;
|
|
2117
|
-
|
|
2118
|
-
const invoke = (args, now = Date.now()) => {
|
|
2119
|
-
timestamp = now;
|
|
2120
|
-
lastArgs = null;
|
|
2121
|
-
if (timer) {
|
|
2122
|
-
clearTimeout(timer);
|
|
2123
|
-
timer = null;
|
|
2124
|
-
}
|
|
2125
|
-
fn.apply(null, args);
|
|
2126
|
-
};
|
|
2127
|
-
|
|
2128
|
-
const throttled = (...args) => {
|
|
2129
|
-
const now = Date.now();
|
|
2130
|
-
const passed = now - timestamp;
|
|
2131
|
-
if ( passed >= threshold) {
|
|
2132
|
-
invoke(args, now);
|
|
2133
|
-
} else {
|
|
2134
|
-
lastArgs = args;
|
|
2135
|
-
if (!timer) {
|
|
2136
|
-
timer = setTimeout(() => {
|
|
2137
|
-
timer = null;
|
|
2138
|
-
invoke(lastArgs);
|
|
2139
|
-
}, threshold - passed);
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
};
|
|
2143
|
-
|
|
2144
|
-
const flush = () => lastArgs && invoke(lastArgs);
|
|
2145
|
-
|
|
2146
|
-
return [throttled, flush];
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
2150
|
-
let bytesNotified = 0;
|
|
2151
|
-
const _speedometer = speedometer(50, 250);
|
|
2152
|
-
|
|
2153
|
-
return throttle(e => {
|
|
2154
|
-
const loaded = e.loaded;
|
|
2155
|
-
const total = e.lengthComputable ? e.total : undefined;
|
|
2156
|
-
const progressBytes = loaded - bytesNotified;
|
|
2157
|
-
const rate = _speedometer(progressBytes);
|
|
2158
|
-
const inRange = loaded <= total;
|
|
2159
|
-
|
|
2160
|
-
bytesNotified = loaded;
|
|
2161
|
-
|
|
2162
|
-
const data = {
|
|
2163
|
-
loaded,
|
|
2164
|
-
total,
|
|
2165
|
-
progress: total ? (loaded / total) : undefined,
|
|
2166
|
-
bytes: progressBytes,
|
|
2167
|
-
rate: rate ? rate : undefined,
|
|
2168
|
-
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
|
2169
|
-
event: e,
|
|
2170
|
-
lengthComputable: total != null,
|
|
2171
|
-
[isDownloadStream ? 'download' : 'upload']: true
|
|
2172
|
-
};
|
|
2173
|
-
|
|
2174
|
-
listener(data);
|
|
2175
|
-
}, freq);
|
|
2176
|
-
};
|
|
2177
|
-
|
|
2178
|
-
const progressEventDecorator = (total, throttled) => {
|
|
2179
|
-
const lengthComputable = total != null;
|
|
2180
|
-
|
|
2181
|
-
return [(loaded) => throttled[0]({
|
|
2182
|
-
lengthComputable,
|
|
2183
|
-
total,
|
|
2184
|
-
loaded
|
|
2185
|
-
}), throttled[1]];
|
|
2186
|
-
};
|
|
2187
|
-
|
|
2188
|
-
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
|
2189
|
-
|
|
2190
|
-
var isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
|
2191
|
-
|
|
2192
|
-
// Standard browser envs have full support of the APIs needed to test
|
|
2193
|
-
// whether the request URL is of the same origin as current location.
|
|
2194
|
-
(function standardBrowserEnv() {
|
|
2195
|
-
const msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
2196
|
-
const urlParsingNode = document.createElement('a');
|
|
2197
|
-
let originURL;
|
|
2198
|
-
|
|
2199
|
-
/**
|
|
2200
|
-
* Parse a URL to discover its components
|
|
2201
|
-
*
|
|
2202
|
-
* @param {String} url The URL to be parsed
|
|
2203
|
-
* @returns {Object}
|
|
2204
|
-
*/
|
|
2205
|
-
function resolveURL(url) {
|
|
2206
|
-
let href = url;
|
|
2207
|
-
|
|
2208
|
-
if (msie) {
|
|
2209
|
-
// IE needs attribute set twice to normalize properties
|
|
2210
|
-
urlParsingNode.setAttribute('href', href);
|
|
2211
|
-
href = urlParsingNode.href;
|
|
2212
|
-
}
|
|
2213
|
-
|
|
2214
|
-
urlParsingNode.setAttribute('href', href);
|
|
2215
|
-
|
|
2216
|
-
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
|
2217
|
-
return {
|
|
2218
|
-
href: urlParsingNode.href,
|
|
2219
|
-
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
2220
|
-
host: urlParsingNode.host,
|
|
2221
|
-
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
2222
|
-
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
2223
|
-
hostname: urlParsingNode.hostname,
|
|
2224
|
-
port: urlParsingNode.port,
|
|
2225
|
-
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
2226
|
-
urlParsingNode.pathname :
|
|
2227
|
-
'/' + urlParsingNode.pathname
|
|
2228
|
-
};
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
originURL = resolveURL(window.location.href);
|
|
2232
|
-
|
|
2233
|
-
/**
|
|
2234
|
-
* Determine if a URL shares the same origin as the current location
|
|
2235
|
-
*
|
|
2236
|
-
* @param {String} requestURL The URL to test
|
|
2237
|
-
* @returns {boolean} True if URL shares the same origin, otherwise false
|
|
2238
|
-
*/
|
|
2239
|
-
return function isURLSameOrigin(requestURL) {
|
|
2240
|
-
const parsed = (utils$1.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
|
2241
|
-
return (parsed.protocol === originURL.protocol &&
|
|
2242
|
-
parsed.host === originURL.host);
|
|
2243
|
-
};
|
|
2244
|
-
})() :
|
|
2245
|
-
|
|
2246
|
-
// Non standard browser envs (web workers, react-native) lack needed support.
|
|
2247
|
-
(function nonStandardBrowserEnv() {
|
|
2248
|
-
return function isURLSameOrigin() {
|
|
2249
|
-
return true;
|
|
2250
|
-
};
|
|
2251
|
-
})();
|
|
2252
|
-
|
|
2253
|
-
var cookies = platform.hasStandardBrowserEnv ?
|
|
2254
|
-
|
|
2255
|
-
// Standard browser envs support document.cookie
|
|
2256
|
-
{
|
|
2257
|
-
write(name, value, expires, path, domain, secure) {
|
|
2258
|
-
const cookie = [name + '=' + encodeURIComponent(value)];
|
|
2259
|
-
|
|
2260
|
-
utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
|
|
2261
|
-
|
|
2262
|
-
utils$1.isString(path) && cookie.push('path=' + path);
|
|
2263
|
-
|
|
2264
|
-
utils$1.isString(domain) && cookie.push('domain=' + domain);
|
|
2265
|
-
|
|
2266
|
-
secure === true && cookie.push('secure');
|
|
2267
|
-
|
|
2268
|
-
document.cookie = cookie.join('; ');
|
|
2269
|
-
},
|
|
2270
|
-
|
|
2271
|
-
read(name) {
|
|
2272
|
-
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
|
2273
|
-
return (match ? decodeURIComponent(match[3]) : null);
|
|
2274
|
-
},
|
|
2275
|
-
|
|
2276
|
-
remove(name) {
|
|
2277
|
-
this.write(name, '', Date.now() - 86400000);
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
|
|
2281
|
-
:
|
|
2282
|
-
|
|
2283
|
-
// Non-standard browser env (web workers, react-native) lack needed support.
|
|
2284
|
-
{
|
|
2285
|
-
write() {},
|
|
2286
|
-
read() {
|
|
2287
|
-
return null;
|
|
2288
|
-
},
|
|
2289
|
-
remove() {}
|
|
2290
|
-
};
|
|
2291
|
-
|
|
2292
|
-
/**
|
|
2293
|
-
* Determines whether the specified URL is absolute
|
|
2294
|
-
*
|
|
2295
|
-
* @param {string} url The URL to test
|
|
2296
|
-
*
|
|
2297
|
-
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
|
2298
|
-
*/
|
|
2299
|
-
function isAbsoluteURL(url) {
|
|
2300
|
-
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
|
2301
|
-
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
|
2302
|
-
// by any combination of letters, digits, plus, period, or hyphen.
|
|
2303
|
-
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
|
2304
|
-
}
|
|
2305
|
-
|
|
2306
|
-
/**
|
|
2307
|
-
* Creates a new URL by combining the specified URLs
|
|
2308
|
-
*
|
|
2309
|
-
* @param {string} baseURL The base URL
|
|
2310
|
-
* @param {string} relativeURL The relative URL
|
|
2311
|
-
*
|
|
2312
|
-
* @returns {string} The combined URL
|
|
2313
|
-
*/
|
|
2314
|
-
function combineURLs(baseURL, relativeURL) {
|
|
2315
|
-
return relativeURL
|
|
2316
|
-
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
|
2317
|
-
: baseURL;
|
|
2318
|
-
}
|
|
2319
|
-
|
|
2320
|
-
/**
|
|
2321
|
-
* Creates a new URL by combining the baseURL with the requestedURL,
|
|
2322
|
-
* only when the requestedURL is not already an absolute URL.
|
|
2323
|
-
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
|
2324
|
-
*
|
|
2325
|
-
* @param {string} baseURL The base URL
|
|
2326
|
-
* @param {string} requestedURL Absolute or relative URL to combine
|
|
2327
|
-
*
|
|
2328
|
-
* @returns {string} The combined full path
|
|
2329
|
-
*/
|
|
2330
|
-
function buildFullPath(baseURL, requestedURL) {
|
|
2331
|
-
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
|
2332
|
-
return combineURLs(baseURL, requestedURL);
|
|
2333
|
-
}
|
|
2334
|
-
return requestedURL;
|
|
2335
|
-
}
|
|
2336
|
-
|
|
2337
|
-
const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
|
|
2338
|
-
|
|
2339
|
-
/**
|
|
2340
|
-
* Config-specific merge-function which creates a new config-object
|
|
2341
|
-
* by merging two configuration objects together.
|
|
2342
|
-
*
|
|
2343
|
-
* @param {Object} config1
|
|
2344
|
-
* @param {Object} config2
|
|
2345
|
-
*
|
|
2346
|
-
* @returns {Object} New object resulting from merging config2 to config1
|
|
2347
|
-
*/
|
|
2348
|
-
function mergeConfig(config1, config2) {
|
|
2349
|
-
// eslint-disable-next-line no-param-reassign
|
|
2350
|
-
config2 = config2 || {};
|
|
2351
|
-
const config = {};
|
|
2352
|
-
|
|
2353
|
-
function getMergedValue(target, source, caseless) {
|
|
2354
|
-
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
|
2355
|
-
return utils$1.merge.call({caseless}, target, source);
|
|
2356
|
-
} else if (utils$1.isPlainObject(source)) {
|
|
2357
|
-
return utils$1.merge({}, source);
|
|
2358
|
-
} else if (utils$1.isArray(source)) {
|
|
2359
|
-
return source.slice();
|
|
2360
|
-
}
|
|
2361
|
-
return source;
|
|
2362
|
-
}
|
|
2363
|
-
|
|
2364
|
-
// eslint-disable-next-line consistent-return
|
|
2365
|
-
function mergeDeepProperties(a, b, caseless) {
|
|
2366
|
-
if (!utils$1.isUndefined(b)) {
|
|
2367
|
-
return getMergedValue(a, b, caseless);
|
|
2368
|
-
} else if (!utils$1.isUndefined(a)) {
|
|
2369
|
-
return getMergedValue(undefined, a, caseless);
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
|
|
2373
|
-
// eslint-disable-next-line consistent-return
|
|
2374
|
-
function valueFromConfig2(a, b) {
|
|
2375
|
-
if (!utils$1.isUndefined(b)) {
|
|
2376
|
-
return getMergedValue(undefined, b);
|
|
2377
|
-
}
|
|
2378
|
-
}
|
|
2379
|
-
|
|
2380
|
-
// eslint-disable-next-line consistent-return
|
|
2381
|
-
function defaultToConfig2(a, b) {
|
|
2382
|
-
if (!utils$1.isUndefined(b)) {
|
|
2383
|
-
return getMergedValue(undefined, b);
|
|
2384
|
-
} else if (!utils$1.isUndefined(a)) {
|
|
2385
|
-
return getMergedValue(undefined, a);
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
|
|
2389
|
-
// eslint-disable-next-line consistent-return
|
|
2390
|
-
function mergeDirectKeys(a, b, prop) {
|
|
2391
|
-
if (prop in config2) {
|
|
2392
|
-
return getMergedValue(a, b);
|
|
2393
|
-
} else if (prop in config1) {
|
|
2394
|
-
return getMergedValue(undefined, a);
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
|
|
2398
|
-
const mergeMap = {
|
|
2399
|
-
url: valueFromConfig2,
|
|
2400
|
-
method: valueFromConfig2,
|
|
2401
|
-
data: valueFromConfig2,
|
|
2402
|
-
baseURL: defaultToConfig2,
|
|
2403
|
-
transformRequest: defaultToConfig2,
|
|
2404
|
-
transformResponse: defaultToConfig2,
|
|
2405
|
-
paramsSerializer: defaultToConfig2,
|
|
2406
|
-
timeout: defaultToConfig2,
|
|
2407
|
-
timeoutMessage: defaultToConfig2,
|
|
2408
|
-
withCredentials: defaultToConfig2,
|
|
2409
|
-
withXSRFToken: defaultToConfig2,
|
|
2410
|
-
adapter: defaultToConfig2,
|
|
2411
|
-
responseType: defaultToConfig2,
|
|
2412
|
-
xsrfCookieName: defaultToConfig2,
|
|
2413
|
-
xsrfHeaderName: defaultToConfig2,
|
|
2414
|
-
onUploadProgress: defaultToConfig2,
|
|
2415
|
-
onDownloadProgress: defaultToConfig2,
|
|
2416
|
-
decompress: defaultToConfig2,
|
|
2417
|
-
maxContentLength: defaultToConfig2,
|
|
2418
|
-
maxBodyLength: defaultToConfig2,
|
|
2419
|
-
beforeRedirect: defaultToConfig2,
|
|
2420
|
-
transport: defaultToConfig2,
|
|
2421
|
-
httpAgent: defaultToConfig2,
|
|
2422
|
-
httpsAgent: defaultToConfig2,
|
|
2423
|
-
cancelToken: defaultToConfig2,
|
|
2424
|
-
socketPath: defaultToConfig2,
|
|
2425
|
-
responseEncoding: defaultToConfig2,
|
|
2426
|
-
validateStatus: mergeDirectKeys,
|
|
2427
|
-
headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
|
|
2428
|
-
};
|
|
2429
|
-
|
|
2430
|
-
utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
|
|
2431
|
-
const merge = mergeMap[prop] || mergeDeepProperties;
|
|
2432
|
-
const configValue = merge(config1[prop], config2[prop], prop);
|
|
2433
|
-
(utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
2434
|
-
});
|
|
2435
|
-
|
|
2436
|
-
return config;
|
|
2437
|
-
}
|
|
2438
|
-
|
|
2439
|
-
var resolveConfig = (config) => {
|
|
2440
|
-
const newConfig = mergeConfig({}, config);
|
|
2441
|
-
|
|
2442
|
-
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
|
2443
|
-
|
|
2444
|
-
newConfig.headers = headers = AxiosHeaders.from(headers);
|
|
2445
|
-
|
|
2446
|
-
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
|
2447
|
-
|
|
2448
|
-
// HTTP basic authentication
|
|
2449
|
-
if (auth) {
|
|
2450
|
-
headers.set('Authorization', 'Basic ' +
|
|
2451
|
-
btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
|
|
2452
|
-
);
|
|
2453
|
-
}
|
|
2454
|
-
|
|
2455
|
-
let contentType;
|
|
2456
|
-
|
|
2457
|
-
if (utils$1.isFormData(data)) {
|
|
2458
|
-
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2459
|
-
headers.setContentType(undefined); // Let the browser set it
|
|
2460
|
-
} else if ((contentType = headers.getContentType()) !== false) {
|
|
2461
|
-
// fix semicolon duplication issue for ReactNative FormData implementation
|
|
2462
|
-
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
|
|
2463
|
-
headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
|
|
2464
|
-
}
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
// Add xsrf header
|
|
2468
|
-
// This is only done if running in a standard browser environment.
|
|
2469
|
-
// Specifically not if we're in a web worker, or react-native.
|
|
2470
|
-
|
|
2471
|
-
if (platform.hasStandardBrowserEnv) {
|
|
2472
|
-
withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
|
|
2473
|
-
|
|
2474
|
-
if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
|
|
2475
|
-
// Add xsrf header
|
|
2476
|
-
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
|
2477
|
-
|
|
2478
|
-
if (xsrfValue) {
|
|
2479
|
-
headers.set(xsrfHeaderName, xsrfValue);
|
|
2480
|
-
}
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
|
|
2484
|
-
return newConfig;
|
|
2485
|
-
};
|
|
2486
|
-
|
|
2487
|
-
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
|
2488
|
-
|
|
2489
|
-
var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2490
|
-
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
2491
|
-
const _config = resolveConfig(config);
|
|
2492
|
-
let requestData = _config.data;
|
|
2493
|
-
const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
|
|
2494
|
-
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
|
2495
|
-
let onCanceled;
|
|
2496
|
-
let uploadThrottled, downloadThrottled;
|
|
2497
|
-
let flushUpload, flushDownload;
|
|
2498
|
-
|
|
2499
|
-
function done() {
|
|
2500
|
-
flushUpload && flushUpload(); // flush events
|
|
2501
|
-
flushDownload && flushDownload(); // flush events
|
|
2502
|
-
|
|
2503
|
-
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
|
2504
|
-
|
|
2505
|
-
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
let request = new XMLHttpRequest();
|
|
2509
|
-
|
|
2510
|
-
request.open(_config.method.toUpperCase(), _config.url, true);
|
|
2511
|
-
|
|
2512
|
-
// Set the request timeout in MS
|
|
2513
|
-
request.timeout = _config.timeout;
|
|
2514
|
-
|
|
2515
|
-
function onloadend() {
|
|
2516
|
-
if (!request) {
|
|
2517
|
-
return;
|
|
2518
|
-
}
|
|
2519
|
-
// Prepare the response
|
|
2520
|
-
const responseHeaders = AxiosHeaders.from(
|
|
2521
|
-
'getAllResponseHeaders' in request && request.getAllResponseHeaders()
|
|
2522
|
-
);
|
|
2523
|
-
const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
|
2524
|
-
request.responseText : request.response;
|
|
2525
|
-
const response = {
|
|
2526
|
-
data: responseData,
|
|
2527
|
-
status: request.status,
|
|
2528
|
-
statusText: request.statusText,
|
|
2529
|
-
headers: responseHeaders,
|
|
2530
|
-
config,
|
|
2531
|
-
request
|
|
2532
|
-
};
|
|
2533
|
-
|
|
2534
|
-
settle(function _resolve(value) {
|
|
2535
|
-
resolve(value);
|
|
2536
|
-
done();
|
|
2537
|
-
}, function _reject(err) {
|
|
2538
|
-
reject(err);
|
|
2539
|
-
done();
|
|
2540
|
-
}, response);
|
|
2541
|
-
|
|
2542
|
-
// Clean up request
|
|
2543
|
-
request = null;
|
|
2544
|
-
}
|
|
2545
|
-
|
|
2546
|
-
if ('onloadend' in request) {
|
|
2547
|
-
// Use onloadend if available
|
|
2548
|
-
request.onloadend = onloadend;
|
|
2549
|
-
} else {
|
|
2550
|
-
// Listen for ready state to emulate onloadend
|
|
2551
|
-
request.onreadystatechange = function handleLoad() {
|
|
2552
|
-
if (!request || request.readyState !== 4) {
|
|
2553
|
-
return;
|
|
2554
|
-
}
|
|
2555
|
-
|
|
2556
|
-
// The request errored out and we didn't get a response, this will be
|
|
2557
|
-
// handled by onerror instead
|
|
2558
|
-
// With one exception: request that using file: protocol, most browsers
|
|
2559
|
-
// will return status as 0 even though it's a successful request
|
|
2560
|
-
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
|
2561
|
-
return;
|
|
2562
|
-
}
|
|
2563
|
-
// readystate handler is calling before onerror or ontimeout handlers,
|
|
2564
|
-
// so we should call onloadend on the next 'tick'
|
|
2565
|
-
setTimeout(onloadend);
|
|
2566
|
-
};
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
// Handle browser request cancellation (as opposed to a manual cancellation)
|
|
2570
|
-
request.onabort = function handleAbort() {
|
|
2571
|
-
if (!request) {
|
|
2572
|
-
return;
|
|
2573
|
-
}
|
|
2574
|
-
|
|
2575
|
-
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
|
2576
|
-
|
|
2577
|
-
// Clean up request
|
|
2578
|
-
request = null;
|
|
2579
|
-
};
|
|
2580
|
-
|
|
2581
|
-
// Handle low level network errors
|
|
2582
|
-
request.onerror = function handleError() {
|
|
2583
|
-
// Real errors are hidden from us by the browser
|
|
2584
|
-
// onerror should only fire if it's a network error
|
|
2585
|
-
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
|
|
2586
|
-
|
|
2587
|
-
// Clean up request
|
|
2588
|
-
request = null;
|
|
2589
|
-
};
|
|
2590
|
-
|
|
2591
|
-
// Handle timeout
|
|
2592
|
-
request.ontimeout = function handleTimeout() {
|
|
2593
|
-
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
2594
|
-
const transitional = _config.transitional || transitionalDefaults;
|
|
2595
|
-
if (_config.timeoutErrorMessage) {
|
|
2596
|
-
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
2597
|
-
}
|
|
2598
|
-
reject(new AxiosError(
|
|
2599
|
-
timeoutErrorMessage,
|
|
2600
|
-
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
|
2601
|
-
config,
|
|
2602
|
-
request));
|
|
2603
|
-
|
|
2604
|
-
// Clean up request
|
|
2605
|
-
request = null;
|
|
2606
|
-
};
|
|
2607
|
-
|
|
2608
|
-
// Remove Content-Type if data is undefined
|
|
2609
|
-
requestData === undefined && requestHeaders.setContentType(null);
|
|
2610
|
-
|
|
2611
|
-
// Add headers to the request
|
|
2612
|
-
if ('setRequestHeader' in request) {
|
|
2613
|
-
utils$1.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
|
|
2614
|
-
request.setRequestHeader(key, val);
|
|
2615
|
-
});
|
|
2616
|
-
}
|
|
2617
|
-
|
|
2618
|
-
// Add withCredentials to request if needed
|
|
2619
|
-
if (!utils$1.isUndefined(_config.withCredentials)) {
|
|
2620
|
-
request.withCredentials = !!_config.withCredentials;
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
// Add responseType to request if needed
|
|
2624
|
-
if (responseType && responseType !== 'json') {
|
|
2625
|
-
request.responseType = _config.responseType;
|
|
2626
|
-
}
|
|
2627
|
-
|
|
2628
|
-
// Handle progress if needed
|
|
2629
|
-
if (onDownloadProgress) {
|
|
2630
|
-
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
|
2631
|
-
request.addEventListener('progress', downloadThrottled);
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
// Not all browsers support upload events
|
|
2635
|
-
if (onUploadProgress && request.upload) {
|
|
2636
|
-
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
|
2637
|
-
|
|
2638
|
-
request.upload.addEventListener('progress', uploadThrottled);
|
|
2639
|
-
|
|
2640
|
-
request.upload.addEventListener('loadend', flushUpload);
|
|
2641
|
-
}
|
|
2642
|
-
|
|
2643
|
-
if (_config.cancelToken || _config.signal) {
|
|
2644
|
-
// Handle cancellation
|
|
2645
|
-
// eslint-disable-next-line func-names
|
|
2646
|
-
onCanceled = cancel => {
|
|
2647
|
-
if (!request) {
|
|
2648
|
-
return;
|
|
2649
|
-
}
|
|
2650
|
-
reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
|
|
2651
|
-
request.abort();
|
|
2652
|
-
request = null;
|
|
2653
|
-
};
|
|
2654
|
-
|
|
2655
|
-
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|
2656
|
-
if (_config.signal) {
|
|
2657
|
-
_config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
|
|
2658
|
-
}
|
|
2659
|
-
}
|
|
2660
|
-
|
|
2661
|
-
const protocol = parseProtocol(_config.url);
|
|
2662
|
-
|
|
2663
|
-
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
|
2664
|
-
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
|
2665
|
-
return;
|
|
2666
|
-
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
// Send the request
|
|
2670
|
-
request.send(requestData || null);
|
|
2671
|
-
});
|
|
2672
|
-
};
|
|
2673
|
-
|
|
2674
|
-
const composeSignals = (signals, timeout) => {
|
|
2675
|
-
let controller = new AbortController();
|
|
2676
|
-
|
|
2677
|
-
let aborted;
|
|
2678
|
-
|
|
2679
|
-
const onabort = function (cancel) {
|
|
2680
|
-
if (!aborted) {
|
|
2681
|
-
aborted = true;
|
|
2682
|
-
unsubscribe();
|
|
2683
|
-
const err = cancel instanceof Error ? cancel : this.reason;
|
|
2684
|
-
controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
|
|
2685
|
-
}
|
|
2686
|
-
};
|
|
2687
|
-
|
|
2688
|
-
let timer = timeout && setTimeout(() => {
|
|
2689
|
-
onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
|
|
2690
|
-
}, timeout);
|
|
2691
|
-
|
|
2692
|
-
const unsubscribe = () => {
|
|
2693
|
-
if (signals) {
|
|
2694
|
-
timer && clearTimeout(timer);
|
|
2695
|
-
timer = null;
|
|
2696
|
-
signals.forEach(signal => {
|
|
2697
|
-
signal &&
|
|
2698
|
-
(signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
|
|
2699
|
-
});
|
|
2700
|
-
signals = null;
|
|
2701
|
-
}
|
|
2702
|
-
};
|
|
2703
|
-
|
|
2704
|
-
signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
|
|
2705
|
-
|
|
2706
|
-
const {signal} = controller;
|
|
2707
|
-
|
|
2708
|
-
signal.unsubscribe = unsubscribe;
|
|
2709
|
-
|
|
2710
|
-
return [signal, () => {
|
|
2711
|
-
timer && clearTimeout(timer);
|
|
2712
|
-
timer = null;
|
|
2713
|
-
}];
|
|
2714
|
-
};
|
|
2715
|
-
|
|
2716
|
-
const streamChunk = function* (chunk, chunkSize) {
|
|
2717
|
-
let len = chunk.byteLength;
|
|
2718
|
-
|
|
2719
|
-
if (len < chunkSize) {
|
|
2720
|
-
yield chunk;
|
|
2721
|
-
return;
|
|
2722
|
-
}
|
|
2723
|
-
|
|
2724
|
-
let pos = 0;
|
|
2725
|
-
let end;
|
|
2726
|
-
|
|
2727
|
-
while (pos < len) {
|
|
2728
|
-
end = pos + chunkSize;
|
|
2729
|
-
yield chunk.slice(pos, end);
|
|
2730
|
-
pos = end;
|
|
2731
|
-
}
|
|
2732
|
-
};
|
|
2733
|
-
|
|
2734
|
-
const readBytes = async function* (iterable, chunkSize, encode) {
|
|
2735
|
-
for await (const chunk of iterable) {
|
|
2736
|
-
yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
|
|
2737
|
-
}
|
|
2738
|
-
};
|
|
2739
|
-
|
|
2740
|
-
const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
|
2741
|
-
const iterator = readBytes(stream, chunkSize, encode);
|
|
2742
|
-
|
|
2743
|
-
let bytes = 0;
|
|
2744
|
-
let done;
|
|
2745
|
-
let _onFinish = (e) => {
|
|
2746
|
-
if (!done) {
|
|
2747
|
-
done = true;
|
|
2748
|
-
onFinish && onFinish(e);
|
|
2749
|
-
}
|
|
2750
|
-
};
|
|
2751
|
-
|
|
2752
|
-
return new ReadableStream({
|
|
2753
|
-
async pull(controller) {
|
|
2754
|
-
try {
|
|
2755
|
-
const {done, value} = await iterator.next();
|
|
2756
|
-
|
|
2757
|
-
if (done) {
|
|
2758
|
-
_onFinish();
|
|
2759
|
-
controller.close();
|
|
2760
|
-
return;
|
|
2761
|
-
}
|
|
2762
|
-
|
|
2763
|
-
let len = value.byteLength;
|
|
2764
|
-
if (onProgress) {
|
|
2765
|
-
let loadedBytes = bytes += len;
|
|
2766
|
-
onProgress(loadedBytes);
|
|
2767
|
-
}
|
|
2768
|
-
controller.enqueue(new Uint8Array(value));
|
|
2769
|
-
} catch (err) {
|
|
2770
|
-
_onFinish(err);
|
|
2771
|
-
throw err;
|
|
2772
|
-
}
|
|
2773
|
-
},
|
|
2774
|
-
cancel(reason) {
|
|
2775
|
-
_onFinish(reason);
|
|
2776
|
-
return iterator.return();
|
|
2777
|
-
}
|
|
2778
|
-
}, {
|
|
2779
|
-
highWaterMark: 2
|
|
2780
|
-
})
|
|
2781
|
-
};
|
|
2782
|
-
|
|
2783
|
-
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
|
2784
|
-
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
|
2785
|
-
|
|
2786
|
-
// used only inside the fetch adapter
|
|
2787
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
2788
|
-
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
2789
|
-
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
|
2790
|
-
);
|
|
2791
|
-
|
|
2792
|
-
const test = (fn, ...args) => {
|
|
2793
|
-
try {
|
|
2794
|
-
return !!fn(...args);
|
|
2795
|
-
} catch (e) {
|
|
2796
|
-
return false
|
|
2797
|
-
}
|
|
2798
|
-
};
|
|
2799
|
-
|
|
2800
|
-
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
|
2801
|
-
let duplexAccessed = false;
|
|
2802
|
-
|
|
2803
|
-
const hasContentType = new Request(platform.origin, {
|
|
2804
|
-
body: new ReadableStream(),
|
|
2805
|
-
method: 'POST',
|
|
2806
|
-
get duplex() {
|
|
2807
|
-
duplexAccessed = true;
|
|
2808
|
-
return 'half';
|
|
2809
|
-
},
|
|
2810
|
-
}).headers.has('Content-Type');
|
|
2811
|
-
|
|
2812
|
-
return duplexAccessed && !hasContentType;
|
|
2813
|
-
});
|
|
2814
|
-
|
|
2815
|
-
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2816
|
-
|
|
2817
|
-
const supportsResponseStream = isReadableStreamSupported &&
|
|
2818
|
-
test(() => utils$1.isReadableStream(new Response('').body));
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
const resolvers = {
|
|
2822
|
-
stream: supportsResponseStream && ((res) => res.body)
|
|
2823
|
-
};
|
|
2824
|
-
|
|
2825
|
-
isFetchSupported && (((res) => {
|
|
2826
|
-
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
2827
|
-
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
|
|
2828
|
-
(_, config) => {
|
|
2829
|
-
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
2830
|
-
});
|
|
2831
|
-
});
|
|
2832
|
-
})(new Response));
|
|
2833
|
-
|
|
2834
|
-
const getBodyLength = async (body) => {
|
|
2835
|
-
if (body == null) {
|
|
2836
|
-
return 0;
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
if(utils$1.isBlob(body)) {
|
|
2840
|
-
return body.size;
|
|
2841
|
-
}
|
|
2842
|
-
|
|
2843
|
-
if(utils$1.isSpecCompliantForm(body)) {
|
|
2844
|
-
return (await new Request(body).arrayBuffer()).byteLength;
|
|
2845
|
-
}
|
|
2846
|
-
|
|
2847
|
-
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|
2848
|
-
return body.byteLength;
|
|
2849
|
-
}
|
|
2850
|
-
|
|
2851
|
-
if(utils$1.isURLSearchParams(body)) {
|
|
2852
|
-
body = body + '';
|
|
2853
|
-
}
|
|
2854
|
-
|
|
2855
|
-
if(utils$1.isString(body)) {
|
|
2856
|
-
return (await encodeText(body)).byteLength;
|
|
2857
|
-
}
|
|
2858
|
-
};
|
|
2859
|
-
|
|
2860
|
-
const resolveBodyLength = async (headers, body) => {
|
|
2861
|
-
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|
2862
|
-
|
|
2863
|
-
return length == null ? getBodyLength(body) : length;
|
|
2864
|
-
};
|
|
2865
|
-
|
|
2866
|
-
var fetchAdapter = isFetchSupported && (async (config) => {
|
|
2867
|
-
let {
|
|
2868
|
-
url,
|
|
2869
|
-
method,
|
|
2870
|
-
data,
|
|
2871
|
-
signal,
|
|
2872
|
-
cancelToken,
|
|
2873
|
-
timeout,
|
|
2874
|
-
onDownloadProgress,
|
|
2875
|
-
onUploadProgress,
|
|
2876
|
-
responseType,
|
|
2877
|
-
headers,
|
|
2878
|
-
withCredentials = 'same-origin',
|
|
2879
|
-
fetchOptions
|
|
2880
|
-
} = resolveConfig(config);
|
|
2881
|
-
|
|
2882
|
-
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
2883
|
-
|
|
2884
|
-
let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
|
|
2885
|
-
composeSignals([signal, cancelToken], timeout) : [];
|
|
2886
|
-
|
|
2887
|
-
let finished, request;
|
|
2888
|
-
|
|
2889
|
-
const onFinish = () => {
|
|
2890
|
-
!finished && setTimeout(() => {
|
|
2891
|
-
composedSignal && composedSignal.unsubscribe();
|
|
2892
|
-
});
|
|
2893
|
-
|
|
2894
|
-
finished = true;
|
|
2895
|
-
};
|
|
2896
|
-
|
|
2897
|
-
let requestContentLength;
|
|
2898
|
-
|
|
2899
|
-
try {
|
|
2900
|
-
if (
|
|
2901
|
-
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
|
2902
|
-
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
|
2903
|
-
) {
|
|
2904
|
-
let _request = new Request(url, {
|
|
2905
|
-
method: 'POST',
|
|
2906
|
-
body: data,
|
|
2907
|
-
duplex: "half"
|
|
2908
|
-
});
|
|
2909
|
-
|
|
2910
|
-
let contentTypeHeader;
|
|
2911
|
-
|
|
2912
|
-
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
|
2913
|
-
headers.setContentType(contentTypeHeader);
|
|
2914
|
-
}
|
|
2915
|
-
|
|
2916
|
-
if (_request.body) {
|
|
2917
|
-
const [onProgress, flush] = progressEventDecorator(
|
|
2918
|
-
requestContentLength,
|
|
2919
|
-
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
2920
|
-
);
|
|
2921
|
-
|
|
2922
|
-
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
|
2923
|
-
}
|
|
2924
|
-
}
|
|
2925
|
-
|
|
2926
|
-
if (!utils$1.isString(withCredentials)) {
|
|
2927
|
-
withCredentials = withCredentials ? 'include' : 'omit';
|
|
2928
|
-
}
|
|
2929
|
-
|
|
2930
|
-
request = new Request(url, {
|
|
2931
|
-
...fetchOptions,
|
|
2932
|
-
signal: composedSignal,
|
|
2933
|
-
method: method.toUpperCase(),
|
|
2934
|
-
headers: headers.normalize().toJSON(),
|
|
2935
|
-
body: data,
|
|
2936
|
-
duplex: "half",
|
|
2937
|
-
credentials: withCredentials
|
|
2938
|
-
});
|
|
2939
|
-
|
|
2940
|
-
let response = await fetch(request);
|
|
2941
|
-
|
|
2942
|
-
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
|
2943
|
-
|
|
2944
|
-
if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
|
|
2945
|
-
const options = {};
|
|
2946
|
-
|
|
2947
|
-
['status', 'statusText', 'headers'].forEach(prop => {
|
|
2948
|
-
options[prop] = response[prop];
|
|
2949
|
-
});
|
|
2950
|
-
|
|
2951
|
-
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|
2952
|
-
|
|
2953
|
-
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
2954
|
-
responseContentLength,
|
|
2955
|
-
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
2956
|
-
) || [];
|
|
2957
|
-
|
|
2958
|
-
response = new Response(
|
|
2959
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
2960
|
-
flush && flush();
|
|
2961
|
-
isStreamResponse && onFinish();
|
|
2962
|
-
}, encodeText),
|
|
2963
|
-
options
|
|
2964
|
-
);
|
|
2965
|
-
}
|
|
2966
|
-
|
|
2967
|
-
responseType = responseType || 'text';
|
|
2968
|
-
|
|
2969
|
-
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
|
2970
|
-
|
|
2971
|
-
!isStreamResponse && onFinish();
|
|
2972
|
-
|
|
2973
|
-
stopTimeout && stopTimeout();
|
|
2974
|
-
|
|
2975
|
-
return await new Promise((resolve, reject) => {
|
|
2976
|
-
settle(resolve, reject, {
|
|
2977
|
-
data: responseData,
|
|
2978
|
-
headers: AxiosHeaders.from(response.headers),
|
|
2979
|
-
status: response.status,
|
|
2980
|
-
statusText: response.statusText,
|
|
2981
|
-
config,
|
|
2982
|
-
request
|
|
2983
|
-
});
|
|
2984
|
-
})
|
|
2985
|
-
} catch (err) {
|
|
2986
|
-
onFinish();
|
|
2987
|
-
|
|
2988
|
-
if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
|
|
2989
|
-
throw Object.assign(
|
|
2990
|
-
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
|
2991
|
-
{
|
|
2992
|
-
cause: err.cause || err
|
|
2993
|
-
}
|
|
2994
|
-
)
|
|
2995
|
-
}
|
|
2996
|
-
|
|
2997
|
-
throw AxiosError.from(err, err && err.code, config, request);
|
|
2998
|
-
}
|
|
2999
|
-
});
|
|
3000
|
-
|
|
3001
|
-
const knownAdapters = {
|
|
3002
|
-
http: httpAdapter,
|
|
3003
|
-
xhr: xhrAdapter,
|
|
3004
|
-
fetch: fetchAdapter
|
|
3005
|
-
};
|
|
3006
|
-
|
|
3007
|
-
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
3008
|
-
if (fn) {
|
|
3009
|
-
try {
|
|
3010
|
-
Object.defineProperty(fn, 'name', {value});
|
|
3011
|
-
} catch (e) {
|
|
3012
|
-
// eslint-disable-next-line no-empty
|
|
3013
|
-
}
|
|
3014
|
-
Object.defineProperty(fn, 'adapterName', {value});
|
|
3015
|
-
}
|
|
3016
|
-
});
|
|
3017
|
-
|
|
3018
|
-
const renderReason = (reason) => `- ${reason}`;
|
|
3019
|
-
|
|
3020
|
-
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
3021
|
-
|
|
3022
|
-
var adapters = {
|
|
3023
|
-
getAdapter: (adapters) => {
|
|
3024
|
-
adapters = utils$1.isArray(adapters) ? adapters : [adapters];
|
|
3025
|
-
|
|
3026
|
-
const {length} = adapters;
|
|
3027
|
-
let nameOrAdapter;
|
|
3028
|
-
let adapter;
|
|
3029
|
-
|
|
3030
|
-
const rejectedReasons = {};
|
|
3031
|
-
|
|
3032
|
-
for (let i = 0; i < length; i++) {
|
|
3033
|
-
nameOrAdapter = adapters[i];
|
|
3034
|
-
let id;
|
|
3035
|
-
|
|
3036
|
-
adapter = nameOrAdapter;
|
|
3037
|
-
|
|
3038
|
-
if (!isResolvedHandle(nameOrAdapter)) {
|
|
3039
|
-
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
3040
|
-
|
|
3041
|
-
if (adapter === undefined) {
|
|
3042
|
-
throw new AxiosError(`Unknown adapter '${id}'`);
|
|
3043
|
-
}
|
|
3044
|
-
}
|
|
3045
|
-
|
|
3046
|
-
if (adapter) {
|
|
3047
|
-
break;
|
|
3048
|
-
}
|
|
3049
|
-
|
|
3050
|
-
rejectedReasons[id || '#' + i] = adapter;
|
|
3051
|
-
}
|
|
3052
|
-
|
|
3053
|
-
if (!adapter) {
|
|
3054
|
-
|
|
3055
|
-
const reasons = Object.entries(rejectedReasons)
|
|
3056
|
-
.map(([id, state]) => `adapter ${id} ` +
|
|
3057
|
-
(state === false ? 'is not supported by the environment' : 'is not available in the build')
|
|
3058
|
-
);
|
|
3059
|
-
|
|
3060
|
-
let s = length ?
|
|
3061
|
-
(reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
|
|
3062
|
-
'as no adapter specified';
|
|
3063
|
-
|
|
3064
|
-
throw new AxiosError(
|
|
3065
|
-
`There is no suitable adapter to dispatch the request ` + s,
|
|
3066
|
-
'ERR_NOT_SUPPORT'
|
|
3067
|
-
);
|
|
3068
|
-
}
|
|
3069
|
-
|
|
3070
|
-
return adapter;
|
|
3071
|
-
},
|
|
3072
|
-
adapters: knownAdapters
|
|
3073
|
-
};
|
|
3074
|
-
|
|
3075
|
-
/**
|
|
3076
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
|
3077
|
-
*
|
|
3078
|
-
* @param {Object} config The config that is to be used for the request
|
|
3079
|
-
*
|
|
3080
|
-
* @returns {void}
|
|
3081
|
-
*/
|
|
3082
|
-
function throwIfCancellationRequested(config) {
|
|
3083
|
-
if (config.cancelToken) {
|
|
3084
|
-
config.cancelToken.throwIfRequested();
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
if (config.signal && config.signal.aborted) {
|
|
3088
|
-
throw new CanceledError(null, config);
|
|
3089
|
-
}
|
|
3090
|
-
}
|
|
3091
|
-
|
|
3092
|
-
/**
|
|
3093
|
-
* Dispatch a request to the server using the configured adapter.
|
|
3094
|
-
*
|
|
3095
|
-
* @param {object} config The config that is to be used for the request
|
|
3096
|
-
*
|
|
3097
|
-
* @returns {Promise} The Promise to be fulfilled
|
|
3098
|
-
*/
|
|
3099
|
-
function dispatchRequest(config) {
|
|
3100
|
-
throwIfCancellationRequested(config);
|
|
3101
|
-
|
|
3102
|
-
config.headers = AxiosHeaders.from(config.headers);
|
|
3103
|
-
|
|
3104
|
-
// Transform request data
|
|
3105
|
-
config.data = transformData.call(
|
|
3106
|
-
config,
|
|
3107
|
-
config.transformRequest
|
|
3108
|
-
);
|
|
3109
|
-
|
|
3110
|
-
if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
|
|
3111
|
-
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
3112
|
-
}
|
|
3113
|
-
|
|
3114
|
-
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
|
|
3115
|
-
|
|
3116
|
-
return adapter(config).then(function onAdapterResolution(response) {
|
|
3117
|
-
throwIfCancellationRequested(config);
|
|
3118
|
-
|
|
3119
|
-
// Transform response data
|
|
3120
|
-
response.data = transformData.call(
|
|
3121
|
-
config,
|
|
3122
|
-
config.transformResponse,
|
|
3123
|
-
response
|
|
3124
|
-
);
|
|
3125
|
-
|
|
3126
|
-
response.headers = AxiosHeaders.from(response.headers);
|
|
3127
|
-
|
|
3128
|
-
return response;
|
|
3129
|
-
}, function onAdapterRejection(reason) {
|
|
3130
|
-
if (!isCancel(reason)) {
|
|
3131
|
-
throwIfCancellationRequested(config);
|
|
3132
|
-
|
|
3133
|
-
// Transform response data
|
|
3134
|
-
if (reason && reason.response) {
|
|
3135
|
-
reason.response.data = transformData.call(
|
|
3136
|
-
config,
|
|
3137
|
-
config.transformResponse,
|
|
3138
|
-
reason.response
|
|
3139
|
-
);
|
|
3140
|
-
reason.response.headers = AxiosHeaders.from(reason.response.headers);
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
|
|
3144
|
-
return Promise.reject(reason);
|
|
3145
|
-
});
|
|
3146
|
-
}
|
|
3147
|
-
|
|
3148
|
-
const VERSION = "1.7.4";
|
|
3149
|
-
|
|
3150
|
-
const validators$1 = {};
|
|
3151
|
-
|
|
3152
|
-
// eslint-disable-next-line func-names
|
|
3153
|
-
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
|
|
3154
|
-
validators$1[type] = function validator(thing) {
|
|
3155
|
-
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
|
3156
|
-
};
|
|
3157
|
-
});
|
|
3158
|
-
|
|
3159
|
-
const deprecatedWarnings = {};
|
|
3160
|
-
|
|
3161
|
-
/**
|
|
3162
|
-
* Transitional option validator
|
|
3163
|
-
*
|
|
3164
|
-
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
|
3165
|
-
* @param {string?} version - deprecated version / removed since version
|
|
3166
|
-
* @param {string?} message - some message with additional info
|
|
3167
|
-
*
|
|
3168
|
-
* @returns {function}
|
|
3169
|
-
*/
|
|
3170
|
-
validators$1.transitional = function transitional(validator, version, message) {
|
|
3171
|
-
function formatMessage(opt, desc) {
|
|
3172
|
-
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
// eslint-disable-next-line func-names
|
|
3176
|
-
return (value, opt, opts) => {
|
|
3177
|
-
if (validator === false) {
|
|
3178
|
-
throw new AxiosError(
|
|
3179
|
-
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
|
3180
|
-
AxiosError.ERR_DEPRECATED
|
|
3181
|
-
);
|
|
3182
|
-
}
|
|
3183
|
-
|
|
3184
|
-
if (version && !deprecatedWarnings[opt]) {
|
|
3185
|
-
deprecatedWarnings[opt] = true;
|
|
3186
|
-
// eslint-disable-next-line no-console
|
|
3187
|
-
console.warn(
|
|
3188
|
-
formatMessage(
|
|
3189
|
-
opt,
|
|
3190
|
-
' has been deprecated since v' + version + ' and will be removed in the near future'
|
|
3191
|
-
)
|
|
3192
|
-
);
|
|
3193
|
-
}
|
|
3194
|
-
|
|
3195
|
-
return validator ? validator(value, opt, opts) : true;
|
|
3196
|
-
};
|
|
3197
|
-
};
|
|
3198
|
-
|
|
3199
|
-
/**
|
|
3200
|
-
* Assert object's properties type
|
|
3201
|
-
*
|
|
3202
|
-
* @param {object} options
|
|
3203
|
-
* @param {object} schema
|
|
3204
|
-
* @param {boolean?} allowUnknown
|
|
3205
|
-
*
|
|
3206
|
-
* @returns {object}
|
|
3207
|
-
*/
|
|
3208
|
-
|
|
3209
|
-
function assertOptions(options, schema, allowUnknown) {
|
|
3210
|
-
if (typeof options !== 'object') {
|
|
3211
|
-
throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
|
|
3212
|
-
}
|
|
3213
|
-
const keys = Object.keys(options);
|
|
3214
|
-
let i = keys.length;
|
|
3215
|
-
while (i-- > 0) {
|
|
3216
|
-
const opt = keys[i];
|
|
3217
|
-
const validator = schema[opt];
|
|
3218
|
-
if (validator) {
|
|
3219
|
-
const value = options[opt];
|
|
3220
|
-
const result = value === undefined || validator(value, opt, options);
|
|
3221
|
-
if (result !== true) {
|
|
3222
|
-
throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
|
|
3223
|
-
}
|
|
3224
|
-
continue;
|
|
3225
|
-
}
|
|
3226
|
-
if (allowUnknown !== true) {
|
|
3227
|
-
throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
|
|
3228
|
-
}
|
|
3229
|
-
}
|
|
3230
|
-
}
|
|
3231
|
-
|
|
3232
|
-
var validator = {
|
|
3233
|
-
assertOptions,
|
|
3234
|
-
validators: validators$1
|
|
3235
|
-
};
|
|
3236
|
-
|
|
3237
|
-
const validators = validator.validators;
|
|
3238
|
-
|
|
3239
|
-
/**
|
|
3240
|
-
* Create a new instance of Axios
|
|
3241
|
-
*
|
|
3242
|
-
* @param {Object} instanceConfig The default config for the instance
|
|
3243
|
-
*
|
|
3244
|
-
* @return {Axios} A new instance of Axios
|
|
3245
|
-
*/
|
|
3246
|
-
class Axios {
|
|
3247
|
-
constructor(instanceConfig) {
|
|
3248
|
-
this.defaults = instanceConfig;
|
|
3249
|
-
this.interceptors = {
|
|
3250
|
-
request: new InterceptorManager(),
|
|
3251
|
-
response: new InterceptorManager()
|
|
3252
|
-
};
|
|
3253
|
-
}
|
|
3254
|
-
|
|
3255
|
-
/**
|
|
3256
|
-
* Dispatch a request
|
|
3257
|
-
*
|
|
3258
|
-
* @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
|
|
3259
|
-
* @param {?Object} config
|
|
3260
|
-
*
|
|
3261
|
-
* @returns {Promise} The Promise to be fulfilled
|
|
3262
|
-
*/
|
|
3263
|
-
async request(configOrUrl, config) {
|
|
3264
|
-
try {
|
|
3265
|
-
return await this._request(configOrUrl, config);
|
|
3266
|
-
} catch (err) {
|
|
3267
|
-
if (err instanceof Error) {
|
|
3268
|
-
let dummy;
|
|
3269
|
-
|
|
3270
|
-
Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
|
|
3271
|
-
|
|
3272
|
-
// slice off the Error: ... line
|
|
3273
|
-
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
|
|
3274
|
-
try {
|
|
3275
|
-
if (!err.stack) {
|
|
3276
|
-
err.stack = stack;
|
|
3277
|
-
// match without the 2 top stack lines
|
|
3278
|
-
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
|
|
3279
|
-
err.stack += '\n' + stack;
|
|
3280
|
-
}
|
|
3281
|
-
} catch (e) {
|
|
3282
|
-
// ignore the case where "stack" is an un-writable property
|
|
3283
|
-
}
|
|
3284
|
-
}
|
|
3285
|
-
|
|
3286
|
-
throw err;
|
|
3287
|
-
}
|
|
3288
|
-
}
|
|
3289
|
-
|
|
3290
|
-
_request(configOrUrl, config) {
|
|
3291
|
-
/*eslint no-param-reassign:0*/
|
|
3292
|
-
// Allow for axios('example/url'[, config]) a la fetch API
|
|
3293
|
-
if (typeof configOrUrl === 'string') {
|
|
3294
|
-
config = config || {};
|
|
3295
|
-
config.url = configOrUrl;
|
|
3296
|
-
} else {
|
|
3297
|
-
config = configOrUrl || {};
|
|
3298
|
-
}
|
|
3299
|
-
|
|
3300
|
-
config = mergeConfig(this.defaults, config);
|
|
3301
|
-
|
|
3302
|
-
const {transitional, paramsSerializer, headers} = config;
|
|
3303
|
-
|
|
3304
|
-
if (transitional !== undefined) {
|
|
3305
|
-
validator.assertOptions(transitional, {
|
|
3306
|
-
silentJSONParsing: validators.transitional(validators.boolean),
|
|
3307
|
-
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
3308
|
-
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
3309
|
-
}, false);
|
|
3310
|
-
}
|
|
3311
|
-
|
|
3312
|
-
if (paramsSerializer != null) {
|
|
3313
|
-
if (utils$1.isFunction(paramsSerializer)) {
|
|
3314
|
-
config.paramsSerializer = {
|
|
3315
|
-
serialize: paramsSerializer
|
|
3316
|
-
};
|
|
3317
|
-
} else {
|
|
3318
|
-
validator.assertOptions(paramsSerializer, {
|
|
3319
|
-
encode: validators.function,
|
|
3320
|
-
serialize: validators.function
|
|
3321
|
-
}, true);
|
|
3322
|
-
}
|
|
3323
|
-
}
|
|
3324
|
-
|
|
3325
|
-
// Set config.method
|
|
3326
|
-
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
|
3327
|
-
|
|
3328
|
-
// Flatten headers
|
|
3329
|
-
let contextHeaders = headers && utils$1.merge(
|
|
3330
|
-
headers.common,
|
|
3331
|
-
headers[config.method]
|
|
3332
|
-
);
|
|
3333
|
-
|
|
3334
|
-
headers && utils$1.forEach(
|
|
3335
|
-
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
|
3336
|
-
(method) => {
|
|
3337
|
-
delete headers[method];
|
|
3338
|
-
}
|
|
3339
|
-
);
|
|
3340
|
-
|
|
3341
|
-
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
|
3342
|
-
|
|
3343
|
-
// filter out skipped interceptors
|
|
3344
|
-
const requestInterceptorChain = [];
|
|
3345
|
-
let synchronousRequestInterceptors = true;
|
|
3346
|
-
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
3347
|
-
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
|
3348
|
-
return;
|
|
3349
|
-
}
|
|
3350
|
-
|
|
3351
|
-
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
3352
|
-
|
|
3353
|
-
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
3354
|
-
});
|
|
3355
|
-
|
|
3356
|
-
const responseInterceptorChain = [];
|
|
3357
|
-
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
3358
|
-
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
3359
|
-
});
|
|
3360
|
-
|
|
3361
|
-
let promise;
|
|
3362
|
-
let i = 0;
|
|
3363
|
-
let len;
|
|
3364
|
-
|
|
3365
|
-
if (!synchronousRequestInterceptors) {
|
|
3366
|
-
const chain = [dispatchRequest.bind(this), undefined];
|
|
3367
|
-
chain.unshift.apply(chain, requestInterceptorChain);
|
|
3368
|
-
chain.push.apply(chain, responseInterceptorChain);
|
|
3369
|
-
len = chain.length;
|
|
3370
|
-
|
|
3371
|
-
promise = Promise.resolve(config);
|
|
3372
|
-
|
|
3373
|
-
while (i < len) {
|
|
3374
|
-
promise = promise.then(chain[i++], chain[i++]);
|
|
3375
|
-
}
|
|
3376
|
-
|
|
3377
|
-
return promise;
|
|
3378
|
-
}
|
|
3379
|
-
|
|
3380
|
-
len = requestInterceptorChain.length;
|
|
3381
|
-
|
|
3382
|
-
let newConfig = config;
|
|
3383
|
-
|
|
3384
|
-
i = 0;
|
|
3385
|
-
|
|
3386
|
-
while (i < len) {
|
|
3387
|
-
const onFulfilled = requestInterceptorChain[i++];
|
|
3388
|
-
const onRejected = requestInterceptorChain[i++];
|
|
3389
|
-
try {
|
|
3390
|
-
newConfig = onFulfilled(newConfig);
|
|
3391
|
-
} catch (error) {
|
|
3392
|
-
onRejected.call(this, error);
|
|
3393
|
-
break;
|
|
3394
|
-
}
|
|
3395
|
-
}
|
|
3396
|
-
|
|
3397
|
-
try {
|
|
3398
|
-
promise = dispatchRequest.call(this, newConfig);
|
|
3399
|
-
} catch (error) {
|
|
3400
|
-
return Promise.reject(error);
|
|
3401
|
-
}
|
|
3402
|
-
|
|
3403
|
-
i = 0;
|
|
3404
|
-
len = responseInterceptorChain.length;
|
|
3405
|
-
|
|
3406
|
-
while (i < len) {
|
|
3407
|
-
promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
|
3408
|
-
}
|
|
3409
|
-
|
|
3410
|
-
return promise;
|
|
3411
|
-
}
|
|
3412
|
-
|
|
3413
|
-
getUri(config) {
|
|
3414
|
-
config = mergeConfig(this.defaults, config);
|
|
3415
|
-
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
3416
|
-
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
3417
|
-
}
|
|
3418
|
-
}
|
|
3419
|
-
|
|
3420
|
-
// Provide aliases for supported request methods
|
|
3421
|
-
utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
|
3422
|
-
/*eslint func-names:0*/
|
|
3423
|
-
Axios.prototype[method] = function(url, config) {
|
|
3424
|
-
return this.request(mergeConfig(config || {}, {
|
|
3425
|
-
method,
|
|
3426
|
-
url,
|
|
3427
|
-
data: (config || {}).data
|
|
3428
|
-
}));
|
|
3429
|
-
};
|
|
3430
|
-
});
|
|
3431
|
-
|
|
3432
|
-
utils$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
3433
|
-
/*eslint func-names:0*/
|
|
3434
|
-
|
|
3435
|
-
function generateHTTPMethod(isForm) {
|
|
3436
|
-
return function httpMethod(url, data, config) {
|
|
3437
|
-
return this.request(mergeConfig(config || {}, {
|
|
3438
|
-
method,
|
|
3439
|
-
headers: isForm ? {
|
|
3440
|
-
'Content-Type': 'multipart/form-data'
|
|
3441
|
-
} : {},
|
|
3442
|
-
url,
|
|
3443
|
-
data
|
|
3444
|
-
}));
|
|
3445
|
-
};
|
|
3446
|
-
}
|
|
3447
|
-
|
|
3448
|
-
Axios.prototype[method] = generateHTTPMethod();
|
|
3449
|
-
|
|
3450
|
-
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
|
3451
|
-
});
|
|
3452
|
-
|
|
3453
|
-
/**
|
|
3454
|
-
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
|
3455
|
-
*
|
|
3456
|
-
* @param {Function} executor The executor function.
|
|
3457
|
-
*
|
|
3458
|
-
* @returns {CancelToken}
|
|
3459
|
-
*/
|
|
3460
|
-
class CancelToken {
|
|
3461
|
-
constructor(executor) {
|
|
3462
|
-
if (typeof executor !== 'function') {
|
|
3463
|
-
throw new TypeError('executor must be a function.');
|
|
3464
|
-
}
|
|
3465
|
-
|
|
3466
|
-
let resolvePromise;
|
|
3467
|
-
|
|
3468
|
-
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
3469
|
-
resolvePromise = resolve;
|
|
3470
|
-
});
|
|
3471
|
-
|
|
3472
|
-
const token = this;
|
|
3473
|
-
|
|
3474
|
-
// eslint-disable-next-line func-names
|
|
3475
|
-
this.promise.then(cancel => {
|
|
3476
|
-
if (!token._listeners) return;
|
|
3477
|
-
|
|
3478
|
-
let i = token._listeners.length;
|
|
3479
|
-
|
|
3480
|
-
while (i-- > 0) {
|
|
3481
|
-
token._listeners[i](cancel);
|
|
3482
|
-
}
|
|
3483
|
-
token._listeners = null;
|
|
3484
|
-
});
|
|
3485
|
-
|
|
3486
|
-
// eslint-disable-next-line func-names
|
|
3487
|
-
this.promise.then = onfulfilled => {
|
|
3488
|
-
let _resolve;
|
|
3489
|
-
// eslint-disable-next-line func-names
|
|
3490
|
-
const promise = new Promise(resolve => {
|
|
3491
|
-
token.subscribe(resolve);
|
|
3492
|
-
_resolve = resolve;
|
|
3493
|
-
}).then(onfulfilled);
|
|
3494
|
-
|
|
3495
|
-
promise.cancel = function reject() {
|
|
3496
|
-
token.unsubscribe(_resolve);
|
|
3497
|
-
};
|
|
3498
|
-
|
|
3499
|
-
return promise;
|
|
3500
|
-
};
|
|
3501
|
-
|
|
3502
|
-
executor(function cancel(message, config, request) {
|
|
3503
|
-
if (token.reason) {
|
|
3504
|
-
// Cancellation has already been requested
|
|
3505
|
-
return;
|
|
3506
|
-
}
|
|
3507
|
-
|
|
3508
|
-
token.reason = new CanceledError(message, config, request);
|
|
3509
|
-
resolvePromise(token.reason);
|
|
3510
|
-
});
|
|
3511
|
-
}
|
|
3512
|
-
|
|
3513
|
-
/**
|
|
3514
|
-
* Throws a `CanceledError` if cancellation has been requested.
|
|
3515
|
-
*/
|
|
3516
|
-
throwIfRequested() {
|
|
3517
|
-
if (this.reason) {
|
|
3518
|
-
throw this.reason;
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
|
|
3522
|
-
/**
|
|
3523
|
-
* Subscribe to the cancel signal
|
|
3524
|
-
*/
|
|
3525
|
-
|
|
3526
|
-
subscribe(listener) {
|
|
3527
|
-
if (this.reason) {
|
|
3528
|
-
listener(this.reason);
|
|
3529
|
-
return;
|
|
3530
|
-
}
|
|
3531
|
-
|
|
3532
|
-
if (this._listeners) {
|
|
3533
|
-
this._listeners.push(listener);
|
|
3534
|
-
} else {
|
|
3535
|
-
this._listeners = [listener];
|
|
3536
|
-
}
|
|
3537
|
-
}
|
|
3538
|
-
|
|
3539
|
-
/**
|
|
3540
|
-
* Unsubscribe from the cancel signal
|
|
3541
|
-
*/
|
|
3542
|
-
|
|
3543
|
-
unsubscribe(listener) {
|
|
3544
|
-
if (!this._listeners) {
|
|
3545
|
-
return;
|
|
3546
|
-
}
|
|
3547
|
-
const index = this._listeners.indexOf(listener);
|
|
3548
|
-
if (index !== -1) {
|
|
3549
|
-
this._listeners.splice(index, 1);
|
|
3550
|
-
}
|
|
3551
|
-
}
|
|
3552
|
-
|
|
3553
|
-
/**
|
|
3554
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
|
3555
|
-
* cancels the `CancelToken`.
|
|
3556
|
-
*/
|
|
3557
|
-
static source() {
|
|
3558
|
-
let cancel;
|
|
3559
|
-
const token = new CancelToken(function executor(c) {
|
|
3560
|
-
cancel = c;
|
|
3561
|
-
});
|
|
3562
|
-
return {
|
|
3563
|
-
token,
|
|
3564
|
-
cancel
|
|
3565
|
-
};
|
|
3566
|
-
}
|
|
3567
|
-
}
|
|
3568
|
-
|
|
3569
|
-
/**
|
|
3570
|
-
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
|
3571
|
-
*
|
|
3572
|
-
* Common use case would be to use `Function.prototype.apply`.
|
|
3573
|
-
*
|
|
3574
|
-
* ```js
|
|
3575
|
-
* function f(x, y, z) {}
|
|
3576
|
-
* var args = [1, 2, 3];
|
|
3577
|
-
* f.apply(null, args);
|
|
3578
|
-
* ```
|
|
3579
|
-
*
|
|
3580
|
-
* With `spread` this example can be re-written.
|
|
3581
|
-
*
|
|
3582
|
-
* ```js
|
|
3583
|
-
* spread(function(x, y, z) {})([1, 2, 3]);
|
|
3584
|
-
* ```
|
|
3585
|
-
*
|
|
3586
|
-
* @param {Function} callback
|
|
3587
|
-
*
|
|
3588
|
-
* @returns {Function}
|
|
3589
|
-
*/
|
|
3590
|
-
function spread(callback) {
|
|
3591
|
-
return function wrap(arr) {
|
|
3592
|
-
return callback.apply(null, arr);
|
|
3593
|
-
};
|
|
3594
|
-
}
|
|
3595
|
-
|
|
3596
|
-
/**
|
|
3597
|
-
* Determines whether the payload is an error thrown by Axios
|
|
3598
|
-
*
|
|
3599
|
-
* @param {*} payload The value to test
|
|
3600
|
-
*
|
|
3601
|
-
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
|
3602
|
-
*/
|
|
3603
|
-
function isAxiosError(payload) {
|
|
3604
|
-
return utils$1.isObject(payload) && (payload.isAxiosError === true);
|
|
3605
|
-
}
|
|
3606
|
-
|
|
3607
|
-
const HttpStatusCode = {
|
|
3608
|
-
Continue: 100,
|
|
3609
|
-
SwitchingProtocols: 101,
|
|
3610
|
-
Processing: 102,
|
|
3611
|
-
EarlyHints: 103,
|
|
3612
|
-
Ok: 200,
|
|
3613
|
-
Created: 201,
|
|
3614
|
-
Accepted: 202,
|
|
3615
|
-
NonAuthoritativeInformation: 203,
|
|
3616
|
-
NoContent: 204,
|
|
3617
|
-
ResetContent: 205,
|
|
3618
|
-
PartialContent: 206,
|
|
3619
|
-
MultiStatus: 207,
|
|
3620
|
-
AlreadyReported: 208,
|
|
3621
|
-
ImUsed: 226,
|
|
3622
|
-
MultipleChoices: 300,
|
|
3623
|
-
MovedPermanently: 301,
|
|
3624
|
-
Found: 302,
|
|
3625
|
-
SeeOther: 303,
|
|
3626
|
-
NotModified: 304,
|
|
3627
|
-
UseProxy: 305,
|
|
3628
|
-
Unused: 306,
|
|
3629
|
-
TemporaryRedirect: 307,
|
|
3630
|
-
PermanentRedirect: 308,
|
|
3631
|
-
BadRequest: 400,
|
|
3632
|
-
Unauthorized: 401,
|
|
3633
|
-
PaymentRequired: 402,
|
|
3634
|
-
Forbidden: 403,
|
|
3635
|
-
NotFound: 404,
|
|
3636
|
-
MethodNotAllowed: 405,
|
|
3637
|
-
NotAcceptable: 406,
|
|
3638
|
-
ProxyAuthenticationRequired: 407,
|
|
3639
|
-
RequestTimeout: 408,
|
|
3640
|
-
Conflict: 409,
|
|
3641
|
-
Gone: 410,
|
|
3642
|
-
LengthRequired: 411,
|
|
3643
|
-
PreconditionFailed: 412,
|
|
3644
|
-
PayloadTooLarge: 413,
|
|
3645
|
-
UriTooLong: 414,
|
|
3646
|
-
UnsupportedMediaType: 415,
|
|
3647
|
-
RangeNotSatisfiable: 416,
|
|
3648
|
-
ExpectationFailed: 417,
|
|
3649
|
-
ImATeapot: 418,
|
|
3650
|
-
MisdirectedRequest: 421,
|
|
3651
|
-
UnprocessableEntity: 422,
|
|
3652
|
-
Locked: 423,
|
|
3653
|
-
FailedDependency: 424,
|
|
3654
|
-
TooEarly: 425,
|
|
3655
|
-
UpgradeRequired: 426,
|
|
3656
|
-
PreconditionRequired: 428,
|
|
3657
|
-
TooManyRequests: 429,
|
|
3658
|
-
RequestHeaderFieldsTooLarge: 431,
|
|
3659
|
-
UnavailableForLegalReasons: 451,
|
|
3660
|
-
InternalServerError: 500,
|
|
3661
|
-
NotImplemented: 501,
|
|
3662
|
-
BadGateway: 502,
|
|
3663
|
-
ServiceUnavailable: 503,
|
|
3664
|
-
GatewayTimeout: 504,
|
|
3665
|
-
HttpVersionNotSupported: 505,
|
|
3666
|
-
VariantAlsoNegotiates: 506,
|
|
3667
|
-
InsufficientStorage: 507,
|
|
3668
|
-
LoopDetected: 508,
|
|
3669
|
-
NotExtended: 510,
|
|
3670
|
-
NetworkAuthenticationRequired: 511,
|
|
3671
|
-
};
|
|
3672
|
-
|
|
3673
|
-
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
|
3674
|
-
HttpStatusCode[value] = key;
|
|
3675
|
-
});
|
|
3676
|
-
|
|
3677
|
-
/**
|
|
3678
|
-
* Create an instance of Axios
|
|
3679
|
-
*
|
|
3680
|
-
* @param {Object} defaultConfig The default config for the instance
|
|
3681
|
-
*
|
|
3682
|
-
* @returns {Axios} A new instance of Axios
|
|
3683
|
-
*/
|
|
3684
|
-
function createInstance(defaultConfig) {
|
|
3685
|
-
const context = new Axios(defaultConfig);
|
|
3686
|
-
const instance = bind(Axios.prototype.request, context);
|
|
3687
|
-
|
|
3688
|
-
// Copy axios.prototype to instance
|
|
3689
|
-
utils$1.extend(instance, Axios.prototype, context, {allOwnKeys: true});
|
|
3690
|
-
|
|
3691
|
-
// Copy context to instance
|
|
3692
|
-
utils$1.extend(instance, context, null, {allOwnKeys: true});
|
|
3693
|
-
|
|
3694
|
-
// Factory for creating new instances
|
|
3695
|
-
instance.create = function create(instanceConfig) {
|
|
3696
|
-
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
3697
|
-
};
|
|
3698
|
-
|
|
3699
|
-
return instance;
|
|
3700
|
-
}
|
|
3701
|
-
|
|
3702
|
-
// Create the default instance to be exported
|
|
3703
|
-
const axios = createInstance(defaults$1);
|
|
3704
|
-
|
|
3705
|
-
// Expose Axios class to allow class inheritance
|
|
3706
|
-
axios.Axios = Axios;
|
|
3707
|
-
|
|
3708
|
-
// Expose Cancel & CancelToken
|
|
3709
|
-
axios.CanceledError = CanceledError;
|
|
3710
|
-
axios.CancelToken = CancelToken;
|
|
3711
|
-
axios.isCancel = isCancel;
|
|
3712
|
-
axios.VERSION = VERSION;
|
|
3713
|
-
axios.toFormData = toFormData;
|
|
3714
|
-
|
|
3715
|
-
// Expose AxiosError class
|
|
3716
|
-
axios.AxiosError = AxiosError;
|
|
3717
|
-
|
|
3718
|
-
// alias for CanceledError for backward compatibility
|
|
3719
|
-
axios.Cancel = axios.CanceledError;
|
|
3720
|
-
|
|
3721
|
-
// Expose all/spread
|
|
3722
|
-
axios.all = function all(promises) {
|
|
3723
|
-
return Promise.all(promises);
|
|
3724
|
-
};
|
|
3725
|
-
|
|
3726
|
-
axios.spread = spread;
|
|
3727
|
-
|
|
3728
|
-
// Expose isAxiosError
|
|
3729
|
-
axios.isAxiosError = isAxiosError;
|
|
3730
|
-
|
|
3731
|
-
// Expose mergeConfig
|
|
3732
|
-
axios.mergeConfig = mergeConfig;
|
|
3733
|
-
|
|
3734
|
-
axios.AxiosHeaders = AxiosHeaders;
|
|
3735
|
-
|
|
3736
|
-
axios.formToJSON = thing => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
3737
|
-
|
|
3738
|
-
axios.getAdapter = adapters.getAdapter;
|
|
3739
|
-
|
|
3740
|
-
axios.HttpStatusCode = HttpStatusCode;
|
|
3741
|
-
|
|
3742
|
-
axios.default = axios;
|
|
16
|
+
import { ethers } from 'ethers';
|
|
3743
17
|
|
|
3744
18
|
/******************************************************************************
|
|
3745
19
|
Copyright (c) Microsoft Corporation.
|
|
@@ -3764,7 +38,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
3764
38
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3765
39
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3766
40
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3767
|
-
step((generator = generator.apply(thisArg, [])).next());
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3768
42
|
});
|
|
3769
43
|
}
|
|
3770
44
|
|
|
@@ -3773,695 +47,13 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
3773
47
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
3774
48
|
};
|
|
3775
49
|
|
|
3776
|
-
var erc20ABI = [
|
|
3777
|
-
{
|
|
3778
|
-
inputs: [
|
|
3779
|
-
],
|
|
3780
|
-
stateMutability: "nonpayable",
|
|
3781
|
-
type: "constructor"
|
|
3782
|
-
},
|
|
3783
|
-
{
|
|
3784
|
-
anonymous: false,
|
|
3785
|
-
inputs: [
|
|
3786
|
-
{
|
|
3787
|
-
indexed: true,
|
|
3788
|
-
internalType: "address",
|
|
3789
|
-
name: "owner",
|
|
3790
|
-
type: "address"
|
|
3791
|
-
},
|
|
3792
|
-
{
|
|
3793
|
-
indexed: true,
|
|
3794
|
-
internalType: "address",
|
|
3795
|
-
name: "spender",
|
|
3796
|
-
type: "address"
|
|
3797
|
-
},
|
|
3798
|
-
{
|
|
3799
|
-
indexed: false,
|
|
3800
|
-
internalType: "uint256",
|
|
3801
|
-
name: "value",
|
|
3802
|
-
type: "uint256"
|
|
3803
|
-
}
|
|
3804
|
-
],
|
|
3805
|
-
name: "Approval",
|
|
3806
|
-
type: "event"
|
|
3807
|
-
},
|
|
3808
|
-
{
|
|
3809
|
-
anonymous: false,
|
|
3810
|
-
inputs: [
|
|
3811
|
-
{
|
|
3812
|
-
indexed: true,
|
|
3813
|
-
internalType: "address",
|
|
3814
|
-
name: "from",
|
|
3815
|
-
type: "address"
|
|
3816
|
-
},
|
|
3817
|
-
{
|
|
3818
|
-
indexed: true,
|
|
3819
|
-
internalType: "address",
|
|
3820
|
-
name: "to",
|
|
3821
|
-
type: "address"
|
|
3822
|
-
},
|
|
3823
|
-
{
|
|
3824
|
-
indexed: false,
|
|
3825
|
-
internalType: "uint256",
|
|
3826
|
-
name: "value",
|
|
3827
|
-
type: "uint256"
|
|
3828
|
-
}
|
|
3829
|
-
],
|
|
3830
|
-
name: "Transfer",
|
|
3831
|
-
type: "event"
|
|
3832
|
-
},
|
|
3833
|
-
{
|
|
3834
|
-
inputs: [
|
|
3835
|
-
{
|
|
3836
|
-
internalType: "address",
|
|
3837
|
-
name: "",
|
|
3838
|
-
type: "address"
|
|
3839
|
-
},
|
|
3840
|
-
{
|
|
3841
|
-
internalType: "address",
|
|
3842
|
-
name: "",
|
|
3843
|
-
type: "address"
|
|
3844
|
-
}
|
|
3845
|
-
],
|
|
3846
|
-
name: "allowance",
|
|
3847
|
-
outputs: [
|
|
3848
|
-
{
|
|
3849
|
-
internalType: "uint256",
|
|
3850
|
-
name: "",
|
|
3851
|
-
type: "uint256"
|
|
3852
|
-
}
|
|
3853
|
-
],
|
|
3854
|
-
stateMutability: "view",
|
|
3855
|
-
type: "function"
|
|
3856
|
-
},
|
|
3857
|
-
{
|
|
3858
|
-
inputs: [
|
|
3859
|
-
{
|
|
3860
|
-
internalType: "address",
|
|
3861
|
-
name: "spender",
|
|
3862
|
-
type: "address"
|
|
3863
|
-
},
|
|
3864
|
-
{
|
|
3865
|
-
internalType: "uint256",
|
|
3866
|
-
name: "value",
|
|
3867
|
-
type: "uint256"
|
|
3868
|
-
}
|
|
3869
|
-
],
|
|
3870
|
-
name: "approve",
|
|
3871
|
-
outputs: [
|
|
3872
|
-
{
|
|
3873
|
-
internalType: "bool",
|
|
3874
|
-
name: "success",
|
|
3875
|
-
type: "bool"
|
|
3876
|
-
}
|
|
3877
|
-
],
|
|
3878
|
-
stateMutability: "nonpayable",
|
|
3879
|
-
type: "function"
|
|
3880
|
-
},
|
|
3881
|
-
{
|
|
3882
|
-
inputs: [
|
|
3883
|
-
{
|
|
3884
|
-
internalType: "address",
|
|
3885
|
-
name: "",
|
|
3886
|
-
type: "address"
|
|
3887
|
-
}
|
|
3888
|
-
],
|
|
3889
|
-
name: "balanceOf",
|
|
3890
|
-
outputs: [
|
|
3891
|
-
{
|
|
3892
|
-
internalType: "uint256",
|
|
3893
|
-
name: "",
|
|
3894
|
-
type: "uint256"
|
|
3895
|
-
}
|
|
3896
|
-
],
|
|
3897
|
-
stateMutability: "view",
|
|
3898
|
-
type: "function"
|
|
3899
|
-
},
|
|
3900
|
-
{
|
|
3901
|
-
inputs: [
|
|
3902
|
-
],
|
|
3903
|
-
name: "decimals",
|
|
3904
|
-
outputs: [
|
|
3905
|
-
{
|
|
3906
|
-
internalType: "uint256",
|
|
3907
|
-
name: "",
|
|
3908
|
-
type: "uint256"
|
|
3909
|
-
}
|
|
3910
|
-
],
|
|
3911
|
-
stateMutability: "view",
|
|
3912
|
-
type: "function"
|
|
3913
|
-
},
|
|
3914
|
-
{
|
|
3915
|
-
inputs: [
|
|
3916
|
-
],
|
|
3917
|
-
name: "name",
|
|
3918
|
-
outputs: [
|
|
3919
|
-
{
|
|
3920
|
-
internalType: "string",
|
|
3921
|
-
name: "",
|
|
3922
|
-
type: "string"
|
|
3923
|
-
}
|
|
3924
|
-
],
|
|
3925
|
-
stateMutability: "view",
|
|
3926
|
-
type: "function"
|
|
3927
|
-
},
|
|
3928
|
-
{
|
|
3929
|
-
inputs: [
|
|
3930
|
-
],
|
|
3931
|
-
name: "symbol",
|
|
3932
|
-
outputs: [
|
|
3933
|
-
{
|
|
3934
|
-
internalType: "string",
|
|
3935
|
-
name: "",
|
|
3936
|
-
type: "string"
|
|
3937
|
-
}
|
|
3938
|
-
],
|
|
3939
|
-
stateMutability: "view",
|
|
3940
|
-
type: "function"
|
|
3941
|
-
},
|
|
3942
|
-
{
|
|
3943
|
-
inputs: [
|
|
3944
|
-
],
|
|
3945
|
-
name: "totalSupply",
|
|
3946
|
-
outputs: [
|
|
3947
|
-
{
|
|
3948
|
-
internalType: "uint256",
|
|
3949
|
-
name: "",
|
|
3950
|
-
type: "uint256"
|
|
3951
|
-
}
|
|
3952
|
-
],
|
|
3953
|
-
stateMutability: "view",
|
|
3954
|
-
type: "function"
|
|
3955
|
-
},
|
|
3956
|
-
{
|
|
3957
|
-
inputs: [
|
|
3958
|
-
{
|
|
3959
|
-
internalType: "address",
|
|
3960
|
-
name: "to",
|
|
3961
|
-
type: "address"
|
|
3962
|
-
},
|
|
3963
|
-
{
|
|
3964
|
-
internalType: "uint256",
|
|
3965
|
-
name: "value",
|
|
3966
|
-
type: "uint256"
|
|
3967
|
-
}
|
|
3968
|
-
],
|
|
3969
|
-
name: "transfer",
|
|
3970
|
-
outputs: [
|
|
3971
|
-
{
|
|
3972
|
-
internalType: "bool",
|
|
3973
|
-
name: "success",
|
|
3974
|
-
type: "bool"
|
|
3975
|
-
}
|
|
3976
|
-
],
|
|
3977
|
-
stateMutability: "nonpayable",
|
|
3978
|
-
type: "function"
|
|
3979
|
-
},
|
|
3980
|
-
{
|
|
3981
|
-
inputs: [
|
|
3982
|
-
{
|
|
3983
|
-
internalType: "address",
|
|
3984
|
-
name: "from",
|
|
3985
|
-
type: "address"
|
|
3986
|
-
},
|
|
3987
|
-
{
|
|
3988
|
-
internalType: "address",
|
|
3989
|
-
name: "to",
|
|
3990
|
-
type: "address"
|
|
3991
|
-
},
|
|
3992
|
-
{
|
|
3993
|
-
internalType: "uint256",
|
|
3994
|
-
name: "value",
|
|
3995
|
-
type: "uint256"
|
|
3996
|
-
}
|
|
3997
|
-
],
|
|
3998
|
-
name: "transferFrom",
|
|
3999
|
-
outputs: [
|
|
4000
|
-
{
|
|
4001
|
-
internalType: "bool",
|
|
4002
|
-
name: "success",
|
|
4003
|
-
type: "bool"
|
|
4004
|
-
}
|
|
4005
|
-
],
|
|
4006
|
-
stateMutability: "nonpayable",
|
|
4007
|
-
type: "function"
|
|
4008
|
-
}
|
|
4009
|
-
];
|
|
4010
|
-
|
|
4011
|
-
ethers.BigNumber.from(2).pow(256).sub(1);
|
|
4012
|
-
/**
|
|
4013
|
-
* Validate the given address.
|
|
4014
|
-
*
|
|
4015
|
-
* @param {Address} address
|
|
4016
|
-
* @returns {boolean} `true` or `false`
|
|
4017
|
-
*/
|
|
4018
|
-
const validateAddress$1 = (address) => {
|
|
4019
|
-
try {
|
|
4020
|
-
ethers.utils.getAddress(address);
|
|
4021
|
-
return true;
|
|
4022
|
-
}
|
|
4023
|
-
catch (error) {
|
|
4024
|
-
return false;
|
|
4025
|
-
}
|
|
4026
|
-
};
|
|
4027
|
-
|
|
4028
|
-
const getApiKeyQueryParameter = (apiKey) => (!!apiKey ? `&apiKey=${apiKey}` : '');
|
|
4029
|
-
/**
|
|
4030
|
-
* Filter self txs
|
|
4031
|
-
*
|
|
4032
|
-
* @returns {T[]}
|
|
4033
|
-
*
|
|
4034
|
-
**/
|
|
4035
|
-
const filterSelfTxs = (txs) => {
|
|
4036
|
-
const filterTxs = txs.filter((tx) => tx.from !== tx.to);
|
|
4037
|
-
let selfTxs = txs.filter((tx) => tx.from === tx.to);
|
|
4038
|
-
while (selfTxs.length) {
|
|
4039
|
-
const selfTx = selfTxs[0];
|
|
4040
|
-
filterTxs.push(selfTx);
|
|
4041
|
-
selfTxs = selfTxs.filter((tx) => tx.hash !== selfTx.hash);
|
|
4042
|
-
}
|
|
4043
|
-
return filterTxs;
|
|
4044
|
-
};
|
|
4045
|
-
/**
|
|
4046
|
-
* Check if the symbol is valid.
|
|
4047
|
-
*
|
|
4048
|
-
* @param {string|null|undefined} symbol
|
|
4049
|
-
* @returns {boolean} `true` or `false`.
|
|
4050
|
-
*/
|
|
4051
|
-
const validateSymbol = (symbol) => (symbol ? symbol.length >= 3 : false);
|
|
4052
|
-
/**
|
|
4053
|
-
* Get transactions from ETH transaction
|
|
4054
|
-
*
|
|
4055
|
-
* @param {ETHTransactionInfo} tx
|
|
4056
|
-
* @returns {Tx} The parsed transaction.
|
|
4057
|
-
*/
|
|
4058
|
-
const getTxFromEthTransaction = (tx, gasAsset, decimals) => {
|
|
4059
|
-
return {
|
|
4060
|
-
asset: gasAsset,
|
|
4061
|
-
from: [
|
|
4062
|
-
{
|
|
4063
|
-
from: tx.from,
|
|
4064
|
-
amount: baseAmount(tx.value, decimals),
|
|
4065
|
-
},
|
|
4066
|
-
],
|
|
4067
|
-
to: [
|
|
4068
|
-
{
|
|
4069
|
-
to: tx.to,
|
|
4070
|
-
amount: baseAmount(tx.value, decimals),
|
|
4071
|
-
},
|
|
4072
|
-
],
|
|
4073
|
-
date: new Date(parseInt(tx.timeStamp) * 1000),
|
|
4074
|
-
type: TxType.Transfer,
|
|
4075
|
-
hash: tx.hash,
|
|
4076
|
-
};
|
|
4077
|
-
};
|
|
4078
|
-
/**
|
|
4079
|
-
* Get transactions from token tx
|
|
4080
|
-
*
|
|
4081
|
-
* @param {TokenTransactionInfo} tx
|
|
4082
|
-
* @returns {Tx|null} The parsed transaction.
|
|
4083
|
-
*/
|
|
4084
|
-
const getTxFromTokenTransaction = (tx, chain, decimals) => {
|
|
4085
|
-
const decimal = parseInt(tx.tokenDecimal) || decimals;
|
|
4086
|
-
const symbol = tx.tokenSymbol;
|
|
4087
|
-
const address = tx.contractAddress;
|
|
4088
|
-
if (validateSymbol(symbol) && validateAddress$1(address)) {
|
|
4089
|
-
const tokenAsset = assetFromString(`${chain}.${symbol}-${address}`);
|
|
4090
|
-
if (tokenAsset) {
|
|
4091
|
-
return {
|
|
4092
|
-
asset: tokenAsset,
|
|
4093
|
-
from: [
|
|
4094
|
-
{
|
|
4095
|
-
from: tx.from,
|
|
4096
|
-
amount: baseAmount(tx.value, decimal),
|
|
4097
|
-
},
|
|
4098
|
-
],
|
|
4099
|
-
to: [
|
|
4100
|
-
{
|
|
4101
|
-
to: tx.to,
|
|
4102
|
-
amount: baseAmount(tx.value, decimal),
|
|
4103
|
-
},
|
|
4104
|
-
],
|
|
4105
|
-
date: new Date(parseInt(tx.timeStamp) * 1000),
|
|
4106
|
-
type: TxType.Transfer,
|
|
4107
|
-
hash: tx.hash,
|
|
4108
|
-
};
|
|
4109
|
-
}
|
|
4110
|
-
}
|
|
4111
|
-
return null;
|
|
4112
|
-
};
|
|
4113
|
-
/**
|
|
4114
|
-
* SafeGasPrice, ProposeGasPrice And FastGasPrice returned in string-Gwei
|
|
4115
|
-
*
|
|
4116
|
-
* @see https://etherscan.io/apis#gastracker
|
|
4117
|
-
*
|
|
4118
|
-
* @param {string} baseUrl The etherscan node url.
|
|
4119
|
-
* @param {string} apiKey The etherscan API key. (optional)
|
|
4120
|
-
* @returns {GasOracleResponse} LastBlock, SafeGasPrice, ProposeGasPrice, FastGasPrice
|
|
4121
|
-
*/
|
|
4122
|
-
const getGasOracle = (baseUrl, apiKey) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4123
|
-
const url = baseUrl + '/api?module=gastracker&action=gasoracle';
|
|
4124
|
-
const result = (yield axios.get(url + getApiKeyQueryParameter(apiKey))).data.result;
|
|
4125
|
-
if (typeof result === 'string')
|
|
4126
|
-
throw Error(`Can not retrieve gasOracle: ${result}`);
|
|
4127
|
-
return result;
|
|
4128
|
-
});
|
|
4129
|
-
/**
|
|
4130
|
-
* Get ETH transaction history
|
|
4131
|
-
*
|
|
4132
|
-
* @see https://etherscan.io/apis#accounts
|
|
4133
|
-
*
|
|
4134
|
-
* @param {string} baseUrl The etherscan node url.
|
|
4135
|
-
* @param {string} address The address.
|
|
4136
|
-
* @param {TransactionHistoryParam} params The search options.
|
|
4137
|
-
* @param {string} apiKey The etherscan API key. (optional)
|
|
4138
|
-
* @returns {ETHTransactionInfo[]} The ETH transaction history
|
|
4139
|
-
*/
|
|
4140
|
-
const getGasAssetTransactionHistory = ({ gasAsset, gasDecimals, baseUrl, address, page, offset, startblock, endblock, apiKey, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4141
|
-
let url = baseUrl + `/api?module=account&action=txlist&sort=desc` + getApiKeyQueryParameter(apiKey);
|
|
4142
|
-
if (address)
|
|
4143
|
-
url += `&address=${address}`;
|
|
4144
|
-
if (offset)
|
|
4145
|
-
url += `&offset=${offset}`;
|
|
4146
|
-
if (page)
|
|
4147
|
-
url += `&page=${page}`;
|
|
4148
|
-
if (startblock)
|
|
4149
|
-
url += `&startblock=${startblock}`;
|
|
4150
|
-
if (endblock)
|
|
4151
|
-
url += `&endblock=${endblock}`;
|
|
4152
|
-
const result = (yield axios.get(url)).data.result;
|
|
4153
|
-
if (JSON.stringify(result).includes('Invalid API Key'))
|
|
4154
|
-
throw new Error('Invalid API Key');
|
|
4155
|
-
if (typeof result !== 'object')
|
|
4156
|
-
throw new Error(result);
|
|
4157
|
-
return filterSelfTxs(result)
|
|
4158
|
-
.filter((tx) => !bnOrZero(tx.value).isZero())
|
|
4159
|
-
.map((tx) => getTxFromEthTransaction(tx, gasAsset, gasDecimals));
|
|
4160
|
-
});
|
|
4161
|
-
/**
|
|
4162
|
-
* Get token transaction history
|
|
4163
|
-
*
|
|
4164
|
-
* @see https://etherscan.io/apis#accounts
|
|
4165
|
-
*
|
|
4166
|
-
* @param {string} baseUrl The etherscan node url.
|
|
4167
|
-
* @param {string} address The address.
|
|
4168
|
-
* @param {TransactionHistoryParam} params The search options.
|
|
4169
|
-
* @param {string} apiKey The etherscan API key. (optional)
|
|
4170
|
-
* @returns {Tx[]} The token transaction history
|
|
4171
|
-
*/
|
|
4172
|
-
const getTokenTransactionHistory = ({ gasDecimals, baseUrl, address, assetAddress, page, offset, startblock, endblock, apiKey, chain, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
4173
|
-
let url = baseUrl + `/api?module=account&action=tokentx&sort=desc` + getApiKeyQueryParameter(apiKey);
|
|
4174
|
-
if (address)
|
|
4175
|
-
url += `&address=${address}`;
|
|
4176
|
-
if (assetAddress)
|
|
4177
|
-
url += `&contractaddress=${assetAddress}`;
|
|
4178
|
-
if (offset)
|
|
4179
|
-
url += `&offset=${offset}`;
|
|
4180
|
-
if (page)
|
|
4181
|
-
url += `&page=${page}`;
|
|
4182
|
-
if (startblock)
|
|
4183
|
-
url += `&startblock=${startblock}`;
|
|
4184
|
-
if (endblock)
|
|
4185
|
-
url += `&endblock=${endblock}`;
|
|
4186
|
-
const result = (yield axios.get(url)).data.result;
|
|
4187
|
-
if (JSON.stringify(result).includes('Invalid API Key'))
|
|
4188
|
-
throw new Error('Invalid API Key');
|
|
4189
|
-
return filterSelfTxs(result)
|
|
4190
|
-
.filter((tx) => !bnOrZero(tx.value).isZero())
|
|
4191
|
-
.reduce((acc, cur) => {
|
|
4192
|
-
const tx = getTxFromTokenTransaction(cur, chain, gasDecimals);
|
|
4193
|
-
return tx ? [...acc, tx] : acc;
|
|
4194
|
-
}, []);
|
|
4195
|
-
});
|
|
4196
|
-
|
|
4197
|
-
class EtherscanProvider {
|
|
4198
|
-
constructor(provider, baseUrl, apiKey, chain, nativeAsset, nativeAssetDecimals) {
|
|
4199
|
-
this.provider = provider;
|
|
4200
|
-
this.baseUrl = baseUrl;
|
|
4201
|
-
this.apiKey = apiKey;
|
|
4202
|
-
this.chain = chain;
|
|
4203
|
-
this.nativeAsset = nativeAsset;
|
|
4204
|
-
this.nativeAssetDecimals = nativeAssetDecimals;
|
|
4205
|
-
this.nativeAsset;
|
|
4206
|
-
this.chain;
|
|
4207
|
-
}
|
|
4208
|
-
getBalance(address, assets) {
|
|
4209
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4210
|
-
//validate assets are for the correct chain
|
|
4211
|
-
assets === null || assets === void 0 ? void 0 : assets.forEach((i) => {
|
|
4212
|
-
if (i.chain !== this.chain)
|
|
4213
|
-
throw Error(`${assetToString(i)} is not an asset of ${this.chain}`);
|
|
4214
|
-
});
|
|
4215
|
-
const balances = [];
|
|
4216
|
-
balances.push(yield this.getNativeAssetBalance(address));
|
|
4217
|
-
if (assets) {
|
|
4218
|
-
for (const asset of assets) {
|
|
4219
|
-
const splitSymbol = asset.symbol.split('-');
|
|
4220
|
-
const tokenSymbol = splitSymbol[0];
|
|
4221
|
-
const contractAddress = splitSymbol[1];
|
|
4222
|
-
balances.push(yield this.getTokenBalance(address, contractAddress, tokenSymbol));
|
|
4223
|
-
}
|
|
4224
|
-
}
|
|
4225
|
-
else {
|
|
4226
|
-
// Get All Erc-20 txs
|
|
4227
|
-
const response = (yield axios.get(`${this.baseUrl}/api?module=account&action=tokentx&address=${address}&sort=asc&apikey=${this.apiKey}`)).data;
|
|
4228
|
-
const erc20TokenTxs = this.getUniqueContractAddresses(response.result);
|
|
4229
|
-
for (const erc20Token of erc20TokenTxs) {
|
|
4230
|
-
balances.push(yield this.getTokenBalance(address, erc20Token.contractAddress, erc20Token.tokenSymbol));
|
|
4231
|
-
}
|
|
4232
|
-
}
|
|
4233
|
-
return balances;
|
|
4234
|
-
});
|
|
4235
|
-
}
|
|
4236
|
-
getNativeAssetBalance(address) {
|
|
4237
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4238
|
-
const gasAssetBalance = yield this.provider.getBalance(address.toLowerCase());
|
|
4239
|
-
const amount = baseAmount(gasAssetBalance.toString(), this.nativeAssetDecimals);
|
|
4240
|
-
return {
|
|
4241
|
-
asset: this.nativeAsset,
|
|
4242
|
-
amount,
|
|
4243
|
-
};
|
|
4244
|
-
});
|
|
4245
|
-
}
|
|
4246
|
-
getTokenBalance(address, contractAddress, tokenTicker) {
|
|
4247
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4248
|
-
const asset = {
|
|
4249
|
-
chain: this.chain,
|
|
4250
|
-
symbol: `${tokenTicker}-${contractAddress}`,
|
|
4251
|
-
ticker: tokenTicker,
|
|
4252
|
-
type: AssetType.TOKEN,
|
|
4253
|
-
};
|
|
4254
|
-
const contract = new ethers.Contract(contractAddress.toLowerCase(), erc20ABI, this.provider);
|
|
4255
|
-
const balance = (yield contract.balanceOf(address.toLowerCase())).toString();
|
|
4256
|
-
const decimals = (yield contract.decimals()).toString();
|
|
4257
|
-
const amount = baseAmount(balance, Number.parseInt(decimals));
|
|
4258
|
-
return {
|
|
4259
|
-
asset,
|
|
4260
|
-
amount,
|
|
4261
|
-
};
|
|
4262
|
-
});
|
|
4263
|
-
}
|
|
4264
|
-
getUniqueContractAddresses(array) {
|
|
4265
|
-
const mySet = new Set();
|
|
4266
|
-
return array.filter((x) => {
|
|
4267
|
-
const key = x.contractAddress, isNew = !mySet.has(key);
|
|
4268
|
-
if (isNew)
|
|
4269
|
-
mySet.add(key);
|
|
4270
|
-
return isNew;
|
|
4271
|
-
});
|
|
4272
|
-
}
|
|
4273
|
-
getTransactions(params) {
|
|
4274
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4275
|
-
const offset = (params === null || params === void 0 ? void 0 : params.offset) || 0;
|
|
4276
|
-
const limit = (params === null || params === void 0 ? void 0 : params.limit) || 10;
|
|
4277
|
-
const assetAddress = params === null || params === void 0 ? void 0 : params.asset;
|
|
4278
|
-
const maxCount = 10000;
|
|
4279
|
-
let transactions;
|
|
4280
|
-
if (assetAddress) {
|
|
4281
|
-
transactions = yield getTokenTransactionHistory({
|
|
4282
|
-
gasDecimals: this.nativeAssetDecimals,
|
|
4283
|
-
baseUrl: this.baseUrl,
|
|
4284
|
-
address: params === null || params === void 0 ? void 0 : params.address,
|
|
4285
|
-
assetAddress,
|
|
4286
|
-
page: 0,
|
|
4287
|
-
offset: maxCount,
|
|
4288
|
-
apiKey: this.apiKey,
|
|
4289
|
-
chain: this.chain,
|
|
4290
|
-
});
|
|
4291
|
-
}
|
|
4292
|
-
else {
|
|
4293
|
-
transactions = yield getGasAssetTransactionHistory({
|
|
4294
|
-
gasAsset: this.nativeAsset,
|
|
4295
|
-
gasDecimals: this.nativeAssetDecimals,
|
|
4296
|
-
baseUrl: this.baseUrl,
|
|
4297
|
-
address: params === null || params === void 0 ? void 0 : params.address,
|
|
4298
|
-
page: 0,
|
|
4299
|
-
offset: maxCount,
|
|
4300
|
-
apiKey: this.apiKey,
|
|
4301
|
-
});
|
|
4302
|
-
}
|
|
4303
|
-
return {
|
|
4304
|
-
total: transactions.length,
|
|
4305
|
-
txs: transactions.filter((_, index) => index >= offset && index < offset + limit),
|
|
4306
|
-
};
|
|
4307
|
-
});
|
|
4308
|
-
}
|
|
4309
|
-
getTransactionData(txHash, assetAddress) {
|
|
4310
|
-
var _a, _b;
|
|
4311
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4312
|
-
let tx;
|
|
4313
|
-
const txInfo = yield this.provider.getTransaction(txHash);
|
|
4314
|
-
if (txInfo) {
|
|
4315
|
-
if (assetAddress) {
|
|
4316
|
-
tx =
|
|
4317
|
-
(_a = (yield getTokenTransactionHistory({
|
|
4318
|
-
gasDecimals: this.nativeAssetDecimals,
|
|
4319
|
-
baseUrl: this.baseUrl,
|
|
4320
|
-
assetAddress,
|
|
4321
|
-
address: txInfo.from,
|
|
4322
|
-
startblock: txInfo.blockNumber,
|
|
4323
|
-
endblock: txInfo.blockNumber ? txInfo.blockNumber + 1 : undefined,
|
|
4324
|
-
apiKey: this.apiKey,
|
|
4325
|
-
chain: this.chain,
|
|
4326
|
-
})).filter((info) => info.hash === txHash)[0]) !== null && _a !== void 0 ? _a : null;
|
|
4327
|
-
}
|
|
4328
|
-
else {
|
|
4329
|
-
tx =
|
|
4330
|
-
(_b = (yield getGasAssetTransactionHistory({
|
|
4331
|
-
gasAsset: this.nativeAsset,
|
|
4332
|
-
gasDecimals: this.nativeAssetDecimals,
|
|
4333
|
-
baseUrl: this.baseUrl,
|
|
4334
|
-
startblock: txInfo.blockNumber,
|
|
4335
|
-
endblock: txInfo.blockNumber ? txInfo.blockNumber + 1 : undefined,
|
|
4336
|
-
apiKey: this.apiKey,
|
|
4337
|
-
address: txInfo.from,
|
|
4338
|
-
})).filter((info) => info.hash === txHash)[0]) !== null && _b !== void 0 ? _b : null;
|
|
4339
|
-
}
|
|
4340
|
-
}
|
|
4341
|
-
if (!tx)
|
|
4342
|
-
throw new Error('Could not get transaction history');
|
|
4343
|
-
return tx;
|
|
4344
|
-
});
|
|
4345
|
-
}
|
|
4346
|
-
getFeeRates() {
|
|
4347
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4348
|
-
const gasOracleResponse = yield getGasOracle(this.baseUrl, this.apiKey);
|
|
4349
|
-
return {
|
|
4350
|
-
[FeeOption.Average]: Number(gasOracleResponse.SafeGasPrice) * Math.pow(10, 9),
|
|
4351
|
-
[FeeOption.Fast]: Number(gasOracleResponse.ProposeGasPrice) * Math.pow(10, 9),
|
|
4352
|
-
[FeeOption.Fastest]: Number(gasOracleResponse.FastGasPrice) * Math.pow(10, 9),
|
|
4353
|
-
};
|
|
4354
|
-
});
|
|
4355
|
-
}
|
|
4356
|
-
}
|
|
4357
|
-
|
|
4358
|
-
// TODO: Study why this is needed
|
|
4359
|
-
const AVAXChain = 'AVAX';
|
|
4360
|
-
({ chain: AVAXChain, symbol: 'AVAX', ticker: 'AVAX', type: AssetType.NATIVE });
|
|
4361
|
-
|
|
4362
|
-
const LOWER_FEE_BOUND = 1000000;
|
|
4363
|
-
const UPPER_FEE_BOUND = 1000000000;
|
|
4364
|
-
const BASE_GAS_ASSET_DECIMAL = 18;
|
|
4365
|
-
const BASEChain = 'BASE';
|
|
4366
|
-
// BASE ETH Gas asset
|
|
4367
|
-
const AssetBETH = { chain: BASEChain, symbol: 'ETH', ticker: 'ETH', type: AssetType.NATIVE };
|
|
4368
|
-
// Define JSON-RPC providers for mainnet and testnet
|
|
4369
|
-
const BASE_MAINNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider('https://1rpc.io/base');
|
|
4370
|
-
const BASE_TESTNET_ETHERS_PROVIDER = new ethers.providers.JsonRpcProvider('https://base-sepolia-rpc.publicnode.com');
|
|
4371
|
-
// Define ethers providers for different networks
|
|
4372
|
-
const ethersJSProviders = {
|
|
4373
|
-
[Network.Mainnet]: BASE_MAINNET_ETHERS_PROVIDER,
|
|
4374
|
-
[Network.Testnet]: BASE_TESTNET_ETHERS_PROVIDER,
|
|
4375
|
-
[Network.Stagenet]: BASE_MAINNET_ETHERS_PROVIDER,
|
|
4376
|
-
};
|
|
4377
|
-
// Define online providers (Etherscan) for mainnet and testnet
|
|
4378
|
-
const BASE_ONLINE_PROVIDER_MAINNET = new EtherscanProvider(BASE_MAINNET_ETHERS_PROVIDER, 'https://api.basescan.org', process.env.BASE_API_KEY || '', BASEChain, AssetBETH, 18);
|
|
4379
|
-
const BASE_ONLINE_PROVIDER_TESTNET = new EtherscanProvider(BASE_TESTNET_ETHERS_PROVIDER, 'https://api-sepolia.basescan.org', process.env.BASE_API_KEY || '', BASEChain, AssetBETH, 18);
|
|
4380
|
-
// Define providers for different networks
|
|
4381
|
-
const baseProviders = {
|
|
4382
|
-
[Network.Mainnet]: BASE_ONLINE_PROVIDER_MAINNET,
|
|
4383
|
-
[Network.Testnet]: BASE_ONLINE_PROVIDER_TESTNET,
|
|
4384
|
-
[Network.Stagenet]: BASE_ONLINE_PROVIDER_MAINNET,
|
|
4385
|
-
};
|
|
4386
|
-
// Define explorer providers for mainnet and testnet
|
|
4387
|
-
const BASE_MAINNET_EXPLORER = new ExplorerProvider('https://basescan.org/', 'https://basescan.org/address/%%ADDRESS%%', 'https://basescan.org/tx/%%TX_ID%%');
|
|
4388
|
-
const BASE_TESTNET_EXPLORER = new ExplorerProvider('https://sepolia.basescan.org', 'https://sepolia.basescan.org/address/%%ADDRESS%%', 'https://sepolia.basescan.org/tx/%%TX_ID%%');
|
|
4389
|
-
// Define explorer providers for different networks
|
|
4390
|
-
const baseExplorerProviders = {
|
|
4391
|
-
[Network.Mainnet]: BASE_MAINNET_EXPLORER,
|
|
4392
|
-
[Network.Testnet]: BASE_TESTNET_EXPLORER,
|
|
4393
|
-
[Network.Stagenet]: BASE_MAINNET_EXPLORER,
|
|
4394
|
-
};
|
|
4395
|
-
// Define root derivation paths for different networks
|
|
4396
|
-
const ethRootDerivationPaths = {
|
|
4397
|
-
[Network.Mainnet]: `m/44'/60'/0'/0/`,
|
|
4398
|
-
[Network.Testnet]: `m/44'/60'/0'/0/`,
|
|
4399
|
-
[Network.Stagenet]: `m/44'/60'/0'/0/`,
|
|
4400
|
-
};
|
|
4401
|
-
// Define default parameters for the Base client
|
|
4402
|
-
// TODO: not sure
|
|
4403
|
-
const defaults = {
|
|
4404
|
-
[Network.Mainnet]: {
|
|
4405
|
-
approveGasLimit: BigNumber.from(200000),
|
|
4406
|
-
transferGasAssetGasLimit: BigNumber.from(23000),
|
|
4407
|
-
transferTokenGasLimit: BigNumber.from(100000),
|
|
4408
|
-
gasPrice: BigNumber.from(0.03 * Math.pow(10, 9)),
|
|
4409
|
-
},
|
|
4410
|
-
[Network.Testnet]: {
|
|
4411
|
-
approveGasLimit: BigNumber.from(200000),
|
|
4412
|
-
transferGasAssetGasLimit: BigNumber.from(23000),
|
|
4413
|
-
transferTokenGasLimit: BigNumber.from(100000),
|
|
4414
|
-
gasPrice: BigNumber.from(0.03 * Math.pow(10, 9)),
|
|
4415
|
-
},
|
|
4416
|
-
[Network.Stagenet]: {
|
|
4417
|
-
approveGasLimit: BigNumber.from(200000),
|
|
4418
|
-
transferGasAssetGasLimit: BigNumber.from(23000),
|
|
4419
|
-
transferTokenGasLimit: BigNumber.from(100000),
|
|
4420
|
-
gasPrice: BigNumber.from(0.2 * Math.pow(10, 9)),
|
|
4421
|
-
},
|
|
4422
|
-
};
|
|
4423
|
-
// Define the default parameters for the Base client
|
|
4424
|
-
const defaultBaseParams = {
|
|
4425
|
-
chain: BASEChain,
|
|
4426
|
-
gasAsset: AssetBETH,
|
|
4427
|
-
gasAssetDecimals: BASE_GAS_ASSET_DECIMAL,
|
|
4428
|
-
defaults,
|
|
4429
|
-
providers: ethersJSProviders,
|
|
4430
|
-
explorerProviders: baseExplorerProviders,
|
|
4431
|
-
dataProviders: [baseProviders],
|
|
4432
|
-
network: Network.Mainnet,
|
|
4433
|
-
feeBounds: {
|
|
4434
|
-
lower: LOWER_FEE_BOUND,
|
|
4435
|
-
upper: UPPER_FEE_BOUND,
|
|
4436
|
-
},
|
|
4437
|
-
rootDerivationPaths: ethRootDerivationPaths,
|
|
4438
|
-
};
|
|
4439
|
-
|
|
4440
|
-
// Import the Client class from '@xchainjs/xchain-evm' module
|
|
4441
|
-
// Create a class called Client that extends the XchainEvmClient class
|
|
4442
|
-
class ClientKeystore extends ClientKeystore$1 {
|
|
4443
|
-
// Constructor function that takes an optional config parameter, defaulting to defaultBaseParams
|
|
4444
|
-
constructor(config = defaultBaseParams) {
|
|
4445
|
-
// Call the constructor of the parent class (XchainEvmClient) with the provided config
|
|
4446
|
-
super(Object.assign(Object.assign({}, config), { signer: config.phrase
|
|
4447
|
-
? new KeystoreSigner({
|
|
4448
|
-
phrase: config.phrase,
|
|
4449
|
-
provider: config.providers[config.network || Network.Mainnet],
|
|
4450
|
-
derivationPath: config.rootDerivationPaths
|
|
4451
|
-
? config.rootDerivationPaths[config.network || Network.Mainnet]
|
|
4452
|
-
: '',
|
|
4453
|
-
})
|
|
4454
|
-
: undefined }));
|
|
4455
|
-
}
|
|
4456
|
-
}
|
|
4457
|
-
|
|
4458
50
|
/**
|
|
4459
51
|
* Check if a chain is EVM and supported by the protocol
|
|
4460
52
|
* @param {Chain} chain to check
|
|
4461
53
|
* @returns true if chain is EVM, otherwise, false
|
|
4462
54
|
*/
|
|
4463
55
|
const isProtocolEVMChain = (chain) => {
|
|
4464
|
-
return [AssetETH.chain, AssetBSC.chain, AssetAVAX.chain].includes(chain);
|
|
56
|
+
return [AssetETH.chain, AssetBSC.chain, AssetAVAX.chain, AssetBETH.chain].includes(chain);
|
|
4465
57
|
};
|
|
4466
58
|
/**
|
|
4467
59
|
* Check if asset is ERC20
|
|
@@ -4470,7 +62,7 @@ const isProtocolEVMChain = (chain) => {
|
|
|
4470
62
|
*/
|
|
4471
63
|
const isProtocolERC20Asset = (asset) => {
|
|
4472
64
|
return isProtocolEVMChain(asset.chain)
|
|
4473
|
-
? [AssetETH, AssetAVAX, AssetBSC].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 &&
|
|
65
|
+
? [AssetETH, AssetAVAX, AssetBSC, AssetBETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, asset)) === -1 &&
|
|
4474
66
|
!isSynthAsset(asset)
|
|
4475
67
|
: false;
|
|
4476
68
|
};
|
|
@@ -4481,8 +73,7 @@ const isProtocolERC20Asset = (asset) => {
|
|
|
4481
73
|
*/
|
|
4482
74
|
const isTokenCryptoAmount = (amount) => {
|
|
4483
75
|
return isProtocolEVMChain(amount.asset.chain)
|
|
4484
|
-
? [AssetETH, AssetAVAX, AssetBSC].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, amount.asset)) === -1 &&
|
|
4485
|
-
!isSynthAsset(amount.asset)
|
|
76
|
+
? [AssetETH, AssetAVAX, AssetBSC, AssetBETH].findIndex((nativeEVMAsset) => eqAsset(nativeEVMAsset, amount.asset)) === -1 && !isSynthAsset(amount.asset)
|
|
4486
77
|
: false;
|
|
4487
78
|
};
|
|
4488
79
|
/**
|
|
@@ -4496,21 +87,21 @@ const isProtocolBFTChain = (chain) => {
|
|
|
4496
87
|
const validateAddress = (network, chain, address) => {
|
|
4497
88
|
switch (chain) {
|
|
4498
89
|
case BTCChain:
|
|
4499
|
-
return new Client$
|
|
90
|
+
return new Client$9(Object.assign(Object.assign({}, defaultBTCParams), { network })).validateAddress(address);
|
|
4500
91
|
case BCHChain:
|
|
4501
|
-
return new Client$
|
|
92
|
+
return new Client$8(Object.assign(Object.assign({}, defaultBchParams), { network })).validateAddress(address);
|
|
4502
93
|
case LTCChain:
|
|
4503
|
-
return new Client$
|
|
94
|
+
return new Client$7(Object.assign(Object.assign({}, defaultLtcParams), { network })).validateAddress(address);
|
|
4504
95
|
case DOGEChain:
|
|
4505
|
-
return new Client$
|
|
96
|
+
return new Client$6(Object.assign(Object.assign({}, defaultDogeParams), { network })).validateAddress(address);
|
|
4506
97
|
case ETHChain:
|
|
4507
|
-
return new Client$
|
|
4508
|
-
case AVAXChain
|
|
4509
|
-
return new Client$
|
|
98
|
+
return new Client$5(Object.assign(Object.assign({}, defaultEthParams), { network })).validateAddress(address);
|
|
99
|
+
case AVAXChain:
|
|
100
|
+
return new Client$4(Object.assign(Object.assign({}, defaultAvaxParams), { network })).validateAddress(address);
|
|
4510
101
|
case BSCChain:
|
|
4511
|
-
return new Client$
|
|
102
|
+
return new Client$3(Object.assign(Object.assign({}, defaultBscParams), { network })).validateAddress(address);
|
|
4512
103
|
case BASEChain:
|
|
4513
|
-
return new
|
|
104
|
+
return new Client$2(Object.assign(Object.assign({}, defaultBaseParams), { network })).validateAddress(address);
|
|
4514
105
|
case GAIAChain:
|
|
4515
106
|
return new Client$1({ network }).validateAddress(address);
|
|
4516
107
|
case THORChain:
|
|
@@ -4522,14 +113,14 @@ const validateAddress = (network, chain, address) => {
|
|
|
4522
113
|
|
|
4523
114
|
class ThorchainAction {
|
|
4524
115
|
static makeAction(actionParams) {
|
|
4525
|
-
return __awaiter
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4526
117
|
return this.isNonProtocolParams(actionParams)
|
|
4527
118
|
? this.makeNonProtocolAction(actionParams)
|
|
4528
119
|
: this.makeProtocolAction(actionParams);
|
|
4529
120
|
});
|
|
4530
121
|
}
|
|
4531
122
|
static makeProtocolAction({ wallet, assetAmount, memo }) {
|
|
4532
|
-
return __awaiter
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4533
124
|
const hash = yield wallet.deposit({
|
|
4534
125
|
chain: THORChain,
|
|
4535
126
|
asset: assetAmount.asset,
|
|
@@ -4543,7 +134,7 @@ class ThorchainAction {
|
|
|
4543
134
|
});
|
|
4544
135
|
}
|
|
4545
136
|
static makeNonProtocolAction({ wallet, assetAmount, recipient, memo, }) {
|
|
4546
|
-
return __awaiter
|
|
137
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4547
138
|
// Non EVM actions
|
|
4548
139
|
if (!isProtocolEVMChain(assetAmount.asset.chain)) {
|
|
4549
140
|
if (isProtocolBFTChain(assetAmount.asset.chain)) {
|
|
@@ -4636,16 +227,16 @@ class ThorchainAMM {
|
|
|
4636
227
|
* @returns ThorchainAMM
|
|
4637
228
|
*/
|
|
4638
229
|
constructor(thorchainQuery = new ThorchainQuery(), wallet = new Wallet({
|
|
4639
|
-
BTC: new Client$
|
|
4640
|
-
BCH: new Client$
|
|
4641
|
-
LTC: new Client$
|
|
4642
|
-
DOGE: new Client$
|
|
4643
|
-
ETH: new Client$
|
|
4644
|
-
AVAX: new Client$
|
|
4645
|
-
BSC: new Client$
|
|
230
|
+
BTC: new Client$9(Object.assign(Object.assign({}, defaultBTCParams), { network: Network.Mainnet })),
|
|
231
|
+
BCH: new Client$8(Object.assign(Object.assign({}, defaultBchParams), { network: Network.Mainnet })),
|
|
232
|
+
LTC: new Client$7(Object.assign(Object.assign({}, defaultLtcParams), { network: Network.Mainnet })),
|
|
233
|
+
DOGE: new Client$6(Object.assign(Object.assign({}, defaultDogeParams), { network: Network.Mainnet })),
|
|
234
|
+
ETH: new Client$5(Object.assign(Object.assign({}, defaultEthParams), { network: Network.Mainnet })),
|
|
235
|
+
AVAX: new Client$4(Object.assign(Object.assign({}, defaultAvaxParams), { network: Network.Mainnet })),
|
|
236
|
+
BSC: new Client$3(Object.assign(Object.assign({}, defaultBscParams), { network: Network.Mainnet })),
|
|
4646
237
|
GAIA: new Client$1({ network: Network.Mainnet }),
|
|
4647
238
|
THOR: new Client(Object.assign(Object.assign({}, defaultClientConfig), { network: Network.Mainnet })),
|
|
4648
|
-
BASE: new
|
|
239
|
+
BASE: new Client$2(Object.assign(Object.assign({}, defaultBaseParams), { network: Network.Mainnet })),
|
|
4649
240
|
})) {
|
|
4650
241
|
this.thorchainQuery = thorchainQuery;
|
|
4651
242
|
this.wallet = wallet;
|
|
@@ -4660,7 +251,7 @@ class ThorchainAMM {
|
|
|
4660
251
|
* @returns The estimated swap details.
|
|
4661
252
|
*/
|
|
4662
253
|
estimateSwap({ fromAddress, fromAsset, amount, destinationAsset, destinationAddress, affiliateAddress = '', affiliateBps = 0, toleranceBps, streamingInterval, streamingQuantity, }) {
|
|
4663
|
-
return __awaiter
|
|
254
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4664
255
|
const errors = yield this.validateSwap({
|
|
4665
256
|
fromAddress,
|
|
4666
257
|
fromAsset,
|
|
@@ -4691,7 +282,7 @@ class ThorchainAMM {
|
|
|
4691
282
|
* @returns {string[]} the reasons the swap can not be done. If it is empty there are no reason to avoid the swap
|
|
4692
283
|
*/
|
|
4693
284
|
validateSwap({ fromAsset, fromAddress, destinationAsset, destinationAddress, amount, affiliateAddress, affiliateBps, streamingInterval, streamingQuantity, }) {
|
|
4694
|
-
return __awaiter
|
|
285
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4695
286
|
const errors = [];
|
|
4696
287
|
if (destinationAddress &&
|
|
4697
288
|
!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, isSynthAsset(destinationAsset) || isTradeAsset(destinationAsset) || isSecuredAsset(destinationAsset)
|
|
@@ -4744,7 +335,7 @@ class ThorchainAMM {
|
|
|
4744
335
|
* @returns {SwapSubmitted} - The transaction hash, URL of BlockExplorer, and expected wait time.
|
|
4745
336
|
*/
|
|
4746
337
|
doSwap({ fromAsset, fromAddress, amount, destinationAsset, destinationAddress, affiliateAddress, affiliateBps, toleranceBps, streamingInterval, streamingQuantity, }) {
|
|
4747
|
-
return __awaiter
|
|
338
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4748
339
|
// Retrieve swap details from ThorchainQuery to ensure validity
|
|
4749
340
|
const txDetails = yield this.thorchainQuery.quoteSwap({
|
|
4750
341
|
fromAsset,
|
|
@@ -4776,7 +367,7 @@ class ThorchainAMM {
|
|
|
4776
367
|
* @returns {Promise<TxSubmitted>} Transaction hash and URL
|
|
4777
368
|
*/
|
|
4778
369
|
approveRouterToSpend({ asset, amount }) {
|
|
4779
|
-
return __awaiter
|
|
370
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4780
371
|
// Get inbound details for the asset chain
|
|
4781
372
|
const inboundDetails = yield this.thorchainQuery.getChainInboundDetails(asset.chain);
|
|
4782
373
|
if (!inboundDetails.router)
|
|
@@ -4798,7 +389,7 @@ class ThorchainAMM {
|
|
|
4798
389
|
* @returns {string[]} the reasons the router of the asset is not allowed to spend the amount. If it is empty, the asset router is allowed to spend the amount
|
|
4799
390
|
*/
|
|
4800
391
|
isRouterApprovedToSpend({ asset, amount, address }) {
|
|
4801
|
-
return __awaiter
|
|
392
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4802
393
|
const errors = [];
|
|
4803
394
|
if (!isProtocolERC20Asset(asset)) {
|
|
4804
395
|
errors.push('Asset should be ERC20');
|
|
@@ -4819,7 +410,7 @@ class ThorchainAMM {
|
|
|
4819
410
|
* @returns - The estimated liquidity addition object.
|
|
4820
411
|
*/
|
|
4821
412
|
estimateAddLiquidity(params) {
|
|
4822
|
-
return __awaiter
|
|
413
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4823
414
|
return yield this.thorchainQuery.estimateAddLP(params);
|
|
4824
415
|
});
|
|
4825
416
|
}
|
|
@@ -4829,7 +420,7 @@ class ThorchainAMM {
|
|
|
4829
420
|
* @returns - The estimated liquidity withdrawal object.
|
|
4830
421
|
*/
|
|
4831
422
|
estimateWithdrawLiquidity(params) {
|
|
4832
|
-
return __awaiter
|
|
423
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4833
424
|
return yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
4834
425
|
});
|
|
4835
426
|
}
|
|
@@ -4840,7 +431,7 @@ class ThorchainAMM {
|
|
|
4840
431
|
* @returns
|
|
4841
432
|
*/
|
|
4842
433
|
addLiquidityPosition(params) {
|
|
4843
|
-
return __awaiter
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4844
435
|
// Check amounts are greater than fees and use return estimated wait
|
|
4845
436
|
const checkLPAdd = yield this.thorchainQuery.estimateAddLP(params);
|
|
4846
437
|
if (!checkLPAdd.canAdd)
|
|
@@ -4899,7 +490,7 @@ class ThorchainAMM {
|
|
|
4899
490
|
* @return - The array of transaction submissions.
|
|
4900
491
|
*/
|
|
4901
492
|
withdrawLiquidityPosition(params) {
|
|
4902
|
-
return __awaiter
|
|
493
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4903
494
|
// Caution Dust Limits: BTC, BCH, LTC chains: 10k sats; DOGE: 1m Sats; ETH: 0 wei; THOR: 0 RUNE.
|
|
4904
495
|
const withdrawParams = yield this.thorchainQuery.estimateWithdrawLP(params);
|
|
4905
496
|
const withdrawLiquidity = {
|
|
@@ -4956,7 +547,7 @@ class ThorchainAMM {
|
|
|
4956
547
|
* @returns The estimated addition to the saver object.
|
|
4957
548
|
*/
|
|
4958
549
|
estimateAddSaver(addAssetAmount) {
|
|
4959
|
-
return __awaiter
|
|
550
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4960
551
|
return yield this.thorchainQuery.estimateAddSaver(addAssetAmount);
|
|
4961
552
|
});
|
|
4962
553
|
}
|
|
@@ -4966,7 +557,7 @@ class ThorchainAMM {
|
|
|
4966
557
|
* @returns The estimated withdrawal from the saver object.
|
|
4967
558
|
*/
|
|
4968
559
|
estimateWithdrawSaver(withdrawParams) {
|
|
4969
|
-
return __awaiter
|
|
560
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4970
561
|
return yield this.thorchainQuery.estimateWithdrawSaver(withdrawParams);
|
|
4971
562
|
});
|
|
4972
563
|
}
|
|
@@ -4976,7 +567,7 @@ class ThorchainAMM {
|
|
|
4976
567
|
* @returns The saver position object.
|
|
4977
568
|
*/
|
|
4978
569
|
getSaverPosition(getsaver) {
|
|
4979
|
-
return __awaiter
|
|
570
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4980
571
|
return yield this.thorchainQuery.getSaverPosition(getsaver);
|
|
4981
572
|
});
|
|
4982
573
|
}
|
|
@@ -4987,7 +578,7 @@ class ThorchainAMM {
|
|
|
4987
578
|
* @returns - The submitted transaction.
|
|
4988
579
|
*/
|
|
4989
580
|
addSaver(addAssetAmount) {
|
|
4990
|
-
return __awaiter
|
|
581
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4991
582
|
const addEstimate = yield this.thorchainQuery.estimateAddSaver(addAssetAmount);
|
|
4992
583
|
if (!addEstimate.canAddSaver)
|
|
4993
584
|
throw Error(`Cannot add to savers`);
|
|
@@ -5005,7 +596,7 @@ class ThorchainAMM {
|
|
|
5005
596
|
* @returns The submitted transaction.
|
|
5006
597
|
*/
|
|
5007
598
|
withdrawSaver(withdrawParams) {
|
|
5008
|
-
return __awaiter
|
|
599
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5009
600
|
const withdrawEstimate = yield this.thorchainQuery.estimateWithdrawSaver(withdrawParams);
|
|
5010
601
|
if (withdrawEstimate.errors.length > 0)
|
|
5011
602
|
throw Error(`${withdrawEstimate.errors}`);
|
|
@@ -5023,7 +614,7 @@ class ThorchainAMM {
|
|
|
5023
614
|
* @returns The quote for opening the loan.
|
|
5024
615
|
*/
|
|
5025
616
|
getLoanQuoteOpen(loanOpenParams) {
|
|
5026
|
-
return __awaiter
|
|
617
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5027
618
|
return yield this.thorchainQuery.getLoanQuoteOpen(loanOpenParams);
|
|
5028
619
|
});
|
|
5029
620
|
}
|
|
@@ -5033,7 +624,7 @@ class ThorchainAMM {
|
|
|
5033
624
|
* @returns The quote for closing the loan.
|
|
5034
625
|
*/
|
|
5035
626
|
getLoanQuoteClose(loanCloseParams) {
|
|
5036
|
-
return __awaiter
|
|
627
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5037
628
|
return yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
5038
629
|
});
|
|
5039
630
|
}
|
|
@@ -5043,7 +634,7 @@ class ThorchainAMM {
|
|
|
5043
634
|
* @returns - The submitted transaction.
|
|
5044
635
|
*/
|
|
5045
636
|
addLoan(loanOpenParams) {
|
|
5046
|
-
return __awaiter
|
|
637
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5047
638
|
const loanOpen = yield this.thorchainQuery.getLoanQuoteOpen(loanOpenParams);
|
|
5048
639
|
if (loanOpen.errors.length > 0)
|
|
5049
640
|
throw Error(`${loanOpen.errors}`);
|
|
@@ -5061,7 +652,7 @@ class ThorchainAMM {
|
|
|
5061
652
|
* @returns The submitted transaction.
|
|
5062
653
|
*/
|
|
5063
654
|
withdrawLoan(loanCloseParams) {
|
|
5064
|
-
return __awaiter
|
|
655
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5065
656
|
const withdrawLoan = yield this.thorchainQuery.getLoanQuoteClose(loanCloseParams);
|
|
5066
657
|
// Checks if there are any errors in the quote
|
|
5067
658
|
if (withdrawLoan.errors.length > 0)
|
|
@@ -5080,7 +671,7 @@ class ThorchainAMM {
|
|
|
5080
671
|
* @returns The Thornames data.
|
|
5081
672
|
*/
|
|
5082
673
|
getThornamesByAddress(address) {
|
|
5083
|
-
return __awaiter
|
|
674
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5084
675
|
return this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.getTHORNameReverseLookup(address);
|
|
5085
676
|
});
|
|
5086
677
|
}
|
|
@@ -5090,7 +681,7 @@ class ThorchainAMM {
|
|
|
5090
681
|
* @returns {QuoteTHORName} Memo to make the registration and the estimation of the operation
|
|
5091
682
|
*/
|
|
5092
683
|
estimateTHORNameRegistration(params) {
|
|
5093
|
-
return __awaiter
|
|
684
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5094
685
|
const errors = [];
|
|
5095
686
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, params.chain, params.chainAddress)) {
|
|
5096
687
|
errors.push(`Invalid address ${params.chainAddress} for ${params.chain} chain`);
|
|
@@ -5127,7 +718,7 @@ class ThorchainAMM {
|
|
|
5127
718
|
* @returns {QuoteTHORName} Memo to make the update and the estimation of the operation
|
|
5128
719
|
*/
|
|
5129
720
|
estimateTHORNameUpdate(params) {
|
|
5130
|
-
return __awaiter
|
|
721
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5131
722
|
const errors = [];
|
|
5132
723
|
if ((params.chain && !params.chainAddress) || (!params.chain && params.chainAddress)) {
|
|
5133
724
|
errors.push(`Alias not provided correctly`);
|
|
@@ -5170,7 +761,7 @@ class ThorchainAMM {
|
|
|
5170
761
|
* @returns {TxSubmitted} Transaction made to register the THORName
|
|
5171
762
|
*/
|
|
5172
763
|
registerTHORName(params) {
|
|
5173
|
-
return __awaiter
|
|
764
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5174
765
|
const quote = yield this.estimateTHORNameRegistration(params);
|
|
5175
766
|
if (!quote.allowed)
|
|
5176
767
|
throw Error(`Can not register THORName. ${quote.errors.join(' ')}`);
|
|
@@ -5187,7 +778,7 @@ class ThorchainAMM {
|
|
|
5187
778
|
* @returns {TxSubmitted} Transaction made to update the THORName
|
|
5188
779
|
*/
|
|
5189
780
|
updateTHORName(params) {
|
|
5190
|
-
return __awaiter
|
|
781
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5191
782
|
const quote = yield this.estimateTHORNameUpdate(params);
|
|
5192
783
|
if (!quote.allowed)
|
|
5193
784
|
throw Error(`Can not update THORName. ${quote.errors.join(' ')}`);
|
|
@@ -5204,7 +795,7 @@ class ThorchainAMM {
|
|
|
5204
795
|
* @returns {AddToTradeAccount} Estimation to add amount to trade account
|
|
5205
796
|
*/
|
|
5206
797
|
estimateAddToTradeAccount({ amount, address }) {
|
|
5207
|
-
return __awaiter
|
|
798
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5208
799
|
const errors = [];
|
|
5209
800
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, THORChain, address)) {
|
|
5210
801
|
errors.push('Invalid trade account address');
|
|
@@ -5240,7 +831,7 @@ class ThorchainAMM {
|
|
|
5240
831
|
* @returns {TxSubmitted} Transaction made to add the trade amount
|
|
5241
832
|
*/
|
|
5242
833
|
addToTradeAccount({ amount, address }) {
|
|
5243
|
-
return __awaiter
|
|
834
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5244
835
|
const quote = yield this.estimateAddToTradeAccount({ amount, address });
|
|
5245
836
|
if (!quote.allowed)
|
|
5246
837
|
throw Error(`Can not add to trade account. ${quote.errors.join(' ')}`);
|
|
@@ -5258,7 +849,7 @@ class ThorchainAMM {
|
|
|
5258
849
|
* @returns {WithdrawFromTradeAccount} Estimation to withdraw amount from trade account
|
|
5259
850
|
*/
|
|
5260
851
|
estimateWithdrawFromTradeAccount({ amount, address, }) {
|
|
5261
|
-
return __awaiter
|
|
852
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5262
853
|
const errors = [];
|
|
5263
854
|
if (!validateAddress(this.thorchainQuery.thorchainCache.midgardQuery.midgardCache.midgard.network, amount.asset.chain, address)) {
|
|
5264
855
|
errors.push('Invalid address to send the withdraw');
|
|
@@ -5285,7 +876,7 @@ class ThorchainAMM {
|
|
|
5285
876
|
* @returns {TxSubmitted} Estimation to withdraw amount from trade account
|
|
5286
877
|
*/
|
|
5287
878
|
withdrawFromTradeAccount({ amount, address }) {
|
|
5288
|
-
return __awaiter
|
|
879
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5289
880
|
const quote = yield this.estimateWithdrawFromTradeAccount({ amount, address });
|
|
5290
881
|
if (!quote.allowed)
|
|
5291
882
|
throw Error(`Can not withdraw from trade account. ${quote.errors.join(' ')}`);
|
|
@@ -5302,7 +893,7 @@ class ThorchainAMM {
|
|
|
5302
893
|
* @returns {EstimateDepositToRunePool} Estimation to make the deposit
|
|
5303
894
|
*/
|
|
5304
895
|
estimateDepositToRunePool({ amount }) {
|
|
5305
|
-
return __awaiter
|
|
896
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5306
897
|
const constants = yield this.thorchainQuery.thorchainCache.thornode.getTcConstants();
|
|
5307
898
|
return {
|
|
5308
899
|
allowed: true,
|
|
@@ -5319,7 +910,7 @@ class ThorchainAMM {
|
|
|
5319
910
|
* @returns {TxSubmitted} Transaction made to deposit to Rune pool
|
|
5320
911
|
*/
|
|
5321
912
|
depositToRunePool(params) {
|
|
5322
|
-
return __awaiter
|
|
913
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5323
914
|
const quote = yield this.estimateDepositToRunePool(params);
|
|
5324
915
|
if (!quote.allowed)
|
|
5325
916
|
throw Error(`Can not deposit to Rune pool. ${quote.errors.join(' ')}`);
|
|
@@ -5336,7 +927,7 @@ class ThorchainAMM {
|
|
|
5336
927
|
* @returns {EstimateWithdrawFromRunePool} Estimation to make a withdraw from Rune pool
|
|
5337
928
|
*/
|
|
5338
929
|
estimateWithdrawFromRunePool({ withdrawBps, affiliate, feeBps, }) {
|
|
5339
|
-
return __awaiter
|
|
930
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5340
931
|
const errors = [];
|
|
5341
932
|
if (withdrawBps <= 0 || withdrawBps > 10000) {
|
|
5342
933
|
errors.push('withdrawBps out of range. Range 0-10000');
|
|
@@ -5372,7 +963,7 @@ class ThorchainAMM {
|
|
|
5372
963
|
* @returns {TxSubmitted} Transaction made to withdraw from Rune pool
|
|
5373
964
|
*/
|
|
5374
965
|
withdrawFromRunePool(params) {
|
|
5375
|
-
return __awaiter
|
|
966
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5376
967
|
const quote = yield this.estimateWithdrawFromRunePool(params);
|
|
5377
968
|
if (!quote.allowed)
|
|
5378
969
|
throw Error(`Can not withdraw from Rune pool. ${quote.errors.join(' ')}`);
|
|
@@ -5384,7 +975,7 @@ class ThorchainAMM {
|
|
|
5384
975
|
});
|
|
5385
976
|
}
|
|
5386
977
|
isTHORName(thorname) {
|
|
5387
|
-
return __awaiter
|
|
978
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
5388
979
|
const details = yield this.thorchainQuery.getThornameDetails(thorname);
|
|
5389
980
|
return details.owner !== '';
|
|
5390
981
|
});
|