Documentation
¶
Overview ¶
Package brandkit is the workspace's brand kit (review 2026-10, CO-11): the logo in light and dark versions, the colours with their contrast where they are used, the heading and body fonts with email-safe fallbacks, and the button style that new emails, templates and blocks start from. It can be filled in from the workspace's website (import.go). Emails already written keep their own styles.
Synced blocks (synced.go) are the Header and Footer every email can hold, and any section saved as a named synced block (R4.A3): edit once, and the drafts and scheduled emails holding the block get the change; sent emails keep what they went out with.
Index ¶
- Constants
- Variables
- func Apply(src string, k BrandKit) string
- func Contrast(a, b string) float64
- func Named(kind string) bool
- func Register(h huma.API, s *Service)
- type BrandButtonStyle
- type BrandColors
- type BrandFont
- type BrandImportColor
- type BrandKit
- type BrandKitImport
- type BrandKitImportInput
- type BrandKitInput
- type BrandLogo
- type BrandStyle
- type Campaigns
- type KitSaved
- type Service
- func (s *Service) CreateSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (SyncedBlock, error)
- func (s *Service) DeleteSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, kind string) (SyncedDeleted, error)
- func (s *Service) Get(ctx context.Context, ws *store.Workspace) (BrandKit, error)
- func (s *Service) Import(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (BrandKitImport, error)
- func (s *Service) Kit(ctx context.Context, ws *store.Workspace) (BrandKit, error)
- func (s *Service) Save(ctx context.Context, ws *store.Workspace, p *authz.Principal, in BrandKitInput) (BrandKit, error)
- func (s *Service) SaveIn(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, ...) (KitSaved, error)
- func (s *Service) SaveSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, kind string, ...) (SyncedSaved, error)
- func (s *Service) SaveSyncedIn(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, ...) (*SyncedBlock, []audit.Event, error)
- func (s *Service) Starter(ctx context.Context, ws *store.Workspace, src string) string
- type SyncedBlock
- type SyncedCreateInput
- type SyncedDeleted
- type SyncedInput
- type SyncedSaved
Constants ¶
const ( KindHeader = "header" )
Synced block kinds.
Variables ¶
var Fallbacks = []string{
"Georgia, 'Times New Roman', serif",
"'Times New Roman', serif",
"Arial, Helvetica, sans-serif",
"Helvetica, Arial, sans-serif",
"Verdana, Geneva, sans-serif",
"'Trebuchet MS', Arial, sans-serif",
"Tahoma, Geneva, sans-serif",
}
Fallbacks are the email-safe font stacks a font can fall back to: Gmail and Outlook for Windows show these, whatever the web font.
var Kinds = []string{KindFooter, KindHeader}
Kinds are the synced blocks every kit has, in the order the kit lists them; named blocks (R4.A3) follow, oldest first.
Functions ¶
func Apply ¶
Apply puts the kit on content written with ReputeCast's default style (a starter template or a new block): its colours, fonts, button style and logo replace the defaults. Content written by people is left as it is; only what still has a default changes.
Types ¶
type BrandButtonStyle ¶
type BrandButtonStyle struct {
Shape string `json:"shape" enum:"square,rounded,pill"`
Size int `json:"size" enum:"14,15" doc:"Text size in px (bold, body font)"`
}
BrandButtonStyle is how buttons look.
func (BrandButtonStyle) Radius ¶
func (b BrandButtonStyle) Radius() string
Radius is the shape's border-radius.
type BrandColors ¶
type BrandColors struct {
Button string `json:"button" pattern:"^#[0-9A-Fa-f]{6}$" doc:"Button fill, with white text"`
Text string `json:"text" pattern:"^#[0-9A-Fa-f]{6}$" doc:"Paragraphs and headings"`
Background string `json:"background" pattern:"^#[0-9A-Fa-f]{6}$" doc:"Behind the 600 px email column"`
Link string `json:"link" pattern:"^#[0-9A-Fa-f]{6}$" doc:"Links inside text, underlined"`
}
BrandColors are the kit's colours, #RRGGBB.
type BrandFont ¶
type BrandFont struct {
Name string `json:"name" maxLength:"60" pattern:"^[A-Za-z0-9 ]*$" doc:"The web font's family (Inter); empty uses the fallback alone"`
URL string `json:"url,omitempty" maxLength:"500" doc:"The web font's stylesheet (https)"`
Fallback string `` /* 290-byte string literal not displayed */
}
BrandFont is a heading or body font: a web font (Apple Mail and iOS Mail load it) and the email-safe fallback everyone else sees.
type BrandImportColor ¶
type BrandImportColor struct {
Hex string `json:"hex"`
// Used is false when the kit doesn't use it (Notes say why).
Used bool `json:"used"`
}
BrandImportColor is a colour found on the site.
type BrandKit ¶
type BrandKit struct {
// Saved is false until the kit is first saved: the values are then
// ReputeCast's defaults.
Saved bool `json:"saved"`
LogoLight *BrandLogo `json:"logoLight,omitempty" doc:"For light backgrounds"`
LogoDark *BrandLogo `json:"logoDark,omitempty" doc:"For dark mode (Apple Mail and Outlook for Mac switch to it)"`
LogoAlt string `json:"logoAlt"`
BrandStyle
Website string `json:"website"`
UpdatedBy string `json:"updatedBy,omitempty"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
// Synced are the synced Header and Footer, with the emails holding them.
Synced []SyncedBlock `json:"synced"`
}
BrandKit is the workspace's kit.
type BrandKitImport ¶
type BrandKitImport struct {
Website string `json:"website"`
FoundAt time.Time `json:"foundAt"`
LogoLight *BrandLogo `json:"logoLight,omitempty"`
LogoDark *BrandLogo `json:"logoDark,omitempty"`
LogoAlt string `json:"logoAlt"`
Style BrandStyle `json:"style"`
Colors []BrandImportColor `json:"colors"`
Fonts []string `json:"fonts"`
// Notes say what the import decided and why ("#6366F1 isn't used for
// links…"), in the reader's language.
Notes []string `json:"notes"`
}
BrandKitImport is what a website shows, as a kit to check: nothing is saved. Logos found are added to the media library so the kit can use them.
type BrandKitImportInput ¶
type BrandKitImportInput struct {
Website string `json:"website" minLength:"3" maxLength:"200" doc:"acme.io or https://acme.io"`
}
BrandKitImportInput asks for a website's logo, colours and fonts.
type BrandKitInput ¶
type BrandKitInput struct {
LogoLightID string `json:"logoLightId,omitempty" doc:"A media library image id; empty: no logo"`
LogoDarkID string `json:"logoDarkId,omitempty"`
LogoAlt string `json:"logoAlt" maxLength:"120"`
BrandStyle
Website string `json:"website,omitempty" maxLength:"200"`
}
BrandKitInput saves the kit.
type BrandLogo ¶
type BrandLogo struct {
MediaID string `json:"mediaId"`
URL string `json:"url"`
FileName string `json:"fileName"`
Width int `json:"width"`
Height int `json:"height"`
}
BrandLogo is a logo image from the media library.
type BrandStyle ¶
type BrandStyle struct {
Colors BrandColors `json:"colors"`
Heading BrandFont `json:"heading"`
Body BrandFont `json:"body"`
Button BrandButtonStyle `json:"button"`
}
BrandStyle is everything but the logo.
func DefaultStyle ¶
func DefaultStyle() BrandStyle
DefaultStyle is ReputeCast's own: the starters' and blocks' colours and fonts before a kit is saved.
type Campaigns ¶
type Campaigns interface {
CountSynced(ctx context.Context, ws *store.Workspace, kind string) (campaigns.SyncedUses, error)
ApplySynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, kind, block, label string) (campaigns.SyncedUses, []uuid.UUID, error)
UnlinkSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, kind, label string) (campaigns.SyncedUses, []uuid.UUID, error)
}
Campaigns is what synced blocks need from the campaign domain (internal/campaigns).
type KitSaved ¶
type KitSaved struct {
Before, After BrandKit
// Header is the synced Header when the kit's logo changed it, for the
// emails holding it once the kit's transaction commits.
Header *SyncedBlock
// Audit are the entries the save makes, for the caller to write.
Audit []audit.Event
}
KitSaved is what saving the kit did.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Campaigns Campaigns
// Media stores the logos an import finds.
Media *media.Service
// Guard checks the addresses an import fetches.
Guard netguard.Policy
Now func() time.Time
// contains filtered or unexported fields
}
Service is the brand kit domain.
func (*Service) CreateSynced ¶
func (s *Service) CreateSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, in SyncedCreateInput) (SyncedBlock, error)
CreateSynced saves a section as a named synced block (R4.A3, "Save as synced block" in the composer). The block it returns is the section marked with its new key: the composer puts it in place of the section, so the email it came from holds the block too. Other emails get it from the blocks panel.
func (*Service) DeleteSynced ¶
func (s *Service) DeleteSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, kind string) (SyncedDeleted, error)
DeleteSynced deletes a named synced block (R4.A3). The drafts and scheduled emails holding it keep its content as ordinary sections, in a new version; emails in an approval, sending, paused or sent keep theirs (the composer offers to unlink a block that's gone). The Header and Footer stay: every kit has them.
func (*Service) Import ¶
func (s *Service) Import(ctx context.Context, ws *store.Workspace, p *authz.Principal, in BrandKitImportInput) (BrandKitImport, error)
Import reads a website's logo, colours and fonts into a kit to check.
func (*Service) Save ¶
func (s *Service) Save(ctx context.Context, ws *store.Workspace, p *authz.Principal, in BrandKitInput) (BrandKit, error)
Save stores the kit. A new light logo or alt text reaches the synced Header, and through it the drafts and scheduled emails holding it when the caller can edit campaigns.
func (*Service) SaveIn ¶
func (s *Service) SaveIn(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, in BrandKitInput) (KitSaved, error)
SaveIn is Save's work in the caller's transaction (q): it checks and stores the kit, creates the synced Header and Footer on the first save, and puts a new light logo or alt text in the Header. It leaves the audit entries and the emails holding the Header to the caller (Save; internal/demo seeds the Acme kit through it).
func (*Service) SaveSynced ¶
func (s *Service) SaveSynced(ctx context.Context, ws *store.Workspace, p *authz.Principal, kind string, in SyncedInput) (SyncedSaved, error)
SaveSynced changes a synced block: drafts and scheduled emails holding it get the change as a new version; emails in an approval, sending, paused or sent keep theirs.
func (*Service) SaveSyncedIn ¶
func (s *Service) SaveSyncedIn(ctx context.Context, q *store.Queries, ws *store.Workspace, p *authz.Principal, kind string, in SyncedInput) (*SyncedBlock, []audit.Event, error)
SaveSyncedIn is SaveSynced's work in the caller's transaction (q): it checks the block (one section or wrapper that compiles; the footer with its unsubscribe link) and stores its next version. It leaves the audit entries and the emails holding the block to the caller (SaveSynced; internal/demo seeds the Acme blocks through it).
type SyncedBlock ¶
type SyncedBlock struct {
Kind string `json:"kind" pattern:"^(header|footer|b-[0-9a-f]{12})$" doc:"header, footer, or a named block's key (R4.A3)"`
// Name is a named block's name; the Header and Footer have none.
Name string `json:"name"`
MJML string `json:"mjml" doc:"One section or wrapper, marked rc-synced"`
Version int `json:"version"`
UpdatedBy string `json:"updatedBy"`
UpdatedAt time.Time `json:"updatedAt"`
// Uses counts the emails holding it: what a change does to them.
Uses campaigns.SyncedUses `json:"uses"`
}
SyncedBlock is a synced block and the emails holding it.
type SyncedCreateInput ¶
type SyncedCreateInput struct {
Name string `json:"name" minLength:"1" maxLength:"80" doc:"What the block is called in the blocks panel and the brand kit"`
MJML string `json:"mjml" minLength:"1" maxLength:"200000" doc:"One mj-section or mj-wrapper, from the email it is saved from"`
}
SyncedCreateInput saves a section as a named synced block (R4.A3).
type SyncedDeleted ¶
type SyncedDeleted struct {
Applied campaigns.SyncedUses `json:"applied"`
}
SyncedDeleted is what deleting a named synced block did to the emails holding it: drafts and scheduled ones keep its content, unlinked; held and sent ones keep theirs as it was.
type SyncedInput ¶
type SyncedInput struct {
MJML string `json:"mjml" minLength:"1" maxLength:"200000" doc:"One mj-section or mj-wrapper"`
// Name renames a named block; the Header and Footer keep theirs.
Name *string `json:"name,omitempty" maxLength:"80" doc:"A named block's new name"`
}
SyncedInput changes a synced block.
type SyncedSaved ¶
type SyncedSaved struct {
Block SyncedBlock `json:"block"`
// Applied counts the drafts and scheduled emails that got the change,
// and the held and sent ones that kept theirs.
Applied campaigns.SyncedUses `json:"applied"`
}
SyncedSaved is a synced block's change and what it did to the emails.