nitro-web 0.3.21 → 0.3.23
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitro-web",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"repository": "github:boycce/nitro-web",
|
|
5
5
|
"homepage": "https://boycce.github.io/nitro-web/",
|
|
6
6
|
"description": "Nitro is a battle-tested, modular base project to turbocharge your projects, styled using Tailwind 🚀",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"node": ">=20.19.0"
|
|
75
75
|
},
|
|
76
76
|
"standard-version": {
|
|
77
|
-
"releaseCommitMessageFormat": "{{currentTag}}",
|
|
77
|
+
"releaseCommitMessageFormat": "chore(release): {{currentTag}}",
|
|
78
78
|
"sign": true,
|
|
79
79
|
"tag-prefix": "",
|
|
80
80
|
"skip": {
|
package/server/email/index.js
CHANGED
|
@@ -25,7 +25,8 @@ export const optionalEmailConfigKeys = ['emailReplyTo', 'emailTestMode', 'mailgu
|
|
|
25
25
|
* @param {string} opts.template - Template name or raw HTML, e.g., 'reset-password'
|
|
26
26
|
* @param {string} opts.to - Recipient(s), e.g. "Bruce<bruce@wayneenterprises.com>,..."
|
|
27
27
|
* @param {Config} opts.config - Config object
|
|
28
|
-
* @param {string} [opts.
|
|
28
|
+
* @param {string} [opts.cc] - CC, e.g. "Bruce<bruce@wayneenterprises.com>,..." (not sent in development)
|
|
29
|
+
* @param {string} [opts.bcc] - BCC, e.g. "Bruce<bruce@wayneenterprises.com>,..." (not sent in development)
|
|
29
30
|
* @param {object} [opts.data] - common template data shared across recipients
|
|
30
31
|
* @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun). Inherits data.
|
|
31
32
|
* @param {string} [opts.from] - sender address, e.g. "Bruce<bruce@wayneenterprises.com>"
|
|
@@ -41,6 +42,7 @@ export async function sendEmail({
|
|
|
41
42
|
template,
|
|
42
43
|
to,
|
|
43
44
|
config,
|
|
45
|
+
cc,
|
|
44
46
|
bcc,
|
|
45
47
|
data,
|
|
46
48
|
swigData,
|
|
@@ -89,13 +91,14 @@ export async function sendEmail({
|
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
// Copied recipients need their own values too, Mailgun doesn't share them from `to`
|
|
95
|
+
const recipients = [to, cc, bcc].filter(Boolean).join(',').split(',')
|
|
93
96
|
|
|
94
97
|
// Add default recipientVariables
|
|
95
98
|
if (!recipientVariables) recipientVariables = {}
|
|
96
99
|
|
|
97
100
|
// Add default values to recipientVariables
|
|
98
|
-
for (let toNameEmail of
|
|
101
|
+
for (let toNameEmail of recipients) {
|
|
99
102
|
const [toName, toEmail] = getNameEmail(toNameEmail)
|
|
100
103
|
recipientVariables[toEmail] = {
|
|
101
104
|
...defaultData,
|
|
@@ -108,6 +111,7 @@ export async function sendEmail({
|
|
|
108
111
|
|
|
109
112
|
let settings = {
|
|
110
113
|
attachments: attachments,
|
|
114
|
+
cc: cc,
|
|
111
115
|
bcc: bcc,
|
|
112
116
|
emailTemplateDir: getDirectories(path, config.pwd).emailTemplateDir,
|
|
113
117
|
from: from,
|
|
@@ -186,7 +190,9 @@ function processTemplate(settings, html) {
|
|
|
186
190
|
if (!settings.to.match(/,/) && Object.keys(settings.recipientVariables).length) {
|
|
187
191
|
const recipientVariables = settings.recipientVariables[Object.keys(settings.recipientVariables)[0]]
|
|
188
192
|
for (let key in recipientVariables) {
|
|
189
|
-
|
|
193
|
+
const placeholder = new RegExp('%recipient\\.' + key + '%', 'g')
|
|
194
|
+
html = html.replace(placeholder, recipientVariables[key])
|
|
195
|
+
if (settings.subject) settings.subject = settings.subject.replace(placeholder, recipientVariables[key])
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
// Extract the subject from the template
|
|
@@ -204,15 +210,17 @@ async function sendWithMailgun(settings, html) {
|
|
|
204
210
|
// Supports batch sending via recipientVariables, limit 1000 emails
|
|
205
211
|
// https://documentation.mailgun.com/en/latest/user_manual.html?highlight=batch%20sending#batch-sending
|
|
206
212
|
const processedhtml = await processTemplate(settings, html)
|
|
213
|
+
const copies = { ...(settings.cc ? { cc: settings.cc } : {}), ...(settings.bcc ? { bcc: settings.bcc } : {}) }
|
|
207
214
|
const mailgunOpts = {
|
|
208
|
-
...(settings.
|
|
215
|
+
...(settings.isDev ? {} : copies),
|
|
209
216
|
...(settings.attachments?.length ? { attachments: settings.attachments } : {}),
|
|
210
217
|
from: settings.from,
|
|
211
218
|
html: processedhtml,
|
|
212
219
|
'h:Reply-To': settings.replyTo,
|
|
213
220
|
subject: settings.subject,
|
|
214
221
|
to: settings.to,
|
|
215
|
-
|
|
222
|
+
// A single `to` already had its placeholders filled in processTemplate
|
|
223
|
+
...(!settings.recipientVariables || !settings.to.match(/,/) ? {} : {
|
|
216
224
|
'recipient-variables': typeof settings.recipientVariables == 'string'
|
|
217
225
|
? settings.recipientVariables
|
|
218
226
|
: JSON.stringify(settings.recipientVariables),
|
|
@@ -221,6 +229,7 @@ async function sendWithMailgun(settings, html) {
|
|
|
221
229
|
if (settings.test && settings.isDev) {
|
|
222
230
|
console.info('Test mode: sendEmail mailgunOpts', {
|
|
223
231
|
...mailgunOpts,
|
|
232
|
+
...copies,
|
|
224
233
|
html: null,
|
|
225
234
|
'recipient-variables': settings.recipientVariables,
|
|
226
235
|
attachments: settings.attachments?.map((a) => `${a.filename} (${a.content?.length} bytes)`),
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* @param {string} opts.template - Template name or raw HTML, e.g., 'reset-password'
|
|
7
7
|
* @param {string} opts.to - Recipient(s), e.g. "Bruce<bruce@wayneenterprises.com>,..."
|
|
8
8
|
* @param {Config} opts.config - Config object
|
|
9
|
-
* @param {string} [opts.
|
|
9
|
+
* @param {string} [opts.cc] - CC, e.g. "Bruce<bruce@wayneenterprises.com>,..." (not sent in development)
|
|
10
|
+
* @param {string} [opts.bcc] - BCC, e.g. "Bruce<bruce@wayneenterprises.com>,..." (not sent in development)
|
|
10
11
|
* @param {object} [opts.data] - common template data shared across recipients
|
|
11
12
|
* @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun). Inherits data.
|
|
12
13
|
* @param {string} [opts.from] - sender address, e.g. "Bruce<bruce@wayneenterprises.com>"
|
|
@@ -18,10 +19,11 @@
|
|
|
18
19
|
* @param {{ filename: string, content: Buffer, contentType?: string }[]} [opts.attachments] - file attachments
|
|
19
20
|
* @returns {Promise<[any, any]>} Resolves with [mailgunErr, mailgunInfo]
|
|
20
21
|
*/
|
|
21
|
-
export function sendEmail({ template, to, config, bcc, data, swigData, from, replyTo, recipientVariables, subject, skipCssInline, test, attachments, }: {
|
|
22
|
+
export function sendEmail({ template, to, config, cc, bcc, data, swigData, from, replyTo, recipientVariables, subject, skipCssInline, test, attachments, }: {
|
|
22
23
|
template: string;
|
|
23
24
|
to: string;
|
|
24
25
|
config: Config;
|
|
26
|
+
cc?: string;
|
|
25
27
|
bcc?: string;
|
|
26
28
|
data?: object;
|
|
27
29
|
swigData?: object;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/email/index.js"],"names":[],"mappings":"AAmBA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/email/index.js"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,4JAhBG;IAAqB,QAAQ,EAArB,MAAM;IACO,EAAE,EAAf,MAAM;IACO,MAAM,EAAnB,MAAM;IACQ,EAAE,GAAhB,MAAM;IACQ,GAAG,GAAjB,MAAM;IACQ,IAAI,GAAlB,MAAM;IACQ,QAAQ,GAAtB,MAAM;IACQ,IAAI,GAAlB,MAAM;IACQ,OAAO,GAArB,MAAM;IACQ,kBAAkB,GAAhC,MAAM;IACQ,OAAO,GAArB,MAAM;IACS,aAAa,GAA5B,OAAO;IACQ,IAAI,GAAnB,OAAO;IAC8D,WAAW,GAAhF;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE;CACrE,GAAU,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CA8F/B;AArHD,+CAA8E;AAC9E,+CAAuG;;;;qBAK1F;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE"}
|