@passkeyme/auth 2.0.9 → 2.0.11

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
  }
@@ -1827,6 +1831,13 @@ function createAuth(config) {
1827
1831
  return new PasskeymeAuth(config);
1828
1832
  }
1829
1833
 
1834
+ /**
1835
+ * Create a bound version of a function with a specified `this` context
1836
+ *
1837
+ * @param {Function} fn - The function to bind
1838
+ * @param {*} thisArg - The value to be passed as the `this` parameter
1839
+ * @returns {Function} A new function that will call the original function with the specified `this` context
1840
+ */
1830
1841
  function bind(fn, thisArg) {
1831
1842
  return function wrap() {
1832
1843
  return fn.apply(thisArg, arguments);
@@ -1878,7 +1889,7 @@ const isUndefined = typeOfTest('undefined');
1878
1889
  */
1879
1890
  function isBuffer(val) {
1880
1891
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
1881
- && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
1892
+ && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
1882
1893
  }
1883
1894
 
1884
1895
  /**
@@ -1923,7 +1934,7 @@ const isString = typeOfTest('string');
1923
1934
  * @param {*} val The value to test
1924
1935
  * @returns {boolean} True if value is a Function, otherwise false
1925
1936
  */
1926
- const isFunction = typeOfTest('function');
1937
+ const isFunction$1 = typeOfTest('function');
1927
1938
 
1928
1939
  /**
1929
1940
  * Determine if a value is a Number
@@ -1979,7 +1990,7 @@ const isEmptyObject = (val) => {
1979
1990
  if (!isObject(val) || isBuffer(val)) {
1980
1991
  return false;
1981
1992
  }
1982
-
1993
+
1983
1994
  try {
1984
1995
  return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
1985
1996
  } catch (e) {
@@ -2031,7 +2042,7 @@ const isFileList = kindOfTest('FileList');
2031
2042
  *
2032
2043
  * @returns {boolean} True if value is a Stream, otherwise false
2033
2044
  */
2034
- const isStream = (val) => isObject(val) && isFunction(val.pipe);
2045
+ const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
2035
2046
 
2036
2047
  /**
2037
2048
  * Determine if a value is a FormData
@@ -2044,10 +2055,10 @@ const isFormData = (thing) => {
2044
2055
  let kind;
2045
2056
  return thing && (
2046
2057
  (typeof FormData === 'function' && thing instanceof FormData) || (
2047
- isFunction(thing.append) && (
2058
+ isFunction$1(thing.append) && (
2048
2059
  (kind = kindOf(thing)) === 'formdata' ||
2049
2060
  // detect form-data instance
2050
- (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
2061
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
2051
2062
  )
2052
2063
  )
2053
2064
  )
@@ -2172,7 +2183,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
2172
2183
  * @returns {Object} Result of all merge properties
2173
2184
  */
2174
2185
  function merge(/* obj1, obj2, obj3, ... */) {
2175
- const {caseless} = isContextDefined(this) && this || {};
2186
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
2176
2187
  const result = {};
2177
2188
  const assignValue = (val, key) => {
2178
2189
  const targetKey = caseless && findKey(result, key) || key;
@@ -2182,7 +2193,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
2182
2193
  result[targetKey] = merge({}, val);
2183
2194
  } else if (isArray(val)) {
2184
2195
  result[targetKey] = val.slice();
2185
- } else {
2196
+ } else if (!skipUndefined || !isUndefined(val)) {
2186
2197
  result[targetKey] = val;
2187
2198
  }
2188
2199
  };
@@ -2205,7 +2216,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
2205
2216
  */
2206
2217
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
2207
2218
  forEach(b, (val, key) => {
2208
- if (thisArg && isFunction(val)) {
2219
+ if (thisArg && isFunction$1(val)) {
2209
2220
  a[key] = bind(val, thisArg);
2210
2221
  } else {
2211
2222
  a[key] = val;
@@ -2421,13 +2432,13 @@ const reduceDescriptors = (obj, reducer) => {
2421
2432
  const freezeMethods = (obj) => {
2422
2433
  reduceDescriptors(obj, (descriptor, name) => {
2423
2434
  // skip restricted props in strict mode
2424
- if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
2435
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
2425
2436
  return false;
2426
2437
  }
2427
2438
 
2428
2439
  const value = obj[name];
2429
2440
 
2430
- if (!isFunction(value)) return;
2441
+ if (!isFunction$1(value)) return;
2431
2442
 
2432
2443
  descriptor.enumerable = false;
2433
2444
 
@@ -2464,6 +2475,8 @@ const toFiniteNumber = (value, defaultValue) => {
2464
2475
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
2465
2476
  };
2466
2477
 
2478
+
2479
+
2467
2480
  /**
2468
2481
  * If the thing is a FormData object, return true, otherwise return false.
2469
2482
  *
@@ -2472,7 +2485,7 @@ const toFiniteNumber = (value, defaultValue) => {
2472
2485
  * @returns {boolean}
2473
2486
  */
2474
2487
  function isSpecCompliantForm(thing) {
2475
- return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
2488
+ return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
2476
2489
  }
2477
2490
 
2478
2491
  const toJSONObject = (obj) => {
@@ -2514,7 +2527,7 @@ const toJSONObject = (obj) => {
2514
2527
  const isAsyncFn = kindOfTest('AsyncFunction');
2515
2528
 
2516
2529
  const isThenable = (thing) =>
2517
- thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
2530
+ thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
2518
2531
 
2519
2532
  // original code
2520
2533
  // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
@@ -2538,7 +2551,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
2538
2551
  })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
2539
2552
  })(
2540
2553
  typeof setImmediate === 'function',
2541
- isFunction(_global.postMessage)
2554
+ isFunction$1(_global.postMessage)
2542
2555
  );
2543
2556
 
2544
2557
  const asap = typeof queueMicrotask !== 'undefined' ?
@@ -2547,7 +2560,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
2547
2560
  // *********************
2548
2561
 
2549
2562
 
2550
- const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
2563
+ const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
2551
2564
 
2552
2565
 
2553
2566
  var utils$1 = {
@@ -2571,7 +2584,7 @@ var utils$1 = {
2571
2584
  isFile,
2572
2585
  isBlob,
2573
2586
  isRegExp,
2574
- isFunction,
2587
+ isFunction: isFunction$1,
2575
2588
  isStream,
2576
2589
  isURLSearchParams,
2577
2590
  isTypedArray,
@@ -2697,11 +2710,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
2697
2710
  return prop !== 'isAxiosError';
2698
2711
  });
2699
2712
 
2700
- AxiosError.call(axiosError, error.message, code, config, request, response);
2713
+ const msg = error && error.message ? error.message : 'Error';
2701
2714
 
2702
- axiosError.cause = error;
2715
+ // Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
2716
+ const errCode = code == null && error ? error.code : code;
2717
+ AxiosError.call(axiosError, msg, errCode, config, request, response);
2703
2718
 
2704
- axiosError.name = error.name;
2719
+ // Chain the original error on the standard field; non-enumerable to avoid JSON noise
2720
+ if (error && axiosError.cause == null) {
2721
+ Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
2722
+ }
2723
+
2724
+ axiosError.name = (error && error.name) || 'Error';
2705
2725
 
2706
2726
  customProps && Object.assign(axiosError, customProps);
2707
2727
 
@@ -2992,9 +3012,7 @@ function encode(val) {
2992
3012
  replace(/%3A/gi, ':').
2993
3013
  replace(/%24/g, '$').
2994
3014
  replace(/%2C/gi, ',').
2995
- replace(/%20/g, '+').
2996
- replace(/%5B/gi, '[').
2997
- replace(/%5D/gi, ']');
3015
+ replace(/%20/g, '+');
2998
3016
  }
2999
3017
 
3000
3018
  /**
@@ -3072,7 +3090,7 @@ class InterceptorManager {
3072
3090
  *
3073
3091
  * @param {Number} id The ID that was returned by `use`
3074
3092
  *
3075
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
3093
+ * @returns {void}
3076
3094
  */
3077
3095
  eject(id) {
3078
3096
  if (this.handlers[id]) {
@@ -3399,7 +3417,7 @@ const defaults = {
3399
3417
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
3400
3418
 
3401
3419
  try {
3402
- return JSON.parse(data);
3420
+ return JSON.parse(data, this.parseReviver);
3403
3421
  } catch (e) {
3404
3422
  if (strictJSONParsing) {
3405
3423
  if (e.name === 'SyntaxError') {
@@ -4038,27 +4056,38 @@ var cookies = platform.hasStandardBrowserEnv ?
4038
4056
 
4039
4057
  // Standard browser envs support document.cookie
4040
4058
  {
4041
- write(name, value, expires, path, domain, secure) {
4042
- const cookie = [name + '=' + encodeURIComponent(value)];
4059
+ write(name, value, expires, path, domain, secure, sameSite) {
4060
+ if (typeof document === 'undefined') return;
4043
4061
 
4044
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
4062
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
4045
4063
 
4046
- utils$1.isString(path) && cookie.push('path=' + path);
4047
-
4048
- utils$1.isString(domain) && cookie.push('domain=' + domain);
4049
-
4050
- secure === true && cookie.push('secure');
4064
+ if (utils$1.isNumber(expires)) {
4065
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
4066
+ }
4067
+ if (utils$1.isString(path)) {
4068
+ cookie.push(`path=${path}`);
4069
+ }
4070
+ if (utils$1.isString(domain)) {
4071
+ cookie.push(`domain=${domain}`);
4072
+ }
4073
+ if (secure === true) {
4074
+ cookie.push('secure');
4075
+ }
4076
+ if (utils$1.isString(sameSite)) {
4077
+ cookie.push(`SameSite=${sameSite}`);
4078
+ }
4051
4079
 
4052
4080
  document.cookie = cookie.join('; ');
4053
4081
  },
4054
4082
 
4055
4083
  read(name) {
4056
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
4057
- return (match ? decodeURIComponent(match[3]) : null);
4084
+ if (typeof document === 'undefined') return null;
4085
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
4086
+ return match ? decodeURIComponent(match[1]) : null;
4058
4087
  },
4059
4088
 
4060
4089
  remove(name) {
4061
- this.write(name, '', Date.now() - 86400000);
4090
+ this.write(name, '', Date.now() - 86400000, '/');
4062
4091
  }
4063
4092
  }
4064
4093
 
@@ -4147,11 +4176,11 @@ function mergeConfig(config1, config2) {
4147
4176
  }
4148
4177
 
4149
4178
  // eslint-disable-next-line consistent-return
4150
- function mergeDeepProperties(a, b, prop , caseless) {
4179
+ function mergeDeepProperties(a, b, prop, caseless) {
4151
4180
  if (!utils$1.isUndefined(b)) {
4152
- return getMergedValue(a, b, prop , caseless);
4181
+ return getMergedValue(a, b, prop, caseless);
4153
4182
  } else if (!utils$1.isUndefined(a)) {
4154
- return getMergedValue(undefined, a, prop , caseless);
4183
+ return getMergedValue(undefined, a, prop, caseless);
4155
4184
  }
4156
4185
  }
4157
4186
 
@@ -4209,7 +4238,7 @@ function mergeConfig(config1, config2) {
4209
4238
  socketPath: defaultToConfig2,
4210
4239
  responseEncoding: defaultToConfig2,
4211
4240
  validateStatus: mergeDirectKeys,
4212
- headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
4241
+ headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
4213
4242
  };
4214
4243
 
4215
4244
  utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
@@ -4224,7 +4253,7 @@ function mergeConfig(config1, config2) {
4224
4253
  var resolveConfig = (config) => {
4225
4254
  const newConfig = mergeConfig({}, config);
4226
4255
 
4227
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
4256
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
4228
4257
 
4229
4258
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
4230
4259
 
@@ -4237,17 +4266,21 @@ var resolveConfig = (config) => {
4237
4266
  );
4238
4267
  }
4239
4268
 
4240
- let contentType;
4241
-
4242
4269
  if (utils$1.isFormData(data)) {
4243
4270
  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('; '));
4271
+ headers.setContentType(undefined); // browser handles it
4272
+ } else if (utils$1.isFunction(data.getHeaders)) {
4273
+ // Node.js FormData (like form-data package)
4274
+ const formHeaders = data.getHeaders();
4275
+ // Only set safe headers to avoid overwriting security headers
4276
+ const allowedHeaders = ['content-type', 'content-length'];
4277
+ Object.entries(formHeaders).forEach(([key, val]) => {
4278
+ if (allowedHeaders.includes(key.toLowerCase())) {
4279
+ headers.set(key, val);
4280
+ }
4281
+ });
4249
4282
  }
4250
- }
4283
+ }
4251
4284
 
4252
4285
  // Add xsrf header
4253
4286
  // This is only done if running in a standard browser environment.
@@ -4364,15 +4397,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
4364
4397
  };
4365
4398
 
4366
4399
  // 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;
4400
+ request.onerror = function handleError(event) {
4401
+ // Browsers deliver a ProgressEvent in XHR onerror
4402
+ // (message may be empty; when present, surface it)
4403
+ // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
4404
+ const msg = event && event.message ? event.message : 'Network Error';
4405
+ const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
4406
+ // attach the underlying event for consumers who want details
4407
+ err.event = event || null;
4408
+ reject(err);
4409
+ request = null;
4374
4410
  };
4375
-
4411
+
4376
4412
  // Handle timeout
4377
4413
  request.ontimeout = function handleTimeout() {
4378
4414
  let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
@@ -4588,14 +4624,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
4588
4624
  })
4589
4625
  };
4590
4626
 
4591
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
4592
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
4627
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
4628
+
4629
+ const {isFunction} = utils$1;
4630
+
4631
+ const globalFetchAPI = (({Request, Response}) => ({
4632
+ Request, Response
4633
+ }))(utils$1.global);
4634
+
4635
+ const {
4636
+ ReadableStream: ReadableStream$1, TextEncoder
4637
+ } = utils$1.global;
4593
4638
 
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
4639
 
4600
4640
  const test = (fn, ...args) => {
4601
4641
  try {
@@ -4605,278 +4645,380 @@ const test = (fn, ...args) => {
4605
4645
  }
4606
4646
  };
4607
4647
 
4608
- const supportsRequestStream = isReadableStreamSupported && test(() => {
4609
- let duplexAccessed = false;
4648
+ const factory = (env) => {
4649
+ env = utils$1.merge.call({
4650
+ skipUndefined: true
4651
+ }, globalFetchAPI, env);
4610
4652
 
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');
4653
+ const {fetch: envFetch, Request, Response} = env;
4654
+ const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
4655
+ const isRequestSupported = isFunction(Request);
4656
+ const isResponseSupported = isFunction(Response);
4619
4657
 
4620
- return duplexAccessed && !hasContentType;
4621
- });
4658
+ if (!isFetchSupported) {
4659
+ return false;
4660
+ }
4622
4661
 
4623
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
4662
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
4624
4663
 
4625
- const supportsResponseStream = isReadableStreamSupported &&
4626
- test(() => utils$1.isReadableStream(new Response('').body));
4664
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
4665
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
4666
+ async (str) => new Uint8Array(await new Request(str).arrayBuffer())
4667
+ );
4627
4668
 
4669
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
4670
+ let duplexAccessed = false;
4628
4671
 
4629
- const resolvers = {
4630
- stream: supportsResponseStream && ((res) => res.body)
4631
- };
4672
+ const hasContentType = new Request(platform.origin, {
4673
+ body: new ReadableStream$1(),
4674
+ method: 'POST',
4675
+ get duplex() {
4676
+ duplexAccessed = true;
4677
+ return 'half';
4678
+ },
4679
+ }).headers.has('Content-Type');
4632
4680
 
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
- });
4681
+ return duplexAccessed && !hasContentType;
4639
4682
  });
4640
- })(new Response));
4641
4683
 
4642
- const getBodyLength = async (body) => {
4643
- if (body == null) {
4644
- return 0;
4645
- }
4684
+ const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
4685
+ test(() => utils$1.isReadableStream(new Response('').body));
4646
4686
 
4647
- if(utils$1.isBlob(body)) {
4648
- return body.size;
4649
- }
4687
+ const resolvers = {
4688
+ stream: supportsResponseStream && ((res) => res.body)
4689
+ };
4650
4690
 
4651
- if(utils$1.isSpecCompliantForm(body)) {
4652
- const _request = new Request(platform.origin, {
4653
- method: 'POST',
4654
- body,
4691
+ isFetchSupported && ((() => {
4692
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
4693
+ !resolvers[type] && (resolvers[type] = (res, config) => {
4694
+ let method = res && res[type];
4695
+
4696
+ if (method) {
4697
+ return method.call(res);
4698
+ }
4699
+
4700
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
4701
+ });
4655
4702
  });
4656
- return (await _request.arrayBuffer()).byteLength;
4657
- }
4703
+ })());
4658
4704
 
4659
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
4660
- return body.byteLength;
4661
- }
4705
+ const getBodyLength = async (body) => {
4706
+ if (body == null) {
4707
+ return 0;
4708
+ }
4662
4709
 
4663
- if(utils$1.isURLSearchParams(body)) {
4664
- body = body + '';
4665
- }
4710
+ if (utils$1.isBlob(body)) {
4711
+ return body.size;
4712
+ }
4666
4713
 
4667
- if(utils$1.isString(body)) {
4668
- return (await encodeText(body)).byteLength;
4669
- }
4670
- };
4714
+ if (utils$1.isSpecCompliantForm(body)) {
4715
+ const _request = new Request(platform.origin, {
4716
+ method: 'POST',
4717
+ body,
4718
+ });
4719
+ return (await _request.arrayBuffer()).byteLength;
4720
+ }
4671
4721
 
4672
- const resolveBodyLength = async (headers, body) => {
4673
- const length = utils$1.toFiniteNumber(headers.getContentLength());
4722
+ if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
4723
+ return body.byteLength;
4724
+ }
4674
4725
 
4675
- return length == null ? getBodyLength(body) : length;
4676
- };
4726
+ if (utils$1.isURLSearchParams(body)) {
4727
+ body = body + '';
4728
+ }
4729
+
4730
+ if (utils$1.isString(body)) {
4731
+ return (await encodeText(body)).byteLength;
4732
+ }
4733
+ };
4734
+
4735
+ const resolveBodyLength = async (headers, body) => {
4736
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
4737
+
4738
+ return length == null ? getBodyLength(body) : length;
4739
+ };
4740
+
4741
+ return async (config) => {
4742
+ let {
4743
+ url,
4744
+ method,
4745
+ data,
4746
+ signal,
4747
+ cancelToken,
4748
+ timeout,
4749
+ onDownloadProgress,
4750
+ onUploadProgress,
4751
+ responseType,
4752
+ headers,
4753
+ withCredentials = 'same-origin',
4754
+ fetchOptions
4755
+ } = resolveConfig(config);
4756
+
4757
+ let _fetch = envFetch || fetch;
4677
4758
 
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 && (() => {
4759
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
4760
+
4761
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
4762
+
4763
+ let request = null;
4764
+
4765
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
4701
4766
  composedSignal.unsubscribe();
4702
- });
4767
+ });
4703
4768
 
4704
- let requestContentLength;
4769
+ let requestContentLength;
4705
4770
 
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
- });
4771
+ try {
4772
+ if (
4773
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
4774
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
4775
+ ) {
4776
+ let _request = new Request(url, {
4777
+ method: 'POST',
4778
+ body: data,
4779
+ duplex: "half"
4780
+ });
4716
4781
 
4717
- let contentTypeHeader;
4782
+ let contentTypeHeader;
4718
4783
 
4719
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
4720
- headers.setContentType(contentTypeHeader);
4721
- }
4784
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
4785
+ headers.setContentType(contentTypeHeader);
4786
+ }
4722
4787
 
