@passkeyme/auth 2.0.10 → 2.0.12
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/README.md +2 -2
- package/dist/index.esm.js +429 -268
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +429 -268
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +429 -268
- package/dist/index.umd.js.map +1 -1
- package/dist/src/passkeyme-auth.d.ts.map +1 -1
- package/dist/src/types.d.ts +5 -5
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -826,7 +826,7 @@ class PasskeymeAuth {
|
|
|
826
826
|
const defaultRedirectUri = typeof window !== "undefined" && window.location && window.location.origin
|
|
827
827
|
? `${window.location.origin}/auth/callback`
|
|
828
828
|
: "http://localhost:3000/auth/callback";
|
|
829
|
-
//
|
|
829
|
+
// Base URL for hosted auth UI pages - defaults to auth.passkeyme.com
|
|
830
830
|
const serverUrl = config.baseUrl || "https://auth.passkeyme.com";
|
|
831
831
|
console.log("[DEBUG] serverUrl determined as:", serverUrl);
|
|
832
832
|
this.config = {
|
|
@@ -1017,11 +1017,15 @@ class PasskeymeAuth {
|
|
|
1017
1017
|
*/
|
|
1018
1018
|
redirectToOAuth(provider, redirectUri) {
|
|
1019
1019
|
const finalRedirectUri = redirectUri || this.config.redirectUri;
|
|
1020
|
-
// Build direct OAuth initiation URL
|
|
1020
|
+
// Build direct OAuth initiation URL - use apiUrl for backend API endpoints
|
|
1021
|
+
const apiBaseUrl = this.config.apiUrl ||
|
|
1022
|
+
(typeof window !== "undefined" && window.location.hostname !== "localhost"
|
|
1023
|
+
? "https://api.passkeyme.com"
|
|
1024
|
+
: "http://localhost:8000");
|
|
1021
1025
|
const params = new URLSearchParams({
|
|
1022
1026
|
redirect_uri: finalRedirectUri,
|
|
1023
1027
|
});
|
|
1024
|
-
const oauthUrl = `${
|
|
1028
|
+
const oauthUrl = `${apiBaseUrl}/auth/${this.config.appId}/oauth/${provider}/start?${params.toString()}`;
|
|
1025
1029
|
logger.debug("Redirecting directly to OAuth provider:", provider, oauthUrl);
|
|
1026
1030
|
this.performRedirect(oauthUrl, finalRedirectUri);
|
|
1027
1031
|
}
|
|
@@ -1429,6 +1433,19 @@ class PasskeymeAuth {
|
|
|
1429
1433
|
}
|
|
1430
1434
|
// Extract token and user info from response
|
|
1431
1435
|
const { token, user_uuid, success, message } = completeResponse.data;
|
|
1436
|
+
// Decode JWT to extract email and other user info
|
|
1437
|
+
let tokenEmail;
|
|
1438
|
+
try {
|
|
1439
|
+
const tokenParts = token.split(".");
|
|
1440
|
+
if (tokenParts.length === 3) {
|
|
1441
|
+
const payload = JSON.parse(atob(tokenParts[1]));
|
|
1442
|
+
tokenEmail = payload.email;
|
|
1443
|
+
logger.debug("Extracted email from JWT:", tokenEmail);
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
catch (decodeError) {
|
|
1447
|
+
logger.debug("Failed to decode JWT token:", decodeError);
|
|
1448
|
+
}
|
|
1432
1449
|
// Store tokens - use the JWT token as access token
|
|
1433
1450
|
const tokens = {
|
|
1434
1451
|
accessToken: token,
|
|
@@ -1437,11 +1454,13 @@ class PasskeymeAuth {
|
|
|
1437
1454
|
};
|
|
1438
1455
|
await this.tokenStorage.setTokens(tokens);
|
|
1439
1456
|
// Create user object with available information
|
|
1457
|
+
// Prefer email from JWT token, fallback to username
|
|
1458
|
+
const userEmail = tokenEmail || username;
|
|
1440
1459
|
const user = {
|
|
1441
1460
|
id: user_uuid,
|
|
1442
1461
|
uuid: user_uuid,
|
|
1443
1462
|
username: username,
|
|
1444
|
-
email:
|
|
1463
|
+
email: userEmail,
|
|
1445
1464
|
authenticated: true,
|
|
1446
1465
|
};
|
|
1447
1466
|
// Update state
|
|
@@ -1831,6 +1850,13 @@ function createAuth(config) {
|
|
|
1831
1850
|
return new PasskeymeAuth(config);
|
|
1832
1851
|
}
|
|
1833
1852
|
|
|
1853
|
+
/**
|
|
1854
|
+
* Create a bound version of a function with a specified `this` context
|
|
1855
|
+
*
|
|
1856
|
+
* @param {Function} fn - The function to bind
|
|
1857
|
+
* @param {*} thisArg - The value to be passed as the `this` parameter
|
|
1858
|
+
* @returns {Function} A new function that will call the original function with the specified `this` context
|
|
1859
|
+
*/
|
|
1834
1860
|
function bind(fn, thisArg) {
|
|
1835
1861
|
return function wrap() {
|
|
1836
1862
|
return fn.apply(thisArg, arguments);
|
|
@@ -1882,7 +1908,7 @@ const isUndefined = typeOfTest('undefined');
|
|
|
1882
1908
|
*/
|
|
1883
1909
|
function isBuffer(val) {
|
|
1884
1910
|
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
1885
|
-
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
1911
|
+
&& isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
1886
1912
|
}
|
|
1887
1913
|
|
|
1888
1914
|
/**
|
|
@@ -1927,7 +1953,7 @@ const isString = typeOfTest('string');
|
|
|
1927
1953
|
* @param {*} val The value to test
|
|
1928
1954
|
* @returns {boolean} True if value is a Function, otherwise false
|
|
1929
1955
|
*/
|
|
1930
|
-
const isFunction = typeOfTest('function');
|
|
1956
|
+
const isFunction$1 = typeOfTest('function');
|
|
1931
1957
|
|
|
1932
1958
|
/**
|
|
1933
1959
|
* Determine if a value is a Number
|
|
@@ -1983,7 +2009,7 @@ const isEmptyObject = (val) => {
|
|
|
1983
2009
|
if (!isObject(val) || isBuffer(val)) {
|
|
1984
2010
|
return false;
|
|
1985
2011
|
}
|
|
1986
|
-
|
|
2012
|
+
|
|
1987
2013
|
try {
|
|
1988
2014
|
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
1989
2015
|
} catch (e) {
|
|
@@ -2035,7 +2061,7 @@ const isFileList = kindOfTest('FileList');
|
|
|
2035
2061
|
*
|
|
2036
2062
|
* @returns {boolean} True if value is a Stream, otherwise false
|
|
2037
2063
|
*/
|
|
2038
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
|
2064
|
+
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
2039
2065
|
|
|
2040
2066
|
/**
|
|
2041
2067
|
* Determine if a value is a FormData
|
|
@@ -2048,10 +2074,10 @@ const isFormData = (thing) => {
|
|
|
2048
2074
|
let kind;
|
|
2049
2075
|
return thing && (
|
|
2050
2076
|
(typeof FormData === 'function' && thing instanceof FormData) || (
|
|
2051
|
-
isFunction(thing.append) && (
|
|
2077
|
+
isFunction$1(thing.append) && (
|
|
2052
2078
|
(kind = kindOf(thing)) === 'formdata' ||
|
|
2053
2079
|
// detect form-data instance
|
|
2054
|
-
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
|
|
2080
|
+
(kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
|
|
2055
2081
|
)
|
|
2056
2082
|
)
|
|
2057
2083
|
)
|
|
@@ -2176,7 +2202,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
|
|
|
2176
2202
|
* @returns {Object} Result of all merge properties
|
|
2177
2203
|
*/
|
|
2178
2204
|
function merge(/* obj1, obj2, obj3, ... */) {
|
|
2179
|
-
const {caseless} = isContextDefined(this) && this || {};
|
|
2205
|
+
const {caseless, skipUndefined} = isContextDefined(this) && this || {};
|
|
2180
2206
|
const result = {};
|
|
2181
2207
|
const assignValue = (val, key) => {
|
|
2182
2208
|
const targetKey = caseless && findKey(result, key) || key;
|
|
@@ -2186,7 +2212,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
2186
2212
|
result[targetKey] = merge({}, val);
|
|
2187
2213
|
} else if (isArray(val)) {
|
|
2188
2214
|
result[targetKey] = val.slice();
|
|
2189
|
-
} else {
|
|
2215
|
+
} else if (!skipUndefined || !isUndefined(val)) {
|
|
2190
2216
|
result[targetKey] = val;
|
|
2191
2217
|
}
|
|
2192
2218
|
};
|
|
@@ -2209,7 +2235,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
2209
2235
|
*/
|
|
2210
2236
|
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
|
2211
2237
|
forEach(b, (val, key) => {
|
|
2212
|
-
if (thisArg && isFunction(val)) {
|
|
2238
|
+
if (thisArg && isFunction$1(val)) {
|
|
2213
2239
|
a[key] = bind(val, thisArg);
|
|
2214
2240
|
} else {
|
|
2215
2241
|
a[key] = val;
|
|
@@ -2425,13 +2451,13 @@ const reduceDescriptors = (obj, reducer) => {
|
|
|
2425
2451
|
const freezeMethods = (obj) => {
|
|
2426
2452
|
reduceDescriptors(obj, (descriptor, name) => {
|
|
2427
2453
|
// skip restricted props in strict mode
|
|
2428
|
-
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
2454
|
+
if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
2429
2455
|
return false;
|
|
2430
2456
|
}
|
|
2431
2457
|
|
|
2432
2458
|
const value = obj[name];
|
|
2433
2459
|
|
|
2434
|
-
if (!isFunction(value)) return;
|
|
2460
|
+
if (!isFunction$1(value)) return;
|
|
2435
2461
|
|
|
2436
2462
|
descriptor.enumerable = false;
|
|
2437
2463
|
|
|
@@ -2468,6 +2494,8 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
2468
2494
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
2469
2495
|
};
|
|
2470
2496
|
|
|
2497
|
+
|
|
2498
|
+
|
|
2471
2499
|
/**
|
|
2472
2500
|
* If the thing is a FormData object, return true, otherwise return false.
|
|
2473
2501
|
*
|
|
@@ -2476,7 +2504,7 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
2476
2504
|
* @returns {boolean}
|
|
2477
2505
|
*/
|
|
2478
2506
|
function isSpecCompliantForm(thing) {
|
|
2479
|
-
return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|
2507
|
+
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|
2480
2508
|
}
|
|
2481
2509
|
|
|
2482
2510
|
const toJSONObject = (obj) => {
|
|
@@ -2518,7 +2546,7 @@ const toJSONObject = (obj) => {
|
|
|
2518
2546
|
const isAsyncFn = kindOfTest('AsyncFunction');
|
|
2519
2547
|
|
|
2520
2548
|
const isThenable = (thing) =>
|
|
2521
|
-
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
|
2549
|
+
thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
2522
2550
|
|
|
2523
2551
|
// original code
|
|
2524
2552
|
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|
@@ -2542,7 +2570,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
2542
2570
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
2543
2571
|
})(
|
|
2544
2572
|
typeof setImmediate === 'function',
|
|
2545
|
-
isFunction(_global.postMessage)
|
|
2573
|
+
isFunction$1(_global.postMessage)
|
|
2546
2574
|
);
|
|
2547
2575
|
|
|
2548
2576
|
const asap = typeof queueMicrotask !== 'undefined' ?
|
|
@@ -2551,7 +2579,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
|
|
|
2551
2579
|
// *********************
|
|
2552
2580
|
|
|
2553
2581
|
|
|
2554
|
-
const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
|
|
2582
|
+
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
2555
2583
|
|
|
2556
2584
|
|
|
2557
2585
|
var utils$1 = {
|
|
@@ -2575,7 +2603,7 @@ var utils$1 = {
|
|
|
2575
2603
|
isFile,
|
|
2576
2604
|
isBlob,
|
|
2577
2605
|
isRegExp,
|
|
2578
|
-
isFunction,
|
|
2606
|
+
isFunction: isFunction$1,
|
|
2579
2607
|
isStream,
|
|
2580
2608
|
isURLSearchParams,
|
|
2581
2609
|
isTypedArray,
|
|
@@ -2701,11 +2729,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
|
2701
2729
|
return prop !== 'isAxiosError';
|
|
2702
2730
|
});
|
|
2703
2731
|
|
|
2704
|
-
|
|
2732
|
+
const msg = error && error.message ? error.message : 'Error';
|
|
2733
|
+
|
|
2734
|
+
// Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
|
|
2735
|
+
const errCode = code == null && error ? error.code : code;
|
|
2736
|
+
AxiosError.call(axiosError, msg, errCode, config, request, response);
|
|
2705
2737
|
|
|
2706
|
-
|
|
2738
|
+
// Chain the original error on the standard field; non-enumerable to avoid JSON noise
|
|
2739
|
+
if (error && axiosError.cause == null) {
|
|
2740
|
+
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
|
|
2741
|
+
}
|
|
2707
2742
|
|
|
2708
|
-
axiosError.name = error.name;
|
|
2743
|
+
axiosError.name = (error && error.name) || 'Error';
|
|
2709
2744
|
|
|
2710
2745
|
customProps && Object.assign(axiosError, customProps);
|
|
2711
2746
|
|
|
@@ -2996,9 +3031,7 @@ function encode(val) {
|
|
|
2996
3031
|
replace(/%3A/gi, ':').
|
|
2997
3032
|
replace(/%24/g, '$').
|
|
2998
3033
|
replace(/%2C/gi, ',').
|
|
2999
|
-
replace(/%20/g, '+')
|
|
3000
|
-
replace(/%5B/gi, '[').
|
|
3001
|
-
replace(/%5D/gi, ']');
|
|
3034
|
+
replace(/%20/g, '+');
|
|
3002
3035
|
}
|
|
3003
3036
|
|
|
3004
3037
|
/**
|
|
@@ -3076,7 +3109,7 @@ class InterceptorManager {
|
|
|
3076
3109
|
*
|
|
3077
3110
|
* @param {Number} id The ID that was returned by `use`
|
|
3078
3111
|
*
|
|
3079
|
-
* @returns {
|
|
3112
|
+
* @returns {void}
|
|
3080
3113
|
*/
|
|
3081
3114
|
eject(id) {
|
|
3082
3115
|
if (this.handlers[id]) {
|
|
@@ -3403,7 +3436,7 @@ const defaults = {
|
|
|
3403
3436
|
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
3404
3437
|
|
|
3405
3438
|
try {
|
|
3406
|
-
return JSON.parse(data);
|
|
3439
|
+
return JSON.parse(data, this.parseReviver);
|
|
3407
3440
|
} catch (e) {
|
|
3408
3441
|
if (strictJSONParsing) {
|
|
3409
3442
|
if (e.name === 'SyntaxError') {
|
|
@@ -4042,27 +4075,38 @@ var cookies = platform.hasStandardBrowserEnv ?
|
|
|
4042
4075
|
|
|
4043
4076
|
// Standard browser envs support document.cookie
|
|
4044
4077
|
{
|
|
4045
|
-
write(name, value, expires, path, domain, secure) {
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
|
|
4049
|
-
|
|
4050
|
-
utils$1.isString(path) && cookie.push('path=' + path);
|
|
4078
|
+
write(name, value, expires, path, domain, secure, sameSite) {
|
|
4079
|
+
if (typeof document === 'undefined') return;
|
|
4051
4080
|
|
|
4052
|
-
|
|
4081
|
+
const cookie = [`${name}=${encodeURIComponent(value)}`];
|
|
4053
4082
|
|
|
4054
|
-
|
|
4083
|
+
if (utils$1.isNumber(expires)) {
|
|
4084
|
+
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
|
4085
|
+
}
|
|
4086
|
+
if (utils$1.isString(path)) {
|
|
4087
|
+
cookie.push(`path=${path}`);
|
|
4088
|
+
}
|
|
4089
|
+
if (utils$1.isString(domain)) {
|
|
4090
|
+
cookie.push(`domain=${domain}`);
|
|
4091
|
+
}
|
|
4092
|
+
if (secure === true) {
|
|
4093
|
+
cookie.push('secure');
|
|
4094
|
+
}
|
|
4095
|
+
if (utils$1.isString(sameSite)) {
|
|
4096
|
+
cookie.push(`SameSite=${sameSite}`);
|
|
4097
|
+
}
|
|
4055
4098
|
|
|
4056
4099
|
document.cookie = cookie.join('; ');
|
|
4057
4100
|
},
|
|
4058
4101
|
|
|
4059
4102
|
read(name) {
|
|
4060
|
-
|
|
4061
|
-
|
|
4103
|
+
if (typeof document === 'undefined') return null;
|
|
4104
|
+
const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
|
|
4105
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
4062
4106
|
},
|
|
4063
4107
|
|
|
4064
4108
|
remove(name) {
|
|
4065
|
-
this.write(name, '', Date.now() - 86400000);
|
|
4109
|
+
this.write(name, '', Date.now() - 86400000, '/');
|
|
4066
4110
|
}
|
|
4067
4111
|
}
|
|
4068
4112
|
|
|
@@ -4151,11 +4195,11 @@ function mergeConfig(config1, config2) {
|
|
|
4151
4195
|
}
|
|
4152
4196
|
|
|
4153
4197
|
// eslint-disable-next-line consistent-return
|
|
4154
|
-
function mergeDeepProperties(a, b, prop
|
|
4198
|
+
function mergeDeepProperties(a, b, prop, caseless) {
|
|
4155
4199
|
if (!utils$1.isUndefined(b)) {
|
|
4156
|
-
return getMergedValue(a, b, prop
|
|
4200
|
+
return getMergedValue(a, b, prop, caseless);
|
|
4157
4201
|
} else if (!utils$1.isUndefined(a)) {
|
|
4158
|
-
return getMergedValue(undefined, a, prop
|
|
4202
|
+
return getMergedValue(undefined, a, prop, caseless);
|
|
4159
4203
|
}
|
|
4160
4204
|
}
|
|
4161
4205
|
|
|
@@ -4213,7 +4257,7 @@ function mergeConfig(config1, config2) {
|
|
|
4213
4257
|
socketPath: defaultToConfig2,
|
|
4214
4258
|
responseEncoding: defaultToConfig2,
|
|
4215
4259
|
validateStatus: mergeDirectKeys,
|
|
4216
|
-
headers: (a, b
|
|
4260
|
+
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
|
4217
4261
|
};
|
|
4218
4262
|
|
|
4219
4263
|
utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
|
|
@@ -4228,7 +4272,7 @@ function mergeConfig(config1, config2) {
|
|
|
4228
4272
|
var resolveConfig = (config) => {
|
|
4229
4273
|
const newConfig = mergeConfig({}, config);
|
|
4230
4274
|
|
|
4231
|
-
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
|
4275
|
+
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
4232
4276
|
|
|
4233
4277
|
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
|
4234
4278
|
|
|
@@ -4241,17 +4285,21 @@ var resolveConfig = (config) => {
|
|
|
4241
4285
|
);
|
|
4242
4286
|
}
|
|
4243
4287
|
|
|
4244
|
-
let contentType;
|
|
4245
|
-
|
|
4246
4288
|
if (utils$1.isFormData(data)) {
|
|
4247
4289
|
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
4248
|
-
headers.setContentType(undefined); //
|
|
4249
|
-
} else if ((
|
|
4250
|
-
//
|
|
4251
|
-
const
|
|
4252
|
-
headers
|
|
4290
|
+
headers.setContentType(undefined); // browser handles it
|
|
4291
|
+
} else if (utils$1.isFunction(data.getHeaders)) {
|
|
4292
|
+
// Node.js FormData (like form-data package)
|
|
4293
|
+
const formHeaders = data.getHeaders();
|
|
4294
|
+
// Only set safe headers to avoid overwriting security headers
|
|
4295
|
+
const allowedHeaders = ['content-type', 'content-length'];
|
|
4296
|
+
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
4297
|
+
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
4298
|
+
headers.set(key, val);
|
|
4299
|
+
}
|
|
4300
|
+
});
|
|
4253
4301
|
}
|
|
4254
|
-
}
|
|
4302
|
+
}
|
|
4255
4303
|
|
|
4256
4304
|
// Add xsrf header
|
|
4257
4305
|
// This is only done if running in a standard browser environment.
|
|
@@ -4368,15 +4416,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
|
4368
4416
|
};
|
|
4369
4417
|
|
|
4370
4418
|
// Handle low level network errors
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4419
|
+
request.onerror = function handleError(event) {
|
|
4420
|
+
// Browsers deliver a ProgressEvent in XHR onerror
|
|
4421
|
+
// (message may be empty; when present, surface it)
|
|
4422
|
+
// See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
|
|
4423
|
+
const msg = event && event.message ? event.message : 'Network Error';
|
|
4424
|
+
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
|
4425
|
+
// attach the underlying event for consumers who want details
|
|
4426
|
+
err.event = event || null;
|
|
4427
|
+
reject(err);
|
|
4428
|
+
request = null;
|
|
4378
4429
|
};
|
|
4379
|
-
|
|
4430
|
+
|
|
4380
4431
|
// Handle timeout
|
|
4381
4432
|
request.ontimeout = function handleTimeout() {
|
|
4382
4433
|
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
@@ -4592,14 +4643,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
4592
4643
|
})
|
|
4593
4644
|
};
|
|
4594
4645
|
|
|
4595
|
-
const
|
|
4596
|
-
|
|
4646
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
4647
|
+
|
|
4648
|
+
const {isFunction} = utils$1;
|
|
4649
|
+
|
|
4650
|
+
const globalFetchAPI = (({Request, Response}) => ({
|
|
4651
|
+
Request, Response
|
|
4652
|
+
}))(utils$1.global);
|
|
4653
|
+
|
|
4654
|
+
const {
|
|
4655
|
+
ReadableStream: ReadableStream$1, TextEncoder
|
|
4656
|
+
} = utils$1.global;
|
|
4597
4657
|
|
|
4598
|
-
// used only inside the fetch adapter
|
|
4599
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
4600
|
-
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
4601
|
-
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
|
4602
|
-
);
|
|
4603
4658
|
|
|
4604
4659
|
const test = (fn, ...args) => {
|
|
4605
4660
|
try {
|
|
@@ -4609,278 +4664,380 @@ const test = (fn, ...args) => {
|
|
|
4609
4664
|
}
|
|
4610
4665
|
};
|
|
4611
4666
|
|
|
4612
|
-
const
|
|
4613
|
-
|
|
4667
|
+
const factory = (env) => {
|
|
4668
|
+
env = utils$1.merge.call({
|
|
4669
|
+
skipUndefined: true
|
|
4670
|
+
}, globalFetchAPI, env);
|
|
4614
4671
|
|
|
4615
|
-
const
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
|
|
4619
|
-
duplexAccessed = true;
|
|
4620
|
-
return 'half';
|
|
4621
|
-
},
|
|
4622
|
-
}).headers.has('Content-Type');
|
|
4672
|
+
const {fetch: envFetch, Request, Response} = env;
|
|
4673
|
+
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
|
|
4674
|
+
const isRequestSupported = isFunction(Request);
|
|
4675
|
+
const isResponseSupported = isFunction(Response);
|
|
4623
4676
|
|
|
4624
|
-
|
|
4625
|
-
|
|
4677
|
+
if (!isFetchSupported) {
|
|
4678
|
+
return false;
|
|
4679
|
+
}
|
|
4626
4680
|
|
|
4627
|
-
const
|
|
4681
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
|
|
4628
4682
|
|
|
4629
|
-
const
|
|
4630
|
-
|
|
4683
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
4684
|
+
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
4685
|
+
async (str) => new Uint8Array(await new Request(str).arrayBuffer())
|
|
4686
|
+
);
|
|
4631
4687
|
|
|
4688
|
+
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
4689
|
+
let duplexAccessed = false;
|
|
4632
4690
|
|
|
4633
|
-
const
|
|
4634
|
-
|
|
4635
|
-
|
|
4691
|
+
const hasContentType = new Request(platform.origin, {
|
|
4692
|
+
body: new ReadableStream$1(),
|
|
4693
|
+
method: 'POST',
|
|
4694
|
+
get duplex() {
|
|
4695
|
+
duplexAccessed = true;
|
|
4696
|
+
return 'half';
|
|
4697
|
+
},
|
|
4698
|
+
}).headers.has('Content-Type');
|
|
4636
4699
|
|
|
4637
|
-
|
|
4638
|
-
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
4639
|
-
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
|
|
4640
|
-
(_, config) => {
|
|
4641
|
-
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
4642
|
-
});
|
|
4700
|
+
return duplexAccessed && !hasContentType;
|
|
4643
4701
|
});
|
|
4644
|
-
})(new Response));
|
|
4645
4702
|
|
|
4646
|
-
const
|
|
4647
|
-
|
|
4648
|
-
return 0;
|
|
4649
|
-
}
|
|
4703
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
|
|
4704
|
+
test(() => utils$1.isReadableStream(new Response('').body));
|
|
4650
4705
|
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
}
|
|
4706
|
+
const resolvers = {
|
|
4707
|
+
stream: supportsResponseStream && ((res) => res.body)
|
|
4708
|
+
};
|
|
4654
4709
|
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4710
|
+
isFetchSupported && ((() => {
|
|
4711
|
+
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
4712
|
+
!resolvers[type] && (resolvers[type] = (res, config) => {
|
|
4713
|
+
let method = res && res[type];
|
|
4714
|
+
|
|
4715
|
+
if (method) {
|
|
4716
|
+
return method.call(res);
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4719
|
+
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
4720
|
+
});
|
|
4659
4721
|
});
|
|
4660
|
-
|
|
4661
|
-
}
|
|
4722
|
+
})());
|
|
4662
4723
|
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4724
|
+
const getBodyLength = async (body) => {
|
|
4725
|
+
if (body == null) {
|
|
4726
|
+
return 0;
|
|
4727
|
+
}
|
|
4666
4728
|
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4729
|
+
if (utils$1.isBlob(body)) {
|
|
4730
|
+
return body.size;
|
|
4731
|
+
}
|
|
4670
4732
|
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4733
|
+
if (utils$1.isSpecCompliantForm(body)) {
|
|
4734
|
+
const _request = new Request(platform.origin, {
|
|
4735
|
+
method: 'POST',
|
|
4736
|
+
body,
|
|
4737
|
+
});
|
|
4738
|
+
return (await _request.arrayBuffer()).byteLength;
|
|
4739
|
+
}
|
|
4675
4740
|
|
|
4676
|
-
|
|
4677
|
-
|
|
4741
|
+
if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|
4742
|
+
return body.byteLength;
|
|
4743
|
+
}
|
|
4678
4744
|
|
|
4679
|
-
|
|
4680
|
-
|
|
4745
|
+
if (utils$1.isURLSearchParams(body)) {
|
|
4746
|
+
body = body + '';
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
if (utils$1.isString(body)) {
|
|
4750
|
+
return (await encodeText(body)).byteLength;
|
|
4751
|
+
}
|
|
4752
|
+
};
|
|
4681
4753
|
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4754
|
+
const resolveBodyLength = async (headers, body) => {
|
|
4755
|
+
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|
4756
|
+
|
|
4757
|
+
return length == null ? getBodyLength(body) : length;
|
|
4758
|
+
};
|
|
4759
|
+
|
|
4760
|
+
return async (config) => {
|
|
4761
|
+
let {
|
|
4762
|
+
url,
|
|
4763
|
+
method,
|
|
4764
|
+
data,
|
|
4765
|
+
signal,
|
|
4766
|
+
cancelToken,
|
|
4767
|
+
timeout,
|
|
4768
|
+
onDownloadProgress,
|
|
4769
|
+
onUploadProgress,
|
|
4770
|
+
responseType,
|
|
4771
|
+
headers,
|
|
4772
|
+
withCredentials = 'same-origin',
|
|
4773
|
+
fetchOptions
|
|
4774
|
+
} = resolveConfig(config);
|
|
4775
|
+
|
|
4776
|
+
let _fetch = envFetch || fetch;
|
|
4777
|
+
|
|
4778
|
+
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
4779
|
+
|
|
4780
|
+
let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
4781
|
+
|
|
4782
|
+
let request = null;
|
|
4783
|
+
|
|
4784
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
4705
4785
|
composedSignal.unsubscribe();
|
|
4706
|
-
|
|
4786
|
+
});
|
|
4707
4787
|
|
|
4708
|
-
|
|
4788
|
+
let requestContentLength;
|
|
4709
4789
|
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4790
|
+
try {
|
|
4791
|
+
if (
|
|
4792
|
+
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
|
4793
|
+
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
|
4794
|
+
) {
|
|
4795
|
+
let _request = new Request(url, {
|
|
4796
|
+
method: 'POST',
|
|
4797
|
+
body: data,
|
|
4798
|
+
duplex: "half"
|
|
4799
|
+
});
|
|
4720
4800
|
|
|
4721
|
-
|
|
4801
|
+
let contentTypeHeader;
|
|
4722
4802
|
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
|
|
4803
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
|
4804
|
+
headers.setContentType(contentTypeHeader);
|
|
4805
|
+
}
|
|
4726
4806
|
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
|
|
4730
|
-
|
|
4731
|
-
|
|
4807
|
+
if (_request.body) {
|
|
4808
|
+
const [onProgress, flush] = progressEventDecorator(
|
|
4809
|
+
requestContentLength,
|
|
4810
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
4811
|
+
);
|
|
4732
4812
|
|
|
4733
|
-
|
|
4813
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
4814
|
+
}
|
|
4734
4815
|
}
|
|
4735
|
-
}
|
|
4736
4816
|
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4817
|
+
if (!utils$1.isString(withCredentials)) {
|
|
4818
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
|
4819
|
+
}
|
|
4740
4820
|
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
request = new Request(url, {
|
|
4745
|
-
...fetchOptions,
|
|
4746
|
-
signal: composedSignal,
|
|
4747
|
-
method: method.toUpperCase(),
|
|
4748
|
-
headers: headers.normalize().toJSON(),
|
|
4749
|
-
body: data,
|
|
4750
|
-
duplex: "half",
|
|
4751
|
-
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
4752
|
-
});
|
|
4821
|
+
// Cloudflare Workers throws when credentials are defined
|
|
4822
|
+
// see https://github.com/cloudflare/workerd/issues/902
|
|
4823
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
4753
4824
|
|
|
4754
|
-
|
|
4825
|
+
const resolvedOptions = {
|
|
4826
|
+
...fetchOptions,
|
|
4827
|
+
signal: composedSignal,
|
|
4828
|
+
method: method.toUpperCase(),
|
|
4829
|
+
headers: headers.normalize().toJSON(),
|
|
4830
|
+
body: data,
|
|
4831
|
+
duplex: "half",
|
|
4832
|
+
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
4833
|
+
};
|
|
4755
4834
|
|
|
4756
|
-
|
|
4835
|
+
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
4757
4836
|
|
|
4758
|
-
|
|
4759
|
-
const options = {};
|
|
4837
|
+
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
|
|
4760
4838
|
|
|
4761
|
-
|
|
4762
|
-
options[prop] = response[prop];
|
|
4763
|
-
});
|
|
4839
|
+
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
|
4764
4840
|
|
|
4765
|
-
|
|
4841
|
+
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
|
4842
|
+
const options = {};
|
|
4766
4843
|
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
) || [];
|
|
4844
|
+
['status', 'statusText', 'headers'].forEach(prop => {
|
|
4845
|
+
options[prop] = response[prop];
|
|
4846
|
+
});
|
|
4771
4847
|
|
|
4772
|
-
|
|
4773
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
4774
|
-
flush && flush();
|
|
4775
|
-
unsubscribe && unsubscribe();
|
|
4776
|
-
}),
|
|
4777
|
-
options
|
|
4778
|
-
);
|
|
4779
|
-
}
|
|
4848
|
+
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|
4780
4849
|
|
|
4781
|
-
|
|
4850
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
4851
|
+
responseContentLength,
|
|
4852
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
4853
|
+
) || [];
|
|
4782
4854
|
|
|
4783
|
-
|
|
4855
|
+
response = new Response(
|
|
4856
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
4857
|
+
flush && flush();
|
|
4858
|
+
unsubscribe && unsubscribe();
|
|
4859
|
+
}),
|
|
4860
|
+
options
|
|
4861
|
+
);
|
|
4862
|
+
}
|
|
4784
4863
|
|
|
4785
|
-
|
|
4864
|
+
responseType = responseType || 'text';
|
|
4786
4865
|
|
|
4787
|
-
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
4806
|
-
|
|
4866
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
|
4867
|
+
|
|
4868
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
|
4869
|
+
|
|
4870
|
+
return await new Promise((resolve, reject) => {
|
|
4871
|
+
settle(resolve, reject, {
|
|
4872
|
+
data: responseData,
|
|
4873
|
+
headers: AxiosHeaders$1.from(response.headers),
|
|
4874
|
+
status: response.status,
|
|
4875
|
+
statusText: response.statusText,
|
|
4876
|
+
config,
|
|
4877
|
+
request
|
|
4878
|
+
});
|
|
4879
|
+
})
|
|
4880
|
+
} catch (err) {
|
|
4881
|
+
unsubscribe && unsubscribe();
|
|
4882
|
+
|
|
4883
|
+
if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
|
4884
|
+
throw Object.assign(
|
|
4885
|
+
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
|
4886
|
+
{
|
|
4887
|
+
cause: err.cause || err
|
|
4888
|
+
}
|
|
4889
|
+
)
|
|
4890
|
+
}
|
|
4891
|
+
|
|
4892
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
|
4807
4893
|
}
|
|
4894
|
+
}
|
|
4895
|
+
};
|
|
4896
|
+
|
|
4897
|
+
const seedCache = new Map();
|
|
4898
|
+
|
|
4899
|
+
const getFetch = (config) => {
|
|
4900
|
+
let env = (config && config.env) || {};
|
|
4901
|
+
const {fetch, Request, Response} = env;
|
|
4902
|
+
const seeds = [
|
|
4903
|
+
Request, Response, fetch
|
|
4904
|
+
];
|
|
4905
|
+
|
|
4906
|
+
let len = seeds.length, i = len,
|
|
4907
|
+
seed, target, map = seedCache;
|
|
4908
|
+
|
|
4909
|
+
while (i--) {
|
|
4910
|
+
seed = seeds[i];
|
|
4911
|
+
target = map.get(seed);
|
|
4808
4912
|
|
|
4809
|
-
|
|
4913
|
+
target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
|
|
4914
|
+
|
|
4915
|
+
map = target;
|
|
4810
4916
|
}
|
|
4811
|
-
});
|
|
4812
4917
|
|
|
4918
|
+
return target;
|
|
4919
|
+
};
|
|
4920
|
+
|
|
4921
|
+
getFetch();
|
|
4922
|
+
|
|
4923
|
+
/**
|
|
4924
|
+
* Known adapters mapping.
|
|
4925
|
+
* Provides environment-specific adapters for Axios:
|
|
4926
|
+
* - `http` for Node.js
|
|
4927
|
+
* - `xhr` for browsers
|
|
4928
|
+
* - `fetch` for fetch API-based requests
|
|
4929
|
+
*
|
|
4930
|
+
* @type {Object<string, Function|Object>}
|
|
4931
|
+
*/
|
|
4813
4932
|
const knownAdapters = {
|
|
4814
4933
|
http: httpAdapter,
|
|
4815
4934
|
xhr: xhrAdapter,
|
|
4816
|
-
fetch:
|
|
4935
|
+
fetch: {
|
|
4936
|
+
get: getFetch,
|
|
4937
|
+
}
|
|
4817
4938
|
};
|
|
4818
4939
|
|
|
4940
|
+
// Assign adapter names for easier debugging and identification
|
|
4819
4941
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
4820
4942
|
if (fn) {
|
|
4821
4943
|
try {
|
|
4822
|
-
Object.defineProperty(fn, 'name', {value});
|
|
4944
|
+
Object.defineProperty(fn, 'name', { value });
|
|
4823
4945
|
} catch (e) {
|
|
4824
4946
|
// eslint-disable-next-line no-empty
|
|
4825
4947
|
}
|
|
4826
|
-
Object.defineProperty(fn, 'adapterName', {value});
|
|
4948
|
+
Object.defineProperty(fn, 'adapterName', { value });
|
|
4827
4949
|
}
|
|
4828
4950
|
});
|
|
4829
4951
|
|
|
4952
|
+
/**
|
|
4953
|
+
* Render a rejection reason string for unknown or unsupported adapters
|
|
4954
|
+
*
|
|
4955
|
+
* @param {string} reason
|
|
4956
|
+
* @returns {string}
|
|
4957
|
+
*/
|
|
4830
4958
|
const renderReason = (reason) => `- ${reason}`;
|
|
4831
4959
|
|
|
4960
|
+
/**
|
|
4961
|
+
* Check if the adapter is resolved (function, null, or false)
|
|
4962
|
+
*
|
|
4963
|
+
* @param {Function|null|false} adapter
|
|
4964
|
+
* @returns {boolean}
|
|
4965
|
+
*/
|
|
4832
4966
|
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
4833
4967
|
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4968
|
+
/**
|
|
4969
|
+
* Get the first suitable adapter from the provided list.
|
|
4970
|
+
* Tries each adapter in order until a supported one is found.
|
|
4971
|
+
* Throws an AxiosError if no adapter is suitable.
|
|
4972
|
+
*
|
|
4973
|
+
* @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
|
|
4974
|
+
* @param {Object} config - Axios request configuration
|
|
4975
|
+
* @throws {AxiosError} If no suitable adapter is available
|
|
4976
|
+
* @returns {Function} The resolved adapter function
|
|
4977
|
+
*/
|
|
4978
|
+
function getAdapter(adapters, config) {
|
|
4979
|
+
adapters = utils$1.isArray(adapters) ? adapters : [adapters];
|
|
4841
4980
|
|
|
4842
|
-
|
|
4981
|
+
const { length } = adapters;
|
|
4982
|
+
let nameOrAdapter;
|
|
4983
|
+
let adapter;
|
|
4843
4984
|
|
|
4844
|
-
|
|
4845
|
-
nameOrAdapter = adapters[i];
|
|
4846
|
-
let id;
|
|
4985
|
+
const rejectedReasons = {};
|
|
4847
4986
|
|
|
4848
|
-
|
|
4987
|
+
for (let i = 0; i < length; i++) {
|
|
4988
|
+
nameOrAdapter = adapters[i];
|
|
4989
|
+
let id;
|
|
4849
4990
|
|
|
4850
|
-
|
|
4851
|
-
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
4991
|
+
adapter = nameOrAdapter;
|
|
4852
4992
|
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
}
|
|
4856
|
-
}
|
|
4993
|
+
if (!isResolvedHandle(nameOrAdapter)) {
|
|
4994
|
+
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
4857
4995
|
|
|
4858
|
-
if (adapter) {
|
|
4859
|
-
|
|
4996
|
+
if (adapter === undefined) {
|
|
4997
|
+
throw new AxiosError(`Unknown adapter '${id}'`);
|
|
4860
4998
|
}
|
|
4999
|
+
}
|
|
4861
5000
|
|
|
4862
|
-
|
|
5001
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
|
5002
|
+
break;
|
|
4863
5003
|
}
|
|
4864
5004
|
|
|
4865
|
-
|
|
5005
|
+
rejectedReasons[id || '#' + i] = adapter;
|
|
5006
|
+
}
|
|
4866
5007
|
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
)
|
|
5008
|
+
if (!adapter) {
|
|
5009
|
+
const reasons = Object.entries(rejectedReasons)
|
|
5010
|
+
.map(([id, state]) => `adapter ${id} ` +
|
|
5011
|
+
(state === false ? 'is not supported by the environment' : 'is not available in the build')
|
|
5012
|
+
);
|
|
4871
5013
|
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
5014
|
+
let s = length ?
|
|
5015
|
+
(reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
|
|
5016
|
+
'as no adapter specified';
|
|
4875
5017
|
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
5018
|
+
throw new AxiosError(
|
|
5019
|
+
`There is no suitable adapter to dispatch the request ` + s,
|
|
5020
|
+
'ERR_NOT_SUPPORT'
|
|
5021
|
+
);
|
|
5022
|
+
}
|
|
4881
5023
|
|
|
4882
|
-
|
|
4883
|
-
|
|
5024
|
+
return adapter;
|
|
5025
|
+
}
|
|
5026
|
+
|
|
5027
|
+
/**
|
|
5028
|
+
* Exports Axios adapters and utility to resolve an adapter
|
|
5029
|
+
*/
|
|
5030
|
+
var adapters = {
|
|
5031
|
+
/**
|
|
5032
|
+
* Resolve an adapter from a list of adapter names or functions.
|
|
5033
|
+
* @type {Function}
|
|
5034
|
+
*/
|
|
5035
|
+
getAdapter,
|
|
5036
|
+
|
|
5037
|
+
/**
|
|
5038
|
+
* Exposes all known adapters
|
|
5039
|
+
* @type {Object<string, Function|Object>}
|
|
5040
|
+
*/
|
|
4884
5041
|
adapters: knownAdapters
|
|
4885
5042
|
};
|
|
4886
5043
|
|
|
@@ -4923,7 +5080,7 @@ function dispatchRequest(config) {
|
|
|
4923
5080
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
4924
5081
|
}
|
|
4925
5082
|
|
|
4926
|
-
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
|
|
5083
|
+
const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
|
|
4927
5084
|
|
|
4928
5085
|
return adapter(config).then(function onAdapterResolution(response) {
|
|
4929
5086
|
throwIfCancellationRequested(config);
|
|
@@ -4957,7 +5114,7 @@ function dispatchRequest(config) {
|
|
|
4957
5114
|
});
|
|
4958
5115
|
}
|
|
4959
5116
|
|
|
4960
|
-
const VERSION = "1.
|
|
5117
|
+
const VERSION = "1.13.2";
|
|
4961
5118
|
|
|
4962
5119
|
const validators$1 = {};
|
|
4963
5120
|
|
|
@@ -5213,8 +5370,6 @@ class Axios {
|
|
|
5213
5370
|
|
|
5214
5371
|
let newConfig = config;
|
|
5215
5372
|
|
|
5216
|
-
i = 0;
|
|
5217
|
-
|
|
5218
5373
|
while (i < len) {
|
|
5219
5374
|
const onFulfilled = requestInterceptorChain[i++];
|
|
5220
5375
|
const onRejected = requestInterceptorChain[i++];
|
|
@@ -5518,6 +5673,12 @@ const HttpStatusCode = {
|
|
|
5518
5673
|
LoopDetected: 508,
|
|
5519
5674
|
NotExtended: 510,
|
|
5520
5675
|
NetworkAuthenticationRequired: 511,
|
|
5676
|
+
WebServerIsDown: 521,
|
|
5677
|
+
ConnectionTimedOut: 522,
|
|
5678
|
+
OriginIsUnreachable: 523,
|
|
5679
|
+
TimeoutOccurred: 524,
|
|
5680
|
+
SslHandshakeFailed: 525,
|
|
5681
|
+
InvalidSslCertificate: 526,
|
|
5521
5682
|
};
|
|
5522
5683
|
|
|
5523
5684
|
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|