@paroicms/contact-form-plugin 0.17.2 → 0.18.0

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.
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sendContactFormMail = sendContactFormMail;
4
- const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
5
- const public_server_lib_1 = require("@paroicms/public-server-lib");
6
- async function sendContactFormMail(service, input, i18n) {
1
+ import { messageOf, strValOrUndef } from "@paroi/data-formatters-lib";
2
+ import { escapeHtml, } from "@paroicms/public-server-lib";
3
+ export async function sendContactFormMail(service, input, i18n) {
7
4
  const { email, name, message, subject, gRecaptchaResponse } = input;
8
5
  let contactEmail;
9
6
  try {
10
- contactEmail = (0, data_formatters_lib_1.strValOrUndef)(await service.getSiteFieldValue({
7
+ contactEmail = strValOrUndef(await service.getSiteFieldValue({
11
8
  fieldName: "contactEmail",
12
9
  language: input.language,
13
10
  }));
@@ -28,14 +25,14 @@ async function sendContactFormMail(service, input, i18n) {
28
25
  html: `<p>${i18n.translate({
29
26
  key: "nameIs",
30
27
  language: input.language,
31
- args: [(0, public_server_lib_1.escapeHtml)(name)],
28
+ args: [escapeHtml(name)],
32
29
  })}</p>
33
30
  <p>${i18n.translate({
34
31
  key: "emailIs",
35
32
  language: input.language,
36
- args: [(0, public_server_lib_1.escapeHtml)(email)],
33
+ args: [escapeHtml(email)],
37
34
  })}</p>
38
- <p>${(0, public_server_lib_1.escapeHtml)(message, { newLinesToBr: true })}</p>`,
35
+ <p>${escapeHtml(message, { newLinesToBr: true })}</p>`,
39
36
  });
40
37
  return {
41
38
  success: true,
@@ -44,7 +41,7 @@ async function sendContactFormMail(service, input, i18n) {
44
41
  catch (err) {
45
42
  if (err)
46
43
  throw err;
47
- service.logger.error(`fail to send mail: ${(0, data_formatters_lib_1.messageOf)(err)}`);
44
+ service.logger.error(`fail to send mail: ${messageOf(err)}`);
48
45
  return {
49
46
  success: false,
50
47
  message: contactEmail
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatSendMailInput = formatSendMailInput;
4
- const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
5
- function formatSendMailInput(data) {
1
+ import { strVal, strValOrUndef } from "@paroi/data-formatters-lib";
2
+ export function formatSendMailInput(data) {
6
3
  return {
7
- language: (0, data_formatters_lib_1.strVal)(data.language),
8
- email: (0, data_formatters_lib_1.strVal)(data.email),
9
- name: (0, data_formatters_lib_1.strVal)(data.name),
10
- subject: (0, data_formatters_lib_1.strValOrUndef)(data.subject),
11
- message: (0, data_formatters_lib_1.strVal)(data.message),
12
- gRecaptchaResponse: (0, data_formatters_lib_1.strValOrUndef)(data.gRecaptchaResponse),
4
+ language: strVal(data.language),
5
+ email: strVal(data.email),
6
+ name: strVal(data.name),
7
+ subject: strValOrUndef(data.subject),
8
+ message: strVal(data.message),
9
+ gRecaptchaResponse: strValOrUndef(data.gRecaptchaResponse),
13
10
  };
14
11
  }
@@ -1,24 +1,23 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
4
- const public_server_lib_1 = require("@paroicms/public-server-lib");
5
- const node_path_1 = require("node:path");
6
- const contact_form_mail_1 = require("./contact-form-mail");
7
- const data_format_1 = require("./data-format");
8
- const projectDir = (0, node_path_1.dirname)(__dirname);
9
- const packageDir = (0, node_path_1.dirname)(projectDir);
10
- const version = (0, data_formatters_lib_1.strVal)(require((0, node_path_1.join)(packageDir, "package.json")).version);
1
+ import { strVal } from "@paroi/data-formatters-lib";
2
+ import { escapeHtml, loadSimpleTranslatorFromDirectory, resolveModuleDirectory, } from "@paroicms/public-server-lib";
3
+ import { readFileSync } from "node:fs";
4
+ import { dirname, join } from "node:path";
5
+ import { sendContactFormMail } from "./contact-form-mail.js";
6
+ import { formatSendMailInput } from "./data-format.js";
7
+ const projectDir = resolveModuleDirectory(import.meta.url, { parent: true });
8
+ const packageDir = dirname(projectDir);
9
+ const version = strVal(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8")).version);
11
10
  const plugin = {
12
11
  version,
13
12
  slug: "contact-form",
14
13
  async siteInit(service) {
15
- const simpleI18n = await (0, public_server_lib_1.loadSimpleTranslatorFromDirectory)({
16
- l10nDir: (0, node_path_1.join)(projectDir, "locales"),
14
+ const simpleI18n = await loadSimpleTranslatorFromDirectory({
15
+ l10nDir: join(projectDir, "locales"),
17
16
  languages: ["en", "fr"],
18
17
  logger: service.logger,
19
18
  });
20
- service.setPublicAssetsDirectory((0, node_path_1.join)(packageDir, "public-front", "dist"));
21
- service.addHeadTag(`<link rel="stylesheet" href="${(0, public_server_lib_1.escapeHtml)(`${service.pluginAssetsUrl}/public-front-plugin.css`)}">`, `<script type="module" src="${(0, public_server_lib_1.escapeHtml)(`${service.pluginAssetsUrl}/public-front-plugin.mjs`)}"></script>`);
19
+ service.setPublicAssetsDirectory(join(packageDir, "public-front", "dist"));
20
+ service.addHeadTag(`<link rel="stylesheet" href="${escapeHtml(`${service.pluginAssetsUrl}/public-front-plugin.css`)}">`, `<script type="module" src="${escapeHtml(`${service.pluginAssetsUrl}/public-front-plugin.mjs`)}"></script>`);
22
21
  service.setPublicApiHandler(async (service, req, res, relativePath) => {
23
22
  if (relativePath !== "") {
24
23
  res.status(404).send({ status: 404 });
@@ -26,15 +25,15 @@ const plugin = {
26
25
  }
27
26
  let input;
28
27
  try {
29
- input = (0, data_format_1.formatSendMailInput)(req.body);
28
+ input = formatSendMailInput(req.body);
30
29
  }
31
30
  catch (error) {
32
31
  res.status(400).send({ status: 400, message: error.message });
33
32
  return;
34
33
  }
35
- const result = await (0, contact_form_mail_1.sendContactFormMail)(service, input, simpleI18n);
34
+ const result = await sendContactFormMail(service, input, simpleI18n);
36
35
  res.send(result);
37
36
  });
38
37
  },
39
38
  };
40
- exports.default = plugin;
39
+ export default plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/contact-form-plugin",
3
- "version": "0.17.2",
3
+ "version": "0.18.0",
4
4
  "description": "Contact form plugin for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -15,6 +15,8 @@
15
15
  },
16
16
  "author": "Paroi Team",
17
17
  "license": "MIT",
18
+ "type": "module",
19
+ "main": "backend/dist/plugin.js",
18
20
  "scripts": {
19
21
  "dev:public": "(cd public-front && vite)",
20
22
  "build": "npm run build:backend && npm run build:public",
@@ -32,8 +34,8 @@
32
34
  "@paroicms/public-server-lib": "0"
33
35
  },
34
36
  "devDependencies": {
35
- "@paroicms/public-anywhere-lib": "0.14.0",
36
- "@paroicms/public-server-lib": "0.22.1",
37
+ "@paroicms/public-anywhere-lib": "0.15.0",
38
+ "@paroicms/public-server-lib": "0.23.0",
37
39
  "@solid-primitives/i18n": "~2.1.1",
38
40
  "@types/node": "~22.10.7",
39
41
  "rimraf": "~6.0.1",
@@ -45,7 +47,6 @@
45
47
  "vite-plugin-solid": "~2.11.0",
46
48
  "terser": "~5.37.0"
47
49
  },
48
- "main": "backend/dist/plugin.js",
49
50
  "files": [
50
51
  "backend/dist",
51
52
  "backend/locales",