4723
- if (_request.body) {
4724
- const [onProgress, flush] = progressEventDecorator(
4725
- requestContentLength,
4726
- progressEventReducer(asyncDecorator(onUploadProgress))
4727
- );
4788
+ if (_request.body) {
4789
+ const [onProgress, flush] = progressEventDecorator(
4790
+ requestContentLength,
4791
+ progressEventReducer(asyncDecorator(onUploadProgress))
4792
+ );
4728
4793
 
4729
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
4794
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
4795
+ }
4730
4796
  }
4731
- }
4732
4797
 
4733
- if (!utils$1.isString(withCredentials)) {
4734
- withCredentials = withCredentials ? 'include' : 'omit';
4735
- }
4798
+ if (!utils$1.isString(withCredentials)) {
4799
+ withCredentials = withCredentials ? 'include' : 'omit';
4800
+ }
4736
4801
 
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
- });
4802
+ // Cloudflare Workers throws when credentials are defined
4803
+ // see https://github.com/cloudflare/workerd/issues/902
4804
+ const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
4749
4805
 
4750
- let response = await fetch(request, fetchOptions);
4806
+ const resolvedOptions = {
4807
+ ...fetchOptions,
4808
+ signal: composedSignal,
4809
+ method: method.toUpperCase(),
4810
+ headers: headers.normalize().toJSON(),
4811
+ body: data,
4812
+ duplex: "half",
4813
+ credentials: isCredentialsSupported ? withCredentials : undefined
4814
+ };
4751
4815
 
