Skip to content

@xtandard/webhooks

@xtandard/webhooks — self-hosted, embeddable, Standard Webhooks-compliant outbound-webhooks control plane.

The root export: the core and its types (also on /core and /schema), the dispatcher, the panel’s web-standard fetch handler, signing (also on /signing), portal tokens, the hooks contract, and the auth/authorization contracts. Storage adapters, auth providers, framework adapters and the React embeds are separate subpaths with optional peer dependencies.

import { … } from "@xtandard/webhooks";

Also re-exports symbols of @xtandard/webhooks/core, @xtandard/webhooks/schema, @xtandard/webhooks/signing, documented on those pages.

Name Summary
activeSecrets The endpoint’s currently-signing secrets: the active one + unexpired rotation grace.
attemptDelivery Perform one signed POST to endpoint.url. Never throws for remote-party failures — network errors, timeouts, and non-2xx responses all come back as a failed AttemptOutcome. (It does throw on programmer error, e.g. an endpoint with no unexpired secret.)
buildOpenApiDocument Build the OpenAPI 3.1 document for the admin API. Pure — safe to call anywhere.
buildSignedRequest Build the exact signed request an attempt would POST — Standard Webhooks headers, all unexpired secrets signing — without sending it. Shared by attemptDelivery and the panel’s request inspector so what you preview is byte-for-byte what a receiver gets.
createDispatcher Create a dispatcher over a core. Not started — call Dispatcher.start, or drive Dispatcher.tick manually.
createFetchHandler Build the panel fetch handler.
createPortalToken Mint a portal token granting access to applicationKey until expiresIn elapses (default 7 days). Call this server-side — anyone holding the portal secret can mint tokens for any application.
durationToMs Convert a WebhookDuration to milliseconds: a non-negative number of ms, or "<n><unit>" with unit ms, s, m, h, d (or w). Throws on negative, non-finite or malformed values.
emitDelivery Invoke listener safely off the delivery path: synchronous throws are caught and a returned Promise’s rejection is handled, so a broken sink can never fail (or slow, since it is not awaited) a delivery.
hasDeliveryQueue Runtime feature-detection: does this storage implement claimDue?
idPattern Regex an id of the given prefix must match.
isMutatingAction Whether action changes state.
newId Generate a new entity id, e.g. newId("msg") → "msg_0uK9…" (22-char base62 suffix).
parseDurationList Parse a comma-separated duration list (e.g. the RETRY_SCHEDULE env var, "0,30s,5m,1h"), validating each entry eagerly.
pgListenNotify A WatchSubscribe source for Postgres LISTEN/NOTIFY: the database owns the trigger that pg_notifys channel with the changed key as payload; client is a dedicated listening connection.
requirePeer Helper for adapters whose subpath requires an optional peer dependency. Throws a clear, actionable error when the peer is missing.
validateApplication Validate an Application: structure + reserved-key check.
validateEndpoint Validate an Endpoint input: structure, URL policy, and static-header restrictions (the Standard Webhooks headers are reserved).
validateEndpointUrl Validate an endpoint destination URL: parseable, https: (or http: for localhost, or anywhere when allowInsecureUrls), no embedded credentials, and passing the host’s optional urlPolicy gate.
validateEventType Validate an EventType: structural only (the name regex carries the semantics).
verifyPortalToken Verify a portal token: format, signature (constant time), then expiry. Returns the granted application key on success; throws PortalTokenError otherwise.
Name Summary
AttemptDeliveryInput Input to attemptDelivery.
AttemptOutcome The observed outcome of one HTTP delivery attempt.
BuildSignedRequestInput Input to buildSignedRequest.
CreateFetchHandlerResult Return shape of createFetchHandler.
DeliveryEvent One recorded delivery attempt, delivered to a DeliveryListener.
DeliveryQueueStorage Storage that can natively claim due deliveries (sorted-set / SKIP LOCKED class backends). When present, the dispatcher delegates claiming entirely to the adapter instead of scanning the generic due index.
Dispatcher The delivery engine handle.
DispatcherOptions Options for createDispatcher (also accepted on panels and the core).
OpenApiOptions Options for buildOpenApiDocument.
PortalTokenOptions Options for createPortalToken.
SignedRequest The exact HTTP request a delivery attempt sends — the inspector’s view.
UrlPolicyOptions Options that relax/extend the endpoint URL policy.
WebhooksPanelOptions Options for the panel handler (shared by every framework adapter).
WebhooksPortalOptions Portal composition for the panel: when set, requests bearing a valid whpt_… token act as a portal principal scoped to the token’s application.
Name Summary
AfterEvent Event delivered to WebhooksHooks.after — the committed mutation. Carries the resulting state in full: for destructive events this is the last chance to offload the payload before it is gone from storage.
AfterEventType
AuthorizationProvider Decides whether a principal may perform an action on a resource.
AuthorizeInput What AuthorizationProvider.authorize receives.
BeforeEvent Event delivered to WebhooksHooks.before — the proposed mutation, before it commits. Throw from the handler to deny it.
BeforeEventType The discriminant strings of BeforeEvent / AfterEvent.
DeliveryErrorReporter Reports an error thrown/rejected by a DeliveryListener.
DeliveryListener A fire-and-forget observer of delivery attempts. Return value (including a Promise) is ignored by the caller; throwing / rejecting never affects the delivery — failures are routed to the configured error reporter.
HookErrorReporter Receives an error thrown by an after hook, with the event it was handling.
IdPrefix Prefixes for the four generated entity id kinds.
PortalTokenError An invalid portal token (see the PortalTokenError class).
WebhooksAction Every action an admin API route can require.
WebhooksCorsOptions CORS for the panel: origin (a string, a list, or a predicate; "*" with credentials echoes the caller’s origin), credentials, methods, headers and maxAge.
WebhooksHooks Lifecycle hooks: before may deny a mutation by throwing (sequential, the first throw aborts); after observes committed changes (concurrent, errors isolated and reported).
WebhooksHooksInput One hook object, an array of them, or nothing (as hooks options accept).
WebhooksResource The resource an action targets.
Name Summary
DEFAULT_ATTEMPT_TIMEOUT_MS Default per-attempt timeout.
DEFAULT_PORTAL_ACTIONS The default portal grant: manage own endpoints (including secrets), inspect own messages/deliveries, retry, and read the event-type catalog.
DEFAULT_RESPONSE_BODY_LIMIT Default cap on how many response-body characters are kept per attempt.
DEFAULT_RETRY_SCHEDULE The default retry schedule (Svix-compatible).
defaultHookErrorReporter The default reporter: console.warn with the [@xtandard/webhooks] prefix.
KEY_REGEX Allowed characters for application keys and event type names.
MUTATING_ACTIONS Actions that change state; denied in readonly mode.
PORTAL_TOKEN_PREFIX Prefix of every portal token.
PortalTokenError Thrown by verifyPortalToken for any invalid token — malformed, bad signature, or expired. Maps to HTTP 401 at the API layer.
RESERVED_HEADERS Header names owned by the Standard Webhooks wire contract. Endpoints may not override them via static headers.
VERSION The published package version.