nitro-web 0.2.6 → 0.2.7
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.2.
|
|
3
|
+
"version": "0.2.7",
|
|
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 🚀",
|
package/server/email/index.js
CHANGED
|
@@ -27,6 +27,7 @@ export const optionalEmailConfigKeys = ['emailReplyTo', 'emailTestMode', 'mailgu
|
|
|
27
27
|
* @param {Config} opts.config - Config object
|
|
28
28
|
* @param {string} [opts.bcc] - BCC, e.g. "Bruce<bruce@wayneenterprises.com>" (not sent in development)
|
|
29
29
|
* @param {object} [opts.data] - template data shared across recipients
|
|
30
|
+
* @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun)
|
|
30
31
|
* @param {string} [opts.from] - sender address, e.g. "Bruce<bruce@wayneenterprises.com>"
|
|
31
32
|
* @param {string} [opts.replyTo] - reply-to address, e.g. "Bruce<bruce@wayneenterprises.com>"
|
|
32
33
|
* @param {object} [opts.recipientVariables] - Mailgun recipient-variables for batch sending
|
|
@@ -40,7 +41,8 @@ export async function sendEmail({
|
|
|
40
41
|
to,
|
|
41
42
|
config,
|
|
42
43
|
bcc,
|
|
43
|
-
data,
|
|
44
|
+
data,
|
|
45
|
+
swigData,
|
|
44
46
|
from,
|
|
45
47
|
replyTo,
|
|
46
48
|
recipientVariables,
|
|
@@ -69,6 +71,17 @@ export async function sendEmail({
|
|
|
69
71
|
// From, replayTo
|
|
70
72
|
from = from || config.emailFrom
|
|
71
73
|
replyTo = replyTo || config.emailReplyTo || from
|
|
74
|
+
|
|
75
|
+
if (swigData) {
|
|
76
|
+
swigData = {
|
|
77
|
+
configName: ucFirst(config.name),
|
|
78
|
+
domain: config.baseUrl,
|
|
79
|
+
replyToEmail: getNameEmail(replyTo)[1],
|
|
80
|
+
replyToName: getNameEmail(replyTo)[0],
|
|
81
|
+
...swigData,
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
72
85
|
const toSplit = to.split(',')
|
|
73
86
|
|
|
74
87
|
// Add default recipientVariables
|
|
@@ -103,6 +116,7 @@ export async function sendEmail({
|
|
|
103
116
|
test: isTest,
|
|
104
117
|
to: to,
|
|
105
118
|
url: config.baseUrl,
|
|
119
|
+
swigData: swigData,
|
|
106
120
|
}
|
|
107
121
|
|
|
108
122
|
// Grab html and send
|
|
@@ -114,36 +128,36 @@ export async function sendEmail({
|
|
|
114
128
|
async function getTemplate(settings) {
|
|
115
129
|
try {
|
|
116
130
|
var templateName = settings.template
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
// Return cached template (if there is no swig data)
|
|
132
|
+
if (templates[templateName] && !settings.isDev && !settings.swigData) {
|
|
133
|
+
return templates[templateName]
|
|
134
|
+
}
|
|
135
|
+
// Setup the nunjucks environment
|
|
136
|
+
nunjucks.configure({ noCache: settings.isDev })
|
|
137
|
+
let nunjucksEnv = new nunjucks.Environment([
|
|
138
|
+
new nunjucks.FileSystemLoader(`${settings.emailTemplateDir}`), // user templates take precedence
|
|
139
|
+
new nunjucks.FileSystemLoader(`${_dirname}`), // then fallback to nitro default templates
|
|
140
|
+
])
|
|
141
|
+
// Get the template
|
|
142
|
+
let template = nunjucksEnv.getTemplate(templateName + '.html', true)
|
|
143
|
+
let html = template.render(settings.swigData || {})
|
|
144
|
+
// Inline CSS
|
|
145
|
+
if (!settings.skipCssInline || !settings.test) {
|
|
146
|
+
try {
|
|
147
|
+
// First try to inline the CSS from the user templates directory
|
|
148
|
+
html = await inlineCssForPath(html, settings.emailTemplateDir)
|
|
149
|
+
} catch (e) {
|
|
150
|
+
// If the CSS is not found, use default nitro CSS file
|
|
151
|
+
if (templateName == 'reset-password' || templateName == 'welcome') {
|
|
152
|
+
html = await inlineCssForPath(html, `${_dirname}`)
|
|
153
|
+
} else {
|
|
154
|
+
throw e
|
|
141
155
|
}
|
|
142
156
|
}
|
|
143
|
-
return templates[templateName]
|
|
144
|
-
} else {
|
|
145
|
-
return templates[templateName]
|
|
146
157
|
}
|
|
158
|
+
// Cache the template (if there is no swig data)
|
|
159
|
+
if (!settings.swigData) templates[templateName] = html
|
|
160
|
+
return html
|
|
147
161
|
} catch (e) {
|
|
148
162
|
console.error(`Sendmail: issue retrieving the email template "${templateName}.html"`)
|
|
149
163
|
console.error(e)
|
package/server/router.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @param {Config} opts.config - Config object
|
|
9
9
|
* @param {string} [opts.bcc] - BCC, e.g. "Bruce<bruce@wayneenterprises.com>" (not sent in development)
|
|
10
10
|
* @param {object} [opts.data] - template data shared across recipients
|
|
11
|
+
* @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun)
|
|
11
12
|
* @param {string} [opts.from] - sender address, e.g. "Bruce<bruce@wayneenterprises.com>"
|
|
12
13
|
* @param {string} [opts.replyTo] - reply-to address, e.g. "Bruce<bruce@wayneenterprises.com>"
|
|
13
14
|
* @param {object} [opts.recipientVariables] - Mailgun recipient-variables for batch sending
|
|
@@ -16,12 +17,13 @@
|
|
|
16
17
|
* @param {boolean} [opts.test] - enable test mode
|
|
17
18
|
* @returns {Promise<[any, any]>} Resolves with [mailgunErr, mailgunInfo]
|
|
18
19
|
*/
|
|
19
|
-
export function sendEmail({ template, to, config, bcc, data, from, replyTo, recipientVariables, subject, skipCssInline, test, }: {
|
|
20
|
+
export function sendEmail({ template, to, config, bcc, data, swigData, from, replyTo, recipientVariables, subject, skipCssInline, test, }: {
|
|
20
21
|
template: string;
|
|
21
22
|
to: string;
|
|
22
23
|
config: Config;
|
|
23
24
|
bcc?: string;
|
|
24
25
|
data?: object;
|
|
26
|
+
swigData?: object;
|
|
25
27
|
from?: string;
|
|
26
28
|
replyTo?: string;
|
|
27
29
|
recipientVariables?: 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;;;;;;;;;;;;;;;;;;GAkBG;AACH,2IAdG;IAAqB,QAAQ,EAArB,MAAM;IACO,EAAE,EAAf,MAAM;IACO,MAAM,EAAnB,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;CACf,GAAU,OAAO,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAyF/B;AA9GD,+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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../server/router.js"],"names":[],"mappings":"AAoCA,uGAAuG;AACvG,0CADc,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,SAAS,EAAE,WAAW,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../server/router.js"],"names":[],"mappings":"AAoCA,uGAAuG;AACvG,0CADc,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,SAAS,EAAE,WAAW,CAAA;CAAE,CAAC,CAgIlG;AAkPD,+CAEC;AAED,kEAYC;AAzGD,+BAA+B;AAC/B,yBADW,gBAAgB,CAuF1B;sBApYY,OAAO,CAAC,OAAO,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAoB,CAAC;CAC7B;uBACS,OAAO,CAAC,QAAQ,GAAG;IAC3B,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjE,YAAY,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;IACvD,SAAS,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;IACpD,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;IACnD,WAAW,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,IAAI,CAAC;CACvD;+BACS;IACR,KAAK,EAAE,MAAM,EAAE,CAAC;IACpB,CAAK,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,UAAU,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,CAAC;CACnF;oBAtBgB,SAAS"}
|