@5minds/node-red-contrib-processcube 1.1.4-feature-f06772-m05458aj → 1.1.4-feature-fdfdae-m059c1wy

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@5minds/node-red-contrib-processcube",
3
- "version": "1.1.4-feature-f06772-m05458aj",
3
+ "version": "1.1.4-feature-fdfdae-m059c1wy",
4
4
  "license": "MIT",
5
5
  "description": "Node-RED nodes for ProcessCube",
6
6
  "scripts": {
@@ -40,6 +40,7 @@
40
40
  "externaltaskOutput": "externaltask-output.js",
41
41
  "externaltaskError": "externaltask-error.js",
42
42
  "processStart": "process-start.js",
43
+ "processEventListener": "process-event-listener.js",
43
44
  "processStartedListener": "process-started-listener.js",
44
45
  "processFinishedListener": "process-finished-listener.js",
45
46
  "processTerminatedListener": "process-terminated-listener.js",
@@ -0,0 +1,66 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('process-event-listener', {
3
+ category: 'ProcessCube Events',
4
+ color: '#02AFD6',
5
+ defaults: {
6
+ name: { value: '' },
7
+ engine: { value: '', type: 'processcube-engine-config' },
8
+ processmodel: { value: '', required: false },
9
+ eventtype: { value: '', required: true}
10
+ },
11
+ inputs: 0,
12
+ outputs: 1,
13
+ icon: 'font-awesome/fa-sign-in',
14
+ label: function () {
15
+ return this.name || 'process-event-listener';
16
+ },
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="process-event-listener">
21
+ <div class="form-row">
22
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
+ <input type="text" id="node-input-name" placeholder="Name" />
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-engine"><i class="fa fa-tag"></i> Engine-URL</label>
27
+ <input type="text" id="node-input-engine" placeholder="http://engine:8000" />
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-processmodel"><i class="fa fa-tag"></i> Processmodel</label>
31
+ <input type="text" id="node-input-processmodel" placeholder="ID of Processmodel" />
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-eventtype"><i class="fa fa-sliders"></i> Event</label>
35
+ <select id="node-input-eventtype" style="width: 70%;">
36
+ <option value="starting">starting</option>
37
+ <option value="started">started</option>
38
+ <option value="resumed">resumed</option>
39
+ <option value="finished">finished</option>
40
+ <option value="terminated">terminated</option>
41
+ <option value="error">error</option>
42
+ <option value="owner-changed">owner-changed</option>
43
+ <option value="instances-deleted">instances-deleted</option>
44
+ <option value="is-executable-changed">is-exeutable-changed</option>
45
+ <option value="deployed">deployed</option>
46
+ <option value="undeployed">undeployed</option>
47
+ </select>
48
+ </div>
49
+ </script>
50
+
51
+ <script type="text/markdown" data-help-name="process-event-listener">
52
+ A node which listens for errors in processes.
53
+
54
+ ## Outputs
55
+
56
+ : processInstanceId (string): The instance id of the processInstance with the error.
57
+ : processModelId (string): The model id of the processInstance with the error.
58
+ : token (object): The current token of the processInstance with the error.
59
+ : action (string): The action of the event (error).
60
+ : type (string): The type of the event.
61
+
62
+ ### References
63
+
64
+ - [The ProcessCube Developer Network](https://processcube.io) - All documentation for the ProcessCube&copy; platform
65
+ - [Node-RED Integration in ProcessCube&copy;](https://processcube.io/docs/node-red) - Node-RED integration in ProcessCube&copy;
66
+ </script>
@@ -0,0 +1,248 @@
1
+ module.exports = function (RED) {
2
+ function ProcessEventListener(config) {
3
+ RED.nodes.createNode(this, config);
4
+ var node = this;
5
+ node.engine = RED.nodes.getNode(config.engine);
6
+
7
+ const register = async () => {
8
+ const client = node.engine.engineClient;
9
+
10
+ if (!client) {
11
+ node.error('No engine configured.');
12
+ return;
13
+ }
14
+
15
+ let currentIdentity = node.engine.identity;
16
+
17
+ let subscription;
18
+
19
+ async function subscribe(eventType) {
20
+ switch (eventType) {
21
+ case "starting":
22
+ return await client.notification.onProcessStarting(
23
+ (processNotification) => {
24
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
25
+ return;
26
+ node.send({
27
+ payload: {
28
+ processInstanceId: processNotification.processInstanceId,
29
+ processModelId: processNotification.processModelId,
30
+ action: 'starting',
31
+ type: 'processInstance',
32
+ },
33
+ });
34
+ },
35
+ { identity: currentIdentity }
36
+ );
37
+ case 'started':
38
+ return await client.notification.onProcessStarted(
39
+ (processNotification) => {
40
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
41
+ return;
42
+ node.send({
43
+ payload: {
44
+ processInstanceId: processNotification.processInstanceId,
45
+ processModelId: processNotification.processModelId,
46
+ flowNodeId: processNotification.flowNodeId,
47
+ token: processNotification.currentToken,
48
+ action: 'started',
49
+ type: 'processInstance',
50
+ },
51
+ });
52
+ },
53
+ { identity: currentIdentity }
54
+ );
55
+ case 'resumed':
56
+ return await client.notification.onProcessResumed(
57
+ (processNotification) => {
58
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
59
+ return;
60
+ node.send({
61
+ payload: {
62
+ processInstanceId: processNotification.processInstanceId,
63
+ processModelId: processNotification.processModelId,
64
+ token: processNotification.currentToken,
65
+ action: 'resumed',
66
+ type: 'processInstance',
67
+ },
68
+ });
69
+ },
70
+ { identity: currentIdentity }
71
+ );
72
+ case 'finished':
73
+ return await client.notification.onProcessEnded(
74
+ (processNotification) => {
75
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
76
+ return;
77
+ node.send({
78
+ payload: {
79
+ processInstanceId: processNotification.processInstanceId,
80
+ processModelId: processNotification.processModelId,
81
+ flowNodeId: processNotification.flowNodeId,
82
+ token: processNotification.currentToken,
83
+ action: 'finished',
84
+ type: 'processInstance',
85
+ },
86
+ });
87
+ },
88
+ { identity: currentIdentity }
89
+ );
90
+ case 'terminated':
91
+ return await client.notification.onProcessTerminated(
92
+ (processNotification) => {
93
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
94
+ return;
95
+ node.send({
96
+ payload: {
97
+ processInstanceId: processNotification.processInstanceId,
98
+ processModelId: processNotification.processModelId,
99
+ token: processNotification.currentToken,
100
+ action: 'terminated',
101
+ type: 'processInstance',
102
+ },
103
+ });
104
+ },
105
+ { identity: currentIdentity }
106
+ );
107
+ case "error":
108
+ return await client.notification.onProcessError(
109
+ (processNotification) => {
110
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
111
+ return;
112
+ node.send({
113
+ payload: {
114
+ processInstanceId: processNotification.processInstanceId,
115
+ processModelId: processNotification.processModelId,
116
+ token: processNotification.currentToken,
117
+ action: 'error',
118
+ type: 'processInstance',
119
+ },
120
+ });
121
+ },
122
+ { identity: currentIdentity }
123
+ );
124
+ case "owner-changed":
125
+ return await client.notification.onProcessOwnerChanged(
126
+ (processNotification) => {
127
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
128
+ return;
129
+ node.send({
130
+ payload: {
131
+ processInstanceId: processNotification.processInstanceId,
132
+ processModelId: processNotification.processModelId,
133
+ action: 'owner-changed',
134
+ type: 'processInstance',
135
+ },
136
+ });
137
+ },
138
+ { identity: currentIdentity }
139
+ );
140
+ case "instances-deleted":
141
+ return await client.notification.onProcessInstancesDeleted(
142
+ (processNotification) => {
143
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
144
+ return;
145
+ node.send({
146
+ payload: {
147
+ processInstanceId: processNotification.processInstanceId,
148
+ processModelId: processNotification.processModelId,
149
+ action: 'instances-deleted',
150
+ type: 'processInstance',
151
+ },
152
+ });
153
+ },
154
+ { identity: currentIdentity }
155
+ );
156
+ case "is-executable-changed":
157
+ return await client.notification.onProcessIsExecutableChanged(
158
+ (processNotification) => {
159
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
160
+ return;
161
+ node.send({
162
+ payload: {
163
+ processModelId: processNotification.processModelId,
164
+ action: 'is-executable-changed',
165
+ type: 'processModel',
166
+ },
167
+ });
168
+ },
169
+ { identity: currentIdentity }
170
+ );
171
+ case "deployed":
172
+ return await client.notification.onProcessDeployed(
173
+ (processNotification) => {
174
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
175
+ return;
176
+ node.send({
177
+ payload: {
178
+ processModelId: processNotification.processModelId,
179
+ action: 'deployed',
180
+ type: 'processModel',
181
+ },
182
+ });
183
+ },
184
+ { identity: currentIdentity }
185
+ );
186
+ case "undeployed":
187
+ return await client.notification.onProcessUndeployed(
188
+ (processNotification) => {
189
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
190
+ return;
191
+ node.send({
192
+ payload: {
193
+ processModelId: processNotification.processModelId,
194
+ action: 'undeployed',
195
+ type: 'processModel',
196
+ },
197
+ });
198
+ },
199
+ { identity: currentIdentity }
200
+ );
201
+ default:
202
+ console.error("no such event: " + eventType)
203
+ break;
204
+ }
205
+ }
206
+
207
+ if (node.engine.isIdentityReady()) {
208
+ subscription = await subscribe(config.eventtype)
209
+ }
210
+
211
+ node.engine.registerOnIdentityChanged(async (identity) => {
212
+ if (subscription) {
213
+ client.notification.removeSubscription(subscription, currentIdentity);
214
+ }
215
+
216
+ currentIdentity = identity;
217
+
218
+ subscription = await client.notification.onProcessResumed(
219
+ (processNotification) => {
220
+ if (config.processmodel != '' && config.processmodel != processNotification.processModelId)
221
+ return;
222
+ node.send({
223
+ payload: {
224
+ processInstanceId: processNotification.processInstanceId,
225
+ processModelId: processNotification.processModelId,
226
+ token: processNotification.currentToken,
227
+ action: 'resumed',
228
+ type: 'processInstance',
229
+ },
230
+ });
231
+ },
232
+ { identity: currentIdentity }
233
+ );
234
+ });
235
+
236
+ node.on('close', () => {
237
+ if (node.engine && node.engine.engineClient && client) {
238
+ client.notification.removeSubscription(subscription, currentIdentity);
239
+ }
240
+ });
241
+ };
242
+
243
+ if (node.engine) {
244
+ register();
245
+ }
246
+ }
247
+ RED.nodes.registerType('process-event-listener', ProcessEventListener);
248
+ };