nitro-web 0.2.10 → 0.2.12

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.
@@ -739,8 +739,9 @@ export function resolveBaseUrl(reqUrl, cfgUrl) {
739
739
  try {
740
740
  const reqHost = new URL(reqUrl).hostname
741
741
  const cfgHost = new URL(cfgUrl).hostname
742
- const reqApex = getDomain(reqHost)
743
- const cfgApex = getDomain(cfgHost)
742
+ // tldts treats "localhost" as an unknown suffix, so we add an override
743
+ const reqApex = /(^|\.)localhost$/.test(reqHost) ? 'localhost' : getDomain(reqHost)
744
+ const cfgApex = /(^|\.)localhost$/.test(cfgHost) ? 'localhost' : getDomain(cfgHost)
744
745
  const errorMessage = 'Nitro warning: auth.resolveBaseUrl: The request origin and the config baseUrl ' +
745
746
  'are not the same apex domain. Defaulting to the Cfg baseUrl. Req:'
746
747
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitro-web",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
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 🚀",
@@ -31,7 +31,7 @@
31
31
  "minor": "npm run types && standard-version -a --release-as minor && npm publish && cd ../webpack && npm publish",
32
32
  "patch": "npm run types && standard-version -a --release-as patch && npm publish && cd ../webpack && npm publish",
33
33
  "republish": "npm publish && cd ../webpack && npm publish",
34
- "test": "node --test components/**/*.test.js",
34
+ "test": "node --test tests/",
35
35
  "types": "tsc util.js ./server/index.js --declaration --declarationMap --allowJs --emitDeclarationOnly --jsx react-jsx --esModuleInterop --skipLibCheck --outDir types && cd ../webpack && npm run types -w . && cd ../core"
36
36
  },
37
37
  "dependencies": {
@@ -26,8 +26,8 @@ export const optionalEmailConfigKeys = ['emailReplyTo', 'emailTestMode', 'mailgu
26
26
  * @param {string} opts.to - Recipient(s), e.g. "Bruce<bruce@wayneenterprises.com>,..."
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
- * @param {object} [opts.data] - template data shared across recipients
30
- * @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun)
29
+ * @param {object} [opts.data] - common template data shared across recipients
30
+ * @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun). Inherits data.
31
31
  * @param {string} [opts.from] - sender address, e.g. "Bruce<bruce@wayneenterprises.com>"
32
32
  * @param {string} [opts.replyTo] - reply-to address, e.g. "Bruce<bruce@wayneenterprises.com>"
33
33
  * @param {object} [opts.recipientVariables] - Mailgun recipient-variables for batch sending
@@ -72,12 +72,17 @@ export async function sendEmail({
72
72
  from = from || config.emailFrom
73
73
  replyTo = replyTo || config.emailReplyTo || from
74
74
 
75
+ const defaultData = {
76
+ configName: ucFirst(config.name),
77
+ domain: config.baseUrl,
78
+ replyToEmail: getNameEmail(replyTo)[1],
79
+ replyToName: getNameEmail(replyTo)[0],
80
+ ...(data || {}),
81
+ }
82
+
75
83
  if (swigData) {
76
84
  swigData = {
77
- configName: ucFirst(config.name),
78
- domain: config.baseUrl,
79
- replyToEmail: getNameEmail(replyTo)[1],
80
- replyToName: getNameEmail(replyTo)[0],
85
+ ...defaultData,
81
86
  ...swigData,
82
87
  }
83
88
  }
@@ -91,11 +96,7 @@ export async function sendEmail({
91
96
  for (let toNameEmail of toSplit) {
92
97
  const [toName, toEmail] = getNameEmail(toNameEmail)
93
98
  recipientVariables[toEmail] = {
94
- configName: ucFirst(config.name),
95
- domain: config.baseUrl,
96
- replyToEmail: getNameEmail(replyTo)[1],
97
- replyToName: getNameEmail(replyTo)[0],
98
- ...(data || {}),
99
+ ...defaultData,
99
100
  email: toEmail,
100
101
  greet: toName ? 'Hi ' + toName : 'Hello',
101
102
  name: toName,
@@ -115,7 +116,6 @@ export async function sendEmail({
115
116
  template: template,
116
117
  test: isTest,
117
118
  to: to,
118
- url: config.baseUrl,
119
119
  swigData: swigData,
120
120
  }
121
121
 
@@ -1,6 +1,6 @@
1
1
  import { test } from 'node:test'
2
2
  import assert from 'node:assert/strict'
3
- import { resolveBaseUrl } from './auth.api.js'
3
+ import { resolveBaseUrl } from '../components/auth/auth.api.js'
4
4
 
5
5
  const cases = [
6
6
  // [cfgUrl, reqUrl, expected, description]
@@ -16,6 +16,7 @@ const cases = [
16
16
 
17
17
  ['http://localhost:3000', 'http://localhost:3001', 'http://localhost:3001', 'match: localhost: port (ignored)'],
18
18
  ['http://localhost:3000', 'http://app.localhost:3001', 'http://app.localhost:3001', 'match: localhost: nested'],
19
+ ['http://app.localhost:3000', 'http://app2.localhost:3001', 'http://app2.localhost:3001', 'match: localhost: sibling'],
19
20
  ['http://127.0.0.1:3000', 'http://127.0.0.1:3000', 'http://127.0.0.1:3000', 'match: IP exact'],
20
21
 
21
22
  // cfg: mismatch
@@ -1 +1 @@
1
- {"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAqLA,qEAUC;AAED,qEAwEC;AAED,qEAGC;AAED,gEAMC;AAED,iEAgBC;AAED,oEAGC;AAED,oEA8BC;AAED,gEAgCC;AAID,qGAkDC;AAED;;;GAOC;AAED;;GAKC;AAID;;;;;;;;;GASG;AACH,8EAPG;IAA0B,QAAQ,GAA1B,MAAM;IACY,SAAS,GAA3B,MAAM;IACY,OAAO,GAAzB,MAAM;CACd,YAAQ,MAAM,+BACN,OAAO,GACL,OAAO,CAAC,MAAM,CAAC,CAqE3B;AAED,kFAiBC;AAED,mEAOC;AAED,+EAWC;AAED,sHAiBC;AAED;;;GAEC;AAED;;;GA0BC;AAED;;;;;;;;;GAmCC;AAED;;;;;;;;;;;;;;GAcG;AACH,mGAZG;IAAsD,IAAI,EAAlD,OAAO,GAAG,QAAQ,GAAG,eAAe;IACpB,EAAE,EAAlB,MAAM;IAKH,OAAO,EAJV;QACN,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QACtB,CAAK,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB;IAC0B,YAAY;IACZ,eAAe;IACjB,OAAO,GAAxB,MAAM;CACd,GAAU,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC,CAmEtE;AAED,0CAEC;AAED,8DA6BC;AAED,gFAKC;;;;;;;;;;;;;;;;;;;;AAzuBD;;;;;;;;;;;;;;;EAiBC;AA0ED,0DAEC;AAgCD,mDAEC;AAtBD,iDAkBC;AA5BD,2DAQC;AA0BD,2DAwBC;AAtID,0EAsEC"}
1
+ {"version":3,"file":"auth.api.d.ts","sourceRoot":"","sources":["../../../components/auth/auth.api.js"],"names":[],"mappings":"AAqLA,qEAUC;AAED,qEAwEC;AAED,qEAGC;AAED,gEAMC;AAED,iEAgBC;AAED,oEAGC;AAED,oEA8BC;AAED,gEAgCC;AAID,qGAkDC;AAED;;;GAOC;AAED;;GAKC;AAID;;;;;;;;;GASG;AACH,8EAPG;IAA0B,QAAQ,GAA1B,MAAM;IACY,SAAS,GAA3B,MAAM;IACY,OAAO,GAAzB,MAAM;CACd,YAAQ,MAAM,+BACN,OAAO,GACL,OAAO,CAAC,MAAM,CAAC,CAqE3B;AAED,kFAiBC;AAED,mEAOC;AAED,+EAWC;AAED,sHAiBC;AAED;;;GAEC;AAED;;;GA0BC;AAED;;;;;;;;;GAmCC;AAED;;;;;;;;;;;;;;GAcG;AACH,mGAZG;IAAsD,IAAI,EAAlD,OAAO,GAAG,QAAQ,GAAG,eAAe;IACpB,EAAE,EAAlB,MAAM;IAKH,OAAO,EAJV;QACN,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QACtB,CAAK,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB;IAC0B,YAAY;IACZ,eAAe;IACjB,OAAO,GAAxB,MAAM;CACd,GAAU,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CAAC,CAAC,CAmEtE;AAED,0CAEC;AAED,8DA8BC;AAED,gFAKC;;;;;;;;;;;;;;;;;;;;AA1uBD;;;;;;;;;;;;;;;EAiBC;AA0ED,0DAEC;AAgCD,mDAEC;AAtBD,iDAkBC;AA5BD,2DAQC;AA0BD,2DAwBC;AAtID,0EAsEC"}
@@ -7,8 +7,8 @@
7
7
  * @param {string} opts.to - Recipient(s), e.g. "Bruce<bruce@wayneenterprises.com>,..."
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
- * @param {object} [opts.data] - template data shared across recipients
11
- * @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun)
10
+ * @param {object} [opts.data] - common template data shared across recipients
11
+ * @param {object} [opts.swigData] - vars for Nunjucks/Swig render only (not sent to Mailgun). Inherits data.
12
12
  * @param {string} [opts.from] - sender address, e.g. "Bruce<bruce@wayneenterprises.com>"
13
13
  * @param {string} [opts.replyTo] - reply-to address, e.g. "Bruce<bruce@wayneenterprises.com>"
14
14
  * @param {object} [opts.recipientVariables] - Mailgun recipient-variables for batch sending