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 +5 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +15 -2
- package/package.json +1 -1
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
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 =
|
|
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
|
|
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