Turns the consumer's resource into the outbound Subscription, specifying which events go to which endpoint, and with which signature envelope.
use Ash.Resource,
data_layer: AshSqlite.DataLayer,
extensions: [AshHooks.Subscription]
subscription do
endpoint_resource(MyApp.WebhookEndpoint)
endThe extension injects: event_types ({:array, :string}, default
["*"]), endpoint_id (uuid, the sole UUID-storage-compatible primary
key of the endpoint_resource, under any attribute name), and signing_mode
(:legacy | :dual | :standard, NULLABLE, with the outbound declaration's mode
applying when unset). A subscription's own
primary key follows the same single UUID-storage-compatible contract because
outbound delivery rows store it in subscription_id. UUIDv7 keys satisfy
this contract. Composite and non-UUID keys fail at DSL compilation with the
reference column named in the error.
With pausable :on, the extension also injects paused (boolean,
nonnullable, default false). The dispatcher skips paused subscriptions
before creating delivery rows. Existing delivery rows continue to deliver:
pausing is not cancellation. Applications pause and resume through their own
ordinary update actions and policies. Opting in requires a migration for
the paused column; the default :off adds no attribute or schema requirement.
Typing contract
Events carry string types. You can declare event_types yourself,
including as an array of constrained atoms. Your declaration replaces the
generated attribute, including its constraints and default. Atom and string
entries match the same event names. The bare "*" or :"*" entry matches
all event names.
Matching is exact strings plus the bare wildcard entry, evaluated IN MEMORY by the dispatcher after reading through the consumer's primary read action. There is no array-containment SQL, so the semantics are identical on every data layer.
The package injects NO read action and NO read policies: read surfaces are the consumer's to open through their own domain policies; internal dispatcher reads bypass authorization; application policies govern exposed reads.
subscription
Configuration of this resource as the outbound subscription.
Options
| Name | Type | Default | Docs |
|---|---|---|---|
endpoint_resource required | atom | The resource module carrying AshHooks.Endpoint that endpoint_id references. The dispatcher loads endpoint records through it and calls AshHooks.Endpoint.enabled?/1 to decide whether they receive delivery rows. | |
pausable | :off | :on | :off | Whether the subscription pause column is injected (default :off, leaving existing schemas untouched). With :on, the extension injects paused (boolean, nonnullable, default false). The dispatcher skips paused subscriptions before creating delivery rows; existing delivery rows are unaffected. Applications pause and resume through ordinary updates of paused under their own actions and policies. Declaring :on requires a migration for the column. |
filter_attributes | list(atom) | [] | The closed set of EVENT ATTRIBUTE names subscriptions may filter on (e.g. [:order_id, :region]). Declaring a nonempty list injects the event_filters column (:map, nullable): a subscription whose filters all match the dispatching event's metadata receives the delivery. Filters are evaluated BEFORE any delivery row is created. A filter key outside this set never matches (fail closed); a list value matches any-of. Requires a migration for the column. |