Comparing version 0.1.8 to 0.1.9
12
index.js
const url = require('url') | ||
const requester = require('./lib/requester') | ||
const simpleRequester = require('./lib/simpleRequester') | ||
const poller = require('./lib/poller') | ||
const defaultApiUrl = 'https://api.mythril.ai' | ||
const defaultApiVersion = 'v1' | ||
@@ -76,3 +78,13 @@ module.exports = (bytecode, apiKey, inputApiUrl = defaultApiUrl) => { | ||
module.exports.ApiVersion = (inputApiUrl = defaultApiUrl) => { | ||
return simpleRequester.do({url: `${inputApiUrl}/${defaultApiVersion}/version`, json: true}) | ||
} | ||
module.exports.OpenApiSpec = (inputApiUrl = defaultApiUrl) => { | ||
return simpleRequester.do({url: `${inputApiUrl}/${defaultApiVersion}/openapi.yaml`}) | ||
} | ||
module.exports.Client = Client | ||
module.exports.defaultApiUrl = url.parse(defaultApiUrl) | ||
module.exports.defaultApiHost = defaultApiUrl | ||
module.exports.defaultApiVersion = defaultApiVersion |
@@ -34,3 +34,3 @@ exports.do = (uuid, apiKey, apiUrl, pollStep = 1000, timeout = 10000) => { | ||
clearActions() | ||
reject(new Error(`Unauthorized analysis request, API key: ${this.apiKey}`)) | ||
reject(new Error(`Unauthorized analysis request, API key: ${apiKey}`)) | ||
} | ||
@@ -37,0 +37,0 @@ if (res.statusCode === 500) { |
@@ -27,3 +27,3 @@ const basePath = '/v1/analyses' | ||
[400, 'validation failed'], | ||
[401, `unauthorized analysis request, API key: ${this.apiKey}`], | ||
[401, `unauthorized analysis request, API key: ${apiKey}`], | ||
[429, 'request limit exceeded'], | ||
@@ -30,0 +30,0 @@ [500, 'received error from API server']]) |
{ | ||
"name": "armlet", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "A Mythril Platform API client.", | ||
@@ -8,3 +8,5 @@ "main": "index.js", | ||
"lint": "standard", | ||
"test": "npm run lint && mocha --reporter spec --recursive" | ||
"lint-fix": "standard --fix", | ||
"pretest": "npm run lint", | ||
"test": "mocha --reporter spec --recursive" | ||
}, | ||
@@ -18,3 +20,3 @@ "standard": { | ||
"type": "git", | ||
"url": "git+https://github.com/fgimenez/armlet.git" | ||
"url": "git+https://github.com/consensys/armlet.git" | ||
}, | ||
@@ -24,5 +26,5 @@ "author": "Federico Gimenez <federico.gimenez@gmail.com>", | ||
"bugs": { | ||
"url": "https://github.com/fgimenez/armlet/issues" | ||
"url": "https://github.com/consensys/armlet/issues" | ||
}, | ||
"homepage": "https://github.com/fgimenez/armlet#readme", | ||
"homepage": "https://github.com/consensys/armlet#readme", | ||
"devDependencies": { | ||
@@ -35,3 +37,6 @@ "chai": "^4.1.2", | ||
"standard": "^11.0.1" | ||
}, | ||
"dependencies": { | ||
"request": "^2.88.0" | ||
} | ||
} |
@@ -10,2 +10,3 @@ const analyze = require('../index') | ||
const requester = require('../lib/requester') | ||
const simpleRequester = require('../lib/simpleRequester') | ||
const poller = require('../lib/poller') | ||
@@ -17,10 +18,12 @@ | ||
const userEmail = 'my-userEmail' | ||
const apiUrl = 'http://localhost:3100' | ||
describe('#armlet', () => { | ||
afterEach(() => { | ||
requester.do.restore() | ||
poller.do.restore() | ||
}) | ||
describe('interface', () => { | ||
afterEach(() => { | ||
requester.do.restore() | ||
poller.do.restore() | ||
simpleRequester.do.restore() | ||
}) | ||
describe('interface', () => { | ||
beforeEach(() => { | ||
@@ -31,2 +34,4 @@ sinon.stub(requester, 'do') | ||
.returns(new Promise((resolve, reject) => resolve(true))) | ||
sinon.stub(simpleRequester, 'do') | ||
.returns(new Promise((resolve, reject) => resolve(true))) | ||
}) | ||
@@ -103,2 +108,26 @@ | ||
}) | ||
describe('ApiVersion', () => { | ||
it('should be a function', () => { | ||
analyze.ApiVersion.should.be.a('function') | ||
}) | ||
it('should return a thenable', () => { | ||
const result = analyze.ApiVersion(apiUrl) | ||
result.then.should.be.a('function') | ||
}) | ||
}) | ||
describe('OpenApiSpec', () => { | ||
it('should be a function', () => { | ||
analyze.OpenApiSpec.should.be.a('function') | ||
}) | ||
it('should return a thenable', () => { | ||
const result = analyze.OpenApiSpec(apiUrl) | ||
result.then.should.be.a('function') | ||
}) | ||
}) | ||
}) | ||
@@ -109,6 +138,10 @@ | ||
const issues = ['issue1', 'issue2'] | ||
const apiUrl = 'http://localhost:3100' | ||
const parsedApiUrl = url.parse(apiUrl) | ||
describe('default', () => { | ||
afterEach(() => { | ||
requester.do.restore() | ||
poller.do.restore() | ||
}) | ||
it('should chain requester and poller', async () => { | ||
@@ -163,2 +196,7 @@ sinon.stub(requester, 'do') | ||
describe('Client', () => { | ||
afterEach(() => { | ||
requester.do.restore() | ||
poller.do.restore() | ||
}) | ||
beforeEach(() => { | ||
@@ -232,4 +270,65 @@ this.instance = new Client({userEmail: userEmail, apiKey: apiKey}, apiUrl) | ||
}) | ||
describe('ApiVersion', () => { | ||
const url = `${apiUrl}/${analyze.defaultApiVersion}/version` | ||
afterEach(() => { | ||
simpleRequester.do.restore() | ||
}) | ||
it('should use simpleRequester', async () => { | ||
const result = {result: 'result'} | ||
sinon.stub(simpleRequester, 'do') | ||
.withArgs({url, json: true}) | ||
.returns(new Promise(resolve => { | ||
resolve(result) | ||
})) | ||
await analyze.ApiVersion(apiUrl).should.eventually.equal(result) | ||
}) | ||
it('should reject with simpleRequester failures', async () => { | ||
const errorMsg = 'Booom!' | ||
sinon.stub(simpleRequester, 'do') | ||
.withArgs({url, json: true}) | ||
.returns(new Promise((resolve, reject) => { | ||
reject(new Error(errorMsg)) | ||
})) | ||
await analyze.ApiVersion(apiUrl).should.be.rejectedWith(Error, errorMsg) | ||
}) | ||
}) | ||
describe('OpenApiSpec', () => { | ||
const url = `${apiUrl}/${analyze.defaultApiVersion}/openapi.yaml` | ||
afterEach(() => { | ||
simpleRequester.do.restore() | ||
}) | ||
it('should use simpleRequester', async () => { | ||
const result = 'result' | ||
sinon.stub(simpleRequester, 'do') | ||
.withArgs({url}) | ||
.returns(new Promise(resolve => { | ||
resolve(result) | ||
})) | ||
await analyze.OpenApiSpec(apiUrl).should.eventually.equal(result) | ||
}) | ||
it('should reject with simpleRequester failures', async () => { | ||
const errorMsg = 'Booom!' | ||
sinon.stub(simpleRequester, 'do') | ||
.withArgs({url}) | ||
.returns(new Promise((resolve, reject) => { | ||
reject(new Error(errorMsg)) | ||
})) | ||
await analyze.OpenApiSpec(apiUrl).should.be.rejectedWith(Error, errorMsg) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
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
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
35646
20
817
1
1
1
+ Addedrequest@^2.88.0
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)