New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dynamodb-enhanced

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamodb-enhanced - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1-a

lib/aws-signer.js

353

lib/ddb.js

@@ -26,3 +26,3 @@ // Copyright Teleportd Ltd. and other Contributors

var events = require('events');
var Signer = require('./aws-signer');
var fwk = require('fwk');

@@ -35,3 +35,3 @@

*
* @param spec {secretAccessKey, accessKeyId, endpoint, agent, sessionToken, sessionExpires}
* @param spec {secretAccessKey, accessKeyId, endpoint, agent, region, sessionToken, sessionExpires}
*/

@@ -43,4 +43,5 @@

my.accessKeyId = spec.accessKeyId;
my.secretAccessKey = spec.secretAccessKey;
my.accessKeyId = spec.credentials.accessKeyId;
my.secretAccessKey = spec.credentials.secretAccessKey;
my.endpoint = spec.endpoint || 'dynamodb.us-east-1.amazonaws.com';

@@ -60,2 +61,5 @@ my.port = spec.port || 80;

my.inAuth = false;

@@ -222,6 +226,6 @@ my.consumedCapacity = 0;

data.TableName = table;
var key = { "HashKeyElement": hash };
var key = [hash];
if(typeof range !== 'undefined' &&
range !== null) {
key.RangeKeyElement = range;
key.push(range);
}

@@ -243,3 +247,3 @@ data.Key = objToDDB(key);

else {
my.consumedCapacity += res.ConsumedCapacityUnits;
my.consumedCapacity += res.ConsumedCapacity.CapacityUnits;
try {

@@ -252,3 +256,3 @@ var item = objFromDDB(res.Item);

}
cb(null, item, res.ConsumedCapacityUnits);
cb(null, item, res.ConsumedCapacity.CapacityUnits);
}

@@ -301,3 +305,3 @@ });

else {
my.consumedCapacity += res.ConsumedCapacityUnits;
my.consumedCapacity += res.ConsumedCapacity.CapacityUnits;
try {

@@ -310,3 +314,3 @@ var attr = objFromDDB(res.Attributes);

}
cb(null, attr, res.ConsumedCapacityUnits);
cb(null, attr, res.ConsumedCapacity.CapacityUnits);
}

@@ -359,3 +363,3 @@ });

else {
my.consumedCapacity += res.ConsumedCapacityUnits;
my.consumedCapacity += res.ConsumedCapacity.CapacityUnits;
try {

@@ -368,3 +372,3 @@ var attr = objFromDDB(res.Attributes);

}
cb(null, attr, res.ConsumedCapacityUnits);
cb(null, attr, res.ConsumedCapacity.CapacityUnits);
}

@@ -430,3 +434,3 @@ });

else {
my.consumedCapacity += res.ConsumedCapacityUnits;
my.consumedCapacity += res.ConsumedCapacity.CapacityUnits;
try {

@@ -439,3 +443,3 @@ var attr = objFromDDB(res.Attributes);

}
cb(null, attr, res.ConsumedCapacityUnits);
cb(null, attr, res.ConsumedCapacity.CapacityUnits);
}

@@ -467,3 +471,3 @@ });

var key = part.keys[j];
var keyData = hasRange ? {"HashKeyElement": scToDDB(key[0]), "RangeKeyElement": scToDDB(key[1])} : {"HashKeyElement": scToDDB(key)};
var keyData = objToDDB(key);
tableData.Keys.push(keyData);

@@ -475,2 +479,6 @@ }

}
if (part.consistentRead) {
tableData.ConsistentRead = part.consistentRead;
}
data.RequestItems[table] = tableData;

@@ -491,3 +499,3 @@ }

