Webhooks

Subscribe to what happens to artifacts, and get a signed POST for each event. Delivery is a port (ADR 0003): the reference sender is in-process, and Svix/Hookdeck/Convoy replace it without changing the event catalogue, the payload, or the outbox.

POST /api/webhooks   { "url": "https://example.com/hooks", "kinds": ["artifact.version.published"] }
→ 201 { "subscription": { "id": "sub_…", "secret": "whsec_…", … } }   // secret shown once

The events

kindwhen
artifact.createda new artifact
artifact.updateda version was added
artifact.deleteddeleted
artifact.version.publisheda body row was attached (the domain event artifact.published)
artifact.share.created / artifact.share.revokedthe public link changed
artifact.vieweda page was served — { version, channel }, one per GET, never for HEAD
artifact.state.changeda state key was written — { scope, key, bytes }, never the value
comment.thread.created / comment.thread.resolved / comment.createdthreads and replies

kinds empty means every kind; artifactIds empty means every artifact the subscriber owns. A body never travels in an event — the payload says what changed and gives the id, and the consumer fetches the thing if it needs it.

The delivery

POST https://example.com/hooks
content-type: application/json
x-artifactkit-event: artifact.version.published
x-artifactkit-delivery: evt_ab12cd34_812
x-artifactkit-seq: 812
x-artifactkit-timestamp: 1795842019
x-artifactkit-signature: sha256=<hex hmac of `${timestamp}.${body}` with your secret>

{ "id": "evt_ab12cd34_812", "kind": "…", "seq": 812, "artifactId": "art_…",
  "createdAt": "…", "data": { …domain event… } }

Verify by recomputing the HMAC over the timestamp and the raw body, and reject a timestamp older than a few minutes — that is what stops a captured request being replayed. Dedupe on x-artifactkit-delivery: delivery is at-least-once, and a retry carries the same id.

Retries

Draining

Nothing here runs a timer. A cron, a queue consumer, or you:

POST /api/webhooks/drain            → { delivered, retrying, deadLettered, subscriptions }
POST /api/webhooks/drain  { "all": true }   // deployment-level: every active subscription

Each call does bounded work (one page of the outbox per subscription, stopping at the first failure so ordering per artifact holds). On a serverless host, point a scheduled function at it.

Swapping in Svix

import { createSvixSender } from '@artifactkitdev/core/adapters/webhook/svix';

const webhooks = createWebhookService({
  subscriptions, log, runtime,
  sender: createSvixSender({ apiKey: process.env.SVIX_API_KEY! }),
});

They take over the endpoint registry, retries, the signing scheme, the delivery log and the replay UI. Ours stay: the catalogue, the payload, and the outbox cursor — the drain only advances after Svix accepts the message, and the message's eventId is our deliveryId, so their dedupe and ours agree on what "the same delivery" means.

SSRF

A subscription URL must be https, may not carry credentials, and may not resolve to a literal private/loopback/link-local host or *.internal/*.local. That is a string check at subscription time; the redirect rule above is the other half, because a public URL can redirect anywhere.