Help us shape the future of Go! Take the 2026 Go Developer Survey

transactional

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package transactional is the Transactional send operation (ADR 0005): a single-recipient email rendered from a referenced Template with per-call variables. It owns everything up to the Outbound send module: normalizing the destination, looking the Template up in the Workspace, decoding the variables, resolving the Contact the address belongs to and building the Outbound request. Idempotency, the freeze check, the Sending-domain gate, eligibility, rendering, the provider call and the send record stay the Outbound module's (ADR 0015).

The module holds no database client: it takes the Workspace scope of the caller. Its Result is closed. A Deferral from Outbound is not one of its variants: a Transactional request is never rate limited or deferred (ADR 0023), so one that comes back is an ErrInvariant.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyDestination: the address is empty once normalized.
	ErrEmptyDestination = errors.New("transactional: destination must not be empty")
	// ErrTemplateNotFound: no such Template in the Workspace.
	ErrTemplateNotFound = errors.New("transactional: template not found")
	// ErrInvariant: Outbound answered with something a Transactional request can never get.
	// It is a bug, reported loudly, not a refusal the caller can act on.
	ErrInvariant = errors.New("transactional: invariant violated")
)

Domain errors of a request that cannot be sent as asked.

Functions

This section is empty.

Types

type InvalidVariablesError

type InvalidVariablesError struct {
	Name string
	Err  error
}

InvalidVariablesError reports that a per-call variable is not valid JSON.

func (*InvalidVariablesError) Error

func (e *InvalidVariablesError) Error() string

func (*InvalidVariablesError) Unwrap

func (e *InvalidVariablesError) Unwrap() error

type Module

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

Module is the Transactional send operation.

func New

func New(t *templates.Module, sender Sender) *Module

New builds the module over the Templates module and the Outbound send module.

func (*Module) Send

func (m *Module) Send(ctx context.Context, s *ent.Scoped, req Request) (Result, error)

Send runs the Transactional send in the Workspace of s.

type Request

type Request struct {
	TemplateID     int64
	Destination    string
	Variables      map[string]json.RawMessage
	IdempotencyKey string
	Track          bool
}

Request is one Transactional send. Variables are raw JSON values, decoded here to their natural Go types so merge tags like {{ amount }} render correctly.

type Result

type Result struct {
	Status Status
	// MessageID is the Outbound message of a Sent or Suppressed request.
	MessageID int64
	// Destination is the normalized address.
	Destination string
	// Reason explains FailedRender (the render error) and Held (a hold reason; see
	// outbound.Detail).
	Reason string
}

Result is the answer to a Request.

type Sender

type Sender interface {
	Send(ctx context.Context, s *ent.Scoped, req outbound.Request) (outbound.Result, error)
}

Sender is the Outbound send module.

type Status

type Status string

Status is how a Transactional request ended. It is closed: each value is a final answer or a reversible refusal, and a Deferral is not among them.

const (
	// Sent: the provider accepted the message.
	Sent Status = "sent"
	// Suppressed: Suppression, the global hard floor, forbids the destination.
	Suppressed Status = "suppressed"
	// FailedRender: the Template cannot be rendered with these variables; Reason says why.
	FailedRender Status = "failed_render"
	// ReplayedFailed: the Idempotency-Key was spent by a send that failed; retry under a new key.
	ReplayedFailed Status = "replayed_failed"
	// InProgress: a send with this Idempotency-Key is still in flight.
	InProgress Status = "in_progress"
	// Held: a reversible hold on the Workspace or its Sending domain; Reason is the hold.
	Held Status = "held"
)

Jump to

Keyboard shortcuts

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