@plusscommunities/pluss-core-aws 2.1.1-beta.2 → 2.1.1-beta.3
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/aws/getDefaultEmailAddress.js +24 -22
- package/aws/getEmailService.js +21 -17
- package/aws/sendEmail.js +33 -28
- package/package.json +2 -1
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { SESv2Client, ListEmailIdentitiesCommand } = require("@aws-sdk/client-sesv2");
|
|
2
2
|
|
|
3
|
-
module.exports = (accessKey, secretKey) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
accessKeyId: accessKey,
|
|
8
|
-
secretAccessKey: secretKey,
|
|
9
|
-
});
|
|
3
|
+
module.exports = async (accessKey, secretKey) => {
|
|
4
|
+
if (!accessKey || !secretKey) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
EmailIdentities && EmailIdentities.length > 0
|
|
18
|
-
? EmailIdentities[0]
|
|
19
|
-
: null
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
resolve(null);
|
|
24
|
-
}
|
|
8
|
+
const client = new SESv2Client({
|
|
9
|
+
region: "ap-southeast-2",
|
|
10
|
+
credentials: {
|
|
11
|
+
accessKeyId: accessKey,
|
|
12
|
+
secretAccessKey: secretKey,
|
|
13
|
+
},
|
|
25
14
|
});
|
|
15
|
+
|
|
16
|
+
const params = { PageSize: 1 };
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const command = new ListEmailIdentitiesCommand(params);
|
|
20
|
+
const data = await client.send(command);
|
|
21
|
+
const { EmailIdentities } = data;
|
|
22
|
+
return EmailIdentities && EmailIdentities.length > 0
|
|
23
|
+
? EmailIdentities[0]
|
|
24
|
+
: null;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
26
28
|
};
|
package/aws/getEmailService.js
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { SESv2Client, GetAccountCommand } = require("@aws-sdk/client-sesv2");
|
|
2
2
|
|
|
3
|
-
module.exports = (accessKey, secretKey) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
accessKeyId: accessKey,
|
|
8
|
-
secretAccessKey: secretKey,
|
|
9
|
-
});
|
|
3
|
+
module.exports = async (accessKey, secretKey) => {
|
|
4
|
+
if (!accessKey || !secretKey) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} else {
|
|
18
|
-
resolve(null);
|
|
19
|
-
}
|
|
8
|
+
const client = new SESv2Client({
|
|
9
|
+
region: "ap-southeast-2",
|
|
10
|
+
credentials: {
|
|
11
|
+
accessKeyId: accessKey,
|
|
12
|
+
secretAccessKey: secretKey,
|
|
13
|
+
},
|
|
20
14
|
});
|
|
15
|
+
|
|
16
|
+
const params = {};
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const command = new GetAccountCommand(params);
|
|
20
|
+
const data = await client.send(command);
|
|
21
|
+
return data;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
21
25
|
};
|
package/aws/sendEmail.js
CHANGED
|
@@ -1,37 +1,42 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { SESv2Client, SendEmailCommand } = require("@aws-sdk/client-sesv2");
|
|
2
2
|
const { getConfig } = require("../config");
|
|
3
3
|
|
|
4
|
-
module.exports = (from, to, subject, content, access = null, bcc = null) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
module.exports = async (from, to, subject, content, access = null, bcc = null) => {
|
|
5
|
+
const { serverlessConfig } = getConfig();
|
|
6
|
+
|
|
7
|
+
const client = new SESv2Client({
|
|
8
|
+
region: "ap-southeast-2", // Set your default region
|
|
9
|
+
credentials: {
|
|
8
10
|
accessKeyId: access ? access.key : serverlessConfig.key,
|
|
9
11
|
secretAccessKey: access ? access.secret : serverlessConfig.secret,
|
|
10
|
-
}
|
|
12
|
+
},
|
|
13
|
+
});
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Data: content,
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
Subject: {
|
|
22
|
-
Data: subject,
|
|
15
|
+
const params = {
|
|
16
|
+
Content: {
|
|
17
|
+
Simple: {
|
|
18
|
+
Body: {
|
|
19
|
+
Html: {
|
|
20
|
+
Data: content,
|
|
23
21
|
},
|
|
24
22
|
},
|
|
23
|
+
Subject: {
|
|
24
|
+
Data: subject,
|
|
25
|
+
},
|
|
25
26
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
},
|
|
28
|
+
Destination: {
|
|
29
|
+
ToAddresses: to.split(",").map((i) => i.trim()),
|
|
30
|
+
BccAddresses: bcc ? bcc.split(",").map((i) => i.trim()) : [],
|
|
31
|
+
},
|
|
32
|
+
FromEmailAddress: from,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const command = new SendEmailCommand(params);
|
|
37
|
+
const data = await client.send(command);
|
|
38
|
+
return data;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
37
42
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plusscommunities/pluss-core-aws",
|
|
3
|
-
"version": "2.1.1-beta.
|
|
3
|
+
"version": "2.1.1-beta.3",
|
|
4
4
|
"description": "Core extension package for Pluss Communities platform",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"betapatch": "npm version prepatch --preid=beta",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@aws-sdk/client-dynamodb": "^3.855.0",
|
|
17
|
+
"@aws-sdk/client-sesv2": "^3.857.0",
|
|
17
18
|
"@aws-sdk/lib-dynamodb": "^3.855.0",
|
|
18
19
|
"@aws/dynamodb-auto-marshaller": "^0.7.1",
|
|
19
20
|
"amazon-cognito-identity-js": "^2.0.19",
|