@3d-outlet/contracts
v1.3.5
Published
Protobuf definitions and generated TypeScript types
Readme
📡 @3d-outlet/contracts
Protobuf definitions and generated TypeScript types for 3D OUTLET microservices
✨ Features
- 🔌 Protobuf Definitions - Type-safe gRPC service definitions
- 📦 TypeScript Types - Auto-generated TypeScript interfaces from
.protofiles - 🚀 NestJS Integration - Ready-to-use with NestJS microservices
- 🔄 Event Types - Shared event interfaces for inter-service communication
- 💎 Type Safety - Full type checking across microservices
📦 Installation
npm install @3d-outlet/contracts
# or
pnpm add @3d-outlet/contracts
# or
yarn add @3d-outlet/contracts
# or
bun add @3d-outlet/contracts🚀 Quick Start
Using Protobuf Services
import { PROTO_PATHS } from '@3d-outlet/contracts'
// In your NestJS microservice
const app = await NestFactory.createMicroservice(AppModule, {
transport: Transport.GRPC,
options: {
protoPath: PROTO_PATHS.AUTH,
package: 'auth.v1'
}
})Using Generated Types
import { SendOtpRequest, SendOtpResponse } from '@3d-outlet/contracts'
async function sendOtp(data: SendOtpRequest): Promise<SendOtpResponse> {
// Type-safe implementation
return { ok: true }
}Using Event Interfaces
import { OtpRequestedEvent } from '@3d-outlet/contracts'
function handleOtpRequested(event: OtpRequestedEvent) {
console.log(`OTP requested for ${event.identifier}`)
}📁 Project Structure
contracts/
├── proto/ # Protobuf definition files
│ └── auth.proto # Authentication service definitions
├── gen/ # Generated TypeScript files (auto-generated)
│ └── ts/
├── src/ # Source TypeScript files
│ ├── events/ # Event interfaces
│ │ └── auth/ # Auth-related events
│ └── proto/ # Proto path utilities
└── dist/ # Compiled JavaScript (after build)🛠️ Development
Prerequisites
- Node.js: >= 16.0.0
- protoc: Protocol Buffer compiler
- TypeScript: ^5.9.3
Installing protoc
macOS:
brew install protobufUbuntu/Debian:
sudo apt-get update && sudo apt-get install -y protobuf-compilerWindows: Download from
Building the Package
# Install dependencies
npm install
# or
pnpm install
# or
bun install
# Generate TypeScript from Protobuf
npm run generate
# Build TypeScript
npm run build📋 Available Services
Auth Service (auth.v1)
Authentication and authorization service with OTP-based authentication.
RPC Methods:
SendOtp- Send OTP code to userVerifyOtp- Verify OTP code and get tokensRefresh- Refresh access token
Example:
import { AuthServiceController } from '@3d-outlet/contracts'
@Controller()
export class AuthController implements AuthServiceController {
async sendOtp(request: SendOtpRequest): Promise<SendOtpResponse> {
// Implementation
return { ok: true }
}
}🎯 Usage in NestJS
Client Side
import { ClientGrpc } from '@nestjs/microservices'
import { AuthServiceClient } from '@3d-outlet/contracts'
@Injectable()
export class AuthClient {
private authService: AuthServiceClient
constructor(@Inject('AUTH_PACKAGE') private client: ClientGrpc) {}
onModuleInit() {
this.authService = this.client.getService<AuthServiceClient>('AuthService')
}
async sendOtp(identifier: string, type: string) {
return this.authService.sendOtp({ identifier, type })
}
}Server Side
import { PROTO_PATHS } from '@3d-outlet/contracts'
// In main.ts or app.module.ts
const microserviceOptions: MicroserviceOptions = {
transport: Transport.GRPC,
options: {
protoPath: PROTO_PATHS.AUTH,
package: 'auth.v1',
url: '0.0.0.0:5000'
}
}📝 License
ISC © TeaCoder & Ilnaz Mingaleev
👨💻 Authors
TeaCoder (Vadim)
- Email: [email protected]
Ilnaz Mingaleev
- Email: [email protected]
Made with ❤️ for the 3D OUTLET project (private repo)
Internal use only.
