@alacard-project/shared 1.0.4 → 1.0.6

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.
Files changed (117) hide show
  1. package/dist/constants/common.constants.d.ts +6 -0
  2. package/dist/constants/common.constants.js +7 -1
  3. package/dist/constants/common.constants.js.map +1 -1
  4. package/dist/constants/env.constants.d.ts +13 -11
  5. package/dist/constants/env.constants.js +13 -11
  6. package/dist/constants/env.constants.js.map +1 -1
  7. package/dist/constants/grpc.constants.d.ts +1 -0
  8. package/dist/constants/grpc.constants.js +1 -0
  9. package/dist/constants/grpc.constants.js.map +1 -1
  10. package/dist/constants/index.d.ts +0 -3
  11. package/dist/constants/index.js +0 -3
  12. package/dist/constants/index.js.map +1 -1
  13. package/dist/constants/logging-messages.constants.d.ts +25 -0
  14. package/dist/constants/logging-messages.constants.js +25 -0
  15. package/dist/constants/logging-messages.constants.js.map +1 -1
  16. package/dist/constants/microservices.constants.d.ts +48 -4
  17. package/dist/constants/microservices.constants.js +48 -4
  18. package/dist/constants/microservices.constants.js.map +1 -1
  19. package/dist/contracts/auth.contract.d.ts +22 -0
  20. package/dist/contracts/index.d.ts +1 -0
  21. package/dist/contracts/index.js +1 -0
  22. package/dist/contracts/index.js.map +1 -1
  23. package/dist/contracts/token.contract.d.ts +39 -0
  24. package/dist/contracts/token.contract.js +3 -0
  25. package/dist/contracts/token.contract.js.map +1 -0
  26. package/dist/decorators/index.d.ts +3 -0
  27. package/dist/{logging → decorators}/index.js +3 -1
  28. package/dist/decorators/index.js.map +1 -0
  29. package/dist/decorators/permissions.decorator.d.ts +3 -0
  30. package/dist/decorators/permissions.decorator.js +8 -0
  31. package/dist/decorators/permissions.decorator.js.map +1 -0
  32. package/dist/decorators/roles.decorator.d.ts +3 -0
  33. package/dist/decorators/roles.decorator.js +8 -0
  34. package/dist/decorators/roles.decorator.js.map +1 -0
  35. package/dist/dto/auth.dto.d.ts +15 -0
  36. package/dist/dto/auth.dto.js +43 -1
  37. package/dist/dto/auth.dto.js.map +1 -1
  38. package/dist/dto/card.dto.d.ts +18 -0
  39. package/dist/dto/card.dto.js +93 -0
  40. package/dist/dto/card.dto.js.map +1 -0
  41. package/dist/dto/client.dto.d.ts +41 -0
  42. package/dist/dto/client.dto.js +185 -0
  43. package/dist/dto/client.dto.js.map +1 -0
  44. package/dist/dto/index.d.ts +4 -0
  45. package/dist/dto/index.js +4 -0
  46. package/dist/dto/index.js.map +1 -1
  47. package/dist/dto/partner.dto.d.ts +7 -0
  48. package/dist/dto/partner.dto.js +39 -0
  49. package/dist/dto/partner.dto.js.map +1 -0
  50. package/dist/dto/transaction.dto.d.ts +16 -0
  51. package/dist/dto/transaction.dto.js +78 -0
  52. package/dist/dto/transaction.dto.js.map +1 -0
  53. package/dist/enums/error.enum.d.ts +3 -1
  54. package/dist/enums/error.enum.js +2 -0
  55. package/dist/enums/error.enum.js.map +1 -1
  56. package/dist/enums/user.enum.d.ts +19 -1
  57. package/dist/enums/user.enum.js +21 -1
  58. package/dist/enums/user.enum.js.map +1 -1
  59. package/dist/errors/error-map.js +10 -0
  60. package/dist/errors/error-map.js.map +1 -1
  61. package/dist/index.d.ts +1 -4
  62. package/dist/index.js +1 -4
  63. package/dist/index.js.map +1 -1
  64. package/dist/interceptors/http-logging.interceptor.d.ts +10 -0
  65. package/dist/interceptors/http-logging.interceptor.js +74 -0
  66. package/dist/interceptors/http-logging.interceptor.js.map +1 -0
  67. package/dist/types/auth.types.d.ts +4 -0
  68. package/dist/utils/health.utils.d.ts +4 -6
  69. package/dist/utils/health.utils.js +7 -51
  70. package/dist/utils/health.utils.js.map +1 -1
  71. package/dist/utils/logging-client.d.ts +7 -5
  72. package/dist/utils/logging-client.js +49 -13
  73. package/dist/utils/logging-client.js.map +1 -1
  74. package/dist/utils/proto-path.js +5 -1
  75. package/dist/utils/proto-path.js.map +1 -1
  76. package/package.json +12 -1
  77. package/proto/card.proto +43 -0
  78. package/proto/client.proto +45 -0
  79. package/proto/partner.proto +18 -0
  80. package/proto/terminal.proto +18 -0
  81. package/proto/transaction.proto +45 -0
  82. package/src/constants/common.constants.ts +7 -0
  83. package/src/constants/env.constants.ts +17 -11
  84. package/src/constants/grpc.constants.ts +1 -0
  85. package/src/constants/index.ts +0 -3
  86. package/src/constants/logging-messages.constants.ts +28 -0
  87. package/src/constants/microservices.constants.ts +48 -4
  88. package/src/contracts/auth.contract.ts +17 -0
  89. package/src/contracts/index.ts +1 -0
  90. package/src/contracts/token.contract.ts +47 -0
  91. package/src/decorators/index.ts +3 -0
  92. package/src/decorators/permissions.decorator.ts +5 -0
  93. package/src/decorators/roles.decorator.ts +5 -0
  94. package/src/dto/auth.dto.ts +31 -0
  95. package/src/dto/card.dto.ts +64 -0
  96. package/src/dto/client.dto.ts +137 -0
  97. package/src/dto/index.ts +4 -0
  98. package/src/dto/partner.dto.ts +21 -0
  99. package/src/dto/transaction.dto.ts +51 -0
  100. package/src/enums/error.enum.ts +2 -0
  101. package/src/enums/user.enum.ts +20 -0
  102. package/src/errors/error-map.ts +10 -0
  103. package/src/index.ts +1 -4
  104. package/src/types/auth.types.ts +5 -0
  105. package/src/utils/health.utils.ts +8 -63
  106. package/src/utils/proto-path.ts +13 -7
  107. package/dist/logging/dto/log-filter.dto.d.ts +0 -29
  108. package/dist/logging/dto/log-filter.dto.js +0 -146
  109. package/dist/logging/dto/log-filter.dto.js.map +0 -1
  110. package/dist/logging/index.d.ts +0 -1
  111. package/dist/logging/index.js.map +0 -1
  112. package/src/config/base-config.service.ts +0 -101
  113. package/src/constants/logging.constants.ts +0 -26
  114. package/src/constants/monitoring.constants.ts +0 -71
  115. package/src/constants/tokens.constants.ts +0 -6
  116. package/src/utils/logging-client.ts +0 -21
  117. package/src/utils/prometheus.utils.ts +0 -114
