@tryghost/content-api 1.12.0 → 1.12.2

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
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Create a bound version of a function with a specified `this` context
3
+ *
4
+ * @param {Function} fn - The function to bind
5
+ * @param {*} thisArg - The value to be passed as the `this` parameter
6
+ * @returns {Function} A new function that will call the original function with the specified `this` context
7
+ */
1
8
  function bind(fn, thisArg) {
2
9
  return function wrap() {
3
10
  return fn.apply(thisArg, arguments);
@@ -49,7 +56,7 @@ const isUndefined = typeOfTest('undefined');
49
56
  */
50
57
  function isBuffer(val) {
51
58
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
52
- && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
59
+ && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
53
60
  }
54
61
 
55
62
  /**
@@ -94,7 +101,7 @@ const isString = typeOfTest('string');
94
101
  * @param {*} val The value to test
95
102
  * @returns {boolean} True if value is a Function, otherwise false
96
103
  */
97
- const isFunction = typeOfTest('function');
104
+ const isFunction$1 = typeOfTest('function');
98
105
 
99
106
  /**
100
107
  * Determine if a value is a Number
@@ -138,6 +145,27 @@ const isPlainObject = (val) => {
138
145
  return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
139
146
  };
140
147
 
148
+ /**
149
+ * Determine if a value is an empty object (safely handles Buffers)
150
+ *
151
+ * @param {*} val The value to test
152
+ *
153
+ * @returns {boolean} True if value is an empty object, otherwise false
154
+ */
155
+ const isEmptyObject = (val) => {
156
+ // Early return for non-objects or Buffers to prevent RangeError
157
+ if (!isObject(val) || isBuffer(val)) {
158
+ return false;
159
+ }
160
+
161
+ try {
162
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
163
+ } catch (e) {
164
+ // Fallback for any other objects that might cause RangeError with Object.keys()
165
+ return false;
166
+ }
167
+ };
168
+
141
169
  /**
142
170
  * Determine if a value is a Date
143
171
  *
@@ -181,7 +209,7 @@ const isFileList = kindOfTest('FileList');
181
209
  *
182
210
  * @returns {boolean} True if value is a Stream, otherwise false
183
211
  */
184
- const isStream = (val) => isObject(val) && isFunction(val.pipe);
212
+ const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
185
213
 
186
214
  /**
187
215
  * Determine if a value is a FormData
@@ -194,10 +222,10 @@ const isFormData = (thing) => {
194
222
  let kind;
195
223
  return thing && (
196
224
  (typeof FormData === 'function' && thing instanceof FormData) || (
197
- isFunction(thing.append) && (
225
+ isFunction$1(thing.append) && (
198
226
  (kind = kindOf(thing)) === 'formdata' ||
199
227
  // detect form-data instance
200
- (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
228
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
201
229
  )
202
230
  )
203
231
  )
@@ -260,6 +288,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
260
288
  fn.call(null, obj[i], i, obj);
261
289
  }
262
290
  } else {
291
+ // Buffer check
292
+ if (isBuffer(obj)) {
293
+ return;
294
+ }
295
+
263
296
  // Iterate over object keys
264
297
  const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
265
298
  const len = keys.length;
@@ -273,6 +306,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
273
306
  }
274
307
 
275
308
  function findKey(obj, key) {
309
+ if (isBuffer(obj)){
310
+ return null;
311
+ }
312
+
276
313
  key = key.toLowerCase();
277
314
  const keys = Object.keys(obj);
278
315
  let i = keys.length;
@@ -313,7 +350,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
313
350
  * @returns {Object} Result of all merge properties
314
351
  */
315
352
  function merge(/* obj1, obj2, obj3, ... */) {
316
- const {caseless} = isContextDefined(this) && this || {};
353
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
317
354
  const result = {};
318
355
  const assignValue = (val, key) => {
319
356
  const targetKey = caseless && findKey(result, key) || key;
@@ -323,7 +360,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
323
360
  result[targetKey] = merge({}, val);
324
361
  } else if (isArray(val)) {
325
362
  result[targetKey] = val.slice();
326
- } else {
363
+ } else if (!skipUndefined || !isUndefined(val)) {
327
364
  result[targetKey] = val;
328
365
  }
329
366
  };
@@ -346,7 +383,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
346
383
  */
347
384
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
348
385
  forEach(b, (val, key) => {
349
- if (thisArg && isFunction(val)) {
386
+ if (thisArg && isFunction$1(val)) {
350
387
  a[key] = bind(val, thisArg);
351
388
  } else {
352
389
  a[key] = val;
@@ -562,13 +599,13 @@ const reduceDescriptors = (obj, reducer) => {
562
599
  const freezeMethods = (obj) => {
563
600
  reduceDescriptors(obj, (descriptor, name) => {
564
601
  // skip restricted props in strict mode
565
- if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
602
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
566
603
  return false;
567
604
  }
568
605
 
569
606
  const value = obj[name];
570
607
 
571
- if (!isFunction(value)) return;
608
+ if (!isFunction$1(value)) return;
572
609
 
573
610
  descriptor.enumerable = false;
574
611
 
@@ -605,6 +642,8 @@ const toFiniteNumber = (value, defaultValue) => {
605
642
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
606
643
  };
607
644
 
645
+
646
+
608
647
  /**
609
648
  * If the thing is a FormData object, return true, otherwise return false.
610
649
  *
@@ -613,7 +652,7 @@ const toFiniteNumber = (value, defaultValue) => {
613
652
  * @returns {boolean}
614
653
  */
615
654
  function isSpecCompliantForm(thing) {
616
- return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
655
+ return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
617
656
  }
618
657
 
619
658
  const toJSONObject = (obj) => {
@@ -626,6 +665,11 @@ const toJSONObject = (obj) => {
626
665
  return;
627
666
  }
628
667
 
668
+ //Buffer check
669
+ if (isBuffer(source)) {
670
+ return source;
671
+ }
672
+
629
673
  if(!('toJSON' in source)) {
630
674
  stack[i] = source;
631
675
  const target = isArray(source) ? [] : {};
@@ -650,7 +694,7 @@ const toJSONObject = (obj) => {
650
694
  const isAsyncFn = kindOfTest('AsyncFunction');
651
695
 
652
696
  const isThenable = (thing) =>
653
- thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
697
+ thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
654
698
 
655
699
  // original code
656
700
  // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
@@ -674,7 +718,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
674
718
  })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
675
719
  })(
676
720
  typeof setImmediate === 'function',
677
- isFunction(_global.postMessage)
721
+ isFunction$1(_global.postMessage)
678
722
  );
679
723
 
680
724
  const asap = typeof queueMicrotask !== 'undefined' ?
@@ -683,7 +727,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
683
727
  // *********************
684
728
 
685
729
 
686
- const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
730
+ const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
687
731
 
688
732
 
689
733
  var utils$1 = {
@@ -697,6 +741,7 @@ var utils$1 = {
697
741
  isBoolean,
698
742
  isObject,
699
743
  isPlainObject,
744
+ isEmptyObject,
700
745
  isReadableStream,
701
746
  isRequest,
702
747
  isResponse,
@@ -706,7 +751,7 @@ var utils$1 = {
706
751
  isFile,
707
752
  isBlob,
708
753
  isRegExp,
709
- isFunction,
754
+ isFunction: isFunction$1,
710
755
  isStream,
711
756
  isURLSearchParams,
712
757
  isTypedArray,
@@ -832,11 +877,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
832
877
  return prop !== 'isAxiosError';
833
878
  });
834
879
 
835
- AxiosError.call(axiosError, error.message, code, config, request, response);
880
+ const msg = error && error.message ? error.message : 'Error';
836
881
 
837
- axiosError.cause = error;
882
+ // Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
883
+ const errCode = code == null && error ? error.code : code;
884
+ AxiosError.call(axiosError, msg, errCode, config, request, response);
838
885
 
839
- axiosError.name = error.name;
886
+ // Chain the original error on the standard field; non-enumerable to avoid JSON noise
887
+ if (error && axiosError.cause == null) {
888
+ Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
889
+ }
890
+
891
+ axiosError.name = (error && error.name) || 'Error';
840
892
 
841
893
  customProps && Object.assign(axiosError, customProps);
842
894
 
@@ -1127,9 +1179,7 @@ function encode(val) {
1127
1179
  replace(/%3A/gi, ':').
1128
1180
  replace(/%24/g, '$').
1129
1181
  replace(/%2C/gi, ',').
1130
- replace(/%20/g, '+').
1131
- replace(/%5B/gi, '[').
1132
- replace(/%5D/gi, ']');
1182
+ replace(/%20/g, '+');
1133
1183
  }
1134
1184
 
1135
1185
  /**
@@ -1207,7 +1257,7 @@ class InterceptorManager {
1207
1257
  *
1208
1258
  * @param {Number} id The ID that was returned by `use`
1209
1259
  *
1210
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
1260
+ * @returns {void}
1211
1261
  */
1212
1262
  eject(id) {
1213
1263
  if (this.handlers[id]) {
@@ -1328,7 +1378,7 @@ var platform = {
1328
1378
  };
1329
1379
 
1330
1380
  function toURLEncodedForm(data, options) {
1331
- return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
1381
+ return toFormData(data, new platform.classes.URLSearchParams(), {
1332
1382
  visitor: function(value, key, path, helpers) {
1333
1383
  if (platform.isNode && utils$1.isBuffer(value)) {
1334
1384
  this.append(key, value.toString('base64'));
@@ -1336,8 +1386,9 @@ function toURLEncodedForm(data, options) {
1336
1386
  }
1337
1387
 
1338
1388
  return helpers.defaultVisitor.apply(this, arguments);
1339
- }
1340
- }, options));
1389
+ },
1390
+ ...options
1391
+ });
1341
1392
  }
1342
1393
 
1343
1394
  /**
@@ -1533,7 +1584,7 @@ const defaults = {
1533
1584
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
1534
1585
 
1535
1586
  try {
1536
- return JSON.parse(data);
1587
+ return JSON.parse(data, this.parseReviver);
1537
1588
  } catch (e) {
1538
1589
  if (strictJSONParsing) {
1539
1590
  if (e.name === 'SyntaxError') {
@@ -2090,7 +2141,7 @@ function throttle(fn, freq) {
2090
2141
  clearTimeout(timer);
2091
2142
  timer = null;
2092
2143
  }
2093
- fn.apply(null, args);
2144
+ fn(...args);
2094
2145
  };
2095
2146
 
2096
2147
  const throttled = (...args) => {
@@ -2172,27 +2223,38 @@ var cookies = platform.hasStandardBrowserEnv ?
2172
2223
 
2173
2224
  // Standard browser envs support document.cookie
2174
2225
  {
2175
- write(name, value, expires, path, domain, secure) {
2176
- const cookie = [name + '=' + encodeURIComponent(value)];
2226
+ write(name, value, expires, path, domain, secure, sameSite) {
2227
+ if (typeof document === 'undefined') return;
2177
2228
 
2178
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
2229
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
2179
2230
 
2180
- utils$1.isString(path) && cookie.push('path=' + path);
2181
-
2182
- utils$1.isString(domain) && cookie.push('domain=' + domain);
2183
-
2184
- secure === true && cookie.push('secure');
2231
+ if (utils$1.isNumber(expires)) {
2232
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
2233
+ }
2234
+ if (utils$1.isString(path)) {
2235
+ cookie.push(`path=${path}`);
2236
+ }
2237
+ if (utils$1.isString(domain)) {
2238
+ cookie.push(`domain=${domain}`);
2239
+ }
2240
+ if (secure === true) {
2241
+ cookie.push('secure');
2242
+ }
2243
+ if (utils$1.isString(sameSite)) {
2244
+ cookie.push(`SameSite=${sameSite}`);
2245
+ }
2185
2246
 
2186
2247
  document.cookie = cookie.join('; ');
2187
2248
  },
2188
2249
 
2189
2250
  read(name) {
2190
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2191
- return (match ? decodeURIComponent(match[3]) : null);
2251
+ if (typeof document === 'undefined') return null;
2252
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
2253
+ return match ? decodeURIComponent(match[1]) : null;
2192
2254
  },
2193
2255
 
2194
2256
  remove(name) {
2195
- this.write(name, '', Date.now() - 86400000);
2257
+ this.write(name, '', Date.now() - 86400000, '/');
2196
2258
  }
2197
2259
  }
2198
2260
 
@@ -2281,11 +2343,11 @@ function mergeConfig(config1, config2) {
2281
2343
  }
2282
2344
 
2283
2345
  // eslint-disable-next-line consistent-return
2284
- function mergeDeepProperties(a, b, prop , caseless) {
2346
+ function mergeDeepProperties(a, b, prop, caseless) {
2285
2347
  if (!utils$1.isUndefined(b)) {
2286
- return getMergedValue(a, b, prop , caseless);
2348
+ return getMergedValue(a, b, prop, caseless);
2287
2349
  } else if (!utils$1.isUndefined(a)) {
2288
- return getMergedValue(undefined, a, prop , caseless);
2350
+ return getMergedValue(undefined, a, prop, caseless);
2289
2351
  }
2290
2352
  }
2291
2353
 
@@ -2343,10 +2405,10 @@ function mergeConfig(config1, config2) {
2343
2405
  socketPath: defaultToConfig2,
2344
2406
  responseEncoding: defaultToConfig2,
2345
2407
  validateStatus: mergeDirectKeys,
2346
- headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2408
+ headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
2347
2409
  };
2348
2410
 
2349
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2411
+ utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
2350
2412
  const merge = mergeMap[prop] || mergeDeepProperties;
2351
2413
  const configValue = merge(config1[prop], config2[prop], prop);
2352
2414
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
@@ -2358,7 +2420,7 @@ function mergeConfig(config1, config2) {
2358
2420
  var resolveConfig = (config) => {
2359
2421
  const newConfig = mergeConfig({}, config);
2360
2422
 
2361
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2423
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
2362
2424
 
2363
2425
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
2364
2426
 
@@ -2371,17 +2433,21 @@ var resolveConfig = (config) => {
2371
2433
  );
2372
2434
  }
2373
2435
 
2374
- let contentType;
2375
-
2376
2436
  if (utils$1.isFormData(data)) {
2377
2437
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2378
- headers.setContentType(undefined); // Let the browser set it
2379
- } else if ((contentType = headers.getContentType()) !== false) {
2380
- // fix semicolon duplication issue for ReactNative FormData implementation
2381
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2382
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2438
+ headers.setContentType(undefined); // browser handles it
2439
+ } else if (utils$1.isFunction(data.getHeaders)) {
2440
+ // Node.js FormData (like form-data package)
2441
+ const formHeaders = data.getHeaders();
2442
+ // Only set safe headers to avoid overwriting security headers
2443
+ const allowedHeaders = ['content-type', 'content-length'];
2444
+ Object.entries(formHeaders).forEach(([key, val]) => {
2445
+ if (allowedHeaders.includes(key.toLowerCase())) {
2446
+ headers.set(key, val);
2447
+ }
2448
+ });
2383
2449
  }
2384
- }
2450
+ }
2385
2451
 
2386
2452
  // Add xsrf header
2387
2453
  // This is only done if running in a standard browser environment.
@@ -2498,15 +2564,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2498
2564
  };
2499
2565
 
2500
2566
  // Handle low level network errors
2501
- request.onerror = function handleError() {
2502
- // Real errors are hidden from us by the browser
2503
- // onerror should only fire if it's a network error
2504
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2505
-
2506
- // Clean up request
2507
- request = null;
2567
+ request.onerror = function handleError(event) {
2568
+ // Browsers deliver a ProgressEvent in XHR onerror
2569
+ // (message may be empty; when present, surface it)
2570
+ // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
2571
+ const msg = event && event.message ? event.message : 'Network Error';
2572
+ const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
2573
+ // attach the underlying event for consumers who want details
2574
+ err.event = event || null;
2575
+ reject(err);
2576
+ request = null;
2508
2577
  };
2509
-
2578
+
2510
2579
  // Handle timeout
2511
2580
  request.ontimeout = function handleTimeout() {
2512
2581
  let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
@@ -2722,14 +2791,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2722
2791
  })
2723
2792
  };
2724
2793
 
2725
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
2726
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
2794
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2795
+
2796
+ const {isFunction} = utils$1;
2797
+
2798
+ const globalFetchAPI = (({Request, Response}) => ({
2799
+ Request, Response
2800
+ }))(utils$1.global);
2801
+
2802
+ const {
2803
+ ReadableStream: ReadableStream$1, TextEncoder
2804
+ } = utils$1.global;
2727
2805
 
2728
- // used only inside the fetch adapter
2729
- const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2730
- ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2731
- async (str) => new Uint8Array(await new Response(str).arrayBuffer())
2732
- );
2733
2806
 
2734
2807
  const test = (fn, ...args) => {
2735
2808
  try {
@@ -2739,278 +2812,380 @@ const test = (fn, ...args) => {
2739
2812
  }
2740
2813
  };
2741
2814
 
2742
- const supportsRequestStream = isReadableStreamSupported && test(() => {
2743
- let duplexAccessed = false;
2815
+ const factory = (env) => {
2816
+ env = utils$1.merge.call({
2817
+ skipUndefined: true
2818
+ }, globalFetchAPI, env);
2744
2819
 
2745
- const hasContentType = new Request(platform.origin, {
2746
- body: new ReadableStream(),
2747
- method: 'POST',
2748
- get duplex() {
2749
- duplexAccessed = true;
2750
- return 'half';
2751
- },
2752
- }).headers.has('Content-Type');
2820
+ const {fetch: envFetch, Request, Response} = env;
2821
+ const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
2822
+ const isRequestSupported = isFunction(Request);
2823
+ const isResponseSupported = isFunction(Response);
2753
2824
 
2754
- return duplexAccessed && !hasContentType;
2755
- });
2825
+ if (!isFetchSupported) {
2826
+ return false;
2827
+ }
2756
2828
 
2757
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
2829
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
2758
2830
 
2759
- const supportsResponseStream = isReadableStreamSupported &&
2760
- test(() => utils$1.isReadableStream(new Response('').body));
2831
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2832
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2833
+ async (str) => new Uint8Array(await new Request(str).arrayBuffer())
2834
+ );
2761
2835
 
2836
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
2837
+ let duplexAccessed = false;
2762
2838
 
2763
- const resolvers = {
2764
- stream: supportsResponseStream && ((res) => res.body)
2765
- };
2839
+ const hasContentType = new Request(platform.origin, {
2840
+ body: new ReadableStream$1(),
2841
+ method: 'POST',
2842
+ get duplex() {
2843
+ duplexAccessed = true;
2844
+ return 'half';
2845
+ },
2846
+ }).headers.has('Content-Type');
2766
2847
 
2767
- isFetchSupported && (((res) => {
2768
- ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2769
- !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2770
- (_, config) => {
2771
- throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2772
- });
2848
+ return duplexAccessed && !hasContentType;
2773
2849
  });
2774
- })(new Response));
2775
2850
 
2776
- const getBodyLength = async (body) => {
2777
- if (body == null) {
2778
- return 0;
2779
- }
2851
+ const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
2852
+ test(() => utils$1.isReadableStream(new Response('').body));
2780
2853
 
2781
- if(utils$1.isBlob(body)) {
2782
- return body.size;
2783
- }
2854
+ const resolvers = {
2855
+ stream: supportsResponseStream && ((res) => res.body)
2856
+ };
2784
2857
 
2785
- if(utils$1.isSpecCompliantForm(body)) {
2786
- const _request = new Request(platform.origin, {
2787
- method: 'POST',
2788
- body,
2858
+ isFetchSupported && ((() => {
2859
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2860
+ !resolvers[type] && (resolvers[type] = (res, config) => {
2861
+ let method = res && res[type];
2862
+
2863
+ if (method) {
2864
+ return method.call(res);
2865
+ }
2866
+
2867
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2868
+ });
2789
2869
  });
2790
- return (await _request.arrayBuffer()).byteLength;
2791
- }
2870
+ })());
2792
2871
 
2793
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2794
- return body.byteLength;
2795
- }
2872
+ const getBodyLength = async (body) => {
2873
+ if (body == null) {
2874
+ return 0;
2875
+ }
2796
2876
 
2797
- if(utils$1.isURLSearchParams(body)) {
2798
- body = body + '';
2799
- }
2877
+ if (utils$1.isBlob(body)) {
2878
+ return body.size;
2879
+ }
2800
2880
 
2801
- if(utils$1.isString(body)) {
2802
- return (await encodeText(body)).byteLength;
2803
- }
2804
- };
2881
+ if (utils$1.isSpecCompliantForm(body)) {
2882
+ const _request = new Request(platform.origin, {
2883
+ method: 'POST',
2884
+ body,
2885
+ });
2886
+ return (await _request.arrayBuffer()).byteLength;
2887
+ }
2805
2888
 
2806
- const resolveBodyLength = async (headers, body) => {
2807
- const length = utils$1.toFiniteNumber(headers.getContentLength());
2889
+ if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2890
+ return body.byteLength;
2891
+ }
2808
2892
 
2809
- return length == null ? getBodyLength(body) : length;
2810
- };
2893
+ if (utils$1.isURLSearchParams(body)) {
2894
+ body = body + '';
2895
+ }
2896
+
2897
+ if (utils$1.isString(body)) {
2898
+ return (await encodeText(body)).byteLength;
2899
+ }
2900
+ };
2901
+
2902
+ const resolveBodyLength = async (headers, body) => {
2903
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
2904
+
2905
+ return length == null ? getBodyLength(body) : length;
2906
+ };
2907
+
2908
+ return async (config) => {
2909
+ let {
2910
+ url,
2911
+ method,
2912
+ data,
2913
+ signal,
2914
+ cancelToken,
2915
+ timeout,
2916
+ onDownloadProgress,
2917
+ onUploadProgress,
2918
+ responseType,
2919
+ headers,
2920
+ withCredentials = 'same-origin',
2921
+ fetchOptions
2922
+ } = resolveConfig(config);
2811
2923
 
2812
- var fetchAdapter = isFetchSupported && (async (config) => {
2813
- let {
2814
- url,
2815
- method,
2816
- data,
2817
- signal,
2818
- cancelToken,
2819
- timeout,
2820
- onDownloadProgress,
2821
- onUploadProgress,
2822
- responseType,
2823
- headers,
2824
- withCredentials = 'same-origin',
2825
- fetchOptions
2826
- } = resolveConfig(config);
2827
-
2828
- responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2829
-
2830
- let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2831
-
2832
- let request;
2833
-
2834
- const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2924
+ let _fetch = envFetch || fetch;
2925
+
2926
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2927
+
2928
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2929
+
2930
+ let request = null;
2931
+
2932
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2835
2933
  composedSignal.unsubscribe();
2836
- });
2934
+ });
2837
2935
 
2838
- let requestContentLength;
2936
+ let requestContentLength;
2839
2937
 
2840
- try {
2841
- if (
2842
- onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2843
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2844
- ) {
2845
- let _request = new Request(url, {
2846
- method: 'POST',
2847
- body: data,
2848
- duplex: "half"
2849
- });
2938
+ try {
2939
+ if (
2940
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2941
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2942
+ ) {
2943
+ let _request = new Request(url, {
2944
+ method: 'POST',
2945
+ body: data,
2946
+ duplex: "half"
2947
+ });
2850
2948
 
2851
- let contentTypeHeader;
2949
+ let contentTypeHeader;
2852
2950
 
2853
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2854
- headers.setContentType(contentTypeHeader);
2855
- }
2951
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2952
+ headers.setContentType(contentTypeHeader);
2953
+ }
2856
2954
 
2857
- if (_request.body) {
2858
- const [onProgress, flush] = progressEventDecorator(
2859
- requestContentLength,
2860
- progressEventReducer(asyncDecorator(onUploadProgress))
2861
- );
2955
+ if (_request.body) {
2956
+ const [onProgress, flush] = progressEventDecorator(
2957
+ requestContentLength,
2958
+ progressEventReducer(asyncDecorator(onUploadProgress))
2959
+ );
2960
+
2961
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2962
+ }
2963
+ }
2862
2964
 
2863
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2965
+ if (!utils$1.isString(withCredentials)) {
2966
+ withCredentials = withCredentials ? 'include' : 'omit';
2864
2967
  }
2865
- }
2866
2968
 
2867
- if (!utils$1.isString(withCredentials)) {
2868
- withCredentials = withCredentials ? 'include' : 'omit';
2869
- }
2969
+ // Cloudflare Workers throws when credentials are defined
2970
+ // see https://github.com/cloudflare/workerd/issues/902
2971
+ const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
2870
2972
 
2871
- // Cloudflare Workers throws when credentials are defined
2872
- // see https://github.com/cloudflare/workerd/issues/902
2873
- const isCredentialsSupported = "credentials" in Request.prototype;
2874
- request = new Request(url, {
2875
- ...fetchOptions,
2876
- signal: composedSignal,
2877
- method: method.toUpperCase(),
2878
- headers: headers.normalize().toJSON(),
2879
- body: data,
2880
- duplex: "half",
2881
- credentials: isCredentialsSupported ? withCredentials : undefined
2882
- });
2973
+ const resolvedOptions = {
2974
+ ...fetchOptions,
2975
+ signal: composedSignal,
2976
+ method: method.toUpperCase(),
2977
+ headers: headers.normalize().toJSON(),
2978
+ body: data,
2979
+ duplex: "half",
2980
+ credentials: isCredentialsSupported ? withCredentials : undefined
2981
+ };
2883
2982
 
2884
- let response = await fetch(request, fetchOptions);
2983
+ request = isRequestSupported && new Request(url, resolvedOptions);
2885
2984
 
2886
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2985
+ let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
2887
2986
 
2888
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2889
- const options = {};
2987
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2890
2988
 
2891
- ['status', 'statusText', 'headers'].forEach(prop => {
2892
- options[prop] = response[prop];
2893
- });
2989
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2990
+ const options = {};
2894
2991
 
2895
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2992
+ ['status', 'statusText', 'headers'].forEach(prop => {
2993
+ options[prop] = response[prop];
2994
+ });
2896
2995
 
2897
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2898
- responseContentLength,
2899
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
2900
- ) || [];
2996
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2901
2997
 
2902
- response = new Response(
2903
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2904
- flush && flush();
2905
- unsubscribe && unsubscribe();
2906
- }),
2907
- options
2908
- );
2909
- }
2998
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2999
+ responseContentLength,
3000
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
3001
+ ) || [];
2910
3002
 
2911
- responseType = responseType || 'text';
3003
+ response = new Response(
3004
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
3005
+ flush && flush();
3006
+ unsubscribe && unsubscribe();
3007
+ }),
3008
+ options
3009
+ );
3010
+ }
2912
3011
 
2913
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
3012
+ responseType = responseType || 'text';
2914
3013
 
2915
- !isStreamResponse && unsubscribe && unsubscribe();
3014
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2916
3015
 
2917
- return await new Promise((resolve, reject) => {
2918
- settle(resolve, reject, {
2919
- data: responseData,
2920
- headers: AxiosHeaders$1.from(response.headers),
2921
- status: response.status,
2922
- statusText: response.statusText,
2923
- config,
2924
- request
2925
- });
2926
- })
2927
- } catch (err) {
2928
- unsubscribe && unsubscribe();
2929
-
2930
- if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
2931
- throw Object.assign(
2932
- new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
2933
- {
2934
- cause: err.cause || err
2935
- }
2936
- )
3016
+ !isStreamResponse && unsubscribe && unsubscribe();
3017
+
3018
+ return await new Promise((resolve, reject) => {
3019
+ settle(resolve, reject, {
3020
+ data: responseData,
3021
+ headers: AxiosHeaders$1.from(response.headers),
3022
+ status: response.status,
3023
+ statusText: response.statusText,
3024
+ config,
3025
+ request
3026
+ });
3027
+ })
3028
+ } catch (err) {
3029
+ unsubscribe && unsubscribe();
3030
+
3031
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
3032
+ throw Object.assign(
3033
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
3034
+ {
3035
+ cause: err.cause || err
3036
+ }
3037
+ )
3038
+ }
3039
+
3040
+ throw AxiosError.from(err, err && err.code, config, request);
2937
3041
  }
3042
+ }
3043
+ };
2938
3044
 
2939
- throw AxiosError.from(err, err && err.code, config, request);
3045
+ const seedCache = new Map();
3046
+
3047
+ const getFetch = (config) => {
3048
+ let env = (config && config.env) || {};
3049
+ const {fetch, Request, Response} = env;
3050
+ const seeds = [
3051
+ Request, Response, fetch
3052
+ ];
3053
+
3054
+ let len = seeds.length, i = len,
3055
+ seed, target, map = seedCache;
3056
+
3057
+ while (i--) {
3058
+ seed = seeds[i];
3059
+ target = map.get(seed);
3060
+
3061
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
3062
+
3063
+ map = target;
2940
3064
  }
2941
- });
2942
3065
 
3066
+ return target;
3067
+ };
3068
+
3069
+ getFetch();
3070
+
3071
+ /**
3072
+ * Known adapters mapping.
3073
+ * Provides environment-specific adapters for Axios:
3074
+ * - `http` for Node.js
3075
+ * - `xhr` for browsers
3076
+ * - `fetch` for fetch API-based requests
3077
+ *
3078
+ * @type {Object<string, Function|Object>}
3079
+ */
2943
3080
  const knownAdapters = {
2944
3081
  http: httpAdapter,
2945
3082
  xhr: xhrAdapter,
2946
- fetch: fetchAdapter
3083
+ fetch: {
3084
+ get: getFetch,
3085
+ }
2947
3086
  };
2948
3087
 
3088
+ // Assign adapter names for easier debugging and identification
2949
3089
  utils$1.forEach(knownAdapters, (fn, value) => {
2950
3090
  if (fn) {
2951
3091
  try {
2952
- Object.defineProperty(fn, 'name', {value});
3092
+ Object.defineProperty(fn, 'name', { value });
2953
3093
  } catch (e) {
2954
3094
  // eslint-disable-next-line no-empty
2955
3095
  }
2956
- Object.defineProperty(fn, 'adapterName', {value});
3096
+ Object.defineProperty(fn, 'adapterName', { value });
2957
3097
  }
2958
3098
  });
2959
3099
 
3100
+ /**
3101
+ * Render a rejection reason string for unknown or unsupported adapters
3102
+ *
3103
+ * @param {string} reason
3104
+ * @returns {string}
3105
+ */
2960
3106
  const renderReason = (reason) => `- ${reason}`;
2961
3107
 
3108
+ /**
3109
+ * Check if the adapter is resolved (function, null, or false)
3110
+ *
3111
+ * @param {Function|null|false} adapter
3112
+ * @returns {boolean}
3113
+ */
2962
3114
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
2963
3115
 
2964
- var adapters = {
2965
- getAdapter: (adapters) => {
2966
- adapters = utils$1.isArray(adapters) ? adapters : [adapters];
3116
+ /**
3117
+ * Get the first suitable adapter from the provided list.
3118
+ * Tries each adapter in order until a supported one is found.
3119
+ * Throws an AxiosError if no adapter is suitable.
3120
+ *
3121
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
3122
+ * @param {Object} config - Axios request configuration
3123
+ * @throws {AxiosError} If no suitable adapter is available
3124
+ * @returns {Function} The resolved adapter function
3125
+ */
3126
+ function getAdapter(adapters, config) {
3127
+ adapters = utils$1.isArray(adapters) ? adapters : [adapters];
2967
3128
 
2968
- const {length} = adapters;
2969
- let nameOrAdapter;
2970
- let adapter;
3129
+ const { length } = adapters;
3130
+ let nameOrAdapter;
3131
+ let adapter;
2971
3132
 
2972
- const rejectedReasons = {};
3133
+ const rejectedReasons = {};
2973
3134
 
2974
- for (let i = 0; i < length; i++) {
2975
- nameOrAdapter = adapters[i];
2976
- let id;
3135
+ for (let i = 0; i < length; i++) {
3136
+ nameOrAdapter = adapters[i];
3137
+ let id;
2977
3138
 
2978
- adapter = nameOrAdapter;
3139
+ adapter = nameOrAdapter;
2979
3140
 
2980
- if (!isResolvedHandle(nameOrAdapter)) {
2981
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3141
+ if (!isResolvedHandle(nameOrAdapter)) {
3142
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
2982
3143
 
2983
- if (adapter === undefined) {
2984
- throw new AxiosError(`Unknown adapter '${id}'`);
2985
- }
2986
- }
2987
-
2988
- if (adapter) {
2989
- break;
3144
+ if (adapter === undefined) {
3145
+ throw new AxiosError(`Unknown adapter '${id}'`);
2990
3146
  }
3147
+ }
2991
3148
 
2992
- rejectedReasons[id || '#' + i] = adapter;
3149
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
3150
+ break;
2993
3151
  }
2994
3152
 
2995
- if (!adapter) {
3153
+ rejectedReasons[id || '#' + i] = adapter;
3154
+ }
2996
3155
 
2997
- const reasons = Object.entries(rejectedReasons)
2998
- .map(([id, state]) => `adapter ${id} ` +
2999
- (state === false ? 'is not supported by the environment' : 'is not available in the build')
3000
- );
3156
+ if (!adapter) {
3157
+ const reasons = Object.entries(rejectedReasons)
3158
+ .map(([id, state]) => `adapter ${id} ` +
3159
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
3160
+ );
3001
3161
 
3002
- let s = length ?
3003
- (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3004
- 'as no adapter specified';
3162
+ let s = length ?
3163
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3164
+ 'as no adapter specified';
3005
3165
 
3006
- throw new AxiosError(
3007
- `There is no suitable adapter to dispatch the request ` + s,
3008
- 'ERR_NOT_SUPPORT'
3009
- );
3010
- }
3166
+ throw new AxiosError(
3167
+ `There is no suitable adapter to dispatch the request ` + s,
3168
+ 'ERR_NOT_SUPPORT'
3169
+ );
3170
+ }
3011
3171
 
3012
- return adapter;
3013
- },
3172
+ return adapter;
3173
+ }
3174
+
3175
+ /**
3176
+ * Exports Axios adapters and utility to resolve an adapter
3177
+ */
3178
+ var adapters = {
3179
+ /**
3180
+ * Resolve an adapter from a list of adapter names or functions.
3181
+ * @type {Function}
3182
+ */
3183
+ getAdapter,
3184
+
3185
+ /**
3186
+ * Exposes all known adapters
3187
+ * @type {Object<string, Function|Object>}
3188
+ */
3014
3189
  adapters: knownAdapters
3015
3190
  };
3016
3191
 
@@ -3053,7 +3228,7 @@ function dispatchRequest(config) {
3053
3228
  config.headers.setContentType('application/x-www-form-urlencoded', false);
3054
3229
  }
3055
3230
 
3056
- const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3231
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
3057
3232
 
3058
3233
  return adapter(config).then(function onAdapterResolution(response) {
3059
3234
  throwIfCancellationRequested(config);
@@ -3087,7 +3262,7 @@ function dispatchRequest(config) {
3087
3262
  });
3088
3263
  }
3089
3264
 
3090
- const VERSION = "1.10.0";
3265
+ const VERSION = "1.13.2";
3091
3266
 
3092
3267
  const validators$1 = {};
3093
3268
 
@@ -3326,8 +3501,8 @@ class Axios {
3326
3501
 
3327
3502
  if (!synchronousRequestInterceptors) {
3328
3503
  const chain = [dispatchRequest.bind(this), undefined];
3329
- chain.unshift.apply(chain, requestInterceptorChain);
3330
- chain.push.apply(chain, responseInterceptorChain);
3504
+ chain.unshift(...requestInterceptorChain);
3505
+ chain.push(...responseInterceptorChain);
3331
3506
  len = chain.length;
3332
3507
 
3333
3508
  promise = Promise.resolve(config);
@@ -3343,8 +3518,6 @@ class Axios {
3343
3518
 
3344
3519
  let newConfig = config;
3345
3520
 
3346
- i = 0;
3347
-
3348
3521
  while (i < len) {
3349
3522
  const onFulfilled = requestInterceptorChain[i++];
3350
3523
  const onRejected = requestInterceptorChain[i++];
@@ -3648,6 +3821,12 @@ const HttpStatusCode = {
3648
3821
  LoopDetected: 508,
3649
3822
  NotExtended: 510,
3650
3823
  NetworkAuthenticationRequired: 511,
3824
+ WebServerIsDown: 521,
3825
+ ConnectionTimedOut: 522,
3826
+ OriginIsUnreachable: 523,
3827
+ TimeoutOccurred: 524,
3828
+ SslHandshakeFailed: 525,
3829
+ InvalidSslCertificate: 526,
3651
3830
  };
3652
3831
 
3653
3832
  Object.entries(HttpStatusCode).forEach(([key, value]) => {
@@ -3727,7 +3906,7 @@ axios.default = axios;
3727
3906
  var axios$1 = axios;
3728
3907
 
3729
3908
  var name$1 = "@tryghost/content-api";
3730
- var version = "1.12.0";
3909
+ var version = "1.12.1";
3731
3910
  var repository = {
3732
3911
  type: "git",
3733
3912
  url: "git+https://github.com/TryGhost/SDK.git",
@@ -3760,14 +3939,14 @@ var publishConfig = {
3760
3939
  access: "public"
3761
3940
  };
3762
3941
  var devDependencies = {
3763
- "@babel/core": "7.27.7",
3942
+ "@babel/core": "7.28.5",
3764
3943
  "@babel/polyfill": "7.12.1",
3765
- "@babel/preset-env": "7.27.2",
3944
+ "@babel/preset-env": "7.28.5",
3766
3945
  "@rollup/plugin-json": "6.1.0",
3767
3946
  c8: "10.1.3",
3768
- "core-js": "3.43.0",
3947
+ "core-js": "3.47.0",
3769
3948
  "eslint-plugin-ghost": "3.4.3",
3770
- mocha: "11.2.2",
3949
+ mocha: "11.7.5",
3771
3950
  rollup: "2.79.2",
3772
3951
  "rollup-plugin-babel": "4.4.0",
3773
3952
  "rollup-plugin-commonjs": "10.1.0",
@@ -3781,7 +3960,6 @@ var devDependencies = {
3781
3960
  var dependencies = {
3782
3961
  axios: "^1.0.0"
3783
3962
  };
3784
- var gitHead = "860707f032864400017b0f176cbabf181f99b764";
3785
3963
  var packageInfo = {
3786
3964
  name: name$1,
3787
3965
  version: version,
@@ -3797,8 +3975,7 @@ var packageInfo = {
3797
3975
  scripts: scripts,
3798
3976
  publishConfig: publishConfig,
3799
3977
  devDependencies: devDependencies,
3800
- dependencies: dependencies,
3801
- gitHead: gitHead
3978
+ dependencies: dependencies
3802
3979
  };
3803
3980
 
3804
3981
  // @NOTE: this value is dynamically replaced based on browser/node environment