Welcome to Nebutra Sailor Docs 🎉
ChangelogIntroductionLicensing
Help Center (External) ↗

Webhooks

Send and receive real-time events between Nebutra and your external systems.

Overview

Nebutra's webhook system (@nebutra/webhooks) allows you to:

  1. Receive events from Nebutra (inbound webhooks — e.g. Creem, GitHub)
  2. Send events to your customers' systems (outbound webhooks — when things happen in your product)

Outbound webhooks

Register an endpoint

Customers register webhook endpoints from Settings → Webhooks → Add Endpoint. There's no separate client SDK for this — the settings page calls the gateway route directly, which stores the endpoint and its event subscriptions via @nebutra/webhooks.

Send an event

import { getWebhooks } from "@nebutra/webhooks";

const webhooks = await getWebhooks();

await webhooks.sendEvent({
  id: crypto.randomUUID(),
  eventType: "invoice.paid",
  payload: {
    invoiceId: "inv_123",
    amount: 9900,
    currency: "usd",
  },
  timestamp: new Date().toISOString(),
  tenantId: "org_123",
});

Nebutra handles delivery, retries (with exponential backoff), and signature signing automatically.

Event delivery guarantees

PropertyValue
DeliveryAt-least-once
Retry attempts6 (exponential backoff, 5s initial delay)
SignatureHMAC-SHA256
Payload formatJSON
Timeout per attempt30 seconds

Inbound webhooks (receiving events)

Verifying signatures

Always verify webhook signatures before processing events. Nebutra's own current card rail (Creem, per ADR 2026-09-26) verifies the raw request body before parsing it — the same pattern applies to any inbound webhook you receive:

import { verifyCreemSignature } from "@nebutra/billing";

export async function POST(req: Request) {
  // Verify the bytes as received — parsing first would change them.
  const rawBody = await req.text();
  const signature = req.headers.get("creem-signature");

  if (!verifyCreemSignature(rawBody, signature)) {
    return new Response("Invalid signature", { status: 401 });
  }

  const event = JSON.parse(rawBody);

  switch (event.eventType) {
    case "checkout.completed":
      await handleCheckoutCompleted(event.object);
      break;
    case "refund.created":
      await handleRefundCreated(event.object);
      break;
  }

  return new Response("OK", { status: 200 });
}

Subscription webhooks (customer.subscription.*, invoice.*) still arrive from Stripe today (legacy) at a separate endpoint — see Payment Webhooks.

GitHub webhooks

import { createHmac, timingSafeEqual } from "node:crypto";

export async function POST(req: Request) {
  const body = await req.text();
  const signature = req.headers.get("x-hub-signature-256") ?? "";

  const expected =
    "sha256=" +
    createHmac("sha256", process.env.GITHUB_WEBHOOK_SECRET!).update(body).digest("hex");

  if (!timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return new Response("Invalid signature", { status: 400 });
  }

  const event = JSON.parse(body);
  // handle event.action, event.repository, etc.

  return new Response("OK", { status: 200 });
}

Webhook events reference

EventWhen it fires
org.createdA new organization is created
org.updatedOrg name or settings change
org.deletedOrganization is deleted
member.invitedA member invitation is sent
member.joinedA member accepts an invitation
member.removedA member is removed from the org
api_key.createdAn API key is created
api_key.revokedAn API key is revoked
project.createdA new project is created
project.deletedA project is deleted
invoice.paidA billing invoice is paid
subscription.changedPlan upgrade or downgrade
quota.warningUsage reaches 80% of quota
quota.exceededUsage exceeds 100% of quota

Testing webhooks locally

For Creem, set CREEM_TEST_MODE=true and point the webhook at your local tunnel, or use ngrok to expose your local server:

ngrok http 3000
# Copy the HTTPS URL → paste into your webhook endpoint settings

Related

Error Handling

How to handle failed webhook deliveries.

Creem Integration

Creem webhook setup guide — the current card rail.

How is this guide?

Edit on GitHub

Last updated on

On this page

Overview
Outbound webhooks
Register an endpoint
Send an event
Event delivery guarantees
Inbound webhooks (receiving events)
Verifying signatures
GitHub webhooks
Webhook events reference
Testing webhooks locally
Related