@flusys/nestjs-email 1.1.0-beta → 1.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/README.md +604 -0
- package/cjs/config/email.constants.js +0 -18
- package/cjs/config/index.js +0 -1
- package/cjs/controllers/email-config.controller.js +46 -4
- package/cjs/controllers/email-send.controller.js +13 -26
- package/cjs/controllers/email-template.controller.js +60 -11
- package/cjs/docs/email-swagger.config.js +18 -80
- package/cjs/dtos/email-config.dto.js +6 -106
- package/cjs/dtos/email-send.dto.js +101 -123
- package/cjs/dtos/email-template.dto.js +41 -103
- package/cjs/entities/email-config-with-company.entity.js +2 -2
- package/cjs/entities/email-config.entity.js +91 -3
- package/cjs/entities/email-template-with-company.entity.js +5 -3
- package/cjs/entities/email-template.entity.js +119 -3
- package/cjs/entities/index.js +34 -19
- package/cjs/index.js +1 -0
- package/cjs/interfaces/email-provider.interface.js +1 -3
- package/cjs/modules/email.module.js +50 -104
- package/cjs/providers/email-factory.service.js +37 -109
- package/cjs/providers/email-provider.registry.js +5 -15
- package/cjs/providers/mailgun-provider.js +54 -58
- package/cjs/providers/sendgrid-provider.js +68 -92
- package/cjs/providers/smtp-provider.js +58 -69
- package/cjs/{config → services}/email-config.service.js +9 -32
- package/cjs/services/email-datasource.provider.js +17 -104
- package/cjs/services/email-provider-config.service.js +28 -58
- package/cjs/services/email-send.service.js +120 -125
- package/cjs/services/email-template.service.js +62 -85
- package/cjs/services/index.js +2 -1
- package/cjs/utils/email-templates.util.js +64 -0
- package/cjs/utils/index.js +18 -0
- package/config/email.constants.d.ts +0 -9
- package/config/index.d.ts +0 -1
- package/controllers/email-send.controller.d.ts +5 -12
- package/controllers/email-template.controller.d.ts +5 -7
- package/dtos/email-config.dto.d.ts +5 -13
- package/dtos/email-send.dto.d.ts +17 -21
- package/dtos/email-template.dto.d.ts +5 -16
- package/entities/email-config-with-company.entity.d.ts +2 -2
- package/entities/email-config.entity.d.ts +9 -2
- package/entities/email-template-with-company.entity.d.ts +2 -2
- package/entities/email-template.entity.d.ts +13 -2
- package/entities/index.d.ts +9 -3
- package/fesm/config/email.constants.js +0 -9
- package/fesm/config/index.js +0 -1
- package/fesm/controllers/email-config.controller.js +49 -7
- package/fesm/controllers/email-send.controller.js +13 -26
- package/fesm/controllers/email-template.controller.js +61 -12
- package/fesm/docs/email-swagger.config.js +21 -86
- package/fesm/dtos/email-config.dto.js +9 -115
- package/fesm/dtos/email-send.dto.js +103 -139
- package/fesm/dtos/email-template.dto.js +43 -111
- package/fesm/entities/email-config-with-company.entity.js +2 -2
- package/fesm/entities/email-config.entity.js +92 -4
- package/fesm/entities/email-template-with-company.entity.js +5 -3
- package/fesm/entities/email-template.entity.js +120 -4
- package/fesm/entities/index.js +22 -16
- package/fesm/index.js +1 -0
- package/fesm/interfaces/email-config.interface.js +1 -3
- package/fesm/interfaces/email-module-options.interface.js +1 -3
- package/fesm/interfaces/email-provider.interface.js +1 -5
- package/fesm/interfaces/email-template.interface.js +1 -3
- package/fesm/modules/email.module.js +52 -106
- package/fesm/providers/email-factory.service.js +38 -69
- package/fesm/providers/email-provider.registry.js +6 -19
- package/fesm/providers/mailgun-provider.js +55 -63
- package/fesm/providers/sendgrid-provider.js +69 -97
- package/fesm/providers/smtp-provider.js +59 -73
- package/fesm/{config → services}/email-config.service.js +9 -32
- package/fesm/services/email-datasource.provider.js +18 -64
- package/fesm/services/email-provider-config.service.js +26 -56
- package/fesm/services/email-send.service.js +118 -123
- package/fesm/services/email-template.service.js +60 -83
- package/fesm/services/index.js +2 -1
- package/fesm/utils/email-templates.util.js +47 -0
- package/fesm/utils/index.js +1 -0
- package/index.d.ts +1 -0
- package/interfaces/email-config.interface.d.ts +6 -0
- package/interfaces/email-module-options.interface.d.ts +0 -5
- package/modules/email.module.d.ts +1 -2
- package/package.json +9 -4
- package/providers/email-factory.service.d.ts +4 -7
- package/providers/mailgun-provider.d.ts +6 -2
- package/providers/sendgrid-provider.d.ts +6 -2
- package/providers/smtp-provider.d.ts +7 -2
- package/services/email-config.service.d.ts +12 -0
- package/services/email-datasource.provider.d.ts +3 -6
- package/services/email-provider-config.service.d.ts +3 -3
- package/services/email-send.service.d.ts +11 -3
- package/services/email-template.service.d.ts +5 -4
- package/services/index.d.ts +2 -1
- package/utils/email-templates.util.d.ts +2 -0
- package/utils/index.d.ts +1 -0
- package/cjs/entities/email-config-base.entity.js +0 -111
- package/cjs/entities/email-template-base.entity.js +0 -134
- package/config/email-config.service.d.ts +0 -13
- package/entities/email-config-base.entity.d.ts +0 -11
- package/entities/email-template-base.entity.d.ts +0 -14
- package/fesm/entities/email-config-base.entity.js +0 -101
- package/fesm/entities/email-template-base.entity.js +0 -124
|
@@ -25,22 +25,64 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
28
|
+
import { createApiController, EMAIL_CONFIG_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
|
+
import { Controller, Inject } from '@nestjs/common';
|
|
30
|
+
import { ApiTags } from '@nestjs/swagger';
|
|
32
31
|
import { CreateEmailConfigDto, EmailConfigResponseDto, UpdateEmailConfigDto } from '../dtos';
|
|
33
32
|
import { EmailProviderConfigService } from '../services';
|
|
34
|
-
export class EmailConfigController extends createApiController(CreateEmailConfigDto, UpdateEmailConfigDto, EmailConfigResponseDto
|
|
33
|
+
export class EmailConfigController extends createApiController(CreateEmailConfigDto, UpdateEmailConfigDto, EmailConfigResponseDto, {
|
|
34
|
+
security: {
|
|
35
|
+
insert: {
|
|
36
|
+
level: 'permission',
|
|
37
|
+
permissions: [
|
|
38
|
+
EMAIL_CONFIG_PERMISSIONS.CREATE
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
insertMany: {
|
|
42
|
+
level: 'permission',
|
|
43
|
+
permissions: [
|
|
44
|
+
EMAIL_CONFIG_PERMISSIONS.CREATE
|
|
45
|
+
]
|
|
46
|
+
},
|
|
47
|
+
getById: {
|
|
48
|
+
level: 'permission',
|
|
49
|
+
permissions: [
|
|
50
|
+
EMAIL_CONFIG_PERMISSIONS.READ
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
getAll: {
|
|
54
|
+
level: 'permission',
|
|
55
|
+
permissions: [
|
|
56
|
+
EMAIL_CONFIG_PERMISSIONS.READ
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
update: {
|
|
60
|
+
level: 'permission',
|
|
61
|
+
permissions: [
|
|
62
|
+
EMAIL_CONFIG_PERMISSIONS.UPDATE
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
updateMany: {
|
|
66
|
+
level: 'permission',
|
|
67
|
+
permissions: [
|
|
68
|
+
EMAIL_CONFIG_PERMISSIONS.UPDATE
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
delete: {
|
|
72
|
+
level: 'permission',
|
|
73
|
+
permissions: [
|
|
74
|
+
EMAIL_CONFIG_PERMISSIONS.DELETE
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}) {
|
|
35
79
|
constructor(emailConfigService){
|
|
36
80
|
super(emailConfigService), _define_property(this, "emailConfigService", void 0), this.emailConfigService = emailConfigService;
|
|
37
81
|
}
|
|
38
82
|
}
|
|
39
83
|
EmailConfigController = _ts_decorate([
|
|
40
84
|
ApiTags('Email Config'),
|
|
41
|
-
ApiBearerAuth(),
|
|
42
85
|
Controller('email/email-config'),
|
|
43
|
-
UseGuards(JwtAuthGuard),
|
|
44
86
|
_ts_param(0, Inject(EmailProviderConfigService)),
|
|
45
87
|
_ts_metadata("design:type", Function),
|
|
46
88
|
_ts_metadata("design:paramtypes", [
|
|
@@ -25,46 +25,30 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
import { CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
|
|
28
29
|
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
29
|
-
import { CurrentUser } from '@flusys/nestjs-shared/decorators';
|
|
30
30
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
31
31
|
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
32
32
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
33
33
|
import { SendEmailDto, SendTemplateEmailDto, TestEmailDto } from '../dtos';
|
|
34
34
|
import { EmailSendService } from '../services';
|
|
35
35
|
export class EmailSendController {
|
|
36
|
-
|
|
37
|
-
* Send email directly (without template)
|
|
38
|
-
*/ async sendEmail(dto, user) {
|
|
36
|
+
async sendEmail(dto, user) {
|
|
39
37
|
const result = await this.emailSendService.sendEmail(dto, user);
|
|
40
|
-
return
|
|
41
|
-
success: result.success,
|
|
42
|
-
data: {
|
|
43
|
-
success: result.success,
|
|
44
|
-
messageId: result.messageId,
|
|
45
|
-
error: result.error
|
|
46
|
-
}
|
|
47
|
-
};
|
|
38
|
+
return this.toResponse(result, 'Email');
|
|
48
39
|
}
|
|
49
|
-
|
|
50
|
-
* Send email using template
|
|
51
|
-
*/ async sendTemplateEmail(dto, user) {
|
|
40
|
+
async sendTemplateEmail(dto, user) {
|
|
52
41
|
const result = await this.emailSendService.sendTemplateEmail(dto, user);
|
|
53
|
-
return
|
|
54
|
-
success: result.success,
|
|
55
|
-
data: {
|
|
56
|
-
success: result.success,
|
|
57
|
-
messageId: result.messageId,
|
|
58
|
-
error: result.error
|
|
59
|
-
}
|
|
60
|
-
};
|
|
42
|
+
return this.toResponse(result, 'Template email');
|
|
61
43
|
}
|
|
62
|
-
|
|
63
|
-
* Send test email (for testing configuration)
|
|
64
|
-
*/ async sendTestEmail(dto, user) {
|
|
44
|
+
async sendTestEmail(dto, user) {
|
|
65
45
|
const result = await this.emailSendService.sendTestEmail(dto.emailConfigId, dto.recipient, user);
|
|
46
|
+
return this.toResponse(result, 'Test email');
|
|
47
|
+
}
|
|
48
|
+
toResponse(result, label) {
|
|
66
49
|
return {
|
|
67
50
|
success: result.success,
|
|
51
|
+
message: result.success ? `${label} sent successfully` : `Failed to send ${label.toLowerCase()}`,
|
|
68
52
|
data: {
|
|
69
53
|
success: result.success,
|
|
70
54
|
messageId: result.messageId,
|
|
@@ -79,6 +63,7 @@ export class EmailSendController {
|
|
|
79
63
|
}
|
|
80
64
|
_ts_decorate([
|
|
81
65
|
Post('direct'),
|
|
66
|
+
RequirePermission('email.send'),
|
|
82
67
|
ApiOperation({
|
|
83
68
|
summary: 'Send email directly with custom content'
|
|
84
69
|
}),
|
|
@@ -93,6 +78,7 @@ _ts_decorate([
|
|
|
93
78
|
], EmailSendController.prototype, "sendEmail", null);
|
|
94
79
|
_ts_decorate([
|
|
95
80
|
Post('template'),
|
|
81
|
+
RequirePermission('email.send'),
|
|
96
82
|
ApiOperation({
|
|
97
83
|
summary: 'Send email using a template with variable interpolation'
|
|
98
84
|
}),
|
|
@@ -107,6 +93,7 @@ _ts_decorate([
|
|
|
107
93
|
], EmailSendController.prototype, "sendTemplateEmail", null);
|
|
108
94
|
_ts_decorate([
|
|
109
95
|
Post('test'),
|
|
96
|
+
RequirePermission('email.send'),
|
|
110
97
|
ApiOperation({
|
|
111
98
|
summary: 'Send a test email to verify configuration'
|
|
112
99
|
}),
|
|
@@ -25,22 +25,66 @@ function _ts_param(paramIndex, decorator) {
|
|
|
25
25
|
decorator(target, key, paramIndex);
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
+
import { createApiController, EMAIL_TEMPLATE_PERMISSIONS } from '@flusys/nestjs-shared/classes';
|
|
29
|
+
import { CurrentUser, RequirePermission } from '@flusys/nestjs-shared/decorators';
|
|
28
30
|
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
29
|
-
import { createApiController } from '@flusys/nestjs-shared/classes';
|
|
30
|
-
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
31
|
-
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
32
|
-
import { CurrentUser } from '@flusys/nestjs-shared/decorators';
|
|
33
31
|
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
32
|
+
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
33
|
+
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
34
34
|
import { CreateEmailTemplateDto, EmailTemplateResponseDto, UpdateEmailTemplateDto } from '../dtos';
|
|
35
35
|
import { EmailTemplateService } from '../services';
|
|
36
|
-
export class EmailTemplateController extends createApiController(CreateEmailTemplateDto, UpdateEmailTemplateDto, EmailTemplateResponseDto
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export class EmailTemplateController extends createApiController(CreateEmailTemplateDto, UpdateEmailTemplateDto, EmailTemplateResponseDto, {
|
|
37
|
+
security: {
|
|
38
|
+
insert: {
|
|
39
|
+
level: 'permission',
|
|
40
|
+
permissions: [
|
|
41
|
+
EMAIL_TEMPLATE_PERMISSIONS.CREATE
|
|
42
|
+
]
|
|
43
|
+
},
|
|
44
|
+
insertMany: {
|
|
45
|
+
level: 'permission',
|
|
46
|
+
permissions: [
|
|
47
|
+
EMAIL_TEMPLATE_PERMISSIONS.CREATE
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
getById: {
|
|
51
|
+
level: 'permission',
|
|
52
|
+
permissions: [
|
|
53
|
+
EMAIL_TEMPLATE_PERMISSIONS.READ
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
getAll: {
|
|
57
|
+
level: 'permission',
|
|
58
|
+
permissions: [
|
|
59
|
+
EMAIL_TEMPLATE_PERMISSIONS.READ
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
update: {
|
|
63
|
+
level: 'permission',
|
|
64
|
+
permissions: [
|
|
65
|
+
EMAIL_TEMPLATE_PERMISSIONS.UPDATE
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
updateMany: {
|
|
69
|
+
level: 'permission',
|
|
70
|
+
permissions: [
|
|
71
|
+
EMAIL_TEMPLATE_PERMISSIONS.UPDATE
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
delete: {
|
|
75
|
+
level: 'permission',
|
|
76
|
+
permissions: [
|
|
77
|
+
EMAIL_TEMPLATE_PERMISSIONS.DELETE
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}) {
|
|
82
|
+
async getBySlug(body, user) {
|
|
83
|
+
const data = await this.emailTemplateService.findBySlug(body.slug, user);
|
|
41
84
|
return {
|
|
42
85
|
success: true,
|
|
43
|
-
|
|
86
|
+
message: 'Template retrieved',
|
|
87
|
+
data: data ?? undefined
|
|
44
88
|
};
|
|
45
89
|
}
|
|
46
90
|
constructor(emailTemplateService){
|
|
@@ -49,9 +93,16 @@ export class EmailTemplateController extends createApiController(CreateEmailTemp
|
|
|
49
93
|
}
|
|
50
94
|
_ts_decorate([
|
|
51
95
|
Post('get-by-slug'),
|
|
96
|
+
UseGuards(JwtAuthGuard),
|
|
97
|
+
ApiBearerAuth(),
|
|
98
|
+
RequirePermission(EMAIL_TEMPLATE_PERMISSIONS.READ),
|
|
52
99
|
ApiOperation({
|
|
53
100
|
summary: 'Get email template by slug'
|
|
54
101
|
}),
|
|
102
|
+
ApiResponse({
|
|
103
|
+
status: 200,
|
|
104
|
+
type: EmailTemplateResponseDto
|
|
105
|
+
}),
|
|
55
106
|
_ts_param(0, Body()),
|
|
56
107
|
_ts_param(1, CurrentUser()),
|
|
57
108
|
_ts_metadata("design:type", Function),
|
|
@@ -63,9 +114,7 @@ _ts_decorate([
|
|
|
63
114
|
], EmailTemplateController.prototype, "getBySlug", null);
|
|
64
115
|
EmailTemplateController = _ts_decorate([
|
|
65
116
|
ApiTags('Email Template'),
|
|
66
|
-
ApiBearerAuth(),
|
|
67
117
|
Controller('email/email-template'),
|
|
68
|
-
UseGuards(JwtAuthGuard),
|
|
69
118
|
_ts_param(0, Inject(EmailTemplateService)),
|
|
70
119
|
_ts_metadata("design:type", Function),
|
|
71
120
|
_ts_metadata("design:paramtypes", [
|
|
@@ -12,108 +12,34 @@
|
|
|
12
12
|
]
|
|
13
13
|
}
|
|
14
14
|
];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* @param bootstrapConfig - Bootstrap configuration to determine feature visibility
|
|
20
|
-
* @returns Swagger configuration with appropriate excludeSchemaProperties based on enableCompanyFeature
|
|
21
|
-
*/ export function emailSwaggerConfig(bootstrapConfig) {
|
|
22
|
-
const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
|
|
23
|
-
return {
|
|
24
|
-
title: 'Email API',
|
|
25
|
-
description: enableCompanyFeature ? `
|
|
26
|
-
# Email Management API
|
|
27
|
-
|
|
28
|
-
Complete email management system with multi-tenant and company support.
|
|
29
|
-
|
|
30
|
-
## Features
|
|
31
|
-
|
|
32
|
-
### 📧 Email Configuration
|
|
33
|
-
- Multiple email providers (SMTP, SendGrid, Mailgun)
|
|
34
|
-
- Provider-specific configurations
|
|
35
|
-
- Default sender settings
|
|
36
|
-
- **Company-level email configs**
|
|
37
|
-
|
|
38
|
-
### 📝 Email Templates
|
|
39
|
-
- Visual template builder
|
|
40
|
-
- Variable interpolation ({{variable}})
|
|
41
|
-
- HTML and plain text support
|
|
42
|
-
- Template versioning
|
|
43
|
-
- **Company isolation**
|
|
44
|
-
|
|
45
|
-
### ✉️ Email Sending
|
|
46
|
-
- Direct email sending
|
|
47
|
-
- Template-based sending
|
|
48
|
-
- Attachments support
|
|
49
|
-
- CC/BCC recipients
|
|
50
|
-
|
|
51
|
-
### 🔒 Security
|
|
52
|
-
- JWT authentication required
|
|
53
|
-
- **Company isolation**
|
|
54
|
-
- Secure credential storage
|
|
55
|
-
|
|
56
|
-
## Supported Providers
|
|
57
|
-
|
|
58
|
-
### SMTP
|
|
59
|
-
- Universal email protocol
|
|
60
|
-
- Custom server support
|
|
61
|
-
- TLS/SSL encryption
|
|
62
|
-
|
|
63
|
-
### SendGrid (optional)
|
|
64
|
-
- Cloud email service
|
|
65
|
-
- High deliverability
|
|
66
|
-
- Install: \`npm install @sendgrid/mail\`
|
|
67
|
-
|
|
68
|
-
### Mailgun (optional)
|
|
69
|
-
- Developer-friendly API
|
|
70
|
-
- Detailed analytics
|
|
71
|
-
- Install: \`npm install mailgun.js\`
|
|
72
|
-
|
|
73
|
-
## Template Variables
|
|
74
|
-
|
|
75
|
-
Templates support Handlebars-style variables:
|
|
76
|
-
- \`{{userName}}\` - Simple variable
|
|
77
|
-
- \`{{user.email}}\` - Nested properties
|
|
78
|
-
- Variables are replaced at send time
|
|
79
|
-
|
|
15
|
+
function buildDescription(enableCompanyFeature) {
|
|
16
|
+
const companyConfigs = enableCompanyFeature ? '\n- **Company-level email configs**' : '';
|
|
17
|
+
const companyIsolation = enableCompanyFeature ? '\n- **Company isolation**' : '';
|
|
18
|
+
const multiTenantSection = enableCompanyFeature ? `
|
|
80
19
|
## Multi-Tenant Support
|
|
81
20
|
|
|
82
21
|
Emails are automatically isolated by:
|
|
83
22
|
- **Company ID**: Company-level templates and configs
|
|
84
23
|
|
|
85
24
|
All queries automatically filter by current user's company context.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
All email endpoints are prefixed with \`/email\`:
|
|
90
|
-
- \`/email/email-config/*\` - Email provider configurations
|
|
91
|
-
- \`/email/email-template/*\` - Email templates
|
|
92
|
-
- \`/email/email-send/*\` - Send emails
|
|
93
|
-
|
|
94
|
-
## Getting Started
|
|
95
|
-
|
|
96
|
-
1. **Authenticate**: Obtain JWT token from /auth/login
|
|
97
|
-
2. **Configure Provider**: Create email config via /email/email-config/insert
|
|
98
|
-
3. **Create Templates**: Add templates via /email/email-template/insert
|
|
99
|
-
4. **Send Emails**: Send via /email/email-send/send or /email/email-send/send-template
|
|
100
|
-
` : `
|
|
25
|
+
` : '';
|
|
26
|
+
return `
|
|
101
27
|
# Email Management API
|
|
102
28
|
|
|
103
|
-
Complete email management system.
|
|
29
|
+
Complete email management system${enableCompanyFeature ? ' with multi-tenant and company support' : ''}.
|
|
104
30
|
|
|
105
31
|
## Features
|
|
106
32
|
|
|
107
33
|
### 📧 Email Configuration
|
|
108
34
|
- Multiple email providers (SMTP, SendGrid, Mailgun)
|
|
109
35
|
- Provider-specific configurations
|
|
110
|
-
- Default sender settings
|
|
36
|
+
- Default sender settings${companyConfigs}
|
|
111
37
|
|
|
112
38
|
### 📝 Email Templates
|
|
113
39
|
- Visual template builder
|
|
114
40
|
- Variable interpolation ({{variable}})
|
|
115
41
|
- HTML and plain text support
|
|
116
|
-
- Template versioning
|
|
42
|
+
- Template versioning${companyIsolation}
|
|
117
43
|
|
|
118
44
|
### ✉️ Email Sending
|
|
119
45
|
- Direct email sending
|
|
@@ -122,7 +48,7 @@ Complete email management system.
|
|
|
122
48
|
- CC/BCC recipients
|
|
123
49
|
|
|
124
50
|
### 🔒 Security
|
|
125
|
-
- JWT authentication required
|
|
51
|
+
- JWT authentication required${companyIsolation}
|
|
126
52
|
- Secure credential storage
|
|
127
53
|
|
|
128
54
|
## Supported Providers
|
|
@@ -148,7 +74,7 @@ Templates support Handlebars-style variables:
|
|
|
148
74
|
- \`{{userName}}\` - Simple variable
|
|
149
75
|
- \`{{user.email}}\` - Nested properties
|
|
150
76
|
- Variables are replaced at send time
|
|
151
|
-
|
|
77
|
+
${multiTenantSection}
|
|
152
78
|
## API Endpoints
|
|
153
79
|
|
|
154
80
|
All email endpoints are prefixed with \`/email\`:
|
|
@@ -162,7 +88,16 @@ All email endpoints are prefixed with \`/email\`:
|
|
|
162
88
|
2. **Configure Provider**: Create email config via /email/email-config/insert
|
|
163
89
|
3. **Create Templates**: Add templates via /email/email-template/insert
|
|
164
90
|
4. **Send Emails**: Send via /email/email-send/send or /email/email-send/send-template
|
|
165
|
-
|
|
91
|
+
`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Email Module Swagger Configuration
|
|
95
|
+
* Use this with setupSwaggerDocs() from @flusys/nestjs-core
|
|
96
|
+
*/ export function emailSwaggerConfig(bootstrapConfig) {
|
|
97
|
+
const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
|
|
98
|
+
return {
|
|
99
|
+
title: 'Email API',
|
|
100
|
+
description: buildDescription(enableCompanyFeature),
|
|
166
101
|
version: '1.0',
|
|
167
102
|
path: 'api/docs/email',
|
|
168
103
|
bearerAuth: true,
|
|
@@ -21,12 +21,10 @@ function _ts_metadata(k, v) {
|
|
|
21
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
22
|
}
|
|
23
23
|
import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
|
|
24
|
-
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
24
|
+
import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
|
|
25
25
|
import { IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, MaxLength } from 'class-validator';
|
|
26
26
|
import { EmailProviderTypeEnum } from '../enums';
|
|
27
|
-
|
|
28
|
-
* DTO for creating email configuration
|
|
29
|
-
*/ export class CreateEmailConfigDto {
|
|
27
|
+
export class CreateEmailConfigDto {
|
|
30
28
|
constructor(){
|
|
31
29
|
_define_property(this, "name", void 0);
|
|
32
30
|
_define_property(this, "provider", void 0);
|
|
@@ -49,8 +47,7 @@ _ts_decorate([
|
|
|
49
47
|
_ts_decorate([
|
|
50
48
|
ApiProperty({
|
|
51
49
|
enum: EmailProviderTypeEnum,
|
|
52
|
-
example: EmailProviderTypeEnum.SMTP
|
|
53
|
-
description: 'Email provider type'
|
|
50
|
+
example: EmailProviderTypeEnum.SMTP
|
|
54
51
|
}),
|
|
55
52
|
IsEnum(EmailProviderTypeEnum),
|
|
56
53
|
IsNotEmpty(),
|
|
@@ -59,38 +56,8 @@ _ts_decorate([
|
|
|
59
56
|
_ts_decorate([
|
|
60
57
|
ApiProperty({
|
|
61
58
|
type: 'object',
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
type: 'string',
|
|
65
|
-
example: 'smtp.gmail.com',
|
|
66
|
-
description: 'SMTP host'
|
|
67
|
-
},
|
|
68
|
-
port: {
|
|
69
|
-
type: 'number',
|
|
70
|
-
example: 587,
|
|
71
|
-
description: 'SMTP port'
|
|
72
|
-
},
|
|
73
|
-
secure: {
|
|
74
|
-
type: 'boolean',
|
|
75
|
-
example: false,
|
|
76
|
-
description: 'Use TLS'
|
|
77
|
-
},
|
|
78
|
-
auth: {
|
|
79
|
-
type: 'object',
|
|
80
|
-
properties: {
|
|
81
|
-
user: {
|
|
82
|
-
type: 'string',
|
|
83
|
-
example: 'user@gmail.com'
|
|
84
|
-
},
|
|
85
|
-
pass: {
|
|
86
|
-
type: 'string',
|
|
87
|
-
example: 'app-password'
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
additionalProperties: true,
|
|
93
|
-
description: 'Provider-specific configuration'
|
|
59
|
+
description: 'Provider-specific configuration (SMTP: host, port, secure, auth)',
|
|
60
|
+
additionalProperties: true
|
|
94
61
|
}),
|
|
95
62
|
IsObject(),
|
|
96
63
|
IsNotEmpty(),
|
|
@@ -130,18 +97,9 @@ _ts_decorate([
|
|
|
130
97
|
IsOptional(),
|
|
131
98
|
_ts_metadata("design:type", Boolean)
|
|
132
99
|
], CreateEmailConfigDto.prototype, "isDefault", void 0);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
constructor(){
|
|
137
|
-
_define_property(this, "id", void 0);
|
|
138
|
-
_define_property(this, "name", void 0);
|
|
139
|
-
_define_property(this, "provider", void 0);
|
|
140
|
-
_define_property(this, "config", void 0);
|
|
141
|
-
_define_property(this, "fromEmail", void 0);
|
|
142
|
-
_define_property(this, "fromName", void 0);
|
|
143
|
-
_define_property(this, "isActive", void 0);
|
|
144
|
-
_define_property(this, "isDefault", void 0);
|
|
100
|
+
export class UpdateEmailConfigDto extends PartialType(CreateEmailConfigDto) {
|
|
101
|
+
constructor(...args){
|
|
102
|
+
super(...args), _define_property(this, "id", void 0);
|
|
145
103
|
}
|
|
146
104
|
}
|
|
147
105
|
_ts_decorate([
|
|
@@ -152,71 +110,7 @@ _ts_decorate([
|
|
|
152
110
|
IsNotEmpty(),
|
|
153
111
|
_ts_metadata("design:type", String)
|
|
154
112
|
], UpdateEmailConfigDto.prototype, "id", void 0);
|
|
155
|
-
|
|
156
|
-
ApiPropertyOptional({
|
|
157
|
-
example: 'Production SMTP'
|
|
158
|
-
}),
|
|
159
|
-
IsString(),
|
|
160
|
-
IsOptional(),
|
|
161
|
-
MaxLength(255),
|
|
162
|
-
_ts_metadata("design:type", String)
|
|
163
|
-
], UpdateEmailConfigDto.prototype, "name", void 0);
|
|
164
|
-
_ts_decorate([
|
|
165
|
-
ApiPropertyOptional({
|
|
166
|
-
enum: EmailProviderTypeEnum,
|
|
167
|
-
example: EmailProviderTypeEnum.SMTP
|
|
168
|
-
}),
|
|
169
|
-
IsEnum(EmailProviderTypeEnum),
|
|
170
|
-
IsOptional(),
|
|
171
|
-
_ts_metadata("design:type", typeof EmailProviderTypeEnum === "undefined" ? Object : EmailProviderTypeEnum)
|
|
172
|
-
], UpdateEmailConfigDto.prototype, "provider", void 0);
|
|
173
|
-
_ts_decorate([
|
|
174
|
-
ApiPropertyOptional({
|
|
175
|
-
type: 'object',
|
|
176
|
-
additionalProperties: true,
|
|
177
|
-
description: 'Provider-specific configuration'
|
|
178
|
-
}),
|
|
179
|
-
IsObject(),
|
|
180
|
-
IsOptional(),
|
|
181
|
-
_ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
|
|
182
|
-
], UpdateEmailConfigDto.prototype, "config", void 0);
|
|
183
|
-
_ts_decorate([
|
|
184
|
-
ApiPropertyOptional({
|
|
185
|
-
example: 'noreply@example.com'
|
|
186
|
-
}),
|
|
187
|
-
IsEmail(),
|
|
188
|
-
IsOptional(),
|
|
189
|
-
_ts_metadata("design:type", String)
|
|
190
|
-
], UpdateEmailConfigDto.prototype, "fromEmail", void 0);
|
|
191
|
-
_ts_decorate([
|
|
192
|
-
ApiPropertyOptional({
|
|
193
|
-
example: 'FLUSYS'
|
|
194
|
-
}),
|
|
195
|
-
IsString(),
|
|
196
|
-
IsOptional(),
|
|
197
|
-
MaxLength(255),
|
|
198
|
-
_ts_metadata("design:type", String)
|
|
199
|
-
], UpdateEmailConfigDto.prototype, "fromName", void 0);
|
|
200
|
-
_ts_decorate([
|
|
201
|
-
ApiPropertyOptional({
|
|
202
|
-
example: true
|
|
203
|
-
}),
|
|
204
|
-
IsBoolean(),
|
|
205
|
-
IsOptional(),
|
|
206
|
-
_ts_metadata("design:type", Boolean)
|
|
207
|
-
], UpdateEmailConfigDto.prototype, "isActive", void 0);
|
|
208
|
-
_ts_decorate([
|
|
209
|
-
ApiPropertyOptional({
|
|
210
|
-
example: false,
|
|
211
|
-
description: 'Set as default email configuration'
|
|
212
|
-
}),
|
|
213
|
-
IsBoolean(),
|
|
214
|
-
IsOptional(),
|
|
215
|
-
_ts_metadata("design:type", Boolean)
|
|
216
|
-
], UpdateEmailConfigDto.prototype, "isDefault", void 0);
|
|
217
|
-
/**
|
|
218
|
-
* Response DTO for email configuration
|
|
219
|
-
*/ export class EmailConfigResponseDto extends IdentityResponseDto {
|
|
113
|
+
export class EmailConfigResponseDto extends IdentityResponseDto {
|
|
220
114
|
constructor(...args){
|
|
221
115
|
super(...args), _define_property(this, "name", void 0), _define_property(this, "provider", void 0), _define_property(this, "config", void 0), _define_property(this, "fromEmail", void 0), _define_property(this, "fromName", void 0), _define_property(this, "isActive", void 0), _define_property(this, "isDefault", void 0);
|
|
222
116
|
}
|