New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@node-red/nodes

Package Overview
Dependencies
Maintainers
2
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@node-red/nodes - npm Package Compare versions

Comparing version 1.3.5 to 2.0.0-beta.1

core/function/rbe.html

18

core/common/20-inject.js

@@ -19,3 +19,3 @@ /**

"use strict";
var cron = require("cron");
const {scheduleTask} = require("cronosjs");

@@ -89,3 +89,3 @@ function InjectNode(n) {

}
this.cronjob = new cron.CronJob(this.crontab, function() { node.emit("input", {}); }, null, true);
this.cronjob = scheduleTask(this.crontab,() => { node.emit("input", {})});
}

@@ -105,4 +105,8 @@ };

var errors = [];
this.props.forEach(p => {
var props = this.props;
if(msg.__user_inject_props__ && Array.isArray(msg.__user_inject_props__)) {
props = msg.__user_inject_props__;
}
delete msg.__user_inject_props__;
props.forEach(p => {
var property = p.p;

@@ -162,3 +166,7 @@ var value = p.v ? p.v : '';

try {
node.receive();
if (req.body && req.body.__user_inject_props__) {
node.receive(req.body);
} else {
node.receive();
}
res.sendStatus(200);

@@ -165,0 +173,0 @@ } catch(err) {

@@ -22,2 +22,4 @@ /**

var vm = require("vm");
var acorn = require("acorn");
var acornWalk = require("acorn-walk");

@@ -106,10 +108,3 @@ function sendResults(node,send,_msgid,msgs,cloneFirstMessage) {

var handleNodeDoneCall = true;
// Check to see if the Function appears to call `node.done()`. If so,
// we will assume it is well written and does actually call node.done().
// Otherwise, we will call node.done() after the function returns regardless.
if (/node\.done\s*\(\s*\)/.test(node.func)) {
handleNodeDoneCall = false;
}

@@ -135,2 +130,22 @@ var functionText = "var results = null;"+

"})(msg,__send__,__done__);";
var handleNodeDoneCall = true;
// Check to see if the Function appears to call `node.done()`. If so,
// we will assume it is well written and does actually call node.done().
// Otherwise, we will call node.done() after the function returns regardless.
if (/node\.done\s*\(\s*\)/.test(functionText)) {
// We have spotted the code contains `node.done`. It could be in a comment
// so need to do the extra work to parse the AST and examine it properly.
acornWalk.simple(acorn.parse(functionText,{ecmaVersion: "latest"} ), {
CallExpression(astNode) {
if (astNode.callee && astNode.callee.object) {
if (astNode.callee.object.name === "node" && astNode.callee.property.name === "done") {
handleNodeDoneCall = false;
}
}
}
})
}
var finScript = null;

@@ -137,0 +152,0 @@ var finOpt = null;

@@ -220,2 +220,6 @@ /**

if (!state) {
if (node.rules.length === 0) {
done(undefined, []);
return;
}
state = {

@@ -222,0 +226,0 @@ currentRule: 0,

@@ -23,3 +23,17 @@ /**

var SECONDS_TO_NANOS = 1000000000;
var _maxKeptMsgsCount;
function maxKeptMsgsCount(node) {
if (_maxKeptMsgsCount === undefined) {
var name = "nodeMessageBufferMaxLength";
if (RED.settings.hasOwnProperty(name)) {
_maxKeptMsgsCount = RED.settings[name];
}
else {
_maxKeptMsgsCount = 0;
}
}
return _maxKeptMsgsCount;
}
function DelayNode(n) {

@@ -82,2 +96,5 @@ RED.nodes.createNode(this,n);

this.drop = n.drop;
this.droppedMsgs = 0;
this.allowrate = n.allowrate|| false;
this.fixedrate = this.rate;
var node = this;

@@ -93,2 +110,15 @@

var sendMsgFromBuffer = function() {
if (node.buffer.length === 0) {
clearInterval(node.intervalID);
node.intervalID = -1;
}
if (node.buffer.length > 0) {
const msgInfo = node.buffer.shift();
msgInfo.send(msgInfo.msg);
msgInfo.done();
}
node.reportDepth();
}
var clearDelayList = function(s) {

@@ -118,17 +148,24 @@ for (var i=0; i<node.idList.length; i++ ) { node.idList[i].clear(); }

var loggerId = setInterval(function () {
if (node.droppedMsgs !== 0) {
node.debug("node.droppedMsgs = " + node.droppedMsgs);
node.droppedMsgs = 0;
}
}, 15 * 1000);
node.on("close", function() { clearInterval(loggerId); });
if (node.pauseType === "delay") {
node.on("input", function(msg, send, done) {
var id = ourTimeout(function() {
node.idList.splice(node.idList.indexOf(id),1);
if (node.idList.length === 0) { node.status({}); }
send(msg);
done();
}, node.timeout, () => done());
if (Object.keys(msg).length === 2 && msg.hasOwnProperty("flush")) { id.clear(); }
else { node.idList.push(id); }
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
if (msg.hasOwnProperty("flush")) { flushDelayList(); done(); }
else {
var id = ourTimeout(function() {
node.idList.splice(node.idList.indexOf(id),1);
if (node.idList.length === 0) { node.status({}); }
send(msg);
done();
}, node.timeout, () => done());
node.idList.push(id);
if ((node.timeout > 1000) && (node.idList.length !== 0)) {
node.status({fill:"blue",shape:"dot",text:" "});
}
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
if ((node.timeout > 1000) && (node.idList.length !== 0)) {
node.status({fill:"blue",shape:"dot",text:" "});
}

@@ -152,7 +189,7 @@ });

node.idList.push(id);
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
if (msg.hasOwnProperty("flush")) { flushDelayList(); done(); }
if ((delayvar >= 0) && (node.idList.length !== 0)) {
node.status({fill:"blue",shape:"dot",text:delayvar/1000+"s"});
}
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
if (msg.hasOwnProperty("flush")) { flushDelayList(); }
});

@@ -170,2 +207,3 @@ node.on("close", function() { clearDelayList(); });

node.buffer = [];
node.rate = node.fixedrate;
node.status({text:"reset"});

@@ -175,2 +213,3 @@ done();

}
if (!node.drop) {

@@ -180,20 +219,23 @@ var m = RED.util.cloneMessage(msg);

if (node.intervalID !== -1) {
node.buffer.push({msg: m, send: send, done: done});
node.reportDepth();
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
node.rate = msg.rate;
clearInterval(node.intervalID);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
}
var max_msgs = maxKeptMsgsCount(node);
if ((max_msgs > 0) && (node.buffer.length >= max_msgs)) {
node.buffer = [];
node.error(RED._("delay.errors.too-many"), msg);
} else {
node.buffer.push({msg: m, send: send, done: done});
node.reportDepth();
}
}
else {
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
node.rate = msg.rate;
}
send(m);
node.reportDepth();
node.intervalID = setInterval(function() {
if (node.buffer.length === 0) {
clearInterval(node.intervalID);
node.intervalID = -1;
}
if (node.buffer.length > 0) {
const msgInfo = node.buffer.shift();
msgInfo.send(msgInfo.msg);
msgInfo.done();
}
node.reportDepth();
}, node.rate);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
done();

@@ -212,14 +254,37 @@ }

else {
var timeSinceLast;
if (node.lastSent) {
timeSinceLast = process.hrtime(node.lastSent);
if (maxKeptMsgsCount(node) > 0) {
if (node.intervalID === -1) {
node.send(msg);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
} else {
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
node.rate = msg.rate;
clearInterval(node.intervalID);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
}
if (node.buffer.length < _maxKeptMsgsCount) {
var m = RED.util.cloneMessage(msg);
node.buffer.push({msg: m, send: send, done: done});
} else {
node.trace("dropped due to buffer overflow. msg._msgid = " + msg._msgid);
node.droppedMsgs++;
}
}
} else {
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate))) {
node.rate = msg.rate;
}
var timeSinceLast;
if (node.lastSent) {
timeSinceLast = process.hrtime(node.lastSent);
}
if (!node.lastSent) { // ensuring that we always send the first message
node.lastSent = process.hrtime();
send(msg);
}
else if ( ( (timeSinceLast[0] * SECONDS_TO_NANOS) + timeSinceLast[1] ) > (node.rate * MILLIS_TO_NANOS) ) {
node.lastSent = process.hrtime();
send(msg);
}
}
if (!node.lastSent) { // ensuring that we always send the first message
node.lastSent = process.hrtime();
send(msg);
}
else if ( ( (timeSinceLast[0] * SECONDS_TO_NANOS) + timeSinceLast[1] ) > (node.rate * MILLIS_TO_NANOS) ) {
node.lastSent = process.hrtime();
send(msg);
}
done();

@@ -257,2 +322,7 @@ }

node.on("input", function(msg, send, done) {
if (node.allowrate && msg.hasOwnProperty("rate") && !isNaN(parseFloat(msg.rate)) && node.rate !== msg.rate) {
node.rate = msg.rate;
clearInterval(node.intervalID);
node.intervalID = setInterval(sendMsgFromBuffer, node.rate);
}
if (!msg.hasOwnProperty("topic")) { msg.topic = "_none_"; }

@@ -278,2 +348,3 @@ hit = false;

node.buffer = [];
node.rate = node.fixedrate;
node.status({text:"reset"});

@@ -311,8 +382,9 @@ done();

}, wait, () => done());
node.idList.push(id);
if (Object.keys(msg).length === 2 && msg.hasOwnProperty("flush")) { id.clear(); }
else { node.idList.push(id); }
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
if (msg.hasOwnProperty("flush")) { flushDelayList(); done(); }
if ((node.timeout >= 1000) && (node.idList.length !== 0)) {
node.status({fill:"blue",shape:"dot",text:parseInt(wait/10)/100+"s"});
}
if (msg.hasOwnProperty("reset")) { clearDelayList(true); }
if (msg.hasOwnProperty("flush")) { flushDelayList(); }
});

@@ -319,0 +391,0 @@ node.on("close", function() { clearDelayList(); });

@@ -29,2 +29,3 @@ /**

this.servername = (n.servername||"").trim();
this.alpnprotocol = (n.alpnprotocol||"").trim();

@@ -110,2 +111,5 @@ if ((certPath.length > 0) || (keyPath.length > 0) || (caPath.length > 0)) {

}
if (this.alpnprotocol) {
opts.ALPNProtocols = [this.alpnprotocol];
}
opts.rejectUnauthorized = this.verifyservercert;

@@ -112,0 +116,0 @@ }

@@ -317,3 +317,3 @@ /**

// Build options for passing to the MQTT.js API
this.options.clientId = this.clientid || 'mqtt_' + (1+Math.random()*4294967295).toString(16);
this.options.clientId = this.clientid || 'mqtt_' + RED.util.generateId();
this.options.username = this.username;

@@ -320,0 +320,0 @@ this.options.password = this.password;

@@ -19,3 +19,9 @@ /**

"use strict";
var request = require("request");
const got = require("got");
const {CookieJar} = require("tough-cookie");
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
const FormData = require('form-data');
const { v4: uuid } = require('uuid');
const crypto = require('crypto');
const URL = require("url").URL
var mustache = require("mustache");

@@ -34,2 +40,4 @@ var querystring = require("querystring");

var paytobody = false;
var redirectList = [];
var nodeHTTPPersistent = n["persist"];

@@ -62,2 +70,4 @@ if (n.tls) {

this.on("input",function(msg,nodeSend,nodeDone) {
//reset redirectList on each request
redirectList = [];
var preRequestTimestamp = process.hrtime();

@@ -69,2 +79,3 @@ node.status({fill:"blue",shape:"dot",text:"httpin.status.requesting"});

}
if (isTemplatedUrl) {

@@ -78,2 +89,4 @@ url = mustache.render(nodeUrl,msg);

}
// url must start http:// or https:// so assume http:// if not set

@@ -94,2 +107,3 @@ if (url.indexOf("://") !== -1 && url.indexOf("http") !== 0) {

var method = nodeMethod.toUpperCase() || "GET";

@@ -103,15 +117,15 @@ if (msg.method && n.method && (n.method !== "use")) { // warn if override option not set

var isHttps = (/^https/i.test(url));
// var isHttps = (/^https/i.test(url));
var opts = {};
opts.url = url;
// set defaultport, else when using HttpsProxyAgent, it's defaultPort of 443 will be used :(.
opts.defaultPort = isHttps?443:80;
// Had to remove this to get http->https redirect to work
// opts.defaultPort = isHttps?443:80;
opts.timeout = node.reqTimeout;
opts.method = method;
opts.headers = {};
opts.encoding = null; // Force NodeJs to return a Buffer (instead of a string)
opts.retry = 0;
opts.responseType = 'buffer';
opts.maxRedirects = 21;
opts.jar = request.jar();
opts.proxy = null;
opts.cookieJar = new CookieJar();
opts.forever = nodeHTTPPersistent;

@@ -127,2 +141,17 @@ if (msg.requestTimeout !== undefined) {

}
opts.hooks = {
beforeRedirect: [
(options, response) => {
let redirectInfo = {
location: response.headers.location
}
if (response.headers.hasOwnProperty('set-cookie')) {
redirectInfo.cookies = extractCookies(response.headers['set-cookie']);
}
redirectList.push(redirectInfo)
}
]
}
var ctSet = "Content-Type"; // set default camel case

@@ -155,26 +184,11 @@ var clSet = "Content-Length";

}
if (msg.hasOwnProperty('followRedirects')) {
opts.followRedirect = msg.followRedirects;
opts.followAllRedirects = !!opts.followRedirect;
opts.followRedirect = !!msg.followRedirects;
}
var redirectList = [];
if (!opts.hasOwnProperty('followRedirect') || opts.followRedirect) {
opts.followRedirect = function(res) {
var redirectInfo = {
location: res.headers.location,
};
if (res.headers.hasOwnProperty('set-cookie')) {
redirectInfo.cookies = extractCookies(res.headers['set-cookie']);
}
redirectList.push(redirectInfo);
if (this.headers.cookie) {
delete this.headers.cookie;
}
return true;
};
}
if (opts.headers.hasOwnProperty('cookie')) {
var cookies = cookie.parse(opts.headers.cookie, {decode:String});
for (var name in cookies) {
opts.jar.setCookie(cookie.serialize(name, cookies[name], {encode:String}), url);
opts.cookieJar.setCookie(cookie.serialize(name, cookies[name], {encode:String}), url);
}

@@ -192,9 +206,9 @@ delete opts.headers.cookie;

// If the encode option is false, the value is not encoded.
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url);
opts.cookieJar.setCookie(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url);
} else {
// The value is encoded by encodeURIComponent().
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name].value), url);
opts.cookieJar.setCookie(cookie.serialize(name, msg.cookies[name].value), url);
}
} else {
opts.jar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
opts.cookieJar.setCookie(cookie.serialize(name, msg.cookies[name]), url);
}

@@ -207,21 +221,32 @@ }

if (this.credentials.user) {
opts.auth = {
user: this.credentials.user,
pass: this.credentials.password || ""
};
opts.username = this.credentials.user;
}
if (this.credentials.password) {
opts.password = this.credentials.password;
}
} else if (this.authType === "digest") {
if (this.credentials.user) {
// The first request will be sent without auth information. Based on the 401 response, the library can determine
// which auth type is required by the server. Then the request is resubmitted with the appropriate auth header.
opts.auth = {
user: this.credentials.user,
pass: this.credentials.password || "",
sendImmediately: false
};
}
let digestCreds = this.credentials;
let sentCreds = false;
opts.hooks.afterResponse = [(response, retry) => {
if (response.statusCode === 401) {
if (sentCreds) {
return response
}
const requestUrl = new URL(response.request.requestUrl);
const options = response.request.options;
const normalisedHeaders = {};
Object.keys(response.headers).forEach(k => {
normalisedHeaders[k.toLowerCase()] = response.headers[k]
})
if (normalisedHeaders['www-authenticate']) {
let authHeader = buildDigestHeader(digestCreds.user,digestCreds.password, options.method, requestUrl.pathname, normalisedHeaders['www-authenticate'])
options.headers.authorization = authHeader;
}
sentCreds = true;
return retry(options);
}
return response
}];
} else if (this.authType === "bearer") {
opts.auth = {
bearer: this.credentials.password || ""
};
opts.headers.Authorization = `Bearer ${this.credentials.password||""}`
}

@@ -231,6 +256,6 @@ }

if (method !== 'GET' && method !== 'HEAD' && typeof msg.payload !== "undefined") {
if (opts.headers['content-type'] == 'multipart/form-data' && typeof msg.payload === "object") {
opts.formData = {};
let formData = new FormData();
for (var opt in msg.payload) {

@@ -241,12 +266,7 @@ if (msg.payload.hasOwnProperty(opt)) {

if (typeof val === 'string' || Buffer.isBuffer(val)) {
opts.formData[opt] = val;
formData.append(opt, val);
} else if (typeof val === 'object' && val.hasOwnProperty('value')) {
// Treat as file to upload - ensure it has an options object
// as request complains if it doesn't
if (!val.hasOwnProperty('options')) {
val.options = {};
}
opts.formData[opt] = val;
formData.append(opt,val.value,val.options || {});
} else {
opts.formData[opt] = JSON.stringify(val);
formData.append(opt,JSON.stringify(val));
}

@@ -256,2 +276,6 @@ }

}
// GOT will only set the content-type header with the correct boundary
// if the header isn't set. So we delete it here, for GOT to reset it.
delete opts.headers['content-type'];
opts.body = formData;
} else {

@@ -283,11 +307,13 @@ if (typeof msg.payload === "string" || Buffer.isBuffer(msg.payload)) {

if (method == 'GET' && typeof msg.payload !== "undefined" && paytoqs) {
if (typeof msg.payload === "object") {
try {
if (opts.url.indexOf("?") !== -1) {
opts.url += (opts.url.endsWith("?")?"":"&") + querystring.stringify(msg.payload);
if (url.indexOf("?") !== -1) {
url += (url.endsWith("?")?"":"&") + querystring.stringify(msg.payload);
} else {
opts.url += "?" + querystring.stringify(msg.payload);
url += "?" + querystring.stringify(msg.payload);
}
} catch(err) {
node.error(RED._("httpin.errors.invalid-payload"),msg);

@@ -298,2 +324,3 @@ nodeDone();

} else {
node.error(RED._("httpin.errors.invalid-payload"),msg);

@@ -304,2 +331,3 @@ nodeDone();

} else if ( method == "GET" && typeof msg.payload !== "undefined" && paytobody) {
opts.allowGetBody = true;
if (typeof msg.payload === "object") {

@@ -331,75 +359,96 @@ opts.body = JSON.stringify(msg.payload);

if (prox && !noproxy) {
var match = prox.match(/^(http:\/\/)?(.+)?:([0-9]+)?/i);
var match = prox.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i);
if (match) {
opts.proxy = prox;
let proxyAgent;
let proxyURL = new URL(prox);
//set username/password to null to stop empty creds header
let proxyOptions = {
proxy: {
protocol: proxyURL.protocol,
hostname: proxyURL.hostname,
port: proxyURL.port,
username: null,
password: null
},
maxFreeSockets: 256,
maxSockets: 256,
keepAlive: true
}
if (proxyConfig && proxyConfig.credentials) {
let proxyUsername = proxyConfig.credentials.username || '';
let proxyPassword = proxyConfig.credentials.password || '';
if (proxyUsername || proxyPassword) {
proxyOptions.proxy.username = proxyUsername;
proxyOptions.proxy.password = proxyPassword;
}
} else if (proxyURL.username || proxyURL.password){
proxyOptions.proxy.username = proxyURL.username;
proxyOptions.proxy.password = proxyURL.password;
}
//need both incase of http -> https redirect
opts.agent = {
http: new HttpProxyAgent(proxyOptions),
https: new HttpsProxyAgent(proxyOptions)
};
} else {
node.warn("Bad proxy url: "+ prox);
opts.proxy = null;
}
}
if (proxyConfig && proxyConfig.credentials && opts.proxy == proxyConfig.url) {
var proxyUsername = proxyConfig.credentials.username || '';
var proxyPassword = proxyConfig.credentials.password || '';
if (proxyUsername || proxyPassword) {
opts.headers['proxy-authorization'] =
'Basic ' +
Buffer.from(proxyUsername + ':' + proxyPassword).toString('base64');
}
}
if (tlsNode) {
tlsNode.addTLSOptions(opts);
opts.https = {};
tlsNode.addTLSOptions(opts.https);
} else {
if (msg.hasOwnProperty('rejectUnauthorized')) {
opts.rejectUnauthorized = msg.rejectUnauthorized;
opts.https = { rejectUnauthorized: msg.rejectUnauthorized };
}
}
request(opts, function(err, res, body) {
if(err){
if(err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
node.error(RED._("common.notification.errors.no-response"), msg);
node.status({fill:"red", shape:"ring", text:"common.notification.errors.no-response"});
}else{
node.error(err,msg);
node.status({fill:"red", shape:"ring", text:err.code});
}
msg.payload = err.toString() + " : " + url;
msg.statusCode = err.code;
nodeSend(msg);
nodeDone();
}else{
msg.statusCode = res.statusCode;
msg.headers = res.headers;
msg.responseUrl = res.request.uri.href;
msg.payload = body;
msg.redirectList = redirectList;
got(url,opts).then(res => {
msg.statusCode = res.statusCode;
msg.headers = res.headers;
msg.responseUrl = res.url;
msg.payload = res.body;
msg.redirectList = redirectList;
msg.retry = 0;
if (msg.headers.hasOwnProperty('set-cookie')) {
msg.responseCookies = extractCookies(msg.headers['set-cookie']);
if (msg.headers.hasOwnProperty('set-cookie')) {
msg.responseCookies = extractCookies(msg.headers['set-cookie']);
}
msg.headers['x-node-red-request-node'] = hashSum(msg.headers);
// msg.url = url; // revert when warning above finally removed
if (node.metric()) {
// Calculate request time
var diff = process.hrtime(preRequestTimestamp);
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
var metricRequestDurationMillis = ms.toFixed(3);
node.metric("duration.millis", msg, metricRequestDurationMillis);
if (res.client && res.client.bytesRead) {
node.metric("size.bytes", msg, res.client.bytesRead);
}
msg.headers['x-node-red-request-node'] = hashSum(msg.headers);
// msg.url = url; // revert when warning above finally removed
if (node.metric()) {
// Calculate request time
var diff = process.hrtime(preRequestTimestamp);
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
var metricRequestDurationMillis = ms.toFixed(3);
node.metric("duration.millis", msg, metricRequestDurationMillis);
if (res.client && res.client.bytesRead) {
node.metric("size.bytes", msg, res.client.bytesRead);
}
}
}
// Convert the payload to the required return type
if (node.ret !== "bin") {
msg.payload = msg.payload.toString('utf8'); // txt
// Convert the payload to the required return type
if (node.ret !== "bin") {
msg.payload = msg.payload.toString('utf8'); // txt
if (node.ret === "obj") {
try { msg.payload = JSON.parse(msg.payload); } // obj
catch(e) { node.warn(RED._("httpin.errors.json-error")); }
}
if (node.ret === "obj") {
try { msg.payload = JSON.parse(msg.payload); } // obj
catch(e) { node.warn(RED._("httpin.errors.json-error")); }
}
node.status({});
nodeSend(msg);
nodeDone();
}
node.status({});
nodeSend(msg);
nodeDone();
}).catch(err => {
if(err.code === 'ETIMEDOUT' || err.code === 'ESOCKETTIMEDOUT') {
node.error(RED._("common.notification.errors.no-response"), msg);
node.status({fill:"red", shape:"ring", text:"common.notification.errors.no-response"});
}else{
node.error(err,msg);
node.status({fill:"red", shape:"ring", text:err.code});
}
msg.payload = err.toString() + " : " + url;
msg.statusCode = err.code || (err.response?err.response.statusCode:undefined);
nodeSend(msg);
nodeDone();
});

@@ -432,2 +481,67 @@ });

});
const md5 = (value) => { return crypto.createHash('md5').update(value).digest('hex') }
function ha1Compute(algorithm, user, realm, pass, nonce, cnonce) {
/**
* RFC 2617: handle both MD5 and MD5-sess algorithms.
*
* If the algorithm directive's value is "MD5" or unspecified, then HA1 is
* HA1=MD5(username:realm:password)
* If the algorithm directive's value is "MD5-sess", then HA1 is
* HA1=MD5(MD5(username:realm:password):nonce:cnonce)
*/
var ha1 = md5(user + ':' + realm + ':' + pass)
if (algorithm && algorithm.toLowerCase() === 'md5-sess') {
return md5(ha1 + ':' + nonce + ':' + cnonce)
} else {
return ha1
}
}
function buildDigestHeader(user, pass, method, path, authHeader) {
var challenge = {}
var re = /([a-z0-9_-]+)=(?:"([^"]+)"|([a-z0-9_-]+))/gi
for (;;) {
var match = re.exec(authHeader)
if (!match) {
break
}
challenge[match[1]] = match[2] || match[3]
}
var qop = /(^|,)\s*auth\s*($|,)/.test(challenge.qop) && 'auth'
var nc = qop && '00000001'
var cnonce = qop && uuid().replace(/-/g, '')
var ha1 = ha1Compute(challenge.algorithm, user, challenge.realm, pass, challenge.nonce, cnonce)
var ha2 = md5(method + ':' + path)
var digestResponse = qop
? md5(ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2)
: md5(ha1 + ':' + challenge.nonce + ':' + ha2)
var authValues = {
username: user,
realm: challenge.realm,
nonce: challenge.nonce,
uri: path,
qop: qop,
response: digestResponse,
nc: nc,
cnonce: cnonce,
algorithm: challenge.algorithm,
opaque: challenge.opaque
}
authHeader = []
for (var k in authValues) {
if (authValues[k]) {
if (k === 'qop' || k === 'nc' || k === 'algorithm') {
authHeader.push(k + '=' + authValues[k])
} else {
authHeader.push(k + '="' + authValues[k] + '"')
}
}
}
authHeader = 'Digest ' + authHeader.join(', ')
return authHeader
}
}

