@tryghost/content-api 1.11.21 → 1.11.23

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
@@ -8,6 +8,7 @@ function bind(fn, thisArg) {
8
8
 
9
9
  const {toString} = Object.prototype;
10
10
  const {getPrototypeOf} = Object;
11
+ const {iterator, toStringTag} = Symbol;
11
12
 
12
13
  const kindOf = (cache => thing => {
13
14
  const str = toString.call(thing);
@@ -134,7 +135,7 @@ const isPlainObject = (val) => {
134
135
  }
135
136
 
136
137
  const prototype = getPrototypeOf(val);
137
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
138
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
138
139
  };
139
140
 
140
141
  /**
@@ -211,6 +212,8 @@ const isFormData = (thing) => {
211
212
  */
212
213
  const isURLSearchParams = kindOfTest('URLSearchParams');
213
214
 
215
+ const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
216
+
214
217
  /**
215
218
  * Trim excess whitespace off the beginning and end of a string
216
219
  *
@@ -483,13 +486,13 @@ const isTypedArray = (TypedArray => {
483
486
  * @returns {void}
484
487
  */
485
488
  const forEachEntry = (obj, fn) => {
486
- const generator = obj && obj[Symbol.iterator];
489
+ const generator = obj && obj[iterator];
487
490
 
488
- const iterator = generator.call(obj);
491
+ const _iterator = generator.call(obj);
489
492
 
490
493
  let result;
491
494
 
492
- while ((result = iterator.next()) && !result.done) {
495
+ while ((result = _iterator.next()) && !result.done) {
493
496
  const pair = result.value;
494
497
  fn.call(obj, pair[0], pair[1]);
495
498
  }
@@ -599,28 +602,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
599
602
  const noop = () => {};
600
603
 
601
604
  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;
605
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
624
606
  };
625
607
 
626
608
  /**
@@ -631,7 +613,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
631
613
  * @returns {boolean}
632
614
  */
633
615
  function isSpecCompliantForm(thing) {
634
- return !!(thing && isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator]);
616
+ return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
635
617
  }
636
618
 
637
619
  const toJSONObject = (obj) => {
@@ -670,6 +652,40 @@ const isAsyncFn = kindOfTest('AsyncFunction');
670
652
  const isThenable = (thing) =>
671
653
  thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
672
654
 
655
+ // original code
656
+ // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
657
+
658
+ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
659
+ if (setImmediateSupported) {
660
+ return setImmediate;
661
+ }
662
+
663
+ return postMessageSupported ? ((token, callbacks) => {
664
+ _global.addEventListener("message", ({source, data}) => {
665
+ if (source === _global && data === token) {
666
+ callbacks.length && callbacks.shift()();
667
+ }
668
+ }, false);
669
+
670
+ return (cb) => {
671
+ callbacks.push(cb);
672
+ _global.postMessage(token, "*");
673
+ }
674
+ })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
675
+ })(
676
+ typeof setImmediate === 'function',
677
+ isFunction(_global.postMessage)
678
+ );
679
+
680
+ const asap = typeof queueMicrotask !== 'undefined' ?
681
+ queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
682
+
683
+ // *********************
684
+
685
+
686
+ const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
687
+
688
+
673
689
  var utils$1 = {
674
690
  isArray,
675
691
  isArrayBuffer,
@@ -681,6 +697,10 @@ var utils$1 = {
681
697
  isBoolean,
682
698
  isObject,
683
699
  isPlainObject,
700
+ isReadableStream,
701
+ isRequest,
702
+ isResponse,
703
+ isHeaders,
684
704
  isUndefined,
685
705
  isDate,
686
706
  isFile,
@@ -716,12 +736,13 @@ var utils$1 = {
716
736
  findKey,
717
737
  global: _global,
718
738
  isContextDefined,
719
- ALPHABET,
720
- generateString,
721
739
  isSpecCompliantForm,
722
740
  toJSONObject,
723
741
  isAsyncFn,
724
- isThenable
742
+ isThenable,
743
+ setImmediate: _setImmediate,
744
+ asap,
745
+ isIterable
725
746
  };
726
747
 
727
748
  /**
@@ -749,7 +770,10 @@ function AxiosError(message, code, config, request, response) {
749
770
  code && (this.code = code);
750
771
  config && (this.config = config);
751
772
  request && (this.request = request);
752
- response && (this.response = response);
773
+ if (response) {
774
+ this.response = response;
775
+ this.status = response.status ? response.status : null;
776
+ }
753
777
  }
754
778
 
755
779
  utils$1.inherits(AxiosError, Error, {
@@ -769,7 +793,7 @@ utils$1.inherits(AxiosError, Error, {
769
793
  // Axios
770
794
  config: utils$1.toJSONObject(this.config),
771
795
  code: this.code,
772
- status: this.response && this.response.status ? this.response.status : null
796
+ status: this.status
773
797
  };
774
798
  }
775
799
  });
@@ -1109,7 +1133,7 @@ function encode(val) {
1109
1133
  *
1110
1134
  * @param {string} url The base of the url (e.g., http://www.google.com)
1111
1135
  * @param {object} [params] The params to be appended
1112
- * @param {?object} options
1136
+ * @param {?(object|Function)} options
1113
1137
  *
1114
1138
  * @returns {string} The formatted url
1115
1139
  */
@@ -1121,6 +1145,12 @@ function buildURL(url, params, options) {
1121
1145
 
1122
1146
  const _encode = options && options.encode || encode;
1123
1147
 
1148
+ if (utils$1.isFunction(options)) {
1149
+ options = {
1150
+ serialize: options
1151
+ };
1152
+ }
1153
+
1124
1154
  const serializeFn = options && options.serialize;
1125
1155
 
1126
1156
  let serializedParams;
@@ -1237,6 +1267,8 @@ var platform$1 = {
1237
1267
 
1238
1268
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1239
1269
 
1270
+ const _navigator = typeof navigator === 'object' && navigator || undefined;
1271
+
1240
1272
  /**
1241
1273
  * Determine if we're running in a standard browser environment
1242
1274
  *
@@ -1254,10 +1286,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
1254
1286
  *
1255
1287
  * @returns {boolean}
1256
1288
  */
1257
- const hasStandardBrowserEnv = (
1258
- (product) => {
1259
- return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
1260
- })(typeof navigator !== 'undefined' && navigator.product);
1289
+ const hasStandardBrowserEnv = hasBrowserEnv &&
1290
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
1261
1291
 
1262
1292
  /**
1263
1293
  * Determine if we're running in a standard browser webWorker environment
@@ -1277,11 +1307,15 @@ const hasStandardBrowserWebWorkerEnv = (() => {
1277
1307
  );
1278
1308
  })();
1279
1309
 
1310
+ const origin = hasBrowserEnv && window.location.href || 'http://localhost';
1311
+
1280
1312
  var utils = /*#__PURE__*/Object.freeze({
1281
1313
  __proto__: null,
1282
1314
  hasBrowserEnv: hasBrowserEnv,
1283
1315
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1284
- hasStandardBrowserEnv: hasStandardBrowserEnv
1316
+ hasStandardBrowserEnv: hasStandardBrowserEnv,
1317
+ navigator: _navigator,
1318
+ origin: origin
1285
1319
  });
1286
1320
 
1287
1321
  var platform = {
@@ -1421,7 +1455,7 @@ const defaults = {
1421
1455
 
1422
1456
  transitional: transitionalDefaults,
1423
1457
 
1424
- adapter: ['xhr', 'http'],
1458
+ adapter: ['xhr', 'http', 'fetch'],
1425
1459
 
1426
1460
  transformRequest: [function transformRequest(data, headers) {
1427
1461
  const contentType = headers.getContentType() || '';
@@ -1442,7 +1476,8 @@ const defaults = {
1442
1476
  utils$1.isBuffer(data) ||
1443
1477
  utils$1.isStream(data) ||
1444
1478
  utils$1.isFile(data) ||
1445
- utils$1.isBlob(data)
1479
+ utils$1.isBlob(data) ||
1480
+ utils$1.isReadableStream(data)
1446
1481
  ) {
1447
1482
  return data;
1448
1483
  }
@@ -1485,6 +1520,10 @@ const defaults = {
1485
1520
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1486
1521
  const JSONRequested = this.responseType === 'json';
1487
1522
 
1523
+ if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
1524
+ return data;
1525
+ }
1526
+
1488
1527
  if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1489
1528
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
1490
1529
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
@@ -1688,6 +1727,18 @@ class AxiosHeaders {
1688
1727
  setHeaders(header, valueOrRewrite);
1689
1728
  } else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1690
1729
  setHeaders(parseHeaders(header), valueOrRewrite);
1730
+ } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
1731
+ let obj = {}, dest, key;
1732
+ for (const entry of header) {
1733
+ if (!utils$1.isArray(entry)) {
1734
+ throw TypeError('Object iterator must return a key-value pair');
1735
+ }
1736
+
1737
+ obj[key = entry[0]] = (dest = obj[key]) ?
1738
+ (utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]]) : entry[1];
1739
+ }
1740
+
1741
+ setHeaders(obj, valueOrRewrite);
1691
1742
  } else {
1692
1743
  header != null && setHeader(valueOrRewrite, header, rewrite);
1693
1744
  }
@@ -1829,6 +1880,10 @@ class AxiosHeaders {
1829
1880
  return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
1830
1881
  }
1831
1882
 
1883
+ getSetCookie() {
1884
+ return this.get("set-cookie") || [];
1885
+ }
1886
+
1832
1887
  get [Symbol.toStringTag]() {
1833
1888
  return 'AxiosHeaders';
1834
1889
  }
@@ -1955,153 +2010,6 @@ function settle(resolve, reject, response) {
1955
2010
  }
1956
2011
  }
1957
2012
 
1958
- var cookies = platform.hasStandardBrowserEnv ?
1959
-
1960
- // Standard browser envs support document.cookie
1961
- {
1962
- write(name, value, expires, path, domain, secure) {
1963
- const cookie = [name + '=' + encodeURIComponent(value)];
1964
-
1965
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
1966
-
1967
- utils$1.isString(path) && cookie.push('path=' + path);
1968
-
1969
- utils$1.isString(domain) && cookie.push('domain=' + domain);
1970
-
1971
- secure === true && cookie.push('secure');
1972
-
1973
- document.cookie = cookie.join('; ');
1974
- },
1975
-
1976
- read(name) {
1977
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
1978
- return (match ? decodeURIComponent(match[3]) : null);
1979
- },
1980
-
1981
- remove(name) {
1982
- this.write(name, '', Date.now() - 86400000);
1983
- }
1984
- }
1985
-
1986
- :
1987
-
1988
- // Non-standard browser env (web workers, react-native) lack needed support.
1989
- {
1990
- write() {},
1991
- read() {
1992
- return null;
1993
- },
1994
- remove() {}
1995
- };
1996
-
1997
- /**
1998
- * Determines whether the specified URL is absolute
1999
- *
2000
- * @param {string} url The URL to test
2001
- *
2002
- * @returns {boolean} True if the specified URL is absolute, otherwise false
2003
- */
2004
- function isAbsoluteURL(url) {
2005
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
2006
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
2007
- // by any combination of letters, digits, plus, period, or hyphen.
2008
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
2009
- }
2010
-
2011
- /**
2012
- * Creates a new URL by combining the specified URLs
2013
- *
2014
- * @param {string} baseURL The base URL
2015
- * @param {string} relativeURL The relative URL
2016
- *
2017
- * @returns {string} The combined URL
2018
- */
2019
- function combineURLs(baseURL, relativeURL) {
2020
- return relativeURL
2021
- ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2022
- : baseURL;
2023
- }
2024
-
2025
- /**
2026
- * Creates a new URL by combining the baseURL with the requestedURL,
2027
- * only when the requestedURL is not already an absolute URL.
2028
- * If the requestURL is absolute, this function returns the requestedURL untouched.
2029
- *
2030
- * @param {string} baseURL The base URL
2031
- * @param {string} requestedURL Absolute or relative URL to combine
2032
- *
2033
- * @returns {string} The combined full path
2034
- */
2035
- function buildFullPath(baseURL, requestedURL) {
2036
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2037
- return combineURLs(baseURL, requestedURL);
2038
- }
2039
- return requestedURL;
2040
- }
2041
-
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
- }
2065
-
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
- };
2081
- }
2082
-
2083
- originURL = resolveURL(window.location.href);
2084
-
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
- })() :
2097
-
2098
- // Non standard browser envs (web workers, react-native) lack needed support.
2099
- (function nonStandardBrowserEnv() {
2100
- return function isURLSameOrigin() {
2101
- return true;
2102
- };
2103
- })();
2104
-
2105
2013
  function parseProtocol(url) {
2106
2014
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2107
2015
  return match && match[1] || '';
@@ -2159,11 +2067,54 @@ function speedometer(samplesCount, min) {
2159
2067
  };
2160
2068
  }
