@gennext/lb-infra 0.0.4 → 0.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.
- package/dist/base/loopback/@lb/rest/index.d.ts +1 -0
- package/dist/base/loopback/@lb/rest/index.d.ts.map +1 -1
- package/dist/base/loopback/@lb/rest/index.js +1 -0
- package/dist/base/loopback/@lb/rest/index.js.map +1 -1
- package/dist/base/loopback/openapi-v3/index.d.ts +3 -0
- package/dist/base/loopback/openapi-v3/index.d.ts.map +1 -0
- package/dist/base/loopback/openapi-v3/index.js +18 -0
- package/dist/base/loopback/openapi-v3/index.js.map +1 -0
- package/dist/helpers/logger/enhanced-factory.d.ts +14 -0
- package/dist/helpers/logger/enhanced-factory.d.ts.map +1 -0
- package/dist/helpers/logger/enhanced-factory.js +40 -0
- package/dist/helpers/logger/enhanced-factory.js.map +1 -0
- package/dist/helpers/logger/factory.d.ts +4 -0
- package/dist/helpers/logger/factory.d.ts.map +1 -1
- package/dist/helpers/logger/factory.js +7 -0
- package/dist/helpers/logger/factory.js.map +1 -1
- package/dist/helpers/logger/http/access-logger.d.ts +14 -0
- package/dist/helpers/logger/http/access-logger.d.ts.map +1 -0
- package/dist/helpers/logger/http/access-logger.js +137 -0
- package/dist/helpers/logger/http/access-logger.js.map +1 -0
- package/dist/helpers/logger/http/client-ip.d.ts +8 -0
- package/dist/helpers/logger/http/client-ip.d.ts.map +1 -0
- package/dist/helpers/logger/http/client-ip.js +63 -0
- package/dist/helpers/logger/http/client-ip.js.map +1 -0
- package/dist/helpers/logger/http/data-masking.d.ts +13 -0
- package/dist/helpers/logger/http/data-masking.d.ts.map +1 -0
- package/dist/helpers/logger/http/data-masking.js +84 -0
- package/dist/helpers/logger/http/data-masking.js.map +1 -0
- package/dist/helpers/logger/http/index.d.ts +6 -0
- package/dist/helpers/logger/http/index.d.ts.map +1 -0
- package/dist/helpers/logger/http/index.js +22 -0
- package/dist/helpers/logger/http/index.js.map +1 -0
- package/dist/helpers/logger/http/request-context.d.ts +15 -0
- package/dist/helpers/logger/http/request-context.d.ts.map +1 -0
- package/dist/helpers/logger/http/request-context.js +44 -0
- package/dist/helpers/logger/http/request-context.js.map +1 -0
- package/dist/helpers/logger/http/types.d.ts +53 -0
- package/dist/helpers/logger/http/types.d.ts.map +1 -0
- package/dist/helpers/logger/http/types.js +3 -0
- package/dist/helpers/logger/http/types.js.map +1 -0
- package/dist/helpers/logger/index.d.ts +2 -0
- package/dist/helpers/logger/index.d.ts.map +1 -1
- package/dist/helpers/logger/index.js +2 -0
- package/dist/helpers/logger/index.js.map +1 -1
- package/package.json +1 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/base/loopback/@lb/rest/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/base/loopback/@lb/rest/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC"}
|
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./../../rest"), exports);
|
|
18
|
+
__exportStar(require("./../../openapi-v3"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/base/loopback/@lb/rest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/base/loopback/@lb/rest/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,qDAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/base/loopback/openapi-v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,mBAAmB,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@loopback/openapi-v3"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/base/loopback/openapi-v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Logger, ApplicationLogger } from "./application-logger";
|
|
2
|
+
import { HttpAccessLogger } from "./http/access-logger";
|
|
3
|
+
import { IEnhancedLoggerOptions } from "./http/types";
|
|
4
|
+
export interface IEnhancedLogger {
|
|
5
|
+
application: ApplicationLogger;
|
|
6
|
+
http: HttpAccessLogger | null;
|
|
7
|
+
}
|
|
8
|
+
export declare class EnhancedLoggerFactory {
|
|
9
|
+
private static httpLoggers;
|
|
10
|
+
static createEnhancedLogger(scopes: string[], httpOptions?: IEnhancedLoggerOptions, customLogger?: Logger): IEnhancedLogger;
|
|
11
|
+
static getHttpLogger(scopes: string[]): HttpAccessLogger | null;
|
|
12
|
+
static createHttpMiddleware(scopes: string[], _options?: IEnhancedLoggerOptions): (req: any, res: any, next: () => void) => void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=enhanced-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhanced-factory.d.ts","sourceRoot":"","sources":["../../../src/helpers/logger/enhanced-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,iBAAiB,CAAC;IAC/B,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAC/B;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAuC;IAEjE,MAAM,CAAC,oBAAoB,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,WAAW,CAAC,EAAE,sBAAsB,EACpC,YAAY,CAAC,EAAE,MAAM,GACpB,eAAe;IAsBlB,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,gBAAgB,GAAG,IAAI;IAK/D,MAAM,CAAC,oBAAoB,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,QAAQ,CAAC,EAAE,sBAAsB;CAQpC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EnhancedLoggerFactory = void 0;
|
|
4
|
+
const application_logger_1 = require("./application-logger");
|
|
5
|
+
const access_logger_1 = require("./http/access-logger");
|
|
6
|
+
class EnhancedLoggerFactory {
|
|
7
|
+
static { this.httpLoggers = new Map(); }
|
|
8
|
+
static createEnhancedLogger(scopes, httpOptions, customLogger) {
|
|
9
|
+
const applicationLogger = customLogger || new application_logger_1.ApplicationLogger();
|
|
10
|
+
applicationLogger.withScope(scopes.join("-"));
|
|
11
|
+
let httpLogger = null;
|
|
12
|
+
if (httpOptions?.enableAccessLog) {
|
|
13
|
+
const key = scopes.join("-");
|
|
14
|
+
if (!this.httpLoggers.has(key)) {
|
|
15
|
+
httpLogger = new access_logger_1.HttpAccessLogger(applicationLogger, httpOptions);
|
|
16
|
+
this.httpLoggers.set(key, httpLogger);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
httpLogger = this.httpLoggers.get(key);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
application: applicationLogger,
|
|
24
|
+
http: httpLogger,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static getHttpLogger(scopes) {
|
|
28
|
+
const key = scopes.join("-");
|
|
29
|
+
return this.httpLoggers.get(key) || null;
|
|
30
|
+
}
|
|
31
|
+
static createHttpMiddleware(scopes, _options) {
|
|
32
|
+
const httpLogger = this.getHttpLogger(scopes);
|
|
33
|
+
if (!httpLogger) {
|
|
34
|
+
throw new Error("HTTP Access Logger not enabled for these scopes");
|
|
35
|
+
}
|
|
36
|
+
return access_logger_1.HttpAccessLogger.createMiddleware(httpLogger);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.EnhancedLoggerFactory = EnhancedLoggerFactory;
|
|
40
|
+
//# sourceMappingURL=enhanced-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enhanced-factory.js","sourceRoot":"","sources":["../../../src/helpers/logger/enhanced-factory.ts"],"names":[],"mappings":";;;AAAA,6DAAiE;AACjE,wDAAwD;AAQx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AAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,gCAAgB,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACvD,CAAC;;AA3CH,sDA4CC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { Logger } from "./application-logger";
|
|
2
|
+
import { IEnhancedLogger } from "./enhanced-factory";
|
|
3
|
+
import { IEnhancedLoggerOptions } from "./http/types";
|
|
2
4
|
export declare class LoggerFactory {
|
|
3
5
|
static getLogger(scopes: string[], customLogger?: Logger): Logger;
|
|
6
|
+
static getEnhancedLogger(scopes: string[], httpOptions?: IEnhancedLoggerOptions, customLogger?: Logger): IEnhancedLogger;
|
|
7
|
+
static createHttpMiddleware(scopes: string[], options?: IEnhancedLoggerOptions): (req: any, res: any, next: () => void) => void;
|
|
4
8
|
}
|
|
5
9
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/helpers/logger/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/helpers/logger/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAyB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,qBAAa,aAAa;IACxB,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM;IAMjE,MAAM,CAAC,iBAAiB,CACtB,MAAM,EAAE,MAAM,EAAE,EAChB,WAAW,CAAC,EAAE,sBAAsB,EACpC,YAAY,CAAC,EAAE,MAAM,GACpB,eAAe;IAQlB,MAAM,CAAC,oBAAoB,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,CAAC,EAAE,sBAAsB;CAInC"}
|
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LoggerFactory = void 0;
|
|
4
4
|
const application_logger_1 = require("./application-logger");
|
|
5
|
+
const enhanced_factory_1 = require("./enhanced-factory");
|
|
5
6
|
class LoggerFactory {
|
|
6
7
|
static getLogger(scopes, customLogger) {
|
|
7
8
|
const logger = customLogger ?? new application_logger_1.ApplicationLogger();
|
|
8
9
|
logger.withScope(scopes.join("-"));
|
|
9
10
|
return logger;
|
|
10
11
|
}
|
|
12
|
+
static getEnhancedLogger(scopes, httpOptions, customLogger) {
|
|
13
|
+
return enhanced_factory_1.EnhancedLoggerFactory.createEnhancedLogger(scopes, httpOptions, customLogger);
|
|
14
|
+
}
|
|
15
|
+
static createHttpMiddleware(scopes, options) {
|
|
16
|
+
return enhanced_factory_1.EnhancedLoggerFactory.createHttpMiddleware(scopes, options);
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
19
|
exports.LoggerFactory = LoggerFactory;
|
|
13
20
|
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/helpers/logger/factory.ts"],"names":[],"mappings":";;;AAAA,6DAAiE;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/helpers/logger/factory.ts"],"names":[],"mappings":";;;AAAA,6DAAiE;AACjE,yDAA4E;AAG5E,MAAa,aAAa;IACxB,MAAM,CAAC,SAAS,CAAC,MAAgB,EAAE,YAAqB;QACtD,MAAM,MAAM,GAAG,YAAY,IAAI,IAAI,sCAAiB,EAAE,CAAC;QACvD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,iBAAiB,CACtB,MAAgB,EAChB,WAAoC,EACpC,YAAqB;QAErB,OAAO,wCAAqB,CAAC,oBAAoB,CAC/C,MAAM,EACN,WAAW,EACX,YAAY,CACb,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,oBAAoB,CACzB,MAAgB,EAChB,OAAgC;QAEhC,OAAO,wCAAqB,CAAC,oBAAoB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrE,CAAC;CACF;AAzBD,sCAyBC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApplicationLogger } from "../application-logger";
|
|
2
|
+
import { IAccessLogEntry, IHttpAccessLogger, IPerformanceMetrics, IEnhancedLoggerOptions } from "./types";
|
|
3
|
+
export declare class HttpAccessLogger implements IHttpAccessLogger {
|
|
4
|
+
private logger;
|
|
5
|
+
private options;
|
|
6
|
+
constructor(logger: ApplicationLogger, options?: IEnhancedLoggerOptions);
|
|
7
|
+
logAccess(entry: IAccessLogEntry): void;
|
|
8
|
+
logPerformance(metrics: IPerformanceMetrics): void;
|
|
9
|
+
logRequestData(data: any, level?: "info" | "warn" | "error"): void;
|
|
10
|
+
private formatAccessLog;
|
|
11
|
+
private sanitizeRequestData;
|
|
12
|
+
static createMiddleware(httpLogger: HttpAccessLogger): (req: any, res: any, next: () => void) => void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=access-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-logger.d.ts","sourceRoot":"","sources":["../../../../src/helpers/logger/http/access-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAKjB,qBAAa,gBAAiB,YAAW,iBAAiB;IACxD,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,OAAO,CAAyB;gBAE5B,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAE,sBAA2B;IAW3E,SAAS,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI;IAUvC,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAUlD,cAAc,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,GAAE,MAAM,GAAG,MAAM,GAAG,OAAgB,GAAG,IAAI;IAkB1E,OAAO,CAAC,eAAe;IAmBvB,OAAO,CAAC,mBAAmB;IAsB3B,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,IAC1C,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,MAAM,IAAI;CAkE/C"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpAccessLogger = void 0;
|
|
4
|
+
const data_masking_1 = require("./data-masking");
|
|
5
|
+
const client_ip_1 = require("./client-ip");
|
|
6
|
+
const request_context_1 = require("./request-context");
|
|
7
|
+
class HttpAccessLogger {
|
|
8
|
+
constructor(logger, options = {}) {
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.options = {
|
|
11
|
+
enableAccessLog: true,
|
|
12
|
+
enablePerformanceMetrics: true,
|
|
13
|
+
enableDataMasking: true,
|
|
14
|
+
sanitizeRequestData: true,
|
|
15
|
+
...options,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
logAccess(entry) {
|
|
19
|
+
if (!this.options.enableAccessLog)
|
|
20
|
+
return;
|
|
21
|
+
const logMessage = this.formatAccessLog(entry);
|
|
22
|
+
this.logger.log(entry.level, logMessage, {
|
|
23
|
+
type: "access",
|
|
24
|
+
...entry,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
logPerformance(metrics) {
|
|
28
|
+
if (!this.options.enablePerformanceMetrics)
|
|
29
|
+
return;
|
|
30
|
+
const logMessage = `Performance metrics | Duration: ${metrics.duration}ms | Memory: ${JSON.stringify(metrics.memoryUsage)}`;
|
|
31
|
+
this.logger.info(logMessage, {
|
|
32
|
+
type: "performance",
|
|
33
|
+
...metrics,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
logRequestData(data, level = "info") {
|
|
37
|
+
let sanitizedData = data;
|
|
38
|
+
if (this.options.enableDataMasking && this.options.dataMaskingConfig) {
|
|
39
|
+
sanitizedData = data_masking_1.DataMasking.mask(data, this.options.dataMaskingConfig);
|
|
40
|
+
}
|
|
41
|
+
if (this.options.sanitizeRequestData) {
|
|
42
|
+
sanitizedData = this.sanitizeRequestData(sanitizedData);
|
|
43
|
+
}
|
|
44
|
+
this.logger[level]("Request data", {
|
|
45
|
+
type: "request_data",
|
|
46
|
+
data: sanitizedData,
|
|
47
|
+
requestId: request_context_1.RequestContextManager.getRequestId(),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
formatAccessLog(entry) {
|
|
51
|
+
const parts = [
|
|
52
|
+
entry.method,
|
|
53
|
+
entry.url,
|
|
54
|
+
entry.statusCode,
|
|
55
|
+
`${entry.responseTime}ms`,
|
|
56
|
+
];
|
|
57
|
+
if (entry.clientIP) {
|
|
58
|
+
parts.push(`IP:${entry.clientIP}`);
|
|
59
|
+
}
|
|
60
|
+
if (entry.userId) {
|
|
61
|
+
parts.push(`User:${entry.userId}`);
|
|
62
|
+
}
|
|
63
|
+
return parts.join(" | ");
|
|
64
|
+
}
|
|
65
|
+
sanitizeRequestData(data) {
|
|
66
|
+
if (typeof data !== "object" || data === null) {
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
const sanitized = {};
|
|
70
|
+
const excludeFields = ["authorization", "cookie", "session", "csrf"];
|
|
71
|
+
for (const [key, value] of Object.entries(data)) {
|
|
72
|
+
const lowerKey = key.toLowerCase();
|
|
73
|
+
if (!excludeFields.some((field) => lowerKey.includes(field))) {
|
|
74
|
+
sanitized[key] =
|
|
75
|
+
typeof value === "object" && value !== null
|
|
76
|
+
? this.sanitizeRequestData(value)
|
|
77
|
+
: value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return sanitized;
|
|
81
|
+
}
|
|
82
|
+
// Static middleware factory method
|
|
83
|
+
static createMiddleware(httpLogger) {
|
|
84
|
+
return (req, res, next) => {
|
|
85
|
+
const startTime = Date.now();
|
|
86
|
+
const requestId = request_context_1.RequestContextManager.generateRequestId();
|
|
87
|
+
// Set request context
|
|
88
|
+
request_context_1.RequestContextManager.setContext({
|
|
89
|
+
requestId,
|
|
90
|
+
startTime,
|
|
91
|
+
clientIP: client_ip_1.ClientIPDetection.getClientIP(req, httpLogger.options.ipConfig),
|
|
92
|
+
userAgent: req.headers?.["user-agent"],
|
|
93
|
+
});
|
|
94
|
+
// Log request start
|
|
95
|
+
httpLogger.logRequestData({
|
|
96
|
+
method: req.method,
|
|
97
|
+
url: req.url,
|
|
98
|
+
headers: req.headers,
|
|
99
|
+
query: req.query,
|
|
100
|
+
body: req.body,
|
|
101
|
+
}, "info");
|
|
102
|
+
// Capture response
|
|
103
|
+
const originalSend = res.send;
|
|
104
|
+
res.send = function (data) {
|
|
105
|
+
const responseTime = Date.now() - startTime;
|
|
106
|
+
const accessLogEntry = {
|
|
107
|
+
timestamp: new Date().toISOString(),
|
|
108
|
+
requestId,
|
|
109
|
+
method: req.method,
|
|
110
|
+
url: req.url,
|
|
111
|
+
statusCode: res.statusCode,
|
|
112
|
+
responseTime,
|
|
113
|
+
userAgent: req.headers?.["user-agent"],
|
|
114
|
+
clientIP: request_context_1.RequestContextManager.getClientIP(),
|
|
115
|
+
contentLength: res.get("content-length"),
|
|
116
|
+
referer: req.headers?.["referer"],
|
|
117
|
+
userId: request_context_1.RequestContextManager.getUserId(),
|
|
118
|
+
level: res.statusCode >= 400 ? "warn" : "info",
|
|
119
|
+
};
|
|
120
|
+
httpLogger.logAccess(accessLogEntry);
|
|
121
|
+
// Log performance metrics
|
|
122
|
+
const performanceMetrics = {
|
|
123
|
+
duration: responseTime,
|
|
124
|
+
memoryUsage: process.memoryUsage(),
|
|
125
|
+
cpuUsage: process.cpuUsage(),
|
|
126
|
+
timestamp: new Date().toISOString(),
|
|
127
|
+
requestId,
|
|
128
|
+
};
|
|
129
|
+
httpLogger.logPerformance(performanceMetrics);
|
|
130
|
+
return originalSend.call(this, data);
|
|
131
|
+
};
|
|
132
|
+
next();
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.HttpAccessLogger = HttpAccessLogger;
|
|
137
|
+
//# sourceMappingURL=access-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access-logger.js","sourceRoot":"","sources":["../../../../src/helpers/logger/http/access-logger.ts"],"names":[],"mappings":";;;AAOA,iDAA6C;AAC7C,2CAAgD;AAChD,uDAA0D;AAE1D,MAAa,gBAAgB;IAI3B,YAAY,MAAyB,EAAE,UAAkC,EAAE;QACzE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG;YACb,eAAe,EAAE,IAAI;YACrB,wBAAwB,EAAE,IAAI;YAC9B,iBAAiB,EAAE,IAAI;YACvB,mBAAmB,EAAE,IAAI;YACzB,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,KAAsB;QAC9B,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe;YAAE,OAAO;QAE1C,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE;YACvC,IAAI,EAAE,QAAQ;YACd,GAAG,KAAK;SACT,CAAC,CAAC;IACL,CAAC;IAED,cAAc,CAAC,OAA4B;QACzC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,wBAAwB;YAAE,OAAO;QAEnD,MAAM,UAAU,GAAG,mCAAmC,OAAO,CAAC,QAA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,EAAE,YAAY;oBACtB,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE;oBAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE;oBAC5B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACnC,SAAS;iBACV,CAAC;gBAEF,UAAU,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;gBAE9C,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YACvC,CAAC,CAAC;YAEF,IAAI,EAAE,CAAC;QACT,CAAC,CAAC;IACJ,CAAC;CACF;AAjKD,4CAiKC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IClientIPConfig } from "./types";
|
|
2
|
+
export declare class ClientIPDetection {
|
|
3
|
+
private static readonly DEFAULT_CONFIG;
|
|
4
|
+
static getClientIP(req: any, config?: Partial<IClientIPConfig>): string | undefined;
|
|
5
|
+
private static extractIPFromHeader;
|
|
6
|
+
private static isValidIP;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=client-ip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip.d.ts","sourceRoot":"","sources":["../../../../src/helpers/logger/http/client-ip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAQpC;IAEF,MAAM,CAAC,WAAW,CAChB,GAAG,EAAE,GAAG,EACR,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAChC,MAAM,GAAG,SAAS;IAgCrB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAsBlC,OAAO,CAAC,MAAM,CAAC,SAAS;CAUzB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientIPDetection = void 0;
|
|
4
|
+
class ClientIPDetection {
|
|
5
|
+
static { this.DEFAULT_CONFIG = {
|
|
6
|
+
trustProxy: false,
|
|
7
|
+
headerNames: [
|
|
8
|
+
"x-forwarded-for",
|
|
9
|
+
"x-real-ip",
|
|
10
|
+
"cf-connecting-ip",
|
|
11
|
+
"x-client-ip",
|
|
12
|
+
],
|
|
13
|
+
}; }
|
|
14
|
+
static getClientIP(req, config) {
|
|
15
|
+
const ipConfig = { ...this.DEFAULT_CONFIG, ...config };
|
|
16
|
+
if (!req)
|
|
17
|
+
return undefined;
|
|
18
|
+
// If not trusting proxy, use remote address directly
|
|
19
|
+
if (!ipConfig.trustProxy) {
|
|
20
|
+
return (req.connection?.remoteAddress ||
|
|
21
|
+
req.socket?.remoteAddress ||
|
|
22
|
+
req.ip ||
|
|
23
|
+
req.remoteAddress);
|
|
24
|
+
}
|
|
25
|
+
// Check various headers in order of preference
|
|
26
|
+
for (const header of ipConfig.headerNames) {
|
|
27
|
+
const ip = this.extractIPFromHeader(req.headers?.[header]);
|
|
28
|
+
if (ip) {
|
|
29
|
+
return ip;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Fallback to remote address
|
|
33
|
+
return (req.connection?.remoteAddress ||
|
|
34
|
+
req.socket?.remoteAddress ||
|
|
35
|
+
req.ip ||
|
|
36
|
+
req.remoteAddress);
|
|
37
|
+
}
|
|
38
|
+
static extractIPFromHeader(headerValue) {
|
|
39
|
+
if (!headerValue)
|
|
40
|
+
return undefined;
|
|
41
|
+
const value = Array.isArray(headerValue) ? headerValue[0] : headerValue;
|
|
42
|
+
if (!value)
|
|
43
|
+
return undefined;
|
|
44
|
+
// Handle comma-separated list of IPs (common in x-forwarded-for)
|
|
45
|
+
const ips = value.split(",").map((ip) => ip.trim());
|
|
46
|
+
// Return the first IP in the list (original client IP)
|
|
47
|
+
const ip = ips[0];
|
|
48
|
+
// Validate IP format
|
|
49
|
+
if (this.isValidIP(ip)) {
|
|
50
|
+
return ip;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
static isValidIP(ip) {
|
|
55
|
+
// IPv4 regex
|
|
56
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
57
|
+
// IPv6 regex (simplified)
|
|
58
|
+
const ipv6Regex = /^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$/;
|
|
59
|
+
return ipv4Regex.test(ip) || ipv6Regex.test(ip);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ClientIPDetection = ClientIPDetection;
|
|
63
|
+
//# sourceMappingURL=client-ip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-ip.js","sourceRoot":"","sources":["../../../../src/helpers/logger/http/client-ip.ts"],"names":[],"mappings":";;;AAEA,MAAa,iBAAiB;aACJ,mBAAc,GAAoB;QACxD,UAAU,EAAE,KAAK;QACjB,WAAW,EAAE;YACX,iBAAiB;YACjB,WAAW;YACX,kBAAkB;YAClB,aAAa;SACd;KACF,CAAC;IAEF,MAAM,CAAC,WAAW,CAChB,GAAQ,EACR,MAAiC;QAEjC,MAAM,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;QAEvD,IAAI,CAAC,GAAG;YAAE,OAAO,SAAS,CAAC;QAE3B,qDAAqD;QACrD,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;YACzB,OAAO,CACL,GAAG,CAAC,UAAU,EAAE,aAAa;gBAC7B,GAAG,CAAC,MAAM,EAAE,aAAa;gBACzB,GAAG,CAAC,EAAE;gBACN,GAAG,CAAC,aAAa,CAClB,CAAC;QACJ,CAAC;QAED,+CAA+C;QAC/C,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,WAA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,EAAE,CAAC,CAAC;IAClD,CAAC;;AA7EH,8CA8EC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IDataMaskingConfig } from "./types";
|
|
2
|
+
export declare class DataMasking {
|
|
3
|
+
private static readonly DEFAULT_CONFIG;
|
|
4
|
+
private static readonly EMAIL_REGEX;
|
|
5
|
+
private static readonly PHONE_REGEX;
|
|
6
|
+
private static readonly CREDIT_CARD_REGEX;
|
|
7
|
+
private static readonly PASSWORD_FIELDS;
|
|
8
|
+
private static readonly TOKEN_REGEX;
|
|
9
|
+
static mask(data: any, config?: Partial<IDataMaskingConfig>): any;
|
|
10
|
+
private static shouldMaskField;
|
|
11
|
+
private static maskValue;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=data-masking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-masking.d.ts","sourceRoot":"","sources":["../../../../src/helpers/logger/http/data-masking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAMpC;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CACsB;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CACiC;IACpE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAA8B;IACvE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAOrC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAEtE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,GAAG;IAyBjE,OAAO,CAAC,MAAM,CAAC,eAAe;IAa9B,OAAO,CAAC,MAAM,CAAC,SAAS;CAoCzB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataMasking = void 0;
|
|
4
|
+
class DataMasking {
|
|
5
|
+
static { this.DEFAULT_CONFIG = {
|
|
6
|
+
email: true,
|
|
7
|
+
phone: true,
|
|
8
|
+
creditCard: true,
|
|
9
|
+
password: true,
|
|
10
|
+
token: true,
|
|
11
|
+
}; }
|
|
12
|
+
static { this.EMAIL_REGEX = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g; }
|
|
13
|
+
static { this.PHONE_REGEX = /\b(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{4})\b/g; }
|
|
14
|
+
static { this.CREDIT_CARD_REGEX = /\b(?:\d[ -]*?){13,16}\b/g; }
|
|
15
|
+
static { this.PASSWORD_FIELDS = [
|
|
16
|
+
"password",
|
|
17
|
+
"pwd",
|
|
18
|
+
"pass",
|
|
19
|
+
"secret",
|
|
20
|
+
"token",
|
|
21
|
+
"key",
|
|
22
|
+
]; }
|
|
23
|
+
static { this.TOKEN_REGEX = /\b[A-Za-z0-9+/]{20,}={0,2}\b/g; }
|
|
24
|
+
static mask(data, config) {
|
|
25
|
+
const maskConfig = { ...this.DEFAULT_CONFIG, ...config };
|
|
26
|
+
if (typeof data !== "object" || data === null) {
|
|
27
|
+
return this.maskValue(data, maskConfig);
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(data)) {
|
|
30
|
+
return data.map((item) => this.mask(item, maskConfig));
|
|
31
|
+
}
|
|
32
|
+
const masked = {};
|
|
33
|
+
for (const [key, value] of Object.entries(data)) {
|
|
34
|
+
if (this.shouldMaskField(key, maskConfig)) {
|
|
35
|
+
masked[key] = this.maskValue(value, maskConfig);
|
|
36
|
+
}
|
|
37
|
+
else if (typeof value === "object" && value !== null) {
|
|
38
|
+
masked[key] = this.mask(value, maskConfig);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
masked[key] = this.maskValue(value, maskConfig);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return masked;
|
|
45
|
+
}
|
|
46
|
+
static shouldMaskField(fieldName, config) {
|
|
47
|
+
const lowerFieldName = fieldName.toLowerCase();
|
|
48
|
+
if (config.customFields?.includes(fieldName)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return this.PASSWORD_FIELDS.some((field) => lowerFieldName.includes(field));
|
|
52
|
+
}
|
|
53
|
+
static maskValue(value, config) {
|
|
54
|
+
if (typeof value !== "string") {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
let masked = value;
|
|
58
|
+
if (config.email) {
|
|
59
|
+
masked = masked.replace(this.EMAIL_REGEX, (match) => {
|
|
60
|
+
const [username, domain] = match.split("@");
|
|
61
|
+
const maskedUsername = username.charAt(0) +
|
|
62
|
+
"*".repeat(username.length - 2) +
|
|
63
|
+
username.charAt(username.length - 1);
|
|
64
|
+
return `${maskedUsername}@${domain}`;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (config.phone) {
|
|
68
|
+
masked = masked.replace(this.PHONE_REGEX, "***-***-****");
|
|
69
|
+
}
|
|
70
|
+
if (config.creditCard) {
|
|
71
|
+
masked = masked.replace(this.CREDIT_CARD_REGEX, (match) => {
|
|
72
|
+
return "*".repeat(match.length - 4) + match.slice(-4);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (config.token) {
|
|
76
|
+
masked = masked.replace(this.TOKEN_REGEX, (match) => {
|
|
77
|
+
return match.substring(0, 8) + "*".repeat(match.length - 8);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return masked;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.DataMasking = DataMasking;
|
|
84
|
+
//# sourceMappingURL=data-masking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-masking.js","sourceRoot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+1,22 @@
|
|
|
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("./types"), exports);
|
|
18
|
+
__exportStar(require("./access-logger"), exports);
|
|
19
|
+
__exportStar(require("./data-masking"), exports);
|
|
20
|
+
__exportStar(require("./client-ip"), exports);
|
|
21
|
+
__exportStar(require("./request-context"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/helpers/logger/http/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,kDAAgC;AAChC,iDAA+B;AAC/B,8CAA4B;AAC5B,oDAAkC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { IRequestContext } from "./types";
|
|
2
|
+
export declare class RequestContextManager {
|
|
3
|
+
private static asyncLocalStorage;
|
|
4
|
+
static setContext(context: Partial<IRequestContext>): void;
|
|
5
|
+
static getContext(): IRequestContext | undefined;
|
|
6
|
+
static getRequestId(): string | undefined;
|
|
7
|
+
static getUserId(): string | undefined;
|
|
8
|
+
static getClientIP(): string | undefined;
|
|
9
|
+
static getUserAgent(): string | undefined;
|
|
10
|
+
static getStartTime(): number | undefined;
|
|
11
|
+
static generateRequestId(): string;
|
|
12
|
+
static withContext<T>(context: Partial<IRequestContext>, callback: () => T): T;
|
|
13
|
+
static updateContext(context: Partial<IRequestContext>): void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=request-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-context.d.ts","sourceRoot":"","sources":["../../../../src/helpers/logger/http/request-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA4C;IAE5E,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;IAK1D,MAAM,CAAC,UAAU,IAAI,eAAe,GAAG,SAAS;IAIhD,MAAM,CAAC,YAAY,IAAI,MAAM,GAAG,SAAS;IAIzC,MAAM,CAAC,SAAS,IAAI,MAAM,GAAG,SAAS;IAItC,MAAM,CAAC,WAAW,IAAI,MAAM,GAAG,SAAS;IAIxC,MAAM,CAAC,YAAY,IAAI,MAAM,GAAG,SAAS;IAIzC,MAAM,CAAC,YAAY,IAAI,MAAM,GAAG,SAAS;IAIzC,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAIlC,MAAM,CAAC,WAAW,CAAC,CAAC,EAClB,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,EACjC,QAAQ,EAAE,MAAM,CAAC,GAChB,CAAC;IAQJ,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;CAM9D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RequestContextManager = void 0;
|
|
4
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
+
class RequestContextManager {
|
|
6
|
+
static { this.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage(); }
|
|
7
|
+
static setContext(context) {
|
|
8
|
+
const currentContext = this.asyncLocalStorage.getStore() || {};
|
|
9
|
+
this.asyncLocalStorage.enterWith({ ...currentContext, ...context });
|
|
10
|
+
}
|
|
11
|
+
static getContext() {
|
|
12
|
+
return this.asyncLocalStorage.getStore();
|
|
13
|
+
}
|
|
14
|
+
static getRequestId() {
|
|
15
|
+
return this.asyncLocalStorage.getStore()?.requestId;
|
|
16
|
+
}
|
|
17
|
+
static getUserId() {
|
|
18
|
+
return this.asyncLocalStorage.getStore()?.userId;
|
|
19
|
+
}
|
|
20
|
+
static getClientIP() {
|
|
21
|
+
return this.asyncLocalStorage.getStore()?.clientIP;
|
|
22
|
+
}
|
|
23
|
+
static getUserAgent() {
|
|
24
|
+
return this.asyncLocalStorage.getStore()?.userAgent;
|
|
25
|
+
}
|
|
26
|
+
static getStartTime() {
|
|
27
|
+
return this.asyncLocalStorage.getStore()?.startTime;
|
|
28
|
+
}
|
|
29
|
+
static generateRequestId() {
|
|
30
|
+
return `req_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
31
|
+
}
|
|
32
|
+
static withContext(context, callback) {
|
|
33
|
+
const currentContext = this.asyncLocalStorage.getStore() || {};
|
|
34
|
+
return this.asyncLocalStorage.run({ ...currentContext, ...context }, callback);
|
|
35
|
+
}
|
|
36
|
+
static updateContext(context) {
|
|
37
|
+
const currentContext = this.asyncLocalStorage.getStore();
|
|
38
|
+
if (currentContext) {
|
|
39
|
+
this.asyncLocalStorage.enterWith({ ...currentContext, ...context });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.RequestContextManager = RequestContextManager;
|
|
44
|
+
//# sourceMappingURL=request-context.js.map
|
|
@@ -0,0 +1 @@
|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AAC,WAAW,CAChB,OAAiC,EACjC,QAAiB;QAEjB,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC/D,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAC/B,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,EACjC,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,OAAiC;QACpD,MAAM,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,CAAC;QACzD,IAAI,cAAc,EAAE,CAAC;YACnB,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;;AApDH,sDAqDC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { TLogLevel } from "../common/types";
|
|
2
|
+
export interface IAccessLogEntry {
|
|
3
|
+
timestamp: string;
|
|
4
|
+
requestId?: string;
|
|
5
|
+
method: string;
|
|
6
|
+
url: string;
|
|
7
|
+
statusCode: number;
|
|
8
|
+
responseTime: number;
|
|
9
|
+
userAgent?: string;
|
|
10
|
+
clientIP?: string;
|
|
11
|
+
contentLength?: number;
|
|
12
|
+
referer?: string;
|
|
13
|
+
userId?: string;
|
|
14
|
+
level: TLogLevel;
|
|
15
|
+
}
|
|
16
|
+
export interface IHttpAccessLogger {
|
|
17
|
+
logAccess(entry: IAccessLogEntry): void;
|
|
18
|
+
}
|
|
19
|
+
export interface IPerformanceMetrics {
|
|
20
|
+
duration: number;
|
|
21
|
+
memoryUsage?: NodeJS.MemoryUsage;
|
|
22
|
+
cpuUsage?: NodeJS.CpuUsage;
|
|
23
|
+
timestamp: string;
|
|
24
|
+
requestId?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface IDataMaskingConfig {
|
|
27
|
+
email: boolean;
|
|
28
|
+
phone: boolean;
|
|
29
|
+
creditCard: boolean;
|
|
30
|
+
password: boolean;
|
|
31
|
+
token: boolean;
|
|
32
|
+
customFields?: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface IClientIPConfig {
|
|
35
|
+
trustProxy: boolean;
|
|
36
|
+
headerNames: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface IRequestContext {
|
|
39
|
+
requestId?: string;
|
|
40
|
+
userId?: string;
|
|
41
|
+
clientIP?: string;
|
|
42
|
+
userAgent?: string;
|
|
43
|
+
startTime?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface IEnhancedLoggerOptions {
|
|
46
|
+
enableAccessLog?: boolean;
|
|
47
|
+
enablePerformanceMetrics?: boolean;
|
|
48
|
+
enableDataMasking?: boolean;
|
|
49
|
+
dataMaskingConfig?: IDataMaskingConfig;
|
|
50
|
+
ipConfig?: IClientIPConfig;
|
|
51
|
+
sanitizeRequestData?: boolean;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/helpers/logger/http/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IA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3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/logger/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,QAAQ,CAAC"}
|
|
@@ -18,4 +18,6 @@ __exportStar(require("./application-logger"), exports);
|
|
|
18
18
|
__exportStar(require("./default-logger"), exports);
|
|
19
19
|
__exportStar(require("./factory"), exports);
|
|
20
20
|
__exportStar(require("./transports"), exports);
|
|
21
|
+
__exportStar(require("./enhanced-factory"), exports);
|
|
22
|
+
__exportStar(require("./http"), exports);
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,mDAAiC;AACjC,4CAA0B;AAC1B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/helpers/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,mDAAiC;AACjC,4CAA0B;AAC1B,+CAA6B;AAC7B,qDAAmC;AACnC,yCAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gennext/lb-infra",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"@gennext/dev-configs": "^0.0.1",
|
|
6
6
|
"@loopback/authentication": "^12.0.6",
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
"@loopback/rest-explorer": "^8.0.5",
|
|
18
18
|
"@loopback/security": "^0.12.5",
|
|
19
19
|
"@loopback/service-proxy": "^8.0.4",
|
|
20
|
-
"bcryptjs": "^3.0.3",
|
|
21
20
|
"dayjs": "^1.11.19",
|
|
22
21
|
"ioredis": "^5.9.2",
|
|
23
22
|
"lodash": "^4.17.21",
|
|
@@ -28,7 +27,6 @@
|
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@gennext/eslint-node": "^0.0.1",
|
|
31
|
-
"@types/bcryptjs": "^3.0.0",
|
|
32
30
|
"@types/lodash": "^4.17.23",
|
|
33
31
|
"@types/multer": "^2.0.0",
|
|
34
32
|
"@types/node": "^24.7.2",
|