@@ -65,3 +65,3 @@ /**

if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); }
var noproxy = false;

@@ -73,3 +73,3 @@ if (noprox) {

}
var agent = undefined;

@@ -97,3 +97,3 @@ if (prox && !noproxy) {

function handleConnection(/*socket*/socket) {
var id = (1+Math.random()*4294967295).toString(16);
var id = RED.util.generateId();
if (node.isServer) {

@@ -100,0 +100,0 @@ node._clients[id] = socket;

@@ -72,3 +72,3 @@ /**

node.status({fill:"grey",shape:"dot",text:"common.status.connecting"});
var id = (1+Math.random()*4294967295).toString(16);
var id = RED.util.generateId();
client = net.connect(node.port, node.host, function() {

@@ -157,3 +157,3 @@ buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";

if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
var id = (1+Math.random()*4294967295).toString(16);
var id = RED.util.generateId();
var fromi;

@@ -160,0 +160,0 @@ var fromp;

@@ -206,3 +206,3 @@ /**

if (line[i-1] === node.sep || line[i-1].includes('\n','\r')) k[j] = null;
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j].trim()) ) { k[j] = parseFloat(k[j].trim()); }
if (node.include_null_values && k[j] === null) o[template[j]] = k[j];

@@ -222,3 +222,3 @@ if (node.include_empty_strings && k[j] === "") o[template[j]] = k[j];

if (line[i-1] === node.sep) k[j] = null;
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j].trim()) ) { k[j] = parseFloat(k[j].trim()); }
else { if (k[j] !== null) k[j].replace(/\r$/,''); }

@@ -247,3 +247,3 @@ if (node.include_null_values && k[j] === null) o[template[j]] = k[j];

if ( template[j] && (template[j] !== "") ) {
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j]) ) { k[j] = parseFloat(k[j]); }
if ( (k[j] !== null && node.parsestrings === true) && reg.test(k[j].trim()) ) { k[j] = parseFloat(k[j].trim()); }
else { if (k[j] !== null) k[j].replace(/\r$/,''); }

@@ -250,0 +250,0 @@ if (node.include_null_values && k[j] === null) o[template[j]] = k[j];

@@ -35,3 +35,3 @@ /**

try {
var $ = cheerio.load(value);
var $ = cheerio.load(value,null,false);
var pay = [];

@@ -46,5 +46,7 @@ var count = 0;

var pay2 = null;
if (node.ret === "html") { pay2 = cheerio.load($(this).html().trim()).xml(); }
if (node.ret === "html") { pay2 = cheerio.load($(this).html().trim(),null,false).xml(); }
if (node.ret === "text") { pay2 = $(this).text(); }
if (node.ret === "attr") { pay2 = this.attribs; }
if (node.ret === "attr") {
pay2 = Object.assign({},this.attribs);
}
//if (node.ret === "val") { pay2 = $(this).val(); }

@@ -66,5 +68,8 @@ /* istanbul ignore else */

if (node.as === "single") {
if (node.ret === "html") { pay.push( cheerio.load($(this).html().trim()).xml() ); }
if (node.ret === "html") { pay.push( cheerio.load($(this).html().trim(),null,false).xml() ); }
if (node.ret === "text") { pay.push( $(this).text() ); }
if (node.ret === "attr") { pay.push( this.attribs ); }
if (node.ret === "attr") {
var attribs = Object.assign({},this.attribs);
pay.push( attribs );
}
//if (node.ret === "val") { pay.push( $(this).val() ); }

@@ -71,0 +76,0 @@ }

@@ -20,4 +20,3 @@ /**

const Ajv = require('ajv');
const ajv = new Ajv({allErrors: true, schemaId: 'auto'});
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
const ajv = new Ajv({allErrors: true});
ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));

@@ -24,0 +23,0 @@

@@ -54,2 +54,6 @@ /**

var filename = node.filename || msg.filename || "";
var fullFilename = filename;
if (filename && RED.settings.fileWorkingDirectory && !path.isAbsolute(filename)) {
fullFilename = path.resolve(path.join(RED.settings.fileWorkingDirectory,filename));
}
if ((!node.filename) && (!node.tout)) {

@@ -65,5 +69,4 @@ node.tout = setTimeout(function() {

done();
}
else if (node.overwriteFile === "delete") {
fs.unlink(filename, function (err) {
} else if (node.overwriteFile === "delete") {
fs.unlink(fullFilename, function (err) {
if (err) {

@@ -80,5 +83,4 @@ node.error(RED._("file.errors.deletefail",{error:err.toString()}),msg);

});
}
else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) {
var dir = path.dirname(filename);
} else if (msg.hasOwnProperty("payload") && (typeof msg.payload !== "undefined")) {
var dir = path.dirname(fullFilename);
if (node.createDir) {

@@ -108,3 +110,3 @@ try {

if (node.overwriteFile === "true") {
var wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'w', autoClose:true });
var wstream = fs.createWriteStream(fullFilename, { encoding:'binary', flags:'w', autoClose:true });
node.wstream = wstream;

@@ -132,3 +134,3 @@ wstream.on("error", function(err) {

try {
var stat = fs.statSync(filename);
var stat = fs.statSync(fullFilename);
// File exists - check the inode matches

@@ -153,6 +155,6 @@ if (stat.ino !== node.wstreamIno) {

if (recreateStream) {
node.wstream = fs.createWriteStream(filename, { encoding:'binary', flags:'a', autoClose:true });
node.wstream = fs.createWriteStream(fullFilename, { encoding:'binary', flags:'a', autoClose:true });
node.wstream.on("open", function(fd) {
try {
var stat = fs.statSync(filename);
var stat = fs.statSync(fullFilename);
node.wstreamIno = stat.ino;

@@ -279,2 +281,6 @@ } catch(err) {

var filename = (node.filename || msg.filename || "").replace(/\t|\r|\n/g,'');
var fullFilename = filename;
if (filename && RED.settings.fileWorkingDirectory && !path.isAbsolute(filename)) {
fullFilename = path.resolve(path.join(RED.settings.fileWorkingDirectory,filename));
}
if (!node.filename) {

@@ -300,3 +306,3 @@ node.status({fill:"grey",shape:"dot",text:filename});

var rs = fs.createReadStream(filename)
var rs = fs.createReadStream(fullFilename)
.on('readable', function () {

@@ -303,0 +309,0 @@ var chunk;

@@ -26,5 +26,9 @@ /**

fs.readdirSync(dir).forEach(file => {
if (fs.statSync(path.join(dir, file)).isDirectory() ) {
filelist.push(path.join(dir, file));
getAllDirs(path.join(dir, file), filelist);
try {
if (fs.statSync(path.join(dir, file)).isDirectory() ) {
filelist.push(path.join(dir, file));
getAllDirs(path.join(dir, file), filelist);
}
} catch (error) {
//should we raise an error?
}

@@ -31,0 +35,0 @@ });

@@ -1003,3 +1003,30 @@ {

"no-parts": "Keine parts-Eigenschaft in Nachricht"
},
"rbe": {
"rbe": "filter",
"label": {
"func": "Modus",
"init": "Sende Anfangswert",
"start": "Startwert",
"name": "Name",
"septopics": "Modus für jedes msg.topic separat anwenden"
},
"placeholder":{
"bandgap": "z.B. 10 oder 5%",
"start": "Leer lassen, um erste empfangenen Daten zu nutzen"
},
"opts": {
"rbe": "Blockieren bis Wertänderung",
"rbei": "Blockieren bis Wertänderung (Anfangswert ignorieren)",
"deadband": "Blockieren bis Wertänderung ist größer als",
"deadbandEq": "Blockieren bis Wertänderung ist größer-gleich",
"narrowband": "Blockieren wenn Wertänderung ist größer als",
"narrowbandEq": "Blockieren wenn Wertänderung ist größer-gleich",
"in": "verglichen mit letzten Eingangswert",
"out": "verglichen mit letzten gültigen Ausgangswert"
},
"warn": {
"nonumber": "Keine Zahl gefunden in den Nutzdaten (Payload)"
}
}
}

@@ -35,2 +35,3 @@ {

"inject": "inject",
"injectNow": "inject now",
"repeat": "repeat = __repeat__",

@@ -174,3 +175,4 @@ "crontab": "crontab = __crontab__",

"verify-server-cert":"Verify server certificate",
"servername": "Server Name"
"servername": "Server Name",
"alpnprotocol": "ALPN Protocol"
},

@@ -182,3 +184,4 @@ "placeholder": {

"passphrase":"private key passphrase (optional)",
"servername":"for use with SNI"
"servername":"for use with SNI",
"alpnprotocol":"for use with ALPN"
},

@@ -283,2 +286,3 @@ "error": {

"dropmsg": "drop intermediate messages",
"allowrate": "allow msg.rate (in ms) to override rate",
"label": {

@@ -309,5 +313,4 @@ "delay": "delay",

},
"error": {
"buffer": "buffer exceeded 1000 messages",
"buffer1": "buffer exceeded 10000 messages"
"errors": {
"too-many" : "too many pending messages in delay node"
}

@@ -1011,3 +1014,30 @@ },

"no-parts" : "no parts property in message"
},
"rbe": {
"rbe": "filter",
"label": {
"func": "Mode",
"init": "Send initial value",
"start": "Start value",
"name": "Name",
"septopics": "Apply mode separately for each "
},
"placeholder":{
"bandgap": "e.g. 10 or 5%",
"start": "leave blank to use first data received"
},
"opts": {
"rbe": "block unless value changes",
"rbei": "block unless value changes (ignore initial value)",
"deadband": "block unless value change is greater than",
"deadbandEq": "block unless value change is greater or equal to",
"narrowband": "block if value change is greater than",
"narrowbandEq": "block if value change is greater or equal to",
"in": "compared to last input value",
"out": "compared to last valid output value"
},
"warn": {
"nonumber": "no number found in payload"
}
}
}

@@ -280,2 +280,3 @@ {

"dropmsg": "中間メッセージを削除",
"allowrate": "msg.rate(ミリ秒単位)で流量値を上書き",
"label": {

@@ -306,5 +307,4 @@ "delay": "delay",

},
"error": {
"buffer": "バッファ上限の1000メッセージを超えました",
"buffer1": "バッファ上限の10000メッセージを超えました"
"errors": {
"too-many": "delayノード内で保持しているメッセージが多すぎます"
}

@@ -1006,3 +1006,28 @@ },

"no-parts": "メッセージにpartsプロパティがありません"
},
"rbe": {
"label": {
"func": "動作",
"init": "初期値を送付",
"start": "初期値",
"name": "名前"
},
"placeholder": {
"bandgap": "例:10、5%",
"start": "最初に受け取った値を用いる場合は空欄"
},
"opts": {
"rbe": "値が変化した時のみメッセージを中継",
"rbei": "値が変化した時のみメッセージを中継(初期値を無視)",
"deadband": "値が指定した変化量を超える時のみメッセージを中継",
"deadbandEq": "値が指定した変化量以上の時のみメッセージを中継",
"narrowband": "値が指定した変化量を超えない時のみメッセージを中継",
"narrowbandEq": "値が指定した変化量以上でない時のみメッセージを中継",
"in": "最後の入力値と比較",
"out": "最後の出力値と比較"
},
"warn": {
"nonumber": "ペイロードに数値が含まれていません"
}
}
}

@@ -275,6 +275,2 @@ {

}
},
"error": {
"buffer": "버퍼 상한의 1000메세지를 넘었습니다",
"buffer1": "버퍼 상한의 10000메세지를 넘었습니다"
}

@@ -281,0 +277,0 @@ },

@@ -293,6 +293,2 @@ {

}
},
"error": {
"buffer": "缓冲了超过 1000 条信息",
"buffer1": "缓冲了超过 10000 条信息"
}

@@ -299,0 +295,0 @@ },

{
"name": "@node-red/nodes",
"version": "1.3.5",
"version": "2.0.0-beta.1",
"license": "Apache-2.0",

@@ -18,5 +18,7 @@ "repository": {

"dependencies": {
"ajv": "6.12.6",
"acorn": "8.3.0",
"acorn-walk": "8.1.0",
"ajv": "8.6.0",
"body-parser": "1.19.0",
"cheerio": "0.22.0",
"cheerio": "1.0.0-rc.10",
"content-type": "1.0.4",

@@ -26,7 +28,10 @@ "cookie-parser": "1.4.5",

"cors": "2.8.5",
"cron": "1.7.2",
"cronosjs": "1.7.1",
"denque": "1.5.0",
"fs-extra": "8.1.0",
"form-data": "4.0.0",
"fs-extra": "10.0.0",
"fs.notify": "0.0.4",
"got": "11.8.2",
"hash-sum": "2.0.0",
"hpagent": "0.1.1",
"https-proxy-agent": "5.0.0",

@@ -42,6 +47,8 @@ "is-utf8": "0.2.1",

"request": "2.88.0",
"ws": "6.2.1",
"tough-cookie": "4.0.0",
"uuid": "8.3.2",
"ws": "7.4.6",
"xml2js": "0.4.23",
"iconv-lite": "0.6.2"
"iconv-lite": "0.6.3"
}
}

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc