@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 +1 -1
- package/{dist-backend/mail → backend/dist}/contact-form-mail.js +20 -21
- package/backend/dist/plugin.js +40 -0
- package/backend/locales/en.json +8 -0
- package/backend/locales/fr.json +8 -0
- package/package.json +12 -12
- package/public-front/dist/public-front-plugin.mjs +612 -0
- package/public-front/locales/en.json +14 -0
- package/public-front/locales/fr.json +14 -0
- package/dist-backend/plugin.js +0 -36
- package/dist-frontend/front-plugin.mjs +0 -632
- package/locales/en.json +0 -24
- package/locales/fr.json +0 -24
- /package/{dist-backend/helpers → backend/dist}/data-format.js +0 -0
- /package/{dist-frontend → public-front/dist}/style.css +0 -0
package/README.md
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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(`['${
|
|
17
|
-
if (!(await
|
|
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 =
|
|
21
|
-
key: "
|
|
19
|
+
const noSubject = i18n.translate({
|
|
20
|
+
key: "noSubject",
|
|
22
21
|
language: input.language,
|
|
23
22
|
});
|
|
24
|
-
const contactFrom =
|
|
25
|
-
key: "
|
|
23
|
+
const contactFrom = i18n.translate({
|
|
24
|
+
key: "contactFrom",
|
|
26
25
|
language: input.language,
|
|
27
|
-
args: [
|
|
26
|
+
args: [ctx.fqdn],
|
|
28
27
|
});
|
|
29
|
-
await
|
|
28
|
+
await ctx.sendMail({
|
|
30
29
|
to: contactEmail,
|
|
31
30
|
replyTo: { email, name },
|
|
32
31
|
subject: `${subject ?? noSubject} ${contactFrom}`,
|
|
33
|
-
html: `<p>${
|
|
34
|
-
key: "
|
|
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>${
|
|
39
|
-
key: "
|
|
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:
|
|
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
|
-
|
|
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
|
-
?
|
|
57
|
-
key: "
|
|
55
|
+
? i18n.translate({
|
|
56
|
+
key: "sendUsAnEmailTo",
|
|
58
57
|
language: input.language,
|
|
59
58
|
args: [contactEmail],
|
|
60
59
|
})
|
|
61
|
-
:
|
|
62
|
-
key: "
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paroicms/contact-form-plugin",
|
|
3
|
-
"version": "0.
|
|
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": "
|
|
22
|
-
"build:frontend": "tsc && vite build",
|
|
23
|
-
"clear": "rimraf
|
|
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/
|
|
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.
|
|
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": "
|
|
45
|
+
"main": "backend/dist/plugin.js",
|
|
47
46
|
"files": [
|
|
48
|
-
"dist
|
|
49
|
-
"
|
|
50
|
-
"
|
|
47
|
+
"backend/dist",
|
|
48
|
+
"backend/locales",
|
|
49
|
+
"public-front/dist",
|
|
50
|
+
"public-front/locales"
|
|
51
51
|
]
|
|
52
52
|
}
|