2161
2069
 
2162
- function progressEventReducer(listener, isDownloadStream) {
2070
+ /**
2071
+ * Throttle decorator
2072
+ * @param {Function} fn
2073
+ * @param {Number} freq
2074
+ * @return {Function}
2075
+ */
2076
+ function throttle(fn, freq) {
2077
+ let timestamp = 0;
2078
+ let threshold = 1000 / freq;
2079
+ let lastArgs;
2080
+ let timer;
2081
+
2082
+ const invoke = (args, now = Date.now()) => {
2083
+ timestamp = now;
2084
+ lastArgs = null;
2085
+ if (timer) {
2086
+ clearTimeout(timer);
2087
+ timer = null;
2088
+ }
2089
+ fn.apply(null, args);
2090
+ };
2091
+
2092
+ const throttled = (...args) => {
2093
+ const now = Date.now();
2094
+ const passed = now - timestamp;
2095
+ if ( passed >= threshold) {
2096
+ invoke(args, now);
2097
+ } else {
2098
+ lastArgs = args;
2099
+ if (!timer) {
2100
+ timer = setTimeout(() => {
2101
+ timer = null;
2102
+ invoke(lastArgs);
2103
+ }, threshold - passed);
2104
+ }
2105
+ }
2106
+ };
2107
+
2108
+ const flush = () => lastArgs && invoke(lastArgs);
2109
+
2110
+ return [throttled, flush];
2111
+ }
2112
+
2113
+ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2163
2114
  let bytesNotified = 0;
2164
2115
  const _speedometer = speedometer(50, 250);
2165
2116
 
2166
- return e => {
2117
+ return throttle(e => {
2167
2118
  const loaded = e.loaded;
2168
2119
  const total = e.lengthComputable ? e.total : undefined;
2169
2120
  const progressBytes = loaded - bytesNotified;
@@ -2179,143 +2130,385 @@ function progressEventReducer(listener, isDownloadStream) {
2179
2130
  bytes: progressBytes,
2180
2131
  rate: rate ? rate : undefined,
2181
2132
  estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2182
- event: e
2133
+ event: e,
2134
+ lengthComputable: total != null,
2135
+ [isDownloadStream ? 'download' : 'upload']: true
2183
2136
  };
2184
2137
 
2185
- data[isDownloadStream ? 'download' : 'upload'] = true;
2186
-
2187
2138
  listener(data);
2188
- };
2189
- }
2190
-
2191
- const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2139
+ }, freq);
2140
+ };
2192
2141
 
