@trash-streamers/common 1.1.5 → 1.2.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.
@@ -2,4 +2,5 @@ export declare class GrpcValidator {
2
2
  GRPC_HOST: string;
3
3
  GRPC_PORT: number;
4
4
  USERS_GRPC_URL: string;
5
+ AUTH_GRPC_URL: string;
5
6
  }
@@ -15,6 +15,7 @@ class GrpcValidator {
15
15
  GRPC_HOST;
16
16
  GRPC_PORT;
17
17
  USERS_GRPC_URL;
18
+ AUTH_GRPC_URL;
18
19
  }
19
20
  exports.GrpcValidator = GrpcValidator;
20
21
  __decorate([
@@ -26,6 +27,12 @@ __decorate([
26
27
  __metadata("design:type", Number)
27
28
  ], GrpcValidator.prototype, "GRPC_PORT", void 0);
28
29
  __decorate([
30
+ (0, class_validator_1.IsOptional)(),
29
31
  (0, class_validator_1.IsString)(),
30
32
  __metadata("design:type", String)
31
33
  ], GrpcValidator.prototype, "USERS_GRPC_URL", void 0);
34
+ __decorate([
35
+ (0, class_validator_1.IsOptional)(),
36
+ (0, class_validator_1.IsString)(),
37
+ __metadata("design:type", String)
38
+ ], GrpcValidator.prototype, "AUTH_GRPC_URL", void 0);
@@ -0,0 +1 @@
1
+ export declare const GRPC_CLIENT_PREFIX = "GRPC_CLIENT";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRPC_CLIENT_PREFIX = void 0;
4
+ exports.GRPC_CLIENT_PREFIX = 'GRPC_CLIENT';
@@ -0,0 +1 @@
1
+ export * from './inject-grpc-client.decorator';
@@ -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("./inject-grpc-client.decorator"), exports);
@@ -0,0 +1 @@
1
+ export declare const InjectGrpcClient: (name: string) => PropertyDecorator & ParameterDecorator;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectGrpcClient = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const grpc_constants_1 = require("../constants/grpc.constants");
6
+ const InjectGrpcClient = (name) => (0, common_1.Inject)(`${grpc_constants_1.GRPC_CLIENT_PREFIX}_${name}`);
7
+ exports.InjectGrpcClient = InjectGrpcClient;
@@ -0,0 +1,11 @@
1
+ import { ClientGrpc } from '@nestjs/microservices';
2
+ export declare class GrpcClientFactory {
3
+ private clients;
4
+ createClient(options: {
5
+ package: string;
6
+ protoPath: string;
7
+ url: string;
8
+ }): ClientGrpc;
9
+ register(token: string, client: ClientGrpc): void;
10
+ getClient<T extends ClientGrpc = ClientGrpc>(token: string): T;
11
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.GrpcClientFactory = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const microservices_1 = require("@nestjs/microservices");
12
+ let GrpcClientFactory = class GrpcClientFactory {
13
+ clients = new Map();
14
+ createClient(options) {
15
+ return microservices_1.ClientProxyFactory.create({
16
+ transport: microservices_1.Transport.GRPC,
17
+ options
18
+ });
19
+ }
20
+ register(token, client) {
21
+ this.clients.set(token, client);
22
+ }
23
+ getClient(token) {
24
+ const client = this.clients.get(token);
25
+ if (!client)
26
+ throw new Error(`Grpc client "${token}" not found`);
27
+ return client;
28
+ }
29
+ };
30
+ exports.GrpcClientFactory = GrpcClientFactory;
31
+ exports.GrpcClientFactory = GrpcClientFactory = __decorate([
32
+ (0, common_1.Injectable)()
33
+ ], GrpcClientFactory);
@@ -0,0 +1,5 @@
1
+ import { type DynamicModule } from '@nestjs/common';
2
+ import { GRPC_CLIENTS } from './registry/grpc.registry';
3
+ export declare class GrpcModule {
4
+ static register(clients: Array<keyof typeof GRPC_CLIENTS>): DynamicModule;
5
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var GrpcModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.GrpcModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const config_1 = require("@nestjs/config");
13
+ const grpc_constants_1 = require("./constants/grpc.constants");
14
+ const grpc_client_factory_1 = require("./factory/grpc-client.factory");
15
+ const grpc_registry_1 = require("./registry/grpc.registry");
16
+ let GrpcModule = GrpcModule_1 = class GrpcModule {
17
+ static register(clients) {
18
+ return {
19
+ module: GrpcModule_1,
20
+ providers: [
21
+ grpc_client_factory_1.GrpcClientFactory,
22
+ ...clients.map(token => {
23
+ const cfg = grpc_registry_1.GRPC_CLIENTS[token];
24
+ return {
25
+ provide: `${grpc_constants_1.GRPC_CLIENT_PREFIX}_${token}`,
26
+ useFactory: (factory, config) => {
27
+ const url = config.getOrThrow(cfg.env);
28
+ const client = factory.createClient({
29
+ package: cfg.package,
30
+ protoPath: cfg.protoPath,
31
+ url
32
+ });
33
+ factory.register(token, client);
34
+ return client;
35
+ },
36
+ inject: [grpc_client_factory_1.GrpcClientFactory, config_1.ConfigService]
37
+ };
38
+ })
39
+ ],
40
+ exports: [
41
+ grpc_client_factory_1.GrpcClientFactory,
42
+ ...clients.map(token => `${grpc_constants_1.GRPC_CLIENT_PREFIX}_${token}`)
43
+ ]
44
+ };
45
+ }
46
+ };
47
+ exports.GrpcModule = GrpcModule;
48
+ exports.GrpcModule = GrpcModule = GrpcModule_1 = __decorate([
49
+ (0, common_1.Module)({})
50
+ ], GrpcModule);
@@ -0,0 +1,2 @@
1
+ export * from './decorators';
2
+ export * from './grpc.module';
@@ -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("./decorators"), exports);
18
+ __exportStar(require("./grpc.module"), exports);
@@ -0,0 +1,17 @@
1
+ export declare const GRPC_CLIENTS: {
2
+ readonly AUTH_PACKAGE: {
3
+ readonly package: "auth.v1";
4
+ readonly protoPath: string;
5
+ readonly env: "AUTH_GRPC_URL";
6
+ };
7
+ readonly ACCOUNT_PACKAGE: {
8
+ readonly package: "account.v1";
9
+ readonly protoPath: string;
10
+ readonly env: "AUTH_GRPC_URL";
11
+ };
12
+ readonly USERS_PACKAGE: {
13
+ readonly package: "users.v1";
14
+ readonly protoPath: string;
15
+ readonly env: "USERS_GRPC_URL";
16
+ };
17
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRPC_CLIENTS = void 0;
4
+ const contracts_1 = require("@trash-streamers/contracts");
5
+ exports.GRPC_CLIENTS = {
6
+ AUTH_PACKAGE: {
7
+ package: 'auth.v1',
8
+ protoPath: contracts_1.PROTO_PATHS.AUTH,
9
+ env: 'AUTH_GRPC_URL'
10
+ },
11
+ ACCOUNT_PACKAGE: {
12
+ package: 'account.v1',
13
+ protoPath: contracts_1.PROTO_PATHS.ACCOUNT,
14
+ env: 'AUTH_GRPC_URL'
15
+ },
16
+ USERS_PACKAGE: {
17
+ package: 'users.v1',
18
+ protoPath: contracts_1.PROTO_PATHS.USERS,
19
+ env: 'USERS_GRPC_URL'
20
+ }
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trash-streamers/common",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "description": "Core shared component for Trash-streamers microservice ecosystem",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,13 +17,18 @@
17
17
  "devDependencies": {
18
18
  "@trash-streamers/core": "^1.0.2",
19
19
  "@types/node": "^25.0.3",
20
- "prettier": "^3.7.4",
21
- "typescript": "^5.9.3",
22
20
  "class-transformer": "^0.5.1",
23
- "class-validator": "^0.14.3"
21
+ "class-validator": "^0.14.3",
22
+ "prettier": "^3.7.4",
23
+ "typescript": "^5.9.3"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "class-transformer": "^0.5.1",
27
27
  "class-validator": "^0.14.3"
28
+ },
29
+ "dependencies": {
30
+ "@nestjs/common": "^11.1.12",
31
+ "@nestjs/config": "^4.0.2",
32
+ "@trash-streamers/contracts": "^1.1.7"
28
33
  }
29
34
  }