bpmn-client 1.3.2 → 1.3.15
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/{testCLI.js → cli.js} +113 -21
- package/{testCLI.ts → cli.ts} +121 -16
- package/package.json +3 -3
- package/remote-import.js +97 -0
- package/remote-import.ts +116 -0
- package/src/BPMNClient.js +101 -20
- package/src/BPMNClient.ts +119 -23
- package/src/interfaces/Enums.js +5 -2
- package/src/interfaces/Enums.ts +16 -5
- package/test.js +52 -2
- package/test.ts +62 -2
package/{testCLI.js → cli.js}
RENAMED
|
@@ -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
|
-
|
|
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("
|
|
55
|
+
console.log("Listing Outstanding Items");
|
|
46
56
|
yield findItems({ "items.status": "wait" });
|
|
47
57
|
break;
|
|
48
58
|
case 'l':
|
|
49
|
-
console.log("
|
|
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("
|
|
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("
|
|
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
|
-
|
|
79
|
-
|
|
100
|
+
console.log(taskData);
|
|
101
|
+
try {
|
|
102
|
+
if (taskData === "") {
|
|
103
|
+
taskData = {};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
taskData = JSON.parse(taskData.toString());
|
|
107
|
+
}
|
|
80
108
|
}
|
|
81
|
-
|
|
82
|
-
|
|
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:",
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
});
|
package/{testCLI.ts → cli.ts}
RENAMED
|
@@ -19,15 +19,24 @@ const question = function(q) {
|
|
|
19
19
|
|
|
20
20
|
completeUserTask();
|
|
21
21
|
|
|
22
|
-
|
|
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
|
|
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("
|
|
54
|
+
console.log("Listing Outstanding Items");
|
|
43
55
|
await findItems({ "items.status": "wait"});
|
|
44
56
|
break;
|
|
45
57
|
case 'l':
|
|
46
|
-
console.log("
|
|
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("
|
|
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("
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "1.3.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --build",
|
|
7
|
-
"compileRun": "tsc --build && node
|
|
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
|
|
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/remote-import.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
//FromPostMan();
|
|
13
|
+
//request('test4', 'Trans.bpmn');
|
|
14
|
+
const _1 = require("./");
|
|
15
|
+
fromClientLib();
|
|
16
|
+
//FromPostMan();
|
|
17
|
+
function fromClientLib() {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const server = new _1.BPMNClient('localhost', 3000, '1234');
|
|
20
|
+
var name = 'test-import';
|
|
21
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
22
|
+
server.definitions.import(name, file);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function FromPostMan() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
console.log("Testing Remote import");
|
|
28
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
29
|
+
var http = require('follow-redirects').http;
|
|
30
|
+
var fs = require('fs');
|
|
31
|
+
var options = {
|
|
32
|
+
'method': 'POST',
|
|
33
|
+
'hostname': 'localhost',
|
|
34
|
+
'port': 3000,
|
|
35
|
+
'path': '/api/definitions/import/testing3',
|
|
36
|
+
'headers': {
|
|
37
|
+
'x-api-key': '12345',
|
|
38
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
39
|
+
},
|
|
40
|
+
'maxRedirects': 20
|
|
41
|
+
};
|
|
42
|
+
var req = http.request(options, function (res) {
|
|
43
|
+
var chunks = [];
|
|
44
|
+
res.on("data", function (chunk) {
|
|
45
|
+
chunks.push(chunk);
|
|
46
|
+
});
|
|
47
|
+
res.on("end", function (chunk) {
|
|
48
|
+
var body = Buffer.concat(chunks);
|
|
49
|
+
console.log(body.toString());
|
|
50
|
+
});
|
|
51
|
+
res.on("error", function (error) {
|
|
52
|
+
console.error(error);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"Trans.bpmn\"\r\nContent-Type: \"text/plain\"\r\n\r\n" + fs.readFileSync(file) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
56
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
57
|
+
req.write(postData);
|
|
58
|
+
req.end();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function request(name, path) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
console.log("Testing Request");
|
|
64
|
+
var http = require('http');
|
|
65
|
+
var fs = require('fs');
|
|
66
|
+
var options = {
|
|
67
|
+
'method': 'POST',
|
|
68
|
+
'hostname': 'localhost',
|
|
69
|
+
'port': 3000,
|
|
70
|
+
'path': '/api/definitions/import/' + name,
|
|
71
|
+
'headers': {
|
|
72
|
+
'x-api-key': '12345',
|
|
73
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
74
|
+
},
|
|
75
|
+
'maxRedirects': 20
|
|
76
|
+
};
|
|
77
|
+
var req = http.request(options, function (res) {
|
|
78
|
+
var chunks = [];
|
|
79
|
+
res.on("data", function (chunk) {
|
|
80
|
+
chunks.push(chunk);
|
|
81
|
+
});
|
|
82
|
+
res.on("end", function (chunk) {
|
|
83
|
+
var body = Buffer.concat(chunks);
|
|
84
|
+
console.log(body.toString());
|
|
85
|
+
});
|
|
86
|
+
res.on("error", function (error) {
|
|
87
|
+
console.error(error);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
|
|
91
|
+
+ path + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
|
|
92
|
+
fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
93
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
94
|
+
req.write(postData);
|
|
95
|
+
req.end();
|
|
96
|
+
});
|
|
97
|
+
}
|
package/remote-import.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
|
|
2
|
+
//FromPostMan();
|
|
3
|
+
//request('test4', 'Trans.bpmn');
|
|
4
|
+
import { BPMNClient } from './';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
fromClientLib();
|
|
9
|
+
//FromPostMan();
|
|
10
|
+
|
|
11
|
+
async function fromClientLib() {
|
|
12
|
+
const server = new BPMNClient('localhost', 3000, '1234');
|
|
13
|
+
|
|
14
|
+
var name = 'test-import';
|
|
15
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
16
|
+
|
|
17
|
+
server.definitions.import(name, file);
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
async function FromPostMan() {
|
|
21
|
+
|
|
22
|
+
console.log("Testing Remote import");
|
|
23
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var http = require('follow-redirects').http;
|
|
27
|
+
var fs = require('fs');
|
|
28
|
+
|
|
29
|
+
var options = {
|
|
30
|
+
'method': 'POST',
|
|
31
|
+
'hostname': 'localhost',
|
|
32
|
+
'port': 3000,
|
|
33
|
+
'path': '/api/definitions/import/testing3',
|
|
34
|
+
'headers': {
|
|
35
|
+
'x-api-key': '12345',
|
|
36
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
37
|
+
},
|
|
38
|
+
'maxRedirects': 20
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
var req = http.request(options, function (res) {
|
|
42
|
+
var chunks = [];
|
|
43
|
+
|
|
44
|
+
res.on("data", function (chunk) {
|
|
45
|
+
chunks.push(chunk);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
res.on("end", function (chunk) {
|
|
49
|
+
var body = Buffer.concat(chunks);
|
|
50
|
+
console.log(body.toString());
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
res.on("error", function (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"Trans.bpmn\"\r\nContent-Type: \"text/plain\"\r\n\r\n" + fs.readFileSync(file) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
59
|
+
|
|
60
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
61
|
+
|
|
62
|
+
req.write(postData);
|
|
63
|
+
|
|
64
|
+
req.end();
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
async function request(name,path) {
|
|
70
|
+
|
|
71
|
+
console.log("Testing Request");
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
var http = require('http');
|
|
75
|
+
var fs = require('fs');
|
|
76
|
+
|
|
77
|
+
var options = {
|
|
78
|
+
'method': 'POST',
|
|
79
|
+
'hostname': 'localhost',
|
|
80
|
+
'port': 3000,
|
|
81
|
+
'path': '/api/definitions/import/'+name,
|
|
82
|
+
'headers': {
|
|
83
|
+
'x-api-key': '12345',
|
|
84
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
85
|
+
},
|
|
86
|
+
'maxRedirects': 20
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var req = http.request(options, function (res) {
|
|
90
|
+
var chunks = [];
|
|
91
|
+
|
|
92
|
+
res.on("data", function (chunk) {
|
|
93
|
+
chunks.push(chunk);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
res.on("end", function (chunk) {
|
|
97
|
+
var body = Buffer.concat(chunks);
|
|
98
|
+
console.log(body.toString());
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
res.on("error", function (error) {
|
|
102
|
+
console.error(error);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
|
|
107
|
+
+ path + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
|
|
108
|
+
fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
109
|
+
|
|
110
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
111
|
+
|
|
112
|
+
req.write(postData);
|
|
113
|
+
|
|
114
|
+
req.end();
|
|
115
|
+
|
|
116
|
+
}
|
package/src/BPMNClient.js
CHANGED
|
@@ -13,9 +13,10 @@ exports.ClientDefinitions = exports.ClientDatastore = exports.ClientEngine = exp
|
|
|
13
13
|
console.log("BPMNClient 1.2");
|
|
14
14
|
const https = require('https');
|
|
15
15
|
const http = require('http');
|
|
16
|
+
const fs = require("fs");
|
|
16
17
|
class WebService {
|
|
17
18
|
constructor() { }
|
|
18
|
-
invoke(params, options) {
|
|
19
|
+
invoke(params, options, postData = null) {
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
21
|
var driver = http;
|
|
21
22
|
var body = JSON.stringify(params);
|
|
@@ -26,7 +27,7 @@ class WebService {
|
|
|
26
27
|
let self = this;
|
|
27
28
|
return new Promise(function (resolve, reject) {
|
|
28
29
|
try {
|
|
29
|
-
driver.request(options, function (res) {
|
|
30
|
+
var req = driver.request(options, function (res) {
|
|
30
31
|
// console.log('STATUS: ' + res.statusCode);
|
|
31
32
|
this.response = res;
|
|
32
33
|
//console.log(res);
|
|
@@ -36,13 +37,23 @@ class WebService {
|
|
|
36
37
|
data += chunk;
|
|
37
38
|
});
|
|
38
39
|
res.on('end', () => {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
try {
|
|
41
|
+
self.result = JSON.parse(data);
|
|
42
|
+
resolve(self.result);
|
|
43
|
+
}
|
|
44
|
+
catch (exc) {
|
|
45
|
+
console.log(data);
|
|
46
|
+
console.log(exc);
|
|
47
|
+
}
|
|
41
48
|
});
|
|
42
|
-
})
|
|
49
|
+
});
|
|
50
|
+
req.on("error", (err) => {
|
|
43
51
|
console.log("Error: " + err.message);
|
|
44
52
|
reject(err);
|
|
45
|
-
})
|
|
53
|
+
});
|
|
54
|
+
if (postData !== null)
|
|
55
|
+
req.write(postData);
|
|
56
|
+
req.end(body);
|
|
46
57
|
}
|
|
47
58
|
catch (exc) {
|
|
48
59
|
console.log(exc);
|
|
@@ -81,9 +92,59 @@ class BPMNClient extends WebService {
|
|
|
81
92
|
return yield this.request(url, 'DELETE', data);
|
|
82
93
|
});
|
|
83
94
|
}
|
|
95
|
+
upload(url, fileName, path) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
console.log('upload');
|
|
98
|
+
var options = {
|
|
99
|
+
'method': 'POST',
|
|
100
|
+
'hostname': this.host,
|
|
101
|
+
'port': this.port,
|
|
102
|
+
'path': url + '/' + fileName,
|
|
103
|
+
'headers': {
|
|
104
|
+
'x-api-key': this.apiKey
|
|
105
|
+
},
|
|
106
|
+
'maxRedirects': 20
|
|
107
|
+
};
|
|
108
|
+
var req = http.request(options, function (res) {
|
|
109
|
+
var chunks = [];
|
|
110
|
+
res.on("data", function (chunk) {
|
|
111
|
+
chunks.push(chunk);
|
|
112
|
+
});
|
|
113
|
+
res.on("end", function (chunk) {
|
|
114
|
+
var body = Buffer.concat(chunks);
|
|
115
|
+
console.log(body.toString());
|
|
116
|
+
});
|
|
117
|
+
res.on("error", function (error) {
|
|
118
|
+
console.error(error);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
|
|
122
|
+
+ fileName + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
|
|
123
|
+
fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
124
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
125
|
+
req.write(postData);
|
|
126
|
+
req.end();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
84
129
|
request(url, method, params) {
|
|
85
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
131
|
var body = JSON.stringify(params);
|
|
132
|
+
var size = Buffer.byteLength(body);
|
|
133
|
+
var contentType = "application/json";
|
|
134
|
+
if (method == 'UPLOAD') {
|
|
135
|
+
contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
|
|
136
|
+
method = 'POST';
|
|
137
|
+
}
|
|
138
|
+
var headers = {
|
|
139
|
+
"Content-Type": contentType,
|
|
140
|
+
"x-api-key": this.apiKey,
|
|
141
|
+
"Accept": "*/*",
|
|
142
|
+
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
143
|
+
// "Accept-Encoding": "gzip, deflate, br",
|
|
144
|
+
"Connection": "keep-alive"
|
|
145
|
+
//,
|
|
146
|
+
// "Content-Length": Buffer.byteLength(body)
|
|
147
|
+
};
|
|
87
148
|
var options;
|
|
88
149
|
if (params) {
|
|
89
150
|
options = {
|
|
@@ -91,15 +152,7 @@ class BPMNClient extends WebService {
|
|
|
91
152
|
port: this.port,
|
|
92
153
|
path: '/api/' + url,
|
|
93
154
|
method: method,
|
|
94
|
-
headers:
|
|
95
|
-
"Content-Type": "application/json",
|
|
96
|
-
"x-api-key": this.apiKey,
|
|
97
|
-
"Accept": "*/*",
|
|
98
|
-
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
99
|
-
// "Accept-Encoding": "gzip, deflate, br",
|
|
100
|
-
"Connection": "keep-alive",
|
|
101
|
-
"Content-Length": Buffer.byteLength(body)
|
|
102
|
-
}
|
|
155
|
+
headers: headers
|
|
103
156
|
};
|
|
104
157
|
}
|
|
105
158
|
else {
|
|
@@ -141,9 +194,9 @@ class ClientEngine {
|
|
|
141
194
|
return instance;
|
|
142
195
|
});
|
|
143
196
|
}
|
|
144
|
-
throwMessage(messageId, data) {
|
|
197
|
+
throwMessage(messageId, data = {}, messageMatchingKey = {}) {
|
|
145
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
const ret = yield this.client.
|
|
199
|
+
const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
|
|
147
200
|
if (ret['errors']) {
|
|
148
201
|
console.log(ret['errors']);
|
|
149
202
|
throw new Error(ret['errors']);
|
|
@@ -151,9 +204,9 @@ class ClientEngine {
|
|
|
151
204
|
return ret;
|
|
152
205
|
});
|
|
153
206
|
}
|
|
154
|
-
throwSignal(signalId, data) {
|
|
207
|
+
throwSignal(signalId, data = {}, messageMatchingKey = {}) {
|
|
155
208
|
return __awaiter(this, void 0, void 0, function* () {
|
|
156
|
-
const ret = yield this.client.
|
|
209
|
+
const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
|
|
157
210
|
if (ret['errors']) {
|
|
158
211
|
console.log(ret['errors']);
|
|
159
212
|
throw new Error(ret['errors']);
|
|
@@ -221,6 +274,12 @@ class ClientDefinitions {
|
|
|
221
274
|
constructor(client) {
|
|
222
275
|
this.client = client;
|
|
223
276
|
}
|
|
277
|
+
import(name, path) {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
var res = yield this.client.upload('definitions/import', name, path);
|
|
280
|
+
return res;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
224
283
|
list() {
|
|
225
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
285
|
var res = yield this.client.get('definitions/list', []);
|
|
@@ -231,9 +290,31 @@ class ClientDefinitions {
|
|
|
231
290
|
return res;
|
|
232
291
|
});
|
|
233
292
|
}
|
|
293
|
+
delete(name) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
const res = yield this.client.post('definitions/delete/', { name });
|
|
296
|
+
if (res['errors']) {
|
|
297
|
+
console.log(res['errors']);
|
|
298
|
+
throw new Error(res['errors']);
|
|
299
|
+
}
|
|
300
|
+
console.log(res);
|
|
301
|
+
return res;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
rename(name, newName) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
const res = yield this.client.post('definitions/rename/', { name, newName });
|
|
307
|
+
if (res['errors']) {
|
|
308
|
+
console.log(res['errors']);
|
|
309
|
+
throw new Error(res['errors']);
|
|
310
|
+
}
|
|
311
|
+
console.log(res);
|
|
312
|
+
return res;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
234
315
|
load(name) {
|
|
235
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
236
|
-
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name
|
|
317
|
+
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
|
|
237
318
|
if (res['errors']) {
|
|
238
319
|
console.log(res['errors']);
|
|
239
320
|
throw new Error(res['errors']);
|
package/src/BPMNClient.ts
CHANGED
|
@@ -4,15 +4,18 @@ console.log("BPMNClient 1.2");
|
|
|
4
4
|
|
|
5
5
|
const https = require('https');
|
|
6
6
|
const http = require('http');
|
|
7
|
+
const fs = require("fs");
|
|
7
8
|
|
|
8
9
|
class WebService {
|
|
9
10
|
statusCode;
|
|
10
11
|
result;
|
|
11
12
|
response;
|
|
12
13
|
constructor() { }
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
async invoke(params, options,postData=null) {
|
|
14
16
|
|
|
15
17
|
var driver = http;
|
|
18
|
+
|
|
16
19
|
var body = JSON.stringify(params);
|
|
17
20
|
|
|
18
21
|
// console.log(options, params);
|
|
@@ -24,8 +27,8 @@ class WebService {
|
|
|
24
27
|
return new Promise(function (resolve, reject) {
|
|
25
28
|
try {
|
|
26
29
|
|
|
27
|
-
driver.request(options, function (res) {
|
|
28
|
-
// console.log('STATUS: ' + res.statusCode);
|
|
30
|
+
var req = driver.request(options, function (res) {
|
|
31
|
+
// console.log('STATUS: ' + res.statusCode);
|
|
29
32
|
this.response = res;
|
|
30
33
|
//console.log(res);
|
|
31
34
|
self.statusCode = res.statusCode;
|
|
@@ -34,16 +37,26 @@ class WebService {
|
|
|
34
37
|
data += chunk;
|
|
35
38
|
});
|
|
36
39
|
res.on('end', () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
try {
|
|
41
|
+
self.result = JSON.parse(data);
|
|
42
|
+
resolve(self.result);
|
|
43
|
+
}
|
|
44
|
+
catch (exc) {
|
|
45
|
+
console.log(data);
|
|
46
|
+
console.log(exc);
|
|
47
|
+
}
|
|
40
48
|
});
|
|
41
49
|
|
|
42
50
|
|
|
43
|
-
})
|
|
51
|
+
});
|
|
52
|
+
req.on("error", (err) => {
|
|
44
53
|
console.log("Error: " + err.message);
|
|
45
54
|
reject(err);
|
|
46
|
-
})
|
|
55
|
+
});
|
|
56
|
+
if (postData !==null)
|
|
57
|
+
req.write(postData);
|
|
58
|
+
|
|
59
|
+
req.end(body);
|
|
47
60
|
}
|
|
48
61
|
catch (exc) {
|
|
49
62
|
console.log(exc);
|
|
@@ -87,9 +100,70 @@ class BPMNClient extends WebService {
|
|
|
87
100
|
return await this.request(url, 'DELETE', data);
|
|
88
101
|
|
|
89
102
|
}
|
|
103
|
+
|
|
104
|
+
async upload(url, fileName, path) {
|
|
105
|
+
console.log('upload');
|
|
106
|
+
var options = {
|
|
107
|
+
'method': 'POST',
|
|
108
|
+
'hostname': this.host,
|
|
109
|
+
'port': this.port,
|
|
110
|
+
'path': url + '/' + fileName,
|
|
111
|
+
'headers': {
|
|
112
|
+
'x-api-key': this.apiKey
|
|
113
|
+
},
|
|
114
|
+
'maxRedirects': 20
|
|
115
|
+
};
|
|
116
|
+
var req = http.request(options, function (res) {
|
|
117
|
+
var chunks = [];
|
|
118
|
+
|
|
119
|
+
res.on("data", function (chunk) {
|
|
120
|
+
chunks.push(chunk);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
res.on("end", function (chunk) {
|
|
124
|
+
var body = Buffer.concat(chunks);
|
|
125
|
+
console.log(body.toString());
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
res.on("error", function (error) {
|
|
129
|
+
console.error(error);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
|
|
134
|
+
+ fileName + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
|
|
135
|
+
fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
136
|
+
|
|
137
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
138
|
+
|
|
139
|
+
req.write(postData);
|
|
140
|
+
|
|
141
|
+
req.end();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
90
145
|
async request(url, method, params) {
|
|
91
146
|
|
|
92
147
|
var body = JSON.stringify(params);
|
|
148
|
+
var size = Buffer.byteLength(body);
|
|
149
|
+
var contentType = "application/json";
|
|
150
|
+
|
|
151
|
+
if (method == 'UPLOAD') {
|
|
152
|
+
contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
|
|
153
|
+
method = 'POST';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var headers = {
|
|
157
|
+
"Content-Type": contentType ,
|
|
158
|
+
"x-api-key": this.apiKey,
|
|
159
|
+
"Accept": "*/*",
|
|
160
|
+
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
161
|
+
// "Accept-Encoding": "gzip, deflate, br",
|
|
162
|
+
"Connection": "keep-alive"
|
|
163
|
+
//,
|
|
164
|
+
// "Content-Length": Buffer.byteLength(body)
|
|
165
|
+
};
|
|
166
|
+
|
|
93
167
|
|
|
94
168
|
var options;
|
|
95
169
|
|
|
@@ -99,15 +173,7 @@ class BPMNClient extends WebService {
|
|
|
99
173
|
port: this.port,
|
|
100
174
|
path: '/api/' + url,
|
|
101
175
|
method: method,
|
|
102
|
-
headers:
|
|
103
|
-
"Content-Type": "application/json",
|
|
104
|
-
"x-api-key": this.apiKey,
|
|
105
|
-
"Accept": "*/*",
|
|
106
|
-
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
107
|
-
// "Accept-Encoding": "gzip, deflate, br",
|
|
108
|
-
"Connection": "keep-alive",
|
|
109
|
-
"Content-Length": Buffer.byteLength(body)
|
|
110
|
-
}
|
|
176
|
+
headers: headers
|
|
111
177
|
};
|
|
112
178
|
}
|
|
113
179
|
else {
|
|
@@ -132,7 +198,7 @@ class ClientEngine {
|
|
|
132
198
|
constructor(client) {
|
|
133
199
|
this.client = client;
|
|
134
200
|
}
|
|
135
|
-
async start(name, data = {}
|
|
201
|
+
async start(name, data = {}, startNodeId = null, options = {}): Promise<IInstanceData> {
|
|
136
202
|
const ret = await this.client.post('engine/start',
|
|
137
203
|
{ name, data, startNodeId, options });
|
|
138
204
|
if (ret['errors']) {
|
|
@@ -152,16 +218,16 @@ class ClientEngine {
|
|
|
152
218
|
return instance;
|
|
153
219
|
}
|
|
154
220
|
|
|
155
|
-
async throwMessage(messageId, data) {
|
|
156
|
-
const ret = await this.client.
|
|
221
|
+
async throwMessage(messageId, data = {} , messageMatchingKey = {}) {
|
|
222
|
+
const ret = await this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
|
|
157
223
|
if (ret['errors']) {
|
|
158
224
|
console.log(ret['errors']);
|
|
159
225
|
throw new Error(ret['errors']);
|
|
160
226
|
}
|
|
161
227
|
return ret;
|
|
162
228
|
}
|
|
163
|
-
async throwSignal(signalId, data) {
|
|
164
|
-
const ret = await this.client.
|
|
229
|
+
async throwSignal(signalId, data = {} , messageMatchingKey = {}) {
|
|
230
|
+
const ret = await this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
|
|
165
231
|
if (ret['errors']) {
|
|
166
232
|
console.log(ret['errors']);
|
|
167
233
|
throw new Error(ret['errors']);
|
|
@@ -205,6 +271,7 @@ class ClientDatastore {
|
|
|
205
271
|
}
|
|
206
272
|
async findInstances(query): Promise<IInstanceData[]> {
|
|
207
273
|
const res = await this.client.get('datastore/findInstances', query);
|
|
274
|
+
|
|
208
275
|
if (res['errors']) {
|
|
209
276
|
console.log(res['errors']);
|
|
210
277
|
throw new Error(res['errors']);
|
|
@@ -222,6 +289,15 @@ class ClientDefinitions {
|
|
|
222
289
|
constructor(client) {
|
|
223
290
|
this.client = client;
|
|
224
291
|
}
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
async import(name, path) {
|
|
295
|
+
|
|
296
|
+
var res = await this.client.upload('definitions/import',name,path);
|
|
297
|
+
|
|
298
|
+
return res;
|
|
299
|
+
|
|
300
|
+
}
|
|
225
301
|
async list(): Promise<string[]> {
|
|
226
302
|
var res = await this.client.get('definitions/list', []);
|
|
227
303
|
if (res['errors']) {
|
|
@@ -230,9 +306,29 @@ class ClientDefinitions {
|
|
|
230
306
|
}
|
|
231
307
|
return res as string[];
|
|
232
308
|
|
|
309
|
+
}
|
|
310
|
+
async delete(name) {
|
|
311
|
+
const res = await this.client.post('definitions/delete/', { name });
|
|
312
|
+
if (res['errors']) {
|
|
313
|
+
console.log(res['errors']);
|
|
314
|
+
throw new Error(res['errors']);
|
|
315
|
+
}
|
|
316
|
+
console.log(res);
|
|
317
|
+
return res as IDefinitionData;
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
async rename(name,newName) {
|
|
321
|
+
const res = await this.client.post('definitions/rename/', { name , newName });
|
|
322
|
+
if (res['errors']) {
|
|
323
|
+
console.log(res['errors']);
|
|
324
|
+
throw new Error(res['errors']);
|
|
325
|
+
}
|
|
326
|
+
console.log(res);
|
|
327
|
+
return res as IDefinitionData;
|
|
328
|
+
|
|
233
329
|
}
|
|
234
330
|
async load(name): Promise<IDefinitionData> {
|
|
235
|
-
const res = await this.client.get(encodeURI('definitions/load/' + name), { name
|
|
331
|
+
const res = await this.client.get(encodeURI('definitions/load/' + name), { name });
|
|
236
332
|
if (res['errors']) {
|
|
237
333
|
console.log(res['errors']);
|
|
238
334
|
throw new Error(res['errors']);
|
package/src/interfaces/Enums.js
CHANGED
|
@@ -9,7 +9,7 @@ var BPMN_TYPE;
|
|
|
9
9
|
BPMN_TYPE["SendTask"] = "bpmn:SendTask";
|
|
10
10
|
BPMN_TYPE["ReceiveTask"] = "bpmn:ReceiveTask";
|
|
11
11
|
BPMN_TYPE["BusinessRuleTask"] = "bpmn:BusinessRuleTask";
|
|
12
|
-
BPMN_TYPE["SubProcess"] = "bpmn:
|
|
12
|
+
BPMN_TYPE["SubProcess"] = "bpmn:SubProcess";
|
|
13
13
|
BPMN_TYPE["ParallelGateway"] = "bpmn:ParallelGateway";
|
|
14
14
|
BPMN_TYPE["EventBasedGateway"] = "bpmn:EventBasedGateway";
|
|
15
15
|
BPMN_TYPE["InclusiveGateway"] = "bpmn:InclusiveGateway";
|
|
@@ -31,6 +31,8 @@ var NODE_SUBTYPE;
|
|
|
31
31
|
NODE_SUBTYPE["signal"] = "signal";
|
|
32
32
|
NODE_SUBTYPE["error"] = "error";
|
|
33
33
|
NODE_SUBTYPE["escalation"] = "escalation";
|
|
34
|
+
NODE_SUBTYPE["cancel"] = "cancel";
|
|
35
|
+
NODE_SUBTYPE["compensate"] = "compensate";
|
|
34
36
|
})(NODE_SUBTYPE || (NODE_SUBTYPE = {}));
|
|
35
37
|
exports.NODE_SUBTYPE = NODE_SUBTYPE;
|
|
36
38
|
/*
|
|
@@ -56,7 +58,7 @@ var EXECUTION_EVENT;
|
|
|
56
58
|
EXECUTION_EVENT["process_resumed"] = "process_resumed";
|
|
57
59
|
EXECUTION_EVENT["process_wait"] = "process.wait";
|
|
58
60
|
EXECUTION_EVENT["process_end"] = "process.end";
|
|
59
|
-
EXECUTION_EVENT["process_terminated"] = "
|
|
61
|
+
EXECUTION_EVENT["process_terminated"] = "process.terminated";
|
|
60
62
|
EXECUTION_EVENT["token_start"] = "token.start";
|
|
61
63
|
EXECUTION_EVENT["token_wait"] = "token.wait";
|
|
62
64
|
EXECUTION_EVENT["token_end"] = "token.end";
|
|
@@ -85,6 +87,7 @@ var ITEM_STATUS;
|
|
|
85
87
|
ITEM_STATUS["wait"] = "wait";
|
|
86
88
|
ITEM_STATUS["end"] = "end";
|
|
87
89
|
ITEM_STATUS["terminated"] = "terminated";
|
|
90
|
+
ITEM_STATUS["cancelled"] = "cancelled";
|
|
88
91
|
ITEM_STATUS["discard"] = "discard";
|
|
89
92
|
})(ITEM_STATUS || (ITEM_STATUS = {}));
|
|
90
93
|
exports.ITEM_STATUS = ITEM_STATUS;
|
package/src/interfaces/Enums.ts
CHANGED
|
@@ -6,7 +6,7 @@ enum BPMN_TYPE {
|
|
|
6
6
|
SendTask = 'bpmn:SendTask',
|
|
7
7
|
ReceiveTask = 'bpmn:ReceiveTask',
|
|
8
8
|
BusinessRuleTask = 'bpmn:BusinessRuleTask',
|
|
9
|
-
SubProcess = 'bpmn:
|
|
9
|
+
SubProcess = 'bpmn:SubProcess',
|
|
10
10
|
ParallelGateway = 'bpmn:ParallelGateway',
|
|
11
11
|
EventBasedGateway = 'bpmn:EventBasedGateway',
|
|
12
12
|
InclusiveGateway = 'bpmn:InclusiveGateway',
|
|
@@ -26,7 +26,10 @@ enum NODE_SUBTYPE {
|
|
|
26
26
|
message = 'message',
|
|
27
27
|
signal = 'signal',
|
|
28
28
|
error = 'error',
|
|
29
|
-
escalation = 'escalation'
|
|
29
|
+
escalation = 'escalation',
|
|
30
|
+
cancel = 'cancel',
|
|
31
|
+
|
|
32
|
+
compensate = 'compensate'
|
|
30
33
|
}
|
|
31
34
|
/*
|
|
32
35
|
* ALL events
|
|
@@ -40,7 +43,7 @@ enum EXECUTION_EVENT {
|
|
|
40
43
|
process_invoke = 'process.invoke', process_invoked = 'process.invoked',
|
|
41
44
|
process_restored = 'process.restored', process_resumed = 'process_resumed',
|
|
42
45
|
process_wait = 'process.wait',
|
|
43
|
-
process_end = 'process.end', process_terminated = '
|
|
46
|
+
process_end = 'process.end', process_terminated = 'process.terminated' ,
|
|
44
47
|
token_start = 'token.start', token_wait = 'token.wait', token_end = 'token.end', token_terminated = 'token.terminated'
|
|
45
48
|
}
|
|
46
49
|
/*
|
|
@@ -49,7 +52,16 @@ enum EXECUTION_EVENT {
|
|
|
49
52
|
// must be same as above
|
|
50
53
|
enum NODE_ACTION { continue = 1, wait, end , stop , error , abort };
|
|
51
54
|
|
|
52
|
-
enum ITEM_STATUS {
|
|
55
|
+
enum ITEM_STATUS {
|
|
56
|
+
enter = 'enter',
|
|
57
|
+
start = 'start',
|
|
58
|
+
wait = 'wait',
|
|
59
|
+
end = 'end',
|
|
60
|
+
terminated = 'terminated',
|
|
61
|
+
cancelled = 'cancelled',
|
|
62
|
+
discard = 'discard'
|
|
63
|
+
|
|
64
|
+
}
|
|
53
65
|
|
|
54
66
|
//type ITEMSTATUS = 'enter' | 'start' | 'wait' | 'end' | 'terminated' | 'discard';
|
|
55
67
|
|
|
@@ -63,7 +75,6 @@ enum TOKEN_STATUS { running = 'running', wait = 'wait', end = 'end', terminated
|
|
|
63
75
|
|
|
64
76
|
enum FLOW_ACTION { take = 'take', discard = 'discard' }
|
|
65
77
|
|
|
66
|
-
|
|
67
78
|
export {
|
|
68
79
|
BPMN_TYPE ,
|
|
69
80
|
EXECUTION_EVENT, NODE_ACTION, FLOW_ACTION,
|
package/test.js
CHANGED
|
@@ -13,8 +13,58 @@ const _1 = require("./");
|
|
|
13
13
|
console.log("Testing BPMNClient");
|
|
14
14
|
const dotenv = require('dotenv');
|
|
15
15
|
const res = dotenv.config();
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const server = new _1.BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
18
|
+
//testMessage();
|
|
19
|
+
testImport();
|
|
20
|
+
function testImport() {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
var file = 'test-import';
|
|
23
|
+
var path = '../webApp/processes/Trans.bpmn';
|
|
24
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;filename=\"" + path + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" + fs.readFileSync(file) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
25
|
+
console.log(postData);
|
|
26
|
+
// var res = await upload('definitions/import/' + name, postData);
|
|
27
|
+
if (res['errors']) {
|
|
28
|
+
console.log(res['errors']);
|
|
29
|
+
throw new Error(res['errors']);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function testImport2() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
console.log('calling');
|
|
36
|
+
var file = '../webApp/processes/Trans.bpmn';
|
|
37
|
+
let response = yield server.definitions.import('testing_123', file);
|
|
38
|
+
console.log(response);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function displayInstance(instanceId) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
let insts = yield server.datastore.findInstances({ id: instanceId });
|
|
44
|
+
for (var i = 0; i < insts.length; i++) {
|
|
45
|
+
let inst = insts[i];
|
|
46
|
+
var items = inst.items;
|
|
47
|
+
console.log(`name: ${inst.name} status: ${inst.status} instanceId: ${inst.id}
|
|
48
|
+
startedAt: ${inst.startedAt} endedAt ${inst.endedAt}`, 'data:', inst.data);
|
|
49
|
+
for (var j = 0; j < items.length; j++) {
|
|
50
|
+
let item = items[j];
|
|
51
|
+
console.log(`element: ${item.elementId} status: ${item.status} id: ${item.id}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function testMessage() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const messageId = 'Message-104';
|
|
59
|
+
let messageData = {};
|
|
60
|
+
console.log('calling');
|
|
61
|
+
let response = yield server.engine.throwMessage(messageId, messageData);
|
|
62
|
+
if (response['id'])
|
|
63
|
+
return yield displayInstance(response['id']);
|
|
64
|
+
else
|
|
65
|
+
return null;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
18
68
|
function test() {
|
|
19
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
70
|
const server = new _1.BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
package/test.ts
CHANGED
|
@@ -4,9 +4,69 @@ import { BPMNClient } from './';
|
|
|
4
4
|
console.log("Testing BPMNClient");
|
|
5
5
|
const dotenv = require('dotenv');
|
|
6
6
|
const res = dotenv.config();
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
const server = new BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
10
|
+
|
|
11
|
+
//testMessage();
|
|
12
|
+
testImport();
|
|
13
|
+
|
|
14
|
+
async function testImport() {
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
var file = 'test-import';
|
|
18
|
+
var path = '../webApp/processes/Trans.bpmn';
|
|
19
|
+
|
|
20
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data;filename=\"" + path + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" + fs.readFileSync(file) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
21
|
+
|
|
22
|
+
console.log(postData);
|
|
23
|
+
// var res = await upload('definitions/import/' + name, postData);
|
|
24
|
+
|
|
25
|
+
if(res['errors']) {
|
|
26
|
+
console.log(res['errors']);
|
|
27
|
+
throw new Error(res['errors']);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
async function testImport2() {
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
console.log('calling');
|
|
35
|
+
var file = '../webApp/processes/Trans.bpmn';
|
|
36
|
+
let response = await server.definitions.import('testing_123', file);
|
|
37
|
+
console.log(response);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function displayInstance(instanceId) {
|
|
41
|
+
|
|
42
|
+
let insts = await server.datastore.findInstances({ id: instanceId })
|
|
43
|
+
|
|
44
|
+
for (var i = 0; i < insts.length; i++) {
|
|
45
|
+
let inst = insts[i];
|
|
46
|
+
var items = inst.items;
|
|
47
|
+
console.log(`name: ${inst.name} status: ${inst.status} instanceId: ${inst.id}
|
|
48
|
+
startedAt: ${inst.startedAt} endedAt ${inst.endedAt}`, 'data:', inst.data);
|
|
49
|
+
for (var j = 0; j < items.length; j++) {
|
|
50
|
+
let item = items[j];
|
|
51
|
+
console.log(`element: ${item.elementId} status: ${item.status} id: ${item.id}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async function testMessage() {
|
|
58
|
+
const messageId = 'Message-104';
|
|
59
|
+
|
|
60
|
+
let messageData = {};
|
|
61
|
+
|
|
62
|
+
console.log('calling');
|
|
63
|
+
let response = await server.engine.throwMessage(messageId, messageData);
|
|
64
|
+
if (response['id'])
|
|
65
|
+
return await displayInstance(response['id']);
|
|
66
|
+
else
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
7
69
|
|
|
8
|
-
console.log(res);
|
|
9
|
-
test();
|
|
10
70
|
|
|
11
71
|
async function test() {
|
|
12
72
|
|