2193
- var xhrAdapter = isXHRAdapterSupported && function (config) {
2194
- 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;
2198
- let onCanceled;
2199
- function done() {
2200
- if (config.cancelToken) {
2201
- config.cancelToken.unsubscribe(onCanceled);
2202
- }
2142
+ const progressEventDecorator = (total, throttled) => {
2143
+ const lengthComputable = total != null;
2203
2144
 
2204
- if (config.signal) {
2205
- config.signal.removeEventListener('abort', onCanceled);
2206
- }
2207
- }
2145
+ return [(loaded) => throttled[0]({
2146
+ lengthComputable,
2147
+ total,
2148
+ loaded
2149
+ }), throttled[1]];
2150
+ };
2208
2151
 
2209
- let contentType;
2152
+ const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
2210
2153
 
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
- }
2219
- }
2154
+ var isURLSameOrigin = platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => {
2155
+ url = new URL(url, platform.origin);
2220
2156
 
2221
- let request = new XMLHttpRequest();
2157
+ return (
2158
+ origin.protocol === url.protocol &&
2159
+ origin.host === url.host &&
2160
+ (isMSIE || origin.port === url.port)
2161
+ );
2162
+ })(
2163
+ new URL(platform.origin),
2164
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
2165
+ ) : () => true;
2222
2166
 
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
- }
2167
+ var cookies = platform.hasStandardBrowserEnv ?
2229
2168
 
2230
- const fullPath = buildFullPath(config.baseURL, config.url);
2169
+ // Standard browser envs support document.cookie
2170
+ {
2171
+ write(name, value, expires, path, domain, secure) {
2172
+ const cookie = [name + '=' + encodeURIComponent(value)];
2231
2173
 
2232
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
2174
+ utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
2233
2175
 
2234
- // Set the request timeout in MS
2235
- request.timeout = config.timeout;
2176
+ utils$1.isString(path) && cookie.push('path=' + path);
2236
2177
 
2237
- function onloadend() {
2238
- if (!request) {
2239
- return;
2240
- }
2241
- // Prepare the response
2242
- const responseHeaders = AxiosHeaders$1.from(
2243
- 'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2244
- );
2245
- const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
2246
- request.responseText : request.response;
2247
- const response = {
2248
- data: responseData,
2249
- status: request.status,
2250
- statusText: request.statusText,
2251
- headers: responseHeaders,
2252
- config,
2253
- request
2254
- };
2178
+ utils$1.isString(domain) && cookie.push('domain=' + domain);
2255
2179
 
2256
- settle(function _resolve(value) {
2257
- resolve(value);
2258
- done();
2259
- }, function _reject(err) {
2260
- reject(err);
2261
- done();
2262
- }, response);
2180
+ secure === true && cookie.push('secure');
2263
2181
 
2264
- // Clean up request
2265
- request = null;
2266
- }
2182
+ document.cookie = cookie.join('; ');
2183
+ },
2267
2184
 
2268
- if ('onloadend' in request) {
2269
- // Use onloadend if available
2270
- request.onloadend = onloadend;
2271
- } else {
2272
- // Listen for ready state to emulate onloadend
2273
- request.onreadystatechange = function handleLoad() {
2274
- if (!request || request.readyState !== 4) {
2275
- return;
2276
- }
2185
+ read(name) {
2186
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2187
+ return (match ? decodeURIComponent(match[3]) : null);
2188
+ },
2277
2189
 
2278
- // The request errored out and we didn't get a response, this will be
2279
- // handled by onerror instead
2280
- // With one exception: request that using file: protocol, most browsers
2281
- // will return status as 0 even though it's a successful request
2282
- if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
2283
- return;
2284
- }
2285
- // readystate handler is calling before onerror or ontimeout handlers,
2286
- // so we should call onloadend on the next 'tick'
2287
- setTimeout(onloadend);
2288
- };
2190
+ remove(name) {
2191
+ this.write(name, '', Date.now() - 86400000);
2289
2192
  }
2193
+ }
2290
2194
 
