@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.
- package/ADVANCED.md +283 -0
- package/CONTRIBUTING.md +109 -0
- package/LICENSE +21 -0
- package/MIGRATION.md +364 -0
- package/README.md +36 -0
- package/TYPESCRIPT.md +329 -0
- package/changes.json +30 -0
- package/dist/contentful.browser.js +10886 -0
- package/dist/contentful.browser.min.js +1 -0
- package/dist/contentful.cjs +23983 -0
- package/dist/esm/contentful.js +60 -0
- package/dist/esm/create-contentful-api.js +463 -0
- package/dist/esm/create-global-options.js +21 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/make-client.js +52 -0
- package/dist/esm/mixins/stringify-safe.js +23 -0
- package/dist/esm/paged-sync.js +118 -0
- package/dist/esm/utils/normalize-cursor-pagination-parameters.js +9 -0
- package/dist/esm/utils/normalize-cursor-pagination-response.js +23 -0
- package/dist/esm/utils/normalize-search-parameters.js +18 -0
- package/dist/esm/utils/normalize-select.js +25 -0
- package/dist/esm/utils/query-selection-set.js +14 -0
- package/dist/esm/utils/resolve-circular.js +15 -0
- package/dist/esm/utils/timeline-preview-helpers.js +33 -0
- package/dist/esm/utils/validate-params.js +65 -0
- package/dist/esm/utils/validate-search-parameters.js +11 -0
- package/dist/esm/utils/validate-timestamp.js +16 -0
- package/dist/esm/utils/validation-error.js +8 -0
- package/dist/stats-browser-min.html +4949 -0
- package/dist/types/contentful.d.ts +150 -0
- package/dist/types/create-contentful-api.d.ts +13 -0
- package/dist/types/create-global-options.d.ts +19 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/make-client.d.ts +3 -0
- package/dist/types/mixins/stringify-safe.d.ts +1 -0
- package/dist/types/paged-sync.d.ts +7 -0
- package/dist/types/types/asset-key.d.ts +7 -0
- package/dist/types/types/asset.d.ts +79 -0
- package/dist/types/types/client.d.ts +477 -0
- package/dist/types/types/collection.d.ts +42 -0
- package/dist/types/types/concept-scheme.d.ts +26 -0
- package/dist/types/types/concept.d.ts +51 -0
- package/dist/types/types/content-type.d.ts +105 -0
- package/dist/types/types/entry.d.ts +246 -0
- package/dist/types/types/index.d.ts +17 -0
- package/dist/types/types/link.d.ts +61 -0
- package/dist/types/types/locale.d.ts +30 -0
- package/dist/types/types/metadata.d.ts +13 -0
- package/dist/types/types/query/equality.d.ts +29 -0
- package/dist/types/types/query/existence.d.ts +15 -0
- package/dist/types/types/query/index.d.ts +12 -0
- package/dist/types/types/query/location.d.ts +29 -0
- package/dist/types/types/query/order.d.ts +44 -0
- package/dist/types/types/query/query.d.ts +155 -0
- package/dist/types/types/query/range.d.ts +18 -0
- package/dist/types/types/query/reference.d.ts +12 -0
- package/dist/types/types/query/search.d.ts +17 -0
- package/dist/types/types/query/select.d.ts +29 -0
- package/dist/types/types/query/set.d.ts +10 -0
- package/dist/types/types/query/subset.d.ts +20 -0
- package/dist/types/types/query/util.d.ts +32 -0
- package/dist/types/types/resource-link.d.ts +9 -0
- package/dist/types/types/space.d.ts +20 -0
- package/dist/types/types/sync.d.ts +84 -0
- package/dist/types/types/sys.d.ts +30 -0
- package/dist/types/types/tag.d.ts +32 -0
- package/dist/types/types/timeline-preview.d.ts +16 -0
- package/dist/types/utils/client-helpers.d.ts +9 -0
- package/dist/types/utils/normalize-cursor-pagination-parameters.d.ts +5 -0
- package/dist/types/utils/normalize-cursor-pagination-response.d.ts +2 -0
- package/dist/types/utils/normalize-search-parameters.d.ts +1 -0
- package/dist/types/utils/normalize-select.d.ts +1 -0
- package/dist/types/utils/query-selection-set.d.ts +1 -0
- package/dist/types/utils/resolve-circular.d.ts +4 -0
- package/dist/types/utils/timeline-preview-helpers.d.ts +7 -0
- package/dist/types/utils/validate-params.d.ts +6 -0
- package/dist/types/utils/validate-search-parameters.d.ts +1 -0
- package/dist/types/utils/validate-timestamp.d.ts +6 -0
- package/dist/types/utils/validation-error.d.ts +3 -0
- package/images/contentful-icon.png +0 -0
- package/images/dynamic-query-keys.png +0 -0
- package/images/static-query-keys.png +0 -0
- package/package.json +221 -0
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
import type { ContentType, ContentTypeCollection } from './content-type.js';
|
|
2
|
+
import type { Space } from './space.js';
|
|
3
|
+
import type { LocaleCode, LocaleCollection } from './locale.js';
|
|
4
|
+
import type { AssetQueries, AssetsQueries, AssetsQueriesWithCursor, ConceptAncestorsDescendantsQueries, ConceptSchemesQueries, ConceptsQueries, EntriesQueries, EntriesQueriesWithCursor, EntryQueries, EntrySkeletonType, TagQueries } from './query/index.js';
|
|
5
|
+
import type { SyncCollection, SyncOptions, SyncQuery } from './sync.js';
|
|
6
|
+
import type { Tag, TagCollection } from './tag.js';
|
|
7
|
+
import type { AssetKey } from './asset-key.js';
|
|
8
|
+
import type { Entry, EntryCollection, EntryCursorPaginatedCollection } from './entry.js';
|
|
9
|
+
import type { Asset, AssetCollection, AssetCursorPaginatedCollection, AssetFields } from './asset.js';
|
|
10
|
+
import type { Concept, ConceptCollection } from './concept.js';
|
|
11
|
+
import type { ConceptScheme, ConceptSchemeCollection } from './concept-scheme.js';
|
|
12
|
+
/**
|
|
13
|
+
* Client chain modifiers used in all types that depend on the client configuration.
|
|
14
|
+
* @category Client
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export type ChainModifiers = 'WITH_ALL_LOCALES' | 'WITHOUT_LINK_RESOLUTION' | 'WITHOUT_UNRESOLVABLE_LINKS' | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a modifier to a list of client chain modifiers.
|
|
20
|
+
* @category Client
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export type AddChainModifier<Modifiers extends ChainModifiers, AddedModifier extends Exclude<ChainModifiers, undefined>> = undefined extends Modifiers ? AddedModifier : Modifiers | AddedModifier;
|
|
24
|
+
/**
|
|
25
|
+
* Contentful Delivery API Client. Contains methods which allow access to the different kinds of entities present in Contentful (Entries, Assets, etc).
|
|
26
|
+
* @category Client
|
|
27
|
+
* @typeParam Modifiers - The chain modifiers used to configure the client. They’re set automatically when using the client chain modifiers.
|
|
28
|
+
*/
|
|
29
|
+
export interface ContentfulClientApi<Modifiers extends ChainModifiers> {
|
|
30
|
+
/**
|
|
31
|
+
* Fetches a content type
|
|
32
|
+
* @param id - The content type’s ID
|
|
33
|
+
* @returns Promise for a content type
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import * as contentful from 'contentful'
|
|
37
|
+
*
|
|
38
|
+
* const client = contentful.createClient({
|
|
39
|
+
* space: '<space_id>',
|
|
40
|
+
* accessToken: '<content_delivery_api_key>'
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* const contentType = await client.getContentType('<content_type_id>')
|
|
44
|
+
* console.log(contentType)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
getContentType(id: string): Promise<ContentType>;
|
|
48
|
+
/**
|
|
49
|
+
* Fetches a collection of content types
|
|
50
|
+
* @returns Promise for a collection of content types
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import * as contentful from 'contentful'
|
|
54
|
+
*
|
|
55
|
+
* const client = contentful.createClient({
|
|
56
|
+
* space: '<space_id>',
|
|
57
|
+
* accessToken: '<content_delivery_api_key>'
|
|
58
|
+
* })
|
|
59
|
+
*
|
|
60
|
+
* const response = await client.getContentTypes()
|
|
61
|
+
* console.log(response.items)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
getContentTypes(query?: {
|
|
65
|
+
query?: string;
|
|
66
|
+
}): Promise<ContentTypeCollection>;
|
|
67
|
+
/**
|
|
68
|
+
* Fetches the space which the client is currently configured to use
|
|
69
|
+
* @returns Promise for the space
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import * as contentful from 'contentful'
|
|
73
|
+
*
|
|
74
|
+
* const client = contentful.createClient({
|
|
75
|
+
* space: '<space_id>',
|
|
76
|
+
* accessToken: '<content_delivery_api_key>'
|
|
77
|
+
* })
|
|
78
|
+
*
|
|
79
|
+
* const space = await client.getSpace()
|
|
80
|
+
* console.log(space)
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
getSpace(): Promise<Space>;
|
|
84
|
+
/**
|
|
85
|
+
* Fetches a collection of locales
|
|
86
|
+
* @returns Promise for a collection of locales
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* import * as contentful from 'contentful'
|
|
90
|
+
*
|
|
91
|
+
* const client = contentful.createClient({
|
|
92
|
+
* space: '<space_id>',
|
|
93
|
+
* accessToken: '<content_delivery_api_key>'
|
|
94
|
+
* })
|
|
95
|
+
*
|
|
96
|
+
* const response = await client.getLocales()
|
|
97
|
+
* console.log(response.items)
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
getLocales(): Promise<LocaleCollection>;
|
|
101
|
+
/**
|
|
102
|
+
* Synchronizes either all the content or only new content since last sync.
|
|
103
|
+
* <strong> Important note: </strong> The Sync API endpoint does not support include or link resolution.
|
|
104
|
+
* However, contentful.js can do link resolution on the client side for the initial sync.
|
|
105
|
+
* For the delta sync (using nextSyncToken) link resolution is not possible since the sdk won’t have access to all linked entities.
|
|
106
|
+
* @param query - Query object
|
|
107
|
+
* @param query.initial - Optional, unless first sync call
|
|
108
|
+
* @param query.limit - Optional, sets the page size for the number of retrieved entries
|
|
109
|
+
* @param query.nextSyncToken - Optional, used in subsequent sync calls
|
|
110
|
+
* @param query.nextPageToken - Optional, used in subsequent sync calls
|
|
111
|
+
* @param query.type - Optional, query for specific entities
|
|
112
|
+
* @param query.content_type - Query for specific content types; optional,
|
|
113
|
+
* unless `query.type` is defined as `Entry`
|
|
114
|
+
* @param syncOptions
|
|
115
|
+
* @param syncOptions.paginate - Configures the client to call the sync API recursively,
|
|
116
|
+
* collecting all items from responses into one collection
|
|
117
|
+
* @typeParam EntrySkeleton - Shape of entity fields used to calculate dynamic keys
|
|
118
|
+
* @typeParam Modifiers - The chain modifiers used to configure the client. They’re set automatically when using the client chain modifiers.
|
|
119
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for entity field values.
|
|
120
|
+
* @see {@link https://www.contentful.com/developers/docs/concepts/sync/ | Documentation}
|
|
121
|
+
* @see {@link https://www.contentful.com/developers/docs/javascript/tutorials/using-the-sync-api-with-js/ | Tutorial for using sync API}
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import * as contentful from 'contentful'
|
|
125
|
+
*
|
|
126
|
+
* const client = contentful.createClient({
|
|
127
|
+
* space: '<space_id>',
|
|
128
|
+
* accessToken: '<content_delivery_api_key>'
|
|
129
|
+
* })
|
|
130
|
+
*
|
|
131
|
+
* const response = await client.sync({
|
|
132
|
+
* initial: true
|
|
133
|
+
* })
|
|
134
|
+
* console.log({
|
|
135
|
+
* entries: response.entries,
|
|
136
|
+
* assets: response.assets,
|
|
137
|
+
* nextSyncToken: response.nextSyncToken
|
|
138
|
+
* })
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
sync<EntrySkeleton extends EntrySkeletonType = EntrySkeletonType, Modifiers extends ChainModifiers = ChainModifiers, Locales extends LocaleCode = LocaleCode>(query: SyncQuery, syncOptions?: SyncOptions): Promise<SyncCollection<EntrySkeleton, Modifiers, Locales>>;
|
|
142
|
+
/**
|
|
143
|
+
* Fetches a tag
|
|
144
|
+
* @param id - The tag’s ID
|
|
145
|
+
* @returns Promise for a tag
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* import * as contentful from 'contentful'
|
|
149
|
+
*
|
|
150
|
+
* const client = contentful.createClient({
|
|
151
|
+
* space: '<space_id>',
|
|
152
|
+
* accessToken: '<content_delivery_api_key>'
|
|
153
|
+
* })
|
|
154
|
+
*
|
|
155
|
+
* const tag = await client.getTag('<asset_id>')
|
|
156
|
+
* console.log(tag)
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
getTag(id: string): Promise<Tag>;
|
|
160
|
+
/**
|
|
161
|
+
* Gets a collection of Tags
|
|
162
|
+
* @returns Promise for a collection of tags
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* import * as contentful from 'contentful'
|
|
166
|
+
*
|
|
167
|
+
* const client = contentful.createClient({
|
|
168
|
+
* space: '<space_id>',
|
|
169
|
+
* accessToken: '<content_delivery_api_key>'
|
|
170
|
+
* })
|
|
171
|
+
*
|
|
172
|
+
* const response = await client.getTags()
|
|
173
|
+
* console.log(response.items)
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
getTags(query?: TagQueries): Promise<TagCollection>;
|
|
177
|
+
/**
|
|
178
|
+
* Fetches a Concept
|
|
179
|
+
* @param id - The concept’s ID
|
|
180
|
+
* @returns Promise for a concept
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* const contentful = require('contentful')
|
|
184
|
+
*
|
|
185
|
+
* const client = contentful.createClient({
|
|
186
|
+
* space: '<space_id>',
|
|
187
|
+
* accessToken: '<content_delivery_api_key>'
|
|
188
|
+
* })
|
|
189
|
+
*
|
|
190
|
+
* const concept = await client.getConcept('<concept_id>')
|
|
191
|
+
* console.log(concept)
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
getConcept<Locales extends LocaleCode>(id: string): Promise<Concept<Locales>>;
|
|
195
|
+
/**
|
|
196
|
+
* Fetches a Concept Ancestors traversing the concept hierarchy by depth
|
|
197
|
+
* @param id - The concept’s ID
|
|
198
|
+
* @returns Promise for a concept
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const contentful = require('contentful')
|
|
202
|
+
*
|
|
203
|
+
* const client = contentful.createClient({
|
|
204
|
+
* space: '<space_id>',
|
|
205
|
+
* accessToken: '<content_delivery_api_key>'
|
|
206
|
+
* })
|
|
207
|
+
*
|
|
208
|
+
* const concept = await client.getConceptAncestors('<concept_id>', { depth: 5, order: 'sys.updatedAt' })
|
|
209
|
+
* console.log(concept)
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
getConceptAncestors<Locales extends LocaleCode>(id: string, query?: ConceptAncestorsDescendantsQueries): Promise<ConceptCollection<Locales>>;
|
|
213
|
+
/**
|
|
214
|
+
* Fetches a Concept Descendants traversing the concept hierarchy by depth
|
|
215
|
+
* @param id - The concept’s ID
|
|
216
|
+
* @returns Promise for a concept
|
|
217
|
+
* @example
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const contentful = require('contentful')
|
|
220
|
+
*
|
|
221
|
+
* const client = contentful.createClient({
|
|
222
|
+
* space: '<space_id>',
|
|
223
|
+
* accessToken: '<content_delivery_api_key>'
|
|
224
|
+
* })
|
|
225
|
+
*
|
|
226
|
+
* const concept = await client.getConceptDescendants('<concept_id>', { depth: 5, order: 'sys.updatedAt' })
|
|
227
|
+
* console.log(concept)
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
getConceptDescendants<Locale extends LocaleCode>(id: string, query?: ConceptAncestorsDescendantsQueries): Promise<ConceptCollection<Locale>>;
|
|
231
|
+
/**
|
|
232
|
+
* Fetches a collection of Concepts
|
|
233
|
+
* @param query - Object with search parameters
|
|
234
|
+
* @returns Promise for a collection of Concepts
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const contentful = require('contentful')
|
|
238
|
+
*
|
|
239
|
+
* const client = contentful.createClient({
|
|
240
|
+
* space: '<space_id>',
|
|
241
|
+
* accessToken: '<content_delivery_api_key>'
|
|
242
|
+
* })
|
|
243
|
+
*
|
|
244
|
+
* const response = await client.getConcepts()
|
|
245
|
+
* console.log(response.items)
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
getConcepts<Locales extends LocaleCode = 'en-US'>(query?: ConceptsQueries): Promise<ConceptCollection<Locales>>;
|
|
249
|
+
/**
|
|
250
|
+
* Fetches a Concept Scheme
|
|
251
|
+
* @param id - The concept scheme's ID
|
|
252
|
+
* @returns Promise for a concept scheme
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const contentful = require('contentful')
|
|
256
|
+
*
|
|
257
|
+
* const client = contentful.createClient({
|
|
258
|
+
* space: '<space_id>',
|
|
259
|
+
* accessToken: '<content_delivery_api_key>'
|
|
260
|
+
* })
|
|
261
|
+
*
|
|
262
|
+
* const conceptScheme = await client.getConceptScheme('<concept_id>')
|
|
263
|
+
* console.log(conceptScheme)
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
getConceptScheme<Locales extends LocaleCode = 'en-US'>(id: string): Promise<ConceptScheme<Locales>>;
|
|
267
|
+
/**
|
|
268
|
+
* Fetches a collection of Concept Schemes
|
|
269
|
+
* @param query - Object with search parameters
|
|
270
|
+
* @returns Promise for a collection of Concept Schemes
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* const contentful = require('contentful')
|
|
274
|
+
*
|
|
275
|
+
* const client = contentful.createClient({
|
|
276
|
+
* space: '<space_id>',
|
|
277
|
+
* accessToken: '<content_delivery_api_key>'
|
|
278
|
+
* })
|
|
279
|
+
*
|
|
280
|
+
* const response = await client.getConceptSchemes()
|
|
281
|
+
* console.log(response.items)
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
getConceptSchemes<Locales extends LocaleCode = 'en-US'>(query?: ConceptSchemesQueries): Promise<ConceptSchemeCollection<Locales>>;
|
|
285
|
+
/**
|
|
286
|
+
* Creates an asset key for signing asset URLs (Embargoed Assets)
|
|
287
|
+
* @returns Promise for an asset key
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* import * as contentful from 'contentful'
|
|
291
|
+
*
|
|
292
|
+
* const client = contentful.createClient({
|
|
293
|
+
* space: '<space_id>',
|
|
294
|
+
* accessToken: '<content_delivery_api_key>'
|
|
295
|
+
* })
|
|
296
|
+
*
|
|
297
|
+
* const assetKey = await client.getAssetKey(<UNIX timestamp>)
|
|
298
|
+
* console.log(assetKey)
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
createAssetKey(expiresAt: number): Promise<AssetKey>;
|
|
302
|
+
/**
|
|
303
|
+
* Fetches an entry
|
|
304
|
+
* @param id - The entry’s ID
|
|
305
|
+
* @param query - Object with search parameters. In this method it's only used for `locale` when querying.
|
|
306
|
+
* @returns Promise for an entry
|
|
307
|
+
* @typeParam EntrySkeleton - Shape of entry fields used to calculate dynamic keys
|
|
308
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for entry field values.
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const contentful = require('contentful')
|
|
312
|
+
*
|
|
313
|
+
* const client = contentful.createClient({
|
|
314
|
+
* space: '<space_id>',
|
|
315
|
+
* accessToken: '<content_delivery_api_key>'
|
|
316
|
+
* })
|
|
317
|
+
*
|
|
318
|
+
* const entry = await client.getEntry('<entry_id>')
|
|
319
|
+
* console.log(entry)
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
getEntry<EntrySkeleton extends EntrySkeletonType = EntrySkeletonType, Locales extends LocaleCode = LocaleCode>(id: string, query?: EntryQueries<Modifiers>): Promise<Entry<EntrySkeleton, Modifiers, Locales>>;
|
|
323
|
+
/**
|
|
324
|
+
* Fetches a collection of Entries
|
|
325
|
+
* @param query - Object with search parameters
|
|
326
|
+
* @returns Promise for a collection of Entries
|
|
327
|
+
* @typeParam EntrySkeleton - Shape of entry fields used to calculate dynamic keys
|
|
328
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for entry field values.
|
|
329
|
+
* @see {@link https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters | JS SDK tutorial}
|
|
330
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters | REST API reference}
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const contentful = require('contentful')
|
|
334
|
+
*
|
|
335
|
+
* const client = contentful.createClient({
|
|
336
|
+
* space: '<space_id>',
|
|
337
|
+
* accessToken: '<content_delivery_api_key>'
|
|
338
|
+
* })
|
|
339
|
+
*
|
|
340
|
+
* const response = await client.getEntries()
|
|
341
|
+
* console.log(response.items)
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
getEntries<EntrySkeleton extends EntrySkeletonType = EntrySkeletonType, Locales extends LocaleCode = LocaleCode>(query?: EntriesQueries<EntrySkeleton, Modifiers>): Promise<EntryCollection<EntrySkeleton, Modifiers, Locales>>;
|
|
345
|
+
/**
|
|
346
|
+
* Fetches a cursor paginated collection of Entries
|
|
347
|
+
* @param pagination - Object with cursor pagination options
|
|
348
|
+
* @param query - Object with search parameters
|
|
349
|
+
* @returns Promise for a cursor paginated collection of Entries
|
|
350
|
+
* @typeParam EntrySkeleton - Shape of entry fields used to calculate dynamic keys
|
|
351
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for entry field values.
|
|
352
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/cursor-pagination | REST API cursor pagination reference}
|
|
353
|
+
* @see {@link https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters | JS SDK tutorial}
|
|
354
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters | REST API reference}
|
|
355
|
+
* @example
|
|
356
|
+
* ```typescript
|
|
357
|
+
* const contentful = require('contentful')
|
|
358
|
+
*
|
|
359
|
+
* const client = contentful.createClient({
|
|
360
|
+
* space: '<space_id>',
|
|
361
|
+
* accessToken: '<content_delivery_api_key>'
|
|
362
|
+
* })
|
|
363
|
+
*
|
|
364
|
+
* const response = await client.getEntriesWithCursor()
|
|
365
|
+
* console.log(response.items)
|
|
366
|
+
* ```
|
|
367
|
+
*/
|
|
368
|
+
getEntriesWithCursor<EntrySkeleton extends EntrySkeletonType = EntrySkeletonType, Locales extends LocaleCode = LocaleCode>(query?: EntriesQueriesWithCursor<EntrySkeleton, Modifiers>): Promise<EntryCursorPaginatedCollection<EntrySkeleton, Modifiers, Locales>>;
|
|
369
|
+
/**
|
|
370
|
+
* Parse raw json data into a collection of entries. objects.Links will be resolved also
|
|
371
|
+
* @param data - json data
|
|
372
|
+
* @typeParam EntrySkeleton - Shape of entry fields used to calculate dynamic keys
|
|
373
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for entry field values.
|
|
374
|
+
* @example
|
|
375
|
+
* ```typescript
|
|
376
|
+
* const data = {items: [
|
|
377
|
+
* {
|
|
378
|
+
* sys: {type: 'Entry', locale: 'en-US'},
|
|
379
|
+
* fields: {
|
|
380
|
+
* animal: {sys: {type: 'Link', linkType: 'Animal', id: 'oink'}},
|
|
381
|
+
* anotheranimal: {sys: {type: 'Link', linkType: 'Animal', id: 'middle-parrot'}}
|
|
382
|
+
* }
|
|
383
|
+
* }
|
|
384
|
+
* ],
|
|
385
|
+
* includes: {
|
|
386
|
+
* Animal: [
|
|
387
|
+
* {
|
|
388
|
+
* sys: {type: 'Animal', id: 'oink', locale: 'en-US'},
|
|
389
|
+
* fields: {
|
|
390
|
+
* name: 'Pig',
|
|
391
|
+
* friend: {sys: {type: 'Link', linkType: 'Animal', id: 'groundhog'}}
|
|
392
|
+
* }
|
|
393
|
+
* }
|
|
394
|
+
* ]
|
|
395
|
+
* }
|
|
396
|
+
* }
|
|
397
|
+
* console.log( data.items[0].fields.foo ); // undefined
|
|
398
|
+
* const parsedData = client.parseEntries(data);
|
|
399
|
+
* console.log( parsedData.items[0].fields.foo ); // foo
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
parseEntries<EntrySkeleton extends EntrySkeletonType = EntrySkeletonType, Locales extends LocaleCode = LocaleCode>(data: EntryCollection<EntrySkeleton, AddChainModifier<Modifiers, 'WITHOUT_LINK_RESOLUTION'>, Locales>): EntryCollection<EntrySkeleton, Modifiers, Locales>;
|
|
403
|
+
/**
|
|
404
|
+
* Fetches an asset
|
|
405
|
+
* @param id
|
|
406
|
+
* @param query - Object with search parameters. In this method it's only useful for `locale`.
|
|
407
|
+
* @returns Promise for an asset
|
|
408
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for asset field values.
|
|
409
|
+
* @example
|
|
410
|
+
* const contentful = require('contentful')
|
|
411
|
+
*
|
|
412
|
+
* const client = contentful.createClient({
|
|
413
|
+
* space: '<space_id>',
|
|
414
|
+
* accessToken: '<content_delivery_api_key>'
|
|
415
|
+
* })
|
|
416
|
+
*
|
|
417
|
+
* const asset = await client.getAsset('<asset_id>')
|
|
418
|
+
* console.log(asset)
|
|
419
|
+
*/
|
|
420
|
+
getAsset<Locales extends LocaleCode = LocaleCode>(id: string, query?: AssetQueries<Modifiers>): Promise<Asset<Modifiers, Locales>>;
|
|
421
|
+
/**
|
|
422
|
+
* Fetches a collection of assets
|
|
423
|
+
* @param query - Object with search parameters
|
|
424
|
+
* @see {@link https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters | JS SDK tutorial}
|
|
425
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters | REST API reference}
|
|
426
|
+
* @returns Promise for a collection of Assets
|
|
427
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for asset field values.
|
|
428
|
+
* @example
|
|
429
|
+
* const contentful = require('contentful')
|
|
430
|
+
*
|
|
431
|
+
* const client = contentful.createClient({
|
|
432
|
+
* space: '<space_id>',
|
|
433
|
+
* accessToken: '<content_delivery_api_key>'
|
|
434
|
+
* })
|
|
435
|
+
*
|
|
436
|
+
* const response = await client.getAssets()
|
|
437
|
+
* console.log(response.items)
|
|
438
|
+
*/
|
|
439
|
+
getAssets<Locales extends LocaleCode = LocaleCode>(query?: AssetsQueries<AssetFields, Modifiers>): Promise<AssetCollection<Modifiers, Locales>>;
|
|
440
|
+
/**
|
|
441
|
+
* Fetches a cursor paginated collection of assets
|
|
442
|
+
* @param pagination - Object with cursor pagination options
|
|
443
|
+
* @param query - Object with search parameters
|
|
444
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/cursor-pagination | REST API cursor pagination reference}
|
|
445
|
+
* @see {@link https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters | JS SDK tutorial}
|
|
446
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters | REST API reference}
|
|
447
|
+
* @returns Promise for a cursor paginated collection of Assets
|
|
448
|
+
* @typeParam Locales - If provided for a client using `allLocales` modifier, response type defines locale keys for asset field values.
|
|
449
|
+
* @example
|
|
450
|
+
* const contentful = require('contentful')
|
|
451
|
+
*
|
|
452
|
+
* const client = contentful.createClient({
|
|
453
|
+
* space: '<space_id>',
|
|
454
|
+
* accessToken: '<content_delivery_api_key>'
|
|
455
|
+
* })
|
|
456
|
+
*
|
|
457
|
+
* const response = await client.getAssetsWithCursor()
|
|
458
|
+
* console.log(response.items)
|
|
459
|
+
*/
|
|
460
|
+
getAssetsWithCursor<Locales extends LocaleCode = LocaleCode>(query?: AssetsQueriesWithCursor<AssetFields, Modifiers>): Promise<AssetCursorPaginatedCollection<Modifiers, Locales>>;
|
|
461
|
+
/**
|
|
462
|
+
* A client that will fetch assets and entries with all locales. Only available if not already enabled.
|
|
463
|
+
*/
|
|
464
|
+
withAllLocales: 'WITH_ALL_LOCALES' extends Modifiers ? never : ContentfulClientApi<AddChainModifier<Modifiers, 'WITH_ALL_LOCALES'>>;
|
|
465
|
+
/**
|
|
466
|
+
* A client that will not resolve links in entries. Only available if not already disabled.
|
|
467
|
+
*/
|
|
468
|
+
withoutLinkResolution: 'WITHOUT_LINK_RESOLUTION' extends Modifiers ? never : 'WITHOUT_UNRESOLVABLE_LINKS' extends Modifiers ? never : ContentfulClientApi<AddChainModifier<Modifiers, 'WITHOUT_LINK_RESOLUTION'>>;
|
|
469
|
+
/**
|
|
470
|
+
* A client that will remove unresolvable links from entries. Only available if not already disabled.
|
|
471
|
+
*/
|
|
472
|
+
withoutUnresolvableLinks: 'WITHOUT_LINK_RESOLUTION' extends Modifiers ? never : 'WITHOUT_UNRESOLVABLE_LINKS' extends Modifiers ? never : ContentfulClientApi<AddChainModifier<Modifiers, 'WITHOUT_UNRESOLVABLE_LINKS'>>;
|
|
473
|
+
/**
|
|
474
|
+
* The current Contentful.js version
|
|
475
|
+
*/
|
|
476
|
+
version: string;
|
|
477
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type CollectionBase<T> = {
|
|
2
|
+
limit: number;
|
|
3
|
+
items: Array<T>;
|
|
4
|
+
sys?: {
|
|
5
|
+
type: 'Array';
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export type OffsetPagination = {
|
|
9
|
+
total: number;
|
|
10
|
+
skip: number;
|
|
11
|
+
};
|
|
12
|
+
export type CursorPagination = {
|
|
13
|
+
pages: {
|
|
14
|
+
next?: string;
|
|
15
|
+
prev?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A wrapper object containing additional information for
|
|
20
|
+
* an offset paginated collection of Contentful resources
|
|
21
|
+
* @category Entity
|
|
22
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination | Documentation}
|
|
23
|
+
*/
|
|
24
|
+
export type OffsetPaginatedCollection<T = unknown> = CollectionBase<T> & OffsetPagination;
|
|
25
|
+
/**
|
|
26
|
+
* A wrapper object containing additional information for
|
|
27
|
+
* an offset paginated collection of Contentful resources
|
|
28
|
+
* @category Entity
|
|
29
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination | Documentation}
|
|
30
|
+
*/
|
|
31
|
+
export interface ContentfulCollection<T = unknown> extends OffsetPaginatedCollection<T> {
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A wrapper object containing additional information for
|
|
35
|
+
* a curisor paginated collection of Contentful resources
|
|
36
|
+
* @category Entity
|
|
37
|
+
* @see {@link https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/cursor-pagination | Documentation}
|
|
38
|
+
*/
|
|
39
|
+
export type CursorPaginatedCollection<T = unknown> = CollectionBase<T> & CursorPagination;
|
|
40
|
+
export type CollectionForQuery<T = unknown, Query extends Record<string, unknown> = Record<string, unknown>> = Query extends {
|
|
41
|
+
cursor: true;
|
|
42
|
+
} ? CursorPaginatedCollection<T> : OffsetPaginatedCollection<T>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CursorPaginatedCollection } from './collection';
|
|
2
|
+
import type { UnresolvedLink } from './link';
|
|
3
|
+
import type { LocaleCode } from './locale';
|
|
4
|
+
type ISODateString = string;
|
|
5
|
+
export type ConceptSchemeSys = {
|
|
6
|
+
id: string;
|
|
7
|
+
type: 'TaxonomyConceptScheme';
|
|
8
|
+
createdAt: ISODateString;
|
|
9
|
+
updatedAt: ISODateString;
|
|
10
|
+
version: number;
|
|
11
|
+
};
|
|
12
|
+
export interface ConceptScheme<Locales extends LocaleCode> {
|
|
13
|
+
sys: ConceptSchemeSys;
|
|
14
|
+
uri?: string;
|
|
15
|
+
prefLabel: {
|
|
16
|
+
[locale in Locales]: string;
|
|
17
|
+
};
|
|
18
|
+
definition?: {
|
|
19
|
+
[locale in Locales]: string;
|
|
20
|
+
} | null;
|
|
21
|
+
topConcepts: UnresolvedLink<'TaxonomyConcept'>[];
|
|
22
|
+
concepts: UnresolvedLink<'TaxonomyConcept'>[];
|
|
23
|
+
totalConcepts: number;
|
|
24
|
+
}
|
|
25
|
+
export type ConceptSchemeCollection<Locale extends LocaleCode> = CursorPaginatedCollection<ConceptScheme<Locale>>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CursorPaginatedCollection } from './collection';
|
|
2
|
+
import type { UnresolvedLink } from './link';
|
|
3
|
+
import type { LocaleCode } from './locale';
|
|
4
|
+
type ISODateString = string;
|
|
5
|
+
export type ConceptSys = {
|
|
6
|
+
id: string;
|
|
7
|
+
type: 'TaxonomyConcept';
|
|
8
|
+
createdAt: ISODateString;
|
|
9
|
+
updatedAt: ISODateString;
|
|
10
|
+
version: number;
|
|
11
|
+
};
|
|
12
|
+
export interface Concept<Locales extends LocaleCode> {
|
|
13
|
+
sys: ConceptSys;
|
|
14
|
+
uri?: string;
|
|
15
|
+
prefLabel: {
|
|
16
|
+
[locale in Locales]: string;
|
|
17
|
+
};
|
|
18
|
+
altLabels?: {
|
|
19
|
+
[locale in Locales]: string[];
|
|
20
|
+
};
|
|
21
|
+
hiddenLabels?: {
|
|
22
|
+
[locale in Locales]: string[];
|
|
23
|
+
};
|
|
24
|
+
note?: {
|
|
25
|
+
[locale in Locales]: string;
|
|
26
|
+
} | null;
|
|
27
|
+
changeNote?: {
|
|
28
|
+
[locale in Locales]: string;
|
|
29
|
+
} | null;
|
|
30
|
+
definition?: {
|
|
31
|
+
[locale in Locales]: string;
|
|
32
|
+
} | null;
|
|
33
|
+
editorialNote?: {
|
|
34
|
+
[locale in Locales]: string;
|
|
35
|
+
} | null;
|
|
36
|
+
example?: {
|
|
37
|
+
[locale in Locales]: string;
|
|
38
|
+
} | null;
|
|
39
|
+
historyNote?: {
|
|
40
|
+
[locale in Locales]: string;
|
|
41
|
+
} | null;
|
|
42
|
+
scopeNote?: {
|
|
43
|
+
[locale in Locales]: string;
|
|
44
|
+
} | null;
|
|
45
|
+
notations?: string[];
|
|
46
|
+
broader?: UnresolvedLink<'TaxonomyConcept'>[];
|
|
47
|
+
related?: UnresolvedLink<'TaxonomyConcept'>[];
|
|
48
|
+
conceptSchemes?: UnresolvedLink<'TaxonomyConceptScheme'>[];
|
|
49
|
+
}
|
|
50
|
+
export type ConceptCollection<Locale extends LocaleCode> = CursorPaginatedCollection<Concept<Locale>>;
|
|
51
|
+
export {};
|