{"id":18777494,"url":"https://github.com/onify/flow-validator","last_synced_at":"2025-12-16T23:30:12.931Z","repository":{"id":57133241,"uuid":"358183544","full_name":"onify/flow-validator","owner":"onify","description":"Validate you Onify Flow","archived":false,"fork":false,"pushed_at":"2021-11-13T06:50:07.000Z","size":71,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-16T17:57:04.779Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-15T08:25:08.000Z","updated_at":"2021-11-13T06:50:10.000Z","dependencies_parsed_at":"2022-09-03T15:02:21.060Z","dependency_job_id":null,"html_url":"https://github.com/onify/flow-validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Fflow-validator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Fflow-validator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Fflow-validator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onify%2Fflow-validator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onify","download_url":"https://codeload.github.com/onify/flow-validator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239687633,"owners_count":19680767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T20:11:21.104Z","updated_at":"2025-12-16T23:30:12.878Z","avatar_url":"https://github.com/onify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flow-validator\n\n![Test suite](https://github.com/onify/flow-validator/workflows/Test%20suite/badge.svg)\n\nValidate you Onify Flow.\n\n- [Flow Validator](#flow-validator)\n  - [Linting of script](#linting-of-script)\n- [Onify Flow Introduction](#onify-flow-introduction)\n- [Timers](#timers)\n  - [`timeDuration`](#timeduration)\n  - [`timeCycle`](#timecycle)\n  - [`timeDate`](#timedate)\n- [Input/Output](#inputoutput)\n  - [Expressions](#expressions)\n  - [Input parameters](#input-parameters)\n    - [Process state](#process-state)\n  - [Output parameters](#output-parameters)\n    - [Process state](#process-state)\n  - [Process status](#process-status)\n- [ServiceTasks](#servicetasks)\n  - [`onifyApiRequest(options[, callback])`](#onifyapirequestoptions-callback)\n  - [`onifyElevatedApiRequest(options[, callback])`](#onifyelevatedapirequestoptions-callback)\n  - [`httpRequest(options[, callback])`](#httprequestoptions-callback)\n- [JavaScript](#javascript)\n  - [Global context](#global-context)\n    - [`fields`](#fields)\n    - [`content`](#content)\n    - [`properties`](#properties)\n    - [`environment`](#environment)\n    - [`contextName`](#contextname)\n    - [`next(err, result)`](#nexterr-result)\n    - [`Buffer.from(...args)`](#bufferfromargs)\n      - [Encode as base64](#encode-as-base64)\n      - [Decode base64](#decode-base64)\n    - [`console.log(...args)`](#consolelogargs)\n    - [`decrypt(encryptedText, encoding = 'hex')`](#decryptencryptedtext-encoding--hex)\n    - [`encrypt(text, encoding = 'hex')`](#encrypttext-encoding--hex)\n    - [`jwt.sign(...)`](#jwtsign)\n    - [`jwt.verify(...)`](#jwtverify)\n\n# Flow Validator\n\nMocha example\n\n```js\nconst FlowValidator = require('@onify/flow-validator');\nconst {expect} = require('chai');\nconst {promises: fs} = require('fs');\n\ndescribe('all my flows are valid', () =\u003e {\n  let source, validator;\n  before(async () =\u003e {\n    source = await fs.readFile('./resources/happy-trail.bpmn');\n    validator = FlowValidator(source);\n  });\n\n  it('model has no errors', async () =\u003e {\n    const {warnings} = await validator.validate();\n    const message = warnings.map(({message}) =\u003e message).join('\\n');\n    expect(warnings, message).to.have.length(0);\n  });\n\n  it('scripts have no linting errors', async () =\u003e {\n    const linting = await validator.lint();\n    expect(linting, linting).to.have.length(0);\n  });\n\n  it('but I know we have some console.logs, it\\'s OK', async () =\u003e {\n    const {linting} = await validator.validate({\n      rules: {\n        'no-console': 2,\n      }\n    });\n    expect(linting, linting).to.have.length.above(0);\n    expect(linting[0]).to.contain('no-console');\n  });\n});\n````\n\n## Linting of script\n\nFor the linting to run successfully you need to have an eslint config `.eslintrc.json` in your root folder. Here is a sample:\n\n```json\n{\n  \"parserOptions\": {\n    \"ecmaVersion\": 2020\n  },\n  \"env\": {\n    \"node\": true,\n    \"es6\": true\n  },\n  \"extends\": \"eslint:recommended\",\n  \"rules\": {\n    \"unicode-bom\": [\"error\", \"never\"]\n  }\n}\n```\n\n# Onify Flow Introduction\n\nOnify flow is based on the open source workflow engine [bpmn-engine](https://github.com/paed01/bpmn-engine).\n\n# Timers\n\nOnify flow supports timers, i.e. [TimerEventDefinition's](https://github.com/paed01/bpmn-elements/blob/master/docs/TimerEventDefinition.md) with one addition. Onify also supports time cycle using cron.\n\n## `timeDuration`\n\nSuitable for activity timeouts. Duration is defined using ISO8601 duration\n\n## `timeCycle`\n\nSuitable for scheduled flows. Cycle is defined using cron.\n\n## `timeDate`\n\nSuitable for scheduled flows. Date should be set using `new Date()` or in ISO format.\n\n# Input/Output\n\nWhen modelling a flow for Onify it is possible to define activity Input/Output parameters. Onify has some special handling of the content of that.\n\n1. If a parameter with the same name appears the parameter will be overwritten with the new value\n2. If a Map is used the Map will be converted into an object\n3. If a Map contains fields with the same name the field will be converted into an Array and the values will be pushed\n\n## Expressions\n\nInput/output parameters can be set using expressions. The [bpmn-engine](https://github.com/paed01/bpmn-engine) has built in expression handling that is documented [here](https://github.com/paed01/bpmn-elements/blob/master/docs/Expression.md).\n\nTip! Since all parameter values are treated as strings, typed booleans and numbers can defined using: `${true}`, `${false}`, or `${1234}`.\n\n## Input parameters\n\nInput parameters will be available under [`content.input`](#content).\n\n### Process state\n\nIf a `state` input parameter is defined it will be mapped as process state. States can be one or many. The input parameter can be either a Map or a script returning an object.\n\nExample Map:\n\n| field name    | type               | description               |\n|---------------|--------------------|---------------------------|\n| `id`          | string             | example: `state-1`        |\n| `name`        | (optional) string  | example: `My first state` |\n| `order`       | (optional) integer | display order             |\n| `description` | (optional) string  | description               |\n| `user`        | (optional) array   | allowed user              |\n| `role`        | (optional) array   | allowed roles             |\n\n## Output parameters\n\nInput parameters will be available under [`content.output`](#content).\n\n### Process state\n\nIf a `state` output parameter is defined it will be mapped as process state. States can be one or many. The output parameter can be either a Map or a script returning an object.\n\nA script can be preferred since a complex object can be set:\n```js\nnext(null, {\n  id: 'state-1',\n  result: {\n    done: true,\n    error: false,\n    skipped: false,\n    timestamp: new Date(),\n    statuscode: 200,\n    statusmessage: 'OK',\n    link: '/',\n    link_text: 'Back to root',\n    user: ''\n  }\n});\n```\n\n\u003e Not all properties of result has to be used\n\n## Process status\n\nInput/Output can also be used to manipulate process status using a parameter named `status`. The status can contain the following properties:\n\nExample Map:\n\n| field name     | type               | description                                                       |\n|----------------|--------------------|-------------------------------------------------------------------|\n| `statuskey`    | (optional) string  | can be one of `start`, `continue`, `complete`, `pause`, or `stop` |\n| `statuscode`   | (optional) integer | HTTP status code                                                  |\n| `statusmessage`| (optional) string  | Status message                                                    |\n| `error`        | (optional) boolean | has the process errored                                           |\n| `data`         | (optional) object  | object with additional data                                       |\n\n\n# ServiceTasks\n\n## `onifyApiRequest(options[, callback])`\n\nMake an Onify API request with the user currently running the flow.\n\nArguments:\n- `options`: a string with the requested URI, or an object with:\n  - `url`: (required) the request URL, accepts relative api URL e.g. `/my/settings` without api version\n  - `query`: (optional) optional object containing search parameters. Will be stringified using node.js built in function `querystring.stringify`\n  - `method`: (optional) the request HTTP method (e.g. `POST`). Defaults to `GET`\n  - `headers`: (optional) an object with optional request headers where each key is the header name and the value is the header content\n    - `authorization`: (optional) override authorization\n  - `throwHttpErrors`: (optional) boolean indicating that non 200 responses will throw an error, defaults to `true`\n  - `payload`: (optional) a string, buffer or object containing the request payload\n\nReturns:\n  - `statusCode`: the HTTP status code\n  - `statusMessage`: the HTTP status message\n  - `headers`: an object containing the headers set\n  - `payload`: the response raw payload\n  - `body`: response body, parsed as JSON\n\n## `onifyElevatedApiRequest(options[, callback])`\n\nSame as `onifyApiRequest` but with admin privilegies.\n\n## `httpRequest(options[, callback])`\n\nMake an external HTTP request. The request library used is [npm module got](https://github.com/sindresorhus/got).\n\nArguments:\n- `options`: required object passed to [got](https://github.com/sindresorhus/got):\n  - `url`: (required) the request URL\n  - `query`: (optional) optional object containing search parameters. Will be stringified using node.js built in function `querystring.stringify`\n  - `method`: (optional) the request HTTP method (e.g. `POST`). Defaults to `GET`\n  - `headers`: (optional) an object with optional request headers where each key is the header name and the value is the header content\n    - `authorization`: (optional) override authorization\n  - `throwHttpErrors`: (optional) boolean indicating that non 200 responses will throw an error, defaults to `true`\n  - `payload`: (optional) a string, buffer or object containing the request payload\n\nReturns:\n  - `statusCode`: the HTTP status code\n  - `statusMessage`: the HTTP status message\n  - `headers`: an object containing the headers set\n  - `body`: response body\n\n# JavaScript\n\nOnify flow supports javascript in a ScriptTask, as SequenceFlow condition, or in Input/Output parameters.\n\n\u003e NB! The flow execution stalls until [next](#nexterr-result) has to be called for the flow to continue.\n\n## Global context\n\nSince script will be sandboxed they have some specific global properties and functions that can be addressed directly or under `this`.\n\nWhen in doubt on where to find your information insert this script:\n\n```js\nconsole.log(this);\nnext();\n```\n\n### `fields`\n\nObject with information regarding the message that executed activity.\n\n### `content`\n\nObject with information of the current running activity.\n\nHere you can find input and/or output that was defined for the activity execution.\n\n### `properties`\n\nObject with properties of the message that executed activity.\n\n### `environment`\n\nFlow execution [environment](https://github.com/paed01/bpmn-elements/blob/master/docs/Environment.md).\n\n\n### `contextName`\n\nName of running flow.\n\n### `next(err, result)`\n\nMust be called when script is completed.\n\n### `Buffer.from(...args)`\n\nNode.js function [Buffer.from](https://nodejs.org/dist/latest-v14.x/docs/api/buffer.html#buffer_buffer_from_buffer_alloc_and_buffer_allocunsafe).\n\nUsefull for encoding and decoding Base64.\n\n#### Encode as base64\n\nExample:\n```js\nBuffer.from('Hello world').toString('base64');\n```\n\n#### Decode base64\n\nExample:\n```js\nBuffer.from('SGVsbG8gd29ybGQ=', 'base64').toString();\n```\n\n### `console.log(...args)`\n\nBasic javascript `console.log('Hello world')`. Write something on stdout. Will end up in console or in a container log.\n\n### `decrypt(encryptedText, encoding = 'hex')`\n\nDecrypt an encrypted text with defined Onify client secret.\n\n### `encrypt(text, encoding = 'hex')`\n\nEncrypt text with defined Onify client secret.\n\n### `jwt.sign(...)`\n\nCreate a signed JWT using [npm module jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) sign function.\n\n### `jwt.verify(...)`\n\nVarify a signed JWT using [npm module jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) verify function.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonify%2Fflow-validator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonify%2Fflow-validator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonify%2Fflow-validator/lists"}