@novu/framework 2.9.0 → 2.10.0-alpha.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.
@@ -90,10 +90,10 @@ commodo consequat Duis aute irure dolor in reprehenderit in voluptate velit esse
90
90
  pariatur Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est
91
91
  laborum`.split(/\W/),Wt=qs,Vt={type:He.ALLOWED_TYPES},sr=Bs,si=Js,or=Gs,qt=Ks,ar=Hs,lr=zs,oi="[a-zA-Z][a-zA-Z0-9+-.]*",Bt=`https?://{hostname}(?:${oi})+`,cr="(?:\\?([a-z]{1,7}(=\\w{1,5})?&){0,3})?",je={email:"[a-zA-Z\\d][a-zA-Z\\d-]{1,13}[a-zA-Z\\d]@{hostname}",hostname:"[a-zA-Z]{1,33}\\.[a-z]{2,4}",ipv6:"[a-f\\d]{4}(:[a-f\\d]{4}){7}",uri:Bt,slug:"[a-zA-Z\\d_-]+","uri-reference":`${Bt}${cr}`,"uri-template":Bt.replace("(?:","(?:/\\{[a-z][:a-zA-Z0-9-]*\\}|"),"json-pointer":`(/(?:${oi.replace("]*","/]*")}|~[01]))+`,uuid:"^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$",duration:"^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$"},je.iri=je["uri-reference"],je["iri-reference"]=je["uri-reference"],je["idn-email"]=je.email,je["idn-hostname"]=je.hostname,pr=new RegExp(`\\{(${Object.keys(je).join("|")})\\}`),ur=Xs,dr=Zs,fr={boolean:Qi,null:tr,array:nr,integer:ir,number:ri,object:sr,string:dr},Et=fr,hr=ft,mr=({refs:e,schema:t,container:i,synchronous:c,refDepthMax:p,refDepthMin:h})=>{let d={},O={},U=0,T,$;return d.resolveSchema=(E,J,W)=>{if(E==null)return null;if(typeof E.generate=="function")return E;if(typeof(E.$id||E.id)=="string"&&(delete E.id,delete E.$id,delete E.$schema),typeof E.$ref=="string"){let Q=Math.max(h,p)-1;if(E.$ref==="#"||O[E.$ref]<0||T===E.$ref&&++U>Q)return E.$ref!=="#"&&$&&$.length===W.length?de.getLocalRef(t,E.$ref,c&&e):(delete E.$ref,E);typeof O[E.$ref]=="undefined"&&(O[E.$ref]=Z.number(h,p)-1),$=W,T=E.$ref;let ne;E.$ref.indexOf("#/")===-1?ne=e[E.$ref]||null:ne=de.getLocalRef(t,E.$ref,c&&e)||null;let he;if(typeof ne!="undefined"){if(!ne&&te("ignoreMissingRefs")!==!0)throw new Error(`Reference not found: ${E.$ref}`);O[E.$ref]-=1,de.merge(E,ne||{}),he=c&&ne&&ne.$ref}return he||delete E.$ref,E}if(Array.isArray(E.allOf)){let Q=E.allOf;delete E.allOf,Q.forEach(ne=>{let he=d.resolveSchema(ne,null,W);de.merge(E,typeof he.thunk=="function"?he.thunk(E):he),Array.isArray(E.allOf)&&d.resolveSchema(E,J,W)})}if(Array.isArray(E.oneOf||E.anyOf)&&W[W.length-2]!=="dependencies"){let Q=E.oneOf||E.anyOf;return E.enum&&E.oneOf&&(E.enum=E.enum.filter(ne=>de.validate(ne,Q))),{thunk(ne){let he=de.omitProps(E,["anyOf","oneOf"]),ye=Z.pick(Q);return de.merge(he,ye),Q.forEach(j=>{j.required&&j!==ye&&j.required.forEach(S=>{if(ye.required&&ye.required.includes(S))return;let b=he.required&&he.required.includes(S);he.properties&&!b&&delete he.properties[S],ne&&ne.properties&&delete ne.properties[S]})}),he}}}if(Object.keys(E).forEach(Q=>{(Array.isArray(E[Q])||typeof E[Q]=="object")&&!de.isKey(Q)&&(E[Q]=d.resolveSchema(E[Q],Q,W.concat(Q)))}),W){let Q=W[W.length-1];if(Q==="properties"||Q==="items")return E}return i.wrap(E)},d},yr=mr,ai=io,li=ro,Le=Kn(Ci(),1),ao=Le.default.binaryOptions,lo=Le.default.boolOptions,co=Le.default.intOptions,po=Le.default.nullOptions,uo=Le.default.strOptions,fo=Le.default.Schema,ho=Le.default.Alias,mo=Le.default.Collection,yo=Le.default.Merge,go=Le.default.Node,wo=Le.default.Pair,So=Le.default.Scalar,gr=Le.default.YAMLMap,wr=Le.default.YAMLSeq,_t=oo,Xe=new Ji,Oe=(e,t,i)=>(console.debug("[json-schema-faker] calling JSONSchemaFaker() is deprecated, call either .generate() or .resolve()"),i&&console.debug("[json-schema-faker] local references are only supported by calling .resolve()"),Oe.generate(e,t)),Oe.generateWithContext=(e,t)=>{let i=Ti(t,e);return ai(i,e,Xe,!0)},Oe.generate=(e,t)=>li(Oe.generateWithContext(e,t)),Oe.generateYAML=(e,t)=>_t(Oe.generateWithContext(e,t)),Oe.resolveWithContext=(e,t,i)=>{typeof t=="string"&&(i=t,t={}),i=i||(typeof process!="undefined"&&typeof process.cwd=="function"?process.cwd():""),i=`${i.replace(/\/+$/,"")}/`;let c=Ti(t,e),p={order:1,canRead(d){let O=d.url.replace("/:",":");return c[O]||c[O.split("/").pop()]},read(d,O){try{O(null,this.canRead(d))}catch(U){O(U)}}},{$RefParser:h}=Qn();return h.bundle(i,e,{resolve:{file:{order:100},http:{order:200},fixedRefs:p},dereference:{circular:"ignore"}}).then(d=>ai(c,d,Xe)).catch(d=>{throw new Error(`Error while resolving schema (${d.message})`)})},Oe.resolve=(e,t,i)=>Oe.resolveWithContext(e,t,i).then(li),Oe.resolveYAML=(e,t,i)=>Oe.resolveWithContext(e,t,i).then(_t),bi(),Oe.format=ii,Oe.option=te,Oe.random=Z,Oe.extend=(e,t)=>(Xe.extend(e,t),Oe),Oe.define=(e,t)=>(Xe.define(e,t),Oe),Oe.reset=e=>(Xe.reset(e),bi(),Oe),Oe.locate=e=>Xe.get(e),Oe.VERSION="0.5.5",Sr={...Oe},br=Oe}}),To=M({"src/src/main.iife.js"(e,t){var i=(bo(),ie(Se));typeof $RefParser!="undefined"&&typeof JSONPath!="undefined"&&i.setDependencies({...JSONPath,$RefParser}),typeof window!="undefined"&&(window.JSONSchemaFaker=i.default),t.exports=i.default,t.exports.JSONSchemaFaker=i.JSONSchemaFaker}});return To()})();((f,n)=>{f.JSONSchemaFaker=n()})(typeof self!="undefined"?self:typeof window!="undefined"?window:globalThis,()=>bn);bn.random.shuffle=function(){return["[placeholder]"]};bn.option({useDefaultValue:!0,alwaysFakeOptionals:!0});function Ir(f){return bn.generate(f)}var Nr=async(f,n)=>{let s=new TextEncoder,l=s.encode(f),w=s.encode(n),M=await crypto.subtle.importKey("raw",l,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),C=await crypto.subtle.sign("HMAC",M,w);return Array.from(new Uint8Array(C)).map(K=>K.toString(16).padStart(2,"0")).join("")};var Bo=require("cross-fetch");var kr=async()=>{if(process.env.NOVU_BRIDGE_ORIGIN)return`${process.env.NOVU_BRIDGE_ORIGIN}/api/novu`;if(process.env.NEXT_PUBLIC_VERCEL_ENV==="preview"&&process.env.NEXT_PUBLIC_VERCEL_URL)return`https://${process.env.NEXT_PUBLIC_VERCEL_URL}/api/novu`;try{if(process.env.NODE_ENV==="development"||process.env.NODE_ENV==="dev"){let n=await(await fetch("http://localhost:2022/.well-known/novu")).json();return`${n.tunnelOrigin}${n.route}`}}catch(f){console.error(f)}return""};function Cr(f){return!!f&&typeof f=="object"&&"error"in f&&"message"in f&&"statusCode"in f}var Tn=(f,n)=>{if(!f)throw new cn;return{post:async(s,l)=>{let w=await fetch(`${n}/v1${s}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${f}`},body:JSON.stringify(l)}),M=await w.json();if(w.ok)return M;throw Cr(M)?new pn(M.statusCode,M.error,M.message):new mt(M)},delete:async s=>(await fetch(`${n}/v1${s}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${f}`}})).json()}};var $r=require("liquidjs");function di(f,n){let s={...f};for(let l of Object.keys(n)){let w=n[l];w&&typeof w=="object"&&!Array.isArray(w)?s[l]=di(s[l]||{},w):(Array.isArray(w),s[l]=w)}return s}function On(f,n){let s=n.split(".").reduce((l,w)=>{if(l&&typeof l=="object")return l[w]},f);if(s==null)return"";if(typeof s=="string")return s;if(typeof s=="number"||typeof s=="boolean")return String(s);if(typeof s=="object"){let l=JSON.stringify(s);return l==="{}"?"":l}return""}function Mr(f,n=2,s,l=", "){if(!Array.isArray(f)||f.length===0)return"";let w=s?f.map(K=>typeof K!="object"||!K?"":On(K,s)):f;if(w.length===1)return w[0];if(w.length===2)return`${w[0]} and ${w[1]}`;if(w.length===3&&n>=3)return`${w[0]}, ${l}${w[1]} and ${w[2]}`;let M=w.slice(0,n),C=w.length-n;return`${M.join(l)} and ${C} ${C===1?"other":"others"}`}var Lr=et(require("pluralize"),1);function Dr(f,n="",s="",l="true"){if(f==null)return"";let w=0;if(Array.isArray(f)?w=f.length:typeof f=="object"?w=Object.keys(f).length:typeof f=="string"?w=+f:typeof f=="number"?w=f:w=Number(f),Number.isNaN(w)&&(w=0),w<=0)return"";let M;return s?M=w===1?n:s:M=(0,Lr.default)(n,w),l==="true"?`${w} ${M}`:M}var Jo=require("liquidjs"),Ur=et(require("pluralize"),1),Go=require("zod");var Ko="",Ho=2,zo="other",Xo=", ",Qo=" and ",Zo=", and ";function Fr(f,n=Ko,s=Ho,l=zo,w=Xo,M=Qo,C=Zo){if(!Array.isArray(f)||f.length===0)return"";let K=n?f.map(be=>typeof be!="object"||!be?"":On(be,n)):f,ie=K.length;if(ie===1)return K[0];if(ie===2)return`${K[0]}${M}${K[1]}`;if(s>=ie){let be=K.slice(0,ie-1),ke=K[ie-1];return`${be.join(w)}${C}${ke}`}let Se=K.slice(0,s),Ie=ie-s,Ne=s===1?M:C;return`${Se.join(w)}${Ne}${Ie} ${(0,Ur.default)(l,Ie)}`}function ea(f){return Array.isArray(f)||typeof f=="object"&&f!==null?jr(f):typeof f=="string"&&f.includes(`
