contentful 11.0.1 → 11.0.2

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 (43) hide show
  1. package/ADVANCED.md +41 -0
  2. package/README.md +83 -54
  3. package/dist/contentful.browser.js +9712 -21037
  4. package/dist/contentful.browser.min.js +1 -1
  5. package/dist/contentful.cjs +23471 -0
  6. package/dist/esm/contentful.js +60 -0
  7. package/dist/esm/create-contentful-api.js +320 -0
  8. package/dist/esm/create-global-options.js +21 -0
  9. package/dist/esm/index.js +4 -0
  10. package/dist/esm/make-client.js +52 -0
  11. package/dist/esm/mixins/stringify-safe.js +23 -0
  12. package/dist/esm/paged-sync.js +118 -0
  13. package/dist/esm/utils/normalize-search-parameters.js +18 -0
  14. package/dist/esm/utils/normalize-select.js +25 -0
  15. package/dist/esm/utils/query-selection-set.js +14 -0
  16. package/dist/esm/utils/resolve-circular.js +15 -0
  17. package/dist/esm/utils/validate-params.js +52 -0
  18. package/dist/esm/utils/validate-search-parameters.js +11 -0
  19. package/dist/esm/utils/validate-timestamp.js +16 -0
  20. package/dist/esm/utils/validation-error.js +8 -0
  21. package/dist/stats-browser-min.html +4842 -0
  22. package/dist/types/contentful.d.ts +8 -4
  23. package/dist/types/create-contentful-api.d.ts +3 -3
  24. package/dist/types/index.d.ts +6 -6
  25. package/dist/types/make-client.d.ts +2 -2
  26. package/dist/types/paged-sync.d.ts +2 -2
  27. package/dist/types/types/asset.d.ts +2 -2
  28. package/dist/types/types/entry.d.ts +8 -3
  29. package/dist/types/types/index.d.ts +15 -15
  30. package/dist/types/types/link.d.ts +6 -1
  31. package/dist/types/types/metadata.d.ts +5 -1
  32. package/dist/types/types/query/index.d.ts +12 -12
  33. package/dist/types/types/query/query.d.ts +18 -12
  34. package/dist/types/types/query/reference.d.ts +1 -1
  35. package/dist/types/types/query/select.d.ts +2 -2
  36. package/dist/types/types/resource-link.d.ts +2 -2
  37. package/dist/types/utils/validate-params.d.ts +1 -2
  38. package/package.json +59 -60
  39. package/dist/contentful.browser.js.map +0 -1
  40. package/dist/contentful.node.js +0 -28637
  41. package/dist/contentful.node.js.map +0 -1
  42. package/dist/contentful.node.min.js +0 -2
  43. package/dist/contentful.node.min.js.LICENSE.txt +0 -12
package/ADVANCED.md CHANGED
@@ -157,6 +157,47 @@ client
157
157
  .catch((err) => console.log(err))
