-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Template Schema Validation #4
Comments
@scopsy do you guys mind if I dig my head into this issue? |
@davidsoderberg sure thing, assigning this to you right now, @scopsy do you have anything else to add here?---- Lets assume this didn't happen 😆 |
@davidsoderberg sure! You can outline and API for the validations so we can discuss it with the community? Some initial thoughts: we can create an API that will allow any validation system to work using some sort of plugin approach. This can support validators like Joi or class validators. Or just a simple function validation with custom logic. |
I was thinking of a function that can be a promise and then we do not catch it so the error can be catched by the user of the package. Any thoughts on that? |
@davidsoderberg Yeah! This definitely can be a promise. I've attached some ideas for making a pluggable system with bringing your own validator library style. Let me know what you think: This can be the validator schema, the main thing is that each validator should return a validate function, the implementation doesn't matter as long as the validate method exists. interface ITemplateSchema {
validate(payload: ITriggerPayload): Promise<boolean>;
} This is one implementation for JOI, we can use similar once to validate with other validator libraries or custom code. class JoiValidator implements ITemplateSchema {
constructor(private schema: JoiSchema) {
}
async validate(payload: ITrigger) {
await this.schema.validateAsync(payload);
return true;
}
} Not sure about the const passwordResetTemplate = await notifire.registerTemplate({
id: 'password-reset',
schema: new JoiValidator(Joi.object({
username: Joi.string()
.alphanum()
.min(3)
.max(30)
.required()
})),
messages: [
{
subject: 'Your password reset request',
channel: ChannelTypeEnum.EMAIL,
template: `
Hi {{firstName}}!
`
},
]
}); |
I'm submitting a ...
[ ] bug report
[X] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
Summary
Add for variable schema for templates
Add option for variable validation using Joi, Yup, class-validator, and such
Add option for a variable to fall back if missing of failing validation
Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
The text was updated successfully, but these errors were encountered: