Guides
Webhooks
Verify schema-v1 event envelopes before parsing or processing them.
Webhook delivery is optional. When configured, Domain0 sends schema-v1 envelopes to the operator-selected HTTPS endpoint.
import { verifyDomain0Webhook } from 'domain0/contracts'
export async function POST(request: Request) {
const event = await verifyDomain0Webhook({
body: new Uint8Array(await request.arrayBuffer()),
headers: request.headers,
secretKeyring: {
'webhook-v1': decodeBase64(process.env.DOMAIN0_WEBHOOK_SECRET!),
},
})
await processOnceInTransaction(event.eventId, () => applyEvent(event))
return new Response(null, { status: 204 })
}Verify the untouched request bytes before parsing them. Store the event ID and your business mutation in one database transaction. Return success when that event ID was already processed.
Envelope
Schema v1 includes:
eventIdtypeconnectionIdapplicationIdtenantIdsequencetimestamp- typed
attributes
Use the exported discriminated union for exhaustive event handling. Do not trust duplicated identity or event headers until signature verification passes.