@paroicms/contact-form-plugin 0.26.0 → 0.27.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,10 +1,10 @@
1
- import { messageOf, strValOrUndef } from "@paroi/data-formatters-lib";
1
+ import { ensureString, messageOf } from "@paroicms/public-anywhere-lib";
2
2
  import { escapeHtml, } from "@paroicms/public-server-lib";
3
3
  export async function sendContactFormMail(service, input, i18n) {
4
4
  const { email, name, message, subject, gRecaptchaResponse } = input;
5
5
  let contactEmail;
6
6
  try {
7
- contactEmail = strValOrUndef(await service.getSiteFieldValue({
7
+ contactEmail = ensureString(await service.getSiteFieldValue({
8
8
  fieldName: "contactEmail",
9
9
  language: input.language,
10
10
  }));
@@ -1,11 +1,10 @@
1
- import { strVal, strValOrUndef } from "@paroi/data-formatters-lib";
2
- export function formatSendMailInput(data) {
3
- return {
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),
10
- };
11
- }
1
+ import { type } from "arktype";
2
+ export const SendMailInputBody = type({
3
+ language: "string",
4
+ email: "string",
5
+ name: "string",
6
+ "subject?": "string|undefined",
7
+ message: "string",
8
+ "gRecaptchaResponse?": "string|undefined",
9
+ "+": "reject",
10
+ });
@@ -1,13 +1,13 @@
1
- import { strVal } from "@paroi/data-formatters-lib";
2
- import { escapeHtml, loadSimpleTranslatorFromDirectory, makeStylesheetLinkAsyncTag, resolveModuleDirectory, } from "@paroicms/public-server-lib";
3
1
  import { readFileSync } from "node:fs";
4
2
  import { dirname, join } from "node:path";
3
+ import { escapeHtml, loadSimpleTranslatorFromDirectory, makeStylesheetLinkAsyncTag, resolveModuleDirectory, } from "@paroicms/public-server-lib";
4
+ import { type } from "arktype";
5
5
  import { sendContactFormMail } from "./contact-form-mail.js";
6
- import { formatSendMailInput } from "./data-format.js";
6
+ import { SendMailInputBody } from "./data-format.js";
7
7
  const SLUG = "contact-form";
8
8
  const projectDir = resolveModuleDirectory(import.meta.url, { parent: true });
9
9
  const packageDir = dirname(projectDir);
10
- const version = strVal(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8")).version);
10
+ const version = type({ version: "string", "+": "ignore" }).assert(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8"))).version;
11
11
  const plugin = {
12
12
  version,
13
13
  slug: SLUG,
@@ -38,7 +38,7 @@ const plugin = {
38
38
  }
39
39
  let input;
40
40
  try {
41
- input = formatSendMailInput(req.body);
41
+ input = SendMailInputBody.assert(req.body);
42
42
  }
43
43
  catch (error) {
44
44
  res.status(400).send({ status: 400, message: error.message });
@@ -1 +1 @@
1
- import{template as $,insert as o,setAttribute as g,createComponent as M,effect as P,render as ae}from"https://esm.sh/solid-js@1.9.7/web";import{createMemo as re,createSignal as d,Show as I,onMount as oe,onCleanup as ce}from"https://esm.sh/solid-js@1.9.7";function le(e){return e.varName?` for '${e.varName}'`:""}function B(e,t={}){if(e==null||e===""&&!t.allowEmpty)throw new Error(`Missing string value${le(t)}`);return typeof e=="string"?e:e.toString()}const J=e=>e!=null&&(e=Object.getPrototypeOf(e),e===Array.prototype||e===Object.prototype);function V(e,t,a){for(const[n,c]of Object.entries(t)){const m=`${a}.${n}`;e[m]=c,J(c)&&V(e,c,m)}}function ie(e){const t={...e};for(const[a,n]of Object.entries(e))J(n)&&V(t,n,a);return t}const de=(e,t)=>{if(t)for(const[a,n]of Object.entries(t))e=e.replace(new RegExp(`{{\\s*${a}\\s*}}`,"g"),n);return e},ue=e=>e;function me(e,t=ue){return(a,...n)=>{a[0]==="."&&(a=a.slice(1));const c=e()?.[a];switch(typeof c){case"function":return c(...n);case"string":return t(c,n[0]);default:return c}}}const pe="Name",fe="Email",ge="Subject",he="Message",be="Send",ve="johndoe@gmail.com",Pe="John Doe",$e="The subject of your message",ye="Enter your message here…",Ee="Unexpected error, the message could not be sent.",we="Return Home",Fe="Your message has been sent. If there is a response, it will be sent to the address:",Se={name:pe,email:fe,subject:ge,message:he,send:be,emailPlaceholder:ve,namePlaceholder:Pe,subjectPlaceholder:$e,messagePlaceholder:ye,unexpectedErrorMessage:Ee,returnHome:we,successMessage:Fe},xe="Nom",_e="Courriel",Me="Sujet",je="Message",Ce="Envoyer",Re="johndoe@gmail.com",Le="John Doe",ke="Le sujet de votre message",He="Saisissez votre message…",Oe="Erreur inattendue, le message n'a pas pu être envoyé.",Te="Retourner à l'accueil",Ne="Votre message a été envoyé. S'il y a une réponse, elle sera envoyée à l'adresse :",Ae={name:xe,email:_e,subject:Me,message:je,send:Ce,emailPlaceholder:Re,namePlaceholder:Le,subjectPlaceholder:ke,messagePlaceholder:He,unexpectedErrorMessage:Oe,returnHome:Te,successMessage:Ne},U={en:Se,fr:Ae};function De(e){const t=re((()=>{const n=e in U?e:"en";return ie(U[n])}));return{t:me(t,de)}}async function Ie(e,t,a){a(!0);try{const n=await Ue(e);return t.reset(),n}finally{a(!1)}}async function Ue(e){const t=await fetch("/api/plugin/contact-form",{headers:{"Content-Type":"application/json"},body:JSON.stringify(e),method:"POST"});if(t.status!==200){const n=await t.text();throw new Error(`Unexpected error: ${n}`)}return await t.json()}var qe=$("<div class=PaForm-error>"),Be=$('<div class=PaForm-ended><div class=PaForm-message><p> <i></i></p></div><div class=PaForm-action><a class="PaForm-button PaButton">'),Je=$('<form class=PaForm><div class=PaForm-fields><label class=PaField><span class=PaField-label></span><input class=PaField-input type=text name=name required></label><label class=PaField><span class=PaField-label></span><input class=PaField-input type=email name=email required></label><label class=PaField><span class=PaField-label></span><textarea class=PaField-input rows=5 name=message required></textarea></label></div><div class=PaForm-action><button class="PaForm-button PaButton"type=submit>'),Ve=$("<div class=PaForm-captcha><div class=g-recaptcha data-callback=onRecaptchaSubmitted data-expired-callback=onRecaptchaExpired>");function ze({googleRecaptchaSiteKey:e,language:t,homeUrl:a}){const[n,c]=d(""),[m,G]=d(""),[j,Y]=d(""),[Q,W]=d(),[C,R]=d(!e),[L,y]=d(),[X,k]=d(""),[Z,K]=d(!1),{t:r}=De(t),ee=async l=>{try{if(l.preventDefault(),!C()||!h)throw new Error("Recaptcha error");const i=await Ie({language:t,name:n(),message:j(),email:m(),gRecaptchaResponse:Q()},h,K);i.success?y(!0):(y(!1),k(i.message??r("unexpectedErrorMessage")))}catch{y(!1),k(r("unexpectedErrorMessage"))}},h=(()=>{var l=Je(),i=l.firstChild,H=i.firstChild,O=H.firstChild,E=O.nextSibling,T=H.nextSibling,N=T.firstChild,w=N.nextSibling,ne=T.nextSibling,A=ne.firstChild,F=A.nextSibling,S=i.nextSibling,x=S.firstChild;return l.addEventListener("submit",ee),o(O,(()=>r("name"))),E.addEventListener("change",(s=>c(s.currentTarget.value))),o(N,(()=>r("email"))),w.addEventListener("change",(s=>{G(s.currentTarget.value)})),o(A,(()=>r("message"))),F.addEventListener("change",(s=>Y(s.currentTarget.value))),o(l,e&&(()=>{var s=Ve(),u=s.firstChild;return g(u,"data-sitekey",e),s})(),S),o(l,M(I,{get when(){return L()===!1},get children(){var s=qe();return o(s,X),s}}),S),o(x,(()=>r("send"))),o(l,M(I,{get when(){return L()===!0},get children(){var s=Be(),u=s.firstChild,p=u.firstChild,f=p.firstChild,b=f.nextSibling,v=u.nextSibling,D=v.firstChild;return o(p,(()=>r("successMessage")),f),o(b,m),g(D,"href",a),o(D,(()=>r("returnHome"))),s}}),null),P((s=>{var u=r("namePlaceholder"),p=r("emailPlaceholder"),f=r("messagePlaceholder"),b=!!Z(),v=!C();return u!==s.e&&g(E,"placeholder",s.e=u),p!==s.t&&g(w,"placeholder",s.t=p),f!==s.a&&g(F,"placeholder",s.a=f),b!==s.o&&x.classList.toggle("inProgress",s.o=b),v!==s.i&&(x.disabled=s.i=v),s}),{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),P((()=>E.value=n())),P((()=>w.value=m())),P((()=>F.value=j())),l})();return oe((()=>{e&&(window.onRecaptchaSubmitted=te,window.onRecaptchaExpired=se)})),ce((()=>{e&&(window.onRecaptchaSubmitted=void 0,window.onRecaptchaExpired=void 0)})),h;function te(l){if(!l)return;R(!0);const i=h?.elements.namedItem("g-recaptcha-response");W(i.value)}function se(){R(!1)}}let z;const[_]=document.getElementsByClassName("js-script-contact-form");_&&_ instanceof HTMLScriptElement&&(z=B(_.dataset.googleRecaptchaSiteKey,{varName:"data-google-recaptcha-site-key"}));function Ge(e,{language:t}){if(!t)throw new Error("Missing language");e.dataset.recaptchaKey&&console.warn('Remove "data-recaptcha-key" attribute, it is not needed anymore.');const a=B(e.dataset.homeUrl),n=document.createElement("script");n.setAttribute("src","https://www.google.com/recaptcha/api.js"),document.head.appendChild(n),ae((()=>M(ze,{googleRecaptchaSiteKey:z,language:t,homeUrl:a})),e)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",q):q();function q(){const e=document.documentElement.lang,t=document.querySelector("[data-effect='paContactForm']");t&&Ge(t,{language:e})}
1
+ import{template as $,insert as o,setAttribute as f,createComponent as j,effect as P,render as ne}from"https://esm.sh/solid-js@1.9.7/web";import{createMemo as ae,createSignal as d,Show as U,onMount as re,onCleanup as oe}from"https://esm.sh/solid-js@1.9.7";const J=e=>e!=null&&(e=Object.getPrototypeOf(e),e===Array.prototype||e===Object.prototype);function z(e,t,a){for(const[n,c]of Object.entries(t)){const m=`${a}.${n}`;e[m]=c,J(c)&&z(e,c,m)}}function ce(e){const t={...e};for(const[a,n]of Object.entries(e))J(n)&&z(t,n,a);return t}const le=(e,t)=>{if(t)for(const[a,n]of Object.entries(t))e=e.replace(new RegExp(`{{\\s*${a}\\s*}}`,"g"),n);return e},ie=e=>e;function de(e,t=ie){return(a,...n)=>{a[0]==="."&&(a=a.slice(1));const c=e()?.[a];switch(typeof c){case"function":return c(...n);case"string":return t(c,n[0]);default:return c}}}const ue="Name",me="Email",pe="Subject",he="Message",fe="Send",ge="johndoe@gmail.com",be="John Doe",ve="The subject of your message",Pe="Enter your message here…",$e="Unexpected error, the message could not be sent.",ye="Return Home",Ee="Your message has been sent. If there is a response, it will be sent to the address:",we={name:ue,email:me,subject:pe,message:he,send:fe,emailPlaceholder:ge,namePlaceholder:be,subjectPlaceholder:ve,messagePlaceholder:Pe,unexpectedErrorMessage:$e,returnHome:ye,successMessage:Ee},Fe="Nom",Se="Courriel",xe="Sujet",_e="Message",je="Envoyer",Me="johndoe@gmail.com",Ce="John Doe",Re="Le sujet de votre message",Le="Saisissez votre message…",ke="Erreur inattendue, le message n'a pas pu être envoyé.",He="Retourner à l'accueil",Oe="Votre message a été envoyé. S'il y a une réponse, elle sera envoyée à l'adresse :",Te={name:Fe,email:Se,subject:xe,message:_e,send:je,emailPlaceholder:Me,namePlaceholder:Ce,subjectPlaceholder:Re,messagePlaceholder:Le,unexpectedErrorMessage:ke,returnHome:He,successMessage:Oe},q={en:we,fr:Te};function Ae(e){const t=ae((()=>{const n=e in q?e:"en";return ce(q[n])}));return{t:de(t,le)}}async function De(e,t,a){a(!0);try{const n=await Ie(e);return t.reset(),n}finally{a(!1)}}async function Ie(e){const t=await fetch("/api/plugin/contact-form",{headers:{"Content-Type":"application/json"},body:JSON.stringify(e),method:"POST"});if(t.status!==200){const n=await t.text();throw new Error(`Unexpected error: ${n}`)}return await t.json()}var Ne=$("<div class=PaForm-error>"),Ue=$('<div class=PaForm-ended><div class=PaForm-message><p> <i></i></p></div><div class=PaForm-action><a class="PaForm-button PaButton">'),qe=$('<form class=PaForm><div class=PaForm-fields><label class=PaField><span class=PaField-label></span><input class=PaField-input type=text name=name required></label><label class=PaField><span class=PaField-label></span><input class=PaField-input type=email name=email required></label><label class=PaField><span class=PaField-label></span><textarea class=PaField-input rows=5 name=message required></textarea></label></div><div class=PaForm-action><button class="PaForm-button PaButton"type=submit>'),Be=$("<div class=PaForm-captcha><div class=g-recaptcha data-callback=onRecaptchaSubmitted data-expired-callback=onRecaptchaExpired>");function Je({googleRecaptchaSiteKey:e,language:t,homeUrl:a}){const[n,c]=d(""),[m,G]=d(""),[C,V]=d(""),[Y,Q]=d(),[R,L]=d(!e),[k,y]=d(),[W,H]=d(""),[X,Z]=d(!1),{t:r}=Ae(t),K=async l=>{try{if(l.preventDefault(),!R()||!g)throw new Error("Recaptcha error");const i=await De({language:t,name:n(),message:C(),email:m(),gRecaptchaResponse:Y()},g,Z);i.success?y(!0):(y(!1),H(i.message??r("unexpectedErrorMessage")))}catch{y(!1),H(r("unexpectedErrorMessage"))}},g=(()=>{var l=qe(),i=l.firstChild,O=i.firstChild,T=O.firstChild,E=T.nextSibling,A=O.nextSibling,D=A.firstChild,w=D.nextSibling,se=A.nextSibling,I=se.firstChild,F=I.nextSibling,S=i.nextSibling,x=S.firstChild;return l.addEventListener("submit",K),o(T,(()=>r("name"))),E.addEventListener("change",(s=>c(s.currentTarget.value))),o(D,(()=>r("email"))),w.addEventListener("change",(s=>{G(s.currentTarget.value)})),o(I,(()=>r("message"))),F.addEventListener("change",(s=>V(s.currentTarget.value))),o(l,e&&(()=>{var s=Be(),u=s.firstChild;return f(u,"data-sitekey",e),s})(),S),o(l,j(U,{get when(){return k()===!1},get children(){var s=Ne();return o(s,W),s}}),S),o(x,(()=>r("send"))),o(l,j(U,{get when(){return k()===!0},get children(){var s=Ue(),u=s.firstChild,p=u.firstChild,h=p.firstChild,b=h.nextSibling,v=u.nextSibling,N=v.firstChild;return o(p,(()=>r("successMessage")),h),o(b,m),f(N,"href",a),o(N,(()=>r("returnHome"))),s}}),null),P((s=>{var u=r("namePlaceholder"),p=r("emailPlaceholder"),h=r("messagePlaceholder"),b=!!X(),v=!R();return u!==s.e&&f(E,"placeholder",s.e=u),p!==s.t&&f(w,"placeholder",s.t=p),h!==s.a&&f(F,"placeholder",s.a=h),b!==s.o&&x.classList.toggle("inProgress",s.o=b),v!==s.i&&(x.disabled=s.i=v),s}),{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),P((()=>E.value=n())),P((()=>w.value=m())),P((()=>F.value=C())),l})();return re((()=>{e&&(window.onRecaptchaSubmitted=ee,window.onRecaptchaExpired=te)})),oe((()=>{e&&(window.onRecaptchaSubmitted=void 0,window.onRecaptchaExpired=void 0)})),g;function ee(l){if(!l)return;L(!0);const i=g?.elements.namedItem("g-recaptcha-response");Q(i.value)}function te(){L(!1)}}let M;const[_]=document.getElementsByClassName("js-script-contact-form");_&&_ instanceof HTMLScriptElement&&(M=_.dataset.googleRecaptchaSiteKey);if(!M)throw new Error('Missing "data-google-recaptcha-site-key" or the script element "js-script-contact-form"');function ze(e,{language:t}){if(!t)throw new Error("Missing language");e.dataset.recaptchaKey&&console.warn('Remove "data-recaptcha-key" attribute, it is not needed anymore.');const a=e.dataset.homeUrl;if(!a)throw new Error('Missing "data-home-url"');const n=document.createElement("script");n.setAttribute("src","https://www.google.com/recaptcha/api.js"),document.head.appendChild(n),ne((()=>j(Je,{googleRecaptchaSiteKey:M,language:t,homeUrl:a})),e)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",B):B();function B(){const e=document.documentElement.lang,t=document.querySelector("[data-effect='paContactForm']");t&&ze(t,{language:e})}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/contact-form-plugin",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "Contact form plugin for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -27,25 +27,25 @@
27
27
  "clear": "rimraf backend/dist/* frontend/dist/*"
28
28
  },
29
29
  "dependencies": {
30
- "@paroi/data-formatters-lib": "~0.4.0"
30
+ "arktype": "~2.1.20"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@paroicms/public-anywhere-lib": "0",
34
34
  "@paroicms/public-server-lib": "0"
35
35
  },
36
36
  "devDependencies": {
37
- "@paroicms/public-anywhere-lib": "0.24.0",
38
- "@paroicms/public-server-lib": "0.36.0",
37
+ "@paroicms/public-anywhere-lib": "0.25.0",
38
+ "@paroicms/public-server-lib": "0.37.0",
39
39
  "@solid-primitives/i18n": "~2.2.1",
40
40
  "@types/node": "~24.0.1",
41
41
  "rimraf": "~6.0.1",
42
42
  "sass": "~1.89.2",
43
43
  "solid-devtools": "~0.34.0",
44
44
  "solid-js": "1.9.7",
45
+ "terser": "~5.42.0",
45
46
  "typescript": "~5.8.3",
46
47
  "vite": "~6.3.5",
47
- "vite-plugin-solid": "~2.11.6",
48
- "terser": "~5.42.0"
48
+ "vite-plugin-solid": "~2.11.6"
49
49
  },
50
50
  "files": [
51
51
  "backend/dist",