@weblablv/js-utils
v1.1.28
Published
Shared JavaScript utilities for WebLab serverless apps
Downloads
125
Readme
@weblablv/js-utils
Reusable JavaScript utilities for WebLab serverless apps.
This package includes standard wrappers and tools used across our AWS Lambda functions, with a focus on consistency, clean responses, and easy testing.
📦 Installation
npm install @weblablv/js-utils🚀 Usage
Lambda Response Helpers
successResponse(data, options)
Wraps a successful Lambda response in a standard format.
import { successResponse } from '@weblablv/js-utils';
return successResponse({ message: 'OK' });Options:
| Option | Type | Default | Description |
|-------------|-------------------------|---------|-------------------------|
| statusCode | number | 200 | HTTP status code |
| headers | Record<string,string> | {} | Custom headers (merged) |
errorResponse(error, options)
Wraps an error in a structured Lambda response and logs it.
import { errorResponse } from '@weblablv/js-utils';
return errorResponse(new Error('Invalid input'), {
statusCode: 400,
headers: { 'x-error': 'invalid' }
});The error object can contain .message and optionally .code.
✅ Features
- Clean, CORS-friendly Lambda responses
- Flexible status and headers support
- Support for plain responses (
text/csv) - Unified error output
- Fully tested with Jest
🧪 Testing
Run all tests:
npm test📁 Exports
import { successResponse, errorResponse } from '@weblablv/js-utils';✨ Coming Soon
- AWS service clients (S3, RDS, Slack)
- Debugging/test stubs
- CLI tools
📤 Publishing (for maintainers)
npm version patch
npm publish --access=public📄 License
MIT © WebLab
