@bernierllc/email-sender 0.2.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 +7 -0
- package/README.md +430 -0
- package/dist/core/email-sender.d.ts +71 -0
- package/dist/core/email-sender.d.ts.map +1 -0
- package/dist/core/email-sender.js +125 -0
- package/dist/core/email-sender.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/base.d.ts +63 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +132 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/mailgun.d.ts +40 -0
- package/dist/providers/mailgun.d.ts.map +1 -0
- package/dist/providers/mailgun.js +525 -0
- package/dist/providers/mailgun.js.map +1 -0
- package/dist/providers/postmark.d.ts +37 -0
- package/dist/providers/postmark.d.ts.map +1 -0
- package/dist/providers/postmark.js +482 -0
- package/dist/providers/postmark.js.map +1 -0
- package/dist/providers/sendgrid.d.ts +80 -0
- package/dist/providers/sendgrid.d.ts.map +1 -0
- package/dist/providers/sendgrid.js +407 -0
- package/dist/providers/sendgrid.js.map +1 -0
- package/dist/providers/ses.d.ts +38 -0
- package/dist/providers/ses.d.ts.map +1 -0
- package/dist/providers/ses.js +404 -0
- package/dist/providers/ses.js.map +1 -0
- package/dist/providers/smtp.d.ts +61 -0
- package/dist/providers/smtp.d.ts.map +1 -0
- package/dist/providers/smtp.js +201 -0
- package/dist/providers/smtp.js.map +1 -0
- package/dist/types/index.d.ts +99 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2025 Bernier LLC
|
|
3
|
+
|
|
4
|
+
This file is licensed to the client under a limited-use license.
|
|
5
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
+
*/
|
package/README.md
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
# @bernierllc/email-sender
|
|
2
|
+
|
|
3
|
+
A core utility for basic email sending with provider-agnostic interface.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Provider-Agnostic**: Support for multiple email providers (SMTP, SendGrid, SES, Mailgun, Postmark)
|
|
8
|
+
- **TypeScript**: Full TypeScript support with strict typing
|
|
9
|
+
- **Validation**: Comprehensive email and configuration validation
|
|
10
|
+
- **Attachments**: Support for file attachments
|
|
11
|
+
- **Batch Sending**: Send multiple emails efficiently
|
|
12
|
+
- **Error Handling**: Robust error handling and reporting
|
|
13
|
+
- **Testing**: Comprehensive test coverage
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @bernierllc/email-sender
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**Note**: This package uses peer dependencies. You must install them separately:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# For SMTP provider
|
|
25
|
+
npm install nodemailer
|
|
26
|
+
|
|
27
|
+
# For AWS SES provider
|
|
28
|
+
npm install aws-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### Basic Usage
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { EmailSender } from '@bernierllc/email-sender';
|
|
37
|
+
|
|
38
|
+
// Configure SMTP provider
|
|
39
|
+
const config = {
|
|
40
|
+
provider: 'smtp' as const,
|
|
41
|
+
host: 'smtp.gmail.com',
|
|
42
|
+
port: 587,
|
|
43
|
+
secure: false,
|
|
44
|
+
username: 'your-email@gmail.com',
|
|
45
|
+
password: 'your-app-password',
|
|
46
|
+
fromEmail: 'noreply@yourdomain.com',
|
|
47
|
+
fromName: 'Your App',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Create email sender
|
|
51
|
+
const emailSender = new EmailSender(config);
|
|
52
|
+
|
|
53
|
+
// Send an email
|
|
54
|
+
const result = await emailSender.sendEmail({
|
|
55
|
+
toEmail: 'recipient@example.com',
|
|
56
|
+
toName: 'John Doe',
|
|
57
|
+
subject: 'Welcome to our app!',
|
|
58
|
+
htmlContent: '<h1>Welcome!</h1><p>Thank you for joining us.</p>',
|
|
59
|
+
textContent: 'Welcome! Thank you for joining us.',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (result.success) {
|
|
63
|
+
console.log('Email sent successfully:', result.messageId);
|
|
64
|
+
} else {
|
|
65
|
+
console.error('Failed to send email:', result.errorMessage);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### SendGrid Configuration
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { EmailSender } from '@bernierllc/email-sender';
|
|
73
|
+
|
|
74
|
+
const config = {
|
|
75
|
+
provider: 'sendgrid' as const,
|
|
76
|
+
apiKey: 'your-sendgrid-api-key',
|
|
77
|
+
fromEmail: 'noreply@yourdomain.com',
|
|
78
|
+
fromName: 'Your App',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const emailSender = new EmailSender(config);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### AWS SES Configuration
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { EmailSender } from '@bernierllc/email-sender';
|
|
88
|
+
|
|
89
|
+
const config = {
|
|
90
|
+
provider: 'ses' as const,
|
|
91
|
+
apiKey: 'your-aws-access-key',
|
|
92
|
+
secretKey: 'your-aws-secret-key',
|
|
93
|
+
region: 'us-east-1',
|
|
94
|
+
fromEmail: 'noreply@yourdomain.com',
|
|
95
|
+
fromName: 'Your App',
|
|
96
|
+
sandbox: false, // Set to true if in SES sandbox mode
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const emailSender = new EmailSender(config);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Mailgun Configuration
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { EmailSender } from '@bernierllc/email-sender';
|
|
106
|
+
|
|
107
|
+
const config = {
|
|
108
|
+
provider: 'mailgun' as const,
|
|
109
|
+
apiKey: 'your-mailgun-api-key',
|
|
110
|
+
domain: 'yourdomain.com',
|
|
111
|
+
region: 'us', // or 'eu' for European region
|
|
112
|
+
fromEmail: 'noreply@yourdomain.com',
|
|
113
|
+
fromName: 'Your App',
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const emailSender = new EmailSender(config);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Postmark Configuration
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { EmailSender } from '@bernierllc/email-sender';
|
|
123
|
+
|
|
124
|
+
const config = {
|
|
125
|
+
provider: 'postmark' as const,
|
|
126
|
+
apiKey: 'your-postmark-api-key',
|
|
127
|
+
accountToken: 'your-postmark-account-token', // Optional, for template operations
|
|
128
|
+
fromEmail: 'noreply@yourdomain.com',
|
|
129
|
+
fromName: 'Your App',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const emailSender = new EmailSender(config);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## API Reference
|
|
136
|
+
|
|
137
|
+
### EmailSender
|
|
138
|
+
|
|
139
|
+
The main class for sending emails.
|
|
140
|
+
|
|
141
|
+
#### Constructor
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
new EmailSender(config: EmailProviderConfig)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
#### Methods
|
|
148
|
+
|
|
149
|
+
##### `sendEmail(email: EmailMessage): Promise<SendResult>`
|
|
150
|
+
|
|
151
|
+
Send a single email.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const result = await emailSender.sendEmail({
|
|
155
|
+
toEmail: 'recipient@example.com',
|
|
156
|
+
subject: 'Test Email',
|
|
157
|
+
htmlContent: '<h1>Hello</h1>',
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
##### `sendBatch(emails: EmailMessage[]): Promise<SendResult[]>`
|
|
162
|
+
|
|
163
|
+
Send multiple emails in a batch.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const results = await emailSender.sendBatch([
|
|
167
|
+
{ toEmail: 'user1@example.com', subject: 'Email 1', htmlContent: '<h1>Email 1</h1>' },
|
|
168
|
+
{ toEmail: 'user2@example.com', subject: 'Email 2', htmlContent: '<h1>Email 2</h1>' },
|
|
169
|
+
]);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
##### `validateConfiguration(): EmailValidationResult`
|
|
173
|
+
|
|
174
|
+
Validate the provider configuration.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
const validation = emailSender.validateConfiguration();
|
|
178
|
+
if (!validation.isValid) {
|
|
179
|
+
console.error('Configuration errors:', validation.errors);
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
##### `validateEmailMessage(email: EmailMessage): EmailValidationResult`
|
|
184
|
+
|
|
185
|
+
Validate an email message before sending.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
const validation = emailSender.validateEmailMessage(email);
|
|
189
|
+
if (!validation.isValid) {
|
|
190
|
+
console.error('Email validation errors:', validation.errors);
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
##### `testConnection(): Promise<boolean>`
|
|
195
|
+
|
|
196
|
+
Test the connection to the email provider.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
const isConnected = await emailSender.testConnection();
|
|
200
|
+
if (isConnected) {
|
|
201
|
+
console.log('Connection successful');
|
|
202
|
+
} else {
|
|
203
|
+
console.error('Connection failed');
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
##### `getCapabilities(): EmailProviderCapabilities`
|
|
208
|
+
|
|
209
|
+
Get the capabilities of the current provider.
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const capabilities = emailSender.getCapabilities();
|
|
213
|
+
console.log('Supports attachments:', capabilities.supportsAttachments);
|
|
214
|
+
console.log('Max batch size:', capabilities.maxBatchSize);
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Types
|
|
218
|
+
|
|
219
|
+
#### EmailMessage
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
interface EmailMessage {
|
|
223
|
+
toEmail: string;
|
|
224
|
+
toName?: string;
|
|
225
|
+
fromEmail?: string;
|
|
226
|
+
fromName?: string;
|
|
227
|
+
subject: string;
|
|
228
|
+
htmlContent?: string;
|
|
229
|
+
textContent?: string;
|
|
230
|
+
replyTo?: string;
|
|
231
|
+
headers?: Record<string, string>;
|
|
232
|
+
attachments?: EmailAttachment[];
|
|
233
|
+
metadata?: Record<string, any>;
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
#### EmailAttachment
|
|
238
|
+
|
|
239
|
+
```typescript
|
|
240
|
+
interface EmailAttachment {
|
|
241
|
+
filename: string;
|
|
242
|
+
content: string; // Base64 encoded
|
|
243
|
+
contentType?: string;
|
|
244
|
+
disposition?: 'attachment' | 'inline';
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
#### SendResult
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
interface SendResult {
|
|
252
|
+
success: boolean;
|
|
253
|
+
messageId?: string;
|
|
254
|
+
errorMessage?: string;
|
|
255
|
+
providerResponse?: any;
|
|
256
|
+
metadata?: Record<string, any>;
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### EmailProviderConfig
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
interface EmailProviderConfig {
|
|
264
|
+
provider: 'sendgrid' | 'ses' | 'mailgun' | 'postmark' | 'smtp';
|
|
265
|
+
apiKey?: string;
|
|
266
|
+
region?: string;
|
|
267
|
+
endpoint?: string;
|
|
268
|
+
fromEmail: string;
|
|
269
|
+
fromName?: string;
|
|
270
|
+
replyTo?: string;
|
|
271
|
+
webhookUrl?: string;
|
|
272
|
+
webhookSecret?: string;
|
|
273
|
+
sandbox?: boolean;
|
|
274
|
+
// SMTP specific options
|
|
275
|
+
host?: string;
|
|
276
|
+
port?: number;
|
|
277
|
+
secure?: boolean;
|
|
278
|
+
username?: string;
|
|
279
|
+
password?: string;
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Examples
|
|
284
|
+
|
|
285
|
+
### Send Email with Attachment
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import { EmailSender } from '@bernierllc/email-sender';
|
|
289
|
+
import fs from 'fs';
|
|
290
|
+
|
|
291
|
+
const emailSender = new EmailSender(config);
|
|
292
|
+
|
|
293
|
+
const attachment = {
|
|
294
|
+
filename: 'report.pdf',
|
|
295
|
+
content: fs.readFileSync('report.pdf').toString('base64'),
|
|
296
|
+
contentType: 'application/pdf',
|
|
297
|
+
disposition: 'attachment' as const,
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const result = await emailSender.sendEmail({
|
|
301
|
+
toEmail: 'recipient@example.com',
|
|
302
|
+
subject: 'Monthly Report',
|
|
303
|
+
htmlContent: '<h1>Monthly Report</h1><p>Please find the attached report.</p>',
|
|
304
|
+
attachments: [attachment],
|
|
305
|
+
});
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Send Email with Custom Headers
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
const result = await emailSender.sendEmail({
|
|
312
|
+
toEmail: 'recipient@example.com',
|
|
313
|
+
subject: 'Priority Message',
|
|
314
|
+
htmlContent: '<h1>Important Update</h1>',
|
|
315
|
+
headers: {
|
|
316
|
+
'X-Priority': '1',
|
|
317
|
+
'X-Custom-Header': 'custom-value',
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### Batch Email with Different Content
|
|
323
|
+
|
|
324
|
+
```typescript
|
|
325
|
+
const emails = [
|
|
326
|
+
{
|
|
327
|
+
toEmail: 'user1@example.com',
|
|
328
|
+
toName: 'User One',
|
|
329
|
+
subject: 'Personalized Email 1',
|
|
330
|
+
htmlContent: '<h1>Hello User One!</h1>',
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
toEmail: 'user2@example.com',
|
|
334
|
+
toName: 'User Two',
|
|
335
|
+
subject: 'Personalized Email 2',
|
|
336
|
+
htmlContent: '<h1>Hello User Two!</h1>',
|
|
337
|
+
},
|
|
338
|
+
];
|
|
339
|
+
|
|
340
|
+
const results = await emailSender.sendBatch(emails);
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Error Handling
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
try {
|
|
347
|
+
const result = await emailSender.sendEmail(email);
|
|
348
|
+
|
|
349
|
+
if (result.success) {
|
|
350
|
+
console.log('Email sent successfully');
|
|
351
|
+
} else {
|
|
352
|
+
console.error('Email failed:', result.errorMessage);
|
|
353
|
+
|
|
354
|
+
// Check if it's a validation error
|
|
355
|
+
const validation = emailSender.validateEmailMessage(email);
|
|
356
|
+
if (!validation.isValid) {
|
|
357
|
+
console.error('Validation errors:', validation.errors);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
} catch (error) {
|
|
361
|
+
console.error('Unexpected error:', error);
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## Provider Support
|
|
366
|
+
|
|
367
|
+
### Currently Supported
|
|
368
|
+
|
|
369
|
+
- **SMTP**: Full support with nodemailer
|
|
370
|
+
- **SendGrid**: Full support with SendGrid API
|
|
371
|
+
- **AWS SES**: Full support with AWS SDK (requires `aws-sdk` peer dependency)
|
|
372
|
+
- **Mailgun**: Full support with Mailgun API
|
|
373
|
+
- **Postmark**: Full support with Postmark API
|
|
374
|
+
|
|
375
|
+
### Adding New Providers
|
|
376
|
+
|
|
377
|
+
To add a new provider, extend the `EmailProvider` base class:
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
import { EmailProvider, EmailMessage, SendResult } from '@bernierllc/email-sender';
|
|
381
|
+
|
|
382
|
+
export class CustomProvider extends EmailProvider {
|
|
383
|
+
async sendEmail(email: EmailMessage): Promise<SendResult> {
|
|
384
|
+
// Implement your provider logic here
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
async sendBatch(emails: EmailMessage[]): Promise<SendResult[]> {
|
|
388
|
+
// Implement batch sending logic
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
async getDeliveryStatus(messageId: string): Promise<DeliveryStatus | null> {
|
|
392
|
+
// Implement delivery status checking
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async processWebhook(payload: any, signature: string): Promise<WebhookEvent[]> {
|
|
396
|
+
// Implement webhook processing
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
## Testing
|
|
402
|
+
|
|
403
|
+
Run the test suite:
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
npm test
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
Run tests with coverage:
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
npm run test:coverage
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
## Contributing
|
|
416
|
+
|
|
417
|
+
1. Fork the repository
|
|
418
|
+
2. Create a feature branch
|
|
419
|
+
3. Make your changes
|
|
420
|
+
4. Add tests for new functionality
|
|
421
|
+
5. Ensure all tests pass
|
|
422
|
+
6. Submit a pull request
|
|
423
|
+
|
|
424
|
+
## License
|
|
425
|
+
|
|
426
|
+
ISC License - see LICENSE file for details.
|
|
427
|
+
|
|
428
|
+
## Support
|
|
429
|
+
|
|
430
|
+
For support and questions, please open an issue on GitHub or contact Bernier LLC.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main EmailSender class for managing email providers
|
|
3
|
+
*/
|
|
4
|
+
import { EmailProvider, EmailProviderConfig } from '../providers/base';
|
|
5
|
+
import { EmailMessage, SendResult, DeliveryStatus, WebhookEvent, EmailProviderCapabilities, EmailValidationResult } from '../types';
|
|
6
|
+
export declare class EmailSender {
|
|
7
|
+
private provider;
|
|
8
|
+
constructor(config: EmailProviderConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Create the appropriate provider based on configuration
|
|
11
|
+
*/
|
|
12
|
+
private createProvider;
|
|
13
|
+
/**
|
|
14
|
+
* Send a single email
|
|
15
|
+
*/
|
|
16
|
+
sendEmail(email: EmailMessage): Promise<SendResult>;
|
|
17
|
+
/**
|
|
18
|
+
* Send multiple emails
|
|
19
|
+
*/
|
|
20
|
+
sendBatch(emails: EmailMessage[]): Promise<SendResult[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Get delivery status for a message
|
|
23
|
+
*/
|
|
24
|
+
getDeliveryStatus(messageId: string): Promise<DeliveryStatus | null>;
|
|
25
|
+
/**
|
|
26
|
+
* Process webhook events from the provider
|
|
27
|
+
*/
|
|
28
|
+
processWebhook(payload: any, signature: string): Promise<WebhookEvent[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Validate provider configuration
|
|
31
|
+
*/
|
|
32
|
+
validateConfiguration(): EmailValidationResult;
|
|
33
|
+
/**
|
|
34
|
+
* Get provider name
|
|
35
|
+
*/
|
|
36
|
+
getProviderName(): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get provider capabilities
|
|
39
|
+
*/
|
|
40
|
+
getCapabilities(): EmailProviderCapabilities;
|
|
41
|
+
/**
|
|
42
|
+
* Test the provider connection
|
|
43
|
+
*/
|
|
44
|
+
testConnection(): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Validate an email message
|
|
47
|
+
*/
|
|
48
|
+
validateEmailMessage(email: EmailMessage): EmailValidationResult;
|
|
49
|
+
/**
|
|
50
|
+
* Create a template in the provider (if supported)
|
|
51
|
+
*/
|
|
52
|
+
createTemplate(templateData: {
|
|
53
|
+
name: string;
|
|
54
|
+
subject: string;
|
|
55
|
+
htmlContent: string;
|
|
56
|
+
textContent?: string;
|
|
57
|
+
}): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Send an email using a provider template (if supported)
|
|
60
|
+
*/
|
|
61
|
+
sendTemplateEmail(templateId: string, toEmail: string, templateData: Record<string, any>, toName?: string): Promise<SendResult>;
|
|
62
|
+
/**
|
|
63
|
+
* Get the underlying provider instance
|
|
64
|
+
*/
|
|
65
|
+
getProvider(): EmailProvider;
|
|
66
|
+
/**
|
|
67
|
+
* Update provider configuration
|
|
68
|
+
*/
|
|
69
|
+
updateConfig(config: EmailProviderConfig): void;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=email-sender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.d.ts","sourceRoot":"","sources":["../../src/core/email-sender.ts"],"names":[],"mappings":"AAQA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAMvE,OAAO,EACL,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,yBAAyB,EACzB,qBAAqB,EACtB,MAAM,UAAU,CAAC;AAElB,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,MAAM,EAAE,mBAAmB;IAIvC;;OAEG;IACH,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACG,SAAS,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAIzD;;OAEG;IACG,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAI9D;;OAEG;IACG,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAI1E;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAI9E;;OAEG;IACH,qBAAqB,IAAI,qBAAqB;IAI9C;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB;;OAEG;IACH,eAAe,IAAI,yBAAyB;IAI5C;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxC;;OAEG;IACH,oBAAoB,CAAC,KAAK,EAAE,YAAY,GAAG,qBAAqB;IAIhE;;OAEG;IACG,cAAc,CAAC,YAAY,EAAE;QACjC,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,OAAO,CAAC,MAAM,CAAC;IAOnB;;OAEG;IACG,iBAAiB,CACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,UAAU,CAAC;IAOtB;;OAEG;IACH,WAAW,IAAI,aAAa;IAI5B;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI;CAGhD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (c) 2025 Bernier LLC
|
|
4
|
+
|
|
5
|
+
This file is licensed to the client under a limited-use license.
|
|
6
|
+
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
7
|
+
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EmailSender = void 0;
|
|
11
|
+
const smtp_1 = require("../providers/smtp");
|
|
12
|
+
const sendgrid_1 = require("../providers/sendgrid");
|
|
13
|
+
const ses_1 = require("../providers/ses");
|
|
14
|
+
const mailgun_1 = require("../providers/mailgun");
|
|
15
|
+
const postmark_1 = require("../providers/postmark");
|
|
16
|
+
class EmailSender {
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.provider = this.createProvider(config);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create the appropriate provider based on configuration
|
|
22
|
+
*/
|
|
23
|
+
createProvider(config) {
|
|
24
|
+
switch (config.provider) {
|
|
25
|
+
case 'smtp':
|
|
26
|
+
return new smtp_1.SmtpProvider(config);
|
|
27
|
+
case 'sendgrid':
|
|
28
|
+
return new sendgrid_1.SendGridProvider(config);
|
|
29
|
+
case 'ses':
|
|
30
|
+
return new ses_1.SesProvider(config);
|
|
31
|
+
case 'mailgun':
|
|
32
|
+
return new mailgun_1.MailgunProvider(config);
|
|
33
|
+
case 'postmark':
|
|
34
|
+
return new postmark_1.PostmarkProvider(config);
|
|
35
|
+
default:
|
|
36
|
+
throw new Error(`Unsupported provider: ${config.provider}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Send a single email
|
|
41
|
+
*/
|
|
42
|
+
async sendEmail(email) {
|
|
43
|
+
return this.provider.sendEmail(email);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Send multiple emails
|
|
47
|
+
*/
|
|
48
|
+
async sendBatch(emails) {
|
|
49
|
+
return this.provider.sendBatch(emails);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get delivery status for a message
|
|
53
|
+
*/
|
|
54
|
+
async getDeliveryStatus(messageId) {
|
|
55
|
+
return this.provider.getDeliveryStatus(messageId);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Process webhook events from the provider
|
|
59
|
+
*/
|
|
60
|
+
async processWebhook(payload, signature) {
|
|
61
|
+
return this.provider.processWebhook(payload, signature);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Validate provider configuration
|
|
65
|
+
*/
|
|
66
|
+
validateConfiguration() {
|
|
67
|
+
return this.provider.validateConfiguration();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get provider name
|
|
71
|
+
*/
|
|
72
|
+
getProviderName() {
|
|
73
|
+
return this.provider.getProviderName();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get provider capabilities
|
|
77
|
+
*/
|
|
78
|
+
getCapabilities() {
|
|
79
|
+
return this.provider.getCapabilities();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Test the provider connection
|
|
83
|
+
*/
|
|
84
|
+
async testConnection() {
|
|
85
|
+
return this.provider.testConnection();
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validate an email message
|
|
89
|
+
*/
|
|
90
|
+
validateEmailMessage(email) {
|
|
91
|
+
return this.provider.validateEmailMessage(email);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create a template in the provider (if supported)
|
|
95
|
+
*/
|
|
96
|
+
async createTemplate(templateData) {
|
|
97
|
+
if (!this.provider.createTemplate) {
|
|
98
|
+
throw new Error('Template creation not supported by this provider');
|
|
99
|
+
}
|
|
100
|
+
return this.provider.createTemplate(templateData);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Send an email using a provider template (if supported)
|
|
104
|
+
*/
|
|
105
|
+
async sendTemplateEmail(templateId, toEmail, templateData, toName) {
|
|
106
|
+
if (!this.provider.sendTemplateEmail) {
|
|
107
|
+
throw new Error('Template emails not supported by this provider');
|
|
108
|
+
}
|
|
109
|
+
return this.provider.sendTemplateEmail(templateId, toEmail, templateData, toName);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the underlying provider instance
|
|
113
|
+
*/
|
|
114
|
+
getProvider() {
|
|
115
|
+
return this.provider;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update provider configuration
|
|
119
|
+
*/
|
|
120
|
+
updateConfig(config) {
|
|
121
|
+
this.provider = this.createProvider(config);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.EmailSender = EmailSender;
|
|
125
|
+
//# sourceMappingURL=email-sender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email-sender.js","sourceRoot":"","sources":["../../src/core/email-sender.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email Sender - Core Library
|
|
3
|
+
* Main entry point for the email sending system
|
|
4
|
+
*/
|
|
5
|
+
export * from './types';
|
|
6
|
+
export { EmailSender } from './core/email-sender';
|
|
7
|
+
export { EmailProvider } from './providers/base';
|
|
8
|
+
export { SmtpProvider } from './providers/smtp';
|
|
9
|
+
export { SendGridProvider } from './providers/sendgrid';
|
|
10
|
+
export { SesProvider } from './providers/ses';
|
|
11
|
+
export { MailgunProvider } from './providers/mailgun';
|
|
12
|
+
export { PostmarkProvider } from './providers/postmark';
|
|
13
|
+
export type { EmailMessage, SendResult, DeliveryStatus, WebhookEvent, EmailProviderConfig, EmailProviderCapabilities, EmailValidationResult, EmailAttachment, BatchEmailOptions, EmailTemplate } from './types';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA;;;GAGG;AAGH,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD,YAAY,EACV,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,EACjB,aAAa,EACd,MAAM,SAAS,CAAC"}
|