bpmn-client 2.2.4 → 2.3.2

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.
@@ -1,295 +1,306 @@
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
- class BPMNClient 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 ClientEngine(this);
21
- this.datastore = new ClientDatastore(this);
22
- this.definitions = new ClientDefinitions(this);
23
- }
24
- get(url, data = {}) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return yield this.request(url, 'GET', data);
27
- });
28
- }
29
- post(url, data = {}) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- return yield this.request(url, 'POST', data);
32
- });
33
- }
34
- put(url, data = {}) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return yield this.request(url, 'PUT', data);
37
- });
38
- }
39
- del(url, data = {}) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return yield this.request(url, 'DELETE', data);
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: '/api/' + url,
69
- method: method,
70
- headers: headers
71
- };
72
- }
73
- else {
74
- options = {
75
- host: this.host,
76
- port: this.port,
77
- path: '/api/' + url,
78
- method: method
79
- };
80
- }
81
- return yield this.invoke(params, options);
82
- });
83
- }
84
- }
85
- exports.BPMNClient = BPMNClient;
86
- class ClientEngine {
87
- constructor(client) {
88
- this.client = client;
89
- }
90
- start(name, data = {}, startNodeId = null, userId = null, options = {}) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- const ret = yield this.client.post('engine/start', { name, data, startNodeId, userId, 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, userId = null, 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, userId, 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, userId = null, assignment) {
114
- return __awaiter(this, void 0, void 0, function* () {
115
- const ret = yield this.client.put('engine/assign', { query, data, userId, assignment });
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
- restart(query, data, userId = null, options = {}) {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- console.log('invoke', options);
127
- const ret = yield this.client.put('engine/restart', { query, data, userId, options });
128
- if (ret['errors']) {
129
- console.log(ret['errors']);
130
- throw new Error(ret['errors']);
131
- }
132
- const instance = ret['instance'];
133
- return instance;
134
- });
135
- }
136
- throwMessage(messageId, data = {}, messageMatchingKey = {}) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
139
- if (ret['errors']) {
140
- console.log(ret['errors']);
141
- throw new Error(ret['errors']);
142
- }
143
- return ret;
144
- });
145
- }
146
- throwSignal(signalId, data = {}, messageMatchingKey = {}) {
147
- return __awaiter(this, void 0, void 0, function* () {
148
- const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
149
- if (ret['errors']) {
150
- console.log(ret['errors']);
151
- throw new Error(ret['errors']);
152
- }
153
- return ret;
154
- });
155
- }
156
- startEvent(instanceId, startNodeId, data = {}, userId = null, options = {}) {
157
- return __awaiter(this, void 0, void 0, function* () {
158
- const ret = yield this.client.put('engine/startEvent', { "instanceId": instanceId, "startNodeId": startNodeId, "data": data, "userName": userId, "options": options });
159
- if (ret['errors']) {
160
- console.log(ret['errors']);
161
- throw new Error(ret['errors']);
162
- }
163
- return ret;
164
- });
165
- }
166
- get(query) {
167
- return __awaiter(this, void 0, void 0, function* () {
168
- const ret = yield this.client.get('engine/get', query);
169
- if (ret['errors']) {
170
- console.log(ret['errors']);
171
- throw new Error(ret['errors']);
172
- }
173
- const instance = ret['instance'];
174
- return instance;
175
- });
176
- }
177
- status() {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- const ret = yield this.client.get('engine/status', {});
180
- if (ret['errors']) {
181
- console.log(ret['errors']);
182
- throw new Error(ret['errors']);
183
- }
184
- return ret;
185
- });
186
- }
187
- }
188
- exports.ClientEngine = ClientEngine;
189
- class ClientDatastore {
190
- constructor(client) {
191
- this.client = client;
192
- }
193
- findItems(query) {
194
- return __awaiter(this, void 0, void 0, function* () {
195
- var res = yield this.client.get('datastore/findItems', query);
196
- if (res['errors']) {
197
- console.log(res['errors']);
198
- throw new Error(res['errors']);
199
- }
200
- const items = res['items'];
201
- return items;
202
- });
203
- }
204
- findInstances(query, projection = {}) {
205
- return __awaiter(this, void 0, void 0, function* () {
206
- const res = yield this.client.get('datastore/findInstances', { query, projection });
207
- if (res['errors']) {
208
- console.log(res['errors']);
209
- throw new Error(res['errors']);
210
- }
211
- const instances = res['instances'];
212
- return instances;
213
- });
214
- }
215
- deleteInstances(query) {
216
- return __awaiter(this, void 0, void 0, function* () {
217
- return yield this.client.del('datastore/deleteInstances', query);
218
- });
219
- }
220
- }
221
- exports.ClientDatastore = ClientDatastore;
222
- class ClientDefinitions {
223
- constructor(client) {
224
- this.client = client;
225
- }
226
- import(name, pathToBPMN, pathToSVG = null) {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- var options = {
229
- 'method': 'POST',
230
- 'host': this.client.host,
231
- 'port': this.client.port,
232
- 'path': '/api/definitions/import/' + name,
233
- 'headers': {
234
- 'x-api-key': this.client.apiKey
235
- },
236
- 'maxRedirects': 20
237
- };
238
- console.log('import ', name, pathToBPMN, pathToSVG);
239
- var res = yield this.client.upload(name, pathToBPMN, pathToSVG, options);
240
- console.log('import done ', res);
241
- this.checkErrors(res);
242
- return res;
243
- });
244
- }
245
- list() {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- var res = yield this.client.get('definitions/list', []);
248
- if (res['errors']) {
249
- console.log(res['errors']);
250
- throw new Error(res['errors']);
251
- }
252
- return res;
253
- });
254
- }
255
- delete(name) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- const res = yield this.client.post('definitions/delete/', { name });
258
- if (res['errors']) {
259
- console.log(res['errors']);
260
- throw new Error(res['errors']);
261
- }
262
- console.log(res);
263
- return res;
264
- });
265
- }
266
- rename(name, newName) {
267
- return __awaiter(this, void 0, void 0, function* () {
268
- const res = yield this.client.post('definitions/rename/', { name, newName });
269
- if (res['errors']) {
270
- console.log(res['errors']);
271
- throw new Error(res['errors']);
272
- }
273
- console.log(res);
274
- return res;
275
- });
276
- }
277
- load(name) {
278
- return __awaiter(this, void 0, void 0, function* () {
279
- const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
280
- if (res['errors']) {
281
- console.log(res['errors']);
282
- throw new Error(res['errors']);
283
- }
284
- console.log(res);
285
- return res;
286
- });
287
- }
288
- checkErrors(res) {
289
- if (res['errors']) {
290
- console.log(res['errors']);
291
- throw new Error(res['errors']);
292
- }
293
- }
294
- }
295
- 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
+ class BPMNClient 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 ClientEngine(this);
21
+ this.datastore = new ClientDatastore(this);
22
+ this.definitions = new ClientDefinitions(this);
23
+ }
24
+ get(url_1) {
25
+ return __awaiter(this, arguments, void 0, function* (url, data = {}) {
26
+ return yield this.request(url, 'GET', data);
27
+ });
28
+ }
29
+ post(url_1) {
30
+ return __awaiter(this, arguments, void 0, function* (url, data = {}) {
31
+ return yield this.request(url, 'POST', data);
32
+ });
33
+ }
34
+ put(url_1) {
35
+ return __awaiter(this, arguments, void 0, function* (url, data = {}) {
36
+ return yield this.request(url, 'PUT', data);
37
+ });
38
+ }
39
+ del(url_1) {
40
+ return __awaiter(this, arguments, void 0, function* (url, data = {}) {
41
+ return yield this.request(url, 'DELETE', data);
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: '/api/' + url,
69
+ method: method,
70
+ headers: headers
71
+ };
72
+ }
73
+ else {
74
+ options = {
75
+ host: this.host,
76
+ port: this.port,
77
+ path: '/api/' + url,
78
+ method: method
79
+ };
80
+ }
81
+ return yield this.invoke(params, options);
82
+ });
83
+ }
84
+ }
85
+ exports.BPMNClient = BPMNClient;
86
+ class ClientEngine {
87
+ constructor(client) {
88
+ this.client = client;
89
+ }
90
+ start(name_1) {
91
+ return __awaiter(this, arguments, void 0, function* (name, data = {}, startNodeId = null, userId = null, options = {}) {
92
+ const ret = yield this.client.post('engine/start', { name, data, startNodeId, userId, 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_1, data_1) {
102
+ return __awaiter(this, arguments, void 0, function* (query, data, userId = null, options = {}) {
103
+ console.log('invoke', options);
104
+ const ret = yield this.client.put('engine/invoke', { query, data, userId, 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_1, data_1) {
114
+ return __awaiter(this, arguments, void 0, function* (query, data, userId = null, assignment) {
115
+ const ret = yield this.client.put('engine/assign', { query, data, userId, assignment });
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
+ restart(query_1, data_1) {
125
+ return __awaiter(this, arguments, void 0, function* (query, data, userId = null, options = {}) {
126
+ console.log('invoke', options);
127
+ const ret = yield this.client.put('engine/restart', { query, data, userId, options });
128
+ if (ret['errors']) {
129
+ console.log(ret['errors']);
130
+ throw new Error(ret['errors']);
131
+ }
132
+ const instance = ret['instance'];
133
+ return instance;
134
+ });
135
+ }
136
+ throwMessage(messageId_1) {
137
+ return __awaiter(this, arguments, void 0, function* (messageId, data = {}, messageMatchingKey = {}) {
138
+ const ret = yield this.client.post('engine/throwMessage', { "messageId": messageId, "data": data, messageMatchingKey });
139
+ if (ret['errors']) {
140
+ console.log(ret['errors']);
141
+ throw new Error(ret['errors']);
142
+ }
143
+ return ret;
144
+ });
145
+ }
146
+ throwSignal(signalId_1) {
147
+ return __awaiter(this, arguments, void 0, function* (signalId, data = {}, messageMatchingKey = {}) {
148
+ const ret = yield this.client.post('engine/throwSignal', { "signalId": signalId, "data": data, messageMatchingKey });
149
+ if (ret['errors']) {
150
+ console.log(ret['errors']);
151
+ throw new Error(ret['errors']);
152
+ }
153
+ return ret;
154
+ });
155
+ }
156
+ startEvent(instanceId_1, startNodeId_1) {
157
+ return __awaiter(this, arguments, void 0, function* (instanceId, startNodeId, data = {}, userId = null, options = {}) {
158
+ const ret = yield this.client.put('engine/startEvent', { "instanceId": instanceId, "startNodeId": startNodeId, "data": data, "userName": userId, "options": options });
159
+ if (ret['errors']) {
160
+ console.log(ret['errors']);
161
+ throw new Error(ret['errors']);
162
+ }
163
+ return ret;
164
+ });
165
+ }
166
+ get(query) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const ret = yield this.client.get('engine/get', query);
169
+ if (ret['errors']) {
170
+ console.log(ret['errors']);
171
+ throw new Error(ret['errors']);
172
+ }
173
+ const instance = ret['instance'];
174
+ return instance;
175
+ });
176
+ }
177
+ status() {
178
+ return __awaiter(this, void 0, void 0, function* () {
179
+ const ret = yield this.client.get('engine/status', {});
180
+ if (ret['errors']) {
181
+ console.log(ret['errors']);
182
+ throw new Error(ret['errors']);
183
+ }
184
+ return ret;
185
+ });
186
+ }
187
+ }
188
+ exports.ClientEngine = ClientEngine;
189
+ class ClientDatastore {
190
+ constructor(client) {
191
+ this.client = client;
192
+ }
193
+ find(_a) {
194
+ return __awaiter(this, arguments, void 0, function* ({ filter, sort, limit, after, projection, getTotalCount }) {
195
+ var res = yield this.client.get('datastore/find', { filter, after, limit, sort, projection, getTotalCount });
196
+ if (res.error) {
197
+ console.log(res.error);
198
+ throw new Error(res.error);
199
+ throw new Error(res['errors']);
200
+ }
201
+ return res;
202
+ });
203
+ }
204
+ findItems(query) {
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ var res = yield this.client.get('datastore/findItems', query);
207
+ if (res['errors']) {
208
+ console.log(res['errors']);
209
+ throw new Error(res['errors']);
210
+ }
211
+ const items = res['items'];
212
+ return items;
213
+ });
214
+ }
215
+ findInstances(query_1) {
216
+ return __awaiter(this, arguments, void 0, function* (query, projection = {}) {
217
+ const res = yield this.client.get('datastore/findInstances', { query, projection });
218
+ if (res['errors']) {
219
+ console.log(res['errors']);
220
+ throw new Error(res['errors']);
221
+ }
222
+ const instances = res['instances'];
223
+ return instances;
224
+ });
225
+ }
226
+ deleteInstances(query) {
227
+ return __awaiter(this, void 0, void 0, function* () {
228
+ return yield this.client.del('datastore/deleteInstances', query);
229
+ });
230
+ }
231
+ }
232
+ exports.ClientDatastore = ClientDatastore;
233
+ class ClientDefinitions {
234
+ constructor(client) {
235
+ this.client = client;
236
+ }
237
+ import(name_1, pathToBPMN_1) {
238
+ return __awaiter(this, arguments, void 0, function* (name, pathToBPMN, pathToSVG = null) {
239
+ var options = {
240
+ 'method': 'POST',
241
+ 'host': this.client.host,
242
+ 'port': this.client.port,
243
+ 'path': '/api/definitions/import/' + name,
244
+ 'headers': {
245
+ 'x-api-key': this.client.apiKey
246
+ },
247
+ 'maxRedirects': 20
248
+ };
249
+ console.log('import ', name, pathToBPMN, pathToSVG);
250
+ var res = yield this.client.upload(name, pathToBPMN, pathToSVG, options);
251
+ console.log('import done ', res);
252
+ this.checkErrors(res);
253
+ return res;
254
+ });
255
+ }
256
+ list() {
257
+ return __awaiter(this, void 0, void 0, function* () {
258
+ var res = yield this.client.get('definitions/list', []);
259
+ if (res['errors']) {
260
+ console.log(res['errors']);
261
+ throw new Error(res['errors']);
262
+ }
263
+ return res;
264
+ });
265
+ }
266
+ delete(name) {
267
+ return __awaiter(this, void 0, void 0, function* () {
268
+ const res = yield this.client.post('definitions/delete/', { name });
269
+ if (res['errors']) {
270
+ console.log(res['errors']);
271
+ throw new Error(res['errors']);
272
+ }
273
+ console.log(res);
274
+ return res;
275
+ });
276
+ }
277
+ rename(name, newName) {
278
+ return __awaiter(this, void 0, void 0, function* () {
279
+ const res = yield this.client.post('definitions/rename/', { name, newName });
280
+ if (res['errors']) {
281
+ console.log(res['errors']);
282
+ throw new Error(res['errors']);
283
+ }
284
+ console.log(res);
285
+ return res;
286
+ });
287
+ }
288
+ load(name) {
289
+ return __awaiter(this, void 0, void 0, function* () {
290
+ const res = yield this.client.get(encodeURI('definitions/load/' + name), { name });
291
+ if (res['errors']) {
292
+ console.log(res['errors']);
293
+ throw new Error(res['errors']);
294
+ }
295
+ console.log(res);
296
+ return res;
297
+ });
298
+ }
299
+ checkErrors(res) {
300
+ if (res['errors']) {
301
+ console.log(res['errors']);
302
+ throw new Error(res['errors']);
303
+ }
304
+ }
305
+ }
306
+ exports.ClientDefinitions = ClientDefinitions;