@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/ADVANCED.md ADDED
@@ -0,0 +1,283 @@
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">Advanced Concepts & Tips</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
+ > Find helpful concepts and tips about how to use this library.
30
+
31
+ - [Using ES6 import](#using-es6-import)
32
+ - [Framework specifics](#framework-specifics)
33
+ - [Link resolution](#link-resolution)
34
+ - [Note: link resolution for versions older than 10.0.0](#note:-link-resolution-for-versions-older-than-10.0.0)
35
+ - [Note: link resolution for versions older than 7.0.0](#note:-link-resolution-for-versions-older-than-7.0.0)
36
+ - [Sync](#sync)
37
+ - [Sync without pagination](#sync-without-pagination)
38
+ - [Querying & Search parameters](#querying--search-parameters)
39
+
40
+ ## Using ES6 import
41
+
42
+ You can use the es6 import with the SDK as follows:
43
+
44
+ ```js
45
+ import { createClient } from "contentful";
46
+ const client = createClient({...});
47
+ ```
48
+
49
+ OR
50
+
51
+ ```js
52
+ import * as contentful from "contentful";
53
+ const client = contentful.createClient({...});
54
+ ```
55
+
56
+ ## Framework specifics
57
+
58
+ ### React Native & Server Side Rendering
59
+
60
+ This library is able to handle Server Side Rendering and React Native. Depending on your implementation, you may need to explicitly require the `browser` or `node` variant of the library. (webpack usually is able to handle this on its own).
61
+
62
+ ```js
63
+ const contentful = require('contentful')
64
+ // will become the following to enforce the browser version
65
+ const contentful = require('contentful/dist/contentful.browser.min.js')
66
+ ```
67
+
68
+ ### Angular Universal
69
+
70
+ This library is able to handle Server Side Rendering with Angular Universal. To use it, you will have to provide a custom [Axios adapter](https://github.com/axios/axios/tree/main/lib/adapters), one example for Angular would be the [ngx-axios-adapter](https://github.com/patrickhousley/ngx-axios-adapter).
71
+
72
+ ## Link resolution
73
+
74
+ In Contentful, you can create content that references other content. We call them "linked" or "referenced" entries. In contrast to a simple REST call, this library can render the content of a linked entry in place, using the [contentful-resolve-response](https://github.com/contentful/contentful-resolve-response) package. This enables what we call link resolution.
75
+
76
+ **Example entry response without link resolution:**
77
+
78
+ ```
79
+ {
80
+ "sys": { ... },
81
+ "metadata": { ... },
82
+ "fields": {
83
+ "referencedEntry": {
84
+ "type": "Link",
85
+ "linkType": "Entry",
86
+ "id": "<referenced-entry-id>"
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ **Example entry response with link resolution:**
93
+
94
+ ```
95
+ {
96
+ "sys": { ... },
97
+ "metadata": { ... },
98
+ "fields": {
99
+ "referencedEntry": {
100
+ "sys": { ... },
101
+ "metadata": { ... },
102
+ "fields": {
103
+ ...
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ This makes parsing the response easier, and you don't need to manually extract every linked entry from the response object.
111
+
112
+ The link resolution is applied to one level deep by default. If you need it to be applied deeper, you may specify the `include` parameter when fetching your entries as follows `client.getEntries( { include: <value> })`. The `include` parameter can be set to a number up to 10, which would represent a ten layers deep link resolution.
113
+
114
+ **We resolve links by default**. If this behaviour is not what you want, you can use the chain modifier `withoutLinkResolution` on the Contentful client to keep the link objects instead of the inlined entries in your response object. See [client chain modifiers](README.md#client-chain-modifiers).
115
+
116
+ **Links which could not get resolved will be kept by default** as `UnresolvedLink`. If you want to completely remove fields which could not be resolved, you can use the chain modifier `withoutUnresolvableLinks`.
117
+
118
+ Please see the notes below for link resolution prior to v.10.0.0 and v.7.0.0.
119
+
120
+ #### Note: link resolution for versions older than 10.0.0
121
+
122
+ Please note that for versions older than 10.0.0, disabling link resolution needs to be done via [configuration options](README.md#response-configuration-options) during client creation.
123
+ To disable it, set `resolveLinks` to `false` when creating the Contentful client. Like so:
124
+
125
+ ```js
126
+ const contentful = require('contentful')
127
+ const client = contentful.createClient({
128
+ accessToken: '<you-access-token>',
129
+ space: '<your-space-id>',
130
+ resolveLinks: false,
131
+ })
132
+ ```
133
+
134
+ If you want to completely remove fields which could not be resolved, set `removeUnresolved` to `true` in the configuration options.
135
+
136
+ #### Note: link resolution for versions older than 7.0.0
137
+
138
+ Please note that for versions older than 7.0.0, link resolution is only possible when requesting records from the collection endpoint using `client.getEntries()` or by performing an initial sync `client.sync({ initial: true })`. In case you want to request one entry and benefit from the link resolution you can use the collection end point with the following query parameter `'sys.id': '<your-entry-id>'`.
139
+
140
+ ##### Example
141
+
142
+ Assuming that you have a Content Type `post` that has a reference field `author`:
143
+
144
+ ```js
145
+ const contentful = require('contentful')
146
+ const client = contentful.createClient({
147
+ accessToken: '<you-access-token>',
148
+ space: '<your-space-id>',
149
+ })
150
+ // getting a specific Post
151
+ client
152
+ .getEntries({ 'sys.id': '<entry-id>' })
153
+ .then((response) => {
154
+ // output the author name
155
+ console.log(response.items[0].fields.author.fields.name)
156
+ })
157
+ .catch((err) => console.log(err))
158
+ ```
159
+
160
+ ### Links to other spaces
161
+
162
+ As they are part of another space, resolving cross-space linked entities requires a special header to be passed named `x-contentful-resource-resolution`.
163
+
164
+ To be able to create this header, you need to follow the instructions in this [subsection of our documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/resource-links:~:text=Extra%20header%20for%20cross%2Dspace%20resolution)
165
+
166
+ Once you created the Base64 encoded token, you can pass the new header to your client as part of the `headers` option.
167
+
168
+ When calling the `getEntries` method, The resolved cross space links will be available under the `Entry` array in the `includes` part of the response.
169
+
170
+ #### Example
171
+
172
+ ```ts
173
+ import { createClient } from 'contentful'
174
+ const client = createClient({
175
+ accessToken: '<you-access-token>',
176
+ space: '<your-space-id>',
177
+ environment: '<your-environment-id>',
178
+ headers: {
179
+ 'x-contentful-resource-resolution': '<your-base64-generated-header>'
180
+ }
181
+ })
182
+ // getting all Entries
183
+ client
184
+ .getEntries()
185
+ .then((response) => {
186
+ // You should find the linked entries in the includes.Entry array
187
+ console.log(response.includes.Entry)
188
+ })
189
+ .catch((err) => console.log(err))
190
+
191
+ // filtering on one entry
192
+ client
193
+ .getEntries({ 'sys.id': '<entry-id>' })
194
+ .then((response) => {
195
+ // You should find the linked entries in the includes.Entry array
196
+ console.log(response.includes.Entry)
197
+ })
198
+ .catch((err) => console.log(err))
199
+ ```
200
+
201
+ ## Sync
202
+
203
+ The Sync API allows you to keep a local copy of all content in a space up-to-date via delta updates, meaning only changes that occurred since the last sync call.
204
+ Whenever you perform a sync operation the endpoint will send back a `syncToken` which you can use in a subsequent sync to only retrieve data which changed since the last call.
205
+
206
+ ##### Example
207
+
208
+ ```js
209
+ const contentful = require('contentful')
210
+ const client = contentful.createClient({
211
+ accessToken: '<you-access-token>',
212
+ space: '<your-space-id>',
213
+ })
214
+ // first time you are syncing make sure to specify `initial: true`
215
+ client
216
+ .sync({ initial: true })
217
+ .then((response) => {
218
+ // You should save the `nextSyncToken` to use in the following sync
219
+ console.log(response.nextSyncToken)
220
+ })
221
+ .catch((err) => console.log(err))
222
+ ```
223
+
224
+ The SDK will go through all the pages for you and give you back a response object with the full data so you don't need to handle pagination.
225
+
226
+ ### Sync without pagination
227
+
228
+ You may use syncing without pagination if you want to handle it on your own. To do this, you have to pass `paginate: false` as an option when calling sync. You manually have to take care to pass `nextPageToken` or `nextSyncToken` to your subsequent calls. The logic follows our [sync API docs](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization/pagination-and-subsequent-syncs) while you pass tokens instead of full urls.
229
+
230
+ ##### Example
231
+
232
+ ```js
233
+ const contentful = require('contentful')
234
+ const client = contentful.createClient({
235
+ accessToken: '<you-access-token>',
236
+ space: '<your-space-id>',
237
+ })
238
+
239
+ function customPaginatedSync(query) {
240
+ // Call sync, make sure you set paginate to false for every call
241
+ return client.sync(query, { paginate: false }).then((response) => {
242
+ // Do something with the respond. For example save result to disk.
243
+ console.log('Result of current sync page:', response.items)
244
+
245
+ // Sync finished when `nextSyncToken` is available
246
+ if (response.nextSyncToken) {
247
+ console.log('Syncing done. Start a new sync via ' + response.nextSyncToken)
248
+ return
249
+ }
250
+
251
+ // Otherwise, just continue to next page of the current sync run
252
+ return customPaginatedSync({ nextPageToken: response.nextPageToken })
253
+ })
254
+ }
255
+
256
+ customPaginatedSync({ initial: true }).then(() => console.log('Sync done'))
257
+ ```
258
+
259
+ ## Querying & Search parameters
260
+
261
+ You can pass your query parameters as `key: value` pairs in the query object whenever you request a resource. For example:
262
+
263
+ ```js
264
+ const contentful = require('contentful')
265
+ const client = contentful.createClient({
266
+ accessToken: '<you-access-token>',
267
+ space: '<your-space-id>',
268
+ })
269
+
270
+ // getting a specific Post
271
+ client
272
+ .getEntries({ 'sys.id': '<entry-id>' })
273
+ .then((response) => {
274
+ // output the author name
275
+ console.log(response.items[0].fields.author.fields.name)
276
+ })
277
+ .catch((err) => console.log(err))
278
+
279
+ // You can pass a query when requesting a single entity
280
+ client.getEntry('<entry-id>', { key: value })
281
+ ```
282
+
283
+ For more information about the search parameters, check the [documentation](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters).
@@ -0,0 +1,109 @@
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">Contributing</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
+ <p align="center">
30
+ <a href="http://makeapullrequest.com">
31
+ <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?maxAge=31557600" alt="PRs Welcome">
32
+ </a>
33
+ &nbsp;
34
+ <a href="http://makeapullrequest.com">
35
+ <img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?maxAge=31557600" alt="Semantic Release">
36
+ </a>
37
+ &nbsp;
38
+ <a href="http://standardjs.com/">
39
+ <img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?maxAge=31557600" alt="JS Standard Style">
40
+ </a>
41
+ </p>
42
+
43
+ We appreciate any community contributions to this project, whether in the form of issues or pull requests.
44
+
45
+ This document outlines what we'd like you to follow in terms of commit messages and code style.
46
+
47
+ It also explains what to do in case you want to set up the project locally and run tests.
48
+
49
+ **Working on your first Pull Request?** You can learn how from this extensive [list of resources for people who are new to contributing to Open Source](https://github.com/freeCodeCamp/how-to-contribute-to-open-source).
50
+
51
+ ## Setup
52
+
53
+ This project is written in ES2015 and transpiled to ES5 using Babel, to the `dist` directory. This should generally only happen at publishing time, or for testing purposes only.
54
+
55
+ Run `npm install` to install all necessary dependencies. When running `npm install` locally, `dist` is not compiled.
56
+
57
+ All necessary dependencies are installed under `node_modules` and any necessary tools can be accessed via npm scripts. There is no need to install anything globally.
58
+
59
+ When importing local, in development code, via `index.js`, this file checks if `dist` exists and uses that. Otherwise, it uses the code from `lib`.
60
+
61
+ If you have a `dist` directory, run `npm run clean`.
62
+
63
+ ## Useful npm scripts
64
+
65
+ - `npm run clean` removes any built files
66
+ - `npm run build:dev` builds vendored files, node package and browser version
67
+ - `npm run build:prod` builds production-ready minified sources
68
+ - `npm run build` combines `clean`, `build:dev` and `build:prod`
69
+ - `npm run build:types` emits type declaration files for js files
70
+
71
+ ## Running tests
72
+
73
+ This project has unit and integration tests, as well as tests checking types. All of these run on both Node.js and browser environments.
74
+
75
+ Both of these test environments are setup to deal with Babel and code transpiling, so there's no need to worry about that.
76
+
77
+ - `npm run test:unit` runs Node.js unit tests
78
+ - `npm run test:integration` runs the integration tests against the Contentful CDA API
79
+ - `npm run test:types` runs type checking tests
80
+ - `npm test` runs linting on the test code and runs all three kinds of tests
81
+ - `test:demo-node` runs a Node.js demo application and its tests, making sure that Node.js builds are functioning and are bundled correctly
82
+ - `test:demo-browser` runs a browser client demo application and its tests, making sure that browser builds are functioning and are bundled correctly
83
+ - `test:demo-projects` runs both Node.js and browser application tests
84
+
85
+ ## Documentation
86
+
87
+ Code is documented using TypeDoc, and reference documentation is published automatically with each new version.
88
+
89
+ - `npm run docs:watch` watches code directory, and rebuilds documentation when anything changes. Useful for documentation writing and development
90
+ - `npm run docs:build` builds documentation
91
+ - `npm run docs:publish` builds documentation and publishes it to github pages
92
+
93
+ ## Code style
94
+
95
+ This project uses ESLint configuration from [standard](https://github.com/feross/standard). Install a relevant editor plugin if you'd like.
96
+
97
+ Everywhere where it isn't applicable, follow a style similar to the existing code.
98
+
99
+ ## Commit messages and issues
100
+
101
+ This project uses the [Angular JS Commit Message Conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit), via semantic-release. See the semantic-release [commit message format](https://github.com/semantic-release/semantic-release#commit-message-format) section for more details.
102
+
103
+ ## Versioning
104
+
105
+ This project strictly follows [Semantic Versioning](http://semver.org/) by use of [semantic-release](https://github.com/semantic-release/semantic-release).
106
+
107
+ This means that new versions are released automatically as fixes, features or breaking changes are released.
108
+
109
+ You can check the changelog on the [releases](https://github.com/contentful/contentful.js/releases) page.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Contentful
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.