@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
package/TYPESCRIPT.md ADDED
@@ -0,0 +1,329 @@
1
+ <!-- shared header START -->
2
+
3
+ <p align="center">
4
+ <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/">
5
+ <img alt="Contentful Logo" title="Contentful" src="images/contentful-icon.png" width="150">
6
+ </a>
7
+ </p>
8
+
9
+ <h1 align='center'>Content Delivery API</h1>
10
+
11
+ <h3 align="center">TypeScript</h3>
12
+
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> ·
18
+ <a href="CONTRIBUTING.md">Contributing</a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <a href="https://www.contentful.com/slack/">
23
+ <img src="https://img.shields.io/badge/-Join%20Community%20Slack-2AB27B.svg?logo=slack&maxAge=31557600" alt="Join Contentful Community Slack">
24
+ </a>
25
+ </p>
26
+
27
+ <!-- shared header END -->
28
+
29
+ ## Introduction
30
+
31
+ <a href="LICENSE">
32
+ <img src="https://img.shields.io/badge/license-MIT-brightgreen.svg" alt="MIT License" />
33
+ </a>
34
+ <a href="https://circleci.com/gh/contentful/contentful.js">
35
+ <img src="https://circleci.com/gh/contentful/contentful.js.svg?style=svg" alt="Build Status">
36
+ </a>
37
+ <a href="https://www.npmjs.com/package/contentful">
38
+ <img src="https://img.shields.io/npm/v/contentful.svg" alt="NPM">
39
+ </a>
40
+ <a href="https://www.jsdelivr.com/package/npm/contentful">
41
+ <img src="https://data.jsdelivr.com/v1/package/npm/contentful/badge" alt="jsDelivr Hits">
42
+ </a>
43
+ <a href="https://npm-stat.com/charts.html?package=contentful">
44
+ <img src="https://img.shields.io/npm/dm/contentful.svg" alt="NPM downloads">
45
+ </a>
46
+ <a href="https://unpkg.com/contentful/dist/contentful.browser.min.js">
47
+ <img src="https://img.badgesize.io/https://unpkg.com/contentful/dist/contentful.browser.min.js?compression=gzip" alt="GZIP bundle size">
48
+ </a>
49
+
50
+ With version `10.0.0`, we have completely rewritten the client to give the user more support on types.
51
+
52
+ <details>
53
+ <summary>Table of contents</summary>
54
+ <!-- TOC -->
55
+
56
+ - [Query types](#query-types)
57
+ - [Static query types](#static-query-keys)
58
+ - [Dynamic query types](#dynamic-field-query-keys)
59
+ - [Response types](#response-types)
60
+ - [withAllLocales](#withalllocales)
61
+ - [withoutLinkResolution](#withoutlinkresolution)
62
+ - [withoutUnresolvableLinks](#withoutunresolvablelinks)
63
+ - [Generating type definitions](#generating-type-definitions-for-content-types)
64
+
65
+ <!-- /TOC -->
66
+ </details>
67
+
68
+ ## Query types
69
+
70
+ When querying for entries and assets, you get full type support for keys and values.
71
+ This applies to:
72
+
73
+ - `getEntry`
74
+ - `getEntries`
75
+ - `getAsset`
76
+ - `getAssets`
77
+ - `parseEntries`
78
+ - initial `sync` calls
79
+
80
+ We have 2 levels of support:
81
+
82
+ ### Static query keys
83
+
84
+ Static query keys are not influenced by the shape of the entries or assets you're querying for.
85
+
86
+ ![](images/static-query-keys.png)
87
+
88
+ ```js
89
+ getEntries({
90
+ skip: 10,
91
+ limit: 20,
92
+ include: 5,
93
+ })
94
+ ```
95
+
96
+ ### Dynamic (field) query keys
97
+
98
+ Dynamic query keys are based on the given shape of the expected entries' content type.
99
+
100
+ ![](images/dynamic-query-keys.png)
101
+
102
+ To calculate dynamic keys, we have to provide the shape of the entries:
103
+
104
+ ```typescript
105
+ import * as contentful from 'contentful'
106
+
107
+ type CategoryEntrySkeleton = {
108
+ contentTypeId: 'category'
109
+ fields: {
110
+ categoryName: contentful.EntryFieldTypes.Text
111
+ }
112
+ }
113
+
114
+ type ProductEntrySkeleton = {
115
+ contentTypeId: 'product'
116
+ fields: {
117
+ productName: contentful.EntryFieldTypes.Text
118
+ image: contentful.EntryFieldTypes.AssetLink
119
+ price: contentful.EntryFieldTypes.Number
120
+ categories: contentful.EntryFieldTypes.Array<
121
+ contentful.EntryFieldTypes.EntryLink<CategoryEntrySkeleton>
122
+ >
123
+ location: contentful.EntryFieldTypes.Location
124
+ }
125
+ }
126
+ ```
127
+
128
+ We can then pass this shape to our `getEntries` call. This gives us the relevant information needed to calculate the dynamic keys and their possible value types.
129
+
130
+ ```typescript
131
+ const client = contentful.createClient({
132
+ space: '<space-id>',
133
+ accessToken: '<content-delivery-token>',
134
+ })
135
+
136
+ // content_type query parameter is required when filtering on any field
137
+ client.getEntries<ProductEntrySkeleton>({
138
+ content_type: 'product',
139
+ 'fields.price[gt]': 100,
140
+ })
141
+ ```
142
+
143
+ #### Limitation
144
+
145
+ - To limit the complexity of query types we use a simple type definition for [search on references](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/search-on-references).
146
+ We only check that prefix of the form `fields.reference` matches a reference field called "reference". The rest of the parameter is not evaluated and thus does not provide autocomplete functionality.
147
+
148
+ #### Breaking Change
149
+
150
+ Query types that accept an array of values used to accept them as a comma-separated string which is no longer supported.
151
+ The user must instead provide the original array.
152
+
153
+ The list of query filters that only accept arrays from now on:
154
+
155
+ - `select`
156
+ - `order`
157
+ - `[within]`
158
+ - `[near]`
159
+ - `[in]`
160
+ - `[nin]`
161
+
162
+ Example of the new usage:
163
+
164
+ ```typescript
165
+ client.getEntries<ProductEntrySkeleton>({
166
+ content_type: 'product',
167
+ 'fields.location[near]': [10, 20, 30],
168
+ })
169
+ ```
170
+
171
+ ## Response types
172
+
173
+ With version `10.0.0` we introduce [client chain modifiers](README.md#client-chain-modifiers) to make better assumptions on response types.
174
+ Entries can be returned in six different response shapes. Thanks to the three client modifiers below, the expected return shape can be identified, making it safer to work with the returned data.
175
+
176
+ ### `withAllLocales`
177
+
178
+ If the current chain includes `withAllLocales`, `getAsset` and `getAssets` expect an optional generic parameter for all existing locales in your space. `parseEntries`, `getEntry` and `getEntries` expect an optional second generic parameter.
179
+ If the `Locale` type is provided, your response type will define all locale keys for your field values:
180
+
181
+ ```typescript
182
+ import * as contentful from 'contentful'
183
+
184
+ const client = contentful.createClient({
185
+ space: '<space-id>',
186
+ accessToken: '<content-delivery-token>',
187
+ })
188
+
189
+ type ProductEntrySkeleton = {
190
+ fields: { productName: contentful.EntryFieldTypes.Text }
191
+ contentTypeId: 'product'
192
+ }
193
+ type Locales = 'en-US' | 'de-DE'
194
+ const entry = client.withAllLocales.getEntry<ProductEntrySkeleton, Locales>('some-entry-id')
195
+ ```
196
+
197
+ The return type of the `getEntry` is matching the `fields` shape
198
+
199
+ ```json
200
+ {
201
+ "fields": {
202
+ "productName": {
203
+ "de-DE": "<field-value>",
204
+ "en-US": "<field-value>"
205
+ }
206
+ }
207
+ }
208
+ ```
209
+
210
+ Similar for assets:
211
+
212
+ ```typescript
213
+ import * as contentful from 'contentful'
214
+
215
+ const client = contentful.createClient({
216
+ space: '<space-id>',
217
+ accessToken: '<content-delivery-token>',
218
+ })
219
+
220
+ type Locales = 'en-US' | 'de-DE'
221
+ const asset = client.withAllLocales.getAsset<Locales>('some-asset-id')
222
+ ```
223
+
224
+ ```json
225
+ {
226
+ "fields": {
227
+ "file": {
228
+ "de-DE": "<field-value>",
229
+ "en-US": "<field-value>"
230
+ }
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### `withoutLinkResolution`
236
+
237
+ If the current chain includes `withoutLinkResolution`, the returned type doesn't resolve linked entities, but keeps them as link objects instead.
238
+
239
+ ```typescript
240
+ import * as contentful from 'contentful'
241
+
242
+ const client = contentful.createClient({
243
+ space: '<space-id>',
244
+ accessToken: '<content-delivery-token>',
245
+ })
246
+
247
+ type ProductEntrySkeleton = {
248
+ contentTypeId: 'product'
249
+ fields: {
250
+ productName: contentful.EntryFieldTypes.Text
251
+ image: contentful.EntryFieldTypes.AssetLink
252
+ price: contentful.EntryFieldTypes.Number
253
+ }
254
+ }
255
+
256
+ type ReferencedProductEntrySkeleton = {
257
+ fields: { relatedProduct: contentful.EntryFieldTypes.EntryLink<ProductEntrySkeleton> }
258
+ contentTypeId: 'referencedProduct'
259
+ }
260
+ const entry = client.withoutLinkResolution.getEntry<ReferencedProductEntrySkeleton>('some-entry-id')
261
+ ```
262
+
263
+ The return type of `getEntry` is matching the `fields` shape
264
+
265
+ ```json
266
+ {
267
+ "fields": {
268
+ "productName": {
269
+ "type": "Link",
270
+ "linkType": "Entry",
271
+ "id": "linkedProductId"
272
+ }
273
+ }
274
+ }
275
+ ```
276
+
277
+ [Read more on link resolution](ADVANCED.md#link-resolution)
278
+
279
+ ### `withoutUnresolvableLinks`
280
+
281
+ If the current chain includes `withoutUnresolvableLinks`, the returned type doesn't include linked entries that are not resolvable, for example if the linked entity does not exist anymore or is not yet published.
282
+
283
+ ```typescript
284
+ import * as contentful from 'contentful'
285
+
286
+ const client = contentful.createClient({
287
+ space: '<space-id>',
288
+ accessToken: '<content-delivery-token>',
289
+ })
290
+
291
+ type ProductEntrySkeleton = {
292
+ contentTypeId: 'product'
293
+ fields: {
294
+ productName: contentful.EntryFieldTypes.Text
295
+ image: contentful.EntryFieldTypes.AssetLink
296
+ price: contentful.EntryFieldTypes.Number
297
+ }
298
+ }
299
+
300
+ type ReferencedProductEntrySkeleton = {
301
+ fields: { relatedProduct: contentful.EntryFieldTypes.EntryLink<ProductEntrySkeleton> }
302
+ contentTypeId: 'referencedProduct'
303
+ }
304
+ const entry =
305
+ client.withoutUnresolvableLinks.getEntry<ReferencedProductEntrySkeleton>('some-entry-id')
306
+ ```
307
+
308
+ The return type of `getEntry` is matching the `fields` shape
309
+
310
+ ```json
311
+ {
312
+ "fields": {}
313
+ }
314
+ ```
315
+
316
+ ## Generating type definitions for content types
317
+
318
+ It is recommended to define field types for all your content types. This helps the type system to infer all possible query keys/value types for you.
319
+ Doing this manually is cumbersome, but do not worry!
320
+ There are several OSS projects out there to generate type definitions for Contentful content types:
321
+
322
+ - [cf-content-types-generator](https://github.com/contentful-userland/cf-content-types-generator)
323
+ - [contentful-typescript-codegen](https://github.com/intercom/contentful-typescript-codegen)
324
+ - [contentful-ts-type-generator](https://github.com/arimkevi/contentful-ts-type-generator)
325
+ - [contentful-ts-generator](https://github.com/watermarkchurch/contentful-ts-generator)
326
+
327
+ If you prefer a GUI, you can also use an app in your Contentful space to automatically generate TypeScript definitions for your content types:
328
+
329
+ - [TS Content Types Generator App](https://github.com/marcolink/cf-content-types-generator-app)
package/changes.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "bumped": {
3
+ "@contentful/content-source-maps": {
4
+ "from": "^0.11.33",
5
+ "to": "^0.12.1"
6
+ },
7
+ "@contentful/rich-text-types": {
8
+ "from": "^16.6.1",
9
+ "to": "^17.2.5"
10
+ },
11
+ "axios": {
12
+ "from": "^1.13.5",
13
+ "to": "^1.13.6"
14
+ },
15
+ "contentful-resolve-response": {
16
+ "from": "^1.9.4",
17
+ "to": "^1.9.7"
18
+ },
19
+ "contentful-sdk-core": {
20
+ "from": "^9.4.4",
21
+ "to": "^9.4.5"
22
+ },
23
+ "type-fest": {
24
+ "from": "^4.0.0",
25
+ "to": "^5.4.4"
26
+ }
27
+ },
28
+ "timestamp": "2026-03-17T22:56:06.881Z",
29
+ "totalUpdated": 6
30
+ }