tinacms-contentful
TypeScript icon, indicating that this package has built-in type declarations

0.7.15 • Public • Published

tinacms-contentful

A library for using Contentful with TinaCMS

Usage

Installation

To install the package, run:

npm install tinacms-contentful contentful contentful-management

Setup

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:

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 published delivery, draft preview, or editable management entry.
  • getEntries: fetch multiple published delivery, draft preview, or editable management entries.
  • 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 published delivery, or draft preview asset.
  • getAssets: fetch multiple published delivery, or draft preview assets.
  • getAssetCollection: fetch a paginated collection of published delivery, or draft preview assets.
  • 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.

Readme

Keywords

none

Package Sidebar

Install

npm i tinacms-contentful

Weekly Downloads

41

Version

0.7.15

License

Apache-2.0

Unpacked Size

65.2 kB

Total Files

33

Last publish

Collaborators

  • scottgallant
  • jbevis
  • jpatters
  • chrisdmacrae