@honeybpm/hbpm
v0.6.0
Published
A simple business process management tool written for NodeJS
Downloads
33
Maintainers
Readme
A BPM (Business Process Management) framework to run business processes in a consistent and reusable way.
Installation
npm install @honeybpm/hbpm
HoneyBPM is a simple process runner to allow developers to create business process which are built with reusable components. They do this by defining a ProcessMap made up of various Steps. Each Step runs a small piece of code called a Vertex.
Getting Started
The goal of HoneyBPM is to allow developers to make business processes in a component-based and standardized way. They do this by defining a ProcessMap made up of various Steps. Each Step runs a piece of code called a Vertex.
Your First Process Map
Let's make our first process. One that calculates tax rate for a value.
// todo: Add a process map code
Vertex
A Vertex is the smallest piece of a HoneyBPM process. Vertices should be reusable across many processes. There are two types of vertices, VertexSync and VertexAsync.
Vertex Sync
VertexSync is a vertex which will run to completion, as opposed to VertexAsync which allows you escape the vertex in the midst of a process and return to it later.
Creation
To create a VertexSync
pass a name, and run middleware into the constructor.
let SomeSyncVertex = new VertexSync({
name: "VertexA",
description: "This vertex doesn't do anything useful",
run: function(data, context,next) {
console.log("Ran SyncVertex");
return next();
}
});
Using in a Step
To use in a step, pass the vertex into the step constructor as the vertex
.
let SomeStep = new Step({
name: "SomeStepName",
description: "Some description of this step",
vertex: SomeSyncVertex
});
Vertex Async
A VertexAsync is a vertex which you are able to leave and then return to at some point in a process map.
Creation
To create a VertexSync
pass a name, and run middleware into the constructor.
let SomeAsyncVertex = new VertexAsync({
name: "VertexA",
description: "This vertex doesn't do anything useful",
runAsync: function(data, context, next) {
console.log("The vertex runs this function when you are running a process, after next() is called the process will stop");
return next();
},
continueAsync: function(data, context,next) {
console.log("Then when the process is continued this function will run");
return next();
}
});
Uses
VertexAsync is useful for in processes which required user intervention. For example, you could have a VertexAsync
create a task for a user to complete and then continue the process after they complete it.
let TaskVertex = new VertexAsync({
name: "TaskVertex",
description: "A vertex for a task",
runAsync: function(data, context, next) {
// some code to write a task to a database...
// write the taskId to the processes data so you can use it when you continue the process
data.taskId = task.id;
return next();
},
continueAsync: function(data, context,next) {
let taskId = data.taskId;
// code to find and complete the task using the data passed into the process
return next();
}
});
Using in a Step
To use in a step, pass the vertex into the step constructor as the vertex
.
let SomeStep = new Step({
name: "SomeStepName",
description: "Some description of this step",
vertex: SomeAsyncVertex
});
Steps
Creating
'use strict';
const hbpm = require('@honeybpm/hbpm');
const logStep = new hbpm.Step({
name: "LogStep",
inputMapping: function (processData, done) {
let inputData = {};
inputData.title = "DDD";
inputData.user = "Test";
return done(null, inputData);
},
outputMapping: function (processData, stepData, done) {
processData.a = "A";
return done();
},
vertex: LogVertex
});
inputMapping
inputMapping: function(processData, done)
inputMapping is a function which has processData and a done callback. You pass the data you want the vertex to the done callback as the second parameter (the first is an error).
outputMapping
outputMapping: function(processData, stepData, done)
outputMapping is a function which has processData, stepData, and a done callback. You don't need to pass anything to done.
Process Map
A process map is the structure of a business process and made up of various steps linked together with a to
function which declares which step to run next.