4752
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
4816
+ request = isRequestSupported && new Request(url, resolvedOptions);
4753
4817
 
4754
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
4755
- const options = {};
4818
+ let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
4756
4819
 
4757
- ['status', 'statusText', 'headers'].forEach(prop => {
4758
- options[prop] = response[prop];
4759
- });
4820
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
4760
4821
 
4761
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
4822
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
4823
+ const options = {};
4762
4824
 
4763
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
4764
- responseContentLength,
4765
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
4766
- ) || [];
4825
+ ['status', 'statusText', 'headers'].forEach(prop => {
4826
+ options[prop] = response[prop];
4827
+ });
4767
4828
 
4768
- response = new Response(
4769
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
4770
- flush && flush();
4771
- unsubscribe && unsubscribe();
4772
- }),
4773
- options
4774
- );
4775
- }
4829
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
4776
4830
 
4777
- responseType = responseType || 'text';
4831
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
4832
+ responseContentLength,
4833
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
4834
+ ) || [];
4778
4835
 
4779
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
4836
+ response = new Response(
4837
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
4838
+ flush && flush();
4839
+ unsubscribe && unsubscribe();
4840
+ }),
4841
+ options
4842
+ );
4843
+ }
4780
4844
 
4781
- !isStreamResponse && unsubscribe && unsubscribe();
4845
+ responseType = responseType || 'text';
4782
4846
 
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
- )
4847
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
4848
+
4849
+ !isStreamResponse && unsubscribe && unsubscribe();
4850
+
4851
+ return await new Promise((resolve, reject) => {
4852
+ settle(resolve, reject, {
4853
+ data: responseData,
4854
+ headers: AxiosHeaders$1.from(response.headers),
4855
+ status: response.status,
4856
+ statusText: response.statusText,
4857
+ config,
4858
+ request
4859
+ });
4860
+ })
4861
+ } catch (err) {
4862
+ unsubscribe && unsubscribe();
4863
+
4864
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
4865
+ throw Object.assign(
4866
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
4867
+ {
4868
+ cause: err.cause || err
4869
+ }
4870
+ )
4871
+ }
4872
+
4873
+ throw AxiosError.from(err, err && err.code, config, request);
4803
4874
  }
