@veloxts/mail 0.6.55 → 0.6.57

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/index.d.ts CHANGED
@@ -64,3 +64,25 @@ export { createResendTransport, DRIVER_NAME as RESEND_DRIVER } from './transport
64
64
  export { createSmtpTransport, DRIVER_NAME as SMTP_DRIVER } from './transports/smtp.js';
65
65
  export type { Attachment, EmailAddress, LogConfig, MailConfig, MailDefinitionConfig, MailDriver, MailEnvelope, MailPluginOptions, MailTransport, Recipient, RenderedMail, ResendConfig, SendMailOptions, SendResult, SmtpConfig, } from './types.js';
66
66
  export { escapeHtml, formatAddress, isValidEmail, normalizeRecipient, normalizeRecipients, sanitizeHeaderValue, stripHtml, validateRecipient, validateRecipients, validateTemplateName, } from './utils.js';
67
+ /**
68
+ * DI tokens and providers for @veloxts/mail
69
+ *
70
+ * Use these to integrate mail services with the @veloxts/core DI container.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * import { Container } from '@veloxts/core';
75
+ * import { registerMailProviders, MAIL_MANAGER } from '@veloxts/mail';
76
+ *
77
+ * const container = new Container();
78
+ * await registerMailProviders(container, {
79
+ * driver: 'log',
80
+ * from: { email: 'test@example.com' },
81
+ * });
82
+ *
83
+ * const mail = container.resolve(MAIL_MANAGER);
84
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
85
+ * ```
86
+ */
87
+ export { registerMailProviders } from './providers.js';
88
+ export { MAIL_CONFIG, MAIL_MANAGER, MAIL_TRANSPORT } from './tokens.js';
package/dist/index.js CHANGED
@@ -68,3 +68,30 @@ export { createResendTransport, DRIVER_NAME as RESEND_DRIVER } from './transport
68
68
  export { createSmtpTransport, DRIVER_NAME as SMTP_DRIVER } from './transports/smtp.js';
69
69
  // Utilities
70
70
  export { escapeHtml, formatAddress, isValidEmail, normalizeRecipient, normalizeRecipients, sanitizeHeaderValue, stripHtml, validateRecipient, validateRecipients, validateTemplateName, } from './utils.js';
