0.2.0 • Published 1 month ago

@last-rev/contentful-webhook-parser v0.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

Usage

Create a netlify function with this code:

const handleWebhook = require('@last-rev/contentful-webhook-handler');
const config = require('../../../../config');

module.exports.handler = async (event) => {
  try {
    await handleWebhook(
      config.clone({
        contentStrategy: 'cms',
        cmsCacheStrategy: 'redis'
      }),
      JSON.parse(event.body),
      event.headers
    );
    return {
      statusCode: 200,
      headers: { 'Content-Type': 'text/plain' },
      body: `Success`
    };
  } catch (err) {
    return {
      statusCode: 400,
      headers: { 'Content-Type': 'text/plain' },
      body: `There was an error, we are on it. ${err}`
    };
  }
};

Data

The webhook will be faster if you use the data as provided by contentful, but if this data exceeds limits, you can configure the webhook payload in the following way and it will not exceed limits, but will request the item from contentful after the webhook is fired:

{
  "sys": {
    "space": {
      "sys": {
        "id": "{ /payload/sys/space/sys/id }"
      }
    },
    "id": "{ /payload/sys/id }",
    "environment": {
      "sys": {
        "id": "{ /payload/sys/environment/sys/id }"
      }
    }
  }
}
0.2.0

1 month ago

0.1.4

11 months ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago