domma-cms 0.14.6 → 0.14.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domma-cms",
3
- "version": "0.14.6",
3
+ "version": "0.14.7",
4
4
  "description": "File-based CMS powered by Domma and Fastify. Run npx domma-cms my-site to create a new project.",
5
5
  "type": "module",
6
6
  "main": "server/server.js",
@@ -1 +1 @@
1
- const targets=document.querySelectorAll("[data-form]");targets.length&&targets.forEach(initFormTarget);function showMessage(i,r,t){const e=i.querySelector(".fb-form-success, .fb-form-error");e&&e.remove();const s=document.createElement("div");s.className=t==="success"?"fb-form-success":"fb-form-error",s.textContent=r,i.appendChild(s)}function buildBlueprintFromFields(i,r){const t={};return i.forEach(function(e){if(e.type==="page-break"||e.type==="spacer"||!e.name)return;const s=e.type==="checkbox"?"boolean":e.type==="date"?"string":e.type,o={...e.formConfig||{}};o.span==="full"&&r&&(o.span=r),t[e.name]={type:s,label:e.label||e.name,required:e.required||!1,options:e.options,formConfig:{...e.placeholder&&{placeholder:e.placeholder},...e.helper&&{hint:e.helper},...o}},e.minLength!==void 0&&(t[e.name].minLength=e.minLength),e.maxLength!==void 0&&(t[e.name].maxLength=e.maxLength),e.min!==void 0&&(t[e.name].min=e.min),e.max!==void 0&&(t[e.name].max=e.max)}),t}function buildInitialData(i){const r={};return i.forEach(function(t){if(!(!t.name||t.type==="page-break"||t.type==="spacer")&&(t.type==="select"||t.type==="multiselect")&&t.required){const e=(t.options||[])[0];e&&(r[t.name]=typeof e=="object"?e.value:e)}}),r}function patchDateInputs(i,r){(r||[]).forEach(function(t){if(t.type!=="date"||!t.name)return;const e=i.querySelector('[name="'+t.name+'"]');e&&e.type!=="date"&&(e.type="date")})}function buildWizardSteps(i,r){const t=[];let e=[],s=r||"Step 1",o="";return i.forEach(function(m){m.type==="page-break"?(t.push({title:s,description:o,fieldGroup:e}),e=[],s=m.label||"Step "+(t.length+1),o=m.description||""):m.type!=="spacer"&&e.push(m)}),t.push({title:s,description:o,fieldGroup:e}),t}function injectHoneypot(i){const r=document.createElement("div");r.className="fb-form-honeypot",r.setAttribute("aria-hidden","true");const t=document.createElement("input");t.name="website",t.type="text",t.tabIndex=-1,t.autocomplete="url",t.placeholder="https://",r.appendChild(t);const e=document.createElement("input");e.name="_t",e.type="hidden",e.value=Date.now(),r.appendChild(e),i.appendChild(r)}function injectSpacers(i,r){const t=i.querySelector("form");if(!t)return;const e=Array.from(t.querySelectorAll(".form-group"));let s=0;r.forEach(function(o){if(o.type==="spacer"){const m=document.createElement("div");m.className="fb-spacer";const a=e[s];if(a)t.insertBefore(m,a);else{const u=t.querySelector('[type="submit"]');u?t.insertBefore(m,u):t.appendChild(m)}}else o.type!=="page-break"&&s++})}function submitForm(i,r,t,e,s){const o=s||e,m=o.querySelector('[name="website"]')?.value||"",a=o.querySelector('[name="_t"]')?.value||"",u=Object.assign({},r,{_hp:m,_t:a});return fetch("/api/forms/submit/"+i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).then(c=>c.json().then(n=>({ok:c.ok,body:n}))).then(c=>{c.ok&&c.body.ok?(e.textContent="",showMessage(e,c.body.message||t.successMessage||"Thank you.","success")):showMessage(e,c.body.error||"Something went wrong.","error")}).catch(()=>{showMessage(e,"Unable to submit. Please check your connection.","error")})}function renderManualForm(i,r,t,e,s){const o=document.createElement("form");o.noValidate=!0,r.forEach(function(a){const u=document.createElement("div");u.className="form-group",u.style.marginBottom="1.25rem";const c=document.createElement("label");if(c.className="form-label",c.textContent=a.label||a.name,a.required){const p=document.createElement("span");p.textContent=" *",p.style.color="#f87171",c.appendChild(p)}let n;a.type==="textarea"?(n=document.createElement("textarea"),n.rows=a.formConfig?.rows||4,n.className="form-input"):a.type==="select"?(n=document.createElement("select"),n.className="form-input",(a.options||[]).forEach(function(p){const l=document.createElement("option");l.value=typeof p=="string"?p:p.value??"",l.textContent=typeof p=="string"?p:p.label||l.value,n.appendChild(l)})):(n=document.createElement("input"),n.type=a.type||"text",n.className="form-input",a.placeholder&&(n.placeholder=a.placeholder)),n.name=a.name,n.required=a.required||!1,u.appendChild(c),u.appendChild(n),o.appendChild(u)}),t.honeypot&&injectHoneypot(o);const m=document.createElement("button");m.type="submit",m.className="btn btn-primary",m.textContent=t.submitText||"Submit",o.appendChild(m),o.addEventListener("submit",function(a){a.preventDefault();const u={};if(r.forEach(function(c){const n=o.querySelector('[name="'+c.name+'"]');n&&(u[c.name]=n.value)}),window.FormLogicEngine&&s){const c=window.FormLogicEngine,n=[],p=[];if(r.forEach(function(l){if(c.evaluateFieldVisibility(l,u)==="hidden"){delete u[l.name];return}const h=c.evaluateFieldRequirement(l,u),f=u[l.name];h&&(!f||!String(f).trim())&&n.push(l.label||l.name);const d=c.validateField(l,f||"",u);d.length&&p.push(d[0].message)}),n.length||p.length){const l=[];n.length&&l.push("Required: "+n.join(", ")),p.length&&l.push(p.join("; ")),showMessage(i,l.join(". "),"error");return}}i.classList.add("fb-form-loading"),m.disabled=!0,submitForm(e,u,t,i,o).finally(function(){i.classList.remove("fb-form-loading"),m.disabled=!1})}),i.appendChild(o),window.FormLogicEngine&&s&&r.some(a=>a.logic)&&new window.FormLogicEngine.FormLogicRuntime(s,i).init()}function initFormTarget(i){const r=i.getAttribute("data-form");r&&fetch("/api/forms/"+r+"/public").then(t=>{if(!t.ok)throw new Error("Form not found: "+r);return t.json()}).then(t=>{const e=t.fields||[],s=t.settings||{},o=document.createElement("div");o.className="fb-form-wrapper",i.appendChild(o);const m=e.some(a=>a.type==="page-break");if(typeof Domma<"u"&&Domma.forms){const a=s.columns||1;if(m&&Domma.forms.wizard){const c=buildWizardSteps(e,t.title).map(function(n){return{title:n.title,description:n.description,fields:buildBlueprintFromFields(n.fieldGroup,a)}});if(Domma.forms.wizard(o,{schema:{steps:c},onSubmit:function(n){return submitForm(r,n,s,o,null)}}),patchDateInputs(o,e),window.FormLogicEngine&&e.some(n=>n.logic)&&new window.FormLogicEngine.FormLogicRuntime(t,o).init(),s.honeypot){const n=o.querySelector("form");n&&injectHoneypot(n)}}else if(Domma.forms.render){const u=buildBlueprintFromFields(e,a),c=buildInitialData(e);if(Domma.forms.render(o,u,c,{submitText:s.submitText||"Submit",layout:s.layout||"stacked",columns:a,onSubmit:function(n){return submitForm(r,n,s,o,null)}}),patchDateInputs(o,e),window.FormLogicEngine&&e.some(n=>n.logic)&&new window.FormLogicEngine.FormLogicRuntime(t,o).init(),e.some(n=>n.type==="spacer")&&injectSpacers(o,e),s.honeypot){const n=o.querySelector("form");n&&injectHoneypot(n)}}}else renderManualForm(o,e.filter(a=>a.type!=="page-break"&&a.type!=="spacer"),s,r,t)}).catch(t=>{const e=document.createElement("p");e.textContent="Form unavailable.",e.style.cssText="color:#f87171;font-style:italic;",i.appendChild(e),console.warn("[forms]",t.message)})}
1
+ const targets=document.querySelectorAll("[data-form]");targets.length&&targets.forEach(initFormTarget);function showMessage(i,r,t){const e=i.querySelector(".fb-form-success, .fb-form-error");e&&e.remove();const s=document.createElement("div");s.className=t==="success"?"fb-form-success":"fb-form-error",s.textContent=r,i.appendChild(s)}function buildBlueprintFromFields(i,r){const t={};return i.forEach(function(e){if(e.type==="page-break"||e.type==="spacer"||!e.name)return;const s=e.type==="checkbox"?"boolean":e.type==="date"?"string":e.type,n={...e.formConfig||{}};n.span==="full"&&r&&(n.span=r),t[e.name]={type:s,label:e.label||e.name,required:e.required||!1,options:e.options,formConfig:{...e.placeholder&&{placeholder:e.placeholder},...e.helper&&{hint:e.helper},...n}},e.minLength!==void 0&&(t[e.name].minLength=e.minLength),e.maxLength!==void 0&&(t[e.name].maxLength=e.maxLength),e.min!==void 0&&(t[e.name].min=e.min),e.max!==void 0&&(t[e.name].max=e.max)}),t}function buildInitialData(i){const r={};return i.forEach(function(t){if(!(!t.name||t.type==="page-break"||t.type==="spacer")&&(t.type==="select"||t.type==="multiselect")&&t.required){const e=(t.options||[])[0];e&&(r[t.name]=typeof e=="object"?e.value:e)}}),r}function patchDateInputs(i,r){(r||[]).forEach(function(t){if(t.type!=="date"||!t.name)return;const e=i.querySelector('[name="'+t.name+'"]');e&&e.type!=="date"&&(e.type="date")})}function buildWizardSteps(i,r){const t=[];let e=[],s=r||"Step 1",n="";return i.forEach(function(u){u.type==="page-break"?(t.push({title:s,description:n,fieldGroup:e}),e=[],s=u.label||"Step "+(t.length+1),n=u.description||""):u.type!=="spacer"&&e.push(u)}),t.push({title:s,description:n,fieldGroup:e}),t}function injectHoneypot(i){const r=document.createElement("div");r.className="fb-form-honeypot",r.setAttribute("aria-hidden","true");const t=document.createElement("input");t.name="website",t.type="text",t.tabIndex=-1,t.autocomplete="url",t.placeholder="https://",r.appendChild(t);const e=document.createElement("input");e.name="_t",e.type="hidden",e.value=Date.now(),r.appendChild(e),i.appendChild(r)}function injectSpacers(i,r){const t=i.querySelector("form");if(!t)return;const e=Array.from(t.querySelectorAll(".form-group"));let s=0;r.forEach(function(n){if(n.type==="spacer"){const u=document.createElement("div");u.className="fb-spacer";const a=e[s];if(a)t.insertBefore(u,a);else{const l=t.querySelector('[type="submit"]');l?t.insertBefore(u,l):t.appendChild(u)}}else n.type!=="page-break"&&s++})}function submitForm(i,r,t,e,s){const n=s||e,u=n.querySelector('[name="website"]')?.value||"",a=n.querySelector('[name="_t"]')?.value||"",l=Object.assign({},r,{_hp:u,_t:a});return fetch("/api/forms/submit/"+i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}).then(m=>m.json().then(c=>({ok:m.ok,body:c}))).then(m=>{m.ok&&m.body.ok?(e.textContent="",showMessage(e,m.body.message||t.successMessage||"Thank you.","success")):showMessage(e,m.body.error||"Something went wrong.","error")}).catch(()=>{showMessage(e,"Unable to submit. Please check your connection.","error")})}function renderManualForm(i,r,t,e,s){const n=document.createElement("form");n.noValidate=!0,r.forEach(function(a){const l=document.createElement("div");l.className="form-group",l.style.marginBottom="1.25rem";const m=document.createElement("label");if(m.className="form-label",m.textContent=a.label||a.name,a.required){const o=document.createElement("span");o.textContent=" *",o.style.color="#f87171",m.appendChild(o)}let c;a.type==="textarea"?(c=document.createElement("textarea"),c.rows=a.formConfig?.rows||4,c.className="form-input"):a.type==="select"?(c=document.createElement("select"),c.className="form-input",(a.options||[]).forEach(function(o){const p=document.createElement("option");p.value=typeof o=="string"?o:o.value??"",p.textContent=typeof o=="string"?o:o.label||p.value,c.appendChild(p)})):(c=document.createElement("input"),c.type=a.type||"text",c.className="form-input",a.placeholder&&(c.placeholder=a.placeholder)),c.name=a.name,c.required=a.required||!1,l.appendChild(m),l.appendChild(c),n.appendChild(l)}),t.honeypot&&injectHoneypot(n);const u=document.createElement("button");u.type="submit",u.className="btn btn-primary",u.textContent=t.submitText||"Submit",n.appendChild(u),n.addEventListener("submit",function(a){a.preventDefault();const l={};if(r.forEach(function(m){const c=n.querySelector('[name="'+m.name+'"]');c&&(l[m.name]=c.value)}),window.FormLogicEngine&&s){const m=window.FormLogicEngine,c=[],o=[];if(r.forEach(function(p){if(m.evaluateFieldVisibility(p,l)==="hidden"){delete l[p.name];return}const h=m.evaluateFieldRequirement(p,l),f=l[p.name];h&&(!f||!String(f).trim())&&c.push(p.label||p.name);const d=m.validateField(p,f||"",l);d.length&&o.push(d[0].message)}),c.length||o.length){const p=[];c.length&&p.push("Required: "+c.join(", ")),o.length&&p.push(o.join("; ")),showMessage(i,p.join(". "),"error");return}}i.classList.add("fb-form-loading"),u.disabled=!0,submitForm(e,l,t,i,n).finally(function(){i.classList.remove("fb-form-loading"),u.disabled=!1})}),i.appendChild(n),window.FormLogicEngine&&s&&r.some(a=>a.logic)&&new window.FormLogicEngine.FormLogicRuntime(s,i).init()}function initFormTarget(i){const r=i.getAttribute("data-form");r&&fetch("/api/forms/"+r+"/public").then(t=>{if(!t.ok)throw new Error("Form not found: "+r);return t.json()}).then(t=>{const e=t.fields||[],s=t.settings||{},n=document.createElement("div");n.className="fb-form-wrapper",i.appendChild(n);const u=e.some(a=>a.type==="page-break");if(typeof Domma<"u"&&Domma.forms){const a=s.columns||1;if(u&&Domma.forms.wizard){const m=buildWizardSteps(e,t.title).map(function(o){return{title:o.title,description:o.description,fields:buildBlueprintFromFields(o.fieldGroup,a)}}),c=Domma.forms.wizard(n,{schema:{steps:m},onSubmit:function(o){return submitForm(r,o,s,n,null)}});Promise.resolve(c).then(function(){if(patchDateInputs(n,e),window.FormLogicEngine&&e.some(o=>o.logic)&&new window.FormLogicEngine.FormLogicRuntime(t,n).init(),s.honeypot){const o=n.querySelector("form");o&&injectHoneypot(o)}})}else if(Domma.forms.render){const l=buildBlueprintFromFields(e,a),m=buildInitialData(e),c=Domma.forms.render(n,l,m,{submitText:s.submitText||"Submit",layout:s.layout||"stacked",columns:a,onSubmit:function(o){return submitForm(r,o,s,n,null)}});Promise.resolve(c).then(function(){if(patchDateInputs(n,e),window.FormLogicEngine&&e.some(o=>o.logic)&&new window.FormLogicEngine.FormLogicRuntime(t,n).init(),e.some(o=>o.type==="spacer")&&injectSpacers(n,e),s.honeypot){const o=n.querySelector("form");o&&injectHoneypot(o)}})}}else renderManualForm(n,e.filter(a=>a.type!=="page-break"&&a.type!=="spacer"),s,r,t)}).catch(t=>{const e=document.createElement("p");e.textContent="Form unavailable.",e.style.cssText="color:#f87171;font-style:italic;",i.appendChild(e),console.warn("[forms]",t.message)})}
@@ -33,7 +33,8 @@ export async function createTransport(smtp) {
33
33
  host: smtp.host,
34
34
  port: smtp.port || 587,
35
35
  secure: smtp.secure || false,
36
- auth: smtp.user ? { user: smtp.user, pass: smtp.pass } : undefined
36
+ auth: smtp.user ? { user: smtp.user, pass: smtp.pass } : undefined,
37
+ tls: { rejectUnauthorized: false }
37
38
  });
38
39
  }
39
40