bpmn-client 1.3.8 → 1.3.16
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 +3 -3
- package/remote-import.js +105 -0
- package/remote-import.ts +126 -0
- package/src/BPMNClient.js +90 -14
- package/src/BPMNClient.ts +108 -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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bpmn-client",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsc --build",
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"connect-busboy": "0.0.2",
|
|
30
30
|
"core-js": "^3.6.5",
|
|
31
|
-
"dotenv": "^16.0.1"
|
|
31
|
+
"dotenv": "^16.0.1",
|
|
32
|
+
"follow-redirects": "^1.15.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/mime": "^1.3.1",
|
|
@@ -40,6 +41,5 @@
|
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=12.0.0"
|
|
43
|
-
|
|
44
44
|
}
|
|
45
45
|
}
|
package/remote-import.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
console.log('remote-import.ts');
|
|
16
|
+
fromClientLib();
|
|
17
|
+
console.log('-------------------');
|
|
18
|
+
//FromPostMan();
|
|
19
|
+
function fromClientLib() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
console.log('from client lib');
|
|
22
|
+
const server = new _1.BPMNClient('localhost', 3000, '12345');
|
|
23
|
+
var name = 'test-import';
|
|
24
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
25
|
+
var res = yield server.definitions.import(name, file);
|
|
26
|
+
//console.log(res.length);
|
|
27
|
+
return res;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function FromPostMan() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
console.log("Testing Remote import");
|
|
33
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
34
|
+
var http = require('follow-redirects').http;
|
|
35
|
+
//const http = require('http');
|
|
36
|
+
var fs = require('fs');
|
|
37
|
+
var options = {
|
|
38
|
+
'method': 'POST',
|
|
39
|
+
'hostname': 'localhost',
|
|
40
|
+
'port': 3000,
|
|
41
|
+
'path': '/api/definitions/import/testing4',
|
|
42
|
+
'headers': {
|
|
43
|
+
'x-api-key': '12345',
|
|
44
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
45
|
+
},
|
|
46
|
+
'maxRedirects': 20
|
|
47
|
+
};
|
|
48
|
+
var req = http.request(options, function (res) {
|
|
49
|
+
var chunks = [];
|
|
50
|
+
res.on("data", function (chunk) {
|
|
51
|
+
chunks.push(chunk);
|
|
52
|
+
});
|
|
53
|
+
res.on("end", function (chunk) {
|
|
54
|
+
var body = Buffer.concat(chunks);
|
|
55
|
+
console.log(body.toString());
|
|
56
|
+
});
|
|
57
|
+
res.on("error", function (error) {
|
|
58
|
+
console.error(error);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
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--";
|
|
62
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
63
|
+
req.write(postData);
|
|
64
|
+
req.end();
|
|
65
|
+
return req;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function request(name, path) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
console.log("Testing Request");
|
|
71
|
+
var http = require('http');
|
|
72
|
+
var fs = require('fs');
|
|
73
|
+
var options = {
|
|
74
|
+
'method': 'POST',
|
|
75
|
+
'hostname': 'localhost',
|
|
76
|
+
'port': 3000,
|
|
77
|
+
'path': '/api/definitions/import/' + name,
|
|
78
|
+
'headers': {
|
|
79
|
+
'x-api-key': '12345',
|
|
80
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
81
|
+
},
|
|
82
|
+
'maxRedirects': 20
|
|
83
|
+
};
|
|
84
|
+
var req = http.request(options, function (res) {
|
|
85
|
+
var chunks = [];
|
|
86
|
+
res.on("data", function (chunk) {
|
|
87
|
+
chunks.push(chunk);
|
|
88
|
+
});
|
|
89
|
+
res.on("end", function (chunk) {
|
|
90
|
+
var body = Buffer.concat(chunks);
|
|
91
|
+
console.log(body.toString());
|
|
92
|
+
});
|
|
93
|
+
res.on("error", function (error) {
|
|
94
|
+
console.error(error);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
|
|
98
|
+
+ path + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
|
|
99
|
+
fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
100
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
101
|
+
req.write(postData);
|
|
102
|
+
req.end();
|
|
103
|
+
console.log('end');
|
|
104
|
+
});
|
|
105
|
+
}
|
package/remote-import.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
|
|
2
|
+
//FromPostMan();
|
|
3
|
+
//request('test4', 'Trans.bpmn');
|
|
4
|
+
import { BPMNClient } from './';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
console.log('remote-import.ts');
|
|
8
|
+
|
|
9
|
+
fromClientLib();
|
|
10
|
+
|
|
11
|
+
console.log('-------------------');
|
|
12
|
+
//FromPostMan();
|
|
13
|
+
|
|
14
|
+
async function fromClientLib() {
|
|
15
|
+
|
|
16
|
+
console.log('from client lib');
|
|
17
|
+
const server = new BPMNClient('localhost', 3000, '12345');
|
|
18
|
+
|
|
19
|
+
var name = 'test-import';
|
|
20
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
21
|
+
|
|
22
|
+
var res=await server.definitions.import(name, file);
|
|
23
|
+
//console.log(res.length);
|
|
24
|
+
return res;
|
|
25
|
+
}
|
|
26
|
+
async function FromPostMan() {
|
|
27
|
+
|
|
28
|
+
console.log("Testing Remote import");
|
|
29
|
+
var file = 'E:\\x4\\dev\\webApp\\processes\\Trans.bpmn';
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var http = require('follow-redirects').http;
|
|
33
|
+
//const http = require('http');
|
|
34
|
+
|
|
35
|
+
var fs = require('fs');
|
|
36
|
+
|
|
37
|
+
var options = {
|
|
38
|
+
'method': 'POST',
|
|
39
|
+
'hostname': 'localhost',
|
|
40
|
+
'port': 3000,
|
|
41
|
+
'path': '/api/definitions/import/testing4',
|
|
42
|
+
'headers': {
|
|
43
|
+
'x-api-key': '12345',
|
|
44
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
45
|
+
},
|
|
46
|
+
'maxRedirects': 20
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var req = http.request(options, function (res) {
|
|
50
|
+
var chunks = [];
|
|
51
|
+
|
|
52
|
+
res.on("data", function (chunk) {
|
|
53
|
+
chunks.push(chunk);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
res.on("end", function (chunk) {
|
|
57
|
+
var body = Buffer.concat(chunks);
|
|
58
|
+
console.log(body.toString());
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
res.on("error", function (error) {
|
|
62
|
+
console.error(error);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
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--";
|
|
67
|
+
|
|
68
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
69
|
+
|
|
70
|
+
req.write(postData);
|
|
71
|
+
|
|
72
|
+
req.end();
|
|
73
|
+
|
|
74
|
+
return req;
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
async function request(name,path) {
|
|
80
|
+
|
|
81
|
+
console.log("Testing Request");
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
var http = require('http');
|
|
85
|
+
var fs = require('fs');
|
|
86
|
+
|
|
87
|
+
var options = {
|
|
88
|
+
'method': 'POST',
|
|
89
|
+
'hostname': 'localhost',
|
|
90
|
+
'port': 3000,
|
|
91
|
+
'path': '/api/definitions/import/'+name,
|
|
92
|
+
'headers': {
|
|
93
|
+
'x-api-key': '12345',
|
|
94
|
+
'Cookie': 'connect.sid=s%3AXMa01DuOlQ4WsrvBj0FVaIrTak49vLPB.hDIV9j7ONA437rZf%2F%2Biu%2Bc6B7T5%2FVuEIjj1BAaoCJW4'
|
|
95
|
+
},
|
|
96
|
+
'maxRedirects': 20
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
var req = http.request(options, function (res) {
|
|
100
|
+
var chunks = [];
|
|
101
|
+
|
|
102
|
+
res.on("data", function (chunk) {
|
|
103
|
+
chunks.push(chunk);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
res.on("end", function (chunk) {
|
|
107
|
+
var body = Buffer.concat(chunks);
|
|
108
|
+
console.log(body.toString());
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
res.on("error", function (error) {
|
|
112
|
+
console.error(error);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
|
|
117
|
+
+ path + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
|
|
118
|
+
fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
|
|
119
|
+
|
|
120
|
+
req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
|
|
121
|
+
|
|
122
|
+
req.write(postData);
|
|
123
|
+
|
|
124
|
+
req.end();
|
|
125
|
+
console.log('end');
|
|
126
|
+
}
|
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,60 @@ 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': '/api/' + 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
|
+
return req;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
90
130
|
request(url, method, params) {
|
|
91
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
92
132
|
var body = JSON.stringify(params);
|
|
133
|
+
var size = Buffer.byteLength(body);
|
|
134
|
+
var contentType = "application/json";
|
|
135
|
+
if (method == 'UPLOAD') {
|
|
136
|
+
contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
|
|
137
|
+
method = 'POST';
|
|
138
|
+
}
|
|
139
|
+
var headers = {
|
|
140
|
+
"Content-Type": contentType,
|
|
141
|
+
"x-api-key": this.apiKey,
|
|
142
|
+
"Accept": "*/*",
|
|
143
|
+
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
144
|
+
// "Accept-Encoding": "gzip, deflate, br",
|
|
145
|
+
"Connection": "keep-alive"
|
|
146
|
+
//,
|
|
147
|
+
// "Content-Length": Buffer.byteLength(body)
|
|
148
|
+
};
|
|
93
149
|
var options;
|
|
94
150
|
if (params) {
|
|
95
151
|
options = {
|
|
@@ -97,15 +153,7 @@ class BPMNClient extends WebService {
|
|
|
97
153
|
port: this.port,
|
|
98
154
|
path: '/api/' + url,
|
|
99
155
|
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
|
-
}
|
|
156
|
+
headers: headers
|
|
109
157
|
};
|
|
110
158
|
}
|
|
111
159
|
else {
|
|
@@ -227,6 +275,12 @@ class ClientDefinitions {
|
|
|
227
275
|
constructor(client) {
|
|
228
276
|
this.client = client;
|
|
229
277
|
}
|
|
278
|
+
import(name, path) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
var res = yield this.client.upload('definitions/import', name, path);
|
|
281
|
+
return res;
|
|
282
|
+
});
|
|
283
|
+
}
|
|
230
284
|
list() {
|
|
231
285
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
286
|
var res = yield this.client.get('definitions/list', []);
|
|
@@ -237,9 +291,31 @@ class ClientDefinitions {
|
|
|
237
291
|
return res;
|
|
238
292
|
});
|
|
239
293
|
}
|
|
294
|
+
delete(name) {
|
|
295
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
296
|
+
const res = yield this.client.post('definitions/delete/', { name });
|
|
297
|
+
if (res['errors']) {
|
|
298
|
+
console.log(res['errors']);
|
|
299
|
+
throw new Error(res['errors']);
|
|
300
|
+
}
|
|
301
|
+
console.log(res);
|
|
302
|
+
return res;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
rename(name, newName) {
|
|
306
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
307
|
+
const res = yield this.client.post('definitions/rename/', { name, newName });
|
|
308
|
+
if (res['errors']) {
|
|
309
|
+
console.log(res['errors']);
|
|
310
|
+
throw new Error(res['errors']);
|
|
311
|
+
}
|
|
312
|
+
console.log(res);
|
|
313
|
+
return res;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
240
316
|
load(name) {
|
|
241
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
-
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name
|
|
318
|
+
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
|
|
243
319
|
if (res['errors']) {
|
|
244
320
|
console.log(res['errors']);
|
|
245
321
|
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,72 @@ 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': '/api/'+ 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
|
+
return req;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
|
|
95
147
|
async request(url, method, params) {
|
|
96
148
|
|
|
97
149
|
var body = JSON.stringify(params);
|
|
150
|
+
var size = Buffer.byteLength(body);
|
|
151
|
+
var contentType = "application/json";
|
|
152
|
+
|
|
153
|
+
if (method == 'UPLOAD') {
|
|
154
|
+
contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
|
|
155
|
+
method = 'POST';
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
var headers = {
|
|
159
|
+
"Content-Type": contentType ,
|
|
160
|
+
"x-api-key": this.apiKey,
|
|
161
|
+
"Accept": "*/*",
|
|
162
|
+
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
163
|
+
// "Accept-Encoding": "gzip, deflate, br",
|
|
164
|
+
"Connection": "keep-alive"
|
|
165
|
+
//,
|
|
166
|
+
// "Content-Length": Buffer.byteLength(body)
|
|
167
|
+
};
|
|
168
|
+
|
|
98
169
|
|
|
99
170
|
var options;
|
|
100
171
|
|
|
@@ -104,15 +175,7 @@ class BPMNClient extends WebService {
|
|
|
104
175
|
port: this.port,
|
|
105
176
|
path: '/api/' + url,
|
|
106
177
|
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
|
-
}
|
|
178
|
+
headers: headers
|
|
116
179
|
};
|
|
117
180
|
}
|
|
118
181
|
else {
|
|
@@ -210,6 +273,7 @@ class ClientDatastore {
|
|
|
210
273
|
}
|
|
211
274
|
async findInstances(query): Promise<IInstanceData[]> {
|
|
212
275
|
const res = await this.client.get('datastore/findInstances', query);
|
|
276
|
+
|
|
213
277
|
if (res['errors']) {
|
|
214
278
|
console.log(res['errors']);
|
|
215
279
|
throw new Error(res['errors']);
|
|
@@ -227,6 +291,15 @@ class ClientDefinitions {
|
|
|
227
291
|
constructor(client) {
|
|
228
292
|
this.client = client;
|
|
229
293
|
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
async import(name, path) {
|
|
297
|
+
|
|
298
|
+
var res = await this.client.upload('definitions/import',name,path);
|
|
299
|
+
|
|
300
|
+
return res;
|
|
301
|
+
|
|
302
|
+
}
|
|
230
303
|
async list(): Promise<string[]> {
|
|
231
304
|
var res = await this.client.get('definitions/list', []);
|
|
232
305
|
if (res['errors']) {
|
|
@@ -235,9 +308,29 @@ class ClientDefinitions {
|
|
|
235
308
|
}
|
|
236
309
|
return res as string[];
|
|
237
310
|
|
|
311
|
+
}
|
|
312
|
+
async delete(name) {
|
|
313
|
+
const res = await this.client.post('definitions/delete/', { name });
|
|
314
|
+
if (res['errors']) {
|
|
315
|
+
console.log(res['errors']);
|
|
316
|
+
throw new Error(res['errors']);
|
|
317
|
+
}
|
|
318
|
+
console.log(res);
|
|
319
|
+
return res as IDefinitionData;
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
async rename(name,newName) {
|
|
323
|
+
const res = await this.client.post('definitions/rename/', { name , newName });
|
|
324
|
+
if (res['errors']) {
|
|
325
|
+
console.log(res['errors']);
|
|
326
|
+
throw new Error(res['errors']);
|
|
327
|
+
}
|
|
328
|
+
console.log(res);
|
|
329
|
+
return res as IDefinitionData;
|
|
330
|
+
|
|
238
331
|
}
|
|
239
332
|
async load(name): Promise<IDefinitionData> {
|
|
240
|
-
const res = await this.client.get(encodeURI('definitions/load/' + name), { name
|
|
333
|
+
const res = await this.client.get(encodeURI('definitions/load/' + name), { name });
|
|
241
334
|
if (res['errors']) {
|
|
242
335
|
console.log(res['errors']);
|
|
243
336
|
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
|
|