contentful 11.5.25 → 11.7.0

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.
@@ -22545,6 +22545,34 @@ function validateTimestamp(name, timestamp, options) {
22545
22545
  }
22546
22546
  }
22547
22547
 
22548
+ function isValidRelease(release) {
22549
+ return !!(release && typeof release === 'object' && typeof release.lte === 'string');
22550
+ }
22551
+ function isValidTimestamp(timestamp) {
22552
+ return !!(timestamp && typeof timestamp === 'object' && (typeof timestamp.lte === 'string' || timestamp.lte instanceof Date));
22553
+ }
22554
+ const isValidTimelinePreviewConfig = timelinePreview => {
22555
+ if (typeof timelinePreview !== 'object' || timelinePreview === null || Array.isArray(timelinePreview)) {
22556
+ throw new ValidationError('timelinePreview', `The 'timelinePreview' parameter must be an object.`);
22557
+ }
22558
+ const hasRelease = isValidRelease(timelinePreview.release);
22559
+ const hasTimestamp = isValidTimestamp(timelinePreview.timestamp);
22560
+ if (!hasRelease && !hasTimestamp) {
22561
+ throw new ValidationError('timelinePreview', `The 'timelinePreview' object must have at least one of 'release' or 'timestamp' with a valid 'lte' property.`);
22562
+ }
22563
+ return hasRelease || hasTimestamp;
22564
+ };
22565
+ const getTimelinePreviewParams = params => {
22566
+ var _a;
22567
+ const host = params === null || params === void 0 ? void 0 : params.host;
22568
+ const timelinePreview = (_a = params === null || params === void 0 ? void 0 : params.alphaFeatures) === null || _a === void 0 ? void 0 : _a.timelinePreview;
22569
+ const enabled = checkEnableTimelinePreviewIsAllowed(host, timelinePreview);
22570
+ return {
22571
+ enabled,
22572
+ timelinePreview
22573
+ };
22574
+ };
22575
+
22548
22576
  function checkLocaleParamIsAll(query) {
22549
22577
  if (query.locale === '*') {
22550
22578
  throw new ValidationError('locale', `The use of locale='*' is no longer supported.To fetch an entry in all existing locales,
@@ -22592,6 +22620,18 @@ function checkIncludeContentSourceMapsParamIsAllowed(host, includeContentSourceM
22592
22620
  }
22593
22621
  return includeContentSourceMaps;
22594
22622
  }
22623
+ function checkEnableTimelinePreviewIsAllowed(host, timelinePreview) {
22624
+ if (timelinePreview === undefined) {
22625
+ return false;
22626
+ }
22627
+ const isValidConfig = isValidTimelinePreviewConfig(timelinePreview);
22628
+ const isValidHost = typeof host === 'string' && host.startsWith('preview');
22629
+ if (isValidConfig && !isValidHost) {
22630
+ throw new ValidationError('timelinePreview', `The 'timelinePreview' parameter can only be used with the CPA. Please set host to 'preview.contentful.com' to enable Timeline Preview.
22631
+ `);
22632
+ }
22633
+ return true;
22634
+ }
22595
22635
 
22596
22636
  function validateSearchParameters(query) {
22597
22637
  for (const key in query) {
@@ -22657,6 +22697,27 @@ function createContentfulApi({
22657
22697
  }
22658
22698
  return query;
22659
22699
  }
22700
+ function maybeEnableTimelinePreview(path) {
22701
+ const {
22702
+ enabled
22703
+ } = getTimelinePreviewParams(http.httpClientParams);
22704
+ return enabled ? `timeline/${path}` : path;
22705
+ }
22706
+ function maybeAddTimelinePreviewConfigToQuery(query) {
22707
+ const {
22708
+ enabled,
22709
+ timelinePreview
22710
+ } = getTimelinePreviewParams(http.httpClientParams);
22711
+ if (enabled) {
22712
+ if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.release) {
22713
+ query.release = timelinePreview.release;
22714
+ }
22715
+ if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.timestamp) {
22716
+ query.timestamp = timelinePreview.timestamp;
22717
+ }
22718
+ }
22719
+ return query;
22720
+ }
22660
22721
  function maybeEncodeCPAResponse(data, config) {
22661
22722
  var _a;
22662
22723
  const includeContentSourceMaps = (_a = config === null || config === void 0 ? void 0 : config.params) === null || _a === void 0 ? void 0 : _a.includeContentSourceMaps;
@@ -22768,6 +22829,12 @@ function createContentfulApi({
22768
22829
  locale: '*'
22769
22830
  }) : query, options);
22770
22831
  }
22832
+ function prepareQuery(query) {
22833
+ // First, add timeline preview config if enabled
22834
+ const withTimelinePreview = maybeAddTimelinePreviewConfigToQuery(Object.assign({}, query));
22835
+ // Then, apply source maps and other normalizations
22836
+ return maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(withTimelinePreview)));
22837
+ }
22771
22838
  async function internalGetEntries(query, options) {
22772
22839
  const {
22773
22840
  withoutLinkResolution,
@@ -22776,9 +22843,9 @@ function createContentfulApi({
22776
22843
  try {
22777
22844
  const entries = await get({
22778
22845
  context: 'environment',
22779
- path: 'entries',
22846
+ path: maybeEnableTimelinePreview('entries'),
22780
22847
  config: createRequestConfig({
22781
- query: maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(query)))
22848
+ query: prepareQuery(query)
22782
22849
  })
22783
22850
  });
22784
22851
  return resolveCircular(entries, {
@@ -22814,9 +22881,9 @@ function createContentfulApi({
22814
22881
  try {
22815
22882
  return get({
22816
22883
  context: 'environment',
22817
- path: `assets/${id}`,
22884
+ path: maybeEnableTimelinePreview(`assets/${id}`),
22818
22885
  config: createRequestConfig({
22819
- query: maybeEnableSourceMaps(normalizeSelect(query))
22886
+ query: prepareQuery(query)
22820
22887
  })
22821
22888
  });
22822
22889
  } catch (error) {
@@ -22842,9 +22909,9 @@ function createContentfulApi({
22842
22909
  try {
22843
22910
  return get({
22844
22911
  context: 'environment',
22845
- path: 'assets',
22912
+ path: maybeEnableTimelinePreview('assets'),
22846
22913
  config: createRequestConfig({
22847
- query: maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(query)))
22914
+ query: prepareQuery(query)
22848
22915
  })
22849
22916
  });
22850
22917
  } catch (error) {
@@ -23003,7 +23070,7 @@ function createContentfulApi({
23003
23070
  http.defaults.baseURL = getGlobalOptions().environmentBaseUrl;
23004
23071
  }
23005
23072
  return {
23006
- version: "11.5.25",
23073
+ version: "11.7.0",
23007
23074
  getSpace,
23008
23075
  getContentType,
23009
23076
  getContentTypes,
@@ -23126,7 +23193,7 @@ function createClient(params) {
23126
23193
  environment: 'master'
23127
23194
  };
23128
23195
  const config = Object.assign(Object.assign({}, defaultConfig), params);
23129
- const userAgentHeader = getUserAgentHeader(`contentful.js/${"11.5.25"}`, config.application, config.integration);
23196
+ const userAgentHeader = getUserAgentHeader(`contentful.js/${"11.7.0"}`, config.application, config.integration);
23130
23197
  config.headers = Object.assign(Object.assign({}, config.headers), {
23131
23198
  'Content-Type': 'application/vnd.contentful.delivery.v1+json',
23132
23199
  'X-Contentful-User-Agent': userAgentHeader
@@ -37,7 +37,7 @@ function createClient(params) {
37
37
  environment: 'master',
38
38
  };
39
39
  const config = Object.assign(Object.assign({}, defaultConfig), params);
40
- const userAgentHeader = getUserAgentHeader(`contentful.js/${"11.5.25"}`, config.application, config.integration);
40
+ const userAgentHeader = getUserAgentHeader(`contentful.js/${"11.7.0"}`, config.application, config.integration);
41
41
  config.headers = Object.assign(Object.assign({}, config.headers), { 'Content-Type': 'application/vnd.contentful.delivery.v1+json', 'X-Contentful-User-Agent': userAgentHeader });
42
42
  const http = createHttpClient(axios, config);
43
43
  if (!http.defaults.baseURL) {
@@ -8,6 +8,7 @@ import getQuerySelectionSet from './utils/query-selection-set.js';
8
8
  import validateTimestamp from './utils/validate-timestamp.js';
9
9
  import { validateLocaleParam, validateResolveLinksParam, validateRemoveUnresolvedParam, checkIncludeContentSourceMapsParamIsAllowed } from './utils/validate-params.js';
10
10
  import validateSearchParameters from './utils/validate-search-parameters.js';
11
+ import { getTimelinePreviewParams } from './utils/timeline-preview-helpers.js';
11
12
 
12
13
  /**
13
14
  * Contentful Delivery API Client. Contains methods which allow access to the
@@ -60,6 +61,22 @@ function createContentfulApi({ http, getGlobalOptions }, options) {
60
61
  }
61
62
  return query;
62
63
  }
64
+ function maybeEnableTimelinePreview(path) {
65
+ const { enabled } = getTimelinePreviewParams(http.httpClientParams);
66
+ return enabled ? `timeline/${path}` : path;
67
+ }
68
+ function maybeAddTimelinePreviewConfigToQuery(query) {
69
+ const { enabled, timelinePreview } = getTimelinePreviewParams(http.httpClientParams);
70
+ if (enabled) {
71
+ if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.release) {
72
+ query.release = timelinePreview.release;
73
+ }
74
+ if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.timestamp) {
75
+ query.timestamp = timelinePreview.timestamp;
76
+ }
77
+ }
78
+ return query;
79
+ }
63
80
  function maybeEncodeCPAResponse(data, config) {
64
81
  var _a;
65
82
  const includeContentSourceMaps = (_a = config === null || config === void 0 ? void 0 : config.params) === null || _a === void 0 ? void 0 : _a.includeContentSourceMaps;
@@ -152,14 +169,20 @@ function createContentfulApi({ http, getGlobalOptions }, options) {
152
169
  return internalGetEntries(withAllLocales
153
170
  ? Object.assign(Object.assign({}, query), { locale: '*' }) : query, options);
154
171
  }
172
+ function prepareQuery(query) {
173
+ // First, add timeline preview config if enabled
174
+ const withTimelinePreview = maybeAddTimelinePreviewConfigToQuery(Object.assign({}, query));
175
+ // Then, apply source maps and other normalizations
176
+ return maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(withTimelinePreview)));
177
+ }
155
178
  async function internalGetEntries(query, options) {
156
179
  const { withoutLinkResolution, withoutUnresolvableLinks } = options;
157
180
  try {
158
181
  const entries = await get({
159
182
  context: 'environment',
160
- path: 'entries',
183
+ path: maybeEnableTimelinePreview('entries'),
161
184
  config: createRequestConfig({
162
- query: maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(query))),
185
+ query: prepareQuery(query),
163
186
  }),
164
187
  });
165
188
  return resolveCircular(entries, {
@@ -192,8 +215,8 @@ function createContentfulApi({ http, getGlobalOptions }, options) {
192
215
  try {
193
216
  return get({
194
217
  context: 'environment',
195
- path: `assets/${id}`,
196
- config: createRequestConfig({ query: maybeEnableSourceMaps(normalizeSelect(query)) }),
218
+ path: maybeEnableTimelinePreview(`assets/${id}`),
219
+ config: createRequestConfig({ query: prepareQuery(query) }),
197
220
  });
198
221
  }
199
222
  catch (error) {
@@ -215,9 +238,9 @@ function createContentfulApi({ http, getGlobalOptions }, options) {
215
238
  try {
216
239
  return get({
217
240
  context: 'environment',
218
- path: 'assets',
241
+ path: maybeEnableTimelinePreview('assets'),
219
242
  config: createRequestConfig({
220
- query: maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(query))),
243
+ query: prepareQuery(query),
221
244
  }),
222
245
  });
223
246
  }
@@ -368,7 +391,7 @@ function createContentfulApi({ http, getGlobalOptions }, options) {
368
391
  http.defaults.baseURL = getGlobalOptions().environmentBaseUrl;
369
392
  }
370
393
  return {
371
- version: "11.5.25",
394
+ version: "11.7.0",
372
395
  getSpace,
373
396
  getContentType,
374
397
  getContentTypes,
@@ -0,0 +1,33 @@
1
+ import { checkEnableTimelinePreviewIsAllowed } from './validate-params.js';
2
+ import { ValidationError } from './validation-error.js';
3
+
4
+ function isValidRelease(release) {
5
+ return !!(release && typeof release === 'object' && typeof release.lte === 'string');
6
+ }
7
+ function isValidTimestamp(timestamp) {
8
+ return !!(timestamp &&
9
+ typeof timestamp === 'object' &&
10
+ (typeof timestamp.lte === 'string' || timestamp.lte instanceof Date));
11
+ }
12
+ const isValidTimelinePreviewConfig = (timelinePreview) => {
13
+ if (typeof timelinePreview !== 'object' ||
14
+ timelinePreview === null ||
15
+ Array.isArray(timelinePreview)) {
16
+ throw new ValidationError('timelinePreview', `The 'timelinePreview' parameter must be an object.`);
17
+ }
18
+ const hasRelease = isValidRelease(timelinePreview.release);
19
+ const hasTimestamp = isValidTimestamp(timelinePreview.timestamp);
20
+ if (!hasRelease && !hasTimestamp) {
21
+ throw new ValidationError('timelinePreview', `The 'timelinePreview' object must have at least one of 'release' or 'timestamp' with a valid 'lte' property.`);
22
+ }
23
+ return hasRelease || hasTimestamp;
24
+ };
25
+ const getTimelinePreviewParams = (params) => {
26
+ var _a;
27
+ const host = params === null || params === void 0 ? void 0 : params.host;
28
+ const timelinePreview = (_a = params === null || params === void 0 ? void 0 : params.alphaFeatures) === null || _a === void 0 ? void 0 : _a.timelinePreview;
29
+ const enabled = checkEnableTimelinePreviewIsAllowed(host, timelinePreview);
30
+ return { enabled, timelinePreview };
31
+ };
32
+
33
+ export { getTimelinePreviewParams, isValidTimelinePreviewConfig };
@@ -1,3 +1,4 @@
1
+ import { isValidTimelinePreviewConfig } from './timeline-preview-helpers.js';
1
2
  import { ValidationError } from './validation-error.js';
2
3
 
3
4
  function checkLocaleParamIsAll(query) {
@@ -48,5 +49,17 @@ function checkIncludeContentSourceMapsParamIsAllowed(host, includeContentSourceM
48
49
  }
49
50
  return includeContentSourceMaps;
50
51
  }
52
+ function checkEnableTimelinePreviewIsAllowed(host, timelinePreview) {
53
+ if (timelinePreview === undefined) {
54
+ return false;
55
+ }
56
+ const isValidConfig = isValidTimelinePreviewConfig(timelinePreview);
57
+ const isValidHost = typeof host === 'string' && host.startsWith('preview');
58
+ if (isValidConfig && !isValidHost) {
59
+ throw new ValidationError('timelinePreview', `The 'timelinePreview' parameter can only be used with the CPA. Please set host to 'preview.contentful.com' to enable Timeline Preview.
60
+ `);
61
+ }
62
+ return true;
63
+ }
51
64
 
52
- export { checkIncludeContentSourceMapsParamIsAllowed, validateLocaleParam, validateRemoveUnresolvedParam, validateResolveLinksParam };
65
+ export { checkEnableTimelinePreviewIsAllowed, checkIncludeContentSourceMapsParamIsAllowed, validateLocaleParam, validateRemoveUnresolvedParam, validateResolveLinksParam };