ts-mailkit 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.
- package/LICENSE +21 -0
- package/README.md +264 -0
- package/dist/core/client.d.ts +128 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/errors.d.ts +34 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/types.d.ts +63 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/index.cjs +794 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +750 -0
- package/dist/index.js.map +1 -0
- package/dist/renderers/default/default-renderer.d.ts +36 -0
- package/dist/renderers/default/default-renderer.d.ts.map +1 -0
- package/dist/renderers/renderer.interface.d.ts +18 -0
- package/dist/renderers/renderer.interface.d.ts.map +1 -0
- package/dist/renderers/utils/html-to-plaintext.d.ts +10 -0
- package/dist/renderers/utils/html-to-plaintext.d.ts.map +1 -0
- package/dist/templates/dto/index.d.ts +99 -0
- package/dist/templates/dto/index.d.ts.map +1 -0
- package/dist/templates/factory.d.ts +60 -0
- package/dist/templates/factory.d.ts.map +1 -0
- package/dist/transports/console/console-sender.d.ts +26 -0
- package/dist/transports/console/console-sender.d.ts.map +1 -0
- package/dist/transports/memory/memory-sender.d.ts +29 -0
- package/dist/transports/memory/memory-sender.d.ts.map +1 -0
- package/dist/transports/sender.interface.d.ts +20 -0
- package/dist/transports/sender.interface.d.ts.map +1 -0
- package/dist/transports/zeptomail/types.d.ts +47 -0
- package/dist/transports/zeptomail/types.d.ts.map +1 -0
- package/dist/transports/zeptomail/zeptomail-sender.d.ts +27 -0
- package/dist/transports/zeptomail/zeptomail-sender.d.ts.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AD-RIAN Studio
|
|
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,264 @@
|
|
|
1
|
+
# ts-mailkit
|
|
2
|
+
|
|
3
|
+
Strictly typed, modular, and composable email composition and dispatch library for TypeScript and modern edge runtimes.
|
|
4
|
+
|
|
5
|
+
Works seamlessly in **Node.js**, **Cloudflare Workers** (`workerd`), **Bun**, **Deno**, **Next.js**, and **Vercel Edge Functions**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Type-Safe DTOs**: Strongly-typed Data Transfer Objects for transactional emails (verification, password reset, 2FA, magic links, newsletters).
|
|
12
|
+
- **Pluggable Transports (`IEmailSender`)**: Decoupled transport adapter interface with built-in senders:
|
|
13
|
+
- `ZeptoMailSender` (Zoho Mail transactional API via native `fetch`).
|
|
14
|
+
- `MemoryEmailSender` (In-memory mock transport for unit and integration testing).
|
|
15
|
+
- `ConsoleEmailSender` (Formatted terminal logger for local development).
|
|
16
|
+
- **Zero Runtime Dependencies**: Core uses standard web APIs (global `fetch`), ensuring zero heavy dependencies and complete edge compatibility.
|
|
17
|
+
- **Separation of Concerns**: Strict decoupling between:
|
|
18
|
+
1. DTO schema and validation.
|
|
19
|
+
2. Template building and responsive HTML rendering.
|
|
20
|
+
3. Dispatch via the chosen transport adapter.
|
|
21
|
+
- **Multitenant & Dynamic Branding**: Configure global branding or pass a dynamic brand name resolver for multi-tenant applications.
|
|
22
|
+
- **Dual ESM & CommonJS**: Full support for `import` and `require` with first-class TypeScript declaration maps.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Install using your preferred package manager:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# pnpm
|
|
32
|
+
pnpm add ts-mailkit
|
|
33
|
+
|
|
34
|
+
# npm
|
|
35
|
+
npm install ts-mailkit
|
|
36
|
+
|
|
37
|
+
# yarn
|
|
38
|
+
yarn add ts-mailkit
|
|
39
|
+
|
|
40
|
+
# bun
|
|
41
|
+
bun add ts-mailkit
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
### 1. Initialize Transport & Client
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { createMailKit, ZeptoMailSender, EmailTemplateFactory } from 'ts-mailkit';
|
|
52
|
+
|
|
53
|
+
// Configure the Zoho ZeptoMail HTTP transport
|
|
54
|
+
const transport = new ZeptoMailSender({
|
|
55
|
+
apiToken: process.env.ZEPTO_MAIL_TOKEN!,
|
|
56
|
+
apiHost: 'api.zeptomail.com', // or 'api.zeptomail.eu', 'api.zeptomail.in'
|
|
57
|
+
from: { address: 'noreply@yourdomain.com', name: 'Acme App' },
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Initialize the MailKit client
|
|
61
|
+
const mailer = createMailKit({
|
|
62
|
+
transport,
|
|
63
|
+
defaultBrandName: 'Acme App',
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Compose and Send Using Typed DTOs
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
// 1. Create a strongly typed email verification DTO
|
|
71
|
+
const verificationEmail = EmailTemplateFactory.createEmailVerification(
|
|
72
|
+
'Alex',
|
|
73
|
+
'https://app.example.com/verify?token=xyz123',
|
|
74
|
+
'482910'
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// 2. Dispatch via MailKit
|
|
78
|
+
await mailer.send({
|
|
79
|
+
to: 'alex@example.com',
|
|
80
|
+
template: verificationEmail,
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Common Use Cases
|
|
87
|
+
|
|
88
|
+
### 1. Built-in Transactional Templates
|
|
89
|
+
|
|
90
|
+
`EmailTemplateFactory` provides type-safe constructors for standard transactional patterns:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { EmailTemplateFactory } from 'ts-mailkit';
|
|
94
|
+
|
|
95
|
+
// Email Verification with OTP
|
|
96
|
+
const verifyDto = EmailTemplateFactory.createEmailVerification(
|
|
97
|
+
'Jordan',
|
|
98
|
+
'https://app.com/verify?token=abc',
|
|
99
|
+
'123456'
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Password Reset
|
|
103
|
+
const resetDto = EmailTemplateFactory.createPasswordReset(
|
|
104
|
+
'Jordan',
|
|
105
|
+
'https://app.com/reset?token=abc',
|
|
106
|
+
'654321'
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Two-Factor Authentication (2FA)
|
|
110
|
+
const twoFactorDto = EmailTemplateFactory.create2FAEmail(
|
|
111
|
+
'Jordan',
|
|
112
|
+
'987654',
|
|
113
|
+
'https://app.com/2fa/magic?token=abc'
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Magic Link Sign-in
|
|
117
|
+
const magicLinkDto = EmailTemplateFactory.createMagicLinkEmail(
|
|
118
|
+
'Jordan',
|
|
119
|
+
'https://app.com/auth/magic?token=abc'
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
// Newsletter / Announcement
|
|
123
|
+
const newsDto = EmailTemplateFactory.createNewsLetter(
|
|
124
|
+
'Product Update - Fall 2026',
|
|
125
|
+
'Introducing New Features',
|
|
126
|
+
'Here is what our team shipped this month.',
|
|
127
|
+
'https://cdn.example.com/hero.png',
|
|
128
|
+
'https://app.com/blog/update',
|
|
129
|
+
'Read Release Notes'
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### 2. Custom Branding & Multi-tenancy
|
|
134
|
+
|
|
135
|
+
You can instantiate `EmailTemplateFactory` with brand-level defaults:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const tenantFactory = new EmailTemplateFactory({
|
|
139
|
+
brandName: 'St. Patrick High School',
|
|
140
|
+
securityMessage: 'If you did not make this request, contact our school IT administration immediately.',
|
|
141
|
+
footer: (brand) => `© ${new Date().getFullYear()} ${brand}. Authorized educational portal.`,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const studentEmail = tenantFactory.createEmailVerification(
|
|
145
|
+
'Student',
|
|
146
|
+
'https://school.edu/verify',
|
|
147
|
+
'554433'
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Or pass a dynamic tenant resolver to `MailKit`:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
const mailer = createMailKit({
|
|
155
|
+
transport,
|
|
156
|
+
defaultFrom: 'notifications@portal.edu',
|
|
157
|
+
brandNameResolver: async () => {
|
|
158
|
+
// Dynamically retrieve active tenant brand from request context or DB
|
|
159
|
+
return 'Springfield Academy';
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### 3. Testing with `MemoryEmailSender`
|
|
165
|
+
|
|
166
|
+
Easily write unit and integration tests without hitting third-party APIs or mocking network sockets:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
170
|
+
import { createMailKit, MemoryEmailSender, EmailTemplateFactory } from 'ts-mailkit';
|
|
171
|
+
|
|
172
|
+
describe('User Registration Email', () => {
|
|
173
|
+
let memoryTransport: MemoryEmailSender;
|
|
174
|
+
let mailer: ReturnType<typeof createMailKit>;
|
|
175
|
+
|
|
176
|
+
beforeEach(() => {
|
|
177
|
+
memoryTransport = new MemoryEmailSender();
|
|
178
|
+
mailer = createMailKit({ transport: memoryTransport });
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('sends verification code to the registered user', async () => {
|
|
182
|
+
const dto = EmailTemplateFactory.createEmailVerification(
|
|
183
|
+
'Sam',
|
|
184
|
+
'https://app.com/verify?token=123',
|
|
185
|
+
'889900'
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
await mailer.send({ to: 'sam@example.com', template: dto });
|
|
189
|
+
|
|
190
|
+
expect(memoryTransport.count()).toBe(1);
|
|
191
|
+
const sent = memoryTransport.getLastMail();
|
|
192
|
+
expect(sent?.subject).toBe('Verify Your Email Address');
|
|
193
|
+
expect(sent?.html).toContain('889900');
|
|
194
|
+
expect(sent?.text).toContain('Your verification code is: 889900');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 4. Sending Raw Emails (No Template DTO)
|
|
200
|
+
|
|
201
|
+
For custom HTML or plain-text messages:
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
await mailer.sendRaw({
|
|
205
|
+
to: [{ address: 'support@example.com', name: 'Support Team' }],
|
|
206
|
+
subject: 'Urgent System Alert',
|
|
207
|
+
html: '<h1>System Alert</h1><p>Database failover completed successfully.</p>',
|
|
208
|
+
text: 'System Alert: Database failover completed successfully.',
|
|
209
|
+
attachments: [
|
|
210
|
+
{
|
|
211
|
+
filename: 'report.txt',
|
|
212
|
+
content: 'Database log summary...',
|
|
213
|
+
mimeType: 'text/plain',
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 5. Pluggable Transports (`IEmailSender`)
|
|
220
|
+
|
|
221
|
+
You can implement custom transports (e.g. SMTP, Resend, SendGrid, Postmark) by satisfying the `IEmailSender` interface:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
import type { IEmailSender, SendMailOptions, SendResult } from 'ts-mailkit';
|
|
225
|
+
|
|
226
|
+
export class CustomSmtpSender implements IEmailSender {
|
|
227
|
+
readonly name = 'smtp';
|
|
228
|
+
|
|
229
|
+
async send(options: SendMailOptions): Promise<SendResult> {
|
|
230
|
+
// Custom dispatch logic using your preferred protocol or client
|
|
231
|
+
return {
|
|
232
|
+
success: true,
|
|
233
|
+
messageId: 'custom-id-123',
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Development & Testing
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
# Install dependencies
|
|
245
|
+
pnpm install
|
|
246
|
+
|
|
247
|
+
# Run unit tests
|
|
248
|
+
pnpm test:unit
|
|
249
|
+
|
|
250
|
+
# Type check
|
|
251
|
+
pnpm run typecheck
|
|
252
|
+
|
|
253
|
+
# Build dual ESM/CJS bundles + .d.ts types
|
|
254
|
+
pnpm run build
|
|
255
|
+
|
|
256
|
+
# Prepublish verification
|
|
257
|
+
pnpm run prepublishOnly
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## License
|
|
263
|
+
|
|
264
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { IEmailSender } from '../transports/sender.interface.js';
|
|
2
|
+
import type { IEmailRenderer, RenderedEmail } from '../renderers/renderer.interface.js';
|
|
3
|
+
import type { BaseEmailDto } from '../templates/dto/index.js';
|
|
4
|
+
import { type Recipient, type SendMailOptions, type SendResult } from './types.js';
|
|
5
|
+
export interface SendTemplateOptions {
|
|
6
|
+
/**
|
|
7
|
+
* One or more recipient email addresses.
|
|
8
|
+
*/
|
|
9
|
+
to: Recipient | Recipient[];
|
|
10
|
+
/**
|
|
11
|
+
* Templated email DTO to render and send.
|
|
12
|
+
*/
|
|
13
|
+
template: BaseEmailDto;
|
|
14
|
+
/**
|
|
15
|
+
* Optional recipient display name (used when `to` is a plain string).
|
|
16
|
+
*/
|
|
17
|
+
toName?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional sender display name override for this specific email.
|
|
20
|
+
*/
|
|
21
|
+
fromName?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional sender email address override.
|
|
24
|
+
*/
|
|
25
|
+
from?: Recipient;
|
|
26
|
+
/**
|
|
27
|
+
* Optional CC recipients.
|
|
28
|
+
*/
|
|
29
|
+
cc?: Recipient | Recipient[];
|
|
30
|
+
/**
|
|
31
|
+
* Optional BCC recipients.
|
|
32
|
+
*/
|
|
33
|
+
bcc?: Recipient | Recipient[];
|
|
34
|
+
/**
|
|
35
|
+
* Optional Reply-To recipients.
|
|
36
|
+
*/
|
|
37
|
+
replyTo?: Recipient | Recipient[];
|
|
38
|
+
/**
|
|
39
|
+
* Optional file attachments.
|
|
40
|
+
*/
|
|
41
|
+
attachments?: SendMailOptions['attachments'];
|
|
42
|
+
/**
|
|
43
|
+
* Optional custom headers.
|
|
44
|
+
*/
|
|
45
|
+
headers?: Record<string, string>;
|
|
46
|
+
/**
|
|
47
|
+
* Optional tags for tracking.
|
|
48
|
+
*/
|
|
49
|
+
tags?: string[];
|
|
50
|
+
/**
|
|
51
|
+
* Optional metadata.
|
|
52
|
+
*/
|
|
53
|
+
metadata?: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
export interface MailKitOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The transport adapter used to dispatch emails (e.g. ZeptoMailSender, MemoryEmailSender).
|
|
58
|
+
*/
|
|
59
|
+
transport: IEmailSender;
|
|
60
|
+
/**
|
|
61
|
+
* Custom renderer implementation. Defaults to DefaultEmailRenderer.
|
|
62
|
+
*/
|
|
63
|
+
renderer?: IEmailRenderer;
|
|
64
|
+
/**
|
|
65
|
+
* Default sender address or Recipient.
|
|
66
|
+
*/
|
|
67
|
+
defaultFrom?: Recipient;
|
|
68
|
+
/**
|
|
69
|
+
* Default brand or application name.
|
|
70
|
+
*/
|
|
71
|
+
defaultBrandName?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Optional asynchronous or synchronous resolver to dynamically resolve brand/tenant name.
|
|
74
|
+
* Useful for multitenant applications.
|
|
75
|
+
*/
|
|
76
|
+
brandNameResolver?: () => Promise<string> | string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Main email client and orchestration service for ts-mailkit.
|
|
80
|
+
*/
|
|
81
|
+
export declare class MailKit {
|
|
82
|
+
private readonly transport;
|
|
83
|
+
private readonly renderer;
|
|
84
|
+
private readonly defaultFrom?;
|
|
85
|
+
private readonly defaultBrandName?;
|
|
86
|
+
private readonly brandNameResolver?;
|
|
87
|
+
constructor(options: MailKitOptions);
|
|
88
|
+
/**
|
|
89
|
+
* Returns the underlying transport instance.
|
|
90
|
+
*/
|
|
91
|
+
getTransport(): IEmailSender;
|
|
92
|
+
/**
|
|
93
|
+
* Renders an email DTO to HTML and plain text without dispatching.
|
|
94
|
+
*/
|
|
95
|
+
render(template: BaseEmailDto): Promise<RenderedEmail>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns the plain-text fallback for an email DTO without sending.
|
|
98
|
+
*/
|
|
99
|
+
buildPlainTextMessage(template: BaseEmailDto): string;
|
|
100
|
+
/**
|
|
101
|
+
* Sends an email using a strongly-typed template DTO.
|
|
102
|
+
* Supports both modern options object:
|
|
103
|
+
* `mailer.send({ to: 'user@example.com', template: myDto })`
|
|
104
|
+
* and legacy positional arguments for seamless migration:
|
|
105
|
+
* `mailer.send('user@example.com', myDto, 'User Name')`
|
|
106
|
+
*/
|
|
107
|
+
send(options: SendTemplateOptions): Promise<SendResult>;
|
|
108
|
+
send(to: string, template: BaseEmailDto, toName?: string): Promise<SendResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Dispatches a raw, pre-rendered email directly through the transport.
|
|
111
|
+
*/
|
|
112
|
+
sendRaw(options: SendMailOptions): Promise<SendResult>;
|
|
113
|
+
/**
|
|
114
|
+
* Sends a raw plain-text email with basic HTML pre-formatting.
|
|
115
|
+
* Useful for plain notifications, alerts, or simple text messages.
|
|
116
|
+
*/
|
|
117
|
+
sendSimpleMessage(to: string, subject: string, text: string, toName?: string): Promise<SendResult>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Drop-in alias for MailKit to maintain compatibility with existing EmailService code.
|
|
121
|
+
*/
|
|
122
|
+
export declare const EmailService: typeof MailKit;
|
|
123
|
+
export type EmailService = MailKit;
|
|
124
|
+
/**
|
|
125
|
+
* Convenience factory to create a MailKit client instance.
|
|
126
|
+
*/
|
|
127
|
+
export declare function createMailKit(options: MailKitOptions): MailKit;
|
|
128
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAGL,KAA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,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAY;IACzC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAiC;gBAExD,OAAO,EAAE,cAAc;IAWnC;;OAEG;IACH,YAAY,IAAI,YAAY;IAI5B;;OAEG;IACG,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAI5D;;OAEG;IACH,qBAAqB,CAAC,QAAQ,EAAE,YAAY,GAAG,MAAM;IAIrD;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IACvD,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAoEpF;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IAQ5D;;;OAGG;IACG,iBAAiB,CACrB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAW,GAClB,OAAO,CAAC,UAAU,CAAC;CASvB;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,gBAAU,CAAC;AACpC,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AAEnC;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAE9D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all ts-mailkit errors.
|
|
3
|
+
*/
|
|
4
|
+
export declare class MailKitError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Thrown when transport configuration is missing or invalid.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ConfigurationError extends MailKitError {
|
|
11
|
+
constructor(message: string);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Thrown when an email transport fails to dispatch an email.
|
|
15
|
+
*/
|
|
16
|
+
export declare class TransportError extends MailKitError {
|
|
17
|
+
readonly transportName: string;
|
|
18
|
+
readonly statusCode?: number;
|
|
19
|
+
readonly responseBody?: string;
|
|
20
|
+
readonly cause?: unknown;
|
|
21
|
+
constructor(message: string, options: {
|
|
22
|
+
transportName: string;
|
|
23
|
+
statusCode?: number;
|
|
24
|
+
responseBody?: string;
|
|
25
|
+
cause?: unknown;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Thrown when template rendering or DTO validation fails.
|
|
30
|
+
*/
|
|
31
|
+
export declare class TemplateError extends MailKitError {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;gBACtC,OAAO,EAAE,MAAM;CAK5B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,YAAY;IAC9C,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAGvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QACP,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CAUJ;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;gBACjC,OAAO,EAAE,MAAM;CAK5B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard email address representation with optional display name.
|
|
3
|
+
*/
|
|
4
|
+
export interface EmailAddress {
|
|
5
|
+
address: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Flexible recipient representation allowing string ('user@example.com'),
|
|
10
|
+
* EmailAddress ({ address: 'user@example.com', name: 'User' }),
|
|
11
|
+
* or legacy/standard object ({ email: 'user@example.com', name: 'User' }).
|
|
12
|
+
*/
|
|
13
|
+
export type Recipient = string | EmailAddress | {
|
|
14
|
+
email: string;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Normalizes a Recipient value into a standardized EmailAddress.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeRecipient(recipient: Recipient): EmailAddress;
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes a single or array of Recipients into an array of EmailAddress.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeRecipients(recipients?: Recipient | Recipient[]): EmailAddress[];
|
|
25
|
+
/**
|
|
26
|
+
* Email attachment representation.
|
|
27
|
+
*/
|
|
28
|
+
export interface EmailAttachment {
|
|
29
|
+
filename: string;
|
|
30
|
+
/**
|
|
31
|
+
* Content can be base64-encoded string, plain text, or binary Buffer/Uint8Array.
|
|
32
|
+
*/
|
|
33
|
+
content: string | Uint8Array;
|
|
34
|
+
mimeType?: string;
|
|
35
|
+
contentType?: string;
|
|
36
|
+
cid?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for sending an email through a transport adapter.
|
|
40
|
+
*/
|
|
41
|
+
export interface SendMailOptions {
|
|
42
|
+
to: Recipient | Recipient[];
|
|
43
|
+
from?: Recipient;
|
|
44
|
+
subject: string;
|
|
45
|
+
html: string;
|
|
46
|
+
text?: string;
|
|
47
|
+
cc?: Recipient | Recipient[];
|
|
48
|
+
bcc?: Recipient | Recipient[];
|
|
49
|
+
replyTo?: Recipient | Recipient[];
|
|
50
|
+
attachments?: EmailAttachment[];
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
tags?: string[];
|
|
53
|
+
metadata?: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Result returned by an IEmailSender upon dispatch.
|
|
57
|
+
*/
|
|
58
|
+
export interface SendResult {
|
|
59
|
+
success: boolean;
|
|
60
|
+
messageId?: string;
|
|
61
|
+
response?: unknown;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,YAAY,GACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAErC;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,YAAY,CAcrE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,GACnC,YAAY,EAAE,CAIhB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,OAAO,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;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