@flusys/nestjs-email 7.1.0 → 8.0.0-beta.1

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.
Files changed (159) hide show
  1. package/config/index.d.ts +3 -3
  2. package/controllers/email-config.controller.d.ts +2 -2
  3. package/controllers/email-send.controller.d.ts +3 -3
  4. package/controllers/email-template.controller.d.ts +4 -4
  5. package/controllers/index.d.ts +3 -3
  6. package/docs/email-swagger.config.d.ts +2 -2
  7. package/docs/index.d.ts +1 -1
  8. package/dtos/email-config.dto.d.ts +1 -1
  9. package/dtos/email-send.dto.d.ts +1 -1
  10. package/dtos/index.d.ts +3 -3
  11. package/entities/email-config-with-company.entity.d.ts +1 -1
  12. package/entities/email-template-with-company.entity.d.ts +1 -1
  13. package/entities/index.d.ts +10 -10
  14. package/enums/index.d.ts +1 -1
  15. package/fesm/261.js +799 -0
  16. package/fesm/493.js +1723 -0
  17. package/fesm/chunks/99.js +12 -0
  18. package/fesm/config/index.js +104 -3
  19. package/fesm/controllers/index.js +396 -3
  20. package/fesm/docs/index.js +134 -1
  21. package/fesm/dtos/index.js +22 -3
  22. package/fesm/entities/index.js +409 -13
  23. package/fesm/enums/index.js +37 -1
  24. package/fesm/index.js +762 -10
  25. package/fesm/interfaces/index.js +18 -4
  26. package/fesm/modules/index.js +541 -1
  27. package/fesm/providers/index.js +523 -5
  28. package/fesm/runtime.js +134 -0
  29. package/fesm/services/index.js +17 -5
  30. package/index.d.ts +10 -10
  31. package/interfaces/email-config.interface.d.ts +2 -2
  32. package/interfaces/email-module-options.interface.d.ts +3 -3
  33. package/interfaces/email-template.interface.d.ts +1 -1
  34. package/interfaces/index.d.ts +4 -4
  35. package/modules/email.module.d.ts +2 -2
  36. package/modules/index.d.ts +1 -1
  37. package/package.json +27 -38
  38. package/providers/email-factory.service.d.ts +2 -2
  39. package/providers/email-provider.registry.d.ts +2 -2
  40. package/providers/index.d.ts +5 -5
  41. package/providers/mailgun-provider.d.ts +1 -1
  42. package/providers/sendgrid-provider.d.ts +1 -1
  43. package/providers/smtp-provider.d.ts +1 -1
  44. package/services/email-config.service.d.ts +3 -3
  45. package/services/email-datasource.provider.d.ts +3 -3
  46. package/services/email-provider-config.service.d.ts +7 -7
  47. package/services/email-send.service.d.ts +7 -7
  48. package/services/email-template.service.d.ts +6 -6
  49. package/services/index.d.ts +5 -5
  50. package/utils/index.d.ts +1 -1
  51. package/cjs/config/email.constants.js +0 -22
  52. package/cjs/config/event-actions.js +0 -34
  53. package/cjs/config/index.js +0 -20
  54. package/cjs/config/message-keys.js +0 -39
  55. package/cjs/controllers/email-config.controller.js +0 -111
  56. package/cjs/controllers/email-config.controller.spec.js +0 -85
  57. package/cjs/controllers/email-send.controller.js +0 -128
  58. package/cjs/controllers/email-send.controller.spec.js +0 -139
  59. package/cjs/controllers/email-template.controller.js +0 -142
  60. package/cjs/controllers/email-template.controller.spec.js +0 -89
  61. package/cjs/controllers/index.js +0 -20
  62. package/cjs/docs/email-swagger.config.js +0 -116
  63. package/cjs/docs/email-swagger.config.spec.js +0 -62
  64. package/cjs/docs/index.js +0 -11
  65. package/cjs/dtos/email-config.dto.js +0 -212
  66. package/cjs/dtos/email-send.dto.js +0 -354
  67. package/cjs/dtos/email-template.dto.js +0 -252
  68. package/cjs/dtos/index.js +0 -20
  69. package/cjs/entities/email-config-with-company.entity.js +0 -63
  70. package/cjs/entities/email-config.entity.js +0 -114
  71. package/cjs/entities/email-template-with-company.entity.js +0 -65
  72. package/cjs/entities/email-template.entity.js +0 -136
  73. package/cjs/entities/index.js +0 -56
  74. package/cjs/entities/index.spec.js +0 -18
  75. package/cjs/enums/email-provider-type.enum.js +0 -18
  76. package/cjs/enums/index.js +0 -18
  77. package/cjs/index.js +0 -28
  78. package/cjs/interfaces/email-config.interface.js +0 -4
  79. package/cjs/interfaces/email-module-options.interface.js +0 -4
  80. package/cjs/interfaces/email-provider.interface.js +0 -4
  81. package/cjs/interfaces/email-template.interface.js +0 -4
  82. package/cjs/interfaces/index.js +0 -21
  83. package/cjs/modules/email.module.js +0 -122
  84. package/cjs/modules/email.module.spec.js +0 -142
  85. package/cjs/modules/index.js +0 -18
  86. package/cjs/providers/email-factory.service.js +0 -113
  87. package/cjs/providers/email-factory.service.spec.js +0 -242
  88. package/cjs/providers/email-provider.registry.js +0 -41
  89. package/cjs/providers/email-provider.registry.spec.js +0 -58
  90. package/cjs/providers/index.js +0 -22
  91. package/cjs/providers/mailgun-provider.js +0 -119
  92. package/cjs/providers/mailgun-provider.spec.js +0 -244
  93. package/cjs/providers/sendgrid-provider.js +0 -129
  94. package/cjs/providers/sendgrid-provider.spec.js +0 -346
  95. package/cjs/providers/smtp-provider.js +0 -164
  96. package/cjs/providers/smtp-provider.spec.js +0 -327
  97. package/cjs/services/email-config.service.js +0 -71
  98. package/cjs/services/email-config.service.spec.js +0 -69
  99. package/cjs/services/email-datasource.provider.js +0 -84
  100. package/cjs/services/email-datasource.provider.spec.js +0 -135
  101. package/cjs/services/email-provider-config.service.js +0 -159
  102. package/cjs/services/email-provider-config.service.spec.js +0 -269
  103. package/cjs/services/email-send.service.js +0 -315
  104. package/cjs/services/email-send.service.spec.js +0 -614
  105. package/cjs/services/email-template.service.js +0 -144
  106. package/cjs/services/email-template.service.spec.js +0 -261
  107. package/cjs/services/index.js +0 -22
  108. package/cjs/utils/email-templates.util.js +0 -64
  109. package/cjs/utils/email-templates.util.spec.js +0 -61
  110. package/cjs/utils/index.js +0 -18
  111. package/fesm/config/email.constants.js +0 -4
  112. package/fesm/config/event-actions.js +0 -13
  113. package/fesm/config/message-keys.js +0 -18
  114. package/fesm/controllers/email-config.controller.js +0 -101
  115. package/fesm/controllers/email-config.controller.spec.js +0 -81
  116. package/fesm/controllers/email-send.controller.js +0 -118
  117. package/fesm/controllers/email-send.controller.spec.js +0 -135
  118. package/fesm/controllers/email-template.controller.js +0 -132
  119. package/fesm/controllers/email-template.controller.spec.js +0 -85
  120. package/fesm/docs/email-swagger.config.js +0 -109
  121. package/fesm/docs/email-swagger.config.spec.js +0 -58
  122. package/fesm/dtos/email-config.dto.js +0 -191
  123. package/fesm/dtos/email-send.dto.js +0 -324
  124. package/fesm/dtos/email-template.dto.js +0 -231
  125. package/fesm/entities/email-config-with-company.entity.js +0 -53
  126. package/fesm/entities/email-config.entity.js +0 -104
  127. package/fesm/entities/email-template-with-company.entity.js +0 -55
  128. package/fesm/entities/email-template.entity.js +0 -126
  129. package/fesm/entities/index.spec.js +0 -14
  130. package/fesm/enums/email-provider-type.enum.js +0 -8
  131. package/fesm/interfaces/email-config.interface.js +0 -1
  132. package/fesm/interfaces/email-module-options.interface.js +0 -1
  133. package/fesm/interfaces/email-provider.interface.js +0 -1
  134. package/fesm/interfaces/email-template.interface.js +0 -1
  135. package/fesm/modules/email.module.js +0 -112
  136. package/fesm/modules/email.module.spec.js +0 -138
  137. package/fesm/providers/email-factory.service.js +0 -103
  138. package/fesm/providers/email-factory.service.spec.js +0 -238
  139. package/fesm/providers/email-provider.registry.js +0 -31
  140. package/fesm/providers/email-provider.registry.spec.js +0 -54
  141. package/fesm/providers/mailgun-provider.js +0 -109
  142. package/fesm/providers/mailgun-provider.spec.js +0 -240
  143. package/fesm/providers/sendgrid-provider.js +0 -119
  144. package/fesm/providers/sendgrid-provider.spec.js +0 -342
  145. package/fesm/providers/smtp-provider.js +0 -113
  146. package/fesm/providers/smtp-provider.spec.js +0 -282
  147. package/fesm/services/email-config.service.js +0 -61
  148. package/fesm/services/email-config.service.spec.js +0 -65
  149. package/fesm/services/email-datasource.provider.js +0 -74
  150. package/fesm/services/email-datasource.provider.spec.js +0 -131
  151. package/fesm/services/email-provider-config.service.js +0 -149
  152. package/fesm/services/email-provider-config.service.spec.js +0 -265
  153. package/fesm/services/email-send.service.js +0 -305
  154. package/fesm/services/email-send.service.spec.js +0 -610
  155. package/fesm/services/email-template.service.js +0 -134
  156. package/fesm/services/email-template.service.spec.js +0 -257
  157. package/fesm/utils/email-templates.util.js +0 -47
  158. package/fesm/utils/email-templates.util.spec.js +0 -57
  159. package/fesm/utils/index.js +0 -1
