node-red-contrib-spark
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -0,1 +1,7 @@ | ||
#### 1.1.0: Feature Release | ||
- added msg.topic to api node output that contains api resource and method | ||
- simplified parser node | ||
- updated swagger definition files to include new APIs for people, organizations, licenses, and roles. | ||
#### 1.0.4: Maintenance Release | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "node-red-contrib-spark", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Node-RED Nodes to integrate with the Cisco Spark API", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -179,14 +179,18 @@ # node-red-contrib-spark | ||
The Spark Parse Node allows parsing of messages received from either the Webhook or API Node. The parsed value is placed in the `msg.payload` of the first output. The parser property value string is passed in `msg.topic` for use with supporting functions like `join`. The original `msg.payload` is passed through to the second output. | ||
The Spark Parse Node allows parsing of messages received from either the Webhook or API Node. The parsed value is placed in the `msg.payload` of the first output. The value of the "parse" field is delivered in `msg.topic` for use with supporting functions like `join`. The original `msg.payload` is passed through to the second output. | ||
If the input receives an array, each element of the array is parsed individually. The results can be returned as either a single array or as multiple messages in the output. This option is configured within the Node itself. If setup to send a single array, only a single message is sent with the `msg.payload` containing the array. If setup to send as multiple messages, the Node will output individual messages sequentially with each element in that message including a `msg.payload` and `msg.topic` property. | ||
The output specifies how the `msg.payload` is formatted. Options are: | ||
<ul> | ||
<li>original - The original value of the property without modifying data | ||
type.</li> | ||
<li>object - The original value of the property placed into an object with | ||
the object key being the parser value, or optionally the topic if | ||
specified.</li> | ||
</ul> | ||
</p> | ||
If the parser input receives an array, each element of the array is parsed individually. The results are returned as multiple sequential messages to the output with each msg having a `msg.payload` and `msg.topic` property. | ||
![](https://github.com/nmarus/node-red-contrib-spark/raw/master/images/parser-node.jpg) | ||
**Example Output (as Array) : `msg.payload`** | ||
```json | ||
[ "Test Room 1", "Test Room 2", "Test Room 3" ] | ||
``` | ||
**Example Output (Individual) : `msg.payload`** | ||
@@ -208,7 +212,7 @@ | ||
* **Property** - The object property to parse from the input. | ||
* **Parse** - The object property to parse from the input. | ||
* **Output** - The selector on how to handle array input. The options are: | ||
* **Individual Messages** - Sends each element property of the input array (collection) as a separate message. | ||
* **Single Message as an Array** - Sends each element property of the input array as an array of strings. | ||
* **Topic** - By default, the value of "property" is used as msg.topic. This can be overridden here if needed. | ||
* **the individual property value** - Outputs the original value of the poperty without modifying data type. | ||
* **a key/value object** - Outputs the original value of the property placed into an object with the object key being the parser value, or optionally the topic if specified. | ||
* **Topic** - By default, the value of "parse" is used as msg.topic. This can be overridden here if needed. | ||
@@ -215,0 +219,0 @@ ## License |
@@ -231,2 +231,6 @@ module.exports = function(RED) { | ||
// set msg.topic | ||
msg.topic = node.resource + '.' + node.method; | ||
// send message | ||
node.send(msg); | ||
@@ -261,2 +265,6 @@ return; | ||
// set msg.topic | ||
msg.topic = node.resource + '.' + node.method; | ||
// send msg | ||
node.send(msg); | ||
@@ -343,2 +351,6 @@ } | ||
// set msg.topic | ||
msg.topic = node.resource + '.' + node.method; | ||
// send message | ||
node.send(msg); | ||
@@ -430,2 +442,6 @@ return; | ||
// set msg.topic | ||
msg.topic = node.resource + '.' + node.method; | ||
// send message | ||
node.send(msg); | ||
@@ -432,0 +448,0 @@ } |
@@ -11,6 +11,12 @@ module.exports = function(RED) { | ||
node.parser = n.parser; | ||
node.output = n.output.toLowerCase(); | ||
node.topic = n.topic; | ||
node.multi = n.multi === 'true' ? true : false; | ||
function processPayload(pl, k) { | ||
// determine topic | ||
var topic = typeof node.topic === 'string' && node.topic.length > 0 ? node.topic : k; | ||
// value | ||
var value = ''; | ||
// validate payload is object | ||
@@ -22,3 +28,3 @@ if(typeof pl === 'object') { | ||
if(pl.data.hasOwnProperty(k)) { | ||
return pl.data[k]; | ||
value = pl.data[k]; | ||
} else { | ||
@@ -32,3 +38,3 @@ return null; | ||
if(pl.hasOwnProperty(k)) { | ||
return pl[k]; | ||
value = pl[k]; | ||
} else { | ||
@@ -39,29 +45,33 @@ return null; | ||
// format output | ||
// if output is original | ||
if(node.output === 'original') { | ||
return value; | ||
} | ||
// else, if output is object | ||
else if(node.output === 'object') { | ||
return { [topic]: value }; | ||
} | ||
// else, unrecognized | ||
else { | ||
return null; | ||
} | ||
} | ||
// else, not an object | ||
else { | ||
return null; | ||
} | ||
} | ||
function processPayloadArray(plArr, k) { | ||
var flatArr = _.map(plArr, function(pl) { | ||
// get payload | ||
var payload = processPayload(pl, k); | ||
if(payload) { | ||
return payload; | ||
} | ||
}); | ||
// determine topic | ||
var topic = typeof node.topic === 'string' && node.topic.length > 0 ? node.topic : k; | ||
return { "payload": flatArr, "topic": topic }; | ||
} | ||
function processPayloadMulti(plArr, k) { | ||
var collection = _.map(plArr, function(pl) { | ||
// define payload | ||
var payload = processPayload(pl, k); | ||
// determine topic | ||
var topic = typeof node.topic === 'string' && node.topic.length > 0 ? node.topic : k; | ||
if(payload) { | ||
@@ -72,3 +82,9 @@ return { "payload": payload, "topic": topic }; | ||
return collection; | ||
collection = _.compact(collection); | ||
if(collection && collection.length > 0) { | ||
return collection; | ||
} else { | ||
return null; | ||
} | ||
} | ||
@@ -78,2 +94,5 @@ | ||
node.on('input', function(msg) { | ||
// determine topic | ||
var topic = typeof node.topic === 'string' && node.topic.length > 0 ? node.topic : node.parser; | ||
var msgParser = {}; | ||
@@ -88,12 +107,10 @@ | ||
if(payload.length > 0) { | ||
if(node.multi) { | ||
msgParser = processPayloadMulti(payload, node.parser); | ||
var newArray = processPayloadArray(payload, node.parser); | ||
if(newArray && newArray.length > 0) { | ||
msgParser = newArray; | ||
} else { | ||
msgParser = processPayloadArray(payload, node.parser); | ||
msgParser = null; | ||
node.warn('unmatched parser'); | ||
} | ||
} | ||
else { | ||
msgParser = null; | ||
node.warn('unmatched parser'); | ||
} | ||
} | ||
@@ -106,3 +123,3 @@ | ||
msgParser.payload = newPayload; | ||
msgParser.topic = typeof node.topic === 'string' && node.topic.length > 0 ? node.topic : node.parser; | ||
msgParser.topic = topic; | ||
} else { | ||
@@ -113,2 +130,5 @@ msgParser = null; | ||
} | ||
// send msgs | ||
node.send([msgParser, msg]); | ||
} | ||
@@ -119,6 +139,6 @@ | ||
node.warn('invalid input'); | ||
// send msgs | ||
node.send([null, msg]); | ||
} | ||
// send msgs | ||
node.send([msgParser, msg]); | ||
}); | ||
@@ -125,0 +145,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
848673
18641
226
12