@shipfox/node-mailer 0.1.0

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.
@@ -0,0 +1,2 @@
1
+ $ shipfox-swc
2
+ Successfully compiled: 4 files with swc (24.74ms)
@@ -0,0 +1 @@
1
+ $ shipfox-tsc-emit
@@ -0,0 +1,2 @@
1
+
2
+ $ shipfox-tsc-check
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shipfox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Shipfox Mailer
2
+
3
+ Small mailer interface for Shipfox Node packages. It supports SMTP delivery for production and a console mailer for local development and tests.
4
+
5
+ ## What it does
6
+
7
+ - **`Mailer`**: Interface with one `send(message)` method.
8
+ - **`MailMessage`**: Message shape with `to`, `subject`, `text`, and optional `html`.
9
+ - **`createConsoleMailer(options)`**: Logs mail through the Shipfox logger and can capture messages in an array.
10
+ - **`createSmtpMailer(options)`**: Sends mail through `nodemailer`.
11
+
12
+ ## Usage
13
+
14
+ ```ts
15
+ import {createConsoleMailer, createSmtpMailer, type Mailer} from '@shipfox/node-mailer';
16
+
17
+ const mailer: Mailer =
18
+ process.env.MAILER_TRANSPORT === 'smtp'
19
+ ? createSmtpMailer({
20
+ host: 'smtp.example.com',
21
+ port: 587,
22
+ user: process.env.SMTP_USER,
23
+ password: process.env.SMTP_PASSWORD,
24
+ from: 'noreply@shipfox.local',
25
+ })
26
+ : createConsoleMailer({from: 'noreply@shipfox.local'});
27
+
28
+ await mailer.send({
29
+ to: 'user@example.com',
30
+ subject: 'Verify your email',
31
+ text: 'Open this link to verify your email.',
32
+ });
33
+ ```
34
+
35
+ ## Notes
36
+
37
+ - SMTP uses `secure: true` by default on port `465`.
38
+ - SMTP auth is only sent when both `user` and `password` are set.
39
+ - The console mailer is useful in tests because `capture` stores each message.
40
+
41
+ ## Development
42
+
43
+ ```sh
44
+ turbo check --filter=@shipfox/node-mailer
45
+ turbo type --filter=@shipfox/node-mailer
46
+ turbo test --filter=@shipfox/node-mailer
47
+ ```
48
+
49
+ ## License
50
+
51
+ MIT
@@ -0,0 +1,7 @@
1
+ import type { Mailer, MailMessage } from './mailer.js';
2
+ export interface ConsoleMailerOptions {
3
+ from: string;
4
+ capture?: MailMessage[];
5
+ }
6
+ export declare function createConsoleMailer(options: ConsoleMailerOptions): Mailer;
7
+ //# sourceMappingURL=console-mailer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-mailer.d.ts","sourceRoot":"","sources":["../src/console-mailer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,WAAW,EAAE,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAmBzE"}
@@ -0,0 +1,20 @@
1
+ import { logger } from '@shipfox/node-opentelemetry';
2
+ export function createConsoleMailer(options) {
3
+ const { from, capture } = options;
4
+ return {
5
+ send: (message)=>{
6
+ capture?.push(message);
7
+ logger().info({
8
+ mailer: 'console',
9
+ from,
10
+ to: message.to,
11
+ subject: message.subject,
12
+ text: message.text,
13
+ html: message.html
14
+ }, 'mailer.send');
15
+ return Promise.resolve();
16
+ }
17
+ };
18
+ }
19
+
20
+ //# sourceMappingURL=console-mailer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/console-mailer.ts"],"sourcesContent":["import {logger} from '@shipfox/node-opentelemetry';\nimport type {Mailer, MailMessage} from './mailer.js';\n\nexport interface ConsoleMailerOptions {\n from: string;\n capture?: MailMessage[];\n}\n\nexport function createConsoleMailer(options: ConsoleMailerOptions): Mailer {\n const {from, capture} = options;\n return {\n send: (message) => {\n capture?.push(message);\n logger().info(\n {\n mailer: 'console',\n from,\n to: message.to,\n subject: message.subject,\n text: message.text,\n html: message.html,\n },\n 'mailer.send',\n );\n return Promise.resolve();\n },\n };\n}\n"],"names":["logger","createConsoleMailer","options","from","capture","send","message","push","info","mailer","to","subject","text","html","Promise","resolve"],"mappings":"AAAA,SAAQA,MAAM,QAAO,8BAA8B;AAQnD,OAAO,SAASC,oBAAoBC,OAA6B;IAC/D,MAAM,EAACC,IAAI,EAAEC,OAAO,EAAC,GAAGF;IACxB,OAAO;QACLG,MAAM,CAACC;YACLF,SAASG,KAAKD;YACdN,SAASQ,IAAI,CACX;gBACEC,QAAQ;gBACRN;gBACAO,IAAIJ,QAAQI,EAAE;gBACdC,SAASL,QAAQK,OAAO;gBACxBC,MAAMN,QAAQM,IAAI;gBAClBC,MAAMP,QAAQO,IAAI;YACpB,GACA;YAEF,OAAOC,QAAQC,OAAO;QACxB;IACF;AACF"}
@@ -0,0 +1,4 @@
1
+ export { type ConsoleMailerOptions, createConsoleMailer } from './console-mailer.js';
2
+ export type { Mailer, MailMessage } from './mailer.js';
3
+ export { createSmtpMailer, type SmtpMailerOptions } from './smtp-mailer.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,oBAAoB,EAAE,mBAAmB,EAAC,MAAM,qBAAqB,CAAC;AACnF,YAAY,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,aAAa,CAAC;AACrD,OAAO,EAAC,gBAAgB,EAAE,KAAK,iBAAiB,EAAC,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { createConsoleMailer } from './console-mailer.js';
2
+ export { createSmtpMailer } from './smtp-mailer.js';
3
+
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {type ConsoleMailerOptions, createConsoleMailer} from './console-mailer.js';\nexport type {Mailer, MailMessage} from './mailer.js';\nexport {createSmtpMailer, type SmtpMailerOptions} from './smtp-mailer.js';\n"],"names":["createConsoleMailer","createSmtpMailer"],"mappings":"AAAA,SAAmCA,mBAAmB,QAAO,sBAAsB;AAEnF,SAAQC,gBAAgB,QAA+B,mBAAmB"}
@@ -0,0 +1,10 @@
1
+ export interface MailMessage {
2
+ to: string;
3
+ subject: string;
4
+ text: string;
5
+ html?: string;
6
+ }
7
+ export interface Mailer {
8
+ send(message: MailMessage): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=mailer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mailer.d.ts","sourceRoot":"","sources":["../src/mailer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
package/dist/mailer.js ADDED
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=mailer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mailer.ts"],"sourcesContent":["export interface MailMessage {\n to: string;\n subject: string;\n text: string;\n html?: string;\n}\n\nexport interface Mailer {\n send(message: MailMessage): Promise<void>;\n}\n"],"names":[],"mappings":"AAOA,WAEC"}
@@ -0,0 +1,11 @@
1
+ import type { Mailer } from './mailer.js';
2
+ export interface SmtpMailerOptions {
3
+ host: string;
4
+ port: number;
5
+ secure?: boolean;
6
+ user?: string;
7
+ password?: string;
8
+ from: string;
9
+ }
10
+ export declare function createSmtpMailer(options: SmtpMailerOptions): Mailer;
11
+ //# sourceMappingURL=smtp-mailer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smtp-mailer.d.ts","sourceRoot":"","sources":["../src/smtp-mailer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAoBnE"}
@@ -0,0 +1,26 @@
1
+ import nodemailer from 'nodemailer';
2
+ export function createSmtpMailer(options) {
3
+ const { host, port, secure, user, password, from } = options;
4
+ const transporter = nodemailer.createTransport({
5
+ host,
6
+ port,
7
+ secure: secure ?? port === 465,
8
+ auth: user && password ? {
9
+ user,
10
+ pass: password
11
+ } : undefined
12
+ });
13
+ return {
14
+ send: async (message)=>{
15
+ await transporter.sendMail({
16
+ from,
17
+ to: message.to,
18
+ subject: message.subject,
19
+ text: message.text,
20
+ html: message.html
21
+ });
22
+ }
23
+ };
24
+ }
25
+
26
+ //# sourceMappingURL=smtp-mailer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/smtp-mailer.ts"],"sourcesContent":["import nodemailer from 'nodemailer';\nimport type {Mailer} from './mailer.js';\n\nexport interface SmtpMailerOptions {\n host: string;\n port: number;\n secure?: boolean;\n user?: string;\n password?: string;\n from: string;\n}\n\nexport function createSmtpMailer(options: SmtpMailerOptions): Mailer {\n const {host, port, secure, user, password, from} = options;\n const transporter = nodemailer.createTransport({\n host,\n port,\n secure: secure ?? port === 465,\n auth: user && password ? {user, pass: password} : undefined,\n });\n\n return {\n send: async (message) => {\n await transporter.sendMail({\n from,\n to: message.to,\n subject: message.subject,\n text: message.text,\n html: message.html,\n });\n },\n };\n}\n"],"names":["nodemailer","createSmtpMailer","options","host","port","secure","user","password","from","transporter","createTransport","auth","pass","undefined","send","message","sendMail","to","subject","text","html"],"mappings":"AAAA,OAAOA,gBAAgB,aAAa;AAYpC,OAAO,SAASC,iBAAiBC,OAA0B;IACzD,MAAM,EAACC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,IAAI,EAAC,GAAGN;IACnD,MAAMO,cAAcT,WAAWU,eAAe,CAAC;QAC7CP;QACAC;QACAC,QAAQA,UAAUD,SAAS;QAC3BO,MAAML,QAAQC,WAAW;YAACD;YAAMM,MAAML;QAAQ,IAAIM;IACpD;IAEA,OAAO;QACLC,MAAM,OAAOC;YACX,MAAMN,YAAYO,QAAQ,CAAC;gBACzBR;gBACAS,IAAIF,QAAQE,EAAE;gBACdC,SAASH,QAAQG,OAAO;gBACxBC,MAAMJ,QAAQI,IAAI;gBAClBC,MAAML,QAAQK,IAAI;YACpB;QACF;IACF;AACF"}