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

hooka-relay-node

v2.0.0

Published

Typed Hooka Relay event client and Standard Webhooks verification

Readme

hooka-relay-node

Server-side Node.js 20.9+ client for Hooka Relay.

npm install hooka-relay-node
import { HookaRelay, HookaError } from "hooka-relay-node";
const relay = new HookaRelay(process.env.HOOKA_API_KEY!);
const event = await relay.sendEvent({
  customerId: "cus_123", type: "order.created", payload: { orderId: "123" }, idempotencyKey: "order-123-created",
});
console.log(event.id);

Use an application key with ingest permission. The customer ID must belong to that application; create customers in the dashboard or customer API before sending. baseUrl, timeoutMs (default 30,000), and fetch are optional constructor settings. HTTP is allowed only for localhost development; redirects are rejected to prevent credential forwarding. The client makes one request, with no implicit retry. On ambiguous network failure, retry with the same explicit idempotencyKey. Omitted keys are generated by the server; resending without a key can create another event.

HookaError exposes status, parsed body, and the raw retryAfter header. Rate limits return 429, oversized requests 413, and schema failures 400 with failures: [{path, message}]. Input limit: 256 KiB / JSON depth 32. Types are generated from the repository's OpenAPI contract.

Verify and queue, then drain

verifyWebhook(rawBody, headers, secret) delegates to the Standard Webhooks reference library. It throws on an invalid signature, changed ID/body, or timestamp outside five minutes. Use the displayed whsec_ secret and raw bytes. During rotation either key verifies the space-separated signatures.

Minimal receiver using only Node's HTTP module. Acknowledge after queue admission; slow processing runs separately. Return 503 when the bounded queue is full so Hooka Relay can retry.

import { createServer } from "node:http";
import { verifyWebhook } from "hooka-relay-node";
const queue = [];
async function processEvent(item) { console.log(item.id, item.payload); }
setInterval(async () => {
  if (draining) return;
  draining = true;
  try {
    for (let item; (item = queue.shift());) {
      try { await processEvent(item); }
      catch (error) { console.error("Move failed item to your dead-letter store", item.id, error); }
    }
  } finally { draining = false; }
}, 25);
let draining = false;
createServer(async (req, res) => {
  if (req.method !== "POST" || req.url !== "/webhook") { res.writeHead(404).end(); return; }
  const chunks = []; let bytes = 0;
  try {
    for await (const chunk of req) {
      bytes += chunk.length;
      if (bytes > 262144) { res.writeHead(413).end(); return; }
      chunks.push(chunk);
    }
    const headers = Object.fromEntries(["webhook-id", "webhook-timestamp", "webhook-signature"].map(k => [k, typeof req.headers[k] === "string" ? req.headers[k] : ""]));
    const payload = verifyWebhook(Buffer.concat(chunks), headers, process.env.HOOKA_SIGNING_SECRET);
    if (queue.length >= 1000) { res.writeHead(503).end(); return; }
    queue.push({ id: headers["webhook-id"], payload });
    res.writeHead(202).end();
  } catch { res.writeHead(400).end(); }
}).listen(8080);

This example's queue is volatile: a process crash loses acknowledged work. For production, durably enqueue before acknowledging (for example, a Postgres inbox table or persistent Redis queue). Atomically deduplicate the verified webhook-id with your business changes. Persist failed processing items for retry/dead-letter handling; logging alone does not recover them.

Event ordering

Ordering is not guaranteed across retries or replay generations. The queue-and-drain example above keeps slow or failing handlers from blocking acknowledgement. It does not restore producer ordering: use per-entity sequence/version checks when your business logic needs that guarantee.

Interactive API reference · Security and migration