@plusscommunities/pluss-core-aws 1.3.4-beta.0 → 1.3.8-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.
- package/aws/getDefaultEmailAddress.js +20 -18
- package/aws/getEmailService.js +21 -0
- package/aws/getEmailServiceInfo.js +21 -0
- package/db/scheduledActions/deleteActionQueue.js +5 -0
- package/db/scheduledActions/getActionQueueById.js +13 -0
- package/db/scheduledActions/updateActionQueue.js +31 -0
- package/helper/sendEmail.js +10 -10
- package/notification/prepNotification.js +4 -0
- package/package.json +1 -1
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
const AWS = require("aws-sdk");
|
|
2
|
-
const { getConfig } = require("../config");
|
|
3
2
|
|
|
4
|
-
module.exports = (
|
|
3
|
+
module.exports = (accessKey, secretKey) => {
|
|
5
4
|
return new Promise((resolve, reject) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
if (accessKey && secretKey) {
|
|
6
|
+
AWS.config.update({
|
|
7
|
+
accessKeyId: accessKey,
|
|
8
|
+
secretAccessKey: secretKey,
|
|
9
|
+
});
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
}
|
|
23
25
|
});
|
|
24
26
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const AWS = require("aws-sdk");
|
|
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
|
+
});
|
|
10
|
+
|
|
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
|
+
}
|
|
20
|
+
});
|
|
21
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const getEmailService = require("./getEmailService");
|
|
2
|
+
const getDefaultEmailAddress = require("./getDefaultEmailAddress");
|
|
3
|
+
|
|
4
|
+
module.exports = async (accessKey, secretKey) => {
|
|
5
|
+
const result = {
|
|
6
|
+
enabled: false,
|
|
7
|
+
sender: null,
|
|
8
|
+
};
|
|
9
|
+
const service = await getEmailService(accessKey, secretKey);
|
|
10
|
+
console.log("Amazon SES status", service);
|
|
11
|
+
if (service && service.SendingEnabled && service.ProductionAccessEnabled) {
|
|
12
|
+
result.enabled = true;
|
|
13
|
+
const sender = await getDefaultEmailAddress(accessKey, secretKey);
|
|
14
|
+
console.log("Amazon SES sender", sender);
|
|
15
|
+
if (sender) {
|
|
16
|
+
result.sender = sender.IdentityName;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const getRef = require("../common/getRef");
|
|
2
|
+
|
|
3
|
+
module.exports = (rowId) => {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
getRef("actionqueue", "RowId", rowId)
|
|
6
|
+
.then((ev) => {
|
|
7
|
+
resolve(ev);
|
|
8
|
+
})
|
|
9
|
+
.catch((error) => {
|
|
10
|
+
reject(error);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const uuid = require("uuid");
|
|
2
|
+
const moment = require("moment");
|
|
3
|
+
const editRef = require("../common/editRef");
|
|
4
|
+
|
|
5
|
+
module.exports = (rowId, update) => {
|
|
6
|
+
return new Promise(async (resolve, reject) => {
|
|
7
|
+
try {
|
|
8
|
+
const now = moment().valueOf();
|
|
9
|
+
const { Created, Updated, TriggerAt, Status, Recipients } = update;
|
|
10
|
+
if (!rowId) {
|
|
11
|
+
rowId = uuid.v1();
|
|
12
|
+
if (!Created) update.Created = now;
|
|
13
|
+
if (!Status) update.Status = "READY";
|
|
14
|
+
} else {
|
|
15
|
+
if (!Updated) update.Updated = now;
|
|
16
|
+
}
|
|
17
|
+
if (TriggerAt) update.TriggerAt = moment(TriggerAt).valueOf();
|
|
18
|
+
if (Recipients)
|
|
19
|
+
update.Recipients =
|
|
20
|
+
typeof Recipients === "string" || Recipients instanceof String
|
|
21
|
+
? Recipients.split(",").map((r) => r.trim())
|
|
22
|
+
: Recipients;
|
|
23
|
+
|
|
24
|
+
const updated = await editRef("actionqueue", "RowId", rowId, update);
|
|
25
|
+
|
|
26
|
+
resolve(updated);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
reject(error);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
package/helper/sendEmail.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const nodemailer = require("nodemailer");
|
|
2
2
|
const sendEmail = require("../aws/sendEmail");
|
|
3
|
-
const
|
|
3
|
+
const getEmailServiceInfo = require("../aws/getEmailServiceInfo");
|
|
4
4
|
const { getConfig } = require("../config");
|
|
5
5
|
|
|
6
6
|
module.exports = async (
|
|
@@ -52,13 +52,16 @@ module.exports = async (
|
|
|
52
52
|
html: content,
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
const sesInfo = await getEmailServiceInfo(
|
|
56
|
+
serverlessConfig.key,
|
|
57
|
+
serverlessConfig.secret
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (sesInfo.enabled) {
|
|
56
61
|
try {
|
|
62
|
+
console.log("Using Amazon SES", mailOptions);
|
|
57
63
|
mailOptions.from =
|
|
58
|
-
fromEmail ||
|
|
59
|
-
(await getDefaultEmailAddress(serverlessConfig)).IdentityName;
|
|
60
|
-
|
|
61
|
-
console.log("serverlessConfig exists, using Amazon SES", mailOptions);
|
|
64
|
+
fromEmail || `${communityConfig.name} <${sesInfo.sender}>`;
|
|
62
65
|
const result = await sendEmail(
|
|
63
66
|
mailOptions.from,
|
|
64
67
|
mailOptions.to,
|
|
@@ -72,10 +75,7 @@ module.exports = async (
|
|
|
72
75
|
throw error;
|
|
73
76
|
}
|
|
74
77
|
} else {
|
|
75
|
-
console.log(
|
|
76
|
-
"serverlessConfig doesn't exist, fall back to nodemailer",
|
|
77
|
-
mailOptions
|
|
78
|
-
);
|
|
78
|
+
console.log("Cannot use Amazon SES, fall back to nodemailer", mailOptions);
|
|
79
79
|
const transporter = nodemailer.createTransport({
|
|
80
80
|
//host: 'smtp.ethereal.email',
|
|
81
81
|
service: "gmail",
|
|
@@ -114,6 +114,10 @@ module.exports = (noti) => {
|
|
|
114
114
|
thisNoti.Text = `There is a new document: ${noti.Data.Name}`;
|
|
115
115
|
thisNoti.Icon = "file-o";
|
|
116
116
|
break;
|
|
117
|
+
case "ScheduledAction":
|
|
118
|
+
thisNoti.Text = noti.Data.message;
|
|
119
|
+
thisNoti.Icon = "bell-o";
|
|
120
|
+
break;
|
|
117
121
|
default:
|
|
118
122
|
thisNoti.Text = "You have received a notification";
|
|
119
123
|
thisNoti.Icon = "bell-o";
|
package/package.json
CHANGED