tinacms-contentful v0.7.15
tinacms-contentful
A library for using Contentful with TinaCMS
Usage
Installation
To install the package, run:
npm install tinacms-contentful contentful contentful-managementSetup
To setup TinaCMS with Contentful, you must create an instance of the TinaCMS ContentfulClient for each space you want to edit content from.
For a single space:
import { ContentfulClient } from 'tinacms-contentful'
const contentful = new ContentfulClient({
spaceId: /* Contentful Space ID */,
defaultEnvironmentId: /* Contentful environment ID to use by default. Default: master */,
accessTokens: {
delivery: /* Contentful delivery access token for the space */,
preview: /* Contentful preview access token for the space */,
}
clientId: /* OAuth App Client ID */,
redirectUrl: /* OAuth App Callback URL */,
rateLimit: /* API Rate Limit for your Contentful Plan (Requests per second). Default: 4 */,
insecure: /* If true, uses same-site HTTPS cookies to create a session. Default: false */
})
const cms = new TinaCMS({
apis: {
contentful
}
})Or if the CMS has already been created:
cms.registerApi('contentful', contentful)For multiple spaces:
import { createContentfulClientForSpaces } from 'tinacms-contentful';
const spaces = [
{
spaceId: /* Contentful Space ID */,
defaultEnvironmentId: /* Contentful environment ID to use by default. Default: master */,
accessTokens: {
delivery: /* Contentful delivery access token for the space */,
preview: /* Contentful preview access token for the space */,
}
},
{
spaceId: /* Contentful Space ID */,
defaultEnvironmentId: /* Contentful environment ID to use by default. Default: master */,
accessTokens: {
delivery: /* Contentful delivery access token for the space */,
preview: /* Contentful preview access token for the space */,
}
}
]
const contentful = createClientForSpaces(spaces, {
clientId: /* OAuth App Client ID */,
redirectUrl: /* OAuth App Callback URL */,
rateLimit: /* API Rate Limit for your Contentful Plan (Requests per second). Default: 4 */,
insecure: /* If true, uses same-site HTTPS cookies to create a session. Default: false */
})Media
To add support for media, you must setup a media store for the space media should be uploaded to.
For a single space:
import { ContentfulClient, ContentfulMediaStore } from 'tinacms-contentful'
const contentful = new ContentfulClient({
spaceId: /* Contentful Space ID */,
defaultEnvironmentId: /* Contentful environment ID to use by default. Default: master */,
accessTokens: {
delivery: /* Contentful delivery access token for the space */,
preview: /* Contentful preview access token for the space */,
}
clientId: /* OAuth App Client ID */,
redirectUrl: /* OAuth App Callback URL */,
rateLimit: /* API Rate Limit for your Contentful Plan (Requests per second). Default: 4 */,
insecure: /* If true, uses same-site HTTPS cookies to create a session. Default: false */
})
const contentfulMediaStore = new ContentfulMediaStore(contentful);
const cms = new TinaCMS({
apis: {
contentful
},
media: contentfulMediaStore
})For multiple spaces:
The media store is only capable of acting on a single space at a time. To change spaces dynamically, run:
const spaceId = 'example-id'
const space = cms.api.contentful[spaceId]
cms.media.store = new ContentfulMediaStore(space)APIs
The library has the following core APIs:
- ContentfulClient: an API client for communicating with Contentful that integrates directly with the CMS.
- ContentfulMediaStore
There are other public APIs as well. To learn more, read the full API documentation.
Contentful Client
Creates a TinaCMS API client for communicating with a Contentful Space.
Options
The client takes the following constructor arguments.
Properties
The Client has the following properties:
allowedOrigins: the FQDNs allowed to receive Oauth bearer tokens. Defaults to the window hostname.environment: the current Contentful environment the space is communicating with.rateLimit: the rate limit at which API operation will be throttled to.sdks: the Contentful SDK Client instances for this space.
Methods
The Client has the following methods:
authenticate: triggers a popup window OAuth workflow .setEnvironment: changes the environment the space is communicating with.getEntry: fetch a publisheddelivery, draftpreview, or editablemanagemententry.getEntries: fetch multiple publisheddelivery, draftpreview, or editablemanagemententries.createEntry: create a new entry for a specific content model.updateEntry: update an existing entry with new data.deleteEntry: delete a specific entry.publishEntry: publish a specific entry.unpublishEntry: unpublish a specific entry.archiveEntry: archive a specific entry.getAsset: fetch a publisheddelivery, or draftpreviewasset.getAssets: fetch multiple publisheddelivery, or draftpreviewassets.getAssetCollection: fetch a paginated collection of publisheddelivery, or draftpreviewassets.createAsset: create a new asset from a file upload.updateAsset: update an existing asset from a file upload.deleteAsset: delete a specific asset.archiveAsset: archive a specific asset.getContentType: fetch a specific content type.sync: [EXPERIMENTAL] Fetch all entries and assets from the space in the given environment to allow access without network connection.
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago