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

fh-api

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fh-api - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

125

lib/act.js
var util = require('util'),
url = require('url'),
assert = require('assert'),
http = require('http'),
https = require('https'),
futils = require('./fhutils'),
fhutils, call, config, widget;
url = require('url'),
assert = require('assert'),
http = require('http'),
https = require('https'),
futils = require('./fhutils'),
fhutils, call, config, widget;
module.exports = function(cfg){
if (!cfg){
module.exports = function(cfg) {
if (!cfg) {
return;

@@ -30,40 +30,38 @@ }

var ERRORS = {
"InvalidCallback" : "$fh.act requires the final parameter to be a function",
"InvalidArgument" : "The param %s is invalid it is required to be a %s",
"MissingArgument" : "The param %s is missing",
"MissingParms" : "params is missing",
"InvalidGuid" : "The app identifier (guid) is invalid %s . Please check it.",
"AppNotFound" : "No app with identifier %s found. Please ensure the identifier is correct"
"InvalidCallback": "$fh.act requires the final parameter to be a function",
"InvalidArgument": "The param %s is invalid it is required to be a %s",
"MissingArgument": "The param %s is missing",
"MissingParms": "params is missing",
"InvalidGuid": "The app identifier (guid) is invalid %s . Please check it.",
"AppNotFound": "No app with identifier %s found. Please ensure the identifier is correct"
};
function validateParams (params, cb){
if(! params || 'object' !== typeof params){
function validateParams(params, cb) {
if (!params || 'object' !== typeof params) {
return cb(ERRORS.MissingParms);
}
if(! params.hasOwnProperty('guid') || 'string' !== typeof params.guid){
return cb(util.format(ERRORS.InvalidArgument,"guid","string"));
if (!params.hasOwnProperty('guid') || 'string' !== typeof params.guid) {
return cb(util.format(ERRORS.InvalidArgument, "guid", "string"));
}
if(params.guid.length !== 24){
if (params.guid.length !== 24) {
return cb(util.format(ERRORS.InvalidGuid, params.guid));
}
if(! params.hasOwnProperty('endpoint') || 'string' !== typeof params.endpoint){
return cb(util.format(ERRORS.InvalidArgument,"endpoint","string"));
if (!params.hasOwnProperty('endpoint') || 'string' !== typeof params.endpoint) {
return cb(util.format(ERRORS.InvalidArgument, "endpoint", "string"));
}
if(params.hasOwnProperty('params') && 'object' !== typeof params['params']){
return cb(util.format(ERRORS.InvalidArgument,"params","object"));
if (params.hasOwnProperty('params') && 'object' !== typeof params['params']) {
return cb(util.format(ERRORS.InvalidArgument, "params", "object"));
}
return cb(null);
};
}
function doAppCall(endpoints, func,params,liveflag,cb) {
if('object'!== typeof endpoints || endpoints.status !== 200) return cb(util.format(ERRORS.AppNotFound,params.guid));
function doAppCall(endpoints, func, params, liveflag, cb) {
if ('object' !== typeof endpoints || endpoints.status !== 200) return cb(util.format(ERRORS.AppNotFound, params.guid));
var retdata = JSON.parse(endpoints['body']);
var callurl = (liveflag)
? retdata['hosts']['live-url']
: retdata['hosts']['development-url'];
callurl+="/cloud/"+func;
var callurl = (liveflag) ? retdata['hosts']['live-url'] : retdata['hosts']['development-url'];
callurl += "/cloud/" + func;
var payload = "";
try{
try {
payload = JSON.stringify(params);
}catch(e){
} catch (e) {
return cb(" Could not send params " + e.message);

@@ -74,33 +72,34 @@ }

var portmatch = urlprops.host.match(/[:\d]*$/);
var port = (portmatch === null)? 443 : portmatch[0].toString().replace(/:/,"");
urlprops.host = urlprops.host.replace(/[:\d]*$/,"");
var port = (portmatch === null) ? 443 : portmatch[0].toString().replace(/:/, "");
urlprops.host = urlprops.host.replace(/[:\d]*$/, "");
var headers = {};
headers["content-type"] = "application/json";
headers["content-length"] = new Buffer(payload).length ||0;
headers["accept"] = "application/json";
headers["content-type"] = "application/json";
headers["content-length"] = new Buffer(payload).length || 0;
headers["accept"] = "application/json";
headers["x-request-with"] = widget;
fhutils.addAppApiKeyHeader(headers);
var opts = {
host:urlprops.host,
path:urlprops.path,
port:port,
method:"POST",
headers:headers
host: urlprops.host,
path: urlprops.path,
port: port,
method: "POST",
headers: headers
};
var protocol = (urlprops.protocol === "http")? http : https;
var protocol = (urlprops.protocol === "http") ? http : https;
//finally make call to other app
var req = protocol.request(opts,function (res){
var req = protocol.request(opts, function(res) {
req.socket && req.socket.setTimeout(60000);
req.connection.setTimeout && req.connection.setTimeout(60000);
var retData="";
res.on('data', function (data){
retData+=data;
var retData = "";
res.on('data', function(data) {
retData += data;
});
res.on('end',function () {
return cb(null,retData);
res.on('end', function() {
return cb(null, retData);
});
});
req.on('error', function (err){
req.on('error', function(err) {
return cb(err);

@@ -113,16 +112,24 @@ });

//return our public function
return function (params, cb) {
if('function' !== typeof cb) throw {name:"InvalidCallback", message:ERRORS.InvalidCallback};
validateParams(params, function (err){
if(err) return cb(err);
return function(params, cb) {
if ('function' !== typeof cb) throw {
name: "InvalidCallback",
message: ERRORS.InvalidCallback
};
validateParams(params, function(err) {
if (err) return cb(err);
//call millicore hosts endpoint sending the guid of app being called and the guid of the app doing the calling
call("ide/apps/app/hosts",{payload: {"guid": params.guid,calling_guid:widget}}, function (err, data){
call("ide/apps/app/hosts", {
payload: {
"guid": params.guid,
calling_guid: widget
}
}, function(err, data) {
//construct our call to secondary app
if(err) return cb(err);
var live = (params.live)?true : false;
if (err) return cb(err);
var live = (params.live) ? true : false;
var funcParams = params.params || {};
doAppCall(data,params.endpoint,funcParams,live,cb);
doAppCall(data, params.endpoint, funcParams, live, cb);
});
})
});
};
};

@@ -6,4 +6,4 @@ /*

var sec = require('fh-security'),
consolelogger = require('./consolelogger.js'),
util = require('util');
consolelogger = require('./consolelogger.js'),
util = require('util');

@@ -19,3 +19,3 @@ //IMPORTANT: This will force node to ignore cert errors for https requests

if (cfg){
if (cfg) {
cfg.logger = logr;

@@ -31,4 +31,4 @@ }

log: false,
stringify : false,
parse : false,
stringify: false,
parse: false,
push: require('./push')(cfg),

@@ -38,14 +38,17 @@ call: require('./call')(cfg),

redisPort: cfg.redis.port || '6379',
redisHost: cfg.redis.host|| 'localhost',
redisHost: cfg.redis.host || 'localhost',
session: require('./session')(cfg),
stats: require('./stats')(cfg),
sync: require('./sync-srv.js')(cfg),
act : require('./act')(cfg),
service : require('./act')(cfg),
act: require('./act')(cfg),
service: require('./act')(cfg),
sec: sec.security,
hash: function(opts, callback){
var p = {act:'hash', params: opts};
hash: function(opts, callback) {
var p = {
act: 'hash',
params: opts
};
sec.security(p, callback);
},
web : require('./web')(cfg)
web: require('./web')(cfg)
};

@@ -57,3 +60,3 @@ }

*/
module.exports = (function(){
module.exports = (function() {
// First setup the required config params from env variables

@@ -81,3 +84,3 @@ var millicore = process.env.FH_MILLICORE || 'NO-MILLICORE-DEFINED';

var messaging_recovery_file = process.env.FH_MESSAGING_RECOVERY_FILE || 'NO-RECOVERY-FILE-DEFINED';
var messaging_protocol = process.env.FH_MESSAGING_PROTOCOL || "https";
var messaging_protocol = process.env.FH_MESSAGING_PROTOCOL || "https";
var messaging_backup_file = process.env.FH_MESSAGING_BACKUP_FILE || 'NO-BACKUP-FILE-DEFINED';

@@ -100,44 +103,44 @@ var stats_host = process.env.FH_STATS_HOST || 'localhost';

var cfg = {
fhapi:{
fhapi: {
appname: appname,
millicore:millicore,
port : 443,
domain:domain,
instance:instance,
widget:widget,
appapikey:appapikey
millicore: millicore,
port: 443,
domain: domain,
instance: instance,
widget: widget,
appapikey: appapikey
},
fhditch:{
host:ditch_host,
port:ditch_port,
protocol : ditch_protocol
fhditch: {
host: ditch_host,
port: ditch_port,
protocol: ditch_protocol
},
redis:{
host:redis_host,
port:redis_port,
password:redis_password
redis: {
host: redis_host,
port: redis_port,
password: redis_password
},
fhmessaging:{
host:messaging_host,
cluster:messaging_cluster,
msgServer:{
logMessageURL:messaging_server
fhmessaging: {
host: messaging_host,
cluster: messaging_cluster,
msgServer: {
logMessageURL: messaging_server
},
recoveryFiles:{
fileName:messaging_recovery_file
recoveryFiles: {
fileName: messaging_recovery_file
},
backupFiles:{
fileName:messaging_backup_file
backupFiles: {
fileName: messaging_backup_file
},
protocol : messaging_protocol
protocol: messaging_protocol
},
fhstats:{
host:stats_host,
port:stats_port,
enabled:stats_enabled,
protocol:stats_protocol
fhstats: {
host: stats_host,
port: stats_port,
enabled: stats_enabled,
protocol: stats_protocol
},
urbanairship:ua,
socketTimeout : 60000,
APP_API_KEY_HEADER : 'X-FH-AUTH-APP'
urbanairship: ua,
socketTimeout: 60000,
APP_API_KEY_HEADER: 'X-FH-AUTH-APP'
};

@@ -147,2 +150,2 @@

return new FHapi(cfg, logger);
})();
})();
var config,
_ = require('underscore'),
https = require('https'),
futils = require('./fhutils'),
fhutils;
module.exports = function(cfg){
_ = require('underscore'),
https = require('https'),
futils = require('./fhutils'),
fhutils;
module.exports = function(cfg) {
config = cfg;

@@ -17,4 +17,6 @@ fhutils = new futils(config);

var call = function call(path, params, callback) {
var headers = { "accept" : "application/json" },
logger = config.logger;
var headers = {
"accept": "application/json"
},
logger = config.logger;
var props = fhutils.getMillicoreProps();

@@ -32,8 +34,8 @@ headers["content-type"] = "application/json; charset=utf-8";

var addParams = (params == undefined || params == null)? new Object() : _.clone(params);
var addParams = (params == undefined || params === null) ? new Object() : _.clone(params);
addParams["instance"] = props.instId;
addParams["widget"] = props.widgId;
addParams["widget"] = props.widgId;
var fhResp = new Object();
var req = https.request(options, function (res) {
var fhResp = {};
var req = https.request(options, function(res) {
fhResp.status = res.statusCode;

@@ -61,4 +63,4 @@ // TODO - *both* of these are recommended ways of setting timeout on http requests..

req.write(JSON.stringify(addParams)+"\n");
req.write(JSON.stringify(addParams) + "\n");
req.end();
};
{
"name": "fh-api",
"version": "0.2.1",
"version": "0.2.2",
"description": "FeedHenry Cloud APIs",

@@ -5,0 +5,0 @@ "main": "lib/api.js",

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

0.2.1-24
0.2.2-25
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