npm package: @gavdi/btpworkflowvalidator
Description: Validator for SAP BTP Workflow
Author: Nicolas Duran
Latest version: 1.2.4



# Workflow validator

Workflow validator for SAP BTP Cloud Foundry workflow definitions

## Installation

`npm i --save-dev @gavdi/btpworkflowvalidator`

## Usage

Run script `start`, passing as only argument the folder where the workflow definitions are stored. The structure should look like this:

```
myproject  
|____**myworkflowproject**  
|____|____ sample-data  
|____|____|____ workflow1  
|____|____|____|____ context.json  
|____|____|____ workflow2  
|____|____|____ workflow3  
|____|____ scripts  
|____|____|____ workflow1  
|____|____|____|____ script1.js  
|____|____|____ workflow2  
|____|____|____ workflow3  
|____|____ webcontent  
|____|____|____ workflow1  
|____|____|____|____ file1.html  
|____|____|____ workflow2  
|____|____|____ workflow3  
|____|____ workflows  
|____|____|____ **workflow1.workflow**  
|____|____|____ **workflow2.workflow**  
|____|____|____ **workflow3.workflow**  
```

In this example, pass as argument ``myworkflowproject``:

```
start ./myworkflowproject
```

The validator will look for workflow definitions (files with extension .workflow) and referenced files inside that folder.

## Integration in build cycle

Process exits with error if workflow is not valid.  
Example `package.json`:

```json
{
    
    "devDependencies": {
        "@gavdi/btpworkflowvalidator": "^1.2.3",
        "npm-run-all": "^4.1.5"
    },
    "scripts": {
        "validateWorkflow": "npx @gavdi/btpworkflowvalidator myworkflowproject",
        "build:mta": "npx mbt build --mtar archive",
        "build": "npm-run-all validateWorkflow build:mta"
    }
}
```


## Validations

* Mandatory fields tasks and important configurations
* Links between nodes: references to non-existent nodes, orphan nodes, etc
* Consistency of model definition
* Duplicate IDs
* Existence of external files (scripts, html content)
* Documentation of tasks
* **ES5 syntax for script files**, using ``acorn``, as that's what the workflow engine expects, otherwise deployment fails with a misterious error ``while trying to invoke the method com.sap.bpm.wds.core.model.WorkflowModuleContent.getSubcontents() of a null object loaded from local variable 'obj'``

## Example output

```log
$ npm run start testworkflows
[Workflow] validworkflow.workflow > Workflow looks alright!
[Workflow] wrongworkflow.workflow > ERROR: Missing mandatory field: id in node: timereventdefinition1 (com.sap.bpm.wfs.TimerEventDefinition)
[Workflow] wrongworkflow.workflow > WARNING: Missing documentation for: Start (com.sap.bpm.wfs.StartEvent)
[Workflow] wrongworkflow.workflow > ERROR: Duplicate ID: endevent1 (com.sap.bpm.wfs.EndEvent)
[Workflow] wrongworkflow.workflow > ERROR: Missing mailDefinitionRef configuration in Mail to approver (com.sap.bpm.wfs.MailTask)
[Workflow] wrongworkflow.workflow > ERROR: Missing mandatory field: mailDefinitionRef in node: Mail to approver (com.sap.bpm.wfs.MailTask)
[Workflow] wrongworkflow.workflow > WARNING: Missing documentation for: Updated? (com.sap.bpm.wfs.ExclusiveGateway)
[Workflow] wrongworkflow.workflow > ERROR: Missing file: /scripts/wrongworkflow/verifyRequesterData.js in Verify requester data (com.sap.bpm.wfs.ScriptTask)
[Workflow] wrongworkflow.workflow > ERROR: Invalid ES5 source file: /scripts/wrongworkflow/scriptNotES5.js. Location: line 3, column 20. Reason: Unexpected token (3:20)
[Workflow] wrongworkflow.workflow > ERROR: Unknown reference to 3b29770b-78ba-4566-b428-bbed131f5afc in SequenceFlow21 (com.sap.bpm.wfs.SequenceFlow)
[Workflow] wrongworkflow.workflow > ERROR: Missing file: /sample-data/workflow/context.json in default-start-context (com.sap.bpm.wfs.SampleContext)
[Workflow] wrongworkflow.workflow > ERROR: Unknown reference to 3b29770b-78ba-4566-b428-bbed131f5afc in undefined (com.sap.bpm.wfs.ui.StartEventSymbol)
[Workflow] wrongworkflow.workflow > ERROR: Orphan node: intermediatetimerevent1 IntermediateTimerEvent1 (com.sap.bpm.wfs.IntermediateCatchEvent)
[Workflow] wrongworkflow.workflow > ERROR: Orphan node: startevent1 Start (com.sap.bpm.wfs.StartEvent)
[Workflow] wrongworkflow.workflow > ERROR: Orphan node: endevent1 Orphan_event_for_testing_with_duplicate_ID (com.sap.bpm.wfs.EndEvent)
[Workflow] wrongworkflow.workflow > ERROR: Orphan node: maildefinition1 maildefinition1 (com.sap.bpm.wfs.MailDefinition)
[Workflow] wrongworkflow.workflow > ERROR: Unknown reference to 3b29770b-78ba-4566-b428-bbed131f5afc in workflow (com.sap.bpm.wfs.Model)
[Workflow] wrongworkflow.workflow > ERROR: Unknown reference to 39e43cc2-0c00-45ed-b7f7-cce9c225fb1c29 in workflow (com.sap.bpm.wfs.Model)
[Workflow] wrongworkflow.workflow > Workflow has 15 errors and 2 warnings
```