Documentation
¶
Overview ¶
Package webhooks is the webhook scenario: endpoint CRUD (the URL, subscription and signature rules), the webhook-events routes (index, show, destroy, retry) and the event publisher that writes the outbox rows inside the caller's transaction.
Index ¶
- Variables
- type EventFilter
- type Input
- type Publisher
- type PublisherStore
- type Scenario
- func (s Scenario) Create(ctx context.Context, account domain.Account, principal access.Principal, ...) (domain.WebhookEndpoint, error)
- func (s Scenario) Destroy(ctx context.Context, account domain.Account, principal access.Principal, ...) error
- func (s Scenario) EventDestroy(ctx context.Context, account domain.Account, principal access.Principal, ...) error
- func (s Scenario) EventShow(ctx context.Context, account domain.Account, principal access.Principal, ...) (domain.WebhookEvent, error)
- func (s Scenario) EventsIndex(ctx context.Context, account domain.Account, principal access.Principal, ...) ([]domain.WebhookEvent, int, error)
- func (s Scenario) Index(ctx context.Context, account domain.Account, principal access.Principal, ...) ([]domain.WebhookEndpoint, int, error)
- func (s Scenario) Retry(ctx context.Context, account domain.Account, principal access.Principal, ...) (domain.WebhookEvent, error)
- func (s Scenario) Show(ctx context.Context, account domain.Account, principal access.Principal, ...) (domain.WebhookEndpoint, error)
- func (s Scenario) Update(ctx context.Context, account domain.Account, principal access.Principal, ...) (domain.WebhookEndpoint, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
var ErrNoResource = errors.New("webhooks: event without a renderable resource")
ErrNoResource answers a publish of a value the publisher cannot render (every event must carry its resource document).
var ErrNotFound = domain.ErrNotFound // one sentinel across the scenario ports
ErrNotFound is the storage port's not-found sentinel.
Functions ¶
This section is empty.
Types ¶
type EventFilter ¶
type EventFilter = port.WebhookEventFilter
EventFilter is the webhook-events index filter.
type Input ¶
type Input struct {
// URL is the raw url attribute; nil when the update leaves it.
URL *string
// Subscriptions is the deduped subscription list; nil when the
// update leaves it (["*"] is the create default).
Subscriptions []string
SubscriptionsOn bool
// SignatureAlgorithm nil means unset (ed25519 on create).
SignatureAlgorithm *string
// APIVersion carries an explicit apiVersion attribute (already
// validated by the handler); nil when absent.
APIVersion *string
// Product carries the product relationship: nil pointer = present
// with null data (clears); ProductOn false = absent.
Product *uuid.UUID
ProductOn bool
}
Input is the endpoint create/update body after the handler's typed-params validation (types, unpermitted keys, apiVersion inclusion — the reference rejects those as 400s before the model).
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publisher is the real events.Publisher: inside the caller's transaction it writes one webhook_events row per subscribed endpoint and enqueues a reference with the payload the delivery POSTs carry.
func NewPublisher ¶
func NewPublisher( store PublisherStore, queue port.WebhookQueue, accountID uuid.UUID, rng io.Reader, clock func() time.Time, ) *Publisher
NewPublisher builds the publisher over the store (the account's id: the installation's single account).
type PublisherStore ¶
type PublisherStore = port.WebhookPublisherStore
PublisherStore is the publisher's storage port: the subscribed endpoints, the outbox writes and the lookups the payload and the product filter need.
type Scenario ¶
type Scenario struct {
// contains filtered or unexported fields
}
Scenario is the webhook endpoints and events scenario.
func New ¶
func New( store Store, resolver domain.Resolver, allowedPrivate []*net.IPNet, queue port.WebhookQueue, clock func() time.Time, ) Scenario
New builds the scenario (resolver, allowlist, queue and clock injectable for tests).
func (Scenario) Create ¶
func (s Scenario) Create( ctx context.Context, account domain.Account, principal access.Principal, in Input, ) (domain.WebhookEndpoint, error)
Create builds the endpoint (the product inferred from a product bearer when the relationship is absent) and answers the 201 row.
func (Scenario) Destroy ¶
func (s Scenario) Destroy( ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, ) error
Destroy removes the endpoint.
func (Scenario) EventDestroy ¶
func (s Scenario) EventDestroy( ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, ) error
EventDestroy removes the event (no delivery side effects).
func (Scenario) EventShow ¶
func (s Scenario) EventShow( ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, ) (domain.WebhookEvent, error)
EventShow answers the event.
func (Scenario) EventsIndex ¶
func (s Scenario) EventsIndex( ctx context.Context, account domain.Account, principal access.Principal, filter EventFilter, page paging.Params, ) ([]domain.WebhookEvent, int, error)
EventsIndex answers the filtered (product-scoped) page and total.
func (Scenario) Index ¶
func (s Scenario) Index( ctx context.Context, account domain.Account, principal access.Principal, page paging.Params, ) ([]domain.WebhookEndpoint, int, error)
Index answers the (product-scoped) page and its total.
func (Scenario) Retry ¶
func (s Scenario) Retry( ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, ) (domain.WebhookEvent, error)
Retry enqueues a fresh delivery of the event (a NEW row copying the payload, api version and idempotency token; the original stays as is). The reference's generic unprocessable entity answers an event whose endpoint is gone.
type Store ¶
type Store = port.WebhooksStore
Store is the scenario's storage port (satisfied by *postgres.Store; Do runs a transaction the publisher's writes join).