Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-red-viseo-helper

Package Overview
Dependencies
Maintainers
3
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-viseo-helper - npm Package Compare versions

Comparing version 0.2.0-alpha.3 to 0.2.0-alpha.6

0

CODE_OF_CONDUCT.md

@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct

@@ -0,0 +0,0 @@ # Contributing to the Project

129

index.js
'use strict';
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const fs = require('fs');
const path = require('path');
const vm = require('vm');
const rp = require('request-promise');
const EventEmitter = require('events');

@@ -110,2 +111,33 @@

const setContextValue = exports.setContextValue = (RED, node, data, str, value, type) => {
try {
if (type === "msg") {
RED.util.setMessageProperty(data,str,value);
return true;
}
else if (type === 'global' || type === 'flow') {
let contextKey = RED.util.parseContextStore(str);
let target = node.context()[type];
target.set(contextKey.key, value, contextKey.store, null);
return true;
}
return false;
}
catch(err) {
error(err);
return false;
}
}
const getContextValue = exports.getContextValue = (RED, node, data, str, type) => {
try {
let value = RED.util.evaluateNodeProperty(str, type, node, data, null);
return value;
}
catch(err) {
error(err);
return null;
}
}
const resolve = exports.resolve = (str, obj, def) => {

@@ -198,2 +230,93 @@ if (str === undefined) return str;

callback(data);
}
// ------------------------------------------
// TRACKING
// ------------------------------------------
let activities = {};
exports.trackActivities = async function trackActivities(node) {
function unauth() {
node.status({fill:"red", shape:"ring", text: 'Missing VISEO Bot Maker key'});
node.error("Missing VISEO Bot Maker key - Read the documentation.")
return false;
}
let conf = CONFIG || global.CONFIG;
let key = conf.key || '';
let time = Date.now();
if (!key) return unauth();
// First pass : set start time
if (!activities.info) {
activities = {
info : {
start : time,
key : key
}
};
}
else if (time - activities.info.start > 1000 ){ // 24h : 24 * 3600 * 1000 = 86400000
try {
node.warn(activities)
await sendActivities(activities);
} catch(err) {
if (err.statusCode === 401) return unauth();
return true;
}
activities = {
info : {
start : time,
key : key
}
};
}
else {
// set the last time
activities.info.end = time;
}
if (!activities[node.type]) {
activities[node.type] = {
"type": node.type,
"start": time,
"nodes": [],
"calls": 0
}
}
if (activities[node.type].nodes.indexOf(node.id) === -1) {
activities[node.type].nodes.push(node.id);
}
activities[node.type].calls += 1;
activities[node.type].end = time;
activities.info.end = time;
return true;
}
async function sendActivities(obj) {
let body = {
info: obj.info,
data: []
}
for (let key in obj) {
if (key === 'info') continue;
obj[key].nodes = obj[key].nodes.length;
body.data.push(obj[key]);
}
// send data
let request = {
url: "https://nodedatafunction.azurewebsites.net/api/sendActivities?code=rriqcWx/cCsUQ0oxcVqTTaxsXWj5gf2AOCqhSayw8vaGaQKf6SgaQw==",
resolveWithFullResponse: true,
method: "post",
json: true,
body: body
}
console.log(request)
return rp(request);
}

@@ -0,0 +0,0 @@ const extend = require('extend');

2

package.json
{
"name" : "node-red-viseo-helper",
"version" : "0.2.0-alpha.3",
"version" : "0.2.0-alpha.6",
"description" : "Utility libarary for Node-RED",

@@ -5,0 +5,0 @@ "dependencies" : {

@@ -0,0 +0,0 @@ # Node-RED

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