@novu/framework 2.1.0 → 2.2.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.
- package/dist/{handler-8vDLpUDh.d.ts → handler-TDgxEYp-.d.ts} +2689 -2665
- package/dist/index.d.ts +2 -2
- package/dist/index.js +22 -20
- package/dist/servers/express.d.ts +1 -1
- package/dist/servers/express.js +6 -6
- package/dist/servers/h3.d.ts +1 -1
- package/dist/servers/h3.js +4 -4
- package/dist/servers/lambda.d.ts +1 -1
- package/dist/servers/lambda.js +5 -5
- package/dist/servers/nest.d.ts +115 -0
- package/dist/servers/nest.js +34 -0
- package/dist/servers/next.d.ts +1 -1
- package/dist/servers/next.js +3 -3
- package/dist/servers/nuxt.d.ts +1 -1
- package/dist/servers/nuxt.js +2 -2
- package/dist/servers/remix.d.ts +1 -1
- package/dist/servers/remix.js +2 -2
- package/dist/servers/sveltekit.d.ts +1 -1
- package/dist/servers/sveltekit.js +2 -2
- package/package.json +16 -4
|
@@ -20,11 +20,11 @@ var we__default = /*#__PURE__*/_interopDefault(we);
|
|
|
20
20
|
var Ve__default = /*#__PURE__*/_interopDefault(Ve);
|
|
21
21
|
var Ye__default = /*#__PURE__*/_interopDefault(Ye);
|
|
22
22
|
|
|
23
|
-
var D=(r=>(r.TRIGGER="trigger",r.EXECUTE="execute",r.PREVIEW="preview",r))(D||{}),V=(r=>(r.DISCOVER="discover",r.HEALTH_CHECK="health-check",r.CODE="code",r))(V||{});var O=(d=>(d.WORKFLOW_NOT_FOUND_ERROR="WorkflowNotFoundError",d.WORKFLOW_ALREADY_EXISTS_ERROR="WorkflowAlreadyExistsError",d.WORKFLOW_EXECUTION_FAILED_ERROR="WorkflowExecutionFailedError",d.EXECUTION_STATE_OUTPUT_INVALID_ERROR="ExecutionStateOutputInvalidError",d.EXECUTION_STATE_RESULT_INVALID_ERROR="ExecutionStateResultInvalidError",d.EXECUTION_PROVIDER_OUTPUT_INVALID_ERROR="ExecutionProviderOutputInvalidError",d.PROVIDER_NOT_FOUND_ERROR="ProviderNotFoundError",d.PROVIDER_EXECUTION_FAILED_ERROR="ProviderExecutionFailedError",d.STEP_NOT_FOUND_ERROR="StepNotFoundError",d.STEP_ALREADY_EXISTS_ERROR="StepAlreadyExistsError",d.STEP_EXECUTION_FAILED_ERROR="StepExecutionFailedError",d.EXECUTION_STATE_CORRUPT_ERROR="ExecutionStateCorruptError",d.EXECUTION_EVENT_PAYLOAD_INVALID_ERROR="ExecutionEventPayloadInvalidError",d.EXECUTION_EVENT_CONTROL_INVALID_ERROR="ExecutionEventControlInvalidError",d.EXECUTION_STATE_CONTROL_INVALID_ERROR="ExecutionStateControlInvalidError",d.STEP_CONTROL_COMPILATION_FAILED_ERROR="StepControlCompilationFailedError",d.METHOD_NOT_ALLOWED_ERROR="MethodNotAllowedError",d.INVALID_ACTION_ERROR="InvalidActionError",d.MISSING_SECRET_KEY_ERROR="MissingSecretKeyError",d.SIGNATURE_MISMATCH_ERROR="SignatureMismatchError",d.SIGNATURE_NOT_FOUND_ERROR="SignatureNotFoundError",d.SIGNATURE_INVALID_ERROR="SignatureInvalidError",d.SIGNATURE_EXPIRED_ERROR="SignatureExpiredError",d.SIGNING_KEY_NOT_FOUND_ERROR="SigningKeyNotFoundError",d.BRIDGE_ERROR="BridgeError",d.SIGNATURE_VERSION_INVALID_ERROR="SignatureVersionInvalidError",d.WORKFLOW_PAYLOAD_INVALID_ERROR="WorkflowPayloadInvalidError",d))(O||{});var Y=(r=>(r.POST="POST",r.GET="GET",r.OPTIONS="OPTIONS",r))(Y||{});var Re=(i=>(i.EMAIL="email",i.SMS="sms",i.PUSH="push",i.CHAT="chat",i.IN_APP="in_app",i))(Re||{});var Te="2.1.0";var P=Te,F="2024-06-26";var E=class extends Error{data},b=class extends E{statusCode=404},R=class extends E{statusCode=400},m=class extends E{statusCode=401},f=class extends E{statusCode=500},L=class extends E{statusCode=409};var C=class extends R{code="ExecutionStateCorruptError";constructor(e,t){super(`Workflow with id: \`${e}\` has a corrupt state. Step with id: \`${t}\` does not exist. Please provide the missing state.`),this.data={workflowId:e,stepId:t};}},y=class extends R{code="ExecutionEventPayloadInvalidError";constructor(e,t){super(`Workflow with id: \`${e}\` has invalid \`payload\`. Please provide the correct event payload.`),this.data=t;}},W=class extends R{code="ExecutionEventControlInvalidError";constructor(e,t){super(`Workflow with id: \`${e}\` has invalid \`controls\`. Please provide the correct event controls.`),this.data=t;}},$=class extends R{code="ExecutionStateControlInvalidError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` has invalid \`controls\`. Please provide the correct step controls.`),this.data=r;}},G=class extends R{code="ExecutionStateOutputInvalidError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` has invalid output. Please provide the correct step output.`),this.data=r;}},j=class extends R{code="ExecutionStateResultInvalidError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` has invalid result. Please provide the correct step result.`),this.data=r;}},K=class extends R{code="StepControlCompilationFailedError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has invalid controls syntax in step with id: \`${t}\`. Please correct step control syntax.`),this.data=r;}},B=class extends R{code="ExecutionProviderOutputInvalidError";constructor(e,t,r,s){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` and provider with id: \`${r}\` has invalid output. Please provide the correct provider output.`),this.data=s;}};var X=class extends E{statusCode;data;code;constructor(e,t,r){super(),this.data={message:r},this.statusCode=e,this.code=t;}};var Ae=()=>typeof Response<"u"?Response:crossFetch.Response;var l={info:o=>N__default.default.blue(o),warning:o=>N__default.default.yellow(o),error:o=>N__default.default.red(o),success:o=>N__default.default.green(o),underline:o=>N__default.default.underline(o),bold:o=>N__default.default.bold(o)},u={SUCCESS:l.success("\u2714"),ERROR:l.error("\u2717"),WARNING:l.warning("\u26A0"),INFO:l.info("\u2139"),ARROW:l.bold("\u2192"),MOCK:l.info("\u25CB"),HYDRATED:l.bold(l.info("\u2192")),STEP:l.info("\u03C3"),ACTION:l.info("\u03B1"),DURATION:l.info("\u0394"),PROVIDER:l.info("\u2699"),OUTPUT:l.info("\u21E2"),INPUT:l.info("\u21E0"),WORKFLOW:l.info("\u03C9"),STATE:l.info("\u03C3"),EXECUTE:l.info("\u03B5"),PREVIEW:l.info("\u03C1")};var _e=o=>Object.values(o).map(e=>`\`${e}\``).join(", "),q=o=>o.replaceAll(/(\w)(\w*)/g,(e,t,r)=>t.toUpperCase()+r.toLowerCase()).replaceAll(/[\s-]+/g,"");var me=(o,e="https://api.novu.co")=>{let t=process.env.NOVU_API_URL||e;return {post:async(r,s)=>{let i=await fetch(`${t}/v1${r}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${o}`},body:JSON.stringify(s)}),a=await i.json();if(i.ok)return a;throw shared.checkIsResponseError(a)?new X(a.statusCode,a.error,a.message):new v("Error processing API request to Novu Cloud from Bridge application.")},delete:async r=>(await fetch(`${t}/v1${r}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${o}`}})).json()}};var Ue={allowedTags:we__default.default.defaults.allowedTags.concat(["style","img","html","head","body","link","meta","title"]),allowedAttributes:!1,allowVulnerableTags:!0,parseStyleAttributes:!1,parser:{lowerCaseAttributeNames:!0}},Ie=o=>{if(!o)return o;let e=/^<!DOCTYPE .*?>/,t=o.match(e),r=we__default.default(o,Ue);return t?t[0]+r:r},J=o=>Object.keys(o).reduce((e,t)=>{let r=o[t];return typeof r=="string"?e[t]=Ie(r):Array.isArray(r)?e[t]=r.map(s=>typeof s=="string"?Ie(s):typeof s=="object"?J(s):s):typeof r=="object"&&r!==null?e[t]=J(r):e[t]=r,e},{});var z=class extends E{code="MethodNotAllowedError";statusCode=405;message=`Method not allowed. Please use one of ${_e(Y)}`},x=class extends R{code="InvalidActionError";constructor(e,t){super(`Invalid query string: \`action\`=\`${e}\`. Please use one of ${_e(t)}`);}};var v=class extends f{code="BridgeError";message="Something went wrong. Please try again later."};var U=class extends L{constructor(e,t){super(`${q(e)} with id: \`${t}\` already exists. Please use a different id.`);}},I=class extends b{constructor(e,t){super(`${q(e)} with id: \`${t}\` does not exist. Please provide a valid id.`);}},g=class extends f{constructor(e,t){super(`Failed to execute ${q(e)} with id: \`${t}\`. Please try again later.`);}};var Z=class extends I{code="ProviderNotFoundError";constructor(e){super("provider",e);}},Q=class extends g{code="ProviderExecutionFailedError";constructor(e){super("workflow",e);}};var H=class extends m{code="SignatureMismatchError";constructor(){super("Signature does not match the expected signature. Please ensure the signature provided in the `novu-signature` header is correct and try again.");}},ee=class extends m{code="SignatureNotFoundError";constructor(){super("Signature not found. Please provide a signature in the `novu-signature` header");}},te=class extends m{code="SignatureInvalidError";constructor(){super("Signature is invalid. Please provide a valid signature in the `novu-signature` header");}},re=class extends m{code="SignatureExpiredError";constructor(){super(`Signature expired. Please provide a signature with a timestamp no older than ${5} minutes in the \`novu-signature\` header`);}},oe=class extends m{code="SigningKeyNotFoundError";constructor(){super("Signature key not found. Please provide a valid key in the Client constructor `config.secretKey`");}};var se=class extends I{code="StepNotFoundError";constructor(e){super("step",e);}};var k=class extends I{code="WorkflowNotFoundError";constructor(e){super("workflow",e);}},ie=class extends U{code="WorkflowAlreadyExistsError";constructor(e){super("workflow",e);}};var Ne=o=>typeof structuredClone=="function"?structuredClone(o):JSON.parse(JSON.stringify(o));var ae=class{ajv;compiledSchemas;constructor(){this.ajv=new Ve__default.default({useDefaults:!0,removeAdditional:"failing"}),Ye__default.default(this.ajv),this.compiledSchemas=new Map;}canHandle(e){return typeof e=="boolean"?!1:e.type==="object"||!!e.anyOf||!!e.allOf||!!e.oneOf}async validate(e,t){let r=this.compiledSchemas.get(t);r||(r=this.ajv.compile(t),this.compiledSchemas.set(t,r));let s=Ne(e);return r(s)?{success:!0,data:s}:{success:!1,errors:r.errors.map(a=>({path:a.instancePath,message:a.message}))}}transformToJsonSchema(e){return e}};var ne=class{canHandle(e){return e.safeParseAsync!==void 0}async validate(e,t){let r=t.safeParse(e);return r.success?{success:!0,data:r.data}:{success:!1,errors:r.error.errors.map(s=>({path:`/${s.path.join("/")}`,message:s.message}))}}transformToJsonSchema(e){try{return zodToJsonSchema.zodToJsonSchema(e)}catch(t){throw t?.message?.includes("Cannot find module")&&console.error("Tried to use a zod schema in @novu/framework without `zod-to-json-schema` installed. Please install it by running `npm install zod-to-json-schema`."),t}}};var ce=new ne,de=new ae,ve=async(o,e)=>{if(ce.canHandle(o))return ce.validate(e,o);if(de.canHandle(o))return de.validate(e,o);throw new Error("Invalid schema")},ge=o=>{if(ce.canHandle(o))return ce.transformToJsonSchema(o);if(de.canHandle(o))return de.transformToJsonSchema(o);throw new Error("Invalid schema")};jsonSchemaFaker.JSONSchemaFaker.random.shuffle=function(){return ["[placeholder]"]};jsonSchemaFaker.JSONSchemaFaker.option({useDefaultValue:!0,alwaysFakeOptionals:!0});function Le(){return ["development",void 0].includes(process.env.NODE_ENV)}var pe=class{discoveredWorkflows=[];templateEngine=new liquidjs.Liquid;secretKey;version=P;strictAuthentication;constructor(e){let t=this.buildOptions(e);this.secretKey=t.secretKey,this.strictAuthentication=t.strictAuthentication;}buildOptions(e){let t={secretKey:void 0,strictAuthentication:!Le()};return t.secretKey=e?.secretKey||process.env.NOVU_SECRET_KEY||process.env.NOVU_API_KEY,e?.strictAuthentication!==void 0?t.strictAuthentication=e.strictAuthentication:process.env.NOVU_STRICT_AUTHENTICATION_ENABLED!==void 0&&(t.strictAuthentication=process.env.NOVU_STRICT_AUTHENTICATION_ENABLED==="true"),t}addWorkflows(e){for(let t of e){if(this.discoveredWorkflows.some(r=>r.workflowId===t.definition.workflowId))throw new ie(t.definition.workflowId);this.discoveredWorkflows.push(t.definition);}}healthCheck(){let e=this.discoveredWorkflows.length,t=this.discoveredWorkflows.reduce((r,s)=>r+s.steps.length,0);return {status:"ok",sdkVersion:P,frameworkVersion:F,discovered:{workflows:e,steps:t}}}getWorkflow(e){let t=this.discoveredWorkflows.find(r=>r.workflowId===e);if(t)return t;throw new k(e)}getStep(e,t){let s=this.getWorkflow(e).steps.find(i=>i.stepId===t);if(s)return s;throw new se(t)}getRegisteredWorkflows(){return this.discoveredWorkflows}discover(){return {workflows:this.getRegisteredWorkflows()}}mock(e){return jsonSchemaFaker.JSONSchemaFaker.generate(ge(e))}async validate(e,t,r,s,i,a,n){let c=await ve(t,e);if(c.success)return c.data;switch(r){case"event":this.throwInvalidEvent(s,i,c.errors);case"step":this.throwInvalidStep(a,s,i,c.errors);case"provider":this.throwInvalidProvider(a,n,s,i,c.errors);default:throw new Error(`Invalid component: '${r}'`)}}throwInvalidProvider(e,t,r,s,i){if(!e)throw new Error("stepId is required");if(!t)throw new Error("providerId is required");switch(r){case"output":throw new B(s,e,t,i);default:throw new Error(`Invalid payload type: '${r}'`)}}throwInvalidStep(e,t,r,s){if(!e)throw new Error("stepId is required");switch(t){case"output":throw new G(r,e,s);case"result":throw new j(r,e,s);case"controls":throw new $(r,e,s);default:throw new Error(`Invalid payload type: '${t}'`)}}throwInvalidEvent(e,t,r){switch(e){case"controls":throw new W(t,r);case"payload":throw new y(t,r);default:throw new Error(`Invalid payload type: '${e}'`)}}executeStepFactory(e,t){return async(r,s,i)=>{let a=this.getStep(e.workflowId,r),n=await this.createStepControls(a,e),c=e.action==="preview";if(!c&&await this.shouldSkip(i?.skip,n))return r===e.stepId&&t({options:{skip:!0},outputs:{},providers:{}}),{};let _=this.previewStep.bind(this),p=this.executeStep.bind(this),T=await(c?_:p)(e,{...a,providers:a.providers.map(S=>{let M=i?.providers?.[S.type];if(!M)throw new Z(S.type);return {...S,resolve:M}}),resolve:s});return Object.values(Re).includes(a.type)&&(T={...T,outputs:J(T.outputs)}),r===e.stepId&&t({...T,options:{skip:!1}}),T.outputs}}async shouldSkip(e,t){return e?e(t):!1}async executeWorkflow(e){let s=`${e.action==="execute"?"Executed":e.action==="preview"?"Previewed":"Invalid action"} workflowId:`;console.log(`
|
|
23
|
+
var D=(r=>(r.TRIGGER="trigger",r.EXECUTE="execute",r.PREVIEW="preview",r))(D||{}),V=(r=>(r.DISCOVER="discover",r.HEALTH_CHECK="health-check",r.CODE="code",r))(V||{});var O=(d=>(d.WORKFLOW_NOT_FOUND_ERROR="WorkflowNotFoundError",d.WORKFLOW_ALREADY_EXISTS_ERROR="WorkflowAlreadyExistsError",d.WORKFLOW_EXECUTION_FAILED_ERROR="WorkflowExecutionFailedError",d.EXECUTION_STATE_OUTPUT_INVALID_ERROR="ExecutionStateOutputInvalidError",d.EXECUTION_STATE_RESULT_INVALID_ERROR="ExecutionStateResultInvalidError",d.EXECUTION_PROVIDER_OUTPUT_INVALID_ERROR="ExecutionProviderOutputInvalidError",d.PROVIDER_NOT_FOUND_ERROR="ProviderNotFoundError",d.PROVIDER_EXECUTION_FAILED_ERROR="ProviderExecutionFailedError",d.STEP_NOT_FOUND_ERROR="StepNotFoundError",d.STEP_ALREADY_EXISTS_ERROR="StepAlreadyExistsError",d.STEP_EXECUTION_FAILED_ERROR="StepExecutionFailedError",d.EXECUTION_STATE_CORRUPT_ERROR="ExecutionStateCorruptError",d.EXECUTION_EVENT_PAYLOAD_INVALID_ERROR="ExecutionEventPayloadInvalidError",d.EXECUTION_EVENT_CONTROL_INVALID_ERROR="ExecutionEventControlInvalidError",d.EXECUTION_STATE_CONTROL_INVALID_ERROR="ExecutionStateControlInvalidError",d.STEP_CONTROL_COMPILATION_FAILED_ERROR="StepControlCompilationFailedError",d.METHOD_NOT_ALLOWED_ERROR="MethodNotAllowedError",d.INVALID_ACTION_ERROR="InvalidActionError",d.MISSING_SECRET_KEY_ERROR="MissingSecretKeyError",d.SIGNATURE_MISMATCH_ERROR="SignatureMismatchError",d.SIGNATURE_NOT_FOUND_ERROR="SignatureNotFoundError",d.SIGNATURE_INVALID_ERROR="SignatureInvalidError",d.SIGNATURE_EXPIRED_ERROR="SignatureExpiredError",d.SIGNING_KEY_NOT_FOUND_ERROR="SigningKeyNotFoundError",d.BRIDGE_ERROR="BridgeError",d.SIGNATURE_VERSION_INVALID_ERROR="SignatureVersionInvalidError",d.WORKFLOW_PAYLOAD_INVALID_ERROR="WorkflowPayloadInvalidError",d))(O||{});var Y=(r=>(r.POST="POST",r.GET="GET",r.OPTIONS="OPTIONS",r))(Y||{});var Re=(i=>(i.EMAIL="email",i.SMS="sms",i.PUSH="push",i.CHAT="chat",i.IN_APP="in_app",i))(Re||{});var Te="2.2.0";var P=Te,F="2024-06-26";var E=class extends Error{data},b=class extends E{statusCode=404},R=class extends E{statusCode=400},m=class extends E{statusCode=401},f=class extends E{statusCode=500},L=class extends E{statusCode=409};var C=class extends R{code="ExecutionStateCorruptError";constructor(e,t){super(`Workflow with id: \`${e}\` has a corrupt state. Step with id: \`${t}\` does not exist. Please provide the missing state.`),this.data={workflowId:e,stepId:t};}},y=class extends R{code="ExecutionEventPayloadInvalidError";constructor(e,t){super(`Workflow with id: \`${e}\` has invalid \`payload\`. Please provide the correct event payload.`),this.data=t;}},W=class extends R{code="ExecutionEventControlInvalidError";constructor(e,t){super(`Workflow with id: \`${e}\` has invalid \`controls\`. Please provide the correct event controls.`),this.data=t;}},$=class extends R{code="ExecutionStateControlInvalidError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` has invalid \`controls\`. Please provide the correct step controls.`),this.data=r;}},G=class extends R{code="ExecutionStateOutputInvalidError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` has invalid output. Please provide the correct step output.`),this.data=r;}},j=class extends R{code="ExecutionStateResultInvalidError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` has invalid result. Please provide the correct step result.`),this.data=r;}},K=class extends R{code="StepControlCompilationFailedError";constructor(e,t,r){super(`Workflow with id: \`${e}\` has invalid controls syntax in step with id: \`${t}\`. Please correct step control syntax.`),this.data=r;}},B=class extends R{code="ExecutionProviderOutputInvalidError";constructor(e,t,r,s){super(`Workflow with id: \`${e}\` has an invalid state. Step with id: \`${t}\` and provider with id: \`${r}\` has invalid output. Please provide the correct provider output.`),this.data=s;}};var X=class extends E{statusCode;data;code;constructor(e,t,r){super(),this.data={message:r},this.statusCode=e,this.code=t;}};var Ae=()=>typeof Response<"u"?Response:crossFetch.Response;var l={info:o=>N__default.default.blue(o),warning:o=>N__default.default.yellow(o),error:o=>N__default.default.red(o),success:o=>N__default.default.green(o),underline:o=>N__default.default.underline(o),bold:o=>N__default.default.bold(o)},u={SUCCESS:l.success("\u2714"),ERROR:l.error("\u2717"),WARNING:l.warning("\u26A0"),INFO:l.info("\u2139"),ARROW:l.bold("\u2192"),MOCK:l.info("\u25CB"),HYDRATED:l.bold(l.info("\u2192")),STEP:l.info("\u03C3"),ACTION:l.info("\u03B1"),DURATION:l.info("\u0394"),PROVIDER:l.info("\u2699"),OUTPUT:l.info("\u21E2"),INPUT:l.info("\u21E0"),WORKFLOW:l.info("\u03C9"),STATE:l.info("\u03C3"),EXECUTE:l.info("\u03B5"),PREVIEW:l.info("\u03C1")};var _e=o=>Object.values(o).map(e=>`\`${e}\``).join(", "),q=o=>o.replaceAll(/(\w)(\w*)/g,(e,t,r)=>t.toUpperCase()+r.toLowerCase()).replaceAll(/[\s-]+/g,"");var me=(o,e="https://api.novu.co")=>{let t=process.env.NOVU_API_URL||e;return {post:async(r,s)=>{let i=await fetch(`${t}/v1${r}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${o}`},body:JSON.stringify(s)}),a=await i.json();if(i.ok)return a;throw shared.checkIsResponseError(a)?new X(a.statusCode,a.error,a.message):new v("Error processing API request to Novu Cloud from Bridge application.")},delete:async r=>(await fetch(`${t}/v1${r}`,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`ApiKey ${o}`}})).json()}};var Ue={allowedTags:we__default.default.defaults.allowedTags.concat(["style","img","html","head","body","link","meta","title"]),allowedAttributes:!1,allowVulnerableTags:!0,parseStyleAttributes:!1,parser:{lowerCaseAttributeNames:!0}},Ie=o=>{if(!o)return o;let e=/^<!DOCTYPE .*?>/,t=o.match(e),r=we__default.default(o,Ue);return t?t[0]+r:r},J=o=>Object.keys(o).reduce((e,t)=>{let r=o[t];return typeof r=="string"?e[t]=Ie(r):Array.isArray(r)?e[t]=r.map(s=>typeof s=="string"?Ie(s):typeof s=="object"?J(s):s):typeof r=="object"&&r!==null?e[t]=J(r):e[t]=r,e},{});var z=class extends E{code="MethodNotAllowedError";statusCode=405;message=`Method not allowed. Please use one of ${_e(Y)}`},x=class extends R{code="InvalidActionError";constructor(e,t){super(`Invalid query string: \`action\`=\`${e}\`. Please use one of ${_e(t)}`);}};var v=class extends f{code="BridgeError";message="Something went wrong. Please try again later."};var U=class extends L{constructor(e,t){super(`${q(e)} with id: \`${t}\` already exists. Please use a different id.`);}},I=class extends b{constructor(e,t){super(`${q(e)} with id: \`${t}\` does not exist. Please provide a valid id.`);}},g=class extends f{constructor(e,t){super(`Failed to execute ${q(e)} with id: \`${t}\`. Please try again later.`);}};var Z=class extends I{code="ProviderNotFoundError";constructor(e){super("provider",e);}},Q=class extends g{code="ProviderExecutionFailedError";constructor(e){super("workflow",e);}};var H=class extends m{code="SignatureMismatchError";constructor(){super("Signature does not match the expected signature. Please ensure the signature provided in the `novu-signature` header is correct and try again.");}},ee=class extends m{code="SignatureNotFoundError";constructor(){super("Signature not found. Please provide a signature in the `novu-signature` header");}},te=class extends m{code="SignatureInvalidError";constructor(){super("Signature is invalid. Please provide a valid signature in the `novu-signature` header");}},re=class extends m{code="SignatureExpiredError";constructor(){super(`Signature expired. Please provide a signature with a timestamp no older than ${5} minutes in the \`novu-signature\` header`);}},oe=class extends m{code="SigningKeyNotFoundError";constructor(){super("Signature key not found. Please provide a valid key in the Client constructor `config.secretKey`");}};var se=class extends I{code="StepNotFoundError";constructor(e){super("step",e);}};var k=class extends I{code="WorkflowNotFoundError";constructor(e){super("workflow",e);}},ie=class extends U{code="WorkflowAlreadyExistsError";constructor(e){super("workflow",e);}};var Ne=o=>typeof structuredClone=="function"?structuredClone(o):JSON.parse(JSON.stringify(o));var ae=class{ajv;compiledSchemas;constructor(){this.ajv=new Ve__default.default({useDefaults:!0,removeAdditional:"failing"}),Ye__default.default(this.ajv),this.compiledSchemas=new Map;}canHandle(e){return typeof e=="boolean"?!1:e.type==="object"||!!e.anyOf||!!e.allOf||!!e.oneOf}async validate(e,t){let r=this.compiledSchemas.get(t);r||(r=this.ajv.compile(t),this.compiledSchemas.set(t,r));let s=Ne(e);return r(s)?{success:!0,data:s}:{success:!1,errors:r.errors.map(a=>({path:a.instancePath,message:a.message}))}}transformToJsonSchema(e){return e}};var ne=class{canHandle(e){return e.safeParseAsync!==void 0}async validate(e,t){let r=t.safeParse(e);return r.success?{success:!0,data:r.data}:{success:!1,errors:r.error.errors.map(s=>({path:`/${s.path.join("/")}`,message:s.message}))}}transformToJsonSchema(e){try{return zodToJsonSchema.zodToJsonSchema(e)}catch(t){throw t?.message?.includes("Cannot find module")&&console.error("Tried to use a zod schema in @novu/framework without `zod-to-json-schema` installed. Please install it by running `npm install zod-to-json-schema`."),t}}};var ce=new ne,de=new ae,ve=async(o,e)=>{if(ce.canHandle(o))return ce.validate(e,o);if(de.canHandle(o))return de.validate(e,o);throw new Error("Invalid schema")},ge=o=>{if(ce.canHandle(o))return ce.transformToJsonSchema(o);if(de.canHandle(o))return de.transformToJsonSchema(o);throw new Error("Invalid schema")};jsonSchemaFaker.JSONSchemaFaker.random.shuffle=function(){return ["[placeholder]"]};jsonSchemaFaker.JSONSchemaFaker.option({useDefaultValue:!0,alwaysFakeOptionals:!0});function Le(){return ["development",void 0].includes(process.env.NODE_ENV)}var pe=class{discoveredWorkflows=[];templateEngine=new liquidjs.Liquid;secretKey;version=P;strictAuthentication;constructor(e){let t=this.buildOptions(e);this.secretKey=t.secretKey,this.strictAuthentication=t.strictAuthentication;}buildOptions(e){let t={secretKey:void 0,strictAuthentication:!Le()};return t.secretKey=e?.secretKey||process.env.NOVU_SECRET_KEY||process.env.NOVU_API_KEY,e?.strictAuthentication!==void 0?t.strictAuthentication=e.strictAuthentication:process.env.NOVU_STRICT_AUTHENTICATION_ENABLED!==void 0&&(t.strictAuthentication=process.env.NOVU_STRICT_AUTHENTICATION_ENABLED==="true"),t}addWorkflows(e){for(let t of e){if(this.discoveredWorkflows.some(r=>r.workflowId===t.definition.workflowId))throw new ie(t.definition.workflowId);this.discoveredWorkflows.push(t.definition);}}healthCheck(){let e=this.discoveredWorkflows.length,t=this.discoveredWorkflows.reduce((r,s)=>r+s.steps.length,0);return {status:"ok",sdkVersion:P,frameworkVersion:F,discovered:{workflows:e,steps:t}}}getWorkflow(e){let t=this.discoveredWorkflows.find(r=>r.workflowId===e);if(t)return t;throw new k(e)}getStep(e,t){let s=this.getWorkflow(e).steps.find(i=>i.stepId===t);if(s)return s;throw new se(t)}getRegisteredWorkflows(){return this.discoveredWorkflows}discover(){return {workflows:this.getRegisteredWorkflows()}}mock(e){return jsonSchemaFaker.JSONSchemaFaker.generate(ge(e))}async validate(e,t,r,s,i,a,n){let c=await ve(t,e);if(c.success)return c.data;switch(r){case"event":this.throwInvalidEvent(s,i,c.errors);case"step":this.throwInvalidStep(a,s,i,c.errors);case"provider":this.throwInvalidProvider(a,n,s,i,c.errors);default:throw new Error(`Invalid component: '${r}'`)}}throwInvalidProvider(e,t,r,s,i){if(!e)throw new Error("stepId is required");if(!t)throw new Error("providerId is required");switch(r){case"output":throw new B(s,e,t,i);default:throw new Error(`Invalid payload type: '${r}'`)}}throwInvalidStep(e,t,r,s){if(!e)throw new Error("stepId is required");switch(t){case"output":throw new G(r,e,s);case"result":throw new j(r,e,s);case"controls":throw new $(r,e,s);default:throw new Error(`Invalid payload type: '${t}'`)}}throwInvalidEvent(e,t,r){switch(e){case"controls":throw new W(t,r);case"payload":throw new y(t,r);default:throw new Error(`Invalid payload type: '${e}'`)}}executeStepFactory(e,t){return async(r,s,i)=>{let a=this.getStep(e.workflowId,r),n=await this.createStepControls(a,e),c=e.action==="preview";if(!c&&await this.shouldSkip(i?.skip,n))return r===e.stepId&&t({options:{skip:!0},outputs:{},providers:{}}),{};let _=this.previewStep.bind(this),p=this.executeStep.bind(this),T=await(c?_:p)(e,{...a,providers:a.providers.map(S=>{let M=i?.providers?.[S.type];if(!M)throw new Z(S.type);return {...S,resolve:M}}),resolve:s});return Object.values(Re).includes(a.type)&&i?.disableOutputSanitization!==!0&&(T={...T,outputs:J(T.outputs)}),r===e.stepId&&t({...T,options:{skip:!1}}),T.outputs}}async shouldSkip(e,t){return e?e(t):!1}async executeWorkflow(e){let s=`${e.action==="execute"?"Executed":e.action==="preview"?"Previewed":"Invalid action"} workflowId:`;console.log(`
|
|
24
24
|
${l.bold(l.underline(s))} '${e.workflowId}'`);let i=this.getWorkflow(e.workflowId),a=process.hrtime(),n={outputs:{},providers:{},options:{skip:!1}},c,_=new Promise(h=>{c=h;}),p=h=>{c(),n=h;},w;try{if(e.action==="execute"&&!e.payload&&!e.data)throw new y(e.workflowId,{message:"Event `payload` is required"});let h=await this.createExecutionPayload(e,i),A={...e,payload:h};await Promise.race([_,i.execute({payload:h,environment:{},input:{},controls:{},subscriber:e.subscriber,step:{email:this.executeStepFactory(A,p),sms:this.executeStepFactory(A,p),inApp:this.executeStepFactory(A,p),digest:this.executeStepFactory(A,p),delay:this.executeStepFactory(A,p),push:this.executeStepFactory(A,p),chat:this.executeStepFactory(A,p),custom:this.executeStepFactory(A,p)}})]);}catch(h){w=h;}let T=process.hrtime(a),S=T[0],M=T[1],Ee=S*1e3+M/1e6,Se=w?u.ERROR:u.SUCCESS,De=e.action==="execute"?"Executed":e.action==="preview"?"Previewed":"Invalid action";if(console.log(`${Se} ${De} workflowId: \`${e.workflowId}\``),this.prettyPrintExecute(e,Ee,w),w)throw w;return {outputs:n.outputs,providers:n.providers,options:n.options,metadata:{status:"success",error:!1,duration:Ee}}}async createExecutionPayload(e,t){let r=e.payload||e.data;if(e.action==="preview"){let i=this.mock(t.payload.schema);r=Object.assign(i,r);}return await this.validate(r,t.payload.unknownSchema,"event","payload",e.workflowId)}prettyPrintExecute(e,t,r){let s=r?u.ERROR:u.SUCCESS,i=e.action==="execute"?"Executed":e.action==="preview"?"Previewed":"Invalid action",a=r?"Failed to execute":i,n=r?l.error:l.success,c=`${s} ${a} workflowId: '${e.workflowId}`;console.log(`
|
|
25
25
|
${l.bold(n(c))}'`),console.log(` \u251C ${u.STEP} stepId: '${e.stepId}'`),console.log(` \u251C ${u.ACTION} action: '${e.action}'`),console.log(` \u2514 ${u.DURATION} duration: '${t.toFixed(2)}ms'
|
|
26
26
|
`);}async executeProviders(e,t,r){return t.providers.reduce(async(s,i)=>{let a=await s,n=this.previewProvider.bind(this),c=this.executeProvider.bind(this),p=await(e.action==="preview"?n:c)(e,t,i,r);return {...a,[i.type]:p}},Promise.resolve({}))}previewProvider(e,t,r,s){return console.log(` ${u.MOCK} Mocked provider: \`${r.type}\``),this.mock(r.outputs.schema)}async executeProvider(e,t,r,s){let i=le__default.default({indent:2}).start(`Executing provider: \`${r.type}\``);try{if(e.stepId===t.stepId){let a=await this.createStepControls(t,e),n=await r.resolve({controls:a,outputs:s}),c=await this.validate(n,r.outputs.unknownSchema,"step","output",e.workflowId,t.stepId,r.type);return i.succeed(`Executed provider: \`${r.type}\``),{...c,_passthrough:n._passthrough}}else return i.stopAndPersist({symbol:u.HYDRATED,text:`Hydrated provider: \`${r.type}\``}),{}}catch(a){throw i.stopAndPersist({symbol:u.ERROR,text:`Failed to execute provider: \`${r.type}\``}),new Q(`Failed to execute provider: '${r.type}'.
|
|
27
|
-
${a.message}`)}}async executeStep(e,t){if(e.stepId===t.stepId){let r=le__default.default({indent:1}).start(`Executing stepId: \`${t.stepId}\``);try{let s=await this.createStepControls(t,e),i=await this.compileControls(s,e),a=await t.resolve(i),n=await this.validate(a,t.outputs.unknownSchema,"step","output",e.workflowId,t.stepId),c=await this.executeProviders(e,t,n);return r.succeed(`Executed stepId: \`${t.stepId}\``),{outputs:n,providers:c}}catch(s){throw r.stopAndPersist({prefixText:"",symbol:u.ERROR,text:`Failed to execute stepId: \`${t.stepId}\``}),s}}else {let r=le__default.default({indent:1}).start(`Hydrating stepId: \`${t.stepId}\``);try{let s=e.state.find(i=>i.stepId===t.stepId);if(s){let i=await this.validate(s.outputs,t.results.unknownSchema,"step","result",e.workflowId,t.stepId);return r.stopAndPersist({symbol:u.HYDRATED,text:`Hydrated stepId: \`${t.stepId}\``}),{outputs:i,providers:await this.executeProviders(e,t,i)}}else throw new C(e.workflowId,t.stepId)}catch(s){throw r.stopAndPersist({symbol:u.ERROR,text:`Failed to hydrate stepId: \`${t.stepId}\``}),s}}}async compileControls(e,t){try{let r=this.templateEngine.parse(JSON.stringify(e)),s=await this.templateEngine.render(r,{payload:t.payload||t.data,subscriber:t.subscriber,...t.payload||t.data});return JSON.parse(s)}catch(r){throw new K(t.workflowId,t.stepId,r)}}async createStepControls(e,t){let r=t.controls||t.inputs;return await this.validate(r,e.controls.unknownSchema,"step","controls",t.workflowId,e.stepId)}async previewStep(e,t){let r=le__default.default({indent:1}).start(`Previewing stepId: \`${t.stepId}\``);try{if(e.stepId===t.stepId){let s=await this.createStepControls(t,e),i=await this.compileControls(s,e),a=await t.resolve(i),n=await this.validate(a,t.outputs.unknownSchema,"step","output",e.workflowId,t.stepId);return r.stopAndPersist({symbol:u.MOCK,text:`Mocked stepId: \`${t.stepId}\``}),{outputs:n,providers:await this.executeProviders(e,t,n)}}else {let s=this.mock(t.results.schema);return r.stopAndPersist({symbol:u.MOCK,text:`Mocked stepId: \`${t.stepId}\``}),{outputs:s,providers:await this.executeProviders(e,t,s)}}}catch(s){throw r.stopAndPersist({symbol:u.ERROR,text:`Failed to preview stepId: \`${t.stepId}\``}),s}}getStepCode(e,t){return {code:this.getStep(e,t).resolve.toString()}}getWorkflowCode(e){return {code:this.getWorkflow(e).execute.toString()}}getCode(e,t){let r;if(e)t?r=this.getStepCode(e,t):r=this.getWorkflowCode(e);else throw new k(e);return r}};var ue=class{frameworkName;handler;client;hmacEnabled;http;constructor(e){this.handler=e.handler,this.client=e.client?e.client:new pe,this.client.addWorkflows(e.workflows),this.http=me(this.client.secretKey),this.frameworkName=e.frameworkName,this.hmacEnabled=this.client.strictAuthentication;}createHandler(){return async(...e)=>{let t=await this.handler(...e),r=await this.handleAction({actions:t});return t.transformResponse(r)}}getStaticHeaders(){let e=`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":F,"novu-framework-sdk":P,"novu-framework-server":this.frameworkName,"user-agent":e}}createResponse(e,t){return {status:e,body:JSON.stringify(t),headers:{...this.getStaticHeaders()}}}createError(e){return {status:e.statusCode,body:JSON.stringify({message:e.message,data:e.data,code:e.code}),headers:this.getStaticHeaders()}}async handleAction({actions:e}){let t=await e.url(),r=await e.method(),s=t.searchParams.get("action")||"",i=t.searchParams.get("workflowId")||"",a=t.searchParams.get("stepId")||"",n=await e.headers("novu-signature")||await e.headers("x-novu-signature")||"",c={};try{r==="POST"&&(c=await e.body());}catch{}try{s!=="health-check"&&this.validateHmac(c,n);let _=this.getPostActionMap(c,i,a,s),p=this.getGetActionMap(i,a);if(r==="POST")return await this.handlePostAction(s,_);if(r==="GET")return await this.handleGetAction(s,p);if(r==="OPTIONS")return this.createResponse(200,{})}catch(_){return this.handleError(_)}return this.createError(new z(r))}getPostActionMap(e,t,r,s){return {trigger:this.triggerAction({workflowId:t,...e}),execute:async()=>{let i=await this.client.executeWorkflow({...e,workflowId:t,stepId:r,action:s});return this.createResponse(200,i)},preview:async()=>{let i=await this.client.executeWorkflow({...e,workflowId:t,stepId:r,action:s});return this.createResponse(200,i)}}}triggerAction(e){return async()=>{let t={name:e.workflowId,to:e.to,payload:e?.payload||{},transactionId:e.transactionId,overrides:e.overrides||{},...e.actor&&{actor:e.actor},...e.bridgeUrl&&{bridgeUrl:e.bridgeUrl},...e.controls&&{controls:e.controls}},r=await this.http.post("/events/trigger",t);return this.createResponse(200,r)}}getGetActionMap(e,t){return {discover:async()=>{let r=await this.client.discover();return this.createResponse(200,r)},"health-check":async()=>{let r=await this.client.healthCheck();return this.createResponse(200,r)},code:async()=>{let r=await this.client.getCode(e,t);return this.createResponse(200,r)}}}async handlePostAction(e,t){if(Object.values(D).includes(e)){let r=t[e];return r()}else throw new x(e,D)}async handleGetAction(e,t){if(Object.values(V).includes(e)){let r=t[e];return r()}else throw new x(e,V)}isBridgeError(e){return Object.values(O).includes(e?.code)}isPlatformError(e){return e?.statusCode>=400&&e?.statusCode<500}handleError(e){return this.isBridgeError(e)?(e.statusCode===500&&console.error(e),this.createError(e)):this.isPlatformError(e)?this.createError(e):(console.error(e),this.createError(new v))}validateHmac(e,t){if(!this.hmacEnabled)return;if(!t)throw new ee;if(!this.client.secretKey)throw new oe;let[r,s]=t.split(",");if(!r||!s)throw new te;let[i,a]=r.split("="),[n,c]=s.split("=");if(Number(i)<Date.now()-1500)throw new re;if(!(this.hashHmac(this.client.secretKey,`${a}.${JSON.stringify(e)}`)===c))throw new H}hashHmac(e,t){return crypto.createHmac("sha256",e).update(t).digest("hex")}};var $e="sveltekit",Zr=o=>{let t=new ue({frameworkName:$e,...o,handler:(i,a)=>({method:()=>i||a.request.method||"",body:()=>a.request.json(),headers:n=>a.request.headers.get(n),url:()=>{let n=process.env.NODE_ENV==="development"?"http":"https";return new URL(a.request.url,`${n}://${a.request.headers.get("host")||""}`)},transformResponse:({body:n,headers:c,status:_})=>{let p=Ae();return new p(n,{status:_,headers:c})}})}).createHandler(),r=t.bind(null,void 0);return Object.defineProperties(r,{GET:{value:t.bind(null,"GET")},POST:{value:t.bind(null,"POST")},OPTIONS:{value:t.bind(null,"OPTIONS")}})};
|
|
27
|
+
${a.message}`)}}async executeStep(e,t){if(e.stepId===t.stepId){let r=le__default.default({indent:1}).start(`Executing stepId: \`${t.stepId}\``);try{let s=await this.createStepControls(t,e),i=await this.compileControls(s,e),a=await t.resolve(i),n=await this.validate(a,t.outputs.unknownSchema,"step","output",e.workflowId,t.stepId),c=await this.executeProviders(e,t,n);return r.succeed(`Executed stepId: \`${t.stepId}\``),{outputs:n,providers:c}}catch(s){throw r.stopAndPersist({prefixText:"",symbol:u.ERROR,text:`Failed to execute stepId: \`${t.stepId}\``}),s}}else {let r=le__default.default({indent:1}).start(`Hydrating stepId: \`${t.stepId}\``);try{let s=e.state.find(i=>i.stepId===t.stepId);if(s){let i=await this.validate(s.outputs,t.results.unknownSchema,"step","result",e.workflowId,t.stepId);return r.stopAndPersist({symbol:u.HYDRATED,text:`Hydrated stepId: \`${t.stepId}\``}),{outputs:i,providers:await this.executeProviders(e,t,i)}}else throw new C(e.workflowId,t.stepId)}catch(s){throw r.stopAndPersist({symbol:u.ERROR,text:`Failed to hydrate stepId: \`${t.stepId}\``}),s}}}async compileControls(e,t){try{let r=this.templateEngine.parse(JSON.stringify(e)),s=await this.templateEngine.render(r,{payload:t.payload||t.data,subscriber:t.subscriber,...t.payload||t.data});return JSON.parse(s)}catch(r){throw new K(t.workflowId,t.stepId,r)}}async createStepControls(e,t){let r=t.controls||t.inputs;return await this.validate(r,e.controls.unknownSchema,"step","controls",t.workflowId,e.stepId)}async previewStep(e,t){let r=le__default.default({indent:1}).start(`Previewing stepId: \`${t.stepId}\``);try{if(e.stepId===t.stepId){let s=await this.createStepControls(t,e),i=await this.compileControls(s,e),a=await t.resolve(i),n=await this.validate(a,t.outputs.unknownSchema,"step","output",e.workflowId,t.stepId);return r.stopAndPersist({symbol:u.MOCK,text:`Mocked stepId: \`${t.stepId}\``}),{outputs:n,providers:await this.executeProviders(e,t,n)}}else {let s=this.mock(t.results.schema);return r.stopAndPersist({symbol:u.MOCK,text:`Mocked stepId: \`${t.stepId}\``}),{outputs:s,providers:await this.executeProviders(e,t,s)}}}catch(s){throw r.stopAndPersist({symbol:u.ERROR,text:`Failed to preview stepId: \`${t.stepId}\``}),s}}getStepCode(e,t){return {code:this.getStep(e,t).resolve.toString()}}getWorkflowCode(e){return {code:this.getWorkflow(e).execute.toString()}}getCode(e,t){let r;if(e)t?r=this.getStepCode(e,t):r=this.getWorkflowCode(e);else throw new k(e);return r}};var ue=class{frameworkName;handler;client;hmacEnabled;http;constructor(e){this.handler=e.handler,this.client=e.client?e.client:new pe,this.client.addWorkflows(e.workflows),this.http=me(this.client.secretKey),this.frameworkName=e.frameworkName,this.hmacEnabled=this.client.strictAuthentication;}createHandler(){return async(...e)=>{let t=await this.handler(...e),r=await this.handleAction({actions:t});return t.transformResponse(r)}}getStaticHeaders(){let e=`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":F,"novu-framework-sdk":P,"novu-framework-server":this.frameworkName,"user-agent":e}}createResponse(e,t){return {status:e,body:JSON.stringify(t),headers:{...this.getStaticHeaders()}}}createError(e){return {status:e.statusCode,body:JSON.stringify({message:e.message,data:e.data,code:e.code}),headers:this.getStaticHeaders()}}async handleAction({actions:e}){let t=await e.url(),r=await e.method(),s=t.searchParams.get("action")||"health-check",i=t.searchParams.get("workflowId")||"",a=t.searchParams.get("stepId")||"",n=await e.headers("novu-signature")||await e.headers("x-novu-signature")||"",c={};try{r==="POST"&&(c=await e.body());}catch{}try{s!=="health-check"&&this.validateHmac(c,n);let _=this.getPostActionMap(c,i,a,s),p=this.getGetActionMap(i,a);if(r==="POST")return await this.handlePostAction(s,_);if(r==="GET")return await this.handleGetAction(s,p);if(r==="OPTIONS")return this.createResponse(200,{})}catch(_){return this.handleError(_)}return this.createError(new z(r))}getPostActionMap(e,t,r,s){return {trigger:this.triggerAction({workflowId:t,...e}),execute:async()=>{let i=await this.client.executeWorkflow({...e,workflowId:t,stepId:r,action:s});return this.createResponse(200,i)},preview:async()=>{let i=await this.client.executeWorkflow({...e,workflowId:t,stepId:r,action:s});return this.createResponse(200,i)}}}triggerAction(e){return async()=>{let t={name:e.workflowId,to:e.to,payload:e?.payload||{},transactionId:e.transactionId,overrides:e.overrides||{},...e.actor&&{actor:e.actor},...e.bridgeUrl&&{bridgeUrl:e.bridgeUrl},...e.controls&&{controls:e.controls}},r=await this.http.post("/events/trigger",t);return this.createResponse(200,r)}}getGetActionMap(e,t){return {discover:async()=>{let r=await this.client.discover();return this.createResponse(200,r)},"health-check":async()=>{let r=await this.client.healthCheck();return this.createResponse(200,r)},code:async()=>{let r=await this.client.getCode(e,t);return this.createResponse(200,r)}}}async handlePostAction(e,t){if(Object.values(D).includes(e)){let r=t[e];return r()}else throw new x(e,D)}async handleGetAction(e,t){if(Object.values(V).includes(e)){let r=t[e];return r()}else throw new x(e,V)}isBridgeError(e){return Object.values(O).includes(e?.code)}isPlatformError(e){return e?.statusCode>=400&&e?.statusCode<500}handleError(e){return this.isBridgeError(e)?(e.statusCode===500&&console.error(e),this.createError(e)):this.isPlatformError(e)?this.createError(e):(console.error(e),this.createError(new v))}validateHmac(e,t){if(!this.hmacEnabled)return;if(!t)throw new ee;if(!this.client.secretKey)throw new oe;let[r,s]=t.split(",");if(!r||!s)throw new te;let[i,a]=r.split("="),[n,c]=s.split("=");if(Number(i)<Date.now()-1500)throw new re;if(!(this.hashHmac(this.client.secretKey,`${a}.${JSON.stringify(e)}`)===c))throw new H}hashHmac(e,t){return crypto.createHmac("sha256",e).update(t).digest("hex")}};var $e="sveltekit",Zr=o=>{let t=new ue({frameworkName:$e,...o,handler:(i,a)=>({method:()=>i||a.request.method||"",body:()=>a.request.json(),headers:n=>a.request.headers.get(n),url:()=>{let n=process.env.NODE_ENV==="development"?"http":"https";return new URL(a.request.url,`${n}://${a.request.headers.get("host")||""}`)},transformResponse:({body:n,headers:c,status:_})=>{let p=Ae();return new p(n,{status:_,headers:c})}})}).createHandler(),r=t.bind(null,void 0);return Object.defineProperties(r,{GET:{value:t.bind(null,"GET")},POST:{value:t.bind(null,"POST")},OPTIONS:{value:t.bind(null,"OPTIONS")}})};
|
|
28
28
|
|
|
29
29
|
exports.frameworkName = $e;
|
|
30
30
|
exports.serve = Zr;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@novu/framework",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "The Code-First Notifications Workflow SDK.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,8 +29,7 @@
|
|
|
29
29
|
"$comment:bump:prerelease": "This is a workaround to support `npm version prerelease` with lerna",
|
|
30
30
|
"bump:prerelease": "npm version prerelease --preid=alpha & PID=$!; (sleep 1 && kill -9 $PID) & wait $PID",
|
|
31
31
|
"release:alpha": "pnpm bump:prerelease || pnpm build && npm publish",
|
|
32
|
-
"devtool": "tsx ./scripts/devtool.ts"
|
|
33
|
-
"release:preview": "pnpx pkg-pr-new publish"
|
|
32
|
+
"devtool": "tsx ./scripts/devtool.ts"
|
|
34
33
|
},
|
|
35
34
|
"keywords": [
|
|
36
35
|
"novu",
|
|
@@ -61,6 +60,11 @@
|
|
|
61
60
|
"import": "./dist/servers/express.js",
|
|
62
61
|
"types": "./dist/servers/express.d.ts"
|
|
63
62
|
},
|
|
63
|
+
"./nest": {
|
|
64
|
+
"require": "./dist/servers/nest.js",
|
|
65
|
+
"import": "./dist/servers/nest.js",
|
|
66
|
+
"types": "./dist/servers/nest.d.ts"
|
|
67
|
+
},
|
|
64
68
|
"./next": {
|
|
65
69
|
"require": "./dist/servers/next.js",
|
|
66
70
|
"import": "./dist/servers/next.js",
|
|
@@ -93,6 +97,7 @@
|
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
"peerDependencies": {
|
|
100
|
+
"@nestjs/common": ">=10.0.0",
|
|
96
101
|
"@sveltejs/kit": ">=1.27.3",
|
|
97
102
|
"@vercel/node": ">=2.15.9",
|
|
98
103
|
"aws-lambda": ">=1.0.7",
|
|
@@ -103,6 +108,9 @@
|
|
|
103
108
|
"zod-to-json-schema": ">=3.0.0"
|
|
104
109
|
},
|
|
105
110
|
"peerDependenciesMeta": {
|
|
111
|
+
"@nestjs/common": {
|
|
112
|
+
"optional": true
|
|
113
|
+
},
|
|
106
114
|
"@sveltejs/kit": {
|
|
107
115
|
"optional": true
|
|
108
116
|
},
|
|
@@ -133,6 +141,7 @@
|
|
|
133
141
|
},
|
|
134
142
|
"devDependencies": {
|
|
135
143
|
"@apidevtools/json-schema-ref-parser": "11.6.4",
|
|
144
|
+
"@nestjs/common": "10.4.1",
|
|
136
145
|
"@sveltejs/kit": "^1.27.3",
|
|
137
146
|
"@types/aws-lambda": "^8.10.141",
|
|
138
147
|
"@types/express": "^4.17.13",
|
|
@@ -153,7 +162,7 @@
|
|
|
153
162
|
"zod-to-json-schema": "^3.23.0"
|
|
154
163
|
},
|
|
155
164
|
"dependencies": {
|
|
156
|
-
"@novu/shared": "^2.1.
|
|
165
|
+
"@novu/shared": "^2.1.1",
|
|
157
166
|
"ajv": "^8.12.0",
|
|
158
167
|
"ajv-formats": "^2.1.1",
|
|
159
168
|
"better-ajv-errors": "^1.2.0",
|
|
@@ -164,5 +173,8 @@
|
|
|
164
173
|
"liquidjs": "^10.13.1",
|
|
165
174
|
"ora": "^5.4.1",
|
|
166
175
|
"sanitize-html": "^2.13.0"
|
|
176
|
+
},
|
|
177
|
+
"nx": {
|
|
178
|
+
"tags": ["package:public"]
|
|
167
179
|
}
|
|
168
180
|
}
|