Comparing version 0.5.0 to 1.0.0
125
index.js
@@ -1,1 +0,124 @@ | ||
module.exports = require('./lib/f.js'); | ||
'use strict'; | ||
var http = require('http'); | ||
var https = require('https'); | ||
var fs = require('fs'); | ||
// Load environment variables for debugging if available | ||
var path = require('path'); | ||
var fenv = {}; | ||
var envdir = path.join(__dirname, 'env', 'env.json'); | ||
if (fs.existsSync(envdir)) { | ||
fenv = require(envdir); | ||
} | ||
function parseArgList(argList) { | ||
var args; | ||
var kwargs = {}; | ||
if (typeof argList[argList.length - 1] === 'object' && argList[argList.length - 1] !== 'null') { | ||
kwargs = argList.pop(); | ||
} | ||
args = argList.slice(); | ||
return new Buffer( | ||
JSON.stringify({ | ||
args: args, | ||
kwargs: kwargs | ||
}) | ||
); | ||
} | ||
function parseContent(content) { | ||
return new Buffer(content.toString()); | ||
} | ||
function f(name, mode, config) { | ||
mode = mode || 'json'; | ||
config = config || f.config; | ||
return function external() { | ||
var argList = [].slice.call(arguments); | ||
var callback = function() {}; | ||
var payload; | ||
var headers; | ||
var req; | ||
if (typeof argList[argList.length - 1] === 'function') { | ||
callback = argList.pop(); | ||
} | ||
if (mode === 'json') { | ||
headers = {'Content-Type': 'application/json'}; | ||
payload = parseArgList(argList); | ||
} else if (mode === 'command') { | ||
headers = {'Content-Type': 'application/command'}; | ||
payload = parseContent(argList[0]); | ||
} else if (mode === 'file') { | ||
if (!argList[0] instanceof Buffer) { | ||
return callback(new Error('Expecting Buffer for function mode: ' + mode)); | ||
} | ||
headers = {'Content-Type': 'application/octet-stream'}; | ||
payload = argList[0]; | ||
} else { | ||
return callback(new Error('Invalid function mode: ' + mode)); | ||
} | ||
req = [http, https][(config.gateway.port === 443) | 0].request({ | ||
host: config.gateway.host, | ||
method: 'POST', | ||
headers: headers, | ||
port: config.gateway.port, | ||
path: config.gateway.path + name | ||
}, function (res) { | ||
var buffers = []; | ||
res.on('data', function (chunk) { buffers.push(chunk); }); | ||
res.on('end', function () { | ||
var response = Buffer.concat(buffers); | ||
var contentType = res.headers['content-type'] || ''; | ||
if (contentType === 'application/json') { | ||
response = response.toString(); | ||
try { | ||
response = JSON.parse(response); | ||
} catch(e) { | ||
response = null; | ||
} | ||
} else if (contentType.match(/^text\/.*$/i)) { | ||
response = response.toString(); | ||
} | ||
if (((res.statusCode / 100) | 0) !== 2) { | ||
return callback(new Error(response)); | ||
} else { | ||
return callback(null, response); | ||
} | ||
}); | ||
}); | ||
req.on('error', callback); | ||
req.write(payload); | ||
req.end(); | ||
}; | ||
}; | ||
f.config = { | ||
gateway: { | ||
host: fenv.host || 'f.stdlib.com', | ||
port: fenv.port || 443, | ||
path: fenv.path || '/' | ||
} | ||
}; | ||
module.exports = f; |
{ | ||
"author": { | ||
"name": "Enrico Marino", | ||
"email": "enrico.marino@email.com", | ||
"url": "http://onirame.no.de" | ||
}, | ||
"name": "f", | ||
"description": "JavaScript functional library", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/onirame/f", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/onirame/f.git" | ||
"version": "1.0.0", | ||
"description": "Functional Microservice Request Library", | ||
"main": "index.js", | ||
"bin": { | ||
"f": "cli/bin.js" | ||
}, | ||
"main": "./index.js", | ||
"engines": { | ||
"node": "*" | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
"author": "Keith Horwood", | ||
"license": "MIT" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
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
0
4964
6
109
12
3
4