@plusscommunities/pluss-core-aws 1.3.2 → 1.3.3-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,36 @@
1
+ const AWS = require("aws-sdk");
2
+ const { getConfig } = require("../config");
3
+
4
+ module.exports = (from, to, subject, content, 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 = {
14
+ Content: {
15
+ Simple: {
16
+ Body: {
17
+ Html: {
18
+ Data: content,
19
+ },
20
+ },
21
+ Subject: {
22
+ Data: subject,
23
+ },
24
+ },
25
+ },
26
+ Destination: {
27
+ ToAddresses: to.split(",").map((i) => i.trim()),
28
+ },
29
+ FromEmailAddress: from,
30
+ };
31
+ sesv2.sendEmail(params, (err, data) => {
32
+ if (err) return reject(err);
33
+ return resolve(data);
34
+ });
35
+ });
36
+ };
@@ -1,4 +1,5 @@
1
1
  const nodemailer = require("nodemailer");
2
+ const sendEmail = require("../aws/sendEmail");
2
3
  const { getConfig } = require("../config");
3
4
 
4
5
  module.exports = function (
@@ -12,18 +13,8 @@ module.exports = function (
12
13
  ) {
13
14
  return new Promise((resolve, reject) => {
14
15
  console.log("sending email");
16
+ const { communityConfig, serverlessConfig, emailConfig } = getConfig();
15
17
 
16
- const transporter = nodemailer.createTransport({
17
- //host: 'smtp.ethereal.email',
18
- service: "gmail",
19
- //port: 587,
20
- auth: {
21
- user: "info@joinpluss.com",
22
- pass: "smartcommunities",
23
- },
24
- });
25
-
26
- const { communityConfig } = getConfig();
27
18
  if (useTemplate) {
28
19
  content = `<div style="padding: 24px; padding-top: 0px; background-color: #f2f4f8;margin: 0px;">
29
20
  <div style="background-color: #fff; padding: 48px; padding-top: 65px; padding-bottom: 24px;">
@@ -52,25 +43,57 @@ module.exports = function (
52
43
  </div>`;
53
44
  }
54
45
 
46
+ const defaultFrom = emailConfig
47
+ ? emailConfig.contactEmail
48
+ : `"${communityConfig.name}" noreply@${communityConfig.subdomain}.plusscommunities.com'`;
55
49
  const mailOptions = {
56
- from:
57
- fromEmail != null
58
- ? fromEmail
59
- : `"${communityConfig.name}" noreply@${communityConfig.subdomain}.plusscommunities.com'`,
50
+ from: fromEmail != null ? fromEmail : defaultFrom,
60
51
  to: toEmail,
61
52
  subject,
62
53
  text: content,
63
54
  html: content,
64
55
  };
65
56
 
66
- transporter.sendMail(mailOptions, (error) => {
67
- if (error) {
68
- console.log("Email failed", toEmail, subject, error);
69
- reject(error);
70
- } else {
71
- console.log("Email success", toEmail, subject);
72
- resolve();
73
- }
74
- });
57
+ if (serverlessConfig && serverlessConfig.key && serverlessConfig.secret) {
58
+ console.log("serverlessConfig exists, using Amazon SES", mailOptions);
59
+ sendEmail(
60
+ mailOptions.from,
61
+ mailOptions.to,
62
+ mailOptions.subject,
63
+ mailOptions.html,
64
+ 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
+ );
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
+ }
75
98
  });
76
99
  };
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.3.2",
3
+ "version": "1.3.3-beta.0",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
+ "betapatch": "npm version prepatch --preid=beta",
6
7
  "patch": "npm version patch",
8
+ "betaupload": "npm publish --access public --tag beta",
9
+ "betaupload:p": "npm run betapatch && npm run betaupload",
7
10
  "upload": "npm publish --access public",
8
11
  "upload:p": "npm run patch && npm run upload"
9
12
  },