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

node-red-contrib-agilite

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-agilite - npm Package Compare versions

Comparing version 5.4.0 to 5.4.1

adhoc/adhoc.html

14

configuration/agilite-login.js

@@ -1,2 +0,2 @@

module.exports = function(RED) {
module.exports = function (RED) {
function AgiliteLogin(config) {

@@ -12,5 +12,9 @@ RED.nodes.createNode(this, config);

RED.nodes.registerType("agilite-login", AgiliteLogin,{
credentials: {apiKey: {type:"password"}}
});
}
RED.nodes.registerType("agilite-login", AgiliteLogin, {
credentials: {
apiKey: {
type: "password"
}
}
});
}

@@ -1,145 +0,214 @@

module.exports = function(RED) {
function IoEConnectors(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function IoEConnectors(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var routeKey = "";
var data = null;
var url = "";
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if there's valid data to pass
if(msg.payload){
data = msg.payload;
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
//Check if we need to use a profile and route key passed to this node
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
return result;
};
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var routeKey = "";
var data = null;
var url = "";
var logProcessId = null;
var failFlow = config.failFlow;
if(msg.agilite.connectors){
if(msg.agilite.connectors.profileKey){
if(msg.agilite.connectors.profileKey !== ""){
profileKey = msg.agilite.connectors.profileKey;
url = serverConfig.server;
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
data = msg.payload;
//Check if we need to use a profile and route key passed to this node
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
if (msg.agilite.connectors) {
if (msg.agilite.connectors.profileKey) {
if (msg.agilite.connectors.profileKey !== "") {
profileKey = msg.agilite.connectors.profileKey;
}
}
if (msg.agilite.connectors.routeKey) {
if (msg.agilite.connectors.routeKey !== "") {
routeKey = msg.agilite.connectors.routeKey;
}
}
}
}
}
if(msg.agilite.connectors.routeKey){
if(msg.agilite.connectors.routeKey !== ""){
routeKey = msg.agilite.connectors.routeKey;
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
}
}
}
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
if (profileKey === "") {
profileKey = config.profileKey;
}
if(profileKey === ""){
profileKey = config.profileKey;
}
if (routeKey === "") {
routeKey = config.routeKey;
}
if(routeKey === ""){
routeKey = config.routeKey;
}
//We need a token, keys and data to proceed
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else if (profileKey === "") {
success = false;
errorMessage = "No Profile Key Provided";
} else if (routeKey === "") {
success = false;
errorMessage = "No Route Key Provided";
}
//We need a token, keys and data to proceed
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else if(profileKey === ""){
success = false;
errorMessage = "No Profile Key Provided";
}else if(routeKey === ""){
success = false;
errorMessage = "No Route Key Provided";
}
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite) {
msg.agilite = {};
}
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
//Perform a HTTP Post to Agilit-e for Data Mapping, passing the body content
var axios = require("axios");
url = url + "/connectors/execute";
//Perform a HTTP Post to Agilit-e for Data Mapping, passing the body content
var axios = require("axios");
url = url + "/connectors/execute";
var headers = {
headers: {
"api-key": apiKey,
"profile-key": profileKey,
"route-key": routeKey,
"Content-Type": "application/json"
}
};
var headers = {
headers: {"api-key": apiKey, "profile-key": profileKey, "route-key": routeKey, "Content-Type":"application/json"}
};
//Check if we need to pass a Log Process Id
if (logProcessId) {
headers.headers["log-process-id"] = logProcessId;
}
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
}
}else{
msg.payload = "";
}
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
node.send(msg);
})
.catch(function (error) {
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
node.send(msg);
});
});
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
RED.nodes.registerType("connectors", IoEConnectors);
}
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
});
}
RED.nodes.registerType("connectors", IoEConnectors);
}

@@ -1,135 +0,197 @@

module.exports = function(RED) {
function DataMapping(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function DataMapping(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var data = {};
var url = "";
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if there's valid data to pass
if(msg.payload){
data = msg.payload;
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
return result;
};
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var data = {};
var url = "";
var logProcessId = null;
var failFlow = config.failFlow;
if(msg.agilite.dataMapping){
if(msg.agilite.dataMapping.profileKey){
if(msg.agilite.dataMapping.profileKey !== ""){
profileKey = msg.agilite.dataMapping.profileKey;
url = serverConfig.server;
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
data = msg.payload;
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
if (msg.agilite.dataMapping) {
if (msg.agilite.dataMapping.profileKey) {
if (msg.agilite.dataMapping.profileKey !== "") {
profileKey = msg.agilite.dataMapping.profileKey;
}
}
}
}
}
}
}
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
if(profileKey === ""){
profileKey = config.profileKey;
}
if (profileKey === "") {
profileKey = config.profileKey;
}
//We need an apiKey, profileKey and data to proceed
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else if(profileKey === ""){
success = false;
errorMessage = "No Valid Profile Key Provided - " + profileKey;
}
//We need an apiKey, profileKey and data to proceed
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else if (profileKey === "") {
success = false;
errorMessage = "No Valid Profile Key Provided - " + profileKey;
}
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite) {
msg.agilite = {};
}
//Perform a HTTP Post to Agilit-e for Data Mapping, passing the body content
var axios = require("axios");
url = url + "/datamappings/execute";
//Perform a HTTP Post to Agilit-e for Data Mapping, passing the body content
var axios = require("axios");
url = url + "/datamappings/execute";
var headers = {
headers: {"api-key": apiKey, "profile-key": profileKey, "Content-Type":"application/json"}
};
var headers = {
headers: {
"api-key": apiKey,
"profile-key": profileKey,
"Content-Type": "application/json"
}
};
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
//Check if we need to pass a Log Process Id
if (logProcessId)
headers.headers["log-process-id"] = logProcessId;
node.status({ fill: "yellow", text: "Running", shape: "ring" });
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
}
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
}else{
msg.payload = "";
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
node.status({ fill: "green", text: "Success", shape: "ring" });
node.send(msg);
})
.catch(function (error) {
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
node.status({ fill: "red", text: "Error", shape: "ring" });
node.send(msg);
});
});
}
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
RED.nodes.registerType("data-mapping", DataMapping);
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
});
}
RED.nodes.registerType("data-mapping", DataMapping);
}

