feat(mail): send service identity mail through a leased worker

This commit is contained in:
shira committed 2026-10-06 21:08:11 +03:00
1 parent 204c6bae62
commit d21fd49a42
58 files changed
+7577 -164

No files matched your search

@@ -6,8 +6,13 @@
// DeliveryHandler consumes the event and, in the transaction of the
// consumer's dedup marker, reads the request, resolves the recipient address
// from the account, renders the current template version once, stores the
// Delivery, and deletes the request. Sending the stored content is the job
// of the delivery worker, which is planned.
// Delivery, and deletes the request. Sending notifications is planned
// (TASK-462); no worker claims them yet.
//
// Service mail of the account flows (email verification and password reset)
// takes a shorter path: ServiceMailer stores its delivery directly in the
// transaction that issues the token, bound to that token, and
// ServiceMailSender (service_sender.go) claims, checks, and sends it.
package notification
import (
@@ -51,6 +56,13 @@ type NotificationRenderer interface {
RenderNotification(data mailtemplate.NotificationData) (domain.MailContent, error)
}
// ServiceMailRenderer renders the service mail of the account flows, which
// carry a one-time token in their link, as the content a delivery stores.
type ServiceMailRenderer interface {
RenderVerification(data mailtemplate.VerificationData) (domain.MailContent, error)
RenderPasswordReset(data mailtemplate.PasswordResetData) (domain.MailContent, error)
}
// TemplateRenderer renders with the current versions of the embedded mail
// templates.
type TemplateRenderer struct {
@@ -73,6 +85,30 @@ func (renderer TemplateRenderer) RenderNotification(data mailtemplate.Notificati
return content, nil
}
func (renderer TemplateRenderer) RenderVerification(data mailtemplate.VerificationData) (domain.MailContent, error) {
rendered, err := renderer.renderer.RenderVerification(data)
if err != nil {
return domain.MailContent{}, fmt.Errorf("TemplateRenderer.RenderVerification - render: %w", err)
}
content, err := rendered.Content()
if err != nil {
return domain.MailContent{}, fmt.Errorf("TemplateRenderer.RenderVerification - convert rendering: %w", err)
}
return content, nil
}
func (renderer TemplateRenderer) RenderPasswordReset(data mailtemplate.PasswordResetData) (domain.MailContent, error) {
rendered, err := renderer.renderer.RenderPasswordReset(data)
if err != nil {
return domain.MailContent{}, fmt.Errorf("TemplateRenderer.RenderPasswordReset - render: %w", err)
}
content, err := rendered.Content()
if err != nil {
return domain.MailContent{}, fmt.Errorf("TemplateRenderer.RenderPasswordReset - convert rendering: %w", err)
}
return content, nil
}
// NotificationRequest asks for one notification mail to one account.
type NotificationRequest struct {
RecipientUserID uuid.UUID