bpmn-client
这是一个允许远程访问的轻量级包 bpmn-server
安装
在调用bpmn-server的应用程序中(一个新文件夹,或一个现有的Node.js项目):
npm init -y && npm pkg set type=module # a new project; skip in an existing one
npm install bpmn-client
npx bpmn-client-setup # writes .env: API_KEY, HOST, PORT
集 .env 对服务器: API_KEY 服务器的(从它的? .env; ADMIN_API_KEY 同样,对于模型
管理), HOST 和 PORT 它跑的地方。然后:
npx bpmn-client-cli # a console on the server: start processes, list and invoke items
一个完整的示例应用程序: bpmn-client-sample.
更新到最新版本
$ npm update bpmn-client
使用
import { BPMNClient2 } from 'bpmn-client';
// apiKey: the server's API_KEY; adminApiKey (optional): its ADMIN_API_KEY, for model administration
const client = new BPMNClient2('localhost', 3000, process.env.API_KEY, { adminApiKey: process.env.ADMIN_API_KEY });
const instance = await client.engine.start('Buy Used Car', { caseId: 1001 });
const items = await client.data.findItems({ id: instance.id, 'items.status': 'wait' });
await client.engine.invoke({ id: instance.id, 'items.elementId': 'task_Buy' }, { needsRepairs: 'Yes' });
const models = await client.model.list(); // /admin/api2, with the admin key
BPMNClient 是遗产的客户吗 /api (其 definitions 和 datastore.deleteInstances
去 /admin/api 使用管理键)。
错误
当每个调用失败时,都会拒绝它,并伴随着服务器的消息:
- HTTP错误:
"<status> <message>",如。401 missing or invalid "x-api-key"(error.status保持状态); - 服务器在其应答(
{ errors }或者{ error }),如。No process definition named X; - 一个网页而不是API(错误的主机,端口或路径);
- 无法连接到服务器时的连接错误(例如:
ECONNREFUSED)。
权限
API密钥代表服务器上的一个服务帐户(API_SERVICE_USER_NAME/_GROUPS):
信息,信号和原始 data.find 需要它 SYSTEM 集团;删除实例和模型
政府需要 ADMIN.
测试
npm test # build, unit tests, contract tests
npm run test:unit # what each method sends and how answers and failures come back (no server)
npm run test:contract # every method against a real bpmn-web (BPMN_WEB_DIR, default ../bpmn-web, built;
# uses bpmn-web's test harness and a MongoDB of its own; skipped without it)
npm run test:live # the older scenarios against a running server (localhost:3000, key 12345)