geniebox-shared-lib 1.0.12 → 1.0.14

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.
@@ -2,9 +2,9 @@ import { OnModuleInit } from "@nestjs/common";
2
2
  import { ClientGrpc } from "@nestjs/microservices";
3
3
  import { AuthServiceClient } from "./auth.interface";
4
4
  export declare class AuthClient implements OnModuleInit {
5
- private client;
5
+ private readonly client;
6
6
  private readonly logger;
7
- private authClient;
7
+ private authClient?;
8
8
  constructor(client: ClientGrpc);
9
9
  onModuleInit(): void;
10
10
  get service(): AuthServiceClient;
@@ -19,15 +19,19 @@ let AuthClient = AuthClient_1 = class AuthClient {
19
19
  constructor(client) {
20
20
  this.client = client;
21
21
  this.logger = new common_1.Logger(AuthClient_1.name);
22
- this.authClient = null;
23
22
  }
24
23
  onModuleInit() {
25
24
  this.authClient = this.client.getService("AuthService");
26
- this.logger.log("AuthServiceClient initialized");
25
+ if (!this.authClient) {
26
+ this.logger.error("Failed to initialize AuthServiceClient");
27
+ throw new Error("AuthServiceClient initialization failed");
28
+ }
29
+ this.logger.log("AuthServiceClient initialized successfully");
27
30
  }
28
31
  get service() {
29
32
  if (!this.authClient) {
30
- throw new Error("AuthService not initialized yet");
33
+ this.logger.error("Tried to access AuthService before initialization");
34
+ throw new Error("AuthServiceClient not initialized yet");
31
35
  }
32
36
  return this.authClient;
33
37
  }
@@ -60,7 +60,7 @@ export declare const AUTH_SERVICE_NAME = "AuthService";
60
60
  export type AuthServiceService = typeof AuthServiceService;
61
61
  export declare const AuthServiceService: {
62
62
  readonly register: {
63
- readonly path: "/auth.AuthService/Register";
63
+ readonly path: "/auth.AuthService/register";
64
64
  readonly requestStream: false;
65
65
  readonly responseStream: false;
66
66
  readonly requestSerialize: (value: RegisterRequest) => Buffer;
@@ -69,7 +69,7 @@ export declare const AuthServiceService: {
69
69
  readonly responseDeserialize: (value: Buffer) => AuthTokensResponse;
70
70
  };
71
71
  readonly refreshToken: {
72
- readonly path: "/auth.AuthService/RefreshToken";
72
+ readonly path: "/auth.AuthService/refreshToken";
73
73
  readonly requestStream: false;
74
74
  readonly responseStream: false;
75
75
  readonly requestSerialize: (value: RefreshTokenRequest) => Buffer;
@@ -436,7 +436,7 @@ function AuthServiceControllerMethods() {
436
436
  exports.AUTH_SERVICE_NAME = "AuthService";
437
437
  exports.AuthServiceService = {
438
438
  register: {
439
- path: "/auth.AuthService/Register",
439
+ path: "/auth.AuthService/register",
440
440
  requestStream: false,
441
441
  responseStream: false,
442
442
  requestSerialize: (value) => Buffer.from(exports.RegisterRequest.encode(value).finish()),
@@ -445,7 +445,7 @@ exports.AuthServiceService = {
445
445
  responseDeserialize: (value) => exports.AuthTokensResponse.decode(value),
446
446
  },
447
447
  refreshToken: {
448
- path: "/auth.AuthService/RefreshToken",
448
+ path: "/auth.AuthService/refreshToken",
449
449
  requestStream: false,
450
450
  responseStream: false,
451
451
  requestSerialize: (value) => Buffer.from(exports.RefreshTokenRequest.encode(value).finish()),
@@ -10,5 +10,6 @@ export interface SharedModuleOptions {
10
10
  };
11
11
  }
12
12
  export declare class SharedModule {
13
+ private static readonly logger;
13
14
  static forRoot(options?: SharedModuleOptions): DynamicModule;
14
15
  }
@@ -29,7 +29,18 @@ let SharedModule = SharedModule_1 = class SharedModule {
29
29
  });
30
30
  providers.push({
31
31
  provide: user_client_1.UsersClient,
32
- useFactory: (client) => new user_client_1.UsersClient(client),
32
+ useFactory: (client) => {
33
+ const svc = new user_client_1.UsersClient(client);
34
+ try {
35
+ // Проверяем готовность сервиса
36
+ svc.onModuleInit();
37
+ SharedModule_1.logger.log("UsersClient initialized successfully");
38
+ }
39
+ catch (err) {
40
+ SharedModule_1.logger.error("UsersClient initialization failed", err);
41
+ }
42
+ return svc;
43
+ },
33
44
  inject: ["USER_PACKAGE"],
34
45
  });
35
46
  }
@@ -51,7 +62,17 @@ let SharedModule = SharedModule_1 = class SharedModule {
51
62
  });
52
63
  providers.push({
53
64
  provide: auth_client_1.AuthClient,
54
- useFactory: (client) => new auth_client_1.AuthClient(client),
65
+ useFactory: (client) => {
66
+ const svc = new auth_client_1.AuthClient(client);
67
+ try {
68
+ svc.onModuleInit();
69
+ SharedModule_1.logger.log("AuthClient initialized successfully");
70
+ }
71
+ catch (err) {
72
+ SharedModule_1.logger.error("AuthClient initialization failed", err);
73
+ }
74
+ return svc;
75
+ },
55
76
  inject: ["AUTH_PACKAGE"],
56
77
  });
57
78
  }
@@ -70,6 +91,7 @@ let SharedModule = SharedModule_1 = class SharedModule {
70
91
  }
71
92
  };
72
93
  exports.SharedModule = SharedModule;
94
+ SharedModule.logger = new common_1.Logger("SharedModule");
73
95
  exports.SharedModule = SharedModule = SharedModule_1 = __decorate([
74
96
  (0, common_1.Module)({})
75
97
  ], SharedModule);
@@ -2,10 +2,11 @@ import { OnModuleInit } from "@nestjs/common";
2
2
  import { ClientGrpc } from "@nestjs/microservices";
3
3
  import { UserServiceClient } from "./user.interface";
4
4
  export declare class UsersClient implements OnModuleInit {
5
- private client;
5
+ private readonly client;
6
6
  private readonly logger;
7
- private userClient;
7
+ private userClient?;
8
8
  constructor(client: ClientGrpc);
9
9
  onModuleInit(): void;
10
10
  get service(): UserServiceClient;
11
+ isReady(): boolean;
11
12
  }
@@ -19,7 +19,6 @@ let UsersClient = UsersClient_1 = class UsersClient {
19
19
  constructor(client) {
20
20
  this.client = client;
21
21
  this.logger = new common_1.Logger(UsersClient_1.name);
22
- this.userClient = null;
23
22
  }
24
23
  onModuleInit() {
25
24
  this.userClient = this.client.getService("UserService");
@@ -27,10 +26,13 @@ let UsersClient = UsersClient_1 = class UsersClient {
27
26
  }
28
27
  get service() {
29
28
  if (!this.userClient) {
30
- throw new Error("UserService not initialized yet");
29
+ throw new common_1.InternalServerErrorException("UserService is not initialized yet");
31
30
  }
32
31
  return this.userClient;
33
32
  }
33
+ isReady() {
34
+ return !!this.userClient;
35
+ }
34
36
  };
35
37
  exports.UsersClient = UsersClient;
36
38
  exports.UsersClient = UsersClient = UsersClient_1 = __decorate([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geniebox-shared-lib",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Shared NestJS library with gRPC clients",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",