nomics-platform
Advanced tools
Comparing version 0.2.0 to 0.2.1
#!/usr/bin/env node | ||
require("../").CLI(process.argv.slice(2)) | ||
require('../').CLI(process.argv.slice(2)) |
module.exports = { | ||
CLI: require("./lib/cli") | ||
CLI: require('./lib/cli') | ||
} |
@@ -1,34 +0,34 @@ | ||
const https = require("https") | ||
const https = require('https') | ||
module.exports = function(u) { | ||
module.exports = function (u) { | ||
return new Promise((resolve, reject) => { | ||
https.get(u, (res) => { | ||
const { statusCode } = res; | ||
const contentType = res.headers['content-type']; | ||
const { statusCode } = res | ||
const contentType = res.headers['content-type'] | ||
if (statusCode !== 200) { | ||
reject(new Error('Request Failed.\n' + `Status Code: ${statusCode}`)); | ||
res.resume(); | ||
return; | ||
reject(new Error('Request Failed.\n' + `Status Code: ${statusCode}`)) | ||
res.resume() | ||
return | ||
} else if (!/^application\/json/.test(contentType)) { | ||
reject(new Error('Invalid content-type.\n' + `Expected application/json but received ${contentType}`)) | ||
res.resume(); | ||
return; | ||
res.resume() | ||
return | ||
} | ||
res.setEncoding('utf8'); | ||
let rawData = ''; | ||
res.on('data', (chunk) => { rawData += chunk; }); | ||
res.setEncoding('utf8') | ||
let rawData = '' | ||
res.on('data', (chunk) => { rawData += chunk }) | ||
res.on('end', () => { | ||
try { | ||
const parsedData = JSON.parse(rawData); | ||
resolve(parsedData); | ||
const parsedData = JSON.parse(rawData) | ||
resolve(parsedData) | ||
} catch (e) { | ||
reject(e); | ||
reject(e) | ||
} | ||
}); | ||
}) | ||
}).on('error', (e) => { | ||
reject(e); | ||
}); | ||
reject(e) | ||
}) | ||
}) | ||
} |
@@ -1,7 +0,6 @@ | ||
const url = require("url") | ||
const fs = require("fs") | ||
const url = require('url') | ||
module.exports = async function(options) { | ||
module.exports = async function (options) { | ||
if (options.length !== 1) { | ||
return new Error("audit takes one argument: a url to and endpoint or a script file to run as an endpoint.") | ||
return new Error('audit takes one argument: a url to and endpoint or a script file to run as an endpoint.') | ||
} | ||
@@ -13,34 +12,26 @@ const endpoint = options[0] | ||
if (u.protocol) { | ||
return await auditURL(endpoint) | ||
return auditURL(endpoint) | ||
} | ||
if (!fs.existsSync(endpoint)) { | ||
return new Error(endpoint+" not recognized as url and file does not exist") | ||
} | ||
return auditFile(endpoint) | ||
return new Error(endpoint + ' not recognized as url') | ||
} | ||
async function auditURL(u) { | ||
async function auditURL (u) { | ||
const results = [] | ||
results.push(...await require("./info")(u)) | ||
results.push(...await require('./info')(u)) | ||
console.log(results.map((r) => r.toString()).join("\n")) | ||
console.log(results.map((r) => r.toString()).join('\n')) | ||
const anyRequiredFailures = results.some((r) => r.required && !r.pass); | ||
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") | ||
return new Error('\x1B[31mAudit Failed: One or more required audits failed\x1B[0m') | ||
} | ||
const anyOptionalFailures = results.some((r) => !r.required && !r.pass); | ||
const anyOptionalFailures = results.some((r) => !r.required && !r.pass) | ||
if (anyOptionalFailures) { | ||
console.log("\x1B[33mAudit Passed, but some optional audits failed\x1B[0m") | ||
console.log('\x1B[33mAudit Passed, but some optional audits failed\x1B[0m') | ||
} else { | ||
console.log("\x1B[32mAudit Passed\x1b[0m") | ||
console.log('\x1B[32mAudit Passed\x1b[0m') | ||
} | ||
} | ||
function auditFile(path) { | ||
return new Error("auditing by script file is not yet implemented") | ||
} |
@@ -1,27 +0,27 @@ | ||
const get = require("./get") | ||
const Result = require("./result") | ||
const url = require("url") | ||
const get = require('./get') | ||
const Result = require('./result') | ||
const url = require('url') | ||
module.exports = async function(u) { | ||
const results = []; | ||
module.exports = async function (u) { | ||
const results = [] | ||
try { | ||
const info = await get(u+"/info"); | ||
results.push(new Result(true, true, "Fetched /info and parsed as JSON")) | ||
const info = await get(u + '/info') | ||
results.push(new Result(true, true, 'Fetched /info and parsed as JSON')) | ||
results.push(...auditInfoData(info)) | ||
} catch(e) { | ||
results.push(new Result(false, true, "Failed to fetch /info and parse as JSON", e)) | ||
} catch (e) { | ||
results.push(new Result(false, true, 'Failed to fetch /info and parse as JSON', e)) | ||
} | ||
return results; | ||
return results | ||
} | ||
function auditInfoData(info) { | ||
const results = []; | ||
function auditInfoData (info) { | ||
const results = [] | ||
results.push(validateStringProperty(info, "name", true, "Info")) | ||
results.push(validateStringProperty(info, "description", false, "Info")) | ||
results.push(validateStringProperty(info, "logo", false, "Info")) | ||
results.push(validateURLProperty(info, "logo", false, "Info")) | ||
results.push(validateStringProperty(info, "website", false, "Info")) | ||
results.push(validateURLProperty(info, "website", false, "Info")) | ||
results.push(validateStringProperty(info, "twitter", false, "Info")) | ||
results.push(validateStringProperty(info, 'name', true, 'Info')) | ||
results.push(validateStringProperty(info, 'description', false, 'Info')) | ||
results.push(validateStringProperty(info, 'logo', false, 'Info')) | ||
results.push(validateURLProperty(info, 'logo', false, 'Info')) | ||
results.push(validateStringProperty(info, 'website', false, 'Info')) | ||
results.push(validateURLProperty(info, 'website', false, 'Info')) | ||
results.push(validateStringProperty(info, 'twitter', false, 'Info')) | ||
@@ -31,3 +31,3 @@ return results | ||
function validateStringProperty(data, name, required, prefix) { | ||
function validateStringProperty (data, name, required, prefix) { | ||
if (hasStringProperty(data, name)) { | ||
@@ -40,3 +40,3 @@ return new Result(true, required, `${prefix} has ${name}`) | ||
function validateURLProperty(data, name, required, prefix) { | ||
function validateURLProperty (data, name, required, prefix) { | ||
if (hasStringProperty(data, name) && isURL(data[name])) { | ||
@@ -49,8 +49,8 @@ return new Result(true, required, `${prefix} ${name} is a valid url`) | ||
function hasStringProperty(data, name) { | ||
return data.hasOwnProperty(name) && typeof data[name] === "string" && data[name].length > 0; | ||
function hasStringProperty (data, name) { | ||
return data.hasOwnProperty(name) && typeof data[name] === 'string' && data[name].length > 0 | ||
} | ||
function isURL(value) { | ||
function isURL (value) { | ||
return url.parse(value).protocol | ||
} |
class Result { | ||
constructor(pass, required, message, error = null) { | ||
this.pass = pass; | ||
this.message = message; | ||
this.required = required; | ||
this.error = error; | ||
constructor (pass, required, message, error = null) { | ||
this.pass = pass | ||
this.message = message | ||
this.required = required | ||
this.error = error | ||
} | ||
@@ -13,14 +13,14 @@ | ||
// reset: 0m | ||
toString() { | ||
const color = "\x1B" + (this.pass ? "[32m" : (this.required ? "[31m" : "[33m")) | ||
toString () { | ||
const color = '\x1B' + (this.pass ? '[32m' : (this.required ? '[31m' : '[33m')) | ||
return [ | ||
color, | ||
this.pass ? "✔ " : "X ", | ||
this.pass ? '✔ ' : 'X ', | ||
this.message, | ||
this.error ? "\n"+this.error.toString() : "", | ||
"\x1B[0m" | ||
].join("") | ||
this.error ? '\n' + this.error.toString() : '', | ||
'\x1B[0m' | ||
].join('') | ||
} | ||
} | ||
module.exports = Result; | ||
module.exports = Result |
@@ -1,10 +0,10 @@ | ||
var audit = require("./audit") | ||
var init = require("./init") | ||
var audit = require('./audit') | ||
var init = require('./init') | ||
class UsageError extends Error {} | ||
module.exports = async function(argv) { | ||
module.exports = async function (argv) { | ||
var err = await run(argv) | ||
if (err) { | ||
console.log("\n"+err.toString()+"\n") | ||
console.log('\n' + err.toString() + '\n') | ||
if (err instanceof UsageError) { | ||
@@ -17,22 +17,22 @@ usage() | ||
async function run(argv) { | ||
async function run (argv) { | ||
if (argv.length < 1) { | ||
return new UsageError("Command is required") | ||
return new UsageError('Command is required') | ||
} | ||
var command = argv[0]; | ||
var options = argv.slice(1); | ||
switch(command) { | ||
case "audit": return await audit(options) | ||
case "init": return init(options) | ||
default: return new UsageError("Unknown command: "+command) | ||
var command = argv[0] | ||
var options = argv.slice(1) | ||
switch (command) { | ||
case 'audit': return audit(options) | ||
case 'init': return init(options) | ||
default: return new UsageError('Unknown command: ' + command) | ||
} | ||
} | ||
function usage() { | ||
function usage () { | ||
console.log([ | ||
"Usage: nomics-platform [command] [flags]", | ||
"Commands:", | ||
"\taudit [url or path to script]", | ||
"\tinit", | ||
].join("\n\t")) | ||
'Usage: nomics-platform [command] [flags]', | ||
'Commands:', | ||
'\taudit [url]', | ||
'\tinit' | ||
].join('\n\t')) | ||
} |
@@ -1,3 +0,3 @@ | ||
module.exports = function(options) { | ||
console.log("init not implemented") | ||
module.exports = function (options) { | ||
console.log('init not implemented') | ||
} |
{ | ||
"name": "nomics-platform", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Nomics Platform Toolkit", | ||
@@ -29,4 +29,13 @@ "keywords": [ | ||
"scripts": { | ||
"cli": "node bin/nomics-platform.js" | ||
"cli": "node bin/nomics-platform.js", | ||
"lint": "eslint **/*.js" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.0.1", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.13.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.8.0", | ||
"eslint-plugin-standard": "^3.1.0" | ||
} | ||
} |
# Nomics Platform Toolkit for Node.js | ||
Usage: | ||
## Installation | ||
`nomics-platform` is a Node.js package. You have multiple options for using it: | ||
Easily run with npx: | ||
``` | ||
npx nomics-platform | ||
``` | ||
Or, install globally via npm: | ||
``` | ||
npm install -g nomics-platform | ||
``` | ||
Or, install globally via yarn: | ||
``` | ||
yarn global add nomics-platform | ||
``` | ||
Or, add it as a `devDependency` in your project's `package.json` to audit as part of your `scripts` or test suite. | ||
## Usage | ||
Usage is documented within the tool and can be viewed by running it with no arguments: | ||
``` | ||
nomics-platform | ||
``` | ||
## Performing Audits on Nomics Platform APIs | ||
The `nomics-platform` tool can audit an API to determine its compatibility with the Nomics Platform. | ||
Audit a url directly: | ||
``` | ||
npx nomics-platform audit https://path-to-root-of-api/ | ||
``` |
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
Network access
Supply chain riskThis module accesses the network.
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
Network access
Supply chain riskThis module accesses the network.
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
7124
44
0
6
167