@nka212bg/backend-utils 0.1.58 → 0.1.60

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,5 +1,5 @@
1
- <!-- wrapper: fills the available width, up to 400px -->
2
- <table border="0" cellpadding="0" cellspacing="0" width="100%" role="presentation" style="width: 100%; max-width: 400px">
1
+ <br />
2
+ <table border="0" cellpadding="0" cellspacing="0" width="100%" role="presentation" style="width: 100%; max-width: 460px">
3
3
  <tr>
4
4
  <td>
5
5
  <!-- divider: mid gray at 70% (solid fallback for clients without rgba), dodger blue accent at the end -->
@@ -50,6 +50,28 @@ const subscriptionState = {
50
50
  },
51
51
  };
52
52
 
53
+ // SMTP_URL=smtps://user%40mail.com:pass@smtp.host.com:465 (smtps = TLS on 465, smtp = STARTTLS on 587)
54
+ // falls back to SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS
55
+ const smtpEnv = () => {
56
+ if (!process.env.SMTP_URL) {
57
+ return {
58
+ host: process.env.SMTP_HOST,
59
+ port: parseInt(process.env.SMTP_PORT),
60
+ secure: true,
61
+ auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS },
62
+ };
63
+ }
64
+
65
+ const u = new URL(process.env.SMTP_URL);
66
+ const secure = u.protocol == "smtps:";
67
+ return {
68
+ host: u.hostname,
69
+ port: parseInt(u.port) || (secure ? 465 : 587),
70
+ secure,
71
+ auth: { user: decodeURIComponent(u.username), pass: decodeURIComponent(u.password) },
72
+ };
73
+ };
74
+
53
75
  // every call creates a separate instance with its own config and transports:
54
76
  // const { sendEmail } = require(".../mailSmsTools")({ name, logoUrl, baseUrl, smtp, twilio });
55
77
  // const { sendEmail } = require(".../mailSmsTools"); // default instance, env config only
@@ -81,13 +103,7 @@ const createInstance = (options = {}) => {
81
103
  maxMessages: Infinity,
82
104
  maxConnections: 20,
83
105
 
84
- host: process.env.SMTP_HOST,
85
- port: parseInt(process.env.SMTP_PORT),
86
- secure: true, // true for 465, false for other ports
87
- auth: {
88
- user: process.env.SMTP_USER,
89
- pass: process.env.SMTP_PASS,
90
- },
106
+ ...smtpEnv(),
91
107
  ...smtp,
92
108
  }));
93
109
  };
@@ -115,7 +131,7 @@ const createInstance = (options = {}) => {
115
131
  const name = val(config.name);
116
132
  const baseUrl = val(config.baseUrl) || process.env.BASE_URL;
117
133
  const smtp = val(config.smtp) || {};
118
- const smtpUser = smtp.auth?.user || process.env.SMTP_USER;
134
+ const smtpUser = smtp.auth?.user || smtpEnv().auth.user;
119
135
  logoUrl ||= val(config.logoUrl);
120
136
 
121
137
  const emailArray = strToEmailsArray(email || smtpUser);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nka212bg/backend-utils",
3
3
  "author": "nka212bg",
4
- "version": "0.1.58",
4
+ "version": "0.1.60",
5
5
  "main": "index.js",
6
6
  "dependencies": {
7
7
  "@maxmind/geoip2-node": "^5.0.0",