Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drhook

Small durable webhook delivery for Node.js 20+.

drhook stores webhook work in SQLite before delivery, retries failures with exponential backoff, and restores in_progress work to pending when the process restarts.

Install

npm install drhook

not yet published to npm (dont have npm pro)

Quickstart

import { createWebhooks } from 'drhook';

const webhooks = createWebhooks({
  databaseUrl: './webhooks.sqlite',
  maxAttempts: 8,
  deliveryTimeoutMs: 5000,
});

await webhooks.start();

await webhooks.register('order.created', 'https://example.com/hook');

await webhooks.emit('order.created', {
  orderId: 123,
});

Webhook requests are sent as JSON:

{
  "id": "delivery-id",
  "eventName": "order.created",
  "payload": {
    "orderId": 123
  }
}

API

webhooks.register(eventName, url);
webhooks.unregister(eventName, url);
webhooks.emit(eventName, payload);
webhooks.start();
webhooks.stop();
webhooks.listSubscriptions();
webhooks.listDeliveries();

Development

cd drhook
npm install
npm run lint
npm run typecheck
npm test
npm run build

Run the Express example:

npm run dev

Then try it:

curl -X POST http://localhost:3000/subscriptions \
  -H 'content-type: application/json' \
  -d '{"eventName":"order.created","url":"http://localhost:3000/demo-receiver"}'

curl -X POST http://localhost:3000/events/order.created \
  -H 'content-type: application/json' \
  -d '{"orderId":123}'

About

A simple persisting hook+action management tool.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages