Comparing version 2.1.0-rc2 to 2.1.0-rc3
@@ -7,3 +7,19 @@ 'use strict'; | ||
Stripe.DEFAULT_API_VERSION = null; | ||
Stripe.PACKAGE_VERSION = require('fs').readFileSync( | ||
require('path').resolve(__dirname, '../VERSION'), 'utf-8' | ||
); | ||
Stripe.USER_AGENT = { | ||
bindings_version: Stripe.PACKAGE_VERSION, | ||
lang: 'node', | ||
lang_version: process.version, | ||
platform: process.platform, | ||
publisher: 'stripe', | ||
uname: null | ||
}; | ||
Stripe.USER_AGENT_SERIALIZED = null; | ||
var exec = require('child_process').exec; | ||
var resources = global.resources = { | ||
@@ -89,2 +105,17 @@ | ||
getConstant: function(c) { | ||
return Stripe[c]; | ||
}, | ||
getClientUserAgent: function(cb) { | ||
if (Stripe.USER_AGENT_SERIALIZED) { | ||
return cb(Stripe.USER_AGENT_SERIALIZED); | ||
} | ||
exec('uname -a', function(err, uname) { | ||
Stripe.USER_AGENT.uname = uname || 'UNKNOWN'; | ||
Stripe.USER_AGENT_SERIALIZED = JSON.stringify(Stripe.USER_AGENT); | ||
cb(Stripe.USER_AGENT_SERIALIZED); | ||
}); | ||
}, | ||
_prepResources: function() { | ||
@@ -91,0 +122,0 @@ |
@@ -96,3 +96,4 @@ 'use strict'; | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Content-Length': requestData.length | ||
'Content-Length': requestData.length, | ||
'User-Agent': 'Stripe/v1 NodeBindings/' + this._stripe.getConstant('PACKAGE_VERSION') | ||
}; | ||
@@ -104,58 +105,68 @@ | ||
var req = ( | ||
this._stripe.getApiField('protocol') == 'http' ? http : https | ||
).request({ | ||
host: this._stripe.getApiField('host'), | ||
port: this._stripe.getApiField('port'), | ||
path: path, | ||
method: method, | ||
headers: headers | ||
// Grab client-user-agent before making the request: | ||
this._stripe.getClientUserAgent(function(cua) { | ||
headers['X-Stripe-Client-User-Agent'] = cua; | ||
makeRequest(); | ||
}); | ||
req.on('response', function(res) { | ||
var response = ''; | ||
function makeRequest() { | ||
res.setEncoding('utf8'); | ||
res.on('data', function(chunk) { | ||
response += chunk; | ||
var req = ( | ||
self._stripe.getApiField('protocol') == 'http' ? http : https | ||
).request({ | ||
host: self._stripe.getApiField('host'), | ||
port: self._stripe.getApiField('port'), | ||
path: path, | ||
method: method, | ||
headers: headers | ||
}); | ||
res.on('end', function() { | ||
try { | ||
response = JSON.parse(response); | ||
if (response.error) { | ||
var err; | ||
if (res.statusCode === 401) { | ||
err = new Error.StripeAuthenticationError(response.error); | ||
} else { | ||
err = Error.StripeError.generate(response.error); | ||
req.on('response', function(res) { | ||
var response = ''; | ||
res.setEncoding('utf8'); | ||
res.on('data', function(chunk) { | ||
response += chunk; | ||
}); | ||
res.on('end', function() { | ||
try { | ||
response = JSON.parse(response); | ||
if (response.error) { | ||
var err; | ||
if (res.statusCode === 401) { | ||
err = new Error.StripeAuthenticationError(response.error); | ||
} else { | ||
err = Error.StripeError.generate(response.error); | ||
} | ||
return callback.call(self, err, null); | ||
} | ||
return callback.call(self, err, null); | ||
} catch (e) { | ||
return callback.call( | ||
self, | ||
new Error.StripeAPIError({ | ||
message: 'Invalid JSON received from the Stripe API' | ||
}), | ||
null | ||
); | ||
} | ||
} catch (e) { | ||
return callback.call( | ||
self, | ||
new Error.StripeAPIError({ | ||
message: 'Invalid JSON received from the Stripe API' | ||
}), | ||
null | ||
); | ||
} | ||
callback.call(self, null, response); | ||
callback.call(self, null, response); | ||
}); | ||
}); | ||
}); | ||
req.on('error', function(error) { | ||
callback.call( | ||
self, | ||
new Error.StripeConnectionError({ | ||
message: 'An error occurred with our connection to Stripe', | ||
detail: error | ||
}), | ||
null | ||
); | ||
}); | ||
req.on('error', function(error) { | ||
callback.call( | ||
self, | ||
new Error.StripeConnectionError({ | ||
message: 'An error occurred with our connection to Stripe', | ||
detail: error | ||
}), | ||
null | ||
); | ||
}); | ||
req.write(requestData); | ||
req.end(); | ||
req.write(requestData); | ||
req.end(); | ||
} | ||
} | ||
@@ -162,0 +173,0 @@ |
{ | ||
"name": "stripe", | ||
"version": "2.1.0-rc2", | ||
"version": "2.1.0-rc3", | ||
"description": "Stripe API wrapper", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/stripe/stripe-node", |
@@ -144,2 +144,10 @@ # Stripe node.js bindings | ||
## More information / wikis | ||
* **[In-depth Documentation](https://stripe.com/docs/api/node.)** | ||
* [Version 2 Overview](https://github.com/stripe/stripe-node/wiki/Version-2) | ||
* [REST API Version](https://github.com/stripe/stripe-node/wiki/REST-API-Version) | ||
* [Error Handling](https://github.com/stripe/stripe-node/wiki/Error-Handling) | ||
* [Using Stripe Connect](https://github.com/stripe/stripe-node/wiki/Using-Stripe-Connect-with-node.js) | ||
## Development | ||
@@ -146,0 +154,0 @@ |
@@ -26,2 +26,12 @@ 'use strict'; | ||
describe('ClientUserAgent', function() { | ||
it('Should return a user-agent serialized JSON object', function() { | ||
var d = when.defer(); | ||
stripe.getClientUserAgent(function(c) { | ||
d.resolve(JSON.parse(c)); | ||
}); | ||
return expect(d.promise).to.eventually.have.property('lang', 'node'); | ||
}); | ||
}); | ||
describe('Callback support', function() { | ||
@@ -28,0 +38,0 @@ |
Sorry, the diff of this file is not supported yet
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
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
80320
2142
170
2
4