71
+ // ============================================================================
72
+ // Dependency Injection
73
+ // ============================================================================
74
+ /**
75
+ * DI tokens and providers for @veloxts/mail
76
+ *
77
+ * Use these to integrate mail services with the @veloxts/core DI container.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * import { Container } from '@veloxts/core';
82
+ * import { registerMailProviders, MAIL_MANAGER } from '@veloxts/mail';
83
+ *
84
+ * const container = new Container();
85
+ * await registerMailProviders(container, {
86
+ * driver: 'log',
87
+ * from: { email: 'test@example.com' },
88
+ * });
89
+ *
90
+ * const mail = container.resolve(MAIL_MANAGER);
91
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
92
+ * ```
93
+ */
94
+ // Provider exports - factory functions for registering services
95
+ export { registerMailProviders } from './providers.js';
96
+ // Token exports - unique identifiers for DI resolution
97
+ export { MAIL_CONFIG, MAIL_MANAGER, MAIL_TRANSPORT } from './tokens.js';
@@ -0,0 +1,64 @@
1
+ /**
2
+ * DI Providers for @veloxts/mail
3
+ *
4
+ * Factory provider functions for registering mail services with the DI container.
5
+ * These providers allow services to be managed by the container for testability and flexibility.
6
+ *
7
+ * @module mail/providers
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { registerMailProviders, MAIL_MANAGER } from '@veloxts/mail';
13
+ *
14
+ * const container = new Container();
15
+ * await registerMailProviders(container, { driver: 'log' });
16
+ *
17
+ * const mail = container.resolve(MAIL_MANAGER);
18
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
19
+ * ```
20
+ */
21
+ import type { Container } from '@veloxts/core';
22
+ import type { MailPluginOptions } from './types.js';
23
+ /**
24
+ * Registers mail providers with a container
25
+ *
26
+ * This handles async initialization of the mail manager and registers
27
+ * the resolved instance directly for synchronous resolution.
28
+ *
29
+ * @param container - The DI container to register providers with
30
+ * @param config - Mail plugin options (driver, from, etc.)
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import { Container } from '@veloxts/core';
35
+ * import { registerMailProviders, MAIL_MANAGER } from '@veloxts/mail';
36
+ *
37
+ * const container = new Container();
38
+ *
39
+ * // Log driver (development)
40
+ * await registerMailProviders(container, { driver: 'log' });
41
+ *
42
+ * // SMTP driver (production)
43
+ * await registerMailProviders(container, {
44
+ * driver: 'smtp',
45
+ * config: {
46
+ * host: 'smtp.example.com',
47
+ * port: 587,
48
+ * auth: { user: '...', pass: '...' },
49
+ * },
50
+ * from: { email: 'hello@example.com', name: 'My App' },
51
+ * });
52
+ *
53
+ * // Resend driver (production)
54
+ * await registerMailProviders(container, {
55
+ * driver: 'resend',
56
+ * config: { apiKey: process.env.RESEND_API_KEY! },
57
+ * from: { email: 'hello@example.com', name: 'My App' },
58
+ * });
59
+ *
60
+ * const mail = container.resolve(MAIL_MANAGER);
61
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
62
+ * ```
63
+ */
64
+ export declare function registerMailProviders(container: Container, config?: MailPluginOptions): Promise<void>;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * DI Providers for @veloxts/mail
3
+ *
4
+ * Factory provider functions for registering mail services with the DI container.
5
+ * These providers allow services to be managed by the container for testability and flexibility.
6
+ *
7
+ * @module mail/providers
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { registerMailProviders, MAIL_MANAGER } from '@veloxts/mail';
13
+ *
14
+ * const container = new Container();
15
+ * await registerMailProviders(container, { driver: 'log' });
16
+ *
17
+ * const mail = container.resolve(MAIL_MANAGER);
18
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
19
+ * ```
20
+ */
21
+ import { createMailManager } from './manager.js';
22
+ import { MAIL_CONFIG, MAIL_MANAGER } from './tokens.js';
23
+ // ============================================================================
24
+ // Bulk Registration Helpers
25
+ // ============================================================================
26
+ /**
27
+ * Registers mail providers with a container
28
+ *
29
+ * This handles async initialization of the mail manager and registers
30
+ * the resolved instance directly for synchronous resolution.
31
+ *
32
+ * @param container - The DI container to register providers with
33
+ * @param config - Mail plugin options (driver, from, etc.)
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * import { Container } from '@veloxts/core';
38
+ * import { registerMailProviders, MAIL_MANAGER } from '@veloxts/mail';
39
+ *
40
+ * const container = new Container();
41
+ *
42
+ * // Log driver (development)
43
+ * await registerMailProviders(container, { driver: 'log' });
44
+ *
45
+ * // SMTP driver (production)
46
+ * await registerMailProviders(container, {
47
+ * driver: 'smtp',
48
+ * config: {
49
+ * host: 'smtp.example.com',
50
+ * port: 587,
51
+ * auth: { user: '...', pass: '...' },
52
+ * },
53
+ * from: { email: 'hello@example.com', name: 'My App' },
54
+ * });
55
+ *
56
+ * // Resend driver (production)
57
+ * await registerMailProviders(container, {
58
+ * driver: 'resend',
59
+ * config: { apiKey: process.env.RESEND_API_KEY! },
60
+ * from: { email: 'hello@example.com', name: 'My App' },
61
+ * });
62
+ *
63
+ * const mail = container.resolve(MAIL_MANAGER);
64
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
65
+ * ```
66
+ */
67
+ export async function registerMailProviders(container, config = {}) {
68
+ // Register config
69
+ container.register({
70
+ provide: MAIL_CONFIG,
71
+ useValue: config,
72
+ });
73
+ // Create mail manager (async operation)
74
+ const mailManager = await createMailManager(config);
75
+ // Register the resolved mail manager instance directly
76
+ // This allows synchronous resolution from the container
77
+ container.register({
78
+ provide: MAIL_MANAGER,
79
+ useValue: mailManager,
80
+ });
81
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * DI Tokens for @veloxts/mail
3
+ *
4
+ * Symbol-based tokens for type-safe dependency injection.
5
+ * These tokens allow mail services to be registered, resolved, and mocked via the DI container.
6
+ *
7
+ * @module mail/tokens
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { MAIL_MANAGER, registerMailProviders } from '@veloxts/mail';
13
+ *
14
+ * const container = new Container();
15
+ * await registerMailProviders(container, { driver: 'log' });
16
+ *
17
+ * const mail = container.resolve(MAIL_MANAGER);
18
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
19
+ * ```
20
+ */
21
+ import type { MailManager } from './manager.js';
22
+ import type { MailPluginOptions, MailTransport } from './types.js';
23
+ /**
24
+ * Mail manager token
25
+ *
26
+ * The main mail manager instance for sending and rendering emails.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const mail = container.resolve(MAIL_MANAGER);
31
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
32
+ * const rendered = await mail.render(WelcomeEmail, { to: 'user@example.com', data: {...} });
33
+ * ```
34
+ */
35
+ export declare const MAIL_MANAGER: import("@veloxts/core").SymbolToken<MailManager>;
36
+ /**
37
+ * Mail transport token
38
+ *
39
+ * The underlying mail transport driver (SMTP, Resend, or Log).
40
+ * Use MAIL_MANAGER for high-level operations; use this for direct transport access.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const transport = container.resolve(MAIL_TRANSPORT);
45
+ * await transport.send({ from: {...}, to: [...], subject: '...', html: '...' });
46
+ * ```
47
+ */
48
+ export declare const MAIL_TRANSPORT: import("@veloxts/core").SymbolToken<MailTransport>;
49
+ /**
50
+ * Mail configuration token
51
+ *
52
+ * Contains mail plugin options including driver and driver-specific config.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const config = container.resolve(MAIL_CONFIG);
57
+ * console.log(config.driver); // 'smtp', 'resend', or 'log'
58
+ * ```
59
+ */
60
+ export declare const MAIL_CONFIG: import("@veloxts/core").SymbolToken<MailPluginOptions>;
package/dist/tokens.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * DI Tokens for @veloxts/mail
3
+ *
4
+ * Symbol-based tokens for type-safe dependency injection.
5
+ * These tokens allow mail services to be registered, resolved, and mocked via the DI container.
6
+ *
7
+ * @module mail/tokens
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { MAIL_MANAGER, registerMailProviders } from '@veloxts/mail';
13
+ *
14
+ * const container = new Container();
15
+ * await registerMailProviders(container, { driver: 'log' });
16
+ *
17
+ * const mail = container.resolve(MAIL_MANAGER);
18
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
19
+ * ```
20
+ */
21
+ import { token } from '@veloxts/core';
22
+ // ============================================================================
23
+ // Core Mail Tokens
24
+ // ============================================================================
25
+ /**
26
+ * Mail manager token
27
+ *
28
+ * The main mail manager instance for sending and rendering emails.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const mail = container.resolve(MAIL_MANAGER);
33
+ * await mail.send(WelcomeEmail, { to: 'user@example.com', data: {...} });
34
+ * const rendered = await mail.render(WelcomeEmail, { to: 'user@example.com', data: {...} });
35
+ * ```
36
+ */
37
+ export const MAIL_MANAGER = token.symbol('MAIL_MANAGER');
38
+ /**
39
+ * Mail transport token
40
+ *
41
+ * The underlying mail transport driver (SMTP, Resend, or Log).
42
+ * Use MAIL_MANAGER for high-level operations; use this for direct transport access.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const transport = container.resolve(MAIL_TRANSPORT);
47
+ * await transport.send({ from: {...}, to: [...], subject: '...', html: '...' });
48
+ * ```
49
+ */
50
+ export const MAIL_TRANSPORT = token.symbol('MAIL_TRANSPORT');
51
+ // ============================================================================
52
+ // Configuration Tokens
53
+ // ============================================================================
54
+ /**
55
+ * Mail configuration token
56
+ *
57
+ * Contains mail plugin options including driver and driver-specific config.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const config = container.resolve(MAIL_CONFIG);
62
+ * console.log(config.driver); // 'smtp', 'resend', or 'log'
63
+ * ```
64
+ */
65
+ export const MAIL_CONFIG = token.symbol('MAIL_CONFIG');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/mail",
3
- "version": "0.6.55",
3
+ "version": "0.6.57",
4
4
  "description": "Email templating and sending for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "nodemailer": "6.10.1",
25
25
  "resend": "4.1.2",
26
26
  "zod": "3.24.4",
27
- "@veloxts/core": "0.6.55"
27
+ "@veloxts/core": "0.6.57"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@biomejs/biome": "2.0.0",
@@ -36,7 +36,7 @@
36
36
  "react": "19.2.3",
37
37
  "typescript": "5.8.3",
38
38
  "vitest": "4.0.16",
39
- "@veloxts/testing": "0.6.55"
39
+ "@veloxts/testing": "0.6.57"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "fastify": "^5.0.0",