bpmn-client 1.0.1 → 1.2.0

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/.env ADDED
@@ -0,0 +1,4 @@
1
+ API_KEY=12345
2
+ HOST=localhost
3
+ PORT=3000
4
+ BASE_URL=api
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "bpmn-client-sample",
3
+ "version": "1.2.0",
4
+ "license": "MIT",
5
+ "scripts": {
6
+ "build": "tsc --build",
7
+ "clean": "tsc --build --clean",
8
+ "start": "node app.ts",
9
+ "test": "mocha -R dot",
10
+ "posttest": "eslint . --cache && npm run toc",
11
+ "wintest": "node_modules/.bin/mocha",
12
+ "start:watch": "tsc-watch --project . --onSuccess \"nodemon ./test.ts\"",
13
+ "toc": "node scripts/generate-api-toc ./docs/API.md,./docs/Examples.md",
14
+ "test-md": "node scripts/test-markdown.js ./docs/API.md && node scripts/test-markdown.js ./docs/Examples.md"
15
+ },
16
+ "description": "Client API for BPMN-Server webservices",
17
+ "keywords": [
18
+ "BPMN",
19
+ "BPMN 2.0",
20
+ "Workflow",
21
+ "Node.js",
22
+ "TypeScript"
23
+ ],
24
+ "author": {
25
+ "name": "ralphhanna"
26
+ },
27
+ "dependencies": {
28
+ "bpmn-client": "*",
29
+ "connect-busboy": "0.0.2",
30
+ "core-js": "^3.6.5",
31
+ "dotenv": "^16.0.1"
32
+ },
33
+ "devDependencies": {
34
+ "@types/mime": "^1.3.1",
35
+ "@types/node": "^8.10.62",
36
+ "@types/serve-static": "^1.7.32",
37
+ "nodemon": "^2.0.19",
38
+ "ts-node": "^8.10.2",
39
+ "typescript": "^3.9.7"
40
+ },
41
+ "engines": {
42
+ "node": "^14.0.0"
43
+ }
44
+ }
package/Sample/test.js ADDED
@@ -0,0 +1,30 @@
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
+ const src_1 = require("bpmn-client/src/");
13
+ console.log("Testing BPMNClient");
14
+ test();
15
+ function test() {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ const client = new src_1.BPMNClient('localhost', 3000, 12345);
18
+ var instance = yield client.engine.start("Buy Used Car", {});
19
+ console.log("instance.id", instance.id, instance.name, instance.status);
20
+ var insts = yield client.datastore.findInstances({ 'status': 'running' });
21
+ insts.forEach(inst => {
22
+ console.log('id==>' + inst.id, inst.name, 'status==>', inst.status);
23
+ });
24
+ var items = yield client.datastore.findItems({ query: { "items.elementId": "task_Buy" } });
25
+ items.forEach(item => {
26
+ console.log('item: id==>' + item.id, item.name, 'status==>', item.status);
27
+ });
28
+ });
29
+ }
30
+ //# sourceMappingURL=test.js.map
package/Sample/test.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { BPMNClient } from "bpmn-client/src/";
2
+
3
+
4
+ console.log("Testing BPMNClient");
5
+ test();
6
+
7
+ async function test() {
8
+ const client = new BPMNClient('localhost', 3000,12345);
9
+ var instance = await client.engine.start("Buy Used Car", {} );
10
+ console.log("instance.id", instance.id, instance.name,instance.status);
11
+
12
+ var insts= await client.datastore.findInstances({ 'status': 'running' });
13
+
14
+ insts.forEach(inst => {
15
+ console.log('id==>' + inst.id,inst.name, 'status==>',inst.status);
16
+ });
17
+
18
+
19
+ var items = await client.datastore.findItems({ query: { "items.elementId": "task_Buy" } });
20
+
21
+
22
+ items.forEach(item => {
23
+ console.log('item: id==>' + item.id, item.name, 'status==>', item.status);
24
+ });
25
+
26
+ }
27
+
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es6",
5
+ "lib": [ "es6" ],
6
+ "sourceMap": false,
7
+ "declaration": false,
8
+ "listFiles" : false
9
+
10
+ },
11
+ "include": [
12
+ "**/*.ts"
13
+ ],
14
+ "exclude": [
15
+ "node_modules"
16
+ ]
17
+ }
Binary file
package/index.js CHANGED
@@ -1,21 +1,13 @@
1
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
- });
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);
10
11
  };
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
- const BPMNClient_1 = require("./BPMNClient");
13
- test();
14
- function test() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- const client = new BPMNClient_1.BPMNClient('bpmn.omniworkflow.com', 80);
17
- const ret = yield client.engine.start({ name: "Buy Used Car", data: {} });
18
- console.log(ret);
19
- });
20
- }
21
- //# sourceMappingURL=index.js.map
13
+ __exportStar(require("./src/"), exports);
package/index.ts CHANGED
@@ -1,10 +1 @@
1
- import { BPMNClient } from './BPMNClient';
2
-
3
-
4
- async function test() {
5
- const client = new BPMNClient('bpmn.omniworkflow.com', 80);
6
- const ret= await client.engine.start({ name: "Buy Used Car", data: {} });
7
- console.log(ret);
8
-
9
- }
10
-
1
+ export * from './src/';
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "bpmn-client",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "build": "tsc --build",
7
7
  "clean": "tsc --build --clean",
