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

aws-core-utils

Package Overview
Dependencies
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-core-utils - npm Package Compare versions

Comparing version 6.0.11 to 6.0.12

24

api-lambdas.js

@@ -66,5 +66,5 @@ 'use strict';

*
* @param {Object|StandardContext|undefined} [initContext] - an optional module-scope context from which to copy an initial standard context
* @param {StandardSettings|undefined} [initSettings] - optional module-scoped settings from which to copy initial settings to use to configure a standard context
* @param {StandardOptions|undefined} [initOptions] - optional module-scoped options from which to copy initial options to use to configure a standard context
* @param {(function(): (Object|StandardContext))|undefined|Object|StandardContext} [generateContext] - an optional function that will be used to generate the initial context to be configured & used (OR or an optional LEGACY module-scope context from which to copy an initial standard context)
* @param {(function(): (Object|StandardSettings))|undefined|Object|StandardSettings} [generateSettings] - an optional function that will be used to generate initial standard settings to use (OR optional LEGACY module-scoped settings from which to copy initial settings to use)
* @param {(function(): (Object|StandardOptions))|undefined|Object|StandardOptions} [generateOptions] - an optional function that will be used to generate initial standard options to use (OR optional LEGACY module-scoped options from which to copy initial options to use)
* @param {function(event: AWSEvent, context: StandardContext)} fn - your function that must accept the AWS event and a standard context and ideally return a Promise

