@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.
@@ -1,26 +1,28 @@
1
- const AWS = require("aws-sdk");
1
+ const { SESv2Client, ListEmailIdentitiesCommand } = require("@aws-sdk/client-sesv2");
2
2
 
3
- module.exports = (accessKey, secretKey) => {
4
- return new Promise((resolve, reject) => {
5
- if (accessKey && secretKey) {
6
- AWS.config.update({
7
- accessKeyId: accessKey,
8
- secretAccessKey: secretKey,
9
- });
3
+ module.exports = async (accessKey, secretKey) => {
4
+ if (!accessKey || !secretKey) {
5
+ return null;
6
+ }
10
7
 
11
- const sesv2 = new AWS.SESV2();
12
- const params = { PageSize: 1 };
13
- sesv2.listEmailIdentities(params, (err, data) => {
14
- if (err) return reject(err);
15
- const { EmailIdentities } = data;
16
- return resolve(
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
  };
@@ -1,21 +1,25 @@
1
- const AWS = require("aws-sdk");
1
+ const { SESv2Client, GetAccountCommand } = require("@aws-sdk/client-sesv2");
2
2
 
3
- module.exports = (accessKey, secretKey) => {
4
- return new Promise((resolve, reject) => {
5
- if (accessKey && secretKey) {
6
- AWS.config.update({
7
- accessKeyId: accessKey,
8
- secretAccessKey: secretKey,
9
- });
3
+ module.exports = async (accessKey, secretKey) => {
4
+ if (!accessKey || !secretKey) {
5
+ return null;
6
+ }
10
7
 
11
- const sesv2 = new AWS.SESV2();
12
- const params = {};
13
- sesv2.getAccount(params, (err, data) => {
14
- if (err) return reject(err);
15
- return resolve(data);
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 AWS = require("aws-sdk");
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
- return new Promise((resolve, reject) => {
6
- const { serverlessConfig } = getConfig();
7
- AWS.config.update({
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
- const sesv2 = new AWS.SESV2();
13
- const params = {
14
- Content: {
15
- Simple: {
16
- Body: {
17
- Html: {
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
- Destination: {
27
- ToAddresses: to.split(",").map((i) => i.trim()),
28
- BccAddresses: bcc ? bcc.split(",").map((i) => i.trim()) : [],
29
- },
30
- FromEmailAddress: from,
31
- };
32
- sesv2.sendEmail(params, (err, data) => {
33
- if (err) return reject(err);
34
- return resolve(data);
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.2",
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",