8
- "start:watch": "nodemon app",
9
8
  "start": "node app.ts",
10
9
  "test": "mocha -R dot",
11
10
  "posttest": "eslint . --cache && npm run toc",
12
11
  "wintest": "node_modules/.bin/mocha",
12
+ "start:watch": "tsc-watch --project . --onSuccess \"nodemon ./test.ts\"",
13
13
  "toc": "node scripts/generate-api-toc ./docs/API.md,./docs/Examples.md",
14
14
  "test-md": "node scripts/test-markdown.js ./docs/API.md && node scripts/test-markdown.js ./docs/Examples.md"
15
15
  },
16
- "description": "bpmn-server.webApp",
16
+ "description": "Client API for BPMN-Server webservices",
17
17
  "keywords": [
18
18
  "BPMN",
19
19
  "BPMN 2.0",
@@ -26,39 +26,22 @@
26
26
  },
27
27
  "repository": {
28
28
  "type": "git",
29
- "url": "git+https:github.com/ralphhanna/bpmn-server.git"
29
+ "url": "git+https:github.com/ralphhanna/bpmn-client.git"
30
30
  },
31
31
  "dependencies": {
32
- "bpmn-server": "^1.0.0",
33
- "camunda-bpmn-moddle": "^4.4.0",
34
- "chai": "^4.2.0",
35
32
  "connect-busboy": "0.0.2",
36
33
  "core-js": "^3.6.5",
37
- "debug": "^2.2.0",
38
- "express": "^4.14.0",
39
- "iso8601-duration": "^1.2.0",
40
- "mocha": "^7.1.2",
41
- "mocha-cakes-2": "^3.3.0",
42
- "mongodb": "^3.5.7",
43
- "mongoose": "^5.9.13",
44
- "nock": "^12.0.3",
45
- "nodemon": "^2.0.4",
46
- "pug": "^2.0.0-rc.3",
47
- "ts-node": "^8.10.1",
48
- "uuid": "^8.0.0"
34
+ "dotenv": "^16.0.1"
49
35
  },
50
36
  "devDependencies": {
51
- "@types/debug": "0.0.30",
52
- "@types/express": "^4.17.7",
53
- "@types/express-serve-static-core": "^4.17.9",
54
37
  "@types/mime": "^1.3.1",
55
38
  "@types/node": "^8.10.62",
56
39
  "@types/serve-static": "^1.7.32",
57
- "typedoc": "^0.17.8",
58
- "typedoc-plugin-markdown": "^2.3.1",
40
+ "nodemon": "^2.0.19",
41
+ "ts-node": "^8.10.2",
59
42
  "typescript": "^3.9.7"
60
43
  },
61
44
  "engines": {
62
- "node": "^8.0.0"
45
+ "node": "^14.0.0"
63
46
  }
64
47
  }
