@saultechitsolutions/gighub-shared-core 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.
Files changed (104) hide show
  1. package/dist/audit/audit.module.d.ts +2 -0
  2. package/dist/audit/audit.module.js +25 -0
  3. package/dist/audit/audit.module.js.map +1 -0
  4. package/dist/audit/audit.service.d.ts +16 -0
  5. package/dist/audit/audit.service.js +95 -0
  6. package/dist/audit/audit.service.js.map +1 -0
  7. package/dist/audit/interfaces/audit-log.interface.d.ts +36 -0
  8. package/dist/audit/interfaces/audit-log.interface.js +3 -0
  9. package/dist/audit/interfaces/audit-log.interface.js.map +1 -0
  10. package/dist/context/geolocation.service.d.ts +19 -0
  11. package/dist/context/geolocation.service.js +87 -0
  12. package/dist/context/geolocation.service.js.map +1 -0
  13. package/dist/context/interfaces/request-context.interface.d.ts +29 -0
  14. package/dist/context/interfaces/request-context.interface.js +3 -0
  15. package/dist/context/interfaces/request-context.interface.js.map +1 -0
  16. package/dist/context/request-context.middleware.d.ts +11 -0
  17. package/dist/context/request-context.middleware.js +88 -0
  18. package/dist/context/request-context.middleware.js.map +1 -0
  19. package/dist/context/request-context.module.d.ts +4 -0
  20. package/dist/context/request-context.module.js +27 -0
  21. package/dist/context/request-context.module.js.map +1 -0
  22. package/dist/context/request-context.service.d.ts +24 -0
  23. package/dist/context/request-context.service.js +150 -0
  24. package/dist/context/request-context.service.js.map +1 -0
  25. package/dist/decorators/current-user.decorator.d.ts +1 -0
  26. package/dist/decorators/current-user.decorator.js +10 -0
  27. package/dist/decorators/current-user.decorator.js.map +1 -0
  28. package/dist/decorators/public.decorator.d.ts +2 -0
  29. package/dist/decorators/public.decorator.js +8 -0
  30. package/dist/decorators/public.decorator.js.map +1 -0
  31. package/dist/decorators/roles.decorator.d.ts +2 -0
  32. package/dist/decorators/roles.decorator.js +8 -0
  33. package/dist/decorators/roles.decorator.js.map +1 -0
  34. package/dist/dto/api-response.dto.d.ts +25 -0
  35. package/dist/dto/api-response.dto.js +87 -0
  36. package/dist/dto/api-response.dto.js.map +1 -0
  37. package/dist/dto/base.dto.d.ts +5 -0
  38. package/dist/dto/base.dto.js +7 -0
  39. package/dist/dto/base.dto.js.map +1 -0
  40. package/dist/dto/pagination.dto.d.ts +14 -0
  41. package/dist/dto/pagination.dto.js +59 -0
  42. package/dist/dto/pagination.dto.js.map +1 -0
  43. package/dist/exceptions/api.exception.d.ts +10 -0
  44. package/dist/exceptions/api.exception.js +31 -0
  45. package/dist/exceptions/api.exception.js.map +1 -0
  46. package/dist/exceptions/business.exception.d.ts +12 -0
  47. package/dist/exceptions/business.exception.js +37 -0
  48. package/dist/exceptions/business.exception.js.map +1 -0
  49. package/dist/exceptions/database.exception.d.ts +11 -0
  50. package/dist/exceptions/database.exception.js +34 -0
  51. package/dist/exceptions/database.exception.js.map +1 -0
  52. package/dist/filters/global-exception.filter.d.ts +10 -0
  53. package/dist/filters/global-exception.filter.js +131 -0
  54. package/dist/filters/global-exception.filter.js.map +1 -0
  55. package/dist/filters/http-exception.filter.d.ts +8 -0
  56. package/dist/filters/http-exception.filter.js +48 -0
  57. package/dist/filters/http-exception.filter.js.map +1 -0
  58. package/dist/guards/auth.guard.d.ts +12 -0
  59. package/dist/guards/auth.guard.js +63 -0
  60. package/dist/guards/auth.guard.js.map +1 -0
  61. package/dist/guards/interfaces/endpoint-permission.interface.d.ts +24 -0
  62. package/dist/guards/interfaces/endpoint-permission.interface.js +3 -0
  63. package/dist/guards/interfaces/endpoint-permission.interface.js.map +1 -0
  64. package/dist/guards/interfaces/permission-provider.interface.d.ts +5 -0
  65. package/dist/guards/interfaces/permission-provider.interface.js +3 -0
  66. package/dist/guards/interfaces/permission-provider.interface.js.map +1 -0
  67. package/dist/guards/interfaces/user.auth.d.ts +22 -0
  68. package/dist/guards/interfaces/user.auth.js +13 -0
  69. package/dist/guards/interfaces/user.auth.js.map +1 -0
  70. package/dist/guards/roles.guard.d.ts +17 -0
  71. package/dist/guards/roles.guard.js +111 -0
  72. package/dist/guards/roles.guard.js.map +1 -0
  73. package/dist/guards/roles.module.d.ts +8 -0
  74. package/dist/guards/roles.module.js +36 -0
  75. package/dist/guards/roles.module.js.map +1 -0
  76. package/dist/index.d.ts +25 -0
  77. package/dist/index.js +42 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/interceptors/logging.interceptor.d.ts +14 -0
  80. package/dist/interceptors/logging.interceptor.js +102 -0
  81. package/dist/interceptors/logging.interceptor.js.map +1 -0
  82. package/dist/interceptors/transform.interceptor.d.ts +12 -0
  83. package/dist/interceptors/transform.interceptor.js +29 -0
  84. package/dist/interceptors/transform.interceptor.js.map +1 -0
  85. package/dist/kafka/interfaces/kafka-config.interface.d.ts +20 -0
  86. package/dist/kafka/interfaces/kafka-config.interface.js +3 -0
  87. package/dist/kafka/interfaces/kafka-config.interface.js.map +1 -0
  88. package/dist/kafka/kafka.module.d.ts +9 -0
  89. package/dist/kafka/kafka.module.js +47 -0
  90. package/dist/kafka/kafka.module.js.map +1 -0
  91. package/dist/kafka/kafka.service.d.ts +24 -0
  92. package/dist/kafka/kafka.service.js +237 -0
  93. package/dist/kafka/kafka.service.js.map +1 -0
  94. package/dist/redis/interfaces/redis-config.interface.d.ts +6 -0
  95. package/dist/redis/interfaces/redis-config.interface.js +3 -0
  96. package/dist/redis/interfaces/redis-config.interface.js.map +1 -0
  97. package/dist/redis/redis.module.d.ts +5 -0
  98. package/dist/redis/redis.module.js +33 -0
  99. package/dist/redis/redis.module.js.map +1 -0
  100. package/dist/redis/redis.service.d.ts +17 -0
  101. package/dist/redis/redis.service.js +78 -0
  102. package/dist/redis/redis.service.js.map +1 -0
  103. package/dist/tsconfig.tsbuildinfo +1 -0
  104. package/package.json +50 -0