@@ -1,72 +1,17 @@
1
- /**
2
- * Health Check Utilities
3
- */
1
+ export type HealthCheckStatus = 'up' | 'down';
4
2
 
5
3
  export interface ComponentHealth {
6
- status: 'up' | 'down';
7
- message?: string;
8
- responseTime?: number;
4
+ status: HealthCheckStatus;
5
+ [key: string]: any;
9
6
  }
10
7
 
11
- /**
12
- * Create Prisma health check function
13
- */
14
- export function createPrismaHealthCheck(prisma: any) {
8
+ export const createPrismaHealthCheck = (prisma: any) => {
15
9
  return async (): Promise<ComponentHealth> => {
16
- const start = Date.now();
17
10
  try {
18
11
  await prisma.$queryRaw`SELECT 1`;
19
- return {
20
- status: 'up',
21
- responseTime: Date.now() - start,
22
- };
23
- } catch (error: any) {
24
- return {
25
- status: 'down',
26
- message: error.message,
27
- };
12
+ return { status: 'up' };
13
+ } catch (e: any) {
14
+ return { status: 'down', error: e.message };
28
15
  }
29
16
  };
30
- }
31
-
32
- /**
33
- * Create Redis health check function
34
- */
35
- export function createRedisHealthCheck(redis: any) {
36
- return async (): Promise<ComponentHealth> => {
37
- const start = Date.now();
38
- try {
39
- await redis.ping();
40
- return {
41
- status: 'up',
42
- responseTime: Date.now() - start,
43
- };
44
- } catch (error: any) {
45
- return {
46
- status: 'down',
47
- message: error.message,
48
- };
49
- }
50
- };
51
- }
52
-
53
- /**
54
- * Create gRPC service health check function
55
- */
56
- export function createGrpcHealthCheck(client: any, methodName: string = 'ping') {
57
- return async (): Promise<ComponentHealth> => {
58
- const start = Date.now();
59
- try {
60
- await client[methodName]({});
61
- return {
62
- status: 'up',
63
- responseTime: Date.now() - start,
64
- };
65
- } catch (error: any) {
66
- return {
67
- status: 'down',
68
- message: error.message,
69
- };
70
- }
71
- };
72
- }
17
+ };
@@ -1,15 +1,21 @@
1
1
  import { join } from 'path';
