
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@abstraks-dev/lambda-responses
Advanced tools
Standardized Lambda response helpers with CORS support for AWS API Gateway
Standardized Lambda response helpers with CORS support for AWS API Gateway.
npm install @abstraks-dev/lambda-responses
import { createSuccessResponse } from '@abstraks-dev/lambda-responses';
export const handler = async (event) => {
const data = { message: 'Hello World', timestamp: new Date().toISOString() };
return createSuccessResponse(data);
};
// Returns:
// {
// statusCode: 200,
// headers: { /* CORS headers */ },
// body: '{"message":"Hello World","timestamp":"2024-01-01T00:00:00.000Z"}'
// }
import {
createBadRequestResponse,
createUnauthorizedResponse,
createNotFoundResponse,
createServerErrorResponse,
} from '@abstraks-dev/lambda-responses';
// Bad Request (400)
export const handler = async (event) => {
if (!event.body) {
return createBadRequestResponse('Request body is required');
}
// ... your logic
};
// Unauthorized (401)
if (!isAuthenticated) {
return createUnauthorizedResponse('Invalid token');
}
// Not Found (404)
if (!user) {
return createNotFoundResponse('User not found');
}
// Server Error (500)
try {
// ... your logic
} catch (error) {
return createServerErrorResponse('Database connection failed');
}
import { createErrorResponse } from '@abstraks-dev/lambda-responses';
export const handler = async (event) => {
try {
// ... your logic
} catch (error) {
// Automatically uses error.statusCode if present, defaults to 500
return createErrorResponse(error);
}
};
// Custom status code:
const error = new Error('Resource not found');
error.statusCode = 404;
return createErrorResponse(error);
import { createValidationErrorResponse } from '@abstraks-dev/lambda-responses';
const validationErrors = [
{ field: 'email', message: 'Invalid email format' },
{ field: 'password', message: 'Password must be at least 8 characters' },
];
return createValidationErrorResponse(validationErrors);
// Returns:
// {
// statusCode: 422,
// headers: { /* CORS headers */ },
// body: '{"error":"Validation failed","details":[...]}'
// }
import { createOptionsResponse } from '@abstraks-dev/lambda-responses';
export const handler = async (event) => {
if (event.httpMethod === 'OPTIONS') {
return createOptionsResponse();
}
// ... your logic
};
import { withErrorHandling } from '@abstraks-dev/lambda-responses';
const myHandler = async (event, context) => {
// If this throws an error, it will automatically be converted to an error response
const data = await fetchData();
return createSuccessResponse(data);
};
// Wrap with automatic error handling
export const handler = withErrorHandling(myHandler);
import { createSuccessResponse } from '@abstraks-dev/lambda-responses';
// Created (201)
return createSuccessResponse({ id: '123', created: true }, 201);
// Accepted (202)
return createSuccessResponse({ queued: true }, 202);
// No Content (204)
return createSuccessResponse({}, 204);
import {
createSuccessResponse,
CORS_HEADERS,
} from '@abstraks-dev/lambda-responses';
const customHeaders = {
...CORS_HEADERS,
'X-Custom-Header': 'value',
'Cache-Control': 'max-age=3600',
};
return createSuccessResponse(data, 200, customHeaders);
createSuccessResponse(data, statusCode?, headers?) - Create success response (default 200)createErrorResponse(error, headers?) - Create error response from Error objectcreateBadRequestResponse(message?, headers?) - Create 400 responsecreateUnauthorizedResponse(message?, headers?) - Create 401 responsecreateForbiddenResponse(message?, headers?) - Create 403 responsecreateNotFoundResponse(message?, headers?) - Create 404 responsecreateValidationErrorResponse(errors, headers?) - Create 422 responsecreateServerErrorResponse(message?, headers?) - Create 500 responsecreateOptionsResponse(headers?) - Create OPTIONS response for CORS preflightcreateResponse(statusCode, body, headers?) - Low-level response creatorcreateErrorResponseWithCode(statusCode, message, headers?) - Create error with specific codewithErrorHandling(handler) - Wrap handler with automatic error handlingCORS_HEADERS - Default CORS headers objectAll responses follow this structure:
{
statusCode: number,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Credentials': 'true',
},
body: string // JSON stringified
}
{
// Your data directly
}
{
"error": "Error message"
}
{
"error": "Validation failed",
"details": [{ "field": "email", "message": "Invalid format" }]
}
// Old code in each service
export const createErrorResponse = (error) => {
return {
statusCode: error.statusCode || 500,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
'Access-Control-Allow-Methods': 'GET,POST,PUT,DELETE,OPTIONS',
'Access-Control-Allow-Credentials': 'true',
},
body: JSON.stringify({ error: error.message }),
};
};
// New code using shared module
import { createErrorResponse } from '@abstraks-dev/lambda-responses';
// That's it! Same functionality, maintained in one place
The package includes comprehensive tests with 100% coverage:
npm test
MIT
See the main shared-modules repository for contribution guidelines.
FAQs
Standardized Lambda response helpers with CORS support for AWS API Gateway
We found that @abstraks-dev/lambda-responses demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.