@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,60 @@
1
+ import axios from 'axios';
2
+ import { getUserAgentHeader, createHttpClient } from 'contentful-sdk-core';
3
+ import { createGlobalOptions } from './create-global-options.js';
4
+ import { makeClient } from './make-client.js';
5
+ import { validateResolveLinksParam, validateRemoveUnresolvedParam } from './utils/validate-params.js';
6
+
7
+ /**
8
+ * Contentful Delivery API SDK. Allows you to create instances of a client
9
+ * with access to the Contentful Content Delivery API.
10
+ */
11
+ /**
12
+ * Create a client instance
13
+ * @param params - Client initialization parameters
14
+ * @category Client
15
+ * @example
16
+ * ```typescript
17
+ * const contentful = require('contentful')
18
+ * const client = contentful.createClient({
19
+ * accessToken: 'myAccessToken',
20
+ * space: 'mySpaceId'
21
+ * })
22
+ * ```
23
+ */
24
+ function createClient(params) {
25
+ if (!params.accessToken) {
26
+ throw new TypeError('Expected parameter accessToken');
27
+ }
28
+ if (!params.space) {
29
+ throw new TypeError('Expected parameter space');
30
+ }
31
+ validateResolveLinksParam(params);
32
+ validateRemoveUnresolvedParam(params);
33
+ const defaultConfig = {
34
+ resolveLinks: true,
35
+ removeUnresolved: false,
36
+ defaultHostname: 'cdn.contentful.com',
37
+ environment: 'master',
38
+ };
39
+ const config = Object.assign(Object.assign({}, defaultConfig), params);
40
+ const userAgentHeader = getUserAgentHeader(`contentful.js/${"0.0.0-determined-by-semantic-release"}`, config.application, config.integration);
41
+ config.headers = Object.assign(Object.assign({}, config.headers), { 'Content-Type': 'application/vnd.contentful.delivery.v1+json', 'X-Contentful-User-Agent': userAgentHeader });
42
+ const http = createHttpClient(axios, config);
43
+ if (!http.defaults.baseURL) {
44
+ throw new Error('Please define a baseURL');
45
+ }
46
+ const getGlobalOptions = createGlobalOptions({
47
+ space: config.space,
48
+ environment: config.environment,
49
+ spaceBaseUrl: http.defaults.baseURL,
50
+ environmentBaseUrl: `${http.defaults.baseURL}environments/${config.environment}`,
51
+ });
52
+ // Append environment to baseURL
53
+ http.defaults.baseURL = getGlobalOptions({}).environmentBaseUrl;
54
+ return makeClient({
55
+ http,
56
+ getGlobalOptions,
57
+ });
58
+ }
59
+
60
+ export { createClient };
@@ -0,0 +1,463 @@
1
+ import { encodeCPAResponse } from '@contentful/content-source-maps';
2
+ import { createRequestConfig, errorHandler } from 'contentful-sdk-core';
3
+ import pagedSync from './paged-sync.js';
4
+ import normalizeSearchParameters from './utils/normalize-search-parameters.js';
5
+ import normalizeSelect from './utils/normalize-select.js';
6
+ import resolveCircular from './utils/resolve-circular.js';
7
+ import getQuerySelectionSet from './utils/query-selection-set.js';
8
+ import validateTimestamp from './utils/validate-timestamp.js';
9
+ import { validateLocaleParam, validateResolveLinksParam, validateRemoveUnresolvedParam, checkIncludeContentSourceMapsParamIsAllowed } from './utils/validate-params.js';
10
+ import validateSearchParameters from './utils/validate-search-parameters.js';
11
+ import { getTimelinePreviewParams } from './utils/timeline-preview-helpers.js';
12
+ import { normalizeCursorPaginationParameters } from './utils/normalize-cursor-pagination-parameters.js';
13
+ import { normalizeCursorPaginationResponse } from './utils/normalize-cursor-pagination-response.js';
14
+
15
+ /**
16
+ * Contentful Delivery API Client. Contains methods which allow access to the
17
+ * different kinds of entities present in Contentful (Entries, Assets, etc).
18
+ */
19
+ const ASSET_KEY_MAX_LIFETIME = 48 * 60 * 60;
20
+ class NotFoundError extends Error {
21
+ constructor(id, environment, space) {
22
+ super('The resource could not be found.');
23
+ this.sys = {
24
+ type: 'Error',
25
+ id: 'NotFound',
26
+ };
27
+ this.details = {
28
+ type: 'Entry',
29
+ id,
30
+ environment,
31
+ space,
32
+ };
33
+ }
34
+ }
35
+ function createContentfulApi({ http, getGlobalOptions }, options) {
36
+ const notFoundError = (id = 'unknown') => {
37
+ return new NotFoundError(id, getGlobalOptions().environment, getGlobalOptions().space);
38
+ };
39
+ const getBaseUrl = (context) => {
40
+ let baseUrl = context === 'space' ? getGlobalOptions().spaceBaseUrl : getGlobalOptions().environmentBaseUrl;
41
+ if (!baseUrl) {
42
+ throw new Error('Please define baseUrl for ' + context);
43
+ }
44
+ if (!baseUrl.endsWith('/')) {
45
+ baseUrl += '/';
46
+ }
47
+ return baseUrl;
48
+ };
49
+ function maybeEnableSourceMaps(query = {}) {
50
+ var _a, _b;
51
+ const params = http.httpClientParams;
52
+ const includeContentSourceMaps = (_a = params === null || params === void 0 ? void 0 : params.includeContentSourceMaps) !== null && _a !== void 0 ? _a : (_b = params === null || params === void 0 ? void 0 : params.alphaFeatures) === null || _b === void 0 ? void 0 : _b.includeContentSourceMaps;
53
+ const host = params === null || params === void 0 ? void 0 : params.host;
54
+ const areAllowed = checkIncludeContentSourceMapsParamIsAllowed(host, includeContentSourceMaps);
55
+ if (areAllowed) {
56
+ query.includeContentSourceMaps = true;
57
+ // Ensure that content source maps and required attributes are selected
58
+ if (query.select) {
59
+ const selection = getQuerySelectionSet(query);
60
+ selection.add('sys');
61
+ query.select = Array.from(selection).join(',');
62
+ }
63
+ }
64
+ return query;
65
+ }
66
+ function maybeEnableTimelinePreview(path) {
67
+ const { enabled } = getTimelinePreviewParams(http.httpClientParams);
68
+ return enabled ? `timeline/${path}` : path;
69
+ }
70
+ function maybeAddTimelinePreviewConfigToQuery(query) {
71
+ const { enabled, timelinePreview } = getTimelinePreviewParams(http.httpClientParams);
72
+ if (enabled) {
73
+ if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.release) {
74
+ query.release = timelinePreview.release;
75
+ }
76
+ if (timelinePreview === null || timelinePreview === void 0 ? void 0 : timelinePreview.timestamp) {
77
+ query.timestamp = timelinePreview.timestamp;
78
+ }
79
+ }
80
+ return query;
81
+ }
82
+ function maybeEncodeCPAResponse(data, config) {
83
+ var _a;
84
+ const includeContentSourceMaps = (_a = config === null || config === void 0 ? void 0 : config.params) === null || _a === void 0 ? void 0 : _a.includeContentSourceMaps;
85
+ if (includeContentSourceMaps) {
86
+ return encodeCPAResponse(data);
87
+ }
88
+ return data;
89
+ }
90
+ async function get({ context, path, config }) {
91
+ const baseUrl = getBaseUrl(context);
92
+ try {
93
+ const response = await http.get(baseUrl + path, config);
94
+ return maybeEncodeCPAResponse(response.data, config);
95
+ }
96
+ catch (error) {
97
+ errorHandler(error);
98
+ }
99
+ }
100
+ async function post({ context, path, data, config }) {
101
+ const baseUrl = getBaseUrl(context);
102
+ try {
103
+ const response = await http.post(baseUrl + path, data, config);
104
+ return response.data;
105
+ }
106
+ catch (error) {
107
+ errorHandler(error);
108
+ }
109
+ }
110
+ async function getSpace() {
111
+ return get({ context: 'space', path: '' });
112
+ }
113
+ async function getContentType(id) {
114
+ return get({
115
+ context: 'environment',
116
+ path: `content_types/${id}`,
117
+ });
118
+ }
119
+ async function getContentTypes(query = {}) {
120
+ return get({
121
+ context: 'environment',
122
+ path: 'content_types',
123
+ config: createRequestConfig({ query }),
124
+ });
125
+ }
126
+ async function getEntry(id, query = {}) {
127
+ return makeGetEntry(id, query, options);
128
+ }
129
+ async function getEntries(query = {}) {
130
+ return makeGetEntries(query, options);
131
+ }
132
+ async function getEntriesWithCursor(query = {}) {
133
+ const response = await makeGetEntries(normalizeCursorPaginationParameters(query), options);
134
+ return normalizeCursorPaginationResponse(response);
135
+ }
136
+ async function makeGetEntry(id, query, options = {
137
+ withAllLocales: false,
138
+ withoutLinkResolution: false,
139
+ withoutUnresolvableLinks: false,
140
+ }) {
141
+ const { withAllLocales } = options;
142
+ validateLocaleParam(query, withAllLocales);
143
+ validateResolveLinksParam(query);
144
+ validateRemoveUnresolvedParam(query);
145
+ validateSearchParameters(query);
146
+ return internalGetEntry(id, withAllLocales ? Object.assign(Object.assign({}, query), { locale: '*' }) : query, options);
147
+ }
148
+ async function internalGetEntry(id, query, options) {
149
+ if (!id) {
150
+ throw notFoundError(id);
151
+ }
152
+ try {
153
+ const response = await internalGetEntries(Object.assign({ 'sys.id': id }, maybeEnableSourceMaps(query)), options);
154
+ if (response.items.length > 0) {
155
+ return response.items[0];
156
+ }
157
+ else {
158
+ throw notFoundError(id);
159
+ }
160
+ }
161
+ catch (error) {
162
+ errorHandler(error);
163
+ }
164
+ }
165
+ async function makeGetEntries(query, options = {
166
+ withAllLocales: false,
167
+ withoutLinkResolution: false,
168
+ withoutUnresolvableLinks: false,
169
+ }) {
170
+ const { withAllLocales } = options;
171
+ validateLocaleParam(query, withAllLocales);
172
+ validateResolveLinksParam(query);
173
+ validateRemoveUnresolvedParam(query);
174
+ validateSearchParameters(query);
175
+ return internalGetEntries(withAllLocales
176
+ ? Object.assign(Object.assign({}, query), { locale: '*' }) : query, options);
177
+ }
178
+ function prepareQuery(query) {
179
+ // First, add timeline preview config if enabled
180
+ const withTimelinePreview = maybeAddTimelinePreviewConfigToQuery(Object.assign({}, query));
181
+ // Then, apply source maps and other normalizations
182
+ return maybeEnableSourceMaps(normalizeSearchParameters(normalizeSelect(withTimelinePreview)));
183
+ }
184
+ async function internalGetEntries(query, options) {
185
+ const { withoutLinkResolution, withoutUnresolvableLinks } = options;
186
+ try {
187
+ const entries = await get({
188
+ context: 'environment',
189
+ path: maybeEnableTimelinePreview('entries'),
190
+ config: createRequestConfig({
191
+ query: prepareQuery(query),
192
+ }),
193
+ });
194
+ return resolveCircular(entries, {
195
+ resolveLinks: !withoutLinkResolution,
196
+ removeUnresolved: withoutUnresolvableLinks !== null && withoutUnresolvableLinks !== void 0 ? withoutUnresolvableLinks : false,
197
+ });
198
+ }
199
+ catch (error) {
200
+ errorHandler(error);
201
+ }
202
+ }
203
+ async function getAsset(id, query = {}) {
204
+ return makeGetAsset(id, query, options);
205
+ }
206
+ async function getAssets(query = {}) {
207
+ return makeGetAssets(query, options);
208
+ }
209
+ async function getAssetsWithCursor(query = {}) {
210
+ const response = await makeGetAssets(normalizeCursorPaginationParameters(query), options);
211
+ return normalizeCursorPaginationResponse(response);
212
+ }
213
+ async function makeGetAssets(query, options = {
214
+ withAllLocales: false,
215
+ withoutLinkResolution: false,
216
+ withoutUnresolvableLinks: false,
217
+ }) {
218
+ const { withAllLocales } = options;
219
+ validateLocaleParam(query, withAllLocales);
220
+ validateSearchParameters(query);
221
+ const localeSpecificQuery = withAllLocales ? Object.assign(Object.assign({}, query), { locale: '*' }) : query;
222
+ return internalGetAssets(localeSpecificQuery);
223
+ }
224
+ async function internalGetAsset(id, query) {
225
+ try {
226
+ return get({
227
+ context: 'environment',
228
+ path: maybeEnableTimelinePreview(`assets/${id}`),
229
+ config: createRequestConfig({ query: prepareQuery(query) }),
230
+ });
231
+ }
232
+ catch (error) {
233
+ errorHandler(error);
234
+ }
235
+ }
236
+ async function makeGetAsset(id, query, options = {
237
+ withAllLocales: false,
238
+ withoutLinkResolution: false,
239
+ withoutUnresolvableLinks: false,
240
+ }) {
241
+ const { withAllLocales } = options;
242
+ validateLocaleParam(query, withAllLocales);
243
+ validateSearchParameters(query);
244
+ const localeSpecificQuery = withAllLocales ? Object.assign(Object.assign({}, query), { locale: '*' }) : query;
245
+ return internalGetAsset(id, localeSpecificQuery);
246
+ }
247
+ async function internalGetAssets(query) {
248
+ try {
249
+ return get({
250
+ context: 'environment',
251
+ path: maybeEnableTimelinePreview('assets'),
252
+ config: createRequestConfig({
253
+ query: prepareQuery(query),
254
+ }),
255
+ });
256
+ }
257
+ catch (error) {
258
+ errorHandler(error);
259
+ }
260
+ }
261
+ async function getTag(id) {
262
+ return get({
263
+ context: 'environment',
264
+ path: `tags/${id}`,
265
+ });
266
+ }
267
+ async function getTags(query = {}) {
268
+ validateSearchParameters(query);
269
+ return get({
270
+ context: 'environment',
271
+ path: 'tags',
272
+ config: createRequestConfig({ query: normalizeSearchParameters(normalizeSelect(query)) }),
273
+ });
274
+ }
275
+ async function createAssetKey(expiresAt) {
276
+ try {
277
+ const now = Math.floor(Date.now() / 1000);
278
+ const currentMaxLifetime = now + ASSET_KEY_MAX_LIFETIME;
279
+ validateTimestamp('expiresAt', expiresAt, { maximum: currentMaxLifetime, now });
280
+ }
281
+ catch (error) {
282
+ errorHandler(error);
283
+ }
284
+ return post({
285
+ context: 'environment',
286
+ path: 'asset_keys',
287
+ data: { expiresAt },
288
+ });
289
+ }
290
+ async function getLocales(query = {}) {
291
+ validateSearchParameters(query);
292
+ return get({
293
+ context: 'environment',
294
+ path: 'locales',
295
+ config: createRequestConfig({ query: normalizeSelect(query) }),
296
+ });
297
+ }
298
+ async function sync(query, syncOptions = { paginate: true }) {
299
+ return makePagedSync(query, syncOptions, options);
300
+ }
301
+ async function makePagedSync(query, syncOptions, options = {
302
+ withAllLocales: false,
303
+ withoutLinkResolution: false,
304
+ withoutUnresolvableLinks: false,
305
+ }) {
306
+ validateResolveLinksParam(query);
307
+ validateRemoveUnresolvedParam(query);
308
+ const combinedOptions = Object.assign(Object.assign({}, syncOptions), options);
309
+ switchToEnvironment(http);
310
+ return pagedSync(http, query, combinedOptions);
311
+ }
312
+ function parseEntries(data) {
313
+ return makeParseEntries(data, options);
314
+ }
315
+ function makeParseEntries(data, options = {
316
+ withAllLocales: false,
317
+ withoutLinkResolution: false,
318
+ withoutUnresolvableLinks: false,
319
+ }) {
320
+ return internalParseEntries(data, options);
321
+ }
322
+ function internalParseEntries(data, options) {
323
+ const { withoutLinkResolution, withoutUnresolvableLinks } = options;
324
+ return resolveCircular(data, {
325
+ resolveLinks: !withoutLinkResolution,
326
+ removeUnresolved: withoutUnresolvableLinks !== null && withoutUnresolvableLinks !== void 0 ? withoutUnresolvableLinks : false,
327
+ });
328
+ }
329
+ function getConceptScheme(id, query = {}) {
330
+ return internalGetConceptScheme(id, query);
331
+ }
332
+ async function internalGetConceptScheme(id, query = {}) {
333
+ try {
334
+ return get({
335
+ context: 'environment',
336
+ path: `taxonomy/concept-schemes/${id}`,
337
+ config: createRequestConfig({
338
+ query: normalizeSearchParameters(normalizeSelect(query)),
339
+ }),
340
+ });
341
+ }
342
+ catch (error) {
343
+ errorHandler(error);
344
+ }
345
+ }
346
+ function getConceptSchemes(query = {}) {
347
+ return internalGetConceptSchemes(query);
348
+ }
349
+ async function internalGetConceptSchemes(query = {}) {
350
+ try {
351
+ return get({
352
+ context: 'environment',
353
+ path: 'taxonomy/concept-schemes',
354
+ config: createRequestConfig({
355
+ query: normalizeSearchParameters(normalizeSelect(query)),
356
+ }),
357
+ });
358
+ }
359
+ catch (error) {
360
+ errorHandler(error);
361
+ }
362
+ }
363
+ function getConcept(id, query = {}) {
364
+ return internalGetConcept(id, query);
365
+ }
366
+ async function internalGetConcept(id, query = {}) {
367
+ try {
368
+ return get({
369
+ context: 'environment',
370
+ path: `taxonomy/concepts/${id}`,
371
+ config: createRequestConfig({
372
+ query: normalizeSearchParameters(normalizeSelect(query)),
373
+ }),
374
+ });
375
+ }
376
+ catch (error) {
377
+ errorHandler(error);
378
+ }
379
+ }
380
+ function getConcepts(query = {}) {
381
+ return internalGetConcepts(query);
382
+ }
383
+ async function internalGetConcepts(query = {}) {
384
+ try {
385
+ return get({
386
+ context: 'environment',
387
+ path: 'taxonomy/concepts',
388
+ config: createRequestConfig({
389
+ query: normalizeSearchParameters(normalizeSelect(query)),
390
+ }),
391
+ });
392
+ }
393
+ catch (error) {
394
+ errorHandler(error);
395
+ }
396
+ }
397
+ function getConceptAncestors(id, query = {}) {
398
+ return internalGetConceptAncestors(id, query);
399
+ }
400
+ async function internalGetConceptAncestors(id, query = {}) {
401
+ try {
402
+ return get({
403
+ context: 'environment',
404
+ path: `taxonomy/concepts/${id}/ancestors`,
405
+ config: createRequestConfig({
406
+ query: normalizeSearchParameters(normalizeSelect(query)),
407
+ }),
408
+ });
409
+ }
410
+ catch (error) {
411
+ errorHandler(error);
412
+ }
413
+ }
414
+ function getConceptDescendants(id, query = {}) {
415
+ return internalGetConceptDescendants(id, query);
416
+ }
417
+ async function internalGetConceptDescendants(id, query = {}) {
418
+ try {
419
+ return get({
420
+ context: 'environment',
421
+ path: `taxonomy/concepts/${id}/descendants`,
422
+ config: createRequestConfig({
423
+ query: normalizeSearchParameters(normalizeSelect(query)),
424
+ }),
425
+ });
426
+ }
427
+ catch (error) {
428
+ errorHandler(error);
429
+ }
430
+ }
431
+ /*
432
+ * Switches BaseURL to use /environments path
433
+ * */
434
+ function switchToEnvironment(http) {
435
+ http.defaults.baseURL = getGlobalOptions().environmentBaseUrl;
436
+ }
437
+ return {
438
+ version: "0.0.0-determined-by-semantic-release",
439
+ getSpace,
440
+ getContentType,
441
+ getContentTypes,
442
+ getAsset,
443
+ getAssets,
444
+ getAssetsWithCursor,
445
+ getTag,
446
+ getTags,
447
+ getLocales,
448
+ parseEntries,
449
+ sync,
450
+ getEntry,
451
+ getEntries,
452
+ getEntriesWithCursor,
453
+ getConceptScheme,
454
+ getConceptSchemes,
455
+ getConcept,
456
+ getConcepts,
457
+ getConceptAncestors,
458
+ getConceptDescendants,
459
+ createAssetKey,
460
+ };
461
+ }
462
+
463
+ export { createContentfulApi as default };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @param globalSettings - Global library settings
3
+ * @returns getGlobalSettings - Method returning client settings
4
+ * @category Client
5
+ */
6
+ function createGlobalOptions(globalSettings) {
7
+ /**
8
+ * Method merging pre-configured global options and provided local parameters
9
+ * @param query - regular query object used for collection endpoints
10
+ * @param query.environment - optional name of the environment
11
+ * @param query.space - optional space ID
12
+ * @param query.spaceBaseUrl - optional base URL for the space
13
+ * @param query.environmentBaseUrl - optional base URL for the environment
14
+ * @returns global options
15
+ */
16
+ return function getGlobalOptions(query) {
17
+ return Object.assign({}, globalSettings, query);
18
+ };
19
+ }
20
+
21
+ export { createGlobalOptions };
@@ -0,0 +1,4 @@
1
+ export { createClient } from './contentful.js';
2
+ export { createGlobalOptions } from './create-global-options.js';
3
+ import 'json-stringify-safe';
4
+ import 'contentful-resolve-response';
@@ -0,0 +1,52 @@
1
+ import createContentfulApi from './create-contentful-api.js';
2
+
3
+ function create({ http, getGlobalOptions }, options, makeInnerClient) {
4
+ const client = createContentfulApi({
5
+ http,
6
+ getGlobalOptions,
7
+ }, options);
8
+ const response = client ? client : {};
9
+ Object.defineProperty(response, 'withAllLocales', {
10
+ get: () => makeInnerClient(Object.assign(Object.assign({}, options), { withAllLocales: true })),
11
+ });
12
+ Object.defineProperty(response, 'withoutLinkResolution', {
13
+ get: () => makeInnerClient(Object.assign(Object.assign({}, options), { withoutLinkResolution: true })),
14
+ });
15
+ Object.defineProperty(response, 'withoutUnresolvableLinks', {
16
+ get: () => makeInnerClient(Object.assign(Object.assign({}, options), { withoutUnresolvableLinks: true })),
17
+ });
18
+ return Object.create(response);
19
+ }
20
+ const makeClient = ({ http, getGlobalOptions, }) => {
21
+ function makeInnerClient(options) {
22
+ return create({ http, getGlobalOptions }, options, makeInnerClient);
23
+ }
24
+ const client = createContentfulApi({ http, getGlobalOptions }, {
25
+ withoutLinkResolution: false,
26
+ withAllLocales: false,
27
+ withoutUnresolvableLinks: false,
28
+ });
29
+ return Object.assign(Object.assign({}, client), { get withAllLocales() {
30
+ return makeInnerClient({
31
+ withAllLocales: true,
32
+ withoutLinkResolution: false,
33
+ withoutUnresolvableLinks: false,
34
+ });
35
+ },
36
+ get withoutLinkResolution() {
37
+ return makeInnerClient({
38
+ withAllLocales: false,
39
+ withoutLinkResolution: true,
40
+ withoutUnresolvableLinks: false,
41
+ });
42
+ },
43
+ get withoutUnresolvableLinks() {
44
+ return makeInnerClient({
45
+ withAllLocales: false,
46
+ withoutLinkResolution: false,
47
+ withoutUnresolvableLinks: true,
48
+ });
49
+ } });
50
+ };
51
+
52
+ export { makeClient };
@@ -0,0 +1,23 @@
1
+ import jsonStringifySafe from 'json-stringify-safe';
2
+
3
+ function mixinStringifySafe(data) {
4
+ return Object.defineProperty(data, 'stringifySafe', {
5
+ enumerable: false,
6
+ configurable: false,
7
+ writable: false,
8
+ value: function (serializer = null, indent = '') {
9
+ return jsonStringifySafe(this, serializer, indent, (key, value) => {
10
+ return {
11
+ sys: {
12
+ type: 'Link',
13
+ linkType: 'Entry',
14
+ id: value.sys.id,
15
+ circular: true,
16
+ },
17
+ };
18
+ });
19
+ },
20
+ });
21
+ }
22
+
23
+ export { mixinStringifySafe as default };