2291
- // Handle browser request cancellation (as opposed to a manual cancellation)
2292
- request.onabort = function handleAbort() {
2293
- if (!request) {
2294
- return;
2295
- }
2296
-
2297
- reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
2298
-
2299
- // Clean up request
2300
- request = null;
2301
- };
2195
+ :
2302
2196
 
2303
- // Handle low level network errors
2304
- request.onerror = function handleError() {
2305
- // Real errors are hidden from us by the browser
2306
- // onerror should only fire if it's a network error
2307
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2197
+ // Non-standard browser env (web workers, react-native) lack needed support.
2198
+ {
2199
+ write() {},
2200
+ read() {
2201
+ return null;
2202
+ },
2203
+ remove() {}
2204
+ };
2308
2205
 
2309
- // Clean up request
2206
+ /**
2207
+ * Determines whether the specified URL is absolute
2208
+ *
2209
+ * @param {string} url The URL to test
2210
+ *
2211
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
2212
+ */
2213
+ function isAbsoluteURL(url) {
2214
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
2215
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
2216
+ // by any combination of letters, digits, plus, period, or hyphen.
2217
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
2218
+ }
2219
+
2220
+ /**
2221
+ * Creates a new URL by combining the specified URLs
2222
+ *
2223
+ * @param {string} baseURL The base URL
2224
+ * @param {string} relativeURL The relative URL
2225
+ *
2226
+ * @returns {string} The combined URL
2227
+ */
2228
+ function combineURLs(baseURL, relativeURL) {
2229
+ return relativeURL
2230
+ ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2231
+ : baseURL;
2232
+ }
2233
+
2234
+ /**
2235
+ * Creates a new URL by combining the baseURL with the requestedURL,
2236
+ * only when the requestedURL is not already an absolute URL.
2237
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
2238
+ *
2239
+ * @param {string} baseURL The base URL
2240
+ * @param {string} requestedURL Absolute or relative URL to combine
2241
+ *
2242
+ * @returns {string} The combined full path
2243
+ */
2244
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2245
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2246
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
2247
+ return combineURLs(baseURL, requestedURL);
2248
+ }
2249
+ return requestedURL;
2250
+ }
2251
+
2252
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
2253
+
2254
+ /**
2255
+ * Config-specific merge-function which creates a new config-object
2256
+ * by merging two configuration objects together.
2257
+ *
2258
+ * @param {Object} config1
2259
+ * @param {Object} config2
2260
+ *
2261
+ * @returns {Object} New object resulting from merging config2 to config1
2262
+ */
2263
+ function mergeConfig(config1, config2) {
2264
+ // eslint-disable-next-line no-param-reassign
2265
+ config2 = config2 || {};
2266
+ const config = {};
2267
+
2268
+ function getMergedValue(target, source, prop, caseless) {
2269
+ if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2270
+ return utils$1.merge.call({caseless}, target, source);
2271
+ } else if (utils$1.isPlainObject(source)) {
2272
+ return utils$1.merge({}, source);
2273
+ } else if (utils$1.isArray(source)) {
2274
+ return source.slice();
2275
+ }
2276
+ return source;
2277
+ }
2278
+
2279
+ // eslint-disable-next-line consistent-return
2280
+ function mergeDeepProperties(a, b, prop , caseless) {
2281
+ if (!utils$1.isUndefined(b)) {
2282
+ return getMergedValue(a, b, prop , caseless);
2283
+ } else if (!utils$1.isUndefined(a)) {
2284
+ return getMergedValue(undefined, a, prop , caseless);
2285
+ }
2286
+ }
2287
+
2288
+ // eslint-disable-next-line consistent-return
2289
+ function valueFromConfig2(a, b) {
2290
+ if (!utils$1.isUndefined(b)) {
2291
+ return getMergedValue(undefined, b);
2292
+ }
2293
+ }
2294
+
2295
+ // eslint-disable-next-line consistent-return
2296
+ function defaultToConfig2(a, b) {
2297
+ if (!utils$1.isUndefined(b)) {
2298
+ return getMergedValue(undefined, b);
2299
+ } else if (!utils$1.isUndefined(a)) {
2300
+ return getMergedValue(undefined, a);
2301
+ }
2302
+ }
2303
+
2304
+ // eslint-disable-next-line consistent-return
2305
+ function mergeDirectKeys(a, b, prop) {
2306
+ if (prop in config2) {
2307
+ return getMergedValue(a, b);
2308
+ } else if (prop in config1) {
2309
+ return getMergedValue(undefined, a);
2310
+ }
2311
+ }
2312
+
2313
+ const mergeMap = {
2314
+ url: valueFromConfig2,
2315
+ method: valueFromConfig2,
2316
+ data: valueFromConfig2,
2317
+ baseURL: defaultToConfig2,
2318
+ transformRequest: defaultToConfig2,
2319
+ transformResponse: defaultToConfig2,
2320
+ paramsSerializer: defaultToConfig2,
2321
+ timeout: defaultToConfig2,
2322
+ timeoutMessage: defaultToConfig2,
2323
+ withCredentials: defaultToConfig2,
2324
+ withXSRFToken: defaultToConfig2,
2325
+ adapter: defaultToConfig2,
2326
+ responseType: defaultToConfig2,
2327
+ xsrfCookieName: defaultToConfig2,
2328
+ xsrfHeaderName: defaultToConfig2,
2329
+ onUploadProgress: defaultToConfig2,
2330
+ onDownloadProgress: defaultToConfig2,
2331
+ decompress: defaultToConfig2,
2332
+ maxContentLength: defaultToConfig2,
2333
+ maxBodyLength: defaultToConfig2,
2334
+ beforeRedirect: defaultToConfig2,
2335
+ transport: defaultToConfig2,
2336
+ httpAgent: defaultToConfig2,
2337
+ httpsAgent: defaultToConfig2,
2338
+ cancelToken: defaultToConfig2,
2339
+ socketPath: defaultToConfig2,
2340
+ responseEncoding: defaultToConfig2,
2341
+ validateStatus: mergeDirectKeys,
2342
+ headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2343
+ };
2344
+
2345
+ utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2346
+ const merge = mergeMap[prop] || mergeDeepProperties;
2347
+ const configValue = merge(config1[prop], config2[prop], prop);
2348
+ (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2349
+ });
2350
+
2351
+ return config;
2352
+ }
2353
+
2354
+ var resolveConfig = (config) => {
2355
+ const newConfig = mergeConfig({}, config);
2356
+
2357
+ let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2358
+
2359
+ newConfig.headers = headers = AxiosHeaders$1.from(headers);
2360
+
2361
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2362
+
2363
+ // HTTP basic authentication
2364
+ if (auth) {
2365
+ headers.set('Authorization', 'Basic ' +
2366
+ btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
2367
+ );
2368
+ }
2369
+
2370
+ let contentType;
2371
+
2372
+ if (utils$1.isFormData(data)) {
2373
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2374
+ headers.setContentType(undefined); // Let the browser set it
2375
+ } else if ((contentType = headers.getContentType()) !== false) {
2376
+ // fix semicolon duplication issue for ReactNative FormData implementation
2377
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2378
+ headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2379
+ }
2380
+ }
2381
+
2382
+ // Add xsrf header
2383
+ // This is only done if running in a standard browser environment.
2384
+ // Specifically not if we're in a web worker, or react-native.
2385
+
2386
+ if (platform.hasStandardBrowserEnv) {
2387
+ withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
2388
+
2389
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
2390
+ // Add xsrf header
2391
+ const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
2392
+
2393
+ if (xsrfValue) {
2394
+ headers.set(xsrfHeaderName, xsrfValue);
2395
+ }
2396
+ }
2397
+ }
2398
+
2399
+ return newConfig;
2400
+ };
2401
+
2402
+ const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2403
+
2404
+ var xhrAdapter = isXHRAdapterSupported && function (config) {
2405
+ return new Promise(function dispatchXhrRequest(resolve, reject) {
2406
+ const _config = resolveConfig(config);
2407
+ let requestData = _config.data;
2408
+ const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
2409
+ let {responseType, onUploadProgress, onDownloadProgress} = _config;
2410
+ let onCanceled;
2411
+ let uploadThrottled, downloadThrottled;
2412
+ let flushUpload, flushDownload;
2413
+
2414
+ function done() {
2415
+ flushUpload && flushUpload(); // flush events
2416
+ flushDownload && flushDownload(); // flush events
2417
+
2418
+ _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
2419
+
2420
+ _config.signal && _config.signal.removeEventListener('abort', onCanceled);
2421
+ }
2422
+
2423
+ let request = new XMLHttpRequest();
2424
+
2425
+ request.open(_config.method.toUpperCase(), _config.url, true);
2426
+
2427
+ // Set the request timeout in MS
2428
+ request.timeout = _config.timeout;
2429
+
2430
+ function onloadend() {
2431
+ if (!request) {
2432
+ return;
2433
+ }
2434
+ // Prepare the response
2435
+ const responseHeaders = AxiosHeaders$1.from(
2436
+ 'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2437
+ );
2438
+ const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
2439
+ request.responseText : request.response;
2440
+ const response = {
2441
+ data: responseData,
2442
+ status: request.status,
2443
+ statusText: request.statusText,
2444
+ headers: responseHeaders,
2445
+ config,
2446
+ request
2447
+ };
2448
+
2449
+ settle(function _resolve(value) {
2450
+ resolve(value);
2451
+ done();
2452
+ }, function _reject(err) {
2453
+ reject(err);
2454
+ done();
2455
+ }, response);
2456
+
2457
+ // Clean up request
2458
+ request = null;
2459
+ }
2460
+
2461
+ if ('onloadend' in request) {
2462
+ // Use onloadend if available
2463
+ request.onloadend = onloadend;
2464
+ } else {
2465
+ // Listen for ready state to emulate onloadend
2466
+ request.onreadystatechange = function handleLoad() {
2467
+ if (!request || request.readyState !== 4) {
2468
+ return;
2469
+ }
2470
+
2471
+ // The request errored out and we didn't get a response, this will be
2472
+ // handled by onerror instead
2473
+ // With one exception: request that using file: protocol, most browsers
2474
+ // will return status as 0 even though it's a successful request
2475
+ if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
2476
+ return;
2477
+ }
2478
+ // readystate handler is calling before onerror or ontimeout handlers,
2479
+ // so we should call onloadend on the next 'tick'
2480
+ setTimeout(onloadend);
2481
+ };
2482
+ }
2483
+
2484
+ // Handle browser request cancellation (as opposed to a manual cancellation)
2485
+ request.onabort = function handleAbort() {
2486
+ if (!request) {
2487
+ return;
2488
+ }
2489
+
2490
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
2491
+
2492
+ // Clean up request
2493
+ request = null;
2494
+ };
2495
+
2496
+ // Handle low level network errors
2497
+ request.onerror = function handleError() {
2498
+ // Real errors are hidden from us by the browser
2499
+ // onerror should only fire if it's a network error
2500
+ reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2501
+
2502
+ // Clean up request
2310
2503
  request = null;
2311
2504
  };
2312
2505
 
2313
2506
  // Handle timeout
2314
2507
  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;
2508
+ let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
2509
+ const transitional = _config.transitional || transitionalDefaults;
2510
+ if (_config.timeoutErrorMessage) {
2511
+ timeoutErrorMessage = _config.timeoutErrorMessage;
2319
2512
  }
2320
2513
  reject(new AxiosError(
2321
2514
  timeoutErrorMessage,
@@ -2327,22 +2520,6 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2327
2520
  request = null;
2328
2521
  };
2329
2522
 
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
2523
  // Remove Content-Type if data is undefined
2347
2524
  requestData === undefined && requestHeaders.setContentType(null);
2348
2525
 
@@ -2354,26 +2531,31 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2354
2531
  }
2355
2532
 
2356
2533
  // Add withCredentials to request if needed
2357
- if (!utils$1.isUndefined(config.withCredentials)) {
2358
- request.withCredentials = !!config.withCredentials;
2534
+ if (!utils$1.isUndefined(_config.withCredentials)) {
2535
+ request.withCredentials = !!_config.withCredentials;
2359
2536
  }
2360
2537
 
2361
2538
  // Add responseType to request if needed
2362
2539
  if (responseType && responseType !== 'json') {
2363
- request.responseType = config.responseType;
2540
+ request.responseType = _config.responseType;
2364
2541
  }
2365
2542
 
2366
2543
  // Handle progress if needed
2367
- if (typeof config.onDownloadProgress === 'function') {
2368
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
2544
+ if (onDownloadProgress) {
2545
+ ([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
2546
+ request.addEventListener('progress', downloadThrottled);
2369
2547
  }
2370
2548
 
2371
2549
  // Not all browsers support upload events
2372
- if (typeof config.onUploadProgress === 'function' && request.upload) {
2373
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
2550
+ if (onUploadProgress && request.upload) {
2551
+ ([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
2552
+
2553
+ request.upload.addEventListener('progress', uploadThrottled);
2554
+
2555
+ request.upload.addEventListener('loadend', flushUpload);
2374
2556
  }
2375
2557
 
2376
- if (config.cancelToken || config.signal) {
2558
+ if (_config.cancelToken || _config.signal) {
2377
2559
  // Handle cancellation
2378
2560
  // eslint-disable-next-line func-names
2379
2561
  onCanceled = cancel => {
@@ -2385,13 +2567,13 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2385
2567
  request = null;
2386
2568
  };
2387
2569
 
2388
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
2389
- if (config.signal) {
2390
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
2570
+ _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
2571
+ if (_config.signal) {
2572
+ _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
2391
2573
  }
2392
2574
  }
2393
2575
 
2394
- const protocol = parseProtocol(fullPath);
2576
+ const protocol = parseProtocol(_config.url);
2395
2577
 
2396
2578
  if (protocol && platform.protocols.indexOf(protocol) === -1) {
2397
2579
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
@@ -2404,9 +2586,360 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2404
2586
  });
2405
2587
  };
2406
2588
 
2589
+ const composeSignals = (signals, timeout) => {
2590
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
2591
+
2592
+ if (timeout || length) {
2593
+ let controller = new AbortController();
2594
+
2595
+ let aborted;
2596
+
2597
+ const onabort = function (reason) {
2598
+ if (!aborted) {
2599
+ aborted = true;
2600
+ unsubscribe();
2601
+ const err = reason instanceof Error ? reason : this.reason;
2602
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2603
+ }
2604
+ };
2605
+
2606
+ let timer = timeout && setTimeout(() => {
2607
+ timer = null;
2608
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2609
+ }, timeout);
2610
+
2611
+ const unsubscribe = () => {
2612
+ if (signals) {
2613
+ timer && clearTimeout(timer);
2614
+ timer = null;
2615
+ signals.forEach(signal => {
2616
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
2617
+ });
2618
+ signals = null;
2619
+ }
2620
+ };
2621
+
2622
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
2623
+
2624
+ const {signal} = controller;
2625
+
2626
+ signal.unsubscribe = () => utils$1.asap(unsubscribe);
2627
+
2628
+ return signal;
2629
+ }
2630
+ };
2631
+
2632
+ var composeSignals$1 = composeSignals;
2633
+
2634
+ const streamChunk = function* (chunk, chunkSize) {
2635
+ let len = chunk.byteLength;
2636
+
2637
+ if (!chunkSize || len < chunkSize) {
2638
+ yield chunk;
2639
+ return;
2640
+ }
2641
+
2642
+ let pos = 0;
2643
+ let end;
2644
+
2645
+ while (pos < len) {
2646
+ end = pos + chunkSize;
2647
+ yield chunk.slice(pos, end);
2648
+ pos = end;
2649
+ }
2650
+ };
2651
+
2652
+ const readBytes = async function* (iterable, chunkSize) {
2653
+ for await (const chunk of readStream(iterable)) {
2654
+ yield* streamChunk(chunk, chunkSize);
2655
+ }
2656
+ };
2657
+
2658
+ const readStream = async function* (stream) {
2659
+ if (stream[Symbol.asyncIterator]) {
2660
+ yield* stream;
2661
+ return;
2662
+ }
2663
+
2664
+ const reader = stream.getReader();
2665
+ try {
2666
+ for (;;) {
2667
+ const {done, value} = await reader.read();
2668
+ if (done) {
2669
+ break;
2670
+ }
2671
+ yield value;
2672
+ }
2673
+ } finally {
2674
+ await reader.cancel();
2675
+ }
2676
+ };
2677
+
2678
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2679
+ const iterator = readBytes(stream, chunkSize);
2680
+
2681
+ let bytes = 0;
2682
+ let done;
2683
+ let _onFinish = (e) => {
2684
+ if (!done) {
2685
+ done = true;
2686
+ onFinish && onFinish(e);
2687
+ }
2688
+ };
2689
+
2690
+ return new ReadableStream({
2691
+ async pull(controller) {
2692
+ try {
2693
+ const {done, value} = await iterator.next();
2694
+
2695
+ if (done) {
2696
+ _onFinish();
2697
+ controller.close();
2698
+ return;
2699
+ }
2700
+
2701
+ let len = value.byteLength;
2702
+ if (onProgress) {
2703
+ let loadedBytes = bytes += len;
2704
+ onProgress(loadedBytes);
2705
+ }
2706
+ controller.enqueue(new Uint8Array(value));
2707
+ } catch (err) {
2708
+ _onFinish(err);
2709
+ throw err;
2710
+ }
2711
+ },
2712
+ cancel(reason) {
2713
+ _onFinish(reason);
2714
+ return iterator.return();
2715
+ }
2716
+ }, {
2717
+ highWaterMark: 2
2718
+ })
2719
+ };
2720
+
2721
+ const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
2722
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
2723
+
2724
+ // used only inside the fetch adapter
2725
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2726
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2727
+ async (str) => new Uint8Array(await new Response(str).arrayBuffer())
2728
+ );
2729
+
2730
+ const test = (fn, ...args) => {
2731
+ try {
2732
+ return !!fn(...args);
2733
+ } catch (e) {
2734
+ return false
2735
+ }
2736
+ };
2737
+
2738
+ const supportsRequestStream = isReadableStreamSupported && test(() => {
2739
+ let duplexAccessed = false;
2740
+
2741
+ const hasContentType = new Request(platform.origin, {
2742
+ body: new ReadableStream(),
2743
+ method: 'POST',
2744
+ get duplex() {
2745
+ duplexAccessed = true;
2746
+ return 'half';
2747
+ },
2748
+ }).headers.has('Content-Type');
2749
+
2750
+ return duplexAccessed && !hasContentType;
2751
+ });
2752
+
2753
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2754
+
2755
+ const supportsResponseStream = isReadableStreamSupported &&
2756
+ test(() => utils$1.isReadableStream(new Response('').body));
2757
+
2758
+
2759
+ const resolvers = {
2760
+ stream: supportsResponseStream && ((res) => res.body)
2761
+ };
2762
+
2763
+ isFetchSupported && (((res) => {
2764
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2765
+ !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2766
+ (_, config) => {
2767
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2768
+ });
2769
+ });
2770
+ })(new Response));
2771
+
2772
+ const getBodyLength = async (body) => {
2773
+ if (body == null) {
2774
+ return 0;
2775
+ }
2776
+
2777
+ if(utils$1.isBlob(body)) {
2778
+ return body.size;
2779
+ }
2780
+
2781
+ if(utils$1.isSpecCompliantForm(body)) {
2782
+ const _request = new Request(platform.origin, {
2783
+ method: 'POST',
2784
+ body,
2785
+ });
2786
+ return (await _request.arrayBuffer()).byteLength;
2787
+ }
2788
+
2789
+ if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2790
+ return body.byteLength;
2791
+ }
2792
+
2793
+ if(utils$1.isURLSearchParams(body)) {
2794
+ body = body + '';
2795
+ }
2796
+
2797
+ if(utils$1.isString(body)) {
2798
+ return (await encodeText(body)).byteLength;
2799
+ }
2800
+ };
2801
+
2802
+ const resolveBodyLength = async (headers, body) => {
2803
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
2804
+
2805
+ return length == null ? getBodyLength(body) : length;
2806
+ };
2807
+
2808
+ var fetchAdapter = isFetchSupported && (async (config) => {
2809
+ let {
2810
+ url,
2811
+ method,
2812
+ data,
2813
+ signal,
2814
+ cancelToken,
2815
+ timeout,
2816
+ onDownloadProgress,
2817
+ onUploadProgress,
2818
+ responseType,
2819
+ headers,
2820
+ withCredentials = 'same-origin',
2821
+ fetchOptions
2822
+ } = resolveConfig(config);
2823
+
2824
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2825
+
2826
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2827
+
2828
+ let request;
2829
+
2830
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2831
+ composedSignal.unsubscribe();
2832
+ });
2833
+
2834
+ let requestContentLength;
2835
+
2836
+ try {
2837
+ if (
2838
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2839
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2840
+ ) {
2841
+ let _request = new Request(url, {
2842
+ method: 'POST',
2843
+ body: data,
2844
+ duplex: "half"
2845
+ });
2846
+
2847
+ let contentTypeHeader;
2848
+
2849
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2850
+ headers.setContentType(contentTypeHeader);
2851
+ }
2852
+
2853
+ if (_request.body) {
2854
+ const [onProgress, flush] = progressEventDecorator(
2855
+ requestContentLength,
2856
+ progressEventReducer(asyncDecorator(onUploadProgress))
2857
+ );
2858
+
2859
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2860
+ }
2861
+ }
2862
+
2863
+ if (!utils$1.isString(withCredentials)) {
2864
+ withCredentials = withCredentials ? 'include' : 'omit';
2865
+ }
2866
+
2867
+ // Cloudflare Workers throws when credentials are defined
2868
+ // see https://github.com/cloudflare/workerd/issues/902
2869
+ const isCredentialsSupported = "credentials" in Request.prototype;
2870
+ request = new Request(url, {
2871
+ ...fetchOptions,
2872
+ signal: composedSignal,
2873
+ method: method.toUpperCase(),
2874
+ headers: headers.normalize().toJSON(),
2875
+ body: data,
2876
+ duplex: "half",
2877
+ credentials: isCredentialsSupported ? withCredentials : undefined
2878
+ });
2879
+
2880
+ let response = await fetch(request);
2881
+
2882
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2883
+
2884
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2885
+ const options = {};
2886
+
2887
+ ['status', 'statusText', 'headers'].forEach(prop => {
2888
+ options[prop] = response[prop];
2889
+ });
2890
+
2891
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2892
+
2893
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2894
+ responseContentLength,
2895
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
2896
+ ) || [];
2897
+
2898
+ response = new Response(
2899
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2900
+ flush && flush();
2901
+ unsubscribe && unsubscribe();
2902
+ }),
2903
+ options
2904
+ );
2905
+ }
2906
+
2907
+ responseType = responseType || 'text';
2908
+
2909
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2910
+
2911
+ !isStreamResponse && unsubscribe && unsubscribe();
2912
+
2913
+ return await new Promise((resolve, reject) => {
2914
+ settle(resolve, reject, {
2915
+ data: responseData,
2916
+ headers: AxiosHeaders$1.from(response.headers),
2917
+ status: response.status,
2918
+ statusText: response.statusText,
2919
+ config,
2920
+ request
2921
+ });
2922
+ })
2923
+ } catch (err) {
2924
+ unsubscribe && unsubscribe();
2925
+
2926
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
2927
+ throw Object.assign(
2928
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
2929
+ {
2930
+ cause: err.cause || err
2931
+ }
2932
+ )
2933
+ }
2934
+
2935
+ throw AxiosError.from(err, err && err.code, config, request);
2936
+ }
2937
+ });
2938
+
2407
2939
  const knownAdapters = {
2408
2940
  http: httpAdapter,
2409
- xhr: xhrAdapter
2941
+ xhr: xhrAdapter,
2942
+ fetch: fetchAdapter
2410
2943
  };
