Skip to content

@xtandard/kit/hooks

@xtandard/kit/hooks — the hooks runner: before hooks run sequentially and may deny with HookDeniedError, after hooks run concurrently with isolated errors. Generic over a product’s event unions. Also isNamed, for mapping domain errors across bundles by name.

import { … } from "@xtandard/kit/hooks";
Name Summary
createHookErrorReporter Build an after-hook error reporter that warns with [source] as the log prefix and never throws. Products pass their package name: createHookErrorReporter("@xtandard/webhooks").
hookDeniedStatus The status of a hook denial — a HookDeniedError, or a foreign-bundle copy of it recognised by name (default 403 when it carries no numeric status) — or null when error is not a denial.
isNamed True when error is an error object whose name is name. Use it instead of instanceof to map domain errors to HTTP statuses: an error class loaded from a separate bundle (another subpath’s copy of the class, or another realm) fails instanceof but keeps its name.
normalizeHooks Normalize the hooks option into a flat array (empty when unset).
runAfter Run after hooks concurrently; errors go to onError, never to the caller.
runBefore Run before hooks sequentially; the first throw denies.
Name Summary
HookDeniedError Throw from a before hook to deny with a status (default 403).
Name Summary
HookEvent The minimum shape of a hook event: a type discriminant.
Hooks A hook: implement either side or both.
Name Summary
HookErrorReporter Reports an error thrown by an after hook.
HooksInput Accepts a single hook, an array, or nothing.
Name Summary
defaultHookErrorReporter Default after-hook error reporter: warns with the [@xtandard/kit] prefix, never throws.