refactor(domain): add FeedId, EmailAddress and Domain value objects

Encapsulate the email/domain/feed-id parsing that was scattered as ad-hoc
regexes and split("@") calls into three small immutable value objects under
src/domain/value-objects/. EmailParser.extractFeedId and generateFeedId now
delegate to FeedId; the sender policy, favicon domain extraction and the admin
SenderField parse through EmailAddress/Domain.

Left as-is on purpose: forwardemail's multi-address free-text extraction and the
admin allow/block list normaliser, which operate on mixed email-or-domain input
that the single-address value objects would reject.

Behaviour-preserving; adds unit tests for each value object.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Julien Herr
2026-05-24 00:05:46 +02:00
parent 8f036cf223
commit c65aabe7f4
11 changed files with 198 additions and 35 deletions
+2 -2
View File
@@ -1,10 +1,10 @@
import { EmailData } from "../types";
import { FeedId } from "../domain/value-objects/feed-id";
export class EmailParser {
// Matches noun1.noun2.XY (the feed ID format) before the @ symbol
static extractFeedId(emailAddress: string): string | null {
const match = emailAddress.match(/^([a-z]+\.[a-z]+\.\d{2})@/i);
return match ? match[1] : null;
return FeedId.parse(emailAddress)?.value ?? null;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any