92
92
  `)?f.replace(/\n/g,"\\n"):f==null?"":String(f)}var jr=(f,n=0)=>Array.isArray(f)||typeof f=="object"&&f!==null?JSON.stringify(f,null,n).replace(/"/g,"'").replace(/\n/g,"\\n"):f==null?"":String(f);function Yr(f){let n=new $r.Liquid({outputEscape:ea,...f});return n.registerFilter("json",(s,l)=>jr(s,l)),n.registerFilter("digest",Mr),n.registerFilter("toSentence",Fr),n.registerFilter("pluralize",Dr),n}var pt=et(require("chalk"),1),we={info:f=>pt.default.blue(f),warning:f=>pt.default.yellow(f),error:f=>pt.default.red(f),success:f=>pt.default.green(f),underline:f=>pt.default.underline(f),bold:f=>pt.default.bold(f)},Re={SUCCESS:we.success("\u2714"),ERROR:we.error("\u2717"),WARNING:we.warning("\u26A0"),INFO:we.info("\u2139"),ARROW:we.bold("\u2192"),MOCK:we.info("\u25CB"),HYDRATED:we.bold(we.info("\u2192")),STEP:we.info("\u03C3"),ACTION:we.info("\u03B1"),DURATION:we.info("\u0394"),PROVIDER:we.info("\u2699"),OUTPUT:we.info("\u21E2"),INPUT:we.info("\u21E0"),WORKFLOW:we.info("\u03C9"),STATE:we.info("\u03C3"),EXECUTE:we.info("\u03B5"),PREVIEW:we.info("\u03C1")};function An(f){return f||process.env.NOVU_API_URL||"https://api.novu.co"}function vn(f){return f||process.env.NOVU_SECRET_KEY||process.env.NOVU_API_KEY||""}var fi=et(require("sanitize-html"),1),ta=["src","alt","width","height","loading","srcset","sizes","crossorigin","usemap","ismap","class","id","style","title","dir","lang"],na={allowedTags:fi.default.defaults.allowedTags.concat(["style","img","html","head","body","link","meta","title"]),allowedAttributes:!1,transformTags:{img:(f,n)=>{let s={};for(let[l,w]of Object.entries(n))ta.includes(l.toLowerCase())&&(s[l]=w);return{tagName:f,attribs:s}}},allowVulnerableTags:!0,parseStyleAttributes:!1,parser:{lowerCaseAttributeNames:!0}},Wr=f=>{if(!f)return f;let n=/^<!DOCTYPE .*?>/,s=f.match(n),l=(0,fi.default)(f,na);return s?s[0]+l:l},En=f=>Object.keys(f).reduce((n,s)=>{let l=f[s];return typeof l=="string"?n[s]=Wr(l):Array.isArray(l)?n[s]=l.map(w=>typeof w=="string"?Wr(w):typeof w=="object"?En(w):w):typeof l=="object"&&l!==null?n[s]=En(l):n[s]=l,n},{});function Vr(f){console.log(`
