apiserver

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package apiserver builds the process HTTP handler: the typed Huma /v1 surface (internal/httpapi) wrapping the legacy gorilla/mux fallback.

It exists so the production binary (cmd/e2a) and the contract-test harness (internal/testutil) construct the SAME handler from the SAME dependency wiring. Before this, the contract harness served only the legacy mux, so it could not exercise /v1 at all and would silently drift from production. With one builder, a dep that production wires but the harness forgets shows up as a failing contract test, not a silent gap.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDeps

func BuildDeps(p Params) httpapi.Deps

BuildDeps maps Params into the httpapi dependency set. Kept as the single definition of the /v1 wiring so production and tests cannot diverge.

func New

func New(p Params) *httpapi.Server

New builds the process HTTP handler (chi root owning /v1, legacy fallback).

Types

type Params

type Params struct {
	API             *agent.API
	Store           *identity.Store
	Enforcer        *limits.DBEnforcer
	UsageStore      *usage.Store
	SubscriberStore *webhook.SubscriberStore
	Idempotency     *idempotency.Store
	Pool            *pgxpool.Pool

	SMTPDomain   string
	SharedDomain string
	PublicURL    string
	Production   bool

	// SESRegion is the SES sending-identity region (config
	// sender_identity.ses_region). Non-empty enables the sending feature, which
	// makes domainView emit the deterministic mail_from_* DNS records. Mirrors
	// the gate used to wire SenderIdentity below.
	SESRegion string

	// SigningSecret is the deployment HMAC secret (config.Signing.HMACSecret) —
	// used to mint/verify short-lived attachment download tokens (§6a #5), the
	// same primitive as the HITL magic-link. When empty, attachment endpoints
	// are left unwired.
	SigningSecret string

	// EventsEnabled mirrors the outbox's flag (now unconditional in production).
	// When false the webhook_events durable log is never written, so the events
	// list/get/redeliver endpoints return 501 events_log_disabled instead of an
	// empty result. Webhook delivery (River) is unaffected.
	EventsEnabled bool

	// Legacy is the gorilla/mux handler the chi root falls back to for any
	// route not on /v1. WSHandle serves the /v1 WebSocket upgrade.
	Legacy   http.Handler
	WSHandle func(w http.ResponseWriter, r *http.Request, address string)

	// SenderIdentity (decision 4 / Slice 4) schedules SES sending-identity
	// provisioning on domain verify and teardown on domain delete. Optional —
	// nil when SES is not configured (dev/self-host), leaving sending_status
	// at none and the relay From in place. *senderidentity.Manager satisfies it.
	SenderIdentity SenderIdentityEnqueuer

	// EnqueueDelivery enqueues a River webhook_deliver job for a
	// webhook_subscriber_deliveries row inserted directly by the /test endpoint
	// or the event-redelivery API (both bypass the outbox drain). River is the
	// sole delivery engine, so without this those rows would never deliver.
	// Wired from *webhookdelivery.Jobs.EnqueueDelivery in the binary. Optional —
	// nil in minimal test setups with no River client.
	EnqueueDelivery func(ctx context.Context, deliveryID string) error

	// AgentSuppressionAddedHook writes the beta suppression event in the same
	// transaction as any newly inserted agent suppression, whether it came from
	// authenticated management or a recipient token. Optional until the event
	// slice is wired by the caller.
	AgentSuppressionAddedHook identity.AgentSuppressionTxHook
	ManagedUnsubscribeIssuer  agent.ManagedUnsubscribeIssuer
}

Params bundles the already-constructed components the /v1 Deps closures bind to. Callers build these once (the binary for real, the harness for tests) and hand them over; the builder owns only the mapping into httpapi.Deps.

type SenderIdentityEnqueuer

type SenderIdentityEnqueuer interface {
	EnqueueProvision(ctx context.Context, domain string) error
	EnqueueDeprovisionTx(ctx context.Context, tx pgx.Tx, domain string) error
}

SenderIdentityEnqueuer is the slice of *senderidentity.Manager apiserver needs. Defined as an interface so apiserver does not hard-depend on the senderidentity package (River + AWS SDK) just to wire two optional deps.

Jump to

Keyboard shortcuts

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