nuxt-generation-emails 1.4.3 → 1.4.5

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/README.md CHANGED
@@ -284,6 +284,11 @@ The `components/` directory is reserved — it is skipped during route generatio
284
284
  |----------------------------|-------------------------------|-------------------------------|
285
285
  | `emails/welcome.vue` | `/__emails/welcome` | `POST /api/emails/welcome` |
286
286
  | `emails/v1/order.vue` | `/__emails/v1/order` | `POST /api/emails/v1/order` |
287
+ | `emails/v1/order/index.vue` | `/__emails/v1/order/index` | `POST /api/emails/v1/order` |
288
+
289
+ For API endpoints, nested `index.vue` files are treated as directory index routes, so the trailing `/index` is removed. Root-level `emails/index.vue` keeps the existing endpoint: `POST /api/emails/index`.
290
+
291
+ If both `emails/foo.vue` and `emails/foo/index.vue` exist, the nested file keeps `POST /api/emails/foo/index` to avoid route collisions and preserve OpenAPI examples/schema for both handlers.
287
292
 
288
293
  ---
289
294
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "1.4.3",
7
+ "version": "1.4.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -762,6 +762,18 @@ function sanitizeForOpenApi(value) {
762
762
  }
763
763
  return value;
764
764
  }
765
+ function normalizeApiEmailPath(emailsDir, routePrefix, emailName) {
766
+ const rawPath = `${routePrefix}/${emailName}`.replace(/^\//, "");
767
+ if (emailName === "index" && routePrefix) {
768
+ const indexlessPath = routePrefix.replace(/^\//, "");
769
+ const siblingTemplatePath = join(emailsDir, `${indexlessPath}.vue`);
770
+ if (fs.existsSync(siblingTemplatePath)) {
771
+ return rawPath;
772
+ }
773
+ return indexlessPath;
774
+ }
775
+ return rawPath;
776
+ }
765
777
  function generateServerRoutes(emailsDir, buildDir) {
766
778
  if (!fs.existsSync(emailsDir)) return [];
767
779
  const handlersDir = join(buildDir, "email-handlers");
@@ -781,7 +793,7 @@ function generateServerRoutes(emailsDir, buildDir) {
781
793
  processEmailDirectory(fullPath, `${routePrefix}/${entry}`);
782
794
  } else if (entry.endsWith(".vue")) {
783
795
  const emailName = entry.replace(".vue", "");
784
- const emailPath = `${routePrefix}/${emailName}`.replace(/^\//, "");
796
+ const emailPath = normalizeApiEmailPath(emailsDir, routePrefix, emailName);
785
797
  const mjmlTemplateName = extractMjmlTemplateName(fullPath);
786
798
  if (!mjmlTemplateName) {
787
799
  console.warn(`[nuxt-generation-emails] Could not find useNgeTemplate() call in ${emailName}.vue \u2014 skipping API route.`);
@@ -798,7 +810,8 @@ function generateServerRoutes(emailsDir, buildDir) {
798
810
  }
799
811
  const { defaults } = extractPropsFromSFC(fullPath);
800
812
  const sanitized = sanitizeForOpenApi(defaults);
801
- const examplePayload = Object.keys(sanitized).length > 0 ? JSON.stringify(sanitized, null, 2) : "{}";
813
+ const sanitizedDefaults = sanitized && typeof sanitized === "object" && !Array.isArray(sanitized) ? sanitized : {};
814
+ const examplePayload = Object.keys(sanitizedDefaults).length > 0 ? JSON.stringify(sanitizedDefaults, null, 2) : "{}";
802
815
  const handlerFileName = `${emailName}.ts`;
803
816
  const handlerFilePath = join(handlerDir, handlerFileName);
804
817
  const handlerContent = generateApiRoute(emailName, emailPath, examplePayload, mjmlTemplateName);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-generation-emails",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "A Nuxt module for authoring, previewing, and sending transactional email templates with MJML and Handlebars.",
5
5
  "author": "nullcarry@icloud.com",
6
6
  "repository": {