@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.97 kB
JavaScript
import e from"../../../constants/constants.mjs";import{cloneValue as t,emailStorageSegmentsToPath as n,getValueAtEmailStoragePath as r,removeValueAtEmailStoragePath as i,resolveExistingEmailStoragePaths as a,setValueAtEmailStoragePath as o}from"./paths.mjs";import{parseEmailStorageRules as s}from"./config.mjs";import{decryptEmailStorageValue as c,encryptEmailStorageValue as l}from"./encryption.mjs";const u=(e,t)=>[...e].sort((e,n)=>{let r=t===`specific`?n.specificity-e.specificity:e.specificity-n.specificity;return r===0?e.index-n.index:r}),d=e=>{if(e.data===null)return{error:void 0,data:null};let n=s(e.storage);if(n.error)return n;let i=t(e.data),c=u(n.data,`specific`);for(let{rule:t,segments:n}of c)if(!(t.encrypt!==!0&&(t.neverStore!==!0||e.options?.encryptNeverStore===!1)))for(let t of a(i,n)){let n=l(r(i,t),e.encryptionKey);if(n.error)return n;o(i,t,n.data)}return{error:void 0,data:i}},f=i=>{if(i.data===null)return{error:void 0,data:null};let l=s(i.storage);if(l.error)return l;let d=t(i.data),f=l.data;for(let{rule:e,segments:t}of u(f,`broad`))if(!(e.encrypt!==!0&&e.neverStore!==!0)&&!(i.mode===`preview`&&(e.redact===!0||e.neverStore===!0)))for(let e of a(d,t)){let t=c(r(d,e),i.encryptionKey);if(t.error)return t;o(d,e,t.data)}if(i.mode===`send`)return{error:void 0,data:d};for(let{rule:r,segments:i}of u(f,`broad`)){if(r.redact!==!0&&r.neverStore!==!0)continue;let s=r.previewFallback??e.email.storage.defaultPreviewFallback,c=a(d,i),l=i.some(e=>e.type===`wildcard`);if(c.length===0&&!l){o(d,n(i),t(s),{createMissing:!0});continue}for(let e of c)o(d,e,t(s))}return{error:void 0,data:d}},p=e=>{if(e.data===null)return{error:void 0,data:null};let n=s(e.storage);if(n.error)return n;let r=t(e.data),o=u(n.data,`specific`);for(let{rule:e,segments:t}of o)if(e.neverStore===!0)for(let e of a(r,t))i(r,e);return{error:void 0,data:r}};export{d as createStoredEmailData,f as resolveEmailData,p as stripNeverStoreEmailData};
//# sourceMappingURL=data.mjs.map