@plusscommunities/pluss-core-aws 1.3.3-beta.0 → 1.3.4-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.
@@ -0,0 +1,24 @@
1
+ const AWS = require("aws-sdk");
2
+ const { getConfig } = require("../config");
3
+
4
+ module.exports = (access = null) => {
5
+ return new Promise((resolve, reject) => {
6
+ const { serverlessConfig } = getConfig();
7
+ AWS.config.update({
8
+ accessKeyId: access ? access.key : serverlessConfig.key,
9
+ secretAccessKey: access ? access.secret : serverlessConfig.secret,
10
+ });
11
+
12
+ const sesv2 = new AWS.SESV2();
13
+ const params = { PageSize: 1 };
14
+ sesv2.listEmailIdentities(params, (err, data) => {
15
+ if (err) return reject(err);
16
+ const { EmailIdentities } = data;
17
+ return resolve(
18
+ EmailIdentities && EmailIdentities.length > 0
19
+ ? EmailIdentities[0]
20
+ : null
21
+ );
22
+ });
23
+ });
24
+ };
@@ -1,8 +1,9 @@
1
1
  const nodemailer = require("nodemailer");
2
2
  const sendEmail = require("../aws/sendEmail");
3
+ const getDefaultEmailAddress = require("../aws/getDefaultEmailAddress");
3
4
  const { getConfig } = require("../config");
4
5
 
5
- module.exports = function (
6
+ module.exports = async (
6
7
  toEmail,
7
8
  subject,
8
9
  content,
@@ -10,13 +11,11 @@ module.exports = function (
10
11
  fromEmail,
11
12
  excludeClientBranding,
12
13
  brandingImage
13
- ) {
14
- return new Promise((resolve, reject) => {
15
- console.log("sending email");
16
- const { communityConfig, serverlessConfig, emailConfig } = getConfig();
14
+ ) => {
15
+ const { communityConfig, serverlessConfig } = getConfig();
17
16
 
18
- if (useTemplate) {
19
- content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
17
+ if (useTemplate) {
18
+ content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
20
19
  <div style="background-color: #fff; padding: 48px; padding-top: 65px; padding-bottom: 24px;">
21
20
  ${content}
22
21
  ${
@@ -41,59 +40,59 @@ module.exports = function (
41
40
  </div>
42
41
  </div>
43
42
  </div>`;
44
- }
43
+ }
44
+
45
+ const mailOptions = {
46
+ from:
47
+ fromEmail ||
48
+ `"${communityConfig.name}" noreply@${communityConfig.subdomain}.plusscommunities.com'`,
49
+ to: toEmail,
50
+ subject,
51
+ text: content,
52
+ html: content,
53
+ };
45
54
 
46
- const defaultFrom = emailConfig
47
- ? emailConfig.contactEmail
48
- : `"${communityConfig.name}" noreply@${communityConfig.subdomain}.plusscommunities.com'`;
49
- const mailOptions = {
50
- from: fromEmail != null ? fromEmail : defaultFrom,
51
- to: toEmail,
52
- subject,
53
- text: content,
54
- html: content,
55
- };
55
+ if (serverlessConfig && serverlessConfig.key && serverlessConfig.secret) {
56
+ try {
57
+ mailOptions.from =
58
+ fromEmail ||
59
+ (await getDefaultEmailAddress(serverlessConfig)).IdentityName;
56
60
 
57
- if (serverlessConfig && serverlessConfig.key && serverlessConfig.secret) {
58
61
  console.log("serverlessConfig exists, using Amazon SES", mailOptions);
59
- sendEmail(
62
+ const result = await sendEmail(
60
63
  mailOptions.from,
61
64
  mailOptions.to,
62
65
  mailOptions.subject,
63
66
  mailOptions.html,
64
67
  serverlessConfig
65
- )
66
- .then((result) => {
67
- console.log("Email success", toEmail, subject, result);
68
- resolve();
69
- })
70
- .catch((error) => {
71
- console.log("Email failed", toEmail, subject, error);
72
- reject(error);
73
- });
74
- } else {
75
- console.log(
76
- "serverlessConfig doesn't exist, fall back to nodemailer",
77
- mailOptions
78
68
  );
79
- const transporter = nodemailer.createTransport({
80
- //host: 'smtp.ethereal.email',
81
- service: "gmail",
82
- //port: 587,
83
- auth: {
84
- user: "info@joinpluss.com",
85
- pass: "smartcommunities",
86
- },
87
- });
88
- transporter.sendMail(mailOptions, (error) => {
89
- if (error) {
90
- console.log("Email failed", toEmail, subject, error);
91
- reject(error);
92
- } else {
93
- console.log("Email success", toEmail, subject);
94
- resolve();
95
- }
96
- });
69
+ console.log("Email success", toEmail, subject, result);
70
+ } catch (error) {
71
+ console.log("Email failed", toEmail, subject, error);
72
+ throw error;
97
73
  }
98
- });
74
+ } else {
75
+ console.log(
76
+ "serverlessConfig doesn't exist, fall back to nodemailer",
77
+ mailOptions
78
+ );
79
+ const transporter = nodemailer.createTransport({
80
+ //host: 'smtp.ethereal.email',
81
+ service: "gmail",
82
+ //port: 587,
83
+ auth: {
84
+ user: "info@joinpluss.com",
85
+ pass: "smartcommunities",
86
+ },
87
+ });
88
+ transporter.sendMail(mailOptions, (error) => {
89
+ if (error) {
90
+ console.log("Email failed", toEmail, subject, error);
91
+ reject(error);
92
+ } else {
93
+ console.log("Email success", toEmail, subject);
94
+ resolve();
95
+ }
96
+ });
97
+ }
99
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.3.3-beta.0",
3
+ "version": "1.3.4-beta.0",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",