preferences

package
v1.6.18 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package preferences holds the wire shape + validation + row-mapper for the notification_preferences collection.

This package is intentionally separate from internal/router/ because the router is a pure function operating on a resolved Preferences struct, while this package owns the persistence + JSON marshalling boilerplate. Keeping them apart preserves the router's no-dependencies-but-time discipline.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyWire

func ApplyWire(rec *core.Record, w *Wire) error

ApplyWire writes the Wire fields into the *core.Record. user_id / tenant are forced by the caller so this only writes the mutable columns.

func ToRouterPreferences

func ToRouterPreferences(w Wire) *router.Preferences

ToRouterPreferences converts a Wire into the router's Preferences struct. Caller of router.DeliveryChannels uses this to bridge the persistence and routing layers.

func Validate

func Validate(w *Wire) error

Validate enforces the structural rules from §2: required emails, HH:MM format, known channel ids, known marketing category ids. Bad input is rejected at the API boundary — the persistence layer trusts what it stores.

Types

type Wire

type Wire struct {
	ID     string `json:"id,omitempty"`
	UserID string `json:"user_id"`
	OrgID  string `json:"org_id"`

	PrimaryEmail  string `json:"primary_email"`
	BackupEmail   string `json:"backup_email,omitempty"`
	PrimaryPhone  string `json:"primary_phone,omitempty"`
	WhatsAppPhone string `json:"whatsapp_phone,omitempty"`
	LegalEmail    string `json:"legal_email"`

	PreferredChannels      []string        `json:"preferred_channels"`
	RealtimeChannels       []string        `json:"realtime_channels"`
	MarketingSubscriptions map[string]bool `json:"marketing_subscriptions"`

	QuietHoursStart string `json:"quiet_hours_start"`
	QuietHoursEnd   string `json:"quiet_hours_end"`
	Timezone        string `json:"timezone"`

	MarketingGloballyMuted bool `json:"marketing_globally_muted"`

	Created string `json:"created,omitempty"`
	Updated string `json:"updated,omitempty"`
}

Wire is the JSON shape returned by GET /v1/notify/preferences and accepted by PUT /v1/notify/preferences. Field order + names match §2.1 of the notification-preferences paper.

func ToWire

func ToWire(rec *core.Record) Wire

ToWire materialises a Wire from a *core.Record. JSON blobs are parsed defensively — a corrupt blob falls back to an empty slice/map rather than failing the read.

Jump to

Keyboard shortcuts

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