nomics-platform
Advanced tools
Comparing version 0.5.8 to 0.6.0
const url = require('url') | ||
const { spawn } = require('child_process') | ||
const net = require('net') | ||
const teenytest = require('teenytest') | ||
const Info = require('./info') | ||
const Market = require('./market') | ||
const Trade = require('./trade') | ||
module.exports = async function (options) { | ||
module.exports = function (options) { | ||
if (options.length < 1) { | ||
return new Error('audit requires at least one argument: a url to and endpoint or a script file to run as an endpoint.') | ||
console.log('audit requires at least one argument: a url to and endpoint or a script file to run as an endpoint.') | ||
process.exit(1) | ||
} | ||
@@ -24,26 +22,17 @@ const endpoint = options[0] | ||
async function auditURL (u) { | ||
const results = [] | ||
results.push(...await Info(u)) | ||
results.push(...await Market(u)) | ||
results.push(...await Trade(u)) | ||
console.log(results.map((r) => r.toString()).join('\n')) | ||
const anyRequiredFailures = results.some((r) => r.required && !r.pass) | ||
if (anyRequiredFailures) { | ||
return new Error('\x1B[31mAudit Failed: One or more required audits failed\x1B[0m') | ||
} | ||
const anyOptionalFailures = results.some((r) => !r.required && !r.pass) | ||
if (anyOptionalFailures) { | ||
console.log('\x1B[33mAudit Passed, but some optional audits failed\x1B[0m') | ||
} else { | ||
console.log('\x1B[32mAudit Passed\x1b[0m') | ||
} | ||
function auditURL (u) { | ||
return new Promise((resolve, reject) => { | ||
process.chdir(__dirname) | ||
process.env.NOMICS_PLATFORM_URL_ROOT = u | ||
teenytest('test/*.js', {plugins: ['teenytest-promise']}, (err, passing) => { | ||
if (err || !passing) { | ||
reject(new Error('Audit Failed')) | ||
} else { | ||
resolve() | ||
} | ||
}) | ||
}) | ||
} | ||
async function auditCommand (command, options) { | ||
function auditCommand (command, options) { | ||
const parts = command.split(' ') | ||
@@ -57,10 +46,5 @@ const child = spawn(parts[0], parts.slice(1)) | ||
child.stdout.on('data', (data) => { | ||
console.log(`server: ${data}`) | ||
}) | ||
child.stdout.on('data', (data) => console.log(`server: ${data}`)) | ||
child.stderr.on('data', (data) => console.log(`server: ${data}`)) | ||
child.stderr.on('data', (data) => { | ||
console.log(`server: ${data}`) | ||
}) | ||
return new Promise(async (resolve, reject) => { | ||
@@ -74,4 +58,10 @@ child.on('error', reject) | ||
} | ||
const result = await auditURL(`http://localhost:${port}${path}`) | ||
let err | ||
try { | ||
err = await auditURL(`http://localhost:${port}${path}`) | ||
} catch (e) { | ||
err = e | ||
} | ||
await new Promise((resolve, reject) => { | ||
@@ -82,3 +72,3 @@ child.on('exit', resolve) | ||
resolve(result) | ||
resolve(err) | ||
}) | ||
@@ -85,0 +75,0 @@ } |
var audit = require('./audit') | ||
class UsageError extends Error {} | ||
module.exports = async function (argv) { | ||
var err = await run(argv) | ||
if (err) { | ||
console.log('\n' + err.toString() + '\n') | ||
if (err instanceof UsageError) { | ||
usage() | ||
} | ||
module.exports = function (argv) { | ||
if (argv.length < 1) { | ||
usage() | ||
process.exit(1) | ||
} | ||
} | ||
async function run (argv) { | ||
if (argv.length < 1) { | ||
return new UsageError('Command is required') | ||
} | ||
var command = argv[0] | ||
var options = argv.slice(1) | ||
switch (command) { | ||
case 'audit': return audit(options) | ||
default: return new UsageError('Unknown command: ' + command) | ||
default: | ||
usage() | ||
process.exit(1) | ||
} | ||
@@ -32,4 +24,5 @@ } | ||
'Commands:', | ||
'\taudit [url] [path-to-root]' | ||
'\taudit url', | ||
'\taudit "command to run server on localhost:3000" [path to root]' | ||
].join('\n\t')) | ||
} |
{ | ||
"name": "nomics-platform", | ||
"version": "0.5.8", | ||
"version": "0.6.0", | ||
"description": "Nomics Platform Toolkit", | ||
@@ -30,3 +30,4 @@ "keywords": [ | ||
"cli": "node bin/nomics-platform.js", | ||
"lint": "eslint **/*.js" | ||
"lint": "eslint **/*.js", | ||
"test": "yarn cli audit \"node ./example/index.js\"" | ||
}, | ||
@@ -39,7 +40,10 @@ "devDependencies": { | ||
"eslint-plugin-promise": "^3.8.0", | ||
"eslint-plugin-standard": "^3.1.0" | ||
"eslint-plugin-standard": "^3.1.0", | ||
"express": "^4.16.3" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.18.0" | ||
"axios": "^0.18.0", | ||
"teenytest": "^5.1.1", | ||
"teenytest-promise": "^1.0.0" | ||
} | ||
} |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
11
13276
3
7
344
5
3
+ Addedteenytest@^5.1.1
+ Addedteenytest-promise@^1.0.0
+ Addedacorn@7.4.1(transitive)
+ Addedacorn-walk@7.2.0(transitive)
+ Addedasync@2.6.4(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction-names-at-line@1.1.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash-deeper@1.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedteenytest@5.3.0(transitive)
+ Addedteenytest-promise@1.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)