@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,2 @@
1
+ export declare class AuditModule {
2
+ }
@@ -0,0 +1,25 @@
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.AuditModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const kafka_module_1 = require("../kafka/kafka.module");
12
+ const request_context_module_1 = require("../context/request-context.module");
13
+ const audit_service_1 = require("./audit.service");
14
+ let AuditModule = class AuditModule {
15
+ };
16
+ exports.AuditModule = AuditModule;
17
+ exports.AuditModule = AuditModule = __decorate([
18
+ (0, common_1.Global)(),
19
+ (0, common_1.Module)({
20
+ imports: [kafka_module_1.KafkaModule, request_context_module_1.RequestContextModule],
21
+ providers: [audit_service_1.AuditService],
22
+ exports: [audit_service_1.AuditService],
23
+ })
24
+ ], AuditModule);
25
+ //# sourceMappingURL=audit.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.module.js","sourceRoot":"","sources":["../../src/audit/audit.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgD;AAChD,wDAAoD;AACpD,8EAAyE;AACzE,mDAA6C;AAQtC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IANvB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACJ,OAAO,EAAE,CAAC,0BAAW,EAAE,6CAAoB,CAAC;QAC5C,SAAS,EAAE,CAAC,4BAAY,CAAC;QACzB,OAAO,EAAE,CAAC,4BAAY,CAAC;KAC1B,CAAC;GACW,WAAW,CAAG"}
@@ -0,0 +1,16 @@
1
+ import { KafkaService } from '../kafka/kafka.service';
2
+ import { RequestContextService } from "../context/request-context.service";
3
+ export declare class AuditService {
4
+ private readonly kafkaService;
5
+ private readonly requestContextService;
6
+ private readonly logger;
7
+ constructor(kafkaService: KafkaService, requestContextService: RequestContextService);
8
+ log(action: string, entity: string, entityId?: string | number, metadata?: any, before?: Record<string, any>, after?: Record<string, any>): Promise<void>;
9
+ logCreate(entity: string, entityId: string | number, data: Record<string, any>, metadata?: any): Promise<void>;
10
+ logUpdate(entity: string, entityId: string | number, before: Record<string, any>, after: Record<string, any>, metadata?: any): Promise<void>;
11
+ logDelete(entity: string, entityId: string | number, data: Record<string, any>, metadata?: any): Promise<void>;
12
+ logView(entity: string, entityId: string | number, metadata?: any): Promise<void>;
13
+ logAction(action: string, entity: string, entityId?: string | number, data?: Record<string, any>, metadata?: any): Promise<void>;
14
+ logAuth(action: 'login' | 'logout' | 'login.failed' | 'password.reset' | 'password.changed', userId?: string, metadata?: any): Promise<void>;
15
+ logSecurity(action: string, description: string, metadata?: any): Promise<void>;
16
+ }
@@ -0,0 +1,95 @@
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 AuditService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.AuditService = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const kafka_service_1 = require("../kafka/kafka.service");
16
+ const request_context_service_1 = require("../context/request-context.service");
17
+ let AuditService = AuditService_1 = class AuditService {
18
+ constructor(kafkaService, requestContextService) {
19
+ this.kafkaService = kafkaService;
20
+ this.requestContextService = requestContextService;
21
+ this.logger = new common_1.Logger(AuditService_1.name);
22
+ }
23
+ async log(action, entity, entityId, metadata, before, after) {
24
+ try {
25
+ const context = this.requestContextService.getContext();
26
+ const event = {
27
+ userId: context.userId || 'system',
28
+ userRole: context.userRole,
29
+ userType: context.userType,
30
+ action,
31
+ entity,
32
+ entityId: entityId?.toString(),
33
+ before,
34
+ after,
35
+ ip: context.ip,
36
+ userAgent: context.userAgent,
37
+ device: context.device ? {
38
+ type: context.device.type,
39
+ os: context.device.os,
40
+ browser: context.device.browser,
41
+ isMobile: context.device.type === 'mobile',
42
+ } : undefined,
43
+ location: context.location ? {
44
+ country: context.location.country,
45
+ countryCode: context.location.countryCode,
46
+ region: context.location.region,
47
+ city: context.location.city,
48
+ latitude: context.location.latitude,
49
+ longitude: context.location.longitude,
50
+ timezone: context.location.timezone,
51
+ } : undefined,
52
+ correlationId: context.correlationId,
53
+ requestId: context.requestId,
54
+ timestamp: Date.now(),
55
+ metadata,
56
+ };
57
+ await this.kafkaService.sendMessage('audit-events', JSON.stringify(event));
58
+ this.logger.log(`[AUDIT] ${event.action} by ${event.userId} on ${event.entity}${event.entityId ? ` #${event.entityId}` : ''}`);
59
+ }
60
+ catch (error) {
61
+ this.logger.error('Failed to publish audit event:', error);
62
+ }
63
+ }
64
+ async logCreate(entity, entityId, data, metadata) {
65
+ await this.log(`${entity.toLowerCase()}.created`, entity, entityId, metadata, undefined, data);
66
+ }
67
+ async logUpdate(entity, entityId, before, after, metadata) {
68
+ await this.log(`${entity.toLowerCase()}.updated`, entity, entityId, metadata, before, after);
69
+ }
70
+ async logDelete(entity, entityId, data, metadata) {
71
+ await this.log(`${entity.toLowerCase()}.deleted`, entity, entityId, metadata, data, undefined);
72
+ }
73
+ async logView(entity, entityId, metadata) {
74
+ await this.log(`${entity.toLowerCase()}.viewed`, entity, entityId, metadata);
75
+ }
76
+ async logAction(action, entity, entityId, data, metadata) {
77
+ await this.log(action, entity, entityId, metadata, undefined, data);
78
+ }
79
+ async logAuth(action, userId, metadata) {
80
+ await this.log(`auth.${action}`, 'Auth', userId, metadata);
81
+ }
82
+ async logSecurity(action, description, metadata) {
83
+ await this.log(`security.${action}`, 'Security', undefined, {
84
+ ...metadata,
85
+ description,
86
+ });
87
+ }
88
+ };
89
+ exports.AuditService = AuditService;
90
+ exports.AuditService = AuditService = AuditService_1 = __decorate([
91
+ (0, common_1.Injectable)(),
92
+ __metadata("design:paramtypes", [kafka_service_1.KafkaService,
93
+ request_context_service_1.RequestContextService])
94
+ ], AuditService);
95
+ //# sourceMappingURL=audit.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.service.js","sourceRoot":"","sources":["../../src/audit/audit.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,0DAAsD;AAEtD,gFAAyE;AAGlE,IAAM,YAAY,oBAAlB,MAAM,YAAY;IAGrB,YACqB,YAA0B,EAC1B,qBAA4C;QAD5C,iBAAY,GAAZ,YAAY,CAAc;QAC1B,0BAAqB,GAArB,qBAAqB,CAAuB;QAJhD,WAAM,GAAG,IAAI,eAAM,CAAC,cAAY,CAAC,IAAI,CAAC,CAAC;IAKrD,CAAC;IAYJ,KAAK,CAAC,GAAG,CACL,MAAc,EACd,MAAc,EACd,QAA0B,EAC1B,QAAc,EACd,MAA4B,EAC5B,KAA2B;QAE3B,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,CAAC,UAAU,EAAE,CAAC;YAExD,MAAM,KAAK,GAAe;gBAEtB,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,QAAQ;gBAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAG1B,MAAM;gBACN,MAAM;gBACN,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE;gBAG9B,MAAM;gBACN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M,EACN,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,IAAI,CACP,CAAC;IACN,CAAC;IAKD,KAAK,CAAC,OAAO,CACT,MAAmF,EACnF,MAAe,EACf,QAAc;QAEd,MAAM,IAAI,CAAC,GAAG,CACV,QAAQ,MAAM,EAAE,EAChB,MAAM,EACN,MAAM,EACN,QAAQ,CACX,CAAC;IACN,CAAC;IAKD,KAAK,CAAC,WAAW,CACb,MAAc,EACd,WAAmB,EACnB,QAAc;QAEd,MAAM,IAAI,CAAC,GAAG,CACV,YAAY,MAAM,EAAE,EACpB,UAAU,EACV,SAAS,EACT;YACI,GAAG,QAAQ;YACX,WAAW;SACd,CACJ,CAAC;IACN,CAAC;CACJ,CAAA;AA7NY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,mBAAU,GAAE;qCAK0B,4BAAY;QACH,+CAAqB;GALxD,YAAY,CA6NxB"}
@@ -0,0 +1,36 @@
1
+ export interface AuditEvent {
2
+ userId: string;
3
+ tenantId?: string;
4
+ userRole?: string;
5
+ userType?: string;
6
+ action: string;
7
+ entity: string;
8
+ entityId?: string;
9
+ before?: Record<string, any>;
10
+ after?: Record<string, any>;
11
+ ip?: string;
12
+ userAgent?: string;
13
+ device?: {
14
+ type?: string;
15
+ os?: string;
16
+ osVersion?: string;
17
+ browser?: string;
18
+ browserVersion?: string;
19
+ brand?: string;
20
+ model?: string;
21
+ isMobile?: boolean;
22
+ };
23
+ location?: {
24
+ country?: string;
25
+ countryCode?: string;
26
+ region?: string;
27
+ city?: string;
28
+ latitude?: number;
29
+ longitude?: number;
30
+ timezone?: string;
31
+ };
32
+ correlationId?: string;
33
+ requestId?: string;
34
+ timestamp: number;
35
+ metadata?: any;
36
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=audit-log.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-log.interface.js","sourceRoot":"","sources":["../../../src/audit/interfaces/audit-log.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { RedisService } from "../redis/redis.service";
2
+ export interface GeoLocation {
3
+ country?: string;
4
+ region?: string;
5
+ city?: string;
6
+ lat?: number;
7
+ lon?: number;
8
+ }
9
+ export declare class GeolocationService {
10
+ private readonly redisService;
11
+ private readonly logger;
12
+ private readonly cacheKeyPrefix;
13
+ constructor(redisService: RedisService);
14
+ getLocation(ip: string): Promise<GeoLocation | null>;
15
+ clearCache(): Promise<void>;
16
+ getStats(): Promise<{
17
+ note: string;
18
+ }>;
19
+ }
@@ -0,0 +1,87 @@
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 GeolocationService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.GeolocationService = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const node_fetch_1 = require("node-fetch");
16
+ const redis_service_1 = require("../redis/redis.service");
17
+ let GeolocationService = GeolocationService_1 = class GeolocationService {
18
+ constructor(redisService) {
19
+ this.redisService = redisService;
20
+ this.logger = new common_1.Logger(GeolocationService_1.name);
21
+ this.cacheKeyPrefix = 'geo:';
22
+ }
23
+ async getLocation(ip) {
24
+ if (!ip ||
25
+ ip === 'unknown' ||
26
+ ip === '127.0.0.1' ||
27
+ ip === '::1' ||
28
+ ip.startsWith('192.168.') ||
29
+ ip.startsWith('10.') ||
30
+ ip.startsWith('172.')) {
31
+ return null;
32
+ }
33
+ const cacheKey = `${this.cacheKeyPrefix}${ip}`;
34
+ const cached = await this.redisService.get(cacheKey);
35
+ if (cached !== undefined) {
36
+ if (cached === null) {
37
+ this.logger.debug(`Geo cache HIT (null) for IP: ${ip}`);
38
+ }
39
+ else {
40
+ this.logger.debug(`Geo cache HIT for IP: ${ip}`);
41
+ }
42
+ return cached;
43
+ }
44
+ this.logger.debug(`Geo cache MISS for IP: ${ip} – fetching from ip-api.com`);
45
+ try {
46
+ const controller = new AbortController();
47
+ const timeoutId = setTimeout(() => controller.abort(), 5000);
48
+ const response = await (0, node_fetch_1.default)(`http://ip-api.com/json/${ip}?fields=status,message,country,regionName,city,lat,lon`, { signal: controller.signal });
49
+ clearTimeout(timeoutId);
50
+ if (!response.ok) {
51
+ throw new Error(`HTTP ${response.status}`);
52
+ }
53
+ const data = await response.json();
54
+ if (data.status !== 'success') {
55
+ this.logger.warn(`ip-api.com failed for ${ip}: ${data.message || 'unknown'}`);
56
+ await this.redisService.set(cacheKey, null, 3600);
57
+ return null;
58
+ }
59
+ const location = {
60
+ country: data.country,
61
+ region: data.regionName,
62
+ city: data.city,
63
+ lat: data.lat,
64
+ lon: data.lon,
65
+ };
66
+ await this.redisService.set(cacheKey, location, 86400);
67
+ return location;
68
+ }
69
+ catch (error) {
70
+ this.logger.warn(`Geolocation lookup failed for ${ip}: ${error.message || error}`);
71
+ await this.redisService.set(cacheKey, null, 600);
72
+ return null;
73
+ }
74
+ }
75
+ async clearCache() {
76
+ this.logger.log('Cache clear requested – not implemented for in-memory store');
77
+ }
78
+ async getStats() {
79
+ return { note: 'Stats not available with default in-memory store' };
80
+ }
81
+ };
82
+ exports.GeolocationService = GeolocationService;
83
+ exports.GeolocationService = GeolocationService = GeolocationService_1 = __decorate([
84
+ (0, common_1.Injectable)(),
85
+ __metadata("design:paramtypes", [redis_service_1.RedisService])
86
+ ], GeolocationService);
87
+ //# sourceMappingURL=geolocation.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geolocation.service.js","sourceRoot":"","sources":["../../src/context/geolocation.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAA4D;AAC5D,2CAA+B;AAC/B,0DAAoD;AAW7C,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAI3B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;QAHtC,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7C,mBAAc,GAAG,MAAM,CAAC;IAEiB,CAAC;IAE3D,KAAK,CAAC,WAAW,CAAC,EAAU;QAExB,IACI,CAAC,EAAE;YACH,EAAE,KAAK,SAAS;YAChB,EAAE,KAAK,WAAW;YAClB,EAAE,KAAK,KAAK;YACZ,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC;YACzB,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC;YACpB,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EACvB,CAAC;YACC,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,cAAc,GAAG,EAAE,EAAE,CAAC;QAG/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAqB,QAAQ,CAAC,CAAC;QACzE,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBAClB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gCAAgC,EAAE,EAAE,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACJ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,EAAE,6B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AAC;YAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,EAAE,KAAK,KAAK,CAAC,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC;YAGnF,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YACjD,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IAGD,KAAK,CAAC,UAAU;QAGZ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,6DAA6D,CAAC,CAAC;IACnF,CAAC;IAED,KAAK,CAAC,QAAQ;QAGV,OAAO,EAAE,IAAI,EAAE,kDAAkD,EAAE,CAAC;IACxE,CAAC;CACJ,CAAA;AA3FY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAKkC,4BAAY;GAJ9C,kBAAkB,CA2F9B"}
@@ -0,0 +1,29 @@
1
+ export interface RequestContext {
2
+ correlationId: string;
3
+ requestId?: string;
4
+ userId?: string;
5
+ userEmail?: string;
6
+ userRole?: string;
7
+ userType?: string;
8
+ roles?: string[];
9
+ ip: string;
10
+ userAgent: string;
11
+ device?: {
12
+ type: string;
13
+ os?: string;
14
+ browser?: string;
15
+ version?: string;
16
+ };
17
+ location?: {
18
+ country?: string;
19
+ countryCode?: string;
20
+ region?: string;
21
+ city?: string;
22
+ latitude?: number;
23
+ longitude?: number;
24
+ timezone?: string;
25
+ };
26
+ path?: string;
27
+ method?: string;
28
+ timestamp?: Date;
29
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=request-context.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.interface.js","sourceRoot":"","sources":["../../../src/context/interfaces/request-context.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { NestMiddleware } from '@nestjs/common';
2
+ import { Request, Response, NextFunction } from 'express';
3
+ import { RequestContextService } from './request-context.service';
4
+ import { GeolocationService } from './geolocation.service';
5
+ export declare class RequestContextMiddleware implements NestMiddleware {
6
+ private readonly contextService;
7
+ private readonly geolocationService;
8
+ private readonly logger;
9
+ constructor(contextService: RequestContextService, geolocationService: GeolocationService);
10
+ use(req: Request, res: Response, next: NextFunction): Promise<void>;
11
+ }
@@ -0,0 +1,88 @@
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 RequestContextMiddleware_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.RequestContextMiddleware = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const uuid_1 = require("uuid");
16
+ const request_context_service_1 = require("./request-context.service");
17
+ const geolocation_service_1 = require("./geolocation.service");
18
+ let RequestContextMiddleware = RequestContextMiddleware_1 = class RequestContextMiddleware {
19
+ constructor(contextService, geolocationService) {
20
+ this.contextService = contextService;
21
+ this.geolocationService = geolocationService;
22
+ this.logger = new common_1.Logger(RequestContextMiddleware_1.name);
23
+ }
24
+ async use(req, res, next) {
25
+ const namespace = request_context_service_1.RequestContextService.getNamespace();
26
+ namespace.run(async () => {
27
+ try {
28
+ const correlationId = req.headers['x-correlation-id'] ||
29
+ req.headers['x-request-id'] ||
30
+ (0, uuid_1.v4)();
31
+ this.contextService.set('correlationId', correlationId);
32
+ this.contextService.set('requestId', (0, uuid_1.v4)());
33
+ res.setHeader('X-Correlation-Id', correlationId);
34
+ const ip = req.headers['x-forwarded-for']?.split(',')[0].trim() ||
35
+ req.headers['x-real-ip'] ||
36
+ req.ip ||
37
+ req.socket.remoteAddress ||
38
+ 'unknown';
39
+ this.contextService.set('ip', ip);
40
+ const userAgent = req.headers['user-agent'] || 'unknown';
41
+ this.contextService.set('userAgent', userAgent);
42
+ this.contextService.parseDevice(userAgent);
43
+ this.contextService.set('path', req.path);
44
+ this.contextService.set('method', req.method);
45
+ this.contextService.set('timestamp', new Date());
46
+ if (req.user) {
47
+ const user = req.user;
48
+ this.contextService.set('userId', user.id?.toString() || user.sub?.toString());
49
+ this.contextService.set('userEmail', user.email);
50
+ this.contextService.set('userRole', user.role?.name || user.role);
51
+ this.contextService.set('userType', user.userType || 'platform');
52
+ if (user.roles && Array.isArray(user.roles)) {
53
+ this.contextService.set('roles', user.roles);
54
+ }
55
+ }
56
+ else {
57
+ this.contextService.set('userId', 'anonymous');
58
+ this.contextService.set('userRole', 'guest');
59
+ this.contextService.set('userType', 'platform');
60
+ }
61
+ if (ip && !['127.0.0.1', '::1', 'unknown', 'localhost'].includes(ip)) {
62
+ this.geolocationService
63
+ .getLocation(ip)
64
+ .then((location) => {
65
+ if (location) {
66
+ this.contextService.set('location', location);
67
+ }
68
+ })
69
+ .catch((err) => {
70
+ this.logger.warn(`Geolocation lookup failed for ${ip}:`, err.message);
71
+ });
72
+ }
73
+ next();
74
+ }
75
+ catch (error) {
76
+ this.logger.error('Error in RequestContextMiddleware:', error);
77
+ next();
78
+ }
79
+ });
80
+ }
81
+ };
82
+ exports.RequestContextMiddleware = RequestContextMiddleware;
83
+ exports.RequestContextMiddleware = RequestContextMiddleware = RequestContextMiddleware_1 = __decorate([
84
+ (0, common_1.Injectable)(),
85
+ __metadata("design:paramtypes", [request_context_service_1.RequestContextService,
86
+ geolocation_service_1.GeolocationService])
87
+ ], RequestContextMiddleware);
88
+ //# sourceMappingURL=request-context.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.middleware.js","sourceRoot":"","sources":["../../src/context/request-context.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoE;AAEpE,+BAAoC;AACpC,uEAAkE;AAClE,+DAA2D;AAGpD,IAAM,wBAAwB,gCAA9B,MAAM,wBAAwB;IAGjC,YACqB,cAAqC,EACrC,kBAAsC;QADtC,mBAAc,GAAd,cAAc,CAAuB;QACrC,uBAAkB,GAAlB,kBAAkB,CAAoB;QAJ1C,WAAM,GAAG,IAAI,eAAM,CAAC,0BAAwB,CAAC,IAAI,CAAC,CAAC;IAKjE,CAAC;IAEJ,KAAK,CAAC,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB;QACrD,MAAM,SAAS,GAAG,+CAAqB,CAAC,YAAY,EAAE,CAAC;QAEvD,SAAS,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE;YACrB,IAAI,CAAC;gBAED,MAAM,aAAa,GACd,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAY;oBAC1C,GAAG,CAAC,OAAO,CAAC,cAAc,CAAY;oBACvC,IAAA,SAAM,GAAE,CAAC;gBAEb,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;gBACxD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,IAAA,SAAM,GAAE,CAAC,CAAC;gBAG/C,GAAG,CAAC,SAAS,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAC;gBAGjD,MAAM,EAAE,GACH,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAY,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;oBAC/D,GAAG,CAAC,OAAO,CAAC,WAAW,CAAY;oBACpC,GAAG,CAAC,EAAE;oBACN,GAAG,CAAC,MAAM,CAAC,aAAa;oBACxB,SAAS,CAAC;gBAEd,IAAI,CAAC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umer, NestModule } from '@nestjs/common';
2
+ export declare class RequestContextModule implements NestModule {
3
+ configure(consumer: MiddlewareConsumer): void;
4
+ }
@@ -0,0 +1,27 @@
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.RequestContextModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const request_context_service_1 = require("./request-context.service");
12
+ const request_context_middleware_1 = require("./request-context.middleware");
13
+ const geolocation_service_1 = require("./geolocation.service");
14
+ let RequestContextModule = class RequestContextModule {
15
+ configure(consumer) {
16
+ consumer.apply(request_context_middleware_1.RequestContextMiddleware).forRoutes('*');
17
+ }
18
+ };
19
+ exports.RequestContextModule = RequestContextModule;
20
+ exports.RequestContextModule = RequestContextModule = __decorate([
21
+ (0, common_1.Global)(),
22
+ (0, common_1.Module)({
23
+ providers: [request_context_service_1.RequestContextService, geolocation_service_1.GeolocationService],
24
+ exports: [request_context_service_1.RequestContextService, geolocation_service_1.GeolocationService],
25
+ })
26
+ ], RequestContextModule);
27
+ //# sourceMappingURL=request-context.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-context.module.js","sourceRoot":"","sources":["../../src/context/request-context.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAgF;AAChF,uEAAkE;AAClE,6EAAwE;AACxE,+DAA2D;AAOpD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAC7B,SAAS,CAAC,QAA4B;QAClC,QAAQ,CAAC,KAAK,CAAC,qDAAwB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC5D,CAAC;CACJ,CAAA;AAJY,oDAAoB;+BAApB,oBAAoB;IALhC,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC;QACJ,SAAS,EAAE,CAAC,+CAAqB,EAAE,wCAAkB,CAAC;QACtD,OAAO,EAAE,CAAC,+CAAqB,EAAE,wCAAkB,CAAC;KACvD,CAAC;GACW,oBAAoB,CAIhC"}
@@ -0,0 +1,24 @@
1
+ import { RequestContext } from './interfaces/request-context.interface';
2
+ export declare class RequestContextService {
3
+ private static namespace;
4
+ static getNamespace(): any;
5
+ set<K extends keyof RequestContext>(key: K, value: RequestContext[K]): void;
6
+ get<K extends keyof RequestContext>(key: K): RequestContext[K] | undefined;
7
+ setContext(context: Partial<RequestContext>): void;
8
+ getContext(): RequestContext;
9
+ getCorrelationId(): string | undefined;
10
+ getUserId(): string | undefined;
11
+ getUserEmail(): string | undefined;
12
+ getUserRole(): string | undefined;
13
+ getUserType(): string | undefined;
14
+ getRoles(): string[] | undefined;
15
+ getIp(): string | undefined;
16
+ getUserAgent(): string | undefined;
17
+ getDevice(): RequestContext['device'] | undefined;
18
+ getLocation(): RequestContext['location'] | undefined;
19
+ parseDevice(userAgent: string): void;
20
+ isAuthenticated(): boolean;
21
+ hasRole(role: string): boolean;
22
+ hasAnyRole(roles: string[]): boolean;
23
+ clear(): void;
24
+ }