contentful 9.2.5 → 9.2.7
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/dist/contentful.browser.js +973 -194
- package/dist/contentful.browser.js.map +1 -1
- package/dist/contentful.browser.min.js +3 -3
- package/dist/contentful.node.js +976 -206
- package/dist/contentful.node.js.map +1 -1
- package/dist/contentful.node.min.js +3 -3
- package/dist/es-modules/contentful.js +4 -16
- package/dist/es-modules/create-contentful-api.js +15 -56
- package/dist/es-modules/create-global-options.js +0 -1
- package/dist/es-modules/entities/asset-key.js +0 -4
- package/dist/es-modules/entities/asset.js +1 -6
- package/dist/es-modules/entities/content-type.js +1 -6
- package/dist/es-modules/entities/entry.js +1 -10
- package/dist/es-modules/entities/index.js +0 -10
- package/dist/es-modules/entities/locale.js +1 -6
- package/dist/es-modules/entities/space.js +0 -2
- package/dist/es-modules/entities/tag.js +1 -6
- package/dist/es-modules/mixins/stringify-safe.js +0 -3
- package/dist/es-modules/paged-sync.js +7 -35
- package/dist/es-modules/utils/normalize-select.js +12 -13
- package/dist/es-modules/utils/validate-timestamp.js +0 -7
- package/package.json +1 -1
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = pagedSync;
|
|
7
|
-
|
|
8
7
|
var _contentfulSdkCore = require("contentful-sdk-core");
|
|
9
|
-
|
|
10
8
|
var _contentfulResolveResponse = _interopRequireDefault(require("contentful-resolve-response"));
|
|
11
|
-
|
|
12
9
|
var _stringifySafe = _interopRequireDefault(require("./mixins/stringify-safe"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
|
|
18
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
|
|
20
13
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* @memberof Sync
|
|
24
16
|
* @typedef SyncCollection
|
|
@@ -58,72 +50,60 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
58
50
|
*/
|
|
59
51
|
async function pagedSync(http, query) {
|
|
60
52
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
61
|
-
|
|
62
53
|
if (!query || !query.initial && !query.nextSyncToken && !query.nextPageToken) {
|
|
63
54
|
throw new Error('Please provide one of `initial`, `nextSyncToken` or `nextPageToken` parameters for syncing');
|
|
64
55
|
}
|
|
65
|
-
|
|
66
56
|
if (query && query.content_type && !query.type) {
|
|
67
57
|
query.type = 'Entry';
|
|
68
58
|
} else if (query && query.content_type && query.type && query.type !== 'Entry') {
|
|
69
59
|
throw new Error('When using the `content_type` filter your `type` parameter cannot be different from `Entry`.');
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
const defaultOptions = {
|
|
73
62
|
resolveLinks: true,
|
|
74
63
|
removeUnresolved: false,
|
|
75
64
|
paginate: true
|
|
76
65
|
};
|
|
77
|
-
|
|
78
66
|
const {
|
|
79
67
|
resolveLinks,
|
|
80
68
|
removeUnresolved,
|
|
81
69
|
paginate
|
|
82
70
|
} = _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
83
|
-
|
|
84
71
|
const syncOptions = {
|
|
85
72
|
paginate
|
|
86
73
|
};
|
|
87
|
-
const response = await getSyncPage(http, [], query, syncOptions);
|
|
88
|
-
|
|
74
|
+
const response = await getSyncPage(http, [], query, syncOptions);
|
|
75
|
+
// clones response.items used in includes because we don't want these to be mutated
|
|
89
76
|
if (resolveLinks) {
|
|
90
77
|
response.items = (0, _contentfulResolveResponse.default)(response, {
|
|
91
78
|
removeUnresolved,
|
|
92
79
|
itemEntryPoints: ['fields']
|
|
93
80
|
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
}
|
|
82
|
+
// maps response items again after getters are attached
|
|
97
83
|
const mappedResponseItems = mapResponseItems(response.items);
|
|
98
|
-
|
|
99
84
|
if (response.nextSyncToken) {
|
|
100
85
|
mappedResponseItems.nextSyncToken = response.nextSyncToken;
|
|
101
86
|
}
|
|
102
|
-
|
|
103
87
|
if (response.nextPageToken) {
|
|
104
88
|
mappedResponseItems.nextPageToken = response.nextPageToken;
|
|
105
89
|
}
|
|
106
|
-
|
|
107
90
|
return (0, _contentfulSdkCore.freezeSys)((0, _stringifySafe.default)((0, _contentfulSdkCore.toPlainObject)(mappedResponseItems)));
|
|
108
91
|
}
|
|
92
|
+
|
|
109
93
|
/**
|
|
110
94
|
* @private
|
|
111
95
|
* @param {Array<Entities.Entry|Entities.Array|Sync.DeletedEntry|Sync.DeletedAsset>} items
|
|
112
96
|
* @return {Object} Entities mapped to an object for each entity type
|
|
113
97
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
98
|
function mapResponseItems(items) {
|
|
117
99
|
const reducer = type => {
|
|
118
100
|
return (accumulated, item) => {
|
|
119
101
|
if (item.sys.type === type) {
|
|
120
102
|
accumulated.push((0, _contentfulSdkCore.toPlainObject)(item));
|
|
121
103
|
}
|
|
122
|
-
|
|
123
104
|
return accumulated;
|
|
124
105
|
};
|
|
125
106
|
};
|
|
126
|
-
|
|
127
107
|
return {
|
|
128
108
|
entries: items.reduce(reducer('Entry'), []),
|
|
129
109
|
assets: items.reduce(reducer('Asset'), []),
|
|
@@ -131,6 +111,7 @@ function mapResponseItems(items) {
|
|
|
131
111
|
deletedAssets: items.reduce(reducer('DeletedAsset'), [])
|
|
132
112
|
};
|
|
133
113
|
}
|
|
114
|
+
|
|
134
115
|
/**
|
|
135
116
|
* If the response contains a nextPageUrl, extracts the sync token to get the
|
|
136
117
|
* next page and calls itself again with that token.
|
|
@@ -146,36 +127,29 @@ function mapResponseItems(items) {
|
|
|
146
127
|
* @param {boolean} [options.paginate = true] - If further sync pages should automatically be crawled
|
|
147
128
|
* @return {Promise<{items: Array, nextSyncToken: string}>}
|
|
148
129
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
130
|
async function getSyncPage(http, items, query, _ref) {
|
|
152
131
|
let {
|
|
153
132
|
paginate
|
|
154
133
|
} = _ref;
|
|
155
|
-
|
|
156
134
|
if (query.nextSyncToken) {
|
|
157
135
|
query.sync_token = query.nextSyncToken;
|
|
158
136
|
delete query.nextSyncToken;
|
|
159
137
|
}
|
|
160
|
-
|
|
161
138
|
if (query.nextPageToken) {
|
|
162
139
|
query.sync_token = query.nextPageToken;
|
|
163
140
|
delete query.nextPageToken;
|
|
164
141
|
}
|
|
165
|
-
|
|
166
142
|
if (query.sync_token) {
|
|
167
143
|
delete query.initial;
|
|
168
144
|
delete query.type;
|
|
169
145
|
delete query.content_type;
|
|
170
146
|
delete query.limit;
|
|
171
147
|
}
|
|
172
|
-
|
|
173
148
|
const response = await http.get('sync', (0, _contentfulSdkCore.createRequestConfig)({
|
|
174
149
|
query: query
|
|
175
150
|
}));
|
|
176
151
|
const data = response.data || {};
|
|
177
152
|
items = items.concat(data.items || []);
|
|
178
|
-
|
|
179
153
|
if (data.nextPageUrl) {
|
|
180
154
|
if (paginate) {
|
|
181
155
|
delete query.initial;
|
|
@@ -184,7 +158,6 @@ async function getSyncPage(http, items, query, _ref) {
|
|
|
184
158
|
paginate
|
|
185
159
|
});
|
|
186
160
|
}
|
|
187
|
-
|
|
188
161
|
return {
|
|
189
162
|
items: items,
|
|
190
163
|
nextPageToken: getToken(data.nextPageUrl)
|
|
@@ -200,12 +173,11 @@ async function getSyncPage(http, items, query, _ref) {
|
|
|
200
173
|
};
|
|
201
174
|
}
|
|
202
175
|
}
|
|
176
|
+
|
|
203
177
|
/**
|
|
204
178
|
* Extracts token out of an url
|
|
205
179
|
* @private
|
|
206
180
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
181
|
function getToken(url) {
|
|
210
182
|
const urlParts = url.split('?');
|
|
211
183
|
return urlParts.length > 0 ? urlParts[1].replace('sync_token=', '') : '';
|
|
@@ -4,38 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = normalizeSelect;
|
|
7
|
-
|
|
8
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
-
|
|
10
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
-
|
|
12
9
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
|
|
14
10
|
/*
|
|
15
11
|
* sdk relies heavily on sys metadata
|
|
16
12
|
* so we cannot omit the sys property on sdk level entirely
|
|
17
13
|
* and we have to ensure that at least `id` and `type` are present
|
|
18
14
|
* */
|
|
15
|
+
|
|
19
16
|
function normalizeSelect(query) {
|
|
20
17
|
if (!query.select) {
|
|
21
18
|
return query;
|
|
22
|
-
}
|
|
23
|
-
// Get the different parts that are listed for selection
|
|
24
|
-
|
|
19
|
+
}
|
|
25
20
|
|
|
26
|
-
|
|
21
|
+
// The selection of fields for the query is limited
|
|
22
|
+
// Get the different parts that are listed for selection
|
|
23
|
+
const allSelects = Array.isArray(query.select) ? query.select : query.select.split(',');
|
|
24
|
+
// Move the parts into a set for easy access and deduplication
|
|
25
|
+
const selectedSet = new Set(allSelects);
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
// If we already select all of `sys` we can just return
|
|
29
28
|
// since we're anyway fetching everything that is needed
|
|
30
|
-
|
|
31
29
|
if (selectedSet.has('sys')) {
|
|
32
30
|
return query;
|
|
33
|
-
}
|
|
34
|
-
|
|
31
|
+
}
|
|
35
32
|
|
|
33
|
+
// We don't select `sys` so we need to ensure the minimum set
|
|
36
34
|
selectedSet.add('sys.id');
|
|
37
|
-
selectedSet.add('sys.type');
|
|
35
|
+
selectedSet.add('sys.type');
|
|
38
36
|
|
|
37
|
+
// Reassign the normalized sys properties
|
|
39
38
|
return _objectSpread(_objectSpread({}, query), {}, {
|
|
40
39
|
select: [...selectedSet].join(',')
|
|
41
40
|
});
|
|
@@ -5,28 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ValidationError = void 0;
|
|
7
7
|
exports.default = validateTimestamp;
|
|
8
|
-
|
|
9
8
|
class ValidationError extends Error {
|
|
10
9
|
constructor(name, message) {
|
|
11
10
|
super(`Invalid "${name}" provided, ` + message);
|
|
12
11
|
this.name = 'ValidationError';
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
exports.ValidationError = ValidationError;
|
|
18
|
-
|
|
19
15
|
function validateTimestamp(name, timestamp, options) {
|
|
20
16
|
options = options || {};
|
|
21
|
-
|
|
22
17
|
if (typeof timestamp !== 'number') {
|
|
23
18
|
throw new ValidationError(name, `only numeric values are allowed for timestamps, provided type was "${typeof timestamp}"`);
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
if (options.maximum && timestamp > options.maximum) {
|
|
27
21
|
throw new ValidationError(name, `value (${timestamp}) cannot be further in the future than expected maximum (${options.maximum})`);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
if (options.now && timestamp < options.now) {
|
|
31
24
|
throw new ValidationError(name, `value (${timestamp}) cannot be in the past, current time was ${options.now}`);
|
|
32
25
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "contentful",
|
|
3
3
|
"description": "Client for Contentful's Content Delivery API",
|
|
4
|
-
"version": "9.2.
|
|
4
|
+
"version": "9.2.7",
|
|
5
5
|
"homepage": "https://www.contentful.com/developers/documentation/content-delivery-api/",
|
|
6
6
|
"main": "./dist/contentful.node.js",
|
|
7
7
|
"module": "./dist/es-modules/contentful.js",
|