Socket
Socket
Sign inDemoInstall

tinacms-contentful

Package Overview
Dependencies
2
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tinacms-contentful

TinaCMS API Client, Media Client, and utilities for the Contentful APIs


Version published
Weekly downloads
2
increased by100%
Maintainers
3
Install size
204 kB
Created
Weekly downloads
 

Readme

Source

tinacms-contentful

A library for using Contentful with TinaCMS

  • tinacms-contentful

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.

FAQs

Last updated on 12 May 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc