@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/dist/index.esm.js CHANGED
@@ -822,7 +822,7 @@ class PasskeymeAuth {
822
822
  const defaultRedirectUri = typeof window !== "undefined" && window.location && window.location.origin
823
823
  ? `${window.location.origin}/auth/callback`
824
824
  : "http://localhost:3000/auth/callback";
825
- // Use baseUrl for auth endpoints, apiUrl is separate for API calls
825
+ // Base URL for hosted auth UI pages - defaults to auth.passkeyme.com
826
826
  const serverUrl = config.baseUrl || "https://auth.passkeyme.com";
827
827
  console.log("[DEBUG] serverUrl determined as:", serverUrl);
828
828
  this.config = {
@@ -1013,11 +1013,15 @@ class PasskeymeAuth {
1013
1013
  */
1014
1014
  redirectToOAuth(provider, redirectUri) {
1015
1015
  const finalRedirectUri = redirectUri || this.config.redirectUri;
1016
- // Build direct OAuth initiation URL
1016
+ // Build direct OAuth initiation URL - use apiUrl for backend API endpoints
1017
+ const apiBaseUrl = this.config.apiUrl ||
1018
+ (typeof window !== "undefined" && window.location.hostname !== "localhost"
1019
+ ? "https://api.passkeyme.com"
1020
+ : "http://localhost:8000");
1017
1021
  const params = new URLSearchParams({
1018
1022
  redirect_uri: finalRedirectUri,
1019
1023
  });
1020
- const oauthUrl = `${this.config.baseUrl}/auth/${this.config.appId}/oauth/${provider}/start?${params.toString()}`;
1024
+ const oauthUrl = `${apiBaseUrl}/auth/${this.config.appId}/oauth/${provider}/start?${params.toString()}`;
1021
1025
  logger.debug("Redirecting directly to OAuth provider:", provider, oauthUrl);
1022
1026
  this.performRedirect(oauthUrl, finalRedirectUri);
1023
1027
  }
@@ -1425,6 +1429,19 @@ class PasskeymeAuth {
1425
1429
  }
1426
1430
  // Extract token and user info from response
1427
1431
  const { token, user_uuid, success, message } = completeResponse.data;
1432
+ // Decode JWT to extract email and other user info
1433
+ let tokenEmail;
1434
+ try {
1435
+ const tokenParts = token.split(".");
1436
+ if (tokenParts.length === 3) {
1437
+ const payload = JSON.parse(atob(tokenParts[1]));
1438
+ tokenEmail = payload.email;
1439
+ logger.debug("Extracted email from JWT:", tokenEmail);
1440
+ }
1441
+ }
1442
+ catch (decodeError) {
1443
+ logger.debug("Failed to decode JWT token:", decodeError);
1444
+ }
1428
1445
  // Store tokens - use the JWT token as access token
1429
1446
  const tokens = {
1430
1447
  accessToken: token,
@@ -1433,11 +1450,13 @@ class PasskeymeAuth {
1433
1450
  };
1434
1451
  await this.tokenStorage.setTokens(tokens);
1435
1452
  // Create user object with available information
1453
+ // Prefer email from JWT token, fallback to username
1454
+ const userEmail = tokenEmail || username;
1436
1455
  const user = {
1437
1456
  id: user_uuid,
1438
1457
  uuid: user_uuid,
1439
1458
  username: username,
1440
- email: username, // Assume username is email for now
1459
+ email: userEmail,
1441
1460
  authenticated: true,
1442
1461
  };
1443
1462
  // Update state
@@ -1827,6 +1846,13 @@ function createAuth(config) {
1827
1846
  return new PasskeymeAuth(config);
1828
1847
  }
1829
1848
 
1849
+ /**
1850
+ * Create a bound version of a function with a specified `this` context
1851
+ *
1852
+ * @param {Function} fn - The function to bind
1853
+ * @param {*} thisArg - The value to be passed as the `this` parameter
1854
+ * @returns {Function} A new function that will call the original function with the specified `this` context
1855
+ */
1830
1856
  function bind(fn, thisArg) {
1831
1857
  return function wrap() {
1832
1858
  return fn.apply(thisArg, arguments);
@@ -1878,7 +1904,7 @@ const isUndefined = typeOfTest('undefined');
1878
1904
  */
1879
1905
  function isBuffer(val) {
1880
1906
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
1881
- && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
1907
+ && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
1882
1908
  }
1883
1909
 
1884
1910
  /**
@@ -1923,7 +1949,7 @@ const isString = typeOfTest('string');
1923
1949
  * @param {*} val The value to test
1924
1950
  * @returns {boolean} True if value is a Function, otherwise false
1925
1951
  */
1926
- const isFunction = typeOfTest('function');
1952
+ const isFunction$1 = typeOfTest('function');
1927
1953
 
1928
1954
  /**
1929
1955
  * Determine if a value is a Number
@@ -1979,7 +2005,7 @@ const isEmptyObject = (val) => {
1979
2005
  if (!isObject(val) || isBuffer(val)) {
1980
2006
  return false;
1981
2007
  }
1982
-
2008
+
1983
2009
  try {
1984
2010
  return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
1985
2011
  } catch (e) {
@@ -2031,7 +2057,7 @@ const isFileList = kindOfTest('FileList');
2031
2057
  *
2032
2058
  * @returns {boolean} True if value is a Stream, otherwise false
2033
2059
  */
2034
- const isStream = (val) => isObject(val) && isFunction(val.pipe);
2060
+ const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
2035
2061
 
2036
2062
  /**
2037
2063
  * Determine if a value is a FormData
@@ -2044,10 +2070,10 @@ const isFormData = (thing) => {
2044
2070
  let kind;
2045
2071
  return thing && (
2046
2072
  (typeof FormData === 'function' && thing instanceof FormData) || (
2047
- isFunction(thing.append) && (
2073
+ isFunction$1(thing.append) && (
2048
2074
  (kind = kindOf(thing)) === 'formdata' ||
2049
2075
  // detect form-data instance
2050
- (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
2076
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
2051
2077
  )
2052
2078
  )
2053
2079
  )
@@ -2172,7 +2198,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
2172
2198
  * @returns {Object} Result of all merge properties
2173
2199
  */
2174
2200
  function merge(/* obj1, obj2, obj3, ... */) {
2175
- const {caseless} = isContextDefined(this) && this || {};
2201
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
2176
2202
  const result = {};
2177
2203
  const assignValue = (val, key) => {
2178
2204
  const targetKey = caseless && findKey(result, key) || key;
@@ -2182,7 +2208,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
2182
2208
  result[targetKey] = merge({}, val);
2183
2209
  } else if (isArray(val)) {
2184
2210
  result[targetKey] = val.slice();
2185
- } else {
2211
+ } else if (!skipUndefined || !isUndefined(val)) {
2186
2212
  result[targetKey] = val;
2187
2213
  }
2188
2214
  };
@@ -2205,7 +2231,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
2205
2231
  */
2206
2232
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
2207
2233
  forEach(b, (val, key) => {
2208
- if (thisArg && isFunction(val)) {
2234
+ if (thisArg && isFunction$1(val)) {
2209
2235
  a[key] = bind(val, thisArg);
2210
2236
  } else {
2211
2237
  a[key] = val;
@@ -2421,13 +2447,13 @@ const reduceDescriptors = (obj, reducer) => {
2421
2447
  const freezeMethods = (obj) => {
2422
2448
  reduceDescriptors(obj, (descriptor, name) => {
2423
2449
  // skip restricted props in strict mode
2424
- if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
2450
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
2425
2451
  return false;
2426
2452
  }
2427
2453
 
2428
2454
  const value = obj[name];
2429
2455
 
2430
- if (!isFunction(value)) return;
2456
+ if (!isFunction$1(value)) return;
2431
2457
 
2432
2458
  descriptor.enumerable = false;
2433
2459
 
@@ -2464,6 +2490,8 @@ const toFiniteNumber = (value, defaultValue) => {
2464
2490
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
2465
2491
  };
2466
2492
 
2493
+
2494
+
2467
2495
  /**
2468
2496
  * If the thing is a FormData object, return true, otherwise return false.
2469
2497
  *
@@ -2472,7 +2500,7 @@ const toFiniteNumber = (value, defaultValue) => {
2472
2500
  * @returns {boolean}
2473
2501
  */
2474
2502
  function isSpecCompliantForm(thing) {
2475
- return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
2503
+ return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
2476
2504
  }
2477
2505
 
2478
2506
  const toJSONObject = (obj) => {
@@ -2514,7 +2542,7 @@ const toJSONObject = (obj) => {
2514
2542
  const isAsyncFn = kindOfTest('AsyncFunction');
2515
2543
 
2516
2544
  const isThenable = (thing) =>
2517
- thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
2545
+ thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
2518
2546
 
2519
2547
  // original code
2520
2548
  // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
@@ -2538,7 +2566,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
2538
2566
  })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
2539
2567
  })(
2540
2568
  typeof setImmediate === 'function',
2541
- isFunction(_global.postMessage)
2569
+ isFunction$1(_global.postMessage)
2542
2570
  );
2543
2571
 
2544
2572
  const asap = typeof queueMicrotask !== 'undefined' ?
@@ -2547,7 +2575,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
2547
2575
  // *********************
2548
2576
 
2549
2577
 
2550
- const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
2578
+ const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
2551
2579
 
2552
2580
 
2553
2581
  var utils$1 = {
@@ -2571,7 +2599,7 @@ var utils$1 = {
2571
2599
  isFile,
2572
2600
  isBlob,
2573
2601
  isRegExp,
2574
- isFunction,
2602
+ isFunction: isFunction$1,
2575
2603
  isStream,
2576
2604
  isURLSearchParams,
2577
2605
  isTypedArray,
@@ -2697,11 +2725,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
2697
2725
  return prop !== 'isAxiosError';
2698
2726
  });
2699
2727
 
2700
- AxiosError.call(axiosError, error.message, code, config, request, response);
2728
+ const msg = error && error.message ? error.message : 'Error';
2729
+
2730
+ // Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
2731
+ const errCode = code == null && error ? error.code : code;
2732
+ AxiosError.call(axiosError, msg, errCode, config, request, response);
2701
2733
 
2702
- axiosError.cause = error;
2734
+ // Chain the original error on the standard field; non-enumerable to avoid JSON noise
2735
+ if (error && axiosError.cause == null) {
2736
+ Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
2737
+ }
2703
2738
 
2704
- axiosError.name = error.name;
2739
+ axiosError.name = (error && error.name) || 'Error';
2705
2740
 
2706
2741
  customProps && Object.assign(axiosError, customProps);
2707
2742
 
@@ -2992,9 +3027,7 @@ function encode(val) {
2992
3027
  replace(/%3A/gi, ':').
2993
3028
  replace(/%24/g, '$').
2994
3029
  replace(/%2C/gi, ',').
2995
- replace(/%20/g, '+').
2996
- replace(/%5B/gi, '[').
2997
- replace(/%5D/gi, ']');
3030
+ replace(/%20/g, '+');
2998
3031
  }
2999
3032
 
3000
3033
  /**
@@ -3072,7 +3105,7 @@ class InterceptorManager {
3072
3105
  *
3073
3106
  * @param {Number} id The ID that was returned by `use`
3074
3107
  *
3075
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
3108
+ * @returns {void}
3076
3109
  */
3077
3110
  eject(id) {
3078
3111
  if (this.handlers[id]) {
@@ -3399,7 +3432,7 @@ const defaults = {
3399
3432
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
3400
3433
 
3401
3434
  try {
3402
- return JSON.parse(data);
3435
+ return JSON.parse(data, this.parseReviver);
3403
3436
  } catch (e) {
3404
3437
  if (strictJSONParsing) {
3405
3438
  if (e.name === 'SyntaxError') {
@@ -4038,27 +4071,38 @@ var cookies = platform.hasStandardBrowserEnv ?
4038
4071
 
4039
4072
  // Standard browser envs support document.cookie
4040
4073
  {
4041
- write(name, value, expires, path, domain, secure) {
4042
- const cookie = [name + '=' + encodeURIComponent(value)];
4043
-
4044
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
4045
-
4046
- utils$1.isString(path) && cookie.push('path=' + path);
4074
+ write(name, value, expires, path, domain, secure, sameSite) {
4075
+ if (typeof document === 'undefined') return;
4047
4076
 
4048
- utils$1.isString(domain) && cookie.push('domain=' + domain);
4077
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
4049
4078
 
4050
- secure === true && cookie.push('secure');
4079
+ if (utils$1.isNumber(expires)) {
4080
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
4081
+ }
4082
+ if (utils$1.isString(path)) {
4083
+ cookie.push(`path=${path}`);
4084
+ }
4085
+ if (utils$1.isString(domain)) {
4086
+ cookie.push(`domain=${domain}`);
4087
+ }
4088
+ if (secure === true) {
4089
+ cookie.push('secure');
4090
+ }
4091
+ if (utils$1.isString(sameSite)) {
4092
+ cookie.push(`SameSite=${sameSite}`);
4093
+ }
4051
4094
 
4052
4095
  document.cookie = cookie.join('; ');
4053
4096
  },
4054
4097
 
4055
4098
  read(name) {
4056
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
4057
- return (match ? decodeURIComponent(match[3]) : null);
4099
+ if (typeof document === 'undefined') return null;
4100
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
4101
+ return match ? decodeURIComponent(match[1]) : null;
4058
4102
  },
4059
4103
 
4060
4104
  remove(name) {
4061
- this.write(name, '', Date.now() - 86400000);
4105
+ this.write(name, '', Date.now() - 86400000, '/');
4062
4106
  }
4063
4107
  }
4064
4108
 
@@ -4147,11 +4191,11 @@ function mergeConfig(config1, config2) {
4147
4191
  }
4148
4192
 
4149
4193
  // eslint-disable-next-line consistent-return
4150
- function mergeDeepProperties(a, b, prop , caseless) {
4194
+ function mergeDeepProperties(a, b, prop, caseless) {
4151
4195
  if (!utils$1.isUndefined(b)) {
4152
- return getMergedValue(a, b, prop , caseless);
4196
+ return getMergedValue(a, b, prop, caseless);
4153
4197
  } else if (!utils$1.isUndefined(a)) {
4154
- return getMergedValue(undefined, a, prop , caseless);
4198
+ return getMergedValue(undefined, a, prop, caseless);
4155
4199
  }
4156
4200
  }
4157
4201
 
@@ -4209,7 +4253,7 @@ function mergeConfig(config1, config2) {
4209
4253
  socketPath: defaultToConfig2,
4210
4254
  responseEncoding: defaultToConfig2,
4211
4255
  validateStatus: mergeDirectKeys,
4212
- headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
4256
+ headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
4213
4257
  };
4214
4258
 
4215
4259
  utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
@@ -4224,7 +4268,7 @@ function mergeConfig(config1, config2) {
4224
4268
  var resolveConfig = (config) => {
4225
4269
  const newConfig = mergeConfig({}, config);
4226
4270
 
4227
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
4271
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
4228
4272
 
4229
4273
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
4230
4274
 
@@ -4237,17 +4281,21 @@ var resolveConfig = (config) => {
4237
4281
  );
4238
4282
  }
4239
4283
 
4240
- let contentType;
4241
-
4242
4284
  if (utils$1.isFormData(data)) {
4243
4285
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
4244
- headers.setContentType(undefined); // Let the browser set it
4245
- } else if ((contentType = headers.getContentType()) !== false) {
4246
- // fix semicolon duplication issue for ReactNative FormData implementation
4247
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
4248
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
4286
+ headers.setContentType(undefined); // browser handles it
4287
+ } else if (utils$1.isFunction(data.getHeaders)) {
4288
+ // Node.js FormData (like form-data package)
4289
+ const formHeaders = data.getHeaders();
4290
+ // Only set safe headers to avoid overwriting security headers
4291
+ const allowedHeaders = ['content-type', 'content-length'];
4292
+ Object.entries(formHeaders).forEach(([key, val]) => {
4293
+ if (allowedHeaders.includes(key.toLowerCase())) {
4294
+ headers.set(key, val);
4295
+ }
4296
+ });
4249
4297
  }
4250
- }
4298
+ }
4251
4299
 
4252
4300
  // Add xsrf header
4253
4301
  // This is only done if running in a standard browser environment.
@@ -4364,15 +4412,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
4364
4412
  };
4365
4413
 
4366
4414
  // Handle low level network errors
4367
- request.onerror = function handleError() {
4368
- // Real errors are hidden from us by the browser
4369
- // onerror should only fire if it's a network error
4370
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
4371
-
4372
- // Clean up request
4373
- request = null;
4415
+ request.onerror = function handleError(event) {
4416
+ // Browsers deliver a ProgressEvent in XHR onerror
4417
+ // (message may be empty; when present, surface it)
4418
+ // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
4419
+ const msg = event && event.message ? event.message : 'Network Error';
4420
+ const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
4421
+ // attach the underlying event for consumers who want details
4422
+ err.event = event || null;
4423
+ reject(err);
4424
+ request = null;
4374
4425
  };
4375
-
4426
+
4376
4427
  // Handle timeout
4377
4428
  request.ontimeout = function handleTimeout() {
4378
4429
  let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
@@ -4588,14 +4639,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
4588
4639
  })
4589
4640
  };
4590
4641
 
4591
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
4592
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
4642
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
4643
+
4644
+ const {isFunction} = utils$1;
4645
+
4646
+ const globalFetchAPI = (({Request, Response}) => ({
4647
+ Request, Response
4648
+ }))(utils$1.global);
4649
+
4650
+ const {
4651
+ ReadableStream: ReadableStream$1, TextEncoder
4652
+ } = utils$1.global;
4593
4653
 
4594
- // used only inside the fetch adapter
4595
- const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
4596
- ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
4597
- async (str) => new Uint8Array(await new Response(str).arrayBuffer())
4598
- );
4599
4654
 
4600
4655
  const test = (fn, ...args) => {
4601
4656
  try {
@@ -4605,278 +4660,380 @@ const test = (fn, ...args) => {
4605
4660
  }
4606
4661
  };
4607
4662
 
4608
- const supportsRequestStream = isReadableStreamSupported && test(() => {
4609
- let duplexAccessed = false;
4663
+ const factory = (env) => {
4664
+ env = utils$1.merge.call({
4665
+ skipUndefined: true
4666
+ }, globalFetchAPI, env);
4610
4667
 
4611
- const hasContentType = new Request(platform.origin, {
4612
- body: new ReadableStream(),
4613
- method: 'POST',
4614
- get duplex() {
4615
- duplexAccessed = true;
4616
- return 'half';
4617
- },
4618
- }).headers.has('Content-Type');
4668
+ const {fetch: envFetch, Request, Response} = env;
4669
+ const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
4670
+ const isRequestSupported = isFunction(Request);
4671
+ const isResponseSupported = isFunction(Response);
4619
4672
 
4620
- return duplexAccessed && !hasContentType;
4621
- });
4673
+ if (!isFetchSupported) {
4674
+ return false;
4675
+ }
4622
4676
 
4623
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
4677
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
4624
4678
 
4625
- const supportsResponseStream = isReadableStreamSupported &&
4626
- test(() => utils$1.isReadableStream(new Response('').body));
4679
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
4680
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
4681
+ async (str) => new Uint8Array(await new Request(str).arrayBuffer())
4682
+ );
4627
4683
 
4684
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
4685
+ let duplexAccessed = false;
4628
4686
 
4629
- const resolvers = {
4630
- stream: supportsResponseStream && ((res) => res.body)
4631
- };
4687
+ const hasContentType = new Request(platform.origin, {
4688
+ body: new ReadableStream$1(),
4689
+ method: 'POST',
4690
+ get duplex() {
4691
+ duplexAccessed = true;
4692
+ return 'half';
4693
+ },
4694
+ }).headers.has('Content-Type');
4632
4695
 
4633
- isFetchSupported && (((res) => {
4634
- ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
4635
- !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
4636
- (_, config) => {
4637
- throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
4638
- });
4696
+ return duplexAccessed && !hasContentType;
4639
4697
  });
4640
- })(new Response));
4641
4698
 
4642
- const getBodyLength = async (body) => {
4643
- if (body == null) {
4644
- return 0;
4645
- }
4699
+ const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
4700
+ test(() => utils$1.isReadableStream(new Response('').body));
4646
4701
 
4647
- if(utils$1.isBlob(body)) {
4648
- return body.size;
4649
- }
4702
+ const resolvers = {
4703
+ stream: supportsResponseStream && ((res) => res.body)
4704
+ };
4650
4705
 
4651
- if(utils$1.isSpecCompliantForm(body)) {
4652
- const _request = new Request(platform.origin, {
4653
- method: 'POST',
4654
- body,
4706
+ isFetchSupported && ((() => {
4707
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
4708
+ !resolvers[type] && (resolvers[type] = (res, config) => {
4709
+ let method = res && res[type];
4710
+
4711
+ if (method) {
4712
+ return method.call(res);
4713
+ }
4714
+
4715
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
4716
+ });
4655
4717
  });
4656
- return (await _request.arrayBuffer()).byteLength;
4657
- }
4718
+ })());
4658
4719
 
4659
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
4660
- return body.byteLength;
4661
- }
4720
+ const getBodyLength = async (body) => {
4721
+ if (body == null) {
4722
+ return 0;
4723
+ }
4662
4724
 
4663
- if(utils$1.isURLSearchParams(body)) {
4664
- body = body + '';
4665
- }
4725
+ if (utils$1.isBlob(body)) {
4726
+ return body.size;
4727
+ }
4666
4728
 
4667
- if(utils$1.isString(body)) {
4668
- return (await encodeText(body)).byteLength;
4669
- }
4670
- };
4729
+ if (utils$1.isSpecCompliantForm(body)) {
4730
+ const _request = new Request(platform.origin, {
4731
+ method: 'POST',
4732
+ body,
4733
+ });
4734
+ return (await _request.arrayBuffer()).byteLength;
4735
+ }
4671
4736
 
4672
- const resolveBodyLength = async (headers, body) => {
4673
- const length = utils$1.toFiniteNumber(headers.getContentLength());
4737
+ if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
4738
+ return body.byteLength;
4739
+ }
4674
4740
 
4675
- return length == null ? getBodyLength(body) : length;
4676
- };
4741
+ if (utils$1.isURLSearchParams(body)) {
4742
+ body = body + '';
4743
+ }
4744
+
4745
+ if (utils$1.isString(body)) {
4746
+ return (await encodeText(body)).byteLength;
4747
+ }
4748
+ };
4677
4749
 
4678
- var fetchAdapter = isFetchSupported && (async (config) => {
4679
- let {
4680
- url,
4681
- method,
4682
- data,
4683
- signal,
4684
- cancelToken,
4685
- timeout,
4686
- onDownloadProgress,
4687
- onUploadProgress,
4688
- responseType,
4689
- headers,
4690
- withCredentials = 'same-origin',
4691
- fetchOptions
4692
- } = resolveConfig(config);
4693
-
4694
- responseType = responseType ? (responseType + '').toLowerCase() : 'text';
4695
-
4696
- let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
4697
-
4698
- let request;
4699
-
4700
- const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
4750
+ const resolveBodyLength = async (headers, body) => {
4751
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
4752
+
4753
+ return length == null ? getBodyLength(body) : length;
4754
+ };
4755
+
4756
+ return async (config) => {
4757
+ let {
4758
+ url,
4759
+ method,
4760
+ data,
4761
+ signal,
4762
+ cancelToken,
4763
+ timeout,
4764
+ onDownloadProgress,
4765
+ onUploadProgress,
4766
+ responseType,
4767
+ headers,
4768
+ withCredentials = 'same-origin',
4769
+ fetchOptions
4770
+ } = resolveConfig(config);
4771
+
4772
+ let _fetch = envFetch || fetch;
4773
+
4774
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
4775
+
4776
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
4777
+
4778
+ let request = null;
4779
+
4780
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
4701
4781
  composedSignal.unsubscribe();
4702
- });
4782
+ });
4703
4783
 
4704
- let requestContentLength;
4784
+ let requestContentLength;
4705
4785
 
4706
- try {
4707
- if (
4708
- onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
4709
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
4710
- ) {
4711
- let _request = new Request(url, {
4712
- method: 'POST',
4713
- body: data,
4714
- duplex: "half"
4715
- });
4786
+ try {
4787
+ if (
4788
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
4789
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
4790
+ ) {
4791
+ let _request = new Request(url, {
4792
+ method: 'POST',
4793
+ body: data,
4794
+ duplex: "half"
4795
+ });
4716
4796
 
4717
- let contentTypeHeader;
4797
+ let contentTypeHeader;
4718
4798
 
4719
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
4720
- headers.setContentType(contentTypeHeader);
4721
- }
4799
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
4800
+ headers.setContentType(contentTypeHeader);
4801
+ }
4722
4802
 
4723
- if (_request.body) {
4724
- const [onProgress, flush] = progressEventDecorator(
4725
- requestContentLength,
4726
- progressEventReducer(asyncDecorator(onUploadProgress))
4727
- );
4803
+ if (_request.body) {
4804
+ const [onProgress, flush] = progressEventDecorator(
4805
+ requestContentLength,
4806
+ progressEventReducer(asyncDecorator(onUploadProgress))
4807
+ );
4728
4808
 
4729
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
4809
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
4810
+ }
4730
4811
  }
4731
- }
4732
4812
 
4733
- if (!utils$1.isString(withCredentials)) {
4734
- withCredentials = withCredentials ? 'include' : 'omit';
4735
- }
4813
+ if (!utils$1.isString(withCredentials)) {
4814
+ withCredentials = withCredentials ? 'include' : 'omit';
4815
+ }
4736
4816
 
4737
- // Cloudflare Workers throws when credentials are defined
4738
- // see https://github.com/cloudflare/workerd/issues/902
4739
- const isCredentialsSupported = "credentials" in Request.prototype;
4740
- request = new Request(url, {
4741
- ...fetchOptions,
4742
- signal: composedSignal,
4743
- method: method.toUpperCase(),
4744
- headers: headers.normalize().toJSON(),
4745
- body: data,
4746
- duplex: "half",
4747
- credentials: isCredentialsSupported ? withCredentials : undefined
4748
- });
4817
+ // Cloudflare Workers throws when credentials are defined
4818
+ // see https://github.com/cloudflare/workerd/issues/902
4819
+ const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
4749
4820
 
4750
- let response = await fetch(request, fetchOptions);
4821
+ const resolvedOptions = {
4822
+ ...fetchOptions,
4823
+ signal: composedSignal,
4824
+ method: method.toUpperCase(),
4825
+ headers: headers.normalize().toJSON(),
4826
+ body: data,
4827
+ duplex: "half",
4828
+ credentials: isCredentialsSupported ? withCredentials : undefined
4829
+ };
4751
4830
 
4752
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
4831
+ request = isRequestSupported && new Request(url, resolvedOptions);
4753
4832
 
4754
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
4755
- const options = {};
4833
+ let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
4756
4834
 
4757
- ['status', 'statusText', 'headers'].forEach(prop => {
4758
- options[prop] = response[prop];
4759
- });
4835
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
4760
4836
 
4761
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
4837
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
4838
+ const options = {};
4762
4839
 
4763
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
4764
- responseContentLength,
4765
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
4766
- ) || [];
4840
+ ['status', 'statusText', 'headers'].forEach(prop => {
4841
+ options[prop] = response[prop];
4842
+ });
4767
4843
 
4768
- response = new Response(
4769
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
4770
- flush && flush();
4771
- unsubscribe && unsubscribe();
4772
- }),
4773
- options
4774
- );
4775
- }
4844
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
4776
4845
 
4777
- responseType = responseType || 'text';
4846
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
4847
+ responseContentLength,
4848
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
4849
+ ) || [];
4778
4850
 
4779
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
4851
+ response = new Response(
4852
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
4853
+ flush && flush();
4854
+ unsubscribe && unsubscribe();
4855
+ }),
4856
+ options
4857
+ );
4858
+ }
4780
4859
 
4781
- !isStreamResponse && unsubscribe && unsubscribe();
4860
+ responseType = responseType || 'text';
4782
4861
 
4783
- return await new Promise((resolve, reject) => {
4784
- settle(resolve, reject, {
4785
- data: responseData,
4786
- headers: AxiosHeaders$1.from(response.headers),
4787
- status: response.status,
4788
- statusText: response.statusText,
4789
- config,
4790
- request
4791
- });
4792
- })
4793
- } catch (err) {
4794
- unsubscribe && unsubscribe();
4795
-
4796
- if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
4797
- throw Object.assign(
4798
- new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
4799
- {
4800
- cause: err.cause || err
4801
- }
4802
- )
4862
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
4863
+
4864
+ !isStreamResponse && unsubscribe && unsubscribe();
4865
+
4866
+ return await new Promise((resolve, reject) => {
4867
+ settle(resolve, reject, {
4868
+ data: responseData,
4869
+ headers: AxiosHeaders$1.from(response.headers),
4870
+ status: response.status,
4871
+ statusText: response.statusText,
4872
+ config,
4873
+ request
4874
+ });
4875
+ })
4876
+ } catch (err) {
4877
+ unsubscribe && unsubscribe();
4878
+
4879
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
4880
+ throw Object.assign(
4881
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
4882
+ {
4883
+ cause: err.cause || err
4884
+ }
4885
+ )
4886
+ }
4887
+
4888
+ throw AxiosError.from(err, err && err.code, config, request);
4803
4889
  }
4890
+ }
4891
+ };
4892
+
4893
+ const seedCache = new Map();
4894
+
4895
+ const getFetch = (config) => {
4896
+ let env = (config && config.env) || {};
4897
+ const {fetch, Request, Response} = env;
4898
+ const seeds = [
4899
+ Request, Response, fetch
4900
+ ];
4901
+
4902
+ let len = seeds.length, i = len,
4903
+ seed, target, map = seedCache;
4904
+
4905
+ while (i--) {
4906
+ seed = seeds[i];
4907
+ target = map.get(seed);
4804
4908
 
4805
- throw AxiosError.from(err, err && err.code, config, request);
4909
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
4910
+
4911
+ map = target;
4806
4912
  }
4807
- });
4808
4913
 
