fh-mbaas-api
Advanced tools
Comparing version 3.0.0-beta9 to 3.0.1
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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
88157
2436
1
42
+ Addedadm-zip@0.4.16(transitive)
+ Addedcsvtojson@0.3.6(transitive)
+ Addedfh-db@0.5.4(transitive)
+ Addedfh-forms@0.5.20(transitive)
+ Addedjcsv@0.0.3(transitive)
+ Addedlodash@2.4.1(transitive)
- Removedfh-forms@0.5.16(transitive)
Updatedfh-db@~0.5.1
Updatedfh-forms@0.5.20