@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
2 lines • 1.74 kB
JavaScript
import e from"../../constants/constants.mjs";import t from"../../libs/repositories/alert-recipients.mjs";import n from"../../libs/repositories/alerts.mjs";import r from"../email/send-email.mjs";const i=e=>e instanceof Date?e.toISOString():String(e),a=async(a,o)=>{let s=Array.from(new Map(o.recipients.map(e=>[e.id,e])).values());if(s.length===0)return{error:void 0,data:void 0};let c=new n(a.db.client,a.config.db),l=new t(a.db.client,a.config.db),u=a.translate(o.title)??``,d=a.translate(o.message),f=(o.details??[]).filter(e=>e.value!==null&&e.value!==void 0).map(e=>({label:a.translate(e.label)??``,value:i(e.value)})),p=o.comment?.value?.trim()||null,m=o.comment?.html?.trim()||null,h=o.comment?a.translate(o.comment.label):void 0,g=await c.createSingle({data:{type:e.alerts.publishRequest.type,level:`info`,dedupe_key:`publish-request:${o.operationId}:${o.dedupeAction}`,title:u,message:d,metadata:{operationId:o.operationId,collectionKey:o.collectionKey,documentId:o.documentId,action:o.dedupeAction,comment:p,details:f},email_id:null},returning:[`id`],validation:{enabled:!0}});if(g.error)return g;let _=await l.createMultiple({data:s.map(e=>({alert_id:g.data.id,user_id:e.id}))});if(_.error)return _;let v=s.flatMap(e=>e.email?[e.email]:[]);if(v.length>0){let t=`/lucid/collections/${o.collectionKey}/${o.documentId}/release-requests/${o.operationId}`,n=await r(a,{type:`internal`,to:v,subject:u,template:e.email.templates.publishRequest.key,data:{title:u,message:d,actionUrl:t,details:f,hasDetails:f.length>0,comment:p,commentHtml:m,commentLabel:h},storage:e.email.templates.publishRequest.storage??void 0});if(n.error)return n}return{error:void 0,data:void 0}};export{a as default};
//# sourceMappingURL=notifications.mjs.map