@novu/framework
Version:
The Code-First Notifications Workflow SDK.
2 lines (1 loc) • 11.9 kB
JavaScript
import{d as w,g as m,i as C,q as A,r as P,s as i,t as y,u as x,v as k}from"./chunk-LPE4ME2M.js";var N=class extends x{constructor(t){super("Unknown BridgeError",{cause:t});this.statusCode=500;this.code="BridgeError"}};var U=class extends i{constructor(t,n){super(`Workflow with id: \`${t}\` has a corrupt state. Step with id: \`${n}\` does not exist. Please provide the missing state.`);this.code="ExecutionStateCorruptError";this.data={workflowId:t,stepId:n}}},v=class extends i{constructor(t,n){super(`Workflow with id: \`${t}\` has invalid \`payload\`. Please provide the correct event payload.`);this.code="ExecutionEventPayloadInvalidError";this.data=n}},I=class extends i{constructor(t,n){super(`Workflow with id: \`${t}\` has invalid \`controls\`. Please provide the correct event controls.`);this.code="ExecutionEventControlInvalidError";this.data=n}},D=class extends i{constructor(t,n,r){super(`Workflow with id: \`${t}\` has an invalid state. Step with id: \`${n}\` has invalid \`controls\`. Please provide the correct step controls.`);this.code="ExecutionStateControlInvalidError";this.data=r}},F=class extends i{constructor(t,n,r){super(`Workflow with id: \`${t}\` has an invalid state. Step with id: \`${n}\` has invalid output. Please provide the correct step output.`);this.code="ExecutionStateOutputInvalidError";this.data=r}},$=class extends i{constructor(t,n,r){super(`Workflow with id: \`${t}\` has an invalid state. Step with id: \`${n}\` has invalid result. Please provide the correct step result.`);this.code="ExecutionStateResultInvalidError";this.data=r}},L=class extends i{constructor(t,n,r){super(`Workflow with id: \`${t}\` has invalid controls syntax in step with id: \`${n}\`. Please correct step control syntax.`);this.code="StepControlCompilationFailedError";this.data=r}},j=class extends i{constructor(t,n,r,p){super(`Workflow with id: \`${t}\` has an invalid state. Step with id: \`${n}\` and provider with id: \`${r}\` has invalid output. Please provide the correct provider output.`);this.code="ExecutionProviderOutputInvalidError";this.data=p}},W=class extends i{constructor(t,n){super(`Workflow with id: \`${t}\` has invalid \`payload\`. Please provide the correct payload.`);this.code="WorkflowPayloadInvalidError";this.data=n}};var q=e=>Object.values(m).includes(e==null?void 0:e.code),Me=e=>!q(e)&&typeof e.statusCode=="number"&&e.statusCode>=400&&e.statusCode<500;var E=e=>Object.values(e).map(o=>`\`${o}\``).join(", "),O=e=>e.replaceAll(/(\w)(\w*)/g,(o,t,n)=>t.toUpperCase()+n.toLowerCase()).replaceAll(/[\s-]+/g,"");var V=class extends A{constructor(){super(...arguments);this.code="MethodNotAllowedError";this.statusCode=405;this.message=`Method not allowed. Please use one of ${E(C)}`}},G=class extends i{constructor(t,n){super(`Invalid query string: \`action\`=\`${t}\`. Please use one of ${E(n)}`);this.code="InvalidActionError"}},K=class extends i{constructor(){super("Missing secret key. Set the `NOVU_SECRET_KEY` environment variable or pass `secretKey` to the client options.");this.code="MissingSecretKeyError"}};var M=class extends Error{constructor(o,t,n){super(),this.data={message:n},this.statusCode=o,this.code=t}};var f=class extends k{constructor(o,t){super(`${O(o)} with id: \`${t}\` already exists. Please use a different id.`)}},l=class extends P{constructor(o,t){super(`${O(o)} with id: \`${t}\` does not exist. Please provide a valid id.`)}},g=class extends x{constructor(t,n,r,p){super(`Failed to ${r} ${O(t)} with id: \`${n}\``,{cause:p});this.statusCode=502}};var H=class extends l{constructor(t){super("provider",t);this.code="ProviderNotFoundError"}},J=class extends g{constructor(t,n,r){super("provider",t,n,r);this.code="ProviderExecutionFailedError"}};var Y=class extends y{constructor(){super("Signature does not match the expected signature. Please ensure the signature provided in the `novu-signature` header is correct and try again.");this.code="SignatureMismatchError"}},z=class extends y{constructor(){super("Signature not found. Please provide a signature in the `novu-signature` header");this.code="SignatureNotFoundError"}},Q=class extends y{constructor(){super("Signature is invalid. Please provide a valid signature in the `novu-signature` header");this.code="SignatureInvalidError"}},B=class extends y{constructor(){super(`Signature expired. Please provide a signature with a timestamp no older than ${5} minutes in the \`novu-signature\` header`);this.code="SignatureExpiredError"}},Z=class extends y{constructor(){super("Signature key not found. Please provide a valid key in the Client constructor `config.secretKey`");this.code="SigningKeyNotFoundError"}},ee=class extends y{constructor(){super("Signature version is invalid. Please provide a signature version with version `v1` in the `novu-signature` header");this.code="SignatureVersionInvalidError"}};var te=class extends l{constructor(t){super("step",t);this.code="StepNotFoundError"}},oe=class extends f{constructor(t){super("step",t);this.code="StepAlreadyExistsError"}},re=class extends g{constructor(t,n,r){super("step",t,n,r);this.code="StepExecutionFailedError"}};var ne=class extends l{constructor(t){super("workflow",t);this.code="WorkflowNotFoundError"}},se=class extends f{constructor(t){super("workflow",t);this.code="WorkflowAlreadyExistsError"}};function Te(e,o){let t={...e};for(let n of Object.keys(o)){let r=o[n];r&&typeof r=="object"&&!Array.isArray(r)?t[n]=Te(t[n]||{},r):(Array.isArray(r),t[n]=r)}return t}function T(e,o){let t=o.split(".").reduce((n,r)=>{if(n&&typeof n=="object")return n[r]},e);if(t==null)return"";if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean")return String(t);if(typeof t=="object"){let n=JSON.stringify(t);return n==="{}"?"":n}return""}function ae(e,o=2,t,n=", "){if(!Array.isArray(e)||e.length===0)return"";let r=t?e.map(s=>typeof s!="object"||!s?"":T(s,t)):e;if(r.length===1)return r[0];if(r.length===2)return`${r[0]} and ${r[1]}`;if(r.length===3&&o>=3)return`${r[0]}, ${n}${r[1]} and ${r[2]}`;let p=r.slice(0,o),d=r.length-o;return`${p.join(n)} and ${d} ${d===1?"other":"others"}`}import Ee from"pluralize";function pe(e,o="",t="",n="true"){if(e==null)return"";let r=0;if(Array.isArray(e)?r=e.length:typeof e=="object"?r=Object.keys(e).length:typeof e=="string"?r=+e:typeof e=="number"?r=e:r=Number(e),Number.isNaN(r)&&(r=0),r<=0)return"";let p;return t?p=r===1?o:t:p=Ee(o,r),n==="true"?`${r} ${p}`:p}import{TokenKind as ie}from"liquidjs";import _e from"pluralize";import{z as h}from"zod";var ce="",me=2,de="other",le=", ",he=" and ",Se=", and ",ue={0:"keyPath",1:"limit",2:"overflowSuffix",3:"wordsConnector",4:"twoWordsConnector",5:"lastWordConnector"};function ye(e,o=ce,t=me,n=de,r=le,p=he,d=Se){if(!Array.isArray(e)||e.length===0)return"";let s=o?e.map(c=>typeof c!="object"||!c?"":T(c,o)):e,u=s.length;if(u===1)return s[0];if(u===2)return`${s[0]}${p}${s[1]}`;if(t>=u){let c=s.slice(0,u-1),_=s[u-1];return`${c.join(r)}${d}${_}`}let a=s.slice(0,t),S=u-t,R=t===1?p:d;return`${a.join(r)}${R}${S} ${_e(n,S)}`}function Vt(e={},...o){let{requireKeyPath:t=!1}=e,n=[];if(o.length<1)return n.push({message:"Expected at least 1 argument",begin:0,end:0,value:""}),n;let r=h.object({keyPath:t?h.string().min(1,"must be non-empty"):h.string().optional().default(ce),limit:h.number().optional().default(me).refine(s=>s>=0,"must be greater than or equal to 0"),overflowSuffix:h.string().optional().default(de),wordsConnector:h.string().optional().default(le),twoWordsConnector:h.string().optional().default(he),lastWordConnector:h.string().optional().default(Se)}),p={};o.forEach((s,u)=>{if(!Array.isArray(s)){let a=s.getText();(s.kind===ie.Quoted||s.kind===ie.Number)&&(a=s.content);let S=ue[u];p[S]=a}});let d=r.safeParse(p);if(!d.success)for(let s of d.error.issues){let u="string";"type"in s&&(u=s.type);let a=s.path[0],S=Object.entries(ue).find(([_,Oe])=>Oe===a),R=S?parseInt(S[0],10):null,c=typeof R=="number"?o[R]:null;c&&!Array.isArray(c)&&n.push({message:`"toSentence" expects a ${u}${s.message?` that ${s.message}`:""} for argument "${a}"`,begin:c.begin,end:c.end,value:c.getText()})}return n}import{Liquid as we}from"liquidjs";function Ce(e){return Array.isArray(e)||typeof e=="object"&&e!==null?fe(e):typeof e=="string"?e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t"):e==null?"":String(e)}var fe=(e,o=0)=>Array.isArray(e)||typeof e=="object"&&e!==null?JSON.stringify(e,null,o).replace(/"/g,"'").replace(/\n/g,"\\n"):e==null?"":String(e);function Yt(e){let o=new we({outputEscape:Ce,...e});return o.registerFilter("json",(t,n)=>fe(t,n)),o.registerFilter("digest",ae),o.registerFilter("toSentence",ye),o.registerFilter("pluralize",pe),o}var Ae={type:"object",properties:{type:{enum:["regular"]},amount:{type:"number"},unit:{type:"string",enum:["seconds","minutes","hours","days","weeks","months"]},extendToSchedule:{type:"boolean"}},required:["amount","unit"],additionalProperties:!1},Pe={type:"object",properties:{type:{enum:["timed"]},cron:{type:"string"},extendToSchedule:{type:"boolean"}},required:["cron"],additionalProperties:!1},ke={type:"object",properties:{type:{enum:["dynamic"]},dynamicKey:{type:"string"},extendToSchedule:{type:"boolean"}},required:["dynamicKey"],additionalProperties:!1},Ne={oneOf:[Ae,Pe,ke]},be={type:"object",properties:{duration:{type:"number"}},required:["duration"],additionalProperties:!1},ge={output:Ne,result:be};var Ue={type:"object",properties:{type:{enum:["regular"]},amount:{type:"number"},unit:{type:"string",enum:["seconds","minutes","hours","days","weeks","months"]},digestKey:{type:"string"},lookBackWindow:{type:"object",properties:{amount:{type:"number"},unit:{type:"string",enum:["seconds","minutes","hours","days","weeks","months"]}},required:["amount","unit"],additionalProperties:!1},extendToSchedule:{type:"boolean"}},required:["amount","unit"],additionalProperties:!1},ve={type:"object",properties:{type:{enum:["timed"]},cron:{type:"string"},digestKey:{type:"string"},extendToSchedule:{type:"boolean"}},required:["cron"],additionalProperties:!1},Ie={oneOf:[Ue,ve]},De={type:"object",properties:{eventCount:{type:"number"},events:{type:"array",items:{type:"object",properties:{id:{type:"string"},time:{type:"string"},payload:{type:"object"}},required:["id","time","payload"],additionalProperties:!1}}},required:["events"],additionalProperties:!1},Re={output:Ie,result:De};var xe={output:{type:"object",properties:{type:{type:"string",enum:["fixed","dynamic"]},amount:{type:"number"},unit:{type:"string",enum:["minutes","hours","days"]},dynamicKey:{type:"string"},threshold:{type:"number"},throttleKey:{type:"string"}},required:["type"],additionalProperties:!1},result:{type:"object",properties:{throttled:{type:"boolean",description:"Whether the workflow execution was throttled"},executionCount:{type:"number",description:"Number of executions within the throttle window"},threshold:{type:"number",description:"The throttle threshold that was applied"},windowStart:{type:"string",format:"date-time",description:"Start time of the throttle window"}},required:["throttled"],additionalProperties:!1}};var ro={delay:ge,digest:Re,throttle:xe};var so={type:"object",properties:{},required:[],additionalProperties:!1};var Fe=(a=>(a.PENDING="pending",a.QUEUED="queued",a.RUNNING="running",a.COMPLETED="completed",a.FAILED="failed",a.DELAYED="delayed",a.CANCELED="canceled",a.MERGED="merged",a.SKIPPED="skipped",a))(Fe||{});var $e=(r=>(r.NONE="none",r.LOW="low",r.MEDIUM="medium",r.HIGH="high",r))($e||{});export{N as a,U as b,v as c,I as d,D as e,F as f,$ as g,L as h,j as i,W as j,q as k,Me as l,V as m,G as n,K as o,M as p,f as q,l as r,g as s,H as t,J as u,Y as v,z as w,Q as x,B as y,Z as z,ee as A,te as B,oe as C,re as D,ne as E,se as F,Te as G,ae as H,pe as I,ye as J,Vt as K,Yt as L,ge as M,Re as N,xe as O,ro as P,so as Q,Fe as R,$e as S};