← All packages

@lacspace/webhooks

v1.0.2Backend Kit1 @lacspace dep

The webhook toolkit for both directions — sign & deliver outgoing webhooks with retries, and verify incoming ones (timing-safe, replay-protected) with Stripe / GitHub / Shopify presets. Plus event ids & idempotency. One internal dependency (@lacspace/crypto), isomorphic.

npm i @lacspace/webhooks

Usage

webhooks.ts
import { verify } from "@lacspace/webhooks";

// in your route — use the RAW request body, not the parsed JSON
const rawBody = await request.text();
const r = await verify(rawBody, request.headers.get("webhook-signature"), {
  secret: process.env.WEBHOOK_SECRET!,
  toleranceSec: 300, // reject anything older than 5 min (replay protection)
});

if (!r.valid) return new Response(`rejected: ${r.reason}`, { status: 400 });
// r.reason ∈ "no-signature" | "bad-format" | "bad-signature" | "timestamp-out-of-tolerance"

Exports 11

MemoryIdempotencyStoredeliverisDuplicateisValidnewIdsignsignHeadersverifyverifyGitHubverifyShopifyverifyStripe

Keywords

webhookwebhookswebhook-signatureverify-webhooksign-webhookstripe-webhook

More in Backend Kit