@gregoriusrippenstein/node-red-contrib-introspection 0.2.9 → 0.3.1
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/README.md +10 -9
- package/nodes/15-screenshot.html +90 -30
- package/nodes/15-screenshot.js +2 -0
- package/nodes/40-drawsvg.html +13 -1
- package/nodes/40-drawsvg.js +1 -1
- package/nodes/50-send-flow.html +126 -0
- package/nodes/50-send-flow.js +112 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ This is a hack that uses the `onpaletteadd` callback to do its magic. If this fu
|
|
|
75
75
|
|
|
76
76
|
A node for inserting an SVG image into the workspace. The image is layered above the grid but below nodes and their connections. The input message must contain SVG data (in string form) in the `payload` attribute.
|
|
77
77
|
|
|
78
|
-
### GetFlows
|
|
78
|
+
### GetFlows
|
|
79
79
|
|
|
80
80
|
Node retrieves the current `flows.json` from the server but using the [Node-RED API](https://nodered.org/docs/api/admin/methods/get/flows/) so that it is storage independent. It returns the flows as a `payload` of the message.
|
|
81
81
|
|
|
@@ -85,18 +85,19 @@ GetFlows supports version selection of the flows and it has limited authenticati
|
|
|
85
85
|
|
|
86
86
|
Inspired by the [dsm](https://flows.nodered.org/node/node-red-contrib-dsm) package that has a [backup](https://github.com/cflurin/node-red-contrib-dsm/wiki/Backup) state machine.
|
|
87
87
|
|
|
88
|
-
##
|
|
88
|
+
## Node-RED Versions
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
These nodes have been tested and found to work on Node-RED 3.0.2 and 3.1.0.beta.4.
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
- [Seeker](https://demo.openmindmap.org/omm/#flow/40ea5f2aea6592ae/n/b5f189a78d829197) - top left and the [Sink](https://demo.openmindmap.org/omm/#flow/459c271a96458c7c/n/e3262d9d2791ab78) - top right
|
|
94
|
-
- [Screenshot](https://demo.openmindmap.org/omm/#flow/4e2d8c13066b705e/n/499b1383580831aa) - top left
|
|
95
|
-
- [DrawSVG](https://demo.openmindmap.org/omm/#flow/6c8ce462533a1da4/n/248f2edd3d8acd96)
|
|
92
|
+
## Examples
|
|
96
93
|
|
|
97
|
-
|
|
94
|
+
There are [example flows](/examples) contained in the package, examples can also be found online at [FlowHub.org](https://flowhub.org):
|
|
98
95
|
|
|
99
|
-
|
|
96
|
+
- [Orphans](https://flowhub.org/f/2401c255b056e0e1)
|
|
97
|
+
- [Sink and Seeker](https://flowhub.org/f/139a816449acd89f)
|
|
98
|
+
- [Screenshot](https://flowhub.org/f/07b2d0f3b0445ab5)
|
|
99
|
+
- [DrawSVG](https://flowhub.org/f/141037dcda5b69fd)
|
|
100
|
+
- [GetFlows](https://flowhub.org/f/0b1bfbf6e540be66)
|
|
100
101
|
|
|
101
102
|
## License
|
|
102
103
|
|
package/nodes/15-screenshot.html
CHANGED
|
@@ -6,15 +6,39 @@
|
|
|
6
6
|
// Tested this on Node-RED 3.1.0.beta.4 - dunno about other 3.1.x.beta.y
|
|
7
7
|
//****
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
return (callbackWithSvgCode) => {
|
|
10
|
+
try {
|
|
11
|
+
handleSvgObject( $($('svg[width=8000]')[0]), callbackWithSvgCode );
|
|
12
|
+
} catch ( e ) {
|
|
13
|
+
var msg = "Error Generating SVG: " + JSON.stringify(e);
|
|
14
|
+
|
|
15
|
+
red.notify(msg,{ type: "error" });
|
|
16
|
+
|
|
17
|
+
var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="1000" height="1000" viewBox="0 0 1000 1000" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style>.small { font: bold 20px sans-serif; fill: red;}</style><text x="10" y="30" class="small">'+msg+'</text></svg>';
|
|
18
|
+
|
|
19
|
+
callbackWithSvgCode(svgData);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
10
22
|
}
|
|
11
23
|
|
|
12
|
-
function nr_intro_generate_svg_3_0(
|
|
24
|
+
function nr_intro_generate_svg_3_0( red ) {
|
|
13
25
|
//****
|
|
14
26
|
// for Node-RED v3.0.x (well 3.0.2 tested, dunno about 3.0.1)
|
|
15
27
|
//****
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
return (callbackWithSvgCode) => {
|
|
30
|
+
try {
|
|
31
|
+
handleSvgObject( $($('svg')[0]), callbackWithSvgCode);
|
|
32
|
+
} catch ( e ) {
|
|
33
|
+
var msg = "Error Generating SVG: " + JSON.stringify(e);
|
|
34
|
+
|
|
35
|
+
red.notify(msg,{ type: "error" });
|
|
36
|
+
|
|
37
|
+
var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="1000" height="1000" viewBox="0 0 1000 1000" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style>.small { font: bold 20px sans-serif; fill: red;}</style><text x="10" y="30" class="small">'+msg+'</text></svg>';
|
|
38
|
+
|
|
39
|
+
callbackWithSvgCode(svgData);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
18
42
|
}
|
|
19
43
|
|
|
20
44
|
|
|
@@ -29,6 +53,9 @@
|
|
|
29
53
|
var preParseSvg = origSvg.clone();
|
|
30
54
|
preParseSvg.find("foreignObject").remove();
|
|
31
55
|
|
|
56
|
+
// these are svgdraw inserts, this would be mirroring mirroring ...
|
|
57
|
+
preParseSvg.find("svg.__screenshot").remove();
|
|
58
|
+
|
|
32
59
|
var hwAttrs = (
|
|
33
60
|
'width="' + origSvg.attr('width') + '" height="' +
|
|
34
61
|
origSvg.attr('height') + '"'
|
|
@@ -39,7 +66,7 @@
|
|
|
39
66
|
'<?xml version="1.0" standalone="no"?>\r\n' +
|
|
40
67
|
'<svg ' + hwAttrs + ' pointer-events="all" style="cursor: crosshair; '+
|
|
41
68
|
'touch-action: none;" xmlns="http://www.w3.org/2000/svg" '+
|
|
42
|
-
'xmlns:xlink="http://www.w3.org/1999/xlink">\r\n'
|
|
69
|
+
'class="__screenshot" xmlns:xlink="http://www.w3.org/1999/xlink">\r\n'
|
|
43
70
|
);
|
|
44
71
|
|
|
45
72
|
var svgBody = preParseSvg.html();
|
|
@@ -151,6 +178,17 @@
|
|
|
151
178
|
}
|
|
152
179
|
}
|
|
153
180
|
|
|
181
|
+
var removeAllClassAndIdAttrs = (doc) => {
|
|
182
|
+
["g", "rect", "line", "path", "circle", "image", "text"].forEach((t)=>{
|
|
183
|
+
$(doc.getElementsByTagName(t)).each( (idx, elem ) => {
|
|
184
|
+
elem.setAttribute("class","");
|
|
185
|
+
elem.setAttribute("id","");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
return doc;
|
|
190
|
+
};
|
|
191
|
+
|
|
154
192
|
// probably missed some elements ...
|
|
155
193
|
var tagnames = [ "g", "rect", "line", "path", "circle", "image" ];
|
|
156
194
|
tagnames.forEach( function(tagname) {
|
|
@@ -242,7 +280,9 @@
|
|
|
242
280
|
var cb = (cntr) => {
|
|
243
281
|
if ( cntr < 0 ) {
|
|
244
282
|
delete imageCache;
|
|
245
|
-
callbackWithSvgCode((new XMLSerializer()).serializeToString(
|
|
283
|
+
callbackWithSvgCode((new XMLSerializer()).serializeToString(
|
|
284
|
+
removeAllClassAndIdAttrs(doc)
|
|
285
|
+
));
|
|
246
286
|
} else {
|
|
247
287
|
getDataAndCallbackWhenDone( imageColl.item(cntr), cntr, cb );
|
|
248
288
|
}
|
|
@@ -254,27 +294,35 @@
|
|
|
254
294
|
cb );
|
|
255
295
|
} else {
|
|
256
296
|
delete imageCache;
|
|
257
|
-
callbackWithSvgCode( (new XMLSerializer()).serializeToString(
|
|
297
|
+
callbackWithSvgCode( (new XMLSerializer()).serializeToString(
|
|
298
|
+
removeAllClassAndIdAttrs(doc)
|
|
299
|
+
));
|
|
258
300
|
}
|
|
259
301
|
};
|
|
260
302
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
303
|
+
function generatorFunctionForVersion(red) {
|
|
304
|
+
var version = red.settings.version.split(".")
|
|
305
|
+
var major = version[0]; // 3.0.x or 3.1.x --> making assumptions that
|
|
306
|
+
var minor = version[1]; // between minor version nothing changed
|
|
307
|
+
|
|
308
|
+
var dummy = (red) => {
|
|
309
|
+
return (cb) => {
|
|
310
|
+
var msg = "Node-RED version (" + red.settings.version + ") not supported";
|
|
311
|
+
red.notify(msg,{ type: "error" });
|
|
312
|
+
|
|
313
|
+
if ( cb ) {
|
|
314
|
+
var svgData = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg width="1000" height="1000" viewBox="0 0 1000 1000" pointer-events="all" style="cursor: crosshair; touch-action: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style>.small { font: bold 20px sans-serif; fill: red;}</style><text x="10" y="30" class="small">'+msg+'</text></svg>';
|
|
315
|
+
cb(svgData);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
if ( major == "3" ) {
|
|
321
|
+
if ( minor == "0" ) { return nr_intro_generate_svg_3_0(red); }
|
|
322
|
+
if ( minor == "1" ) { return nr_intro_generate_svg_3_1(red); }
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return dummy(red);
|
|
278
326
|
};
|
|
279
327
|
|
|
280
328
|
/*
|
|
@@ -291,11 +339,12 @@
|
|
|
291
339
|
}
|
|
292
340
|
|
|
293
341
|
var notification = data.notification;
|
|
294
|
-
|
|
342
|
+
|
|
343
|
+
generatorFunctionForVersion(RED)( (svgdata) => {
|
|
295
344
|
$.ajax({
|
|
296
345
|
type: "POST",
|
|
297
|
-
url:
|
|
298
|
-
dataType: "
|
|
346
|
+
url: data.endpoint,
|
|
347
|
+
dataType: "application/json;charset=utf-8",
|
|
299
348
|
data: {
|
|
300
349
|
...data,
|
|
301
350
|
d: svgdata
|
|
@@ -315,7 +364,7 @@
|
|
|
315
364
|
case 404:
|
|
316
365
|
// Http-in POST node is missing
|
|
317
366
|
RED.notify(
|
|
318
|
-
"Missing http-in node: method: POST, path:
|
|
367
|
+
"Missing http-in node: method: POST, path: " + data.endpoint, {
|
|
319
368
|
type: "error"
|
|
320
369
|
}
|
|
321
370
|
);
|
|
@@ -347,10 +396,13 @@
|
|
|
347
396
|
paletteLabel: "Screenshot",
|
|
348
397
|
defaults: {
|
|
349
398
|
name: {
|
|
350
|
-
value:"",
|
|
399
|
+
value: "",
|
|
351
400
|
},
|
|
352
401
|
screenshot: {
|
|
353
|
-
value:""
|
|
402
|
+
value: ""
|
|
403
|
+
},
|
|
404
|
+
endpoint: {
|
|
405
|
+
value: "/screenshot"
|
|
354
406
|
},
|
|
355
407
|
},
|
|
356
408
|
inputs:1,
|
|
@@ -395,7 +447,7 @@
|
|
|
395
447
|
|
|
396
448
|
this.editor.setValue( "Please wait, screenshot being prepared ..." );
|
|
397
449
|
|
|
398
|
-
generatorFunctionForVersion(RED
|
|
450
|
+
generatorFunctionForVersion(RED)( (svgdata) => {
|
|
399
451
|
that.editor.setValue( svgdata );
|
|
400
452
|
});
|
|
401
453
|
|
|
@@ -479,6 +531,14 @@
|
|
|
479
531
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
480
532
|
</div>
|
|
481
533
|
|
|
534
|
+
<div class="form-row">
|
|
535
|
+
<label for="node-input-endpoint">
|
|
536
|
+
<i class="fa fa-send-o"></i>
|
|
537
|
+
<span>Post Endpoint</span>
|
|
538
|
+
</label>
|
|
539
|
+
<input type="text" id="node-input-endpoint" placeholder="/screenshot">
|
|
540
|
+
</div>
|
|
541
|
+
|
|
482
542
|
<div class="form-row" style="position: relative; margin-bottom: 0px;">
|
|
483
543
|
<label for="node-input-screenshot"><i class="fa fa-file-code-o"></i> <span data-i18n="screenshot.label.screenshot">Screenshot</span></label>
|
|
484
544
|
<input type="hidden" id="node-input-screenshot" autofocus="autofocus">
|
package/nodes/15-screenshot.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = function(RED) {
|
|
|
14
14
|
RED.util.encodeObject({
|
|
15
15
|
...msg,
|
|
16
16
|
msg: "timer-tripped",
|
|
17
|
+
endpoint: cfg.endpoint,
|
|
17
18
|
})
|
|
18
19
|
);
|
|
19
20
|
|
|
@@ -23,5 +24,6 @@ module.exports = function(RED) {
|
|
|
23
24
|
send(msg);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
27
|
+
|
|
26
28
|
RED.nodes.registerType("Screenshot", ScreenshotFunctionality);
|
|
27
29
|
}
|
package/nodes/40-drawsvg.html
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
2
|
RED.comms.subscribe("introspect:drawsvg", (event,data) => {
|
|
3
3
|
if ( data.msg == "svgdata" ) {
|
|
4
|
-
|
|
4
|
+
var version = RED.settings.version.split(".");
|
|
5
|
+
|
|
6
|
+
if ( version[0] == "3" && version[1] == "0" ) {
|
|
7
|
+
$($($('svg')[0]).find('> g > g > g')[2]).append(
|
|
8
|
+
data.payload
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if ( version[0] == "3" && version[1] == "1" ) {
|
|
13
|
+
$($($('svg[width=8000]')[0]).find('> g > g > g')[2]).append(
|
|
14
|
+
data.payload
|
|
15
|
+
);
|
|
16
|
+
}
|
|
5
17
|
}
|
|
6
18
|
});
|
|
7
19
|
|
package/nodes/40-drawsvg.js
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('SendFlow',{
|
|
3
|
+
color: '#e5e4ef',
|
|
4
|
+
icon: "icons/subflow.svg",
|
|
5
|
+
category: 'introspection',
|
|
6
|
+
defaults: {
|
|
7
|
+
name: {
|
|
8
|
+
value:"",
|
|
9
|
+
},
|
|
10
|
+
hostUrl: {
|
|
11
|
+
value: ""
|
|
12
|
+
},
|
|
13
|
+
flowVersion: {
|
|
14
|
+
value: "v1"
|
|
15
|
+
},
|
|
16
|
+
useAuthentication: {
|
|
17
|
+
value:false
|
|
18
|
+
},
|
|
19
|
+
apiUsername: {
|
|
20
|
+
value: "",
|
|
21
|
+
},
|
|
22
|
+
apiUsernameType: {
|
|
23
|
+
value: "env",
|
|
24
|
+
},
|
|
25
|
+
apiPassword: {
|
|
26
|
+
value: "",
|
|
27
|
+
},
|
|
28
|
+
apiPasswordType: {
|
|
29
|
+
value: "env",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
inputs:1,
|
|
33
|
+
outputs:1,
|
|
34
|
+
|
|
35
|
+
label: function() {
|
|
36
|
+
return (this.name || this._def.paletteLabel);
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
labelStyle: function() {
|
|
40
|
+
return this.name?"node_label_italic":"";
|
|
41
|
+
},
|
|
42
|
+
oneditprepare: function() {
|
|
43
|
+
$("#node-input-apiUsername").typedInput({
|
|
44
|
+
types:["env", "msg", "flow","global", "cred"],
|
|
45
|
+
typeField: "#node-input-apiUsernameType"
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
$("#node-input-apiPassword").typedInput({
|
|
49
|
+
types:["env", "msg", "flow","global", "env", "cred"],
|
|
50
|
+
typeField: "#node-input-apiPasswordType"
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if ( $('#node-input-useAuthentication').is(":checked") ) {
|
|
54
|
+
$('#useAuthentication-input-fields').show();
|
|
55
|
+
} else {
|
|
56
|
+
$('#useAuthentication-input-fields').hide()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
$('#node-input-useAuthentication').on( 'change', function() {
|
|
60
|
+
if ( $('#node-input-useAuthentication').is(":checked") ) {
|
|
61
|
+
$('#useAuthentication-input-fields').show();
|
|
62
|
+
} else {
|
|
63
|
+
$('#useAuthentication-input-fields').hide()
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<script type="text/html" data-template-name="SendFlow">
|
|
71
|
+
<div class="form-row">
|
|
72
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
73
|
+
<input type="text" id="node-input-name" placeholder="Name">
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div class="form-row">
|
|
77
|
+
<label for="node-input-hostUrl"><i class="fa fa-tag"></i> Host</label>
|
|
78
|
+
<input type="text" id="node-input-hostUrl" placeholder="Host URL">
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<div class="form-row">
|
|
82
|
+
<label for="node-input-flowVersion">
|
|
83
|
+
<i class="fa fa-tag"></i>
|
|
84
|
+
<span>Flow Version</span>
|
|
85
|
+
</label>
|
|
86
|
+
|
|
87
|
+
<select id="node-input-flowVersion">
|
|
88
|
+
<option value="v1" selected=selected>Version 1</option>
|
|
89
|
+
<option value="v2">Version 2</option>
|
|
90
|
+
</select>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<div class="form-row">
|
|
94
|
+
<label for="node-input-useAuthentication">
|
|
95
|
+
<i class="fa "></i>
|
|
96
|
+
<span>Use Authentication?</span>
|
|
97
|
+
</label>
|
|
98
|
+
|
|
99
|
+
<input type="checkbox" id="node-input-useAuthentication"
|
|
100
|
+
style="display:inline-block; width:15px; vertical-align:baseline;">
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<div id="useAuthentication-input-fields" class="hidden">
|
|
104
|
+
<div class="form-row">
|
|
105
|
+
<label for="node-input-apiUsername">
|
|
106
|
+
<i class="fa fa-tag"></i>
|
|
107
|
+
Username
|
|
108
|
+
</label>
|
|
109
|
+
<input type="text" id="node-input-apiUsername">
|
|
110
|
+
<input type="hidden" id="node-input-apiUsernameType">
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
<div class="form-row">
|
|
114
|
+
<label for="node-input-apiPassword">
|
|
115
|
+
<i class="fa fa-tag"></i>
|
|
116
|
+
Password
|
|
117
|
+
</label>
|
|
118
|
+
<input type="text" id="node-input-apiPassword">
|
|
119
|
+
<input type="hidden" id="node-input-apiPasswordType">
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
<script type="text/html" data-help-name="SendFlow">
|
|
125
|
+
<p>Send flow to another Node-RED instance.</p>
|
|
126
|
+
</script>
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
module.exports = function(RED) {
|
|
2
|
+
function SendFlowFunctionality(config) {
|
|
3
|
+
RED.nodes.createNode(this,config);
|
|
4
|
+
|
|
5
|
+
var node = this;
|
|
6
|
+
var cfg = config;
|
|
7
|
+
|
|
8
|
+
node.on('close', function() {
|
|
9
|
+
node.status({});
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
node.on("input", function(msg, send, done) {
|
|
13
|
+
var sendFlow = (hdrs, got) => {
|
|
14
|
+
got.post( cfg.hostUrl + "/flows", {
|
|
15
|
+
headers: {
|
|
16
|
+
"Node-RED-API-Version": cfg.flowVersion,
|
|
17
|
+
"Content-type": "application/json",
|
|
18
|
+
"Node-RED-Deployment-Type": "full",
|
|
19
|
+
...hdrs
|
|
20
|
+
},
|
|
21
|
+
body: JSON.stringify(msg.payload)
|
|
22
|
+
}).then( res => {
|
|
23
|
+
var bodySize = res.body.length;
|
|
24
|
+
|
|
25
|
+
send({
|
|
26
|
+
...msg,
|
|
27
|
+
payload: res.body
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
node.status({fill:"green",shape:"dot",text:"Good"});
|
|
31
|
+
setTimeout( function() {
|
|
32
|
+
node.status({})
|
|
33
|
+
}, 450);
|
|
34
|
+
|
|
35
|
+
}).catch( err => {
|
|
36
|
+
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
37
|
+
node.error(err)
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Authentication
|
|
43
|
+
**/
|
|
44
|
+
if ( cfg.useAuthentication ) {
|
|
45
|
+
var username = undefined;
|
|
46
|
+
var password = undefined;
|
|
47
|
+
|
|
48
|
+
node.status({fill:"blue",shape:"dot",text:"Requesting token"});
|
|
49
|
+
|
|
50
|
+
RED.util.evaluateNodeProperty(cfg.apiUsername, cfg.apiUsernameType,
|
|
51
|
+
node, msg, (err, result) => {
|
|
52
|
+
if (err) {
|
|
53
|
+
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
54
|
+
node.error(err)
|
|
55
|
+
} else {
|
|
56
|
+
username = result;
|
|
57
|
+
|
|
58
|
+
RED.util.evaluateNodeProperty(cfg.apiPassword, cfg.apiPasswordType,
|
|
59
|
+
node, msg, (err, result) => {
|
|
60
|
+
if (err) {
|
|
61
|
+
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
62
|
+
node.error(err)
|
|
63
|
+
} else {
|
|
64
|
+
password = result;
|
|
65
|
+
|
|
66
|
+
var data = {
|
|
67
|
+
"client_id": "node-red-admin",
|
|
68
|
+
"grant_type": "password",
|
|
69
|
+
"scope": "*",
|
|
70
|
+
"username": username,
|
|
71
|
+
"password": password
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
import('got').then( (module) => {
|
|
75
|
+
module.got.post( cfg.hostUrl + "/auth/token", {
|
|
76
|
+
json: data
|
|
77
|
+
}).then( res => {
|
|
78
|
+
node.status({
|
|
79
|
+
fill:"blue",
|
|
80
|
+
shape:"dot",
|
|
81
|
+
text:"Sending flow"
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
var access_token = JSON.parse(res.body).access_token;
|
|
85
|
+
|
|
86
|
+
sendFlow({
|
|
87
|
+
"Authorization": "Bearer " + access_token
|
|
88
|
+
}, module.got);
|
|
89
|
+
|
|
90
|
+
}).catch((err) => {
|
|
91
|
+
node.status({fill:"red",shape:"dot",text:"Failed"});
|
|
92
|
+
node.error( err );
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
} else {
|
|
100
|
+
/*
|
|
101
|
+
* Authentication free zone...
|
|
102
|
+
*/
|
|
103
|
+
node.status({fill:"blue",shape:"dot",text:"Sending flow"});
|
|
104
|
+
import('got').then( (module) => {
|
|
105
|
+
sendFlow({}, module.got);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
RED.nodes.registerType("SendFlow", SendFlowFunctionality);
|
|
112
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gregoriusrippenstein/node-red-contrib-introspection",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"got": "latest"
|
|
6
6
|
},
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"ismobile": "nodes/25-ismobile.js",
|
|
24
24
|
"navigator": "nodes/30-navigator.js",
|
|
25
25
|
"drawsvg": "nodes/40-drawsvg.js",
|
|
26
|
-
"getflows": "nodes/45-get-flows.js"
|
|
26
|
+
"getflows": "nodes/45-get-flows.js",
|
|
27
|
+
"sendflow": "nodes/50-send-flow.js"
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
30
|
"description": "Node-RED Editor-only nodes for introspecting flows.",
|