@@ -82,3 +82,4 @@ * @param {LogLevel|string|undefined} [logRequestResponseAtLogLevel] - an optional log level at which to log the request (i.e.

*/
function generateHandlerFunction(initContext, initSettings, initOptions, fn, logRequestResponseAtLogLevel, allowedHttpStatusCodes, invalidRequestMsg, failureMsg, successMsg) {
function generateHandlerFunction(generateContext, generateSettings, generateOptions, fn,
logRequestResponseAtLogLevel, allowedHttpStatusCodes, invalidRequestMsg, failureMsg, successMsg) {
/**

@@ -91,7 +92,16 @@ * An API-Gateway exposed Lambda handler function.

function handler(event, awsContext, callback) {
const context = initContext && typeof initContext === 'object' ? copy(initContext, {deep: true}) : {};
let context = undefined;
const deep = {deep: true};
try {
const settings = initSettings && typeof initSettings === 'object' ? copy(initSettings, {deep: true}) : undefined;
const options = initOptions && typeof initOptions === 'object' ? copy(initOptions, {deep: true}) : undefined;
// Configure the context as a standard context
context = typeof generateContext === 'function' ? generateContext() :
generateContext && typeof generateContext === 'object' ? copy(generateContext, deep) : {};
if (!context) context = {};
const settings = typeof generateSettings === 'function' ? copy(generateSettings(), deep) :
generateSettings && typeof generateSettings === 'object' ? copy(generateSettings, deep) : undefined;
const options = typeof generateOptions === 'function' ? copy(generateOptions(), deep) :
generateOptions && typeof generateOptions === 'object' ? copy(generateOptions, deep) : undefined;
// Configure the context as a standard context

@@ -98,0 +108,0 @@ contexts.configureStandardContext(context, settings, options, event, awsContext, false);

'use strict';
let AWS = require("aws-sdk");
let AWS = require('aws-sdk');

@@ -5,0 +5,0 @@ // Module-scope cache of AWS.DynamoDB.DocumentClient instances by region key

'use strict';
let AWS = require("aws-sdk");
let AWS = require('aws-sdk');

@@ -5,0 +5,0 @@ // Module-scope cache of AWS.Kinesis instances by region key

{
"name": "aws-core-utils",
"version": "6.0.11",
"version": "6.0.12",
"description": "Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc.",

@@ -15,9 +15,9 @@ "author": "Byron du Preez",

"core-functions": "3.0.6",
"logging-utils": "4.0.5",
"logging-utils": "4.0.6",
"deep-equal": "1.0.1"
},
"devDependencies": {
"aws-sdk": "2.45.0"
"aws-sdk": "2.54.0"
},
"repository": "https://github.com/byron-dupreez/aws-core-utils"
}

@@ -1,2 +0,2 @@

# aws-core-utils v6.0.11
# aws-core-utils v6.0.12

@@ -394,2 +394,13 @@ Core utilities for working with Amazon Web Services (AWS), including ARNs, regions, stages, Lambdas, AWS errors, stream events, Kinesis, DynamoDB.DocumentClients, etc.

### 6.0.12
- Changes to `api-lambdas` module:
- Renamed `initContext`, `initSettings` & `initOptions` parameters of `generateHandler` function to `generateContext`,
`generateSettings` & `generateOptions` respectively
- Changed `generateHandler` function to accept `generateContext`, `generateSettings` & `generateOptions` arguments
as functions that can be used to generate non-shared objects, in addition to still providing legacy support for them
being passed as shared, module-scoped objects that must be copied to be safely used
- Upgraded `logging-utils` dependency to 4.0.6
- Upgraded `aws-sdk` dev dependency to 2.54.0 to match current AWS Lambda runtime version
- Upgraded `aws-core-test-utils` test dependency to 2.0.8
### 6.0.11

@@ -396,0 +407,0 @@ - Upgraded `aws-core-test-utils` test dependency to 2.0.7

@@ -66,6 +66,6 @@ 'use strict';

// =====================================================================================================================
// generateHandlerFunction simulating successful response
// generateHandlerFunction simulating successful response (with legacy parameters)
// =====================================================================================================================
test('generateHandlerFunction simulating successful response', t => {
test('generateHandlerFunction simulating successful response (with legacy parameters)', t => {
try {

@@ -116,6 +116,6 @@ // Set up environment for testing

// =====================================================================================================================
// generateHandlerFunction simulating invalid request
// generateHandlerFunction simulating invalid request (with legacy parameters)
// =====================================================================================================================
test('generateHandlerFunction simulating invalid request', t => {
test('generateHandlerFunction simulating invalid request (with legacy parameters)', t => {
try {

@@ -175,6 +175,6 @@ // Set up environment for testing

// =====================================================================================================================
// generateHandlerFunction simulating failure
// generateHandlerFunction simulating failure (with legacy parameters)
// =====================================================================================================================
test('generateHandlerFunction simulating failure', t => {
test('generateHandlerFunction simulating failure (with legacy parameters)', t => {
try {

@@ -230,2 +230,53 @@ // Set up environment for testing

}
});
// =====================================================================================================================
// generateHandlerFunction simulating successful response (with NON-legacy parameters)
// =====================================================================================================================
test('generateHandlerFunction simulating successful response (with NON-legacy parameters)', t => {
try {
// Set up environment for testing
const region = setRegionStageAndDeleteCachedInstances('us-west-2', 'dev99');
// Create sample AWS event and AWS context
const event = {body: {abc: 123}};
const invokedFunctionArn = sampleInvokedFunctionArn(region, 'myLambdaFunctionName', 'dev77');
const awsContext = sampleAwsContext('myLambdaFunctionName', '1.0.1', invokedFunctionArn, 500);
const expectedResponse = {def: 456};
// Create a sample function to be executed within the Lambda handler function
const fn = sampleFunction(expectedResponse, undefined);
// Create a sample AWS Lambda handler function
const generateContext = () => { return {}; }; // NB: Do NOT use () => {}, since this returns undefined & not an object!
const generateSettings = () => undefined;
const generateOptions = () => require('./sample-standard-options.json');
const handler = apiLambdas.generateHandlerFunction(generateContext, generateSettings, generateOptions, fn,
LogLevel.INFO); //, undefined, 'Invalid do something request', 'Failed to do something useful', 'Did something useful');
// Wrap the callback-based AWS Lambda handler function as a Promise returning function purely for testing purposes
const handlerWithPromise = Promises.wrap(handler);
// Invoke the handler function
handlerWithPromise(event, awsContext)
.then(response => {
t.pass(`handler should have passed`);
t.equal(response, expectedResponse, `response must be ${JSON.stringify(expectedResponse)}`);
t.end();
})
.catch(err => {
t.fail(`handler should not have failed - ${err.stack}`);
t.end();
});
} catch (err) {
t.fail(`handler should not have failed in try-catch - ${err.stack}`);
t.end();
} finally {
// Clean up environment
setRegionStageAndDeleteCachedInstances(undefined, undefined);
}
});
{
"name": "aws-core-utils-tests",
"description": "Unit tests for aws-core-utils modules",
"version": "6.0.11",
"version": "6.0.12",
"author": "Byron du Preez",

@@ -15,3 +15,3 @@ "license": "Apache-2.0",

"devDependencies": {
"aws-core-test-utils": "2.0.7",
"aws-core-test-utils": "2.0.8",
"tape": "^4.6.3",

@@ -18,0 +18,0 @@ "uuid": "3.1.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