4875
+ }
4876
+ };
4877
+
4878
+ const seedCache = new Map();
4879
+
4880
+ const getFetch = (config) => {
4881
+ let env = (config && config.env) || {};
4882
+ const {fetch, Request, Response} = env;
4883
+ const seeds = [
4884
+ Request, Response, fetch
4885
+ ];
4886
+
4887
+ let len = seeds.length, i = len,
4888
+ seed, target, map = seedCache;
4889
+
4890
+ while (i--) {
4891
+ seed = seeds[i];
4892
+ target = map.get(seed);
4893
+
4894
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
4804
4895
 
4805
- throw AxiosError.from(err, err && err.code, config, request);
4896
+ map = target;
4806
4897
  }
4807
- });
4808
4898
 
4899
+ return target;
4900
+ };
4901
+
4902
+ getFetch();
4903
+
4904
+ /**
4905
+ * Known adapters mapping.
4906
+ * Provides environment-specific adapters for Axios:
4907
+ * - `http` for Node.js
4908
+ * - `xhr` for browsers
4909
+ * - `fetch` for fetch API-based requests
4910
+ *
4911
+ * @type {Object<string, Function|Object>}
4912
+ */
4809
4913
  const knownAdapters = {
4810
4914
  http: httpAdapter,
4811
4915
  xhr: xhrAdapter,
4812
- fetch: fetchAdapter
4916
+ fetch: {
4917
+ get: getFetch,
4918
+ }
4813
4919
  };
