blockscore
Advanced tools
Comparing version 1.0.0 to 1.0.1
146
lib/main.js
"use strict"; | ||
var http = require('http'); | ||
var querystring = require('querystring'); | ||
var https = require('https'); | ||
var fs = require('fs'); | ||
@@ -12,11 +12,11 @@ function setup_response_handler(req, callback) { | ||
req.on('response', | ||
function (res) { | ||
function(res) { | ||
var response = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', | ||
function (chunk) { | ||
function(chunk) { | ||
response += chunk; | ||
}); | ||
res.on('end', | ||
function () { | ||
function() { | ||
var err = null; | ||
@@ -39,3 +39,3 @@ try { | ||
}); | ||
req.on('error', function (error) { | ||
req.on('error', function(error) { | ||
callback(error); | ||
@@ -45,37 +45,62 @@ }); | ||
module.exports = function(api_key){ | ||
var auth = 'Basic ' + new Buffer(api_key + ":").toString('base64'); | ||
var get_ca = (function() { | ||
var ca = []; | ||
function serialize(obj, prefix) { | ||
var str = []; | ||
for(var p in obj) { | ||
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; | ||
str.push(typeof v == "object" ? | ||
serialize(v, k) : | ||
encodeURIComponent(k) + "=" + encodeURIComponent(v)); | ||
return function get_ca(callback) { | ||
// return cached ca | ||
if (ca.length) { | ||
return process.nextTick(function() { | ||
callback(null, ca); | ||
}); | ||
} | ||
// retrieve ca from disk and cache it | ||
fs.readFile(__dirname + '/../api.blockscore.com.pem', 'utf8', function(err, data) { | ||
if (err) return callback(err); | ||
var cert = []; | ||
var lines = data.split("\n"); | ||
for (var i in lines) { | ||
cert.push(lines[i]); | ||
if (lines[i].match(/-END CERTIFICATE-/)) { | ||
ca.push(cert.join("\n")); | ||
cert = []; | ||
} | ||
} | ||
return str.join("&"); | ||
} | ||
callback(null, ca); | ||
}); | ||
function _request(method, path, data, callback){ | ||
}; | ||
var request_data = serialize(data); | ||
})(); | ||
var request_options = { | ||
host: 'api.blockscore.com', | ||
port: '443', | ||
path: path, | ||
method: method, | ||
headers: { | ||
'Authorization': auth, | ||
'Accept': 'application/json', | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': request_data.length | ||
} | ||
}; | ||
module.exports = function(api_key) { | ||
var auth = 'Basic ' + new Buffer(api_key + ":").toString('base64'); | ||
var req = http.request(request_options); | ||
setup_response_handler(req, callback); | ||
req.write(request_data); | ||
req.end(); | ||
function _request(method, path, data, callback) { | ||
get_ca(function(err, ca) { | ||
if (err) return callback(err); | ||
var request_data = JSON.stringify(data); | ||
var request_options = { | ||
host: 'api.blockscore.com', | ||
port: '443', | ||
path: path, | ||
method: method, | ||
headers: { | ||
'Authorization': auth, | ||
'Accept': 'application/vnd.blockscore+json;version=2', | ||
'Content-Type': 'application/json', | ||
'Content-Length': request_data.length | ||
}, | ||
ca: ca, | ||
agent: false | ||
}; | ||
var req = https.request(request_options); | ||
setup_response_handler(req, callback); | ||
req.write(request_data); | ||
req.end(); | ||
}); | ||
} | ||
@@ -88,30 +113,39 @@ | ||
function get(path, data, callback) { | ||
_request('GET', path, data, callback); | ||
_request('GET', path, data, callback); | ||
} | ||
function del(path, data, callback) { | ||
_request('DELETE', path, data, callback); | ||
_request('DELETE', path, data, callback); | ||
} | ||
function normalizeArguments() { | ||
var args = arguments[0]; | ||
if(typeof args[0] == 'object' && typeof args[1] == 'function' && !args[2]) | ||
return { count: args[0].count, offset: args[0].offset, cb: args[1] }; | ||
else | ||
return { count: args[0], offset: args[1], cb: args[2] }; | ||
var args = arguments[0]; | ||
if (typeof args[0] == 'object' && typeof args[1] == 'function' && !args[2]) | ||
return { | ||
count: args[0].count, | ||
offset: args[0].offset, | ||
cb: args[1] | ||
}; | ||
else | ||
return { | ||
count: args[0], | ||
offset: args[1], | ||
cb: args[2] | ||
}; | ||
} | ||
return { | ||
verifications: { | ||
create: function (data, cb) { | ||
post("/v1/verifications", data, cb); | ||
create: function(data, cb) { | ||
post("/verifications", data, cb); | ||
}, | ||
retrieve: function (verification_id, cb) { | ||
retrieve: function(verification_id, cb) { | ||
if (!(verification_id && typeof verification_id === 'string')) { | ||
cb("verification_id required"); | ||
return cb(new Error("verification_id required")); | ||
} | ||
get("/v1/verifications/" + verification_id, {}, cb); | ||
get("/verifications/" + encodeURIComponent(verification_id), {}, cb); | ||
}, | ||
list: function (count, offset, cb) { | ||
list: function(count, offset, cb) { | ||
var nArgs = normalizeArguments(arguments); | ||
get("/v1/verifications", { | ||
get("/verifications", { | ||
count: nArgs.count, | ||
@@ -121,4 +155,16 @@ offset: nArgs.offset | ||
} | ||
}, | ||
questions: { | ||
create: function(verification_id, cb) { | ||
if (!(verification_id && typeof verification_id === 'string')) { | ||
return cb(new Error("verification_id required")); | ||
} | ||
var data = { verification_id: verification_id }; | ||
post("/questions", data, cb); | ||
}, | ||
score: function(data, cb) { | ||
post("/questions/score", data, cb); | ||
} | ||
} | ||
}; | ||
} | ||
}; |
{ | ||
"author":"John Backus <john@blockscore.com>", | ||
"name":"blockscore", | ||
"description":"Block Score API wrapper", | ||
"keywords":[ | ||
"blockscore", | ||
"block score", | ||
"kyc", | ||
"know your customer", | ||
"bitcoin", | ||
"verification" | ||
], | ||
"version":"1.0.0", | ||
"homepage":"https://github.com/blockscore/blockscore-node", | ||
"repository":{ | ||
"type":"git", | ||
"url":"git://github.com/blockscore/blockscore-node.git" | ||
}, | ||
"engines":{ | ||
"node":">= v0.4.0" | ||
}, | ||
"main":"lib/main.js", | ||
"dependencies":{ | ||
"vows":"~0.7.0" | ||
}, | ||
"devDependencies":{ | ||
} | ||
} | ||
"author": "John Backus <john@blockscore.com>", | ||
"name": "blockscore", | ||
"description": "Block Score API wrapper", | ||
"keywords": [ | ||
"blockscore", | ||
"block score", | ||
"kyc", | ||
"know your customer", | ||
"bitcoin", | ||
"verification" | ||
], | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/blockscore/blockscore-node", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/blockscore/blockscore-node.git" | ||
}, | ||
"engines": { | ||
"node": ">= v0.4.0" | ||
}, | ||
"main": "./lib/main.js", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"vows": "~0.7.0" | ||
}, | ||
"scripts": { | ||
"test": "vows test/*.js" | ||
} | ||
} |
121
README.md
@@ -1,4 +0,119 @@ | ||
blockscore-node | ||
=============== | ||
# blockscore-node | ||
Blockscore.com API for node.js | ||
This is the official library for Node.JS clients of the BlockScore API. [Click here to read the full documentation](https://manage.blockscore.com/docs). | ||
## Install | ||
Via npm: | ||
```javascript | ||
npm install blockscore | ||
``` | ||
## Getting Started | ||
### Initializing BlockScore | ||
```javascript | ||
var blockscore = require('blockscore')('your api key') | ||
``` | ||
## Verifications | ||
### List all verifications | ||
```javascript | ||
blockscore.verifications.list({}, callback); | ||
``` | ||
### List `5` verifications | ||
```javascript | ||
blockscore.verifications.list({ | ||
count: 5 | ||
}, callback); | ||
``` | ||
### View a verification by ID | ||
```javascript | ||
blockscore.verifications.retrieve(verification_id, callback); | ||
``` | ||
### Create a new verification | ||
```javascript | ||
blockscore.verifications.create({ | ||
type: "us_citizen", | ||
date_of_birth: '1993-08-23', | ||
identification: { | ||
ssn: "0000" | ||
}, | ||
address: { | ||
street1: "1 Infinite Loop", | ||
city: "Cupertino", | ||
state: "CA", | ||
postal_code: "95014", | ||
country_code: "US" | ||
}, | ||
name: { | ||
first: "Alain", | ||
last: "Meier" | ||
} | ||
}, callback); | ||
``` | ||
## Question Sets | ||
### Create a new question set | ||
```javascript | ||
blockscore.questions.create(verification_id, callback); | ||
``` | ||
### Score a question set | ||
```javascript | ||
var data = { | ||
verification_id: response.verification_id, | ||
question_set_id: response.question_set_id, | ||
answers: [ | ||
{ | ||
question_id: 1, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 2, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 3, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 4, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 5, | ||
answer_id: 1 | ||
} | ||
] | ||
}; | ||
blockscore.questions.score(data, callback); | ||
``` | ||
## Contributing to BlockScore | ||
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet. | ||
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it. | ||
* Fork the project. | ||
* Start a feature/bugfix branch. | ||
* Commit and push until you are happy with your contribution. | ||
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. | ||
## Copyright | ||
Copyright (c) 2014 BlockScore. See LICENSE.txt for | ||
further details. | ||
@@ -8,4 +8,4 @@ var vows = require('vows'), | ||
if (!api_key) { | ||
sys.puts('To run vows, you must have a BLOCKSCORE_API environment variable with a test api key'); | ||
process.exit(2) | ||
sys.puts('To run vows, you must have a BLOCKSCORE_API environment variable with a test api key'); | ||
process.exit(2) | ||
} | ||
@@ -16,65 +16,117 @@ | ||
vows.describe("Verifications API").addBatch({ | ||
'Create verification' : { | ||
topic: function() { | ||
blockscore.verifications.create({ | ||
verification: { | ||
type: "U.S. Citizen", | ||
date_of_birth: '1993-01-13', | ||
ssn: "000-42-4242", | ||
address: { | ||
street1: "3515 Woodridge Lane", | ||
city: "Memphis", | ||
state: "TN", | ||
postal_code: "38115", | ||
country: "United States" | ||
}, | ||
name: { | ||
first: "David", | ||
last: "Brooks" | ||
} | ||
} | ||
}, this.callback); | ||
'Create verification': { | ||
topic: function() { | ||
blockscore.verifications.create({ | ||
type: "us_citizen", | ||
date_of_birth: '1993-01-13', | ||
identification: { | ||
ssn: "0000" | ||
}, | ||
'returns a verification' : function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.isDefined(response.id); | ||
assert.isDefined(response.created_at); | ||
assert.isDefined(response.updated_at); | ||
assert.equal(response.status, 'pending'); | ||
address: { | ||
street1: "3515 Woodridge Lane", | ||
city: "Memphis", | ||
state: "TN", | ||
postal_code: "38115", | ||
country_code: "US" | ||
}, | ||
'retrieve a verification' : { | ||
topic: function(create_err, verification) { | ||
blockscore.verifications.retrieve(verification.id, this.callback); | ||
}, | ||
'Got a verification' : function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.isDefined(response.id); | ||
}, | ||
} | ||
name: { | ||
first: "David", | ||
last: "Brooks" | ||
} | ||
}, this.callback); | ||
}, | ||
'Listing verifications' : { | ||
topic: [], | ||
'Listing without count or offset': { | ||
topic: function (arr) { | ||
blockscore.verifications.list({},this.callback); | ||
}, | ||
'when listed with no parameters': function (err,result) { | ||
assert.instanceOf(result,Array); | ||
assert.isNotZero(result.length); | ||
} | ||
'returns a verification': function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.isDefined(response.id); | ||
assert.isDefined(response.created_at); | ||
assert.isDefined(response.updated_at); | ||
assert.equal(response.status, 'valid'); | ||
}, | ||
'retrieve a verification': { | ||
topic: function(create_err, verification) { | ||
blockscore.verifications.retrieve(verification.id, this.callback); | ||
}, | ||
'Got a verification': function(err, response) { | ||
assert.isNull(err); | ||
assert.isDefined(response); | ||
assert.isDefined(response.id); | ||
}, | ||
}, | ||
'create questions': { | ||
topic: function(create_err, verification) { | ||
blockscore.questions.create(verification.id, this.callback); | ||
}, | ||
'Got questions': function(err, response) { | ||
assert.ifError(err); | ||
assert.ok(response.verification_id); | ||
assert.ok(response.question_set_id); | ||
assert.ok(Array.isArray(response.questions)); | ||
assert.ok(Array.isArray(response.questions[0].answers)); | ||
}, | ||
'score questions': { | ||
topic: function(err, response) { | ||
var data = { | ||
verification_id: response.verification_id, | ||
question_set_id: response.question_set_id, | ||
answers: [ | ||
{ | ||
question_id: 1, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 2, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 3, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 4, | ||
answer_id: 1 | ||
}, | ||
{ | ||
question_id: 5, | ||
answer_id: 1 | ||
} | ||
] | ||
}; | ||
blockscore.questions.score(data, this.callback); | ||
}, | ||
'Listing with count of 1': { | ||
topic: function(arr){ | ||
blockscore.verifications.list({count:1},this.callback); | ||
}, | ||
'when given count of one': function(err,result){ | ||
assert.isNotZero(result.length); | ||
assert.isTrue(result.length === 1); | ||
assert.isDefined(result[0].id); | ||
} | ||
'Got score': function(err, response) { | ||
assert.ifError(err); | ||
assert.ok(response.question_set_id); | ||
assert.ok(typeof response.score == 'number'); | ||
} | ||
} | ||
} | ||
}).export(module, {error: false}); | ||
}, | ||
'Listing verifications': { | ||
topic: [], | ||
'Listing without count or offset': { | ||
topic: function(arr) { | ||
blockscore.verifications.list({}, this.callback); | ||
}, | ||
'when listed with no parameters': function(err, result) { | ||
assert.instanceOf(result, Array); | ||
assert.isNotZero(result.length); | ||
} | ||
}, | ||
'Listing with count of 1': { | ||
topic: function(arr) { | ||
blockscore.verifications.list({ | ||
count: 1 | ||
}, this.callback); | ||
}, | ||
'when given count of one': function(err, result) { | ||
assert.isNotZero(result.length); | ||
assert.isTrue(result.length === 1); | ||
assert.isDefined(result[0].id); | ||
} | ||
} | ||
} | ||
}).export(module, { | ||
error: false | ||
}); |
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 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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
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
No License Found
License(Experimental) License information could not be found
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
59286
0
9
0
272
0
120
1
2
- Removedvows@~0.7.0
- Removeddiff@1.0.8(transitive)
- Removedeyes@0.1.8(transitive)
- Removedvows@0.7.0(transitive)