idea-aws 3.10.7 → 3.11.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/dist/src/cognito.js +5 -1
- package/dist/src/ses.d.ts +6 -0
- package/dist/src/ses.js +48 -3
- package/package.json +1 -1
package/dist/src/cognito.js
CHANGED
|
@@ -99,6 +99,7 @@ class Cognito {
|
|
|
99
99
|
if (typeof cognitoUserOrEmail === 'object') {
|
|
100
100
|
const user = cognitoUserOrEmail;
|
|
101
101
|
UserAttributes.push({ Name: 'name', Value: user.name });
|
|
102
|
+
UserAttributes.push({ Name: 'picture', Value: user.picture || '' });
|
|
102
103
|
Object.keys(user.attributes).forEach(a => UserAttributes.push({ Name: 'custom:'.concat(a), Value: String(user.attributes[a]) }));
|
|
103
104
|
}
|
|
104
105
|
const params = {
|
|
@@ -212,7 +213,10 @@ class Cognito {
|
|
|
212
213
|
* Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
|
|
213
214
|
*/
|
|
214
215
|
async updateUser(user, cognitoUserPoolId) {
|
|
215
|
-
const UserAttributes = [
|
|
216
|
+
const UserAttributes = [
|
|
217
|
+
{ Name: 'name', Value: user.name },
|
|
218
|
+
{ Name: 'picture', Value: user.picture || '' }
|
|
219
|
+
];
|
|
216
220
|
Object.keys(user.attributes).forEach(customAttribute => UserAttributes.push({
|
|
217
221
|
Name: 'custom:'.concat(customAttribute),
|
|
218
222
|
Value: String(user.attributes[customAttribute])
|
package/dist/src/ses.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ 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
|
+
setTemplate(templateName: string, subject: string, content: string, isHTML?: boolean): Promise<void>;
|
|
14
|
+
deleteTemplate(templateName: string): Promise<void>;
|
|
9
15
|
/**
|
|
10
16
|
* Send a templated email through AWS Simple Email Service.
|
|
11
17
|
*/
|
package/dist/src/ses.js
CHANGED
|
@@ -10,6 +10,36 @@ 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 setTemplate(templateName, subject, content, isHTML) {
|
|
20
|
+
const template = { TemplateName: templateName, SubjectPart: subject };
|
|
21
|
+
if (isHTML)
|
|
22
|
+
template.HtmlPart = content;
|
|
23
|
+
else
|
|
24
|
+
template.TextPart = content;
|
|
25
|
+
let isNew = false;
|
|
26
|
+
try {
|
|
27
|
+
await this.ses.getTemplate({ TemplateName: templateName }).promise();
|
|
28
|
+
}
|
|
29
|
+
catch (notFound) {
|
|
30
|
+
isNew = true;
|
|
31
|
+
}
|
|
32
|
+
if (isNew)
|
|
33
|
+
await this.ses.createTemplate({ Template: template }).promise();
|
|
34
|
+
else
|
|
35
|
+
await this.ses.updateTemplate({ Template: template }).promise();
|
|
36
|
+
}
|
|
37
|
+
async deleteTemplate(templateName) {
|
|
38
|
+
await this.ses.deleteTemplate({ TemplateName: templateName }).promise();
|
|
39
|
+
}
|
|
40
|
+
//
|
|
41
|
+
// SENDING
|
|
42
|
+
//
|
|
13
43
|
/**
|
|
14
44
|
* Send a templated email through AWS Simple Email Service.
|
|
15
45
|
*/
|
|
@@ -23,8 +53,13 @@ class SES {
|
|
|
23
53
|
Source: sesParams.sourceName ? `${sesParams.sourceName} <${sesParams.source}>` : sesParams.source,
|
|
24
54
|
SourceArn: sesParams.sourceArn
|
|
25
55
|
};
|
|
56
|
+
let ses;
|
|
57
|
+
if (this.ses.config.region === sesParams.region)
|
|
58
|
+
ses = this.ses;
|
|
59
|
+
else
|
|
60
|
+
ses = new aws_sdk_1.SES({ region: sesParams.region });
|
|
26
61
|
logger.debug('SES send templated email');
|
|
27
|
-
return await
|
|
62
|
+
return await ses.sendTemplatedEmail(request).promise();
|
|
28
63
|
}
|
|
29
64
|
/**
|
|
30
65
|
* Send an email through AWS Simple Email Service.
|
|
@@ -58,8 +93,13 @@ class SES {
|
|
|
58
93
|
Source: sesParams.sourceName ? `${sesParams.sourceName} <${sesParams.source}>` : sesParams.source,
|
|
59
94
|
SourceArn: sesParams.sourceArn
|
|
60
95
|
};
|
|
96
|
+
let ses;
|
|
97
|
+
if (this.ses.config.region === sesParams.region)
|
|
98
|
+
ses = this.ses;
|
|
99
|
+
else
|
|
100
|
+
ses = new aws_sdk_1.SES({ region: sesParams.region });
|
|
61
101
|
logger.debug('SES send email');
|
|
62
|
-
return await
|
|
102
|
+
return await ses.sendEmail(request).promise();
|
|
63
103
|
}
|
|
64
104
|
async sendEmailWithNodemailer(emailData, sesParams) {
|
|
65
105
|
const mailOptions = {};
|
|
@@ -77,8 +117,13 @@ class SES {
|
|
|
77
117
|
if (emailData.text)
|
|
78
118
|
mailOptions.text = emailData.text;
|
|
79
119
|
mailOptions.attachments = emailData.attachments;
|
|
120
|
+
let ses;
|
|
121
|
+
if (this.ses.config.region === sesParams.region)
|
|
122
|
+
ses = this.ses;
|
|
123
|
+
else
|
|
124
|
+
ses = new aws_sdk_1.SES({ region: sesParams.region });
|
|
80
125
|
logger.debug('SES send email (Nodemailer)');
|
|
81
|
-
return await (0, nodemailer_1.createTransport)({ SES:
|
|
126
|
+
return await (0, nodemailer_1.createTransport)({ SES: ses }).sendMail(mailOptions);
|
|
82
127
|
}
|
|
83
128
|
prepareEmailDestination(emailData) {
|
|
84
129
|
return {
|