mktcms 0.1.42 → 0.1.44

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mktcms",
3
3
  "configKey": "mktcms",
4
- "version": "0.1.42",
4
+ "version": "0.1.44",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -17,7 +17,6 @@ const value = defineModel("value", { type: Boolean, ...{
17
17
  >
18
18
  {{ label }}
19
19
  </label>
20
- <div class="relative">
21
- </div>
20
+ <div class="relative" />
22
21
  </div>
23
22
  </template>
@@ -5,6 +5,7 @@ export declare function useForm(endpoint: string, successMessageText: string, er
5
5
  errorMessage: import("vue").Ref<string, string>;
6
6
  validationErrors: import("vue").Ref<Record<string, string[] | undefined>, Record<string, string[] | undefined>>;
7
7
  fieldsTouched: import("vue").Ref<Record<string, boolean>, Record<string, boolean>>;
8
+ isValid: import("vue").ComputedRef<boolean>;
8
9
  validationErrorsFor: (field: string) => string[];
9
10
  validate: (body: Record<string, any>) => boolean;
10
11
  touchField: (field: string) => void;
@@ -1,11 +1,12 @@
1
1
  import { z } from "zod";
2
- import { ref } from "vue";
2
+ import { computed, ref } from "vue";
3
3
  export function useForm(endpoint, successMessageText, errorMessageText, validationSchema) {
4
4
  const isSending = ref(false);
5
5
  const successMessage = ref("");
6
6
  const errorMessage = ref("");
7
7
  const validationErrors = ref({});
8
8
  const fieldsTouched = ref({});
9
+ const isValid = computed(() => Object.keys(validationErrors.value).length === 0 && Object.keys(fieldsTouched.value).length > 0);
9
10
  function validate(body) {
10
11
  const parseResult = validationSchema.safeParse(body);
11
12
  if (parseResult.success) {
@@ -52,6 +53,7 @@ export function useForm(endpoint, successMessageText, errorMessageText, validati
52
53
  errorMessage,
53
54
  validationErrors,
54
55
  fieldsTouched,
56
+ isValid,
55
57
  validationErrorsFor,
56
58
  validate,
57
59
  touchField,
@@ -1,5 +1,7 @@
1
- export declare function sendMail({ subject, fields, replyTo }: {
1
+ export declare function sendMail({ subject, fields, replyTo, templateHtml, templateText, }: {
2
2
  subject: string;
3
3
  fields: Record<string, any>;
4
4
  replyTo?: string;
5
+ templateHtml?: string;
6
+ templateText?: string;
5
7
  }): Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
@@ -1,6 +1,13 @@
1
1
  import nodemailer from "nodemailer";
2
+ import ejs from "ejs";
2
3
  import { useRuntimeConfig } from "nitropack/runtime";
3
- export async function sendMail({ subject, fields, replyTo }) {
4
+ export async function sendMail({
5
+ subject,
6
+ fields,
7
+ replyTo,
8
+ templateHtml,
9
+ templateText
10
+ }) {
4
11
  const { mktcms: { smtpHost, smtpPort, smtpUser, smtpPass, smtpSecure, mailerFrom, mailerTo } } = useRuntimeConfig();
5
12
  const transporter = nodemailer.createTransport({
6
13
  host: smtpHost,
@@ -11,13 +18,15 @@ export async function sendMail({ subject, fields, replyTo }) {
11
18
  pass: smtpPass
12
19
  }
13
20
  });
21
+ const finalHtml = templateHtml ? ejs.render(templateHtml, { fields }) : Object.entries(fields).map(([key, value]) => `<p><strong>${key}:</strong> ${value}</p>`).join("");
22
+ const finalText = templateText ? ejs.render(templateText, { fields }) : Object.entries(fields).map(([key, value]) => `${key}: ${value}`).join("\n");
14
23
  const mailOptions = {
15
24
  from: mailerFrom,
16
25
  to: mailerTo,
17
26
  replyTo: replyTo || void 0,
18
27
  subject,
19
- html: Object.entries(fields).map(([key, value]) => `<p><strong>${key}:</strong> ${value}</p>`).join(""),
20
- text: Object.entries(fields).map(([key, value]) => `${key}: ${value}`).join("\n")
28
+ html: finalHtml,
29
+ text: finalText
21
30
  };
22
31
  return await transporter.sendMail(mailOptions);
23
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mktcms",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "Simple CMS module for Nuxt",
5
5
  "repository": "mktcode/mktcms",
6
6
  "license": "MIT",
@@ -39,10 +39,12 @@
39
39
  "dependencies": {
40
40
  "@nuxt/kit": "^4.2.2",
41
41
  "@nuxtjs/mdc": "^0.20.0",
42
+ "@types/ejs": "^3.1.5",
42
43
  "@vueuse/core": "^14.1.0",
43
44
  "csv-parse": "^6.1.0",
44
45
  "csv-stringify": "^6.6.0",
45
46
  "defu": "^6.1.4",
47
+ "ejs": "^4.0.1",
46
48
  "marked": "^17.0.1",
47
49
  "nodemailer": "^7.0.12",
48
50
  "sharp": "^0.34.5",