2
2
 
3
- /**
4
- * Returns the absolute path to a proto file.
5
- * Assumes protos are in the 'proto' directory at the shared library root.
6
- */
7
3
  export function getProtoPath(serviceName: string): string {
8
- // In Docker/Production, this might be absolute
4
+ // Priority 1: Environment variable override
9
5
  if (process.env.PROTO_PATH_OVERRIDE) {
10
6
  return join(process.env.PROTO_PATH_OVERRIDE, `${serviceName}.proto`);
11
7
  }
12
8
 
13
- // Default path relative to the shared/proto directory
14
- return join(__dirname, '../../proto', `${serviceName}.proto`);
9
+ // Priority 2: Well-known Docker location (even in development mode if running in container)
10
+ // We detect container by checking if we are on Linux and /app directory exists
11
+ // but a simpler check is often just looking for common Docker env vars or assuming /app/proto
12
+ const dockerProtoPath = '/app/proto';
13
+
14
+ // In our specific Docker stack, we ALWAYS want this path if it's likely we are in Docker
15
+ if (process.platform === 'linux' || process.env.NODE_ENV === 'production' || process.env.KUBERNETES_SERVICE_HOST) {
16
+ return join(dockerProtoPath, `${serviceName}.proto`);
17
+ }
18
+
19
+ // Priority 3: Default path relative to the current working directory (local development)
20
+ return join(process.cwd(), 'proto', `${serviceName}.proto`);
15
21
  }
