@takentrade/takentrade-libs
v4.1.8
Published
TakeNTrade shared libraries
Downloads
1,451
Maintainers
Readme
TakeNTrade Microservices Libraries
Shared libraries for the TakeNTrade microservices architecture, providing authentication, caching, messaging, notifications, and common utilities.
Installation
npm install @takentrade/takentrade-libsQuick Start
import { CacheModule } from '@takentrade/takentrade-libs';
import { ConfigService } from '@nestjs/config';
@Module({
imports: [
CacheModule.registerAsync({
inject: [ConfigService],
useFactory: (configService: ConfigService) => ({
host: configService.get<string>('redis.host'),
port: configService.get<number>('redis.port'),
username: configService.get<string>('redis.username'),
password: configService.get<string>('redis.password'),
}),
}),
],
})
export class AppModule {}For authentication, services can extend the shared TntBaseAuthGuard and pair it with their own JWT strategy implementation based on TntJwtStrategy.
Modules
| Module | Description | Documentation | | ------------------ | ---------------------------------------------- | ---------------------------------------------- | | Authentication | Route protection and role-based access control | docs/auth.md | | Cache | Redis-based caching with TTL support | docs/cache.md | | BullMQ | Background job processing and queues | docs/bullmq.md | | NATS | Microservice messaging and event streaming | docs/nats.md | | Notifications | Email, SMS, and push notifications | docs/notifications.md | | RPC | Request-response patterns for NATS | docs/rpc.md | | Common | Shared constants, enums, and utilities | docs/common.md | | Utils | DTOs, pipes, filters, and helpers | docs/utils.md |
Features
🔐 Authentication & Authorization
@Public()and@Roles()decoratorsTntBaseAuthGuardfor shared JWT guard behavior- JWT-based authentication support
- Role-based access control
💾 Caching
- Redis integration with ioredis
- TTL support
- Hash operations
- Auto-reconnection
🚀 Background Jobs
- BullMQ integration
- Job scheduling and retries
- Delayed and repeatable jobs
- Progress tracking
📨 Messaging
- NATS integration
- Event patterns
- Request-response (RPC)
- Subject constants
- Automatic logging
📧 Notifications
- Email (verification, OTP, password reset, etc.)
- SMS notifications
- Push notifications
- Template support
Environment Variables
# Cache & BullMQ
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your_password
# NATS
NATS_URL=nats://localhost:4222
NATS_SERVICE_QUEUE=service_queue
# JWT
JWT_SECRET=your_jwt_secretUsage Examples
Cache
await this.cacheService.set('key', 'value', 3600); // 1 hour TTL
const value = await this.cacheService.get('key');Background Jobs
await this.queue.add(
'process-order',
{ orderId: '123' },
{
attempts: 3,
backoff: { type: 'exponential', delay: 1000 },
}
);Documentation
- Authentication - Route protection and RBAC
- Cache - Redis caching
- BullMQ - Background jobs
- NATS - Messaging
- Notifications - Email, SMS, push
- RPC - Request-response patterns
- Common - Shared utilities
- Utils - DTOs, pipes, filters
Contributing
This is a private package for TakeNTrade microservices.
License
Proprietary - See LICENSE file for details.
Support
For issues or questions, contact the TakeNTrade development team.