@@ -0,0 +1,131 @@
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
+ var GlobalExceptionFilter_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.GlobalExceptionFilter = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const request_context_service_1 = require("../context/request-context.service");
16
+ const database_exception_1 = require("../exceptions/database.exception");
17
+ const api_exception_1 = require("../exceptions/api.exception");
18
+ const business_exception_1 = require("../exceptions/business.exception");
19
+ let GlobalExceptionFilter = GlobalExceptionFilter_1 = class GlobalExceptionFilter {
20
+ constructor(contextService) {
21
+ this.contextService = contextService;
22
+ this.logger = new common_1.Logger(GlobalExceptionFilter_1.name);
23
+ }
24
+ catch(exception, host) {
25
+ const ctx = host.switchToHttp();
26
+ const response = ctx.getResponse();
27
+ const request = ctx.getRequest();
28
+ const correlationId = this.contextService.getCorrelationId();
29
+ const userId = this.contextService.getUserId();
30
+ const context = this.contextService.getContext();
31
+ const { statusCode, errorResponse } = this.buildErrorResponse(exception, request, correlationId);
32
+ this.logError(exception, request, statusCode, correlationId, userId);
33
+ response.status(statusCode).json(errorResponse);
34
+ }
35
+ buildErrorResponse(exception, request, correlationId) {
36
+ let statusCode = common_1.HttpStatus.INTERNAL_SERVER_ERROR;
37
+ let message = 'Internal server error';
38
+ let error = 'Internal Server Error';
39
+ let errorCode;
40
+ let details;
41
+ if (exception instanceof common_1.HttpException) {
42
+ statusCode = exception.getStatus();
43
+ const exceptionResponse = exception.getResponse();
44
+ if (typeof exceptionResponse === 'string') {
45
+ message = exceptionResponse;
46
+ }
47
+ else if (typeof exceptionResponse === 'object') {
48
+ const responseObj = exceptionResponse;
49
+ message = responseObj.message || message;
50
+ error = responseObj.error || error;
51
+ errorCode = responseObj.errorCode;
52
+ details = responseObj.details;
53
+ }
54
+ }
55
+ if (exception instanceof database_exception_1.DatabaseException) {
56
+ errorCode = exception.errorCode;
57
+ error = 'Database Error';
58
+ details = exception.details;
59
+ }
60
+ if (exception instanceof api_exception_1.APIException) {
61
+ errorCode = exception.errorCode;
62
+ error = 'API Error';
63
+ details = exception.details;
64
+ }
65
+ if (exception instanceof business_exception_1.BusinessException) {
66
+ errorCode = exception.errorCode;
67
+ error = 'Business Logic Error';
68
+ details = exception.details;
69
+ }
70
+ if (!(exception instanceof common_1.HttpException)) {
71
+ message = 'An unexpected error occurred';
72
+ errorCode = 'UNHANDLED_EXCEPTION';
73
+ if (process.env.NODE_ENV === 'development' && exception instanceof Error) {
74
+ message = exception.message;
75
+ details = {
76
+ name: exception.name,
77
+ };
78
+ }
79
+ }
80
+ const errorResponse = {
81
+ statusCode,
82
+ message,
83
+ error,
84
+ path: request.originalUrl || request.url,
85
+ method: request.method,
86
+ timestamp: new Date().toISOString(),
87
+ correlationId,
88
+ };
89
+ if (errorCode) {
90
+ errorResponse.errorCode = errorCode;
91
+ }
92
+ if (details) {
93
+ errorResponse.details = details;
94
+ }
95
+ if (process.env.NODE_ENV === 'development' && exception instanceof Error) {
96
+ errorResponse.stack = exception.stack;
97
+ }
98
+ return { statusCode, errorResponse };
99
+ }
100
+ logError(exception, request, statusCode, correlationId, userId) {
101
+ const errorMessage = exception instanceof Error ? exception.message : 'Unknown error';
102
+ const stack = exception instanceof Error ? exception.stack : undefined;
103
+ const logContext = {
104
+ correlationId,
105
+ userId: userId || 'anonymous',
106
+ method: request.method,
107
+ url: request.originalUrl || request.url,
108
+ statusCode,
109
+ ip: request.ip,
110
+ userAgent: request.headers['user-agent'],
111
+ };
112
+ if (statusCode >= 500) {
113
+ this.logger.error(`[${correlationId}] ${request.method} ${request.url} - ${statusCode} - ${errorMessage}`, stack, JSON.stringify(logContext));
114
+ }
115
+ else if (statusCode >= 400) {
116
+ this.logger.warn(`[${correlationId}] ${request.method} ${request.url} - ${statusCode} - ${errorMessage}`, JSON.stringify(logContext));
117
+ }
118
+ if (exception instanceof database_exception_1.DatabaseException) {
119
+ this.logger.error(`[DATABASE ERROR] ${exception.errorCode}: ${errorMessage}`, stack);
120
+ }
121
+ if (exception instanceof api_exception_1.APIException) {
122
+ this.logger.error(`[API ERROR] ${exception.errorCode}: ${errorMessage}`, stack);
123
+ }
124
+ }
125
+ };
126
+ exports.GlobalExceptionFilter = GlobalExceptionFilter;
127
+ exports.GlobalExceptionFilter = GlobalExceptionFilter = GlobalExceptionFilter_1 = __decorate([
128
+ (0, common_1.Catch)(),
129
+ __metadata("design:paramtypes", [request_context_service_1.RequestContextService])
130
+ ], GlobalExceptionFilter);
131
+ //# sourceMappingURL=global-exception.filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-exception.filter.js","sourceRoot":"","sources":["../../src/filters/global-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAOwB;AAExB,gFAA2E;AAC3E,yEAAqE;AACrE,+DAAyD;AACzD,yEAAmE;AAgB5D,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAG9B,YAA6B,cAAqC;QAArC,mBAAc,GAAd,cAAc,CAAuB;QAFjD,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;IAEI,CAAC;IAEtE,KAAK,CAAC,SAAkB,EAAE,IAAmB;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAG1C,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC;QAC7D,MAA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U,MAAM,YAAY,EAAE,EACvF,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAC7B,CAAC;QACN,CAAC;QAGD,IAAI,SAAS,YAAY,sCAAiB,EAAE,CAAC;YACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CACb,oBAAoB,SAAS,CAAC,SAAS,KAAK,YAAY,EAAE,EAC1D,KAAK,CACR,CAAC;QACN,CAAC;QAED,IAAI,SAAS,YAAY,4BAAY,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CACb,eAAe,SAAS,CAAC,SAAS,KAAK,YAAY,EAAE,EACrD,KAAK,CACR,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AA1KY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,cAAK,GAAE;qCAIyC,+CAAqB;GAHzD,qBAAqB,CA0KjC"}
@@ -0,0 +1,8 @@
1
+ import { ExceptionFilter, ArgumentsHost, HttpException } from '@nestjs/common';
2
+ import { RequestContextService } from '../context/request-context.service';
3
+ export declare class HttpExceptionFilter implements ExceptionFilter {
4
+ private readonly contextService;
5
+ private readonly logger;
6
+ constructor(contextService: RequestContextService);
7
+ catch(exception: HttpException, host: ArgumentsHost): void;
8
+ }
@@ -0,0 +1,48 @@
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
+ var HttpExceptionFilter_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.HttpExceptionFilter = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const request_context_service_1 = require("../context/request-context.service");
16
+ let HttpExceptionFilter = HttpExceptionFilter_1 = class HttpExceptionFilter {
17
+ constructor(contextService) {
18
+ this.contextService = contextService;
19
+ this.logger = new common_1.Logger(HttpExceptionFilter_1.name);
20
+ }
21
+ catch(exception, host) {
22
+ const ctx = host.switchToHttp();
23
+ const response = ctx.getResponse();
24
+ const request = ctx.getRequest();
25
+ const status = exception.getStatus();
26
+ const correlationId = this.contextService.getCorrelationId();
27
+ const exceptionResponse = exception.getResponse();
28
+ const message = typeof exceptionResponse === 'string'
29
+ ? exceptionResponse
30
+ : exceptionResponse.message;
31
+ const errorResponse = {
32
+ statusCode: status,
33
+ timestamp: new Date().toISOString(),
34
+ path: request.url,
35
+ method: request.method,
36
+ message,
37
+ correlationId,
38
+ };
39
+ this.logger.error(`[${correlationId}] ${request.method} ${request.url} - ${status}`, exception.stack);
40
+ response.status(status).json(errorResponse);
41
+ }
42
+ };
43
+ exports.HttpExceptionFilter = HttpExceptionFilter;
44
+ exports.HttpExceptionFilter = HttpExceptionFilter = HttpExceptionFilter_1 = __decorate([
45
+ (0, common_1.Catch)(common_1.HttpException),
46
+ __metadata("design:paramtypes", [request_context_service_1.RequestContextService])
47
+ ], HttpExceptionFilter);
48
+ //# sourceMappingURL=http-exception.filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-exception.filter.js","sourceRoot":"","sources":["../../src/filters/http-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAOwB;AAExB,gFAA2E;AAIpE,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAG5B,YAA6B,cAAqC;QAArC,mBAAc,GAAd,cAAc,CAAuB;QAFjD,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;IAEM,CAAC;IAEtE,KAAK,CAAC,SAAwB,EAAE,IAAmB;QAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAY,CAAC;QAC7C,MAAM,OAAO,GAAG,GAAG,CAAC,UAAU,EAAW,CAAC;QAC1C,MAAM,MAAM,GAAG,SAAS,CAAC,SAAS,EAAE,CAAC;QACrC,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC;QAE7D,MAAM,iBAAiB,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QAClD,MAAM,OAAO,GACT,OAAO,iBAAiB,KAAK,QAAQ;YACjC,CAAC,CAAC,iBAAiB;YACnB,CAAC,CAAE,iBAAyB,CAAC,OAAO,CAAC;QAE7C,MAAM,aAAa,GAAG;YAClB,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,IAAI,EAAE,OAAO,CAAC,GAAG;YACjB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,OAAO;YACP,aAAa;SAChB,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CACb,IAAI,aAAa,KAAK,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,MAAM,MAAM,EAAE,EACjE,SAAS,CAAC,KAAK,CAClB,CAAC;QAEF,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAChD,CAAC;CACJ,CAAA;AAlCY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,cAAK,EAAC,sBAAa,CAAC;qCAI4B,+CAAqB;GAHzD,mBAAmB,CAkC/B"}
@@ -0,0 +1,12 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { Reflector } from '@nestjs/core';
3
+ import { RequestContextService } from '../context/request-context.service';
4
+ export declare const IS_PUBLIC_KEY = "isPublic";
5
+ export declare class AuthGuard implements CanActivate {
6
+ private reflector;
7
+ private contextService;
8
+ constructor(reflector: Reflector, contextService: RequestContextService);
9
+ canActivate(context: ExecutionContext): Promise<boolean>;
10
+ private extractTokenFromHeader;
11
+ private verifyToken;
12
+ }
@@ -0,0 +1,63 @@
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.AuthGuard = exports.IS_PUBLIC_KEY = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const core_1 = require("@nestjs/core");
15
+ const request_context_service_1 = require("../context/request-context.service");
16
+ exports.IS_PUBLIC_KEY = 'isPublic';
17
+ let AuthGuard = class AuthGuard {
18
+ constructor(reflector, contextService) {
19
+ this.reflector = reflector;
20
+ this.contextService = contextService;
21
+ }
22
+ async canActivate(context) {
23
+ const isPublic = this.reflector.getAllAndOverride(exports.IS_PUBLIC_KEY, [
24
+ context.getHandler(),
25
+ context.getClass(),
26
+ ]);
27
+ if (isPublic) {
28
+ return true;
29
+ }
30
+ const request = context.switchToHttp().getRequest();
31
+ const token = this.extractTokenFromHeader(request);
32
+ if (!token) {
33
+ throw new common_1.UnauthorizedException('No token provided');
34
+ }
35
+ try {
36
+ const user = await this.verifyToken(token);
37
+ this.contextService.setContext({
38
+ userId: user.id,
39
+ userEmail: user.email,
40
+ roles: user.roles,
41
+ });
42
+ request.user = user;
43
+ return true;
44
+ }
45
+ catch {
46
+ throw new common_1.UnauthorizedException('Invalid token');
47
+ }
48
+ }
49
+ extractTokenFromHeader(request) {
50
+ const [type, token] = request.headers.authorization?.split(' ') ?? [];
51
+ return type === 'Bearer' ? token : undefined;
52
+ }
53
+ async verifyToken(token) {
54
+ return { id: 1, email: 'user@example.com', roles: ['user'] };
55
+ }
56
+ };
57
+ exports.AuthGuard = AuthGuard;
58
+ exports.AuthGuard = AuthGuard = __decorate([
59
+ (0, common_1.Injectable)(),
60
+ __metadata("design:paramtypes", [core_1.Reflector,
61
+ request_context_service_1.RequestContextService])
62
+ ], AuthGuard);
63
+ //# sourceMappingURL=auth.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.guard.js","sourceRoot":"","sources":["../../src/guards/auth.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAKwB;AACxB,uCAAyC;AACzC,gFAA2E;AAE9D,QAAA,aAAa,GAAG,UAAU,CAAC;AAGjC,IAAM,SAAS,GAAf,MAAM,SAAS;IAClB,YACY,SAAoB,EACpB,cAAqC;QADrC,cAAS,GAAT,SAAS,CAAW;QACpB,mBAAc,GAAd,cAAc,CAAuB;IAC9C,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAU,qBAAa,EAAE;YACtE,OAAO,CAAC,UAAU,EAAE;YACpB,OAAO,CAAC,QAAQ,EAAE;SACrB,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YACX,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,CAAC,KAAK,EAAE,CAAC;YACT,MAAM,IAAI,8BAAqB,CAAC,mBAAmB,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,CAAC;YAGD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAG3C,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;gBAC3B,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,SAAS,EAAE,IAAI,CAAC,KAAK;gBACrB,KAAK,EAAE,IAAI,CAAC,KAAK;aACpB,CAAC,CAAC;YAEH,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;YACpB,OAAO,IAAI,CAAC;QAChB,CAAC;QAAC,MAAM,CAAC;YACL,MAAM,IAAI,8BAAqB,CAAC,eAAe,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IAEO,sBAAsB,CAAC,OAAY;QACvC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IACjD,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,KAAa;QAGnC,OAAO,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;IACjE,CAAC;CACJ,CAAA;AApDY,8BAAS;oBAAT,SAAS;IADrB,IAAA,mBAAU,GAAE;qCAGc,gBAAS;QACJ,+CAAqB;GAHxC,SAAS,CAoDrB"}
@@ -0,0 +1,24 @@
1
+ export interface EndpointPermission {
2
+ id: number;
3
+ method: string;
4
+ path: string;
5
+ allowedRoleGroups?: {
6
+ id: number | string;
7
+ }[];
8
+ allowedRoles?: {
9
+ id: number | string;
10
+ }[];
11
+ requiredPrivileges?: {
12
+ id: number | string;
13
+ }[];
14
+ }
15
+ export interface AuthUser {
16
+ id: number | string;
17
+ email?: string;
18
+ role: {
19
+ id: number | string;
20
+ name: string;
21
+ };
22
+ roleGroupIds?: (number | string)[];
23
+ permissions?: string[];
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=endpoint-permission.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-permission.interface.js","sourceRoot":"","sources":["../../../src/guards/interfaces/endpoint-permission.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { EndpointPermission } from "./endpoint-permission.interface";
2
+ export interface PermissionProvider {
3
+ findEndpointPermission(method: string, path: string): Promise<EndpointPermission | null>;
4
+ getUserPermissions(roleId: number | string): Promise<string[]>;
5
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=permission-provider.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-provider.interface.js","sourceRoot":"","sources":["../../../src/guards/interfaces/permission-provider.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ export declare enum UserType {
2
+ EMPLOYER = "employer",
3
+ APPLICANT = "applicant",
4
+ ADMIN = "admin"
5
+ }
6
+ export declare class AuthUser {
7
+ id: number;
8
+ email: string;
9
+ role: {
10
+ id: string;
11
+ name: string;
12
+ };
13
+ roleGroupIds: string[];
14
+ userType: UserType;
15
+ }
16
+ declare global {
17
+ namespace Express {
18
+ interface Request {
19
+ user?: AuthUser;
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthUser = exports.UserType = void 0;
4
+ var UserType;
5
+ (function (UserType) {
6
+ UserType["EMPLOYER"] = "employer";
7
+ UserType["APPLICANT"] = "applicant";
8
+ UserType["ADMIN"] = "admin";
9
+ })(UserType || (exports.UserType = UserType = {}));
10
+ class AuthUser {
11
+ }
12
+ exports.AuthUser = AuthUser;
13
+ //# sourceMappingURL=user.auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.auth.js","sourceRoot":"","sources":["../../../src/guards/interfaces/user.auth.ts"],"names":[],"mappings":";;;AAAA,IAAY,QAIX;AAJD,WAAY,QAAQ;IAChB,iCAAmB,CAAA;IACnB,mCAAqB,CAAA;IACrB,2BAAa,CAAA;AACjB,CAAC,EAJW,QAAQ,wBAAR,QAAQ,QAInB;AAED,MAAa,QAAQ;CASpB;AATD,4BASC"}
@@ -0,0 +1,17 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { RedisService } from '../redis/redis.service';
3
+ import { RequestContextService } from '../context/request-context.service';
4
+ import { PermissionProvider } from './interfaces/permission-provider.interface';
5
+ export declare class RolesGuard implements CanActivate {
6
+ private readonly permissionProvider;
7
+ private readonly redisService;
8
+ private readonly contextService;
9
+ constructor(permissionProvider: PermissionProvider, redisService: RedisService, contextService: RequestContextService);
10
+ canActivate(context: ExecutionContext): Promise<boolean>;
11
+ private resolveEndpointPermission;
12
+ private checkRoleGroupAccess;
13
+ private checkRoleAccess;
14
+ private checkPrivilegeAccess;
15
+ private idsEqual;
16
+ private normalizePath;
17
+ }
@@ -0,0 +1,111 @@
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
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RolesGuard = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const redis_service_1 = require("../redis/redis.service");
18
+ const request_context_service_1 = require("../context/request-context.service");
19
+ let RolesGuard = class RolesGuard {
20
+ constructor(permissionProvider, redisService, contextService) {
21
+ this.permissionProvider = permissionProvider;
22
+ this.redisService = redisService;
23
+ this.contextService = contextService;
24
+ }
25
+ async canActivate(context) {
26
+ const request = context.switchToHttp().getRequest();
27
+ const user = request.user;
28
+ const method = request.method;
29
+ const actualPath = this.normalizePath(`${request.baseUrl}${request.route?.path}`);
30
+ const endpointPerm = await this.resolveEndpointPermission(method, actualPath);
31
+ if (!endpointPerm) {
32
+ return true;
33
+ }
34
+ if (!user) {
35
+ throw new common_1.ForbiddenException('Access denied: insufficient access rights.');
36
+ }
37
+ this.contextService.setContext({
38
+ userId: String(user.id),
39
+ userEmail: user.email,
40
+ userRole: user.role?.name,
41
+ roles: user.roleGroupIds?.map(String),
42
+ });
43
+ if (endpointPerm.allowedRoleGroups?.length) {
44
+ const hasRoleGroupAccess = this.checkRoleGroupAccess(user, endpointPerm.allowedRoleGroups);
45
+ if (!hasRoleGroupAccess) {
46
+ throw new common_1.ForbiddenException('Access denied: insufficient access rights.');
47
+ }
48
+ }
49
+ if (endpointPerm.allowedRoles?.length) {
50
+ const hasRoleAccess = this.checkRoleAccess(user, endpointPerm.allowedRoles);
51
+ if (!hasRoleAccess) {
52
+ throw new common_1.ForbiddenException('Access denied: insufficient access rights.');
53
+ }
54
+ }
55
+ if (endpointPerm.requiredPrivileges?.length) {
56
+ const hasPrivilege = await this.checkPrivilegeAccess(user, endpointPerm.requiredPrivileges);
57
+ if (!hasPrivilege) {
58
+ throw new common_1.ForbiddenException('Access denied: insufficient access rights.');
59
+ }
60
+ }
61
+ return true;
62
+ }
63
+ async resolveEndpointPermission(method, path) {
64
+ const cacheKey = `endpoint_perm:${method}:${path}`;
65
+ let endpointPerm = await this.redisService.get(cacheKey);
66
+ if (!endpointPerm) {
67
+ endpointPerm = await this.permissionProvider.findEndpointPermission(method, path);
68
+ if (endpointPerm) {
69
+ await this.redisService.set(cacheKey, endpointPerm, 300);
70
+ }
71
+ }
72
+ return endpointPerm;
73
+ }
74
+ checkRoleGroupAccess(user, allowedRoleGroups) {
75
+ if (!user.roleGroupIds || user.roleGroupIds.length === 0) {
76
+ return false;
77
+ }
78
+ return allowedRoleGroups.some((rg) => user.roleGroupIds.some((id) => this.idsEqual(rg.id, id)));
79
+ }
80
+ checkRoleAccess(user, allowedRoles) {
81
+ return allowedRoles.some((r) => this.idsEqual(r.id, user.role.id));
82
+ }
83
+ async checkPrivilegeAccess(user, requiredPrivileges) {
84
+ const roleId = user.role.id;
85
+ const permCacheKey = `role_permissions:${roleId}`;
86
+ let permissionIds = await this.redisService.get(permCacheKey);
87
+ if (!permissionIds) {
88
+ permissionIds = await this.permissionProvider.getUserPermissions(roleId);
89
+ await this.redisService.set(permCacheKey, permissionIds, 600);
90
+ }
91
+ const userPermissions = new Set(permissionIds);
92
+ return requiredPrivileges.some((p) => userPermissions.has(String(p.id)));
93
+ }
94
+ idsEqual(id1, id2) {
95
+ return String(id1) === String(id2);
96
+ }
97
+ normalizePath(path) {
98
+ return path
99
+ .replace(/\/+/g, '/')
100
+ .replace(/\/$/, '')
101
+ .toLowerCase();
102
+ }
103
+ };
104
+ exports.RolesGuard = RolesGuard;
105
+ exports.RolesGuard = RolesGuard = __decorate([
106
+ (0, common_1.Injectable)(),
107
+ __param(0, (0, common_1.Inject)('PERMISSION_PROVIDER')),
108
+ __metadata("design:paramtypes", [Object, redis_service_1.RedisService,
109
+ request_context_service_1.RequestContextService])
110
+ ], RolesGuard);
111
+ //# sourceMappingURL=roles.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.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AAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACjC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CACpC,CAAC;IACN,CAAC;IAOO,QAAQ,CAAC,GAAoB,EAAE,GAAoB;QACvD,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IAKO,aAAa,CAAC,IAAY;QAC9B,OAAO,IAAI;aACN,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;aAClB,WAAW,EAAE,CAAC;IACvB,CAAC;CACJ,CAAA;AA1LY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;IAGJ,WAAA,IAAA,eAAM,EAAC,qBAAqB,CAAC,CAAA;6CAEC,4BAAY;QACV,+CAAqB;GALjD,UAAU,CA0LtB"}
@@ -0,0 +1,8 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { PermissionProvider } from './interfaces/permission-provider.interface';
3
+ export interface RolesGuardModuleOptions {
4
+ permissionProvider: new (...args: any[]) => PermissionProvider;
5
+ }
6
+ export declare class RolesGuardModule {
7
+ static forRoot(options: RolesGuardModuleOptions): DynamicModule;
8
+ }
@@ -0,0 +1,36 @@
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 RolesGuardModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.RolesGuardModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const roles_guard_1 = require("./roles.guard");
13
+ const redis_module_1 = require("../redis/redis.module");
14
+ const request_context_module_1 = require("../context/request-context.module");
15
+ let RolesGuardModule = RolesGuardModule_1 = class RolesGuardModule {
16
+ static forRoot(options) {
17
+ return {
18
+ module: RolesGuardModule_1,
19
+ imports: [redis_module_1.RedisModule, request_context_module_1.RequestContextModule],
20
+ providers: [
21
+ {
22
+ provide: 'PERMISSION_PROVIDER',
23
+ useClass: options.permissionProvider,
24
+ },
25
+ roles_guard_1.RolesGuard,
26
+ ],
27
+ exports: [roles_guard_1.RolesGuard],
28
+ };
29
+ }
30
+ };
31
+ exports.RolesGuardModule = RolesGuardModule;
32
+ exports.RolesGuardModule = RolesGuardModule = RolesGuardModule_1 = __decorate([
33
+ (0, common_1.Global)(),
34
+ (0, common_1.Module)({})
35
+ ], RolesGuardModule);
36
+ //# sourceMappingURL=roles.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roles.module.js","sourceRoot":"","sources":["../../src/guards/roles.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+D;AAC/D,+CAA2C;AAC3C,wDAAoD;AACpD,8EAAyE;AASlE,IAAM,gBAAgB,wBAAtB,MAAM,gBAAgB;IACzB,MAAM,CAAC,OAAO,CAAC,OAAgC;QAC3C,OAAO;YACH,MAAM,EAAE,kBAAgB;YACxB,OAAO,EAAE,CAAC,0BAAW,EAAE,6CAAoB,CAAC;YAC5C,SAAS,EAAE;gBACP;oBACI,OAAO,EAAE,qBAAqB;oBAC9B,QAAQ,EAAE,OAAO,CAAC,kBAAkB;iBACvC;gBACD,wBAAU;aACb;YACD,OAAO,EAAE,CAAC,wBAAU,CAAC;SACxB,CAAC;IACN,CAAC;CACJ,CAAA;AAfY,4CAAgB;2BAAhB,gBAAgB;IAF5B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,gBAAgB,CAe5B"}
@@ -0,0 +1,25 @@
1
+ export * from './audit/audit.module';
2
+ export * from './kafka/kafka.module';
3
+ export * from './redis/redis.module';
4
+ export * from './context/request-context.module';
5
+ export * from './audit/audit.service';
6
+ export * from './kafka/kafka.service';
7
+ export * from './redis/redis.service';
8
+ export * from './context/request-context.service';
9
+ export * from './guards/auth.guard';
10
+ export * from './guards/roles.guard';
11
+ export * from './interceptors/logging.interceptor';
12
+ export * from './interceptors/transform.interceptor';
13
+ export * from './filters/http-exception.filter';
14
+ export * from './filters/global-exception.filter';
15
+ export * from './decorators/current-user.decorator';
16
+ export * from './decorators/roles.decorator';
17
+ export * from './dto/base.dto';
18
+ export * from './dto/pagination.dto';
19
+ export * from './dto/api-response.dto';
20
+ export * from './exceptions/business.exception';
21
+ export * from './exceptions/api.exception';
22
+ export * from './exceptions/database.exception';
23
+ export * from './audit/interfaces/audit-log.interface';
24
+ export * from './kafka/interfaces/kafka-config.interface';
25
+ export * from './redis/interfaces/redis-config.interface';
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
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("./audit/audit.module"), exports);
18
+ __exportStar(require("./kafka/kafka.module"), exports);
19
+ __exportStar(require("./redis/redis.module"), exports);
20
+ __exportStar(require("./context/request-context.module"), exports);
21
+ __exportStar(require("./audit/audit.service"), exports);
22
+ __exportStar(require("./kafka/kafka.service"), exports);
23
+ __exportStar(require("./redis/redis.service"), exports);
24
+ __exportStar(require("./context/request-context.service"), exports);
25
+ __exportStar(require("./guards/auth.guard"), exports);
26
+ __exportStar(require("./guards/roles.guard"), exports);
27
+ __exportStar(require("./interceptors/logging.interceptor"), exports);
28
+ __exportStar(require("./interceptors/transform.interceptor"), exports);
29
+ __exportStar(require("./filters/http-exception.filter"), exports);
30
+ __exportStar(require("./filters/global-exception.filter"), exports);
31
+ __exportStar(require("./decorators/current-user.decorator"), exports);
32
+ __exportStar(require("./decorators/roles.decorator"), exports);
33
+ __exportStar(require("./dto/base.dto"), exports);
34
+ __exportStar(require("./dto/pagination.dto"), exports);
35
+ __exportStar(require("./dto/api-response.dto"), exports);
36
+ __exportStar(require("./exceptions/business.exception"), exports);
37
+ __exportStar(require("./exceptions/api.exception"), exports);
38
+ __exportStar(require("./exceptions/database.exception"), exports);
39
+ __exportStar(require("./audit/interfaces/audit-log.interface"), exports);
40
+ __exportStar(require("./kafka/interfaces/kafka-config.interface"), exports);
41
+ __exportStar(require("./redis/interfaces/redis-config.interface"), exports);
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,uDAAqC;AACrC,uDAAqC;AACrC,mEAAiD;AAGjD,wDAAsC;AACtC,wDAAsC;AACtC,wDAAsC;AACtC,oEAAkD;AAGlD,sDAAoC;AACpC,uDAAqC;AAGrC,qEAAmD;AACnD,uEAAqD;AAGrD,kEAAgD;AAChD,oEAAkD;AAGlD,sEAAoD;AACpD,+DAA6C;AAG7C,iDAA+B;AAC/B,uDAAqC;AACrC,yDAAuC;AAGvC,kEAAgD;AAChD,6DAA2C;AAC3C,kEAAgD;AAGhD,yEAAuD;AACvD,4EAA0D;AAC1D,4EAA0D"}