bpmn-client 1.6.0 → 2.1.5

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.
@@ -0,0 +1,252 @@
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.ClientModel2 = exports.ClientData2 = exports.ClientEngine2 = exports.BPMNClient2 = void 0;
13
+ const WebService_1 = require("./WebService");
14
+ class BPMNClient2 extends WebService_1.WebService {
15
+ constructor(host, port, apiKey) {
16
+ super();
17
+ this.host = host;
18
+ this.port = port;
19
+ this.apiKey = apiKey;
20
+ this.engine = new ClientEngine2(this);
21
+ this.data = new ClientData2(this);
22
+ this.model = new ClientModel2(this);
23
+ }
24
+ get(url, params) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ return yield this.request(url, 'GET', params);
27
+ });
28
+ }
29
+ post(url, params) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return yield this.request(url, 'POST', params);
32
+ });
33
+ }
34
+ put(url, params) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return yield this.request(url, 'PUT', params);
37
+ });
38
+ }
39
+ del(url, params) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return yield this.request(url, 'DELETE', params);
42
+ });
43
+ }
44
+ request(url, method, params) {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ var body = JSON.stringify(params);
47
+ var size = Buffer.byteLength(body);
48
+ var contentType = "application/json";
49
+ if (method == 'UPLOAD') {
50
+ contentType = 'multipart/form-data; boundary = ----WebKitFormBoundary7MA4YWxkTrZu0gW';
51
+ method = 'POST';
52
+ }
53
+ var headers = {
54
+ "Content-Type": contentType,
55
+ "x-api-key": this.apiKey,
56
+ "Accept": "*/*",
57
+ // "User-Agent": "PostmanRuntime/ 7.26.8",
58
+ // "Accept-Encoding": "gzip, deflate, br",
59
+ "Connection": "keep-alive"
60
+ //,
61
+ // "Content-Length": Buffer.byteLength(body)
62
+ };
63
+ var options;
64
+ if (params) {
65
+ options = {
66
+ host: this.host,
67
+ port: this.port,
68
+ path: '/api2/' + url,
69
+ method: method,
70
+ headers: headers
71
+ };
72
+ }
73
+ else {
74
+ options = {
75
+ host: this.host,
76
+ port: this.port,
77
+ path: '/api2/' + url,
78
+ method: method
79
+ };
80
+ }
81
+ return yield this.invoke(params, options);
82
+ });
83
+ }
84
+ }
85
+ exports.BPMNClient2 = BPMNClient2;
86
+ class ClientEngine2 {
87
+ constructor(client) {
88
+ this.client = client;
89
+ }
90
+ start(name, data = {}, user, options = {}) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const ret = yield this.client.post('engine/start', { name, data, user, options });
93
+ if (ret['errors']) {
94
+ console.log(ret['errors']);
95
+ throw new Error(ret['errors']);
96
+ }
97
+ const instance = ret;
98
+ return instance;
99
+ });
100
+ }
101
+ invoke(query, data, user, options = {}) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ console.log('invoke', options);
104
+ const ret = yield this.client.put('engine/invoke', { query, data, user, options });
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
+ assign(query, data, assignment, user) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const ret = yield this.client.put('engine/assign', { query, data, assignment, user });
116
+ if (ret['errors']) {
117
+ console.log(ret['errors']);
118
+ throw new Error(ret['errors']);
119
+ }
120
+ const instance = ret['instance'];
121
+ return instance;
122
+ });
123
+ }
124
+ throwMessage(messageId, data = {}, messageMatchingKey = {}, user, options) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey, user, options });
127
+ if (ret['errors']) {
128
+ console.log(ret['errors']);
129
+ throw new Error(ret['errors']);
130
+ }
131
+ return ret;
132
+ });
133
+ }
134
+ throwSignal(signalId, data = {}, messageMatchingKey = {}, user, options) {
135
+ return __awaiter(this, void 0, void 0, function* () {
136
+ const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey, user, options });
137
+ if (ret['errors']) {
138
+ console.log(ret['errors']);
139
+ throw new Error(ret['errors']);
140
+ }
141
+ return ret;
142
+ });
143
+ }
144
+ }
145
+ exports.ClientEngine2 = ClientEngine2;
146
+ class ClientData2 {
147
+ constructor(client) {
148
+ this.client = client;
149
+ }
150
+ findItems(query, user) {
151
+ return __awaiter(this, void 0, void 0, function* () {
152
+ var res = yield this.client.get('data/findItems', { query, user });
153
+ if (res['errors']) {
154
+ console.log(res['errors']);
155
+ throw new Error(res['errors']);
156
+ }
157
+ const items = res['items'];
158
+ return items;
159
+ });
160
+ }
161
+ findInstances(query, user) {
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const res = yield this.client.get('data/findInstances', { query, user });
164
+ if (res['errors']) {
165
+ console.log(res['errors']);
166
+ throw new Error(res['errors']);
167
+ }
168
+ const instances = res['instances'];
169
+ return instances;
170
+ });
171
+ }
172
+ deleteInstances(query, user) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ return yield this.client.del('data/deleteInstances', { query, user });
175
+ });
176
+ }
177
+ }
178
+ exports.ClientData2 = ClientData2;
179
+ class ClientModel2 {
180
+ constructor(client) {
181
+ this.client = client;
182
+ }
183
+ import(name, pathToBPMN, pathToSVG = null, user) {
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ var options = {
186
+ 'method': 'POST',
187
+ 'host': this.client.host,
188
+ 'port': this.client.port,
189
+ 'path': '/api/model/import/' + name,
190
+ 'headers': {
191
+ 'x-api-key': this.client.apiKey
192
+ },
193
+ 'maxRedirects': 20
194
+ };
195
+ console.log('import ', name, pathToBPMN, pathToSVG);
196
+ var res = yield this.client.upload(name, pathToBPMN, pathToSVG, options);
197
+ console.log('import done ', res);
198
+ this.checkErrors(res);
199
+ return res;
200
+ });
201
+ }
202
+ list() {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ var res = yield this.client.get('model/list', []);
205
+ if (res['errors']) {
206
+ console.log(res['errors']);
207
+ throw new Error(res['errors']);
208
+ }
209
+ return res;
210
+ });
211
+ }
212
+ delete(name) {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ const res = yield this.client.post('model/delete/', { name });
215
+ if (res['errors']) {
216
+ console.log(res['errors']);
217
+ throw new Error(res['errors']);
218
+ }
219
+ console.log(res);
220
+ return res;
221
+ });
222
+ }
223
+ rename(name, newName) {
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ const res = yield this.client.post('model/rename/', { name, newName });
226
+ if (res['errors']) {
227
+ console.log(res['errors']);
228
+ throw new Error(res['errors']);
229
+ }
230
+ console.log(res);
231
+ return res;
232
+ });
233
+ }
234
+ load(name) {
235
+ return __awaiter(this, void 0, void 0, function* () {
236
+ const res = yield this.client.get(encodeURI('model/load/' + name), { name });
237
+ if (res['errors']) {
238
+ console.log(res['errors']);
239
+ throw new Error(res['errors']);
240
+ }
241
+ console.log(res);
242
+ return res;
243
+ });
244
+ }
245
+ checkErrors(res) {
246
+ if (res['errors']) {
247
+ console.log(res['errors']);
248
+ throw new Error(res['errors']);
249
+ }
250
+ }
251
+ }
252
+ exports.ClientModel2 = ClientModel2;
@@ -1,82 +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.host + ':' + 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);
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;
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.host + ':' + 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);
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;