@@ -1,173 +0,308 @@

module.exports = function(RED) {
function Files(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function Files(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var actionType = "";
var recordId = "";
var url = "";
var requestType = "";
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
return result;
};
if(msg.agilite.files){
if(msg.agilite.files.recordId){
if(msg.agilite.files.recordId !== ""){
recordId = msg.agilite.files.recordId;
}
}
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var actionType = "";
var recordId = "";
var data = {};
var url = "";
var requestType = "";
var logProcessId = null;
var failFlow = config.failFlow;
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
url = serverConfig.server;
if(recordId === ""){
recordId = config.recordId;
}
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
//Validate Values
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else if(recordId === ""){
success = false;
errorMessage = "No Record Id Provided";
}
data = msg.payload;
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
requestType = "get";
if (msg.agilite.files) {
if (msg.agilite.files.recordId) {
if (msg.agilite.files.recordId !== "") {
recordId = msg.agilite.files.recordId;
}
}
}
}
var headers = {
headers: {"api-key": apiKey, "record-id": recordId, "Content-Type":"application/json"}
};
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
switch(config.actionType){
case "1"://Get File
url = url + "/files";
headers.headers["responseType"] = "arraybuffer";
break;
case "2"://Get File Name
url = url + "/files/getFileName";
break;
case "3"://Delete File
url = url + "/files";
requestType = "delete"
break;
}
if (recordId === "") {
recordId = config.recordId;
}
switch (requestType) {
case "get":
axios.get(url, headers)
.then(function(response){
if(config.actionType === "1"){
msg.agilite.success = true;
msg.agilite.messages = [];
msg.payload = response.data;
}else{
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
//Validate Values
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else if (recordId === "") {
success = false;
errorMessage = "No Record Id Provided";
}
if(response.data.success){
msg.payload = response.data.data;
}else{
msg.payload = "";
}
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite) {
msg.agilite = {};
}
node.send(msg);
});
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
requestType = "get";
break;
case "delete":
axios.delete(url, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
var headers = {
headers: {
"api-key": apiKey,
"record-id": recordId,
"Content-Type": "application/json"
}
};
if(response.data.success){
msg.payload = response.data.data;
}else{
msg.payload = "";
}
//Check if we need to pass a Log Process Id
if (logProcessId)
headers.headers["log-process-id"] = logProcessId;
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
switch (config.actionType) {
case "1": //Get File
url = url + "/files";
headers.headers["responseType"] = "arraybuffer";
break;
case "2": //Get File Name
url = url + "/files/getFileName";
break;
case "3": //Delete File
url = url + "/files";
requestType = "delete"
break;
}
node.send(msg);
});
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
break;
default:
switch (requestType) {
case "get":
axios.get(url, headers)
.then(function (response) {
if (config.actionType === "1") {
msg.agilite.success = true;
msg.agilite.messages = [];
}
});
}
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data);
break;
case "flow":
node.context().flow.set(node.field, response.data);
break;
case "global":
node.context().global.set(node.field, response.data);
break;
}
RED.nodes.registerType("files", Files);
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
} else {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
break;
case "delete":
axios.delete(url, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
break;
}
});
}
RED.nodes.registerType("files", Files);
}

@@ -1,329 +0,466 @@

