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.
- package/README.md +37 -30
- package/dist/contentful.browser.js +72 -8
- package/dist/contentful.browser.min.js +1 -1
- package/dist/contentful.cjs +75 -8
- package/dist/esm/contentful.js +1 -1
- package/dist/esm/create-contentful-api.js +30 -7
- package/dist/esm/utils/timeline-preview-helpers.js +33 -0
- package/dist/esm/utils/validate-params.js +14 -1
- package/dist/stats-browser-min.html +1 -1
- package/dist/types/contentful.d.ts +7 -0
- package/dist/types/types/concept.d.ts +1 -0
- package/dist/types/types/link.d.ts +1 -1
- package/dist/types/types/timeline-preview.d.ts +16 -0
- package/dist/types/utils/timeline-preview-helpers.d.ts +7 -0
- package/dist/types/utils/validate-params.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
<h3 align="center">Javascript</h3>
|
|
12
12
|
|
|
13
13
|
<p align="center">
|
|
14
|
-
<a href="README.md">Readme</a> ·
|
|
15
|
-
<a href="MIGRATION.md">Migration</a> ·
|
|
16
|
-
<a href="ADVANCED.md">Advanced</a> ·
|
|
17
|
-
<a href="TYPESCRIPT.md">TypeScript</a> ·
|
|
14
|
+
<a href="README.md">Readme</a> ·
|
|
15
|
+
<a href="MIGRATION.md">Migration</a> ·
|
|
16
|
+
<a href="ADVANCED.md">Advanced</a> ·
|
|
17
|
+
<a href="TYPESCRIPT.md">TypeScript</a> ·
|
|
18
18
|
<a href="CONTRIBUTING.md">Contributing</a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
@@ -70,8 +70,8 @@ JavaScript library for the Contentful [Content Delivery API](https://www.content
|
|
|
70
70
|
- [Authentication](#authentication)
|
|
71
71
|
- [Documentation \& References](#documentation--references)
|
|
72
72
|
- [Configuration](#configuration)
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
- [Request configuration options](#request-configuration-options)
|
|
74
|
+
- [Response configuration options](#response-configuration-options)
|
|
75
75
|
- [Client chain modifiers](#client-chain-modifiers)
|
|
76
76
|
- [Entries](#entries)
|
|
77
77
|
- [Example](#example)
|
|
@@ -186,7 +186,7 @@ Check the [releases](https://github.com/contentful/contentful.js/releases) page
|
|
|
186
186
|
The following code snippet is the most basic one you can use to get some content from Contentful with this library:
|
|
187
187
|
|
|
188
188
|
```js
|
|
189
|
-
import * as contentful from
|
|
189
|
+
import * as contentful from 'contentful'
|
|
190
190
|
const client = contentful.createClient({
|
|
191
191
|
// This is the space ID. A space is like a project folder in Contentful terms
|
|
192
192
|
space: 'developer_bookshelf',
|
|
@@ -207,7 +207,7 @@ Check out this [JSFiddle](https://jsfiddle.net/contentful/kefaj4s8/) version of
|
|
|
207
207
|
This library can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:
|
|
208
208
|
|
|
209
209
|
```js
|
|
210
|
-
import * as contentful from
|
|
210
|
+
import * as contentful from 'contentful'
|
|
211
211
|
const client = contentful.createClient({
|
|
212
212
|
space: 'developer_bookshelf',
|
|
213
213
|
accessToken: 'preview_0b7f6x59a0',
|
|
@@ -279,6 +279,28 @@ The configuration options belong to two categories: request config and response
|
|
|
279
279
|
|
|
280
280
|
> :warning: **Response config options** have been **removed** in `v10.0.0` in favor of the new [client chain modifiers](#client-chain-modifiers) approach.
|
|
281
281
|
|
|
282
|
+
### Timeline Preview
|
|
283
|
+
|
|
284
|
+
The Timeline Preview API provides the ability to query content by future date or specific release
|
|
285
|
+
|
|
286
|
+
##### Example
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
import * as contentful from 'contentful'
|
|
290
|
+
const client = contentful.createClient({
|
|
291
|
+
space: 'developer_bookshelf',
|
|
292
|
+
accessToken: 'preview_0b7f6x59a0',
|
|
293
|
+
host: 'preview.contentful.com',
|
|
294
|
+
// either release or timestamp or both can be passed as a valid config
|
|
295
|
+
alphaFeatures: {
|
|
296
|
+
timelinePreview: {
|
|
297
|
+
release: { lte: 'black-friday' },
|
|
298
|
+
timestamp: { lte: '2025-11-29T08:46:15Z' },
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
})
|
|
302
|
+
```
|
|
303
|
+
|
|
282
304
|
### Client chain modifiers
|
|
283
305
|
|
|
284
306
|
> Introduced in `v10.0.0`.
|
|
@@ -332,24 +354,18 @@ const localizedData = {
|
|
|
332
354
|
{
|
|
333
355
|
metadata: { tags: [] },
|
|
334
356
|
sys: {
|
|
335
|
-
space: {
|
|
336
|
-
sys: { type: 'Link', linkType: 'Space', id: 'my-space-id' },
|
|
337
|
-
},
|
|
357
|
+
space: { sys: { type: 'Link', linkType: 'Space', id: 'my-space-id' } },
|
|
338
358
|
id: 'my-zoo',
|
|
339
359
|
type: 'Entry',
|
|
340
360
|
createdAt: '2020-01-01T00:00:00.000Z',
|
|
341
361
|
updatedAt: '2020-01-01T00:00:00.000Z',
|
|
342
|
-
environment: {
|
|
343
|
-
sys: { id: 'master', type: 'Link', linkType: 'Environment' },
|
|
344
|
-
},
|
|
362
|
+
environment: { sys: { id: 'master', type: 'Link', linkType: 'Environment' } },
|
|
345
363
|
revision: 1,
|
|
346
364
|
contentType: { sys: { type: 'Link', linkType: 'ContentType', id: 'zoo' } },
|
|
347
365
|
locale: 'en-US',
|
|
348
366
|
},
|
|
349
367
|
fields: {
|
|
350
|
-
animal: {
|
|
351
|
-
'en-US': { sys: { type: 'Link', linkType: 'Entry', id: 'oink' } },
|
|
352
|
-
},
|
|
368
|
+
animal: { 'en-US': { sys: { type: 'Link', linkType: 'Entry', id: 'oink' } } },
|
|
353
369
|
anotheranimal: {
|
|
354
370
|
'en-US': { sys: { type: 'Link', linkType: 'Entry', id: 'middle-parrot' } },
|
|
355
371
|
},
|
|
@@ -361,28 +377,19 @@ const localizedData = {
|
|
|
361
377
|
{
|
|
362
378
|
metadata: { tags: [] },
|
|
363
379
|
sys: {
|
|
364
|
-
space: {
|
|
365
|
-
sys: { type: 'Link', linkType: 'Space', id: 'my-space-id' },
|
|
366
|
-
},
|
|
380
|
+
space: { sys: { type: 'Link', linkType: 'Space', id: 'my-space-id' } },
|
|
367
381
|
id: 'oink',
|
|
368
382
|
type: 'Entry',
|
|
369
383
|
createdAt: '2020-01-01T00:00:00.000Z',
|
|
370
384
|
updatedAt: '2020-02-01T00:00:00.000Z',
|
|
371
|
-
environment: {
|
|
372
|
-
sys: { id: 'master', type: 'Link', linkType: 'Environment' },
|
|
373
|
-
},
|
|
385
|
+
environment: { sys: { id: 'master', type: 'Link', linkType: 'Environment' } },
|
|
374
386
|
revision: 2,
|
|
375
387
|
contentType: { sys: { type: 'Link', linkType: 'ContentType', id: 'animal' } },
|
|
376
388
|
locale: 'en-US',
|
|
377
389
|
},
|
|
378
390
|
fields: {
|
|
379
|
-
name: {
|
|
380
|
-
|
|
381
|
-
de: 'Schwein',
|
|
382
|
-
},
|
|
383
|
-
friend: {
|
|
384
|
-
'en-US': { sys: { type: 'Link', linkType: 'Entry', id: 'groundhog' } },
|
|
385
|
-
},
|
|
391
|
+
name: { 'en-US': 'Pig', de: 'Schwein' },
|
|
392
|
+
friend: { 'en-US': { sys: { type: 'Link', linkType: 'Entry', id: 'groundhog' } } },
|
|
386
393
|
},
|
|
387
394
|
},
|
|
388
395
|
],
|
|
@@ -9204,6 +9204,34 @@ var contentful = (function (exports) {
|
|
|
9204
9204
|
}
|
|
9205
9205
|
}
|
|
9206
9206
|
|
|
9207
|
+
function isValidRelease(release) {
|
|
9208
|
+
return !!(release && _typeof$2(release) === 'object' && typeof release.lte === 'string');
|
|
9209
|
+
}
|
|
9210
|
+
function isValidTimestamp(timestamp) {
|
|
9211
|
+
return !!(timestamp && _typeof$2(timestamp) === 'object' && (typeof timestamp.lte === 'string' || timestamp.lte instanceof Date));
|
|
9212
|
+
}
|
|
9213
|
+
var isValidTimelinePreviewConfig = function isValidTimelinePreviewConfig(timelinePreview) {
|
|
9214
|
+
if (_typeof$2(timelinePreview) !== 'object' || timelinePreview === null || Array.isArray(timelinePreview)) {
|
|
9215
|
+
throw new ValidationError('timelinePreview', "The 'timelinePreview' parameter must be an object.");
|
|
9216
|
+
}
|
|
9217
|
+
var hasRelease = isValidRelease(timelinePreview.release);
|
|
9218
|
+
var hasTimestamp = isValidTimestamp(timelinePreview.timestamp);
|
|
9219
|
+
if (!hasRelease && !hasTimestamp) {
|
|
9220
|
+
throw new ValidationError('timelinePreview', "The 'timelinePreview' object must have at least one of 'release' or 'timestamp' with a valid 'lte' property.");
|
|
9221
|
+
}
|
|
9222
|
+
return hasRelease || hasTimestamp;
|
|
9223
|
+
};
|
|
9224
|
+
var getTimelinePreviewParams = function getTimelinePreviewParams(params) {
|
|
9225
|
+
var _a;
|
|
9226
|
+
var host = params === null || params === void 0 ? void 0 : params.host;
|
|
9227
|
+
var timelinePreview = (_a = params === null || params === void 0 ? void 0 : params.alphaFeatures) === null || _a === void 0 ? void 0 : _a.timelinePreview;
|
|
9228
|
+
var enabled = checkEnableTimelinePreviewIsAllowed(host, timelinePreview);
|
|
9229
|
+
return {
|
|
9230
|
+
enabled: enabled,
|
|
9231
|
+
timelinePreview: timelinePreview
|
|
9232
|
+
};
|
|
9233
|
+
};
|
|
9234
|
+
|
|
9207
9235
|
function checkLocaleParamIsAll(query) {
|
|
9208
9236
|
if (query.locale === '*') {
|
|
9209
9237
|
throw new ValidationError('locale', "The use of locale='*' is no longer supported.To fetch an entry in all existing locales,\n use client.withAllLocales instead of the locale='*' parameter.");
|
|
@@ -9247,6 +9275,17 @@ var contentful = (function (exports) {
|
|
|
9247
9275
|
}
|
|
9248
9276
|
return includeContentSourceMaps;
|
|
9249
9277
|
}
|
|
9278
|
+
function checkEnableTimelinePreviewIsAllowed(host, timelinePreview) {
|
|
9279
|
+
if (timelinePreview === undefined) {
|
|
9280
|
+
return false;
|
|
9281
|
+
}
|
|
9282
|
+
var isValidConfig = isValidTimelinePreviewConfig(timelinePreview);
|
|
9283
|
+
var isValidHost = typeof host === 'string' && host.startsWith('preview');
|
|
9284
|
+
if (isValidConfig && !isValidHost) {
|
|
9285
|
+
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.\n ");
|
|
9286
|
+
}
|
|
9287
|
+
return true;
|
|
9288
|
+
}
|
|
9250
9289
|
|
|
9251
9290
|
function validateSearchParameters(query) {
|
|
9252
9291
|
for (var key in query) {
|
|
@@ -9316,6 +9355,25 @@ var contentful = (function (exports) {
|
|
|
9316
9355
|
}
|
|
9317
9356
|
return query;
|
|
9318
9357
|
}
|
|
9358
|
+
function maybeEnableTimelinePreview(path) {
|
|
9359
|
+
var _getTimelinePreviewPa = getTimelinePreviewParams(http.httpClientParams),
|
|
9360
|
+
enabled = _getTimelinePreviewPa.enabled;
|
|
9361
|
+
return enabled ? "timeline/".concat(path) : path;
|
|
9362
|
+
}
|
|
9363
|
+
function maybeAddTimelinePreviewConfigToQuery(query) {
|
|
9364
|
+
var _getTimelinePreviewPa2 = getTimelinePreviewParams(http.httpClientParams),
|
|
9365
|
+
enabled = _getTimelinePreviewPa2.enabled,
|
|
9366
|
+
timelinePreview = _getTimelinePreviewPa2.timelinePreview;
|
|
9367
|
+
if (enabled) {
|
|
9368
|
+
if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.release) {
|
|
9369
|
+
query.release = timelinePreview.release;
|
|
9370
|
+
}
|
|
9371
|
+
if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.timestamp) {
|
|
9372
|
+
query.timestamp = timelinePreview.timestamp;
|
|
9373
|
+
}
|
|
9374
|
+
}
|
|
9375
|
+
return query;
|
|
9376
|
+
}
|
|
9319
9377
|
function maybeEncodeCPAResponse(data, config) {
|
|
9320
9378
|
var _a;
|
|
9321
9379
|
var includeContentSourceMaps = (_a = config === null || config === void 0 ? void 0 : config.params) === null || _a === void 0 ? void 0 : _a.includeContentSourceMaps;
|
|
@@ -9596,6 +9654,12 @@ var contentful = (function (exports) {
|
|
|
9596
9654
|
}));
|
|
9597
9655
|
return _makeGetEntries.apply(this, arguments);
|
|
9598
9656
|
}
|
|
9657
|
+
function prepareQuery(query) {
|
|
9658
|
+
// First, add timeline preview config if enabled
|
|
9659
|
+
var withTimelinePreview = maybeAddTimelinePreviewConfigToQuery(Object.assign({}, query));
|
|
9660
|
+
// Then, apply source maps and other normalizations
|
|
9661
|
+
return maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(withTimelinePreview)));
|
|
9662
|
+
}
|
|
9599
9663
|
function internalGetEntries(_x11, _x12) {
|
|
9600
9664
|
return _internalGetEntries.apply(this, arguments);
|
|
9601
9665
|
}
|
|
@@ -9610,9 +9674,9 @@ var contentful = (function (exports) {
|
|
|
9610
9674
|
_context11.next = 4;
|
|
9611
9675
|
return get({
|
|
9612
9676
|
context: 'environment',
|
|
9613
|
-
path: 'entries',
|
|
9677
|
+
path: maybeEnableTimelinePreview('entries'),
|
|
9614
9678
|
config: createRequestConfig({
|
|
9615
|
-
query:
|
|
9679
|
+
query: prepareQuery(query)
|
|
9616
9680
|
})
|
|
9617
9681
|
});
|
|
9618
9682
|
case 4:
|
|
@@ -9716,9 +9780,9 @@ var contentful = (function (exports) {
|
|
|
9716
9780
|
_context15.prev = 0;
|
|
9717
9781
|
return _context15.abrupt("return", get({
|
|
9718
9782
|
context: 'environment',
|
|
9719
|
-
path: "assets/".concat(id),
|
|
9783
|
+
path: maybeEnableTimelinePreview("assets/".concat(id)),
|
|
9720
9784
|
config: createRequestConfig({
|
|
9721
|
-
query:
|
|
9785
|
+
query: prepareQuery(query)
|
|
9722
9786
|
})
|
|
9723
9787
|
}));
|
|
9724
9788
|
case 4:
|
|
@@ -9776,9 +9840,9 @@ var contentful = (function (exports) {
|
|
|
9776
9840
|
_context17.prev = 0;
|
|
9777
9841
|
return _context17.abrupt("return", get({
|
|
9778
9842
|
context: 'environment',
|
|
9779
|
-
path: 'assets',
|
|
9843
|
+
path: maybeEnableTimelinePreview('assets'),
|
|
9780
9844
|
config: createRequestConfig({
|
|
9781
|
-
query:
|
|
9845
|
+
query: prepareQuery(query)
|
|
9782
9846
|
})
|
|
9783
9847
|
}));
|
|
9784
9848
|
case 4:
|
|
@@ -10117,7 +10181,7 @@ var contentful = (function (exports) {
|
|
|
10117
10181
|
http.defaults.baseURL = getGlobalOptions().environmentBaseUrl;
|
|
10118
10182
|
}
|
|
10119
10183
|
return {
|
|
10120
|
-
version: "11.
|
|
10184
|
+
version: "11.7.0",
|
|
10121
10185
|
getSpace: getSpace,
|
|
10122
10186
|
getContentType: getContentType,
|
|
10123
10187
|
getContentTypes: getContentTypes,
|
|
@@ -10244,7 +10308,7 @@ var contentful = (function (exports) {
|
|
|
10244
10308
|
environment: 'master'
|
|
10245
10309
|
};
|
|
10246
10310
|
var config = Object.assign(Object.assign({}, defaultConfig), params);
|
|
10247
|
-
var userAgentHeader = getUserAgentHeader("contentful.js/".concat("11.
|
|
10311
|
+
var userAgentHeader = getUserAgentHeader("contentful.js/".concat("11.7.0"), config.application, config.integration);
|
|
10248
10312
|
config.headers = Object.assign(Object.assign({}, config.headers), {
|
|
10249
10313
|
'Content-Type': 'application/vnd.contentful.delivery.v1+json',
|
|
10250
10314
|
'X-Contentful-User-Agent': userAgentHeader
|