Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apac

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apac - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

.npmignore

20

examples/example-item-search.js

@@ -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');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc