template

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package template renders Notify templates and manages the lifecycle.

Lifecycle: draft → pending_approval → approved → published → archived. Only `published` templates can be invoked from a SendRequest. The approval transition (pending_approval → approved) requires a privileged caller (X-Roles claim contains "notify-approver").

Rendering uses Go's text/template with a small custom function map. The library is text/template (not html/template) because notify payloads include SMS and voice scripts that have no HTML semantics; callers sending email templates with HTML are responsible for escaping their inputs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadPublished

func LoadPublished(app core.App, tenant, idOrName, channel string) (*core.Record, error)

LoadPublished fetches the latest published version of (tenant, name).

The lookup key is (tenant, name) when channel is empty, and (tenant, name, channel) when channel is non-empty. There is no silent fall-through between the two: an SMS request for which no SMS-channel template exists is an error, not "give me the email version anyway". This keeps the wire contract honest — channel in == channel out.

Returns a "not found" error when no row matches; the routes layer maps that to HTTP 400.

func Transition

func Transition(app *base.Base, rec *core.Record, next string) error

Transition moves a template from one lifecycle state to another. Returns an error if the transition is not allowed. Callers must check authorization separately — this function does not consult X-Roles.

Types

type Resolved

type Resolved struct {
	Subject string
	Body    string
	Channel string
}

Resolved is the result of rendering a published Template against a caller-supplied variable map.

func Render

func Render(rec *core.Record, vars map[string]any) (*Resolved, error)

Render renders the template's subject + body against vars.

Jump to

Keyboard shortcuts

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