bpmn-client 1.3.2 → 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.
@@ -24,16 +24,23 @@ const question = function (q) {
24
24
  });
25
25
  };
26
26
  completeUserTask();
27
+ function menu() {
28
+ console.log('Commands:');
29
+ console.log(' q to quit');
30
+ console.log(' s start process ');
31
+ console.log(' lo list outstanding items');
32
+ console.log(' li list items');
33
+ console.log(' l list instances for a process');
34
+ console.log(' di display Instance information');
35
+ console.log(' i Invoke Task');
36
+ console.log(' sgl Signal Task');
37
+ console.log(' msg Message Task');
38
+ console.log(' d delete instnaces');
39
+ console.log(' ? repeat this list');
40
+ }
27
41
  function completeUserTask() {
28
42
  return __awaiter(this, void 0, void 0, function* () {
29
- console.log('Commands:');
30
- console.log(' q to quit');
31
- console.log(' s start process ');
32
- console.log(' lo list outstanding items');
33
- console.log(' l list instances for a process');
34
- console.log(' di display Instance information');
35
- console.log(' i invoke item');
36
- console.log(' d delete instnaces');
43
+ menu();
37
44
  let option = '';
38
45
  var command;
39
46
  while (option !== 'q') {
@@ -41,16 +48,23 @@ function completeUserTask() {
41
48
  let opts = command.split(' ');
42
49
  option = opts[0];
43
50
  switch (option) {
51
+ case '?':
52
+ menu();
53
+ break;
44
54
  case 'lo':
45
- console.log("list outstanding items");
55
+ console.log("Listing Outstanding Items");
46
56
  yield findItems({ "items.status": "wait" });
47
57
  break;
48
58
  case 'l':
49
- console.log("list instances");
59
+ console.log("Listing Instances for a Process");
50
60
  yield listInstances();
51
61
  break;
62
+ case 'li':
63
+ console.log("list items");
64
+ yield listItems();
65
+ break;
52
66
  case 'di':
53
- console.log("displaying ");
67
+ console.log("Displaying Instance Details");
54
68
  yield displayInstance();
55
69
  break;
56
70
  case 'i':
@@ -58,9 +72,17 @@ function completeUserTask() {
58
72
  yield invoke();
59
73
  break;
60
74
  case 's':
61
- console.log("starting");
75
+ console.log("Starting Process");
62
76
  yield start();
63
77
  break;
78
+ case 'sgl':
79
+ console.log("Signalling Process");
80
+ yield signal();
81
+ break;
82
+ case 'msg':
83
+ console.log("Message Process");
84
+ yield message();
85
+ break;
64
86
  case 'd':
65
87
  console.log("deleting");
66
88
  yield delInstances();
@@ -75,14 +97,22 @@ function start() {
75
97
  return __awaiter(this, void 0, void 0, function* () {
76
98
  const name = yield question('Please provide your process name: ');
77
99
  let taskData = yield question('Please provide your Task Data (json obj) if any: ');
78
- if (taskData === "") {
79
- taskData = {};
100
+ console.log(taskData);
101
+ try {
102
+ if (taskData === "") {
103
+ taskData = {};
104
+ }
105
+ else {
106
+ taskData = JSON.parse(taskData.toString());
107
+ }
80
108
  }
81
- else {
82
- taskData = JSON.parse(taskData.toString());
109
+ catch (exc) {
110
+ console.log(exc);
111
+ return;
83
112
  }
84
113
  let response = yield server.engine.start(name, taskData);
85
- console.log("Process " + name + " started:", response.items, 'InstanceId', response.id);
114
+ console.log("Process " + name + " started:", 'InstanceId', response.id);
115
+ return yield displayInstance(response.id);
86
116
  });
87
117
  }
88
118
  function findItems(query) {
@@ -95,6 +125,26 @@ function findItems(query) {
95
125
  }
96
126
  });
97
127
  }
128
+ function listItems() {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const answer = yield question('Please items criteria name value pair; example: items.status wait ');
131
+ let str = '' + answer;
132
+ const list = str.split(' ');
133
+ let criteria = {};
134
+ console.log(list);
135
+ for (var i = 0; i < list.length; i += 2) {
136
+ console.log(list[i], list[i + 1]);
137
+ criteria[list[i]] = list[i + 1];
138
+ }
139
+ console.log(criteria);
140
+ var items = yield server.datastore.findItems(criteria);
141
+ console.log(items.length);
142
+ for (var j = 0; j < items.length; j++) {
143
+ let item = items[j];
144
+ console.log(`element: ${item.elementId} status: ${item.status} processName: ${item['processName']} InstanceId: ${item['instanceId']} id: ${item.id}`);
145
+ }
146
+ });
147
+ }
98
148
  function listInstances() {
99
149
  return __awaiter(this, void 0, void 0, function* () {
100
150
  const name = yield question('Please provide your process name: ');
@@ -106,9 +156,10 @@ function listInstances() {
106
156
  }
107
157
  });
108
158
  }
109
- function displayInstance() {
159
+ function displayInstance(instanceId = null) {
110
160
  return __awaiter(this, void 0, void 0, function* () {
111
- const instanceId = yield question('Please provide your Instance ID: ');
161
+ if (instanceId == null)
162
+ instanceId = yield question('Please provide your Instance ID: ');
112
163
  let insts = yield server.datastore.findInstances({ id: instanceId });
113
164
  for (var i = 0; i < insts.length; i++) {
114
165
  let inst = insts[i];
@@ -135,7 +186,8 @@ function invoke() {
135
186
  }
136
187
  try {
137
188
  let response = yield server.engine.invoke({ id: instanceId, "items.elementId": taskId }, taskData);
138
- console.log("Completed UserTask:", taskId, response.items);
189
+ console.log("Completed UserTask:", taskId);
190
+ return yield displayInstance(response.id);
139
191
  }
140
192
  catch (exc) {
141
193
  console.log("Invoking task failed for:", taskId, instanceId);
@@ -143,9 +195,49 @@ function invoke() {
143
195
  }
144
196
  });
145
197
  }
198
+ function signal() {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ const signalId = yield question('Please provide signal ID: ');
201
+ let signalData = yield question('Please provide your Data (json obj) if any: ');
202
+ //if (typeof signalData === 'string' && signalData.trim() === '') {
203
+ if (signalData === "") {
204
+ signalData = {};
205
+ }
206
+ else {
207
+ try {
208
+ signalData = JSON.parse(signalData.toString());
209
+ }
210
+ catch (exc) {
211
+ console.log(exc);
212
+ return;
213
+ }
214
+ }
215
+ let response = yield server.engine.throwSignal(signalId, signalData);
216
+ console.log("Signal Response:", response);
217
+ });
218
+ }
219
+ function message() {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ const messageId = yield question('Please provide message ID: ');
222
+ let messageData = yield question('Please provide your Data (json obj) if any: ');
223
+ if (typeof messageData === 'string' && messageData.trim() === '') {
224
+ messageData = {};
225
+ }
226
+ else {
227
+ messageData = JSON.parse(messageData.toString());
228
+ }
229
+ let response = yield server.engine.throwMessage(messageId, messageData);
230
+ if (response['id'])
231
+ return yield displayInstance(response['id']);
232
+ else {
233
+ console.log(' no results.');
234
+ return null;
235
+ }
236
+ });
237
+ }
146
238
  function delInstances() {
147
239
  return __awaiter(this, void 0, void 0, function* () {
148
- const name = yield question('Please provide process name to delete instnaces: ');
240
+ const name = yield question('Please provide process name to delete instances for process: ');
149
241
  let response = yield server.datastore.deleteInstances({ name: name });
150
242
  console.log("Instances Deleted:", response['result']['deletedCount']);
151
243
  });
@@ -19,15 +19,24 @@ const question = function(q) {
19
19
 
20
20
  completeUserTask();
21
21
 
22
- async function completeUserTask() {
22
+ function menu() {
23
23
  console.log('Commands:');
24
24
  console.log(' q to quit');
25
25
  console.log(' s start process ');
26
26
  console.log(' lo list outstanding items');
27
+ console.log(' li list items');
27
28
  console.log(' l list instances for a process');
28
29
  console.log(' di display Instance information');
29
- console.log(' i invoke item');
30
+ console.log(' i Invoke Task');
31
+ console.log(' sgl Signal Task');
32
+ console.log(' msg Message Task');
30
33
  console.log(' d delete instnaces');
34
+ console.log(' ? repeat this list');
35
+
36
+ }
37
+ async function completeUserTask() {
38
+
39
+ menu();
31
40
 
32
41
  let option='';
33
42
  var command;
@@ -38,16 +47,23 @@ async function completeUserTask() {
38
47
  option=opts[0];
39
48
  switch(option)
40
49
  {
50
+ case '?':
51
+ menu();
52
+ break;
41
53
  case 'lo':
42
- console.log("list outstanding items");
54
+ console.log("Listing Outstanding Items");
43
55
  await findItems({ "items.status": "wait"});
44
56
  break;
45
57
  case 'l':
46
- console.log("list instances");
58
+ console.log("Listing Instances for a Process");
47
59
  await listInstances();
48
60
  break;
61
+ case 'li':
62
+ console.log("list items");
63
+ await listItems();
64
+ break;
49
65
  case 'di':
50
- console.log("displaying ");
66
+ console.log("Displaying Instance Details");
51
67
  await displayInstance();
52
68
  break;
53
69
  case 'i':
@@ -56,9 +72,18 @@ async function completeUserTask() {
56
72
  break;
57
73
 
58
74
  case 's':
59
- console.log("starting");
75
+ console.log("Starting Process");
60
76
  await start();
61
77
  break;
78
+ case 'sgl':
79
+ console.log("Signalling Process");
80
+ await signal();
81
+ break;
82
+ case 'msg':
83
+ console.log("Message Process");
84
+ await message();
85
+ break;
86
+
62
87
  case 'd':
63
88
  console.log("deleting");
64
89
  await delInstances();
@@ -79,15 +104,25 @@ async function start()
79
104
  const name = await question('Please provide your process name: ');
80
105
  let taskData = await question('Please provide your Task Data (json obj) if any: ');
81
106
 
82
- if (taskData === ""){
83
- taskData = {};
84
- }else{
85
- taskData = JSON.parse(taskData.toString());
86
- }
107
+ console.log(taskData);
108
+
109
+ try {
110
+ if (taskData === "") {
111
+ taskData = {};
112
+ } else {
113
+ taskData = JSON.parse(taskData.toString());
114
+ }
115
+
116
+ }
117
+ catch (exc) {
118
+ console.log(exc);
119
+ return;
120
+ }
87
121
 
88
122
  let response=await server.engine.start(name, taskData);
89
123
 
90
- console.log("Process "+name+" started:", response.items,'InstanceId',response.id);
124
+ console.log("Process " + name + " started:", 'InstanceId', response.id);
125
+ return await displayInstance(response.id);
91
126
  }
92
127
  async function findItems(query) {
93
128
  var items = await server.datastore.findItems(query);
@@ -99,6 +134,28 @@ async function findItems(query) {
99
134
  }
100
135
 
101
136
  }
137
+ async function listItems() {
138
+ const answer = await question('Please items criteria name value pair; example: items.status wait ');
139
+ let str=''+ answer;
140
+
141
+ const list = str.split(' ');
142
+ let criteria = {};
143
+ console.log(list);
144
+ for (var i = 0; i < list.length; i += 2) {
145
+ console.log(list[i], list[i + 1]);
146
+ criteria[list[i]] = list[i + 1];
147
+ }
148
+ console.log(criteria);
149
+
150
+ var items = await server.datastore.findItems(criteria)
151
+ console.log(items.length);
152
+
153
+ for (var j = 0; j < items.length; j++) {
154
+ let item = items[j];
155
+ console.log(`element: ${item.elementId} status: ${item.status} processName: ${item['processName']} InstanceId: ${item['instanceId']} id: ${item.id}`);
156
+ }
157
+ }
158
+
102
159
  async function listInstances() {
103
160
  const name = await question('Please provide your process name: ');
104
161
 
@@ -111,8 +168,10 @@ async function listInstances() {
111
168
  }
112
169
  }
113
170
 
114
- async function displayInstance() {
115
- const instanceId = await question('Please provide your Instance ID: ');
171
+ async function displayInstance(instanceId=null) {
172
+
173
+ if (instanceId==null)
174
+ instanceId = await question('Please provide your Instance ID: ');
116
175
 
117
176
  let insts = await server.datastore.findInstances({id: instanceId})
118
177
 
@@ -144,8 +203,9 @@ async function invoke()
144
203
  { id: instanceId, "items.elementId": taskId }
145
204
  , taskData);
146
205
 
147
- console.log("Completed UserTask:", taskId, response.items);
206
+ console.log("Completed UserTask:", taskId);
148
207
 
208
+ return await displayInstance(response.id);
149
209
  }
150
210
  catch (exc) {
151
211
  console.log("Invoking task failed for:", taskId, instanceId);
@@ -154,8 +214,53 @@ async function invoke()
154
214
 
155
215
  }
156
216
  }
217
+
218
+ async function signal() {
219
+ const signalId = await question('Please provide signal ID: ');
220
+
221
+ let signalData = await question('Please provide your Data (json obj) if any: ');
222
+
223
+ //if (typeof signalData === 'string' && signalData.trim() === '') {
224
+ if (signalData === "") {
225
+ signalData = {};
226
+ } else {
227
+ try {
228
+ signalData = JSON.parse(signalData.toString());
229
+ }
230
+ catch (exc) {
231
+ console.log(exc);
232
+ return;
233
+ }
234
+ }
235
+
236
+ let response = await server.engine.throwSignal(signalId, signalData);
237
+
238
+ console.log("Signal Response:", response);
239
+ }
240
+
241
+ async function message() {
242
+ const messageId = await question('Please provide message ID: ');
243
+
244
+ let messageData = await question('Please provide your Data (json obj) if any: ');
245
+
246
+ if (typeof messageData === 'string' && messageData.trim() === '') {
247
+ messageData = {};
248
+ } else {
249
+ messageData = JSON.parse(messageData.toString());
250
+ }
251
+
252
+ let response = await server.engine.throwMessage(messageId, messageData);
253
+
254
+ if (response['id'])
255
+ return await displayInstance(response['id']);
256
+ else {
257
+ console.log(' no results.');
258
+ return null;
259
+ }
260
+ }
261
+
157
262
  async function delInstances() {
158
- const name = await question('Please provide process name to delete instnaces: ');
263
+ const name = await question('Please provide process name to delete instances for process: ');
159
264
 
160
265
  let response = await server.datastore.deleteInstances({ name: name });
161
266
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "bpmn-client",
3
- "version": "1.3.2",
3
+ "version": "1.3.8",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "build": "tsc --build",
7
- "compileRun": "tsc --build && node test.js",
7
+ "compileRun": "tsc --build && node cli.js",
8
8
  "dev": "nodemon -e ts --exec \"npm run compileRun\"",
9
9
  "clean": "tsc --build --clean",
10
- "start": "node test.ts",
10
+ "start": "node cli.ts",
11
11
  "test": "mocha -exit --config=test\\.mocharc.json"
12
12
  },
13
13
  "description": "Client API for BPMN-Server webservices",
package/src/BPMNClient.js CHANGED
@@ -36,8 +36,14 @@ class WebService {
36
36
  data += chunk;
37
37
  });
38
38
  res.on('end', () => {
39
- self.result = JSON.parse(data);
40
- resolve(self.result);
39
+ try {
40
+ self.result = JSON.parse(data);
41
+ resolve(self.result);
42
+ }
43
+ catch (exc) {
44
+ console.log(data);
45
+ console.log(exc);
46
+ }
41
47
  });
42
48
  }).on("error", (err) => {
43
49
  console.log("Error: " + err.message);
@@ -141,9 +147,9 @@ class ClientEngine {
141
147
  return instance;
142
148
  });
143
149
  }
144
- throwMessage(messageId, data) {
150
+ throwMessage(messageId, data = {}, messageMatchingKey = {}) {
145
151
  return __awaiter(this, void 0, void 0, function* () {
146
- const ret = yield this.client.put('engine/throwMessage', { "messageId": messageId, "data": data });
152
+ const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
147
153
  if (ret['errors']) {
148
154
  console.log(ret['errors']);
149
155
  throw new Error(ret['errors']);
@@ -151,9 +157,9 @@ class ClientEngine {
151
157
  return ret;
152
158
  });
153
159
  }
154
- throwSignal(signalId, data) {
160
+ throwSignal(signalId, data = {}, messageMatchingKey = {}) {
155
161
  return __awaiter(this, void 0, void 0, function* () {
156
- const ret = yield this.client.put('engine/throwSignal', { "signalId": signalId, "data": data });
162
+ const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
157
163
  if (ret['errors']) {
158
164
  console.log(ret['errors']);
159
165
  throw new Error(ret['errors']);
package/src/BPMNClient.ts CHANGED
@@ -34,9 +34,14 @@ class WebService {
34
34
  data += chunk;
35
35
  });
36
36
  res.on('end', () => {
37
- self.result = JSON.parse(data);
38
-
39
- resolve(self.result);
37
+ try {
38
+ self.result = JSON.parse(data);
39
+ resolve(self.result);
40
+ }
41
+ catch (exc) {
42
+ console.log(data);
43
+ console.log(exc);
44
+ }
40
45
  });
41
46
 
42
47
 
@@ -132,7 +137,7 @@ class ClientEngine {
132
137
  constructor(client) {
133
138
  this.client = client;
134
139
  }
135
- async start(name, data = {} , startNodeId = null, options = {}): Promise<IInstanceData> {
140
+ async start(name, data = {}, startNodeId = null, options = {}): Promise<IInstanceData> {
136
141
  const ret = await this.client.post('engine/start',
137
142
  { name, data, startNodeId, options });
138
143
  if (ret['errors']) {
@@ -152,16 +157,16 @@ class ClientEngine {
152
157
  return instance;
153
158
  }
154
159
 
155
- async throwMessage(messageId, data) {
156
- const ret = await this.client.put('engine/throwMessage', { "messageId": messageId , "data": data });
160
+ async throwMessage(messageId, data = {} , messageMatchingKey = {}) {
161
+ const ret = await this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
157
162
  if (ret['errors']) {
158
163
  console.log(ret['errors']);
159
164
  throw new Error(ret['errors']);
160
165
  }
161
166
  return ret;
162
167
  }
163
- async throwSignal(signalId, data) {
164
- const ret = await this.client.put('engine/throwSignal', { "signalId": signalId, "data": data });
168
+ async throwSignal(signalId, data = {} , messageMatchingKey = {}) {
169
+ const ret = await this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
165
170
  if (ret['errors']) {
166
171
  console.log(ret['errors']);
167
172
  throw new Error(ret['errors']);
package/test.js CHANGED
@@ -13,8 +13,35 @@ const _1 = require("./");
13
13
  console.log("Testing BPMNClient");
14
14
  const dotenv = require('dotenv');
15
15
  const res = dotenv.config();
16
- console.log(res);
17
- test();
16
+ const server = new _1.BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
17
+ testMessage();
18
+ function displayInstance(instanceId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ let insts = yield server.datastore.findInstances({ id: instanceId });
21
+ for (var i = 0; i < insts.length; i++) {
22
+ let inst = insts[i];
23
+ var items = inst.items;
24
+ console.log(`name: ${inst.name} status: ${inst.status} instanceId: ${inst.id}
25
+ startedAt: ${inst.startedAt} endedAt ${inst.endedAt}`, 'data:', inst.data);
26
+ for (var j = 0; j < items.length; j++) {
27
+ let item = items[j];
28
+ console.log(`element: ${item.elementId} status: ${item.status} id: ${item.id}`);
29
+ }
30
+ }
31
+ });
32
+ }
33
+ function testMessage() {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ const messageId = 'Message-104';
36
+ let messageData = {};
37
+ console.log('calling');
38
+ let response = yield server.engine.throwMessage(messageId, messageData);
39
+ if (response['id'])
40
+ return yield displayInstance(response['id']);
41
+ else
42
+ return null;
43
+ });
44
+ }
18
45
  function test() {
19
46
  return __awaiter(this, void 0, void 0, function* () {
20
47
  const server = new _1.BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
package/test.ts CHANGED
@@ -5,8 +5,40 @@ console.log("Testing BPMNClient");
5
5
  const dotenv = require('dotenv');
6
6
  const res = dotenv.config();
7
7
 
8
- console.log(res);
9
- test();
8
+ const server = new BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
9
+
10
+ testMessage();
11
+
12
+ async function displayInstance(instanceId) {
13
+
14
+ let insts = await server.datastore.findInstances({ id: instanceId })
15
+
16
+ for (var i = 0; i < insts.length; i++) {
17
+ let inst = insts[i];
18
+ var items = inst.items;
19
+ console.log(`name: ${inst.name} status: ${inst.status} instanceId: ${inst.id}
20
+ startedAt: ${inst.startedAt} endedAt ${inst.endedAt}`, 'data:', inst.data);
21
+ for (var j = 0; j < items.length; j++) {
22
+ let item = items[j];
23
+ console.log(`element: ${item.elementId} status: ${item.status} id: ${item.id}`);
24
+ }
25
+ }
26
+ }
27
+
28
+
29
+ async function testMessage() {
30
+ const messageId = 'Message-104';
31
+
32
+ let messageData = {};
33
+
34
+ console.log('calling');
35
+ let response = await server.engine.throwMessage(messageId, messageData);
36
+ if (response['id'])
37
+ return await displayInstance(response['id']);
38
+ else
39
+ return null;
40
+ }
41
+
10
42
 
11
43
  async function test() {
12
44