@isloth/common-lib
v0.2.123
Published
shared codes
Readme
common-lib
Shared code for all services
Build Library
npm run prepareInstallation
Install
npm install @isloth/common-libInstall/Update by latest version
npm install @isloth/common-lib@latestEnums
- CurrencyCode: ISO 4217 currency codes enumeration. Each member of this enum represents a three-letter currency code as defined by the ISO 4217 standard
classDiagram
class CurrencyCode {
<<enumeration>>
AED // United Arab Emirates Dirham
AFN // Afghanistan Afghani
ALL // Albania Lek
AMD // Armenia Dram
ANG // Netherlands Antillean Guilder
...
ZMW // Zambia Kwacha
ZWL // Zimbabwe Dollar
}
- DetailLevel: Represents the level of detail for displaying or processing information.
classDiagram
class DetailLevel {
<<enumeration>>
OVERVIEW
DETAIL
}
- ErrorCode: Standardized error codes used throughout the application.
classDiagram
class ErrorCode {
<<enumeration>>
// Client Errors - 4xx
INVALID_INPUT
VALIDATION
REQUIRED_INPUT
UNAUTHORIZED
NOT_FOUND
FORBIDDEN
CONFLICT
// Server Errors - 5xx
INTERNAL_SERVER_ERROR
NOT_IMPLEMENTED
SERVICE_UNAVAILABLE
GATEWAY_TIMEOUT
DATABASE_ERROR
EXTERNAL_SERVICE_ERROR
LIBRARY_ERROR
UNKNOWN_ERROR
}
- MediaType: Represents the different types of media supported by the application.
classDiagram
class MediaType {
<<enumeration>>
SCREENSHOT
PHOTO
VIDEO
AUDIO
DOCUMENT
}
- NodeEnv: Represents the possible runtime environments for a Node.js application.
classDiagram
class NodeEnv {
<<enumeration>>
DEVELOPMENT
PRODUCTION
TEST
}
- SortOrder: Specifies the sorting order for queries or collections.
classDiagram
class SortOrder {
<<enumeration>>
ASC
DESC
}
- StatusCode: Represents standard HTTP status codes used to indicate the result of an HTTP request.
classDiagram
class StatusCode {
<<enumeration>>
// 2xx Success
OK = 200
CREATED = 201
ACCEPTED = 202
NON_AUTHORITATIVE_INFORMATION = 203
NO_CONTENT = 204
// 4xx Client Errors
BAD_REQUEST = 400
UNAUTHORIZED = 401
PAYMENT_REQUIRED = 402
FORBIDDEN = 403
NOT_FOUND = 404
METHOD_NOT_ALLOWED = 405
NOT_ACCEPTABLE = 406
REQUEST_TIMEOUT = 408
CONFLICT = 409
LENGTH_REQUIRED = 411
PRECONDITION_FAILED = 412
PAYLOAD_TOO_LARGE = 413
URI_TOO_LONG = 414
UNSUPPORTED_MEDIA_TYPE = 415
UNPROCESSABLE_ENTITY = 422
LOCKED = 423
FAILED_DEPENDENCY = 424
UPGRADE_REQUIRED = 426
PRECONDITION_REQUIRED = 428
TOO_MANY_REQUESTS = 429
// 5xx Server Errors
INTERNAL_SERVER_ERROR = 500
NOT_IMPLEMENTED = 501
BAD_GATEWAY = 502
SERVICE_UNAVAILABLE = 503
HTTP_VERSION_NOT_SUPPORTED = 505
INSUFFICIENT_STORAGE = 507
LOOP_DETECTED = 508
NETWORK_AUTHENTICATION_REQUIRED = 511
}
- Role: Represents the different roles a user can have within the system.
classDiagram
class Role {
<<enumeration>>
USER
ADMIN
MODERATOR
SUPERADMIN
GUEST
}
Errors
classDiagram
class AppError {
+ errors: ErrorMessage[];
+ statusCode: StatusCode;
+ details: any;
+ constructor(message: string, statusCode: StatusCode = StatusCode.INTERNAL_SERVER_ERROR, details?: any)
+ addError(error: ErrorMessage): this
+ setErrors(errors: ErrorMessage[]): this
+ hasError(): boolean
+ toJson(): Object
}
class BadRequestError {
+ constructor(details?: any)
+ addInvalidInputError(field: string, value: string): this
+ addRequiredInputError(field: string): this
+ addConflictError(field: string, value: string): this
+ addErrors(errors: ErrorMessage[]): this
+ addValidationErrors(errors: ZodError): this
}
class ConflictError {
+ constructor(message: string, details?: any)
}
class DatabaseError {
+ constructor(database: string, table: string, operation: string, details?: any)
}
class ExternalServiceError {
+ constructor(service: string, message: string, details?: any)
}
class ForbiddenError {
+ constructor(details?: any)
}
class InternalServerError {
+ constructor(details?: any)
}
class LibraryError {
+ constructor(libName: string, message: string, details?: any)
}
class NotFoundError {
+ constructor(resource: string, details?: any)
}
class NotImplementedError {
+ constructor(source: string, message: string, details?: any)
}
class ServiceUnavailableError {
+ constructor(service: string, details?: any)
}
class TimeoutError {
+ constructor(source: string, message: string, details?: any)
}
class UnauthorizedError {
+ constructor(message: string, details?: any)
}
class UnexpectedError {
+ constructor(details?: any)
}
AppError <|.. BadRequestError
AppError <|.. ConflictError
AppError <|.. DatabaseError
AppError <|.. ExternalServiceError
AppError <|.. ForbiddenError
AppError <|.. InternalServerError
AppError <|.. LibraryError
AppError <|.. NotFoundError
AppError <|.. NotImplementedError
AppError <|.. ServiceUnavailableError
AppError <|.. TimeoutError
AppError <|.. UnauthorizedError
AppError <|.. UnexpectedError
