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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@happyvertical/smrt-webhooks

v0.75.0

Published

Outbound webhook subscriptions, signed delivery, and durable retries

Readme

Outbound webhooks

@happyvertical/smrt-webhooks delivers tenant-scoped create, update, delete and custom events to public HTTPS endpoints, with an HMAC signature, a durable jobs queue, retry/backoff, and a safe delivery log.

Server setup

Migrate the package models and jobs system tables with the normal application migration flow before starting workers. Runtime code never creates application schema. Run this only in a Node server; import the UI from /svelte separately.

import {
  WebhookDispatcher, WebhookAdminService,
  registerWebhookRuntime, WebhookChangeFeed,
} from '@happyvertical/smrt-webhooks';
import { TaskRunner } from '@happyvertical/smrt-jobs';

const webhooks = new WebhookDispatcher({ db, runtime: 'application-webhooks' });
registerWebhookRuntime('application-webhooks', webhooks);
const events = new WebhookChangeFeed(webhooks, { orders: '@example/app:Order' });
// Poll from a host scheduler inside each authenticated tenant context.
await events.poll();
const admin = new WebhookAdminService(webhooks.store, async () =>
  currentUserHasPermission('webhooks:admin'));
const runner = new TaskRunner({ queues: ['webhooks'] });
await runner.initialize(db);
await runner.start();

Register the same runtime name in every worker process before starting jobs. The runner restores captured tenant context; all service calls require the host's authenticated withTenant context. Do not derive that context from a client-supplied tenant ID. Unregister optional hooks and call unregisterWebhookRuntime() on shutdown. The server entry is intentionally not browser-safe.

Lifecycle subscriptions use qualified model names. The recommended durable path is WebhookChangeFeed: map physical application tables to model names and poll in each tenant context. It reads s-m-r-t's committed change feed (including delete tombstones), publishes identity-only { id } payloads, and advances a persisted tenant/runtime cursor only after outbox/jobs are durable. Partial failure or process death before cursor advancement replays stable change-sequence IDs, which deduplicate against already enqueued deliveries. Global records and other tenants are excluded. Shared STI tables must map to their base model: the feed does not encode a child discriminator. Custom SQL that bypasses s-m-r-t persistence must explicitly append its domain event or core change-feed entry.

Poll more frequently than core change-feed retention. A pruned cursor raises WebhookHistoryExpiredError and stops rather than silently dropping history. After an operator reconciles source state and publishes any recoverable missing events, call resumeAfterResync(error.resumeCursor). Lost historical transitions cannot be reconstructed from a current-state snapshot alone; retain domain event history if that guarantee is required. Keep one stable model mapping per runtime; adding tables after its cursor has advanced does not backfill their older events.

registerWebhookModelEvents is an alternative low-latency hook binding with an explicit model allowlist. It also publishes only identities, but source writes and hooks are not atomic: a crash between source commit and hook enqueue can miss an event. Use the durable change-feed path when that gap is unacceptable. Do not enable both paths for the same models: their event IDs represent different publication streams. Neither path promises atomic network effects with source writes. Hooks propagate enqueue failures; re-saving a source object does not reconstruct a missing historical create/update event.

For custom events, authorize the data projection on the server:

await webhooks.dispatch({
  id: durableDomainEventId, event: 'custom.paid', model: '@example/app:Invoice',
  occurredAt: new Date().toISOString(), data: { id: invoiceId },
});

Empty event/model filters mean all events/models. Unknown nonempty custom names are supported; malformed envelopes and bodies over 256 KiB are rejected.

Delivery and recovery

A unique (tenant, subscription, event ID) outbox row and its jobs enqueue commit in one database transaction. Repeated dispatch is a no-op for that identity. Jobs contain only runtime, opaque tenant/delivery IDs, and a replay generation. Five attempts use jobs' exponential retry (1 second initial delay, multiplier 2, 5 minute cap). A delivery lease prevents overlapping HTTP attempts; an expired lease permits recovery after worker death. Terminal writes require the current lease token. Disabled subscriptions cancel unsent deliveries. Secrets are read at delivery time, so rotation applies to subsequent attempts.

Call store.reconcile() from a tenant-scoped operator sweep to turn exhausted or cancelled jobs into replayable failed deliveries. Admin refresh also runs reconciliation. admin.replay(id) atomically creates a new job only for a failed delivery; repeated replay is a no-op. Delivered events are never replayed by this API. Receivers must deduplicate x-smrt-delivery: if HTTP succeeds and the process dies before the outcome commits, recovery can send the same request again. The package does not claim exactly-once HTTP effects.

