countdown

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 46 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package countdown is the Countdown block of emails (M59 G-21): a timer to a moment in a time zone, drawn as an animated GIF each time the email is opened, so every reader sees the time left when they look.

POST /workspaces/{workspace}/countdowns   the block's settings → its image
GET  /t/cd/{token}.gif                    the image (HEAD too)

Each distinct set of settings is one email_countdowns row per workspace, found again by the SHA-256 of its canonical JSON, so the composer gets the same address back for the same settings. The image's token is signed (internal/linktoken, Kind) and names the workspace and the row. Images are drawn from a per-settings atlas of pre-drawn digits and labels, kept briefly per second, and drawn at most four at a time.

Index

Constants

View Source
const (
	IssueEnded = "content.countdown_ended"
	IssueSoon  = "content.countdown_soon"
)

IssueEnded is the check of a countdown that has ended (the composer's warning, Send Readiness's block); IssueSoon Send Readiness's warning of one that ends within an hour of the send's start.

View Source
const Frames = 60

Frames is how many seconds one image plays: it stops on its last frame.

View Source
const Kind linktoken.Kind = 230

Kind is the image token's kind; its MessageID names the countdown.

View Source
const MaxEndText = 60

MaxEndText is the longest message shown once the countdown ends.

View Source
const MinContrast = 4.5

MinContrast is the digits' least contrast on the background (WCAG AA for text).

Variables

This section is empty.

Functions

func Alt

func Alt(set CountdownSettings, endsAt time.Time) string

Alt is the image's alt text in the block's language: "Offer ends Fri 28 Nov at 23:59 (EST)", in the countdown's time zone.

func Hash

func Hash(s CountdownSettings) ([]byte, []byte)

Hash is the key of normalized settings: the SHA-256 of their canonical JSON (fields in a fixed order).

func Register

func Register(h huma.API, s *Service)

Register adds the countdown operation.

Types

type CountdownEnded

type CountdownEnded struct {
	Mode string `json:"mode" enum:"zeros,text"`
	Text string `json:"text,omitempty" doc:"The message shown when mode is text, up to 60 characters"`
}

CountdownEnded is what the timer shows once it ends.

type CountdownImage

type CountdownImage struct {
	ID     string    `json:"id" format:"uuid"`
	URL    string    `json:"url" doc:"The animated GIF, drawn when the email is opened"`
	EndsAt time.Time `json:"endsAt"`
	Alt    string    `json:"alt" example:"Offer ends Fri 28 Nov at 23:59 (EST)"`
	Width  int       `json:"width"`
	Height int       `json:"height"`
}

CountdownImage is a countdown's image for the block.

type CountdownSettings

type CountdownSettings struct {
	// EndsAt is the local date and time it ends ("2026-11-28T23:59") in
	// TimeZone (IANA, "America/New_York").
	EndsAt   string `json:"endsAt" maxLength:"16" doc:"The local date and time the countdown ends, YYYY-MM-DDTHH:MM" example:"2026-11-28T23:59"`
	TimeZone string `json:"timeZone" maxLength:"64" doc:"IANA time zone of endsAt" example:"America/New_York"`
	// Units: days, hours, minutes and seconds; hours, minutes and seconds;
	// days, hours and minutes.
	Units    string `json:"units" enum:"dhms,hms,dhm"`
	Language string `json:"language" enum:"en,de,es,fr,vi" doc:"The labels' and the alt text's language: the language version being edited"`
	// Size: s 360×96, m 480×120, l 600×150 pixels.
	Size       string         `json:"size" enum:"s,m,l"`
	Background string         `json:"background" maxLength:"7" doc:"#RRGGBB" example:"#0F172A"`
	Digits     string         `json:"digits" maxLength:"7" doc:"#RRGGBB, at least 4.5:1 on the background" example:"#FFFFFF"`
	Labels     string         `json:"labels" maxLength:"7" doc:"#RRGGBB" example:"#CBD5E1"`
	Ended      CountdownEnded `json:"ended"`
}

CountdownSettings are a Countdown block's settings, as the composer keeps them on the block (rc-countdown) and sends them here.

func Normalize

Normalize checks settings and returns them as they're kept (colours in capitals, no message unless the end shows one) with the moment they end. Problems are 422s in the request's language.

type Found

type Found struct {
	// ID is the countdown's; uuid.Nil for a block whose image wasn't made
	// yet (only its settings are known).
	ID       uuid.UUID
	Settings CountdownSettings
	EndsAt   time.Time
	// Path is the block's place from mj-body, and Section its top-level
	// section (-1 when the countdown was found in HTML only).
	Path    []int
	Section int
}

Found is a countdown an email shows.

type ReadinessRow

type ReadinessRow struct {
	Key, Status               string // block or warn
	Title, Detail, Label, Ack i18n.Text
	// Link opens the campaign in the composer (a workspace path).
	LinkLabel i18n.Text
	Href      string
}

ReadinessRow is a Send Readiness row about a campaign's countdowns; its texts are kept messages, written in each reader's language.

type Service

type Service struct {
	Pool  *pgxpool.Pool
	Q     *store.Queries
	Audit *audit.Logger
	Links *linktoken.Signer
	URLs  publicurl.Builder
	// Hosts says whose host a request came to (nil: every host carries
	// every workspace's images).
	Hosts *customhost.Hosts
	Log   *slog.Logger
	Now   func() time.Time
	// contains filtered or unexported fields
}

Service creates and serves countdowns.

func (*Service) ComposerIssues

func (s *Service) ComposerIssues(ctx context.Context, ws *store.Workspace, _ uuid.UUID, src string) []contentcheck.ContentCheckIssue

ComposerIssues warns about countdowns of a campaign's MJML that have already ended (campaigns.MoreChecks).

func (*Service) Create

func (s *Service) Create(ctx context.Context, ws *store.Workspace, actor *uuid.UUID, in CountdownSettings) (CountdownImage, error)

Create returns the image of a block's settings: the workspace's countdown with the same settings, or a new one (audited).

func (*Service) Find

func (s *Service) Find(ctx context.Context, ws *store.Workspace, contents ...string) []Found

Find lists the countdowns that content (MJML or HTML) shows: by their image's token, and by the settings of blocks whose image isn't made yet, soonest first. Tokens of another workspace count for nothing.

func (*Service) FlowWarnings

func (s *Service) FlowWarnings(ctx context.Context, ws *store.Workspace, contents ...string) []string

FlowWarnings are a flow's publish badges, in the request's language: one for each countdown of its emails that ends within 30 days, after which the flow keeps sending it.

func (*Service) ReadinessRows

func (s *Service) ReadinessRows(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID, html string, start time.Time, at func(time.Time) any) []ReadinessRow

ReadinessRows checks the countdowns of a campaign's HTML against when its send starts: one that has ended by then blocks the send; one that ends within an hour of it warns. at writes a moment as Send Readiness keeps it, in the workspace's time zone.

func (*Service) Routes

func (s *Service) Routes(r chi.Router)

Routes mounts the image, next to the tracking endpoints:

GET|HEAD /t/cd/{token}.gif

func (*Service) Token

func (s *Service) Token(workspace, id uuid.UUID) string

Token is the image token of a workspace's countdown.

Jump to

Keyboard shortcuts

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