feedbackv1

import feedbackv1 "pocketone.dev/ext/contracts/mail/feedback/v1"

Package feedbackv1 is the mail.feedback/v1 contract: what mail providers report back about mail an app sent (bounces, complaints, unsubscribes), received at one place and turned into [Event]s that any extension can act on. The provider receives the reports (Amazon SES through SNS, or a generic webhook); handlers bind OnEvent: a suppression list adds the address, a CRM marks the contact.

A wire contract at /api/_c/mail.feedback/v1. Its operations are public: SES messages are checked by their SNS signature, webhook calls by a shared secret.

Source: ext/contracts/mail/feedback/v1.

Constants

const (
	Bounce      = "bounce"      // permanent: the address doesn't exist
	Complaint   = "complaint"   // the recipient marked it as spam
	Unsubscribe = "unsubscribe" // the recipient asked to stop
)

Kinds of feedback.

Variables

var Contract = extkit.NewContract[Receiver]("mail.feedback/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)

Contract is mail.feedback/v1.

var ErrBadSecret = &extkit.Error{Code: "unauthorized", Message: "missing or wrong X-Feedback-Secret", Status: 401}

ErrBadSecret: the webhook's secret is missing or wrong.

var W = extkit.NewWire(Contract, "public", func(inner Receiver, g *extkit.Guard[Receiver]) Receiver {
	return &guardReceiver{inner, g}
},
	extkit.Op[Receiver]{
		Name:   "s_e_s",
		Desc:   "Takes an Amazon SNS delivery carrying SES bounce and complaint notifications (and confirms the topic subscription). Point an SNS HTTPS subscription here.",
		Method: "POST",
		Path:   "ses",
		Scope:  "public",
		RawIn:  true,
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Receiver, a extkit.Auth, req extkit.OpRequest) (any, error) {
			in := extkit.RawIn{Query: req.Query, Body: req.Body, ContentType: req.ContentType, Header: req.Header}
			return impl.SES(ctx, a, in)
		},
	},
	extkit.Op[Receiver]{
		Name:   "webhook",
		Desc:   "Takes {\"type\": \"bounce|complaint|unsubscribe\", \"email\": ..., \"campaign\": ...} from any provider, with the shared secret in the X-Feedback-Secret header.",
		Method: "POST",
		Path:   "webhook",
		Scope:  "public",
		RawIn:  true,
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Receiver, a extkit.Auth, req extkit.OpRequest) (any, error) {
			in := extkit.RawIn{Query: req.Query, Body: req.Body, ContentType: req.ContentType, Header: req.Header}
			return impl.Webhook(ctx, a, in)
		},
	},
)

W is mail.feedback/v1's wire side: routes at /api/_c/mail.feedback/v1/<op>, action hooks, MCP tools and the client.

Functions

OnEvent

func OnEvent(app core.App) *hook.Hook[*Event]

OnEvent is the hook every feedback event goes through, for any number of handlers.

OnSES

func OnSES(owner any, fn func(e *extkit.CallEvent, in *extkit.RawIn) error)

OnSES binds fn to s_e_s calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnWebhook

func OnWebhook(owner any, fn func(e *extkit.CallEvent, in *extkit.RawIn) error)

OnWebhook binds fn to webhook calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

Raise

func Raise(app core.App, ev *Event) error

Raise sends ev through OnEvent (providers call it for each report).

Types

Ack

type Ack struct {
	Accepted int `json:"accepted"` // events raised
}

Ack is a receipt.

Client

type Client struct {
	// contains filtered or unexported fields
}

Client is mail.feedback/v1 over HTTP, for the CLI and other apps. It implements Receiver; the token it was made with is the credential, so the extkit.Auth argument is ignored.

NewClient

func NewClient(baseURL, token string, hc *http.Client) *Client

NewClient calls mail.feedback/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.SES

func (c *Client) SES(ctx context.Context, _ extkit.Auth, in extkit.RawIn) (Ack, error)

Client.Webhook

func (c *Client) Webhook(ctx context.Context, _ extkit.Auth, in extkit.RawIn) (Ack, error)

Event

type Event struct {
	hook.Event
	App      core.App
	Kind     string // Bounce, Complaint or Unsubscribe
	Email    string
	Campaign string // the bulk mail campaign it was about, when known (X-Bulkmail-Campaign)
	Source   string // ses, webhook, ...
}

Event is one report about one address.

Receiver

type Receiver interface {
	// SES takes an Amazon SNS delivery carrying SES bounce and complaint notifications (and confirms the topic
	// subscription). Point an SNS HTTPS subscription here.
	//
	//op: POST ses scope=public
	SES(ctx context.Context, a extkit.Auth, in extkit.RawIn) (Ack, error)

	// Webhook takes {"type": "bounce|complaint|unsubscribe", "email": ..., "campaign": ...} from any provider, with
	// the shared secret in the X-Feedback-Secret header.
	//
	//op: POST webhook scope=public
	Webhook(ctx context.Context, a extkit.Auth, in extkit.RawIn) (Ack, error)
}

Receiver takes mail providers' reports.