4814
4920
 
4921
+ // Assign adapter names for easier debugging and identification
4815
4922
  utils$1.forEach(knownAdapters, (fn, value) => {
4816
4923
  if (fn) {
4817
4924
  try {
4818
- Object.defineProperty(fn, 'name', {value});
4925
+ Object.defineProperty(fn, 'name', { value });
4819
4926
  } catch (e) {
4820
4927
  // eslint-disable-next-line no-empty
4821
4928
  }
4822
- Object.defineProperty(fn, 'adapterName', {value});
4929
+ Object.defineProperty(fn, 'adapterName', { value });
4823
4930
  }
4824
4931
  });
4825
4932
 
4933
+ /**
4934
+ * Render a rejection reason string for unknown or unsupported adapters
4935
+ *
4936
+ * @param {string} reason
4937
+ * @returns {string}
4938
+ */
4826
4939
  const renderReason = (reason) => `- ${reason}`;
4827
4940
 
4941
+ /**
4942
+ * Check if the adapter is resolved (function, null, or false)
4943
+ *
4944
+ * @param {Function|null|false} adapter
4945
+ * @returns {boolean}
4946
+ */
4828
4947
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
4829
4948
 
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;
4949
+ /**
4950
+ * Get the first suitable adapter from the provided list.
4951
+ * Tries each adapter in order until a supported one is found.
4952
+ * Throws an AxiosError if no adapter is suitable.
4953
+ *
4954
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
4955
+ * @param {Object} config - Axios request configuration
4956
+ * @throws {AxiosError} If no suitable adapter is available
4957
+ * @returns {Function} The resolved adapter function
4958
+ */
4959
+ function getAdapter(adapters, config) {
4960
+ adapters = utils$1.isArray(adapters) ? adapters : [adapters];
4837
4961
 
4838
- const rejectedReasons = {};
4962
+ const { length } = adapters;
4963
+ let nameOrAdapter;
4964
+ let adapter;
4839
4965
 
4840
- for (let i = 0; i < length; i++) {
4841
- nameOrAdapter = adapters[i];
4842
- let id;
4966
+ const rejectedReasons = {};
4843
4967
 
4844
- adapter = nameOrAdapter;
4968
+ for (let i = 0; i < length; i++) {
4969
+ nameOrAdapter = adapters[i];
4970
+ let id;
4845
4971
 
4846
- if (!isResolvedHandle(nameOrAdapter)) {
4847
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
4972
+ adapter = nameOrAdapter;
4848
4973
 
4849
- if (adapter === undefined) {
4850
- throw new AxiosError(`Unknown adapter '${id}'`);
4851
- }
4852
- }
4974
+ if (!isResolvedHandle(nameOrAdapter)) {
4975
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
4853
4976
 
4854
- if (adapter) {
4855
- break;
4977
+ if (adapter === undefined) {
4978
+ throw new AxiosError(`Unknown adapter '${id}'`);
4856
4979
  }
4980
+ }
4857
4981
 
4858
- rejectedReasons[id || '#' + i] = adapter;
4982
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
4983
+ break;
4859
4984
  }
4860
4985
 
4861
- if (!adapter) {
4986
+ rejectedReasons[id || '#' + i] = adapter;
4987
+ }
4862
4988
 
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
- );
4989
+ if (!adapter) {
4990
+ const reasons = Object.entries(rejectedReasons)
4991
+ .map(([id, state]) => `adapter ${id} ` +
4992
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
4993
+ );
4867
4994
 
4868
- let s = length ?
4869
- (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
4870
- 'as no adapter specified';
4995
+ let s = length ?
4996
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
4997
+ 'as no adapter specified';
4871
4998
 
4872
- throw new AxiosError(
4873
- `There is no suitable adapter to dispatch the request ` + s,
4874
- 'ERR_NOT_SUPPORT'
4875
- );
4876
- }
4999
+ throw new AxiosError(
5000
+ `There is no suitable adapter to dispatch the request ` + s,
5001
+ 'ERR_NOT_SUPPORT'
5002
+ );
5003
+ }
4877
5004
 
4878
- return adapter;
4879
- },
5005
+ return adapter;
5006
+ }
5007
+
5008
+ /**
5009
+ * Exports Axios adapters and utility to resolve an adapter
5010
+ */
5011
+ var adapters = {
5012
+ /**
5013
+ * Resolve an adapter from a list of adapter names or functions.
5014
+ * @type {Function}
5015
+ */
5016
+ getAdapter,
5017
+
5018
+ /**
5019
+ * Exposes all known adapters
5020
+ * @type {Object<string, Function|Object>}
5021
+ */
4880
5022
  adapters: knownAdapters
4881
5023
  };
