app

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 172 Imported by: 0

Documentation

Overview

Package app wires configuration, the database, background jobs, the HTTP API and every domain package into one runnable process.

Index

Constants

View Source
const SourceGiftRedeem = "gift_redeem"

SourceGiftRedeem is the consent source of a redeemed gift.

Variables

This section is empty.

Functions

func ApprovalsTickAt

func ApprovalsTickAt(a *App, now time.Time) error

ApprovalsTickAt runs Review & send's minute job as if it were now: tests move the clock to a scheduled send's recheck, or past a held send's expiry.

func CampaignChangeHook

func CampaignChangeHook(a *App) campaigns.ChangeHook

CampaignChangeHook re-checks a campaign's open approval after the composer saved it (the composer's campaigns.Service.AfterChange).

func HeldSendCheck

func HeldSendCheck(a *App) func(ctx context.Context, workspaceID, campaignID uuid.UUID) error

HeldSendCheck is the send-time check the minute job runs for scheduled and held sends: it holds a send that turns Blocked or lost its approval (and tells people), and returns an error wrapping sending.ErrNotReady.

func NewHumaConfig

func NewHumaConfig() huma.Config

NewHumaConfig returns the OpenAPI configuration shared by the server and the `reputecast openapi` command.

func ReadinessQueue

func ReadinessQueue(ctx context.Context, a *App) (int, error)

ReadinessQueue works the Send Readiness runs waiting in the job queue, in this process: tests (whose app runs no workers) call it after asking for a run. It returns how many it worked.

func RegisterOperations

func RegisterOperations(h huma.API)

RegisterOperations registers every operation on h without a database, for generating the OpenAPI document. Handlers are never called.

func SecretBox

func SecretBox(cfg *config.Config, log *slog.Logger) (*secrets.Box, error)

SecretBox loads the encryption key (from config or the key file) and returns the box that seals secrets at rest.

func SendRecheck

func SendRecheck(a *App) func(ctx context.Context, campaignID uuid.UUID) (approvals.SendRecheck, error)

SendRecheck is the recheck the sending engine runs as a send starts (its sending.Readiness, via readinessRecheck): Send Readiness again, and the approval must still cover the campaign. It records nothing; the engine holds the send when the verdict is Blocked.

Types

type App

type App struct {
	Cfg     *config.Config
	Log     *slog.Logger
	Pool    *pgxpool.Pool
	Q       *store.Queries
	Secrets *secrets.Box
	Audit   *audit.Logger
	Jobs    *jobs.Client
	JobReg  *jobs.Registry
	Auth    *api.Authenticator
	Metrics *prometheus.Registry
	// Mail sends system mail through the System-stream provider.
	Mail mailer.Sender
	// Sending starts, pauses, resumes and cancels campaign sends; set by the
	// sending domain's start hook.
	Sending sending.Starter
	// Links signs open, click, unsubscribe and preference tokens in emails.
	Links *linktoken.Signer
	// Counts keeps the slow audience counts that read every contact for a
	// minute (review 2026-11 OP-12); audited contact changes drop a
	// workspace's.
	Counts *countcache.Cache
	// Now is the clock of the services that read it (texting); nil is the
	// wall clock. Tests that seed the sample at a fixed moment set it.
	Now func() time.Time
	// URLs builds public links (tracking, unsubscribe, preferences, archive,
	// shared reports, provider webhooks) on the instance's public URL.
	URLs publicurl.Builder
	// PublicURL is that URL: the saved instance setting, else http.public_url
	// (see wire_publicurl.go).
	PublicURL *publicurl.Source
	// contains filtered or unexported fields
}

App holds the shared dependencies every domain uses.

func New

func New(ctx context.Context, cfg *config.Config, log *slog.Logger) (*App, error)

New connects to the database and builds every dependency. It does not start listeners or workers; see Run.

func (*App) Audience

func (a *App) Audience() *audience.Service

Audience is the audience service (tests and tools reach it here).

func (*App) Close

func (a *App) Close()

Close releases the database pool.

func (*App) Commerce

func (a *App) Commerce() *commerce.Service

Commerce is the stores' domain (tests set its clock and its stores).

func (*App) CommunityRuntime

func (a *App) CommunityRuntime() *remote.Runtime

CommunityRuntime is the App's community adapter runtime (tests that change the configuration stop its sync loop first).

func (*App) Digests

func (a *App) Digests() *digests.Service

Digests returns the App's digests service (tests drive its jobs).

func (*App) Earn

func (a *App) Earn() *earn.Service

Earn is the Earn domain (tests set its clock and its Stripe).

func (*App) Gifts

func (a *App) Gifts() *gifts.Service

Gifts is the gifts domain (tests set its clock).

func (*App) Handler

func (a *App) Handler() http.Handler

Handler builds the full HTTP handler for the configured roles.

func (*App) InvalidatePolicy

func (a *App) InvalidatePolicy()

InvalidatePolicy drops the cached authentication policy after a change.

func (*App) Offers

func (a *App) Offers() *offers.Service

Offers is the offers domain (tests set its clock).

func (*App) Pages

func (a *App) Pages() *pages.Service

Pages is the pages domain (tests set its clock).

func (*App) Products

func (a *App) Products() *products.Service

Products is the products domain (tests set its clock).

func (*App) ProxyDetector

func (a *App) ProxyDetector() *proxycheck.Detector

ProxyDetector returns the App's untrusted proxy detector (tests flush it).

func (*App) Push

func (a *App) Push() *push.Service

Push is the web push domain.

func (*App) PushFake

func (a *App) PushFake() *webpushtest.Service

PushFake is the in-process push service the demo's subscriptions (and tests) are sent to: nothing reaches FCM, Mozilla, Apple or Windows.

func (*App) Revenue

func (a *App) Revenue() *revenue.Service

Revenue is Earn's revenue and attribution (tests set its clock).

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run serves HTTP (web/ingest roles) and runs workers (worker role) until ctx ends.

func (*App) RunSMTPRelay

func (a *App) RunSMTPRelay(ctx context.Context) error

RunSMTPRelay runs the SMTP relay's listeners until ctx ends, in processes with the web role (the relay is an API surface, like the HTTP API). It returns once the listeners stopped gracefully.

func (*App) SMTPRelay

func (a *App) SMTPRelay() *smtprelay.Relay

SMTPRelay is the App's SMTP relay (tests drive it).

func (*App) Scoring

func (a *App) Scoring() *scoring.Service

Scoring is the scoring domain (tests set its clock).

func (*App) SendingEngine

func (a *App) SendingEngine() *engine.Engine

SendingEngine returns the App's sending engine (the demo command drives it).

func (*App) Sponsors

func (a *App) Sponsors() *sponsors.Service

Sponsors is the sponsorships domain (tests set its clock).

func (*App) Transactional

func (a *App) Transactional() *transactional.Service

Transactional is the transactional domain (tests set its clock).

func (*App) TransactionalOutbox

func (a *App) TransactionalOutbox() *engine.TransactionalOutbox

TransactionalOutbox is the sending engine's transactional outbox (tests drive it with Step).

func (*App) Website

func (a *App) Website() *website.Service

Website is the website domain (tests set its clock).

func (*App) WhatsApp

func (a *App) WhatsApp() *whatsapp.Service

WhatsApp is the WhatsApp domain.

func (*App) WhatsAppFake

func (a *App) WhatsAppFake() *metatest.Fake

WhatsAppFake is the in-process Graph API the demo's account (and tests) answer from: nothing reaches Meta.

Jump to

Keyboard shortcuts

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