4914
+ return target;
4915
+ };
4916
+
4917
+ getFetch();
4918
+
4919
+ /**
4920
+ * Known adapters mapping.
4921
+ * Provides environment-specific adapters for Axios:
4922
+ * - `http` for Node.js
4923
+ * - `xhr` for browsers
4924
+ * - `fetch` for fetch API-based requests
4925
+ *
4926
+ * @type {Object<string, Function|Object>}
4927
+ */
4809
4928
  const knownAdapters = {
4810
4929
  http: httpAdapter,
4811
4930
  xhr: xhrAdapter,
4812
- fetch: fetchAdapter
4931
+ fetch: {
4932
+ get: getFetch,
4933
+ }
4813
4934
  };
4814
4935
 
4936
+ // Assign adapter names for easier debugging and identification
4815
4937
  utils$1.forEach(knownAdapters, (fn, value) => {
4816
4938
  if (fn) {
4817
4939
  try {
4818
- Object.defineProperty(fn, 'name', {value});
4940
+ Object.defineProperty(fn, 'name', { value });
4819
4941
  } catch (e) {
4820
4942
  // eslint-disable-next-line no-empty
4821
4943
  }
4822
- Object.defineProperty(fn, 'adapterName', {value});
4944
+ Object.defineProperty(fn, 'adapterName', { value });
4823
4945
  }
4824
4946
  });
