Comparing version 0.0.11 to 0.0.12
@@ -1,17 +0,17 @@ | ||
var sys = require('sys'), | ||
OperationHelper = require('apac').OperationHelper; | ||
var util = require('util'), | ||
OperationHelper = require('../lib/apac').OperationHelper; | ||
var opHelper = new OperationHelper({ | ||
awsId: '[YOUR AWS ID HERE]', | ||
awsSecret: '[YOUR AWS SECRET HERE]', | ||
assocId: '[YOUR ASSOCIATE TAG HERE]', | ||
awsId: '[YOUR AWS ID HERE]', | ||
awsSecret: '[YOUR AWS SECRET HERE]', | ||
assocId: '[YOUR ASSOCIATE TAG HERE]' | ||
}); | ||
opHelper.execute('ItemSearch', { | ||
'SearchIndex': 'Books', | ||
'Keywords': 'harry potter', | ||
'ResponseGroup': 'ItemAttributes,Offers' | ||
'SearchIndex': 'Books', | ||
'Keywords': 'harry potter', | ||
'ResponseGroup': 'ItemAttributes,Offers' | ||
}, function(error, results) { | ||
if (error) { sys.print('Error: ' + error + "\n") } | ||
sys.print("Results:\n" + sys.inspect(results) + "\n"); | ||
if (error) { util.print('Error: ' + error + '\n') } | ||
util.print('Results:\n' + util.inspect(results) + '\n'); | ||
}); |
@@ -9,3 +9,3 @@ var RSH = require('./RequestSignatureHelper').RequestSignatureHelper, | ||
OperationHelper.version = '2010-11-01'; | ||
OperationHelper.version = '2013-05-05'; | ||
OperationHelper.service = 'AWSECommerceService'; | ||
@@ -67,17 +67,24 @@ OperationHelper.defaultEndPoint = 'ecs.amazonaws.com'; | ||
var host = this.endPoint; | ||
var amazonClient = http.createClient(80, host); | ||
var options = { | ||
hostname: host, | ||
path: uri, | ||
method: 'GET' | ||
}; | ||
var parser = this.parser; | ||
var request = amazonClient.request('GET', uri, {'host':host}); | ||
request.end(); | ||
request.addListener('response', function(response) { | ||
var responseBody = ''; | ||
response.addListener('data', function(chunk) { | ||
var responseBody = ''; | ||
var request = http.request(options, function (response) { | ||
response.setEncoding('utf8'); | ||
response.on('data', function (chunk) { | ||
responseBody += chunk; | ||
}); | ||
response.addListener('end', function() { | ||
response.on('end', function() { | ||
var statusCode = response.statusCode == 200 ? null : response.statusCode; | ||
parser.addListener('end', function(result) { | ||
parser.addListener('end', function (result) { | ||
callback(statusCode, result); | ||
// so that next time this is called the result isn't concatenated | ||
parser.reset(); | ||
parser.removeAllListeners('end'); | ||
@@ -87,6 +94,12 @@ }); | ||
}); | ||
response.setEncoding('utf8'); | ||
}); | ||
request.on('error', function (err) { | ||
console.log(err.message); | ||
}); | ||
request.end(); | ||
}; | ||
exports.OperationHelper = OperationHelper; |
var crypto = require('crypto'); | ||
var RSH = function(params) { | ||
this.init(params); | ||
this.init(params); | ||
}; | ||
RSH.kAWSAccessKeyId = 'AWSAccessKeyId'; | ||
RSH.kAWSSecretKey = 'AWSSecretKey'; | ||
RSH.kEndPoint = 'EndPoint'; | ||
RSH.kRequestMethod = 'RequestMethod'; | ||
RSH.kRequestUri = 'RequestUri'; | ||
RSH.kAWSSecretKey = 'AWSSecretKey'; | ||
RSH.kEndPoint = 'EndPoint'; | ||
RSH.kRequestMethod = 'RequestMethod'; | ||
RSH.kRequestUri = 'RequestUri'; | ||
RSH.kTimestampParam = 'Timestamp'; | ||
@@ -16,53 +16,54 @@ RSH.kSignatureParam = 'Signature'; | ||
RSH.prototype.init = function(params) { | ||
// enforce required params | ||
if (typeof(params[RSH.kAWSAccessKeyId]) === 'undefined') { throw 'Need access key id argument' } | ||
if (typeof(params[RSH.kAWSSecretKey]) === 'undefined') { throw 'Need secret key argument' } | ||
if (typeof(params[RSH.kEndPoint]) === 'undefined') { throw 'Need end point argument' } | ||
// enforce required params | ||
if (typeof(params[RSH.kAWSAccessKeyId]) === 'undefined') { throw 'Need access key id argument' } | ||
if (typeof(params[RSH.kAWSSecretKey]) === 'undefined') { throw 'Need secret key argument' } | ||
if (typeof(params[RSH.kEndPoint]) === 'undefined') { throw 'Need end point argument' } | ||
// set params | ||
this[RSH.kAWSAccessKeyId] = params[RSH.kAWSAccessKeyId]; | ||
this[RSH.kAWSSecretKey] = params[RSH.kAWSSecretKey]; | ||
this[RSH.kEndPoint] = params[RSH.kEndPoint].toLowerCase(); | ||
this[RSH.kRequestMethod] = params[RSH.kRequestMethod] || 'GET'; | ||
this[RSH.kRequestUri] = params[RSH.kRequestUri] || '/onca/xml'; | ||
// set params | ||
this[RSH.kAWSAccessKeyId] = params[RSH.kAWSAccessKeyId]; | ||
this[RSH.kAWSSecretKey] = params[RSH.kAWSSecretKey]; | ||
this[RSH.kEndPoint] = params[RSH.kEndPoint].toLowerCase(); | ||
this[RSH.kRequestMethod] = params[RSH.kRequestMethod] || 'GET'; | ||
this[RSH.kRequestUri] = params[RSH.kRequestUri] || '/onca/xml'; | ||
}; | ||
RSH.prototype.sign = function(params) { | ||
var self = this; | ||
// append params | ||
params[RSH.kTimestampParam] = this.generateTimestamp(); | ||
params[RSH.kAWSAccessKeyId] = this[RSH.kAWSAccessKeyId] ; | ||
// generate signature | ||
var canonical = this.canonicalize(params); | ||
var stringToSign = [ | ||
this[RSH.kRequestMethod], | ||
this[RSH.kEndPoint], | ||
this[RSH.kRequestUri], | ||
canonical | ||
].join("\n"); | ||
params[RSH.kSignatureParam] = this.digest(stringToSign); | ||
var self = this; | ||
// append params | ||
params[RSH.kTimestampParam] = this.generateTimestamp(); | ||
params[RSH.kAWSAccessKeyId] = this[RSH.kAWSAccessKeyId]; | ||
// generate signature | ||
var canonical = this.canonicalize(params); | ||
var stringToSign = [ | ||
this[RSH.kRequestMethod], | ||
this[RSH.kEndPoint], | ||
this[RSH.kRequestUri], | ||
canonical | ||
].join('\n'); | ||
params[RSH.kSignatureParam] = this.digest(stringToSign); | ||
return params; | ||
return params; | ||
}; | ||
RSH.prototype.zeroPad = function(num, length) { | ||
num = num + ''; | ||
while (num.length < length) { | ||
num = '0' + num; | ||
} | ||
return num; | ||
num = num + ''; | ||
while (num.length < length) { | ||
num = '0' + num; | ||
} | ||
return num; | ||
}; | ||
RSH.prototype.generateTimestamp = function() { | ||
var now = new Date(), | ||
year = now.getUTCFullYear(), | ||
month = this.zeroPad(now.getUTCMonth() + 1, 2), | ||
day = this.zeroPad(now.getUTCDate(), 2), | ||
hours = this.zeroPad(now.getUTCHours(), 2), | ||
mins = this.zeroPad(now.getUTCMinutes(), 2), | ||
secs = this.zeroPad(now.getUTCSeconds(), 2); | ||
return [year, month, day].join('-') + 'T' + | ||
[hours, mins, secs].join(':') + 'Z'; | ||
var now = new Date(), | ||
year = now.getUTCFullYear(), | ||
month = this.zeroPad(now.getUTCMonth() + 1, 2), | ||
day = this.zeroPad(now.getUTCDate(), 2), | ||
hours = this.zeroPad(now.getUTCHours(), 2), | ||
mins = this.zeroPad(now.getUTCMinutes(), 2), | ||
secs = this.zeroPad(now.getUTCSeconds(), 2); | ||
return [year, month, day].join('-') + 'T' + | ||
[hours, mins, secs].join(':') + 'Z'; | ||
}; | ||
/** | ||
@@ -72,20 +73,20 @@ * Port of PHP rawurlencode(). | ||
RSH.prototype.escape = function(x) { | ||
return encodeURIComponent(x).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A'); | ||
return encodeURIComponent(x).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A'); | ||
}; | ||
RSH.prototype.digest = function(x) { | ||
var secretKey = this[RSH.kAWSSecretKey]; | ||
var hmac = crypto.createHmac('sha256', secretKey); | ||
hmac.update(x); | ||
return hmac.digest('base64'); | ||
var secretKey = this[RSH.kAWSSecretKey]; | ||
var hmac = crypto.createHmac('sha256', secretKey); | ||
hmac.update(x); | ||
return hmac.digest('base64'); | ||
}; | ||
RSH.prototype.canonicalize = function(params) { | ||
var parts = []; | ||
for (var key in params) { | ||
parts.push([this.escape(key), this.escape(params[key])].join('=')); | ||
} | ||
return parts.sort().join('&'); | ||
var parts = []; | ||
for (var key in params) { | ||
parts.push([this.escape(key), this.escape(params[key])].join('=')); | ||
} | ||
return parts.sort().join('&'); | ||
}; | ||
exports.RequestSignatureHelper = RSH; |
@@ -1,23 +0,37 @@ | ||
{ "name" : "apac" | ||
, "description" : "Amazon Product Advertising API Client for Node" | ||
, "version" : "0.0.11" | ||
, "author" : "Dustin McQuay <dmcquay@gmail.com>" | ||
, "repository" : | ||
{ "type" : "git" | ||
, "url" : "git://github.com/dmcquay/node-apac.git" | ||
} | ||
, "bugs" : { "url" : "http://github.com/dmcquay/node-apac/issues" } | ||
, "os" : [ "linux", "darwin", "freebsd" ] | ||
, "directories" : { "lib" : "./lib/" } | ||
, "main" : "./lib/apac" | ||
, "dependencies" : | ||
{ "vows" : ">=0.5.0" | ||
, "xml2js" : ">=0.1.7" | ||
} | ||
, "engines" : { "node" : ">=0.1.97" } | ||
, "licenses" : | ||
[ { "type" : "MIT" | ||
, "url" : "http://github.com/dmcquay/node-apac/raw/master/LICENSE" | ||
{ | ||
"name": "apac", | ||
"description": "Amazon Product Advertising API Client for Node", | ||
"version": "0.0.12", | ||
"author": "Dustin McQuay <dmcquay@gmail.com>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/dmcquay/node-apac.git" | ||
}, | ||
"bugs": { | ||
"url": "http://github.com/dmcquay/node-apac/issues" | ||
}, | ||
"directories": { | ||
"lib": "./lib/" | ||
}, | ||
"main": "./lib/apac", | ||
"dependencies": { | ||
"xml2js": ">=0.1.7", | ||
"request" : ">=2.12.0" | ||
}, | ||
"devDependencies": { | ||
"vows": ">=0.5.0" | ||
}, | ||
"engines": { | ||
"node": ">=0.1.97" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://github.com/dmcquay/node-apac/raw/master/LICENSE" | ||
} | ||
], | ||
"keywords": [ | ||
"Amazon Product Advertising API", | ||
"AWS" | ||
] | ||
} |
@@ -1,5 +0,5 @@ | ||
var apac = require("../lib/apac"), | ||
vows = require("vows"), | ||
assert = require("assert"), | ||
http = require("http"), | ||
var apac = require('../lib/apac'), | ||
vows = require('vows'), | ||
assert = require('assert'), | ||
http = require('http'), | ||
event = require('events'); | ||
@@ -10,5 +10,5 @@ | ||
var opHelper = new OperationHelper({ | ||
awsId: 'test', | ||
awsSecret: 'test+test', | ||
assocId: 'test-01', | ||
awsId: 'test', | ||
awsSecret: 'test+test', | ||
assocId: 'test-01' | ||
}); | ||
@@ -24,36 +24,36 @@ | ||
response_emitter.setEncoding = function(something) {return true}; | ||
response_emitter.statusCode = 200 | ||
response_emitter.statusCode = 200; | ||
http.createClient = function(port, host) { | ||
return { | ||
request: function(it, doesnt, matter) { | ||
return request_emitter; | ||
} | ||
}; | ||
} | ||
return { | ||
request: function(it, doesnt, matter) { | ||
return request_emitter; | ||
} | ||
}; | ||
}; | ||
// now for the tests! | ||
vows.describe('OperationHelper execute').addBatch({ | ||
'results': { | ||
topic: function() { | ||
opHelper.execute('ItemSearch', { | ||
'SearchIndex': 'Books', | ||
'Keywords': 'harry potter', | ||
'ResponseGroup': 'ItemAttributes,Offers' | ||
}, this.callback); | ||
'results': { | ||
topic: function() { | ||
opHelper.execute('ItemSearch', { | ||
'SearchIndex': 'Books', | ||
'Keywords': 'harry potter', | ||
'ResponseGroup': 'ItemAttributes,Offers' | ||
}, this.callback); | ||
// use the emitter to emit the appropriate events | ||
request_emitter.emit('response', response_emitter); | ||
response_emitter.emit('data', '<it><is><some>xml</some></is></it>'); | ||
response_emitter.emit('end'); | ||
}, | ||
// use the emitter to emit the appropriate events | ||
request_emitter.emit('response', response_emitter); | ||
response_emitter.emit('data', '<it><is><some>xml</some></is></it>'); | ||
response_emitter.emit('end'); | ||
}, | ||
'are json': function(error, result) { | ||
assert.isObject(result); | ||
}, | ||
'are json': function(error, result) { | ||
assert.isObject(result); | ||
}, | ||
'have the right structure': function(error, result) { | ||
assert.deepEqual(result, {is: {some: 'xml'}}); | ||
} | ||
'have the right structure': function(error, result) { | ||
assert.deepEqual(result, {is: {some: 'xml'}}); | ||
} | ||
}).run(); | ||
} | ||
}).run(); |
@@ -10,4 +10,4 @@ var assert = require('assert'), | ||
params[RSH.kAWSAccessKeyId] = accessKeyId; | ||
params[RSH.kAWSSecretKey] = secretKey; | ||
params[RSH.kEndPoint] = endPoint; | ||
params[RSH.kAWSSecretKey] = secretKey; | ||
params[RSH.kEndPoint] = endPoint; | ||
var rsh = new RSH(params); | ||
@@ -17,6 +17,6 @@ assert.equal(typeof(rsh), 'object', 'instance created'); | ||
// canonicalize | ||
assert.equal(typeof(rsh.canonicalize({'a':'b'})), 'string', 'result of canonicalize is a string'); | ||
assert.equal(rsh.canonicalize({'a':'b'}), 'a=b', 'result of canonicalize is a query string'); | ||
assert.equal(rsh.canonicalize({'a':'b','c':'d'}), 'a=b&c=d', 'result of canonicalize is a query string'); | ||
assert.equal(rsh.canonicalize({'f':'b','a':'q'}), 'a=q&f=b', 'result of canonicalize is sorted by key'); | ||
assert.equal(typeof(rsh.canonicalize({'a': 'b'})), 'string', 'result of canonicalize is a string'); | ||
assert.equal(rsh.canonicalize({'a': 'b'}), 'a=b', 'result of canonicalize is a query string'); | ||
assert.equal(rsh.canonicalize({'a': 'b', 'c': 'd'}), 'a=b&c=d', 'result of canonicalize is a query string'); | ||
assert.equal(rsh.canonicalize({'f': 'b', 'a': 'q'}), 'a=q&f=b', 'result of canonicalize is sorted by key'); | ||
@@ -37,3 +37,3 @@ // digest | ||
// sign | ||
var params = rsh.sign({'d':'a','c':'f'}); | ||
params = rsh.sign({'d': 'a', 'c': 'f'}); | ||
assert.equal(typeof(params), 'object'); | ||
@@ -40,0 +40,0 @@ assert.equal(params[RSH.kAWSAccessKeyId], accessKeyId, 'accessKeyId was added to params'); |
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
15813
260
77
1
3
+ Addedrequest@>=2.12.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.10.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)
- Removedvows@>=0.5.0
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddiff@4.0.2(transitive)
- Removedeyes@0.1.8(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedvows@0.8.3(transitive)
- Removedwrappy@1.0.2(transitive)