@@ -9,14 +9,57 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Engine = exports.BPMNClient = void 0;
12
+ exports.ClientDefinitions = exports.ClientDatastore = exports.ClientEngine = exports.BPMNClient = void 0;
13
+ const dotenv = require('dotenv');
14
+ const res = dotenv.config();
15
+ console.log("BPMNClient 1.2");
16
+ const https = require('https');
13
17
  const http = require('http');
14
- class BPMNClient {
15
- constructor(host, port) {
18
+ class WebService {
19
+ constructor() { }
20
+ invoke(params, options) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ var driver = http;
23
+ var body = JSON.stringify(params);
24
+ console.log(options, params);
25
+ if (options.port == 443)
26
+ driver = https;
27
+ let data = '';
28
+ let self = this;
29
+ return new Promise(function (resolve, reject) {
30
+ try {
31
+ driver.request(options, function (res) {
32
+ console.log('STATUS: ' + res.statusCode);
33
+ //console.log(res);
34
+ self.statusCode = res.statusCode;
35
+ res.setEncoding('utf8');
36
+ res.on('data', function (chunk) {
37
+ data += chunk;
38
+ });
39
+ res.on('end', () => {
40
+ self.result = JSON.parse(data);
41
+ resolve(self.result);
42
+ });
43
+ }).on("error", (err) => {
44
+ console.log("Error: " + err.message);
45
+ reject(err);
46
+ }).end(body);
47
+ }
48
+ catch (exc) {
49
+ console.log(exc);
50
+ }
51
+ });
52
+ });
53
+ }
54
+ }
55
+ class BPMNClient extends WebService {
56
+ constructor(host, port, apiKey) {
57
+ super();
16
58
  this.host = host;
17
59
  this.port = port;
18
- this.engine = new Engine(this);
19
- this.datastore = new Datastore(this);
60
+ this.apiKey = apiKey;
61
+ this.engine = new ClientEngine(this);
62
+ this.datastore = new ClientDatastore(this);
20
63
  }
21
64
  get(url, data = {}) {
22
65
  return __awaiter(this, void 0, void 0, function* () {
@@ -40,8 +83,8 @@ class BPMNClient {
40
83
  }
41
84
  request(url, method, params) {
42
85
  return __awaiter(this, void 0, void 0, function* () {
43
- var options;
44
86
  var body = JSON.stringify(params);
87
+ var options;
45
88
  if (params) {
46
89
  options = {
47
90
  host: this.host,
@@ -50,6 +93,11 @@ class BPMNClient {
50
93
  method: method,
51
94
  headers: {
52
95
  "Content-Type": "application/json",
96
+ "x-api-key": this.apiKey,
97
+ "Accept": "*/*",
98
+ // "User-Agent": "PostmanRuntime/ 7.26.8",
99
+ // "Accept-Encoding": "gzip, deflate, br",
100
+ "Connection": "keep-alive",
53
101
  "Content-Length": Buffer.byteLength(body)
54
102
  }
55
103
  };
@@ -62,77 +110,74 @@ class BPMNClient {
62
110
  method: method
63
111
  };
64
112
  }
65
- console.log(options);
66
- let data = '';
67
- let self = this;
68
- return new Promise(function (resolve, reject) {
69
- try {
70
- http.request(options, function (res) {
71
- console.log('STATUS: ' + res.statusCode);
72
- // console.log('HEADERS: ' + JSON.stringify(res.headers));
73
- self.statusCode = res.statusCode;
74
- res.setEncoding('utf8');
75
- res.on('data', function (chunk) {
76
- data += chunk;
77
- });
78
- res.on('end', () => {
79
- // console.log(JSON.parse(data));
80
- self.result = JSON.parse(data);
81
- resolve(self.result);
82
- });
83
- }).on("error", (err) => {
84
- console.log("Error: " + err.message);
85
- reject(err);
86
- }).end(body);
87
- }
88
- catch (exc) {
89
- console.log(exc);
90
- }
91
- });
113
+ return yield this.invoke(params, options);
92
114
  });
93
115
  }
94
- getItem(id) {
95
- if (!this.result.instance) {
96
- console.log(this.result);
97
- return;
98
- }
99
- return this.result.instance.items.filter(item => { return item.elementId == id; })[0];
100
- }
101
116
  }
102
117
  exports.BPMNClient = BPMNClient;
103
- class Engine {
118
+ class ClientEngine {
104
119
  constructor(client) {
105
120
  this.client = client;
106
121
  }
107
- start({ name, data }) {
122
+ start(name, data) {
108
123
  return __awaiter(this, void 0, void 0, function* () {
109
- return yield this.client.post('engine/start', { name, data });
124
+ const ret = yield this.client.post('engine/start', { name, data });
125
+ if (ret['errors']) {
126
+ console.log(ret['errors']);
127
+ throw new Error(ret['errors']);
128
+ }
129
+ const instance = ret;
130
+ return instance;
110
131
  });
111
132
  }
112
- invoke({ query, data }) {
133
+ invoke(query, data) {
113
134
  return __awaiter(this, void 0, void 0, function* () {
114
- return yield this.client.put('engine/invoke', { query, data });
135
+ const ret = yield this.client.put('engine/invoke', { query, data });
136
+ if (ret['errors']) {
137
+ console.log(ret['errors']);
138
+ throw new Error(ret['errors']);
139
+ }
140
+ const instance = ret['instance'];
141
+ return instance;
115
142
  });
116
143
  }
117
144
  get(query) {
118
145
  return __awaiter(this, void 0, void 0, function* () {
119
- return yield this.client.get('engine/get', query);
146
+ const ret = yield this.client.get('engine/get', query);
147
+ if (ret['errors']) {
148
+ console.log(ret['errors']);
149
+ throw new Error(ret['errors']);
150
+ }
151
+ const instance = ret['instance'];
152
+ return instance;
120
153
  });
121
154
  }
122
155
  }
123
- exports.Engine = Engine;
124
- class Datastore {
156
+ exports.ClientEngine = ClientEngine;
157
+ class ClientDatastore {
125
158
  constructor(client) {
126
159
  this.client = client;
127
160
  }
128
161
  findItems(query) {
129
162
  return __awaiter(this, void 0, void 0, function* () {
130
- return yield this.client.get('datastore/findItems', query);
163
+ var res = yield this.client.get('datastore/findItems', query);
164
+ if (res['errors']) {
165
+ console.log(res['errors']);
166
+ throw new Error(res['errors']);
167
+ }
168
+ const items = res['items'];
169
+ return items;
131
170
  });
132
171
  }
133
- findInsances(query) {
172
+ findInstances(query) {
134
173
  return __awaiter(this, void 0, void 0, function* () {
135
- return yield this.client.get('datastore/findInstances', query);
174
+ const res = yield this.client.get('datastore/findInstances', query);
175
+ if (res['errors']) {
176
+ console.log(res['errors']);
177
+ throw new Error(res['errors']);
178
+ }
179
+ const instances = res['instances'];
180
+ return instances;
136
181
  });
137
182
  }
138
183
  deleteInstances(query) {
@@ -141,4 +186,31 @@ class Datastore {
141
186
  });
142
187
  }
143
188
  }
144
- //# sourceMappingURL=BPMNClient.js.map
189
+ exports.ClientDatastore = ClientDatastore;
190
+ class ClientDefinitions {
191
+ constructor(client) {
192
+ this.client = client;
193
+ }
194
+ list() {
195
+ return __awaiter(this, void 0, void 0, function* () {
196
+ var res = yield this.client.get('definitions/list', []);
197
+ if (res['errors']) {
198
+ console.log(res['errors']);
199
+ throw new Error(res['errors']);
200
+ }
201
+ return res;
202
+ });
203
+ }
204
+ load(name) {
205
+ return __awaiter(this, void 0, void 0, function* () {
206
+ const res = yield this.client.get(encodeURI('definitions/load/' + name), { name: name });
207
+ if (res['errors']) {
208
+ console.log(res['errors']);
209
+ throw new Error(res['errors']);
210
+ }
211
+ console.log(res);
212
+ return res;
213
+ });
214
+ }
215
+ }
216
+ exports.ClientDefinitions = ClientDefinitions;