geniebox-shared-lib 1.0.74 → 2.0.1
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 +636 -0
- package/dist/{ai/ai.interface.d.ts → ai.interface.d.ts} +0 -5
- package/dist/index.d.ts +14 -14
- package/dist/index.js +27 -26
- package/dist/shared.module.d.ts +1 -1
- package/dist/shared.module.js +19 -19
- package/dist/{file/file.client.d.ts → storage.client.d.ts} +4 -4
- package/dist/{file/file.client.js → storage.client.js} +15 -14
- package/dist/{file/file.interface.d.ts → storage.interface.d.ts} +12 -12
- package/dist/{file/file.interface.js → storage.interface.js} +13 -13
- package/dist/{user/user.interface.d.ts → user.interface.d.ts} +23 -7
- package/dist/{user/user.interface.js → user.interface.js} +49 -6
- package/package.json +2 -9
- package/dist/account/account.client.d.ts +0 -11
- package/dist/account/account.client.js +0 -41
- package/dist/account/account.interface.d.ts +0 -184
- package/dist/account/account.interface.js +0 -625
- package/dist/ai/google/protobuf/struct.interface.d.ts +0 -91
- package/dist/ai/google/protobuf/struct.interface.js +0 -300
- package/dist/auth/google/protobuf/empty.interface.d.ts +0 -19
- package/dist/auth/google/protobuf/empty.interface.js +0 -35
- package/dist/key/google/protobuf/empty.interface.d.ts +0 -19
- package/dist/key/google/protobuf/empty.interface.js +0 -35
- package/dist/openai/google/protobuf/struct.interface.d.ts +0 -91
- package/dist/openai/google/protobuf/struct.interface.js +0 -300
- package/dist/user/account.interface.d.ts +0 -184
- package/dist/user/account.interface.js +0 -625
- package/dist/user/google/protobuf/empty.interface.d.ts +0 -19
- package/dist/user/google/protobuf/empty.interface.js +0 -35
- package/dist/user/google/protobuf/timestamp.interface.d.ts +0 -114
- package/dist/user/google/protobuf/timestamp.interface.js +0 -65
- /package/dist/{ai/ai.client.d.ts → ai.client.d.ts} +0 -0
- /package/dist/{ai/ai.client.js → ai.client.js} +0 -0
- /package/dist/{ai/ai.interface.js → ai.interface.js} +0 -0
- /package/dist/{auth/auth.client.d.ts → auth.client.d.ts} +0 -0
- /package/dist/{auth/auth.client.js → auth.client.js} +0 -0
- /package/dist/{auth/auth.interface.d.ts → auth.interface.d.ts} +0 -0
- /package/dist/{auth/auth.interface.js → auth.interface.js} +0 -0
- /package/dist/{event/event.client.d.ts → event.client.d.ts} +0 -0
- /package/dist/{event/event.client.js → event.client.js} +0 -0
- /package/dist/{event/event.interface.d.ts → event.interface.d.ts} +0 -0
- /package/dist/{event/event.interface.js → event.interface.js} +0 -0
- /package/dist/{ai/google → google}/protobuf/empty.interface.d.ts +0 -0
- /package/dist/{ai/google → google}/protobuf/empty.interface.js +0 -0
- /package/dist/{key/key.client.d.ts → key.client.d.ts} +0 -0
- /package/dist/{key/key.client.js → key.client.js} +0 -0
- /package/dist/{key/key.interface.d.ts → key.interface.d.ts} +0 -0
- /package/dist/{key/key.interface.js → key.interface.js} +0 -0
- /package/dist/{openai/openai.client.d.ts → openai.client.d.ts} +0 -0
- /package/dist/{openai/openai.client.js → openai.client.js} +0 -0
- /package/dist/{openai/openai.interface.d.ts → openai.interface.d.ts} +0 -0
- /package/dist/{openai/openai.interface.js → openai.interface.js} +0 -0
- /package/dist/{user/user.client.d.ts → user.client.d.ts} +0 -0
- /package/dist/{user/user.client.js → user.client.js} +0 -0
package/README.md
CHANGED
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
# GenieBox Shared Library
|
|
2
|
+
|
|
3
|
+
A comprehensive shared NestJS library providing gRPC clients, interfaces, and utilities for the GenieBox microservices ecosystem. This library serves as the central communication layer between all GenieBox services.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **gRPC Clients**: Pre-configured clients for all GenieBox services
|
|
8
|
+
- **TypeScript Interfaces**: Fully typed interfaces for all service communications
|
|
9
|
+
- **Protocol Buffers**: Auto-generated from proto files with type safety
|
|
10
|
+
- **NestJS Integration**: Seamless integration with NestJS microservices
|
|
11
|
+
- **Service Discovery**: Centralized service client management
|
|
12
|
+
- **Error Handling**: Consistent error handling across all services
|
|
13
|
+
- **Observable Support**: RxJS observables for reactive programming
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
### Core Components
|
|
18
|
+
|
|
19
|
+
- **gRPC Clients**: Service-specific clients for communication
|
|
20
|
+
- **Interfaces**: TypeScript interfaces for all service methods
|
|
21
|
+
- **Shared Module**: NestJS module for easy integration
|
|
22
|
+
- **Protocol Buffers**: Auto-generated from proto definitions
|
|
23
|
+
- **Type Definitions**: Complete TypeScript type definitions
|
|
24
|
+
|
|
25
|
+
### Supported Services
|
|
26
|
+
|
|
27
|
+
- **User Service**: User management and authentication
|
|
28
|
+
- **Auth Service**: Authentication and authorization
|
|
29
|
+
- **AI Service**: AI processing and machine learning
|
|
30
|
+
- **OpenAI Service**: OpenAI API integration
|
|
31
|
+
- **Storage Service**: File storage and management
|
|
32
|
+
- **Event Service**: Real-time event streaming
|
|
33
|
+
- **Key Service**: API key management
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Install from npm registry
|
|
39
|
+
npm install geniebox-shared-lib
|
|
40
|
+
|
|
41
|
+
# Or install from local development
|
|
42
|
+
npm install file:../libs/geniebox-shared
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### Basic Usage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import {
|
|
51
|
+
SharedModule,
|
|
52
|
+
UsersClient,
|
|
53
|
+
AuthClient,
|
|
54
|
+
AIClient
|
|
55
|
+
} from 'geniebox-shared-lib';
|
|
56
|
+
|
|
57
|
+
// Import in your NestJS module
|
|
58
|
+
@Module({
|
|
59
|
+
imports: [SharedModule],
|
|
60
|
+
// ... other module configuration
|
|
61
|
+
})
|
|
62
|
+
export class YourModule {}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Using gRPC Clients
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { Injectable } from '@nestjs/common';
|
|
69
|
+
import { UsersClient, CreateUserRequest } from 'geniebox-shared-lib';
|
|
70
|
+
|
|
71
|
+
@Injectable()
|
|
72
|
+
export class YourService {
|
|
73
|
+
constructor(private readonly usersClient: UsersClient) {}
|
|
74
|
+
|
|
75
|
+
async createUser(userData: CreateUserRequest) {
|
|
76
|
+
return await this.usersClient.createUser(userData);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Service-Specific Usage
|
|
82
|
+
|
|
83
|
+
#### User Service
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import {
|
|
87
|
+
UsersClient,
|
|
88
|
+
CreateUserRequest,
|
|
89
|
+
UserResponse
|
|
90
|
+
} from 'geniebox-shared-lib';
|
|
91
|
+
|
|
92
|
+
// Create user
|
|
93
|
+
const createUserRequest: CreateUserRequest = {
|
|
94
|
+
email: 'user@example.com',
|
|
95
|
+
password: 'securePassword',
|
|
96
|
+
firstName: 'John',
|
|
97
|
+
lastName: 'Doe'
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const user: UserResponse = await usersClient.createUser(createUserRequest);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Auth Service
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import {
|
|
107
|
+
AuthClient,
|
|
108
|
+
LoginCredentials,
|
|
109
|
+
AuthResponse
|
|
110
|
+
} from 'geniebox-shared-lib';
|
|
111
|
+
|
|
112
|
+
// Login user
|
|
113
|
+
const credentials: LoginCredentials = {
|
|
114
|
+
email: 'user@example.com',
|
|
115
|
+
password: 'securePassword',
|
|
116
|
+
rememberMe: true
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const authResponse: AuthResponse = await authClient.login(credentials);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### AI Service
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import {
|
|
126
|
+
AIClient,
|
|
127
|
+
AICallRequest,
|
|
128
|
+
AICallResponse
|
|
129
|
+
} from 'geniebox-shared-lib';
|
|
130
|
+
|
|
131
|
+
// Make AI request
|
|
132
|
+
const aiRequest: AICallRequest = {
|
|
133
|
+
endpoint: '/ai/chat',
|
|
134
|
+
payload: { message: 'Hello, AI!' },
|
|
135
|
+
priority: 'normal'
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const aiResponse: AICallResponse = await aiClient.call(aiRequest);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Storage Service
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import {
|
|
145
|
+
StorageClient,
|
|
146
|
+
UploadRequest,
|
|
147
|
+
UploadResponse
|
|
148
|
+
} from 'geniebox-shared-lib';
|
|
149
|
+
|
|
150
|
+
// Upload file
|
|
151
|
+
const uploadRequest: UploadRequest = {
|
|
152
|
+
filename: 'document.pdf',
|
|
153
|
+
content: fileBuffer,
|
|
154
|
+
contentType: 'application/pdf'
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const uploadResponse: UploadResponse = await storageClient.upload(uploadRequest);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
#### Event Service
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import {
|
|
164
|
+
EventClient,
|
|
165
|
+
SubscribeRequest,
|
|
166
|
+
EventMessage
|
|
167
|
+
} from 'geniebox-shared-lib';
|
|
168
|
+
|
|
169
|
+
// Subscribe to events
|
|
170
|
+
const subscribeRequest: SubscribeRequest = {
|
|
171
|
+
eventType: 'user.created',
|
|
172
|
+
userId: 'user-123'
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const eventStream = eventClient.subscribe(subscribeRequest);
|
|
176
|
+
eventStream.subscribe((event: EventMessage) => {
|
|
177
|
+
console.log('Received event:', event);
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
#### Key Service
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import {
|
|
185
|
+
KeyClient,
|
|
186
|
+
CreateKeyRequest,
|
|
187
|
+
KeyResponse
|
|
188
|
+
} from 'geniebox-shared-lib';
|
|
189
|
+
|
|
190
|
+
// Create API key
|
|
191
|
+
const createKeyRequest: CreateKeyRequest = {
|
|
192
|
+
name: 'My API Key',
|
|
193
|
+
permissions: ['read', 'write'],
|
|
194
|
+
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000) // 30 days
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const key: KeyResponse = await keyClient.createKey(createKeyRequest);
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Configuration
|
|
201
|
+
|
|
202
|
+
### Environment Variables
|
|
203
|
+
|
|
204
|
+
The shared library uses environment variables for service configuration:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# User Service
|
|
208
|
+
USER_SERVICE_URL=grpc://user-service:50051
|
|
209
|
+
|
|
210
|
+
# Auth Service
|
|
211
|
+
AUTH_SERVICE_URL=grpc://auth-service:50052
|
|
212
|
+
|
|
213
|
+
# AI Service
|
|
214
|
+
AI_SERVICE_URL=grpc://ai-service:50053
|
|
215
|
+
|
|
216
|
+
# OpenAI Service
|
|
217
|
+
OPENAI_SERVICE_URL=grpc://openai-service:50054
|
|
218
|
+
|
|
219
|
+
# Storage Service
|
|
220
|
+
STORAGE_SERVICE_URL=grpc://storage-service:50055
|
|
221
|
+
|
|
222
|
+
# Event Service
|
|
223
|
+
EVENT_SERVICE_URL=grpc://event-service:50056
|
|
224
|
+
|
|
225
|
+
# Key Service
|
|
226
|
+
KEY_SERVICE_URL=grpc://key-service:50057
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Service Configuration
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { Module } from '@nestjs/common';
|
|
233
|
+
import { SharedModule } from 'geniebox-shared-lib';
|
|
234
|
+
|
|
235
|
+
@Module({
|
|
236
|
+
imports: [
|
|
237
|
+
SharedModule.forRoot({
|
|
238
|
+
userService: {
|
|
239
|
+
url: process.env.USER_SERVICE_URL || 'grpc://localhost:50051',
|
|
240
|
+
options: {
|
|
241
|
+
keepalive: true,
|
|
242
|
+
keepaliveTimeMs: 30000,
|
|
243
|
+
keepaliveTimeoutMs: 5000,
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
authService: {
|
|
247
|
+
url: process.env.AUTH_SERVICE_URL || 'grpc://localhost:50052',
|
|
248
|
+
options: {
|
|
249
|
+
keepalive: true,
|
|
250
|
+
keepaliveTimeMs: 30000,
|
|
251
|
+
keepaliveTimeoutMs: 5000,
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
// ... other services
|
|
255
|
+
})
|
|
256
|
+
],
|
|
257
|
+
})
|
|
258
|
+
export class AppModule {}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
### Prerequisites
|
|
264
|
+
|
|
265
|
+
- Node.js 18.x or higher
|
|
266
|
+
- npm 9.x or higher
|
|
267
|
+
- Protocol Buffers compiler (protoc)
|
|
268
|
+
- TypeScript 5.x
|
|
269
|
+
|
|
270
|
+
### Setup
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Install dependencies
|
|
274
|
+
npm install
|
|
275
|
+
|
|
276
|
+
# Generate protobuf files
|
|
277
|
+
npm run proto:gen
|
|
278
|
+
|
|
279
|
+
# Build the library
|
|
280
|
+
npm run build
|
|
281
|
+
|
|
282
|
+
# Generate and build
|
|
283
|
+
npm run generate
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Scripts
|
|
287
|
+
|
|
288
|
+
| Script | Description |
|
|
289
|
+
|--------|-------------|
|
|
290
|
+
| `npm run build` | Build TypeScript to JavaScript |
|
|
291
|
+
| `npm run proto:gen` | Generate TypeScript from proto files |
|
|
292
|
+
| `npm run generate` | Generate proto files and build |
|
|
293
|
+
| `npm run prepublishOnly` | Build before publishing |
|
|
294
|
+
|
|
295
|
+
### Proto File Generation
|
|
296
|
+
|
|
297
|
+
The library automatically generates TypeScript interfaces and clients from Protocol Buffer definitions:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
# Generate from proto files
|
|
301
|
+
npm run proto:gen
|
|
302
|
+
|
|
303
|
+
# This command:
|
|
304
|
+
# 1. Reads proto files from ../../protos/
|
|
305
|
+
# 2. Generates TypeScript interfaces in src/
|
|
306
|
+
# 3. Creates gRPC clients for each service
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## API Reference
|
|
310
|
+
|
|
311
|
+
### SharedModule
|
|
312
|
+
|
|
313
|
+
The main NestJS module that provides all gRPC clients.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
@Module({
|
|
317
|
+
imports: [SharedModule],
|
|
318
|
+
providers: [YourService],
|
|
319
|
+
})
|
|
320
|
+
export class YourModule {}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Service Clients
|
|
324
|
+
|
|
325
|
+
#### UsersClient
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
class UsersClient {
|
|
329
|
+
createUser(request: CreateUserRequest): Promise<UserResponse>
|
|
330
|
+
getUserById(request: GetByIdRequest): Promise<UserResponse>
|
|
331
|
+
updateUser(request: UpdateUserRequest): Promise<UserResponse>
|
|
332
|
+
deleteUser(request: GetByIdRequest): Promise<void>
|
|
333
|
+
findUserByEmail(request: FindByEmailRequest): Promise<UserResponse>
|
|
334
|
+
findUserByPhone(request: FindByPhoneRequest): Promise<UserResponse>
|
|
335
|
+
updateUserPersonal(request: UpdateUserPersonal): Promise<UserResponse>
|
|
336
|
+
updatePassword(request: UpdatePasswordRequest): Promise<void>
|
|
337
|
+
updateEmailVerification(request: UpdateEmailVerificationRequest): Promise<void>
|
|
338
|
+
getEmailVerificationStatus(request: GetEmailVerificationStatusRequest): Promise<EmailVerificationStatusResponse>
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
#### AuthClient
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
class AuthClient {
|
|
346
|
+
login(request: LoginCredentials): Promise<AuthResponse>
|
|
347
|
+
register(request: RegisterCredentials): Promise<AuthResponse>
|
|
348
|
+
logout(request: LogoutRequest): Promise<void>
|
|
349
|
+
refresh(request: RefreshRequest): Promise<RefreshTokenResponse>
|
|
350
|
+
recover(request: RecoverRequest): Promise<void>
|
|
351
|
+
resetPassword(request: ResetPasswordRequest): Promise<void>
|
|
352
|
+
confirmEmail(request: ConfirmEmailRequest): Promise<ConfirmEmailResponse>
|
|
353
|
+
confirmEmailByCode(request: ConfirmEmailByCodeRequest): Promise<AuthResponse>
|
|
354
|
+
checkEmailVerified(request: CheckEmailVerifiedRequest): Promise<CheckEmailVerifiedResponse>
|
|
355
|
+
resendConfirmationCode(request: ResendConfirmationCodeRequest): Promise<void>
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### AIClient
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
class AIClient {
|
|
363
|
+
call(request: AICallRequest): Promise<AICallResponse>
|
|
364
|
+
status(request: AIStatusRequest): Promise<AIStatusResponse>
|
|
365
|
+
result(request: AIResultRequest): Promise<AIResultResponse>
|
|
366
|
+
cancel(request: AICancelRequest): Promise<AICancelResponse>
|
|
367
|
+
stream(request: AIStreamRequest): Observable<AIStreamResponse>
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### StorageClient
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
class StorageClient {
|
|
375
|
+
upload(request: UploadRequest): Promise<UploadResponse>
|
|
376
|
+
download(request: DownloadRequest): Promise<DownloadResponse>
|
|
377
|
+
delete(request: DeleteRequest): Promise<DeleteResponse>
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
#### EventClient
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
class EventClient {
|
|
385
|
+
subscribe(request: SubscribeRequest): Observable<EventMessage>
|
|
386
|
+
publish(event: EventMessage): Promise<void>
|
|
387
|
+
}
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
#### KeyClient
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
class KeyClient {
|
|
394
|
+
createKey(request: CreateKeyRequest): Promise<KeyResponse>
|
|
395
|
+
getKeyById(request: GetKeyByIdRequest): Promise<KeyResponse>
|
|
396
|
+
updateKey(request: UpdateKeyRequest): Promise<KeyResponse>
|
|
397
|
+
removeKey(request: RemoveKeyRequest): Promise<void>
|
|
398
|
+
getKeysByUser(request: GetKeysByUserRequest): Promise<KeysResponse>
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## Error Handling
|
|
403
|
+
|
|
404
|
+
The library provides consistent error handling across all services:
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { RpcException } from '@nestjs/microservices';
|
|
408
|
+
|
|
409
|
+
try {
|
|
410
|
+
const user = await usersClient.createUser(request);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (error instanceof RpcException) {
|
|
413
|
+
// Handle gRPC errors
|
|
414
|
+
console.error('gRPC Error:', error.message);
|
|
415
|
+
} else {
|
|
416
|
+
// Handle other errors
|
|
417
|
+
console.error('Unexpected error:', error);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
## Type Safety
|
|
423
|
+
|
|
424
|
+
All interfaces are fully typed with TypeScript:
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
// Fully typed request/response objects
|
|
428
|
+
interface CreateUserRequest {
|
|
429
|
+
email: string;
|
|
430
|
+
password: string;
|
|
431
|
+
firstName: string;
|
|
432
|
+
lastName: string;
|
|
433
|
+
phone?: string;
|
|
434
|
+
dateOfBirth?: Date;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
interface UserResponse {
|
|
438
|
+
id: string;
|
|
439
|
+
email: string;
|
|
440
|
+
firstName: string;
|
|
441
|
+
lastName: string;
|
|
442
|
+
phone?: string;
|
|
443
|
+
dateOfBirth?: Date;
|
|
444
|
+
createdAt: Date;
|
|
445
|
+
updatedAt: Date;
|
|
446
|
+
}
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
## Performance
|
|
450
|
+
|
|
451
|
+
### Connection Pooling
|
|
452
|
+
|
|
453
|
+
The library uses gRPC connection pooling for optimal performance:
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
// Configure connection options
|
|
457
|
+
const clientOptions = {
|
|
458
|
+
keepalive: true,
|
|
459
|
+
keepaliveTimeMs: 30000,
|
|
460
|
+
keepaliveTimeoutMs: 5000,
|
|
461
|
+
keepalivePermitWithoutCalls: true,
|
|
462
|
+
maxReceiveMessageLength: 4 * 1024 * 1024, // 4MB
|
|
463
|
+
maxSendMessageLength: 4 * 1024 * 1024, // 4MB
|
|
464
|
+
};
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Caching
|
|
468
|
+
|
|
469
|
+
Service clients can be configured with caching:
|
|
470
|
+
|
|
471
|
+
```typescript
|
|
472
|
+
// Enable client-side caching
|
|
473
|
+
const usersClient = new UsersClient(serviceUrl, {
|
|
474
|
+
...clientOptions,
|
|
475
|
+
cache: {
|
|
476
|
+
enabled: true,
|
|
477
|
+
ttl: 300000, // 5 minutes
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
## Testing
|
|
483
|
+
|
|
484
|
+
### Unit Testing
|
|
485
|
+
|
|
486
|
+
```typescript
|
|
487
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
488
|
+
import { SharedModule, UsersClient } from 'geniebox-shared-lib';
|
|
489
|
+
|
|
490
|
+
describe('YourService', () => {
|
|
491
|
+
let service: YourService;
|
|
492
|
+
let usersClient: UsersClient;
|
|
493
|
+
|
|
494
|
+
beforeEach(async () => {
|
|
495
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
496
|
+
imports: [SharedModule],
|
|
497
|
+
providers: [YourService],
|
|
498
|
+
}).compile();
|
|
499
|
+
|
|
500
|
+
service = module.get<YourService>(YourService);
|
|
501
|
+
usersClient = module.get<UsersClient>(UsersClient);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it('should create user', async () => {
|
|
505
|
+
const mockUser = { id: '1', email: 'test@example.com' };
|
|
506
|
+
jest.spyOn(usersClient, 'createUser').mockResolvedValue(mockUser);
|
|
507
|
+
|
|
508
|
+
const result = await service.createUser({ email: 'test@example.com' });
|
|
509
|
+
expect(result).toEqual(mockUser);
|
|
510
|
+
});
|
|
511
|
+
});
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Integration Testing
|
|
515
|
+
|
|
516
|
+
```typescript
|
|
517
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
518
|
+
import { SharedModule } from 'geniebox-shared-lib';
|
|
519
|
+
|
|
520
|
+
describe('Integration Tests', () => {
|
|
521
|
+
let app: INestApplication;
|
|
522
|
+
|
|
523
|
+
beforeAll(async () => {
|
|
524
|
+
const moduleFixture: TestingModule = await Test.createTestingModule({
|
|
525
|
+
imports: [SharedModule],
|
|
526
|
+
}).compile();
|
|
527
|
+
|
|
528
|
+
app = moduleFixture.createNestApplication();
|
|
529
|
+
await app.init();
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
afterAll(async () => {
|
|
533
|
+
await app.close();
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
it('should connect to services', async () => {
|
|
537
|
+
// Test actual service connections
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
## Troubleshooting
|
|
543
|
+
|
|
544
|
+
### Common Issues
|
|
545
|
+
|
|
546
|
+
#### Connection Errors
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
# Check service URLs
|
|
550
|
+
echo $USER_SERVICE_URL
|
|
551
|
+
echo $AUTH_SERVICE_URL
|
|
552
|
+
|
|
553
|
+
# Test gRPC connectivity
|
|
554
|
+
grpcurl -plaintext localhost:50051 list
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
#### Type Errors
|
|
558
|
+
|
|
559
|
+
```bash
|
|
560
|
+
# Regenerate types from proto files
|
|
561
|
+
npm run proto:gen
|
|
562
|
+
|
|
563
|
+
# Rebuild the library
|
|
564
|
+
npm run build
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
#### Import Errors
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
// Ensure correct imports
|
|
571
|
+
import { UsersClient, CreateUserRequest } from 'geniebox-shared-lib';
|
|
572
|
+
|
|
573
|
+
// Not from individual files
|
|
574
|
+
// import { UsersClient } from 'geniebox-shared-lib/src/user.client';
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Debug Mode
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
// Enable gRPC debug logging
|
|
581
|
+
process.env.GRPC_VERBOSITY = 'DEBUG';
|
|
582
|
+
process.env.GRPC_TRACE = 'all';
|
|
583
|
+
|
|
584
|
+
// Enable client debug mode
|
|
585
|
+
const client = new UsersClient(serviceUrl, {
|
|
586
|
+
...options,
|
|
587
|
+
debug: true,
|
|
588
|
+
});
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
## Contributing
|
|
592
|
+
|
|
593
|
+
### Development Setup
|
|
594
|
+
|
|
595
|
+
1. Fork the repository
|
|
596
|
+
2. Create a feature branch
|
|
597
|
+
3. Install dependencies: `npm install`
|
|
598
|
+
4. Make your changes
|
|
599
|
+
5. Run tests: `npm test`
|
|
600
|
+
6. Submit a pull request
|
|
601
|
+
|
|
602
|
+
### Code Standards
|
|
603
|
+
|
|
604
|
+
- **TypeScript**: Strict type checking enabled
|
|
605
|
+
- **ESLint**: Code linting with TypeScript rules
|
|
606
|
+
- **Prettier**: Code formatting
|
|
607
|
+
- **Testing**: All new code must include tests
|
|
608
|
+
- **Documentation**: JSDoc comments for public APIs
|
|
609
|
+
|
|
610
|
+
### Adding New Services
|
|
611
|
+
|
|
612
|
+
1. Add proto file to `../../protos/`
|
|
613
|
+
2. Run `npm run proto:gen` to generate interfaces
|
|
614
|
+
3. Create client class in `src/`
|
|
615
|
+
4. Export from `src/index.ts`
|
|
616
|
+
5. Update `SharedModule` to include new client
|
|
617
|
+
6. Add tests for new client
|
|
618
|
+
|
|
619
|
+
## License
|
|
620
|
+
|
|
621
|
+
This project is licensed under the ISC License - see the package.json file for details.
|
|
622
|
+
|
|
623
|
+
## Support
|
|
624
|
+
|
|
625
|
+
For support and questions:
|
|
626
|
+
|
|
627
|
+
- **Issues**: Create a GitHub issue
|
|
628
|
+
- **Documentation**: Check this README and inline JSDoc
|
|
629
|
+
- **Logs**: Review gRPC connection logs
|
|
630
|
+
- **Debug**: Enable debug mode for detailed logging
|
|
631
|
+
|
|
632
|
+
---
|
|
633
|
+
|
|
634
|
+
**Version**: 2.0.0
|
|
635
|
+
**Last Updated**: January 2024
|
|
636
|
+
**Maintainer**: GenieBox Team
|
|
@@ -8,11 +8,6 @@ export interface AICallResponse {
|
|
|
8
8
|
export interface AIStatusResponse {
|
|
9
9
|
requestId: string;
|
|
10
10
|
status: string;
|
|
11
|
-
logs?: Array<{
|
|
12
|
-
message: string;
|
|
13
|
-
level?: 'info' | 'warn' | 'error';
|
|
14
|
-
timestamp?: string;
|
|
15
|
-
}>;
|
|
16
11
|
}
|
|
17
12
|
export interface AIResultResponse {
|
|
18
13
|
requestId: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export { SharedModule } from "./shared.module";
|
|
2
|
-
export { UsersClient } from "./user
|
|
3
|
-
export { AuthClient } from "./auth
|
|
4
|
-
export { AIClient } from "./ai
|
|
5
|
-
export { OpenAIClient } from "./openai
|
|
6
|
-
export {
|
|
7
|
-
export { EventClient } from "./event
|
|
8
|
-
export { KeyClient } from "./key
|
|
9
|
-
export { MessageFns as UserMessageFns, protobufPackage as UserProtobufPackage, User, CreateUserRequest, CreateUserPersonal, UpdateUserRequest,
|
|
10
|
-
export { MessageFns as AuthMessageFns, protobufPackage as AuthProtobufPackage, LoginCredentials, RegisterCredentials, LogoutRequest, RefreshRequest, AuthResponse, RefreshTokenResponse, RecoverRequest, ResetPasswordRequest, ConfirmEmailRequest, ConfirmEmailByCodeRequest, ConfirmEmailResponse, CheckEmailVerifiedRequest, CheckEmailVerifiedResponse, ResendConfirmationCodeRequest, } from "./auth
|
|
11
|
-
export { MessageFns as AIMessageFns, protobufPackage as AIProtobufPackage, AICallRequest, AICallResponse, AIStatusRequest, AIStatusResponse, AIResultRequest, AIResultResponse, AICancelRequest, AICancelResponse, AIStreamRequest, AIStreamResponse, AIServiceService as AIService, } from "./ai
|
|
12
|
-
export { MessageFns as OpenAIMessageFns, protobufPackage as OpenAIProtobufPackage, CreateRequest as OpenAICreateRequest, CreateResponse as OpenAICreateResponse, OpenAIServiceService as OpenAIService, } from "./openai
|
|
13
|
-
export { UploadRequest, UploadResponse, DownloadRequest, DownloadResponse, DeleteRequest, DeleteResponse,
|
|
14
|
-
export { MessageFns as EventMessageFns, protobufPackage as EventProtobufPackage, SubscribeRequest, EventMessage, EventServiceService as EventService, } from "./event
|
|
15
|
-
export { MessageFns as KeysMessageFns, protobufPackage as KeysProtobufPackage, Key, CreateKeyRequest, UpdateKeyRequest, RemoveKeyRequest, GetKeyByIdRequest, KeyResponse, KeysResponse, GetKeysByUserRequest, KeyServiceService as KeyService, } from "./key
|
|
2
|
+
export { UsersClient } from "./user.client";
|
|
3
|
+
export { AuthClient } from "./auth.client";
|
|
4
|
+
export { AIClient } from "./ai.client";
|
|
5
|
+
export { OpenAIClient } from "./openai.client";
|
|
6
|
+
export { StorageClient } from "./storage.client";
|
|
7
|
+
export { EventClient } from "./event.client";
|
|
8
|
+
export { KeyClient } from "./key.client";
|
|
9
|
+
export { MessageFns as UserMessageFns, protobufPackage as UserProtobufPackage, User, CreateUserRequest, CreateUserPersonal, UpdateUserRequest, FindOneRequest, UserResponse, UsersResponse, FindByEmailRequest, FindByPhoneRequest, UpdateUserPersonal, UpdatePasswordRequest, UpdateEmailVerificationRequest, ResetPasswordData, GetEmailVerificationStatusRequest, EmailVerificationStatusResponse, FindUsersByIdsRequest, UserServiceService as UserService, } from "./user.interface";
|
|
10
|
+
export { MessageFns as AuthMessageFns, protobufPackage as AuthProtobufPackage, LoginCredentials, RegisterCredentials, LogoutRequest, RefreshRequest, AuthResponse, RefreshTokenResponse, RecoverRequest, ResetPasswordRequest, ConfirmEmailRequest, ConfirmEmailByCodeRequest, ConfirmEmailResponse, CheckEmailVerifiedRequest, CheckEmailVerifiedResponse, ResendConfirmationCodeRequest, } from "./auth.interface";
|
|
11
|
+
export { MessageFns as AIMessageFns, protobufPackage as AIProtobufPackage, AICallRequest, AICallResponse, AIStatusRequest, AIStatusResponse, AIResultRequest, AIResultResponse, AICancelRequest, AICancelResponse, AIStreamRequest, AIStreamResponse, AIServiceService as AIService, } from "./ai.interface";
|
|
12
|
+
export { MessageFns as OpenAIMessageFns, protobufPackage as OpenAIProtobufPackage, CreateRequest as OpenAICreateRequest, CreateResponse as OpenAICreateResponse, OpenAIServiceService as OpenAIService, } from "./openai.interface";
|
|
13
|
+
export { UploadRequest, UploadResponse, DownloadRequest, DownloadResponse, DeleteRequest, DeleteResponse, StorageServiceService as StorageService, protobufPackage as FileProtobufPackage, } from "./storage.interface";
|
|
14
|
+
export { MessageFns as EventMessageFns, protobufPackage as EventProtobufPackage, SubscribeRequest, EventMessage, EventServiceService as EventService, } from "./event.interface";
|
|
15
|
+
export { MessageFns as KeysMessageFns, protobufPackage as KeysProtobufPackage, Key, CreateKeyRequest, UpdateKeyRequest, RemoveKeyRequest, GetKeyByIdRequest, KeyResponse, KeysResponse, GetKeysByUserRequest, KeyServiceService as KeyService, } from "./key.interface";
|