@flusys/nestjs-email 1.1.0-beta
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/cjs/config/email-config.service.js +94 -0
- package/cjs/config/email.constants.js +40 -0
- package/cjs/config/index.js +19 -0
- package/cjs/controllers/email-config.controller.js +59 -0
- package/cjs/controllers/email-send.controller.js +142 -0
- package/cjs/controllers/email-template.controller.js +84 -0
- package/cjs/controllers/index.js +20 -0
- package/cjs/docs/email-swagger.config.js +176 -0
- package/cjs/docs/index.js +11 -0
- package/cjs/dtos/email-config.dto.js +238 -0
- package/cjs/dtos/email-send.dto.js +376 -0
- package/cjs/dtos/email-template.dto.js +283 -0
- package/cjs/dtos/index.js +20 -0
- package/cjs/entities/email-config-base.entity.js +111 -0
- package/cjs/entities/email-config-with-company.entity.js +63 -0
- package/cjs/entities/email-config.entity.js +25 -0
- package/cjs/entities/email-template-base.entity.js +134 -0
- package/cjs/entities/email-template-with-company.entity.js +63 -0
- package/cjs/entities/email-template.entity.js +25 -0
- package/cjs/entities/index.js +41 -0
- package/cjs/enums/email-provider-type.enum.js +18 -0
- package/cjs/enums/index.js +18 -0
- package/cjs/index.js +27 -0
- package/cjs/interfaces/email-config.interface.js +4 -0
- package/cjs/interfaces/email-module-options.interface.js +4 -0
- package/cjs/interfaces/email-provider.interface.js +6 -0
- package/cjs/interfaces/email-template.interface.js +4 -0
- package/cjs/interfaces/index.js +21 -0
- package/cjs/modules/email.module.js +177 -0
- package/cjs/modules/index.js +18 -0
- package/cjs/providers/email-factory.service.js +160 -0
- package/cjs/providers/email-provider.registry.js +51 -0
- package/cjs/providers/index.js +22 -0
- package/cjs/providers/mailgun-provider.js +125 -0
- package/cjs/providers/sendgrid-provider.js +156 -0
- package/cjs/providers/smtp-provider.js +185 -0
- package/cjs/services/email-datasource.provider.js +215 -0
- package/cjs/services/email-provider-config.service.js +180 -0
- package/cjs/services/email-send.service.js +228 -0
- package/cjs/services/email-template.service.js +186 -0
- package/cjs/services/index.js +21 -0
- package/config/email-config.service.d.ts +13 -0
- package/config/email.constants.d.ts +11 -0
- package/config/index.d.ts +2 -0
- package/controllers/email-config.controller.d.ts +17 -0
- package/controllers/email-send.controller.d.ts +19 -0
- package/controllers/email-template.controller.d.ts +25 -0
- package/controllers/index.d.ts +3 -0
- package/docs/email-swagger.config.d.ts +3 -0
- package/docs/index.d.ts +1 -0
- package/dtos/email-config.dto.d.ts +33 -0
- package/dtos/email-send.dto.d.ts +45 -0
- package/dtos/email-template.dto.d.ts +42 -0
- package/dtos/index.d.ts +3 -0
- package/entities/email-config-base.entity.d.ts +11 -0
- package/entities/email-config-with-company.entity.d.ts +4 -0
- package/entities/email-config.entity.d.ts +3 -0
- package/entities/email-template-base.entity.d.ts +14 -0
- package/entities/email-template-with-company.entity.d.ts +4 -0
- package/entities/email-template.entity.d.ts +3 -0
- package/entities/index.d.ts +7 -0
- package/enums/email-provider-type.enum.d.ts +5 -0
- package/enums/index.d.ts +1 -0
- package/fesm/config/email-config.service.js +84 -0
- package/fesm/config/email.constants.js +13 -0
- package/fesm/config/index.js +2 -0
- package/fesm/controllers/email-config.controller.js +49 -0
- package/fesm/controllers/email-send.controller.js +132 -0
- package/fesm/controllers/email-template.controller.js +74 -0
- package/fesm/controllers/index.js +3 -0
- package/fesm/docs/email-swagger.config.js +172 -0
- package/fesm/docs/index.js +1 -0
- package/fesm/dtos/email-config.dto.js +223 -0
- package/fesm/dtos/email-send.dto.js +360 -0
- package/fesm/dtos/email-template.dto.js +268 -0
- package/fesm/dtos/index.js +3 -0
- package/fesm/entities/email-config-base.entity.js +101 -0
- package/fesm/entities/email-config-with-company.entity.js +53 -0
- package/fesm/entities/email-config.entity.js +15 -0
- package/fesm/entities/email-template-base.entity.js +124 -0
- package/fesm/entities/email-template-with-company.entity.js +53 -0
- package/fesm/entities/email-template.entity.js +15 -0
- package/fesm/entities/index.js +20 -0
- package/fesm/enums/email-provider-type.enum.js +8 -0
- package/fesm/enums/index.js +1 -0
- package/fesm/index.js +10 -0
- package/fesm/interfaces/email-config.interface.js +3 -0
- package/fesm/interfaces/email-module-options.interface.js +3 -0
- package/fesm/interfaces/email-provider.interface.js +5 -0
- package/fesm/interfaces/email-template.interface.js +3 -0
- package/fesm/interfaces/index.js +4 -0
- package/fesm/modules/email.module.js +167 -0
- package/fesm/modules/index.js +1 -0
- package/fesm/providers/email-factory.service.js +109 -0
- package/fesm/providers/email-provider.registry.js +44 -0
- package/fesm/providers/index.js +5 -0
- package/fesm/providers/mailgun-provider.js +119 -0
- package/fesm/providers/sendgrid-provider.js +150 -0
- package/fesm/providers/smtp-provider.js +137 -0
- package/fesm/services/email-datasource.provider.js +164 -0
- package/fesm/services/email-provider-config.service.js +170 -0
- package/fesm/services/email-send.service.js +218 -0
- package/fesm/services/email-template.service.js +176 -0
- package/fesm/services/index.js +4 -0
- package/index.d.ts +9 -0
- package/interfaces/email-config.interface.d.ts +28 -0
- package/interfaces/email-module-options.interface.d.ts +26 -0
- package/interfaces/email-provider.interface.d.ts +34 -0
- package/interfaces/email-template.interface.d.ts +64 -0
- package/interfaces/index.d.ts +4 -0
- package/modules/email.module.d.ts +9 -0
- package/modules/index.d.ts +1 -0
- package/package.json +105 -0
- package/providers/email-factory.service.d.ts +14 -0
- package/providers/email-provider.registry.d.ts +10 -0
- package/providers/index.d.ts +5 -0
- package/providers/mailgun-provider.d.ts +11 -0
- package/providers/sendgrid-provider.d.ts +11 -0
- package/providers/smtp-provider.d.ts +11 -0
- package/services/email-datasource.provider.d.ts +25 -0
- package/services/email-provider-config.service.d.ts +32 -0
- package/services/email-send.service.d.ts +20 -0
- package/services/email-template.service.d.ts +31 -0
- package/services/index.d.ts +4 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
2
|
+
import { EmailSendResultDto, SendEmailDto, SendTemplateEmailDto, TestEmailDto } from '../dtos';
|
|
3
|
+
import { EmailSendService } from '../services';
|
|
4
|
+
export declare class EmailSendController {
|
|
5
|
+
private readonly emailSendService;
|
|
6
|
+
constructor(emailSendService: EmailSendService);
|
|
7
|
+
sendEmail(dto: SendEmailDto, user: ILoggedUserInfo): Promise<{
|
|
8
|
+
success: boolean;
|
|
9
|
+
data: EmailSendResultDto;
|
|
10
|
+
}>;
|
|
11
|
+
sendTemplateEmail(dto: SendTemplateEmailDto, user: ILoggedUserInfo): Promise<{
|
|
12
|
+
success: boolean;
|
|
13
|
+
data: EmailSendResultDto;
|
|
14
|
+
}>;
|
|
15
|
+
sendTestEmail(dto: TestEmailDto, user: ILoggedUserInfo): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
data: EmailSendResultDto;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
2
|
+
import { CreateEmailTemplateDto, EmailTemplateResponseDto, UpdateEmailTemplateDto } from '../dtos';
|
|
3
|
+
import { IEmailTemplate } from '../interfaces';
|
|
4
|
+
import { EmailTemplateService } from '../services';
|
|
5
|
+
declare const EmailTemplateController_base: abstract new (service: EmailTemplateService) => {
|
|
6
|
+
service: EmailTemplateService;
|
|
7
|
+
insert(addDto: CreateEmailTemplateDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").SingleResponseDto<EmailTemplateResponseDto>>;
|
|
8
|
+
insertMany(addDto: CreateEmailTemplateDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<EmailTemplateResponseDto>>;
|
|
9
|
+
getById(id: string, body: import("@flusys/nestjs-shared/dtos").GetByIdBodyDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").SingleResponseDto<EmailTemplateResponseDto>>;
|
|
10
|
+
update(updateDto: UpdateEmailTemplateDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").SingleResponseDto<EmailTemplateResponseDto>>;
|
|
11
|
+
updateMany(updateDtos: UpdateEmailTemplateDto[], user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").BulkResponseDto<EmailTemplateResponseDto>>;
|
|
12
|
+
getAll(filterAndPaginationDto: import("@flusys/nestjs-shared/dtos").FilterAndPaginationDto, user: ILoggedUserInfo | null, search?: string): Promise<import("@flusys/nestjs-shared/dtos").ListResponseDto<EmailTemplateResponseDto>>;
|
|
13
|
+
delete(deleteDto: import("@flusys/nestjs-shared/dtos").DeleteDto, user: ILoggedUserInfo | null): Promise<import("@flusys/nestjs-shared/dtos").MessageResponseDto>;
|
|
14
|
+
};
|
|
15
|
+
export declare class EmailTemplateController extends EmailTemplateController_base {
|
|
16
|
+
emailTemplateService: EmailTemplateService;
|
|
17
|
+
constructor(emailTemplateService: EmailTemplateService);
|
|
18
|
+
getBySlug(body: {
|
|
19
|
+
slug: string;
|
|
20
|
+
}, user: ILoggedUserInfo): Promise<{
|
|
21
|
+
success: boolean;
|
|
22
|
+
data: IEmailTemplate | null;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/docs/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { emailSwaggerConfig } from './email-swagger.config';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
|
|
2
|
+
import { EmailProviderTypeEnum } from '../enums';
|
|
3
|
+
export declare class CreateEmailConfigDto implements Record<string, unknown> {
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
name: string;
|
|
6
|
+
provider: EmailProviderTypeEnum;
|
|
7
|
+
config: Record<string, any>;
|
|
8
|
+
fromEmail?: string;
|
|
9
|
+
fromName?: string;
|
|
10
|
+
isActive?: boolean;
|
|
11
|
+
isDefault?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class UpdateEmailConfigDto implements Record<string, unknown> {
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
id: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
provider?: EmailProviderTypeEnum;
|
|
18
|
+
config?: Record<string, any>;
|
|
19
|
+
fromEmail?: string;
|
|
20
|
+
fromName?: string;
|
|
21
|
+
isActive?: boolean;
|
|
22
|
+
isDefault?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class EmailConfigResponseDto extends IdentityResponseDto implements Record<string, unknown> {
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
name: string;
|
|
27
|
+
provider: EmailProviderTypeEnum;
|
|
28
|
+
config: Record<string, any>;
|
|
29
|
+
fromEmail: string | null;
|
|
30
|
+
fromName: string | null;
|
|
31
|
+
isActive: boolean;
|
|
32
|
+
isDefault: boolean;
|
|
33
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare class EmailAttachmentDto implements Record<string, unknown> {
|
|
2
|
+
[key: string]: unknown;
|
|
3
|
+
filename: string;
|
|
4
|
+
content: string;
|
|
5
|
+
contentType?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class SendEmailDto implements Record<string, unknown> {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
to: string | string[];
|
|
10
|
+
cc?: string | string[];
|
|
11
|
+
bcc?: string | string[];
|
|
12
|
+
subject: string;
|
|
13
|
+
html: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
from?: string;
|
|
16
|
+
fromName?: string;
|
|
17
|
+
replyTo?: string;
|
|
18
|
+
emailConfigId?: string;
|
|
19
|
+
attachments?: EmailAttachmentDto[];
|
|
20
|
+
}
|
|
21
|
+
export declare class SendTemplateEmailDto implements Record<string, unknown> {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
templateId?: string;
|
|
24
|
+
templateSlug?: string;
|
|
25
|
+
to: string | string[];
|
|
26
|
+
cc?: string | string[];
|
|
27
|
+
bcc?: string | string[];
|
|
28
|
+
variables?: Record<string, any>;
|
|
29
|
+
from?: string;
|
|
30
|
+
fromName?: string;
|
|
31
|
+
replyTo?: string;
|
|
32
|
+
emailConfigId?: string;
|
|
33
|
+
attachments?: EmailAttachmentDto[];
|
|
34
|
+
}
|
|
35
|
+
export declare class TestEmailDto implements Record<string, unknown> {
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
emailConfigId: string;
|
|
38
|
+
recipient: string;
|
|
39
|
+
}
|
|
40
|
+
export declare class EmailSendResultDto implements Record<string, unknown> {
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
success: boolean;
|
|
43
|
+
messageId?: string;
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { IdentityResponseDto } from '@flusys/nestjs-shared/dtos';
|
|
2
|
+
export declare class CreateEmailTemplateDto implements Record<string, unknown> {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
name: string;
|
|
5
|
+
slug: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
subject: string;
|
|
8
|
+
schema: Record<string, unknown>;
|
|
9
|
+
htmlContent: string;
|
|
10
|
+
textContent?: string;
|
|
11
|
+
isActive?: boolean;
|
|
12
|
+
isHtml?: boolean;
|
|
13
|
+
metadata?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export declare class UpdateEmailTemplateDto implements Record<string, unknown> {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
slug?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
subject?: string;
|
|
22
|
+
schema?: Record<string, unknown>;
|
|
23
|
+
htmlContent?: string;
|
|
24
|
+
textContent?: string;
|
|
25
|
+
isActive?: boolean;
|
|
26
|
+
isHtml?: boolean;
|
|
27
|
+
metadata?: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
export declare class EmailTemplateResponseDto extends IdentityResponseDto implements Record<string, unknown> {
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
name: string;
|
|
32
|
+
slug: string;
|
|
33
|
+
description: string | null;
|
|
34
|
+
subject: string;
|
|
35
|
+
schema: Record<string, unknown>;
|
|
36
|
+
htmlContent: string;
|
|
37
|
+
textContent: string | null;
|
|
38
|
+
schemaVersion: number;
|
|
39
|
+
isActive: boolean;
|
|
40
|
+
isHtml: boolean;
|
|
41
|
+
metadata: Record<string, unknown> | null;
|
|
42
|
+
}
|
package/dtos/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
2
|
+
import { EmailProviderTypeEnum } from '../enums';
|
|
3
|
+
export declare abstract class EmailConfigBase extends Identity {
|
|
4
|
+
name: string;
|
|
5
|
+
provider: EmailProviderTypeEnum;
|
|
6
|
+
config: Record<string, any>;
|
|
7
|
+
fromEmail: string | null;
|
|
8
|
+
fromName: string | null;
|
|
9
|
+
isActive: boolean;
|
|
10
|
+
isDefault: boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Identity } from '@flusys/nestjs-shared/entities';
|
|
2
|
+
export declare abstract class EmailTemplateBase extends Identity {
|
|
3
|
+
name: string;
|
|
4
|
+
slug: string;
|
|
5
|
+
description: string | null;
|
|
6
|
+
subject: string;
|
|
7
|
+
schema: Record<string, unknown>;
|
|
8
|
+
htmlContent: string;
|
|
9
|
+
textContent: string | null;
|
|
10
|
+
schemaVersion: number;
|
|
11
|
+
isActive: boolean;
|
|
12
|
+
isHtml: boolean;
|
|
13
|
+
metadata: Record<string, unknown> | null;
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './email-config-base.entity';
|
|
2
|
+
export * from './email-config.entity';
|
|
3
|
+
export * from './email-config-with-company.entity';
|
|
4
|
+
export * from './email-template-base.entity';
|
|
5
|
+
export * from './email-template.entity';
|
|
6
|
+
export * from './email-template-with-company.entity';
|
|
7
|
+
export declare function getEmailEntitiesByConfig(enableCompanyFeature: boolean): any[];
|
package/enums/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './email-provider-type.enum';
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
29
|
+
import { EmailModuleOptions } from '../interfaces';
|
|
30
|
+
import { EMAIL_MODULE_OPTIONS, DEFAULT_FROM_NAME } from './email.constants';
|
|
31
|
+
export class EmailConfigService {
|
|
32
|
+
/**
|
|
33
|
+
* Check if company feature is enabled
|
|
34
|
+
*/ isCompanyFeatureEnabled() {
|
|
35
|
+
return this.options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get database mode
|
|
39
|
+
*/ getDatabaseMode() {
|
|
40
|
+
return this.options.bootstrapAppConfig?.databaseMode ?? 'single';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get rate limit per minute
|
|
44
|
+
*/ getRateLimitPerMinute() {
|
|
45
|
+
return this.options.config?.rateLimitPerMinute ?? 60;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if email logging is enabled
|
|
49
|
+
*/ isLoggingEnabled() {
|
|
50
|
+
return this.options.config?.enableLogging ?? false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get default provider type
|
|
54
|
+
*/ getDefaultProvider() {
|
|
55
|
+
return this.options.config?.defaultProvider;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get default from name
|
|
59
|
+
*/ getDefaultFromName() {
|
|
60
|
+
return DEFAULT_FROM_NAME;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get default database config
|
|
64
|
+
*/ getDefaultDatabaseConfig() {
|
|
65
|
+
return this.options.config?.defaultDatabaseConfig;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get all options
|
|
69
|
+
*/ getOptions() {
|
|
70
|
+
return this.options;
|
|
71
|
+
}
|
|
72
|
+
constructor(options){
|
|
73
|
+
_define_property(this, "options", void 0);
|
|
74
|
+
this.options = options;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
EmailConfigService = _ts_decorate([
|
|
78
|
+
Injectable(),
|
|
79
|
+
_ts_param(0, Inject(EMAIL_MODULE_OPTIONS)),
|
|
80
|
+
_ts_metadata("design:type", Function),
|
|
81
|
+
_ts_metadata("design:paramtypes", [
|
|
82
|
+
typeof EmailModuleOptions === "undefined" ? Object : EmailModuleOptions
|
|
83
|
+
])
|
|
84
|
+
], EmailConfigService);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email Module Constants
|
|
3
|
+
*/ export const EMAIL_MODULE_OPTIONS = 'EMAIL_MODULE_OPTIONS';
|
|
4
|
+
export const EMAIL_CONFIG_SERVICE = 'EMAIL_CONFIG_SERVICE';
|
|
5
|
+
export const EMAIL_DATA_SOURCE_PROVIDER = 'EMAIL_DATA_SOURCE_PROVIDER';
|
|
6
|
+
export const DEFAULT_FROM_NAME = 'FLUSYS';
|
|
7
|
+
export const EMAIL_VALIDATION_MESSAGES = {
|
|
8
|
+
INVALID_RECIPIENT: 'Invalid email recipient',
|
|
9
|
+
TEMPLATE_NOT_FOUND: 'Email template not found',
|
|
10
|
+
CONFIG_NOT_FOUND: 'Email configuration not found',
|
|
11
|
+
PROVIDER_NOT_AVAILABLE: 'Email provider not available',
|
|
12
|
+
SEND_FAILED: 'Failed to send email'
|
|
13
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
29
|
+
import { createApiController } from '@flusys/nestjs-shared/classes';
|
|
30
|
+
import { Controller, Inject, UseGuards } from '@nestjs/common';
|
|
31
|
+
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
32
|
+
import { CreateEmailConfigDto, EmailConfigResponseDto, UpdateEmailConfigDto } from '../dtos';
|
|
33
|
+
import { EmailProviderConfigService } from '../services';
|
|
34
|
+
export class EmailConfigController extends createApiController(CreateEmailConfigDto, UpdateEmailConfigDto, EmailConfigResponseDto) {
|
|
35
|
+
constructor(emailConfigService){
|
|
36
|
+
super(emailConfigService), _define_property(this, "emailConfigService", void 0), this.emailConfigService = emailConfigService;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
EmailConfigController = _ts_decorate([
|
|
40
|
+
ApiTags('Email Config'),
|
|
41
|
+
ApiBearerAuth(),
|
|
42
|
+
Controller('email/email-config'),
|
|
43
|
+
UseGuards(JwtAuthGuard),
|
|
44
|
+
_ts_param(0, Inject(EmailProviderConfigService)),
|
|
45
|
+
_ts_metadata("design:type", Function),
|
|
46
|
+
_ts_metadata("design:paramtypes", [
|
|
47
|
+
typeof EmailProviderConfigService === "undefined" ? Object : EmailProviderConfigService
|
|
48
|
+
])
|
|
49
|
+
], EmailConfigController);
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
29
|
+
import { CurrentUser } from '@flusys/nestjs-shared/decorators';
|
|
30
|
+
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
31
|
+
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
32
|
+
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
33
|
+
import { SendEmailDto, SendTemplateEmailDto, TestEmailDto } from '../dtos';
|
|
34
|
+
import { EmailSendService } from '../services';
|
|
35
|
+
export class EmailSendController {
|
|
36
|
+
/**
|
|
37
|
+
* Send email directly (without template)
|
|
38
|
+
*/ async sendEmail(dto, user) {
|
|
39
|
+
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
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Send email using template
|
|
51
|
+
*/ async sendTemplateEmail(dto, user) {
|
|
52
|
+
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
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Send test email (for testing configuration)
|
|
64
|
+
*/ async sendTestEmail(dto, user) {
|
|
65
|
+
const result = await this.emailSendService.sendTestEmail(dto.emailConfigId, dto.recipient, user);
|
|
66
|
+
return {
|
|
67
|
+
success: result.success,
|
|
68
|
+
data: {
|
|
69
|
+
success: result.success,
|
|
70
|
+
messageId: result.messageId,
|
|
71
|
+
error: result.error
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
constructor(emailSendService){
|
|
76
|
+
_define_property(this, "emailSendService", void 0);
|
|
77
|
+
this.emailSendService = emailSendService;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
_ts_decorate([
|
|
81
|
+
Post('direct'),
|
|
82
|
+
ApiOperation({
|
|
83
|
+
summary: 'Send email directly with custom content'
|
|
84
|
+
}),
|
|
85
|
+
_ts_param(0, Body()),
|
|
86
|
+
_ts_param(1, CurrentUser()),
|
|
87
|
+
_ts_metadata("design:type", Function),
|
|
88
|
+
_ts_metadata("design:paramtypes", [
|
|
89
|
+
typeof SendEmailDto === "undefined" ? Object : SendEmailDto,
|
|
90
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
91
|
+
]),
|
|
92
|
+
_ts_metadata("design:returntype", Promise)
|
|
93
|
+
], EmailSendController.prototype, "sendEmail", null);
|
|
94
|
+
_ts_decorate([
|
|
95
|
+
Post('template'),
|
|
96
|
+
ApiOperation({
|
|
97
|
+
summary: 'Send email using a template with variable interpolation'
|
|
98
|
+
}),
|
|
99
|
+
_ts_param(0, Body()),
|
|
100
|
+
_ts_param(1, CurrentUser()),
|
|
101
|
+
_ts_metadata("design:type", Function),
|
|
102
|
+
_ts_metadata("design:paramtypes", [
|
|
103
|
+
typeof SendTemplateEmailDto === "undefined" ? Object : SendTemplateEmailDto,
|
|
104
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
105
|
+
]),
|
|
106
|
+
_ts_metadata("design:returntype", Promise)
|
|
107
|
+
], EmailSendController.prototype, "sendTemplateEmail", null);
|
|
108
|
+
_ts_decorate([
|
|
109
|
+
Post('test'),
|
|
110
|
+
ApiOperation({
|
|
111
|
+
summary: 'Send a test email to verify configuration'
|
|
112
|
+
}),
|
|
113
|
+
_ts_param(0, Body()),
|
|
114
|
+
_ts_param(1, CurrentUser()),
|
|
115
|
+
_ts_metadata("design:type", Function),
|
|
116
|
+
_ts_metadata("design:paramtypes", [
|
|
117
|
+
typeof TestEmailDto === "undefined" ? Object : TestEmailDto,
|
|
118
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
119
|
+
]),
|
|
120
|
+
_ts_metadata("design:returntype", Promise)
|
|
121
|
+
], EmailSendController.prototype, "sendTestEmail", null);
|
|
122
|
+
EmailSendController = _ts_decorate([
|
|
123
|
+
ApiTags('Email Send'),
|
|
124
|
+
ApiBearerAuth(),
|
|
125
|
+
Controller('email/send'),
|
|
126
|
+
UseGuards(JwtAuthGuard),
|
|
127
|
+
_ts_param(0, Inject(EmailSendService)),
|
|
128
|
+
_ts_metadata("design:type", Function),
|
|
129
|
+
_ts_metadata("design:paramtypes", [
|
|
130
|
+
typeof EmailSendService === "undefined" ? Object : EmailSendService
|
|
131
|
+
])
|
|
132
|
+
], EmailSendController);
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
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
|
+
import { ILoggedUserInfo } from '@flusys/nestjs-shared/interfaces';
|
|
34
|
+
import { CreateEmailTemplateDto, EmailTemplateResponseDto, UpdateEmailTemplateDto } from '../dtos';
|
|
35
|
+
import { EmailTemplateService } from '../services';
|
|
36
|
+
export class EmailTemplateController extends createApiController(CreateEmailTemplateDto, UpdateEmailTemplateDto, EmailTemplateResponseDto) {
|
|
37
|
+
/**
|
|
38
|
+
* Get template by slug (POST-only RPC pattern)
|
|
39
|
+
*/ async getBySlug(body, user) {
|
|
40
|
+
const template = await this.emailTemplateService.findBySlug(body.slug, user);
|
|
41
|
+
return {
|
|
42
|
+
success: true,
|
|
43
|
+
data: template
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
constructor(emailTemplateService){
|
|
47
|
+
super(emailTemplateService), _define_property(this, "emailTemplateService", void 0), this.emailTemplateService = emailTemplateService;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
_ts_decorate([
|
|
51
|
+
Post('get-by-slug'),
|
|
52
|
+
ApiOperation({
|
|
53
|
+
summary: 'Get email template by slug'
|
|
54
|
+
}),
|
|
55
|
+
_ts_param(0, Body()),
|
|
56
|
+
_ts_param(1, CurrentUser()),
|
|
57
|
+
_ts_metadata("design:type", Function),
|
|
58
|
+
_ts_metadata("design:paramtypes", [
|
|
59
|
+
Object,
|
|
60
|
+
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
61
|
+
]),
|
|
62
|
+
_ts_metadata("design:returntype", Promise)
|
|
63
|
+
], EmailTemplateController.prototype, "getBySlug", null);
|
|
64
|
+
EmailTemplateController = _ts_decorate([
|
|
65
|
+
ApiTags('Email Template'),
|
|
66
|
+
ApiBearerAuth(),
|
|
67
|
+
Controller('email/email-template'),
|
|
68
|
+
UseGuards(JwtAuthGuard),
|
|
69
|
+
_ts_param(0, Inject(EmailTemplateService)),
|
|
70
|
+
_ts_metadata("design:type", Function),
|
|
71
|
+
_ts_metadata("design:paramtypes", [
|
|
72
|
+
typeof EmailTemplateService === "undefined" ? Object : EmailTemplateService
|
|
73
|
+
])
|
|
74
|
+
], EmailTemplateController);
|