Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CloudflareSender ¶
type CloudflareSender struct {
// contains filtered or unexported fields
}
CloudflareSender sends login emails via the Cloudflare Email Sending REST API.
func NewCloudflareSender ¶
func NewCloudflareSender(cfg EmailConfig) (*CloudflareSender, error)
NewCloudflareSender constructs a CloudflareSender from cfg. Returns an error if accountID, apiToken, or fromAddress are missing.
func (*CloudflareSender) SendLoginLink ¶
func (s *CloudflareSender) SendLoginLink(ctx context.Context, msg LoginEmail) error
SendLoginLink sends a magic-link login email via the Cloudflare Email Sending API.
Security constraints:
- The API token is never included in any returned error.
- msg.HTML, msg.Text, and msg.Subject (which may contain the magic link token) are never logged.
type EmailConfig ¶
type EmailConfig struct {
Provider string // "cloudflare", "memory", "log"
AccountID string // Cloudflare account ID
APIToken string // Cloudflare Email Workers API token
From string // e.g. login@example.com
FromName string // e.g. td-watch
ReplyTo string // e.g. support@example.com
// CloudflareBaseURL overrides the Cloudflare REST API base. Tests-only.
// Empty => https://api.cloudflare.com/client/v4. WARNING: do NOT set this to
// td-sync's own base URL (SYNC_EMAIL_BASE_URL) — that points email sends at
// the wrong host (causes 404 "unexpected status").
CloudflareBaseURL string
CallbackURL string // e.g. https://watch.example.com/home/login/complete
}
EmailConfig holds the fields that email senders need. The mapping from api.Config to EmailConfig is done in the api/cmd layer to avoid import cycles.
type EmailSender ¶
type EmailSender interface {
SendLoginLink(ctx context.Context, msg LoginEmail) error
}
EmailSender is the provider-neutral interface for sending login emails.
func NewEmailSender ¶
func NewEmailSender(cfg EmailConfig) (EmailSender, error)
NewEmailSender constructs the appropriate EmailSender for cfg.Provider. Recognised values: "cloudflare", "memory", "log", "" (empty string treated as "log").
type LogSender ¶
type LogSender struct{}
LogSender logs a structured record for each login email. It intentionally omits Subject, Text, and HTML because those fields carry the magic link token.
func (*LogSender) SendLoginLink ¶
func (s *LogSender) SendLoginLink(ctx context.Context, msg LoginEmail) error
SendLoginLink logs To, Purpose, and TraceID via slog. Token material (Subject, Text, HTML) is never logged.
type LoginEmail ¶
type LoginEmail struct {
To string
Subject string
Text string
HTML string
Purpose string // e.g. "web_login", "device_login"
TraceID string
}
LoginEmail holds the data for a magic-link login email.
type MemorySender ¶
type MemorySender struct {
// contains filtered or unexported fields
}
MemorySender stores sent emails in memory. Intended for tests and local dev.
func NewMemorySender ¶
func NewMemorySender() *MemorySender
NewMemorySender returns an empty MemorySender.
func (*MemorySender) Last ¶
func (s *MemorySender) Last() (LoginEmail, bool)
Last returns the most recently sent email and true, or a zero LoginEmail and false when nothing has been sent yet. It returns a copy, so the caller cannot mutate the buffered message.
func (*MemorySender) SendLoginLink ¶
func (s *MemorySender) SendLoginLink(_ context.Context, msg LoginEmail) error
SendLoginLink appends msg to the in-memory store.
func (*MemorySender) Sent ¶
func (s *MemorySender) Sent() []LoginEmail
Sent returns a copy of all emails that have been sent so far.