Developer docs/Guides
Events and hooks
Reference: Events index (every event, payload and emit site), Cancel and modify (everything you can stop or change) and Hook points index.
PeltyCMS emits a domain event after something has happened, for example invoice.paid. Before a few sensitive actions it also runs a pre-event, for example order.before_place, which a hook can cancel or modify. Every name, payload field and flag is listed in the event registry. That registry is checked by a test that scans the source for every emitted event.
#Who can receive events
- WASM addons list domain events in
capabilities.events. The host callson-event(name, payload)after the action has been committed. - WASM hooks list event names in
capabilities.hooks. These are pre-events, lifecycle phases such asbefore:PUT /api/v1/client/profile, or custom events. The host calls ophook. - Webhook plugins declare
hooksin their plugin manifest. The host sends each event as a signed HTTPS POST towebhook_url.
#Listening
/// Domain events listed in `capabilities.events` arrive here after the fact.
/// They cannot be cancelled; use them to sync, notify or count.
#Cancelling and modifying
/// Pre-events and lifecycle phases listed in `capabilities.hooks` call op
/// `hook`. Return `proceed`, `modify(payload)` or `cancel(reason)`.
A hook replies with one of the following:
{"action":"continue"}: let it through.{"action":"modify","payload":{…}}: replace the payload. Money fields can only change for addons holdingmoney.modify.{"action":"cancel","reason":"…"}: stop the action.{"action":"uncancel"}: undo an earlier cancellation. This only works withignore_cancelled: true.
#Lifecycle phases
Phases in order: before, during, after, finished. Source: crates/pelty-api/src/addon_events.rs.
before: synchronous, in priority order; listeners maymodifythe payload orcancelit (uncanceltoo whenignore_cancelled).monitorlisteners only observe. Money and secret rules apply.during: delivered while the action runs (concurrently, observe only).after: the action succeeded; the result is in the payload.finished: always last, withstatus=ok|failed|cancelled.
#Custom events
An addon can emit <its-own-id>:<event> if the name is listed in capabilities.emits. The before phase runs synchronously through every listener, in priority order. Other addons subscribe with before:<id>:<event> (and after: or finished:) in their hooks. An addon cannot emit an event in another addon's namespace.
/// Emit a custom event (`capabilities.emits`, name `<addon-id>:<event>`).
/// The `before` phase runs synchronously, so listeners can cancel or modify it.