How to Validate BPMN Workflow Variables in TypeScript/JavaScript

Raghu Rana: Hi, is there any guidance around bpmn workflow variables validation. For example: - when we start a new workflow using nodejs zeebeclient we invoke createworkflowinstance method and pass in the worflow-id and the variables as payload. We could potentially validate input variables there, but just wondering if there is a better way to validate inside the bpmn model itself or any other recommended/tried approach.

Josh Wulf: The runtime environment for variables in the broker is more dynamic than JS

Josh Wulf: You need to validate at the boundary

Josh Wulf: I use io-ts for this

Josh Wulf: https://github.com/gcanti/io-ts

Raghu Rana: Thanks Josh.

Josh Wulf: There is an example in the Zeebe GitHub Action. I use it to validate the required parameters for operations coming from the yaml config

Josh Wulf: https://github.com/jwulf/zeebe-action/blob/master/src/operation-config-validation.ts

Josh Wulf: https://github.com/jwulf/zeebe-action/blob/master/src/parameters/getEnvironment.ts

Raghu Rana: So by declaring types via io-ts you can hv type safety by default, perform validations via decode and also perform set operations like union, intersection. Is that a reasonable understanding of this package ?

Josh Wulf: Yes. Union and intersection you use for required and optional parameters

Josh Wulf: Union is for “this or that”. Intersection is for “this, and maybe that”

Josh Wulf: It does bring functional programming into your codebase with the Either type, but I found that to be a good thing ultimately.

Josh Wulf: Instead of my programs/functions having multiple exit points with different handlers, execution switches to a “failure rail” and there is single failure handler at the end.

Raghu Rana: Thanks mate, much appreciated. Will check this out in detail shortly.

Doug Wilson: Great question, @Raghu Rana. Great answer, @Josh Wulf. Might this be archive-worthy?

Josh Wulf: The author of io-ts / fp-ts is on this Slack: https://fpchat-invite.herokuapp.com/

Josh Wulf: He helped me get it working for the Zeebe Action

Josh Wulf: @Doug Wilson - fire it up

Note: This post was generated by Slack Archivist from a conversation in the Zeebe Slack, a source of valuable discussions on Zeebe (get an invite). Someone in the Slack thought this was worth sharing!

If this post answered a question for you, hit the Like button - we use that to assess which posts to put into docs.

2 Likes