bpmn-client 1.2.1 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Sample/package.json +44 -44
- package/cli.js +244 -0
- package/cli.ts +268 -0
- package/demo.env +4 -0
- package/local.env +4 -0
- package/monitor.js +91 -0
- package/monitor.ts +100 -0
- package/package.json +5 -8
- package/src/BPMNClient.js +26 -9
- package/src/BPMNClient.ts +26 -11
- package/test/.mocharc.json +12 -0
- package/test/feature/.env +1 -3
- package/test/feature/carServer.js +9 -4
- package/test.env +4 -0
- package/test.js +45 -2
- package/test.ts +56 -3
- package/test2.js +70 -249
- package/test3.js +42 -0
- package/test3.ts +40 -0
- package/test/mocha.opts +0 -5
- package/test/resources/Invoice.js +0 -91
- package/test/resources/car.js +0 -69
- package/test/resources/loop.js +0 -50
- package/test2.ts +0 -326
package/test2.ts
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
//import { BPMNClient } from './';
|
|
2
|
-
//import { BPMNServer, IInstanceData, IItemData } from './';
|
|
3
|
-
|
|
4
|
-
import { BPMNServer, IDefinition, IInstanceData, IItemData } from '../WebApp/';
|
|
5
|
-
|
|
6
|
-
const dotenv = require('dotenv');
|
|
7
|
-
const res = dotenv.config();
|
|
8
|
-
|
|
9
|
-
console.log("Testing BPMNClient 2");
|
|
10
|
-
|
|
11
|
-
const https = require('https');
|
|
12
|
-
const http = require('http');
|
|
13
|
-
|
|
14
|
-
class WebService {
|
|
15
|
-
statusCode;
|
|
16
|
-
result;
|
|
17
|
-
constructor() {}
|
|
18
|
-
async invoke(params, options) {
|
|
19
|
-
|
|
20
|
-
var driver = http;
|
|
21
|
-
var body = JSON.stringify(params);
|
|
22
|
-
|
|
23
|
-
console.log(options, params);
|
|
24
|
-
if (options.port == 443)
|
|
25
|
-
driver = https;
|
|
26
|
-
|
|
27
|
-
let data = '';
|
|
28
|
-
let self = this;
|
|
29
|
-
return new Promise(function (resolve, reject) {
|
|
30
|
-
try {
|
|
31
|
-
|
|
32
|
-
driver.request(options, function (res) {
|
|
33
|
-
console.log('STATUS: ' + res.statusCode);
|
|
34
|
-
//console.log(res);
|
|
35
|
-
self.statusCode = res.statusCode;
|
|
36
|
-
res.setEncoding('utf8');
|
|
37
|
-
res.on('data', function (chunk) {
|
|
38
|
-
data += chunk;
|
|
39
|
-
});
|
|
40
|
-
res.on('end', () => {
|
|
41
|
-
self.result = JSON.parse(data);
|
|
42
|
-
|
|
43
|
-
resolve(self.result);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}).on("error", (err) => {
|
|
48
|
-
console.log("Error: " + err.message);
|
|
49
|
-
reject(err);
|
|
50
|
-
}).end(body);
|
|
51
|
-
}
|
|
52
|
-
catch (exc) {
|
|
53
|
-
console.log(exc);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
class BPMNClient extends WebService {
|
|
61
|
-
host;
|
|
62
|
-
port;
|
|
63
|
-
apiKey;
|
|
64
|
-
engine: ClientEngine;
|
|
65
|
-
datastore: ClientDatastore;
|
|
66
|
-
definitions: ClientDefinitions;
|
|
67
|
-
constructor(host, port, apiKey) {
|
|
68
|
-
super();
|
|
69
|
-
this.host = host;
|
|
70
|
-
this.port = port;
|
|
71
|
-
this.apiKey = apiKey;
|
|
72
|
-
this.engine = new ClientEngine(this);
|
|
73
|
-
this.datastore = new ClientDatastore(this);
|
|
74
|
-
this.definitions = new ClientDefinitions(this);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async get(url, data = {}) {
|
|
78
|
-
return await this.request(url, 'GET', data);
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
async post(url, data = {}) {
|
|
82
|
-
return await this.request(url, 'POST', data);
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
async put(url, data = {}) {
|
|
86
|
-
return await this.request(url, 'PUT', data);
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
async del(url, data = {}) {
|
|
90
|
-
return await this.request(url, 'DELETE', data);
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
async request(url, method, params) {
|
|
94
|
-
|
|
95
|
-
var body = JSON.stringify(params);
|
|
96
|
-
|
|
97
|
-
var options;
|
|
98
|
-
|
|
99
|
-
if (params) {
|
|
100
|
-
options = {
|
|
101
|
-
host: this.host,
|
|
102
|
-
port: this.port,
|
|
103
|
-
path: '/api/' + url,
|
|
104
|
-
method: method,
|
|
105
|
-
headers: {
|
|
106
|
-
"Content-Type": "application/json",
|
|
107
|
-
"x-api-key": this.apiKey,
|
|
108
|
-
"Accept": "*/*",
|
|
109
|
-
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
110
|
-
// "Accept-Encoding": "gzip, deflate, br",
|
|
111
|
-
"Connection": "keep-alive",
|
|
112
|
-
"Content-Length": Buffer.byteLength(body)
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
options = {
|
|
118
|
-
host: this.host,
|
|
119
|
-
port: this.port,
|
|
120
|
-
path: '/api/' + url,
|
|
121
|
-
method: method
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return await this.invoke(params, options);
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
class ClientEngine {
|
|
133
|
-
private client: BPMNClient;
|
|
134
|
-
|
|
135
|
-
constructor(client) {
|
|
136
|
-
this.client = client;
|
|
137
|
-
}
|
|
138
|
-
async start(name, data): Promise<IInstanceData>{
|
|
139
|
-
const ret = await this.client.post('engine/start', { name, data });
|
|
140
|
-
if (ret['errors']) {
|
|
141
|
-
console.log(ret['errors']);
|
|
142
|
-
throw new Error(ret['errors']);
|
|
143
|
-
}
|
|
144
|
-
const instance = ret as IInstanceData;
|
|
145
|
-
return instance;
|
|
146
|
-
}
|
|
147
|
-
async invoke(query, data): Promise<IInstanceData> {
|
|
148
|
-
const ret = await this.client.put('engine/invoke', { query, data });
|
|
149
|
-
if (ret['errors']) {
|
|
150
|
-
console.log(ret['errors']);
|
|
151
|
-
throw new Error(ret['errors']);
|
|
152
|
-
}
|
|
153
|
-
const instance = ret['instance'] as IInstanceData;
|
|
154
|
-
return instance;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async get(query): Promise<IInstanceData> {
|
|
158
|
-
const ret=await this.client.get('engine/get', query);
|
|
159
|
-
if (ret['errors']) {
|
|
160
|
-
console.log(ret['errors']);
|
|
161
|
-
throw new Error(ret['errors']);
|
|
162
|
-
}
|
|
163
|
-
const instance = ret['instance'] as IInstanceData;
|
|
164
|
-
return instance;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
class ClientDatastore {
|
|
168
|
-
private client: BPMNClient;
|
|
169
|
-
|
|
170
|
-
constructor(client) {
|
|
171
|
-
this.client = client;
|
|
172
|
-
}
|
|
173
|
-
async findItems(query) : Promise<IItemData []>{
|
|
174
|
-
var res = await this.client.get('datastore/findItems', query);
|
|
175
|
-
if (res['errors']) {
|
|
176
|
-
console.log(res['errors']);
|
|
177
|
-
throw new Error(res['errors']);
|
|
178
|
-
}
|
|
179
|
-
const items = res['items'] as IItemData[];
|
|
180
|
-
return items;
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
async findInstances(query) : Promise<IInstanceData []> {
|
|
184
|
-
const res = await this.client.get('datastore/findInstances', query);
|
|
185
|
-
if (res['errors']) {
|
|
186
|
-
console.log(res['errors']);
|
|
187
|
-
throw new Error(res['errors']);
|
|
188
|
-
}
|
|
189
|
-
const instances = res['instances'] as IInstanceData[];
|
|
190
|
-
return instances;
|
|
191
|
-
}
|
|
192
|
-
async deleteInstances(query) {
|
|
193
|
-
return await this.client.del('datastore/delete', query);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
class ClientDefinitions {
|
|
197
|
-
private client: BPMNClient;
|
|
198
|
-
|
|
199
|
-
constructor(client) {
|
|
200
|
-
this.client = client;
|
|
201
|
-
}
|
|
202
|
-
async list(): Promise<string[]> {
|
|
203
|
-
var res = await this.client.get('definitions/list', []);
|
|
204
|
-
if (res['errors']) {
|
|
205
|
-
console.log(res['errors']);
|
|
206
|
-
throw new Error(res['errors']);
|
|
207
|
-
}
|
|
208
|
-
return res as string[];
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
async load(name): Promise<IDefinition> {
|
|
212
|
-
const res = await this.client.get(encodeURI('definitions/load/'+name), {name:name} );
|
|
213
|
-
if (res['errors']) {
|
|
214
|
-
console.log(res['errors']);
|
|
215
|
-
throw new Error(res['errors']);
|
|
216
|
-
}
|
|
217
|
-
console.log(res);
|
|
218
|
-
return res as IDefinition;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
test();
|
|
225
|
-
|
|
226
|
-
async function test() {
|
|
227
|
-
|
|
228
|
-
const API_KEY = '12345';
|
|
229
|
-
const HOST = 'test.omniworkflow.com';
|
|
230
|
-
const PORT = '443';
|
|
231
|
-
|
|
232
|
-
// const HOST = 'localhost';
|
|
233
|
-
// const PORT = '3000';
|
|
234
|
-
|
|
235
|
-
const BASE_URL = 'api';
|
|
236
|
-
|
|
237
|
-
//const client = new BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
238
|
-
|
|
239
|
-
const client = new BPMNClient(HOST, PORT, API_KEY);
|
|
240
|
-
|
|
241
|
-
const server = client;
|
|
242
|
-
const caseId = 3040;
|
|
243
|
-
|
|
244
|
-
var defs = await server.definitions.list();
|
|
245
|
-
|
|
246
|
-
console.log(defs);
|
|
247
|
-
var def = await server.definitions.load('Buy Used Car');
|
|
248
|
-
|
|
249
|
-
console.log(def['elements']);
|
|
250
|
-
|
|
251
|
-
//var instance = await client.engine.start("Buy Used Car", {});
|
|
252
|
-
|
|
253
|
-
var instance = await server.engine.start("Buy Used Car", { caseId: caseId });
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
console.log("instance.id", instance.id, instance.name, instance.status, instance.data.caseId);
|
|
257
|
-
|
|
258
|
-
var response = await server.engine.invoke(
|
|
259
|
-
{ id: instance.id, "items.elementId": 'task_Buy' }
|
|
260
|
-
, { needsCleaning: "Yes", needsRepairs: "Yes" });
|
|
261
|
-
|
|
262
|
-
console.log('after buy', response.id, response.data);
|
|
263
|
-
|
|
264
|
-
response = await server.engine.invoke(
|
|
265
|
-
{ id: instance.id, "items.elementId": 'task_clean' }
|
|
266
|
-
, {});
|
|
267
|
-
|
|
268
|
-
console.log('after clean', response.id, response.data);
|
|
269
|
-
|
|
270
|
-
response = await server.engine.invoke(
|
|
271
|
-
{ id: instance.id, "items.elementId": 'task_repair' }
|
|
272
|
-
, {});
|
|
273
|
-
|
|
274
|
-
console.log('after repair', response.id, response.data);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
try {
|
|
278
|
-
response = await server.engine.invoke(
|
|
279
|
-
{ id: instance.id, "items.elementId": 'task_Drive' }
|
|
280
|
-
, {});
|
|
281
|
-
|
|
282
|
-
console.log('after drive', response.id, response.data);
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
catch (exc) {
|
|
286
|
-
console.log(exc);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var insts = await client.datastore.findInstances({ data: { caseId: caseId } });
|
|
292
|
-
|
|
293
|
-
insts.forEach(inst => {
|
|
294
|
-
console.log('Inst for CaseId id==>' + inst.id, inst.name, inst.data.caseId, 'status==>', inst.status);
|
|
295
|
-
});
|
|
296
|
-
var insts = await client.datastore.findInstances({ id: instance.id });
|
|
297
|
-
|
|
298
|
-
insts.forEach(inst => {
|
|
299
|
-
for (var i = 0; i < inst.items.length; i++) {
|
|
300
|
-
var item = inst.items[i];
|
|
301
|
-
console.log(' item: elementId==>' + item.elementId, item.name, 'status==>', item.status);
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
var inst = await client.engine.get( { id: instance.id });
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
for (var i = 0; i < inst.items.length; i++) {
|
|
310
|
-
var item = inst.items[i];
|
|
311
|
-
console.log(' item: elementId==>' + item.elementId, item.name, 'status==>', item.status);
|
|
312
|
-
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// var items = await client.datastore.findItems({ query: { "items.elementId": "task_Buy" } });
|
|
318
|
-
var items = await client.datastore.findItems({ id: instance.id} );
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
items.forEach(item => {
|
|
322
|
-
console.log('item: id==>' + item.elementId,item.type, item.name, 'status==>', item.status);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
|