Documentation
¶
Overview ¶
Package approvals implements send approvals (add-on 3.8, 5.12) and the Review & send flow around them (spec 7.5): the workspace policy and its rules, approval requests with a snapshot of what they cover (content and subject, audience definition, route, schedule), invalidation with the exact diff when any of it changes or the audience moves more than 10%, comments, decisions, the send-time recheck, the Owners' emergency bypass, and scheduling or starting the send through the sending engine.
Index ¶
- Constants
- Variables
- func EnableClientSignoff(raw json.RawMessage, on bool) (json.RawMessage, error)
- func Initials(name string) string
- func InvalidationReason(changes []ApprovalChange) string
- func Links(mjmlSrc, html string) []string
- func Register(h huma.API, s *Service)
- func RegisterTransactional(h huma.API, s *Service)
- func RouteKey(shares []readiness.ReadinessRouteShare) string
- func ScheduleText(raw json.RawMessage, loc *time.Location) string
- func Sections(mjmlSrc string) []string
- type ApprovalAudienceRule
- type ApprovalAudienceView
- type ApprovalAuditLine
- type ApprovalAutomationSnapshot
- type ApprovalBypassInput
- type ApprovalCampaignView
- type ApprovalCan
- type ApprovalChange
- type ApprovalClientSignoff
- type ApprovalClientSignoffInfo
- type ApprovalClientSignoffState
- type ApprovalCommentInput
- type ApprovalCommentView
- type ApprovalCostRule
- type ApprovalCounts
- type ApprovalDecisionInput
- type ApprovalDecisionView
- type ApprovalDetail
- type ApprovalFilterOption
- type ApprovalList
- type ApprovalListItem
- type ApprovalPageSnapshot
- type ApprovalPath
- type ApprovalPendingItem
- type ApprovalPerson
- type ApprovalPolicy
- type ApprovalPolicyMatches
- type ApprovalPolicySummary
- type ApprovalPolicyView
- type ApprovalPreview
- type ApprovalPreviewLanguage
- type ApprovalPushButton
- type ApprovalPushSnapshot
- type ApprovalReadinessView
- type ApprovalRequestInput
- type ApprovalRequestView
- type ApprovalRequested
- type ApprovalRouteView
- type ApprovalRuleMatch
- type ApprovalSMSCountry
- type ApprovalSMSSnapshot
- type ApprovalScheduleView
- type ApprovalShare
- type ApprovalSnapshotSummary
- type ApprovalTransactionalSnapshot
- type ApprovalTransactionalTestRender
- type ApprovalWebsiteSnapshot
- type ApprovalWhatsAppSnapshot
- type ApprovalWhatsAppValue
- type AutomationGate
- type CampaignReview
- type ChannelCampaign
- type ChannelCampaigns
- type ChannelMove
- type Current
- type HoldDetail
- type IssueRequest
- type ListParams
- type PagesGate
- func (g PagesGate) PageChanged(ctx context.Context, ws *store.Workspace, p *authz.Principal, pageID uuid.UUID, ...) error
- func (g PagesGate) PageDecision(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (pages.ApprovalDecision, error)
- func (g PagesGate) PagePublished(ctx context.Context, ws *store.Workspace, pageID uuid.UUID, hash string) error
- func (g PagesGate) RequestPage(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (uuid.UUID, error)
- type PagesPublisher
- type ReviewAB
- type ReviewAccess
- type ReviewApproval
- type ReviewCampaign
- type ReviewCanary
- type ReviewCount
- type ReviewHeld
- type ReviewHoldReason
- type ReviewScheduled
- type ReviewSendInput
- type ReviewSendResult
- type ReviewTestSend
- type ReviewTyped
- type ReviewUTM
- type RuleFacts
- type RuleShare
- type SendRecheck
- type Service
- func (s *Service) Bypass(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (ReviewSendResult, error)
- func (s *Service) CampaignChanged(ctx context.Context, ws *store.Workspace, id uuid.UUID)
- func (s *Service) Cancel(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- func (s *Service) ChannelGate(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (*store.ApprovalRequest, error)
- func (s *Service) ChannelReview(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (ReviewApproval, error)
- func (s *Service) CheckSendTime(ctx context.Context, wsID, campaignID uuid.UUID) error
- func (s *Service) Comment(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- func (s *Service) Decide(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (uuid.UUID, error)
- func (s *Service) Detail(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (ApprovalDetail, error)
- func (s *Service) List(ctx context.Context, ws *store.Workspace, p *authz.Principal, f ListParams) (ApprovalList, error)
- func (s *Service) PolicyView(ctx context.Context, ws *store.Workspace, p *authz.Principal) (ApprovalPolicyView, error)
- func (s *Service) Preview(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (ApprovalPreview, error)
- func (s *Service) PreviewIn(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, ...) (ApprovalPreview, error)
- func (s *Service) Remind(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- func (s *Service) RequestApproval(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (uuid.UUID, error)
- func (s *Service) RequestForIssue(ctx context.Context, ws *store.Workspace, ownerID, campaignID uuid.UUID, ...) (uuid.UUID, error)
- func (s *Service) RequestTemplateApproval(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string, ...) (TransactionalApprovalState, error)
- func (s *Service) Reschedule(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- func (s *Service) Restore(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- func (s *Service) Revalidate(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID) ([]ApprovalChange, error)
- func (s *Service) Review(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (CampaignReview, error)
- func (s *Service) SavePolicy(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (ApprovalPolicyView, error)
- func (s *Service) ScheduleApproved(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (ReviewSendResult, error)
- func (s *Service) Send(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (ReviewSendResult, error)
- func (s *Service) SendRecheck(ctx context.Context, campaignID uuid.UUID) (SendRecheck, error)
- func (s *Service) TemplateApproval(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string) (TransactionalApprovalState, error)
- func (s *Service) Tick(ctx context.Context) error
- func (s *Service) Unschedule(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) error
- type Snapshot
- type SnapshotReadiness
- type SnapshotShare
- type TemplateApprovalPath
- type TickArgs
- type TickWorker
- type TransactionalApprovalInput
- type TransactionalApprovalState
- type TransactionalGate
- type TransactionalTemplates
- type WebsiteGate
- func (g WebsiteGate) PostChanged(ctx context.Context, ws *store.Workspace, p *authz.Principal, postID uuid.UUID, ...) error
- func (g WebsiteGate) PostDecision(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (website.PostApprovalDecision, error)
- func (g WebsiteGate) PostPublished(ctx context.Context, ws *store.Workspace, postID uuid.UUID, hash string) error
- func (g WebsiteGate) RequestPost(ctx context.Context, ws *store.Workspace, p *authz.Principal, ...) (uuid.UUID, error)
- type WebsitePosts
Constants ¶
const ( RuleAudienceMin = "audience_min" RuleWarmingProvider = "warming_provider" RuleNewProvider = "new_provider" RuleReadyWithWarnings = "ready_with_warnings" RuleAuthorLacksSend = "author_lacks_send" RuleApprovalLists = "approval_lists" RuleAutomationPublish = "automation_publish" // RuleTransactionalPublish: publishing a transactional template needs // approval (add-on transactional §3.6; off by default). RuleTransactionalPublish = "transactional_publish" // RulePostPublish: publishing a post of the publication website (or a // page) needs approval (design expansion phase 7; off by default). RulePostPublish = "post_publish" // RuleChannelCost: an SMS or WhatsApp campaign is estimated to cost at // least an amount (phase 8 brief §3.6; off by default). RuleChannelCost = "channel_cost_min" )
Rule keys, in the order of the policy screen.
const ( DecisionApprove = "approve" DecisionRequestChanges = "request_changes" DecisionReject = "reject" )
Decisions.
const HeldRetry = 15 * time.Minute
HeldRetry is how often a held send is rechecked.
InvalidationShare is how far the audience may move (in percent) before an approval no longer covers it.
const RecheckLead = 15 * time.Minute
RecheckLead is how long before a scheduled send Send Readiness runs again.
const RemindEvery = time.Hour
RemindEvery is how often an author can remind the approvers.
const RuleClientSignoff = "client_signoff"
RuleClientSignoff is the client sign-off rule.
const SendNowWithin = 15 * time.Minute
SendNowWithin is how recent the run a person confirms must be for a send that starts now: it is that send's send-time check.
Variables ¶
var ErrNoApprovers = errors.New("no approver other than the owner")
ErrNoApprovers means no one other than the owner can approve the issue.
Functions ¶
func EnableClientSignoff ¶
func EnableClientSignoff(raw json.RawMessage, on bool) (json.RawMessage, error)
EnableClientSignoff turns a stored policy's client sign-off on (with publishing automations left as it was) or off, keeping the rest.
func InvalidationReason ¶
func InvalidationReason(changes []ApprovalChange) string
InvalidationReason sums up the changes: "subject changed", "audience moved +14%". The screens add "after approval" when an approval was given.
func RegisterTransactional ¶
RegisterTransactional adds the approval operations of the template publish dialog.
func RouteKey ¶
func RouteKey(shares []readiness.ReadinessRouteShare) string
RouteKey is "ses:90,postal:10" for the route of a run.
func ScheduleText ¶
func ScheduleText(raw json.RawMessage, loc *time.Location) string
ScheduleText is "Nov 4, 09:00", "Send now" or "Best time within 24 h of Nov 4, 09:00", in English (as stored and as API clients read it).
Types ¶
type ApprovalAudienceRule ¶
type ApprovalAudienceRule struct {
Enabled bool `json:"enabled"`
N int64 `json:"n" minimum:"1" maximum:"100000000"`
}
ApprovalAudienceRule is the audience-size rule.
type ApprovalAudienceView ¶
type ApprovalAudienceView struct {
Count int64 `json:"count"`
Lists []string `json:"lists"`
// Excluded is "301 suppressed · 0 bounced in 30 days · role addresses".
Excluded string `json:"excluded"`
// Current is today's count and ChangePct how far it moved since the request.
Current int64 `json:"current"`
ChangePct float64 `json:"changePct"`
}
ApprovalAudienceView is the audience part of a request.
type ApprovalAuditLine ¶
type ApprovalAuditLine struct {
Action string `json:"action"`
Actor string `json:"actor"`
At time.Time `json:"at"`
IP string `json:"ip,omitempty"`
}
ApprovalAuditLine is the audit entry behind a decision ("campaign.approved · Marcus Chen · 10:42 · from 198.51.100.40").
type ApprovalAutomationSnapshot ¶
type ApprovalAutomationSnapshot struct {
Version int `json:"version"`
Migration string `json:"migration"`
Changes []string `json:"changes"`
}
ApprovalAutomationSnapshot is what an automation publish request covers.
type ApprovalBypassInput ¶
type ApprovalBypassInput struct {
ReviewSendInput
Reason string `json:"reason" minLength:"1" maxLength:"1000"`
Password string `json:"password,omitempty" maxLength:"500"`
}
ApprovalBypassInput is an Owner's emergency bypass of the approval policy.
type ApprovalCampaignView ¶
type ApprovalCampaignView struct {
ID string `json:"id"`
Status string `json:"status"`
Subject string `json:"subject"`
Preheader string `json:"preheader"`
From string `json:"from"`
Version int `json:"version"`
// CurrentVersion is the campaign's version now: after edits it is past
// the snapshot's ("What changed · v9 → v10").
CurrentVersion int `json:"currentVersion"`
EditedBy string `json:"editedBy,omitempty"`
EditedAt *time.Time `json:"editedAt,omitempty"`
// ScheduledAt is set while the campaign is scheduled.
ScheduledAt *time.Time `json:"scheduledAt,omitempty"`
}
ApprovalCampaignView is the campaign part of a request.
type ApprovalCan ¶
type ApprovalCan struct {
Decide bool `json:"decide"`
DecideReason string `json:"decideReason,omitempty"`
Comment bool `json:"comment"`
Cancel bool `json:"cancel"`
Remind bool `json:"remind"`
Restore bool `json:"restore"`
Schedule bool `json:"schedule"`
IsAuthor bool `json:"isAuthor"`
}
ApprovalCan says what the viewer may do on a request.
type ApprovalChange ¶
type ApprovalChange struct {
Field string `json:"field" enum:"subject,preheader,link,content,sender,audience,audience_count,route,schedule,language"`
Label string `json:"label"`
Before string `json:"before"`
After string `json:"after"`
// What says how a language version changed ("intro changed").
What string `json:"what,omitempty"`
}
ApprovalChange is one difference between an approval's snapshot and the campaign.
type ApprovalClientSignoff ¶
type ApprovalClientSignoff struct {
Enabled bool `json:"enabled"`
// Automations: publishing an automation needs the client's sign-off too.
Automations bool `json:"automations"`
}
ApprovalClientSignoff is the client sign-off rule of a client workspace.
type ApprovalClientSignoffInfo ¶
type ApprovalClientSignoffInfo struct {
Agency string `json:"agency"`
// Approvers are the client's people with campaigns:approve.
Approvers []string `json:"approvers"`
// Staff are the agency's people among the approvers; their approvals
// don't count toward it.
Staff []string `json:"staff"`
}
ApprovalClientSignoffInfo is the client sign-off rule on Settings › Approvals: the agency, and the client's people who can give it.
type ApprovalClientSignoffState ¶
type ApprovalClientSignoffState struct {
Met bool `json:"met"`
// Approvers are the client's people who can sign off.
Approvers []string `json:"approvers"`
// SignedOffBy is the client approver whose approval met it.
SignedOffBy string `json:"signedOffBy,omitempty"`
// StaffApprovals are agency staff who approved; they don't count.
StaffApprovals []string `json:"staffApprovals"`
// ViewerIsStaff: the person looking is agency staff, so their own
// approval wouldn't count either.
ViewerIsStaff bool `json:"viewerIsStaff"`
}
ApprovalClientSignoffState is a request's client sign-off, for the review page: who can give it, whether it's met, and whose approvals didn't count.
type ApprovalCommentInput ¶
type ApprovalCommentInput struct {
Body string `json:"body" minLength:"1" maxLength:"4000"`
}
ApprovalCommentInput adds to the discussion.
type ApprovalCommentView ¶
type ApprovalCommentView struct {
ID string `json:"id"`
Author ApprovalPerson `json:"author"`
Body string `json:"body"`
At time.Time `json:"at"`
}
ApprovalCommentView is one comment of the discussion.
type ApprovalCostRule ¶
type ApprovalCostRule struct {
Enabled bool `json:"enabled"`
Amount float64 `json:"amount" minimum:"0.01" maximum:"1000000"`
}
ApprovalCostRule is the cost rule for SMS and WhatsApp campaigns.
type ApprovalCounts ¶
type ApprovalCounts struct {
Pending int `json:"pending"`
Approved int `json:"approved"`
ChangesRequested int `json:"changesRequested"`
Rejected int `json:"rejected"`
Invalidated int `json:"invalidated"`
All int `json:"all"`
}
ApprovalCounts feeds the inbox tabs.
type ApprovalDecisionInput ¶
type ApprovalDecisionInput struct {
Decision string `json:"decision" enum:"approve,request_changes,reject"`
Comment string `json:"comment,omitempty" maxLength:"2000"`
}
ApprovalDecisionInput is an approver's decision.
type ApprovalDecisionView ¶
type ApprovalDecisionView struct {
Approver ApprovalPerson `json:"approver"`
Decision string `json:"decision" enum:"approve,request_changes,reject"`
Comment string `json:"comment"`
At time.Time `json:"at"`
}
ApprovalDecisionView is one approver's decision.
type ApprovalDetail ¶
type ApprovalDetail struct {
ApprovalRequestView
Name string `json:"name"`
Author ApprovalPerson `json:"author"`
Approvers []ApprovalPerson `json:"approvers"`
Campaign *ApprovalCampaignView `json:"campaign,omitempty"`
Readiness *ApprovalReadinessView `json:"readiness,omitempty"`
Audience *ApprovalAudienceView `json:"audience,omitempty"`
Route *ApprovalRouteView `json:"route,omitempty"`
Schedule *ApprovalScheduleView `json:"schedule,omitempty"`
Automation *ApprovalAutomationSnapshot `json:"automation,omitempty"`
// Transactional is what a transactional template publish request covers.
Transactional *ApprovalTransactionalSnapshot `json:"transactional,omitempty"`
// Website is what a post publish request covers.
Website *ApprovalWebsiteSnapshot `json:"website,omitempty"`
// Channel is a campaign's channel; SMS is what an SMS campaign's request
// covers (the text, segments, senders and cost per country).
Channel string `json:"channel" enum:"email,sms,push,whatsapp"`
SMS *ApprovalSMSSnapshot `json:"sms,omitempty"`
// Push and WhatsApp are what push and WhatsApp campaigns' requests
// cover: the notification, or the template with its variables (X22).
Push *ApprovalPushSnapshot `json:"push,omitempty"`
WhatsApp *ApprovalWhatsAppSnapshot `json:"whatsapp,omitempty"`
// Page is what a page publish request covers.
Page *ApprovalPageSnapshot `json:"page,omitempty"`
// ChangesSince lists what changed since the previous request this one
// follows (empty for a first request).
ChangesSince []ApprovalChange `json:"changesSince"`
// Next is the request that followed this one (after an invalidation).
NextID string `json:"nextId,omitempty"`
Comments []ApprovalCommentView `json:"comments"`
Held *ReviewHeld `json:"held,omitempty"`
Can ApprovalCan `json:"can"`
// ClientSignoff is set when the request needs the client's sign-off.
ClientSignoff *ApprovalClientSignoffState `json:"clientSignoff,omitempty"`
}
ApprovalDetail is the approval review screen.
type ApprovalFilterOption ¶
ApprovalFilterOption is an author or approver to filter by.
type ApprovalList ¶
type ApprovalList struct {
Items []ApprovalListItem `json:"items"`
Counts ApprovalCounts `json:"counts"`
Authors []ApprovalFilterOption `json:"authors"`
Approvers []ApprovalFilterOption `json:"approvers"`
Policy ApprovalPolicySummary `json:"policy"`
// AllRequests is true for approvers (they see every request).
AllRequests bool `json:"allRequests"`
CanManage bool `json:"canManage"`
// NextCursor asks for the next page; empty on the last one.
NextCursor string `json:"nextCursor,omitempty"`
}
ApprovalList is the approval inbox.
type ApprovalListItem ¶
type ApprovalListItem struct {
ID string `json:"id"`
SubjectType string `json:"subjectType" enum:"campaign,automation,transactional_template,website_post,website_page"`
CampaignID string `json:"campaignId,omitempty"`
// AutomationID is set for automation publish requests.
AutomationID string `json:"automationId,omitempty"`
// TransactionalTemplateID is set for transactional template publish requests.
TransactionalTemplateID string `json:"transactionalTemplateId,omitempty"`
// WebsitePostID is set for post publish requests; Website says what
// they cover (the inbox's "Post · Members").
WebsitePostID string `json:"websitePostId,omitempty"`
Website *ApprovalWebsiteSnapshot `json:"website,omitempty"`
// Channel is a campaign's channel (the row's icon): email, sms, push or
// whatsapp.
Channel string `json:"channel" enum:"email,sms,push,whatsapp"`
// WebsitePageID is set for page publish requests; Page says what they
// cover (the inbox's "Page · /field-guide").
WebsitePageID string `json:"websitePageId,omitempty"`
Page *ApprovalPageSnapshot `json:"page,omitempty"`
Name string `json:"name"`
// Rules is "rules: audience ≥ 10,000 · warming-up provider".
Rules string `json:"rules"`
Author ApprovalPerson `json:"author"`
Audience int64 `json:"audience"`
// AudienceNow is set when the audience moved after approval (15,002 → 17,110).
AudienceNow *int64 `json:"audienceNow,omitempty"`
Route string `json:"route"`
// Schedule: the snapshot's schedule, or when it was sent.
ScheduleMode string `json:"scheduleMode" enum:"now,at,best_time,local"`
ScheduleAt *time.Time `json:"scheduleAt,omitempty"`
SentAt *time.Time `json:"sentAt,omitempty"`
RequestedAt time.Time `json:"requestedAt"`
Status string `json:"status" enum:"pending,approved,changes_requested,rejected,invalidated,bypassed,sent,cancelled"`
DecidedBy string `json:"decidedBy,omitempty"`
DecidedAt *time.Time `json:"decidedAt,omitempty"`
// Note is the line under the status ("Marcus Chen: “exclude 180-day unengaged”").
Note string `json:"note,omitempty"`
}
ApprovalListItem is one row of the approval inbox.
type ApprovalPageSnapshot ¶
type ApprovalPageSnapshot struct {
PageID string `json:"pageId"`
Name string `json:"name"`
Template string `json:"template"`
Slug string `json:"slug"`
Path string `json:"path"`
// Visibility is who can read the page; VisibilityLabel says it in words
// ("Members", "Paid").
Visibility string `json:"visibility" enum:"public,members,paid"`
VisibilityLabel string `json:"visibilityLabel"`
// When the page goes live once approved: now (when approved) or at a
// time.
When string `json:"when" enum:"now,at"`
PublishAt *time.Time `json:"publishAt,omitempty"`
// Published is set once the approved page went live.
Published bool `json:"published"`
}
ApprovalPageSnapshot is what a page publish request covers, as the approval review shows it.
type ApprovalPath ¶
type ApprovalPath struct {
api.WorkspaceInput
ApprovalID string `path:"approvalId" format:"uuid"`
}
ApprovalPath is the {workspace}/{approvalId} of approval operations.
type ApprovalPendingItem ¶
type ApprovalPendingItem struct {
ID string `json:"id"`
Name string `json:"name"`
Author ApprovalPerson `json:"author"`
Audience int64 `json:"audience"`
RequestedAt time.Time `json:"requestedAt"`
}
ApprovalPendingItem is a pending request on the policy screen.
type ApprovalPerson ¶
type ApprovalPerson struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Initials string `json:"initials"`
Color string `json:"color"`
Role string `json:"role"`
// Presence is "online" (active in the last 15 minutes) or "active 2 h ago".
Presence string `json:"presence,omitempty"`
}
ApprovalPerson is a member as approval screens show them.
type ApprovalPolicy ¶
type ApprovalPolicy struct {
AudienceMin ApprovalAudienceRule `json:"audienceMin"`
// WarmingProvider: the route includes a provider that is warming up or
// was connected in the last NewProviderDays days.
WarmingProvider bool `json:"warmingProvider"`
NewProviderDays int `json:"newProviderDays" minimum:"1" maximum:"90"`
ReadyWithWarnings bool `json:"readyWithWarnings"`
AuthorLacksSend bool `json:"authorLacksSend"`
ApprovalLists bool `json:"approvalLists"`
ApprovalsRequired int `json:"approvalsRequired" minimum:"1" maximum:"2"`
AutomationPublish bool `json:"automationPublish"`
// TransactionalPublish: publishing a transactional template needs an
// approver other than the publisher (off by default).
TransactionalPublish bool `json:"transactionalPublish"`
// PostPublish: publishing a post or page of the website needs an
// approver other than the publisher (off by default). "The author
// lacks the send permission" covers website:publish too.
PostPublish bool `json:"postPublish"`
EmergencyBypass bool `json:"emergencyBypass"`
// ClientSignoff: in a client workspace, every send needs one approval
// from a Client approver; approvals from agency staff don't count.
// Leaving it out of a save turns it off.
ClientSignoff ApprovalClientSignoff `json:"clientSignoff,omitempty"`
// ChannelCost: an SMS or WhatsApp campaign is estimated to cost at
// least Amount (off by default).
ChannelCost ApprovalCostRule `json:"channelCost,omitempty"`
}
ApprovalPolicy is the workspace's approval policy.
func ParsePolicy ¶
func ParsePolicy(raw json.RawMessage) ApprovalPolicy
ParsePolicy reads the stored policy. An empty policy is the default of a new workspace (A5 §3.8).
func (ApprovalPolicy) Evaluate ¶
func (p ApprovalPolicy) Evaluate(f RuleFacts) []ApprovalRuleMatch
Evaluate returns the rules that match a send. No match: no approval needed.
func (ApprovalPolicy) RuleLabels ¶
func (p ApprovalPolicy) RuleLabels() []string
RuleLabels are the short phrases of the enabled rules ("audience ≥ 10,000").
func (ApprovalPolicy) RuleLabelsIn ¶
func (p ApprovalPolicy) RuleLabelsIn(l i18n.Lang) []string
RuleLabelsIn are the short phrases of the enabled rules in a language.
type ApprovalPolicyMatches ¶
type ApprovalPolicyMatches struct {
// Warming is "Postal (mta.acme.io) is warming up, day 9 of 21." or empty.
Warming string `json:"warming"`
// LacksSend names the members who can edit but not send.
LacksSend []string `json:"lacksSend"`
// LacksSendRoles names their roles ("Content Writers").
LacksSendRoles []string `json:"lacksSendRoles"`
// ApprovalLists names the lists marked "Requires approval".
ApprovalLists []string `json:"approvalLists"`
}
ApprovalPolicyMatches says what each rule matches today.
type ApprovalPolicySummary ¶
type ApprovalPolicySummary struct {
Rules []string `json:"rules"`
ApprovalsRequired int `json:"approvalsRequired"`
Approvers []string `json:"approvers"`
MedianWaitMinutes *int `json:"medianWaitMinutes,omitempty"`
}
ApprovalPolicySummary is the "Policy in force" card.
type ApprovalPolicyView ¶
type ApprovalPolicyView struct {
Policy ApprovalPolicy `json:"policy"`
Approvers []ApprovalPerson `json:"approvers"`
Matches ApprovalPolicyMatches `json:"matches"`
// BypassCount is how often the emergency bypass was used in 90 days.
BypassCount int64 `json:"bypassCount"`
Pending []ApprovalPendingItem `json:"pending"`
CanManage bool `json:"canManage"`
Reason string `json:"reason,omitempty"`
// ClientSignoff describes the client sign-off rule; set in an agency's
// client workspaces, where the rule is offered (clientsignoff.go).
ClientSignoff *ApprovalClientSignoffInfo `json:"clientSignoff,omitempty"`
}
ApprovalPolicyView is Settings › Approvals.
type ApprovalPreview ¶
type ApprovalPreview struct {
Subject string `json:"subject"`
Preheader string `json:"preheader"`
HTML string `json:"html"`
Version int `json:"version"`
// Language is the language version shown; Languages are the versions
// the approval covers, the source first (the preview's language picker).
Language string `json:"language"`
Languages []ApprovalPreviewLanguage `json:"languages"`
}
ApprovalPreview is the email a request covers.
type ApprovalPreviewLanguage ¶
type ApprovalPreviewLanguage struct {
Language string `json:"language"`
Name string `json:"name"`
Status string `json:"status" enum:"source,translated,draft"`
}
ApprovalPreviewLanguage is one language version an approval covers.
type ApprovalPushButton ¶
ApprovalPushButton is a notification's button.
type ApprovalPushSnapshot ¶
type ApprovalPushSnapshot struct {
Title string `json:"title"`
Message string `json:"message"`
Link string `json:"link"`
Image string `json:"image,omitempty"`
Icon string `json:"icon,omitempty"`
Host string `json:"host,omitempty"`
Buttons []ApprovalPushButton `json:"buttons"`
TTLMinutes int `json:"ttlMinutes"`
Tag string `json:"tag,omitempty"`
Sites []string `json:"sites"`
Recipients int64 `json:"recipients"`
Schedule string `json:"schedule"`
}
ApprovalPushSnapshot is a push campaign at request time.
type ApprovalReadinessView ¶
type ApprovalReadinessView struct {
Verdict string `json:"verdict" enum:"ready,warnings,blocked"`
Passed int `json:"passed"`
Warnings int `json:"warnings"`
Blocks int `json:"blocks"`
Total int `json:"total"`
CheckedAt time.Time `json:"checkedAt"`
Issues []readiness.ReadinessCheck `json:"issues"`
}
ApprovalReadinessView is the Send Readiness result a request was given on.
type ApprovalRequestInput ¶
type ApprovalRequestInput struct {
Note string `json:"note,omitempty" maxLength:"2000" doc:"A note for approvers"`
}
ApprovalRequestInput asks for approval.
type ApprovalRequestView ¶
type ApprovalRequestView struct {
ID string `json:"id"`
Status string `json:"status" enum:"pending,approved,changes_requested,rejected,invalidated,bypassed,sent,cancelled"`
SubjectType string `json:"subjectType" enum:"campaign,automation,transactional_template,website_post,website_page"`
RequestedAt time.Time `json:"requestedAt"`
RequestedBy ApprovalPerson `json:"requestedBy"`
Note string `json:"note"`
Version int `json:"version"`
Given int `json:"given"`
Needed int `json:"needed"`
Decisions []ApprovalDecisionView `json:"decisions"`
DecidedBy string `json:"decidedBy,omitempty"`
DecidedAt *time.Time `json:"decidedAt,omitempty"`
// Comment is the latest decision's comment.
Comment string `json:"comment,omitempty"`
InvalidatedAt *time.Time `json:"invalidatedAt,omitempty"`
// InvalidatedReason says what changed ("subject changed", "audience
// moved +14%"); screens add "after approval" when one was given.
// InvalidatedFields is what it says changed, for a screen that writes its
// own sentence around it ("edited the subject and a link"); empty when
// the reason isn't about edited fields.
InvalidatedReason string `json:"invalidatedReason,omitempty"`
InvalidatedFields string `json:"invalidatedFields,omitempty"`
InvalidatedBy string `json:"invalidatedBy,omitempty"`
Changes []ApprovalChange `json:"changes"`
Snapshot ApprovalSnapshotSummary `json:"snapshot"`
Rules []ApprovalRuleMatch `json:"rules"`
Audit *ApprovalAuditLine `json:"audit,omitempty"`
BypassReason string `json:"bypassReason,omitempty"`
FollowsID string `json:"followsId,omitempty"`
}
ApprovalRequestView is a request as Review & send and the approval page show it.
type ApprovalRequested ¶
type ApprovalRequested struct {
ID string `json:"id"`
}
ApprovalRequested is the request that was opened.
type ApprovalRouteView ¶
type ApprovalRouteView struct {
SplitLabel string `json:"splitLabel"`
}
ApprovalRouteView is the route part of a request.
type ApprovalRuleMatch ¶
type ApprovalRuleMatch struct {
Key string `` /* 199-byte string literal not displayed */
// Label is the sentence ("Audience of 47,912 is at least 10,000"),
// Short the inbox phrase ("audience ≥ 10,000") and Badge the chip.
Label string `json:"label"`
Short string `json:"short"`
Badge string `json:"badge"`
// Author is the author's name for "author lacks send" ("You don't hold…"
// is written by the screen when the author reads it).
Author string `json:"author,omitempty"`
Role string `json:"role,omitempty"`
// contains filtered or unexported fields
}
ApprovalRuleMatch is a rule that matched a send.
type ApprovalSMSCountry ¶
type ApprovalSMSCountry struct {
Country string `json:"country"`
Sender string `json:"sender"`
Provider string `json:"provider"`
Recipients int64 `json:"recipients"`
Price float64 `json:"price"`
Cost float64 `json:"cost"`
Skipped bool `json:"skipped"`
}
ApprovalSMSCountry is one country of an SMS campaign's route.
type ApprovalSMSSnapshot ¶
type ApprovalSMSSnapshot struct {
Text string `json:"text"`
Prefix string `json:"prefix"`
OptOut string `json:"optOut"`
Body string `json:"body"`
Chars int `json:"chars"`
Segments int `json:"segments"`
Encoding string `json:"encoding"`
Recipients int64 `json:"recipients"`
Cost float64 `json:"cost"`
Schedule string `json:"schedule"`
Countries []ApprovalSMSCountry `json:"countries"`
}
ApprovalSMSSnapshot is an SMS campaign at request time.
type ApprovalScheduleView ¶
type ApprovalScheduleView struct {
Mode string `json:"mode" enum:"now,at,best_time,local"`
At *time.Time `json:"at,omitempty"`
Timezone string `json:"timezone"`
Minutes int `json:"minutes"`
// AutoPause is "Bounces 2% · complaints 0.10% per mailbox provider".
AutoPause string `json:"autoPause"`
}
ApprovalScheduleView is the schedule part of a request.
type ApprovalShare ¶
type ApprovalShare struct {
}
ApprovalShare is one provider of a request's route.
type ApprovalSnapshotSummary ¶
type ApprovalSnapshotSummary struct {
Version int `json:"version"`
Subject string `json:"subject"`
AudienceCount int64 `json:"audienceCount"`
// RouteLabel is "SES 90 / Postal 10"; RouteText "SES 43,121 · Postal 4,791".
RouteLabel string `json:"routeLabel"`
RouteText string `json:"routeText"`
SplitLabel string `json:"splitLabel"`
ScheduleText string `json:"scheduleText"`
ScheduleMode string `json:"scheduleMode" enum:"now,at,best_time,local"`
ScheduleAt *time.Time `json:"scheduleAt,omitempty"`
Timezone string `json:"timezone,omitempty"`
}
ApprovalSnapshotSummary is the gist of what a request covers.
type ApprovalTransactionalSnapshot ¶
type ApprovalTransactionalSnapshot struct {
TemplateID string `json:"templateId"`
Key string `json:"key"`
Name string `json:"name"`
Category string `json:"category"`
Version int `json:"version"`
LiveVersion *int `json:"liveVersion,omitempty"`
DraftRevision int `json:"draftRevision"`
// Subject is the subject's change ("" when unchanged).
SubjectBefore string `json:"subjectBefore,omitempty"`
SubjectAfter string `json:"subjectAfter,omitempty"`
// Variables are the variable changes ("+ trial_end_date · date · required").
Variables []string `json:"variables"`
ContentSummary string `json:"contentSummary"`
// Breaking is the breaking-change sentence, empty when nothing breaks.
Breaking string `json:"breaking,omitempty"`
TestRenders []ApprovalTransactionalTestRender `json:"testRenders"`
Passed int `json:"passed"`
Warnings int `json:"warnings"`
// PublishedVersion is set once the approved draft was published.
PublishedVersion int `json:"published_version,omitempty"`
}
ApprovalTransactionalSnapshot is what a template publish request covers, as the approval review shows it.
type ApprovalTransactionalTestRender ¶
ApprovalTransactionalTestRender is one test render at request time.
type ApprovalWebsiteSnapshot ¶
type ApprovalWebsiteSnapshot struct {
PostID string `json:"postId"`
Title string `json:"title"`
Kind string `json:"kind" enum:"campaign,web"`
Slug string `json:"slug"`
Path string `json:"path"`
Visibility string `json:"visibility" enum:"public,members,paid"`
// VisibilityLabel says it in words ("Members", "Paid · all tiers").
VisibilityLabel string `json:"visibilityLabel"`
// When the post goes live once approved: now (when approved), at a
// time, or with the campaign's send.
When string `json:"when" enum:"now,at,with_send"`
PublishAt *time.Time `json:"publishAt,omitempty"`
Excerpt string `json:"excerpt"`
// Published is set once the approved post went live.
Published bool `json:"published"`
}
ApprovalWebsiteSnapshot is what a post publish request covers, as the approval review shows it.
type ApprovalWhatsAppSnapshot ¶
type ApprovalWhatsAppSnapshot struct {
Template string `json:"template"`
Language string `json:"language"`
Category string `json:"category"`
Body string `json:"body"`
Preview string `json:"preview"`
Buttons []string `json:"buttons"`
Variables []ApprovalWhatsAppValue `json:"variables"`
Business string `json:"business"`
Number string `json:"number"`
Recipients int64 `json:"recipients"`
Cost float64 `json:"cost"`
Schedule string `json:"schedule"`
}
ApprovalWhatsAppSnapshot is a WhatsApp campaign at request time.
type ApprovalWhatsAppValue ¶
type ApprovalWhatsAppValue struct {
Key string `json:"key"`
Source string `json:"source"`
Fallback string `json:"fallback,omitempty"`
}
ApprovalWhatsAppValue is a template variable and what fills it.
type AutomationGate ¶
type AutomationGate struct{ S *Service }
AutomationGate asks for approval before an automation version goes live when the workspace policy says so (automations.PublishGate). Once approved, the approvals domain publishes it with Service.CompletePublish.
func (AutomationGate) Check ¶
func (g AutomationGate) Check(ctx context.Context, tx pgx.Tx, req automations.PublishRequest) (automations.GateDecision, error)
Check implements automations.PublishGate, inside the publish transaction.
type CampaignReview ¶
type CampaignReview struct {
Campaign ReviewCampaign `json:"campaign"`
Run *readiness.ReadinessRun `json:"run,omitempty"`
Stale bool `json:"stale"`
Running *readiness.ReadinessProgress `json:"running,omitempty"`
// Failed is the last run when it stopped on an error.
Failed *readiness.ReadinessRunFailure `json:"failed,omitempty"`
// Fixes are the latest one-click fixes applied together, while Undo can
// still put the campaign back as it was before them (R1.U3).
Fixes *readiness.ReadinessFixBatch `json:"fixes,omitempty"`
// SendNowWithin is how many minutes old the run may be for a send that
// starts now (it is that send's check); older, the checks run again.
SendNowWithin int `json:"sendNowWithin"`
Thresholds readiness.ReadinessThresholds `json:"thresholds"`
// ThresholdsOwn is true when the campaign has thresholds of its own
// instead of the workspace's defaults.
ThresholdsOwn bool `json:"thresholdsOwn"`
Schedule readiness.ReadinessSchedule `json:"schedule"`
TestSends []ReviewTestSend `json:"testSends"`
Approval ReviewApproval `json:"approval"`
Held *ReviewHeld `json:"held,omitempty"`
Scheduled *ReviewScheduled `json:"scheduled,omitempty"`
Access ReviewAccess `json:"access"`
// Typed says whether the sender types the recipient count to confirm,
// and why: only unusual sends ask for it (SR-13).
Typed ReviewTyped `json:"typed"`
// PauseSlack is true when a webhook posts campaign.paused to Slack, so a
// held send is announced there as well as by email.
PauseSlack bool `json:"pauseSlack"`
// Timezone is the workspace's.
Timezone string `json:"timezone"`
// Canary is the send's canary phase (C1): the choice, and what the
// sending engine would do on its own.
Canary ReviewCanary `json:"canary"`
}
CampaignReview is the Review & send screen.
type ChannelCampaign ¶
type ChannelCampaign struct {
Name string
Status string
Version int
// Facts are what the rules look at; the author's fields are filled here.
Facts RuleFacts
// Snapshot is what a request covers; Current the same, for revalidation.
Snapshot Snapshot
Current Current
// Blocks counts blocking checks: a blocked campaign isn't sent for
// approval.
Blocks int
// SendPermission is the channel's own send permission ("sms:send").
SendPermission authz.Permission
}
ChannelCampaign is a channel campaign as the approval flow sees it.
type ChannelCampaigns ¶
type ChannelCampaigns interface {
DescribeForApproval(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID) (ChannelCampaign, error)
// MoveScheduled moves a scheduled campaign that hasn't started to
// another time: the calendar's reschedule (review 2026-11 CA-9). The
// channel re-plans its own sends (quiet hours, each recipient's zone)
// and writes the audit entry.
MoveScheduled(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID, to ChannelMove) error
}
ChannelCampaigns describes campaigns of one channel; the channel's domain implements it.
type ChannelMove ¶
ChannelMove is the new time of a channel campaign: an instant, or with Local a wall time (LocalDate, LocalMinute after midnight) in each recipient's own zone. At is then when that time first comes, anywhere.
type Current ¶
type Current struct {
Version int
ContentHash string
Subject string
Preheader string
SenderID string
From string
MJML string
HTML string
Audience json.RawMessage
AudienceNames []string
AudienceCount int64
RouteKey string
SplitLabel string
Schedule json.RawMessage
Timezone string
UpdatedBy string
Languages []languages.VersionSnapshot
// Text, ScheduleLabel and ScheduleText are a channel campaign's (see Snapshot).
Text string
ScheduleLabel string
ScheduleText i18n.Text
}
Current is the campaign as it stands, in snapshot terms.
type HoldDetail ¶
type HoldDetail struct {
RunID string `json:"run_id"`
Reason string `json:"reason"`
Blocks []readiness.ReadinessCheck `json:"blocks"`
Blocking []string `json:"blocking,omitempty"`
Holds []readiness.SendHold `json:"holds,omitempty"`
Audience int64 `json:"audience,omitempty"`
Confirmed int64 `json:"confirmed,omitempty"`
}
HoldDetail is campaign_incidents.detail of a held send. Holds recorded here carry the run, its blocking checks and why the send-time recheck held it (Holds, with the confirmed and the fresh count); the sending engine's carry only the titles of what blocked (Blocking).
type IssueRequest ¶
type IssueRequest struct {
Digest string
Number int
// Held is true when Send Readiness blocked the issue at preparation:
// approvers are told it waits for the block to be fixed.
Held bool
// Actor is who the audit entry names ("System · Engineering blog
// roundup, turned on by Sofia Rossi").
Actor *audit.Actor
}
IssueRequest describes the digest issue a request is for.
type ListParams ¶
type ListParams struct {
Status string
Author string
Approver string
Days int
// Query searches what the requests ask about by name.
Query string
// Cursor is a page's NextCursor; Limit is the page size (50, at most 100).
Cursor string
Limit int
}
ListParams filter the inbox.
type PagesGate ¶
type PagesGate struct{ S *Service }
PagesGate implements pages.Approvals with the workspace's rules.
func (PagesGate) PageChanged ¶
func (g PagesGate) PageChanged(ctx context.Context, ws *store.Workspace, p *authz.Principal, pageID uuid.UUID, name, hash string) error
PageChanged implements pages.ApprovalHooks: requests for the page as it was are invalidated, and their authors told.
func (PagesGate) PageDecision ¶
func (g PagesGate) PageDecision(ctx context.Context, ws *store.Workspace, p *authz.Principal, req pages.ApprovalRequest) (pages.ApprovalDecision, error)
PageDecision implements pages.Approvals.
func (PagesGate) PagePublished ¶
func (g PagesGate) PagePublished(ctx context.Context, ws *store.Workspace, pageID uuid.UUID, hash string) error
PagePublished implements pages.ApprovalHooks: the approved request a publish relied on remembers it went out.
func (PagesGate) RequestPage ¶
func (g PagesGate) RequestPage(ctx context.Context, ws *store.Workspace, p *authz.Principal, req pages.ApprovalRequest, note string) (uuid.UUID, error)
RequestPage implements pages.Approvals: it asks the approvers to approve publishing the page as it is. A pending request for an older version is replaced.
type PagesPublisher ¶
type PagesPublisher interface {
PublishApproved(ctx context.Context, ws *store.Workspace, pageID uuid.UUID, approvalID, approver, hash string) error
}
PagesPublisher publishes a page once its approval is granted (internal/pages).
type ReviewAB ¶
type ReviewAB struct {
Kind string `json:"kind" enum:"subject,content,send_time"`
Variants int `json:"variants"`
TestPercent int `json:"testPercent"`
DurationHours int `json:"durationHours"`
Label string `json:"label"`
}
ReviewAB summarises an A/B test ("Subject test · 2 variants · 20% sample").
type ReviewAccess ¶
type ReviewAccess struct {
CanEdit bool `json:"canEdit"`
CanSend bool `json:"canSend"`
CanApprove bool `json:"canApprove"`
CanManageRouting bool `json:"canManageRouting"`
CanSendTestToOthers bool `json:"canSendTestToOthers"`
IsOwner bool `json:"isOwner"`
HasPassword bool `json:"hasPassword"`
Email string `json:"email"`
// SendHelpers and EditHelpers name up to two other members who can
// send or change campaigns: the screen says who can, never a
// permission key (X-1).
SendHelpers []string `json:"sendHelpers"`
EditHelpers []string `json:"editHelpers"`
}
ReviewAccess is what the viewer may do.
type ReviewApproval ¶
type ReviewApproval struct {
// Required is true when a rule matches this send by the viewer.
Required bool `json:"required"`
Rules []ApprovalRuleMatch `json:"rules"`
Needed int `json:"needed"`
Approvers []ApprovalPerson `json:"approvers"`
// Request is the open request, or the latest one when none is open.
Request *ApprovalRequestView `json:"request,omitempty"`
// Valid is true when an approved request covers the campaign as it is.
Valid bool `json:"valid"`
CanRequest bool `json:"canRequest"`
RequestReason string `json:"requestReason,omitempty"`
CanBypass bool `json:"canBypass"`
MedianWaitMinutes *int `json:"medianWaitMinutes,omitempty"`
PolicyRules []string `json:"policyRules"`
// EmergencyBypass says the policy allows the Owners' emergency send;
// Owners names the Owners other than the reader, who can use it
// (the More menu: "Owners only. Ask Linh Nguyen.").
EmergencyBypass bool `json:"emergencyBypass"`
Owners []string `json:"owners"`
}
ReviewApproval is the approval side of Review & send.
type ReviewCampaign ¶
type ReviewCampaign struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status" enum:"draft,approval,approved,scheduled,sending,paused,sent,cancelled,failed"`
Subject string `json:"subject"`
Preheader string `json:"preheader"`
From string `json:"from"`
ReplyTo string `json:"replyTo"`
Version int `json:"version"`
AutosavedAt *time.Time `json:"autosavedAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt"`
UpdatedBy string `json:"updatedBy"`
AudienceLabel string `json:"audienceLabel"`
ScheduledAt *time.Time `json:"scheduledAt,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
AB *ReviewAB `json:"ab,omitempty"`
// Editable is false once the send started.
Editable bool `json:"editable"`
// Settings are the campaign's content settings, which the Links card
// saves whole through update-campaign (its own "Add UTM tags").
Settings campaigns.ComposerContentSettings `json:"settings"`
// UTM are the tags the send adds to its web links, as the sending
// engine computes them; omitted when it adds none.
UTM *ReviewUTM `json:"utm,omitempty"`
// UTMDefault is the workspace's "Add UTM tags to links" (Settings ›
// Senders), which applies when Settings has no choice of its own.
UTMDefault bool `json:"utmDefault"`
}
ReviewCampaign is the campaign as Review & send shows it.
type ReviewCanary ¶
type ReviewCanary struct {
Choice string `json:"choice" enum:"auto,on,off"`
Planned bool `json:"planned"`
Auto bool `json:"auto"`
// Reasons are why the engine would run one by itself, with the numbers
// behind them (the live monitor words them the same way).
Reasons []string `json:"reasons" enum:"new_domain,new_ip,never_mailed,over_usual"`
Size int64 `json:"size"`
Seeds int `json:"seeds"`
Domain string `json:"domain,omitempty"`
NeverMailed int64 `json:"neverMailed"`
Usual int64 `json:"usual"`
Audience int64 `json:"audience"`
// NewIPs are the dedicated sending IPs that never sent for the
// workspace (new_ip, review GS-10).
NewIPs []sending.CanaryIP `json:"newIps"`
}
ReviewCanary is the canary phase of a send (C1, GS-10): the choice confirmed (auto when none was), and the sending engine's plan when it can tell: whether it starts with a canary on its own (Auto), why, and how many recipients the canary holds.
type ReviewCount ¶
ReviewCount is a recipient count and when it was counted.
type ReviewHeld ¶
type ReviewHeld struct {
Since time.Time `json:"since"`
Reason string `json:"reason"`
Held int64 `json:"held"`
Blocks []readiness.ReadinessCheck `json:"blocks"`
// Holds are why the send-time recheck held the send (SR-3): blocks,
// warnings or unknown checks nobody confirmed, the audience changed by
// more than 10%, the content, sender or route edited after scheduling.
Holds []ReviewHoldReason `json:"holds"`
// Reviewed is the count the person confirmed when they scheduled it;
// Rechecked the send-time recheck's (the count to confirm again).
Reviewed *ReviewCount `json:"reviewed,omitempty"`
Rechecked *ReviewCount `json:"rechecked,omitempty"`
// ExpiresAt is when the held send goes back to Draft if nobody
// reviews it (readiness.HeldExpiry after its time).
ExpiresAt *time.Time `json:"expiresAt,omitempty"`
}
ReviewHeld is a scheduled send the send-time recheck held.
type ReviewHoldReason ¶
type ReviewHoldReason struct {
Kind string `json:"kind" enum:"blocked,new_warning,unknown,audience_change,edited"`
Text string `json:"text"`
}
ReviewHoldReason is one reason a send is held, in the reader's language.
type ReviewScheduled ¶
ReviewScheduled is who scheduled the campaign and when.
type ReviewSendInput ¶
type ReviewSendInput struct {
// RunID is the Send Readiness run the person reviewed; the send is
// refused when the checks ran again or the campaign changed since.
RunID string `json:"runId" format:"uuid"`
// Schedule replaces the saved schedule (omit to use it).
Schedule *readiness.ReadinessSchedule `json:"schedule,omitempty"`
// Confirm is the recipient count, typed for large sends.
Confirm string `json:"confirm,omitempty" maxLength:"20"`
// Acknowledged lists the keys of the warnings the person confirmed.
Acknowledged []string `json:"acknowledged,omitempty" maxItems:"60"`
// Canary is the canary choice (review GS-10, C1): auto lets Traffic
// rules decide, on runs one, off sends to everyone at once; without one
// the campaign keeps the choice it has.
Canary string `json:"canary,omitempty" enum:"auto,on,off,"`
}
ReviewSendInput confirms a send from Review & send.
type ReviewSendResult ¶
type ReviewSendResult struct {
Status string `json:"status" enum:"scheduled,sending"`
ScheduledAt *time.Time `json:"scheduledAt,omitempty"`
Recipients int64 `json:"recipients"`
}
ReviewSendResult says what happened.
type ReviewTestSend ¶
type ReviewTestSend struct {
To string `json:"to"`
At time.Time `json:"at"`
By string `json:"by"`
Provider string `json:"provider"`
// Delivered names the mailbox provider that accepted it, when known ("Gmail").
Delivered string `json:"delivered,omitempty"`
// Languages are the language versions sent ("en", "es", "de").
Languages []string `json:"languages,omitempty"`
}
ReviewTestSend is a recent test email.
type ReviewTyped ¶
ReviewTyped is why a send asks its sender to type the recipient count ("31,192 is 2.1× your usual 15,000 for this list."); Needed is false for a routine send, confirmed with checkboxes.
type ReviewUTM ¶
type ReviewUTM struct {
Source string `json:"source"`
Medium string `json:"medium"`
Campaign string `json:"campaign"`
}
ReviewUTM are the UTM tags a send adds to its links.
type RuleFacts ¶
type RuleFacts struct {
Recipients int64
Verdict string
Warnings int
// AuthorCanSend is whether the person sending holds campaigns:send (and
// the channel's own send permission for SMS, push and WhatsApp).
AuthorCanSend bool
AuthorName string
AuthorRole string
// ApprovalLists are the audience's lists marked "Requires approval".
ApprovalLists []string
Now time.Time
// Channel is the campaign's channel ("" or "email" for email); Cost its
// estimated cost; SendPermission the permission the author lacks
// ("sms:send"), named by the "author lacks send" rule.
Channel string
Cost float64
SendPermission string
}
RuleFacts are what the rules look at.
func IssueRulesFacts ¶
func IssueRulesFacts(recipients int64, shares []RuleShare, ownerCanSend bool, ownerName, ownerRole string, now time.Time) RuleFacts
IssueRulesFacts are the facts the approval rules read for a digest's issues before one is prepared (the setup screen says up front which rules every issue will match).
type SendRecheck ¶
type SendRecheck struct {
// Verdict is "ready", "warnings" or "blocked".
Verdict string
// Blocking are the titles of the blocking checks, and why the approval
// doesn't cover the send when it doesn't.
Blocking []string
// Throttles are messages per second per mailbox provider ("outlook": 5);
// nil keeps the engine's defaults.
Throttles map[string]float64
// Audience is the run's final recipient count, RunID the run.
Audience int64
RunID string
}
SendRecheck is Send Readiness as a send starts, in the terms the sending engine asks for (its send-time recheck): the verdict, what blocks and the messages per second Send Readiness set per mailbox provider.
type Service ¶
type Service struct {
Pool *pgxpool.Pool
Q *store.Queries
Audit *audit.Logger
Log *slog.Logger
Now func() time.Time
Readiness *readiness.Service
// Campaigns restores versions ("Restore v9 subject").
Campaigns *campaigns.Service
// Sending starts and schedules sends (App.Sending, read at call time).
Sending func() sending.Starter
// CanaryPlanner tells Review & send whether the sending engine would
// start a send with a canary on its own (C1: engine.CanaryPlanFor);
// nil when the engine doesn't tell.
CanaryPlanner sending.CanaryPlanner
// Automations publishes an automation once its approval is granted.
Automations *automations.Service
// Languages snapshots a campaign's language versions; nil leaves them out.
Languages *languages.Service
// TransactionalTemplates describes what publishing a transactional
// template would change, for its approval request.
TransactionalTemplates TransactionalTemplates
// Website publishes a post once its approval is granted, and
// WebsitePreview draws its web preview for the review (nil without the
// website).
Website func() WebsitePosts
WebsitePreview func(ctx context.Context, ws *store.Workspace, postID uuid.UUID) (string, error)
// Channels describe campaigns on channels other than email, by channel
// ("sms"): their facts and snapshots (channels.go).
Channels map[string]ChannelCampaigns
// Pages publishes a page once its approval is granted, and PagePreview
// draws the page as it would go live, for the review (nil without
// pages).
Pages func() PagesPublisher
PagePreview func(ctx context.Context, ws *store.Workspace, pageID uuid.UUID) (string, error)
}
Service holds the approvals and Review & send dependencies.
func (*Service) Bypass ¶
func (s *Service) Bypass(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID, in ApprovalBypassInput) (ReviewSendResult, error)
Bypass sends without approval: Owners only, with a reason, when the policy allows it. It's logged and every approver is told.
func (*Service) CampaignChanged ¶
CampaignChanged re-checks the open approval of a campaign after a change (the composer's and Send Readiness's change hooks call it).
func (*Service) Cancel ¶
func (s *Service) Cancel(ctx context.Context, ws *store.Workspace, p *authz.Principal, requestID uuid.UUID) error
Cancel withdraws a request (its author, or an Owner).
func (*Service) ChannelGate ¶
func (s *Service) ChannelGate(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID) (*store.ApprovalRequest, error)
ChannelGate checks the approval rules for a channel campaign sent by p. It returns the approved request that covers the campaign as it stands, nil when no rule matches, or a problem: approval_required or approval_invalidated.
func (*Service) ChannelReview ¶
func (s *Service) ChannelReview(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID) (ReviewApproval, error)
ChannelReview is the approval side of a channel campaign's Review & send.
func (*Service) CheckSendTime ¶
CheckSendTime is the recheck when a send starts (add-on 3.8): Send Readiness runs again and the approval must still cover the campaign. It returns an error wrapping sending.ErrNotReady when the send must not start; the campaign is then held and its author and approvers are told. The sending engine calls it before the first batch of a scheduled send.
func (*Service) Comment ¶
func (s *Service) Comment(ctx context.Context, ws *store.Workspace, p *authz.Principal, requestID uuid.UUID, in ApprovalCommentInput) error
Comment adds to a request's discussion (author and approvers).
func (*Service) Decide ¶
func (s *Service) Decide(ctx context.Context, ws *store.Workspace, p *authz.Principal, requestID uuid.UUID, in ApprovalDecisionInput) (uuid.UUID, error)
Decide records an approver's decision. Approving an invalidated request approves the campaign as it stands now (a new request with the diff).
func (*Service) Detail ¶
func (s *Service) Detail(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (ApprovalDetail, error)
Detail returns a request for its review screen.
func (*Service) List ¶
func (s *Service) List(ctx context.Context, ws *store.Workspace, p *authz.Principal, f ListParams) (ApprovalList, error)
List returns the approval inbox: approvers see every request, others their own.
func (*Service) PolicyView ¶
func (s *Service) PolicyView(ctx context.Context, ws *store.Workspace, p *authz.Principal) (ApprovalPolicyView, error)
PolicyView returns the approval policy with what it matches today.
func (*Service) Preview ¶
func (s *Service) Preview(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID) (ApprovalPreview, error)
Preview renders the version a request covers with the personalization fallbacks ("there" for an empty first name).
func (*Service) PreviewIn ¶
func (s *Service) PreviewIn(ctx context.Context, ws *store.Workspace, p *authz.Principal, id uuid.UUID, lang string) (ApprovalPreview, error)
PreviewIn renders one language version a request covers ("" is the source).
func (*Service) Remind ¶
func (s *Service) Remind(ctx context.Context, ws *store.Workspace, p *authz.Principal, requestID uuid.UUID) error
Remind notifies the approvers of a pending request again.
func (*Service) RequestApproval ¶
func (s *Service) RequestApproval(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID, in ApprovalRequestInput) (uuid.UUID, error)
RequestApproval asks the workspace's approvers to approve a send.
func (*Service) RequestForIssue ¶
func (s *Service) RequestForIssue(ctx context.Context, ws *store.Workspace, ownerID, campaignID uuid.UUID, in IssueRequest) (uuid.UUID, error)
RequestForIssue asks the approvers to approve a digest issue, in its owner's name. It returns uuid.Nil when no rule matches (the issue needs no approval) and ErrNoApprovers when only the owner could approve it.
func (*Service) RequestTemplateApproval ¶
func (s *Service) RequestTemplateApproval(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string, in TransactionalApprovalInput) (TransactionalApprovalState, error)
RequestTemplateApproval asks the approvers to approve publishing the draft as it is now. A pending request for an older draft is replaced.
func (*Service) Reschedule ¶
func (s *Service) Reschedule(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID, in readiness.ReadinessSchedule) error
Reschedule moves a scheduled campaign to another time (review 2026-11 CA-3, the calendar's drag and its Reschedule button). Send Readiness checks an email again before it goes out, as any scheduled send; texts, push and WhatsApp are moved by their channel (CA-9). An approval covers its time, so an approved campaign goes back through approval instead.
func (*Service) Restore ¶
func (s *Service) Restore(ctx context.Context, ws *store.Workspace, p *authz.Principal, requestID uuid.UUID) error
Restore puts the campaign back as the snapshot had it (the version, the audience, the route and the schedule), which keeps the approval.
func (*Service) Revalidate ¶
func (s *Service) Revalidate(ctx context.Context, ws *store.Workspace, campaignID uuid.UUID) ([]ApprovalChange, error)
Revalidate compares the open request of a campaign with the campaign and invalidates it when anything it covers changed or the audience moved more than 10%. It returns the invalidated request's changes (none when valid).
func (*Service) Review ¶
func (s *Service) Review(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID) (CampaignReview, error)
Review builds the Review & send screen of a campaign. It re-checks the open approval first, so the screen never shows a stale approval.
func (*Service) SavePolicy ¶
func (s *Service) SavePolicy(ctx context.Context, ws *store.Workspace, p *authz.Principal, in ApprovalPolicy) (ApprovalPolicyView, error)
SavePolicy stores the approval policy.
func (*Service) ScheduleApproved ¶
func (s *Service) ScheduleApproved(ctx context.Context, ws *store.Workspace, p *authz.Principal, requestID uuid.UUID, in ReviewSendInput) (ReviewSendResult, error)
ScheduleApproved schedules an approved campaign, as approved (the snapshot's schedule). Its author can do it without campaigns:send.
func (*Service) Send ¶
func (s *Service) Send(ctx context.Context, ws *store.Workspace, p *authz.Principal, campaignID uuid.UUID, in ReviewSendInput) (ReviewSendResult, error)
Send schedules or starts a campaign for a member holding campaigns:send.
func (*Service) SendRecheck ¶
SendRecheck runs Send Readiness for a send that is starting (the run is recorded with the send_time trigger) and checks that the approval, when the send needed one, still covers the campaign. Unlike CheckSendTime it holds nothing and tells nobody: the sending engine does both when the verdict is Blocked, and the review page reads the blocks from this run.
func (*Service) TemplateApproval ¶
func (s *Service) TemplateApproval(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string) (TransactionalApprovalState, error)
TemplateApproval returns the approval state of a template's draft.
type Snapshot ¶
type Snapshot struct {
Version int `json:"version"`
ContentHash string `json:"content_hash"`
Subject string `json:"subject"`
Preheader string `json:"preheader"`
SenderID string `json:"sender_id,omitempty"`
From string `json:"from"`
// Links lists the email's links in order; Sections its section outline.
Links []string `json:"links"`
Sections []string `json:"sections"`
Audience json.RawMessage `json:"audience"`
AudienceLabels []string `json:"audience_labels"`
AudienceCount int64 `json:"audience_count"`
// AudienceBaseline is the audience counted the way revalidation counts
// it, at request time: the audience "moves" against this number.
AudienceBaseline int64 `json:"audience_baseline,omitempty"`
Suppressed int64 `json:"suppressed"`
Role int64 `json:"role"`
Bounced int64 `json:"bounced"`
Route []SnapshotShare `json:"route"`
RouteKey string `json:"route_key"`
SplitLabel string `json:"split_label"`
Minutes int `json:"minutes"`
Cost float64 `json:"cost"`
Schedule json.RawMessage `json:"schedule"`
Thresholds readiness.ReadinessThresholds `json:"thresholds"`
Readiness SnapshotReadiness `json:"readiness"`
Rules []ApprovalRuleMatch `json:"rules"`
// RuleTexts keeps the matched rules' messages for later readers, by
// rule key (filled from Rules when the snapshot is stored).
RuleTexts map[string]ruleTexts `json:"rule_texts,omitempty"`
// AuthorRole is the requester's role ("Content Writer").
AuthorRole string `json:"author_role"`
Automation *ApprovalAutomationSnapshot `json:"automation,omitempty"`
// AutomationItems keep Automation.Changes' kinds and titles as messages
// for later readers (requests made before have none).
AutomationItems []automationItem `json:"automation_items,omitempty"`
// Languages are the language versions the approval covers.
Languages []languages.VersionSnapshot `json:"languages,omitempty"`
// DraftHash and Transactional: what a transactional template publish
// request covers (one draft of the template).
DraftHash string `json:"draft_hash,omitempty"`
Transactional *ApprovalTransactionalSnapshot `json:"transactional,omitempty"`
// Website: what a post publish request covers (DraftHash is the post's hash).
Website *ApprovalWebsiteSnapshot `json:"website,omitempty"`
// Channel campaigns (SMS; push and WhatsApp later) cover their text and
// a schedule written for people, compared as they are.
Channel string `json:"channel,omitempty"`
Text string `json:"text,omitempty"`
ScheduleLabel string `json:"schedule_label,omitempty"`
// ScheduleText is the label's message, read in each reader's language;
// requests compare the English label.
ScheduleText i18n.Text `json:"schedule_text,omitzero"`
// SMS is what an SMS campaign's approval shows: the text as sent, its
// segments, the senders and the cost per country.
SMS *ApprovalSMSSnapshot `json:"sms,omitempty"`
// Page: what a page publish request covers (DraftHash is the page's hash).
Page *ApprovalPageSnapshot `json:"page,omitempty"`
// Push and WhatsApp are what push and WhatsApp campaigns' approvals
// show: the notification, or the template with its variables (X22).
Push *ApprovalPushSnapshot `json:"push,omitempty"`
WhatsApp *ApprovalWhatsAppSnapshot `json:"whatsapp,omitempty"`
}
Snapshot is what an approval covers (approval_requests.snapshot): the content and subject, the audience definition and count, the route and the schedule, with the readiness result and estimates it was given on.
func ParseSnapshot ¶
func ParseSnapshot(raw json.RawMessage) Snapshot
ParseSnapshot reads a stored snapshot. Its rules carry their kept messages, so they read in each reader's language (localRules).
func (Snapshot) MarshalJSON ¶
MarshalJSON stores the snapshot with its rules' messages (RuleTexts).
type SnapshotReadiness ¶
type SnapshotReadiness struct {
RunID string `json:"run_id"`
Verdict string `json:"verdict"`
Passed int `json:"passed"`
Warnings int `json:"warnings"`
Blocks int `json:"blocks"`
Total int `json:"total"`
RanAt time.Time `json:"ran_at"`
Issues []readiness.ReadinessCheck `json:"issues"`
}
SnapshotReadiness is the Send Readiness result an approval was given on.
type SnapshotShare ¶
type SnapshotShare struct {
// it in each reader's language.
StatusText readiness.Text `json:"status_text,omitempty"`
}
SnapshotShare is one provider of the route at request time.
type TemplateApprovalPath ¶
type TemplateApprovalPath struct {
api.WorkspaceInput
Template string `path:"template" maxLength:"64" doc:"The template's ID or UUID"`
}
type TickArgs ¶
type TickArgs struct{}
TickArgs is the minute job of Review & send: checks run again 15 minutes before scheduled sends, held sends are rechecked and resumed when a recheck passes, and open approvals are re-checked for audience drift.
func (TickArgs) InsertOpts ¶
func (TickArgs) InsertOpts() river.InsertOpts
InsertOpts implements river.JobArgsWithInsertOpts.
type TickWorker ¶
type TickWorker struct {
river.WorkerDefaults[TickArgs]
S *Service
}
type TransactionalApprovalInput ¶
type TransactionalApprovalInput struct {
Note string `json:"note,omitempty" maxLength:"1000" doc:"Shown to the approvers"`
}
TransactionalApprovalInput asks for approval to publish a template's draft.
type TransactionalApprovalState ¶
type TransactionalApprovalState struct {
// Required is true when the workspace's rule is on.
Required bool `json:"required"`
Approvers []string `json:"approvers"`
// Status of the latest request: none, pending, approved,
// changes_requested or rejected.
Status string `json:"status" enum:"none,pending,approved,changes_requested,rejected"`
// CoversDraft is true when that request is about the draft as it is.
CoversDraft bool `json:"coversDraft"`
RequestID string `json:"requestId,omitempty"`
RequestedBy string `json:"requestedBy,omitempty"`
RequestedAt *time.Time `json:"requestedAt,omitempty"`
DecidedBy string `json:"decidedBy,omitempty"`
DecidedAt *time.Time `json:"decidedAt,omitempty"`
Note string `json:"note,omitempty"`
// Comment is the approver's last comment (changes requested, rejected).
Comment string `json:"comment,omitempty"`
// CanRequest is true for a person who can publish while the rule is on.
CanRequest bool `json:"canRequest"`
RequestReason string `json:"requestReason,omitempty"`
}
TransactionalApprovalState is the approval side of a template's publish dialog.
type TransactionalGate ¶
type TransactionalGate struct{ S *Service }
TransactionalGate implements transactional.PublishGate with the rule.
func (TransactionalGate) Check ¶
func (g TransactionalGate) Check(ctx context.Context, q *store.Queries, req transactional.PublishRequest) (transactional.PublishDecision, error)
Check implements transactional.PublishGate.
func (TransactionalGate) Published ¶
func (g TransactionalGate) Published(ctx context.Context, q *store.Queries, req transactional.PublishRequest, version int) error
Published implements transactional.PublishGate: the approval a publish relied on remembers the version it made live.
type TransactionalTemplates ¶
type TransactionalTemplates interface {
Template(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string) (transactional.TransactionalTemplate, error)
PublishPreview(ctx context.Context, ws *store.Workspace, p *authz.Principal, ref string, in transactional.TransactionalPublishPreviewInput) (transactional.TransactionalPublishPreview, error)
}
TransactionalTemplates is the part of the transactional service the approval request needs.
type WebsiteGate ¶
type WebsiteGate struct{ S *Service }
WebsiteGate implements website.Approvals with the workspace's rules.
func (WebsiteGate) PostChanged ¶
func (g WebsiteGate) PostChanged(ctx context.Context, ws *store.Workspace, p *authz.Principal, postID uuid.UUID, title, hash string) error
PostChanged implements website.Approvals: requests for the post as it was are invalidated, and their authors told.
func (WebsiteGate) PostDecision ¶
func (g WebsiteGate) PostDecision(ctx context.Context, ws *store.Workspace, p *authz.Principal, req website.PostApprovalRequest) (website.PostApprovalDecision, error)
PostDecision implements website.Approvals.
func (WebsiteGate) PostPublished ¶
func (g WebsiteGate) PostPublished(ctx context.Context, ws *store.Workspace, postID uuid.UUID, hash string) error
PostPublished implements website.Approvals: the approved request a publish relied on remembers it went out.
func (WebsiteGate) RequestPost ¶
func (g WebsiteGate) RequestPost(ctx context.Context, ws *store.Workspace, p *authz.Principal, req website.PostApprovalRequest, note string) (uuid.UUID, error)
RequestPost implements website.Approvals: it asks the approvers to approve publishing the post as it is. A pending request for an older version is replaced.
type WebsitePosts ¶
type WebsitePosts interface {
PublishApproved(ctx context.Context, ws *store.Workspace, postID uuid.UUID, approvalID string, approverName string) error
}
WebsitePosts is the part of the website the approvals need: publishing a post once it is approved, and its web preview for the review.