module.exports = function(RED) {
function Keywords(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function Keywords(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var actionType = "";
var recordId = "";
var profileKey = "";
var groupName = "";
var labelKey = "";
var valueKey = "";
var sortBy = "";
var url = "";
var requestType = "";
var data = {};
var postData = {};
var tempData = {};
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if there's valid data to pass
if(msg.payload){
data = msg.payload;
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
return result;
};
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var recordId = "";
var profileKey = "";
var groupName = "";
var labelKey = "";
var valueKey = "";
var sortBy = "";
var url = "";
var requestType = "";
var data = {};
var logProcessId = null;
var failFlow = config.failFlow;
if(msg.agilite.keywords){
if(msg.agilite.keywords.recordId){
if(msg.agilite.keywords.recordId !== ""){
recordId = msg.agilite.keywords.recordId;
url = serverConfig.server;
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
data = msg.payload;
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
if (msg.agilite.keywords) {
if (msg.agilite.keywords.recordId) {
if (msg.agilite.keywords.recordId !== "") {
recordId = msg.agilite.keywords.recordId;
}
}
if (msg.agilite.keywords.profileKey) {
if (msg.agilite.keywords.profileKey !== "") {
profileKey = msg.agilite.keywords.profileKey;
}
}
if (msg.agilite.keywords.groupName) {
if (msg.agilite.keywords.groupName !== "") {
groupName = msg.agilite.keywords.groupName;
}
}
if (msg.agilite.keywords.labelKey) {
if (msg.agilite.keywords.labelKey !== "") {
labelKey = msg.agilite.keywords.labelKey;
}
}
if (msg.agilite.keywords.valueKey) {
if (msg.agilite.keywords.valueKey !== "") {
valueKey = msg.agilite.keywords.valueKey;
}
}
if (msg.agilite.keywords.sortBy) {
if (msg.agilite.keywords.sortBy !== "") {
sortBy = msg.agilite.keywords.sortBy;
}
}
}
}
}
if(msg.agilite.keywords.profileKey){
if(msg.agilite.keywords.profileKey !== ""){
profileKey = msg.agilite.keywords.profileKey;
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
}
if(msg.agilite.keywords.groupName){
if(msg.agilite.keywords.groupName !== ""){
groupName = msg.agilite.keywords.groupName;
if (recordId === "") {
recordId = config.recordId;
}
}
if(msg.agilite.keywords.labelKey){
if(msg.agilite.keywords.labelKey !== ""){
labelKey = msg.agilite.keywords.labelKey;
if (profileKey === "") {
profileKey = config.profileKey;
}
}
if(msg.agilite.keywords.valueKey){
if(msg.agilite.keywords.valueKey !== ""){
valueKey = msg.agilite.keywords.valueKey;
if (groupName === "") {
groupName = config.groupName;
}
}
if(msg.agilite.keywords.sortBy){
if(msg.agilite.keywords.sortBy !== ""){
sortBy = msg.agilite.keywords.sortBy;
if (labelKey === "") {
labelKey = config.labelKey;
}
}
}
}
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
if (valueKey === "") {
valueKey = config.valueKey;
}
if(recordId === ""){
recordId = config.recordId;
}
if (sortBy === "") {
sortBy = config.sortBy;
}
if(profileKey === ""){
profileKey = config.profileKey;
}
//We need a apiKey, key and data to proceed
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else {
switch (config.actionType) {
case "1": //Get Keywords By Profile Key
if (profileKey === "") {
success = false;
errorMessage = "No Profile Key found";
}
if(groupName === ""){
groupName = config.groupName;
}
break;
case "2": //Get Profile Keys By Group
if (groupName === "") {
success = false;
errorMessage = "No Group Name found";
}
if(labelKey === ""){
labelKey = config.labelKey;
}
break;
case "3": //Get Keyword Value by Label
if (profileKey === "") {
success = false;
errorMessage = "No Profile Key found";
} else if (labelKey === "") {
success = false;
errorMessage = "No Label Key found";
}
if(valueKey === ""){
valueKey = config.valueKey;
}
break;
case "4": //Get Keyword Label by Value
if (profileKey === "") {
success = false;
errorMessage = "No Profile Key found";
} else if (valueKey === "") {
success = false;
errorMessage = "No Value Key found";
}
if(sortBy === ""){
sortBy = config.sortBy;
}
break;
case "6": //Update Keyword Record
case "7": //Get Keyword Record By Id
if (recordId === "") {
success = false;
errorMessage = "No Record Id found";
}
//We need a apiKey, key and data to proceed
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else{
switch(config.actionType){
case "1"://Get Keywords By Profile Key
if(profileKey === ""){
success = false;
errorMessage = "No Profile Key found";
break;
}
}
break;
case "2"://Get Profile Keys By Group
if(groupName === ""){
success = false;
errorMessage = "No Group Name found";
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
break;
case "3"://Get Keyword Value by Label
if(profileKey === ""){
success = false;
errorMessage = "No Profile Key found";
}else if(labelKey === ""){
success = false;
errorMessage = "No Label Key found";
}
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite)
msg.agilite = {};
break;
case "4"://Get Keyword Label by Value
if(profileKey === ""){
success = false;
errorMessage = "No Profile Key found";
}else if(valueKey === ""){
success = false;
errorMessage = "No Value Key found";
}
//Perform a HTTP Post to Agilit-e, passing the body content
var axios = require("axios");
requestType = "get";
break;
case "6"://Update Keyword Record
case "7"://Get Keyword Record By Id
if(recordId === ""){
success = false;
errorMessage = "No Record Id found";
var headers = {
headers: {
"api-key": apiKey,
"Content-Type": "application/json"
}
};
//Check if we need to pass a Log Process Id
if (logProcessId)
headers.headers["log-process-id"] = logProcessId;
switch (config.actionType) {
case "1": //Get Keywords By Profile Key
url = url + "/keywords/getByProfileKey";
headers.headers["profile-key"] = profileKey;
break;
case "2": //Get Profile Keys By Group
url = url + "/keywords/getProfileKeysByGroup";
headers.headers["group-name"] = groupName;
break;
case "3": //Get Keyword Value by Label
url = url + "/keywords/getValueByLabel";
headers.headers["profile-key"] = profileKey;
headers.headers["label-key"] = labelKey;
break;
case "4": //Get Keyword Label by Value
url = url + "/keywords/getLabelByValue";
headers.headers["profile-key"] = profileKey;
headers.headers["value-key"] = valueKey;
break;
case "7": //Get Keyword Record By Id
url = url + "/keywords/data/getById";
headers.headers["record-id"] = recordId;
break;
case "5": //Create Keyword Record
url = url + "/keywords/data";
requestType = "post";
break;
case "6": //Update Keyword Record
url = url + "/keywords/data";
headers.headers["record-id"] = recordId;
requestType = "put";
break;
}
break;
}
}
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
switch (requestType) {
case "get":
axios.get(url, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
//Perform a HTTP Post to Agilit-e, passing the body content
var axios = require("axios");
requestType = "get";
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
var headers = {
headers: {"api-key": apiKey,"Content-Type":"application/json"}
};
node.send(msg);
} else {
msg.payload = {};
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
switch(config.actionType){
case "1"://Get Keywords By Profile Key
url = url + "/keywords/getByProfileKey";
headers.headers["profile-key"] = profileKey;
break;
case "2"://Get Profile Keys By Group
url = url + "/keywords/getProfileKeysByGroup";
headers.headers["group-name"] = groupName;
break;
case "3"://Get Keyword Value by Label
url = url + "/keywords/getValueByLabel";
headers.headers["profile-key"] = profileKey;
headers.headers["label-key"] = labelKey;
break;
case "4"://Get Keyword Label by Value
url = url + "/keywords/getLabelByValue";
headers.headers["profile-key"] = profileKey;
headers.headers["value-key"] = valueKey;
break;
case "7"://Get Keyword Record By Id
url = url + "/keywords/data/getById";
headers.headers["record-id"] = recordId;
break;
case "5"://Create Keyword Record
url = url + "/keywords/data";
requestType = "post";
break;
case "6"://Update Keyword Record
url = url + "/keywords/data";
headers.headers["record-id"] = recordId;
requestType = "put";
break;
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
switch (requestType) {
case "get":
axios.get(url, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
}
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
}else{
msg.payload = "";
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
break;
case "post":
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
node.send(msg);
});
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
break;
case "post":
axios.post(url, data, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
if(response.data.success){
msg.payload = response.data.data;
}else{
msg.payload = "";
}
node.send(msg);
} else {
msg.payload = {};
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
node.send(msg);
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
break;
case "put":
axios.put(url, data, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if(response.data.success){
msg.payload = response.data.data;
}else{
msg.payload = "";
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
break;
case "put":
axios.put(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
node.send(msg);
});
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
break;
}
});
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
RED.nodes.registerType("keywords", Keywords);
}
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
break;
}
});
}
RED.nodes.registerType("keywords", Keywords);
}

@@ -1,143 +0,227 @@

module.exports = function(RED) {
function Logs(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function Logs(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var actionType = "";
var profileKey = "";
var recordId = "";
var url = "";
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
if(msg.agilite.logs){
if(msg.agilite.logs.profileKey){
if(msg.agilite.logs.profileKey !== ""){
profileKey = msg.agilite.logs.profileKey;
return result;
};
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var recordId = "";
var url = "";
var failFlow = config.failFlow;
url = serverConfig.server;
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
data = msg.payload;
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
if (msg.agilite.logs) {
if (msg.agilite.logs.profileKey) {
if (msg.agilite.logs.profileKey !== "") {
profileKey = msg.agilite.logs.profileKey;
}
}
if (msg.agilite.logs.recordId) {
if (msg.agilite.logs.recordId !== "") {
recordId = msg.agilite.logs.recordId;
}
}
}
}
}
if(msg.agilite.logs.recordId){
if(msg.agilite.logs.recordId !== ""){
recordId = msg.agilite.logs.recordId;
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
}
}
}
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
if (profileKey === "") {
profileKey = config.profileKey;
}
if(profileKey === ""){
profileKey = config.profileKey;
}
if (recordId === "") {
recordId = config.recordId;
}
if(recordId === ""){
recordId = config.recordId;
}
//Validate Values
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else {
switch (config.actionType) {
case "1": //Create Batch Log Process
if (profileKey === "") {
success = false;
errorMessage = "No Profile Key Provided";
}
//Validate Values
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else{
switch(config.actionType){
case "1"://Create Batch Log Process
if(profileKey === ""){
success = false;
errorMessage = "No Profile Key Provided";
break;
case "2": //Get Log Batch Process
if (recordId === "") {
success = false;
errorMessage = "No Record Id Provided";
}
break;
}
}
break;
case "2"://Get Log Batch Process
if(recordId === ""){
success = false;
errorMessage = "No Record Id Provided";
if (!success) {
node.error(errorMessage, msg);
return false;
}
break;
}
}
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
if(!success){
node.error(errorMessage, msg);
return false;
}
var headers = {
headers: {
"api-key": apiKey,
"Content-Type": "application/json"
}
};
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite)
msg.agilite = {};
var headers = {
headers: {"api-key": apiKey, "Content-Type":"application/json"}
};
switch (config.actionType) {
case "1": //Create Batch Log Process
url = url + "/logs/batch/createProcess";
headers.headers["profile-key"] = profileKey;
break;
case "2": //Get Log Batch Process
url = url + "/logs/batch/getProcessLogs";
headers.headers["record-id"] = recordId;
break;
}
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
switch(config.actionType){
case "1"://Create Batch Log Process
url = url + "/logs/batch/createProcess";
headers.headers["profile-key"] = profileKey;
break;
case "2"://Get Log Batch Process
url = url + "/logs/batch/getProcessLogs";
headers.headers["record-id"] = recordId;
break;
}
axios.get(url, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
axios.get(url, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (response.data.success) {
msg.payload = response.data.data;
if(response.data.success){
msg.payload = response.data.data;
}else{
msg.payload = "";
}
//Automatically add Log Process Id to msg.agilite.logProcessId
if (config.actionType === "1") {
msg.agilite.logProcessId = response.data.data._id;
}
//Automatically add Log Process Id to msg.agilite.logProcessId
if(config.actionType === "1"){
msg.agilite.logProcessId = response.data.data._id;
}
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
});
});
}
node.send(msg);
} else {
msg.payload = {};
RED.nodes.registerType("logs", Logs);
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
});
}
RED.nodes.registerType("logs", Logs);
}

@@ -1,133 +0,199 @@

module.exports = function(RED) {
function Numbering(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function Numbering(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var url = "";
var data = {};
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if there's valid data to pass
if(msg.payload){
data = msg.payload;
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
return result;
};
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var url = "";
var data = {};
var logProcessId = null;
var failFlow = config.failFlow;
if(msg.agilite.numbering){
if(msg.agilite.numbering.profileKey){
if(msg.agilite.numbering.profileKey !== ""){
profileKey = msg.agilite.numbering.profileKey;
}
}
}
}
url = serverConfig.server;
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
if(profileKey === ""){
profileKey = config.profileKey;
}
data = msg.payload;
//We need an apiKey, profileKey and data to proceed
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else if(profileKey === ""){
success = false;
errorMessage = "No Profile Key Provided";
}
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
if (msg.agilite.numbering) {
if (msg.agilite.numbering.profileKey) {
if (msg.agilite.numbering.profileKey !== "") {
profileKey = msg.agilite.numbering.profileKey;
}
}
}
}
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
url = url + "/numbering/generate";
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
var headers = {
headers: {"api-key": apiKey, "profile-key": profileKey, "Content-Type":"application/json"}
};
if (profileKey === "") {
profileKey = config.profileKey;
}
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
//We need an apiKey, profileKey and data to proceed
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else if (profileKey === "") {
success = false;
errorMessage = "No Profile Key Provided";
}
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
}else{
msg.payload = "";
}
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite)
msg.agilite = {};
node.send(msg);
})
.catch(function (error) {
console.log(error);
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
url = url + "/numbering/generate";
node.send(msg);
});
});
}
var headers = {
headers: {
"api-key": apiKey,
"profile-key": profileKey,
"Content-Type": "application/json"
}
};
RED.nodes.registerType("numbering", Numbering);
}
//Check if we need to pass a Log Process Id
if (logProcessId)
headers.headers["log-process-id"] = logProcessId;
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
});
}
RED.nodes.registerType("numbering", Numbering);
}
{
"name": "node-red-contrib-agilite",
"license": "MIT",
"version": "5.4.0",
"version": "5.4.1",
"description": "Node-RED nodes to integrate with Agilit-e cloud or Agilit-e on-prem",
"homepage": "https://portal.agilite.io",
"homepage": "https://portal.agilite.io",
"author": "Agilit-e",
"contributors": [
{
"name": "John Jardin",
"email": "support@agilite.io",
"url": "https://agilite.io"
},
{
"name": "Armand Smit",
"email": "support@agilite.io",
"url": "https://agilite.io"
}
],
"dependencies": {

@@ -35,3 +48,3 @@ "axios": "0.18.0"

"Files": "files/files.js",
"Utilities": "utilities/utilities.js",
"Adhoc": "adhoc/adhoc.js",
"Logs": "logs/logs.js"

@@ -38,0 +51,0 @@ }

@@ -1,317 +0,406 @@

module.exports = function(RED) {
function Roles(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function Roles(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var actionType = "";
var roleName = "";
var conditionalLevels = "";
var processKey = "";
var bpmRecordId = "";
var currentUser = "";
var responsibleUsers = "";
var includeHidden = "";
var url = "";
var requestType = "";
var data = {};
var postData = {};
var tempData = {};
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if there's valid data to pass
if(msg.payload){
data = msg.payload;
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
return result;
};
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var roleName = "";
var conditionalLevels = "";
var processKey = "";
var bpmRecordId = "";
var currentUser = "";
var responsibleUsers = "";
var includeHidden = "";
var url = "";
var requestType = "";
var data = {};
var logProcessId = null;
var failFlow = config.failFlow;
if(msg.agilite.roles){
if(msg.agilite.roles.roleName){
if(msg.agilite.roles.roleName !== ""){
roleName = msg.agilite.roles.roleName;
url = serverConfig.server;
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
data = msg.payload;
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
if (msg.agilite.roles) {
if (msg.agilite.roles.roleName) {
if (msg.agilite.roles.roleName !== "") {
roleName = msg.agilite.roles.roleName;
}
}
if (msg.agilite.roles.conditionalLevels) {
if (msg.agilite.roles.conditionalLevels !== "") {
conditionalLevels = msg.agilite.roles.conditionalLevels;
}
}
if (msg.agilite.roles.processKey) {
if (msg.agilite.roles.processKey !== "") {
processKey = msg.agilite.roles.processKey;
}
}
if (msg.agilite.roles.bpmRecordId) {
if (msg.agilite.roles.bpmRecordId !== "") {
bpmRecordId = msg.agilite.roles.bpmRecordId;
}
}
if (msg.agilite.roles.currentUser) {
if (msg.agilite.roles.currentUser !== "") {
currentUser = msg.agilite.roles.currentUser;
}
}
if (msg.agilite.roles.responsibleUsers) {
if (msg.agilite.roles.responsibleUsers !== "") {
responsibleUsers = msg.agilite.roles.responsibleUsers;
}
}
if (msg.agilite.roles.includeHidden) {
if (msg.agilite.roles.includeHidden !== "") {
includeHidden = msg.agilite.roles.includeHidden;
}
}
}
}
}
if(msg.agilite.roles.conditionalLevels){
if(msg.agilite.roles.conditionalLevels !== ""){
conditionalLevels = msg.agilite.roles.conditionalLevels;
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
}
if(msg.agilite.roles.processKey){
if(msg.agilite.roles.processKey !== ""){
processKey = msg.agilite.roles.processKey;
if (roleName === "") {
roleName = config.roleName;
}
}
if(msg.agilite.roles.bpmRecordId){
if(msg.agilite.roles.bpmRecordId !== ""){
bpmRecordId = msg.agilite.roles.bpmRecordId;
if (conditionalLevels === "") {
conditionalLevels = config.conditionalLevels;
}
}
if(msg.agilite.roles.currentUser){
if(msg.agilite.roles.currentUser !== ""){
currentUser = msg.agilite.roles.currentUser;
if (processKey === "") {
processKey = config.processKey;
}
}
if(msg.agilite.roles.responsibleUsers){
if(msg.agilite.roles.responsibleUsers !== ""){
responsibleUsers = msg.agilite.roles.responsibleUsers;
if (bpmRecordId === "") {
bpmRecordId = config.bpmRecordId;
}
}
if(msg.agilite.roles.includeHidden){
if(msg.agilite.roles.includeHidden !== ""){
includeHidden = msg.agilite.roles.includeHidden;
if (currentUser === "") {
currentUser = config.currentUser;
}
}
}
}
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
if (responsibleUsers === "") {
responsibleUsers = config.responsibleUsers;
}
if(roleName === ""){
roleName = config.roleName;
}
if (includeHidden === "") {
includeHidden = config.includeHidden;
if(conditionalLevels === ""){
conditionalLevels = config.conditionalLevels;
}
if (includeHidden === "") {
includeHidden = "false";
}
}
if(processKey === ""){
processKey = config.processKey;
}
//We need a apiKey, key and data to proceed
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else {
switch (config.actionType) {
case "2": //Get Role
if (roleName === "") {
success = false;
errorMessage = "No Role Name found";
}
if(bpmRecordId === ""){
bpmRecordId = config.bpmRecordId;
}
break;
case "3": //Get Assigned Roles
if (processKey === "") {
success = false;
errorMessage = "No BPM Process Key found";
} else if (bpmRecordId === "") {
success = false;
errorMessage = "No BPM Record Id found";
} else if (roleName === "") {
success = false;
errorMessage = "No Role Name found";
}
if(currentUser === ""){
currentUser = config.currentUser;
}
break;
case "4": //Assign Role
if (processKey === "") {
success = false;
errorMessage = "No BPM Process Key found";
} else if (bpmRecordId === "") {
success = false;
errorMessage = "No BPM Record Id found";
} else if (roleName === "") {
success = false;
errorMessage = "No Role Name found";
} else if (currentUser === "") {
success = false;
errorMessage = "No Current User found";
} else if (responsibleUsers === "") {
success = false;
errorMessage = "No Responsible User(s) found";
}
if(responsibleUsers === ""){
responsibleUsers = config.responsibleUsers;
}
break;
}
}
if(includeHidden === ""){
includeHidden = config.includeHidden;
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
if(includeHidden === ""){
includeHidden = "false";
}
}
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite)
msg.agilite = {};
//We need a apiKey, key and data to proceed
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else{
switch(config.actionType){
case "2"://Get Role
if(roleName === ""){
success = false;
errorMessage = "No Role Name found";
}
//Perform a HTTP Post to Agilit-e, passing the body content
var axios = require("axios");
requestType = "get";
break;
case "3"://Get Assigned Roles
if(processKey === ""){
success = false;
errorMessage = "No BPM Process Key found";
}else if(bpmRecordId === ""){
success = false;
errorMessage = "No BPM Record Id found";
}else if(roleName === ""){
success = false;
errorMessage = "No Role Name found";
}
var headers = {
headers: {
"api-key": apiKey,
"Content-Type": "application/json"
}
};
break;
case "4"://Assign Role
if(processKey === ""){
success = false;
errorMessage = "No BPM Process Key found";
}else if(bpmRecordId === ""){
success = false;
errorMessage = "No BPM Record Id found";
}else if(roleName === ""){
success = false;
errorMessage = "No Role Name found";
}else if(currentUser === ""){
success = false;
errorMessage = "No Current User found";
}else if(responsibleUsers === ""){
success = false;
errorMessage = "No Responsible User(s) found";
//Check if we need to pass a Log Process Id
if (logProcessId)
headers.headers["log-process-id"] = logProcessId;
switch (config.actionType) {
case "1": //Get All Roles
url = url + "/roles/data";
headers.headers["include-hidden"] = includeHidden;
break;
case "2": //Get Role
requestType = "post";
url = url + "/roles/getRole";
headers.headers["role-name"] = roleName;
headers.headers["conditional-levels"] = conditionalLevels;
break;
case "3": //Get Assigned Roles
url = url + "/roles/getAssignedRoles";
headers.headers["process-key"] = labelKey;
headers.headers["bpm-record-id"] = labelKey;
headers.headers["role-name"] = roleName;
break;
case "4": //Assign Role
url = url + "/roles/assignRole";
headers.headers["process-key"] = labelKey;
headers.headers["bpm-record-id"] = labelKey;
headers.headers["current-user"] = roleName;
headers.headers["responsible-users"] = roleName;
headers.headers["role-name"] = roleName;
break;
}
break;
}
}
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
switch (requestType) {
case "get":
axios.get(url, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
//Perform a HTTP Post to Agilit-e, passing the body content
var axios = require("axios");
requestType = "get";
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
var headers = {
headers: {"api-key": apiKey,"Content-Type":"application/json"}
};
node.send(msg);
} else {
msg.payload = {};
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
switch(config.actionType){
case "1"://Get All Roles
url = url + "/roles/data";
headers.headers["include-hidden"] = includeHidden;
break;
case "2"://Get Role
requestType = "post";
url = url + "/roles/getRole";
headers.headers["role-name"] = roleName;
headers.headers["conditional-levels"] = conditionalLevels;
break;
case "3"://Get Assigned Roles
url = url + "/roles/getAssignedRoles";
headers.headers["process-key"] = labelKey;
headers.headers["bpm-record-id"] = labelKey;
headers.headers["role-name"] = roleName;
break;
case "4"://Assign Role
url = url + "/roles/assignRole";
headers.headers["process-key"] = labelKey;
headers.headers["bpm-record-id"] = labelKey;
headers.headers["current-user"] = roleName;
headers.headers["responsible-users"] = roleName;
headers.headers["role-name"] = roleName;
break;
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
node.status({ fill: "yellow", text: "Running", shape: "ring" });
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
switch (requestType) {
case "get":
axios.get(url, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
}
}else{
msg.payload = "";
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
node.status({ fill: "green", text: "Success", shape: "ring" });
node.send(msg);
})
.catch(function(error){
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
node.status({ fill: "red", text: "Error", shape: "ring" });
node.send(msg);
});
break;
case "post":
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
break;
case "post":
axios.post(url, data, headers)
.then(function(response){
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
}
}else{
msg.payload = "";
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
node.status({ fill: "green", text: "Success", shape: "ring" });
node.send(msg);
})
.catch(function(error){
node.status({ fill: "red", text: "Error", shape: "ring" });
node.send(msg);
} else {
msg.payload = {};
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
node.status({ fill: "red", text: "Error", shape: "ring" });
node.send(msg);
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
break;
}
});
}
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
RED.nodes.registerType("roles", Roles);
}
break;
}
});
}
RED.nodes.registerType("roles", Roles);
}

@@ -1,131 +0,199 @@

module.exports = function(RED) {
function Templates(config) {
RED.nodes.createNode(this,config);
module.exports = function (RED) {
function Templates(config) {
RED.nodes.createNode(this, config);
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
var node = this;
var success = true;
var errorMessage = "";
this.field = config.field || "payload";
this.fieldType = config.fieldType || "msg";
this.on('input', function(msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var url = "";
var data = {};
var logProcessId = null;
returnTypeOf = (input) => {
let stringConstructor = "test".constructor;
let arrayConstructor = [].constructor;
let objectConstructor = {}.constructor;
let booleanConstructor = true.constructor;
let integerConstructor = (123).constructor;
url = serverConfig.server;
let result = null;
//Check if there's valid data to pass
if(msg.payload){
data = msg.payload;
}
if (input === undefined) {
result = "undefined";
} else if (input === null) {
result = null;
} else if (input.constructor === stringConstructor) {
result = "String";
} else if (input.constructor === arrayConstructor) {
result = "Array";
} else if (input.constructor === objectConstructor) {
result = "Object";
} else if (input.constructor === booleanConstructor) {
result = "Boolean";
} else if (input.constructor === integerConstructor) {
result = "Number";
}
//Check if we need to use programmatic values
if(msg.agilite){
if(msg.agilite.logProcessId){
if(msg.agilite.logProcessId !== ""){
logProcessId = msg.agilite.logProcessId;
}
}
return result;
};
if(msg.agilite.apiKey){
if(msg.agilite.apiKey !== ""){
apiKey = msg.agilite.apiKey;
}
}
this.on('input', function (msg) {
var serverConfig = RED.nodes.getNode(config.server);
var apiKey = "";
var profileKey = "";
var url = "";
var data = {};
var logProcessId = null;
var failFlow = config.failFlow;
if(msg.agilite.templates){
if(msg.agilite.templates.profileKey){
if(msg.agilite.templates.profileKey !== ""){
profileKey = msg.agilite.templates.profileKey;
url = serverConfig.server;
//Check if there's valid data to pass
if (returnTypeOf(msg.payload) !== "Object")
msg.payload = {};
data = msg.payload;
//Check if we need to use programmatic values
if (msg.agilite) {
if (msg.agilite.logProcessId) {
if (msg.agilite.logProcessId !== "") {
logProcessId = msg.agilite.logProcessId;
}
}
if (msg.agilite.apiKey) {
if (msg.agilite.apiKey !== "") {
apiKey = msg.agilite.apiKey;
}
}
if (msg.agilite.templates) {
if (msg.agilite.templates.profileKey) {
if (msg.agilite.templates.profileKey !== "") {
profileKey = msg.agilite.templates.profileKey;
}
}
}
}
}
}
}
if(apiKey === ""){
apiKey = serverConfig.credentials.apiKey;
}
if (apiKey === "") {
apiKey = serverConfig.credentials.apiKey;
}
if(profileKey === ""){
profileKey = config.profileKey;
}
if (profileKey === "") {
profileKey = config.profileKey;
}
//We need an apiKey, profileKey and data to proceed
if(apiKey === ""){
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
}else if(url === ""){
success = false;
errorMessage = "No Server URL Provided";
}else if(profileKey === ""){
success = false;
errorMessage = "No Profile Key Provided";
}
//We need an apiKey, profileKey and data to proceed
if (apiKey === "") {
success = false;
errorMessage = "No valid API Key Provided. Please authenticate with Agilit-e first";
} else if (url === "") {
success = false;
errorMessage = "No Server URL Provided";
} else if (profileKey === "") {
success = false;
errorMessage = "No Profile Key Provided";
}
if(!success){
msg.payload = errorMessage;
node.send(msg);
return false;
}
if (!success) {
msg.payload = errorMessage;
node.send(msg);
return false;
}
//Create msg.agilite if it's null so we can store the result
if(!msg.agilite){
msg.agilite = {};
}
//Create msg.agilite if it's null so we can store the result
if (!msg.agilite) {
msg.agilite = {};
}
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
url = url + "/templates/execute";
//Perform a HTTP Post to Agilit-e for Numbering, passing the body content
var axios = require("axios");
url = url + "/templates/execute";
var headers = {
headers: {"api-key": apiKey, "profile-key": profileKey, "Content-Type":"application/json"}
};
var headers = {
headers: {
"api-key": apiKey,
"profile-key": profileKey,
"Content-Type": "application/json"
}
};
//Check if we need to pass a Log Process Id
if(logProcessId){
headers.headers["log-process-id"] = logProcessId;
}
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
//Check if we need to pass a Log Process Id
if (logProcessId)
headers.headers["log-process-id"] = logProcessId;
if(response.data.success){
if (node.fieldType === "msg"){
RED.util.setMessageProperty(msg,node.field,response.data.data)
}else if (node.fieldType === "flow") {
node.context().flow.set(node.field,response.data.data);
}else if (node.fieldType === "global") {
node.context().global.set(node.field,response.data.data);
}
node.status({
fill: "yellow",
text: "Running",
shape: "ring"
});
}else{
msg.payload = "";
}
axios.post(url, data, headers)
.then(function (response) {
msg.agilite.success = response.data.success;
msg.agilite.messages = response.data.messages;
node.send(msg);
})
.catch(function (error) {
if(error.response){
msg.payload = error.response.data.data;
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
}else{
msg.payload = {};
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
if (response.data.success) {
switch (node.fieldType) {
case "msg":
RED.util.setMessageProperty(msg, node.field, response.data.data);
break;
case "flow":
node.context().flow.set(node.field, response.data.data);
break;
case "global":
node.context().global.set(node.field, response.data.data);
break;
}
node.send(msg);
});
});
}
node.status({
fill: "green",
text: "Success",
shape: "ring"
});
RED.nodes.registerType("templates", Templates);
}
node.send(msg);
} else {
msg.payload = {};
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
}
})
.catch(function (error) {
msg.payload = {};
if (error.response) {
msg.agilite.success = error.response.data.success;
msg.agilite.messages = error.response.data.messages;
} else {
msg.agilite.success = false;
msg.agilite.messages = ["Unknown Error Occurred"];
}
node.status({
fill: "red",
text: "Error",
shape: "ring"
});
if (failFlow) {
node.error(msg.agilite.messages, msg);
} else {
node.send(msg);
}
});
});
}
RED.nodes.registerType("templates", Templates);
}

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

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