@tryghost/content-api 1.11.21 → 1.11.22

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/es/content-api.js CHANGED
@@ -211,6 +211,8 @@ const isFormData = (thing) => {
211
211
  */
212
212
  const isURLSearchParams = kindOfTest('URLSearchParams');
213
213
 
214
+ const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
215
+
214
216
  /**
215
217
  * Trim excess whitespace off the beginning and end of a string
216
218
  *
@@ -599,28 +601,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
599
601
  const noop = () => {};
600
602
 
601
603
  const toFiniteNumber = (value, defaultValue) => {
602
- value = +value;
603
- return Number.isFinite(value) ? value : defaultValue;
604
- };
605
-
606
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
607
-
608
- const DIGIT = '0123456789';
609
-
610
- const ALPHABET = {
611
- DIGIT,
612
- ALPHA,
613
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
614
- };
615
-
616
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
617
- let str = '';
618
- const {length} = alphabet;
619
- while (size--) {
620
- str += alphabet[Math.random() * length|0];
621
- }
622
-
623
- return str;
604
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
624
605
  };
625
606
 
626
607
  /**
@@ -670,6 +651,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
670
651
  const isThenable = (thing) =>
671
652
  thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
672
653
 
654
+ // original code
655
+ // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
656
+
657
+ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
658
+ if (setImmediateSupported) {
659
+ return setImmediate;
660
+ }
661
+
662
+ return postMessageSupported ? ((token, callbacks) => {
663
+ _global.addEventListener("message", ({source, data}) => {
664
+ if (source === _global && data === token) {
665
+ callbacks.length && callbacks.shift()();
666
+ }
667
+ }, false);
668
+
669
+ return (cb) => {
670
+ callbacks.push(cb);
671
+ _global.postMessage(token, "*");
672
+ }
673
+ })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
674
+ })(
675
+ typeof setImmediate === 'function',
676
+ isFunction(_global.postMessage)
677
+ );
678
+
679
+ const asap = typeof queueMicrotask !== 'undefined' ?
680
+ queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
681
+
682
+ // *********************
683
+
673
684
  var utils$1 = {
674
685
  isArray,
675
686
  isArrayBuffer,
@@ -681,6 +692,10 @@ var utils$1 = {
681
692
  isBoolean,
682
693
  isObject,
683
694
  isPlainObject,
695
+ isReadableStream,
696
+ isRequest,
697
+ isResponse,
698
+ isHeaders,
684
699
  isUndefined,
685
700
  isDate,
686
701
  isFile,
@@ -716,12 +731,12 @@ var utils$1 = {
716
731
  findKey,
717
732
  global: _global,
718
733
  isContextDefined,
719
- ALPHABET,
720
- generateString,
721
734
  isSpecCompliantForm,
722
735
  toJSONObject,
723
736
  isAsyncFn,
724
- isThenable
737
+ isThenable,
738
+ setImmediate: _setImmediate,
739
+ asap
725
740
  };
726
741
 
727
742
  /**
@@ -749,7 +764,10 @@ function AxiosError(message, code, config, request, response) {
749
764
  code && (this.code = code);
750
765
  config && (this.config = config);
751
766
  request && (this.request = request);
752
- response && (this.response = response);
767
+ if (response) {
768
+ this.response = response;
769
+ this.status = response.status ? response.status : null;
770
+ }
753
771
  }
754
772
 
755
773
  utils$1.inherits(AxiosError, Error, {
@@ -769,7 +787,7 @@ utils$1.inherits(AxiosError, Error, {
769
787
  // Axios
770
788
  config: utils$1.toJSONObject(this.config),
771
789
  code: this.code,
772
- status: this.response && this.response.status ? this.response.status : null
790
+ status: this.status
773
791
  };
774
792
  }
775
793
  });
@@ -1109,7 +1127,7 @@ function encode(val) {
1109
1127
  *
1110
1128
  * @param {string} url The base of the url (e.g., http://www.google.com)
1111
1129
  * @param {object} [params] The params to be appended
1112
- * @param {?object} options
1130
+ * @param {?(object|Function)} options
1113
1131
  *
1114
1132
  * @returns {string} The formatted url
1115
1133
  */
@@ -1121,6 +1139,12 @@ function buildURL(url, params, options) {
1121
1139
 
1122
1140
  const _encode = options && options.encode || encode;
1123
1141
 
1142
+ if (utils$1.isFunction(options)) {
1143
+ options = {
1144
+ serialize: options
1145
+ };
1146
+ }
1147
+
1124
1148
  const serializeFn = options && options.serialize;
1125
1149
 
1126
1150
  let serializedParams;
@@ -1237,6 +1261,8 @@ var platform$1 = {
1237
1261
 
1238
1262
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1239
1263
 
1264
+ const _navigator = typeof navigator === 'object' && navigator || undefined;
1265
+
1240
1266
  /**
1241
1267
  * Determine if we're running in a standard browser environment
1242
1268
  *
@@ -1254,10 +1280,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
1254
1280
  *
1255
1281
  * @returns {boolean}
1256
1282
  */
1257
- const hasStandardBrowserEnv = (
1258
- (product) => {
1259
- return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
1260
- })(typeof navigator !== 'undefined' && navigator.product);
1283
+ const hasStandardBrowserEnv = hasBrowserEnv &&
1284
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
1261
1285
 
1262
1286
  /**
1263
1287
  * Determine if we're running in a standard browser webWorker environment
@@ -1277,11 +1301,15 @@ const hasStandardBrowserWebWorkerEnv = (() => {
1277
1301
  );
1278
1302
  })();
1279
1303
 
1304
+ const origin = hasBrowserEnv && window.location.href || 'http://localhost';
1305
+
1280
1306
  var utils = /*#__PURE__*/Object.freeze({
1281
1307
  __proto__: null,
1282
1308
  hasBrowserEnv: hasBrowserEnv,
1283
1309
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1284
- hasStandardBrowserEnv: hasStandardBrowserEnv
1310
+ hasStandardBrowserEnv: hasStandardBrowserEnv,
1311
+ navigator: _navigator,
1312
+ origin: origin
1285
1313
  });
1286
1314
 
1287
1315
  var platform = {
@@ -1421,7 +1449,7 @@ const defaults = {
1421
1449
 
1422
1450
  transitional: transitionalDefaults,
1423
1451
 
1424
- adapter: ['xhr', 'http'],
1452
+ adapter: ['xhr', 'http', 'fetch'],
1425
1453
 
1426
1454
  transformRequest: [function transformRequest(data, headers) {
1427
1455
  const contentType = headers.getContentType() || '';
@@ -1442,7 +1470,8 @@ const defaults = {
1442
1470
  utils$1.isBuffer(data) ||
1443
1471
  utils$1.isStream(data) ||
1444
1472
  utils$1.isFile(data) ||
1445
- utils$1.isBlob(data)
1473
+ utils$1.isBlob(data) ||
1474
+ utils$1.isReadableStream(data)
1446
1475
  ) {
1447
1476
  return data;
1448
1477
  }
@@ -1485,6 +1514,10 @@ const defaults = {
1485
1514
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1486
1515
  const JSONRequested = this.responseType === 'json';
1487
1516
 
1517
+ if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
1518
+ return data;
1519
+ }
1520
+
1488
1521
  if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1489
1522
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
1490
1523
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
@@ -1688,6 +1721,10 @@ class AxiosHeaders {
1688
1721
  setHeaders(header, valueOrRewrite);
1689
1722
  } else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1690
1723
  setHeaders(parseHeaders(header), valueOrRewrite);
1724
+ } else if (utils$1.isHeaders(header)) {
1725
+ for (const [key, value] of header.entries()) {
1726
+ setHeader(value, key, rewrite);
1727
+ }
1691
1728
  } else {
1692
1729
  header != null && setHeader(valueOrRewrite, header, rewrite);
1693
1730
  }
@@ -1955,6 +1992,160 @@ function settle(resolve, reject, response) {
1955
1992
  }
1956
1993
  }
1957
1994
 
1995
+ function parseProtocol(url) {
1996
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1997
+ return match && match[1] || '';
1998
+ }
1999
+
2000
+ /**
2001
+ * Calculate data maxRate
2002
+ * @param {Number} [samplesCount= 10]
2003
+ * @param {Number} [min= 1000]
2004
+ * @returns {Function}
2005
+ */
2006
+ function speedometer(samplesCount, min) {
2007
+ samplesCount = samplesCount || 10;
2008
+ const bytes = new Array(samplesCount);
2009
+ const timestamps = new Array(samplesCount);
2010
+ let head = 0;
2011
+ let tail = 0;
2012
+ let firstSampleTS;
2013
+
2014
+ min = min !== undefined ? min : 1000;
2015
+
2016
+ return function push(chunkLength) {
2017
+ const now = Date.now();
2018
+
2019
+ const startedAt = timestamps[tail];
2020
+
2021
+ if (!firstSampleTS) {
2022
+ firstSampleTS = now;
2023
+ }
2024
+
2025
+ bytes[head] = chunkLength;
2026
+ timestamps[head] = now;
2027
+
2028
+ let i = tail;
2029
+ let bytesCount = 0;
2030
+
2031
+ while (i !== head) {
2032
+ bytesCount += bytes[i++];
2033
+ i = i % samplesCount;
2034
+ }
2035
+
2036
+ head = (head + 1) % samplesCount;
2037
+
2038
+ if (head === tail) {
2039
+ tail = (tail + 1) % samplesCount;
2040
+ }
2041
+
2042
+ if (now - firstSampleTS < min) {
2043
+ return;
2044
+ }
2045
+
2046
+ const passed = startedAt && now - startedAt;
2047
+
2048
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2049
+ };
2050
+ }
2051
+
2052
+ /**
2053
+ * Throttle decorator
2054
+ * @param {Function} fn
2055
+ * @param {Number} freq
2056
+ * @return {Function}
2057
+ */
2058
+ function throttle(fn, freq) {
2059
+ let timestamp = 0;
2060
+ let threshold = 1000 / freq;
2061
+ let lastArgs;
2062
+ let timer;
2063
+
2064
+ const invoke = (args, now = Date.now()) => {
2065
+ timestamp = now;
2066
+ lastArgs = null;
2067
+ if (timer) {
2068
+ clearTimeout(timer);
2069
+ timer = null;
2070
+ }
2071
+ fn.apply(null, args);
2072
+ };
2073
+
2074
+ const throttled = (...args) => {
2075
+ const now = Date.now();
2076
+ const passed = now - timestamp;
2077
+ if ( passed >= threshold) {
2078
+ invoke(args, now);
2079
+ } else {
2080
+ lastArgs = args;
2081
+ if (!timer) {
2082
+ timer = setTimeout(() => {
2083
+ timer = null;
2084
+ invoke(lastArgs);
2085
+ }, threshold - passed);
2086
+ }
2087
+ }
2088
+ };
2089
+
2090
+ const flush = () => lastArgs && invoke(lastArgs);
2091
+
2092
+ return [throttled, flush];
2093
+ }
2094
+
2095
+ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2096
+ let bytesNotified = 0;
2097
+ const _speedometer = speedometer(50, 250);
2098
+
2099
+ return throttle(e => {
2100
+ const loaded = e.loaded;
2101
+ const total = e.lengthComputable ? e.total : undefined;
2102
+ const progressBytes = loaded - bytesNotified;
2103
+ const rate = _speedometer(progressBytes);
2104
+ const inRange = loaded <= total;
2105
+
2106
+ bytesNotified = loaded;
2107
+
2108
+ const data = {
2109
+ loaded,
2110
+ total,
2111
+ progress: total ? (loaded / total) : undefined,
2112
+ bytes: progressBytes,
2113
+ rate: rate ? rate : undefined,
2114
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2115
+ event: e,
2116
+ lengthComputable: total != null,
2117
+ [isDownloadStream ? 'download' : 'upload']: true
2118
+ };
2119
+
2120
+ listener(data);
2121
+ }, freq);
2122
+ };
2123
+
2124
+ const progressEventDecorator = (total, throttled) => {
2125
+ const lengthComputable = total != null;
2126
+
2127
+ return [(loaded) => throttled[0]({
2128
+ lengthComputable,
2129
+ total,
2130
+ loaded
2131
+ }), throttled[1]];
2132
+ };
2133
+
2134
+ const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
2135
+
2136
+ var isURLSameOrigin = platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => {
2137
+ url = new URL(url, platform.origin);
2138
+
2139
+ return (
2140
+ origin.protocol === url.protocol &&
2141
+ origin.host === url.host &&
2142
+ (isMSIE || origin.port === url.port)
2143
+ );
2144
+ })(
2145
+ new URL(platform.origin),
2146
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
2147
+ ) : () => true;
2148
+
1958
2149
  var cookies = platform.hasStandardBrowserEnv ?
1959
2150
 
1960
2151
  // Standard browser envs support document.cookie
@@ -2032,207 +2223,191 @@ function combineURLs(baseURL, relativeURL) {
2032
2223
  *
2033
2224
  * @returns {string} The combined full path
2034
2225
  */
2035
- function buildFullPath(baseURL, requestedURL) {
2036
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2226
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2227
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2228
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
2037
2229
  return combineURLs(baseURL, requestedURL);
2038
2230
  }
2039
2231
  return requestedURL;
2040
2232
  }
2041
2233
 
2042
- var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2043
-
2044
- // Standard browser envs have full support of the APIs needed to test
2045
- // whether the request URL is of the same origin as current location.
2046
- (function standardBrowserEnv() {
2047
- const msie = /(msie|trident)/i.test(navigator.userAgent);
2048
- const urlParsingNode = document.createElement('a');
2049
- let originURL;
2050
-
2051
- /**
2052
- * Parse a URL to discover its components
2053
- *
2054
- * @param {String} url The URL to be parsed
2055
- * @returns {Object}
2056
- */
2057
- function resolveURL(url) {
2058
- let href = url;
2059
-
2060
- if (msie) {
2061
- // IE needs attribute set twice to normalize properties
2062
- urlParsingNode.setAttribute('href', href);
2063
- href = urlParsingNode.href;
2064
- }
2234
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
2065
2235
 
2066
- urlParsingNode.setAttribute('href', href);
2067
-
2068
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2069
- return {
2070
- href: urlParsingNode.href,
2071
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2072
- host: urlParsingNode.host,
2073
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2074
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2075
- hostname: urlParsingNode.hostname,
2076
- port: urlParsingNode.port,
2077
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
2078
- urlParsingNode.pathname :
2079
- '/' + urlParsingNode.pathname
2080
- };
2236
+ /**
2237
+ * Config-specific merge-function which creates a new config-object
2238
+ * by merging two configuration objects together.
2239
+ *
2240
+ * @param {Object} config1
2241
+ * @param {Object} config2
2242
+ *
2243
+ * @returns {Object} New object resulting from merging config2 to config1
2244
+ */
2245
+ function mergeConfig(config1, config2) {
2246
+ // eslint-disable-next-line no-param-reassign
2247
+ config2 = config2 || {};
2248
+ const config = {};
2249
+
2250
+ function getMergedValue(target, source, prop, caseless) {
2251
+ if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2252
+ return utils$1.merge.call({caseless}, target, source);
2253
+ } else if (utils$1.isPlainObject(source)) {
2254
+ return utils$1.merge({}, source);
2255
+ } else if (utils$1.isArray(source)) {
2256
+ return source.slice();
2257
+ }
2258
+ return source;
2259
+ }
2260
+
2261
+ // eslint-disable-next-line consistent-return
2262
+ function mergeDeepProperties(a, b, prop , caseless) {
2263
+ if (!utils$1.isUndefined(b)) {
2264
+ return getMergedValue(a, b, prop , caseless);
2265
+ } else if (!utils$1.isUndefined(a)) {
2266
+ return getMergedValue(undefined, a, prop , caseless);
2081
2267
  }
2268
+ }
2082
2269
 
2083
- originURL = resolveURL(window.location.href);
2270
+ // eslint-disable-next-line consistent-return
2271
+ function valueFromConfig2(a, b) {
2272
+ if (!utils$1.isUndefined(b)) {
2273
+ return getMergedValue(undefined, b);
2274
+ }
2275
+ }
2084
2276
 
2085
- /**
2086
- * Determine if a URL shares the same origin as the current location
2087
- *
2088
- * @param {String} requestURL The URL to test
2089
- * @returns {boolean} True if URL shares the same origin, otherwise false
2090
- */
2091
- return function isURLSameOrigin(requestURL) {
2092
- const parsed = (utils$1.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2093
- return (parsed.protocol === originURL.protocol &&
2094
- parsed.host === originURL.host);
2095
- };
2096
- })() :
2277
+ // eslint-disable-next-line consistent-return
2278
+ function defaultToConfig2(a, b) {
2279
+ if (!utils$1.isUndefined(b)) {
2280
+ return getMergedValue(undefined, b);
2281
+ } else if (!utils$1.isUndefined(a)) {
2282
+ return getMergedValue(undefined, a);
2283
+ }
2284
+ }
2097
2285
 
2098
- // Non standard browser envs (web workers, react-native) lack needed support.
2099
- (function nonStandardBrowserEnv() {
2100
- return function isURLSameOrigin() {
2101
- return true;
2102
- };
2103
- })();
2286
+ // eslint-disable-next-line consistent-return
2287
+ function mergeDirectKeys(a, b, prop) {
2288
+ if (prop in config2) {
2289
+ return getMergedValue(a, b);
2290
+ } else if (prop in config1) {
2291
+ return getMergedValue(undefined, a);
2292
+ }
2293
+ }
2104
2294
 
2105
- function parseProtocol(url) {
2106
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2107
- return match && match[1] || '';
2295
+ const mergeMap = {
2296
+ url: valueFromConfig2,
2297
+ method: valueFromConfig2,
2298
+ data: valueFromConfig2,
2299
+ baseURL: defaultToConfig2,
2300
+ transformRequest: defaultToConfig2,
2301
+ transformResponse: defaultToConfig2,
2302
+ paramsSerializer: defaultToConfig2,
2303
+ timeout: defaultToConfig2,
2304
+ timeoutMessage: defaultToConfig2,
2305
+ withCredentials: defaultToConfig2,
2306
+ withXSRFToken: defaultToConfig2,
2307
+ adapter: defaultToConfig2,
2308
+ responseType: defaultToConfig2,
2309
+ xsrfCookieName: defaultToConfig2,
2310
+ xsrfHeaderName: defaultToConfig2,
2311
+ onUploadProgress: defaultToConfig2,
2312
+ onDownloadProgress: defaultToConfig2,
2313
+ decompress: defaultToConfig2,
2314
+ maxContentLength: defaultToConfig2,
2315
+ maxBodyLength: defaultToConfig2,
2316
+ beforeRedirect: defaultToConfig2,
2317
+ transport: defaultToConfig2,
2318
+ httpAgent: defaultToConfig2,
2319
+ httpsAgent: defaultToConfig2,
2320
+ cancelToken: defaultToConfig2,
2321
+ socketPath: defaultToConfig2,
2322
+ responseEncoding: defaultToConfig2,
2323
+ validateStatus: mergeDirectKeys,
2324
+ headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2325
+ };
2326
+
2327
+ utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2328
+ const merge = mergeMap[prop] || mergeDeepProperties;
2329
+ const configValue = merge(config1[prop], config2[prop], prop);
2330
+ (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2331
+ });
2332
+
2333
+ return config;
2108
2334
  }
2109
2335
 
2110
- /**
2111
- * Calculate data maxRate
2112
- * @param {Number} [samplesCount= 10]
2113
- * @param {Number} [min= 1000]
2114
- * @returns {Function}
2115
- */
2116
- function speedometer(samplesCount, min) {
2117
- samplesCount = samplesCount || 10;
2118
- const bytes = new Array(samplesCount);
2119
- const timestamps = new Array(samplesCount);
2120
- let head = 0;
2121
- let tail = 0;
2122
- let firstSampleTS;
2336
+ var resolveConfig = (config) => {
2337
+ const newConfig = mergeConfig({}, config);
2123
2338
 
2124
- min = min !== undefined ? min : 1000;
2339
+ let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2125
2340
 
2126
- return function push(chunkLength) {
2127
- const now = Date.now();
2341
+ newConfig.headers = headers = AxiosHeaders$1.from(headers);
2128
2342
 
2129
- const startedAt = timestamps[tail];
2343
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2130
2344
 
2131
- if (!firstSampleTS) {
2132
- firstSampleTS = now;
2345
+ // HTTP basic authentication
2346
+ if (auth) {
2347
+ headers.set('Authorization', 'Basic ' +
2348
+ btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
2349
+ );
2350
+ }
2351
+
2352
+ let contentType;
2353
+
2354
+ if (utils$1.isFormData(data)) {
2355
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2356
+ headers.setContentType(undefined); // Let the browser set it
2357
+ } else if ((contentType = headers.getContentType()) !== false) {
2358
+ // fix semicolon duplication issue for ReactNative FormData implementation
2359
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2360
+ headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2133
2361
  }
2362
+ }
2134
2363
 
2135
- bytes[head] = chunkLength;
2136
- timestamps[head] = now;
2364
+ // Add xsrf header
2365
+ // This is only done if running in a standard browser environment.
2366
+ // Specifically not if we're in a web worker, or react-native.
2137
2367
 
2138
- let i = tail;
2139
- let bytesCount = 0;
2368
+ if (platform.hasStandardBrowserEnv) {
2369
+ withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
2140
2370
 
2141
- while (i !== head) {
2142
- bytesCount += bytes[i++];
2143
- i = i % samplesCount;
2144
- }
2145
-
2146
- head = (head + 1) % samplesCount;
2371
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
2372
+ // Add xsrf header
2373
+ const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
2147
2374
 
2148
- if (head === tail) {
2149
- tail = (tail + 1) % samplesCount;
2150
- }
2151
-
2152
- if (now - firstSampleTS < min) {
2153
- return;
2375
+ if (xsrfValue) {
2376
+ headers.set(xsrfHeaderName, xsrfValue);
2377
+ }
2154
2378
  }
2379
+ }
2155
2380
 
2156
- const passed = startedAt && now - startedAt;
2157
-
2158
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2159
- };
2160
- }
2161
-
2162
- function progressEventReducer(listener, isDownloadStream) {
2163
- let bytesNotified = 0;
2164
- const _speedometer = speedometer(50, 250);
2165
-
2166
- return e => {
2167
- const loaded = e.loaded;
2168
- const total = e.lengthComputable ? e.total : undefined;
2169
- const progressBytes = loaded - bytesNotified;
2170
- const rate = _speedometer(progressBytes);
2171
- const inRange = loaded <= total;
2172
-
2173
- bytesNotified = loaded;
2174
-
2175
- const data = {
2176
- loaded,
2177
- total,
2178
- progress: total ? (loaded / total) : undefined,
2179
- bytes: progressBytes,
2180
- rate: rate ? rate : undefined,
2181
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2182
- event: e
2183
- };
2184
-
2185
- data[isDownloadStream ? 'download' : 'upload'] = true;
2186
-
2187
- listener(data);
2188
- };
2189
- }
2381
+ return newConfig;
2382
+ };
2190
2383
 
2191
2384
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2192
2385
 
2193
2386
  var xhrAdapter = isXHRAdapterSupported && function (config) {
2194
2387
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2195
- let requestData = config.data;
2196
- const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
2197
- let {responseType, withXSRFToken} = config;
2388
+ const _config = resolveConfig(config);
2389
+ let requestData = _config.data;
2390
+ const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
2391
+ let {responseType, onUploadProgress, onDownloadProgress} = _config;
2198
2392
  let onCanceled;
2199
- function done() {
2200
- if (config.cancelToken) {
2201
- config.cancelToken.unsubscribe(onCanceled);
2202
- }
2393
+ let uploadThrottled, downloadThrottled;
2394
+ let flushUpload, flushDownload;
2203
2395
 
2204
- if (config.signal) {
2205
- config.signal.removeEventListener('abort', onCanceled);
2206
- }
2207
- }
2396
+ function done() {
2397
+ flushUpload && flushUpload(); // flush events
2398
+ flushDownload && flushDownload(); // flush events
2208
2399
 
2209
- let contentType;
2400
+ _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
2210
2401
 
2211
- if (utils$1.isFormData(requestData)) {
2212
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2213
- requestHeaders.setContentType(false); // Let the browser set it
2214
- } else if ((contentType = requestHeaders.getContentType()) !== false) {
2215
- // fix semicolon duplication issue for ReactNative FormData implementation
2216
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2217
- requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2218
- }
2402
+ _config.signal && _config.signal.removeEventListener('abort', onCanceled);
2219
2403
  }
2220
2404
 
2221
2405
  let request = new XMLHttpRequest();
2222
2406
 
2223
- // HTTP basic authentication
2224
- if (config.auth) {
2225
- const username = config.auth.username || '';
2226
- const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
2227
- requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
2228
- }
2229
-
2230
- const fullPath = buildFullPath(config.baseURL, config.url);
2231
-
2232
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
2407
+ request.open(_config.method.toUpperCase(), _config.url, true);
2233
2408
 
2234
2409
  // Set the request timeout in MS
2235
- request.timeout = config.timeout;
2410
+ request.timeout = _config.timeout;
2236
2411
 
2237
2412
  function onloadend() {
2238
2413
  if (!request) {
@@ -2312,10 +2487,10 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2312
2487
 
2313
2488
  // Handle timeout
2314
2489
  request.ontimeout = function handleTimeout() {
2315
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
2316
- const transitional = config.transitional || transitionalDefaults;
2317
- if (config.timeoutErrorMessage) {
2318
- timeoutErrorMessage = config.timeoutErrorMessage;
2490
+ let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
2491
+ const transitional = _config.transitional || transitionalDefaults;
2492
+ if (_config.timeoutErrorMessage) {
2493
+ timeoutErrorMessage = _config.timeoutErrorMessage;
2319
2494
  }
2320
2495
  reject(new AxiosError(
2321
2496
  timeoutErrorMessage,
@@ -2327,22 +2502,6 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2327
2502
  request = null;
2328
2503
  };
2329
2504
 
2330
- // Add xsrf header
2331
- // This is only done if running in a standard browser environment.
2332
- // Specifically not if we're in a web worker, or react-native.
2333
- if(platform.hasStandardBrowserEnv) {
2334
- withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
2335
-
2336
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
2337
- // Add xsrf header
2338
- const xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2339
-
2340
- if (xsrfValue) {
2341
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
2342
- }
2343
- }
2344
- }
2345
-
2346
2505
  // Remove Content-Type if data is undefined
2347
2506
  requestData === undefined && requestHeaders.setContentType(null);
2348
2507
 
@@ -2354,26 +2513,31 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2354
2513
  }
2355
2514
 
2356
2515
  // Add withCredentials to request if needed
2357
- if (!utils$1.isUndefined(config.withCredentials)) {
2358
- request.withCredentials = !!config.withCredentials;
2516
+ if (!utils$1.isUndefined(_config.withCredentials)) {
2517
+ request.withCredentials = !!_config.withCredentials;
2359
2518
  }
2360
2519
 
2361
2520
  // Add responseType to request if needed
2362
2521
  if (responseType && responseType !== 'json') {
2363
- request.responseType = config.responseType;
2522
+ request.responseType = _config.responseType;
2364
2523
  }
2365
2524
 
2366
2525
  // Handle progress if needed
2367
- if (typeof config.onDownloadProgress === 'function') {
2368
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
2526
+ if (onDownloadProgress) {
2527
+ ([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
2528
+ request.addEventListener('progress', downloadThrottled);
2369
2529
  }
2370
2530
 
2371
2531
  // Not all browsers support upload events
2372
- if (typeof config.onUploadProgress === 'function' && request.upload) {
2373
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
2532
+ if (onUploadProgress && request.upload) {
2533
+ ([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
2534
+
2535
+ request.upload.addEventListener('progress', uploadThrottled);
2536
+
2537
+ request.upload.addEventListener('loadend', flushUpload);
2374
2538
  }
2375
2539
 
2376
- if (config.cancelToken || config.signal) {
2540
+ if (_config.cancelToken || _config.signal) {
2377
2541
  // Handle cancellation
2378
2542
  // eslint-disable-next-line func-names
2379
2543
  onCanceled = cancel => {
@@ -2385,13 +2549,13 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2385
2549
  request = null;
2386
2550
  };
2387
2551
 
2388
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
2389
- if (config.signal) {
2390
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
2552
+ _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
2553
+ if (_config.signal) {
2554
+ _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
2391
2555
  }
2392
2556
  }
2393
2557
 
2394
- const protocol = parseProtocol(fullPath);
2558
+ const protocol = parseProtocol(_config.url);
2395
2559
 
2396
2560
  if (protocol && platform.protocols.indexOf(protocol) === -1) {
2397
2561
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
@@ -2404,9 +2568,360 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2404
2568
  });
2405
2569
  };
2406
2570
 
2571
+ const composeSignals = (signals, timeout) => {
2572
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
2573
+
2574
+ if (timeout || length) {
2575
+ let controller = new AbortController();
2576
+
2577
+ let aborted;
2578
+
2579
+ const onabort = function (reason) {
2580
+ if (!aborted) {
2581
+ aborted = true;
2582
+ unsubscribe();
2583
+ const err = reason instanceof Error ? reason : this.reason;
2584
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2585
+ }
2586
+ };
2587
+
2588
+ let timer = timeout && setTimeout(() => {
2589
+ timer = null;
2590
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2591
+ }, timeout);
2592
+
2593
+ const unsubscribe = () => {
2594
+ if (signals) {
2595
+ timer && clearTimeout(timer);
2596
+ timer = null;
2597
+ signals.forEach(signal => {
2598
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
2599
+ });
2600
+ signals = null;
2601
+ }
2602
+ };
2603
+
2604
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
2605
+
2606
+ const {signal} = controller;
2607
+
2608
+ signal.unsubscribe = () => utils$1.asap(unsubscribe);
2609
+
2610
+ return signal;
2611
+ }
2612
+ };
2613
+
2614
+ var composeSignals$1 = composeSignals;
2615
+
2616
+ const streamChunk = function* (chunk, chunkSize) {
2617
+ let len = chunk.byteLength;
2618
+
2619
+ if (!chunkSize || len < chunkSize) {
2620
+ yield chunk;
2621
+ return;
2622
+ }
2623
+
2624
+ let pos = 0;
2625
+ let end;
2626
+
2627
+ while (pos < len) {
2628
+ end = pos + chunkSize;
2629
+ yield chunk.slice(pos, end);
2630
+ pos = end;
2631
+ }
2632
+ };
2633
+
2634
+ const readBytes = async function* (iterable, chunkSize) {
2635
+ for await (const chunk of readStream(iterable)) {
2636
+ yield* streamChunk(chunk, chunkSize);
2637
+ }
2638
+ };
2639
+
2640
+ const readStream = async function* (stream) {
2641
+ if (stream[Symbol.asyncIterator]) {
2642
+ yield* stream;
2643
+ return;
2644
+ }
2645
+
2646
+ const reader = stream.getReader();
2647
+ try {
2648
+ for (;;) {
2649
+ const {done, value} = await reader.read();
2650
+ if (done) {
2651
+ break;
2652
+ }
2653
+ yield value;
2654
+ }
2655
+ } finally {
2656
+ await reader.cancel();
2657
+ }
2658
+ };
2659
+
2660
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2661
+ const iterator = readBytes(stream, chunkSize);
2662
+
2663
+ let bytes = 0;
2664
+ let done;
2665
+ let _onFinish = (e) => {
2666
+ if (!done) {
2667
+ done = true;
2668
+ onFinish && onFinish(e);
2669
+ }
2670
+ };
2671
+
2672
+ return new ReadableStream({
2673
+ async pull(controller) {
2674
+ try {
2675
+ const {done, value} = await iterator.next();
2676
+
2677
+ if (done) {
2678
+ _onFinish();
2679
+ controller.close();
2680
+ return;
2681
+ }
2682
+
2683
+ let len = value.byteLength;
2684
+ if (onProgress) {
2685
+ let loadedBytes = bytes += len;
2686
+ onProgress(loadedBytes);
2687
+ }
2688
+ controller.enqueue(new Uint8Array(value));
2689
+ } catch (err) {
2690
+ _onFinish(err);
2691
+ throw err;
2692
+ }
2693
+ },
2694
+ cancel(reason) {
2695
+ _onFinish(reason);
2696
+ return iterator.return();
2697
+ }
2698
+ }, {
2699
+ highWaterMark: 2
2700
+ })
2701
+ };
2702
+
2703
+ const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
2704
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
2705
+
2706
+ // used only inside the fetch adapter
2707
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2708
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2709
+ async (str) => new Uint8Array(await new Response(str).arrayBuffer())
2710
+ );
2711
+
2712
+ const test = (fn, ...args) => {
2713
+ try {
2714
+ return !!fn(...args);
2715
+ } catch (e) {
2716
+ return false
2717
+ }
2718
+ };
2719
+
2720
+ const supportsRequestStream = isReadableStreamSupported && test(() => {
2721
+ let duplexAccessed = false;
2722
+
2723
+ const hasContentType = new Request(platform.origin, {
2724
+ body: new ReadableStream(),
2725
+ method: 'POST',
2726
+ get duplex() {
2727
+ duplexAccessed = true;
2728
+ return 'half';
2729
+ },
2730
+ }).headers.has('Content-Type');
2731
+
2732
+ return duplexAccessed && !hasContentType;
2733
+ });
2734
+
2735
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2736
+
2737
+ const supportsResponseStream = isReadableStreamSupported &&
2738
+ test(() => utils$1.isReadableStream(new Response('').body));
2739
+
2740
+
2741
+ const resolvers = {
2742
+ stream: supportsResponseStream && ((res) => res.body)
2743
+ };
2744
+
2745
+ isFetchSupported && (((res) => {
2746
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2747
+ !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2748
+ (_, config) => {
2749
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2750
+ });
2751
+ });
2752
+ })(new Response));
2753
+
2754
+ const getBodyLength = async (body) => {
2755
+ if (body == null) {
2756
+ return 0;
2757
+ }
2758
+
2759
+ if(utils$1.isBlob(body)) {
2760
+ return body.size;
2761
+ }
2762
+
2763
+ if(utils$1.isSpecCompliantForm(body)) {
2764
+ const _request = new Request(platform.origin, {
2765
+ method: 'POST',
2766
+ body,
2767
+ });
2768
+ return (await _request.arrayBuffer()).byteLength;
2769
+ }
2770
+
2771
+ if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2772
+ return body.byteLength;
2773
+ }
2774
+
2775
+ if(utils$1.isURLSearchParams(body)) {
2776
+ body = body + '';
2777
+ }
2778
+
2779
+ if(utils$1.isString(body)) {
2780
+ return (await encodeText(body)).byteLength;
2781
+ }
2782
+ };
2783
+
2784
+ const resolveBodyLength = async (headers, body) => {
2785
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
2786
+
2787
+ return length == null ? getBodyLength(body) : length;
2788
+ };
2789
+
2790
+ var fetchAdapter = isFetchSupported && (async (config) => {
2791
+ let {
2792
+ url,
2793
+ method,
2794
+ data,
2795
+ signal,
2796
+ cancelToken,
2797
+ timeout,
2798
+ onDownloadProgress,
2799
+ onUploadProgress,
2800
+ responseType,
2801
+ headers,
2802
+ withCredentials = 'same-origin',
2803
+ fetchOptions
2804
+ } = resolveConfig(config);
2805
+
2806
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2807
+
2808
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2809
+
2810
+ let request;
2811
+
2812
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2813
+ composedSignal.unsubscribe();
2814
+ });
2815
+
2816
+ let requestContentLength;
2817
+
2818
+ try {
2819
+ if (
2820
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2821
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2822
+ ) {
2823
+ let _request = new Request(url, {
2824
+ method: 'POST',
2825
+ body: data,
2826
+ duplex: "half"
2827
+ });
2828
+
2829
+ let contentTypeHeader;
2830
+
2831
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2832
+ headers.setContentType(contentTypeHeader);
2833
+ }
2834
+
2835
+ if (_request.body) {
2836
+ const [onProgress, flush] = progressEventDecorator(
2837
+ requestContentLength,
2838
+ progressEventReducer(asyncDecorator(onUploadProgress))
2839
+ );
2840
+
2841
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2842
+ }
2843
+ }
2844
+
2845
+ if (!utils$1.isString(withCredentials)) {
2846
+ withCredentials = withCredentials ? 'include' : 'omit';
2847
+ }
2848
+
2849
+ // Cloudflare Workers throws when credentials are defined
2850
+ // see https://github.com/cloudflare/workerd/issues/902
2851
+ const isCredentialsSupported = "credentials" in Request.prototype;
2852
+ request = new Request(url, {
2853
+ ...fetchOptions,
2854
+ signal: composedSignal,
2855
+ method: method.toUpperCase(),
2856
+ headers: headers.normalize().toJSON(),
2857
+ body: data,
2858
+ duplex: "half",
2859
+ credentials: isCredentialsSupported ? withCredentials : undefined
2860
+ });
2861
+
2862
+ let response = await fetch(request);
2863
+
2864
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2865
+
2866
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2867
+ const options = {};
2868
+
2869
+ ['status', 'statusText', 'headers'].forEach(prop => {
2870
+ options[prop] = response[prop];
2871
+ });
2872
+
2873
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2874
+
2875
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2876
+ responseContentLength,
2877
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
2878
+ ) || [];
2879
+
2880
+ response = new Response(
2881
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2882
+ flush && flush();
2883
+ unsubscribe && unsubscribe();
2884
+ }),
2885
+ options
2886
+ );
2887
+ }
2888
+
2889
+ responseType = responseType || 'text';
2890
+
2891
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2892
+
2893
+ !isStreamResponse && unsubscribe && unsubscribe();
2894
+
2895
+ return await new Promise((resolve, reject) => {
2896
+ settle(resolve, reject, {
2897
+ data: responseData,
2898
+ headers: AxiosHeaders$1.from(response.headers),
2899
+ status: response.status,
2900
+ statusText: response.statusText,
2901
+ config,
2902
+ request
2903
+ });
2904
+ })
2905
+ } catch (err) {
2906
+ unsubscribe && unsubscribe();
2907
+
2908
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2909
+ throw Object.assign(
2910
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
2911
+ {
2912
+ cause: err.cause || err
2913
+ }
2914
+ )
2915
+ }
2916
+
2917
+ throw AxiosError.from(err, err && err.code, config, request);
2918
+ }
2919
+ });
2920
+
2407
2921
  const knownAdapters = {
2408
2922
  http: httpAdapter,
2409
- xhr: xhrAdapter
2923
+ xhr: xhrAdapter,
2924
+ fetch: fetchAdapter
2410
2925
  };
2411
2926
 
2412
2927
  utils$1.forEach(knownAdapters, (fn, value) => {
@@ -2550,109 +3065,7 @@ function dispatchRequest(config) {
2550
3065
  });
2551
3066
  }
2552
3067
 
2553
- const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
2554
-
2555
- /**
2556
- * Config-specific merge-function which creates a new config-object
2557
- * by merging two configuration objects together.
2558
- *
2559
- * @param {Object} config1
2560
- * @param {Object} config2
2561
- *
2562
- * @returns {Object} New object resulting from merging config2 to config1
2563
- */
2564
- function mergeConfig(config1, config2) {
2565
- // eslint-disable-next-line no-param-reassign
2566
- config2 = config2 || {};
2567
- const config = {};
2568
-
2569
- function getMergedValue(target, source, caseless) {
2570
- if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2571
- return utils$1.merge.call({caseless}, target, source);
2572
- } else if (utils$1.isPlainObject(source)) {
2573
- return utils$1.merge({}, source);
2574
- } else if (utils$1.isArray(source)) {
2575
- return source.slice();
2576
- }
2577
- return source;
2578
- }
2579
-
2580
- // eslint-disable-next-line consistent-return
2581
- function mergeDeepProperties(a, b, caseless) {
2582
- if (!utils$1.isUndefined(b)) {
2583
- return getMergedValue(a, b, caseless);
2584
- } else if (!utils$1.isUndefined(a)) {
2585
- return getMergedValue(undefined, a, caseless);
2586
- }
2587
- }
2588
-
2589
- // eslint-disable-next-line consistent-return
2590
- function valueFromConfig2(a, b) {
2591
- if (!utils$1.isUndefined(b)) {
2592
- return getMergedValue(undefined, b);
2593
- }
2594
- }
2595
-
2596
- // eslint-disable-next-line consistent-return
2597
- function defaultToConfig2(a, b) {
2598
- if (!utils$1.isUndefined(b)) {
2599
- return getMergedValue(undefined, b);
2600
- } else if (!utils$1.isUndefined(a)) {
2601
- return getMergedValue(undefined, a);
2602
- }
2603
- }
2604
-
2605
- // eslint-disable-next-line consistent-return
2606
- function mergeDirectKeys(a, b, prop) {
2607
- if (prop in config2) {
2608
- return getMergedValue(a, b);
2609
- } else if (prop in config1) {
2610
- return getMergedValue(undefined, a);
2611
- }
2612
- }
2613
-
2614
- const mergeMap = {
2615
- url: valueFromConfig2,
2616
- method: valueFromConfig2,
2617
- data: valueFromConfig2,
2618
- baseURL: defaultToConfig2,
2619
- transformRequest: defaultToConfig2,
2620
- transformResponse: defaultToConfig2,
2621
- paramsSerializer: defaultToConfig2,
2622
- timeout: defaultToConfig2,
2623
- timeoutMessage: defaultToConfig2,
2624
- withCredentials: defaultToConfig2,
2625
- withXSRFToken: defaultToConfig2,
2626
- adapter: defaultToConfig2,
2627
- responseType: defaultToConfig2,
2628
- xsrfCookieName: defaultToConfig2,
2629
- xsrfHeaderName: defaultToConfig2,
2630
- onUploadProgress: defaultToConfig2,
2631
- onDownloadProgress: defaultToConfig2,
2632
- decompress: defaultToConfig2,
2633
- maxContentLength: defaultToConfig2,
2634
- maxBodyLength: defaultToConfig2,
2635
- beforeRedirect: defaultToConfig2,
2636
- transport: defaultToConfig2,
2637
- httpAgent: defaultToConfig2,
2638
- httpsAgent: defaultToConfig2,
2639
- cancelToken: defaultToConfig2,
2640
- socketPath: defaultToConfig2,
2641
- responseEncoding: defaultToConfig2,
2642
- validateStatus: mergeDirectKeys,
2643
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2644
- };
2645
-
2646
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2647
- const merge = mergeMap[prop] || mergeDeepProperties;
2648
- const configValue = merge(config1[prop], config2[prop], prop);
2649
- (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2650
- });
2651
-
2652
- return config;
2653
- }
2654
-
2655
- const VERSION = "1.6.8";
3068
+ const VERSION = "1.8.4";
2656
3069
 
