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

aws-api-gateway-client

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-api-gateway-client - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

168

dist/apigClient.js

@@ -0,1 +1,17 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _urlTemplate = require('url-template');
var _urlTemplate2 = _interopRequireDefault(_urlTemplate);
var _apiGatewayClient = require('./lib/apiGatewayCore/apiGatewayClient');
var _apiGatewayClient2 = _interopRequireDefault(_apiGatewayClient);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*

@@ -15,92 +31,92 @@ * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

*/
/* eslint max-len: ["error", 100]*/
// import 'babel-polyfill';
var apigClientFactory = {};
var apiGateway = require('./lib/apiGatewayCore/apiGatewayClient.js');
var uritemplate = require('url-template');
apigClientFactory.newClient = function (config) {
var apigClient = {};
if (config === undefined) {
config = {
accessKey: '',
secretKey: '',
sessionToken: '',
region: '',
apiKey: undefined,
invokeUrl: '',
defaultContentType: 'application/json',
defaultAcceptType: 'application/json'
};
}
if (config.accessKey === undefined) {
config.accessKey = '';
}
if (config.secretKey === undefined) {
config.secretKey = '';
}
if (config.apiKey === undefined) {
config.apiKey = '';
}
if (config.sessionToken === undefined) {
config.sessionToken = '';
}
if (config.region === undefined) {
config.region = 'us-east-1';
}
//If defaultContentType is not defined then default to application/json
if (config.defaultContentType === undefined) {
config.defaultContentType = 'application/json';
}
//If defaultAcceptType is not defined then default to application/json
if (config.defaultAcceptType === undefined) {
config.defaultAcceptType = 'application/json';
}
var apigClient = {};
if (config === undefined) {
config = {
accessKey: '',
secretKey: '',
sessionToken: '',
region: '',
apiKey: undefined,
invokeUrl: '',
defaultContentType: 'application/json',
defaultAcceptType: 'application/json'
};
}
if (config.accessKey === undefined) {
config.accessKey = '';
}
if (config.secretKey === undefined) {
config.secretKey = '';
}
if (config.apiKey === undefined) {
config.apiKey = '';
}
if (config.sessionToken === undefined) {
config.sessionToken = '';
}
if (config.region === undefined) {
config.region = 'us-east-1';
}
// If defaultContentType is not defined then default to application/json
if (config.defaultContentType === undefined) {
config.defaultContentType = 'application/json';
}
// If defaultAcceptType is not defined then default to application/json
if (config.defaultAcceptType === undefined) {
config.defaultAcceptType = 'application/json';
}
// extract endpoint and path from url
var invokeUrl = config.invokeUrl;
var endpoint = /(^https?:\/\/[^\/]+)/g.exec(invokeUrl)[1];
var pathComponent = invokeUrl.substring(endpoint.length);
// extract endpoint and path from url
var invokeUrl = config.invokeUrl;
var endpoint = /(^https?:\/\/[^\/]+)/g.exec(invokeUrl)[1];
var pathComponent = invokeUrl.substring(endpoint.length);
var sigV4ClientConfig = {
accessKey: config.accessKey,
secretKey: config.secretKey,
sessionToken: config.sessionToken,
serviceName: 'execute-api',
region: config.region,
endpoint: endpoint,
defaultContentType: config.defaultContentType,
defaultAcceptType: config.defaultAcceptType
};
var sigV4ClientConfig = {
accessKey: config.accessKey,
secretKey: config.secretKey,
sessionToken: config.sessionToken,
serviceName: 'execute-api',
region: config.region,
endpoint: endpoint,
defaultContentType: config.defaultContentType,
defaultAcceptType: config.defaultAcceptType
};
var authType = 'NONE';
if (sigV4ClientConfig.accessKey !== undefined && sigV4ClientConfig.accessKey !== '' && sigV4ClientConfig.secretKey !== undefined && sigV4ClientConfig.secretKey !== '') {
authType = 'AWS_IAM';
}
var authType = 'NONE';
if (sigV4ClientConfig.accessKey !== undefined && sigV4ClientConfig.accessKey !== '' && sigV4ClientConfig.secretKey !== undefined && sigV4ClientConfig.secretKey !== '') {
authType = 'AWS_IAM';
}
var simpleHttpClientConfig = {
endpoint: endpoint,
defaultContentType: config.defaultContentType,
defaultAcceptType: config.defaultAcceptType
};
var simpleHttpClientConfig = {
endpoint: endpoint,
defaultContentType: config.defaultContentType,
defaultAcceptType: config.defaultAcceptType
};
var apiGatewayClient = apiGateway.core.apiGatewayClientFactory.newClient(simpleHttpClientConfig, sigV4ClientConfig);
var apiGatewayClient = _apiGatewayClient2.default.newClient(simpleHttpClientConfig, sigV4ClientConfig);
apigClient.invokeApi = function (params, pathTemplate, method, additionalParams, body) {
if (additionalParams === undefined) additionalParams = {};
if (body === undefined) body = '';
apigClient.invokeApi = function (params, pathTemplate, method, additionalParams, body) {
if (additionalParams === undefined) additionalParams = {};
if (body === undefined) body = '';
var request = {
verb: method.toUpperCase(),
path: pathComponent + uritemplate.parse(pathTemplate).expand(params),
headers: additionalParams.headers || {},
queryParams: additionalParams.queryParams,
body: body
};
return apiGatewayClient.makeRequest(request, authType, additionalParams, config.apiKey);
var request = {
verb: method.toUpperCase(),
path: pathComponent + _urlTemplate2.default.parse(pathTemplate).expand(params),
headers: additionalParams.headers || {},
queryParams: additionalParams.queryParams,
body: body
};
return apigClient;
return apiGatewayClient.makeRequest(request, authType, additionalParams, config.apiKey);
};
return apigClient;
};
module.exports = apigClientFactory;
exports.default = apigClientFactory;

@@ -1,58 +0,72 @@

/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
'use strict';
var apiGateway = apiGateway || {};
apiGateway.core = apiGateway.core || {};
apiGateway.core.utils = require('./utils');
apiGateway.core.sigV4ClientFactory = require('./sigV4Client');
apiGateway.core.simpleHttpClientFactory = require('./simpleHttpClient');
Object.defineProperty(exports, "__esModule", {
value: true
});
apiGateway.core.apiGatewayClientFactory = {};
apiGateway.core.apiGatewayClientFactory.newClient = function (simpleHttpClientConfig, sigV4ClientConfig) {
var apiGatewayClient = {};
//Spin up 2 httpClients, one for simple requests, one for SigV4
var sigV4Client = apiGateway.core.sigV4ClientFactory.newClient(sigV4ClientConfig);
var simpleHttpClient = apiGateway.core.simpleHttpClientFactory.newClient(simpleHttpClientConfig);
var _utils = require('./utils');
apiGatewayClient.makeRequest = function (request, authType, additionalParams, apiKey) {
//Default the request to use the simple http client
var clientToUse = simpleHttpClient;
var _utils2 = _interopRequireDefault(_utils);
//Attach the apiKey to the headers request if one was provided
if (apiKey !== undefined && apiKey !== '' && apiKey !== null) {
request.headers['x-api-key'] = apiKey;
}
var _sigV4Client = require('./sigV4Client.js');
if (request.body === undefined || request.body === '' || request.body === null || Object.keys(request.body).length === 0) {
request.body = undefined;
}
var _sigV4Client2 = _interopRequireDefault(_sigV4Client);
// If the user specified any additional headers or query params that may not have been modeled
// merge them into the appropriate request properties
request.headers = apiGateway.core.utils.mergeInto(request.headers, additionalParams.headers);
request.queryParams = apiGateway.core.utils.mergeInto(request.queryParams, additionalParams.queryParams);
var _simpleHttpClient = require('./simpleHttpClient.js');
//If an auth type was specified inject the appropriate auth client
if (authType === 'AWS_IAM') {
clientToUse = sigV4Client;
}
var _simpleHttpClient2 = _interopRequireDefault(_simpleHttpClient);
//Call the selected http client to make the request, returning a promise once the request is sent
return clientToUse.makeRequest(request);
};
return apiGatewayClient;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var apiGatewayClientFactory = {}; /*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
apiGatewayClientFactory.newClient = function (simpleHttpClientConfig, sigV4ClientConfig) {
var apiGatewayClient = {};
// Spin up 2 httpClients, one for simple requests, one for SigV4
var sigV4Client = _sigV4Client2.default.newClient(sigV4ClientConfig);
var simpleHttpClient = _simpleHttpClient2.default.newClient(simpleHttpClientConfig);
apiGatewayClient.makeRequest = function (request, authType, additionalParams, apiKey) {
// Default the request to use the simple http client
var clientToUse = simpleHttpClient;
// Attach the apiKey to the headers request if one was provided
if (apiKey !== undefined && apiKey !== '' && apiKey !== null) {
request.headers['x-api-key'] = apiKey;
}
if (request.body === undefined || request.body === '' || request.body === null || Object.keys(request.body).length === 0) {
request.body = undefined;
}
// If the user specified any additional headers or query params that may not have been modeled
// merge them into the appropriate request properties
request.headers = _utils2.default.mergeInto(request.headers, additionalParams.headers);
request.queryParams = _utils2.default.mergeInto(request.queryParams, additionalParams.queryParams);
// If an auth type was specified inject the appropriate auth client
if (authType === 'AWS_IAM') {
clientToUse = sigV4Client;
}
// Call the selected http client to make the request,
// returning a promise once the request is sent
return clientToUse.makeRequest(request);
};
return apiGatewayClient;
};
module.exports = apiGateway;
exports.default = apiGatewayClientFactory;

@@ -0,1 +1,33 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _axios = require('axios');
var _axios2 = _interopRequireDefault(_axios);
var _sha = require('crypto-js/sha256');
var _sha2 = _interopRequireDefault(_sha);
var _encHex = require('crypto-js/enc-hex');
var _encHex2 = _interopRequireDefault(_encHex);
var _hmacSha = require('crypto-js/hmac-sha256');
var _hmacSha2 = _interopRequireDefault(_hmacSha);
var _url = require('url');
var _url2 = _interopRequireDefault(_url);
var _utils = require('./utils');
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*

@@ -15,200 +47,192 @@ * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

*/
/* eslint max-len: ["error", 100]*/
var apiGateway = apiGateway || {};
apiGateway.core = apiGateway.core || {};
apiGateway.core.utils = require('./utils');
var axios = require('axios');
var SHA256 = require('crypto-js/sha256');
var encHex = require('crypto-js/enc-hex');
var HmacSHA256 = require('crypto-js/hmac-sha256');
var urlParser = require('url');
var sigV4ClientFactory = {};
sigV4ClientFactory.newClient = function (config) {
var AWS_SHA_256 = 'AWS4-HMAC-SHA256';
var AWS4_REQUEST = 'aws4_request';
var AWS4 = 'AWS4';
var X_AMZ_DATE = 'x-amz-date';
var X_AMZ_SECURITY_TOKEN = 'x-amz-security-token';
var HOST = 'host';
var AUTHORIZATION = 'Authorization';
apiGateway.core.sigV4ClientFactory = {};
apiGateway.core.sigV4ClientFactory.newClient = function (config) {
var AWS_SHA_256 = 'AWS4-HMAC-SHA256';
var AWS4_REQUEST = 'aws4_request';
var AWS4 = 'AWS4';
var X_AMZ_DATE = 'x-amz-date';
var X_AMZ_SECURITY_TOKEN = 'x-amz-security-token';
var HOST = 'host';
var AUTHORIZATION = 'Authorization';
function hash(value) {
return (0, _sha2.default)(value); // eslint-disable-line
}
function hash(value) {
return SHA256(value);
function hexEncode(value) {
return value.toString(_encHex2.default);
}
function hmac(secret, value) {
return (0, _hmacSha2.default)(value, secret, { asBytes: true }); // eslint-disable-line
}
function buildCanonicalRequest(method, path, queryParams, headers, payload) {
return method + '\n' + buildCanonicalUri(path) + '\n' + buildCanonicalQueryString(queryParams) + '\n' + buildCanonicalHeaders(headers) + '\n' + buildCanonicalSignedHeaders(headers) + '\n' + hexEncode(hash(payload));
}
function hashCanonicalRequest(request) {
return hexEncode(hash(request));
}
function buildCanonicalUri(uri) {
return encodeURI(uri);
}
function buildCanonicalQueryString(queryParams) {
if (Object.keys(queryParams).length < 1) {
return '';
}
function hexEncode(value) {
return value.toString(encHex);
var sortedQueryParams = [];
for (var property in queryParams) {
if (queryParams.hasOwnProperty(property)) {
sortedQueryParams.push(property);
}
}
sortedQueryParams.sort();
function hmac(secret, value) {
return HmacSHA256(value, secret, { asBytes: true });
var canonicalQueryString = '';
for (var i = 0; i < sortedQueryParams.length; i++) {
canonicalQueryString += sortedQueryParams[i] + '=' + encodeURIComponent(queryParams[sortedQueryParams[i]]) + '&';
}
return canonicalQueryString.substr(0, canonicalQueryString.length - 1);
}
function buildCanonicalRequest(method, path, queryParams, headers, payload) {
return method + '\n' + buildCanonicalUri(path) + '\n' + buildCanonicalQueryString(queryParams) + '\n' + buildCanonicalHeaders(headers) + '\n' + buildCanonicalSignedHeaders(headers) + '\n' + hexEncode(hash(payload));
function buildCanonicalHeaders(headers) {
var canonicalHeaders = '';
var sortedKeys = [];
for (var property in headers) {
if (headers.hasOwnProperty(property)) {
sortedKeys.push(property);
}
}
sortedKeys.sort();
function hashCanonicalRequest(request) {
return hexEncode(hash(request));
for (var i = 0; i < sortedKeys.length; i++) {
canonicalHeaders += sortedKeys[i].toLowerCase() + ':' + headers[sortedKeys[i]] + '\n';
}
return canonicalHeaders;
}
function buildCanonicalUri(uri) {
return encodeURI(uri);
function buildCanonicalSignedHeaders(headers) {
var sortedKeys = [];
for (var property in headers) {
if (headers.hasOwnProperty(property)) {
sortedKeys.push(property.toLowerCase());
}
}
sortedKeys.sort();
function buildCanonicalQueryString(queryParams) {
if (Object.keys(queryParams).length < 1) {
return '';
}
return sortedKeys.join(';');
}
var sortedQueryParams = [];
for (var property in queryParams) {
if (queryParams.hasOwnProperty(property)) {
sortedQueryParams.push(property);
}
}
sortedQueryParams.sort();
function buildStringToSign(datetime, credentialScope, hashedCanonicalRequest) {
return AWS_SHA_256 + '\n' + datetime + '\n' + credentialScope + '\n' + hashedCanonicalRequest;
}
var canonicalQueryString = '';
for (var i = 0; i < sortedQueryParams.length; i++) {
canonicalQueryString += sortedQueryParams[i] + '=' + encodeURIComponent(queryParams[sortedQueryParams[i]]) + '&';
}
return canonicalQueryString.substr(0, canonicalQueryString.length - 1);
}
function buildCredentialScope(datetime, region, service) {
return datetime.substr(0, 8) + '/' + region + '/' + service + '/' + AWS4_REQUEST;
}
function buildCanonicalHeaders(headers) {
var canonicalHeaders = '';
var sortedKeys = [];
for (var property in headers) {
if (headers.hasOwnProperty(property)) {
sortedKeys.push(property);
}
}
sortedKeys.sort();
function calculateSigningKey(secretKey, datetime, region, service) {
return hmac(hmac(hmac(hmac(AWS4 + secretKey, datetime.substr(0, 8)), region), service), AWS4_REQUEST);
}
for (var i = 0; i < sortedKeys.length; i++) {
canonicalHeaders += sortedKeys[i].toLowerCase() + ':' + headers[sortedKeys[i]] + '\n';
}
return canonicalHeaders;
}
function calculateSignature(key, stringToSign) {
return hexEncode(hmac(key, stringToSign));
}
function buildCanonicalSignedHeaders(headers) {
var sortedKeys = [];
for (var property in headers) {
if (headers.hasOwnProperty(property)) {
sortedKeys.push(property.toLowerCase());
}
}
sortedKeys.sort();
function buildAuthorizationHeader(accessKey, credentialScope, headers, signature) {
return AWS_SHA_256 + ' Credential=' + accessKey + '/' + credentialScope + ', SignedHeaders=' + buildCanonicalSignedHeaders(headers) + ', Signature=' + signature;
}
return sortedKeys.join(';');
}
var awsSigV4Client = {};
if (config.accessKey === undefined || config.secretKey === undefined) {
return awsSigV4Client;
}
awsSigV4Client.accessKey = _utils2.default.assertDefined(config.accessKey, 'accessKey');
awsSigV4Client.secretKey = _utils2.default.assertDefined(config.secretKey, 'secretKey');
awsSigV4Client.sessionToken = config.sessionToken;
awsSigV4Client.serviceName = _utils2.default.assertDefined(config.serviceName, 'serviceName');
awsSigV4Client.region = _utils2.default.assertDefined(config.region, 'region');
awsSigV4Client.endpoint = _utils2.default.assertDefined(config.endpoint, 'endpoint');
function buildStringToSign(datetime, credentialScope, hashedCanonicalRequest) {
return AWS_SHA_256 + '\n' + datetime + '\n' + credentialScope + '\n' + hashedCanonicalRequest;
awsSigV4Client.makeRequest = function (request) {
var verb = _utils2.default.assertDefined(request.verb, 'verb');
var path = _utils2.default.assertDefined(request.path, 'path');
var queryParams = _utils2.default.copy(request.queryParams);
if (queryParams === undefined) {
queryParams = {};
}
function buildCredentialScope(datetime, region, service) {
return datetime.substr(0, 8) + '/' + region + '/' + service + '/' + AWS4_REQUEST;
var headers = _utils2.default.copy(request.headers);
if (headers === undefined) {
headers = {};
}
function calculateSigningKey(secretKey, datetime, region, service) {
return hmac(hmac(hmac(hmac(AWS4 + secretKey, datetime.substr(0, 8)), region), service), AWS4_REQUEST);
// If the user has not specified an override for Content type the use default
if (headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
function calculateSignature(key, stringToSign) {
return hexEncode(hmac(key, stringToSign));
// If the user has not specified an override for Accept type the use default
if (headers['Accept'] === undefined) {
headers['Accept'] = config.defaultAcceptType;
}
function buildAuthorizationHeader(accessKey, credentialScope, headers, signature) {
return AWS_SHA_256 + ' Credential=' + accessKey + '/' + credentialScope + ', SignedHeaders=' + buildCanonicalSignedHeaders(headers) + ', Signature=' + signature;
var body = _utils2.default.copy(request.body);
// override request body and set to empty when signing GET requests
if (body === undefined || verb === 'GET') {
body = '';
} else {
body = JSON.stringify(body);
}
var awsSigV4Client = {};
if (config.accessKey === undefined || config.secretKey === undefined) {
return awsSigV4Client;
// If there is no body remove the content-type header so it is not included in SigV4 calculation
if (body === '' || body === undefined || body === null) {
delete headers['Content-Type'];
}
awsSigV4Client.accessKey = apiGateway.core.utils.assertDefined(config.accessKey, 'accessKey');
awsSigV4Client.secretKey = apiGateway.core.utils.assertDefined(config.secretKey, 'secretKey');
awsSigV4Client.sessionToken = config.sessionToken;
awsSigV4Client.serviceName = apiGateway.core.utils.assertDefined(config.serviceName, 'serviceName');
awsSigV4Client.region = apiGateway.core.utils.assertDefined(config.region, 'region');
awsSigV4Client.endpoint = apiGateway.core.utils.assertDefined(config.endpoint, 'endpoint');
awsSigV4Client.makeRequest = function (request) {
var verb = apiGateway.core.utils.assertDefined(request.verb, 'verb');
var path = apiGateway.core.utils.assertDefined(request.path, 'path');
var queryParams = apiGateway.core.utils.copy(request.queryParams);
if (queryParams === undefined) {
queryParams = {};
}
var headers = apiGateway.core.utils.copy(request.headers);
if (headers === undefined) {
headers = {};
}
var datetime = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z').replace(/[:\-]|\.\d{3}/g, '');
headers[X_AMZ_DATE] = datetime;
var parser = _url2.default.parse(awsSigV4Client.endpoint);
headers[HOST] = parser.hostname;
//If the user has not specified an override for Content type the use default
if (headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
var canonicalRequest = buildCanonicalRequest(verb, path, queryParams, headers, body);
var hashedCanonicalRequest = hashCanonicalRequest(canonicalRequest);
var credentialScope = buildCredentialScope(datetime, awsSigV4Client.region, awsSigV4Client.serviceName);
var stringToSign = buildStringToSign(datetime, credentialScope, hashedCanonicalRequest);
var signingKey = calculateSigningKey(awsSigV4Client.secretKey, datetime, awsSigV4Client.region, awsSigV4Client.serviceName);
var signature = calculateSignature(signingKey, stringToSign);
headers[AUTHORIZATION] = buildAuthorizationHeader(awsSigV4Client.accessKey, credentialScope, headers, signature);
if (awsSigV4Client.sessionToken !== undefined && awsSigV4Client.sessionToken !== '') {
headers[X_AMZ_SECURITY_TOKEN] = awsSigV4Client.sessionToken;
}
delete headers[HOST];
//If the user has not specified an override for Accept type the use default
if (headers['Accept'] === undefined) {
headers['Accept'] = config.defaultAcceptType;
}
var url = config.endpoint + path;
var queryString = buildCanonicalQueryString(queryParams);
if (queryString != '') {
url += '?' + queryString;
}
var body = apiGateway.core.utils.copy(request.body);
if (body === undefined || verb === 'GET') {
// override request body and set to empty when signing GET requests
body = '';
} else {
body = JSON.stringify(body);
}
// Need to re-attach Content-Type if it is not specified at this point
if (headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
//If there is no body remove the content-type header so it is not included in SigV4 calculation
if (body === '' || body === undefined || body === null) {
delete headers['Content-Type'];
}
var datetime = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z').replace(/[:\-]|\.\d{3}/g, '');
headers[X_AMZ_DATE] = datetime;
var parser = urlParser.parse(awsSigV4Client.endpoint);
headers[HOST] = parser.hostname;
var canonicalRequest = buildCanonicalRequest(verb, path, queryParams, headers, body);
var hashedCanonicalRequest = hashCanonicalRequest(canonicalRequest);
var credentialScope = buildCredentialScope(datetime, awsSigV4Client.region, awsSigV4Client.serviceName);
var stringToSign = buildStringToSign(datetime, credentialScope, hashedCanonicalRequest);
var signingKey = calculateSigningKey(awsSigV4Client.secretKey, datetime, awsSigV4Client.region, awsSigV4Client.serviceName);
var signature = calculateSignature(signingKey, stringToSign);
headers[AUTHORIZATION] = buildAuthorizationHeader(awsSigV4Client.accessKey, credentialScope, headers, signature);
if (awsSigV4Client.sessionToken !== undefined && awsSigV4Client.sessionToken !== '') {
headers[X_AMZ_SECURITY_TOKEN] = awsSigV4Client.sessionToken;
}
delete headers[HOST];
var url = config.endpoint + path;
var queryString = buildCanonicalQueryString(queryParams);
if (queryString != '') {
url += '?' + queryString;
}
//Need to re-attach Content-Type if it is not specified at this point
if (headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
var signedRequest = {
method: verb,
url: url,
headers: headers,
data: body
};
return axios(signedRequest);
var signedRequest = {
method: verb,
url: url,
headers: headers,
data: body
};
return (0, _axios2.default)(signedRequest);
};
return awsSigV4Client;
return awsSigV4Client;
};
module.exports = apiGateway.core.sigV4ClientFactory;
exports.default = sigV4ClientFactory;

@@ -0,1 +1,17 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _axios = require('axios');
var _axios2 = _interopRequireDefault(_axios);
var _utils = require('./utils');
var _utils2 = _interopRequireDefault(_utils);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*

@@ -15,72 +31,68 @@ * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

*/
/* eslint max-len: ["error", 100]*/
var apiGateway = apiGateway || {};
apiGateway.core = apiGateway.core || {};
apiGateway.core.utils = require('./utils');
var axios = require('axios');
var simpleHttpClientFactory = {};
simpleHttpClientFactory.newClient = function (config) {
function buildCanonicalQueryString(queryParams) {
// Build a properly encoded query string from a QueryParam object
if (Object.keys(queryParams).length < 1) {
return '';
}
apiGateway.core.simpleHttpClientFactory = {};
apiGateway.core.simpleHttpClientFactory.newClient = function (config) {
function buildCanonicalQueryString(queryParams) {
//Build a properly encoded query string from a QueryParam object
if (Object.keys(queryParams).length < 1) {
return '';
}
var canonicalQueryString = '';
for (var property in queryParams) {
if (queryParams.hasOwnProperty(property)) {
canonicalQueryString += encodeURIComponent(property) + '=' + encodeURIComponent(queryParams[property]) + '&';
}
}
var canonicalQueryString = '';
for (var property in queryParams) {
if (queryParams.hasOwnProperty(property)) {
canonicalQueryString += encodeURIComponent(property) + '=' + encodeURIComponent(queryParams[property]) + '&';
}
}
return canonicalQueryString.substr(0, canonicalQueryString.length - 1);
}
return canonicalQueryString.substr(0, canonicalQueryString.length - 1);
var simpleHttpClient = {};
simpleHttpClient.endpoint = _utils2.default.assertDefined(config.endpoint, 'endpoint');
simpleHttpClient.makeRequest = function (request) {
var verb = _utils2.default.assertDefined(request.verb, 'verb');
var path = _utils2.default.assertDefined(request.path, 'path');
var queryParams = _utils2.default.copy(request.queryParams);
if (queryParams === undefined) {
queryParams = {};
}
var headers = _utils2.default.copy(request.headers);
if (headers === undefined) {
headers = {};
}
var simpleHttpClient = {};
simpleHttpClient.endpoint = apiGateway.core.utils.assertDefined(config.endpoint, 'endpoint');
// If the user has not specified an override for Content type the use default
if (headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
simpleHttpClient.makeRequest = function (request) {
var verb = apiGateway.core.utils.assertDefined(request.verb, 'verb');
var path = apiGateway.core.utils.assertDefined(request.path, 'path');
var queryParams = apiGateway.core.utils.copy(request.queryParams);
if (queryParams === undefined) {
queryParams = {};
}
var headers = apiGateway.core.utils.copy(request.headers);
if (headers === undefined) {
headers = {};
}
// If the user has not specified an override for Accept type the use default
if (headers['Accept'] === undefined) {
headers['Accept'] = config.defaultAcceptType;
}
//If the user has not specified an override for Content type the use default
if (headers['Content-Type'] === undefined) {
headers['Content-Type'] = config.defaultContentType;
}
var body = _utils2.default.copy(request.body);
if (body === undefined) {
body = '';
}
//If the user has not specified an override for Accept type the use default
if (headers['Accept'] === undefined) {
headers['Accept'] = config.defaultAcceptType;
}
var body = apiGateway.core.utils.copy(request.body);
if (body === undefined) {
body = '';
}
var url = config.endpoint + path;
var queryString = buildCanonicalQueryString(queryParams);
if (queryString != '') {
url += '?' + queryString;
}
var simpleHttpRequest = {
method: verb,
url: url,
headers: headers,
data: body
};
return axios(simpleHttpRequest);
var url = config.endpoint + path;
var queryString = buildCanonicalQueryString(queryParams);
if (queryString != '') {
url += '?' + queryString;
}
var simpleHttpRequest = {
method: verb,
url: url,
headers: headers,
data: body
};
return simpleHttpClient;
return (0, _axios2.default)(simpleHttpRequest);
};
return simpleHttpClient;
};
module.exports = apiGateway.core.simpleHttpClientFactory;
exports.default = simpleHttpClientFactory;

@@ -0,1 +1,9 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/*

@@ -15,71 +23,71 @@ * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.

*/
/* eslint max-len: ["error", 100]*/
var apiGateway = apiGateway || {};
apiGateway.core = apiGateway.core || {};
apiGateway.core.utils = {
assertDefined: function (object, name) {
if (object === undefined) {
throw name + ' must be defined';
} else {
return object;
}
},
assertParametersDefined: function (params, keys, ignore) {
if (keys === undefined) {
return;
}
if (keys.length > 0 && params === undefined) {
params = {};
}
for (var i = 0; i < keys.length; i++) {
if (!apiGateway.core.utils.contains(ignore, keys[i])) {
apiGateway.core.utils.assertDefined(params[keys[i]], keys[i]);
}
}
},
parseParametersToObject: function (params, keys) {
if (params === undefined) {
return {};
}
var object = {};
for (var i = 0; i < keys.length; i++) {
object[keys[i]] = params[keys[i]];
}
return object;
},
contains: function (a, obj) {
if (a === undefined) {
return false;
}
var i = a.length;
while (i--) {
if (a[i] === obj) {
return true;
}
}
return false;
},
copy: function (obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
},
mergeInto: function (baseObj, additionalProps) {
if (null == baseObj || "object" != typeof baseObj) return baseObj;
var merged = baseObj.constructor();
for (var attr in baseObj) {
if (baseObj.hasOwnProperty(attr)) merged[attr] = baseObj[attr];
}
if (null == additionalProps || "object" != typeof additionalProps) return baseObj;
for (attr in additionalProps) {
if (additionalProps.hasOwnProperty(attr)) merged[attr] = additionalProps[attr];
}
return merged;
var utils = {
assertDefined: function assertDefined(object, name) {
if (object === undefined) {
throw new Error(name + ' must be defined');
} else {
return object;
}
},
assertParametersDefined: function assertParametersDefined(params, keys, ignore) {
if (keys === undefined) {
return;
}
if (keys.length > 0 && params === undefined) {
params = {};
}
for (var i = 0; i < keys.length; i++) {
if (!utils.contains(ignore, keys[i])) {
utils.assertDefined(params[keys[i]], keys[i]);
}
}
},
parseParametersToObject: function parseParametersToObject(params, keys) {
if (params === undefined) {
return {};
}
var object = {};
for (var i = 0; i < keys.length; i++) {
object[keys[i]] = params[keys[i]];
}
return object;
},
contains: function contains(a, obj) {
if (a === undefined) {
return false;
}
var i = a.length;
while (i--) {
if (a[i] === obj) {
return true;
}
}
return false;
},
copy: function copy(obj) {
if (null == obj || 'object' != (typeof obj === 'undefined' ? 'undefined' : _typeof(obj))) return obj;
var copy = obj.constructor();
var attr = null;
for (attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
},
mergeInto: function mergeInto(baseObj, additionalProps) {
if (null == baseObj || 'object' != (typeof baseObj === 'undefined' ? 'undefined' : _typeof(baseObj))) return baseObj;
var merged = baseObj.constructor();
var attr = null;
for (attr in baseObj) {
if (baseObj.hasOwnProperty(attr)) merged[attr] = baseObj[attr];
}
if (null == additionalProps || 'object' != (typeof additionalProps === 'undefined' ? 'undefined' : _typeof(additionalProps))) return baseObj;
for (attr in additionalProps) {
if (additionalProps.hasOwnProperty(attr)) merged[attr] = additionalProps[attr];
}
return merged;
}
};
module.exports = apiGateway.core.utils;
exports.default = utils;
{
"name": "aws-api-gateway-client",
"version": "0.2.2",
"version": "0.2.3",
"description": "Node.js moduel for AWS API Gateway client",

@@ -22,5 +22,6 @@ "repository": {

"transpile": "babel src -d dist/",
"prepublish": "npm run lint:js && npm run transpile",
"lint:js": "node_modules/eslint/bin/eslint.js lib *.js",
"test": "npm run lint:js"
"prepublish": "npm run lint && npm run transpile",
"lint": "node_modules/eslint/bin/eslint.js src lib *.js",
"test": "npm run lint && nyc --reporter=text ava",
"test:watch": "ava --watch"
},

@@ -31,5 +32,22 @@ "files": [

],
"ava": {
"require": [
"babel-register",
"babel-polyfill"
],
"babel": "inherit",
"files": [
"test/**/*.test.js"
]
},
"babel": {
"presets": [
"stage-2"
"@ava/stage-4",
"es2017",
"es2016",
"es2015",
"stage-0"
],
"plugins": [
"transform-es5-property-mutators"
]

@@ -44,2 +62,7 @@ },

"rules": {
"max-len": [
"error",
100
],
"require-jsdoc": "off",
"import/extensions": "off",

@@ -50,4 +73,4 @@ "import/no-extraneous-dependencies": "off"

"dependencies": {
"axios": "^0.15.3",
"crypto-js": "^3.1.8",
"axios": "^0.16.1",
"crypto-js": "^3.1.9-1",
"url": "^0.11.0",

@@ -57,12 +80,21 @@ "url-template": "^2.0.8"

"devDependencies": {
"babel-cli": "^6.22.2",
"babel-core": "^6.22.1",
"babel-eslint": "^7.1.1",
"babel-preset-stage-2": "^6.22.0",
"eslint": "^3.18.0",
"@ava/babel-preset-stage-4": "^1.0.0",
"ava": "^0.18.2",
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-eslint": "^7.2.1",
"babel-plugin-transform-es5-property-mutators": "^6.24.1",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"babel-preset-es2017": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.24.1",
"eslint": "^3.19.0",
"eslint-config-google": "^0.7.1",
"eslint-loader": "^1.6.1",
"eslint-loader": "^1.7.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0"
"eslint-plugin-jsx-a11y": "^4.0.0",
"nyc": "^10.2.0"
}
}
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