contentful 11.12.3 → 11.12.5

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.
@@ -1447,10 +1447,10 @@ var contentful = (function (exports) {
1447
1447
  * @returns {Object} The JSON-compatible object.
1448
1448
  */
1449
1449
  var toJSONObject = function toJSONObject(obj) {
1450
- var stack = new Array(10);
1451
- var _visit = function visit(source, i) {
1450
+ var visited = new WeakSet();
1451
+ var _visit = function visit(source) {
1452
1452
  if (isObject(source)) {
1453
- if (stack.indexOf(source) >= 0) {
1453
+ if (visited.has(source)) {
1454
1454
  return;
1455
1455
  }
1456
1456
 
@@ -1459,19 +1459,20 @@ var contentful = (function (exports) {
1459
1459
  return source;
1460
1460
  }
1461
1461
  if (!('toJSON' in source)) {
1462
- stack[i] = source;
1462
+ // add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230).
1463
+ visited.add(source);
1463
1464
  var target = isArray$7(source) ? [] : {};
1464
1465
  forEach(source, function (value, key) {
1465
- var reducedValue = _visit(value, i + 1);
1466
+ var reducedValue = _visit(value);
1466
1467
  !isUndefined(reducedValue) && (target[key] = reducedValue);
1467
1468
  });
1468
- stack[i] = undefined;
1469
+ visited.delete(source);
1469
1470
  return target;
1470
1471
  }
1471
1472
  }
1472
1473
  return source;
1473
1474
  };
1474
- return _visit(obj, 0);
1475
+ return _visit(obj);
1475
1476
  };
1476
1477
 
1477
1478
  /**
@@ -1642,8 +1643,6 @@ var contentful = (function (exports) {
1642
1643
  });
1643
1644
  return parsed;
1644
1645
  };
1645
- var $internals = Symbol('internals');
1646
- var INVALID_HEADER_VALUE_CHARS_RE = /[^\x09\x20-\x7E\x80-\xFF]/g;
1647
1646
  function trimSPorHTAB(str) {
1648
1647
  var start = 0;
1649
1648
  var end = str.length;
@@ -1663,12 +1662,37 @@ var contentful = (function (exports) {
1663
1662
  }
1664
1663
  return start === 0 && end === str.length ? str : str.slice(start, end);
1665
1664
  }
1665
+
1666
+ // The control-code ranges are intentional: header sanitization strips C0/DEL bytes.
1667
+ // eslint-disable-next-line no-control-regex
1668
+ var INVALID_UNICODE_HEADER_VALUE_CHARS = new RegExp("[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+", 'g');
1669
+ // eslint-disable-next-line no-control-regex
1670
+ var INVALID_BYTE_STRING_HEADER_VALUE_CHARS = new RegExp("[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+", 'g');
1671
+ function sanitizeValue(value, invalidChars) {
1672
+ if (utils$1$1.isArray(value)) {
1673
+ return value.map(function (item) {
1674
+ return sanitizeValue(item, invalidChars);
1675
+ });
1676
+ }
1677
+ return trimSPorHTAB(String(value).replace(invalidChars, ''));
1678
+ }
1679
+ var sanitizeHeaderValue = function sanitizeHeaderValue(value) {
1680
+ return sanitizeValue(value, INVALID_UNICODE_HEADER_VALUE_CHARS);
1681
+ };
1682
+ var sanitizeByteStringHeaderValue = function sanitizeByteStringHeaderValue(value) {
1683
+ return sanitizeValue(value, INVALID_BYTE_STRING_HEADER_VALUE_CHARS);
1684
+ };
1685
+ function toByteStringHeaderObject(headers) {
1686
+ var byteStringHeaders = Object.create(null);
1687
+ utils$1$1.forEach(headers.toJSON(), function (value, header) {
1688
+ byteStringHeaders[header] = sanitizeByteStringHeaderValue(value);
1689
+ });
1690
+ return byteStringHeaders;
1691
+ }
1692
+ var $internals = Symbol('internals');
1666
1693
  function normalizeHeader(header) {
1667
1694
  return header && String(header).trim().toLowerCase();
1668
1695
  }
1669
- function sanitizeHeaderValue(str) {
1670
- return trimSPorHTAB(str.replace(INVALID_HEADER_VALUE_CHARS_RE, ''));
1671
- }
1672
1696
  function normalizeValue(value) {
1673
1697
  if (value === false || value == null) {
1674
1698
  return value;
@@ -2621,7 +2645,7 @@ var contentful = (function (exports) {
2621
2645
  }
2622
2646
  return !isNumericKey;
2623
2647
  }
2624
- if (!target[name] || !utils$1$1.isObject(target[name])) {
2648
+ if (!utils$1$1.hasOwnProp(target, name) || !utils$1$1.isObject(target[name])) {
2625
2649
  target[name] = [];
2626
2650
  }
2627
2651
  var result = buildPath(path, value, target[name], index);
@@ -2915,6 +2939,9 @@ var contentful = (function (exports) {
2915
2939
  var bytesNotified = 0;
2916
2940
  var _speedometer = speedometer(50, 250);
2917
2941
  return throttle(function (e) {
2942
+ if (!e || typeof e.loaded !== 'number') {
2943
+ return;
2944
+ }
2918
2945
  var rawLoaded = e.loaded;
2919
2946
  var total = e.lengthComputable ? e.total : undefined;
2920
2947
  var loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
@@ -3382,7 +3409,7 @@ var contentful = (function (exports) {
3382
3409
 
3383
3410
  // Add headers to the request
3384
3411
  if ('setRequestHeader' in request) {
3385
- utils$1$1.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
3412
+ utils$1$1.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
3386
3413
  request.setRequestHeader(key, val);
3387
3414
  });
3388
3415
  }
@@ -3443,42 +3470,43 @@ var contentful = (function (exports) {
3443
3470
  });
3444
3471
  };
3445
3472
  var composeSignals = function composeSignals(signals, timeout) {
3446
- var _signals = signals = signals ? signals.filter(Boolean) : [],
3447
- length = _signals.length;
3448
- if (timeout || length) {
3449
- var controller = new AbortController();
3450
- var aborted;
3451
- var onabort = function onabort(reason) {
3452
- if (!aborted) {
3453
- aborted = true;
3454
- unsubscribe();
3455
- var err = reason instanceof Error ? reason : this.reason;
3456
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
3457
- }
3458
- };
3459
- var timer = timeout && setTimeout(function () {
3460
- timer = null;
3461
- onabort(new AxiosError("timeout of ".concat(timeout, "ms exceeded"), AxiosError.ETIMEDOUT));
3462
- }, timeout);
3463
- var unsubscribe = function unsubscribe() {
3464
- if (signals) {
3465
- timer && clearTimeout(timer);
3466
- timer = null;
3467
- signals.forEach(function (signal) {
3468
- signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
3469
- });
3470
- signals = null;
3471
- }
3472
- };
3473
+ signals = signals ? signals.filter(Boolean) : [];
3474
+ if (!timeout && !signals.length) {
3475
+ return;
3476
+ }
3477
+ var controller = new AbortController();
3478
+ var aborted = false;
3479
+ var onabort = function onabort(reason) {
3480
+ if (!aborted) {
3481
+ aborted = true;
3482
+ unsubscribe();
3483
+ var err = reason instanceof Error ? reason : this.reason;
3484
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
3485
+ }
3486
+ };
3487
+ var timer = timeout && setTimeout(function () {
3488
+ timer = null;
3489
+ onabort(new AxiosError("timeout of ".concat(timeout, "ms exceeded"), AxiosError.ETIMEDOUT));
3490
+ }, timeout);
3491
+ var unsubscribe = function unsubscribe() {
3492
+ if (!signals) {
3493
+ return;
3494
+ }
3495
+ timer && clearTimeout(timer);
3496
+ timer = null;
3473
3497
  signals.forEach(function (signal) {
3474
- return signal.addEventListener('abort', onabort);
3498
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
3475
3499
  });
3476
- var signal = controller.signal;
3477
- signal.unsubscribe = function () {
3478
- return utils$1$1.asap(unsubscribe);
3479
- };
3480
- return signal;
3481
- }
3500
+ signals = null;
3501
+ };
3502
+ signals.forEach(function (signal) {
3503
+ return signal.addEventListener('abort', onabort);
3504
+ });
3505
+ var signal = controller.signal;
3506
+ signal.unsubscribe = function () {
3507
+ return utils$1$1.asap(unsubscribe);
3508
+ };
3509
+ return signal;
3482
3510
  };
3483
3511
  var streamChunk = /*#__PURE__*/_regeneratorRuntime.mark(function streamChunk(chunk, chunkSize) {
3484
3512
  var len, pos, end;
@@ -3778,7 +3806,7 @@ var contentful = (function (exports) {
3778
3806
  }
3779
3807
  return bytes;
3780
3808
  }
3781
- var VERSION = "1.16.0";
3809
+ var VERSION = "1.16.1";
3782
3810
  var DEFAULT_CHUNK_SIZE = 64 * 1024;
3783
3811
  var isFunction = utils$1$1.isFunction;
3784
3812
  var test = function test(fn) {
@@ -3792,8 +3820,7 @@ var contentful = (function (exports) {
3792
3820
  }
3793
3821
  };
3794
3822
  var factory = function factory(env) {
3795
- var _utils$1$global;
3796
- var globalObject = (_utils$1$global = utils$1$1.global) !== null && _utils$1$global !== void 0 ? _utils$1$global : globalThis;
3823
+ var globalObject = utils$1$1.global !== undefined && utils$1$1.global !== null ? utils$1$1.global : globalThis;
3797
3824
  var ReadableStream = globalObject.ReadableStream,
3798
3825
  TextEncoder = globalObject.TextEncoder;
3799
3826
  env = utils$1$1.merge.call({
@@ -4039,7 +4066,7 @@ var contentful = (function (exports) {
4039
4066
  resolvedOptions = _objectSpread$2(_objectSpread$2({}, fetchOptions), {}, {
4040
4067
  signal: composedSignal,
4041
4068
  method: method.toUpperCase(),
4042
- headers: headers.normalize().toJSON(),
4069
+ headers: toByteStringHeaderObject(headers.normalize()),
4043
4070
  body: data,
4044
4071
  duplex: 'half',
4045
4072
  credentials: isCredentialsSupported ? withCredentials : undefined
@@ -10087,8 +10114,13 @@ var contentful = (function (exports) {
10087
10114
  }
10088
10115
  var isValidConfig = isValidTimelinePreviewConfig(timelinePreview);
10089
10116
  // Show error if used outside of CPA.
10090
- // Opt-out of the error if a custom domain is used and CPA could not be idenfified
10091
- var isValidHost = typeof host === 'string' && (!host.includes('contentful') || host.startsWith('preview'));
10117
+ // Opt-out of the error if a custom domain is used and CPA could not be identified.
10118
+ // Use an exact domain match to avoid false-positives on proxy hostnames that contain
10119
+ // "contentful" as a substring (e.g. api-contentful-proxy.example.com).
10120
+ var PREVIEW_HOST_REGEX = /^preview(\.eu)?\.contentful\.com$/;
10121
+ var isContentfulHost = typeof host === 'string' && PREVIEW_HOST_REGEX.test(host);
10122
+ var isCustomHost = typeof host !== 'string' || !host.endsWith('.contentful.com');
10123
+ var isValidHost = isContentfulHost || isCustomHost;
10092
10124
  if (isValidConfig && !isValidHost) {
10093
10125
  throw new ValidationError('timelinePreview', "The 'timelinePreview' parameter can only be used with the CPA. Please set host to 'preview.contentful.com' or 'preview.eu.contentful.com' to enable Timeline Preview.\n ");
10094
10126
  }