Express middleware for BPMN engine.
Under construction so breaking changes will occur until v1.
import express from 'express';
import { bpmnEngineMiddleware, HttpError } from 'bpmn-express-middleware';
const app = express();
app.use('/rest', bpmnEngineMiddleware({ idleTimeout: 90000 }));
app.use(errorHandler);
app.listen(3000);
function errorHandler(err, req, res, next) {
if (!(err instanceof Error)) return next();
if (err instanceof HttpError) return res.status(err.statusCode).send({ message: err.message });
res.status(502).send({ message: err.message });
}
Create BPMN engine middleware.
Options:
adapter
: Optional storage adapter. Defaults to in-memory adapter based on LRU cacheengineOptions
: Optional BPMN Engine optionsengineCache
: Optional engine LRU cache, defaults tonew LRUCache({ max: 1000 })
broker
: Optional smqp broker, used for forwarding events from executing enginesidleTimeout
: Optional positive integer, engine execution timeout in milliseconds before engine execution is considered idle and is stopped, defaults to 120000ms
Returns Expressjs Router with extra properties:
middleware
: middleware route functionsengines
: BPMN engines handler
GET (*)?/version
GET (*)?/deployment
POST (*)?/deployment/create
POST (*)?/process-definition/:deploymentName/start
GET (*)?/running
GET (*)?/status/:token
GET (*)?/status/:token/:activityId
POST (*)?/resume/:token
POST (*)?/signal/:token
POST (*)?/cancel/:token
POST (*)?/fail/:token
GET (*)?/state/:token
DELETE (*)?/state/:token
DELETE (*)?/internal/stop
DELETE (*)?/internal/stop/:token
Get app version.
Response body:
version
: string, resolved fromprocess.cwd() + '/package.json
Get app name.
Response body:
name
: string, resolved fromprocess.cwd() + '/package.json
Create deployment by passing multipart form with BPMN diagram file.
Content-type: multipart/form-data
Form fields:
deployment-name
: string, deployment name;deployment-source
: string, deployment source;
Response body:
id
: string, same as deployment namedeploymentTime
: date, nowdeployedProcessDefinitions
: object[deploymentName]
: object, key as deployment nameid
: string, same as deployment name
Start deployment.
Params:
deploymentName
: deployment name
Request body:
businessKey
: string, business keyvariables
: optional object with variables to pass to engine
Response body:
id
: string, unique execution token
Get all running instances.
Response body:
engines
: list of executing enginestoken
: string, unique execution tokenname
: string, deployment namestate
: string, engine status,idle
,running
,stopped
, orerror
activityStatus
: string, running activity status,idle
,executing
,timer
, orwait
Get process status
Get process activity status
Resume process run
Signal process activity.
Request body:
id
: activity idexecutionId
: optional activity execution idmessage
: optional message to signal activity with
Cancel process activity.
Request body:
id
: activity idexecutionId
: optional activity execution id
Fail process activity.
Request body:
id
: activity idexecutionId
: optional activity execution idmessage
: optional message to send to activity
Get process engine state.
Delete process engine state.
Stop all running instances on this specific app instance.
Stop running instances by token on this specific app instance.
BPMN Engine will forward BPMN engine events to app prefixed by bpmn/
.
BPMN Engine has completed successfully.
Handler arguments:
engine
: Engine instance
BPMN Engine execution has stopped.
Handler arguments:
engine
: Engine instance
BPMN Engine execution has failed.
Handler arguments:
err
: Errorengine
: Engine instance
Persistent storage adapter, defaults to in memory storage.
Three types will be saved to adapter:
deployment
: BPMN deployment with references to BPMN filesfile
: BPMN file with meta and contentstate
: BPMN engine state
Set entry with key.
type
: string, storage type,deployment
,file
, orstate
key
: string, storage keyvalue
: object, valueoptions
: optional object with options
Delete entry by key.
type
: string, storage type,deployment
,file
, orstate
key
: string, storage key
Fetch entry by key.
type
: string, storage type,deployment
,file
, orstate
key
: string, storage keyoptions
: optional object with optionsexclude
: optional list of fields to exclude
Query entries.
type
: string, storage type,deployment
,file
, orstate
qs
: object, storage queryexclude
: optional list of fields to excludestate
: optional string, get engine states by state of engine,idle
,running
, etccaller
: optional object, get engines by call activity callertoken
: string, calling process tokendeployment
: string, calling process deployment nameid
: string, calling activity idtype
: string, calling activity typeexecutionId
: string, calling activity execution id
options
: optional object with options
Returns:
records
: List of entries