@@ -1,29 +0,0 @@
1
- import { LogLevel } from '../../enums';
2
- export declare class LogFilterDto {
3
- startDate?: string;
4
- endDate?: string;
5
- serviceName?: string;
6
- level?: LogLevel;
7
- userId?: string;
8
- requestId?: string;
9
- page?: number;
10
- pageSize?: number;
11
- }
12
- export declare class LogCleanupDto {
13
- startDate: string;
14
- endDate: string;
15
- serviceName?: string;
16
- level?: LogLevel;
17
- }
18
- export declare class RetentionPeriodDto {
19
- retentionDays: number;
20
- }
21
- export declare class UserActionFilterDto {
22
- startDate?: string;
23
- endDate?: string;
24
- userId?: string;
25
- action?: string;
26
- resource?: string;
27
- page?: number;
28
- pageSize?: number;
29
- }
@@ -1,146 +0,0 @@
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 __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserActionFilterDto = exports.RetentionPeriodDto = exports.LogCleanupDto = exports.LogFilterDto = void 0;
13
- const class_validator_1 = require("class-validator");
14
- const class_transformer_1 = require("class-transformer");
15
- const enums_1 = require("../../enums");
16
- class LogFilterDto {
17
- constructor() {
18
- this.page = 1;
19
- this.pageSize = 20;
20
- }
21
- }
22
- exports.LogFilterDto = LogFilterDto;
23
- __decorate([
24
- (0, class_validator_1.IsOptional)(),
25
- (0, class_validator_1.IsDateString)(),
26
- __metadata("design:type", String)
27
- ], LogFilterDto.prototype, "startDate", void 0);
28
- __decorate([
29
- (0, class_validator_1.IsOptional)(),
30
- (0, class_validator_1.IsDateString)(),
31
- __metadata("design:type", String)
32
- ], LogFilterDto.prototype, "endDate", void 0);
33
- __decorate([
34
- (0, class_validator_1.IsOptional)(),
35
- (0, class_validator_1.IsString)(),
36
- __metadata("design:type", String)
37
- ], LogFilterDto.prototype, "serviceName", void 0);
38
- __decorate([
39
- (0, class_validator_1.IsOptional)(),
40
- (0, class_validator_1.IsEnum)(enums_1.LogLevel),
41
- __metadata("design:type", String)
42
- ], LogFilterDto.prototype, "level", void 0);
43
- __decorate([
44
- (0, class_validator_1.IsOptional)(),
45
- (0, class_validator_1.IsString)(),
46
- __metadata("design:type", String)
47
- ], LogFilterDto.prototype, "userId", void 0);
48
- __decorate([
49
- (0, class_validator_1.IsOptional)(),
50
- (0, class_validator_1.IsString)(),
51
- __metadata("design:type", String)
52
- ], LogFilterDto.prototype, "requestId", void 0);
53
- __decorate([
54
- (0, class_validator_1.IsOptional)(),
55
- (0, class_transformer_1.Type)(() => Number),
56
- (0, class_validator_1.IsInt)(),
57
- (0, class_validator_1.Min)(1),
58
- __metadata("design:type", Number)
59
- ], LogFilterDto.prototype, "page", void 0);
60
- __decorate([
61
- (0, class_validator_1.IsOptional)(),
62
- (0, class_transformer_1.Type)(() => Number),
63
- (0, class_validator_1.IsInt)(),
64
- (0, class_validator_1.Min)(1),
65
- (0, class_validator_1.Max)(100),
66
- __metadata("design:type", Number)
67
- ], LogFilterDto.prototype, "pageSize", void 0);
68
- class LogCleanupDto {
69
- }
70
- exports.LogCleanupDto = LogCleanupDto;
71
- __decorate([
72
- (0, class_validator_1.IsDateString)(),
73
- __metadata("design:type", String)
74
- ], LogCleanupDto.prototype, "startDate", void 0);
75
- __decorate([
76
- (0, class_validator_1.IsDateString)(),
77
- __metadata("design:type", String)
78
- ], LogCleanupDto.prototype, "endDate", void 0);
79
- __decorate([
80
- (0, class_validator_1.IsOptional)(),
81
- (0, class_validator_1.IsString)(),
82
- __metadata("design:type", String)
83
- ], LogCleanupDto.prototype, "serviceName", void 0);
84
- __decorate([
85
- (0, class_validator_1.IsOptional)(),
86
- (0, class_validator_1.IsEnum)(enums_1.LogLevel),
87
- __metadata("design:type", String)
88
- ], LogCleanupDto.prototype, "level", void 0);
89
- class RetentionPeriodDto {
90
- }
91
- exports.RetentionPeriodDto = RetentionPeriodDto;
92
- __decorate([
93
- (0, class_transformer_1.Type)(() => Number),
94
- (0, class_validator_1.IsInt)(),
95
- (0, class_validator_1.Min)(1),
96
- (0, class_validator_1.Max)(365),
97
- __metadata("design:type", Number)
98
- ], RetentionPeriodDto.prototype, "retentionDays", void 0);
99
- class UserActionFilterDto {
100
- constructor() {
101
- this.page = 1;
102
- this.pageSize = 20;
103
- }
104
- }
105
- exports.UserActionFilterDto = UserActionFilterDto;
106
- __decorate([
107
- (0, class_validator_1.IsOptional)(),
108
- (0, class_validator_1.IsDateString)(),
109
- __metadata("design:type", String)
110
- ], UserActionFilterDto.prototype, "startDate", void 0);
111
- __decorate([
112
- (0, class_validator_1.IsOptional)(),
113
- (0, class_validator_1.IsDateString)(),
114
- __metadata("design:type", String)
115
- ], UserActionFilterDto.prototype, "endDate", void 0);
116
- __decorate([
117
- (0, class_validator_1.IsOptional)(),
118
- (0, class_validator_1.IsString)(),
119
- __metadata("design:type", String)
120
- ], UserActionFilterDto.prototype, "userId", void 0);
121
- __decorate([
122
- (0, class_validator_1.IsOptional)(),
123
- (0, class_validator_1.IsString)(),
124
- __metadata("design:type", String)
125
- ], UserActionFilterDto.prototype, "action", void 0);
126
- __decorate([
127
- (0, class_validator_1.IsOptional)(),
128
- (0, class_validator_1.IsString)(),
129
- __metadata("design:type", String)
130
- ], UserActionFilterDto.prototype, "resource", void 0);
131
- __decorate([
132
- (0, class_validator_1.IsOptional)(),
133
- (0, class_transformer_1.Type)(() => Number),
134
- (0, class_validator_1.IsInt)(),
135
- (0, class_validator_1.Min)(1),
136
- __metadata("design:type", Number)
137
- ], UserActionFilterDto.prototype, "page", void 0);
138
- __decorate([
139
- (0, class_validator_1.IsOptional)(),
140
- (0, class_transformer_1.Type)(() => Number),
141
- (0, class_validator_1.IsInt)(),
142
- (0, class_validator_1.Min)(1),
143
- (0, class_validator_1.Max)(100),
144
- __metadata("design:type", Number)
145
- ], UserActionFilterDto.prototype, "pageSize", void 0);
146
- //# sourceMappingURL=log-filter.dto.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"log-filter.dto.js","sourceRoot":"","sources":["../../../src/logging/dto/log-filter.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAA8F;AAC9F,yDAAyC;AACzC,uCAAuC;AAEvC,MAAa,YAAY;IAAzB;QA6BI,SAAI,GAAY,CAAC,CAAC;QAOlB,aAAQ,GAAY,EAAE,CAAC;IAC3B,CAAC;CAAA;AArCD,oCAqCC;AAlCG;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,8BAAY,GAAE;;+CACI;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,8BAAY,GAAE;;6CACE;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACU;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,gBAAQ,CAAC;;2CACA;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;4CACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;+CACQ;AAMnB;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;;0CACW;AAOlB;IALC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,qBAAG,EAAC,GAAG,CAAC;;8CACc;AAG3B,MAAa,aAAa;CAczB;AAdD,sCAcC;AAZG;IADC,IAAA,8BAAY,GAAE;;gDACG;AAGlB;IADC,IAAA,8BAAY,GAAE;;8CACC;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACU;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAM,EAAC,gBAAQ,CAAC;;4CACA;AAGrB,MAAa,kBAAkB;CAM9B;AAND,gDAMC;AADG;IAJC,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,qBAAG,EAAC,GAAG,CAAC;;yDACa;AAG1B,MAAa,mBAAmB;IAAhC;QAyBI,SAAI,GAAY,CAAC,CAAC;QAOlB,aAAQ,GAAY,EAAE,CAAC;IAC3B,CAAC;CAAA;AAjCD,kDAiCC;AA9BG;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,8BAAY,GAAE;;sDACI;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,8BAAY,GAAE;;oDACE;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;qDACO;AAMlB;IAJC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;;iDACW;AAOlB;IALC,IAAA,4BAAU,GAAE;IACZ,IAAA,wBAAI,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IAClB,IAAA,uBAAK,GAAE;IACP,IAAA,qBAAG,EAAC,CAAC,CAAC;IACN,IAAA,qBAAG,EAAC,GAAG,CAAC;;qDACc"}
@@ -1 +0,0 @@
1
- export * from './dto/log-filter.dto';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logging/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
@@ -1,101 +0,0 @@
1
- import { ConfigService } from '@nestjs/config';
2
- import { ENV_KEYS } from '../constants/env.constants';
3
- import { Environment } from '../enums/env.enum';
4
-
5
- export abstract class BaseConfigService {
6
- constructor(protected readonly configService: ConfigService) { }
7
-
8
- get environment(): Environment {
9
- return this.configService.get<Environment>(ENV_KEYS.NODE_ENV) || Environment.DEVELOPMENT;
10
- }
11
-
12
- get isProduction(): boolean {
13
- return this.environment === Environment.PRODUCTION;
14
- }
15
-
16
- get port(): number {
17
- return this.getOptionalNumber(ENV_KEYS.PORT, 3000)!;
18
- }
19
-
20
- get databaseUrl(): string {
21
- return this.getRequiredString(ENV_KEYS.DATABASE_URL);
22
- }
23
-
24
- get redisHost(): string {
25
- return this.getRequiredString(ENV_KEYS.REDIS_HOST);
26
- }
27
-
28
- get redisPort(): number {
29
- return this.getRequiredNumber(ENV_KEYS.REDIS_PORT);
30
- }
31
-
32
- get kafkaBrokers(): string[] {
33
- const brokers = this.getRequiredString(ENV_KEYS.KAFKA_BROKERS);
34
- return brokers.split(',');
35
- }
36
-
37
- get corsOrigins(): string[] {
38
- const origins = this.getOptionalString(ENV_KEYS.CORS_ORIGINS);
39
- return origins ? origins.split(',') : ['*'];
40
- }
41
-
42
- get rabbitmqUrl(): string {
43
- return this.getRequiredString(ENV_KEYS.RABBITMQ_URL);
44
- }
45
-
46
- get rateLimitTtl(): number {
47
- return this.getOptionalNumber(ENV_KEYS.RATE_LIMIT_TTL, 60)!;
48
- }
49
-
50
- get rateLimitMax(): number {
51
- return this.getOptionalNumber(ENV_KEYS.RATE_LIMIT_MAX, 10)!;
52
- }
53
-
54
- get userServiceUrl(): string {
55
- return this.getRequiredString(ENV_KEYS.USER_SERVICE_URL);
56
- }
57
-
58
- get userProtoPath(): string {
59
- return this.getRequiredString(ENV_KEYS.USER_PROTO_PATH);
60
- }
61
-
62
- protected getRequiredString(key: string): string {
63
- const value = this.configService.get<string>(key);
64
- if (!value) {
65
- throw new Error(`Config error: ${key} is required`);
66
- }
67
- return value;
68
- }
69
-
70
- protected getRequiredNumber(key: string): number {
71
- const value = this.configService.get<number>(key);
72
- if (value === undefined) {
73
- throw new Error(`Config error: ${key} is required`);
74
- }
75
- return value;
76
- }
77
-
78
- protected getOptionalString(key: string, defaultValue?: string): string | undefined {
79
- return this.configService.get<string>(key) || defaultValue;
80
- }
81
-
82
- protected getOptionalNumber(key: string, defaultValue?: number): number | undefined {
83
- return this.configService.get<number>(key) ?? defaultValue;
84
- }
85
-
86
- protected getOptionalBoolean(key: string, defaultValue = false): boolean {
87
- return this.configService.get<boolean>(key) ?? defaultValue;
88
- }
89
-
90
- protected timeToSeconds(timeStr: string): number {
91
- const unit = timeStr.slice(-1);
92
- const value = parseInt(timeStr.slice(0, -1));
93
- switch (unit) {
94
- case 's': return value;
95
- case 'm': return value * 60;
96
- case 'h': return value * 3600;
97
- case 'd': return value * 86400;
98
- default: return parseInt(timeStr);
99
- }
100
- }
101
- }
@@ -1,26 +0,0 @@
1
- export const LOG_RETENTION_PERIODS = {
2
- SHORT: 7,
3
- MEDIUM: 30,
4
- LONG: 90,
5
- } as const;
6
-
7
- export const LOG_CLEANUP_MESSAGES = {
8
- SUCCESS: 'Logs cleaned up successfully',
9
- INVALID_DATE_RANGE: 'Invalid date range',
10
- NO_LOGS_FOUND: 'No logs found for cleanup',
11
- CLEANUP_STARTED: 'Log cleanup started',
12
- CLEANUP_COMPLETED: 'Log cleanup completed',
13
- CLEANUP_FAILED: 'Log cleanup failed',
14
- FILE_CLEANUP_SUCCESS: 'File cleanup successful',
15
- FILE_CLEANUP_FAILED: 'File cleanup failed',
16
- RETENTION_UPDATED: 'Retention period updated',
17
- } as const;
18
-
19
- export const LOGGING_ERROR_MESSAGES = {
20
- LOG_EVENT_FAILED: 'Failed to log event',
21
- LOG_USER_ACTION_FAILED: 'Failed to log user action',
22
- UPDATE_SERVICE_STATUS_FAILED: 'Failed to update service status',
23
- GET_SERVICE_LOGS_FAILED: 'Failed to get service logs',
24
- GET_SERVICE_STATUS_FAILED: 'Failed to get service status',
25
- GET_USER_ACTIONS_FAILED: 'Failed to get user actions',
26
- } as const;
@@ -1,71 +0,0 @@
1
- /**
2
- * Prometheus Metrics Constants
3
- */
4
-
5
- export const PROMETHEUS_METRICS = {
6
- // HTTP Metrics
7
- HTTP_REQUESTS_TOTAL: 'http_requests_total',
8
- HTTP_REQUEST_DURATION: 'http_request_duration_seconds',
9
- HTTP_ERRORS_TOTAL: 'http_errors_total',
10
- HTTP_RESPONSE_SIZE: 'http_response_size_bytes',
11
-
12
- // Database Metrics
13
- DB_CONNECTIONS_ACTIVE: 'db_connections_active',
14
- DB_CONNECTIONS_IDLE: 'db_connections_idle',
15
- DB_QUERY_DURATION: 'db_query_duration_seconds',
16
- DB_QUERIES_TOTAL: 'db_queries_total',
17
- DB_ERRORS_TOTAL: 'db_errors_total',
18
-
19
- // gRPC Metrics
20
- GRPC_REQUESTS_TOTAL: 'grpc_requests_total',
21
- GRPC_REQUEST_DURATION: 'grpc_request_duration_seconds',
22
- GRPC_ERRORS_TOTAL: 'grpc_errors_total',
23
-
24
- // Kafka Metrics
25
- KAFKA_MESSAGES_SENT: 'kafka_messages_sent_total',
26
- KAFKA_MESSAGES_RECEIVED: 'kafka_messages_received_total',
27
- KAFKA_ERRORS_TOTAL: 'kafka_errors_total',
28
-
29
- // System Metrics
30
- PROCESS_CPU_USAGE: 'process_cpu_usage_percent',
31
- PROCESS_MEMORY_USAGE: 'process_memory_usage_bytes',
32
- PROCESS_HEAP_USED: 'process_heap_used_bytes',
33
- PROCESS_HEAP_TOTAL: 'process_heap_total_bytes',
34
- PROCESS_UPTIME: 'process_uptime_seconds',
35
-
36
- // Application Metrics
37
- ACTIVE_USERS: 'active_users_total',
38
- REGISTERED_USERS: 'registered_users_total',
39
- REQUESTS_PER_SECOND: 'requests_per_second',
40
- ERROR_RATE: 'error_rate_percent',
41
-
42
- // Cache Metrics
43
- CACHE_HITS: 'cache_hits_total',
44
- CACHE_MISSES: 'cache_misses_total',
45
- CACHE_SIZE: 'cache_size_bytes',
46
- } as const;
47
-
48
- export const METRIC_LABELS = {
49
- SERVICE: 'service',
50
- METHOD: 'method',
51
- STATUS: 'status',
52
- ENDPOINT: 'endpoint',
53
- ERROR_TYPE: 'error_type',
54
- DATABASE: 'database',
55
- QUERY_TYPE: 'query_type',
56
- USER_ROLE: 'user_role',
57
- GRPC_METHOD: 'grpc_method',
58
- KAFKA_TOPIC: 'kafka_topic',
59
- } as const;
60
-
61
- export const HEALTH_CHECK_ENDPOINTS = {
62
- LIVENESS: '/health/liveness',
63
- READINESS: '/health/readiness',
64
- STARTUP: '/health/startup',
65
- } as const;
66
-
67
- export const MONITORING_CONFIG = {
68
- SCRAPE_INTERVAL: 15, // seconds
69
- SCRAPE_TIMEOUT: 10, // seconds
70
- RETENTION_DAYS: 15,
71
- } as const;
@@ -1,6 +0,0 @@
1
- export const SERVICE_TOKENS = {
2
- USER_SERVICE: 'USER_PACKAGE',
3
- AUTH_SERVICE: 'AUTH_PACKAGE',
4
- LOGGING_SERVICE: 'LOGGING_PACKAGE',
5
- CONFIG_SERVICE: 'CONFIG_PACKAGE',
6
- } as const;
@@ -1,21 +0,0 @@
1
- export class LoggingClient {
2
- logInfo(message: string, context?: any) {
3
- console.log(`[INFO] ${message}`, context || '');
4
- }
5
-
6
- logWarn(message: string, context?: any) {
7
- console.warn(`[WARN] ${message}`, context || '');
8
- }
9
-
10
- logError(message: string, context?: any) {
11
- console.error(`[ERROR] ${message}`, context || '');
12
- }
13
-
14
- logUserAction(userId: string, email: string, action: string, resource: string, details?: any) {
15
- console.log(`[USER_ACTION] ${action} by ${email} (${userId}) on ${resource}`, details || '');
16
- }
17
-
18
- updateServiceStatus(serviceName: string, status: string, version: string, uptime: number, metadata?: string) {
19
- console.log(`[SERVICE_STATUS] ${serviceName} is ${status} (v${version}, uptime: ${uptime}s)`, metadata || '');
20
- }
21
- }
@@ -1,114 +0,0 @@
1
- /**
2
- * Prometheus Metrics Utilities
3
- */
4
-
5
- import { PrometheusMetric, MetricValue } from '../types/monitoring.types';
6
-
7
- /**
8
- * Format metric for Prometheus exposition format
9
- */
10
- export function formatPrometheusMetric(
11
- metric: PrometheusMetric,
12
- value: MetricValue
13
- ): string {
14
- const labels = value.labels
15
- ? Object.entries(value.labels)
16
- .map(([key, val]) => `${key}="${val}"`)
17
- .join(',')
18
- : '';
19
-
20
- const metricLine = labels
21
- ? `${metric.name}{${labels}} ${value.value}`
22
- : `${metric.name} ${value.value}`;
23
-
24
- return value.timestamp
25
- ? `${metricLine} ${value.timestamp}`
26
- : metricLine;
27
- }
28
-
29
- /**
30
- * Create a counter metric
31
- */
32
- export function createCounter(
33
- name: string,
34
- help: string,
35
- labelNames?: string[]
36
- ): PrometheusMetric {
37
- return {
38
- name,
39
- help,
40
- type: 'counter',
41
- labelNames,
42
- };
43
- }
44
-
45
- /**
46
- * Create a gauge metric
47
- */
48
- export function createGauge(
49
- name: string,
50
- help: string,
51
- labelNames?: string[]
52
- ): PrometheusMetric {
53
- return {
54
- name,
55
- help,
56
- type: 'gauge',
57
- labelNames,
58
- };
59
- }
60
-
61
- /**
62
- * Create a histogram metric
63
- */
64
- export function createHistogram(
65
- name: string,
66
- help: string,
67
- labelNames?: string[]
68
- ): PrometheusMetric {
69
- return {
70
- name,
71
- help,
72
- type: 'histogram',
73
- labelNames,
74
- };
75
- }
76
-
77
- /**
78
- * Calculate percentile from histogram data
79
- */
80
- export function calculatePercentile(
81
- values: number[],
82
- percentile: number
83
- ): number {
84
- if (values.length === 0) return 0;
85
-
86
- const sorted = [...values].sort((a, b) => a - b);
87
- const index = Math.ceil((percentile / 100) * sorted.length) - 1;
88
- return sorted[index];
89
- }
90
-
91
- /**
92
- * Format duration in seconds
93
- */
94
- export function formatDuration(milliseconds: number): number {
95
- return milliseconds / 1000;
96
- }
97
-
98
- /**
99
- * Format bytes to megabytes
100
- */
101
- export function bytesToMegabytes(bytes: number): number {
102
- return bytes / (1024 * 1024);
103
- }
104
-
105
- /**
106
- * Calculate error rate percentage
107
- */
108
- export function calculateErrorRate(
109
- errorCount: number,
110
- totalCount: number
111
- ): number {
112
- if (totalCount === 0) return 0;
113
- return (errorCount / totalCount) * 100;
114
- }