webhooks

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 19 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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).

View Source
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).

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, event string, resource any) error

Publish records the event for delivery to every endpoint subscribed to it. The queries ride the caller's context, so inside a store.Do the rows land in the caller's transaction — the change and its events commit together or not at all.

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.

func (Scenario) Show

func (s Scenario) Show(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID,
) (domain.WebhookEndpoint, error)

Show answers the endpoint.

func (Scenario) Update

func (s Scenario) Update(
	ctx context.Context,
	account domain.Account,
	principal access.Principal,
	id uuid.UUID,
	in Input,
) (domain.WebhookEndpoint, error)

Update applies the partial body and answers the row.

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL