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.ts CHANGED
@@ -1,104 +1,8 @@
1
1
  import { IInstanceData, IItemData , IDefinitionData} from './interfaces/DataObjects';
2
-
2
+ import {WebService} from './WebService';
3
3
  console.log("BPMNClient 1.2");
4
4
 
5
- const https = require('https');
6
- const http = require('http');
7
- const fs = require("fs");
8
-
9
- class WebService {
10
- statusCode;
11
- result;
12
- response;
13
- constructor() { }
14
-
15
- async invoke(params, options, postData = null) {
16
-
17
- var axios = require('axios');
18
-
19
- var data = JSON.stringify(params);
20
- var url = 'http://'+options.host+':'+options.port+options.path;
21
-
22
- if (options.port == 443)
23
- url = 'https://'+options.host+options.path;
24
-
25
- var config = {
26
- method: options.method,
27
- url: url,
28
- headers: options.headers,
29
- data: data
30
- };
31
-
32
- let self = this;
33
-
34
- let response = await axios(config);
35
- self.result = response.data;
36
-
37
- return response.data;
38
- }
39
- async invokeOld(params, options,postData=null) {
40
-
41
- var driver = http;
42
-
43
- var body = JSON.stringify(params);
44
- console.log('invoke:');
45
- console.log('options:',options, params);
46
- if (options.port == 443)
47
- driver = https;
48
-
49
- let data = '';
50
- let self = this;
51
- return new Promise(function (resolve, reject) {
52
- try {
53
-
54
- var req = driver.request(options, function (res) {
55
- console.log('STATUS: ' + res.statusCode);
56
- this.response = res;
57
- //console.log(res);
58
- self.statusCode = res.statusCode;
59
- res.setEncoding('utf8');
60
- res.on('data', function (chunk) {
61
- console.log('>>chunk', chunk);
62
- data += chunk;
63
- });
64
- res.on('end', () => {
65
- console.log('response end');
66
- try {
67
- if (data == null)
68
- console.log("empty response");
69
- console.log('data:', data);
70
-
71
- self.result = JSON.parse(data);
72
- resolve(self.result);
73
- }
74
- catch (exc) {
75
- console.log(data);
76
- console.log(exc);
77
- }
78
- });
79
-
80
-
81
- });
82
- req.on("error", (err) => {
83
- console.log("Error: " + err.message);
84
- reject(err);
85
- });
86
- if (postData !== null)
87
- req.write(postData);
88
- else
89
- req.write('');
90
- console.log('request ending',body);
91
- req.end(body);
92
- console.log('request ended');
93
- }
94
- catch (exc) {
95
- console.log(exc);
96
- }
97
-
98
- });
99
5
 
100
- }
101
- }
102
6
  class BPMNClient extends WebService {
103
7
  host;
104
8
  port;
@@ -109,7 +13,7 @@ class BPMNClient extends WebService {
109
13
 
110
14
  constructor(host, port, apiKey) {
111
15
  super();
112
- ;
16
+
113
17
  this.host = host;
114
18
  this.port = port;
115
19
  this.apiKey = apiKey;
@@ -135,49 +39,6 @@ class BPMNClient extends WebService {
135
39
 
136
40
  }
137
41
 
138
- async upload(url, fileName, path) {
139
- console.log('upload');
140
- var options = {
141
- 'method': 'POST',
142
- 'hostname': this.host,
143
- 'port': this.port,
144
- 'path': '/api/'+ url + '/' + fileName,
145
- 'headers': {
146
- 'x-api-key': this.apiKey
147
- },
148
- 'maxRedirects': 20
149
- };
150
- var req = http.request(options, function (res) {
151
- var chunks = [];
152
-
153
- res.on("data", function (chunk) {
154
- chunks.push(chunk);
155
- });
156
-
157
- res.on("end", function (chunk) {
158
- var body = Buffer.concat(chunks);
159
- console.log(body.toString());
160
- });
161
-
162
- res.on("error", function (error) {
163
- console.error(error);
164
- });
165
- });
166
-
167
- var postData = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\""
168
- + fileName + "\"\r\nContent-Type: \"text/plain\"\r\n\r\n" +
169
- fs.readFileSync(path) + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--";
170
-
171
- req.setHeader('content-type', 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW');
172
-
173
- req.write(postData);
174
-
175
- req.end();
176
-
177
- return req;
178
- }
179
-
180
-
181
42
  async request(url, method, params) {
182
43
 
183
44
  var body = JSON.stringify(params);
@@ -324,12 +185,24 @@ class ClientDefinitions {
324
185
  constructor(client) {
325
186
  this.client = client;
326
187
  }
327
-
328
188
 
329
- async import(name, path) {
189
+ async import(name, pathToBPMN,pathToSVG=null) {
330
190
 
331
- var res = await this.client.upload('definitions/import',name,path);
191
+ var options = {
192
+ 'method': 'POST',
193
+ 'hostname': this.client.host,
194
+ 'port': this.client.port,
195
+ 'path': '/api/definitions/import/' + name,
196
+ 'headers': {
197
+ 'x-api-key': this.client.apiKey
198
+ },
199
+ 'maxRedirects': 20
200
+ };
332
201
 
202
+ console.log('import ',name,pathToBPMN,pathToSVG);
203
+ var res = await this.client.upload(name,pathToBPMN,pathToSVG,options);
204
+ console.log('import done ',res);
205
+ this.checkErrors(res);
333
206
  return res;
334
207
 
335
208
  }
@@ -371,6 +244,12 @@ class ClientDefinitions {
371
244
  console.log(res);
372
245
  return res as IDefinitionData;
373
246
  }
247
+ checkErrors(res) {
248
+ if (res['errors']) {
249
+ console.log(res['errors']);
250
+ throw new Error(res['errors']);
251
+ }
252
+ }
374
253
  }
375
254
 
376
255
 
@@ -0,0 +1,82 @@
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.WebService = void 0;
13
+ const https = require('https');
14
+ const http = require('http');
15
+ const fs = require("fs");
16
+ const axios = require('axios');
17
+ const FormData = require('form-data');
18
+ class WebService {
19
+ constructor() { }
20
+ invoke(params, options, postData = null) {
21
+ return __awaiter(this, void 0, void 0, function* () {
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
+ try {
34
+ let response = yield axios(config);
35
+ self.result = response.data;
36
+ return response.data;
37
+ }
38
+ catch (err) {
39
+ console.log('** Connection failed ***', err);
40
+ }
41
+ });
42
+ }
43
+ upload(fileName, path, path2, options) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const title = fileName;
46
+ var url = 'http://' + options.hostname + ':' + options.port + options.path;
47
+ if (options.port == 443)
48
+ url = 'https://' + options.host + options.path;
49
+ const form = new FormData();
50
+ form.append('title', title);
51
+ const fileContents = fs.createReadStream(path);
52
+ form.append('file', fileContents);
53
+ if (path2 !== null) {
54
+ const fileContents2 = fs.createReadStream(path2);
55
+ form.append('file', fileContents2);
56
+ }
57
+ try {
58
+ const response = yield axios.post(url, form, {
59
+ headers: options.headers
60
+ });
61
+ console.log('Response Status:', response.status, response.data);
62
+ return response.data;
63
+ }
64
+ catch (error) {
65
+ console.log('upload failed:', error.message);
66
+ throw new Error(error.message);
67
+ /*
68
+ if (error.response) { // get response with a status code not in range 2xx
69
+ console.log(error.response.data);
70
+ console.log(error.response.status);
71
+ console.log(error.response.headers);
72
+ } else if (error.request) { // no response
73
+ console.log(error.request);
74
+ } else { // Something wrong in setting up the request
75
+ console.log('Error', error.message);
76
+ }
77
+ console.log(error.config); */
78
+ }
79
+ });
80
+ }
81
+ }
82
+ exports.WebService = WebService;
@@ -0,0 +1,91 @@
1
+
2
+ const https = require('https');
3
+ const http = require('http');
4
+ const fs = require("fs");
5
+ const axios = require('axios');
6
+ const FormData = require('form-data');
7
+
8
+ class WebService {
9
+ statusCode;
10
+ result;
11
+ response;
12
+ constructor() { }
13
+
14
+ async invoke(params, options, postData = null) {
15
+
16
+
17
+ var data = JSON.stringify(params);
18
+ var url = 'http://'+options.host+':'+options.port+options.path;
19
+
20
+ if (options.port == 443)
21
+ url = 'https://'+options.host+options.path;
22
+
23
+ var config = {
24
+ method: options.method,
25
+ url: url,
26
+ headers: options.headers,
27
+ data: data
28
+ };
29
+
30
+ let self = this;
31
+ try {
32
+ let response = await axios(config);
33
+ self.result = response.data;
34
+
35
+ return response.data;
36
+ }
37
+ catch(err)
38
+ {
39
+ console.log('** Connection failed ***',err);
40
+ }
41
+ }
42
+
43
+ async upload(fileName, path,path2, options) {
44
+
45
+ const title = fileName;
46
+
47
+ var url = 'http://'+options.hostname+':'+options.port+options.path;
48
+
49
+ if (options.port == 443)
50
+ url = 'https://'+options.host+options.path;
51
+
52
+
53
+ const form = new FormData();
54
+ form.append('title', title);
55
+ const fileContents = fs.createReadStream(path);
56
+ form.append('file', fileContents);
57
+ if (path2!==null)
58
+ {
59
+ const fileContents2 = fs.createReadStream(path2);
60
+ form.append('file', fileContents2);
61
+ }
62
+
63
+
64
+ try {
65
+
66
+ const response = await axios.post(url, form, {
67
+ headers: options.headers });
68
+
69
+ console.log('Response Status:',response.status,response.data);
70
+ return response.data;
71
+
72
+ }
73
+ catch (error) {
74
+ console.log('upload failed:',error.message);
75
+ throw new Error(error.message);
76
+ /*
77
+ if (error.response) { // get response with a status code not in range 2xx
78
+ console.log(error.response.data);
79
+ console.log(error.response.status);
80
+ console.log(error.response.headers);
81
+ } else if (error.request) { // no response
82
+ console.log(error.request);
83
+ } else { // Something wrong in setting up the request
84
+ console.log('Error', error.message);
85
+ }
86
+ console.log(error.config); */
87
+ }
88
+ }
89
+
90
+ }
91
+ export {WebService }
package/src/index.js CHANGED
@@ -1,15 +1,19 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./interfaces/Enums"), exports);
14
- __exportStar(require("./interfaces/DataObjects"), exports);
15
- __exportStar(require("./BPMNClient"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interfaces/Enums"), exports);
18
+ __exportStar(require("./interfaces/DataObjects"), exports);
19
+ __exportStar(require("./BPMNClient"), exports);
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -6,6 +6,7 @@ interface IItemData {
6
6
  elementId: string; // bpmn element
7
7
  name: string; // name of bpmn element
8
8
  type: string; // bpmn element type
9
+ instanceId: string; // Instance Id of the item
9
10
  tokenId: any; // execution Token
10
11
  userId: any;
11
12
  startedAt: any;
@@ -19,6 +20,7 @@ interface IItemData {
19
20
  assignments;
20
21
  authorizations;
21
22
  notifications;
23
+ vars;
22
24
  }
23
25
  interface IInstanceData {
24
26
  id;