4882
5024
 
@@ -4919,7 +5061,7 @@ function dispatchRequest(config) {
4919
5061
  config.headers.setContentType('application/x-www-form-urlencoded', false);
4920
5062
  }
4921
5063
 
4922
- const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
5064
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
4923
5065
 
4924
5066
  return adapter(config).then(function onAdapterResolution(response) {
4925
5067
  throwIfCancellationRequested(config);
@@ -4953,7 +5095,7 @@ function dispatchRequest(config) {
4953
5095
  });
4954
5096
  }
4955
5097
 
4956
- const VERSION = "1.11.0";
5098
+ const VERSION = "1.13.2";
4957
5099
 
4958
5100
  const validators$1 = {};
4959
5101
 
@@ -5209,8 +5351,6 @@ class Axios {
5209
5351
 
5210
5352
  let newConfig = config;
5211
5353
 
5212
- i = 0;
5213
-
5214
5354
  while (i < len) {
5215
5355
  const onFulfilled = requestInterceptorChain[i++];
5216
5356
  const onRejected = requestInterceptorChain[i++];
@@ -5514,6 +5654,12 @@ const HttpStatusCode = {
5514
5654
  LoopDetected: 508,
5515
5655
  NotExtended: 510,
5516
5656
  NetworkAuthenticationRequired: 511,
5657
+ WebServerIsDown: 521,
5658
+ ConnectionTimedOut: 522,
5659
+ OriginIsUnreachable: 523,
5660
+ TimeoutOccurred: 524,
5661
+ SslHandshakeFailed: 525,
5662
+ InvalidSslCertificate: 526,
5517
5663
  };
5518
5664
 
5519
5665
  Object.entries(HttpStatusCode).forEach(([key, value]) => {