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

fh-mbaas-api

Package Overview
Dependencies
Maintainers
1
Versions
207
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fh-mbaas-api - npm Package Compare versions

Comparing version 3.0.0-beta9 to 3.0.1

80

lib/db.js
var http = require('http'),
https = require('https'),
request = require('request'),
fs = require('fs'),
util = require('util'),

@@ -31,3 +33,3 @@ assert = require('assert'),

// Type required for all but list operations, where we can list collections by omitting the type param
if (params.act !== 'list' && params.act !== 'close' && params.type == undefined) throw new Error("'type' undefined in params. See documentation of $fh.db for proper usage");
if (params.type == undefined && ['close', 'list', 'export', 'import'].indexOf(params.act)===-1) throw new Error("'type' undefined in params. See documentation of $fh.db for proper usage");
if (appname == undefined) throw new Error("Internal error - no appId defined");

@@ -58,40 +60,64 @@

function net_db(params, callback) {
var headers = { "accept" : "application/json" };
var headers = { "accept" : "application/json" },
url = config.fhditch.protocol + "://" + ditch_host + ":" + ditch_port + '/data/' + params.act,
postData = {
uri : url,
method : 'POST',
headers : headers,
timeout : config.socketTimeout
},
req,
requestArgs;
headers["content-type"] = "application/json";
fhutils.addAppApiKeyHeader(headers);
var options = {
host: ditch_host,
port: ditch_port,
path: '/data/' + params.act,
method: 'POST',
headers: headers
};
var protocol = (config.fhditch.protocol === "http")? http : https;
var req = protocol.request(options, function (res) {
// Otherwise, these get sent as form data
if (!params.files){
postData.json = params;
}
requestArgs = [postData];
req.socket && req.socket.setTimeout(config.socketTimeout);
req.connection.setTimeout && req.connection.setTimeout(config.socketTimeout);
var data = '';
res.on('data', function(chunk) {
data += chunk;
if (params.act !== 'export'){
// Only export requests get streamed - the rest use the normal callback mehcanism
requestArgs.push(function(err, res, body){
if (err){
logger.warning('Problem contacting DITCH server: ' + err.message + "\n" + util.inspect(err.stack));
return callback(err);
}
return callback(null, body);
});
}
res.on('end', function() {
if (res.statusCode != 200) {
return callback(new Error(data + " status: " + res.statusCode));
req = request.apply(this, requestArgs);
// if we're sending files, setup the request to use form data
if (params.files){
var form = req.form();
Object.keys(params.files).forEach(function(filekey){
var file = params.files[filekey];
form.append(filekey, fs.createReadStream(file.path));
});
// Append all strings as form data
Object.keys(params).forEach(function(paramkey){
var paramData = params[paramkey];
if (typeof paramData === 'string'){
form.append(paramkey, paramData);
}
return callback(undefined, JSON.parse(data));
});
});
}
req.on('error', function(e) {
logger.warning('Problem contacting DITCH server: ' + e.message + "\n" + util.inspect(e.stack));
callback(e);
});
if (params.act === 'export'){
// Finish up a streaming request for exports
req.on('error', function(err){
logger.warning('Problem contacting DITCH server: ' + err.message + "\n" + util.inspect(err.stack));
return callback(err);
})
req.end();
req.write(JSON.stringify(params)+"\n");
req.end();
return callback(null, { stream : req });
}
return;
}

@@ -8,4 +8,4 @@ var assert = require('assert'),

this.addAppApiKeyHeader = function(header){
if(cfg.appapikey && cfg.appapikey.length > 0){
header[cfg.APP_API_KEY_HEADER] = cfg.appapikey;
if(cfg.fhapi && cfg.fhapi.appapikey && cfg.fhapi.appapikey.length > 0){
header[cfg.APP_API_KEY_HEADER] = cfg.fhapi.appapikey;
}

@@ -45,2 +45,2 @@ };

};
};
{
"name": "fh-mbaas-api",
"version": "3.0.0-beta9",
"version": "3.0.1",
"description": "FeedHenry MBAAS Cloud APIs",

@@ -14,4 +14,4 @@ "main": "lib/api.js",

"winston": "0.6.2",
"fh-forms": "0.5.16",
"fh-db": "~0.4.12",
"fh-forms": "0.5.20",
"fh-db": "~0.5.1",
"fh-security": "0.1.2-3"

@@ -18,0 +18,0 @@ },

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

3.0.0-beta9-28
3.0.1-2
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