Skip to content

nestlibs/nestlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺΊ Nestlib – NestJS Modules & Decorators Monorepo

LSK.js NPM version NPM downloads Package size Ask us in Telegram

❀️‍πŸ”₯ Comprehensive collection of modules, decorators, and utilities for building powerful NestJS applications ❀️‍πŸ”₯

πŸš€ Production Ready: Battle-tested modules used in production environments
πŸ’Ž TypeScript: Full TypeScript support with strict type checking
⚑ Fast: Optimized for performance with minimal overhead
πŸ”§ Modular: Use only what you need, tree-shakeable packages
πŸ“¦ Well Documented: Comprehensive documentation and examples
🎯 Focused: Essential functionality without bloat

πŸ“¦ Packages

Package Version Size Description
@nestlib/access-logger npm size HTTP request logging middleware for NestJS
@nestlib/auth npm size Authentication helpers with OTP support
@nestlib/cache npm size Caching decorators and utilities
@nestlib/config npm size Configuration management module
@nestlib/crypto npm size Cryptographic operations (bcrypt, hashing)
@nestlib/decorators npm size Custom parameter decorators and transformers
@nestlib/interceptors npm size Response and error interceptors
@nestlib/lsk npm size LSK module wrapper for NestJS
@nestlib/mikro-orm npm size MikroORM logger factory integration
@nestlib/mutex npm size Distributed locking and mutex utilities
@nestlib/notify npm size Notification sender (Telegram, Slack, Email)
@nestlib/rabbitmq npm size RabbitMQ integration with RPC support
@nestlib/redis npm size Redis client and service wrapper
@nestlib/upload npm size File upload service for AWS S3
@nestlib/utils npm size Common utilities and helpers

πŸš€ Quick Start

Access Logger

npm install @nestlib/access-logger
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { AccessLoggerMiddleware } from '@nestlib/access-logger';

@Module({})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(AccessLoggerMiddleware)
      .forRoutes('*');
  }
}

Auth

npm install @nestlib/auth
import { AuthModule } from '@nestlib/auth';

@Module({
  imports: [AuthModule.forRoot({ ... })],
})
export class AppModule {}

Cache

npm install @nestlib/cache
import { Cache } from '@nestlib/cache';

@Controller('users')
export class UsersController {
  @Cache({ ttl: 60 })
  @Get(':id')
  async getUser(@Param('id') id: string) {
    return this.usersService.findOne(id);
  }
}

Config

npm install @nestlib/config
import { ConfigModule } from '@nestlib/config';

@Module({
  imports: [ConfigModule.forRoot()],
})
export class AppModule {}

Crypto

npm install @nestlib/crypto
import { CryptoService } from '@nestlib/crypto';

@Injectable()
export class AuthService {
  constructor(private cryptoService: CryptoService) {}

  async hashPassword(password: string) {
    return this.cryptoService.hash(password);
  }
}

Decorators

npm install @nestlib/decorators
import { Query, Data } from '@nestlib/decorators';

@Controller('search')
export class SearchController {
  @Get()
  async search(@Query('q') query: string, @Data() data: any) {
    // ...
  }
}

Interceptors

npm install @nestlib/interceptors
import { ResponseInterceptor, ErrorInterceptor } from '@nestlib/interceptors';

@UseInterceptors(ResponseInterceptor, ErrorInterceptor)
@Controller('api')
export class ApiController {}

Redis

npm install @nestlib/redis
import { RedisModule } from '@nestlib/redis';

@Module({
  imports: [RedisModule.forRoot({ ... })],
})
export class AppModule {}

RabbitMQ

npm install @nestlib/rabbitmq
import { RmqModule } from '@nestlib/rabbitmq';

@Module({
  imports: [RmqModule.forRoot({ ... })],
})
export class AppModule {}

✨ Features

πŸ” Access Logger

  • Request ID Generation: Unique request IDs for tracing
  • Smart Log Levels: Automatic log level based on status codes and response time
  • Comprehensive Logging: Method, URL, IP, user agent, status, duration, and more
  • WebSocket Support: Special handling for WebSocket connections
  • IP Detection: Automatic client IP extraction from headers

πŸ” Auth

  • OTP Support: One-time password generation and validation
  • Session Management: Express session integration with MongoDB storage
  • Password Reset: Complete password reset flow with email support
  • User Models: Ready-to-use user and OTP models for MikroORM
  • Guards & Decorators: @Auth() decorator and AuthGuard for route protection

πŸ’Ύ Cache

  • Decorator-based: @Cache() and @LruCache() decorators
  • LRU Cache: In-memory LRU cache support
  • Cache Manager Integration: Works with NestJS Cache Manager
  • Cache Invalidation: @IgnoreCache() decorator for selective invalidation

βš™οΈ Config

  • Environment Variables: Automatic .env file loading
  • Type-safe Configuration: Full TypeScript support
  • Module Integration: Seamless NestJS Config module integration
  • Validation: Configuration validation with error handling

πŸ”’ Crypto

  • Password Hashing: bcrypt and bcryptjs support
  • Secure Operations: Cryptographic utilities for hashing and comparison
  • Async Operations: Promise-based API

🎨 Decorators

  • Parameter Decorators: @Query(), @Data(), @FindParams(), @QueryOrBody()
  • Transformers: @Trim(), @ToLowerCase() for data transformation
  • Validation: Integrated with class-validator

πŸ›‘οΈ Interceptors

  • Response Interceptor: Standardized API response format
  • Error Interceptor: Comprehensive error handling and formatting
  • Pretty Errors: Human-readable error messages in development
  • Request Context: Request ID and metadata tracking

πŸ”„ Mutex

  • Distributed Locking: Redis-based distributed locks
  • In-memory Locks: Async lock support for single-instance applications
  • Decorator Support: @Lock() decorator for automatic locking
  • Timeout Handling: Configurable lock timeouts

πŸ“’ Notify

  • Multi-channel: Telegram, Slack, and Email support
  • Service Integration: Injectable NotifyService for easy use
  • Error Notifications: Automatic error reporting

🐰 RabbitMQ

  • RPC Support: @RmqRPC() decorator for RPC handlers
  • Message Publishing: Easy message publishing with RmqService
  • Error Handling: Automatic error callbacks and retries
  • Interceptor: Request/response logging and error handling

πŸ”΄ Redis

  • Service Wrapper: Simplified Redis client interface
  • Connection Management: Automatic connection handling
  • Type Safety: Full TypeScript support

πŸ“€ Upload

  • AWS S3 Integration: Direct S3 upload support
  • Presigned URLs: Generate presigned URLs for secure uploads
  • File Management: Upload, delete, and manage files in S3

πŸ› οΈ Utils

  • Exception Filter: AnyExceptionFilter for global error handling
  • Validation Pipe: AnyValidationPipe for request validation
  • Logger Factory: createNestLogger for consistent logging
  • Time Decorator: @Time() decorator for performance measurement

πŸ›  Development

# Install dependencies
pnpm install

# Build all packages
pnpm run build

# Run tests
pnpm run test

# Release packages
pnpm run release

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork it (https://github.com/lskjs/nestlib/fork)
  2. Create your feature branch (git checkout -b features/fooBar)
  3. Commit your changes (git commit -am 'feat: Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

πŸ“ License

MIT Β© Igor Suvorov

πŸ”— Links


@nestlib – Comprehensive modules and decorators for NestJS 🎯

About

Module & Decorator collection for Nest.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 13