
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@hsa-technologies-00/hsa-common
Advanced tools
The @hsa-technologies-00/hsa-common
package is a utility library designed to simplify common tasks in Node.js applications, such as error handling, logging, response formatting, and middleware integration. This package is particularly useful for Express.js applications but can be adapted for other frameworks.
To install the package, using npm:
npm install @hsa-technologies-00/hsa-common
using yarn:
yarn add @hsa-technologies-00/hsa-common
The package provides a set of predefined error classes and a global error handler for Express.js applications.
import { NotFoundException, globalErrorHandler } from '@hsa-technologies-00/hsa-common';
app.get('/not-found', (req, res, next) => {
next(new NotFoundException('Resource not found.'));
});
app.use(globalErrorHandler);
The package includes a logger with development and production configurations.
import { logger } from '@hsa-technologies-00/hsa-common';
logger.info('This is an info message.');
logger.error('This is an error message.');
The ApiResponse
class helps format API responses consistently.
import { ApiResponse } from '@hsa-technologies-00/hsa-common';
app.get('/success', (req, res) => {
const response = new ApiResponse({
message: 'Request successful',
statusCode: 200,
data: { key: 'value' },
fieldName: 'name',
});
res.status(200).json(response);
});
The package includes several middleware utilities, such as rate limiting, validation, and authentication.
Trims and sanitizes query parameters to ensure they are in the correct format.
import { customQueryParser } from '@hsa-technologies-00/hsa-common';
import express from 'express';
const app = express();
app.use(customQueryParser);
Limits the number of requests a user can make to prevent abuse.
import { globalRateLimiter } from '@hsa-technologies-00/hsa-common';
import express from 'express';
const app = express();
app.use(globalRateLimiter);
Validates request data using Joi schemas and throws a BadRequestException if validation fails.
import { validate } from '@hsa-technologies-00/hsa-common';
import express from 'express';
import Joi from 'joi';
const schema = Joi.object({
name: Joi.string().required(),
});
const app = express();
app.post('/data', validate('body')(schema), (req, res) => {
res.send('Data is valid.');
});
Provides middlewares for checking, requiring, and restricting access based on user roles.
import { checkAuth, requireAuth, restrictTo } from '@hsa-technologies-00/hsa-common';
import express from 'express';
const app = express();
app.use(checkAuth);
app.use('/admin', requireAuth, restrictTo('admin'), (req, res) => {
res.send('Admin access granted.');
});
The package provides utility functions for environment variable handling and query parsing.
import { getEnvVariable, trimQuery } from '@hsa-technologies-00/hsa-common';
const dbUrl = getEnvVariable('DATABASE_URL');
app.use((req, res, next) => {
req.query = trimQuery(req.query);
next();
});
The package provides utility functions for environment variable handling and query parsing.
import { ApiResponse, handleController } from '@hsa-technologies-00/hsa-common';
import express from 'express';
const app = express();
const controller = async ({ req }) => {
return new ApiResponse({
message: 'Data retrieved successfully.',
statusCode: 200,
data: { key: 'value' },
fieldName: 'name
});
};
app.get('/data', handleController(controller));
import express from 'express';
import {
NotFoundException,
globalErrorHandler,
logger,
ApiResponse,
globalRateLimiter,
handleController,
validate,
checkAuth,
customQueryParser,
trimQuery,
} from '@hsa-technologies-00/hsa-common';
import Joi from 'joi';
const app = express();
const validateBody = validate('body');
// Middleware
app.use(express.json());
app.use(globalRateLimiter);
// Custom query parser
app.use(customQueryParser);
// Trim query parameters
app.use((req, res, next) => {
req.query = trimQuery(req.query);
next();
});
// Routes
app.get('/not-found', (req, res, next) => {
next(new NotFoundException('Resource not found.'));
});
const validationSchema = Joi.object({
name: Joi.string().required(),
});
const controller = async ({ req }) => {
return new ApiResponse({
message: 'Validation passed',
statusCode: 200,
data: req.body,
fieldName: 'data',
});
};
app.post('/validate', validateBody(validationSchema), handleController(controller));
app.get('/protected', checkAuth, (req, res) => {
res.send('You are authenticated.');
});
// Global error handler
app.all('*', (req, res, next) => {
next(new NotFoundException(`Can't find ${req.method} ${req.originalUrl} on this server.`));
});
app.use(globalErrorHandler);
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
logger.info(`Server running on port ${PORT}`);
});
Contributions are welcome! Please follow these steps:
The @hsa-technologies-00/hsa-common package provides a robust set of tools to streamline the development of Node.js and Express applications. By following the best practices and utilizing the provided components, you can build scalable and maintainable applications.
This project is licensed under the MIT License.
For more information, visit the GitHub repository.
FAQs
Common module for hsa-technologies-00
We found that @hsa-technologies-00/hsa-common demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.