Security contract

Only HTTPS port 443 is allowed, without credentials or fragments. Every resolved DNS address must be public unicast. The socket lookup is pinned to a validated answer while TLS still verifies the original hostname. Redirects and connection pooling are disabled. DNS and request deadlines are 5 and 10 seconds. Special, private, mapped, transition and documentation IP ranges are conservatively rejected. Response bodies are never buffered or logged. A transport override is a trusted server-only integration seam and must preserve those requirements.

x-smrt-signature is sha256=<hex HMAC-SHA256(secret, timestamp + '.' + body)>, where timestamp is the exact x-smrt-timestamp header and body is the exact persisted UTF-8 request body. Verify in constant time, bound timestamp age, and deduplicate the delivery ID. verifyWebhookSignature({ secret, body, timestamp, signature, toleranceMs? }) does the constant-time compare and a 5-minute replay window (secret may be an array during rotation; the sender signs with one secret; body may be a string or Uint8Array; the timestamp must be the emitted YYYY-MM-DDTHH:mm:ss.sssZ form) and returns { ok: true } or { ok: false, reason: 'malformed' | 'expired' | 'mismatch' }; signWebhookPayload is the matching signer. Keys require at least 32 bytes of entropy-bearing secret material (generate them cryptographically; length alone is not entropy).

Signing profiles

Each subscription may store a signingProfile ({ preset, ...overrides }, null by default). The default profile is the scheme above and is pinned byte-for-byte by a golden test. Presets:

| Preset | Headers | Timestamp | Signature | | --- | --- | --- | --- | | default | x-smrt-signature, x-smrt-timestamp | ISO 8601 | sha256=<hex> over timestamp.body | | paperclip | x-paperclip-signature, x-paperclip-timestamp | Unix seconds | sha256=<hex> over timestamp.body; the prefix is optional on verify | | standard-webhooks | webhook-signature, webhook-timestamp, webhook-id | Unix seconds | v1,<base64> over id.timestamp.body, key = base64 of the whsec_ secret (the secret must still be 32+ bytes) |

Overridable fields: signatureHeader, timestampHeader, deliveryHeader, eventHeader (null omits it), timestampFormat (iso | unix | unix-ms), signDeliveryId, signatureEncoding, signaturePrefix, signaturePrefixRequired, multipleSignatures, secretEncoding. Header names must be distinct lowercase tokens. Resolve one with resolveWebhookSigningProfile('paperclip') and pass it as profile (plus deliveryId when the profile signs it) to verifyWebhookSignature; unix formats use the same 5-minute replay window. WebhookAdminService.create accepts signingProfile. Adding the nullable signingProfile column requires the normal application migration before deploying this version.

Secrets and payloads are durable sensitive data: use protected database access, backups and encryption at rest. Never serialize model instances with toJSON for clients; use the admin service or toPublicJSON. The admin view omits secrets, payloads and lease tokens, and transport errors are fixed safe strings.

Admin UI and recipe

WebhookAdmin from /svelte uses smrt-ui Button, Card, Input and Alert primitives. Supply subscriptions, deliveries, and async onCreate, onToggle, onReplay callbacks backed by WebhookAdminService. Refresh the view after mutations. The host owns login, administrator permissions, and CSRF protection. The component has busy/error states and never receives persisted signing secrets.

The integrations.webhooks recipe declares runtime: 'server' and the @happyvertical/smrt-webhooks/svelte#WebhookAdmin settings panel in the Integrations group. The host resolves that export and supplies the authenticated callbacks and safe read models described above. It intentionally declares no model navigation: generated CRUD is disabled for these sensitive internal models. It declares no provider or demo seed because transport configuration and signing secrets belong to the server; selecting the recipe does not configure a worker or authorize a browser to dispatch webhooks. The browser capability gate records this intentional server-only root against #3717; the separate /svelte export contains the administration component, not the delivery transport.

Validation

pnpm test exercises persistence, rollback, tenancy, retries, lease fencing, lifecycle events, redaction, HMAC and DNS pinning. pnpm check and pnpm typecheck check public TypeScript/Svelte contracts. pnpm test:e2e runs the maintained Chromium admin interaction harness. Build with pnpm exec turbo build --filter=@happyvertical/smrt-webhooks... from the root.