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-ap to 0.4.0-aq

214

lib/ddb.js

@@ -42,5 +42,4 @@ // Copyright Teleportd Ltd. and other Contributors

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

@@ -50,8 +49,2 @@ my.port = spec.port || 80;

my.retries = spec.retries || 3;

@@ -949,129 +942,108 @@

execute = function(op, data, cb) {
auth(function(err) {
if(err) { cb(err); }
else {
var dtStr = new Date().toUTCString();
data.ReturnConsumedCapacity = 'TOTAL';
var rqBody = JSON.stringify(data);
var date = new Date();
var sts = ('POST' + '\n' +
'/' + '\n' +
'' + '\n' +
('host' + ':' + my.endpoint + '\n' +
'x-amz-security-token' + ':' + my.access.sessionToken + '\n' +
'x-amz-target' + ':' + 'DynamoDB_20120810.' + op + '\n') + '\n' +
rqBody);
var headers = {
"host": my.endpoint,
"x-amz-date": Signer._requestDate(date),
"x-amz-target": "DynamoDB_20111205." + op,
"content-type": "application/x-amz-json-1.0"
};
var sha = crypto.createHash('sha256');
sha.update(new Buffer(sts,'utf8'));
var hmac = crypto.createHmac('sha256', my.access.secretAccessKey);
hmac.update(sha.digest());
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-security-token': my.access.sessionToken,
'X-amz-target': 'DynamoDB_20120810.' + op,
'X-amzn-authorization' : auth,
'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};
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.sendDate = true;
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.setTimeout(0);
req.setTimeout(0);
req.on('error', function(err) {
cb(err);
cb = undefined; // Clear callback so we do not call it twice
});
req.on('error', function(err) {
cb(err);
cb = undefined; // Clear callback so we do not call it twice
});
req.write(rqBody);
req.end();
};
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);
// 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);
};
/**

@@ -1078,0 +1050,0 @@ * retrieves a temporary access key and secret from amazon STS

{
"name": "dynamodb-enhanced",
"version": "0.4.0ap",
"version": "0.4.0aq",
"description": "Simple DynamoDB Library for Node.js. enhanced version of dynamodb by Stanislas Polu",

@@ -5,0 +5,0 @@ "keywords": [

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