@sdxc/mail 2026.10.17 → 2026.10.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/define.d.ts DELETED
@@ -1,61 +0,0 @@
1
- /**
2
- * `defineEmail()`: an email declared as its props, a subject and a body component, from
3
- * which the package builds the class the mailer sends. Every email built this way is its own
4
- * class, so a test still finds a sent message with `instanceof`.
5
- *
6
- * @author [Sergio Xalambrí](https://sergiodxa.com)
7
- * @copyright Sergio Xalambrí 2026
8
- */
9
- import type { Handle, RemixNode } from "remix/component";
10
- import type { Address, CalendarPart, Email, MailingList, Unsubscribe } from "./types.js";
11
- /**
12
- * What an email says and looks like, written once per kind of email. Every member reads the
13
- * props one instance was built with, so the subject and the body never disagree.
14
- *
15
- * @template Props - The data one email is built from, already translated for its reader.
16
- */
17
- export interface EmailDefinition<Props extends object> {
18
- /** Subject line, already in the reader's language. */
19
- subject(props: Props): string;
20
- /** Body component, rendered by the mailer into the HTML and plain-text parts. */
21
- body: (handle: Handle<Props>) => () => RemixNode;
22
- /** Per-email reply-to; the mailer's configuration supplies the default. */
23
- replyTo?(props: Props): Address | Address[] | undefined;
24
- /** Per-email headers, merged over the mailer's configured headers. */
25
- headers?(props: Props): Record<string, string> | undefined;
26
- /** One-click unsubscribe for optional mail, built per reader since its URL names them. */
27
- unsubscribe?(props: Props): Unsubscribe | undefined;
28
- /** List the email belongs to, written as `List-Id`. */
29
- list?(props: Props): MailingList | undefined;
30
- /** A calendar object, such as an invitation, sent alongside the rendered body. */
31
- calendar?(props: Props): CalendarPart | undefined;
32
- }
33
- /**
34
- * One email built by a {@link defineEmail} class, ready for `send()` or `later()`.
35
- *
36
- * @template Props - The data the email was built from.
37
- */
38
- export interface DefinedEmail<Props extends object> extends Email {
39
- /** Recipients, normalized to addresses from whatever form the constructor received. */
40
- readonly to: Address | Address[];
41
- /** The data the email was built from, so a test can assert on what a caller passed. */
42
- readonly props: Props;
43
- }
44
- /**
45
- * The class `defineEmail()` returns. A bare string recipient is the mailbox alone, the
46
- * common case of mailing the address a record holds.
47
- *
48
- * @template Props - The data one email is built from.
49
- */
50
- export interface EmailClass<Props extends object> {
51
- new (to: string | Address | Address[], props: Props): DefinedEmail<Props>;
52
- }
53
- /**
54
- * Builds an email class from its subject and body, so an email is its props and its markup.
55
- *
56
- * @param definition - The subject, the body component and any per-email delivery options.
57
- * @returns A class constructed with the recipient and the props, sendable by any mailer.
58
- * @example export const WelcomeEmail = defineEmail<WelcomeEmail.Props>({ subject: (props) => props.heading, body: WelcomeBody });
59
- * @example await mailer.send(new WelcomeEmail("ada@example.com", { heading: "Welcome" }));
60
- */
61
- export declare function defineEmail<Props extends object>(definition: EmailDefinition<Props>): EmailClass<Props>;
package/dist/define.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * `defineEmail()`: an email declared as its props, a subject and a body component, from
3
- * which the package builds the class the mailer sends. Every email built this way is its own
4
- * class, so a test still finds a sent message with `instanceof`.
5
- *
6
- * @author [Sergio Xalambrí](https://sergiodxa.com)
7
- * @copyright Sergio Xalambrí 2026
8
- */
9
- import { createElement } from "remix/component";
10
- /**
11
- * Builds an email class from its subject and body, so an email is its props and its markup.
12
- *
13
- * @param definition - The subject, the body component and any per-email delivery options.
14
- * @returns A class constructed with the recipient and the props, sendable by any mailer.
15
- * @example export const WelcomeEmail = defineEmail<WelcomeEmail.Props>({ subject: (props) => props.heading, body: WelcomeBody });
16
- * @example await mailer.send(new WelcomeEmail("ada@example.com", { heading: "Welcome" }));
17
- */
18
- export function defineEmail(definition) {
19
- return class {
20
- to;
21
- props;
22
- constructor(to, props) {
23
- this.to = typeof to === "string" ? { email: to } : to;
24
- this.props = props;
25
- }
26
- get subject() {
27
- return definition.subject(this.props);
28
- }
29
- get replyTo() {
30
- return definition.replyTo?.(this.props);
31
- }
32
- get headers() {
33
- return definition.headers?.(this.props);
34
- }
35
- get unsubscribe() {
36
- return definition.unsubscribe?.(this.props);
37
- }
38
- get list() {
39
- return definition.list?.(this.props);
40
- }
41
- get calendar() {
42
- return definition.calendar?.(this.props);
43
- }
44
- body() {
45
- return createElement(definition.body, this.props);
46
- }
47
- };
48
- }