npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

contentful-webhook-listener

v1.0.4

Published

A Simple HTTP Webserver for listening to Contentful API Webhooks with JavaScript

Downloads

1,297

Readme

Contentful Webhook Listener

Build Status NPM Dependency Status NPM Verion

An HTTP server for listening to Contentful API Webhooks with JavaScript. This provides a Node.js module to create a web server and then emits events for each action (create, save, autoSave, etc) that occurs in Contentful.

Contentful is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.

Webhooks in Contentful can notify you or someone else when content has changed by calling a preconfigured HTTP endpoint. This can be used for notifications, static site generators or other forms of post-processing sourced from Contentful.

Setup a custom callback that executes on-demand and it will receive the latest version of the Entry, Asset, or Content Type for each create, save, autoSave, archive, unarchive, or publish event in Contentful. The unpublish and delete events in Contentful send a DeletedEntry or DeletedAsset payload.

See the Contentful Content Management API documentation for more details on their webhooks.

Pair this with ngork for local development, or a server behind a firewall, that responds to actions in Contentful or consider the contentful-webhook-tunnel module which automates the whole process.

If you are looking for a ruby gem with similar functionality, check out contentful-webhook-listener.

Install

npm install contentful-webhook-listener

Usage

var listener = require("contentful-webhook-listener");
var webhook = listener.createServer();
var port = 5000;

webhook.on("publish", function (payload) {

	console.log(payload);

});

webhook.listen(port);

listener extends the http module, so all the methods, properties, and events from the http module are available on the listener module.

createServer() accepts a options argument in addition to the standard requestListener function. The options argument accepts a auth property which will enable and enforce HTTP Basic Authentication. The auth property value should be the username and password in <username>:<password> format.

var listener = require("contentful-webhook-listener");
var webhook = listener.createServer({
	"auth": "username:password"
}, function requestListener (request, response) {

	console.log("request received");

});
var port = 5000;

webhook.on("publish", function (payload) {

	console.log(payload);

});

webhook.listen(port, function callback () {

	console.log("server is listening");

});

Payload Properties

The payload returned has the following properties for the create, save, autoSave, archive, unarchive, or publish events. Sample data from the Contentful API sample space with cats.

{
	"contentType": "cat",
	"fields": {
		"name": {
			"en-US": "Nyan Cat"
		},
		"likes": {
			"en-US": [
				"rainbows",
				"fish"
			]
		},
		"color": {
			"en-US": "rainbow"
		},
		"bestFriend": {
			"type": "Link",
			"linkType": "Entry",
			"id": "happycat"
		},
		"birthday": {
			"en-US": "2011-04-04T22:00:00+00:00"
		},
		"lives": {
			"en-US": 1337
		},
		"image": {
			"type": "Link",
			"linkType": "Asset",
			"id": "nyancat"
		}
	},
	"id": "cat_nyancat",
	"kind": "Entry",
	"origin": "ContentManagement",
	"space": "cfexampleapi",
	"sys": {
		"space": {
			"sys": { }
		},
		"type": "Entry",
		"contentType": {
			"sys": { }
		},
		"id": "cat_nyancat",
		"revision": 1,
		"createdAt": "2016-10-24T19:48:51.128Z",
		"updatedAt": "2016-11-03T03:12:28.855Z"
	},
	"webhookName": "localhost"
}

The payload has the following properties for the unpublish and delete events:

{
	"contentType": "cat",
	"fields": null,
	"id": "cat_nyancat",
	"kind": "Entry",
	"origin": "ContentManagement",
	"space": "cfexampleapi",
	"sys": {
		"space": {
			"sys": { }
		},
		"type": "DeletedEntry",
		"contentType": {
			"sys": { }
		},
		"id": "cat_nyancat",
		"revision": 2,
		"createdAt": "2016-11-03T03:10:55.676Z",
		"updatedAt": "2016-11-03T03:10:55.676Z",
		"deletedAt": "2016-11-03T03:10:55.676Z"
	},
	"webhookName": "localhost"
}

Todo

  • add a command line interface

Changelog

1.0.4 — October 22, 2019

  • added files to package.json so only necessary files are included in npm tarball

1.0.3 — October 22, 2019

  • upgrade all dependencies

1.0.2 — November 8, 2016

  • closer server after emitting an error
  • only set contentType when contentType is available

1.0.1 — November 3, 2016

  • fixed npm badge in readme
  • fixed date of first release in change log

1.0.0 — November 3, 2016

License

contentful-webhook-listener.js is available under the MIT License.