nitro-web 0.3.27 → 0.3.28

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/client/app.tsx CHANGED
@@ -1,3 +1,5 @@
1
+ // Pulls in axios-retry's types for the 'axios-retry' config key below
2
+ /// <reference types="axios-retry" />
1
3
  import { createBrowserRouter, createHashRouter, redirect, RouterProvider } from 'react-router-dom'
2
4
  import { Fragment, ReactNode } from 'react'
3
5
  import ReactDOM from 'react-dom/client'
@@ -10,7 +10,7 @@ type CommonProps = {
10
10
  rowClassName?: string
11
11
  }
12
12
  export type FilterType = (
13
- | FieldProps & CommonProps
13
+ | (FieldProps & CommonProps & { options?: never }) // Makes TS error when options are passed without type: 'select'
14
14
  | ({ type: 'select' } & SelectProps & CommonProps)
15
15
  )
16
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-web",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
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 🚀",
@@ -14,12 +14,13 @@ let nodemailerMailgun = undefined
14
14
  const _dirname = dirname(fileURLToPath(import.meta.url)) + '/'
15
15
 
16
16
  export const requiredEmailConfigKeys = ['baseUrl', 'emailFrom', 'name', 'env']
17
- export const optionalEmailConfigKeys = ['emailReplyTo', 'emailTestMode', 'mailgunDomain', 'mailgunKey']
17
+ export const optionalEmailConfigKeys = ['emailRedirectTo', 'emailReplyTo', 'emailTestMode', 'mailgunDomain', 'mailgunKey']
18
18
 
19
19
 
20
20
  /**
21
21
  * Sends an email using a predefined template, with optional data/or recipientVariables
22
- * @typedef {{ baseUrl?: string, emailFrom?: string, mailgunDomain?: string, mailgunKey?: string, name?: string }} Config
22
+ * @typedef {{ baseUrl?: string, emailFrom?: string, env?: string, mailgunDomain?: string, mailgunKey?: string,
23
+ * name?: string, pwd?: string, emailRedirectTo?: string }} Config
23
24
  *
24
25
  * @param {object} opts
25
26
  * @param {string} opts.template - Template name or raw HTML, e.g., 'reset-password'
@@ -109,10 +110,17 @@ export async function sendEmail({
109
110
  }
110
111
  }
111
112
 
113
+ // Send everything to emailRedirectTo instead, keeping the first recipient's variables
114
+ const redirectTo = config.emailRedirectTo
115
+ const others = recipients.length - 1
116
+ if (redirectTo) {
117
+ recipientVariables = { [getNameEmail(redirectTo)[1]]: recipientVariables[getNameEmail(to)[1]] }
118
+ }
119
+
112
120
  let settings = {
113
121
  attachments: attachments,
114
- cc: cc,
115
- bcc: bcc,
122
+ cc: redirectTo ? undefined : cc,
123
+ bcc: redirectTo ? undefined : bcc,
116
124
  emailTemplateDir: getDirectories(path, config.pwd).emailTemplateDir,
117
125
  from: from,
118
126
  isDev: config.env === 'development',
@@ -120,9 +128,10 @@ export async function sendEmail({
120
128
  replyTo: replyTo,
121
129
  skipCssInline: skipCssInline,
122
130
  subject: subject,
131
+ subjectPrefix: redirectTo ? `[redirected → ${getNameEmail(to)[1]}${others ? ` +${others}` : ''}] ` : '',
123
132
  template: template,
124
133
  test: isTest,
125
- to: to,
134
+ to: redirectTo || to,
126
135
  swigData: swigData,
127
136
  }
128
137
 
@@ -149,7 +158,7 @@ async function getTemplate(settings) {
149
158
  let template = nunjucksEnv.getTemplate(templateName + '.html', true)
150
159
  let html = template.render(settings.swigData || {})
151
160
  // Inline CSS
152
- if (!settings.skipCssInline || !settings.test) {
161
+ if (!settings.skipCssInline) {
153
162
  try {
154
163
  // First try to inline the CSS from the user templates directory
155
164
  html = await inlineCssForPath(html, settings.emailTemplateDir)
@@ -203,6 +212,8 @@ function processTemplate(settings, html) {
203
212
  if (foundSubject) settings.subject = foundSubject[1]
204
213
  else throw new Error('Sendmail: please pass `subject` or set it in the template')
205
214
  }
215
+ // Name the intended recipients on redirected emails
216
+ if (settings.subjectPrefix) settings.subject = settings.subjectPrefix + settings.subject
206
217
  return html
207
218
  }
208
219
 
@@ -0,0 +1,30 @@
1
+ import { test } from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { sendEmail } from '../server/email/index.js'
4
+
5
+ const redirect = { emailRedirectTo: 'Dev<dev@example.test>' }
6
+
7
+ test('sendEmail redirects in test mode too, keeping the intended recipient\'s variables and prefixing the subject', async () => {
8
+ // Development test mode logs what would be sent; capture that instead of posting to Mailgun
9
+ const info = console.info
10
+ const logged = []
11
+ console.info = (...args) => logged.push(args)
12
+ try {
13
+ const html = await sendEmail({
14
+ config: { ...redirect, baseUrl: 'http://localhost:3000', emailFrom: 'Nitro<support@nitro.test>', name: 'nitro',
15
+ env: 'development', emailTestMode: true, pwd: process.cwd() },
16
+ template: '<p>%recipient.greet%, this went to %recipient.email%</p>',
17
+ subject: 'Welcome %recipient.name%',
18
+ to: 'Jane<jane@customer.test>',
19
+ cc: 'cc@customer.test',
20
+ })
21
+ assert.equal(html, '<p>Hi Jane, this went to jane@customer.test</p>')
22
+ const sent = logged.find((args) => args[0] === 'Test mode: sendEmail mailgunOpts')?.[1]
23
+ assert.ok(sent, 'logged the message it would send')
24
+ assert.equal(sent.to, 'Dev<dev@example.test>')
25
+ assert.equal(sent.cc, undefined)
26
+ assert.equal(sent.subject, '[redirected → jane@customer.test +1] Welcome Jane')
27
+ } finally {
28
+ console.info = info
29
+ }
30
+ })
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Sends an email using a predefined template, with optional data/or recipientVariables
3
- * @typedef {{ baseUrl?: string, emailFrom?: string, mailgunDomain?: string, mailgunKey?: string, name?: string }} Config
3
+ * @typedef {{ baseUrl?: string, emailFrom?: string, env?: string, mailgunDomain?: string, mailgunKey?: string,
4
+ * name?: string, pwd?: string, emailRedirectTo?: string }} Config
4
5
  *
5
6
  * @param {object} opts
6
7
  * @param {string} opts.template - Template name or raw HTML, e.g., 'reset-password'
@@ -47,8 +48,11 @@ export const optionalEmailConfigKeys: string[];
47
48
  export type Config = {
48
49
  baseUrl?: string;
49
50
  emailFrom?: string;
51
+ env?: string;
50
52
  mailgunDomain?: string;
51
53
  mailgunKey?: string;
52
54
  name?: string;
55
+ pwd?: string;
56
+ emailRedirectTo?: string;
53
57
  };
54
58
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../server/email/index.js"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,4JAhBG;IAAqB,QAAQ,EAArB,MAAM;IACO,EAAE,EAAf,MAAM;IACO,MAAM,EAAnB,MAAM;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