bpmn-client 1.3.8 → 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/package.json +1 -1
- package/remote-import.js +97 -0
- package/remote-import.ts +116 -0
- package/src/BPMNClient.js +89 -14
- package/src/BPMNClient.ts +106 -15
- package/src/interfaces/Enums.js +5 -2
- package/src/interfaces/Enums.ts +16 -5
- package/test.js +24 -1
- package/test.ts +29 -1
package/package.json
CHANGED
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);
|
|
@@ -45,10 +46,14 @@ class WebService {
|
|
|
45
46
|
console.log(exc);
|
|
46
47
|
}
|
|
47
48
|
});
|
|
48
|
-
})
|
|
49
|
+
});
|
|
50
|
+
req.on("error", (err) => {
|
|
49
51
|
console.log("Error: " + err.message);
|
|
50
52
|
reject(err);
|
|
51
|
-
})
|
|
53
|
+
});
|
|
54
|
+
if (postData !== null)
|
|
55
|
+
req.write(postData);
|
|
56
|
+
req.end(body);
|
|
52
57
|
}
|
|
53
58
|
catch (exc) {
|
|
54
59
|
console.log(exc);
|
|
@@ -87,9 +92,59 @@ class BPMNClient extends WebService {
|
|
|
87
92
|
return yield this.request(url, 'DELETE', data);
|
|
88
93
|
});
|
|
89
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
|
+
}
|
|
90
129
|
request(url, method, params) {
|
|
91
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
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
|
+
};
|
|
93
148
|
var options;
|
|
94
149
|
if (params) {
|
|
95
150
|
options = {
|
|
@@ -97,15 +152,7 @@ class BPMNClient extends WebService {
|
|
|
97
152
|
port: this.port,
|
|
98
153
|
path: '/api/' + url,
|
|
99
154
|
method: method,
|
|
100
|
-
headers:
|
|
101
|
-
"Content-Type": "application/json",
|
|
102
|
-
"x-api-key": this.apiKey,
|
|
103
|
-
"Accept": "*/*",
|
|
104
|
-
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
105
|
-
// "Accept-Encoding": "gzip, deflate, br",
|
|
106
|
-
"Connection": "keep-alive",
|
|
107
|
-
"Content-Length": Buffer.byteLength(body)
|
|
108
|
-
}
|
|
155
|
+
headers: headers
|
|
109
156
|
};
|
|
110
157
|
}
|
|
111
158
|
else {
|
|
@@ -227,6 +274,12 @@ class ClientDefinitions {
|
|
|
227
274
|
constructor(client) {
|
|
228
275
|
this.client = client;
|
|
229
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
|
+
}
|
|
230
283
|
list() {
|
|
231
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
285
|
var res = yield this.client.get('definitions/list', []);
|
|
@@ -237,9 +290,31 @@ class ClientDefinitions {
|
|
|
237
290
|
return res;
|
|
238
291
|
});
|
|
239
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
|
+
}
|
|
240
315
|
load(name) {
|
|
241
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name
|
|
317
|
+
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
|
|
243
318
|
if (res['errors']) {
|
|
244
319
|
console.log(res['errors']);
|
|
245
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;
|
|
@@ -45,10 +48,15 @@ class WebService {
|
|
|
45
48
|
});
|
|
46
49
|
|
|
47
50
|
|
|
48
|
-
})
|
|
51
|
+
});
|
|
52
|
+
req.on("error", (err) => {
|
|
49
53
|
console.log("Error: " + err.message);
|
|
50
54
|
reject(err);
|
|
51
|
-
})
|
|
55
|
+
});
|
|
56
|
+
if (postData !==null)
|
|
57
|
+
req.write(postData);
|
|
58
|
+
|
|
59
|
+
req.end(body);
|
|
52
60
|
}
|
|
53
61
|
catch (exc) {
|
|
54
62
|
console.log(exc);
|
|
@@ -92,9 +100,70 @@ class BPMNClient extends WebService {
|
|
|
92
100
|
return await this.request(url, 'DELETE', data);
|
|
93
101
|
|
|
94
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
|
+
|
|
95
145
|
async request(url, method, params) {
|
|
96
146
|
|
|
97
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
|
+
|
|
98
167
|
|
|
99
168
|
var options;
|
|
100
169
|
|
|
@@ -104,15 +173,7 @@ class BPMNClient extends WebService {
|
|
|
104
173
|
port: this.port,
|
|
105
174
|
path: '/api/' + url,
|
|
106
175
|
method: method,
|
|
107
|
-
headers:
|
|
108
|
-
"Content-Type": "application/json",
|
|
109
|
-
"x-api-key": this.apiKey,
|
|
110
|
-
"Accept": "*/*",
|
|
111
|
-
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
112
|
-
// "Accept-Encoding": "gzip, deflate, br",
|
|
113
|
-
"Connection": "keep-alive",
|
|
114
|
-
"Content-Length": Buffer.byteLength(body)
|
|
115
|
-
}
|
|
176
|
+
headers: headers
|
|
116
177
|
};
|
|
117
178
|
}
|
|
118
179
|
else {
|
|
@@ -210,6 +271,7 @@ class ClientDatastore {
|
|
|
210
271
|
}
|
|
211
272
|
async findInstances(query): Promise<IInstanceData[]> {
|
|
212
273
|
const res = await this.client.get('datastore/findInstances', query);
|
|
274
|
+
|
|
213
275
|
if (res['errors']) {
|
|
214
276
|
console.log(res['errors']);
|
|
215
277
|
throw new Error(res['errors']);
|
|
@@ -227,6 +289,15 @@ class ClientDefinitions {
|
|
|
227
289
|
constructor(client) {
|
|
228
290
|
this.client = client;
|
|
229
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
|
+
}
|
|
230
301
|
async list(): Promise<string[]> {
|
|
231
302
|
var res = await this.client.get('definitions/list', []);
|
|
232
303
|
if (res['errors']) {
|
|
@@ -235,9 +306,29 @@ class ClientDefinitions {
|
|
|
235
306
|
}
|
|
236
307
|
return res as string[];
|
|
237
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
|
+
|
|
238
329
|
}
|
|
239
330
|
async load(name): Promise<IDefinitionData> {
|
|
240
|
-
const res = await this.client.get(encodeURI('definitions/load/' + name), { name
|
|
331
|
+
const res = await this.client.get(encodeURI('definitions/load/' + name), { name });
|
|
241
332
|
if (res['errors']) {
|
|
242
333
|
console.log(res['errors']);
|
|
243
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,31 @@ const _1 = require("./");
|
|
|
13
13
|
console.log("Testing BPMNClient");
|
|
14
14
|
const dotenv = require('dotenv');
|
|
15
15
|
const res = dotenv.config();
|
|
16
|
+
const fs = require('fs');
|
|
16
17
|
const server = new _1.BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
17
|
-
testMessage();
|
|
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
|
+
}
|
|
18
41
|
function displayInstance(instanceId) {
|
|
19
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
43
|
let insts = yield server.datastore.findInstances({ id: instanceId });
|
package/test.ts
CHANGED
|
@@ -4,10 +4,38 @@ 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');
|
|
7
8
|
|
|
8
9
|
const server = new BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
9
10
|
|
|
10
|
-
testMessage();
|
|
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
|
+
}
|
|
11
39
|
|
|
12
40
|
async function displayInstance(instanceId) {
|
|
13
41
|
|