Schema
Integrate Zod with your notification workflows
Novu Framework allows you to use Zod to define the Control and Payload schemas for your workflows.
Add Zod to your project
1
Install Zod Packages
npm install zod zod-to-json-schema
Novu requires the zod-to-json-schema
package to generate JSON schemas from your Zod definitions.
2
Use Zod in your workflow
After installation, the Zod schemas can be used interchangeably with the controlSchema
and payloadSchema
options in your workflow definitions.
import { workflow } from '@novu/framework';
import { z } from 'zod';
export const testWorkflow = workflow('test-workflow', async ({ step, payload }) => {
await step.email('send-email', async (controls) => {
return {
subject: controls.subject,
body: 'Hello, World!',
};
},
{
controlSchema: z.object({
subject: z.string().default('A test subject'),
}),
});
}, {
payloadSchema: z.object({
userName: z.string(),
}),
});
Controls and Payload UI
When you define a controlSchema
for a step, Novu will automatically generate a UI for the controls in the workflow editor.
- Form Input Title - Will be derived from the key of the Zod schema. Unfortunately Zod does not support custom titles at this point.
- Form Input Type - Will be derived from the Zod schema type, with support for
string
,number
,boolean
, andenum
andarray
types. - Default Value - Will be derived from the Zod schema default value.
- Validation - Will be derived from the Zod schema validation rules, including
min
,max
,email
,url
,regex
and etc…
Was this page helpful?