var part = res.Responses[table];
var cap = part.ConsumedCapacityUnits;
var cap = part.ConsumedCapacity.CapacityUnits;
if (cap) {

@@ -564,10 +572,4 @@ consumedCapacity += cap;

var consumedCapacity = 0;
for(var table in res.Responses) {
if(res.Responses.hasOwnProperty(table)) {
var part = res.Responses[table];
var cap = part.ConsumedCapacityUnits;
if (cap) {
consumedCapacity += cap;
}
}
for (var i = 0; i < res.ConsumedCapacity.length; i++) {
consumedCapacity += res.ConsumedCapacity[i].CapacityUnits;
}

@@ -587,12 +589,32 @@ my.consumedCapacity += consumedCapacity;

* @param table the tableName
* @param hash the hashKey
* @param keys the table {id:2,range:3} range is optional
* @param the hash key + operator ex. {id: 'EQ'}
* @param options {attributesToGet, limit, consistentRead, count,
* rangeKeyCondition, scanIndexForward, exclusiveStartKey, indexName}
* rangeKeyCondition, scanIndexForward, exclusiveStartKey, indexName, filter}
*
* @param cb callback(err, tables) err is set if an error occured
*/
query = function(table, hash, options, cb) {
query = function(table, keys, operators, options, cb) {
var data = {};
try {
for(var i in keys) {
if(keys.hasOwnProperty(i)) {
keys[i] = {ComparisonOperator: operators[i], AttributeValueList: [scToDDB(keys[i])]}
}
}
data.TableName = table;
data.HashKeyValue = scToDDB(hash)
data.KeyConditions = keys;
if(options.filter)
{
var nFilter = {};
for(var i in options.filter.keys) {
if(options.filter.keys.hasOwnProperty(i)) {
nFilter[i] = {ComparisonOperator: options.filter.operators[i], AttributeValueList: [scToDDB(options.filter.keys[i])]}
}
}
data.QueryFilter = nFilter;
}
if(options.attributesToGet) {

@@ -610,18 +632,3 @@ data.AttributesToGet = options.attributesToGet;

}
if(options.rangeKeyCondition) {
for(var op in options.rangeKeyCondition) { // supposed to be only one
if(typeof op === 'string') {
data.RangeKeyCondition = {"AttributeValueList":[],"ComparisonOperator": op.toUpperCase()};
if(op == 'between' &&
Array.isArray(options.rangeKeyCondition[op]) &&
options.rangeKeyCondition[op].length > 1) {
data.RangeKeyCondition.AttributeValueList.push(scToDDB(options.rangeKeyCondition[op][0]));
data.RangeKeyCondition.AttributeValueList.push(scToDDB(options.rangeKeyCondition[op][1]));
}
else {
data.RangeKeyCondition.AttributeValueList.push(scToDDB(options.rangeKeyCondition[op]));
}
}
}
}
if(options.scanIndexForward === false) {

@@ -646,6 +653,7 @@ data.ScanIndexForward = false;

else {
my.consumedCapacity += res.ConsumedCapacityUnits;
my.consumedCapacity += res.ConsumedCapacity.CapacityUnits;
var r = { count: res.Count,
items: [],
lastEvaluatedKey: {}};
lastEvaluatedKey: null,
scannedCount: res.ScannedCount};
try {

@@ -657,4 +665,3 @@ if (res.Items) {

var key = objFromDDB(res.LastEvaluatedKey);
r.lastEvaluatedKey = { hash: key.HashKeyElement,
range: key.RangeKeyElement };
r.lastEvaluatedKey = key;
}

@@ -666,3 +673,3 @@ }

}
cb(null, r, res.ConsumedCapacityUnits);
cb(null, r, res.ConsumedCapacity.CapacityUnits);
}

@@ -731,6 +738,6 @@ });

else {
my.consumedCapacity += res.ConsumedCapacityUnits;
my.consumedCapacity += res.ConsumedCapacity.CapacityUnits;
var r = { count: res.Count,
items: [],
lastEvaluatedKey: {},
lastEvaluatedKey: null,
scannedCount: res.ScannedCount };

@@ -743,4 +750,3 @@ try {

var key = objFromDDB(res.LastEvaluatedKey);
r.lastEvaluatedKey = { hash: key.HashKeyElement,
range: key.RangeKeyElement };
r.lastEvaluatedKey = key;
}

@@ -752,3 +758,3 @@ }

}
cb(null, r, res.ConsumedCapacityUnits);
cb(null, r, res.ConsumedCapacity.CapacityUnits);
}

@@ -806,3 +812,3 @@ });

{
return mapToDDB(value);
return {"M": mapToDDB(value)};
}

@@ -822,8 +828,4 @@

}
else if(typeof value[i] === 'object' && !Array.isArray(value[i])) {
arr[i] = mapToDDB(value[i]);
isSS = "M";
}
else if(typeof value[i] === 'object' && Array.isArray(value[i])) {
arr[i] = mapToDDB(value[i]);
else if(typeof value[i] === 'object') {
arr[i] = {"M":mapToDDB(value[i])};
isSS = "L";

@@ -864,3 +866,3 @@ }

if (obj.hasOwnProperty(key)) {
obj[key] = scToDDB(obj[key]);
nObj[key] = scToDDB(obj[key]);
}

@@ -884,3 +886,3 @@ }

if (obj.hasOwnProperty(key)) {
obj[key] = objFromDDB(obj[key]);
nObj[key] = objFromDDB(obj[key]);
}

