inngest / inngest-js

The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript
https://www.inngest.com/
GNU General Public License v3.0
432 stars 42 forks source link

[Feature] Validate event data against zod schema #410

Open elbalexandre opened 11 months ago

elbalexandre commented 11 months ago

Is your feature request related to a problem? Please describe. Event data is not validated against Zod schemas used for defining Inngest client event schemas.

Describe the solution you'd like When Zod schemas are used, the send() function should validate the provided data against the corresponding Zod schema.

Describe alternatives you've considered An alternative could be to remove EventSchemas.fromZod. This might be less ambiguous, as users familiar with Zod know they can use z.infer.

Additional context N/A

mattddean commented 3 months ago

Agreed, my assumption was that if I was providing a zod schema, the data was being validated, particularly because the event property handed to my function is typed according to the schema. This means that in a pretty normal webhook case, the type can be pretty easily wrong.

jpwilliams commented 3 months ago

There's a preliminary PR for this over at #657. Leaving this issue open to continue to gather feedback, but you can use that PR to get going now if you need this before we add a first-party option. 🙂