nuxt-generation-emails 1.4.6 → 1.4.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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "1.4.6",
7
+ "version": "1.4.7",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,10 +1,12 @@
1
1
  <script setup>
2
2
  import { ref, computed } from "vue";
3
- import { useRoute, useCookie } from "#imports";
3
+ import { useRoute, useCookie, useRouter } from "#imports";
4
+ import { resolveApiEndpointFromPreviewPath } from "../utils/email-route";
4
5
  const props = defineProps({
5
6
  dataObject: { type: Object, required: true }
6
7
  });
7
8
  const route = useRoute();
9
+ const router = useRouter();
8
10
  const isLoading = ref(false);
9
11
  const response = ref("");
10
12
  const responseData = ref(null);
@@ -19,8 +21,8 @@ const testEmailTo = ref(lastUsedEmail.value || "");
19
21
  const sendStatus = ref("idle");
20
22
  let sendStatusTimeout = null;
21
23
  const apiEndpoint = computed(() => {
22
- const templatePath = route.path.replace("/__emails/", "");
23
- return `/api/emails/${templatePath}`;
24
+ const availablePreviewPaths = router.getRoutes().filter((route2) => route2.path.startsWith("/__emails/")).map((route2) => route2.path);
25
+ return resolveApiEndpointFromPreviewPath(route.path, availablePreviewPaths);
24
26
  });
25
27
  const htmlResponse = computed(() => {
26
28
  if (!responseData.value || typeof responseData.value !== "object") return "";
@@ -0,0 +1,3 @@
1
+ export declare function toTemplatePath(previewPath: string): string;
2
+ export declare function normalizeApiTemplatePath(templatePath: string, availableTemplatePaths: string[]): string;
3
+ export declare function resolveApiEndpointFromPreviewPath(currentPreviewPath: string, availablePreviewPaths: string[]): string;
@@ -0,0 +1,30 @@
1
+ const PREVIEW_PREFIX = "/__emails/";
2
+ function stripLeadingSlash(value) {
3
+ return value.replace(/^\/+/, "");
4
+ }
5
+ export function toTemplatePath(previewPath) {
6
+ if (previewPath.startsWith(PREVIEW_PREFIX)) {
7
+ return stripLeadingSlash(previewPath.slice(PREVIEW_PREFIX.length));
8
+ }
9
+ return stripLeadingSlash(previewPath);
10
+ }
11
+ export function normalizeApiTemplatePath(templatePath, availableTemplatePaths) {
12
+ if (!templatePath || templatePath === "index") {
13
+ return templatePath;
14
+ }
15
+ if (!templatePath.endsWith("/index")) {
16
+ return templatePath;
17
+ }
18
+ const indexlessPath = templatePath.slice(0, -"/index".length);
19
+ const hasSiblingTemplate = availableTemplatePaths.includes(indexlessPath);
20
+ if (hasSiblingTemplate) {
21
+ return templatePath;
22
+ }
23
+ return indexlessPath;
24
+ }
25
+ export function resolveApiEndpointFromPreviewPath(currentPreviewPath, availablePreviewPaths) {
26
+ const templatePath = toTemplatePath(currentPreviewPath);
27
+ const availableTemplatePaths = availablePreviewPaths.map(toTemplatePath);
28
+ const normalizedTemplatePath = normalizeApiTemplatePath(templatePath, availableTemplatePaths);
29
+ return `/api/emails/${normalizedTemplatePath}`;
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-generation-emails",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
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": {