@paroicms/contact-form-plugin 0.9.0 → 0.10.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.
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.sendContactFormMail = sendContactFormMail;
|
|
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
|
-
async function sendContactFormMail(
|
|
6
|
+
async function sendContactFormMail(service, input, i18n) {
|
|
7
7
|
const { email, name, message, subject, gRecaptchaResponse } = input;
|
|
8
8
|
let contactEmail;
|
|
9
9
|
try {
|
|
10
|
-
contactEmail = (0, data_formatters_lib_1.strValOrUndef)(await
|
|
10
|
+
contactEmail = (0, data_formatters_lib_1.strValOrUndef)(await service.getSiteFieldValue({
|
|
11
11
|
fieldName: "contactEmail",
|
|
12
12
|
language: input.language,
|
|
13
13
|
}));
|
|
14
14
|
if (!contactEmail)
|
|
15
|
-
throw new Error(`['${
|
|
16
|
-
if (!(await
|
|
15
|
+
throw new Error(`['${service.fqdn}'] missing 'contactEmail'`);
|
|
16
|
+
if (!(await service.validateRecaptchaResponse(gRecaptchaResponse))) {
|
|
17
17
|
throw new Error("invalid recaptcha response");
|
|
18
18
|
}
|
|
19
19
|
const noSubject = i18n.translate({
|
|
@@ -23,9 +23,9 @@ async function sendContactFormMail(ctx, input, i18n) {
|
|
|
23
23
|
const contactFrom = i18n.translate({
|
|
24
24
|
key: "contactFrom",
|
|
25
25
|
language: input.language,
|
|
26
|
-
args: [
|
|
26
|
+
args: [service.fqdn],
|
|
27
27
|
});
|
|
28
|
-
await
|
|
28
|
+
await service.sendMail({
|
|
29
29
|
to: contactEmail,
|
|
30
30
|
replyTo: { email, name },
|
|
31
31
|
subject: `${subject ?? noSubject} ${contactFrom}`,
|
|
@@ -40,7 +40,7 @@ async function sendContactFormMail(ctx, input, i18n) {
|
|
|
40
40
|
args: [(0, public_server_lib_1.escapeHtml)(email)],
|
|
41
41
|
})}</p>
|
|
42
42
|
<p>${(0, public_server_lib_1.escapeHtml)(message, { newLinesToBr: true })}</p>`,
|
|
43
|
-
}
|
|
43
|
+
});
|
|
44
44
|
return {
|
|
45
45
|
success: true,
|
|
46
46
|
};
|
|
@@ -48,7 +48,7 @@ async function sendContactFormMail(ctx, input, i18n) {
|
|
|
48
48
|
catch (err) {
|
|
49
49
|
if (err)
|
|
50
50
|
throw err;
|
|
51
|
-
|
|
51
|
+
service.logger.error(`fail to send mail: ${(0, data_formatters_lib_1.messageOf)(err)}`);
|
|
52
52
|
return {
|
|
53
53
|
success: false,
|
|
54
54
|
message: contactEmail
|
package/backend/dist/plugin.js
CHANGED
|
@@ -15,11 +15,11 @@ const plugin = {
|
|
|
15
15
|
const simpleI18n = await (0, public_server_lib_1.createSimpleTranslator)({
|
|
16
16
|
l10nDir: (0, node_path_1.join)(projectDir, "locales"),
|
|
17
17
|
languages: ["en", "fr"],
|
|
18
|
-
appLog: service.
|
|
18
|
+
appLog: service.logger,
|
|
19
19
|
});
|
|
20
20
|
service.setPublicAssetsDirectory((0, node_path_1.join)(packageDir, "public-front", "dist"));
|
|
21
21
|
service.addHeadTag(`<link rel="stylesheet" href="${(0, public_server_lib_1.escapeHtml)(`${service.pluginAssetsUrl}/style.css`)}">`, `<script type="module" src="${(0, public_server_lib_1.escapeHtml)(`${service.pluginAssetsUrl}/public-front-plugin.mjs`)}"></script>`);
|
|
22
|
-
service.setPublicApiHandler(async (
|
|
22
|
+
service.setPublicApiHandler(async (service, req, res, relativePath) => {
|
|
23
23
|
if (relativePath !== "") {
|
|
24
24
|
res.status(404).send({ status: 404 });
|
|
25
25
|
return;
|
|
@@ -32,7 +32,7 @@ const plugin = {
|
|
|
32
32
|
res.status(400).send({ status: 400, message: error.message });
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
-
const result = await (0, contact_form_mail_1.sendContactFormMail)(
|
|
35
|
+
const result = await (0, contact_form_mail_1.sendContactFormMail)(service, input, simpleI18n);
|
|
36
36
|
res.send(result);
|
|
37
37
|
});
|
|
38
38
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paroicms/contact-form-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Contact form plugin for ParoiCMS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paroicms",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@paroicms/public-server-lib": "0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@paroicms/public-anywhere-lib": "0.
|
|
34
|
-
"@paroicms/public-server-lib": "0.
|
|
33
|
+
"@paroicms/public-anywhere-lib": "0.8.0",
|
|
34
|
+
"@paroicms/public-server-lib": "0.14.0",
|
|
35
35
|
"@solid-primitives/i18n": "~2.1.1",
|
|
36
36
|
"@types/node": "~20.14.8",
|
|
37
37
|
"rimraf": "~6.0.1",
|
|
@@ -92,11 +92,7 @@ function _(e) {
|
|
|
92
92
|
if (!e.fn) return;
|
|
93
93
|
V(e);
|
|
94
94
|
const t = k;
|
|
95
|
-
Be(
|
|
96
|
-
e,
|
|
97
|
-
e.value,
|
|
98
|
-
t
|
|
99
|
-
);
|
|
95
|
+
Be(e, e.value, t);
|
|
100
96
|
}
|
|
101
97
|
function Be(e, t, s) {
|
|
102
98
|
let n;
|
|
@@ -222,25 +218,17 @@ function pe(e) {
|
|
|
222
218
|
const t = e.keyed, s = ee(() => e.when, void 0, {
|
|
223
219
|
equals: (n, l) => t ? n === l : !n == !l
|
|
224
220
|
});
|
|
225
|
-
return ee(
|
|
226
|
-
()
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
)
|
|
237
|
-
) : l;
|
|
238
|
-
}
|
|
239
|
-
return e.fallback;
|
|
240
|
-
},
|
|
241
|
-
void 0,
|
|
242
|
-
void 0
|
|
243
|
-
);
|
|
221
|
+
return ee(() => {
|
|
222
|
+
const n = s();
|
|
223
|
+
if (n) {
|
|
224
|
+
const l = e.children;
|
|
225
|
+
return typeof l == "function" && l.length > 0 ? A(() => l(t ? n : () => {
|
|
226
|
+
if (!A(s)) throw Ve("Show");
|
|
227
|
+
return e.when;
|
|
228
|
+
})) : l;
|
|
229
|
+
}
|
|
230
|
+
return e.fallback;
|
|
231
|
+
}, void 0, void 0);
|
|
244
232
|
}
|
|
245
233
|
function Ge(e, t, s) {
|
|
246
234
|
let n = s.length, l = t.length, r = n, i = 0, o = 0, f = t[l - 1].nextSibling, p = null;
|
|
@@ -354,11 +342,7 @@ function se(e, t, s, n) {
|
|
|
354
342
|
else if (p === "function")
|
|
355
343
|
if (n) {
|
|
356
344
|
for (; typeof o == "function"; ) o = o();
|
|
357
|
-
l = se(
|
|
358
|
-
e,
|
|
359
|
-
Array.isArray(o) ? o : [o],
|
|
360
|
-
Array.isArray(f) ? f : [f]
|
|
361
|
-
) || l;
|
|
345
|
+
l = se(e, Array.isArray(o) ? o : [o], Array.isArray(f) ? f : [f]) || l;
|
|
362
346
|
} else
|
|
363
347
|
e.push(o), l = !0;
|
|
364
348
|
else {
|