@paroicms/contact-form-plugin 0.3.1 → 0.4.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @paroicms/contact-form-plugin
2
2
 
3
- Contact form for ParoiCMS.
3
+ Contact form plugin for ParoiCMS.
4
4
 
5
5
  This package is part of [ParoiCMS](https://www.npmjs.com/package/@paroicms/server).
6
6
 
@@ -3,45 +3,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sendContactFormMail = void 0;
4
4
  const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
5
5
  const public_server_lib_1 = require("@paroicms/public-server-lib");
6
- const plugin_1 = require("../plugin");
7
- async function sendContactFormMail(pluginSiteContext, input) {
6
+ async function sendContactFormMail(ctx, input, i18n) {
8
7
  const { email, name, message, subject, gRecaptchaResponse } = input;
9
8
  let contactEmail;
10
9
  try {
11
- contactEmail = (0, data_formatters_lib_1.strValOrUndef)(await pluginSiteContext.getSiteFieldValue({
10
+ contactEmail = (0, data_formatters_lib_1.strValOrUndef)(await ctx.getSiteFieldValue({
12
11
  fieldName: "contactEmail",
13
12
  language: input.language,
14
13
  }));
15
14
  if (!contactEmail)
16
- throw new Error(`['${pluginSiteContext.fqdn}'] missing 'contactEmail' site field`);
17
- if (!(await pluginSiteContext.validateRecaptchaResponse(gRecaptchaResponse))) {
15
+ throw new Error(`['${ctx.fqdn}'] missing 'contactEmail'`);
16
+ if (!(await ctx.validateRecaptchaResponse(gRecaptchaResponse))) {
18
17
  throw new Error("invalid recaptcha response");
19
18
  }
20
- const noSubject = plugin_1.simpleI18n.translate({
21
- key: "mail.noSubject",
19
+ const noSubject = i18n.translate({
20
+ key: "noSubject",
22
21
  language: input.language,
23
22
  });
24
- const contactFrom = plugin_1.simpleI18n.translate({
25
- key: "mail.contactFrom",
23
+ const contactFrom = i18n.translate({
24
+ key: "contactFrom",
26
25
  language: input.language,
27
- args: [pluginSiteContext.fqdn],
26
+ args: [ctx.fqdn],
28
27
  });
29
- await pluginSiteContext.sendMail({
28
+ await ctx.sendMail({
30
29
  to: contactEmail,
31
30
  replyTo: { email, name },
32
31
  subject: `${subject ?? noSubject} ${contactFrom}`,
33
- html: `<p>${plugin_1.simpleI18n.translate({
34
- key: "mail.nameIs",
32
+ html: `<p>${i18n.translate({
33
+ key: "nameIs",
35
34
  language: input.language,
36
35
  args: [(0, public_server_lib_1.escapeHtml)(name)],
37
36
  })}</p>
38
- <p>${plugin_1.simpleI18n.translate({
39
- key: "mail.emailIs",
37
+ <p>${i18n.translate({
38
+ key: "emailIs",
40
39
  language: input.language,
41
40
  args: [(0, public_server_lib_1.escapeHtml)(email)],
42
41
  })}</p>
43
42
  <p>${(0, public_server_lib_1.escapeHtml)(message, { newLinesToBr: true })}</p>`,
44
- }, { appLog: pluginSiteContext.siteLog });
43
+ }, { appLog: ctx.siteLog });
45
44
  return {
46
45
  success: true,
47
46
  };
@@ -49,17 +48,17 @@ async function sendContactFormMail(pluginSiteContext, input) {
49
48
  catch (err) {
50
49
  if (err)
51
50
  throw err;
52
- pluginSiteContext.siteLog.error(`fail to send mail: ${(0, data_formatters_lib_1.messageOf)(err)}`);
51
+ ctx.siteLog.error(`fail to send mail: ${(0, data_formatters_lib_1.messageOf)(err)}`);
53
52
  return {
54
53
  success: false,
55
54
  message: contactEmail
56
- ? plugin_1.simpleI18n.translate({
57
- key: "mail.sendUsAnEmailTo",
55
+ ? i18n.translate({
56
+ key: "sendUsAnEmailTo",
58
57
  language: input.language,
59
58
  args: [contactEmail],
60
59
  })
61
- : plugin_1.simpleI18n.translate({
62
- key: "mail.sorryMessage",
60
+ : i18n.translate({
61
+ key: "sorryMessage",
63
62
  language: input.language,
64
63
  }),
65
64
  senderEmail: email,
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.plugin = void 0;
4
+ const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
5
+ const public_server_lib_1 = require("@paroicms/public-server-lib");
6
+ const node_path_1 = require("node:path");
7
+ const contact_form_mail_1 = require("./contact-form-mail");
8
+ const data_format_1 = require("./data-format");
9
+ const projectDir = (0, node_path_1.dirname)(__dirname);
10
+ const packageDir = (0, node_path_1.dirname)(projectDir);
11
+ const version = (0, data_formatters_lib_1.strVal)(require((0, node_path_1.join)(packageDir, "package.json")).version);
12
+ const assetsBaseUrl = `/assets/plugin/contact-form/${version}`;
13
+ exports.plugin = {
14
+ version,
15
+ async siteInit(api) {
16
+ const simpleI18n = await (0, public_server_lib_1.createSimpleTranslator)({
17
+ l10nDir: (0, node_path_1.join)(projectDir, "locales"),
18
+ languages: ["en", "fr"],
19
+ appLog: api.siteLog,
20
+ });
21
+ api.setPublicAssetsDirectory((0, node_path_1.join)(packageDir, "public-front", "dist"));
22
+ api.addHeadTag(`<link rel="stylesheet" href="${(0, public_server_lib_1.escapeHtml)(`${assetsBaseUrl}/style.css`)}">`, `<script type="module" src="${(0, public_server_lib_1.escapeHtml)(`${assetsBaseUrl}/public-front-plugin.mjs`)}"></script>`);
23
+ api.setPublicApiHandler(async (ctx, req, res, relativePath) => {
24
+ if (relativePath !== "") {
25
+ res.status(404).send({ status: 404 });
26
+ return;
27
+ }
28
+ let input;
29
+ try {
30
+ input = (0, data_format_1.formatSendMailInput)(req.body);
31
+ }
32
+ catch (error) {
33
+ res.status(400).send({ status: 400, message: error.message });
34
+ return;
35
+ }
36
+ const result = await (0, contact_form_mail_1.sendContactFormMail)(ctx, input, simpleI18n);
37
+ res.send(result);
38
+ });
39
+ },
40
+ };
@@ -0,0 +1,8 @@
1
+ {
2
+ "noSubject": "-no subject-",
3
+ "contactFrom": "(contact from $1)",
4
+ "nameIs": "<b>Name:</b> $1",
5
+ "emailIs": "<b>E-mail:</b> $1",
6
+ "sendUsAnEmailTo": "send us an e-mail to: $1",
7
+ "sorryMessage": "sorry, the website is incorrectly configured"
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "noSubject": "-sans sujet-",
3
+ "contactFrom": "(contact via $1)",
4
+ "nameIs": "<b>Nom :</b> $1",
5
+ "emailIs": "<b>E-mail :</b> $1",
6
+ "sendUsAnEmailTo": "envoyez-nous un e-mail directement à : $1",
7
+ "sorryMessage": "désolé, le site est mal configuré"
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/contact-form-plugin",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Contact form for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -11,28 +11,27 @@
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "https://gitlab.com/paroi/opensource/paroicms.git",
14
- "directory": "plugins/contact-form"
14
+ "directory": "plugins/contact-form-plugin"
15
15
  },
16
16
  "author": "Paroi Team",
17
17
  "license": "MIT",
18
18
  "scripts": {
19
19
  "dev": "vite",
20
20
  "build": "npm run build:backend && npm run build:frontend",
21
- "build:backend": "tsc --project tsconfig.backend.json",
22
- "build:frontend": "tsc && vite build",
23
- "clear": "rimraf bo-dist/*",
24
- "preview": "vite preview"
21
+ "build:backend": "(cd backend && tsc)",
22
+ "build:frontend": "(cd public-front && tsc && vite build)",
23
+ "clear": "rimraf backend/dist/* public-front/dist/*"
25
24
  },
26
25
  "dependencies": {
27
26
  "@paroi/data-formatters-lib": "~0.4.0"
28
27
  },
29
28
  "peerDependencies": {
30
- "@paroicms/internal-anywhere-lib": "1",
29
+ "@paroicms/public-anywhere-lib": "0",
31
30
  "@paroicms/public-server-lib": "0"
32
31
  },
33
32
  "devDependencies": {
34
33
  "@paroicms/public-anywhere-lib": "0.2.1",
35
- "@paroicms/public-server-lib": "0.6.1",
34
+ "@paroicms/public-server-lib": "0.7.0",
36
35
  "@solid-primitives/i18n": "~2.1.1",
37
36
  "@types/node": "~20.12.8",
38
37
  "rimraf": "~6.0.1",
@@ -43,10 +42,11 @@
43
42
  "vite": "~5.2.11",
44
43
  "vite-plugin-solid": "~2.10.2"
45
44
  },
46
- "main": "dist-backend/plugin.js",
45
+ "main": "backend/dist/plugin.js",
47
46
  "files": [
48
- "dist-frontend",
49
- "dist-backend",
50
- "locales"
47
+ "backend/dist",
48
+ "backend/locales",
49
+ "public-front/dist",
50
+ "public-front/locales"
51
51
  ]
52
52
  }