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 +4 -0
- package/Sample/package.json +44 -0
- package/Sample/test.js +30 -0
- package/Sample/test.ts +27 -0
- package/Sample/tsconfig.json +17 -0
- package/bpmn-client-1.2.0.tgz +0 -0
- package/index.js +10 -18
- package/index.ts +1 -10
- package/package.json +8 -25
- package/{BPMNClient.js → src/BPMNClient.js} +124 -52
- package/src/BPMNClient.ts +219 -0
- package/src/index.js +15 -0
- package/src/index.ts +4 -0
- package/src/interfaces/DataObjects.js +2 -0
- package/src/interfaces/DataObjects.ts +97 -0
- package/src/interfaces/Enums.js +117 -0
- package/src/interfaces/Enums.ts +71 -0
- package/test/.eslintrc.json +20 -0
- package/test/feature/.env +5 -0
- package/test/feature/carServer.js +117 -0
- package/test/helpers/setup.js +9 -0
- package/test/logs/Buy Used Carrepairsfalse cleaning +0 -0
- package/test/logs/Buy Used Carrepairstrue cleaning +0 -0
- package/test/logs/Buy Used Carscenario CaseId +0 -0
- package/test/logs/carrepairsfalse cleaning +0 -0
- package/test/logs/carrepairstrue cleaning +0 -0
- package/test/mocha.opts +5 -0
- package/test/resources/Invoice.js +91 -0
- package/test/resources/car.js +69 -0
- package/test/resources/loop.js +50 -0
- package/test.js +29 -0
- package/test.ts +27 -0
- package/test2.js +270 -0
- package/test2.ts +326 -0
- package/tsconfig.json +4 -4
- package/BPMNClient.d.ts +0 -36
- package/BPMNClient.js.map +0 -1
- package/BPMNClient.ts +0 -139
- package/index.d.ts +0 -1
- package/index.js.map +0 -1
- package/npm.list +0 -579
|
File without changes
|
|
File without changes
|
package/test/mocha.opts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
|
|
3
|
+
const source = file = fs.readFileSync('../../WebApp/processes/invoice.bpmn',
|
|
4
|
+
{ encoding: 'utf8', flag: 'r' });
|
|
5
|
+
|
|
6
|
+
const source2 = `
|
|
7
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
8
|
+
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd">
|
|
9
|
+
<bpmn2:collaboration id="Collaboration_1vzc4e2">
|
|
10
|
+
<bpmn2:participant id="Participant_1g6enp2" name="Account Payable" processRef="Process_1" />
|
|
11
|
+
<bpmn2:participant id="Participant_1e7gk8x" name="Manager" processRef="Process_0t314on" />
|
|
12
|
+
<bpmn2:messageFlow id="MessageFlow_18tfm5f" sourceRef="task_cancelInvoice" targetRef="IntermediateCatchEvent_1xr94uz" />
|
|
13
|
+
</bpmn2:collaboration>
|
|
14
|
+
<bpmn2:process id="Process_1" isExecutable="false">
|
|
15
|
+
<bpmn2:startEvent id="StartEvent_0wntki2">
|
|
16
|
+
<bpmn2:outgoing>SequenceFlow_129vlnl</bpmn2:outgoing>
|
|
17
|
+
</bpmn2:startEvent>
|
|
18
|
+
<bpmn2:userTask id="task_issueInvoice" name="Issue Invoice">
|
|
19
|
+
<bpmn2:incoming>SequenceFlow_129vlnl</bpmn2:incoming>
|
|
20
|
+
<bpmn2:outgoing>SequenceFlow_1nmqrtq</bpmn2:outgoing>
|
|
21
|
+
</bpmn2:userTask>
|
|
22
|
+
<bpmn2:sequenceFlow id="SequenceFlow_129vlnl" sourceRef="StartEvent_0wntki2" targetRef="task_issueInvoice" />
|
|
23
|
+
<bpmn2:sequenceFlow id="SequenceFlow_1nmqrtq" sourceRef="task_issueInvoice" targetRef="ExclusiveGateway_04dgpye" />
|
|
24
|
+
<bpmn2:eventBasedGateway id="ExclusiveGateway_04dgpye">
|
|
25
|
+
<bpmn2:incoming>SequenceFlow_1nmqrtq</bpmn2:incoming>
|
|
26
|
+
<bpmn2:outgoing>SequenceFlow_147bbuq</bpmn2:outgoing>
|
|
27
|
+
<bpmn2:outgoing>SequenceFlow_1ucmquu</bpmn2:outgoing>
|
|
28
|
+
<bpmn2:outgoing>SequenceFlow_0dq5qq6</bpmn2:outgoing>
|
|
29
|
+
</bpmn2:eventBasedGateway>
|
|
30
|
+
<bpmn2:sequenceFlow id="SequenceFlow_147bbuq" sourceRef="ExclusiveGateway_04dgpye" targetRef="receiveTask_payment" />
|
|
31
|
+
<bpmn2:sequenceFlow id="SequenceFlow_1ucmquu" sourceRef="ExclusiveGateway_04dgpye" targetRef="event_timer">
|
|
32
|
+
<bpmn2:conditionExpression xsi:type="bpmn:tExpression">
|
|
33
|
+
<![CDATA[(this.reminderCounter < 3)]]>
|
|
34
|
+
</bpmn2:conditionExpression>
|
|
35
|
+
</bpmn2:sequenceFlow>
|
|
36
|
+
<bpmn2:sequenceFlow id="sequence_timer_reminder" sourceRef="event_timer" targetRef="task_reminder" />
|
|
37
|
+
<bpmn2:sequenceFlow id="SequenceFlow_1ml8g8q" sourceRef="receiveTask_payment" targetRef="EndEvent_0sxnxfz" />
|
|
38
|
+
<bpmn2:sequenceFlow id="SequenceFlow_0dq5qq6" sourceRef="ExclusiveGateway_04dgpye" targetRef="IntermediateCatchEvent_1xr94uz" />
|
|
39
|
+
<bpmn2:intermediateCatchEvent id="IntermediateCatchEvent_1xr94uz" name="Cancel by Admin">
|
|
40
|
+
<bpmn2:incoming>SequenceFlow_0dq5qq6</bpmn2:incoming>
|
|
41
|
+
<bpmn2:outgoing>SequenceFlow_0karre6</bpmn2:outgoing>
|
|
42
|
+
<bpmn2:messageEventDefinition />
|
|
43
|
+
</bpmn2:intermediateCatchEvent>
|
|
44
|
+
<bpmn2:sequenceFlow id="SequenceFlow_0karre6" sourceRef="IntermediateCatchEvent_1xr94uz" targetRef="EndEvent_0ypa03q" />
|
|
45
|
+
<bpmn2:endEvent id="EndEvent_0ypa03q">
|
|
46
|
+
<bpmn2:incoming>SequenceFlow_0karre6</bpmn2:incoming>
|
|
47
|
+
<bpmn2:terminateEventDefinition />
|
|
48
|
+
</bpmn2:endEvent>
|
|
49
|
+
<bpmn2:intermediateCatchEvent id="event_timer" name="30 days later">
|
|
50
|
+
<bpmn2:incoming>SequenceFlow_1ucmquu</bpmn2:incoming>
|
|
51
|
+
<bpmn2:outgoing>sequence_timer_reminder</bpmn2:outgoing>
|
|
52
|
+
|
|
53
|
+
<bpmn2:timerEventDefinition id="TimerEventDefinition_07xu06a">
|
|
54
|
+
<bpmn2:timeDuration xsi:type="bpmn2:tExpression">PT2S</bpmn2:timeDuration>
|
|
55
|
+
</bpmn2:timerEventDefinition>
|
|
56
|
+
|
|
57
|
+
</bpmn2:intermediateCatchEvent>
|
|
58
|
+
<bpmn2:sendTask id="task_reminder" name="Issue Reminder">
|
|
59
|
+
<script>
|
|
60
|
+
<![CDATA[
|
|
61
|
+
this.token.log('testing from the inside Issue Reminder ');
|
|
62
|
+
]]>
|
|
63
|
+
</script>
|
|
64
|
+
<bpmn2:incoming>sequence_timer_reminder</bpmn2:incoming>
|
|
65
|
+
</bpmn2:sendTask>
|
|
66
|
+
<bpmn2:receiveTask id="receiveTask_payment" name="Got Payment">
|
|
67
|
+
<bpmn2:incoming>SequenceFlow_147bbuq</bpmn2:incoming>
|
|
68
|
+
<bpmn2:outgoing>SequenceFlow_1ml8g8q</bpmn2:outgoing>
|
|
69
|
+
</bpmn2:receiveTask>
|
|
70
|
+
<bpmn2:endEvent id="EndEvent_0sxnxfz">
|
|
71
|
+
<bpmn2:incoming>SequenceFlow_1ml8g8q</bpmn2:incoming>
|
|
72
|
+
</bpmn2:endEvent>
|
|
73
|
+
</bpmn2:process>
|
|
74
|
+
<bpmn2:process id="Process_0t314on">
|
|
75
|
+
<bpmn2:sequenceFlow id="SequenceFlow_1vs4h9e" sourceRef="StartEvent_0loa7qt" targetRef="task_cancelInvoice" />
|
|
76
|
+
<bpmn2:sequenceFlow id="SequenceFlow_0yw5wjo" sourceRef="task_cancelInvoice" targetRef="IntermediateThrowEvent_0vasq6m" />
|
|
77
|
+
<bpmn2:startEvent id="StartEvent_0loa7qt">
|
|
78
|
+
<bpmn2:outgoing>SequenceFlow_1vs4h9e</bpmn2:outgoing>
|
|
79
|
+
</bpmn2:startEvent>
|
|
80
|
+
<bpmn2:userTask id="task_cancelInvoice" name="Cancel Invoice">
|
|
81
|
+
<bpmn2:incoming>SequenceFlow_1vs4h9e</bpmn2:incoming>
|
|
82
|
+
<bpmn2:outgoing>SequenceFlow_0yw5wjo</bpmn2:outgoing>
|
|
83
|
+
</bpmn2:userTask>
|
|
84
|
+
<bpmn2:endEvent id="IntermediateThrowEvent_0vasq6m">
|
|
85
|
+
<bpmn2:incoming>SequenceFlow_0yw5wjo</bpmn2:incoming>
|
|
86
|
+
</bpmn2:endEvent>
|
|
87
|
+
</bpmn2:process>
|
|
88
|
+
</bpmn2:definitions>
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
module.exports = { source };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const source = `
|
|
2
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
3
|
+
<bpmn:definitions
|
|
4
|
+
xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
5
|
+
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
|
6
|
+
xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
|
|
7
|
+
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
|
|
8
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
9
|
+
xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
|
|
10
|
+
exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="6.5.1">
|
|
11
|
+
<bpmn:collaboration id="Collaboration_0memx95">
|
|
12
|
+
<bpmn:participant id="Participant_1c0lpx5" processRef="Process_1hf9394" />
|
|
13
|
+
</bpmn:collaboration>
|
|
14
|
+
<bpmn:process id="Process_1hf9394" isExecutable="true">
|
|
15
|
+
<bpmn:startEvent id="StartEvent_158yep3">
|
|
16
|
+
<bpmn:outgoing>flow_start_buy</bpmn:outgoing>
|
|
17
|
+
</bpmn:startEvent>
|
|
18
|
+
<bpmn:userTask id="task_Buy" name="Buy">
|
|
19
|
+
<bpmn:extensionElements>
|
|
20
|
+
<camunda:formData>
|
|
21
|
+
<camunda:formField id="repairsRequired" label="Repairs Required?" type="boolean" />
|
|
22
|
+
<camunda:formField id="cleaningRequired" label="Cleaning Required?" type="boolean" />
|
|
23
|
+
</camunda:formData>
|
|
24
|
+
</bpmn:extensionElements>
|
|
25
|
+
<bpmn:incoming>flow_start_buy</bpmn:incoming>
|
|
26
|
+
<bpmn:outgoing>flow_buy_gateway</bpmn:outgoing>
|
|
27
|
+
</bpmn:userTask>
|
|
28
|
+
<bpmn:userTask id="task_clean" name="Clean">
|
|
29
|
+
<bpmn:incoming>flow_gateway_clean</bpmn:incoming>
|
|
30
|
+
<bpmn:outgoing>flow_clean_gateway</bpmn:outgoing>
|
|
31
|
+
</bpmn:userTask>
|
|
32
|
+
<bpmn:parallelGateway id="gateway_2">
|
|
33
|
+
<bpmn:incoming>flow_repair_gateway</bpmn:incoming>
|
|
34
|
+
<bpmn:incoming>flow_clean_gateway</bpmn:incoming>
|
|
35
|
+
<bpmn:outgoing>flow_gateway_drive</bpmn:outgoing>
|
|
36
|
+
</bpmn:parallelGateway>
|
|
37
|
+
<bpmn:endEvent id="Event_19ebav7">
|
|
38
|
+
<bpmn:incoming>flow_drive_end</bpmn:incoming>
|
|
39
|
+
</bpmn:endEvent>
|
|
40
|
+
<bpmn:userTask id="task_repair" name="Repair">
|
|
41
|
+
<bpmn:incoming>flow_gateway_repair</bpmn:incoming>
|
|
42
|
+
<bpmn:outgoing>flow_repair_gateway</bpmn:outgoing>
|
|
43
|
+
</bpmn:userTask>
|
|
44
|
+
<bpmn:sequenceFlow id="flow_start_buy" sourceRef="StartEvent_158yep3" targetRef="task_Buy" />
|
|
45
|
+
<bpmn:sequenceFlow id="flow_buy_gateway" sourceRef="task_Buy" targetRef="gateway_1" />
|
|
46
|
+
<bpmn:sequenceFlow id="flow_gateway_repair" sourceRef="gateway_1" targetRef="task_repair">
|
|
47
|
+
<bpmn:conditionExpression>(this.needsRepairs==true)</bpmn:conditionExpression>
|
|
48
|
+
</bpmn:sequenceFlow >
|
|
49
|
+
<bpmn:sequenceFlow id="flow_gateway_clean" sourceRef="gateway_1" targetRef="task_clean">
|
|
50
|
+
<bpmn:conditionExpression>(this.needsCleaning==true)</bpmn:conditionExpression>
|
|
51
|
+
</bpmn:sequenceFlow >
|
|
52
|
+
<bpmn:sequenceFlow id="flow_repair_gateway" sourceRef="task_repair" targetRef="gateway_2" />
|
|
53
|
+
<bpmn:sequenceFlow id="flow_clean_gateway" sourceRef="task_clean" targetRef="gateway_2" />
|
|
54
|
+
<bpmn:sequenceFlow id="flow_gateway_drive" sourceRef="gateway_2" targetRef="task_Drive" />
|
|
55
|
+
<bpmn:sequenceFlow id="flow_drive_end" sourceRef="task_Drive" targetRef="Event_19ebav7" />
|
|
56
|
+
<bpmn:userTask id="task_Drive" name="Drive">
|
|
57
|
+
<bpmn:incoming>flow_gateway_drive</bpmn:incoming>
|
|
58
|
+
<bpmn:outgoing>flow_drive_end</bpmn:outgoing>
|
|
59
|
+
</bpmn:userTask>
|
|
60
|
+
<bpmn:inclusiveGateway id="gateway_1">
|
|
61
|
+
<bpmn:incoming>flow_buy_gateway</bpmn:incoming>
|
|
62
|
+
<bpmn:outgoing>flow_gateway_repair</bpmn:outgoing>
|
|
63
|
+
<bpmn:outgoing>flow_gateway_clean</bpmn:outgoing>
|
|
64
|
+
</bpmn:inclusiveGateway>
|
|
65
|
+
</bpmn:process>
|
|
66
|
+
</bpmn:definitions>
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
module.exports = { source };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
const source = `
|
|
3
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
4
|
+
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
5
|
+
xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
6
|
+
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
|
7
|
+
xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
|
|
8
|
+
xmlns:di="http://www.omg.org/spec/DD/20100524/DI" id="Definitions_1vpaa20"
|
|
9
|
+
targetNamespace="http://bpmn.io/schema/bpmn"
|
|
10
|
+
exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="6.5.1">
|
|
11
|
+
<bpmn:process id="Process_15krzlx" isExecutable="false">
|
|
12
|
+
<bpmn:startEvent id="StartEvent_12lfa5f">
|
|
13
|
+
<bpmn:outgoing>Flow_0bb7flg</bpmn:outgoing>
|
|
14
|
+
</bpmn:startEvent>
|
|
15
|
+
<bpmn:sequenceFlow id="Flow_0bb7flg" sourceRef="StartEvent_12lfa5f" targetRef="scriptTask" />
|
|
16
|
+
<bpmn:sequenceFlow id="Flow_03lw5wj" sourceRef="scriptTask" targetRef="serviceTask" />
|
|
17
|
+
<bpmn:sequenceFlow id="Flow_0cq93ga" sourceRef="serviceTask" targetRef="sendTask" />
|
|
18
|
+
<bpmn:endEvent id="Event_0iwmzob">
|
|
19
|
+
<bpmn:incoming>Flow_0wyvfqv</bpmn:incoming>
|
|
20
|
+
</bpmn:endEvent>
|
|
21
|
+
<bpmn:sequenceFlow id="Flow_0wyvfqv" sourceRef="sendTask" targetRef="Event_0iwmzob" />
|
|
22
|
+
<bpmn:scriptTask id="scriptTask" name="ScriptTask">
|
|
23
|
+
<script>
|
|
24
|
+
<![CDATA[
|
|
25
|
+
this.token.log('testing from the inside: '+this.token.data.loopKey);
|
|
26
|
+
]]>
|
|
27
|
+
</script>
|
|
28
|
+
<bpmn:multiInstanceLoopCharacteristics isSequential="true" js:collection="(this.records)" />
|
|
29
|
+
<bpmn:incoming>Flow_0bb7flg</bpmn:incoming>
|
|
30
|
+
<bpmn:outgoing>Flow_03lw5wj</bpmn:outgoing>
|
|
31
|
+
</bpmn:scriptTask>
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
<bpmn:serviceTask id="serviceTask" name="ServiceTask"
|
|
35
|
+
implementation="\{this.token.execution.handler.service1(this);}">
|
|
36
|
+
<bpmn:multiInstanceLoopCharacteristics isSequential="false" js:collection="(this.records)" />
|
|
37
|
+
|
|
38
|
+
<bpmn:incoming>Flow_03lw5wj</bpmn:incoming>
|
|
39
|
+
<bpmn:outgoing>Flow_0cq93ga</bpmn:outgoing>
|
|
40
|
+
</bpmn:serviceTask>
|
|
41
|
+
<bpmn:sendTask id="sendTask" name="SendTask">
|
|
42
|
+
<bpmn:incoming>Flow_0cq93ga</bpmn:incoming>
|
|
43
|
+
<bpmn:outgoing>Flow_0wyvfqv</bpmn:outgoing>
|
|
44
|
+
</bpmn:sendTask>
|
|
45
|
+
</bpmn:process>
|
|
46
|
+
</bpmn:definitions>
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
module.exports = { source };
|
package/test.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
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 BPMNClient_1 = require("./src/BPMNClient");
|
|
13
|
+
console.log("Testing BPMNClient");
|
|
14
|
+
test();
|
|
15
|
+
function test() {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const client = new BPMNClient_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
|
+
}
|
package/test.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BPMNClient } from './src/BPMNClient';
|
|
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
|
+
|
package/test2.js
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
//import { BPMNClient } from './';
|
|
3
|
+
//import { BPMNServer, IInstanceData, IItemData } from './';
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
const dotenv = require('dotenv');
|
|
15
|
+
const res = dotenv.config();
|
|
16
|
+
console.log("Testing BPMNClient 2");
|
|
17
|
+
const https = require('https');
|
|
18
|
+
const http = require('http');
|
|
19
|
+
class WebService {
|
|
20
|
+
constructor() { }
|
|
21
|
+
invoke(params, options) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var driver = http;
|
|
24
|
+
var body = JSON.stringify(params);
|
|
25
|
+
console.log(options, params);
|
|
26
|
+
if (options.port == 443)
|
|
27
|
+
driver = https;
|
|
28
|
+
let data = '';
|
|
29
|
+
let self = this;
|
|
30
|
+
return new Promise(function (resolve, reject) {
|
|
31
|
+
try {
|
|
32
|
+
driver.request(options, function (res) {
|
|
33
|
+
console.log('STATUS: ' + res.statusCode);
|
|
34
|
+
//console.log(res);
|
|
35
|
+
self.statusCode = res.statusCode;
|
|
36
|
+
res.setEncoding('utf8');
|
|
37
|
+
res.on('data', function (chunk) {
|
|
38
|
+
data += chunk;
|
|
39
|
+
});
|
|
40
|
+
res.on('end', () => {
|
|
41
|
+
self.result = JSON.parse(data);
|
|
42
|
+
resolve(self.result);
|
|
43
|
+
});
|
|
44
|
+
}).on("error", (err) => {
|
|
45
|
+
console.log("Error: " + err.message);
|
|
46
|
+
reject(err);
|
|
47
|
+
}).end(body);
|
|
48
|
+
}
|
|
49
|
+
catch (exc) {
|
|
50
|
+
console.log(exc);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class BPMNClient extends WebService {
|
|
57
|
+
constructor(host, port, apiKey) {
|
|
58
|
+
super();
|
|
59
|
+
this.host = host;
|
|
60
|
+
this.port = port;
|
|
61
|
+
this.apiKey = apiKey;
|
|
62
|
+
this.engine = new ClientEngine(this);
|
|
63
|
+
this.datastore = new ClientDatastore(this);
|
|
64
|
+
this.definitions = new ClientDefinitions(this);
|
|
65
|
+
}
|
|
66
|
+
get(url, data = {}) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return yield this.request(url, 'GET', data);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
post(url, data = {}) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return yield this.request(url, 'POST', data);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
put(url, data = {}) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return yield this.request(url, 'PUT', data);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
del(url, data = {}) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
return yield this.request(url, 'DELETE', data);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
request(url, method, params) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
var body = JSON.stringify(params);
|
|
89
|
+
var options;
|
|
90
|
+
if (params) {
|
|
91
|
+
options = {
|
|
92
|
+
host: this.host,
|
|
93
|
+
port: this.port,
|
|
94
|
+
path: '/api/' + url,
|
|
95
|
+
method: method,
|
|
96
|
+
headers: {
|
|
97
|
+
"Content-Type": "application/json",
|
|
98
|
+
"x-api-key": this.apiKey,
|
|
99
|
+
"Accept": "*/*",
|
|
100
|
+
// "User-Agent": "PostmanRuntime/ 7.26.8",
|
|
101
|
+
// "Accept-Encoding": "gzip, deflate, br",
|
|
102
|
+
"Connection": "keep-alive",
|
|
103
|
+
"Content-Length": Buffer.byteLength(body)
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
options = {
|
|
109
|
+
host: this.host,
|
|
110
|
+
port: this.port,
|
|
111
|
+
path: '/api/' + url,
|
|
112
|
+
method: method
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return yield this.invoke(params, options);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class ClientEngine {
|
|
120
|
+
constructor(client) {
|
|
121
|
+
this.client = client;
|
|
122
|
+
}
|
|
123
|
+
start(name, data) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const ret = yield this.client.post('engine/start', { name, data });
|
|
126
|
+
if (ret['errors']) {
|
|
127
|
+
console.log(ret['errors']);
|
|
128
|
+
throw new Error(ret['errors']);
|
|
129
|
+
}
|
|
130
|
+
const instance = ret;
|
|
131
|
+
return instance;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
invoke(query, data) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const ret = yield this.client.put('engine/invoke', { query, data });
|
|
137
|
+
if (ret['errors']) {
|
|
138
|
+
console.log(ret['errors']);
|
|
139
|
+
throw new Error(ret['errors']);
|
|
140
|
+
}
|
|
141
|
+
const instance = ret['instance'];
|
|
142
|
+
return instance;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
get(query) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
const ret = yield this.client.get('engine/get', query);
|
|
148
|
+
if (ret['errors']) {
|
|
149
|
+
console.log(ret['errors']);
|
|
150
|
+
throw new Error(ret['errors']);
|
|
151
|
+
}
|
|
152
|
+
const instance = ret['instance'];
|
|
153
|
+
return instance;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
class ClientDatastore {
|
|
158
|
+
constructor(client) {
|
|
159
|
+
this.client = client;
|
|
160
|
+
}
|
|
161
|
+
findItems(query) {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
findInstances(query) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
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;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
deleteInstances(query) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
return yield this.client.del('datastore/delete', query);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
class ClientDefinitions {
|
|
190
|
+
constructor(client) {
|
|
191
|
+
this.client = client;
|
|
192
|
+
}
|
|
193
|
+
list() {
|
|
194
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
+
var res = yield this.client.get('definitions/list', []);
|
|
196
|
+
if (res['errors']) {
|
|
197
|
+
console.log(res['errors']);
|
|
198
|
+
throw new Error(res['errors']);
|
|
199
|
+
}
|
|
200
|
+
return res;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
load(name) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const res = yield this.client.get(encodeURI('definitions/load/' + name), { name: name });
|
|
206
|
+
if (res['errors']) {
|
|
207
|
+
console.log(res['errors']);
|
|
208
|
+
throw new Error(res['errors']);
|
|
209
|
+
}
|
|
210
|
+
console.log(res);
|
|
211
|
+
return res;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
test();
|
|
216
|
+
function test() {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const API_KEY = '12345';
|
|
219
|
+
const HOST = 'test.omniworkflow.com';
|
|
220
|
+
const PORT = '443';
|
|
221
|
+
// const HOST = 'localhost';
|
|
222
|
+
// const PORT = '3000';
|
|
223
|
+
const BASE_URL = 'api';
|
|
224
|
+
//const client = new BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);
|
|
225
|
+
const client = new BPMNClient(HOST, PORT, API_KEY);
|
|
226
|
+
const server = client;
|
|
227
|
+
const caseId = 3040;
|
|
228
|
+
var defs = yield server.definitions.list();
|
|
229
|
+
console.log(defs);
|
|
230
|
+
var def = yield server.definitions.load('Buy Used Car');
|
|
231
|
+
console.log(def['elements']);
|
|
232
|
+
//var instance = await client.engine.start("Buy Used Car", {});
|
|
233
|
+
var instance = yield server.engine.start("Buy Used Car", { caseId: caseId });
|
|
234
|
+
console.log("instance.id", instance.id, instance.name, instance.status, instance.data.caseId);
|
|
235
|
+
var response = yield server.engine.invoke({ id: instance.id, "items.elementId": 'task_Buy' }, { needsCleaning: "Yes", needsRepairs: "Yes" });
|
|
236
|
+
console.log('after buy', response.id, response.data);
|
|
237
|
+
response = yield server.engine.invoke({ id: instance.id, "items.elementId": 'task_clean' }, {});
|
|
238
|
+
console.log('after clean', response.id, response.data);
|
|
239
|
+
response = yield server.engine.invoke({ id: instance.id, "items.elementId": 'task_repair' }, {});
|
|
240
|
+
console.log('after repair', response.id, response.data);
|
|
241
|
+
try {
|
|
242
|
+
response = yield server.engine.invoke({ id: instance.id, "items.elementId": 'task_Drive' }, {});
|
|
243
|
+
console.log('after drive', response.id, response.data);
|
|
244
|
+
}
|
|
245
|
+
catch (exc) {
|
|
246
|
+
console.log(exc);
|
|
247
|
+
}
|
|
248
|
+
var insts = yield client.datastore.findInstances({ data: { caseId: caseId } });
|
|
249
|
+
insts.forEach(inst => {
|
|
250
|
+
console.log('Inst for CaseId id==>' + inst.id, inst.name, inst.data.caseId, 'status==>', inst.status);
|
|
251
|
+
});
|
|
252
|
+
var insts = yield client.datastore.findInstances({ id: instance.id });
|
|
253
|
+
insts.forEach(inst => {
|
|
254
|
+
for (var i = 0; i < inst.items.length; i++) {
|
|
255
|
+
var item = inst.items[i];
|
|
256
|
+
console.log(' item: elementId==>' + item.elementId, item.name, 'status==>', item.status);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
var inst = yield client.engine.get({ id: instance.id });
|
|
260
|
+
for (var i = 0; i < inst.items.length; i++) {
|
|
261
|
+
var item = inst.items[i];
|
|
262
|
+
console.log(' item: elementId==>' + item.elementId, item.name, 'status==>', item.status);
|
|
263
|
+
}
|
|
264
|
+
// var items = await client.datastore.findItems({ query: { "items.elementId": "task_Buy" } });
|
|
265
|
+
var items = yield client.datastore.findItems({ id: instance.id });
|
|
266
|
+
items.forEach(item => {
|
|
267
|
+
console.log('item: id==>' + item.elementId, item.type, item.name, 'status==>', item.status);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
}
|