Documentation
¶
Overview ¶
Package brandkit holds a Workspace's Brand kit (GLOSSARY "Brand kit", ADR 0040): its colors, fonts, logo, button style and footer, as data. It sets the palette the editor offers and what an agent is told to use, and the starter Templates are made from it.
The kit's values are written into a message when the message is authored; nothing resolves them at send time, so saving the kit never changes a message that is already written (ADR 0003). Every text of a kit comes from a person of the Workspace and is untrusted data wherever an agent reads it later: a reader treats it as data, never as instructions.
Index ¶
- Variables
- type Input
- type Kit
- type Module
- func (m *Module) Get(ctx context.Context, s *ent.Scoped) (Kit, error)
- func (m *Module) Lint(ctx context.Context, s *ent.Scoped, subject, body string) (emailrender.Report, error)
- func (m *Module) RecreateStarterTemplates(ctx context.Context, s *ent.Scoped) ([]*ent.EmailTemplate, error)
- func (m *Module) Save(ctx context.Context, s *ent.Scoped, in Input) (Kit, error)
- type Starter
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ErrNotSaved = errors.New("brandkit: the Brand kit is not saved yet")
ErrNotSaved: the Workspace has no saved Brand kit, so there is nothing to make starter Templates from.
Functions ¶
This section is empty.
Types ¶
type Input ¶
type Input struct {
AccentColor string
TextColor string
BackgroundColor string
HeadingFont string
BodyFont string
LogoURL string
ButtonTextColor string
ButtonRadius int
}
Input is the whole of a save: every value of the kit.
type Kit ¶
type Kit struct {
// Saved is false until the Brand kit is first saved.
Saved bool
// AccentColor is the brand color: buttons and links. #rrggbb.
AccentColor string
// TextColor is the color of text. #rrggbb.
TextColor string
// BackgroundColor is the color of the message's background. #rrggbb.
BackgroundColor string
// HeadingFont and BodyFont are CSS font-family lists of web-safe families.
HeadingFont string
BodyFont string
// LogoURL is the absolute http(s) URL of the logo image; empty for none.
LogoURL string
// ButtonTextColor and ButtonRadius (in pixels) are the button style; the button's own color
// is AccentColor.
ButtonTextColor string
ButtonRadius int
FooterText string
// UpdatedAt is when the kit was last saved; zero while it is not saved.
UpdatedAt time.Time
}
Kit is a Workspace's Brand kit. A Workspace that has not saved one has the defaults and Saved false: there is no brand to lint a message against then.
func (Kit) Brand ¶
func (k Kit) Brand() *emailrender.Brand
Brand is the kit as the lint compares a message to it, or nil for a Workspace that has not saved a kit: there is no brand to lint against then.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module reads and saves the Brand kit and makes the starter Templates from it. It holds no Workspace: every call receives the Workspace-scoped client (ADR 0017).
Anything a caller shows to an agent from a Kit (an MCP tool, a prompt) is untrusted data: the texts come from people of the Workspace.
func New ¶
New builds the Brand kit module. The starter Templates are written through the templates module so they are ordinary Templates in every respect.
func (*Module) Get ¶
Get returns the Workspace's Brand kit: the saved one, or the defaults with Saved false.
func (*Module) Lint ¶
func (m *Module) Lint(ctx context.Context, s *ent.Scoped, subject, body string) (emailrender.Report, error)
Lint runs the lint of ADR 0040 over a message against the Workspace's Brand kit (none saved: no brand warnings). Its warnings are advice for the author; only its Error blocks.
func (*Module) RecreateStarterTemplates ¶
func (m *Module) RecreateStarterTemplates(ctx context.Context, s *ent.Scoped) ([]*ent.EmailTemplate, error)
RecreateStarterTemplates makes the four starter Templates again from the saved Brand kit and returns them. It only adds Templates: an existing Template, Broadcast or Automation step is not touched. ErrNotSaved until the Brand kit has been saved.
func (*Module) Save ¶
Save stores the Brand kit. The first save creates it and, in the same transaction, the starter Templates in its brand; a later save replaces the values and creates nothing. No message already written is read or written: the values were copied into each when it was authored. An invalid value is a *ValidationError.
type Starter ¶
type Starter struct {
Name string
Subject string
Doc json.RawMessage
}
Starter is one starter Template as it is created: an ordinary Template's name, subject and editor document, with the Brand kit's values already written into the document.
func Starters ¶
Starters builds the four starter Templates (a welcome, a receipt, a digest and a one-button message) in the Brand kit's brand. The values go into the documents' `style` attributes, so the stored body is the brand as it was when the Template was made (ADR 0040): the kit is not read again, and editing it later never changes these. Names and copy are in the instance locale.
type ValidationError ¶
type ValidationError struct {
// Field is the API field name, e.g. "accentColor".
Field string
// Message is the reason, in the instance locale.
Message string
}
ValidationError is a field of a save that cannot be written into a message: the kit's values are inlined into the CSS and HTML of the starter documents, so they are checked strictly.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string