AshHooks.Event (AshHooks v1.0.2)

Copy Markdown View Source

The outbound pipeline's unit of work — what a consumer emits and the fanout dispatcher delivers.

{:ok, event} = AshHooks.Event.new(type: :order_paid, payload: Jason.encode!(order))

AshHooks.dispatch(OrderResource, :order_paid, event)

Contract:

  • id — the webhook id (msg_-prefixed, URL-safe, NEVER .-carrying: . is the canonical-string delimiter of the Standard Webhooks signature, msg_id.timestamp.payload). Generated when absent; a caller-supplied id that is non-binary, empty, or carries a . is rejected (the signing path enforces the same constraint — this keeps the rejection at the boundary, before anything persists).
  • type — atom or binary, canonicalized to a STRING at construction: strings are the single representation the subscription filter, the delivery ledger, and the outbound DSL name compare on.
  • payload — the exact BINARY bytes to sign and send. Structs and maps are rejected: signing re-encoded maps is the interoperability failure that kept the official Elixir reference library unusable.
  • metadata — a map of non-signed context (default %{}).

Summary

Functions

Builds a validated event. Returns {:ok, %AshHooks.Event{}} or {:error, reason} — never raises on caller input.

Types

t()

@type t() :: %AshHooks.Event{
  id: String.t(),
  metadata: map(),
  payload: binary(),
  type: String.t()
}

Functions

new(attrs)

@spec new(keyword() | map()) :: {:ok, t()} | {:error, String.t()}

Builds a validated event. Returns {:ok, %AshHooks.Event{}} or {:error, reason} — never raises on caller input.