@@ -917,4 +919,4 @@ }

}
else if(ddb[i]['BOOL']){
res[i] = ddb[i]['BOOL'] === 'true';
else if(ddb[i]['BOOL'] !== undefined){
res[i] = ddb[i]['BOOL'];
}

@@ -925,10 +927,3 @@ else if(ddb[i]['NULL']){

else if(ddb[i]['M']){
var tmpObj = ddb[i]['M'];
var newObj = {};
for (key in tmpObj) {
if (tmpObj.hasOwnProperty(key)) {
newObj[key] = objFromDDB(tempObj[key]);
}
}
res[i] = newObj;
res[i] = objFromDDB(ddb[i]['M']);
}

@@ -973,128 +968,110 @@ else if(ddb[i]['L']) {

*/
execute = function(op, data, cb) {
auth(function(err) {
if(err) { cb(err); }
else {
var dtStr = (new Date).toUTCString();
var rqBody = JSON.stringify(data);
var sts = ('POST' + '\n' +
'/' + '\n' +
'' + '\n' +
('host' + ':' + my.endpoint + '\n' +
'x-amz-date' + ':' + dtStr + '\n' +
'x-amz-security-token' + ':' + my.access.sessionToken + '\n' +
'x-amz-target' + ':' + 'DynamoDB_20111205.' + op + '\n') + '\n' +
rqBody);
var date = new Date();
var sha = crypto.createHash('sha256');
sha.update(new Buffer(sts,'utf8'));
var hmac = crypto.createHmac('sha256', my.access.secretAccessKey);
hmac.update(sha.digest());
var headers = {
"host": my.endpoint,
"x-amz-date": Signer._requestDate(date),
"x-amz-target": "DynamoDB_20120810." + op,
"content-type": "application/x-amz-json-1.0"
};
data.ReturnConsumedCapacity = 'TOTAL';
var request = {
method: "POST",
uri: "/",
query: "",
headers: headers,
body: JSON.stringify(data)
};
var auth = ('AWS3' + ' ' +
'AWSAccessKeyId' + '=' + my.access.accessKeyId + ',' +
'Algorithm' + '=' + 'HmacSHA256' + ',' +
'SignedHeaders' + '=' + 'host;x-amz-date;x-amz-target;x-amz-security-token' + ',' +
'Signature' + '=' + hmac.digest(encoding='base64'));
headers.authorization = Signer.authorization(spec.credentials, request, date, spec.region);
var headers = { 'Host': my.endpoint,
'x-amz-date': dtStr,
'x-amz-security-token': my.access.sessionToken,
'X-amz-target': 'DynamoDB_20111205.' + op,
'X-amzn-authorization' : auth,
'date': dtStr,
'content-type': 'application/x-amz-json-1.0',
'content-length': Buffer.byteLength(rqBody,'utf8') };
if ('securityToken' in spec.credentials)
headers["x-amz-security-token"] = self.credentials.securityToken;
var options = { host: my.endpoint,
port: my.port,
path: '/',
method: 'POST',
headers: headers,
agent: my.agent };
var opts = {
method: request.method,
path: request.uri,
headers: headers,
host: my.endpoint
};
var executeRequest = function(cb) {
var req = http.request(options, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
if (!cb) {
// Do not call callback if it's already been called in the error handler.
return;
}
try {
var json = JSON.parse(body);
}
catch(err) {
cb(err);
return;
}
if(res.statusCode >= 300) {
var err = new Error(op + ' [' + res.statusCode + ']: ' + (json.message || json['__type']));
err.type = json['__type'];
err.statusCode = res.statusCode;
err.requestId = res.headers['x-amzn-requestid'];
err.message = op + ' [' + res.statusCode + ']: ' + (json.message || json['__type']);
err.code = err.type.substring(err.type.lastIndexOf("#") + 1, err.type.length);
err.data = json;
cb(err);
}
else {
cb(null, json);
}
});
});
req.on('error', function(err) {
cb(err);
cb = undefined; // Clear callback so we do not call it twice
});
var executeRequest = function(cb) {
var req = http.request(opts, function(res) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
if (!cb) {
// Do not call callback if it's already been called in the error handler.
return;
}
try {
var json = JSON.parse(body);
} catch (err) {
cb(err);
return;
}
if (res.statusCode >= 300) {
var err = new Error(op + ' [' + res.statusCode + ']: ' + (json.message || json['__type']));
err.type = json['__type'];
err.statusCode = res.statusCode;
err.requestId = res.headers['x-amzn-requestid'];
err.message = op + ' [' + res.statusCode + ']: ' + (json.message || json['__type']);
err.code = err.type.substring(err.type.lastIndexOf("#") + 1, err.type.length);
err.data = json;
cb(err);
} else {
cb(null, json);
}
});
});
req.write(rqBody);
req.end();
};
req.setTimeout(0);
// see: https://github.com/amazonwebservices/aws-sdk-for-php/blob/master/sdk.class.php
// for the original php retry logic used here
(function retry(c) {
executeRequest(function (err, json) {
if(err != null) {
if(err.statusCode === 500 || err.statusCode === 503) {
if(c <= my.retries) {
setTimeout(function() {
retry(c + 1);
}, Math.pow(4, c) * 100);
}
else
cb(err);
}
else if(err.statusCode === 400 &&
err.code === "ProvisionedThroughputExceededException") {
if(c === 0) {
retry(c + 1);
}
else if(c <= my.retries && c <= 10) {
setTimeout(function() {
retry(c + 1);
}, Math.pow(2, c-1) * (25 * (Math.random() + 1)));
}
else
cb(err);
}
else {
cb(err);
}
} else {
cb(null, json);
}
});
})(0);
req.on('error', function(err) {
cb(err);
cb = undefined; // Clear callback so we do not call it twice
});
req.write(request.body);
req.end();
};
// see: https://github.com/amazonwebservices/aws-sdk-for-php/blob/master/sdk.class.php
// for the original php retry logic used here
(function retry(c) {
executeRequest(function(err, json) {
if (err != null) {
if (err.statusCode === 500 || err.statusCode === 503) {
if (c <= my.retries) {
setTimeout(function() {
retry(c + 1);
}, Math.pow(4, c) * 100);
} else
cb(err);
} else if (err.statusCode === 400 &&
(err.code === "ProvisionedThroughputExceededException")) {
if (c === 0) {
retry(c + 1);
} else if (c <= my.retries && c <= 10) {
setTimeout(function() {
retry(c + 1);
}, Math.pow(2, c - 1) * (25 * (Math.random() + 1)));
} else
cb(err);
} else {
cb(err);
}
} else {
cb(null, json);
}
});
})(0);
};
/**

@@ -1106,4 +1083,4 @@ * retrieves a temporary access key and secret from amazon STS

// auth if necessary and always async
if(my.access && my.access.expiration.getTime() < ((new Date).getTime() + 60000)) {
//console.log('CLEAR AUTH: ' + my.access.expiration + ' ' + new Date);
if(my.access && my.access.expiration.getTime() < (new Date().getTime() + 60000)) {
console.log('CLEAR AUTH: ' + my.access.expiration + ' ' + new Date);
delete my.access;

@@ -1127,3 +1104,3 @@ my.inAuth = false;

'SignatureVersion' + '=' + '2' + '&' +
'Timestamp' + '=' + encodeURIComponent((new Date).toISOString().substr(0, 19) + 'Z') + '&' +
'Timestamp' + '=' + encodeURIComponent(new Date().toISOString().substr(0, 19) + 'Z') + '&' +
'Version' + '=' + '2011-06-15');

@@ -1130,0 +1107,0 @@

{
"name": "dynamodb-enhanced",
"version": "0.4.0",
"version": "0.4.1a",
"description": "Simple DynamoDB Library for Node.js. enhanced version of dynamodb by Stanislas Polu",
"keywords": ["dynamo", "node", "db", "aws", "amazon"],
"keywords": [
"dynamo",
"node",
"db",
"aws",
"amazon"
],
"homepage": "https://github.com/teleportd/node-dynamodb",
"author": { "name": "Jt Whissel",
"email": "jtwhissel@gmail.com",
"url": "http://www.linkedin.com/in/jtwhissel/" },
"repository" : { "type" : "git",
"url" : "https://github.com/jtwhissel/node-dynamodb" },
"contributors" : [ "Stanislas Polu",
"Karl Seguin",
"Juan Carlos del Valle",
"Pablo Cantero",
"Chris Stivers",
"Juho Mäkinen",
"Paul Tax",
"Alex Bosworth",
"Jimb Esser",
"Anthony Moi" ],
"author": {
"name": "Jt Whissel",
"email": "jtwhissel@gmail.com",
"url": "http://www.linkedin.com/in/jtwhissel/"
},
"repository": {
"type": "git",
"url": "https://github.com/jtwhissel/node-dynamodb"
},
"contributors": [
"Stanislas Polu",
"Karl Seguin",
"Juan Carlos del Valle",
"Pablo Cantero",
"Chris Stivers",
"Juho Mäkinen",
"Paul Tax",
"Alex Bosworth",
"Jimb Esser",
"Anthony Moi"
],
"dependencies": {
"fwk": "0.1.x"
"fwk": "0.1.x",
"utile": "^0.2.1"
},
"main" : "./lib/ddb",
"engines" : { "node" : ">=0.4.0" }
"main": "./lib/ddb",
"engines": {
"node": ">=0.4.0"
}
}

@@ -118,3 +118,3 @@ ## Basics

ddb.query('test', '3d2d6963', {}, function(err, res, cap) {...});
ddb.query('test', '{id: 3d2d6963}',{id: 'EQ'} ,{filter:{keys:{foo:12},operators:{foo:'GT'}}}, function(err, res, cap) {...});

@@ -121,0 +121,0 @@ // res: { count: 23,

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