93
- ${we.bold(we.underline("Discovered workflowId:"))} '${f.workflowId}'`),f.steps.forEach((n,s)=>{let l=s===f.steps.length-1;console.log(`${l?"\u2514":"\u251C"} ${Re.STEP} Discovered stepId: '${n.stepId}' Type: '${n.type}'`),n.providers.forEach((M,C)=>{let K=C===n.providers.length-1;console.log(`${l?" ":"\u2502"} ${K?"\u2514":"\u251C"} ${Re.PROVIDER} Discovered provider: '${M.type}'`)})})}var Br=et(require("ajv"),1),Jr=et(require("ajv-formats"),1);var qr=f=>typeof structuredClone=="function"?structuredClone(f):JSON.parse(JSON.stringify(f));var _n=class extends ot{constructor(s,l){let w=l.length===1?"it":"them";super(`Tried to use a ${s} in @novu/framework without ${l.join(", ")} installed. Please install ${w} by running \`npm install ${l.join(" ")}\`.`);this.statusCode=500;this.code="MissingDependencyError"}};var Rn=async(f,n)=>{let s=new Set;if((await Promise.allSettled(f.map(w=>w.import))).forEach((w,M)=>{let C=f[M];w.status==="fulfilled"&&C.exports.every(ie=>w.value[ie]!==void 0)||s.add(C.name)}),s.size>0)throw new _n(n,Array.from(s))};var Pn=class{constructor(){this.requiredImports=[];this.ajv=new Br.default({useDefaults:!0,removeAdditional:"failing"}),(0,Jr.default)(this.ajv),this.compiledSchemas=new Map}async canHandle(n){let s=n.type==="object"||!!n.anyOf||!!n.allOf||!!n.oneOf;return s&&await Rn(this.requiredImports,"JSON schema"),s}async validate(n,s){let l=this.compiledSchemas.get(s);l||(l=this.ajv.compile(s),this.compiledSchemas.set(s,l));let w=qr(n);return l(w)?{success:!0,data:w}:{success:!1,errors:l.errors.map(C=>({path:C.instancePath,message:C.message}))}}async transformToJsonSchema(n){return n}};var xn=class{constructor(){this.requiredImports=[{name:"zod",import:import("zod"),exports:["ZodType"]},{name:"zod-to-json-schema",import:import("zod-to-json-schema"),exports:["zodToJsonSchema"]}]}async canHandle(n){let s=n.safeParseAsync!==void 0;return s&&await Rn(this.requiredImports,"Zod schema"),s}async validate(n,s){let l=await s.safeParseAsync(n);return l.success?{success:!0,data:l.data}:{success:!1,errors:l.error.errors.map(w=>({path:`/${w.path.join("/")}`,message:w.message}))}}async transformToJsonSchema(n){let{zodToJsonSchema:s}=await import("zod-to-json-schema");return s(n)}};var In=new xn,Nn=new Pn,kn=async(f,n)=>{if(await In.canHandle(f))return In.validate(n,f);if(await Nn.canHandle(f))return Nn.validate(n,f);throw new Error("Invalid schema")},Me=async f=>{if(await In.canHandle(f))return In.transformToJsonSchema(f);if(await Nn.canHandle(f))return Nn.transformToJsonSchema(f);throw new Error("Invalid schema")};function ia(){return["development",void 0,"dev"].includes(process.env.NODE_ENV)}var wt=class{constructor(n){this.discoveredWorkflows=new Map;this.discoverWorkflowPromises=new Map;this.version="2.9.0";let s=this.buildOptions(n);this.apiUrl=s.apiUrl,this.secretKey=s.secretKey,this.strictAuthentication=s.strictAuthentication,this.templateEngine=Yr()}buildOptions(n){let s={apiUrl:An(n==null?void 0:n.apiUrl),secretKey:vn(n==null?void 0:n.secretKey),strictAuthentication:!ia()};return(n==null?void 0:n.strictAuthentication)!==void 0?s.strictAuthentication=n.strictAuthentication:process.env.NOVU_STRICT_AUTHENTICATION_ENABLED!==void 0&&(s.strictAuthentication=process.env.NOVU_STRICT_AUTHENTICATION_ENABLED==="true"),s}async addWorkflows(n){for(let s of n){if(this.discoveredWorkflows.has(s.id))continue;let l=this.discoverWorkflowPromises.get(s.id);if(l){await l;continue}let w=this.addWorkflow(s);this.discoverWorkflowPromises.set(s.id,w),await w}}async addWorkflow(n){try{let s=await n.discover();Vr(s),this.discoveredWorkflows.set(n.id,s)}finally{this.discoverWorkflowPromises.delete(n.id)}}healthCheck(){let n=this.getRegisteredWorkflows(),s=n.length,l=n.reduce((w,M)=>w+M.steps.length,0);return{status:"ok",sdkVersion:"2.9.0",frameworkVersion:"2024-06-26",discovered:{workflows:s,steps:l}}}getWorkflow(n){let s=this.discoveredWorkflows.get(n);if(s)return s;throw new Mt(n)}getStep(n,s){let w=this.getWorkflow(n).steps.find(M=>M.stepId===s);if(w)return w;throw new wn(s)}getRegisteredWorkflows(){return Array.from(this.discoveredWorkflows.values())}discover(){return{workflows:this.getRegisteredWorkflows()}}mock(n){return Ir(n)}async validate(n,s,l,w,M,C,K){let ie=await kn(s,n);if(ie.success)return ie.data;switch(l){case"event":this.throwInvalidEvent(w,M,ie.errors);case"step":this.throwInvalidStep(C,w,M,ie.errors);case"provider":this.throwInvalidProvider(C,K,w,M,ie.errors);default:throw new Error(`Invalid component: '${l}'`)}}throwInvalidProvider(n,s,l,w,M){if(!n)throw new Error("stepId is required");if(!s)throw new Error("providerId is required");switch(l){case"output":throw new sn(w,n,s,M);default:throw new Error(`Invalid payload type: '${l}'`)}}throwInvalidStep(n,s,l,w){if(!n)throw new Error("stepId is required");switch(s){case"output":throw new tn(l,n,w);case"result":throw new nn(l,n,w);case"controls":throw new en(l,n,w);default:throw new Error(`Invalid payload type: '${s}'`)}}throwInvalidEvent(n,s,l){switch(n){case"controls":throw new Zt(s,l);case"payload":throw new It(s,l);default:throw new Error(`Invalid payload type: '${n}'`)}}executeStepFactory(n,s,l){return async(w,M,C)=>{if(l())return;let K=this.getStep(n.workflowId,w),ie=n.action==="preview";if(!ie&&w===n.stepId){let ke=await this.createStepControls(K,n),Fe=await this.compileControls(ke,n);if(await this.shouldSkip(C==null?void 0:C.skip,Fe))return s({options:{skip:!0},outputs:{},providers:{}}),{}}let Se=this.previewStep.bind(this),Ie=this.executeStep.bind(this),be=await(ie?Se:Ie)(n,{...K,providers:K.providers.map(ke=>{var it;let Fe=(it=C==null?void 0:C.providers)==null?void 0:it[ke.type];if(!Fe)throw new un(ke.type);return{...ke,resolve:Fe}}),resolve:M});return this.shouldSanitize({stepType:K.type,options:C})&&(be={...be,outputs:En(be.outputs)}),w===n.stepId&&s({...be,options:{skip:!1}}),be.outputs}}shouldSanitize({stepType:n,options:s}){return(s==null?void 0:s.disableOutputSanitization)===!0?!1:["email","in_app"].includes(n)}async shouldSkip(n,s){return n?n(s):!1}async executeWorkflow(n){let w=`${{execute:"Executing",preview:"Previewing"}[n.action]} workflowId:`;console.log(`
93
+ ${we.bold(we.underline("Discovered workflowId:"))} '${f.workflowId}'`),f.steps.forEach((n,s)=>{let l=s===f.steps.length-1;console.log(`${l?"\u2514":"\u251C"} ${Re.STEP} Discovered stepId: '${n.stepId}' Type: '${n.type}'`),n.providers.forEach((M,C)=>{let K=C===n.providers.length-1;console.log(`${l?" ":"\u2502"} ${K?"\u2514":"\u251C"} ${Re.PROVIDER} Discovered provider: '${M.type}'`)})})}var Br=et(require("ajv"),1),Jr=et(require("ajv-formats"),1);var qr=f=>typeof structuredClone=="function"?structuredClone(f):JSON.parse(JSON.stringify(f));var _n=class extends ot{constructor(s,l){let w=l.length===1?"it":"them";super(`Tried to use a ${s} in @novu/framework without ${l.join(", ")} installed. Please install ${w} by running \`npm install ${l.join(" ")}\`.`);this.statusCode=500;this.code="MissingDependencyError"}};var Rn=async(f,n)=>{let s=new Set;if((await Promise.allSettled(f.map(w=>w.import))).forEach((w,M)=>{let C=f[M];w.status==="fulfilled"&&C.exports.every(ie=>w.value[ie]!==void 0)||s.add(C.name)}),s.size>0)throw new _n(n,Array.from(s))};var Pn=class{constructor(){this.requiredImports=[];this.ajv=new Br.default({useDefaults:!0,removeAdditional:"failing"}),(0,Jr.default)(this.ajv),this.compiledSchemas=new Map}async canHandle(n){let s=n.type==="object"||!!n.anyOf||!!n.allOf||!!n.oneOf;return s&&await Rn(this.requiredImports,"JSON schema"),s}async validate(n,s){let l=this.compiledSchemas.get(s);l||(l=this.ajv.compile(s),this.compiledSchemas.set(s,l));let w=qr(n);return l(w)?{success:!0,data:w}:{success:!1,errors:l.errors.map(C=>({path:C.instancePath,message:C.message}))}}async transformToJsonSchema(n){return n}};var xn=class{constructor(){this.requiredImports=[{name:"zod",import:import("zod"),exports:["ZodType"]},{name:"zod-to-json-schema",import:import("zod-to-json-schema"),exports:["zodToJsonSchema"]}]}async canHandle(n){let s=n.safeParseAsync!==void 0;return s&&await Rn(this.requiredImports,"Zod schema"),s}async validate(n,s){let l=await s.safeParseAsync(n);return l.success?{success:!0,data:l.data}:{success:!1,errors:l.error.errors.map(w=>({path:`/${w.path.join("/")}`,message:w.message}))}}async transformToJsonSchema(n){let{zodToJsonSchema:s}=await import("zod-to-json-schema");return s(n)}};var In=new xn,Nn=new Pn,kn=async(f,n)=>{if(await In.canHandle(f))return In.validate(n,f);if(await Nn.canHandle(f))return Nn.validate(n,f);throw new Error("Invalid schema")},Me=async f=>{if(await In.canHandle(f))return In.transformToJsonSchema(f);if(await Nn.canHandle(f))return Nn.transformToJsonSchema(f);throw new Error("Invalid schema")};function ia(){return["development",void 0,"dev"].includes(process.env.NODE_ENV)}var wt=class{constructor(n){this.discoveredWorkflows=new Map;this.discoverWorkflowPromises=new Map;this.version="2.10.0-alpha.0";let s=this.buildOptions(n);this.apiUrl=s.apiUrl,this.secretKey=s.secretKey,this.strictAuthentication=s.strictAuthentication,this.templateEngine=Yr()}buildOptions(n){let s={apiUrl:An(n==null?void 0:n.apiUrl),secretKey:vn(n==null?void 0:n.secretKey),strictAuthentication:!ia()};return(n==null?void 0:n.strictAuthentication)!==void 0?s.strictAuthentication=n.strictAuthentication:process.env.NOVU_STRICT_AUTHENTICATION_ENABLED!==void 0&&(s.strictAuthentication=process.env.NOVU_STRICT_AUTHENTICATION_ENABLED==="true"),s}async addWorkflows(n){for(let s of n){if(this.discoveredWorkflows.has(s.id))continue;let l=this.discoverWorkflowPromises.get(s.id);if(l){await l;continue}let w=this.addWorkflow(s);this.discoverWorkflowPromises.set(s.id,w),await w}}async addWorkflow(n){try{let s=await n.discover();Vr(s),this.discoveredWorkflows.set(n.id,s)}finally{this.discoverWorkflowPromises.delete(n.id)}}healthCheck(){let n=this.getRegisteredWorkflows(),s=n.length,l=n.reduce((w,M)=>w+M.steps.length,0);return{status:"ok",sdkVersion:"2.10.0-alpha.0",frameworkVersion:"2024-06-26",discovered:{workflows:s,steps:l}}}getWorkflow(n){let s=this.discoveredWorkflows.get(n);if(s)return s;throw new Mt(n)}getStep(n,s){let w=this.getWorkflow(n).steps.find(M=>M.stepId===s);if(w)return w;throw new wn(s)}getRegisteredWorkflows(){return Array.from(this.discoveredWorkflows.values())}discover(){return{workflows:this.getRegisteredWorkflows()}}mock(n){return Ir(n)}async validate(n,s,l,w,M,C,K){let ie=await kn(s,n);if(ie.success)return ie.data;switch(l){case"event":this.throwInvalidEvent(w,M,ie.errors);case"step":this.throwInvalidStep(C,w,M,ie.errors);case"provider":this.throwInvalidProvider(C,K,w,M,ie.errors);default:throw new Error(`Invalid component: '${l}'`)}}throwInvalidProvider(n,s,l,w,M){if(!n)throw new Error("stepId is required");if(!s)throw new Error("providerId is required");switch(l){case"output":throw new sn(w,n,s,M);default:throw new Error(`Invalid payload type: '${l}'`)}}throwInvalidStep(n,s,l,w){if(!n)throw new Error("stepId is required");switch(s){case"output":throw new tn(l,n,w);case"result":throw new nn(l,n,w);case"controls":throw new en(l,n,w);default:throw new Error(`Invalid payload type: '${s}'`)}}throwInvalidEvent(n,s,l){switch(n){case"controls":throw new Zt(s,l);case"payload":throw new It(s,l);default:throw new Error(`Invalid payload type: '${n}'`)}}executeStepFactory(n,s,l){return async(w,M,C)=>{if(l())return;let K=this.getStep(n.workflowId,w),ie=n.action==="preview";if(!ie&&w===n.stepId){let ke=await this.createStepControls(K,n),Fe=await this.compileControls(ke,n);if(await this.shouldSkip(C==null?void 0:C.skip,Fe))return s({options:{skip:!0},outputs:{},providers:{}}),{}}let Se=this.previewStep.bind(this),Ie=this.executeStep.bind(this),be=await(ie?Se:Ie)(n,{...K,providers:K.providers.map(ke=>{var it;let Fe=(it=C==null?void 0:C.providers)==null?void 0:it[ke.type];if(!Fe)throw new un(ke.type);return{...ke,resolve:Fe}}),resolve:M});return this.shouldSanitize({stepType:K.type,options:C})&&(be={...be,outputs:En(be.outputs)}),w===n.stepId&&s({...be,options:{skip:!1}}),be.outputs}}shouldSanitize({stepType:n,options:s}){return(s==null?void 0:s.disableOutputSanitization)===!0?!1:["email","in_app"].includes(n)}async shouldSkip(n,s){return n?n(s):!1}async executeWorkflow(n){let w=`${{execute:"Executing",preview:"Previewing"}[n.action]} workflowId:`;console.log(`
94
94
  ${we.bold(we.underline(w))} '${n.workflowId}'`);let M=this.getWorkflow(n.workflowId),C=process.hrtime(),K={outputs:{},providers:{},options:{skip:!1}},ie,Se=!1,Ie=new Promise(Ke=>{ie=Ke}),Ne=Ke=>{if(Se)throw new Error("setResult can only be called once per workflow execution");ie(),Se=!0,K=Ke},be=()=>Se,ke;try{if(n.action==="execute"&&!n.payload)throw new It(n.workflowId,{message:"Event `payload` is required"});let Ke=await this.createExecutionPayload(n,M),qe={...n,payload:Ke};await Promise.race([Ie,M.execute({payload:Ke,environment:{},controls:{},subscriber:n.subscriber,context:n.context,step:{email:this.executeStepFactory(qe,Ne,be),sms:this.executeStepFactory(qe,Ne,be),inApp:this.executeStepFactory(qe,Ne,be),digest:this.executeStepFactory(qe,Ne,be),delay:this.executeStepFactory(qe,Ne,be),push:this.executeStepFactory(qe,Ne,be),chat:this.executeStepFactory(qe,Ne,be),custom:this.executeStepFactory(qe,Ne,be),throttle:this.executeStepFactory(qe,Ne,be)}})])}catch(Ke){ke=Ke}let Fe=process.hrtime(C),it=Fe[0],Ge=Fe[1],Ut=it*1e3+Ge/1e6,jn=ke?Re.ERROR:Re.SUCCESS,Ft={execute:"Executed",preview:"Previewed"}[n.action];if(console.log(`${jn} ${Ft} workflowId: \`${n.workflowId}\``),this.prettyPrintExecute(n,Ut,ke),ke)throw ke;return{outputs:K.outputs,providers:K.providers,options:K.options,metadata:{status:"success",error:!1,duration:Ut}}}async createExecutionPayload(n,s){let{payload:l}=n;if(n.action==="preview"){let M=this.mock(s.payload.schema);l=Object.assign(M,l)}return await this.validate(l,s.payload.unknownSchema,"event","payload",n.workflowId)}prettyPrintExecute(n,s,l){let w=l?Re.ERROR:Re.SUCCESS,C={execute:"Executed",preview:"Previewed"}[n.action],K=l?"Failed to execute":C,ie=l?we.error:we.success,Se=`${w} ${K} workflowId: '${n.workflowId}`;console.log(`
95
95
  ${we.bold(ie(Se))}'`),console.log(` \u251C ${Re.STEP} stepId: '${n.stepId}'`),console.log(` \u251C ${Re.ACTION} action: '${n.action}'`),console.log(` \u2514 ${Re.DURATION} duration: '${s.toFixed(2)}ms'
96
- `)}async executeProviders(n,s,l){return s.providers.reduce(async(w,M)=>{let C=await w,K=this.previewProvider.bind(this),ie=this.executeProvider.bind(this),Ie=await(n.action==="preview"?K:ie)(n,s,M,l);return{...C,[M.type]:Ie}},Promise.resolve({}))}previewProvider(n,s,l,w){return console.log(` ${Re.MOCK} Mocked provider: \`${l.type}\``),this.mock(l.outputs.schema)}async executeProvider(n,s,l,w){try{if(n.stepId===s.stepId){let M=await this.createStepControls(s,n),C=await l.resolve({controls:M,outputs:w}),K=await this.validate(C,l.outputs.unknownSchema,"step","output",n.workflowId,s.stepId,l.type);return console.log(` ${Re.SUCCESS} Executed provider: \`${l.type}\``),{...K,_passthrough:C._passthrough}}else return console.log(` ${Re.HYDRATED} Hydrated provider: \`${l.type}\``),{}}catch(M){throw console.log(` ${Re.ERROR} Failed to execute provider: \`${l.type}\``),new dn(l.type,n.action,M)}}async executeStep(n,s){if(n.stepId===s.stepId)try{let l=await this.createStepControls(s,n),w=await this.compileControls(l,n),M=await s.resolve(w),C=await this.validate(M,s.outputs.unknownSchema,"step","output",n.workflowId,s.stepId),K=await this.executeProviders(n,s,C);return console.log(` ${Re.SUCCESS} Executed stepId: \`${s.stepId}\``),{outputs:C,providers:K}}catch(l){throw console.log(` ${Re.ERROR} Failed to execute stepId: \`${s.stepId}\``),lt(l)?l:new Ct(s.stepId,n.action,l)}else try{let l=this.getStepState(n,s.stepId);if(l){let w=await this.validate(l.outputs,s.results.unknownSchema,"step","result",n.workflowId,s.stepId);return console.log(` ${Re.HYDRATED} Hydrated stepId: \`${s.stepId}\``),{outputs:w,providers:await this.executeProviders(n,s,w)}}else throw new Qt(n.workflowId,s.stepId)}catch(l){throw console.log(` ${Re.ERROR} Failed to hydrate stepId: \`${s.stepId}\``),l}}async compileControls(n,s){try{let l=this.preprocessTranslationPatterns(JSON.stringify(n));l=this.preprocessFilterTranslationArgs(l);let w=this.templateEngine.parse(l),M=this.getWorkflow(s.workflowId),C={workflow:{workflowId:M.workflowId,name:M.name,description:M.description,tags:M.tags,severity:M.severity},payload:s.payload,subscriber:s.subscriber,context:s.context,steps:ra(s.state)},K=await this.templateEngine.render(w,C),ie=this.postprocessTranslationMarkers(K),Se=(0,Gr.jsonrepair)(ie);return JSON.parse(Se)}catch(l){throw new rn(s.workflowId,s.stepId,l)}}preprocessTranslationPatterns(n){return n.replace(/\{\{\s*t\.([\p{L}\p{N}_.-]+)\s*\}\}/gu,"[T:$1]")}preprocessFilterTranslationArgs(n){return n.replace(/'t\.([\p{L}\p{N}_.-]+)'/gu,"'[T:$1]'")}postprocessTranslationMarkers(n){return n.replace(/\[T:([\p{L}\p{N}_.-]+)\]/gu,"{{t.$1}}")}async createStepControls(n,s){return await this.validate(s.controls,n.controls.unknownSchema,"step","controls",s.workflowId,n.stepId)}async previewStep(n,s){try{return await this.constructStepForPreview(n,s)}catch(l){throw console.log(` ${Re.ERROR} Failed to preview stepId: \`${s.stepId}\``),lt(l)?l:new Ct(s.stepId,n.action,l)}}async constructStepForPreview(n,s){return n.stepId===s.stepId?await this.previewRequiredStep(s,n):await this.extractMockDataForPreviousSteps(n,s)}async extractMockDataForPreviousSteps(n,s){let l={},w=this.getStepState(n,s.stepId),M=this.mock(s.results.schema);return{outputs:di(M,(w==null?void 0:w.outputs)||{}),providers:await this.executeProviders(n,s,l)}}async previewRequiredStep(n,s){let l=await this.createStepControls(n,s),w=await this.compileControls(l,s),M=await n.resolve(w),C=await this.validate(M,n.outputs.unknownSchema,"step","output",s.workflowId,n.stepId);return console.log(` ${Re.MOCK} Mocked stepId: \`${n.stepId}\``),{outputs:C,providers:await this.executeProviders(s,n,C)}}getStepState(n,s){return n.state.find(l=>l.stepId===s)}getStepCode(n,s){return{code:this.getStep(n,s).resolve.toString()}}getWorkflowCode(n){return{code:this.getWorkflow(n).execute.toString()}}getCode(n,s){let l;if(n)s?l=this.getStepCode(n,s):l=this.getWorkflowCode(n);else throw new Mt(n);return l}};function ra(f){let n={};for(let s of f)n[s.stepId]=s.outputs;return n}var St=class{constructor(n){this.handler=n.handler,this.client=n.client?n.client:new wt,this.workflows=n.workflows,this.http=Tn(this.client.secretKey,this.client.apiUrl),this.frameworkName=n.frameworkName,this.hmacEnabled=this.client.strictAuthentication}createHandler(){return async(...n)=>{await this.client.addWorkflows(this.workflows);let s=await this.handler(...n),l=await this.handleAction({actions:s});return s.transformResponse(l)}}getStaticHeaders(){let n=`novu-framework:v${this.client.version}`;return{"content-type":"application/json","access-control-allow-origin":"*","access-control-allow-methods":"GET, POST","access-control-allow-headers":"*","access-control-max-age":"604800","novu-framework-version":"2024-06-26","novu-framework-sdk":"2.9.0","novu-framework-server":this.frameworkName,"user-agent":n}}createResponse(n,s){return{status:n,body:JSON.stringify(s),headers:{...this.getStaticHeaders()}}}createError(n){return{status:n.statusCode,body:JSON.stringify({message:n.message,data:n.data,code:n.code}),headers:this.getStaticHeaders()}}async handleAction({actions:n}){let s=await n.url(),l=await n.method(),w=s.searchParams.get("action")||"health-check",M=s.searchParams.get("workflowId")||"",C=s.searchParams.get("stepId")||"",K=await n.headers("novu-signature")||"",ie={};try{l==="POST"&&(ie=await n.body())}catch{}try{w!=="health-check"&&await this.validateHmac(ie,K);let Se=this.getPostActionMap(ie,M,C,w),Ie=this.getGetActionMap(M,C);if(l==="POST")return await this.handlePostAction(w,Se);if(l==="GET")return await this.handleGetAction(w,Ie);if(l==="OPTIONS")return this.createResponse(200,{})}catch(Se){return this.handleError(Se)}return this.createError(new ln(l))}getPostActionMap(n,s,l,w){return{trigger:this.triggerAction({workflowId:s,...n}),execute:async()=>{let M=await this.client.executeWorkflow({...n,workflowId:s,stepId:l,action:w});return this.createResponse(200,M)},preview:async()=>{let M=await this.client.executeWorkflow({...n,workflowId:s,stepId:l,action:w});return this.createResponse(200,M)}}}triggerAction(n){return async()=>{let s={name:n.workflowId,to:n.to,payload:(n==null?void 0:n.payload)||{},transactionId:n.transactionId,overrides:n.overrides||{},...n.actor&&{actor:n.actor},...n.bridgeUrl&&{bridgeUrl:n.bridgeUrl},...n.controls&&{controls:n.controls},...n.context&&{context:n.context}},l=await this.http.post("/events/trigger",s);return this.createResponse(200,l)}}getGetActionMap(n,s){return{discover:async()=>{let l=await this.client.discover();return this.createResponse(200,l)},"health-check":async()=>{let l=await this.client.healthCheck();return this.createResponse(200,l)},code:async()=>{let l=await this.client.getCode(n,s);return this.createResponse(200,l)}}}async handlePostAction(n,s){if(Object.values(Pt).includes(n)){let l=s[n];return l()}else throw new Nt(n,Pt)}async handleGetAction(n,s){if(Object.values(Kt).includes(n)){let l=s[n];return l()}else throw new Nt(n,Kt)}handleError(n){if(lt(n))return n.statusCode>=500&&console.error(n),this.createError(n);if(Or(n))return this.createError(n);{let s=new mt(n);return console.error(s),this.createError(s)}}async validateHmac(n,s){if(!this.hmacEnabled)return;if(!s)throw new hn;if(!this.client.secretKey)throw new gn;let[l,w]=s.split(",");if(!l||!w)throw new mn;let[M,C]=l.split("="),[K,ie]=w.split("=");if(Number(M)<Date.now()-1500)throw new yn;if(!(await Nr(this.client.secretKey,`${C}.${JSON.stringify(n)}`)===ie))throw new fn}};var B={output:{type:"object",properties:{},required:[],additionalProperties:!0}};var oa={type:"object",properties:{webhookUrl:{type:"string",format:"uri"},text:{type:"string"},blocks:{type:"array",items:{type:"object",properties:{type:{enum:["image","context","actions","divider","section","input","file","header","video","rich_text"]}},required:["type"],additionalProperties:!0}}},additionalProperties:!0},Kr={output:oa};var Hr={"chat-webhook":B,discord:B,getstream:B,"grafana-on-call":B,mattermost:B,msteams:B,"rocket-chat":B,ryver:B,slack:Kr,"whatsapp-business":B,zulip:B};var aa={type:"object",properties:{to:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:'Email address of the recipient(s). Example: "Bob bob@host.com". You can use commas to separate multiple recipients (e.g.: "test@example.com,test@example.com" or ["test@example.com", "test@example.com"]).'},from:{type:"string"},subject:{type:"string",description:"Subject of the message."},text:{type:"string",description:"Text version of the message."},html:{type:"string",description:"HTML version of the message."},message:{type:"string",description:"MIME string of the message. Make sure to use multipart/form-data to send this as a file upload."},cc:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"Same as To but for carbon copy"},bcc:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"Same as To but for blind carbon copy"},ampHtml:{type:"string"},tVersion:{type:"string"},tText:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}]},oTag:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"Tag string. See Tagging for more information."},oDkim:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Enables/disabled DKIM signatures on per-message basis. Pass yes or no"},oDeliverytime:{type:"string",description:"Desired time of delivery. See Date Format. Note: Messages can be scheduled for a maximum of 3 days in the future."},oDeliverytimeOptimizePeriod:{type:"string"},oTimeZoneLocalize:{type:"string"},oTestmode:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Enables sending in test mode. Pass yes if needed. See Sending in Test Mode"},oTracking:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Toggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no."},oTrackingClicks:{anyOf:[{type:"string",enum:["yes","no","htmlonly"]},{type:"boolean"}],description:"Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly."},oTrackingOpens:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no."},oRequireTls:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}]},oSkipVerification:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}]},recipientVariables:{type:"string"}},required:[],additionalProperties:!0},zr={output:aa};var ut={type:"object",properties:{name:{type:"string"},email:{type:"string"}},description:'JSON object, containing 2 properties: Name and Email address of a previously validated and active sender. Including the Name property in the JSON is optional. This property is not mandatory in case you use TemplateID and you specified a From address for the template. Format : { "Email":"value", "Name":"value" }.',required:["Email"],additionalProperties:!0},la={type:"object",properties:{contentType:{type:"string"},filename:{type:"string"},base64Content:{type:"string"}},required:["ContentType","Filename","Base64Content"],additionalProperties:!0},ca={type:"object",properties:{filename:{type:"string"},contentType:{type:"string"},contentId:{type:"string"},base64Content:{type:"string"}},required:["ContentType","Filename","Base64Content"],additionalProperties:!0},pa={type:"object",properties:{from:ut,sender:ut,to:{type:"array",items:ut},cc:{type:"array",items:ut},bcc:{type:"array",items:ut},replyTo:ut,subject:{type:"string"},textPart:{type:"string",description:"Content of the message, sent in Text and/or HTML format. At least one of these content types needs to be specified. When the HTML part is the only part provided, Mailjet will not generate a Text-part from the HTML version. The property can't be set when you use TemplateID"},htmlPart:{type:"string",description:"Content of the message, sent in Text and/or HTML format. At least one of these content types needs to be specified. When the HTML part is the only part provided, Mailjet will not generate a Text-part from the HTML version. The property can't be set when you use TemplateID"},templateId:{type:"number",description:"an ID for a template that is previously created and stored in Mailjet's system. It is mandatory when From and TextPart and/or HtmlPart are not provided. "},templateLanguage:{type:"boolean"},templateErrorReporting:ut,templateErrorDeliver:{type:"boolean"},attachments:{type:"array",items:la},inlineAttachments:{type:"array",items:ca},priority:{type:"number"},customCampaign:{type:"string"},deduplicateCampaign:{type:"boolean"},trackOpens:{type:"string",enum:["account_default","disabled","enabled"]},trackClicks:{type:"string",enum:["account_default","disabled","enabled"]},customId:{type:"string"},eventPayload:{type:"string"},urlTags:{type:"string"},headers:{type:"object",additionalProperties:!0},variables:{type:"object",additionalProperties:!0}},required:[],additionalProperties:!0},Xr={output:pa};var Be={type:"object",properties:{address:{type:"string"},name:{type:"string"}},additionalProperties:!0},Cn={type:"object",properties:{content:{type:"string"},path:{type:"string"}},additionalProperties:!0},ua={type:"object",properties:{from:{anyOf:[{type:"string"},Be]},sender:{anyOf:[{type:"string"},Be]},to:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},cc:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},bcc:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},replyTo:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},inReplyTo:{anyOf:[{type:"string"},Be]},references:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}]},subject:{type:"string"},text:{anyOf:[{type:"string"},Cn]},html:{anyOf:[{type:"string"},Cn]},watchHtml:{anyOf:[{type:"string"},Cn]},amp:{anyOf:[{type:"string"},{type:"object",properties:{content:{type:"string"},path:{type:"string"},href:{type:"string"},encoding:{type:"string"},contentType:{type:"string"},raw:{anyOf:[{type:"string"},Cn]}}}]},icalEvent:{anyOf:[{type:"string"},{type:"object",properties:{content:{type:"string"},path:{type:"string"},method:{type:"string"},filename:{anyOf:[{type:"string"},{type:"boolean"}]},href:{type:"string"},encoding:{type:"string"}}}]},headers:{anyOf:[{type:"object",additionalProperties:!0},{type:"array",items:{type:"object",additionalProperties:!0}}]},list:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}]},attachments:{type:"array",items:{type:"object",properties:{content:{type:"string"},path:{type:"string"}},additionalProperties:!0}}},required:[],additionalProperties:!0},Qr={output:ua};var da={type:"object",properties:{},required:[],additionalProperties:!1},Zr={output:da};var fa={type:"object",properties:{personalizations:{type:"array",description:"An array of messages and their metadata. Each object within personalizations can be thought of as an envelope - it defines who should receive an individual message and how that message should be handled. See our [Personalizations documentation](https://sendgrid.com/docs/for-developers/sending-email/personalizations/) for examples.",uniqueItems:!1,maxItems:1e3,items:{type:"object",properties:{from:{title:"From Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The 'From' email address used to deliver the message. This address should be a verified sender in your Twilio SendGrid account."},name:{type:"string",description:"A name or title associated with the sending email address."}},required:["email"]},to:{title:"To Email Array",type:"array",items:{type:"object",properties:{email:{type:"string",format:"email",description:"The intended recipient's email address."},name:{type:"string",description:"The intended recipient's name."}},required:["email"]}},cc:{type:"array",description:"An array of recipients who will receive a copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.",maxItems:1e3,items:{title:"CC BCC Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The intended recipient's email address."},name:{type:"string",description:"The intended recipient's name."}},required:["email"]}},bcc:{type:"array",description:"An array of recipients who will receive a blind carbon copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.",maxItems:1e3,items:{title:"CC BCC Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The intended recipient's email address."},name:{type:"string",description:"The intended recipient's name."}},required:["email"]}},subject:{type:"string",description:"The subject of your email. See character length requirements according to [RFC 2822](http://stackoverflow.com/questions/1592291/what-is-the-email-subject-length-limit#answer-1592310).",minLength:1},headers:{type:"object",description:"A collection of JSON key/value pairs allowing you to specify handling instructions for your email. You may not overwrite the following headers: `x-sg-id`, `x-sg-eid`, `received`, `dkim-signature`, `Content-Type`, `Content-Transfer-Encoding`, `To`, `From`, `Subject`, `Reply-To`, `CC`, `BCC`"},substitutions:{type:"object",description:'Substitutions allow you to insert data without using Dynamic Transactional Templates. This field should **not** be used in combination with a Dynamic Transactional Template, which can be identified by a `templateId` starting with `d-`. This field is a collection of key/value pairs following the pattern "substitutionTag":"value to substitute". The key/value pairs must be strings. These substitutions will apply to the text and html content of the body of your email, in addition to the `subject` and `reply-to` parameters. The total collective size of your substitutions may not exceed 10,000 bytes per personalization object.',maxProperties:1e4},dynamicTemplateData:{type:"object",description:'Dynamic template data is available using Handlebars syntax in Dynamic Transactional Templates. This field should be used in combination with a Dynamic Transactional Template, which can be identified by a `templateId` starting with `d-`. This field is a collection of key/value pairs following the pattern "variable_name":"value to insert".'},customArgs:{type:"object",description:"Values that are specific to this personalization that will be carried along with the email and its activity data. Substitutions will not be made on custom arguments, so any string that is entered into this parameter will be assumed to be the custom argument that you would like to be used. This field may not exceed 10,000 bytes.",maxProperties:1e4},sendAt:{type:"integer",description:"A unix timestamp allowing you to specify when your email should be delivered. Scheduling delivery more than 72 hours in advance is forbidden."}},required:["to"]}},from:{title:"From Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The 'From' email address used to deliver the message. This address should be a verified sender in your Twilio SendGrid account."},name:{type:"string",description:"A name or title associated with the sending email address."}},required:["email"]},replyTo:{title:"Reply_to Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The email address where any replies or bounces will be returned."},name:{type:"string",description:"A name or title associated with the `replyTo` email address."}},required:["email"]},replyToList:{type:"array",description:"An array of recipients who will receive replies and/or bounces. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name. You can either choose to use \u201CreplyTo\u201D field or \u201CreplyToList\u201D but not both.",uniqueItems:!0,maxItems:1e3,items:{type:"object",properties:{email:{type:"string",description:"The email address where any replies or bounces will be returned.",format:"email"},name:{type:"string",description:"A name or title associated with the `replyToList` email address."}},required:["email"]}},subject:{type:"string",description:"The global or 'message level' subject of your email. This may be overridden by subject lines set in personalizations.",minLength:1},content:{type:"array",description:"An array where you can specify the content of your email. You can include multiple [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of content, but you must specify at least one MIME type. To include more than one MIME type, add another object to the array containing the `type` and `value` parameters.",items:{type:"object",properties:{type:{type:"string",description:"The MIME type of the content you are including in your email (e.g., `\u201Ctext/plain\u201D` or `\u201Ctext/html\u201D`).",minLength:1},value:{type:"string",description:"The actual content of the specified MIME type that you are including in your email.",minLength:1}},required:["type","value"]}},attachments:{type:"array",description:"An array of objects where you can specify any attachments you want to include.",items:{type:"object",properties:{content:{type:"string",description:"The Base64 encoded content of the attachment.",minLength:1},type:{type:"string",description:"The MIME type of the content you are attaching (e.g., `\u201Ctext/plain\u201D` or `\u201Ctext/html\u201D`).",minLength:1},filename:{type:"string",description:"The attachment's filename."},disposition:{type:"string",default:"attachment",description:"The attachment's content-disposition, specifying how you would like the attachment to be displayed. For example, `\u201Cinline\u201D` results in the attached file are displayed automatically within the message while `\u201Cattachment\u201D` results in the attached file require some action to be taken before it is displayed, such as opening or downloading the file.",enum:["inline","attachment"]},contentId:{type:"string",description:"The attachment's content ID. This is used when the disposition is set to `\u201Cinline\u201D` and the attachment is an image, allowing the file to be displayed within the body of your email."}},required:["content","filename"]}},templateId:{type:"string",description:"An email template ID. A template that contains a subject and content \u2014 either text or html \u2014 will override any subject and content values specified at the personalizations or message level."},headers:{description:"An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.",type:"object"},categories:{type:"array",description:"An array of category names for this message. Each category name may not exceed 255 characters. ",uniqueItems:!0,maxItems:10,items:{type:"string",maxLength:255}},customArgs:{description:"Values that are specific to the entire send that will be carried along with the email and its activity data. Key/value pairs must be strings. Substitutions will not be made on custom arguments, so any string that is entered into this parameter will be assumed to be the custom argument that you would like to be used. This parameter is overridden by `customArgs` set at the personalizations level. Total `customArgs` size may not exceed 10,000 bytes.",type:"string"},sendAt:{type:"integer",description:"A unix timestamp allowing you to specify when you want your email to be delivered. This may be overridden by the `sendAt` parameter set at the personalizations level. Delivery cannot be scheduled more than 72 hours in advance. If you have the flexibility, it's better to schedule mail for off-peak times. Most emails are scheduled and sent at the top of the hour or half hour. Scheduling email to avoid peak times \u2014 for example, scheduling at 10:53 \u2014 can result in lower deferral rates due to the reduced traffic during off-peak times."},batchId:{type:"string",description:"An ID representing a batch of emails to be sent at the same time. Including a `batchId` in your request allows you include this email in that batch. It also enables you to cancel or pause the delivery of that batch. For more information, see the [Cancel Scheduled Sends API](https://sendgrid.com/docs/api-reference/)."},asm:{type:"object",description:"An object allowing you to specify how to handle unsubscribes.",properties:{groupId:{type:"integer",description:"The unsubscribe group to associate with this email."},groupsToDisplay:{type:"array",description:"An array containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page.",maxItems:25,items:{type:"integer"}}},required:["groupId"]},ipPoolName:{type:"string",description:"The IP Pool that you would like to send this email from.",minLength:2,maxLength:64},mailSettings:{type:"object",description:"A collection of different mail settings that you can use to specify how you would like this email to be handled.",properties:{bypassListManagement:{type:"object",description:"Allows you to bypass all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient. This should only be used in emergencies when it is absolutely necessary that every recipient receives your email. This filter cannot be combined with any other bypass filters. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},bypassSpamManagement:{type:"object",description:"Allows you to bypass the spam report list to ensure that the email is delivered to recipients. Bounce and unsubscribe lists will still be checked; addresses on these other lists will not receive the message. This filter cannot be combined with the `bypassListManagement` filter. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},bypassBounceManagement:{type:"object",description:"Allows you to bypass the bounce list to ensure that the email is delivered to recipients. Spam report and unsubscribe lists will still be checked; addresses on these other lists will not receive the message. This filter cannot be combined with the `bypassListManagement` filter. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},bypassUnsubscribeManagement:{type:"object",description:"Allows you to bypass the global unsubscribe list to ensure that the email is delivered to recipients. Bounce and spam report lists will still be checked; addresses on these other lists will not receive the message. This filter applies only to global unsubscribes and will not bypass group unsubscribes. This filter cannot be combined with the `bypassListManagement` filter. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},footer:{type:"object",description:"The default footer that you would like included on every email.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},text:{type:"string",description:"The plain text content of your footer."},html:{type:"string",description:"The HTML content of your footer."}}},sandboxMode:{type:"object",description:"Sandbox Mode allows you to send a test email to ensure that your request body is valid and formatted correctly.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}}}},trackingSettings:{type:"object",description:"Settings to determine how you would like to track the metrics of how your recipients interact with your email.",properties:{clickTracking:{type:"object",description:"Allows you to track if a recipient clicked a link in your email.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},enableText:{type:"boolean",description:"Indicates if this setting should be included in the `text/plain` portion of your email."}}},openTracking:{type:"object",description:"Allows you to track if the email was opened by including a single pixel image in the body of the content. When the pixel is loaded, Twilio SendGrid can log that the email was opened.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},substitutionTag:{type:"string",description:"Allows you to specify a substitution tag that you can insert in the body of your email at a location that you desire. This tag will be replaced by the open tracking pixel."}}},subscriptionTracking:{type:"object",description:"Allows you to insert a subscription management link at the bottom of the text and HTML bodies of your email. If you would like to specify the location of the link within your email, you may use the `substitutionTag`.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},text:{type:"string",description:"Text to be appended to the email with the subscription tracking link. You may control where the link is by using the tag <% %>"},html:{type:"string",description:"HTML to be appended to the email with the subscription tracking link. You may control where the link is by using the tag <% %>"},substitutionTag:{type:"string",description:"A tag that will be replaced with the unsubscribe URL. for example: `[unsubscribe_url]`. If this parameter is used, it will override both the `text` and `html` parameters. The URL of the link will be placed at the substitution tag\u2019s location with no additional formatting."}}},ganalytics:{type:"object",description:"Allows you to enable tracking provided by Google Analytics.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},utmSource:{type:"string",description:"Name of the referrer source. (e.g. Google, SomeDomain.com, or Marketing Email)"},utmMedium:{type:"string",description:"Name of the marketing medium. (e.g. Email)"},utmTerm:{type:"string",description:"Used to identify any paid keywords."},utmContent:{type:"string",description:"Used to differentiate your campaign from advertisements."},utmCampaign:{type:"string",description:"The name of the campaign."}}}}}},required:[],additionalProperties:!1},es={output:fa};var ts={braze:B,clickatell:B,nodemailer:Qr,emailjs:B,"email-webhook":B,"infobip-email":B,mailersend:B,mailgun:zr,mailjet:Xr,mailtrap:B,mandrill:B,netcore:B,"novu-email":Zr,outlook365:B,plunk:B,postmark:B,resend:B,sendgrid:es,sendinblue:B,ses:B,sparkpost:B};var ha={type:"object",properties:{},required:[],additionalProperties:!1},ns={output:ha};var is={novu:ns};var rs={anyOf:[{type:"string"},{type:"object",additionalProperties:!0,properties:{name:{type:"string"},volume:{type:"number"},critical:{type:"number"}},required:["name","volume","critical"]}]},ma={type:"object",properties:{topic:{type:"string",description:"The destination topic for the notification."},id:{type:"string",description:"A UUID to identify the notification with APNS. If an id is not supplied, APNS will generate one automatically. If an error occurs the response will contain the id. This property populates the apns-id header."},expiry:{type:"number",description:"A UNIX timestamp when the notification should expire. If the notification cannot be delivered to the device, APNS will retry until it expires. An expiry of 0 indicates that the notification expires immediately, therefore no retries will be attempted."},priority:{type:"number",description:`Provide one of the following values:
96
+ `)}async executeProviders(n,s,l){return s.providers.reduce(async(w,M)=>{let C=await w,K=this.previewProvider.bind(this),ie=this.executeProvider.bind(this),Ie=await(n.action==="preview"?K:ie)(n,s,M,l);return{...C,[M.type]:Ie}},Promise.resolve({}))}previewProvider(n,s,l,w){return console.log(` ${Re.MOCK} Mocked provider: \`${l.type}\``),this.mock(l.outputs.schema)}async executeProvider(n,s,l,w){try{if(n.stepId===s.stepId){let M=await this.createStepControls(s,n),C=await l.resolve({controls:M,outputs:w}),K=await this.validate(C,l.outputs.unknownSchema,"step","output",n.workflowId,s.stepId,l.type);return console.log(` ${Re.SUCCESS} Executed provider: \`${l.type}\``),{...K,_passthrough:C._passthrough}}else return console.log(` ${Re.HYDRATED} Hydrated provider: \`${l.type}\``),{}}catch(M){throw console.log(` ${Re.ERROR} Failed to execute provider: \`${l.type}\``),new dn(l.type,n.action,M)}}async executeStep(n,s){if(n.stepId===s.stepId)try{let l=await this.createStepControls(s,n),w=await this.compileControls(l,n),M=await s.resolve(w),C=await this.validate(M,s.outputs.unknownSchema,"step","output",n.workflowId,s.stepId),K=await this.executeProviders(n,s,C);return console.log(` ${Re.SUCCESS} Executed stepId: \`${s.stepId}\``),{outputs:C,providers:K}}catch(l){throw console.log(` ${Re.ERROR} Failed to execute stepId: \`${s.stepId}\``),lt(l)?l:new Ct(s.stepId,n.action,l)}else try{let l=this.getStepState(n,s.stepId);if(l){let w=await this.validate(l.outputs,s.results.unknownSchema,"step","result",n.workflowId,s.stepId);return console.log(` ${Re.HYDRATED} Hydrated stepId: \`${s.stepId}\``),{outputs:w,providers:await this.executeProviders(n,s,w)}}else throw new Qt(n.workflowId,s.stepId)}catch(l){throw console.log(` ${Re.ERROR} Failed to hydrate stepId: \`${s.stepId}\``),l}}async compileControls(n,s){try{let l=this.preprocessTranslationPatterns(JSON.stringify(n));l=this.preprocessFilterTranslationArgs(l);let w=this.templateEngine.parse(l),M=this.getWorkflow(s.workflowId),C={workflow:{workflowId:M.workflowId,name:M.name,description:M.description,tags:M.tags,severity:M.severity},payload:s.payload,subscriber:s.subscriber,context:s.context,steps:ra(s.state)},K=await this.templateEngine.render(w,C),ie=this.postprocessTranslationMarkers(K),Se=(0,Gr.jsonrepair)(ie);return JSON.parse(Se)}catch(l){throw new rn(s.workflowId,s.stepId,l)}}preprocessTranslationPatterns(n){return n.replace(/\{\{\s*t\.([\p{L}\p{N}_.-]+)\s*\}\}/gu,"[T:$1]")}preprocessFilterTranslationArgs(n){return n.replace(/'t\.([\p{L}\p{N}_.-]+)'/gu,"'[T:$1]'")}postprocessTranslationMarkers(n){return n.replace(/\[T:([\p{L}\p{N}_.-]+)\]/gu,"{{t.$1}}")}async createStepControls(n,s){return await this.validate(s.controls,n.controls.unknownSchema,"step","controls",s.workflowId,n.stepId)}async previewStep(n,s){try{return await this.constructStepForPreview(n,s)}catch(l){throw console.log(` ${Re.ERROR} Failed to preview stepId: \`${s.stepId}\``),lt(l)?l:new Ct(s.stepId,n.action,l)}}async constructStepForPreview(n,s){return n.stepId===s.stepId?await this.previewRequiredStep(s,n):await this.extractMockDataForPreviousSteps(n,s)}async extractMockDataForPreviousSteps(n,s){let l={},w=this.getStepState(n,s.stepId),M=this.mock(s.results.schema);return{outputs:di(M,(w==null?void 0:w.outputs)||{}),providers:await this.executeProviders(n,s,l)}}async previewRequiredStep(n,s){let l=await this.createStepControls(n,s),w=await this.compileControls(l,s),M=await n.resolve(w),C=await this.validate(M,n.outputs.unknownSchema,"step","output",s.workflowId,n.stepId);return console.log(` ${Re.MOCK} Mocked stepId: \`${n.stepId}\``),{outputs:C,providers:await this.executeProviders(s,n,C)}}getStepState(n,s){return n.state.find(l=>l.stepId===s)}getStepCode(n,s){return{code:this.getStep(n,s).resolve.toString()}}getWorkflowCode(n){return{code:this.getWorkflow(n).execute.toString()}}getCode(n,s){let l;if(n)s?l=this.getStepCode(n,s):l=this.getWorkflowCode(n);else throw new Mt(n);return l}};function ra(f){let n={};for(let s of f)n[s.stepId]=s.outputs;return n}var St=class{constructor(n){this.handler=n.handler,this.client=n.client?n.client:new wt,this.workflows=n.workflows,this.http=Tn(this.client.secretKey,this.client.apiUrl),this.frameworkName=n.frameworkName,this.hmacEnabled=this.client.strictAuthentication}createHandler(){return async(...n)=>{await this.client.addWorkflows(this.workflows);let s=await this.handler(...n),l=await this.handleAction({actions:s});return s.transformResponse(l)}}getStaticHeaders(){let n=`novu-framework:v${this.client.version}`;return{"content-type":"application/json","access-control-allow-origin":"*","access-control-allow-private-network":"true","access-control-allow-methods":"GET, POST","access-control-allow-headers":"*","access-control-max-age":"604800","novu-framework-version":"2024-06-26","novu-framework-sdk":"2.10.0-alpha.0","novu-framework-server":this.frameworkName,"user-agent":n}}createResponse(n,s){return{status:n,body:JSON.stringify(s),headers:{...this.getStaticHeaders()}}}createError(n){return{status:n.statusCode,body:JSON.stringify({message:n.message,data:n.data,code:n.code}),headers:this.getStaticHeaders()}}async handleAction({actions:n}){let s=await n.url(),l=await n.method(),w=s.searchParams.get("action")||"health-check",M=s.searchParams.get("workflowId")||"",C=s.searchParams.get("stepId")||"",K=await n.headers("novu-signature")||"",ie={};try{l==="POST"&&(ie=await n.body())}catch{}try{w!=="health-check"&&await this.validateHmac(ie,K);let Se=this.getPostActionMap(ie,M,C,w),Ie=this.getGetActionMap(M,C);if(l==="POST")return await this.handlePostAction(w,Se);if(l==="GET")return await this.handleGetAction(w,Ie);if(l==="OPTIONS")return this.createResponse(200,{})}catch(Se){return this.handleError(Se)}return this.createError(new ln(l))}getPostActionMap(n,s,l,w){return{trigger:this.triggerAction({workflowId:s,...n}),execute:async()=>{let M=await this.client.executeWorkflow({...n,workflowId:s,stepId:l,action:w});return this.createResponse(200,M)},preview:async()=>{let M=await this.client.executeWorkflow({...n,workflowId:s,stepId:l,action:w});return this.createResponse(200,M)}}}triggerAction(n){return async()=>{let s={name:n.workflowId,to:n.to,payload:(n==null?void 0:n.payload)||{},transactionId:n.transactionId,overrides:n.overrides||{},...n.actor&&{actor:n.actor},...n.bridgeUrl&&{bridgeUrl:n.bridgeUrl},...n.controls&&{controls:n.controls},...n.context&&{context:n.context}},l=await this.http.post("/events/trigger",s);return this.createResponse(200,l)}}getGetActionMap(n,s){return{discover:async()=>{let l=await this.client.discover();return this.createResponse(200,l)},"health-check":async()=>{let l=await this.client.healthCheck();return this.createResponse(200,l)},code:async()=>{let l=await this.client.getCode(n,s);return this.createResponse(200,l)}}}async handlePostAction(n,s){if(Object.values(Pt).includes(n)){let l=s[n];return l()}else throw new Nt(n,Pt)}async handleGetAction(n,s){if(Object.values(Kt).includes(n)){let l=s[n];return l()}else throw new Nt(n,Kt)}handleError(n){if(lt(n))return n.statusCode>=500&&console.error(n),this.createError(n);if(Or(n))return this.createError(n);{let s=new mt(n);return console.error(s),this.createError(s)}}async validateHmac(n,s){if(!this.hmacEnabled)return;if(!s)throw new hn;if(!this.client.secretKey)throw new gn;let[l,w]=s.split(",");if(!l||!w)throw new mn;let[M,C]=l.split("="),[K,ie]=w.split("=");if(Number(M)<Date.now()-1500)throw new yn;if(!(await Nr(this.client.secretKey,`${C}.${JSON.stringify(n)}`)===ie))throw new fn}};var B={output:{type:"object",properties:{},required:[],additionalProperties:!0}};var oa={type:"object",properties:{webhookUrl:{type:"string",format:"uri"},text:{type:"string"},blocks:{type:"array",items:{type:"object",properties:{type:{enum:["image","context","actions","divider","section","input","file","header","video","rich_text"]}},required:["type"],additionalProperties:!0}}},additionalProperties:!0},Kr={output:oa};var Hr={"chat-webhook":B,discord:B,getstream:B,"grafana-on-call":B,mattermost:B,msteams:B,"rocket-chat":B,ryver:B,slack:Kr,"whatsapp-business":B,zulip:B};var aa={type:"object",properties:{to:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:'Email address of the recipient(s). Example: "Bob bob@host.com". You can use commas to separate multiple recipients (e.g.: "test@example.com,test@example.com" or ["test@example.com", "test@example.com"]).'},from:{type:"string"},subject:{type:"string",description:"Subject of the message."},text:{type:"string",description:"Text version of the message."},html:{type:"string",description:"HTML version of the message."},message:{type:"string",description:"MIME string of the message. Make sure to use multipart/form-data to send this as a file upload."},cc:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"Same as To but for carbon copy"},bcc:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"Same as To but for blind carbon copy"},ampHtml:{type:"string"},tVersion:{type:"string"},tText:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}]},oTag:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}],description:"Tag string. See Tagging for more information."},oDkim:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Enables/disabled DKIM signatures on per-message basis. Pass yes or no"},oDeliverytime:{type:"string",description:"Desired time of delivery. See Date Format. Note: Messages can be scheduled for a maximum of 3 days in the future."},oDeliverytimeOptimizePeriod:{type:"string"},oTimeZoneLocalize:{type:"string"},oTestmode:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Enables sending in test mode. Pass yes if needed. See Sending in Test Mode"},oTracking:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Toggles tracking on a per-message basis, see Tracking Messages for details. Pass yes or no."},oTrackingClicks:{anyOf:[{type:"string",enum:["yes","no","htmlonly"]},{type:"boolean"}],description:"Toggles clicks tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes, no or htmlonly."},oTrackingOpens:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}],description:"Toggles opens tracking on a per-message basis. Has higher priority than domain-level setting. Pass yes or no."},oRequireTls:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}]},oSkipVerification:{anyOf:[{type:"string",enum:["yes","no"]},{type:"boolean"}]},recipientVariables:{type:"string"}},required:[],additionalProperties:!0},zr={output:aa};var ut={type:"object",properties:{name:{type:"string"},email:{type:"string"}},description:'JSON object, containing 2 properties: Name and Email address of a previously validated and active sender. Including the Name property in the JSON is optional. This property is not mandatory in case you use TemplateID and you specified a From address for the template. Format : { "Email":"value", "Name":"value" }.',required:["Email"],additionalProperties:!0},la={type:"object",properties:{contentType:{type:"string"},filename:{type:"string"},base64Content:{type:"string"}},required:["ContentType","Filename","Base64Content"],additionalProperties:!0},ca={type:"object",properties:{filename:{type:"string"},contentType:{type:"string"},contentId:{type:"string"},base64Content:{type:"string"}},required:["ContentType","Filename","Base64Content"],additionalProperties:!0},pa={type:"object",properties:{from:ut,sender:ut,to:{type:"array",items:ut},cc:{type:"array",items:ut},bcc:{type:"array",items:ut},replyTo:ut,subject:{type:"string"},textPart:{type:"string",description:"Content of the message, sent in Text and/or HTML format. At least one of these content types needs to be specified. When the HTML part is the only part provided, Mailjet will not generate a Text-part from the HTML version. The property can't be set when you use TemplateID"},htmlPart:{type:"string",description:"Content of the message, sent in Text and/or HTML format. At least one of these content types needs to be specified. When the HTML part is the only part provided, Mailjet will not generate a Text-part from the HTML version. The property can't be set when you use TemplateID"},templateId:{type:"number",description:"an ID for a template that is previously created and stored in Mailjet's system. It is mandatory when From and TextPart and/or HtmlPart are not provided. "},templateLanguage:{type:"boolean"},templateErrorReporting:ut,templateErrorDeliver:{type:"boolean"},attachments:{type:"array",items:la},inlineAttachments:{type:"array",items:ca},priority:{type:"number"},customCampaign:{type:"string"},deduplicateCampaign:{type:"boolean"},trackOpens:{type:"string",enum:["account_default","disabled","enabled"]},trackClicks:{type:"string",enum:["account_default","disabled","enabled"]},customId:{type:"string"},eventPayload:{type:"string"},urlTags:{type:"string"},headers:{type:"object",additionalProperties:!0},variables:{type:"object",additionalProperties:!0}},required:[],additionalProperties:!0},Xr={output:pa};var Be={type:"object",properties:{address:{type:"string"},name:{type:"string"}},additionalProperties:!0},Cn={type:"object",properties:{content:{type:"string"},path:{type:"string"}},additionalProperties:!0},ua={type:"object",properties:{from:{anyOf:[{type:"string"},Be]},sender:{anyOf:[{type:"string"},Be]},to:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},cc:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},bcc:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},replyTo:{anyOf:[{type:"string"},Be,{type:"array",items:Be}]},inReplyTo:{anyOf:[{type:"string"},Be]},references:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}]},subject:{type:"string"},text:{anyOf:[{type:"string"},Cn]},html:{anyOf:[{type:"string"},Cn]},watchHtml:{anyOf:[{type:"string"},Cn]},amp:{anyOf:[{type:"string"},{type:"object",properties:{content:{type:"string"},path:{type:"string"},href:{type:"string"},encoding:{type:"string"},contentType:{type:"string"},raw:{anyOf:[{type:"string"},Cn]}}}]},icalEvent:{anyOf:[{type:"string"},{type:"object",properties:{content:{type:"string"},path:{type:"string"},method:{type:"string"},filename:{anyOf:[{type:"string"},{type:"boolean"}]},href:{type:"string"},encoding:{type:"string"}}}]},headers:{anyOf:[{type:"object",additionalProperties:!0},{type:"array",items:{type:"object",additionalProperties:!0}}]},list:{anyOf:[{type:"string"},{type:"array",items:{type:"string"}}]},attachments:{type:"array",items:{type:"object",properties:{content:{type:"string"},path:{type:"string"}},additionalProperties:!0}}},required:[],additionalProperties:!0},Qr={output:ua};var da={type:"object",properties:{},required:[],additionalProperties:!1},Zr={output:da};var fa={type:"object",properties:{personalizations:{type:"array",description:"An array of messages and their metadata. Each object within personalizations can be thought of as an envelope - it defines who should receive an individual message and how that message should be handled. See our [Personalizations documentation](https://sendgrid.com/docs/for-developers/sending-email/personalizations/) for examples.",uniqueItems:!1,maxItems:1e3,items:{type:"object",properties:{from:{title:"From Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The 'From' email address used to deliver the message. This address should be a verified sender in your Twilio SendGrid account."},name:{type:"string",description:"A name or title associated with the sending email address."}},required:["email"]},to:{title:"To Email Array",type:"array",items:{type:"object",properties:{email:{type:"string",format:"email",description:"The intended recipient's email address."},name:{type:"string",description:"The intended recipient's name."}},required:["email"]}},cc:{type:"array",description:"An array of recipients who will receive a copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.",maxItems:1e3,items:{title:"CC BCC Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The intended recipient's email address."},name:{type:"string",description:"The intended recipient's name."}},required:["email"]}},bcc:{type:"array",description:"An array of recipients who will receive a blind carbon copy of your email. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name.",maxItems:1e3,items:{title:"CC BCC Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The intended recipient's email address."},name:{type:"string",description:"The intended recipient's name."}},required:["email"]}},subject:{type:"string",description:"The subject of your email. See character length requirements according to [RFC 2822](http://stackoverflow.com/questions/1592291/what-is-the-email-subject-length-limit#answer-1592310).",minLength:1},headers:{type:"object",description:"A collection of JSON key/value pairs allowing you to specify handling instructions for your email. You may not overwrite the following headers: `x-sg-id`, `x-sg-eid`, `received`, `dkim-signature`, `Content-Type`, `Content-Transfer-Encoding`, `To`, `From`, `Subject`, `Reply-To`, `CC`, `BCC`"},substitutions:{type:"object",description:'Substitutions allow you to insert data without using Dynamic Transactional Templates. This field should **not** be used in combination with a Dynamic Transactional Template, which can be identified by a `templateId` starting with `d-`. This field is a collection of key/value pairs following the pattern "substitutionTag":"value to substitute". The key/value pairs must be strings. These substitutions will apply to the text and html content of the body of your email, in addition to the `subject` and `reply-to` parameters. The total collective size of your substitutions may not exceed 10,000 bytes per personalization object.',maxProperties:1e4},dynamicTemplateData:{type:"object",description:'Dynamic template data is available using Handlebars syntax in Dynamic Transactional Templates. This field should be used in combination with a Dynamic Transactional Template, which can be identified by a `templateId` starting with `d-`. This field is a collection of key/value pairs following the pattern "variable_name":"value to insert".'},customArgs:{type:"object",description:"Values that are specific to this personalization that will be carried along with the email and its activity data. Substitutions will not be made on custom arguments, so any string that is entered into this parameter will be assumed to be the custom argument that you would like to be used. This field may not exceed 10,000 bytes.",maxProperties:1e4},sendAt:{type:"integer",description:"A unix timestamp allowing you to specify when your email should be delivered. Scheduling delivery more than 72 hours in advance is forbidden."}},required:["to"]}},from:{title:"From Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The 'From' email address used to deliver the message. This address should be a verified sender in your Twilio SendGrid account."},name:{type:"string",description:"A name or title associated with the sending email address."}},required:["email"]},replyTo:{title:"Reply_to Email Object",type:"object",properties:{email:{type:"string",format:"email",description:"The email address where any replies or bounces will be returned."},name:{type:"string",description:"A name or title associated with the `replyTo` email address."}},required:["email"]},replyToList:{type:"array",description:"An array of recipients who will receive replies and/or bounces. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name. You can either choose to use \u201CreplyTo\u201D field or \u201CreplyToList\u201D but not both.",uniqueItems:!0,maxItems:1e3,items:{type:"object",properties:{email:{type:"string",description:"The email address where any replies or bounces will be returned.",format:"email"},name:{type:"string",description:"A name or title associated with the `replyToList` email address."}},required:["email"]}},subject:{type:"string",description:"The global or 'message level' subject of your email. This may be overridden by subject lines set in personalizations.",minLength:1},content:{type:"array",description:"An array where you can specify the content of your email. You can include multiple [MIME types](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of content, but you must specify at least one MIME type. To include more than one MIME type, add another object to the array containing the `type` and `value` parameters.",items:{type:"object",properties:{type:{type:"string",description:"The MIME type of the content you are including in your email (e.g., `\u201Ctext/plain\u201D` or `\u201Ctext/html\u201D`).",minLength:1},value:{type:"string",description:"The actual content of the specified MIME type that you are including in your email.",minLength:1}},required:["type","value"]}},attachments:{type:"array",description:"An array of objects where you can specify any attachments you want to include.",items:{type:"object",properties:{content:{type:"string",description:"The Base64 encoded content of the attachment.",minLength:1},type:{type:"string",description:"The MIME type of the content you are attaching (e.g., `\u201Ctext/plain\u201D` or `\u201Ctext/html\u201D`).",minLength:1},filename:{type:"string",description:"The attachment's filename."},disposition:{type:"string",default:"attachment",description:"The attachment's content-disposition, specifying how you would like the attachment to be displayed. For example, `\u201Cinline\u201D` results in the attached file are displayed automatically within the message while `\u201Cattachment\u201D` results in the attached file require some action to be taken before it is displayed, such as opening or downloading the file.",enum:["inline","attachment"]},contentId:{type:"string",description:"The attachment's content ID. This is used when the disposition is set to `\u201Cinline\u201D` and the attachment is an image, allowing the file to be displayed within the body of your email."}},required:["content","filename"]}},templateId:{type:"string",description:"An email template ID. A template that contains a subject and content \u2014 either text or html \u2014 will override any subject and content values specified at the personalizations or message level."},headers:{description:"An object containing key/value pairs of header names and the value to substitute for them. The key/value pairs must be strings. You must ensure these are properly encoded if they contain unicode characters. These headers cannot be one of the reserved headers.",type:"object"},categories:{type:"array",description:"An array of category names for this message. Each category name may not exceed 255 characters. ",uniqueItems:!0,maxItems:10,items:{type:"string",maxLength:255}},customArgs:{description:"Values that are specific to the entire send that will be carried along with the email and its activity data. Key/value pairs must be strings. Substitutions will not be made on custom arguments, so any string that is entered into this parameter will be assumed to be the custom argument that you would like to be used. This parameter is overridden by `customArgs` set at the personalizations level. Total `customArgs` size may not exceed 10,000 bytes.",type:"string"},sendAt:{type:"integer",description:"A unix timestamp allowing you to specify when you want your email to be delivered. This may be overridden by the `sendAt` parameter set at the personalizations level. Delivery cannot be scheduled more than 72 hours in advance. If you have the flexibility, it's better to schedule mail for off-peak times. Most emails are scheduled and sent at the top of the hour or half hour. Scheduling email to avoid peak times \u2014 for example, scheduling at 10:53 \u2014 can result in lower deferral rates due to the reduced traffic during off-peak times."},batchId:{type:"string",description:"An ID representing a batch of emails to be sent at the same time. Including a `batchId` in your request allows you include this email in that batch. It also enables you to cancel or pause the delivery of that batch. For more information, see the [Cancel Scheduled Sends API](https://sendgrid.com/docs/api-reference/)."},asm:{type:"object",description:"An object allowing you to specify how to handle unsubscribes.",properties:{groupId:{type:"integer",description:"The unsubscribe group to associate with this email."},groupsToDisplay:{type:"array",description:"An array containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page.",maxItems:25,items:{type:"integer"}}},required:["groupId"]},ipPoolName:{type:"string",description:"The IP Pool that you would like to send this email from.",minLength:2,maxLength:64},mailSettings:{type:"object",description:"A collection of different mail settings that you can use to specify how you would like this email to be handled.",properties:{bypassListManagement:{type:"object",description:"Allows you to bypass all unsubscribe groups and suppressions to ensure that the email is delivered to every single recipient. This should only be used in emergencies when it is absolutely necessary that every recipient receives your email. This filter cannot be combined with any other bypass filters. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},bypassSpamManagement:{type:"object",description:"Allows you to bypass the spam report list to ensure that the email is delivered to recipients. Bounce and unsubscribe lists will still be checked; addresses on these other lists will not receive the message. This filter cannot be combined with the `bypassListManagement` filter. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},bypassBounceManagement:{type:"object",description:"Allows you to bypass the bounce list to ensure that the email is delivered to recipients. Spam report and unsubscribe lists will still be checked; addresses on these other lists will not receive the message. This filter cannot be combined with the `bypassListManagement` filter. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},bypassUnsubscribeManagement:{type:"object",description:"Allows you to bypass the global unsubscribe list to ensure that the email is delivered to recipients. Bounce and spam report lists will still be checked; addresses on these other lists will not receive the message. This filter applies only to global unsubscribes and will not bypass group unsubscribes. This filter cannot be combined with the `bypassListManagement` filter. See our [documentation](https://sendgrid.com/docs/ui/sending-email/index-suppressions/#bypass-suppressions) for more about bypass filters.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}},footer:{type:"object",description:"The default footer that you would like included on every email.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},text:{type:"string",description:"The plain text content of your footer."},html:{type:"string",description:"The HTML content of your footer."}}},sandboxMode:{type:"object",description:"Sandbox Mode allows you to send a test email to ensure that your request body is valid and formatted correctly.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."}}}}},trackingSettings:{type:"object",description:"Settings to determine how you would like to track the metrics of how your recipients interact with your email.",properties:{clickTracking:{type:"object",description:"Allows you to track if a recipient clicked a link in your email.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},enableText:{type:"boolean",description:"Indicates if this setting should be included in the `text/plain` portion of your email."}}},openTracking:{type:"object",description:"Allows you to track if the email was opened by including a single pixel image in the body of the content. When the pixel is loaded, Twilio SendGrid can log that the email was opened.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},substitutionTag:{type:"string",description:"Allows you to specify a substitution tag that you can insert in the body of your email at a location that you desire. This tag will be replaced by the open tracking pixel."}}},subscriptionTracking:{type:"object",description:"Allows you to insert a subscription management link at the bottom of the text and HTML bodies of your email. If you would like to specify the location of the link within your email, you may use the `substitutionTag`.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},text:{type:"string",description:"Text to be appended to the email with the subscription tracking link. You may control where the link is by using the tag <% %>"},html:{type:"string",description:"HTML to be appended to the email with the subscription tracking link. You may control where the link is by using the tag <% %>"},substitutionTag:{type:"string",description:"A tag that will be replaced with the unsubscribe URL. for example: `[unsubscribe_url]`. If this parameter is used, it will override both the `text` and `html` parameters. The URL of the link will be placed at the substitution tag\u2019s location with no additional formatting."}}},ganalytics:{type:"object",description:"Allows you to enable tracking provided by Google Analytics.",properties:{enable:{type:"boolean",description:"Indicates if this setting is enabled."},utmSource:{type:"string",description:"Name of the referrer source. (e.g. Google, SomeDomain.com, or Marketing Email)"},utmMedium:{type:"string",description:"Name of the marketing medium. (e.g. Email)"},utmTerm:{type:"string",description:"Used to identify any paid keywords."},utmContent:{type:"string",description:"Used to differentiate your campaign from advertisements."},utmCampaign:{type:"string",description:"The name of the campaign."}}}}}},required:[],additionalProperties:!1},es={output:fa};var ts={braze:B,clickatell:B,nodemailer:Qr,emailjs:B,"email-webhook":B,"infobip-email":B,mailersend:B,mailgun:zr,mailjet:Xr,mailtrap:B,mandrill:B,netcore:B,"novu-email":Zr,outlook365:B,plunk:B,postmark:B,resend:B,sendgrid:es,sendinblue:B,ses:B,sparkpost:B};var ha={type:"object",properties:{},required:[],additionalProperties:!1},ns={output:ha};var is={novu:ns};var rs={anyOf:[{type:"string"},{type:"object",additionalProperties:!0,properties:{name:{type:"string"},volume:{type:"number"},critical:{type:"number"}},required:["name","volume","critical"]}]},ma={type:"object",properties:{topic:{type:"string",description:"The destination topic for the notification."},id:{type:"string",description:"A UUID to identify the notification with APNS. If an id is not supplied, APNS will generate one automatically. If an error occurs the response will contain the id. This property populates the apns-id header."},expiry:{type:"number",description:"A UNIX timestamp when the notification should expire. If the notification cannot be delivered to the device, APNS will retry until it expires. An expiry of 0 indicates that the notification expires immediately, therefore no retries will be attempted."},priority:{type:"number",description:`Provide one of the following values:
97
97
 
98
98
  10 - The push notification is sent to the device immediately. (Default)
99
99
  The push notification must trigger an alert, sound, or badge on the device. It is an error to use this priority for a push notification that contains only the content-available key.