@depup/contentful 11.10.7-depup.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.
Files changed (83) hide show
  1. package/ADVANCED.md +283 -0
  2. package/CONTRIBUTING.md +109 -0
  3. package/LICENSE +21 -0
  4. package/MIGRATION.md +364 -0
  5. package/README.md +36 -0
  6. package/TYPESCRIPT.md +329 -0
  7. package/changes.json +30 -0
  8. package/dist/contentful.browser.js +10886 -0
  9. package/dist/contentful.browser.min.js +1 -0
  10. package/dist/contentful.cjs +23983 -0
  11. package/dist/esm/contentful.js +60 -0
  12. package/dist/esm/create-contentful-api.js +463 -0
  13. package/dist/esm/create-global-options.js +21 -0
  14. package/dist/esm/index.js +4 -0
  15. package/dist/esm/make-client.js +52 -0
  16. package/dist/esm/mixins/stringify-safe.js +23 -0
  17. package/dist/esm/paged-sync.js +118 -0
  18. package/dist/esm/utils/normalize-cursor-pagination-parameters.js +9 -0
  19. package/dist/esm/utils/normalize-cursor-pagination-response.js +23 -0
  20. package/dist/esm/utils/normalize-search-parameters.js +18 -0
  21. package/dist/esm/utils/normalize-select.js +25 -0
  22. package/dist/esm/utils/query-selection-set.js +14 -0
  23. package/dist/esm/utils/resolve-circular.js +15 -0
  24. package/dist/esm/utils/timeline-preview-helpers.js +33 -0
  25. package/dist/esm/utils/validate-params.js +65 -0
  26. package/dist/esm/utils/validate-search-parameters.js +11 -0
  27. package/dist/esm/utils/validate-timestamp.js +16 -0
  28. package/dist/esm/utils/validation-error.js +8 -0
  29. package/dist/stats-browser-min.html +4949 -0
  30. package/dist/types/contentful.d.ts +150 -0
  31. package/dist/types/create-contentful-api.d.ts +13 -0
  32. package/dist/types/create-global-options.d.ts +19 -0
  33. package/dist/types/index.d.ts +6 -0
  34. package/dist/types/make-client.d.ts +3 -0
  35. package/dist/types/mixins/stringify-safe.d.ts +1 -0
  36. package/dist/types/paged-sync.d.ts +7 -0
  37. package/dist/types/types/asset-key.d.ts +7 -0
  38. package/dist/types/types/asset.d.ts +79 -0
  39. package/dist/types/types/client.d.ts +477 -0
  40. package/dist/types/types/collection.d.ts +42 -0
  41. package/dist/types/types/concept-scheme.d.ts +26 -0
  42. package/dist/types/types/concept.d.ts +51 -0
  43. package/dist/types/types/content-type.d.ts +105 -0
  44. package/dist/types/types/entry.d.ts +246 -0
  45. package/dist/types/types/index.d.ts +17 -0
  46. package/dist/types/types/link.d.ts +61 -0
  47. package/dist/types/types/locale.d.ts +30 -0
  48. package/dist/types/types/metadata.d.ts +13 -0
  49. package/dist/types/types/query/equality.d.ts +29 -0
  50. package/dist/types/types/query/existence.d.ts +15 -0
  51. package/dist/types/types/query/index.d.ts +12 -0
  52. package/dist/types/types/query/location.d.ts +29 -0
  53. package/dist/types/types/query/order.d.ts +44 -0
  54. package/dist/types/types/query/query.d.ts +155 -0
  55. package/dist/types/types/query/range.d.ts +18 -0
  56. package/dist/types/types/query/reference.d.ts +12 -0
  57. package/dist/types/types/query/search.d.ts +17 -0
  58. package/dist/types/types/query/select.d.ts +29 -0
  59. package/dist/types/types/query/set.d.ts +10 -0
  60. package/dist/types/types/query/subset.d.ts +20 -0
  61. package/dist/types/types/query/util.d.ts +32 -0
  62. package/dist/types/types/resource-link.d.ts +9 -0
  63. package/dist/types/types/space.d.ts +20 -0
  64. package/dist/types/types/sync.d.ts +84 -0
  65. package/dist/types/types/sys.d.ts +30 -0
  66. package/dist/types/types/tag.d.ts +32 -0
  67. package/dist/types/types/timeline-preview.d.ts +16 -0
  68. package/dist/types/utils/client-helpers.d.ts +9 -0
  69. package/dist/types/utils/normalize-cursor-pagination-parameters.d.ts +5 -0
  70. package/dist/types/utils/normalize-cursor-pagination-response.d.ts +2 -0
  71. package/dist/types/utils/normalize-search-parameters.d.ts +1 -0
  72. package/dist/types/utils/normalize-select.d.ts +1 -0
  73. package/dist/types/utils/query-selection-set.d.ts +1 -0
  74. package/dist/types/utils/resolve-circular.d.ts +4 -0
  75. package/dist/types/utils/timeline-preview-helpers.d.ts +7 -0
  76. package/dist/types/utils/validate-params.d.ts +6 -0
  77. package/dist/types/utils/validate-search-parameters.d.ts +1 -0
  78. package/dist/types/utils/validate-timestamp.d.ts +6 -0
  79. package/dist/types/utils/validation-error.d.ts +3 -0
  80. package/images/contentful-icon.png +0 -0
  81. package/images/dynamic-query-keys.png +0 -0
  82. package/images/static-query-keys.png +0 -0
  83. package/package.json +221 -0
