bpmn-client 1.3.17 → 1.3.26

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/src/BPMNClient.js CHANGED
@@ -1,358 +1,262 @@
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
- exports.ClientDefinitions = exports.ClientDatastore = exports.ClientEngine = exports.BPMNClient = void 0;
13
- console.log("BPMNClient 1.2");
14
- const https = require('https');
15
- const http = require('http');
16
- const fs = require("fs");
17
- class WebService {
18
- constructor() { }
19
- invoke(params, options, postData = null) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- var axios = require('axios');
22
- var data = JSON.stringify(params);
23
- var url = 'http://' + options.host + ':' + options.port + options.path;
24
- if (options.port == 443)
25
- url = 'https://' + options.host + options.path;
26
- var config = {
27
- method: options.method,
28
- url: url,
29
- headers: options.headers,
30
- data: data
31
- };
32
- let self = this;
33
- let response = yield axios(config);
34
- self.result = response.data;
35
- return response.data;
36
- });
37
- }
38
- invokeOld(params, options, postData = null) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- var driver = http;
41
- var body = JSON.stringify(params);
42
- console.log('invoke:');
43
- console.log('options:', options, params);
44
- if (options.port == 443)
45
- driver = https;
46
- let data = '';
47
- let self = this;
48
- return new Promise(function (resolve, reject) {
49
- try {
50
- var req = driver.request(options, function (res) {
51
- console.log('STATUS: ' + res.statusCode);
52
- this.response = res;
53
- //console.log(res);
54
- self.statusCode = res.statusCode;
55
- res.setEncoding('utf8');
56
- res.on('data', function (chunk) {
57
- console.log('>>chunk', chunk);
58
- data += chunk;
59
- });
60
- res.on('end', () => {
61
- console.log('response end');
62
- try {
63
- if (data == null)
64
- console.log("empty response");
65
- console.log('data:', data);
66
- self.result = JSON.parse(data);
67
- resolve(self.result);
68
- }
69
- catch (exc) {
70
- console.log(data);
71
- console.log(exc);
72
- }
73
- });
74
- });
75
- req.on("error", (err) => {
76
- console.log("Error: " + err.message);
77
- reject(err);
78
- });
79
- if (postData !== null)
80
- req.write(postData);
81
- else
82
- req.write('');
83
- console.log('request ending', body);
84
- req.end(body);
85
- console.log('request ended');
86
- }
87
- catch (exc) {
88
- console.log(exc);
89
- }
90
- });
91
- });
92
- }
93
- }
94
- class BPMNClient extends WebService {
95
- constructor(host, port, apiKey) {
96
- super();
97
- ;
98
- this.host = host;
99
- this.port = port;
100
- this.apiKey = apiKey;
101
- this.engine = new ClientEngine(this);
102
- this.datastore = new ClientDatastore(this);
103
- this.definitions = new ClientDefinitions(this);
104
- }
105
- get(url, data = {}) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- return yield this.request(url, 'GET', data);
108
- });
109
- }
110
- post(url, data = {}) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- return yield this.request(url, 'POST', data);
113
- });
114
- }
115
- put(url, data = {}) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- return yield this.request(url, 'PUT', data);
118
- });
119
- }
120
- del(url, data = {}) {
121
- return __awaiter(this, void 0, void 0, function* () {
122
- return yield this.request(url, 'DELETE', data);
123
- });
124
- }
125
- upload(url, fileName, path) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- console.log('upload');
128
- var options = {
129
- 'method': 'POST',
130
- 'hostname': this.host,
131
- 'port': this.port,
132
- 'path': '/api/' + url + '/' + fileName,
133
- 'headers': {
134
- 'x-api-key': this.apiKey
135
- },
136
- 'maxRedirects': 20
137
- };
138
- var req = http.request(options, function (res) {
139
- var chunks = [];
140
- res.on("data", function (chunk) {
141
- chunks.push(chunk);
142
- });
143
- res.on("end", function (chunk) {
144
- var body = Buffer.concat(chunks);
145
- console.log(body.toString());
146
- });
147
- res.on("error", function (error) {
148
- console.error(error);
149
- });
150
- });
151
- var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
152
- + fileName + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
153
- fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
154
- req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
155
- req.write(postData);
156
- req.end();
157
- return req;
158
- });
159
- }
160
- request(url, method, params) {
161
- return __awaiter(this, void 0, void 0, function* () {
162
- var body = JSON.stringify(params);
163
- var size = Buffer.byteLength(body);
164
- var contentType = "application/json";
165
- if (method == 'UPLOAD') {
166
- contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
167
- method = 'POST';
168
- }
169
- var headers = {
170
- "Content-Type": contentType,
171
- "x-api-key": this.apiKey,
172
- "Accept": "*/*",
173
- // "User-Agent": "PostmanRuntime/ 7.26.8",
174
- // "Accept-Encoding": "gzip, deflate, br",
175
- "Connection": "keep-alive"
176
- //,
177
- // "Content-Length": Buffer.byteLength(body)
178
- };
179
- var options;
180
- if (params) {
181
- options = {
182
- host: this.host,
183
- port: this.port,
184
- path: '/api/' + url,
185
- method: method,
186
- headers: headers
187
- };
188
- }
189
- else {
190
- options = {
191
- host: this.host,
192
- port: this.port,
193
- path: '/api/' + url,
194
- method: method
195
- };
196
- }
197
- return yield this.invoke(params, options);
198
- });
199
- }
200
- }
201
- exports.BPMNClient = BPMNClient;
202
- class ClientEngine {
203
- constructor(client) {
204
- this.client = client;
205
- }
206
- start(name, data = {}, startNodeId = null, options = {}) {
207
- return __awaiter(this, void 0, void 0, function* () {
208
- const ret = yield this.client.post('engine/start', { name, data, startNodeId, options });
209
- if (ret['errors']) {
210
- console.log(ret['errors']);
211
- throw new Error(ret['errors']);
212
- }
213
- const instance = ret;
214
- return instance;
215
- });
216
- }
217
- invoke(query, data) {
218
- return __awaiter(this, void 0, void 0, function* () {
219
- const ret = yield this.client.put('engine/invoke', { query, data });
220
- if (ret['errors']) {
221
- console.log(ret['errors']);
222
- throw new Error(ret['errors']);
223
- }
224
- const instance = ret['instance'];
225
- return instance;
226
- });
227
- }
228
- throwMessage(messageId, data = {}, messageMatchingKey = {}) {
229
- return __awaiter(this, void 0, void 0, function* () {
230
- const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
231
- if (ret['errors']) {
232
- console.log(ret['errors']);
233
- throw new Error(ret['errors']);
234
- }
235
- return ret;
236
- });
237
- }
238
- throwSignal(signalId, data = {}, messageMatchingKey = {}) {
239
- return __awaiter(this, void 0, void 0, function* () {
240
- const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
241
- if (ret['errors']) {
242
- console.log(ret['errors']);
243
- throw new Error(ret['errors']);
244
- }
245
- return ret;
246
- });
247
- }
248
- get(query) {
249
- return __awaiter(this, void 0, void 0, function* () {
250
- const ret = yield this.client.get('engine/get', query);
251
- if (ret['errors']) {
252
- console.log(ret['errors']);
253
- throw new Error(ret['errors']);
254
- }
255
- const instance = ret['instance'];
256
- return instance;
257
- });
258
- }
259
- status() {
260
- return __awaiter(this, void 0, void 0, function* () {
261
- const ret = yield this.client.get('engine/status', {});
262
- if (ret['errors']) {
263
- console.log(ret['errors']);
264
- throw new Error(ret['errors']);
265
- }
266
- return ret;
267
- });
268
- }
269
- }
270
- exports.ClientEngine = ClientEngine;
271
- class ClientDatastore {
272
- constructor(client) {
273
- this.client = client;
274
- }
275
- findItems(query) {
276
- return __awaiter(this, void 0, void 0, function* () {
277
- var res = yield this.client.get('datastore/findItems', query);
278
- if (res['errors']) {
279
- console.log(res['errors']);
280
- throw new Error(res['errors']);
281
- }
282
- const items = res['items'];
283
- return items;
284
- });
285
- }
286
- findInstances(query) {
287
- return __awaiter(this, void 0, void 0, function* () {
288
- const res = yield this.client.get('datastore/findInstances', query);
289
- if (res['errors']) {
290
- console.log(res['errors']);
291
- throw new Error(res['errors']);
292
- }
293
- const instances = res['instances'];
294
- return instances;
295
- });
296
- }
297
- deleteInstances(query) {
298
- return __awaiter(this, void 0, void 0, function* () {
299
- return yield this.client.del('datastore/deleteInstances', query);
300
- });
301
- }
302
- }
303
- exports.ClientDatastore = ClientDatastore;
304
- class ClientDefinitions {
305
- constructor(client) {
306
- this.client = client;
307
- }
308
- import(name, path) {
309
- return __awaiter(this, void 0, void 0, function* () {
310
- var res = yield this.client.upload('definitions/import', name, path);
311
- return res;
312
- });
313
- }
314
- list() {
315
- return __awaiter(this, void 0, void 0, function* () {
316
- var res = yield this.client.get('definitions/list', []);
317
- if (res['errors']) {
318
- console.log(res['errors']);
319
- throw new Error(res['errors']);
320
- }
321
- return res;
322
- });
323
- }
324
- delete(name) {
325
- return __awaiter(this, void 0, void 0, function* () {
326
- const res = yield this.client.post('definitions/delete/', { name });
327
- if (res['errors']) {
328
- console.log(res['errors']);
329
- throw new Error(res['errors']);
330
- }
331
- console.log(res);
332
- return res;
333
- });
334
- }
335
- rename(name, newName) {
336
- return __awaiter(this, void 0, void 0, function* () {
337
- const res = yield this.client.post('definitions/rename/', { name, newName });
338
- if (res['errors']) {
339
- console.log(res['errors']);
340
- throw new Error(res['errors']);
341
- }
342
- console.log(res);
343
- return res;
344
- });
345
- }
346
- load(name) {
347
- return __awaiter(this, void 0, void 0, function* () {
348
- const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
349
- if (res['errors']) {
350
- console.log(res['errors']);
351
- throw new Error(res['errors']);
352
- }
353
- console.log(res);
354
- return res;
355
- });
356
- }
357
- }
358
- exports.ClientDefinitions = ClientDefinitions;
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
+ exports.ClientDefinitions = exports.ClientDatastore = exports.ClientEngine = exports.BPMNClient = void 0;
13
+ const WebService_1 = require("./WebService");
14
+ console.log("BPMNClient 1.2");
15
+ class BPMNClient extends WebService_1.WebService {
16
+ constructor(host, port, apiKey) {
17
+ super();
18
+ this.host = host;
19
+ this.port = port;
20
+ this.apiKey = apiKey;
21
+ this.engine = new ClientEngine(this);
22
+ this.datastore = new ClientDatastore(this);
23
+ this.definitions = new ClientDefinitions(this);
24
+ }
25
+ get(url, data = {}) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return yield this.request(url, 'GET', data);
28
+ });
29
+ }
30
+ post(url, data = {}) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return yield this.request(url, 'POST', data);
33
+ });
34
+ }
35
+ put(url, data = {}) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return yield this.request(url, 'PUT', data);
38
+ });
39
+ }
40
+ del(url, data = {}) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ return yield this.request(url, 'DELETE', data);
43
+ });
44
+ }
45
+ request(url, method, params) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ var body = JSON.stringify(params);
48
+ var size = Buffer.byteLength(body);
49
+ var contentType = "application/json";
50
+ if (method == 'UPLOAD') {
51
+ contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
52
+ method = 'POST';
53
+ }
54
+ var headers = {
55
+ "Content-Type": contentType,
56
+ "x-api-key": this.apiKey,
57
+ "Accept": "*/*",
58
+ // "User-Agent": "PostmanRuntime/ 7.26.8",
59
+ // "Accept-Encoding": "gzip, deflate, br",
60
+ "Connection": "keep-alive"
61
+ //,
62
+ // "Content-Length": Buffer.byteLength(body)
63
+ };
64
+ var options;
65
+ if (params) {
66
+ options = {
67
+ host: this.host,
68
+ port: this.port,
69
+ path: '/api/' + url,
70
+ method: method,
71
+ headers: headers
72
+ };
73
+ }
74
+ else {
75
+ options = {
76
+ host: this.host,
77
+ port: this.port,
78
+ path: '/api/' + url,
79
+ method: method
80
+ };
81
+ }
82
+ return yield this.invoke(params, options);
83
+ });
84
+ }
85
+ }
86
+ exports.BPMNClient = BPMNClient;
87
+ class ClientEngine {
88
+ constructor(client) {
89
+ this.client = client;
90
+ }
91
+ start(name, data = {}, startNodeId = null, options = {}) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const ret = yield this.client.post('engine/start', { name, data, startNodeId, options });
94
+ if (ret['errors']) {
95
+ console.log(ret['errors']);
96
+ throw new Error(ret['errors']);
97
+ }
98
+ const instance = ret;
99
+ return instance;
100
+ });
101
+ }
102
+ invoke(query, data) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const ret = yield this.client.put('engine/invoke', { query, data });
105
+ if (ret['errors']) {
106
+ console.log(ret['errors']);
107
+ throw new Error(ret['errors']);
108
+ }
109
+ const instance = ret['instance'];
110
+ return instance;
111
+ });
112
+ }
113
+ throwMessage(messageId, data = {}, messageMatchingKey = {}) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
116
+ if (ret['errors']) {
117
+ console.log(ret['errors']);
118
+ throw new Error(ret['errors']);
119
+ }
120
+ return ret;
121
+ });
122
+ }
123
+ throwSignal(signalId, data = {}, messageMatchingKey = {}) {
124
+ return __awaiter(this, void 0, void 0, function* () {
125
+ const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
126
+ if (ret['errors']) {
127
+ console.log(ret['errors']);
128
+ throw new Error(ret['errors']);
129
+ }
130
+ return ret;
131
+ });
132
+ }
133
+ get(query) {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const ret = yield this.client.get('engine/get', query);
136
+ if (ret['errors']) {
137
+ console.log(ret['errors']);
138
+ throw new Error(ret['errors']);
139
+ }
140
+ const instance = ret['instance'];
141
+ return instance;
142
+ });
143
+ }
144
+ status() {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ const ret = yield this.client.get('engine/status', {});
147
+ if (ret['errors']) {
148
+ console.log(ret['errors']);
149
+ throw new Error(ret['errors']);
150
+ }
151
+ return ret;
152
+ });
153
+ }
154
+ }
155
+ exports.ClientEngine = ClientEngine;
156
+ class ClientDatastore {
157
+ constructor(client) {
158
+ this.client = client;
159
+ }
160
+ findItems(query) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ var res = yield this.client.get('datastore/findItems', query);
163
+ if (res['errors']) {
164
+ console.log(res['errors']);
165
+ throw new Error(res['errors']);
166
+ }
167
+ const items = res['items'];
168
+ return items;
169
+ });
170
+ }
171
+ findInstances(query) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ const res = yield this.client.get('datastore/findInstances', query);
174
+ if (res['errors']) {
175
+ console.log(res['errors']);
176
+ throw new Error(res['errors']);
177
+ }
178
+ const instances = res['instances'];
179
+ return instances;
180
+ });
181
+ }
182
+ deleteInstances(query) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ return yield this.client.del('datastore/deleteInstances', query);
185
+ });
186
+ }
187
+ }
188
+ exports.ClientDatastore = ClientDatastore;
189
+ class ClientDefinitions {
190
+ constructor(client) {
191
+ this.client = client;
192
+ }
193
+ import(name, pathToBPMN, pathToSVG = null) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ var options = {
196
+ 'method': 'POST',
197
+ 'hostname': this.client.host,
198
+ 'port': this.client.port,
199
+ 'path': '/api/definitions/import/' + name,
200
+ 'headers': {
201
+ 'x-api-key': this.client.apiKey
202
+ },
203
+ 'maxRedirects': 20
204
+ };
205
+ console.log('import ', name, pathToBPMN, pathToSVG);
206
+ var res = yield this.client.upload(name, pathToBPMN, pathToSVG, options);
207
+ console.log('import done ', res);
208
+ this.checkErrors(res);
209
+ return res;
210
+ });
211
+ }
212
+ list() {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ var res = yield this.client.get('definitions/list', []);
215
+ if (res['errors']) {
216
+ console.log(res['errors']);
217
+ throw new Error(res['errors']);
218
+ }
219
+ return res;
220
+ });
221
+ }
222
+ delete(name) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ const res = yield this.client.post('definitions/delete/', { name });
225
+ if (res['errors']) {
226
+ console.log(res['errors']);
227
+ throw new Error(res['errors']);
228
+ }
229
+ console.log(res);
230
+ return res;
231
+ });
232
+ }
233
+ rename(name, newName) {
234
+ return __awaiter(this, void 0, void 0, function* () {
235
+ const res = yield this.client.post('definitions/rename/', { name, newName });
236
+ if (res['errors']) {
237
+ console.log(res['errors']);
238
+ throw new Error(res['errors']);
239
+ }
240
+ console.log(res);
241
+ return res;
242
+ });
243
+ }
244
+ load(name) {
245
+ return __awaiter(this, void 0, void 0, function* () {
246
+ const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
247
+ if (res['errors']) {
248
+ console.log(res['errors']);
249
+ throw new Error(res['errors']);
250
+ }
251
+ console.log(res);
252
+ return res;
253
+ });
254
+ }
255
+ checkErrors(res) {
256
+ if (res['errors']) {
257
+ console.log(res['errors']);
258
+ throw new Error(res['errors']);
259
+ }
260
+ }
261
+ }
262
+ exports.ClientDefinitions = ClientDefinitions;