158
158
  ```
159
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
+
160
201
  ## Sync
161
202
 
162
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.
package/README.md CHANGED
@@ -58,33 +58,40 @@ JavaScript library for the Contentful [Content Delivery API](https://www.content
58
58
 
59
59
  <!-- TOC -->
60
60
 
61
- - [contentful.js - Contentful JavaScript Delivery library](#contentfuljs---contentful-javascript-delivery-library)
62
- - [Core Features](#core-features)
63
- - [Supported browsers and Node.js versions](#supported-browsers-and-nodejs-versions)
64
- - [Getting started](#getting-started)
65
- - [Installation](#installation)
66
- - [Using it directly in the browser](#using-it-directly-in-the-browser)
67
- - [Legacy browsers:](#legacy-browsers)
68
- - [React Native & Server Side Rendering:](#react-native--server-side-rendering)
69
- - [Your first request](#your-first-request)
70
- - [Using this library with the Preview API](#using-this-library-with-the-preview-api)
71
- - [Authentication](#authentication)
72
- - [Documentation & References](#documentation--references)
73
- - [Configuration](#configuration)
74
- - [Client chain modifiers](#client-chain-modifiers)
75
- - [Reference documentation](#reference-documentation)
76
- - [Tutorials & other resources](#tutorials--other-resources)
77
- - [Troubleshooting](#troubleshooting)
78
- - [Typscript](#typescript)
79
- - [Advanced Concepts](https://github.com/contentful/contentful.js/blob/master/ADVANCED.md)
80
- - [Migration](https://github.com/contentful/contentful.js/blob/master/MIGRATION.md)
81
- - [Reach out to us](#reach-out-to-us)
82
- - [You have questions about how to use this library?](#you-have-questions-about-how-to-use-this-library)
83
- - [You found a bug or want to propose a feature?](#you-found-a-bug-or-want-to-propose-a-feature)
84
- - [You need to share confidential information or have other questions?](#you-need-to-share-confidential-information-or-have-other-questions)
85
- - [Get involved](#get-involved)
86
- - [License](#license)
87
- - [Code of Conduct](#code-of-conduct)
61
+ - [Introduction](#introduction)
62
+ - [Core Features](#core-features)
63
+ - [Supported browsers and Node.js versions](#supported-browsers-and-nodejs-versions)
64
+ - [Getting started](#getting-started)
65
+ - [Installation](#installation)
66
+ - [Using in Legacy Environments Without ESM/Import Support](#using-in-legacy-environments-without-esmimport-support)
67
+ - [Using it directly in the browser](#using-it-directly-in-the-browser)
68
+ - [Your first request](#your-first-request)
69
+ - [Using this library with the Preview API](#using-this-library-with-the-preview-api)
70
+ - [Authentication](#authentication)
71
+ - [Documentation \& References](#documentation--references)
72
+ - [Configuration](#configuration)
73
+ - [Request configuration options](#request-configuration-options)
74
+ - [Response configuration options](#response-configuration-options)
75
+ - [Client chain modifiers](#client-chain-modifiers)
76
+ - [Entries](#entries)
77
+ - [Example](#example)
78
+ - [Assets](#assets)
79
+ - [Example](#example-1)
80
+ - [Sync](#sync)
81
+ - [Example](#example-2)
82
+ - [Reference documentation](#reference-documentation)
83
+ - [Tutorials \& other resources](#tutorials--other-resources)
84
+ - [Troubleshooting](#troubleshooting)
85
+ - [TypeScript](#typescript)
86
+ - [Advanced concepts](#advanced-concepts)
87
+ - [Migration](#migration)
88
+ - [Reach out to us](#reach-out-to-us)
89
+ - [You have questions about how to use this library?](#you-have-questions-about-how-to-use-this-library)
90
+ - [You found a bug or want to propose a feature?](#you-found-a-bug-or-want-to-propose-a-feature)
91
+ - [You need to share confidential information or have other questions?](#you-need-to-share-confidential-information-or-have-other-questions)
92
+ - [Get involved](#get-involved)
93
+ - [License](#license)
94
+ - [Code of Conduct](#code-of-conduct)
88
95
 
89
96
  <!-- /TOC -->
90
97
 
@@ -106,15 +113,17 @@ JavaScript library for the Contentful [Content Delivery API](https://www.content
106
113
  - Edge
107
114
  - Safari
108
115
  - node.js (LTS)
116
+ - React Native (Metro bundler)
109
117
 
110
- > See list of min supported browser version here [@contentful/browserslist-config
111
- > ](https://github.com/contentful/browserslist-config/blob/master/index.js)
118
+ > For the minimum supported browser versions, refer to the [package.json of this library.](https://github.com/contentful/contentful.js/blob/master/package.json#L12)
112
119
 
113
- The default export is an `es9` compliant module. In order to import the `commonJS` bundle, please use:
120
+ To ensure compatibility across various JavaScript environments, this library is built as an ECMAScript Module (ESM) by default, using the `"type": "module"` declaration in `package.json`.
114
121
 
115
- ```js
116
- const contentful = require('contentful/contentful.node')
117
- ```
122
+ We also offer a bundle for the legacy CommonJS (CJS) require syntax, allowing usage in environments that do not support ESM.
123
+
124
+ Additionally, there is a bundle available for direct usage within browsers.
125
+
126
+ For more details on the different variants of this library, see [Installation](#installation).
118
127
 
119
128
  ## Getting started
120
129
 
@@ -132,6 +141,26 @@ In order to get started with the Contentful JS library you'll need not only to i
132
141
  npm install contentful
133
142
  ```
134
143
 
144
+ In a modern environment, you can import this library using:
145
+
146
+ ```js
147
+ import * as contentful from 'contentful'
148
+ ```
149
+
150
+ #### Using in Legacy Environments Without ESM/Import Support
151
+
152
+ Typically, your system will default to our CommonJS export when you use the require syntax:
153
+
154
+ ```js
155
+ const contentful = require('contentful')
156
+ ```
157
+
158
+ If this does not work, you can directly require the CJS-compatible code:
159
+
160
+ ```js
161
+ const contentful = require('contentful/dist/contentful.cjs')
162
+ ```
163
+
135
164
  #### Using it directly in the browser
136
165
 
137
166
  For browsers, we recommend downloading the library via npm or yarn to ensure 100% availability.