@@ -0,0 +1,118 @@
1
+ import resolveResponse from 'contentful-resolve-response';
2
+ import { freezeSys, toPlainObject, createRequestConfig } from 'contentful-sdk-core';
3
+ import mixinStringifySafe from './mixins/stringify-safe.js';
4
+
5
+ /**
6
+ * Retrieves all the available pages for a sync operation
7
+ */
8
+ async function pagedSync(http, query, options) {
9
+ if (!query || (!query.initial && !query.nextSyncToken && !query.nextPageToken)) {
10
+ throw new Error('Please provide one of `initial`, `nextSyncToken` or `nextPageToken` parameters for syncing');
11
+ }
12
+ if (query['content_type'] && !query.type) {
13
+ query.type = 'Entry';
14
+ }
15
+ else if (query['content_type'] && query.type && query.type !== 'Entry') {
16
+ throw new Error('When using the `content_type` filter your `type` parameter cannot be different from `Entry`.');
17
+ }
18
+ const defaultOptions = {
19
+ withoutLinkResolution: false,
20
+ withoutUnresolvableLinks: false,
21
+ paginate: true,
22
+ };
23
+ const { withoutLinkResolution, withoutUnresolvableLinks, paginate } = Object.assign(Object.assign({}, defaultOptions), options);
24
+ const response = await getSyncPage(http, [], query, { paginate });
25
+ // clones response.items used in includes because we don't want these to be mutated
26
+ if (!withoutLinkResolution) {
27
+ response.items = resolveResponse(response, {
28
+ removeUnresolved: withoutUnresolvableLinks,
29
+ itemEntryPoints: ['fields'],
30
+ });
31
+ }
32
+ // maps response items again after getters are attached
33
+ const mappedResponseItems = mapResponseItems(response.items);
34
+ if (response.nextSyncToken) {
35
+ mappedResponseItems.nextSyncToken = response.nextSyncToken;
36
+ }
37
+ if (response.nextPageToken) {
38
+ mappedResponseItems.nextPageToken = response.nextPageToken;
39
+ }
40
+ return freezeSys(mixinStringifySafe(toPlainObject(mappedResponseItems)));
41
+ }
42
+ /**
43
+ * @private
44
+ * @param items
45
+ * @returns Entities mapped to an object for each entity type
46
+ */
47
+ function mapResponseItems(items) {
48
+ const reducer = (type) => {
49
+ return (accumulated, item) => {
50
+ if (item.sys.type === type) {
51
+ accumulated.push(toPlainObject(item));
52
+ }
53
+ return accumulated;
54
+ };
55
+ };
56
+ return {
57
+ entries: items.reduce(reducer('Entry'), []),
58
+ assets: items.reduce(reducer('Asset'), []),
59
+ deletedEntries: items.reduce(reducer('DeletedEntry'), []),
60
+ deletedAssets: items.reduce(reducer('DeletedAsset'), []),
61
+ };
62
+ }
63
+ function createRequestQuery(originalQuery) {
64
+ if (originalQuery.nextPageToken) {
65
+ return { sync_token: originalQuery.nextPageToken };
66
+ }
67
+ if (originalQuery.nextSyncToken) {
68
+ return { sync_token: originalQuery.nextSyncToken };
69
+ }
70
+ if (originalQuery.sync_token) {
71
+ return { sync_token: originalQuery.sync_token };
72
+ }
73
+ return originalQuery;
74
+ }
75
+ /**
76
+ * If the response contains a nextPageUrl, extracts the sync token to get the
77
+ * next page and calls itself again with that token.
78
+ * Otherwise, if the response contains a nextSyncUrl, extracts the sync token
79
+ * and returns it.
80
+ * On each call of this function, any retrieved items are collected in the
81
+ * supplied items array, which gets returned in the end.
82
+ */
83
+ async function getSyncPage(http, items, query, { paginate }) {
84
+ const requestQuery = createRequestQuery(query);
85
+ const response = await http.get('sync', createRequestConfig({ query: requestQuery }));
86
+ const data = response.data || {};
87
+ items = items.concat(data.items || []);
88
+ if (data.nextPageUrl) {
89
+ if (paginate) {
90
+ delete requestQuery.initial;
91
+ requestQuery.sync_token = getToken(data.nextPageUrl);
92
+ return getSyncPage(http, items, requestQuery, { paginate });
93
+ }
94
+ return {
95
+ items,
96
+ nextPageToken: getToken(data.nextPageUrl),
97
+ };
98
+ }
99
+ else if (data.nextSyncUrl) {
100
+ return {
101
+ items,
102
+ nextSyncToken: getToken(data.nextSyncUrl),
103
+ };
104
+ }
105
+ else {
106
+ return { items: [] };
107
+ }
108
+ }
109
+ /**
110
+ * Extracts token out of an url
111
+ * @private
112
+ */
113
+ function getToken(url) {
114
+ const urlParts = url.split('?');
115
+ return urlParts.length > 0 ? urlParts[1].replace('sync_token=', '') : '';
116
+ }
117
+
118
+ export { pagedSync as default };
@@ -0,0 +1,9 @@
1
+ import { __rest } from 'tslib';
2
+
3
+ function normalizeCursorPaginationParameters(query) {
4
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
5
+ const { cursor, pagePrev, pageNext, skip } = query, rest = __rest(query, ["cursor", "pagePrev", "pageNext", "skip"]);
6
+ return Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { cursor: true }), (!!pagePrev && { pagePrev })), (!!pageNext && { pageNext }));
7
+ }
8
+
9
+ export { normalizeCursorPaginationParameters };
@@ -0,0 +1,23 @@
1
+ function extractQueryParam(key, url) {
2
+ const queryString = url === null || url === void 0 ? void 0 : url.split('?')[1];
3
+ if (!queryString) {
4
+ return;
5
+ }
6
+ return new URLSearchParams(queryString).get(key);
7
+ }
8
+ const Pages = {
9
+ prev: 'pagePrev',
10
+ next: 'pageNext',
11
+ };
12
+ function normalizeCursorPaginationResponse(response) {
13
+ const pages = {};
14
+ for (const [responseKey, queryKey] of Object.entries(Pages)) {
15
+ const cursorToken = extractQueryParam(queryKey, response.pages[responseKey]);
16
+ if (cursorToken) {
17
+ pages[responseKey] = cursorToken;
18
+ }
19
+ }
20
+ return Object.assign(Object.assign({}, response), { pages });
21
+ }
22
+
23
+ export { normalizeCursorPaginationResponse };
@@ -0,0 +1,18 @@
1
+ function normalizeSearchParameters(query) {
2
+ const convertedQuery = {};
3
+ let hasConverted = false;
4
+ for (const key in query) {
5
+ // We allow multiple values to be passed as arrays
6
+ // which have to be converted to comma-separated strings before being sent to the API
7
+ if (Array.isArray(query[key])) {
8
+ convertedQuery[key] = query[key].join(',');
9
+ hasConverted = true;
10
+ }
11
+ }
12
+ if (hasConverted) {
13
+ return Object.assign(Object.assign({}, query), convertedQuery);
14
+ }
15
+ return query;
16
+ }
17
+
18
+ export { normalizeSearchParameters as default };
@@ -0,0 +1,25 @@
1
+ import getQuerySelectionSet from './query-selection-set.js';
2
+
3
+ /*
4
+ * sdk relies heavily on sys metadata
5
+ * so we cannot omit the sys property on sdk level entirely
6
+ * and we have to ensure that at least `id` and `type` are present
7
+ * */
8
+ function normalizeSelect(query) {
9
+ if (!query.select) {
10
+ return query;
11
+ }
12
+ const selectedSet = getQuerySelectionSet(query);
13
+ // If we already select all of `sys` we can just return
14
+ // since we're anyway fetching everything that is needed
15
+ if (selectedSet.has('sys')) {
16
+ return query;
17
+ }
18
+ // We don't select `sys` so we need to ensure the minimum set
19
+ selectedSet.add('sys.id');
20
+ selectedSet.add('sys.type');
21
+ // Reassign the normalized sys properties
22
+ return Object.assign(Object.assign({}, query), { select: [...selectedSet].join(',') });
23
+ }
24
+
25
+ export { normalizeSelect as default };
@@ -0,0 +1,14 @@
1
+ function getQuerySelectionSet(query) {
2
+ if (!query.select) {
3
+ return new Set();
4
+ }
5
+ // The selection of fields for the query is limited
6
+ // Get the different parts that are listed for selection
7
+ const allSelects = Array.isArray(query.select)
8
+ ? query.select
9
+ : query.select.split(',').map((q) => q.trim());
10
+ // Move the parts into a set for easy access and deduplication
11
+ return new Set(allSelects);
12
+ }
13
+
14
+ export { getQuerySelectionSet as default };
@@ -0,0 +1,15 @@
1
+ import resolveResponse from 'contentful-resolve-response';
2
+ import mixinStringifySafe from '../mixins/stringify-safe.js';
3
+
4
+ function resolveCircular(data, { resolveLinks, removeUnresolved }) {
5
+ const wrappedData = mixinStringifySafe(data);
6
+ if (resolveLinks) {
7
+ wrappedData.items = resolveResponse(wrappedData, {
8
+ removeUnresolved,
9
+ itemEntryPoints: ['fields'],
10
+ });
11
+ }
12
+ return wrappedData;
13
+ }
14
+
15
+ export { resolveCircular as default };
@@ -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, _b;
27
+ const host = params === null || params === void 0 ? void 0 : params.host;
28
+ const timelinePreview = (_a = params === null || params === void 0 ? void 0 : params.timelinePreview) !== null && _a !== void 0 ? _a : (_b = params === null || params === void 0 ? void 0 : params.alphaFeatures) === null || _b === void 0 ? void 0 : _b.timelinePreview;
29
+ const enabled = checkEnableTimelinePreviewIsAllowed(host, timelinePreview);
30
+ return { enabled, timelinePreview };
31
+ };
32
+
33
+ export { getTimelinePreviewParams, isValidTimelinePreviewConfig };
@@ -0,0 +1,65 @@
1
+ import { isValidTimelinePreviewConfig } from './timeline-preview-helpers.js';
2
+ import { ValidationError } from './validation-error.js';
3
+
4
+ function checkLocaleParamIsAll(query) {
5
+ if (query.locale === '*') {
6
+ throw new ValidationError('locale', `The use of locale='*' is no longer supported.To fetch an entry in all existing locales,
7
+ use client.withAllLocales instead of the locale='*' parameter.`);
8
+ }
9
+ }
10
+ function checkLocaleParamExists(query) {
11
+ if (query.locale) {
12
+ throw new ValidationError('locale', 'The `locale` parameter is not allowed');
13
+ }
14
+ }
15
+ function validateLocaleParam(query, isWithAllLocalesClient) {
16
+ if (isWithAllLocalesClient) {
17
+ checkLocaleParamExists(query);
18
+ }
19
+ else {
20
+ checkLocaleParamIsAll(query);
21
+ }
22
+ return;
23
+ }
24
+ function validateResolveLinksParam(query) {
25
+ if ('resolveLinks' in query) {
26
+ throw new ValidationError('resolveLinks', `The use of the 'resolveLinks' parameter is no longer supported. By default, links are resolved.
27
+ If you do not want to resolve links, use client.withoutLinkResolution.`);
28
+ }
29
+ return;
30
+ }
31
+ function validateRemoveUnresolvedParam(query) {
32
+ if ('removeUnresolved' in query) {
33
+ throw new ValidationError('removeUnresolved', `The use of the 'removeUnresolved' parameter is no longer supported. By default, unresolved links are kept as link objects.
34
+ If you do not want to include unresolved links, use client.withoutUnresolvableLinks.`);
35
+ }
36
+ return;
37
+ }
38
+ function checkIncludeContentSourceMapsParamIsAllowed(host, includeContentSourceMaps) {
39
+ if (includeContentSourceMaps === undefined) {
40
+ return false;
41
+ }
42
+ if (typeof includeContentSourceMaps !== 'boolean') {
43
+ throw new ValidationError('includeContentSourceMaps', `The 'includeContentSourceMaps' parameter must be a boolean.`);
44
+ }
45
+ const includeContentSourceMapsIsAllowed = typeof host === 'string' && host.startsWith('preview');
46
+ if (includeContentSourceMaps && !includeContentSourceMapsIsAllowed) {
47
+ throw new ValidationError('includeContentSourceMaps', `The 'includeContentSourceMaps' parameter can only be used with the CPA. Please set host to 'preview.contentful.com' or 'preview.eu.contentful.com' to include Content Source Maps.
48
+ `);
49
+ }
50
+ return includeContentSourceMaps;
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' or 'preview.eu.contentful.com' to enable Timeline Preview.
60
+ `);
61
+ }
62
+ return true;
63
+ }
64
+
65
+ export { checkEnableTimelinePreviewIsAllowed, checkIncludeContentSourceMapsParamIsAllowed, validateLocaleParam, validateRemoveUnresolvedParam, validateResolveLinksParam };
@@ -0,0 +1,11 @@
1
+ function validateSearchParameters(query) {
2
+ for (const key in query) {
3
+ const value = query[key];
4
+ // We don’t allow any objects as values for query parameters
5
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
6
+ throw new Error(`Objects are not supported as value for the "${key}" query parameter.`);
7
+ }
8
+ }
9
+ }
10
+
11
+ export { validateSearchParameters as default };
@@ -0,0 +1,16 @@
1
+ import { ValidationError } from './validation-error.js';
2
+
3
+ function validateTimestamp(name, timestamp, options) {
4
+ options = options || {};
5
+ if (typeof timestamp !== 'number') {
6
+ throw new ValidationError(name, `only numeric values are allowed for timestamps, provided type was "${typeof timestamp}"`);
7
+ }
8
+ if (options.maximum && timestamp > options.maximum) {
9
+ throw new ValidationError(name, `value (${timestamp}) cannot be further in the future than expected maximum (${options.maximum})`);
10
+ }
11
+ if (options.now && timestamp < options.now) {
12
+ throw new ValidationError(name, `value (${timestamp}) cannot be in the past, current time was ${options.now}`);
13
+ }
14
+ }
15
+
16
+ export { validateTimestamp as default };
@@ -0,0 +1,8 @@
1
+ class ValidationError extends Error {
2
+ constructor(name, message) {
3
+ super(`Invalid "${name}" provided, ` + message);
4
+ this.name = 'ValidationError';
5
+ }
6
+ }
7
+
8
+ export { ValidationError };