dt-common-libs
v2.0.41
Published
This project consists of a collection of modules and utilities for handling various aspects of web development, including exception handling, constants, API responses, Redis operations, Axios wrapper, configuration reading, validation messages, HTTP reque
Downloads
142
Maintainers
Readme
Project Overview
This project consists of a collection of modules and utilities for handling various aspects of web development, including exception handling, constants, API responses, Redis operations, Axios wrapper, configuration reading, validation messages, HTTP request helpers, helper functions, middleware, and request validation.
Modules and Utilities
Exception Handling
- Provides error classes for different types of exceptions:
AuthenticationError
,UnauthorizedError
,ValidationError
,DatabaseError
,RedisError
,ThirdPartyError
, andKafkaError
.
Constants
- Exports a collection of constants from
./constants/constants.js
.
API Responses
- Exports functions for sending different types of API responses:
sendResponse
,sendSuccessResponse
,sendFailureResponse
,sendUnauthorizedResponse
,sendValidationFailureResponse
, andsendServerErrorResponse
.
Redis Operations
- Exports functions for performing Redis operations such as deleting, writing, reading, and cleanup.
Axios Wrapper
- Provides an Axios wrapper for making HTTP requests.
Configuration Reading
- Exports a function
readConfig
to read configuration settings from a file.
Validation Messages
- Exports default validation messages from
./message/validation.js
.
HTTP Request Helpers
- Provides helper functions for making HTTP requests using various methods such as GET, POST, PATCH, PUT, and DELETE.
Helper Functions
- Exports various helper functions like
isEmpty
,getErrorMessage
,paginateHelper
,isUnique
, andisDataExists
.
Middleware
- Exports middleware functions such as
setAcceptedLanguage
,graphqlAuth
,authHandler
, andparseUserHeaders
.
Request Validation
- Exports a function
baseValidateResponse
for validating requests.
Usage
To use any of the functionalities provided by this project, import the required modules and utilities into your codebase using ES6 import syntax.
Example:
import { sendResponse, sendSuccessResponse } from './libs/ApiResponse.js';
// Use sendResponse and sendSuccessResponse functions
Feel free to replace the comment with your actual examples and instructions.