@flusys/nestjs-email 3.0.0-rc → 3.0.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/README.md +441 -3
- package/cjs/utils/email-templates.util.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Email Package Guide
|
|
2
2
|
|
|
3
3
|
> **Package:** `@flusys/nestjs-email`
|
|
4
|
+
> **Version:** 3.0.0
|
|
4
5
|
> **Type:** Email sending with templates, multiple providers, and multi-tenant support
|
|
5
6
|
|
|
6
7
|
## Table of Contents
|
|
@@ -10,11 +11,15 @@
|
|
|
10
11
|
- [Constants](#constants)
|
|
11
12
|
- [Module Setup](#module-setup)
|
|
12
13
|
- [Entities](#entities)
|
|
14
|
+
- [Interfaces](#interfaces)
|
|
13
15
|
- [Email Providers](#email-providers)
|
|
14
16
|
- [Email Configuration](#email-configuration)
|
|
15
17
|
- [Email Templates](#email-templates)
|
|
16
18
|
- [Email Sending](#email-sending)
|
|
19
|
+
- [DTOs](#dtos)
|
|
20
|
+
- [Utility Functions](#utility-functions)
|
|
17
21
|
- [API Endpoints](#api-endpoints)
|
|
22
|
+
- [Swagger Documentation](#swagger-documentation)
|
|
18
23
|
- [Multi-Tenant Support](#multi-tenant-support)
|
|
19
24
|
- [Best Practices](#best-practices)
|
|
20
25
|
|
|
@@ -69,6 +74,21 @@ export const DEFAULT_FROM_NAME = 'FLUSYS';
|
|
|
69
74
|
|
|
70
75
|
## Module Setup
|
|
71
76
|
|
|
77
|
+
### Module Options Interface
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
interface IEmailModuleConfig extends IDataSourceServiceOptions {
|
|
81
|
+
defaultProvider?: string; // Default provider type
|
|
82
|
+
rateLimitPerMinute?: number; // Rate limiting
|
|
83
|
+
enableLogging?: boolean; // Enable debug logging
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface EmailModuleOptions extends IDynamicModuleConfig {
|
|
87
|
+
bootstrapAppConfig?: IBootstrapAppConfig;
|
|
88
|
+
config?: IEmailModuleConfig;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
72
92
|
### Basic Setup
|
|
73
93
|
|
|
74
94
|
```typescript
|
|
@@ -158,6 +178,97 @@ export { EmailTemplate as EmailTemplateBase } from './email-template.entity';
|
|
|
158
178
|
|
|
159
179
|
---
|
|
160
180
|
|
|
181
|
+
## Interfaces
|
|
182
|
+
|
|
183
|
+
### Provider Configuration Interfaces
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
interface ISmtpTlsConfig {
|
|
187
|
+
rejectUnauthorized?: boolean; // Reject unauthorized certs (default: true)
|
|
188
|
+
minVersion?: 'TLSv1.2' | 'TLSv1.3'; // Min TLS version (default: 'TLSv1.2')
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
interface ISmtpConfig {
|
|
192
|
+
host: string;
|
|
193
|
+
port: number;
|
|
194
|
+
secure?: boolean;
|
|
195
|
+
auth?: { user: string; pass: string };
|
|
196
|
+
tls?: ISmtpTlsConfig; // TLS configuration
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
interface ISendGridConfig {
|
|
200
|
+
apiKey: string;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
interface IMailgunConfig {
|
|
204
|
+
apiKey: string;
|
|
205
|
+
domain: string;
|
|
206
|
+
region?: 'us' | 'eu';
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Email Template Schema Interfaces
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
interface IEmailTemplateVariable {
|
|
214
|
+
name: string;
|
|
215
|
+
type: 'string' | 'number' | 'boolean' | 'date';
|
|
216
|
+
required?: boolean;
|
|
217
|
+
defaultValue?: string;
|
|
218
|
+
description?: string;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
interface IEmailSection {
|
|
222
|
+
id: string;
|
|
223
|
+
type: 'header' | 'body' | 'footer';
|
|
224
|
+
name: string;
|
|
225
|
+
blocks: IEmailBlock[];
|
|
226
|
+
order: number;
|
|
227
|
+
style?: IEmailSectionStyle;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
interface IEmailSectionStyle {
|
|
231
|
+
backgroundColor?: string;
|
|
232
|
+
padding?: string;
|
|
233
|
+
maxWidth?: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
interface IEmailBlock {
|
|
237
|
+
id: string;
|
|
238
|
+
type: 'text' | 'image' | 'button' | 'divider' | 'html';
|
|
239
|
+
order: number;
|
|
240
|
+
content: Record<string, any>;
|
|
241
|
+
style?: IEmailBlockStyle;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface IEmailBlockStyle {
|
|
245
|
+
textAlign?: 'left' | 'center' | 'right';
|
|
246
|
+
padding?: string;
|
|
247
|
+
margin?: string;
|
|
248
|
+
backgroundColor?: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
interface IEmailSettings {
|
|
252
|
+
maxWidth?: string;
|
|
253
|
+
backgroundColor?: string;
|
|
254
|
+
fontFamily?: string;
|
|
255
|
+
baseTextColor?: string;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
interface IEmailSchema {
|
|
259
|
+
id: string;
|
|
260
|
+
version: string;
|
|
261
|
+
name: string;
|
|
262
|
+
subject: string;
|
|
263
|
+
preheader?: string;
|
|
264
|
+
sections: IEmailSection[];
|
|
265
|
+
variables?: IEmailTemplateVariable[];
|
|
266
|
+
settings?: IEmailSettings;
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
161
272
|
## Email Providers
|
|
162
273
|
|
|
163
274
|
### Provider Types
|
|
@@ -180,8 +291,12 @@ Providers are auto-registered at module load via `EmailProviderRegistry`.
|
|
|
180
291
|
config: {
|
|
181
292
|
host: 'smtp.gmail.com',
|
|
182
293
|
port: 587,
|
|
183
|
-
secure: false,
|
|
294
|
+
secure: false, // true for port 465
|
|
184
295
|
auth: { user: 'your@gmail.com', pass: 'app-password' },
|
|
296
|
+
tls: {
|
|
297
|
+
rejectUnauthorized: true, // Certificate validation (default: true)
|
|
298
|
+
minVersion: 'TLSv1.2', // Minimum TLS version
|
|
299
|
+
},
|
|
185
300
|
}
|
|
186
301
|
}
|
|
187
302
|
```
|
|
@@ -234,6 +349,13 @@ interface IEmailSendOptions {
|
|
|
234
349
|
attachments?: IEmailAttachment[];
|
|
235
350
|
}
|
|
236
351
|
|
|
352
|
+
interface IEmailAttachment {
|
|
353
|
+
filename: string;
|
|
354
|
+
content: Buffer | string;
|
|
355
|
+
contentType?: string;
|
|
356
|
+
encoding?: string;
|
|
357
|
+
}
|
|
358
|
+
|
|
237
359
|
interface IEmailSendResult {
|
|
238
360
|
success: boolean;
|
|
239
361
|
messageId?: string;
|
|
@@ -241,6 +363,54 @@ interface IEmailSendResult {
|
|
|
241
363
|
}
|
|
242
364
|
```
|
|
243
365
|
|
|
366
|
+
### EmailProviderRegistry
|
|
367
|
+
|
|
368
|
+
Providers are auto-registered at module load:
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
// Built-in registration (happens automatically)
|
|
372
|
+
EmailProviderRegistry.register(EmailProviderTypeEnum.SMTP, SmtpProvider);
|
|
373
|
+
EmailProviderRegistry.register(EmailProviderTypeEnum.SENDGRID, SendGridProvider);
|
|
374
|
+
EmailProviderRegistry.register(EmailProviderTypeEnum.MAILGUN, MailgunProvider);
|
|
375
|
+
|
|
376
|
+
// Registry methods
|
|
377
|
+
EmailProviderRegistry.register(name, ProviderClass); // Register provider
|
|
378
|
+
EmailProviderRegistry.get(name); // Get provider class
|
|
379
|
+
EmailProviderRegistry.has(name); // Check if registered
|
|
380
|
+
EmailProviderRegistry.getAll(); // List all providers
|
|
381
|
+
EmailProviderRegistry.clear(); // Clear registry
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
### Custom Provider Example
|
|
385
|
+
|
|
386
|
+
```typescript
|
|
387
|
+
class MyCustomProvider implements IEmailProvider {
|
|
388
|
+
async initialize(config: any): Promise<void> {
|
|
389
|
+
// Initialize connection
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async sendEmail(options: IEmailSendOptions): Promise<IEmailSendResult> {
|
|
393
|
+
// Send email
|
|
394
|
+
return { success: true, messageId: 'xxx' };
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async sendBulkEmails(options: IEmailSendOptions[]): Promise<IEmailSendResult[]> {
|
|
398
|
+
return Promise.all(options.map(opt => this.sendEmail(opt)));
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
async healthCheck(): Promise<boolean> {
|
|
402
|
+
return true;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async close(): Promise<void> {
|
|
406
|
+
// Cleanup connections
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// Register custom provider
|
|
411
|
+
EmailProviderRegistry.register('custom', MyCustomProvider);
|
|
412
|
+
```
|
|
413
|
+
|
|
244
414
|
---
|
|
245
415
|
|
|
246
416
|
## Email Configuration
|
|
@@ -388,6 +558,103 @@ const result = await emailSendService.sendEmail({
|
|
|
388
558
|
|
|
389
559
|
---
|
|
390
560
|
|
|
561
|
+
## DTOs
|
|
562
|
+
|
|
563
|
+
### Email Send DTOs
|
|
564
|
+
|
|
565
|
+
```typescript
|
|
566
|
+
// Base class for common email fields
|
|
567
|
+
class BaseEmailDto {
|
|
568
|
+
to: string | string[]; // Recipient(s)
|
|
569
|
+
cc?: string | string[]; // CC recipients
|
|
570
|
+
bcc?: string | string[]; // BCC recipients
|
|
571
|
+
from?: string; // Sender email
|
|
572
|
+
fromName?: string; // Sender name
|
|
573
|
+
replyTo?: string; // Reply-to address
|
|
574
|
+
emailConfigId?: string; // Email config to use
|
|
575
|
+
attachments?: EmailAttachmentDto[];
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
class SendEmailDto extends BaseEmailDto {
|
|
579
|
+
subject: string;
|
|
580
|
+
html: string;
|
|
581
|
+
text?: string;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
class SendTemplateEmailDto extends BaseEmailDto {
|
|
585
|
+
templateId?: string; // Template ID (or slug required)
|
|
586
|
+
templateSlug?: string; // Template slug (or ID required)
|
|
587
|
+
variables?: Record<string, any>; // Template variables
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
class TestEmailDto {
|
|
591
|
+
emailConfigId: string;
|
|
592
|
+
recipient: string;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
class EmailAttachmentDto {
|
|
596
|
+
filename: string;
|
|
597
|
+
content: string; // Base64 encoded
|
|
598
|
+
contentType?: string;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
class EmailSendResultDto {
|
|
602
|
+
success: boolean;
|
|
603
|
+
messageId?: string;
|
|
604
|
+
error?: string;
|
|
605
|
+
}
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
### Custom Validators
|
|
609
|
+
|
|
610
|
+
The DTOs use custom validators for email fields:
|
|
611
|
+
|
|
612
|
+
```typescript
|
|
613
|
+
// Validates single email or array of emails
|
|
614
|
+
@IsEmailOrEmailArray()
|
|
615
|
+
to: string | string[];
|
|
616
|
+
|
|
617
|
+
// Requires either templateId or templateSlug
|
|
618
|
+
@RequireTemplateIdOrSlug()
|
|
619
|
+
templateId?: string;
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
## Utility Functions
|
|
625
|
+
|
|
626
|
+
Built-in email template utilities for common use cases:
|
|
627
|
+
|
|
628
|
+
```typescript
|
|
629
|
+
import { getOtpEmailFormat, getResetPasswordEmailFormat } from '@flusys/nestjs-email/utils';
|
|
630
|
+
|
|
631
|
+
// Generate OTP email HTML
|
|
632
|
+
const otpHtml = getOtpEmailFormat(123456, 'John Doe');
|
|
633
|
+
|
|
634
|
+
// Generate password reset email HTML
|
|
635
|
+
const resetHtml = getResetPasswordEmailFormat('https://example.com/reset?token=xyz', 'John Doe');
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
### getOtpEmailFormat(otp, userName?)
|
|
639
|
+
|
|
640
|
+
Generates styled HTML for OTP verification emails.
|
|
641
|
+
|
|
642
|
+
```typescript
|
|
643
|
+
const html = getOtpEmailFormat(123456, 'John');
|
|
644
|
+
// Returns formatted HTML with OTP code prominently displayed
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
### getResetPasswordEmailFormat(resetLink, userName?)
|
|
648
|
+
|
|
649
|
+
Generates styled HTML for password reset emails.
|
|
650
|
+
|
|
651
|
+
```typescript
|
|
652
|
+
const html = getResetPasswordEmailFormat('https://app.example.com/reset?token=abc123', 'John');
|
|
653
|
+
// Returns formatted HTML with reset button
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
---
|
|
657
|
+
|
|
391
658
|
## API Endpoints
|
|
392
659
|
|
|
393
660
|
All endpoints use POST (RPC pattern) and require JWT authentication.
|
|
@@ -440,6 +707,61 @@ curl -X POST http://localhost:3000/email/send/test \
|
|
|
440
707
|
-d '{ "emailConfigId": "uuid", "recipient": "test@example.com" }'
|
|
441
708
|
```
|
|
442
709
|
|
|
710
|
+
### Controller Permissions
|
|
711
|
+
|
|
712
|
+
Controllers use permission-based security via `createApiController`:
|
|
713
|
+
|
|
714
|
+
```typescript
|
|
715
|
+
// Email Config permissions
|
|
716
|
+
EMAIL_CONFIG_PERMISSIONS.CREATE // 'email-config.create'
|
|
717
|
+
EMAIL_CONFIG_PERMISSIONS.READ // 'email-config.read'
|
|
718
|
+
EMAIL_CONFIG_PERMISSIONS.UPDATE // 'email-config.update'
|
|
719
|
+
EMAIL_CONFIG_PERMISSIONS.DELETE // 'email-config.delete'
|
|
720
|
+
|
|
721
|
+
// Email Template permissions
|
|
722
|
+
EMAIL_TEMPLATE_PERMISSIONS.CREATE // 'email-template.create'
|
|
723
|
+
EMAIL_TEMPLATE_PERMISSIONS.READ // 'email-template.read'
|
|
724
|
+
EMAIL_TEMPLATE_PERMISSIONS.UPDATE // 'email-template.update'
|
|
725
|
+
EMAIL_TEMPLATE_PERMISSIONS.DELETE // 'email-template.delete'
|
|
726
|
+
|
|
727
|
+
// Email Send permission
|
|
728
|
+
'email.send'
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
---
|
|
732
|
+
|
|
733
|
+
## Swagger Documentation
|
|
734
|
+
|
|
735
|
+
### Setup Swagger for Email Module
|
|
736
|
+
|
|
737
|
+
```typescript
|
|
738
|
+
import { emailSwaggerConfig } from '@flusys/nestjs-email';
|
|
739
|
+
import { setupSwaggerDocs } from '@flusys/nestjs-core/docs';
|
|
740
|
+
|
|
741
|
+
// In your bootstrap function
|
|
742
|
+
setupSwaggerDocs(app, emailSwaggerConfig(bootstrapAppConfig));
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
### Swagger Config Options
|
|
746
|
+
|
|
747
|
+
```typescript
|
|
748
|
+
function emailSwaggerConfig(bootstrapConfig?: IBootstrapAppConfig): IModuleSwaggerOptions {
|
|
749
|
+
return {
|
|
750
|
+
title: 'Email API',
|
|
751
|
+
description: '...', // Auto-generated based on features
|
|
752
|
+
version: '1.0',
|
|
753
|
+
path: 'api/docs/email', // Swagger UI path
|
|
754
|
+
bearerAuth: true,
|
|
755
|
+
excludeTags: [],
|
|
756
|
+
excludeSchemaProperties: [...], // Excludes companyId when company feature disabled
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
The Swagger documentation automatically adapts based on `enableCompanyFeature`:
|
|
762
|
+
- When enabled: Shows company isolation and multi-tenant features
|
|
763
|
+
- When disabled: Hides companyId fields from schemas
|
|
764
|
+
|
|
443
765
|
---
|
|
444
766
|
|
|
445
767
|
## Multi-Tenant Support
|
|
@@ -534,7 +856,8 @@ import { EmailModule } from '@flusys/nestjs-email';
|
|
|
534
856
|
|
|
535
857
|
// Services
|
|
536
858
|
import {
|
|
537
|
-
|
|
859
|
+
EmailConfigService, // Module configuration service
|
|
860
|
+
EmailProviderConfigService, // CRUD for email provider configs
|
|
538
861
|
EmailTemplateService,
|
|
539
862
|
EmailSendService,
|
|
540
863
|
EmailDataSourceProvider,
|
|
@@ -548,6 +871,9 @@ import {
|
|
|
548
871
|
EmailTemplate,
|
|
549
872
|
EmailTemplateBase,
|
|
550
873
|
EmailTemplateWithCompany,
|
|
874
|
+
EmailCoreEntities,
|
|
875
|
+
EmailCompanyEntities,
|
|
876
|
+
getEmailEntitiesByConfig,
|
|
551
877
|
} from '@flusys/nestjs-email/entities';
|
|
552
878
|
|
|
553
879
|
// DTOs
|
|
@@ -558,6 +884,7 @@ import {
|
|
|
558
884
|
CreateEmailTemplateDto,
|
|
559
885
|
UpdateEmailTemplateDto,
|
|
560
886
|
EmailTemplateResponseDto,
|
|
887
|
+
EmailAttachmentDto,
|
|
561
888
|
SendEmailDto,
|
|
562
889
|
SendTemplateEmailDto,
|
|
563
890
|
TestEmailDto,
|
|
@@ -569,9 +896,25 @@ import {
|
|
|
569
896
|
IEmailProvider,
|
|
570
897
|
IEmailSendOptions,
|
|
571
898
|
IEmailSendResult,
|
|
899
|
+
IEmailAttachment,
|
|
900
|
+
IEmailProviderConfig,
|
|
572
901
|
IEmailConfig,
|
|
573
902
|
IEmailTemplate,
|
|
903
|
+
IEmailTemplateVariable,
|
|
904
|
+
IEmailSection,
|
|
905
|
+
IEmailSectionStyle,
|
|
906
|
+
IEmailBlock,
|
|
907
|
+
IEmailBlockStyle,
|
|
908
|
+
IEmailSettings,
|
|
909
|
+
IEmailSchema,
|
|
910
|
+
ISmtpConfig,
|
|
911
|
+
ISmtpTlsConfig,
|
|
912
|
+
ISendGridConfig,
|
|
913
|
+
IMailgunConfig,
|
|
914
|
+
IEmailModuleConfig,
|
|
574
915
|
EmailModuleOptions,
|
|
916
|
+
EmailModuleAsyncOptions,
|
|
917
|
+
EmailOptionsFactory,
|
|
575
918
|
} from '@flusys/nestjs-email/interfaces';
|
|
576
919
|
|
|
577
920
|
// Providers
|
|
@@ -582,8 +925,103 @@ import {
|
|
|
582
925
|
SendGridProvider,
|
|
583
926
|
MailgunProvider,
|
|
584
927
|
} from '@flusys/nestjs-email/providers';
|
|
928
|
+
|
|
929
|
+
// Controllers
|
|
930
|
+
import {
|
|
931
|
+
EmailConfigController,
|
|
932
|
+
EmailTemplateController,
|
|
933
|
+
EmailSendController,
|
|
934
|
+
} from '@flusys/nestjs-email/controllers';
|
|
935
|
+
|
|
936
|
+
// Enums
|
|
937
|
+
import { EmailProviderTypeEnum } from '@flusys/nestjs-email/enums';
|
|
938
|
+
|
|
939
|
+
// Constants
|
|
940
|
+
import {
|
|
941
|
+
EMAIL_MODULE_OPTIONS,
|
|
942
|
+
DEFAULT_FROM_NAME,
|
|
943
|
+
} from '@flusys/nestjs-email/config';
|
|
944
|
+
|
|
945
|
+
// Utilities
|
|
946
|
+
import {
|
|
947
|
+
getOtpEmailFormat,
|
|
948
|
+
getResetPasswordEmailFormat,
|
|
949
|
+
} from '@flusys/nestjs-email/utils';
|
|
950
|
+
|
|
951
|
+
// Swagger Config
|
|
952
|
+
import { emailSwaggerConfig } from '@flusys/nestjs-email/docs';
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
### Service Methods Reference
|
|
956
|
+
|
|
957
|
+
#### EmailConfigService
|
|
958
|
+
|
|
959
|
+
```typescript
|
|
960
|
+
class EmailConfigService {
|
|
961
|
+
isCompanyFeatureEnabled(): boolean;
|
|
962
|
+
getDatabaseMode(): DatabaseMode;
|
|
963
|
+
isMultiTenant(): boolean;
|
|
964
|
+
getDefaultFromName(): string;
|
|
965
|
+
getOptions(): EmailModuleOptions;
|
|
966
|
+
}
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
#### EmailProviderConfigService
|
|
970
|
+
|
|
971
|
+
```typescript
|
|
972
|
+
class EmailProviderConfigService {
|
|
973
|
+
// Standard CRUD (inherited from RequestScopedApiService)
|
|
974
|
+
insert(dto, user): Promise<EmailConfigBase>;
|
|
975
|
+
getById(id, user): Promise<EmailConfigBase | null>;
|
|
976
|
+
getAll(filterDto, user): Promise<{ list: EmailConfigBase[]; total: number }>;
|
|
977
|
+
update(dto, user): Promise<EmailConfigBase>;
|
|
978
|
+
delete(id, user): Promise<boolean>;
|
|
979
|
+
|
|
980
|
+
// Custom methods
|
|
981
|
+
findByIdDirect(id): Promise<EmailConfigBase | null>;
|
|
982
|
+
getDefaultConfig(user?): Promise<EmailConfigBase | null>;
|
|
983
|
+
getConfigByProvider(provider, user?): Promise<EmailConfigBase[]>;
|
|
984
|
+
}
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
#### EmailTemplateService
|
|
988
|
+
|
|
989
|
+
```typescript
|
|
990
|
+
class EmailTemplateService {
|
|
991
|
+
// Standard CRUD (inherited from RequestScopedApiService)
|
|
992
|
+
insert(dto, user): Promise<EmailTemplateBase>;
|
|
993
|
+
getById(id, user): Promise<EmailTemplateBase | null>;
|
|
994
|
+
getAll(filterDto, user): Promise<{ list: EmailTemplateBase[]; total: number }>;
|
|
995
|
+
update(dto, user): Promise<EmailTemplateBase>;
|
|
996
|
+
delete(id, user): Promise<boolean>;
|
|
997
|
+
|
|
998
|
+
// Custom methods
|
|
999
|
+
findByIdDirect(id): Promise<EmailTemplateBase | null>;
|
|
1000
|
+
findBySlug(slug, user?): Promise<EmailTemplateBase | null>;
|
|
1001
|
+
getActiveTemplates(user?): Promise<EmailTemplateBase[]>;
|
|
1002
|
+
}
|
|
1003
|
+
```
|
|
1004
|
+
|
|
1005
|
+
#### EmailSendService
|
|
1006
|
+
|
|
1007
|
+
```typescript
|
|
1008
|
+
class EmailSendService {
|
|
1009
|
+
sendEmail(dto: SendEmailDto, user?): Promise<IEmailSendResult>;
|
|
1010
|
+
sendTemplateEmail(dto: SendTemplateEmailDto, user?): Promise<IEmailSendResult>;
|
|
1011
|
+
sendTestEmail(emailConfigId, recipient, user?): Promise<IEmailSendResult>;
|
|
1012
|
+
}
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
#### EmailFactoryService
|
|
1016
|
+
|
|
1017
|
+
```typescript
|
|
1018
|
+
class EmailFactoryService {
|
|
1019
|
+
createProvider(config: IEmailProviderConfig): Promise<IEmailProvider>;
|
|
1020
|
+
// Providers are cached by config hash for reuse
|
|
1021
|
+
// Connections cleaned up on module destroy
|
|
1022
|
+
}
|
|
585
1023
|
```
|
|
586
1024
|
|
|
587
1025
|
---
|
|
588
1026
|
|
|
589
|
-
**Last Updated:** 2026-02-
|
|
1027
|
+
**Last Updated:** 2026-02-25
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// ─── Shared Styles ───────────────────────────────────────────────────────────
|
|
2
1
|
"use strict";
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
3
|
value: true
|
|
@@ -17,6 +16,7 @@ _export(exports, {
|
|
|
17
16
|
return getResetPasswordEmailFormat;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
19
|
+
// ─── Shared Styles ───────────────────────────────────────────────────────────
|
|
20
20
|
const BASE_STYLES = `
|
|
21
21
|
body { font-family: Arial, sans-serif; background-color: #f4f4f7; margin: 0; padding: 0; }
|
|
22
22
|
.email-container { max-width: 500px; margin: 40px auto; background-color: #ffffff; padding: 30px; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.1); text-align: center; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flusys/nestjs-email",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Modular email package with SMTP, SendGrid, and Mailgun providers",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "fesm/index.js",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
"dependencies": {
|
|
107
|
-
"@flusys/nestjs-core": "3.0.0
|
|
108
|
-
"@flusys/nestjs-shared": "3.0.0
|
|
107
|
+
"@flusys/nestjs-core": "3.0.0",
|
|
108
|
+
"@flusys/nestjs-shared": "3.0.0"
|
|
109
109
|
}
|
|
110
110
|
}
|