Skip to content

Contentful's content listener based on Contentful's sync API

Notifications You must be signed in to change notification settings

stackbit/contentful-listener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contentful Listener

The Contentful listener listens for content changes in Contentful and invokes the provided callback when such changes occur.

You can use this listener with Nextjs Hot Content Reload package when working locally to "hot reload" your browser with fresh content.

Usage:

import { ContentfulListener } from '@stackbit/contentful-listener';

const contentfulListener = new ContentfulListener({
    spaceId: process.env.CONTENTFUL_SPACE_ID,
    accessToken: process.env.CONTENTFUL_PREVIEW_API_KEY,
    environment: 'master',
    host: 'preview.contentful.com',
    pollingIntervalMs: 1000,
    callback: (result: CallbackResponse) => {
        // Do something
    }
});

contentfulListener.start();

The result is a an object having the following interface, very similar to Contentful's Sync API response:

export interface CallbackResponse {
    entries: Array<Entry<any>>;
    assets: Array<Asset>;
    deletedEntries: Array<Entry<any>>;
    deletedAssets: Array<Asset>;
}

About

Contentful's content listener based on Contentful's sync API

Resources

Stars

Watchers

Forks

Packages