feat(notification): add durable mail delivery state

This commit is contained in:
shira committed 2026-10-06 10:52:47 +03:00
1 parent 391c8a6cec
commit 2db585fbff
41 files changed
+4903 -108

No files matched your search

@@ -1,7 +1,6 @@
package mailtemplate
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"log/slog"
@@ -15,7 +14,7 @@ import (
// the same digest, and any change to any part gives another one. The delivery
// layer can store it with the idempotency key to pin the body of one logical
// delivery and to detect a different body offered under the same key.
type ContentHash [sha256.Size]byte
type ContentHash [domain.MailContentHashSize]byte
// String returns the lowercase hex digest. It is not secret: SHA-256 over a
// body that holds a 256-bit token cannot be reversed.
@@ -50,7 +49,7 @@ func newRenderedMail(kind Kind, version TemplateVersion, subject, text, html str
subject: subject,
text: text,
html: html,
contentHash: contentHash(string(version), subject, text, html),
contentHash: ContentHash(domain.MailContentHash(string(version), subject, text, html)),
}}
}
@@ -78,6 +77,18 @@ func (mail RenderedMail) read() renderedContent {
return *mail.content
}
// Content returns the rendering as domain.MailContent, the form a delivery
// stores. The kinds and the hash are the same: both use
// domain.MailContentHash.
func (mail RenderedMail) Content() (domain.MailContent, error) {
content := mail.read()
stored, err := domain.NewMailContent(domain.MailKind(content.kind), string(content.version), content.subject, content.text, content.html)
if err != nil {
return domain.MailContent{}, fmt.Errorf("RenderedMail.Content - %w", err)
}
return stored, nil
}
// ToOutgoingMail addresses the rendering for the MailSender port. The
// recipient and the idempotency key come from the delivery, never from the
// template data.