0.17.0 • Published 9 months ago

bpmn-middleware v0.17.0

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

bpmn-middleware

BuildCoverage Status

Express middleware for BPMN engine.

Under construction so breaking changes will occur until v1.

Usage

import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';

import express from 'express';
import { Broker } from 'smqp';
import { LRUCache } from 'lru-cache';
import { extensions, OnifySequenceFlow, extendFn } from '@onify/flow-extensions';
import * as bpmnElements from 'bpmn-elements';

import { bpmnEngineMiddleware, HttpError, MemoryAdapter } from 'bpmn-middleware';
import { factory as ScriptsFactory } from './example/middleware-scripts.js';

const isMainModule = process.argv[1] === fileURLToPath(import.meta.url);

const nodeRequire = createRequire(import.meta.url);

const camunda = nodeRequire('camunda-bpmn-moddle/resources/camunda.json');

const elements = {
  ...bpmnElements,
  SequenceFlow: OnifySequenceFlow,
};

const app = express();
const adapter = new MemoryAdapter();
const broker = (app.locals.broker = new Broker(app));
const engineCache = (app.locals.engineCache = new LRUCache({ max: 1000 }));

broker.assertExchange('event', 'topic', { durable: false, autoDelete: false });

const middleware = bpmnEngineMiddleware({
  adapter,
  broker,
  engineCache,
  Scripts: ScriptsFactory,
  engineOptions: {
    moddleOptions: { camunda },
    elements,
    extensions: { onify: extensions },
    extendFn,
  },
});

app.use('/rest', middleware);

app.use(errorHandler);

if (isMainModule) {
  app.listen(3000);
}

export { app };

function errorHandler(err, req, res, next) {
  if (!(err instanceof Error)) return next();
  if (isMainModule) console.log({ err });
  if (err instanceof HttpError) return res.status(err.statusCode).send({ message: err.message });
  res.status(502).send({ message: err.message });
}

Debug

Debug by DEBUG=bpmn-middleware, or on windows $env:DEBUG='bpmn-middleware'. To be more verbose use DEBUG=bpmn*, that will display the whole shebang.

0.17.0

9 months ago

0.16.0

10 months ago

0.16.1

10 months ago

0.15.2

10 months ago

0.15.0

10 months ago

0.15.1

10 months ago

0.13.0

10 months ago

0.14.0

10 months ago

0.11.0

10 months ago

0.12.0

10 months ago

0.10.0

11 months ago

0.9.0

12 months ago

0.8.0

12 months ago

0.7.0

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.1.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago