@3d-outlet/contracts 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ <div align="center">
2
+
3
+ # 📡 @3d-outlet/contracts
4
+
5
+ **Protobuf definitions and generated TypeScript types for 3D OUTLET microservices**
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@3d-outlet/contracts?style=for-the-badge)](https://www.npmjs.com/package/@3d-outlet/contracts)
8
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=for-the-badge)](https://opensource.org/licenses/ISC)
9
+
10
+ </div>
11
+
12
+ ---
13
+
14
+ ## ✨ Features
15
+
16
+ - 🔌 **Protobuf Definitions** - Type-safe gRPC service definitions
17
+ - 📦 **TypeScript Types** - Auto-generated TypeScript interfaces from `.proto` files
18
+ - 🚀 **NestJS Integration** - Ready-to-use with NestJS microservices
19
+ - 🔄 **Event Types** - Shared event interfaces for inter-service communication
20
+ - 💎 **Type Safety** - Full type checking across microservices
21
+
22
+ ---
23
+
24
+ ## 📦 Installation
25
+
26
+ ```bash
27
+ npm install @3d-outlet/contracts
28
+ # or
29
+ pnpm add @3d-outlet/contracts
30
+ # or
31
+ yarn add @3d-outlet/contracts
32
+ # or
33
+ bun add @3d-outlet/contracts
34
+ ```
35
+
36
+ ---
37
+
38
+ ## 🚀 Quick Start
39
+
40
+ ### Using Protobuf Services
41
+
42
+ ```typescript
43
+ import { PROTO_PATHS } from '@3d-outlet/contracts'
44
+
45
+ // In your NestJS microservice
46
+ const app = await NestFactory.createMicroservice(AppModule, {
47
+ transport: Transport.GRPC,
48
+ options: {
49
+ protoPath: PROTO_PATHS.AUTH,
50
+ package: 'auth.v1'
51
+ }
52
+ })
53
+ ```
54
+
55
+ ### Using Generated Types
56
+
57
+ ```typescript
58
+ import { SendOtpRequest, SendOtpResponse } from '@3d-outlet/contracts'
59
+
60
+ async function sendOtp(data: SendOtpRequest): Promise<SendOtpResponse> {
61
+ // Type-safe implementation
62
+ return { ok: true }
63
+ }
64
+ ```
65
+
66
+ ### Using Event Interfaces
67
+
68
+ ```typescript
69
+ import { OtpRequestedEvent } from '@3d-outlet/contracts'
70
+
71
+ function handleOtpRequested(event: OtpRequestedEvent) {
72
+ console.log(`OTP requested for ${event.identifier}`)
73
+ }
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 📁 Project Structure
79
+
80
+ ```
81
+ contracts/
82
+ ├── proto/ # Protobuf definition files
83
+ │ └── auth.proto # Authentication service definitions
84
+ ├── gen/ # Generated TypeScript files (auto-generated)
85
+ │ └── ts/
86
+ ├── src/ # Source TypeScript files
87
+ │ ├── events/ # Event interfaces
88
+ │ │ └── auth/ # Auth-related events
89
+ │ └── proto/ # Proto path utilities
90
+ └── dist/ # Compiled JavaScript (after build)
91
+ ```
92
+
93
+ ---
94
+
95
+ ## 🛠️ Development
96
+
97
+ ### Prerequisites
98
+
99
+ - **Node.js**: >= 16.0.0
100
+ - **protoc**: Protocol Buffer compiler
101
+ - **TypeScript**: ^5.9.3
102
+
103
+ ### Installing protoc
104
+
105
+ **macOS:**
106
+
107
+ ```bash
108
+ brew install protobuf
109
+ ```
110
+
111
+ **Ubuntu/Debian:**
112
+
113
+ ```bash
114
+ sudo apt-get update && sudo apt-get install -y protobuf-compiler
115
+ ```
116
+
117
+ **Windows:** Download from
118
+
119
+ ### Building the Package
120
+
121
+ ```bash
122
+ # Install dependencies
123
+ npm install
124
+ # or
125
+ pnpm install
126
+ # or
127
+ bun install
128
+
129
+ # Generate TypeScript from Protobuf
130
+ npm run generate
131
+
132
+ # Build TypeScript
133
+ npm run build
134
+ ```
135
+
136
+ ---
137
+
138
+ ## 📋 Available Services
139
+
140
+ ### Auth Service (`auth.v1`)
141
+
142
+ Authentication and authorization service with OTP-based authentication.
143
+
144
+ **RPC Methods:**
145
+
146
+ - `SendOtp` - Send OTP code to user
147
+ - `VerifyOtp` - Verify OTP code and get tokens
148
+ - `Refresh` - Refresh access token
149
+
150
+ **Example:**
151
+
152
+ ```typescript
153
+ import { AuthServiceController } from '@3d-outlet/contracts'
154
+
155
+ @Controller()
156
+ export class AuthController implements AuthServiceController {
157
+ async sendOtp(request: SendOtpRequest): Promise<SendOtpResponse> {
158
+ // Implementation
159
+ return { ok: true }
160
+ }
161
+ }
162
+ ```
163
+
164
+ ---
165
+
166
+ ## 🎯 Usage in NestJS
167
+
168
+ ### Client Side
169
+
170
+ ```typescript
171
+ import { ClientGrpc } from '@nestjs/microservices'
172
+ import { AuthServiceClient } from '@3d-outlet/contracts'
173
+
174
+ @Injectable()
175
+ export class AuthClient {
176
+ private authService: AuthServiceClient
177
+
178
+ constructor(@Inject('AUTH_PACKAGE') private client: ClientGrpc) {}
179
+
180
+ onModuleInit() {
181
+ this.authService = this.client.getService<AuthServiceClient>('AuthService')
182
+ }
183
+
184
+ async sendOtp(identifier: string, type: string) {
185
+ return this.authService.sendOtp({ identifier, type })
186
+ }
187
+ }
188
+ ```
189
+
190
+ ### Server Side
191
+
192
+ ```typescript
193
+ import { PROTO_PATHS } from '@3d-outlet/contracts'
194
+
195
+ // In main.ts or app.module.ts
196
+ const microserviceOptions: MicroserviceOptions = {
197
+ transport: Transport.GRPC,
198
+ options: {
199
+ protoPath: PROTO_PATHS.AUTH,
200
+ package: 'auth.v1',
201
+ url: '0.0.0.0:5000'
202
+ }
203
+ }
204
+ ```
205
+
206
+ ---
207
+
208
+ ## 📝 License
209
+
210
+ ISC © [TeaCoder](mailto:admin@teacoder.ru) & [Ilnaz Mingaleev](mailto:development@teamkaif.com)
211
+
212
+ ---
213
+
214
+ ## 👨‍💻 Authors
215
+
216
+ **TeaCoder (Vadim)**
217
+
218
+ - Email: [admin@teacoder.ru](mailto:admin@teacoder.ru)
219
+
220
+ **Ilnaz Mingaleev**
221
+
222
+ - Email: [development@teamkaif.com](mailto:development@teamkaif.com)
223
+
224
+ ---
225
+
226
+ <div align="center">
227
+
228
+ **Made with ❤️ for the 3D OUTLET project (private repo)**
229
+ Internal use only.
230
+
231
+ </div>
@@ -0,0 +1 @@
1
+ export * from './otp-requested.interface';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./otp-requested.interface"), exports);
@@ -0,0 +1,5 @@
1
+ export interface OtpRequestedEvent {
2
+ identifier: string;
3
+ type: string;
4
+ code: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './auth';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./auth"), exports);
@@ -0,0 +1,2 @@
1
+ export * from './events';
2
+ export * from './proto';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./events"), exports);
18
+ __exportStar(require("./proto"), exports);
@@ -0,0 +1 @@
1
+ export * from './paths';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./paths"), exports);
@@ -0,0 +1,3 @@
1
+ export declare const PROTO_PATHS: {
2
+ readonly AUTH: string;
3
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROTO_PATHS = void 0;
4
+ const path_1 = require("path");
5
+ exports.PROTO_PATHS = {
6
+ AUTH: (0, path_1.join)(__dirname, '../../proto/auth.proto')
7
+ };
File without changes
package/gen/ts/auth.ts ADDED
@@ -0,0 +1,75 @@
1
+ // Code generated by protoc-gen-ts_proto. DO NOT EDIT.
2
+ // versions:
3
+ // protoc-gen-ts_proto v2.10.1
4
+ // protoc v3.21.12
5
+ // source: auth.proto
6
+
7
+ /* eslint-disable */
8
+ import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices";
9
+ import { Observable } from "rxjs";
10
+
11
+ export const protobufPackage = "auth.v1";
12
+
13
+ export interface SendOtpRequest {
14
+ identifier: string;
15
+ type: string;
16
+ }
17
+
18
+ export interface SendOtpResponse {
19
+ ok: boolean;
20
+ }
21
+
22
+ export interface VerifyOtpRequest {
23
+ identifier: string;
24
+ type: string;
25
+ code: string;
26
+ }
27
+
28
+ export interface VerifyOtpResponse {
29
+ accessToken: string;
30
+ refreshToken: string;
31
+ }
32
+
33
+ export interface RefreshRequest {
34
+ refreshToken: string;
35
+ }
36
+
37
+ export interface RefreshResponse {
38
+ accessToken: string;
39
+ refreshToken: string;
40
+ }
41
+
42
+ export const AUTH_V1_PACKAGE_NAME = "auth.v1";
43
+
44
+ export interface AuthServiceClient {
45
+ sendOtp(request: SendOtpRequest): Observable<SendOtpResponse>;
46
+
47
+ verifyOtp(request: VerifyOtpRequest): Observable<VerifyOtpResponse>;
48
+
49
+ refresh(request: RefreshRequest): Observable<RefreshResponse>;
50
+ }
51
+
52
+ export interface AuthServiceController {
53
+ sendOtp(request: SendOtpRequest): Promise<SendOtpResponse> | Observable<SendOtpResponse> | SendOtpResponse;
54
+
55
+ verifyOtp(request: VerifyOtpRequest): Promise<VerifyOtpResponse> | Observable<VerifyOtpResponse> | VerifyOtpResponse;
56
+
57
+ refresh(request: RefreshRequest): Promise<RefreshResponse> | Observable<RefreshResponse> | RefreshResponse;
58
+ }
59
+
60
+ export function AuthServiceControllerMethods() {
61
+ return function (constructor: Function) {
62
+ const grpcMethods: string[] = ["sendOtp", "verifyOtp", "refresh"];
63
+ for (const method of grpcMethods) {
64
+ const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
65
+ GrpcMethod("AuthService", method)(constructor.prototype[method], method, descriptor);
66
+ }
67
+ const grpcStreamMethods: string[] = [];
68
+ for (const method of grpcStreamMethods) {
69
+ const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method);
70
+ GrpcStreamMethod("AuthService", method)(constructor.prototype[method], method, descriptor);
71
+ }
72
+ };
73
+ }
74
+
75
+ export const AUTH_SERVICE_NAME = "AuthService";
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@3d-outlet/contracts",
3
+ "version": "1.0.0",
4
+ "description": "Protobuf definitions and generated TypeScript types",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.build.json",
9
+ "generate": "protoc -I ./proto ./proto/*.proto --ts_proto_out=./gen/ts --ts_proto_opt=nestJs=true,package=omit"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "proto",
14
+ "gen"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "dependencies": {
20
+ "@nestjs/microservices": "^11.1.9",
21
+ "rxjs": "^7.8.2",
22
+ "ts-proto": "^2.8.3"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^24.10.1",
26
+ "typescript": "^5.9.3"
27
+ }
28
+ }
@@ -0,0 +1,38 @@
1
+ syntax = "proto3";
2
+
3
+ package auth.v1;
4
+
5
+ service AuthService {
6
+ rpc SendOtp (SendOtpRequest) returns (SendOtpResponse);
7
+ rpc VerifyOtp (VerifyOtpRequest) returns (VerifyOtpResponse);
8
+ rpc Refresh (RefreshRequest) returns (RefreshResponse);
9
+ }
10
+
11
+ message SendOtpRequest {
12
+ string identifier = 1;
13
+ string type = 2;
14
+ }
15
+
16
+ message SendOtpResponse {
17
+ bool ok = 1;
18
+ }
19
+
20
+ message VerifyOtpRequest {
21
+ string identifier = 1;
22
+ string type = 2;
23
+ string code = 3;
24
+ }
25
+
26
+ message VerifyOtpResponse {
27
+ string access_token = 1;
28
+ string refresh_token = 2;
29
+ }
30
+
31
+ message RefreshRequest {
32
+ string refresh_token = 1;
33
+ }
34
+
35
+ message RefreshResponse {
36
+ string access_token = 1;
37
+ string refresh_token = 2;
38
+ }