@@ -157,7 +186,7 @@ Check the [releases](https://github.com/contentful/contentful.js/releases) page
157
186
  The following code snippet is the most basic one you can use to get some content from Contentful with this library:
158
187
 
159
188
  ```js
160
- const contentful = require('contentful')
189
+ import * as contentful from "contentful"
161
190
  const client = contentful.createClient({
162
191
  // This is the space ID. A space is like a project folder in Contentful terms
163
192
  space: 'developer_bookshelf',
@@ -178,7 +207,7 @@ Check out this [JSFiddle](https://jsfiddle.net/contentful/kefaj4s8/) version of
178
207
  This library can also be used with the Preview API. In order to do so, you need to use the Preview API Access token, available on the same page where you get the Delivery API token, and specify the host of the preview API, such as:
179
208
 
180
209
  ```js
181
- const contentful = require('contentful')
210
+ import * as contentful from "contentful"
182
211
  const client = contentful.createClient({
183
212
  space: 'developer_bookshelf',
184
213
  accessToken: 'preview_0b7f6x59a0',
@@ -225,26 +254,26 @@ The configuration options belong to two categories: request config and response
225
254
 
226
255
  ##### Request configuration options
227
256
 
228
- | Name | Default | Description |
229
- | ---------------- | --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
230
- | `accessToken` | | **Required**. Your CDA access token. |
231
- | `space` | | **Required**. Your Space ID. |
232
- | `environment` | `'master'` | Set the environment that the API key has access to. |
233
- | `host` | `'cdn.contentful.com'` | Set the host used to build the request URI's. |
234
- | `basePath` | `''` | This path gets appended to the host to allow request urls like `https://gateway.example.com/contentful/` for custom gateways/proxies. |
235
- | `httpAgent` | `undefined` | Custom agent to perform HTTP requests. Find further information in the [axios request config documentation](https://github.com/axios/axios#request-config). |
236
- | `httpsAgent` | `undefined` | Custom agent to perform HTTPS requests. Find further information in the [axios request config documentation](https://github.com/axios/axios#request-config). |
237
- | `adapter` | `undefined` | Custom adapter to handle making the requests. Find further information in the [axios request config documentation](https://github.com/axios/axios#request-config). |
257
+ | Name | Default | Description |
258
+ | ---------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
259
+ | `accessToken` | | **Required**. Your CDA access token. |
260
+ | `space` | | **Required**. Your Space ID. |
261
+ | `environment` | `'master'` | Set the environment that the API key has access to. |
262
+ | `host` | `'cdn.contentful.com'` | Set the host used to build the request URI's. |
263
+ | `basePath` | `''` | This path gets appended to the host to allow request urls like `https://gateway.example.com/contentful/` for custom gateways/proxies. |
264
+ | `httpAgent` | `undefined` | Custom agent to perform HTTP requests. Find further information in the [axios request config documentation](https://github.com/axios/axios#request-config). |
265
+ | `httpsAgent` | `undefined` | Custom agent to perform HTTPS requests. Find further information in the [axios request config documentation](https://github.com/axios/axios#request-config). |
266
+ | `adapter` | `undefined` | Custom adapter to handle making the requests. Find further information in the [axios request config documentation](https://github.com/axios/axios#request-config). |
238
267
  | `headers` | `{}` | Additional headers to attach to the requests. We add/overwrite the following headers: <ul><li><b>Content-Type:</b> `application/vnd.contentful.delivery.v1+json`</li><li><b>X-Contentful-User-Agent:</b> `sdk contentful.js/1.2.3; platform node.js/1.2.3; os macOS/1.2.3` (Automatically generated)</li></ul> |
239
- | `proxy` | `undefined` | Axios proxy configuration. See the [axios request config documentation](https://github.com/axios/axios#request-config) for further information about the supported values.  |
240
- | `retryOnError` | `true` | By default, this library is retrying requests which resulted in a 500 server error and 429 rate limit response. Set this to `false` to disable this behavior. |
241
- | `application` | `undefined` | Application name and version e.g myApp/version. |
242
- | `integration` | `undefined` | Integration name and version e.g react/version. |
243
- | `timeout` | `30000` | in milliseconds - connection timeout. |
244
- | `retryLimit` | `5` | Optional number of retries before failure. |
245
- | `logHandler` | `function (level, data) {}` | Errors and warnings will be logged by default to the node or browser console. Pass your own log handler to intercept here and handle errors, warnings and info on your own. |
246
- | `requestLogger` | `function (config) {}` | Interceptor called on every request. Takes Axios request config as an arg. |
247
- | `responseLogger` | `function (response) {}` | Interceptor called on every response. Takes Axios response object as an arg. |
268
+ | `proxy` | `undefined` | Axios proxy configuration. See the [axios request config documentation](https://github.com/axios/axios#request-config) for further information about the supported values.  |
269
+ | `retryOnError` | `true` | By default, this library is retrying requests which resulted in a 500 server error and 429 rate limit response. Set this to `false` to disable this behavior. |
270
+ | `application` | `undefined` | Application name and version e.g myApp/version. |
271
+ | `integration` | `undefined` | Integration name and version e.g react/version. |
272
+ | `timeout` | `30000` | in milliseconds - connection timeout. |
273
+ | `retryLimit` | `5` | Optional number of retries before failure. |
274
+ | `logHandler` | `function (level, data) {}` | Errors and warnings will be logged by default to the node or browser console. Pass your own log handler to intercept here and handle errors, warnings and info on your own. |
275
+ | `requestLogger` | `function (config) {}` | Interceptor called on every request. Takes Axios request config as an arg. |
276
+ | `responseLogger` | `function (response) {}` | Interceptor called on every response. Takes Axios response object as an arg. |
248
277
 
249
278
  ##### Response configuration options
250
279