synapsepay
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,7 +0,9 @@ | ||
var request = require('superagent'); | ||
'use strict'; | ||
var APIClient = { | ||
const request = require('superagent'); | ||
delete: function(url, config, callback) { | ||
var headers = generateHeaders(config); | ||
const APIClient = { | ||
delete(url, config, callback) { | ||
const headers = generateHeaders(config); | ||
request | ||
@@ -19,4 +21,4 @@ .delete(url) | ||
get: function(url, config, callback) { | ||
var headers = generateHeaders(config); | ||
get(url, config, callback) { | ||
const headers = generateHeaders(config); | ||
request | ||
@@ -35,5 +37,20 @@ .get(url) | ||
patch: function(url, config, payload, callback) { | ||
var headers = generateHeaders(config); | ||
// Simple get request w/out query | ||
getById(url, config, callback) { | ||
const headers = generateHeaders(config); | ||
request | ||
.get(url) | ||
.set(headers) | ||
.end(function(err, res) { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(err, res.body); | ||
} | ||
}); | ||
}, | ||
patch(url, config, payload, callback) { | ||
const headers = generateHeaders(config); | ||
request | ||
.patch(url) | ||
@@ -47,3 +64,3 @@ .set(headers) | ||
if (res.status !== 200) { | ||
var acceptedError = { | ||
const acceptedError = { | ||
status: res.status, | ||
@@ -60,4 +77,4 @@ body: res.body | ||
post: function(url, config, payload, callback) { | ||
var headers = generateHeaders(config); | ||
post(url, config, payload, callback) { | ||
const headers = generateHeaders(config); | ||
request | ||
@@ -72,3 +89,3 @@ .post(url) | ||
if (res.status !== 200) { | ||
var acceptedError = { | ||
const acceptedError = { | ||
status: res.status, | ||
@@ -94,6 +111,6 @@ body: res.body | ||
*/ | ||
var generateHeaders = function(config) { | ||
var oauth_key = ''; | ||
var ip_address = ''; | ||
var fingerprint = ''; | ||
const generateHeaders = (config) => { | ||
let oauth_key = ''; | ||
let ip_address = ''; | ||
let fingerprint = ''; | ||
if (config.oauth_key) { | ||
@@ -108,3 +125,3 @@ oauth_key = config.oauth_key; | ||
} | ||
var headers = { | ||
const headers = { | ||
'X-SP-GATEWAY': config.client.client_id + '|' + config.client.client_secret, | ||
@@ -111,0 +128,0 @@ 'X-SP-USER': oauth_key + '|' + fingerprint, |
@@ -1,2 +0,10 @@ | ||
var Clients = function(clientId, clientSecret, isProduction) { | ||
'use strict'; | ||
/** | ||
* @param clientId [String] | ||
* @param clientSecret [String] | ||
* @param isProduction [boolean] | ||
**/ | ||
const Clients = function(clientId, clientSecret, isProduction) { | ||
this.client_id = clientId; | ||
@@ -3,0 +11,0 @@ this.client_secret = clientSecret; |
@@ -1,20 +0,22 @@ | ||
var request = require('superagent'); | ||
var mime = require('mime'); | ||
var CryptoJS = require('crypto-js'); | ||
var _ = require('underscore')._; | ||
'use strict'; | ||
const request = require('superagent'); | ||
const mime = require('mime'); | ||
const CryptoJS = require('crypto-js'); | ||
const _ = require('underscore')._; | ||
const os = require('os'); | ||
var Helpers = { | ||
const Helpers = { | ||
urlToBase64: function(url, callback) { | ||
urlToBase64(url, callback) { | ||
request | ||
.get(url) | ||
.buffer() | ||
.end(function(err, res) { | ||
.end((err, res) => { | ||
if (err) { | ||
callback(new Error('Could not download file.')); | ||
} else { | ||
var fileType = res.headers['content-type']; | ||
var base64 = new Buffer(res.body, 'binary').toString('base64'); | ||
var dataURI = 'data:' + fileType + ';base64,' + base64; | ||
const fileType = res.headers['content-type']; | ||
const base64 = new Buffer(res.body, 'binary').toString('base64'); | ||
const dataURI = 'data:' + fileType + ';base64,' + base64; | ||
callback(null, dataURI); | ||
@@ -25,12 +27,12 @@ } | ||
fileToBase64: function(filePath, callback) { | ||
var fs = require('fs'); | ||
fileToBase64(filePath, callback) { | ||
const fs = require('fs'); | ||
fs.statSync(filePath); | ||
fs.readFile(filePath, function(err, original_data) { | ||
fs.readFile(filePath, (err, original_data) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
var fileType = mime.lookup(filePath); | ||
var base64 = new Buffer(original_data, 'binary').toString('base64'); | ||
var dataURI = 'data:' + fileType + ';base64,' + base64; | ||
const fileType = mime.lookup(filePath); | ||
const base64 = new Buffer(original_data, 'binary').toString('base64'); | ||
const dataURI = 'data:' + fileType + ';base64,' + base64; | ||
callback(null, dataURI); | ||
@@ -41,9 +43,9 @@ } | ||
verifyHMAC: function(client, givenHMAC, object_id) { | ||
var raw = String(object_id) + '+' + String(client.client_id); | ||
var hashed = CryptoJS.HmacSHA1(raw, client.client_secret); | ||
verifyHMAC(client, givenHMAC, object_id) { | ||
const raw = String(object_id) + '+' + String(client.client_id); | ||
const hashed = CryptoJS.HmacSHA1(raw, client.client_secret); | ||
return (hashed === given_hmac); | ||
}, | ||
getUserIP: function() { | ||
getUserIP() { | ||
return _.chain(os.networkInterfaces()) | ||
@@ -50,0 +52,0 @@ .values() |
@@ -1,4 +0,6 @@ | ||
var APIClient = require('./APIClient.js'); | ||
'use strict'; | ||
var Node = function(user, json) { | ||
const APIClient = require('./APIClient.js'); | ||
const Node = function(user, json) { | ||
this.user = user; | ||
@@ -13,3 +15,5 @@ this.json = json; | ||
this.json = json; | ||
callback(null, this); | ||
if (callback) { | ||
callback(null, this); | ||
} | ||
} | ||
@@ -19,7 +23,8 @@ }; | ||
Node.prototype.update = function(payload, callback) { | ||
var url = this.json._links.self.href; | ||
var self = this; | ||
var config = this.getAPIConfig(); | ||
const url = this.json._links.self.href; | ||
const self = this; | ||
const config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, function(err, json) { | ||
self.updateJSON(err, json, callback); | ||
self.json = json; | ||
callback(err, json); | ||
}); | ||
@@ -29,5 +34,5 @@ }; | ||
Node.prototype.delete = function(callback) { | ||
var url = this.json._links.self.href; | ||
var self = this; | ||
var config = this.getAPIConfig(); | ||
const url = this.json._links.self.href; | ||
const self = this; | ||
const config = this.getAPIConfig(); | ||
APIClient.delete(url, config, function(err, json) { | ||
@@ -34,0 +39,0 @@ self.updateJSON(err, json, callback); |
@@ -1,8 +0,16 @@ | ||
var APIClient = require('./APIClient.js'); | ||
var Node = require('./Node.js'); | ||
'use strict'; | ||
var Nodes = { | ||
const APIClient = require('./APIClient.js'); | ||
const Node = require('./Node.js'); | ||
get: function(user, options, callback) { | ||
var config = { | ||
const Nodes = { | ||
/** Get all nodes or get info on single node (if node_id provided) | ||
* @param user [Object] | ||
* @param options [Object] : can be null (if getting all nodes) or | ||
{ _id: node_id } (if getting info on single node) | ||
* @param callback [function(error, nodeResponseObject)] | ||
**/ | ||
get(user, options, callback) { | ||
const config = { | ||
client: user.client, | ||
@@ -13,4 +21,5 @@ ip_address: user.ip_address, | ||
} | ||
var url = user.json._links.self.href + '/nodes'; | ||
let url = user.json._links.self.href + '/nodes'; | ||
if (options) { | ||
// if node_id provided | ||
if (options._id) { | ||
@@ -20,3 +29,3 @@ url += '/' + options._id; | ||
} | ||
APIClient.get(url, config, function(err, json) { | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
@@ -34,4 +43,10 @@ callback(err); | ||
create: function(user, payload, callback) { | ||
var config = { | ||
/** Create a node associated w/ a user | ||
* @param user [Object] | ||
* @param payload [Object] : different depending on node type | ||
Look at docs for details on format (https://docs.synapsepay.com/docs/add-ach-us-node) | ||
@param callback -> function(error, nodeResponseObject) | ||
**/ | ||
create(user, payload, callback) { | ||
const config = { | ||
client: user.client, | ||
@@ -42,9 +57,9 @@ ip_address: user.ip_address, | ||
}; | ||
var url = user.json._links.self.href + '/nodes'; | ||
APIClient.post(url, config, payload, function(err, json) { | ||
const url = user.json._links.self.href + '/nodes'; | ||
APIClient.post(url, config, payload, (err, json) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
var nodes = []; | ||
for (var i = 0; i < json.nodes.length; i++) { | ||
const nodes = []; | ||
for (let i = 0; i < json.nodes.length; i++) { | ||
nodes.push(new Node(user, json.nodes[i])); | ||
@@ -51,0 +66,0 @@ } |
@@ -1,4 +0,6 @@ | ||
var APIClient = require('./APIClient.js'); | ||
'use strict'; | ||
var Transaction = function(node, json) { | ||
const APIClient = require('./APIClient.js'); | ||
const Transaction = function(node, json) { | ||
this.node = node; | ||
@@ -13,3 +15,5 @@ this.json = json; | ||
this.json = json.trans; | ||
callback(null, this); | ||
if (callback) { | ||
callback(null, this); | ||
} | ||
} | ||
@@ -28,5 +32,5 @@ }; | ||
Transaction.prototype.update = function(payload, callback) { | ||
var url = this.json._links.self.href; | ||
var config = this.generateConfig(); | ||
var self = this; | ||
const url = this.json._links.self.href; | ||
const config = this.generateConfig(); | ||
const self = this; | ||
APIClient.patch(url, config, payload, function(err, json) { | ||
@@ -38,4 +42,4 @@ self.updateJSON(err, json, callback); | ||
Transaction.prototype.delete = function(callback) { | ||
var url = this.json._links.self.href; | ||
var config = { | ||
const url = this.json._links.self.href; | ||
const config = { | ||
oauth_key: this.node.user.oauth_key, | ||
@@ -46,3 +50,3 @@ fingerprint: this.node.user.fingerprint, | ||
}; | ||
var self = this; | ||
const self = this; | ||
APIClient.delete(url, config, function(err, json) { | ||
@@ -49,0 +53,0 @@ self.updateJSON(err, json, callback); |
@@ -1,8 +0,10 @@ | ||
var APIClient = require('./APIClient.js'); | ||
var Transaction = require('./Transaction.js'); | ||
'use strict'; | ||
var Transactions = { | ||
const APIClient = require('./APIClient.js'); | ||
const Transaction = require('./Transaction.js'); | ||
get: function(node, options, callback) { | ||
var config = { | ||
const Transactions = { | ||
get(node, options, callback) { | ||
const config = { | ||
client: node.user.client, | ||
@@ -13,7 +15,7 @@ fingerprint: node.user.fingerprint, | ||
}; | ||
var url = node.json._links.self.href + '/trans'; | ||
let url = node.json._links.self.href + '/trans'; | ||
if (options) { | ||
if (options._id) { | ||
url += '/' + options._id; | ||
APIClient.get(url, config, function(err, json) { | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
@@ -26,3 +28,3 @@ callback(err); | ||
} else { | ||
APIClient.get(url, config, function(err, json) { | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
@@ -36,3 +38,3 @@ callback(err); | ||
} else { | ||
APIClient.get(url, config, function(err, json) { | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
@@ -47,4 +49,4 @@ callback(err); | ||
create: function(node, payload, callback) { | ||
var config = { | ||
create(node, payload, callback) { | ||
const config = { | ||
client: node.user.client, | ||
@@ -55,4 +57,4 @@ fingerprint: node.user.fingerprint, | ||
}; | ||
var url = node.json._links.self.href + '/trans'; | ||
APIClient.post(url, config, payload, function(err, json) { | ||
const url = node.json._links.self.href + '/trans'; | ||
APIClient.post(url, config, payload, (err, json) => { | ||
if (err) { | ||
@@ -59,0 +61,0 @@ callback(err); |
@@ -1,4 +0,6 @@ | ||
var APIClient = require('./APIClient.js'); | ||
'use strict'; | ||
var User = function(client, json, ip_address, fingerprint, callback) { | ||
const APIClient = require('./APIClient.js'); | ||
const User = function(client, json, ip_address, fingerprint, callback) { | ||
this.client = client; | ||
@@ -12,7 +14,7 @@ this.json = json; | ||
User.prototype.grabOauthKey = function(callback) { | ||
var self = this; | ||
var payload = { | ||
const self = this; | ||
const payload = { | ||
refresh_token: this.json.refresh_token | ||
}; | ||
var config = { | ||
const config = { | ||
client: this.client, | ||
@@ -22,4 +24,4 @@ fingerprint: this.fingerprint, | ||
}; | ||
var url = this.client.baseUrl + '/oauth/'+ this.json['_id']; | ||
APIClient.post(url, config, payload, function(err, json) { | ||
const url = this.client.baseUrl + '/oauth/'+ this.json['_id']; | ||
APIClient.post(url, config, payload, (err, json) => { | ||
if (err) { | ||
@@ -44,6 +46,6 @@ callback(err); | ||
User.prototype.update = function(payload, callback) { | ||
var url = this.json._links.self.href; | ||
var self = this; | ||
var config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, function(err, json) { | ||
const url = this.json._links.self.href; | ||
const self = this; | ||
const config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, (err, json) => { | ||
self.updateJSON(err, json, callback); | ||
@@ -55,6 +57,6 @@ }); | ||
User.prototype.addDocuments = function(payload, callback) { | ||
var url = this.json._links.self.href; | ||
var self = this; | ||
var config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, function(err, json) { | ||
const url = this.json._links.self.href; | ||
const self = this; | ||
const config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, (err, json) => { | ||
self.updateJSON(err, json, callback); | ||
@@ -66,6 +68,6 @@ }); | ||
User.prototype.addDoc = function(payload, callback) { | ||
var url = this.json._links.self.href; | ||
var self = this; | ||
var config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, function(err, json) { | ||
const url = this.json._links.self.href; | ||
const self = this; | ||
const config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, (err, json) => { | ||
self.updateJSON(err, json, callback); | ||
@@ -77,6 +79,6 @@ }); | ||
User.prototype.answerKBA = function(payload, callback) { | ||
var url = this.json._links.self.href; | ||
var self = this; | ||
var config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, function(err, res) { | ||
const url = this.json._links.self.href; | ||
const self = this; | ||
const config = this.getAPIConfig(); | ||
APIClient.patch(url, config, payload, (err, res) => { | ||
self.updateJSON(err, res, callback); | ||
@@ -83,0 +85,0 @@ }); |
@@ -1,13 +0,36 @@ | ||
var APIClient = require('./APIClient.js'); | ||
var User = require('./User.js'); | ||
'use strict'; | ||
var Users = { | ||
const APIClient = require('./APIClient.js'); | ||
const User = require('./User.js'); | ||
const Helpers = require('./Helpers.js'); | ||
get: function(client, options, callback) { | ||
var config = { | ||
const Users = { | ||
/** Gets all users or one user (if given userId) | ||
* @param client [object] : contains client_id, client_secret, is_production | ||
* @param options [object] e.g. (if getting one user) | ||
const options = { | ||
_id: USER_ID, | ||
fingerprint: USER_FINGERPRINT, | ||
ip_address: Helpers.getUserIP() | ||
}; | ||
e.g. (if getting all users) | ||
const options = { | ||
page: '', //optional | ||
per_page: '', //optional | ||
query: '' //optional | ||
}; | ||
* @param callback [function] | ||
e.g. function(error, userObj) { | ||
// do something | ||
} | ||
**/ | ||
get(client, options, callback) { | ||
const config = { | ||
'client': client | ||
}; | ||
var url = `${client.baseUrl}/users`; | ||
let url = `${client.baseUrl}/users`; | ||
if (options) { | ||
// if user_id provided | ||
if (options._id) { | ||
@@ -22,3 +45,3 @@ if (!options.fingerprint) { | ||
url += '/' + String(options._id); | ||
APIClient.get(url, config, function(err, json) { | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
@@ -48,3 +71,3 @@ callback(err); | ||
else { | ||
APIClient.get(url, config, function(err, json) { | ||
APIClient.get(url, config, (err, json) => { | ||
callback(err, json); | ||
@@ -55,10 +78,38 @@ }); | ||
create: function(client, fingerprint, ip_address, payload, callback) { | ||
var config = { | ||
/** Retrieves a user by ID | ||
* @param client [object] : contains client_id, client_secret, is_production | ||
* @param userId [String] | ||
* @param callback [function(err, userObj)] | ||
**/ | ||
getUserById(client, userId, callback) { | ||
const config = { | ||
client: client, | ||
ip_address: Helpers.getUserIP() | ||
}; | ||
let url = `${client.baseUrl}/users/${userId}`; | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
callback(new Error('Unable to find user')); | ||
} else { | ||
callback(err, json); | ||
} | ||
}); | ||
}, | ||
/** Create a user | ||
* @param client [Object] | ||
* @param fingerprint [String] : the device that is trying to access a user's information | ||
* @param ip_address [String] : ip address of user | ||
* @param payload [Object] : Look at docs for format (https://docs.synapsepay.com/docs/create-a-user) | ||
* @param callback [function(error, userResponseObj)] | ||
**/ | ||
create(client, fingerprint, ip_address, payload, callback) { | ||
const config = { | ||
client: client, | ||
fingerprint: fingerprint, | ||
ip_address: ip_address | ||
}; | ||
var url = client.baseUrl + '/users'; | ||
APIClient.post(url, config, payload, function(err, json) { | ||
const url = client.baseUrl + '/users'; | ||
APIClient.post(url, config, payload, (err, json) => { | ||
if (err) { | ||
@@ -65,0 +116,0 @@ callback(err); |
{ | ||
"name": "synapsepay", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Node.js Library for SynapsePay API v3.x Rest", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,7 +5,7 @@ | ||
```javascript | ||
var SynapsePay = require('synapsepay'); | ||
var Clients = SynapsePay.Clients; | ||
var Helpers = SynapsePay.Helpers; | ||
const SynapsePay = require('synapsepay'); | ||
const Clients = SynapsePay.Clients; | ||
const Helpers = SynapsePay.Helpers; | ||
var client = new Clients( | ||
const client = new Clients( | ||
// client id should be stored as an environment variable | ||
@@ -26,3 +26,3 @@ process.env.CLIENT_ID, | ||
var callback = function(err, resp) { | ||
const callback = function(err, resp) { | ||
// DO SOMETHING | ||
@@ -38,3 +38,3 @@ }; | ||
var Users = SynapsePay.Users; | ||
const Users = SynapsePay.Users; | ||
@@ -44,3 +44,3 @@ | ||
var createPayload = { | ||
const createPayload = { | ||
logins: [ | ||
@@ -66,3 +66,3 @@ { | ||
var user; | ||
let user; | ||
@@ -84,3 +84,3 @@ Users.create( | ||
var options = { | ||
let options = { | ||
_id: USER_ID, | ||
@@ -101,5 +101,17 @@ fingerprint: USER_FINGERPRINT, | ||
// Get User By ID (does same as above, but simpler and requires less input) | ||
Users.getUserById( | ||
client, | ||
userId, | ||
function(err, userObj) { | ||
// error or user object | ||
user = userObj; | ||
} | ||
); | ||
// Get All Users | ||
var options = { | ||
let options = { | ||
page: '', | ||
@@ -110,3 +122,3 @@ per_page: '', | ||
var users; | ||
let users; | ||
@@ -125,3 +137,3 @@ Users.get( | ||
var addDocsPayload = { | ||
const addDocsPayload = { | ||
documents: [ | ||
@@ -179,3 +191,3 @@ { | ||
var kbaPayload = { | ||
const kbaPayload = { | ||
documents: [{ | ||
@@ -211,3 +223,3 @@ id: BASE_DOCUMENT_ID, | ||
var userUpdatePayload = { | ||
const userUpdatePayload = { | ||
documents: [{ | ||
@@ -235,3 +247,3 @@ id: BASE_DOCUMENT_ID, | ||
var Nodes = SynapsePay.Nodes; | ||
const Nodes = SynapsePay.Nodes; | ||
@@ -241,3 +253,3 @@ | ||
var nodes; | ||
let nodes; | ||
@@ -259,3 +271,3 @@ Nodes.get( | ||
{ | ||
_id: USER_ID | ||
_id: NODE_ID | ||
}, | ||
@@ -271,3 +283,3 @@ function(err, nodeResponse) { | ||
var synapseNodePayload = { | ||
const synapseNodePayload = { | ||
type: 'SYNAPSE-US', | ||
@@ -294,3 +306,3 @@ info: { | ||
var loginPayload = { | ||
const loginPayload = { | ||
type: 'ACH-US', | ||
@@ -304,3 +316,3 @@ info: { | ||
var mfa; | ||
let mfa; | ||
@@ -319,3 +331,3 @@ Nodes.create( | ||
var mfaPayload = { | ||
const mfaPayload = { | ||
access_token: mfa.access_token, | ||
@@ -338,3 +350,3 @@ // the user's answer | ||
var achPayload = { | ||
const achPayload = { | ||
type: 'ACH-US', | ||
@@ -368,3 +380,3 @@ info: { | ||
var microPayload = { | ||
const microPayload = { | ||
micro: [0.1, 0.1] | ||
@@ -398,3 +410,3 @@ }; | ||
var Transactions = SynapsePay.Transactions; | ||
const Transactions = SynapsePay.Transactions; | ||
@@ -404,3 +416,3 @@ | ||
var createPayload = { | ||
const createPayload = { | ||
to: { | ||
@@ -430,3 +442,3 @@ type: 'SYNAPSE-US', | ||
var transaction; | ||
let transaction; | ||
@@ -448,3 +460,3 @@ Transactions.create( | ||
{ | ||
_id: NODE_ID | ||
_id: TRANSACTION_ID | ||
}, | ||
@@ -460,3 +472,3 @@ function(err, transactionResp) { | ||
var transactions; | ||
let transactions; | ||
@@ -475,3 +487,3 @@ Transactions.get( | ||
var updatePayload = { | ||
const updatePayload = { | ||
comment: 'hi' | ||
@@ -478,0 +490,0 @@ }; |
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
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
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
28123
610