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