@@ -1,109 +0,0 @@
1
- /** Schema properties to exclude when company feature is disabled */ const COMPANY_SCHEMA_EXCLUSIONS = [
2
- {
3
- schemaName: 'EmailConfigResponseDto',
4
- properties: [
5
- 'companyId'
6
- ]
7
- },
8
- {
9
- schemaName: 'EmailTemplateResponseDto',
10
- properties: [
11
- 'companyId'
12
- ]
13
- }
14
- ];
15
- function buildDescription(enableCompanyFeature, isMultiTenant) {
16
- const multiTenantNote = isMultiTenant ? `\n> **Multi-Tenant Mode**: Include \`x-tenant-id\` header to target a specific tenant database.\n` : '';
17
- const companyConfigs = enableCompanyFeature ? '\n- **Company-level email configs**' : '';
18
- const companyIsolation = enableCompanyFeature ? '\n- **Company isolation**' : '';
19
- const multiTenantSection = enableCompanyFeature ? `
20
- ## Multi-Tenant Support
21
-
22
- Emails are automatically isolated by:
23
- - **Company ID**: Company-level templates and configs
24
-
25
- All queries automatically filter by current user's company context.
26
- ` : '';
27
- return `
28
- # Email Management API
29
- ${multiTenantNote}
30
- Complete email management system${enableCompanyFeature ? ' with multi-tenant and company support' : ''}.
31
-
32
- ## Features
33
-
34
- ### 📧 Email Configuration
35
- - Multiple email providers (SMTP, SendGrid, Mailgun)
36
- - Provider-specific configurations
37
- - Default sender settings${companyConfigs}
38
-
39
- ### 📝 Email Templates
40
- - Visual template builder
41
- - Variable interpolation ({{variable}})
42
- - HTML and plain text support
43
- - Template versioning${companyIsolation}
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${companyIsolation}
53
- - Secure credential storage
54
-
55
- ## Supported Providers
56
-
57
- ### SMTP
58
- - Universal email protocol
59
- - Custom server support
60
- - TLS/SSL encryption
61
-
62
- ### SendGrid (optional)
63
- - Cloud email service
64
- - High deliverability
65
- - Install: \`npm install @sendgrid/mail\`
66
-
67
- ### Mailgun (optional)
68
- - Developer-friendly API
69
- - Detailed analytics
70
- - Install: \`npm install mailgun.js\`
71
-
72
- ## Template Variables
73
-
74
- Templates support Handlebars-style variables:
75
- - \`{{userName}}\` - Simple variable
76
- - \`{{user.email}}\` - Nested properties
77
- - Variables are replaced at send time
78
- ${multiTenantSection}
79
- ## API Endpoints
80
-
81
- All email endpoints are prefixed with \`/email\`:
82
- - \`/email/email-config/*\` - Email provider configurations
83
- - \`/email/email-template/*\` - Email templates
84
- - \`/email/email-send/*\` - Send emails
85
-
86
- ## Getting Started
87
-
88
- 1. **Authenticate**: Obtain JWT token from /auth/login
89
- 2. **Configure Provider**: Create email config via /email/email-config/insert
90
- 3. **Create Templates**: Add templates via /email/email-template/insert
91
- 4. **Send Emails**: Send via /email/email-send/send or /email/email-send/send-template
92
- `;
93
- }
94
- /**
95
- * Email Module Swagger Configuration
96
- * Use this with setupSwaggerDocs() from @flusys/nestjs-core
97
- */ export function emailSwaggerConfig(bootstrapConfig) {
98
- const enableCompanyFeature = bootstrapConfig?.enableCompanyFeature ?? true;
99
- const isMultiTenant = bootstrapConfig?.databaseMode === 'multi-tenant';
100
- return {
101
- title: 'Email API',
102
- description: buildDescription(enableCompanyFeature, isMultiTenant),
103
- version: '1.0',
104
- path: 'api/docs/email',
105
- bearerAuth: true,
106
- excludeTags: [],
107
- excludeSchemaProperties: enableCompanyFeature ? undefined : COMPANY_SCHEMA_EXCLUSIONS
108
- };
109
- }
@@ -1,58 +0,0 @@
1
- import { emailSwaggerConfig } from './email-swagger.config';
2
- describe('emailSwaggerConfig', ()=>{
3
- it('should default to company feature enabled and single-database mode when no config is given', ()=>{
4
- const config = emailSwaggerConfig();
5
- expect(config.title).toBe('Email API');
6
- expect(config.bearerAuth).toBe(true);
7
- expect(config.excludeSchemaProperties).toBeUndefined();
8
- expect(config.description).not.toContain('Multi-Tenant Mode');
9
- });
10
- it('should exclude companyId schema properties when the company feature is disabled', ()=>{
11
- const config = emailSwaggerConfig({
12
- enableCompanyFeature: false
13
- });
14
- expect(config.excludeSchemaProperties).toEqual([
15
- {
16
- schemaName: 'EmailConfigResponseDto',
17
- properties: [
18
- 'companyId'
19
- ]
20
- },
21
- {
22
- schemaName: 'EmailTemplateResponseDto',
23
- properties: [
24
- 'companyId'
25
- ]
26
- }
27
- ]);
28
- });
29
- it('should not exclude any schema properties when the company feature is enabled', ()=>{
30
- const config = emailSwaggerConfig({
31
- enableCompanyFeature: true
32
- });
33
- expect(config.excludeSchemaProperties).toBeUndefined();
34
- });
35
- it('should describe company isolation and multi-tenant support only when the company feature is enabled', ()=>{
36
- const withCompany = emailSwaggerConfig({
37
- enableCompanyFeature: true
38
- });
39
- const withoutCompany = emailSwaggerConfig({
40
- enableCompanyFeature: false
41
- });
42
- expect(withCompany.description).toContain('Company isolation');
43
- expect(withCompany.description).toContain('## Multi-Tenant Support');
44
- expect(withCompany.description).toContain('with multi-tenant and company support');
45
- expect(withoutCompany.description).not.toContain('Company isolation');
46
- expect(withoutCompany.description).not.toContain('## Multi-Tenant Support');
47
- });
48
- it('should mention multi-tenant mode in the description only for multi-tenant database mode', ()=>{
49
- const multiTenant = emailSwaggerConfig({
50
- databaseMode: 'multi-tenant'
51
- });
52
- const single = emailSwaggerConfig({
53
- databaseMode: 'single'
54
- });
55
- expect(multiTenant.description).toContain('Multi-Tenant Mode');
56
- expect(single.description).not.toContain('Multi-Tenant Mode');
57
- });
58
- });
@@ -1,191 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- function _ts_metadata(k, v) {
21
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
- }
23
- import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
24
- import { ApiProperty, ApiPropertyOptional, PartialType } from '@nestjs/swagger';
25
- import { Expose } from 'class-transformer';
26
- import { IsBoolean, IsEmail, IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, MaxLength } from 'class-validator';
27
- import { EmailProviderTypeEnum } from '../enums';
28
- export class CreateEmailConfigDto {
29
- constructor(){
30
- _define_property(this, "name", void 0);
31
- _define_property(this, "provider", void 0);
32
- _define_property(this, "config", void 0);
33
- _define_property(this, "fromEmail", void 0);
34
- _define_property(this, "fromName", void 0);
35
- _define_property(this, "isActive", void 0);
36
- _define_property(this, "isDefault", void 0);
37
- }
38
- }
39
- _ts_decorate([
40
- Expose(),
41
- ApiProperty({
42
- example: 'Production SMTP'
43
- }),
44
- IsString(),
45
- IsNotEmpty(),
46
- MaxLength(255),
47
- _ts_metadata("design:type", String)
48
- ], CreateEmailConfigDto.prototype, "name", void 0);
49
- _ts_decorate([
50
- Expose(),
51
- ApiProperty({
52
- enum: EmailProviderTypeEnum,
53
- example: EmailProviderTypeEnum.SMTP
54
- }),
55
- IsEnum(EmailProviderTypeEnum),
56
- IsNotEmpty(),
57
- _ts_metadata("design:type", typeof EmailProviderTypeEnum === "undefined" ? Object : EmailProviderTypeEnum)
58
- ], CreateEmailConfigDto.prototype, "provider", void 0);
59
- _ts_decorate([
60
- Expose(),
61
- ApiProperty({
62
- type: 'object',
63
- description: 'Provider-specific configuration (SMTP: host, port, secure, auth)',
64
- additionalProperties: true
65
- }),
66
- IsObject(),
67
- IsNotEmpty(),
68
- _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
69
- ], CreateEmailConfigDto.prototype, "config", void 0);
70
- _ts_decorate([
71
- Expose(),
72
- ApiPropertyOptional({
73
- example: 'noreply@example.com'
74
- }),
75
- IsEmail(),
76
- IsOptional(),
77
- _ts_metadata("design:type", String)
78
- ], CreateEmailConfigDto.prototype, "fromEmail", void 0);
79
- _ts_decorate([
80
- Expose(),
81
- ApiPropertyOptional({
82
- example: 'FLUSYS'
83
- }),
84
- IsString(),
85
- IsOptional(),
86
- MaxLength(255),
87
- _ts_metadata("design:type", String)
88
- ], CreateEmailConfigDto.prototype, "fromName", void 0);
89
- _ts_decorate([
90
- Expose(),
91
- ApiPropertyOptional({
92
- example: true
93
- }),
94
- IsBoolean(),
95
- IsOptional(),
96
- _ts_metadata("design:type", Boolean)
97
- ], CreateEmailConfigDto.prototype, "isActive", void 0);
98
- _ts_decorate([
99
- Expose(),
100
- ApiPropertyOptional({
101
- example: false,
102
- description: 'Set as default email configuration'
103
- }),
104
- IsBoolean(),
105
- IsOptional(),
106
- _ts_metadata("design:type", Boolean)
107
- ], CreateEmailConfigDto.prototype, "isDefault", void 0);
108
- export class UpdateEmailConfigDto extends PartialType(CreateEmailConfigDto) {
109
- constructor(...args){
110
- super(...args), _define_property(this, "id", void 0);
111
- }
112
- }
113
- _ts_decorate([
114
- Expose(),
115
- ApiProperty({
116
- example: '123e4567-e89b-12d3-a456-426614174000'
117
- }),
118
- IsString(),
119
- IsNotEmpty(),
120
- _ts_metadata("design:type", String)
121
- ], UpdateEmailConfigDto.prototype, "id", void 0);
122
- export class EmailConfigResponseDto extends IdentityResponseDto {
123
- constructor(...args){
124
- 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);
125
- }
126
- }
127
- _ts_decorate([
128
- ApiProperty({
129
- description: 'Human-readable name for this email configuration',
130
- example: 'Primary Transactional Email'
131
- }),
132
- Expose(),
133
- _ts_metadata("design:type", String)
134
- ], EmailConfigResponseDto.prototype, "name", void 0);
135
- _ts_decorate([
136
- ApiProperty({
137
- description: 'The email provider type used for this configuration',
138
- enum: EmailProviderTypeEnum,
139
- example: EmailProviderTypeEnum.SMTP
140
- }),
141
- Expose(),
142
- _ts_metadata("design:type", typeof EmailProviderTypeEnum === "undefined" ? Object : EmailProviderTypeEnum)
143
- ], EmailConfigResponseDto.prototype, "provider", void 0);
144
- _ts_decorate([
145
- ApiProperty({
146
- description: 'Provider-specific configuration key-value pairs',
147
- type: 'object',
148
- additionalProperties: true,
149
- example: {
150
- host: 'smtp.example.com',
151
- port: 587,
152
- secure: true
153
- }
154
- }),
155
- Expose(),
156
- _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
157
- ], EmailConfigResponseDto.prototype, "config", void 0);
158
- _ts_decorate([
159
- ApiPropertyOptional({
160
- description: 'The email address used in the "From" field',
161
- example: 'no-reply@example.com',
162
- nullable: true
163
- }),
164
- Expose(),
165
- _ts_metadata("design:type", Object)
166
- ], EmailConfigResponseDto.prototype, "fromEmail", void 0);
167
- _ts_decorate([
168
- ApiPropertyOptional({
169
- description: 'The display name used in the "From" field',
170
- example: 'Acme Notifications',
171
- nullable: true
172
- }),
173
- Expose(),
174
- _ts_metadata("design:type", Object)
175
- ], EmailConfigResponseDto.prototype, "fromName", void 0);
176
- _ts_decorate([
177
- ApiProperty({
178
- description: 'Whether this email configuration is currently active',
179
- example: true
180
- }),
181
- Expose(),
182
- _ts_metadata("design:type", Boolean)
183
- ], EmailConfigResponseDto.prototype, "isActive", void 0);
184
- _ts_decorate([
185
- ApiProperty({
186
- description: 'Whether this is the default email configuration',
187
- example: false
188
- }),
189
- Expose(),
190
- _ts_metadata("design:type", Boolean)
191
- ], EmailConfigResponseDto.prototype, "isDefault", void 0);
@@ -1,324 +0,0 @@
1
- function _define_property(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _ts_decorate(decorators, target, key, desc) {
15
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
16
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
17
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
18
- return c > 3 && r && Object.defineProperty(target, key, r), r;
19
- }
20
- function _ts_metadata(k, v) {
21
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
22
- }
23
- import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
24
- import { IsArray, IsEmail, IsNotEmpty, IsObject, IsOptional, IsString, IsUUID, registerDecorator, ValidateNested, ValidatorConstraint } from 'class-validator';
25
- import { Type } from 'class-transformer';
26
- export class IsEmailOrEmailArrayConstraint {
27
- validate(value) {
28
- if (typeof value === 'string') {
29
- return this.emailRegex.test(value);
30
- }
31
- if (Array.isArray(value)) {
32
- return value.length > 0 && value.every((email)=>typeof email === 'string' && this.emailRegex.test(email));
33
- }
34
- return false;
35
- }
36
- defaultMessage(args) {
37
- const value = args.value;
38
- if (Array.isArray(value)) {
39
- const invalidEmails = value.filter((v)=>typeof v !== 'string' || !this.emailRegex.test(v));
40
- return `Invalid email(s) in array: ${invalidEmails.join(', ')}`;
41
- }
42
- return `${args.property} must be a valid email address or array of email addresses`;
43
- }
44
- constructor(){
45
- _define_property(this, "emailRegex", /^[^\s@]+@[^\s@]+\.[^\s@]+$/);
46
- }
47
- }
48
- IsEmailOrEmailArrayConstraint = _ts_decorate([
49
- ValidatorConstraint({
50
- name: 'isEmailOrEmailArray',
51
- async: false
52
- })
53
- ], IsEmailOrEmailArrayConstraint);
54
- function IsEmailOrEmailArray(validationOptions) {
55
- return function(object, propertyName) {
56
- registerDecorator({
57
- name: 'isEmailOrEmailArray',
58
- target: object.constructor,
59
- propertyName,
60
- options: validationOptions,
61
- validator: IsEmailOrEmailArrayConstraint
62
- });
63
- };
64
- }
65
- function RequireTemplateIdOrSlug(validationOptions) {
66
- return function(object, propertyName) {
67
- registerDecorator({
68
- name: 'requireTemplateIdOrSlug',
69
- target: object.constructor,
70
- propertyName,
71
- options: validationOptions,
72
- validator: {
73
- validate (_value, args) {
74
- const obj = args.object;
75
- return !!(obj.templateId || obj.templateSlug);
76
- },
77
- defaultMessage () {
78
- return 'Either templateId or templateSlug must be provided';
79
- }
80
- }
81
- });
82
- };
83
- }
84
- export class EmailAttachmentDto {
85
- constructor(){
86
- _define_property(this, "filename", void 0);
87
- _define_property(this, "content", void 0);
88
- _define_property(this, "contentType", void 0);
89
- }
90
- }
91
- _ts_decorate([
92
- ApiProperty({
93
- example: 'document.pdf'
94
- }),
95
- IsString(),
96
- IsNotEmpty(),
97
- _ts_metadata("design:type", String)
98
- ], EmailAttachmentDto.prototype, "filename", void 0);
99
- _ts_decorate([
100
- ApiProperty({
101
- description: 'Base64 encoded content'
102
- }),
103
- IsString(),
104
- IsNotEmpty(),
105
- _ts_metadata("design:type", String)
106
- ], EmailAttachmentDto.prototype, "content", void 0);
107
- _ts_decorate([
108
- ApiPropertyOptional({
109
- example: 'application/pdf'
110
- }),
111
- IsString(),
112
- IsOptional(),
113
- _ts_metadata("design:type", String)
114
- ], EmailAttachmentDto.prototype, "contentType", void 0);
115
- /** Base class for common email fields (recipients, sender, attachments) */ let BaseEmailDto = class BaseEmailDto {
116
- constructor(){
117
- _define_property(this, "to", void 0);
118
- _define_property(this, "cc", void 0);
119
- _define_property(this, "bcc", void 0);
120
- _define_property(this, "from", void 0);
121
- _define_property(this, "fromName", void 0);
122
- _define_property(this, "replyTo", void 0);
123
- _define_property(this, "emailConfigId", void 0);
124
- _define_property(this, "attachments", void 0);
125
- }
126
- };
127
- _ts_decorate([
128
- ApiProperty({
129
- example: 'user@example.com',
130
- description: 'Recipient email(s) - single email or array of emails',
131
- oneOf: [
132
- {
133
- type: 'string'
134
- },
135
- {
136
- type: 'array',
137
- items: {
138
- type: 'string'
139
- }
140
- }
141
- ]
142
- }),
143
- IsNotEmpty(),
144
- IsEmailOrEmailArray(),
145
- _ts_metadata("design:type", Object)
146
- ], BaseEmailDto.prototype, "to", void 0);
147
- _ts_decorate([
148
- ApiPropertyOptional({
149
- description: 'CC recipients - single email or array'
150
- }),
151
- IsOptional(),
152
- IsEmailOrEmailArray(),
153
- _ts_metadata("design:type", Object)
154
- ], BaseEmailDto.prototype, "cc", void 0);
155
- _ts_decorate([
156
- ApiPropertyOptional({
157
- description: 'BCC recipients - single email or array'
158
- }),
159
- IsOptional(),
160
- IsEmailOrEmailArray(),
161
- _ts_metadata("design:type", Object)
162
- ], BaseEmailDto.prototype, "bcc", void 0);
163
- _ts_decorate([
164
- ApiPropertyOptional({
165
- example: 'sender@example.com'
166
- }),
167
- IsEmail(),
168
- IsOptional(),
169
- _ts_metadata("design:type", String)
170
- ], BaseEmailDto.prototype, "from", void 0);
171
- _ts_decorate([
172
- ApiPropertyOptional({
173
- example: 'FLUSYS'
174
- }),
175
- IsString(),
176
- IsOptional(),
177
- _ts_metadata("design:type", String)
178
- ], BaseEmailDto.prototype, "fromName", void 0);
179
- _ts_decorate([
180
- ApiPropertyOptional({
181
- example: 'reply@example.com'
182
- }),
183
- IsEmail(),
184
- IsOptional(),
185
- _ts_metadata("design:type", String)
186
- ], BaseEmailDto.prototype, "replyTo", void 0);
187
- _ts_decorate([
188
- ApiPropertyOptional({
189
- description: 'Email configuration ID to use'
190
- }),
191
- IsUUID(),
192
- IsOptional(),
193
- _ts_metadata("design:type", String)
194
- ], BaseEmailDto.prototype, "emailConfigId", void 0);
195
- _ts_decorate([
196
- ApiPropertyOptional({
197
- type: [
198
- EmailAttachmentDto
199
- ]
200
- }),
201
- IsArray(),
202
- ValidateNested({
203
- each: true
204
- }),
205
- Type(()=>EmailAttachmentDto),
206
- IsOptional(),
207
- _ts_metadata("design:type", Array)
208
- ], BaseEmailDto.prototype, "attachments", void 0);
209
- export class SendEmailDto extends BaseEmailDto {
210
- constructor(...args){
211
- super(...args), _define_property(this, "subject", void 0), _define_property(this, "html", void 0), _define_property(this, "text", void 0);
212
- }
213
- }
214
- _ts_decorate([
215
- ApiProperty({
216
- example: 'Welcome to our platform!'
217
- }),
218
- IsString(),
219
- IsNotEmpty(),
220
- _ts_metadata("design:type", String)
221
- ], SendEmailDto.prototype, "subject", void 0);
222
- _ts_decorate([
223
- ApiProperty({
224
- example: '<h1>Hello!</h1><p>Welcome to our platform.</p>'
225
- }),
226
- IsString(),
227
- IsNotEmpty(),
228
- _ts_metadata("design:type", String)
229
- ], SendEmailDto.prototype, "html", void 0);
230
- _ts_decorate([
231
- ApiPropertyOptional({
232
- example: 'Hello! Welcome to our platform.'
233
- }),
234
- IsString(),
235
- IsOptional(),
236
- _ts_metadata("design:type", String)
237
- ], SendEmailDto.prototype, "text", void 0);
238
- export class SendTemplateEmailDto extends BaseEmailDto {
239
- constructor(...args){
240
- super(...args), _define_property(this, "templateId", void 0), _define_property(this, "templateSlug", void 0), _define_property(this, "variables", void 0);
241
- }
242
- }
243
- _ts_decorate([
244
- ApiPropertyOptional({
245
- description: 'Template ID (required if templateSlug not provided)'
246
- }),
247
- IsUUID(),
248
- IsOptional(),
249
- RequireTemplateIdOrSlug({
250
- message: 'Either templateId or templateSlug must be provided'
251
- }),
252
- _ts_metadata("design:type", String)
253
- ], SendTemplateEmailDto.prototype, "templateId", void 0);
254
- _ts_decorate([
255
- ApiPropertyOptional({
256
- example: 'welcome-email',
257
- description: 'Template slug (required if templateId not provided)'
258
- }),
259
- IsString(),
260
- IsOptional(),
261
- _ts_metadata("design:type", String)
262
- ], SendTemplateEmailDto.prototype, "templateSlug", void 0);
263
- _ts_decorate([
264
- ApiPropertyOptional({
265
- type: 'object',
266
- additionalProperties: true,
267
- example: {
268
- userName: 'John',
269
- activationLink: 'https://...'
270
- },
271
- description: 'Template variables to interpolate'
272
- }),
273
- IsObject(),
274
- IsOptional(),
275
- _ts_metadata("design:type", typeof Record === "undefined" ? Object : Record)
276
- ], SendTemplateEmailDto.prototype, "variables", void 0);
277
- export class TestEmailDto {
278
- constructor(){
279
- _define_property(this, "emailConfigId", void 0);
280
- _define_property(this, "recipient", void 0);
281
- }
282
- }
283
- _ts_decorate([
284
- ApiProperty({
285
- description: 'Email configuration ID'
286
- }),
287
- IsUUID(),
288
- IsNotEmpty(),
289
- _ts_metadata("design:type", String)
290
- ], TestEmailDto.prototype, "emailConfigId", void 0);
291
- _ts_decorate([
292
- ApiProperty({
293
- example: 'test@example.com',
294
- description: 'Test recipient'
295
- }),
296
- IsEmail(),
297
- IsNotEmpty(),
298
- _ts_metadata("design:type", String)
299
- ], TestEmailDto.prototype, "recipient", void 0);
300
- export class EmailSendResultDto {
301
- constructor(){
302
- _define_property(this, "success", void 0);
303
- _define_property(this, "messageId", void 0);
304
- _define_property(this, "error", void 0);
305
- }
306
- }
307
- _ts_decorate([
308
- ApiProperty({
309
- example: true
310
- }),
311
- _ts_metadata("design:type", Boolean)
312
- ], EmailSendResultDto.prototype, "success", void 0);
313
- _ts_decorate([
314
- ApiPropertyOptional({
315
- example: '<message-id@mail.example.com>'
316
- }),
317
- _ts_metadata("design:type", String)
318
- ], EmailSendResultDto.prototype, "messageId", void 0);
319
- _ts_decorate([
320
- ApiPropertyOptional({
321
- example: 'Connection refused'
322
- }),
323
- _ts_metadata("design:type", String)
324
- ], EmailSendResultDto.prototype, "error", void 0);