2657
3070
  const validators$1 = {};
2658
3071
 
@@ -2703,6 +3116,14 @@ validators$1.transitional = function transitional(validator, version, message) {
2703
3116
  };
2704
3117
  };
2705
3118
 
3119
+ validators$1.spelling = function spelling(correctSpelling) {
3120
+ return (value, opt) => {
3121
+ // eslint-disable-next-line no-console
3122
+ console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
3123
+ return true;
3124
+ }
3125
+ };
3126
+
2706
3127
  /**
2707
3128
  * Assert object's properties type
2708
3129
  *
@@ -2772,18 +3193,21 @@ class Axios {
2772
3193
  return await this._request(configOrUrl, config);
2773
3194
  } catch (err) {
2774
3195
  if (err instanceof Error) {
2775
- let dummy;
3196
+ let dummy = {};
2776
3197
 
2777
- Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
3198
+ Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
2778
3199
 
2779
3200
  // slice off the Error: ... line
2780
3201
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
2781
-
2782
- if (!err.stack) {
2783
- err.stack = stack;
2784
- // match without the 2 top stack lines
2785
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
2786
- err.stack += '\n' + stack;
3202
+ try {
3203
+ if (!err.stack) {
3204
+ err.stack = stack;
3205
+ // match without the 2 top stack lines
3206
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3207
+ err.stack += '\n' + stack;
3208
+ }
3209
+ } catch (e) {
3210
+ // ignore the case where "stack" is an un-writable property
2787
3211
  }
2788
3212
  }
2789
3213
 
@@ -2826,6 +3250,18 @@ class Axios {
2826
3250
  }
2827
3251
  }
2828
3252
 
3253
+ // Set config.allowAbsoluteUrls
3254
+ if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
3255
+ config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
3256
+ } else {
3257
+ config.allowAbsoluteUrls = true;
3258
+ }
3259
+
3260
+ validator.assertOptions(config, {
3261
+ baseUrl: validators.spelling('baseURL'),
3262
+ withXsrfToken: validators.spelling('withXSRFToken')
3263
+ }, true);
3264
+
2829
3265
  // Set config.method
2830
3266
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2831
3267
 
@@ -2916,7 +3352,7 @@ class Axios {
2916
3352
 
2917
3353
  getUri(config) {
2918
3354
  config = mergeConfig(this.defaults, config);
2919
- const fullPath = buildFullPath(config.baseURL, config.url);
3355
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
2920
3356
  return buildURL(fullPath, config.params, config.paramsSerializer);
2921
3357
  }
2922
3358
  }
@@ -3056,6 +3492,20 @@ class CancelToken {
3056
3492
  }
3057
3493
  }
3058
3494
 
3495
+ toAbortSignal() {
3496
+ const controller = new AbortController();
3497
+
3498
+ const abort = (err) => {
3499
+ controller.abort(err);
3500
+ };
3501
+
3502
+ this.subscribe(abort);
3503
+
3504
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
3505
+
3506
+ return controller.signal;
3507
+ }
3508
+
3059
3509
  /**
3060
3510
  * Returns an object that contains a new `CancelToken` and a function that, when called,
3061
3511
  * cancels the `CancelToken`.
@@ -3255,7 +3705,7 @@ axios.default = axios;
3255
3705
  var axios$1 = axios;
3256
3706
 
3257
3707
  var name$1 = "@tryghost/content-api";
3258
- var version = "1.11.21";
3708
+ var version = "1.11.22";
3259
3709
  var repository = "https://github.com/TryGhost/SDK/tree/main/packages/content-api";
3260
3710
  var author = "Ghost Foundation";
3261
3711
  var license = "MIT";
@@ -3284,15 +3734,15 @@ var publishConfig = {
3284
3734
  access: "public"
3285
3735
  };
3286
3736
  var devDependencies = {
3287
- "@babel/core": "7.24.4",
3737
+ "@babel/core": "7.26.10",
3288
3738
  "@babel/polyfill": "7.12.1",
3289
- "@babel/preset-env": "7.24.4",
3739
+ "@babel/preset-env": "7.26.9",
3290
3740
  "@rollup/plugin-json": "6.1.0",
3291
- c8: "9.1.0",
3292
- "core-js": "3.37.0",
3741
+ c8: "10.1.3",
3742
+ "core-js": "3.41.0",
3293
3743
  "eslint-plugin-ghost": "3.4.0",
3294
- mocha: "10.4.0",
3295
- rollup: "2.79.1",
3744
+ mocha: "11.1.0",
3745
+ rollup: "2.79.2",
3296
3746
  "rollup-plugin-babel": "4.4.0",
3297
3747
  "rollup-plugin-commonjs": "10.1.0",
3298
3748
  "rollup-plugin-node-resolve": "5.2.0",
@@ -3300,12 +3750,12 @@ var devDependencies = {
3300
3750
  "rollup-plugin-replace": "2.2.0",
3301
3751
  "rollup-plugin-terser": "7.0.2",
3302
3752
  should: "13.2.3",
3303
- sinon: "17.0.1"
3753
+ sinon: "20.0.0"
3304
3754
  };
3305
3755
  var dependencies = {
3306
3756
  axios: "^1.0.0"
3307
3757
  };
3308
- var gitHead = "048ccde4bd78d2dcd60e778d03eb8dc3227cece5";
3758
+ var gitHead = "19592ba6684cd896674e6bd1da92e3eb06e665f2";
3309
3759
  var packageInfo = {
3310
3760
  name: name$1,
3311
3761
  version: version,