idea-aws 3.10.9 → 3.11.2
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/dist/src/ses.d.ts +7 -0
- package/dist/src/ses.js +51 -3
- package/package.json +1 -1
package/dist/src/ses.d.ts
CHANGED
|
@@ -6,6 +6,13 @@ import { Headers } from 'nodemailer/lib/mailer';
|
|
|
6
6
|
* A wrapper for AWS Simple Email Service.
|
|
7
7
|
*/
|
|
8
8
|
export declare class SES {
|
|
9
|
+
protected ses: AWSSES;
|
|
10
|
+
constructor(params?: {
|
|
11
|
+
region?: string;
|
|
12
|
+
});
|
|
13
|
+
getTemplate(templateName: string): Promise<AWSSES.Template>;
|
|
14
|
+
setTemplate(templateName: string, subject: string, content: string, isHTML?: boolean): Promise<void>;
|
|
15
|
+
deleteTemplate(templateName: string): Promise<void>;
|
|
9
16
|
/**
|
|
10
17
|
* Send a templated email through AWS Simple Email Service.
|
|
11
18
|
*/
|
package/dist/src/ses.js
CHANGED
|
@@ -10,6 +10,39 @@ const logger = new logger_1.Logger();
|
|
|
10
10
|
* A wrapper for AWS Simple Email Service.
|
|
11
11
|
*/
|
|
12
12
|
class SES {
|
|
13
|
+
constructor(params = {}) {
|
|
14
|
+
this.ses = new aws_sdk_1.SES({ region: params.region });
|
|
15
|
+
}
|
|
16
|
+
//
|
|
17
|
+
// CONFIG
|
|
18
|
+
//
|
|
19
|
+
async getTemplate(templateName) {
|
|
20
|
+
return (await this.ses.getTemplate({ TemplateName: templateName }).promise()).Template;
|
|
21
|
+
}
|
|
22
|
+
async setTemplate(templateName, subject, content, isHTML) {
|
|
23
|
+
const template = { TemplateName: templateName, SubjectPart: subject };
|
|
24
|
+
if (isHTML)
|
|
25
|
+
template.HtmlPart = content;
|
|
26
|
+
else
|
|
27
|
+
template.TextPart = content;
|
|
28
|
+
let isNew = false;
|
|
29
|
+
try {
|
|
30
|
+
await this.ses.getTemplate({ TemplateName: templateName }).promise();
|
|
31
|
+
}
|
|
32
|
+
catch (notFound) {
|
|
33
|
+
isNew = true;
|
|
34
|
+
}
|
|
35
|
+
if (isNew)
|
|
36
|
+
await this.ses.createTemplate({ Template: template }).promise();
|
|
37
|
+
else
|
|
38
|
+
await this.ses.updateTemplate({ Template: template }).promise();
|
|
39
|
+
}
|
|
40
|
+
async deleteTemplate(templateName) {
|
|
41
|
+
await this.ses.deleteTemplate({ TemplateName: templateName }).promise();
|
|
42
|
+
}
|
|
43
|
+
//
|
|
44
|
+
// SENDING
|
|
45
|
+
//
|
|
13
46
|
/**
|
|
14
47
|
* Send a templated email through AWS Simple Email Service.
|
|
15
48
|
*/
|
|
@@ -23,8 +56,13 @@ class SES {
|
|
|
23
56
|
Source: sesParams.sourceName ? `${sesParams.sourceName} <${sesParams.source}>` : sesParams.source,
|
|
24
57
|
SourceArn: sesParams.sourceArn
|
|
25
58
|
};
|
|
59
|
+
let ses;
|
|
60
|
+
if (this.ses.config.region === sesParams.region)
|
|
61
|
+
ses = this.ses;
|
|
62
|
+
else
|
|
63
|
+
ses = new aws_sdk_1.SES({ region: sesParams.region });
|
|
26
64
|
logger.debug('SES send templated email');
|
|
27
|
-
return await
|
|
65
|
+
return await ses.sendTemplatedEmail(request).promise();
|
|
28
66
|
}
|
|
29
67
|
/**
|
|
30
68
|
* Send an email through AWS Simple Email Service.
|
|
@@ -58,8 +96,13 @@ class SES {
|
|
|
58
96
|
Source: sesParams.sourceName ? `${sesParams.sourceName} <${sesParams.source}>` : sesParams.source,
|
|
59
97
|
SourceArn: sesParams.sourceArn
|
|
60
98
|
};
|
|
99
|
+
let ses;
|
|
100
|
+
if (this.ses.config.region === sesParams.region)
|
|
101
|
+
ses = this.ses;
|
|
102
|
+
else
|
|
103
|
+
ses = new aws_sdk_1.SES({ region: sesParams.region });
|
|
61
104
|
logger.debug('SES send email');
|
|
62
|
-
return await
|
|
105
|
+
return await ses.sendEmail(request).promise();
|
|
63
106
|
}
|
|
64
107
|
async sendEmailWithNodemailer(emailData, sesParams) {
|
|
65
108
|
const mailOptions = {};
|
|
@@ -77,8 +120,13 @@ class SES {
|
|
|
77
120
|
if (emailData.text)
|
|
78
121
|
mailOptions.text = emailData.text;
|
|
79
122
|
mailOptions.attachments = emailData.attachments;
|
|
123
|
+
let ses;
|
|
124
|
+
if (this.ses.config.region === sesParams.region)
|
|
125
|
+
ses = this.ses;
|
|
126
|
+
else
|
|
127
|
+
ses = new aws_sdk_1.SES({ region: sesParams.region });
|
|
80
128
|
logger.debug('SES send email (Nodemailer)');
|
|
81
|
-
return await (0, nodemailer_1.createTransport)({ SES:
|
|
129
|
+
return await (0, nodemailer_1.createTransport)({ SES: ses }).sendMail(mailOptions);
|
|
82
130
|
}
|
|
83
131
|
prepareEmailDestination(emailData) {
|
|
84
132
|
return {
|