4825
4947
 
4948
+ /**
4949
+ * Render a rejection reason string for unknown or unsupported adapters
4950
+ *
4951
+ * @param {string} reason
4952
+ * @returns {string}
4953
+ */
4826
4954
  const renderReason = (reason) => `- ${reason}`;
4827
4955
 
4956
+ /**
4957
+ * Check if the adapter is resolved (function, null, or false)
4958
+ *
4959
+ * @param {Function|null|false} adapter
4960
+ * @returns {boolean}
4961
+ */
4828
4962
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
4829
4963
 
4830
- var adapters = {
4831
- getAdapter: (adapters) => {
4832
- adapters = utils$1.isArray(adapters) ? adapters : [adapters];
4833
-
4834
- const {length} = adapters;
4835
- let nameOrAdapter;
4836
- let adapter;
4964
+ /**
4965
+ * Get the first suitable adapter from the provided list.
4966
+ * Tries each adapter in order until a supported one is found.
4967
+ * Throws an AxiosError if no adapter is suitable.
4968
+ *
4969
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
4970
+ * @param {Object} config - Axios request configuration
4971
+ * @throws {AxiosError} If no suitable adapter is available
4972
+ * @returns {Function} The resolved adapter function
4973
+ */
4974
+ function getAdapter(adapters, config) {
4975
+ adapters = utils$1.isArray(adapters) ? adapters : [adapters];
4837
4976
 
4838
- const rejectedReasons = {};
4977
+ const { length } = adapters;
4978
+ let nameOrAdapter;
4979
+ let adapter;
4839
4980
 
4840
- for (let i = 0; i < length; i++) {
4841
- nameOrAdapter = adapters[i];
4842
- let id;
4981
+ const rejectedReasons = {};
4843
4982
 
4844
- adapter = nameOrAdapter;
4983
+ for (let i = 0; i < length; i++) {
4984
+ nameOrAdapter = adapters[i];
4985
+ let id;
4845
4986
 
4846
- if (!isResolvedHandle(nameOrAdapter)) {
4847
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
4987
+ adapter = nameOrAdapter;
4848
4988
 
4849
- if (adapter === undefined) {
4850
- throw new AxiosError(`Unknown adapter '${id}'`);
4851
- }
4852
- }
4989
+ if (!isResolvedHandle(nameOrAdapter)) {
4990
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
4853
4991
 
4854
- if (adapter) {
4855
- break;
4992
+ if (adapter === undefined) {
4993
+ throw new AxiosError(`Unknown adapter '${id}'`);
4856
4994
  }
4995
+ }
4857
4996
 
4858
- rejectedReasons[id || '#' + i] = adapter;
4997
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
4998
+ break;
4859
4999
  }
4860
5000
 
4861
- if (!adapter) {
5001
+ rejectedReasons[id || '#' + i] = adapter;
5002
+ }
4862
5003
 
4863
- const reasons = Object.entries(rejectedReasons)
4864
- .map(([id, state]) => `adapter ${id} ` +
4865
- (state === false ? 'is not supported by the environment' : 'is not available in the build')
4866
- );
5004
+ if (!adapter) {
5005
+ const reasons = Object.entries(rejectedReasons)
5006
+ .map(([id, state]) => `adapter ${id} ` +
5007
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
5008
+ );
4867
5009
 
4868
- let s = length ?
4869
- (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
4870
- 'as no adapter specified';
5010
+ let s = length ?
5011
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
5012
+ 'as no adapter specified';
4871
5013
 
4872
- throw new AxiosError(
4873
- `There is no suitable adapter to dispatch the request ` + s,
4874
- 'ERR_NOT_SUPPORT'
4875
- );
4876
- }
5014
+ throw new AxiosError(
5015
+ `There is no suitable adapter to dispatch the request ` + s,
5016
+ 'ERR_NOT_SUPPORT'
5017
+ );
5018
+ }
4877
5019
 
4878
- return adapter;
4879
- },
5020
+ return adapter;
5021
+ }
5022
+
5023
+ /**
5024
+ * Exports Axios adapters and utility to resolve an adapter
5025
+ */
5026
+ var adapters = {
5027
+ /**
5028
+ * Resolve an adapter from a list of adapter names or functions.
5029
+ * @type {Function}
5030
+ */
5031
+ getAdapter,
5032
+
5033
+ /**
5034
+ * Exposes all known adapters
5035
+ * @type {Object<string, Function|Object>}
5036
+ */
4880
5037
  adapters: knownAdapters
4881
5038
  };
4882
5039
 
@@ -4919,7 +5076,7 @@ function dispatchRequest(config) {
4919
5076
  config.headers.setContentType('application/x-www-form-urlencoded', false);
4920
5077
  }
4921
5078
 
4922
- const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
5079
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
4923
5080
 
4924
5081
  return adapter(config).then(function onAdapterResolution(response) {
4925
5082
  throwIfCancellationRequested(config);
@@ -4953,7 +5110,7 @@ function dispatchRequest(config) {
4953
5110
  });
4954
5111
  }
4955
5112
 
4956
- const VERSION = "1.11.0";
5113
+ const VERSION = "1.13.2";
4957
5114
 
4958
5115
  const validators$1 = {};
4959
5116
 
@@ -5209,8 +5366,6 @@ class Axios {
5209
5366
 
5210
5367
  let newConfig = config;
5211
5368
 
5212
- i = 0;
5213
-
5214
5369
  while (i < len) {
5215
5370
  const onFulfilled = requestInterceptorChain[i++];
5216
5371
  const onRejected = requestInterceptorChain[i++];
@@ -5514,6 +5669,12 @@ const HttpStatusCode = {
5514
5669
  LoopDetected: 508,
5515
5670
  NotExtended: 510,
5516
5671
  NetworkAuthenticationRequired: 511,
5672
+ WebServerIsDown: 521,
5673
+ ConnectionTimedOut: 522,
5674
+ OriginIsUnreachable: 523,
5675
+ TimeoutOccurred: 524,
5676
+ SslHandshakeFailed: 525,
5677
+ InvalidSslCertificate: 526,
5517
5678
  };
5518
5679
 
5519
5680
  Object.entries(HttpStatusCode).forEach(([key, value]) => {