@mbc-cqrs-serverless/core 0.1.66-beta.0 → 0.1.67-beta.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.
|
@@ -7,6 +7,11 @@ export interface INotification {
|
|
|
7
7
|
action: string;
|
|
8
8
|
content?: object;
|
|
9
9
|
}
|
|
10
|
+
export interface Attachment {
|
|
11
|
+
filename: string;
|
|
12
|
+
content: Buffer;
|
|
13
|
+
contentType?: string;
|
|
14
|
+
}
|
|
10
15
|
export interface EmailNotification {
|
|
11
16
|
fromAddr?: string;
|
|
12
17
|
toAddrs: string[];
|
|
@@ -14,4 +19,6 @@ export interface EmailNotification {
|
|
|
14
19
|
bccAddrs?: string[];
|
|
15
20
|
subject: string;
|
|
16
21
|
body: string;
|
|
22
|
+
replyToAddrs?: string[];
|
|
23
|
+
attachments?: Attachment[];
|
|
17
24
|
}
|
|
@@ -6,6 +6,6 @@ export declare class EmailService {
|
|
|
6
6
|
private readonly logger;
|
|
7
7
|
private readonly [CLIENT_INSTANCE];
|
|
8
8
|
constructor(config: ConfigService);
|
|
9
|
-
sendEmail(msg: EmailNotification): Promise<
|
|
9
|
+
sendEmail(msg: EmailNotification): Promise<any>;
|
|
10
10
|
}
|
|
11
11
|
export {};
|
|
@@ -8,12 +8,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
var EmailService_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.EmailService = void 0;
|
|
14
17
|
const client_sesv2_1 = require("@aws-sdk/client-sesv2");
|
|
15
18
|
const common_1 = require("@nestjs/common");
|
|
16
19
|
const config_1 = require("@nestjs/config");
|
|
20
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
17
21
|
const CLIENT_INSTANCE = Symbol();
|
|
18
22
|
let EmailService = EmailService_1 = class EmailService {
|
|
19
23
|
constructor(config) {
|
|
@@ -25,20 +29,65 @@ let EmailService = EmailService_1 = class EmailService {
|
|
|
25
29
|
});
|
|
26
30
|
}
|
|
27
31
|
async sendEmail(msg) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
try {
|
|
33
|
+
const fromAddress = msg.fromAddr || this.config.get('SES_FROM_EMAIL');
|
|
34
|
+
const destination = {
|
|
31
35
|
ToAddresses: msg.toAddrs,
|
|
32
36
|
CcAddresses: msg.ccAddrs,
|
|
33
37
|
BccAddresses: msg.bccAddrs,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
};
|
|
39
|
+
if (!msg.attachments || msg.attachments.length === 0) {
|
|
40
|
+
this.logger.log(`Sending simple email to ${msg.toAddrs.join(', ')}`);
|
|
41
|
+
const command = new client_sesv2_1.SendEmailCommand({
|
|
42
|
+
FromEmailAddress: fromAddress,
|
|
43
|
+
Destination: destination,
|
|
44
|
+
Content: {
|
|
45
|
+
Simple: {
|
|
46
|
+
Subject: { Data: msg.subject },
|
|
47
|
+
Body: { Html: { Data: msg.body } },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
ReplyToAddresses: msg.replyToAddrs,
|
|
51
|
+
});
|
|
52
|
+
const result = await this[CLIENT_INSTANCE].send(command);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
this.logger.log(`Sending raw email with attachments to ${msg.toAddrs.join(', ')}`);
|
|
56
|
+
const transporter = nodemailer_1.default.createTransport({
|
|
57
|
+
streamTransport: true,
|
|
58
|
+
newline: 'unix',
|
|
59
|
+
buffer: true,
|
|
60
|
+
});
|
|
61
|
+
const mailOptions = {
|
|
62
|
+
from: fromAddress,
|
|
63
|
+
to: msg.toAddrs,
|
|
64
|
+
cc: msg.ccAddrs,
|
|
65
|
+
bcc: msg.bccAddrs,
|
|
66
|
+
replyTo: msg.replyToAddrs,
|
|
67
|
+
subject: msg.subject,
|
|
68
|
+
html: msg.body,
|
|
69
|
+
attachments: msg.attachments,
|
|
70
|
+
};
|
|
71
|
+
const emailBuffer = await new Promise((resolve, reject) => {
|
|
72
|
+
transporter.sendMail(mailOptions, (err, info) => {
|
|
73
|
+
if (err)
|
|
74
|
+
return reject(err);
|
|
75
|
+
resolve(info.message);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
const command = new client_sesv2_1.SendEmailCommand({
|
|
79
|
+
Destination: destination,
|
|
80
|
+
Content: {
|
|
81
|
+
Raw: { Data: emailBuffer },
|
|
39
82
|
},
|
|
40
|
-
}
|
|
41
|
-
|
|
83
|
+
});
|
|
84
|
+
const result = await this[CLIENT_INSTANCE].send(command);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this.logger.error(`Failed to send email to ${msg.toAddrs.join(', ')}`, error.stack);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
42
91
|
}
|
|
43
92
|
};
|
|
44
93
|
exports.EmailService = EmailService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"email.service.js","sourceRoot":"","sources":["../../src/notifications/email.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"email.service.js","sourceRoot":"","sources":["../../src/notifications/email.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAqE;AACrE,2CAAmD;AACnD,2CAA8C;AAC9C,4DAAmC;AAInC,MAAM,eAAe,GAAG,MAAM,EAAE,CAAA;AAGzB,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAIvB,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;QAHjC,WAAM,GAAG,IAAI,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AAC;YACf,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,2BAA2B,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAClD,KAAe,CAAC,KAAK,CACvB,CAAA;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC;CACF,CAAA;AApFY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAK0B,sBAAa;GAJvC,YAAY,CAoFxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbc-cqrs-serverless/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.67-beta.0",
|
|
4
4
|
"description": "CQRS and event base core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mbc",
|
|
@@ -62,10 +62,12 @@
|
|
|
62
62
|
"class-validator": "^0.14.0",
|
|
63
63
|
"jwt-decode": "^4.0.0",
|
|
64
64
|
"node-fetch": "^2.7.0",
|
|
65
|
+
"nodemailer": "^7.0.3",
|
|
65
66
|
"reflect-metadata": "^0.2.2",
|
|
66
67
|
"ulid": "^2.3.0"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
70
|
+
"@types/nodemailer": "^6.4.17",
|
|
69
71
|
"serverless": "^3.40.0",
|
|
70
72
|
"serverless-dynamodb": "^0.2.47",
|
|
71
73
|
"serverless-localstack": "^1.1.2",
|
|
@@ -86,5 +88,5 @@
|
|
|
86
88
|
"serverless-step-functions-local": "^0.5.1",
|
|
87
89
|
"supertest": "^7.0.0"
|
|
88
90
|
},
|
|
89
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "091292669fc8769d8cdf1b223cb8a13d7e4c4e74"
|
|
90
92
|
}
|