webhook-easy
Sign, verify, and deliver JSON webhooks. The signature is HMAC-SHA256 over timestamp.rawBody, sent in X-Webhook-Easy-Signature as t=<seconds>,v1=<hex>.
Node.js 18 or newer. No runtime dependencies.
npm install webhook-easy
Send
const { deliver } = require('webhook-easy');
const result = await deliver({
url: 'https://example.com/webhooks',
secret: process.env.WEBHOOK_SECRET,
event: 'invoice.paid',
payload: { id: 'in_1' },
});
console.log(result.id, result.status, result.attempts, result.ok);
deliver retries network failures and HTTP 500 responses. A 4xx response comes back immediately with ok: false. The same body and signature are reused for every attempt.
Receive
const http = require('node:http');
const { createHandler } = require('webhook-easy');
const handler = createHandler({
secret: process.env.WEBHOOK_SECRET,
onEvent({ id, event, payload }) {
console.log(id, event, payload);
},
});
http.createServer(handler).listen(8787);
A valid event responds with 200 and { "received": true }. A bad signature, a stale timestamp, or invalid JSON responds with 400.
Verify the raw body
Pass the exact bytes you received. Do not parse the JSON and stringify it again.
const { verify } = require('webhook-easy');
const checked = verify(
rawBody,
req.headers['x-webhook-easy-signature'],
process.env.WEBHOOK_SECRET,
);
checked.timestamp is the unix time from the signature. The default tolerance is 300 seconds. verify throws WebhookError. Read error.code.
| Code |
Meaning |
MISSING_SECRET |
The secret was empty. |
MISSING_SIGNATURE |
The header was missing or malformed. |
BAD_SIGNATURE |
The HMAC does not match. |
STALE_TIMESTAMP |
The timestamp is outside the tolerance window. |
BAD_TIMESTAMP |
sign was given a timestamp that is not a number. |
MISSING_URL |
deliver was called without a URL. |
DELIVERY_FAILED |
Every attempt failed before an HTTP response. |
MISSING_HANDLER |
createHandler was called without onEvent. |
Headers
| Header |
Value |
Content-Type |
application/json |
User-Agent |
webhook-easy |
X-Webhook-Easy-Id |
Delivery id |
X-Webhook-Easy-Event |
Event name, default event |
X-Webhook-Easy-Timestamp |
Unix seconds |
X-Webhook-Easy-Signature |
t=<seconds>,v1=<hex> |
Local listener
npx webhook-easy listen --port 8787 --path /webhooks --secret dev-secret
POST signed events to that path. Each accepted event is printed as JSON. GET / returns the latest 20 events. Without --secret or WEBHOOK_EASY_SECRET, posts are stored and signatures are not checked.
Package layout
This package is CommonJS. Load it with require('webhook-easy'). The public API is documented in docs/api.md. Release notes are in CHANGELOG.md. Publish steps are in PUBLISHING.md.
License
MIT