rdev/internal/port/notify_provisioner.go
jordan ddcfe52b5c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
feat: implement shared notify host model for platform email delivery
Replace per-project notify host provisioning (7-9 API calls + DNS + async
Resend verification) with a shared platform host for all *.threesix.ai projects.

Under the new model:
- CreateProjectNotify: 3 calls only (account + send key + host grant)
- No per-project Resend domain, DNS records, or async verification
- All *.threesix.ai projects share `threesix.ai` as the platform host
- Custom domains still get a dedicated host via ReprovisionNotifyHost

Changes:
- domain/notify.go: slim NotifyCredentials (no Host/From/ResendDomainID);
  add NotifyHostCredentials for reprovision return path
- port/notify_provisioner.go: update interface signatures and docs
- adapter/notify/provisioner.go: rewrite CreateProjectNotify (3 steps);
  rewrite DeleteProjectNotify (account-only vs full cleanup)
- adapter/notify/provisioner_reprovision.go: return *NotifyHostCredentials
- adapter/notify/provisioner_test.go: update tests for new model
- service/project_infra_crud.go: store only NOTIFY_API_KEY on provision
- domain/credential.go: add CredKeyNotifySharedHost/CredKeyNotifySharedFrom
- cmd/rdev-api/config.go: add NotifySharedHost/NotifySharedFrom to InfraConfig
- service/component.go: add notifySharedHost/notifySharedFrom + WithNotifyDefaults
- service/component_deploy.go: inject shared host defaults when no custom host stored
- handlers/notify.go: handle shared-host projects in Reprovision guard;
  add WithSharedNotifyHost builder
- cmd/rdev-api/main.go: wire SharedHost to provisioner, component service,
  and notify handler

Bootstrap: NOTIFY_SHARED_HOST=threesix.ai and NOTIFY_SHARED_FROM=noreply@threesix.ai
stored in credential store (host id=1 already provisioned with Resend provider).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 17:04:11 -07:00

55 lines
3.1 KiB
Go

package port
import (
"context"
"github.com/orchard9/rdev/internal/domain"
)
// NotifyProvisioner manages per-project email delivery on the notify service.
// Under the shared-host model, default projects do not receive a dedicated sending
// host. Instead, a single pre-provisioned platform host (e.g., "mail.threesix.ai")
// is shared by all default projects. Per-project provisioning creates only an
// account, a send key, and a host grant (3 API calls). Custom domains still receive
// a dedicated host via ReprovisionNotifyHost.
type NotifyProvisioner interface {
// CreateProjectNotify creates a notify account, a send key, and grants the
// account access to the shared platform sending host. No per-project host,
// Resend domain, or DNS records are created for default projects.
CreateProjectNotify(ctx context.Context, projectID, slug string) (*domain.NotifyCredentials, error)
// DeleteProjectNotify removes notify resources for a project.
// The notify account (and all its keys) is always deleted.
// If perProjectHost is non-empty, the custom sending host, Resend domain
// (when resendDomainID is non-empty), and DNS records are also deleted.
// For default projects where perProjectHost is empty, only the account is deleted.
DeleteProjectNotify(ctx context.Context, projectID, perProjectHost, resendDomainID string) error
// GetProjectNotify returns notify credentials for a project, or nil if not provisioned.
// Only AccountID and CreatedAt are recoverable; use this solely to check whether
// provisioning has already occurred (non-nil return = already provisioned).
GetProjectNotify(ctx context.Context, projectID string) (*domain.NotifyCredentials, error)
// TestConnection verifies the admin API key and notify service are reachable.
TestConnection(ctx context.Context) error
// VerifyProjectNotify triggers Resend domain verification for the given resend domain ID.
// Should be called after DNS records have had time to propagate.
VerifyProjectNotify(ctx context.Context, projectID, resendDomainID string) error
// GetNotifyDomainStatus returns the Resend verification status for the project's email domain.
GetNotifyDomainStatus(ctx context.Context, host, resendDomainID string) (*domain.NotifyDomainStatus, error)
// ProvisionNotifyDomain creates the Resend domain for an existing notify host,
// adds DKIM/SPF DNS records, and starts async verification.
// Use this to repair projects where steps 7-9 of CreateProjectNotify failed.
// Returns the Resend domain ID for storage in the credential store.
ProvisionNotifyDomain(ctx context.Context, projectID, host string) (resendDomainID string, err error)
// ReprovisionNotifyHost migrates a project's notify setup to a new sending host.
// Tears down oldHost's notify host entry, Resend domain, and DNS records, then
// creates new ones for newHost. The project's account and send key are preserved.
// Returns host credentials (Host, From, ResendDomainID) for storage in the credential store.
ReprovisionNotifyHost(ctx context.Context, projectID, oldHost, oldResendDomainID, newHost string) (*domain.NotifyHostCredentials, error)
}