2411
2944
 
2412
2945
  utils$1.forEach(knownAdapters, (fn, value) => {
@@ -2550,109 +3083,7 @@ function dispatchRequest(config) {
2550
3083
  });
2551
3084
  }
2552
3085
 
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";
3086
+ const VERSION = "1.9.0";
2656
3087
 
2657
3088
  const validators$1 = {};
2658
3089
 
@@ -2703,6 +3134,14 @@ validators$1.transitional = function transitional(validator, version, message) {
2703
3134
  };
2704
3135
  };
2705
3136
 
3137
+ validators$1.spelling = function spelling(correctSpelling) {
3138
+ return (value, opt) => {
3139
+ // eslint-disable-next-line no-console
3140
+ console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
3141
+ return true;
3142
+ }
3143
+ };
3144
+
2706
3145
  /**
2707
3146
  * Assert object's properties type
2708
3147
  *
@@ -2752,7 +3191,7 @@ const validators = validator.validators;
2752
3191
  */
2753
3192
  class Axios {
2754
3193
  constructor(instanceConfig) {
2755
- this.defaults = instanceConfig;
3194
+ this.defaults = instanceConfig || {};
2756
3195
  this.interceptors = {
2757
3196
  request: new InterceptorManager$1(),
2758
3197
  response: new InterceptorManager$1()
@@ -2772,18 +3211,21 @@ class Axios {
2772
3211
  return await this._request(configOrUrl, config);
2773
3212
  } catch (err) {
2774
3213
  if (err instanceof Error) {
2775
- let dummy;
3214
+ let dummy = {};
2776
3215
 
2777
- Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
3216
+ Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
2778
3217
 
2779
3218
  // slice off the Error: ... line
2780
3219
  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;
3220
+ try {
3221
+ if (!err.stack) {
3222
+ err.stack = stack;
3223
+ // match without the 2 top stack lines
3224
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3225
+ err.stack += '\n' + stack;
3226
+ }
3227
+ } catch (e) {
3228
+ // ignore the case where "stack" is an un-writable property
2787
3229
  }
2788
3230
  }
2789
3231
 
@@ -2826,6 +3268,18 @@ class Axios {
2826
3268
  }
2827
3269
  }
2828
3270
 
3271
+ // Set config.allowAbsoluteUrls
3272
+ if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
3273
+ config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
3274
+ } else {
3275
+ config.allowAbsoluteUrls = true;
3276
+ }
3277
+
3278
+ validator.assertOptions(config, {
3279
+ baseUrl: validators.spelling('baseURL'),
3280
+ withXsrfToken: validators.spelling('withXSRFToken')
3281
+ }, true);
3282
+
2829
3283
  // Set config.method
2830
3284
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2831
3285
 
@@ -2916,7 +3370,7 @@ class Axios {
2916
3370
 
2917
3371
  getUri(config) {
2918
3372
  config = mergeConfig(this.defaults, config);
2919
- const fullPath = buildFullPath(config.baseURL, config.url);
3373
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
2920
3374
  return buildURL(fullPath, config.params, config.paramsSerializer);
2921
3375
  }
2922
3376
  }
@@ -3056,6 +3510,20 @@ class CancelToken {
3056
3510
  }
3057
3511
  }
3058
3512
 
3513
+ toAbortSignal() {
3514
+ const controller = new AbortController();
3515
+
3516
+ const abort = (err) => {
3517
+ controller.abort(err);
3518
+ };
3519
+
3520
+ this.subscribe(abort);
3521
+
3522
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
3523
+
3524
+ return controller.signal;
3525
+ }
3526
+
3059
3527
  /**
3060
3528
  * Returns an object that contains a new `CancelToken` and a function that, when called,
3061
3529
  * cancels the `CancelToken`.
@@ -3255,7 +3723,7 @@ axios.default = axios;
3255
3723
  var axios$1 = axios;
3256
3724
 
3257
3725
  var name$1 = "@tryghost/content-api";
3258
- var version = "1.11.21";
3726
+ var version = "1.11.23";
3259
3727
  var repository = "https://github.com/TryGhost/SDK/tree/main/packages/content-api";
3260
3728
  var author = "Ghost Foundation";
3261
3729
  var license = "MIT";
@@ -3284,15 +3752,15 @@ var publishConfig = {
3284
3752
  access: "public"
3285
3753
  };
3286
3754
  var devDependencies = {
3287
- "@babel/core": "7.24.4",
3755
+ "@babel/core": "7.27.1",
3288
3756
  "@babel/polyfill": "7.12.1",
3289
- "@babel/preset-env": "7.24.4",
3757
+ "@babel/preset-env": "7.27.2",
3290
3758
  "@rollup/plugin-json": "6.1.0",
3291
- c8: "9.1.0",
3292
- "core-js": "3.37.0",
3759
+ c8: "10.1.3",
3760
+ "core-js": "3.42.0",
3293
3761
  "eslint-plugin-ghost": "3.4.0",
3294
- mocha: "10.4.0",
3295
- rollup: "2.79.1",
3762
+ mocha: "11.2.2",
3763
+ rollup: "2.79.2",
3296
3764
  "rollup-plugin-babel": "4.4.0",
3297
3765
  "rollup-plugin-commonjs": "10.1.0",
3298
3766
  "rollup-plugin-node-resolve": "5.2.0",
@@ -3300,12 +3768,11 @@ var devDependencies = {
3300
3768
  "rollup-plugin-replace": "2.2.0",
3301
3769
  "rollup-plugin-terser": "7.0.2",
3302
3770
  should: "13.2.3",
3303
- sinon: "17.0.1"
3771
+ sinon: "20.0.0"
3304
3772
  };
3305
3773
  var dependencies = {
3306
3774
  axios: "^1.0.0"
3307
3775
  };
3308
- var gitHead = "048ccde4bd78d2dcd60e778d03eb8dc3227cece5";
3309
3776
  var packageInfo = {
3310
3777
  name: name$1,
3311
3778
  version: version,
@@ -3321,8 +3788,7 @@ var packageInfo = {
3321
3788
  scripts: scripts,
3322
3789
  publishConfig: publishConfig,
3323
3790
  devDependencies: devDependencies,
3324
- dependencies: dependencies,
3325
- gitHead: gitHead
3791
+ dependencies: dependencies
3326
3792
  };
3327
3793
 
3328
3794
  // @NOTE: this value is dynamically replaced based on browser/node environment