logiscout 1.0.3 → 1.0.4
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/README.md +193 -1
- package/dist/cjs/api/Interceptor.cjs +66 -7
- package/dist/cjs/api/Interceptor.d.ts +4 -3
- package/dist/cjs/api/Interceptor.d.ts.map +1 -1
- package/dist/cjs/api/LogApi.cjs +2 -6
- package/dist/cjs/api/LogApi.d.ts +2 -3
- package/dist/cjs/api/LogApi.d.ts.map +1 -1
- package/dist/cjs/core/constants/Levels/LevelsColors.cjs +11 -0
- package/dist/cjs/core/constants/Levels/LevelsColors.d.ts +3 -0
- package/dist/cjs/core/constants/Levels/LevelsColors.d.ts.map +1 -0
- package/dist/cjs/core/constants/Levels/LevelsSeverity.cjs +11 -0
- package/dist/cjs/core/constants/Levels/LevelsSeverity.d.ts +3 -0
- package/dist/cjs/core/constants/Levels/LevelsSeverity.d.ts.map +1 -0
- package/dist/cjs/core/context/RequestContext.cjs +4 -14
- package/dist/cjs/core/context/RequestContext.d.ts +0 -3
- package/dist/cjs/core/context/RequestContext.d.ts.map +1 -1
- package/dist/cjs/core/enum/LogPayLoads.cjs +8 -0
- package/dist/cjs/core/enum/LogPayLoads.d.ts +5 -0
- package/dist/cjs/core/enum/LogPayLoads.d.ts.map +1 -0
- package/dist/cjs/core/formatters/winston/FormatLogs.cjs +18 -0
- package/dist/cjs/core/formatters/winston/FormatLogs.d.ts +3 -0
- package/dist/cjs/core/formatters/winston/FormatLogs.d.ts.map +1 -0
- package/dist/cjs/core/interface/CorrelationSession.cjs +2 -0
- package/dist/cjs/core/interface/CorrelationSession.d.ts +32 -0
- package/dist/cjs/core/interface/CorrelationSession.d.ts.map +1 -0
- package/dist/cjs/core/interface/JsonzierConfig.cjs +2 -0
- package/dist/cjs/core/interface/JsonzierConfig.d.ts +6 -0
- package/dist/cjs/core/interface/JsonzierConfig.d.ts.map +1 -0
- package/dist/cjs/core/interface/RequestContext.cjs +2 -0
- package/dist/cjs/core/interface/RequestContext.d.ts +4 -0
- package/dist/cjs/core/interface/RequestContext.d.ts.map +1 -0
- package/dist/cjs/core/interface/payloads/Payloads.cjs +2 -0
- package/dist/cjs/core/interface/payloads/Payloads.d.ts +11 -0
- package/dist/cjs/core/interface/payloads/Payloads.d.ts.map +1 -0
- package/dist/cjs/core/store/CorrelationStore.cjs +29 -0
- package/dist/cjs/core/store/CorrelationStore.d.ts +5 -0
- package/dist/cjs/core/store/CorrelationStore.d.ts.map +1 -0
- package/dist/cjs/errors/ThrowError.cjs +6 -0
- package/dist/cjs/errors/ThrowError.d.ts +2 -0
- package/dist/cjs/errors/ThrowError.d.ts.map +1 -0
- package/dist/cjs/middlewares/correlationMiddleware.cjs +28 -64
- package/dist/cjs/middlewares/correlationMiddleware.d.ts +1 -16
- package/dist/cjs/middlewares/correlationMiddleware.d.ts.map +1 -1
- package/dist/cjs/services/Levels/Levels.cjs +10 -10
- package/dist/cjs/services/Levels/Levels.d.ts +15 -5
- package/dist/cjs/services/Levels/Levels.d.ts.map +1 -1
- package/dist/cjs/services/Logger/Logger.cjs +51 -134
- package/dist/cjs/services/Logger/Logger.d.ts +6 -1
- package/dist/cjs/services/Logger/Logger.d.ts.map +1 -1
- package/dist/cjs/services/formatters/ConsoleFormatter.cjs +2 -9
- package/dist/cjs/services/formatters/ConsoleFormatter.d.ts.map +1 -1
- package/dist/cjs/services/processors/Jsonizer.cjs +31 -0
- package/dist/cjs/services/processors/Jsonizer.d.ts +11 -0
- package/dist/cjs/services/processors/Jsonizer.d.ts.map +1 -0
- package/dist/cjs/services/transporter/ConsoleTranspoter.cjs +16 -0
- package/dist/cjs/services/transporter/ConsoleTranspoter.d.ts +5 -0
- package/dist/cjs/services/transporter/ConsoleTranspoter.d.ts.map +1 -0
- package/dist/cjs/services/transporter/ServerTransporter.cjs +31 -0
- package/dist/cjs/services/transporter/ServerTransporter.d.ts +10 -0
- package/dist/cjs/services/transporter/ServerTransporter.d.ts.map +1 -0
- package/dist/cjs/utils/GenerateCorrelationId.cjs +10 -0
- package/dist/cjs/utils/GenerateCorrelationId.d.ts +2 -0
- package/dist/cjs/utils/GenerateCorrelationId.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateComponentName.cjs +14 -0
- package/dist/cjs/validator/ValidateComponentName.d.ts +2 -0
- package/dist/cjs/validator/ValidateComponentName.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateLogEntry.cjs +18 -0
- package/dist/cjs/validator/ValidateLogEntry.d.ts +3 -0
- package/dist/cjs/validator/ValidateLogEntry.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateLogLevel.cjs +11 -0
- package/dist/cjs/validator/ValidateLogLevel.d.ts +2 -0
- package/dist/cjs/validator/ValidateLogLevel.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateLogMessage.cjs +10 -0
- package/dist/cjs/validator/ValidateLogMessage.d.ts +2 -0
- package/dist/cjs/validator/ValidateLogMessage.d.ts.map +1 -0
- package/dist/cjs/validator/ValidateRequestContext.cjs +18 -0
- package/dist/cjs/validator/ValidateRequestContext.d.ts +2 -0
- package/dist/cjs/validator/ValidateRequestContext.d.ts.map +1 -0
- package/dist/esm/api/Interceptor.d.ts +4 -3
- package/dist/esm/api/Interceptor.d.ts.map +1 -1
- package/dist/esm/api/Interceptor.js +64 -7
- package/dist/esm/api/LogApi.d.ts +2 -3
- package/dist/esm/api/LogApi.d.ts.map +1 -1
- package/dist/esm/api/LogApi.js +2 -3
- package/dist/esm/core/constants/Levels/LevelsColors.d.ts +3 -0
- package/dist/esm/core/constants/Levels/LevelsColors.d.ts.map +1 -0
- package/dist/esm/core/constants/Levels/LevelsColors.js +8 -0
- package/dist/esm/core/constants/Levels/LevelsSeverity.d.ts +3 -0
- package/dist/esm/core/constants/Levels/LevelsSeverity.d.ts.map +1 -0
- package/dist/esm/core/constants/Levels/LevelsSeverity.js +8 -0
- package/dist/esm/core/context/RequestContext.d.ts +0 -3
- package/dist/esm/core/context/RequestContext.d.ts.map +1 -1
- package/dist/esm/core/context/RequestContext.js +4 -14
- package/dist/esm/core/enum/LogPayLoads.d.ts +5 -0
- package/dist/esm/core/enum/LogPayLoads.d.ts.map +1 -0
- package/dist/esm/core/enum/LogPayLoads.js +5 -0
- package/dist/esm/core/formatters/winston/FormatLogs.d.ts +3 -0
- package/dist/esm/core/formatters/winston/FormatLogs.d.ts.map +1 -0
- package/dist/esm/core/formatters/winston/FormatLogs.js +15 -0
- package/dist/esm/core/interface/CorrelationSession.d.ts +32 -0
- package/dist/esm/core/interface/CorrelationSession.d.ts.map +1 -0
- package/dist/esm/core/interface/CorrelationSession.js +1 -0
- package/dist/esm/core/interface/JsonzierConfig.d.ts +6 -0
- package/dist/esm/core/interface/JsonzierConfig.d.ts.map +1 -0
- package/dist/esm/core/interface/JsonzierConfig.js +1 -0
- package/dist/esm/core/interface/RequestContext.d.ts +4 -0
- package/dist/esm/core/interface/RequestContext.d.ts.map +1 -0
- package/dist/esm/core/interface/RequestContext.js +1 -0
- package/dist/esm/core/interface/payloads/Payloads.d.ts +11 -0
- package/dist/esm/core/interface/payloads/Payloads.d.ts.map +1 -0
- package/dist/esm/core/interface/payloads/Payloads.js +1 -0
- package/dist/esm/core/store/CorrelationStore.d.ts +5 -0
- package/dist/esm/core/store/CorrelationStore.d.ts.map +1 -0
- package/dist/esm/core/store/CorrelationStore.js +24 -0
- package/dist/esm/errors/ThrowError.d.ts +2 -0
- package/dist/esm/errors/ThrowError.d.ts.map +1 -0
- package/dist/esm/errors/ThrowError.js +3 -0
- package/dist/esm/middlewares/correlationMiddleware.d.ts +1 -16
- package/dist/esm/middlewares/correlationMiddleware.d.ts.map +1 -1
- package/dist/esm/middlewares/correlationMiddleware.js +27 -59
- package/dist/esm/services/Levels/Levels.d.ts +15 -5
- package/dist/esm/services/Levels/Levels.d.ts.map +1 -1
- package/dist/esm/services/Levels/Levels.js +10 -10
- package/dist/esm/services/Logger/Logger.d.ts +6 -1
- package/dist/esm/services/Logger/Logger.d.ts.map +1 -1
- package/dist/esm/services/Logger/Logger.js +48 -101
- package/dist/esm/services/formatters/ConsoleFormatter.d.ts.map +1 -1
- package/dist/esm/services/formatters/ConsoleFormatter.js +1 -8
- package/dist/esm/services/processors/Jsonizer.d.ts +11 -0
- package/dist/esm/services/processors/Jsonizer.d.ts.map +1 -0
- package/dist/esm/services/processors/Jsonizer.js +27 -0
- package/dist/esm/services/transporter/ConsoleTranspoter.d.ts +5 -0
- package/dist/esm/services/transporter/ConsoleTranspoter.d.ts.map +1 -0
- package/dist/esm/services/transporter/ConsoleTranspoter.js +9 -0
- package/dist/esm/services/transporter/ServerTransporter.d.ts +10 -0
- package/dist/esm/services/transporter/ServerTransporter.d.ts.map +1 -0
- package/dist/esm/services/transporter/ServerTransporter.js +27 -0
- package/dist/esm/utils/GenerateCorrelationId.d.ts +2 -0
- package/dist/esm/utils/GenerateCorrelationId.d.ts.map +1 -0
- package/dist/esm/utils/GenerateCorrelationId.js +4 -0
- package/dist/esm/validator/ValidateComponentName.d.ts +2 -0
- package/dist/esm/validator/ValidateComponentName.d.ts.map +1 -0
- package/dist/esm/validator/ValidateComponentName.js +11 -0
- package/dist/esm/validator/ValidateLogEntry.d.ts +3 -0
- package/dist/esm/validator/ValidateLogEntry.d.ts.map +1 -0
- package/dist/esm/validator/ValidateLogEntry.js +15 -0
- package/dist/esm/validator/ValidateLogLevel.d.ts +2 -0
- package/dist/esm/validator/ValidateLogLevel.d.ts.map +1 -0
- package/dist/esm/validator/ValidateLogLevel.js +8 -0
- package/dist/esm/validator/ValidateLogMessage.d.ts +2 -0
- package/dist/esm/validator/ValidateLogMessage.d.ts.map +1 -0
- package/dist/esm/validator/ValidateLogMessage.js +7 -0
- package/dist/esm/validator/ValidateRequestContext.d.ts +2 -0
- package/dist/esm/validator/ValidateRequestContext.d.ts.map +1 -0
- package/dist/esm/validator/ValidateRequestContext.js +15 -0
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = validateComponentName;
|
|
4
|
+
const ThrowError_js_1 = require("../errors/ThrowError.cjs");
|
|
5
|
+
function validateComponentName(componentName) {
|
|
6
|
+
if (!componentName || typeof componentName !== "string") {
|
|
7
|
+
(0, ThrowError_js_1.throwError)("Logger: Component name must be a non-empty string. " +
|
|
8
|
+
"Usage: createLogger('ComponentName')");
|
|
9
|
+
}
|
|
10
|
+
if (componentName.length > 100) {
|
|
11
|
+
(0, ThrowError_js_1.throwError)("Logger: Component name cannot exceed 100 characters. " +
|
|
12
|
+
`Received: '${componentName.substring(0, 20)}...'`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateComponentName.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateComponentName.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,qBAAqB,CAAC,aAAa,EAAC,MAAM,QAajE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = validateLogEntry;
|
|
4
|
+
const ThrowError_js_1 = require("../errors/ThrowError.cjs");
|
|
5
|
+
function validateLogEntry(entry) {
|
|
6
|
+
if (!entry) {
|
|
7
|
+
(0, ThrowError_js_1.throwError)("[Logiscout] Log entry is undefined or null");
|
|
8
|
+
}
|
|
9
|
+
if (!entry.message || typeof entry.message !== "string") {
|
|
10
|
+
(0, ThrowError_js_1.throwError)("[Logiscout] Log message must be a non-empty string. " +
|
|
11
|
+
`Usage: logiscout.${entry.level}('Your message', { meta })`);
|
|
12
|
+
}
|
|
13
|
+
if (entry.message.length > 10000) {
|
|
14
|
+
console.error("[Logiscout] Log message exceeds 10000 characters. Message truncated.");
|
|
15
|
+
entry.message =
|
|
16
|
+
entry.message.substring(0, 10000) + "... [truncated]";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateLogEntry.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateLogEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAGrD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAoB9D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = validateLogLevel;
|
|
4
|
+
const LogLevels_js_1 = require("../core/enum/LogLevels.cjs");
|
|
5
|
+
const ThrowError_js_1 = require("../errors/ThrowError.cjs");
|
|
6
|
+
function validateLogLevel(logLevel) {
|
|
7
|
+
if (!Object.values(LogLevels_js_1.LogLevels).includes(logLevel)) {
|
|
8
|
+
(0, ThrowError_js_1.throwError)(`Logger: Invalid log level '${logLevel}'. ` +
|
|
9
|
+
`Valid levels: ${Object.values(LogLevels_js_1.LogLevels).join(", ")}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateLogLevel.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateLogLevel.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,QAAQ,EAAE,GAAG,GAAG,IAAI,CAO5D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = validateLogMessage;
|
|
4
|
+
const ThrowError_js_1 = require("../errors/ThrowError.cjs");
|
|
5
|
+
function validateLogMessage(message) {
|
|
6
|
+
if (!message || typeof message !== "string") {
|
|
7
|
+
(0, ThrowError_js_1.throwError)(`Logger: Message must be a non-empty string. ` +
|
|
8
|
+
`Received: ${typeof message === "undefined" ? "undefined" : typeof message}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateLogMessage.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateLogMessage.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAShE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateRequestContext = validateRequestContext;
|
|
4
|
+
const ThrowError_js_1 = require("../errors/ThrowError.cjs");
|
|
5
|
+
function validateRequestContext(fn, correlationId) {
|
|
6
|
+
if (typeof fn !== "function") {
|
|
7
|
+
(0, ThrowError_js_1.throwError)("RequestContext.run() requires a function as the first parameter. " +
|
|
8
|
+
"Usage: RequestContext.run(() => { ... }, correlationId?)");
|
|
9
|
+
}
|
|
10
|
+
// Validate correlationId if provided
|
|
11
|
+
if (correlationId !== undefined && typeof correlationId !== "string") {
|
|
12
|
+
(0, ThrowError_js_1.throwError)("RequestContext.run(): correlationId must be a string if provided. " +
|
|
13
|
+
`Received: ${typeof correlationId}`);
|
|
14
|
+
}
|
|
15
|
+
if (correlationId && correlationId.length > 100) {
|
|
16
|
+
(0, ThrowError_js_1.throwError)("RequestContext.run(): correlationId cannot exceed 100 characters.");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ValidateRequestContext.d.ts","sourceRoot":"","sources":["../../../src/validator/ValidateRequestContext.ts"],"names":[],"mappings":"AAEA,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,MAAM,IAAI,EACd,aAAa,EAAE,MAAM,GAAC,SAAS,GAC9B,IAAI,CAqBN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
export
|
|
1
|
+
declare let IMAGE_BASE_URL: string;
|
|
2
|
+
declare let APP_URL: string;
|
|
3
|
+
export { IMAGE_BASE_URL, APP_URL };
|
|
4
|
+
export declare const HTTP: import("axios").AxiosInstance;
|
|
4
5
|
//# sourceMappingURL=Interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interceptor.d.ts","sourceRoot":"","sources":["../../../src/api/Interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Interceptor.d.ts","sourceRoot":"","sources":["../../../src/api/Interceptor.ts"],"names":[],"mappings":"AAMA,QAAA,IAAI,cAAc,QAAK,CAAC;AACxB,QAAA,IAAI,OAAO,QAAK,CAAC;AAUjB,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;AAUnC,eAAO,MAAM,IAAI,+BAIf,CAAC"}
|
|
@@ -1,10 +1,67 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
// Determine the environment and set base URLs
|
|
3
|
+
const environment = "local";
|
|
4
|
+
console.log("Environment:", environment);
|
|
5
|
+
let IMAGE_BASE_URL = "";
|
|
6
|
+
let APP_URL = "";
|
|
7
|
+
if (environment === "local") {
|
|
8
|
+
APP_URL = "https://practice-backend-new.thedoclinq.com/api/";
|
|
9
|
+
}
|
|
10
|
+
else if (environment === "prod") {
|
|
11
|
+
APP_URL = "https://practicebackend-uat.thedoclinq.com/api/";
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
APP_URL = "http://127.0.0.1:8000/logs/";
|
|
15
|
+
}
|
|
16
|
+
export { IMAGE_BASE_URL, APP_URL };
|
|
17
|
+
// Axios base config
|
|
18
|
+
const baseURL = `${APP_URL}`;
|
|
19
|
+
const headers = {
|
|
20
|
+
accept: "application/json",
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
};
|
|
23
|
+
// Create instance
|
|
24
|
+
export const HTTP = axios.create({
|
|
25
|
+
baseURL,
|
|
26
|
+
headers,
|
|
8
27
|
withCredentials: false,
|
|
9
28
|
});
|
|
10
|
-
|
|
29
|
+
// // Token getter (matches Postman `auth_token`)
|
|
30
|
+
// const getToken = () => {
|
|
31
|
+
// if (typeof window !== "undefined") {
|
|
32
|
+
// return (
|
|
33
|
+
// localStorage.getItem("auth_token") ||
|
|
34
|
+
// localStorage.getItem("token") ||
|
|
35
|
+
// localStorage.getItem("clientaccesstoken")
|
|
36
|
+
// );
|
|
37
|
+
// }
|
|
38
|
+
// // 👇 Hardcoded fallback for build time or SSR
|
|
39
|
+
// return "2|G3Y7woZ55m7W0vHHm0UZbTGO34i1bQJRsLUQqPEY04c662f9";
|
|
40
|
+
// };
|
|
41
|
+
// // Request interceptor for attaching Authorization header
|
|
42
|
+
// HTTP.interceptors.request.use(
|
|
43
|
+
// (config) => {
|
|
44
|
+
// const token = getToken();
|
|
45
|
+
// if (token) {
|
|
46
|
+
// config.headers["Authorization"] = `Bearer ${token}`;
|
|
47
|
+
// }
|
|
48
|
+
// return config;
|
|
49
|
+
// },
|
|
50
|
+
// (error) => Promise.reject(error)
|
|
51
|
+
// );
|
|
52
|
+
// // Response interceptor for handling 401 unauthorized
|
|
53
|
+
// HTTP.interceptors.response.use(
|
|
54
|
+
// (response) => response,
|
|
55
|
+
// (error) => {
|
|
56
|
+
// if (error.response?.status === 401 || message === "Unauthenticated.") {
|
|
57
|
+
// console.error("Unauthorized, redirecting to login...");
|
|
58
|
+
// localStorage.removeItem("auth_token");
|
|
59
|
+
// localStorage.removeItem("token");
|
|
60
|
+
// localStorage.removeItem("clientaccesstoken");
|
|
61
|
+
// localStorage.removeItem("healthcare_user");
|
|
62
|
+
// window.location.reload();
|
|
63
|
+
// // window.location.href = "/doctor-signin";
|
|
64
|
+
// }
|
|
65
|
+
// return Promise.reject(error);
|
|
66
|
+
// }
|
|
67
|
+
// );
|
package/dist/esm/api/LogApi.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
import { BackendLogPayload, FrontendLogPayload } from "../core/interface/payloads/Payloads.js";
|
|
2
|
+
type LogPayload = BackendLogPayload | FrontendLogPayload;
|
|
4
3
|
export declare function LogApi(data: LogPayload): Promise<void>;
|
|
5
4
|
export {};
|
|
6
5
|
//# sourceMappingURL=LogApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LogApi.d.ts","sourceRoot":"","sources":["../../../src/api/LogApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LogApi.d.ts","sourceRoot":"","sources":["../../../src/api/LogApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,wCAAwC,CAAC;AAIhD,KAAK,UAAU,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AACzD,wBAAsB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAO5D"}
|
package/dist/esm/api/LogApi.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import HTTP from "./Interceptor.js";
|
|
2
1
|
export async function LogApi(data) {
|
|
3
2
|
try {
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// console.log(data);
|
|
4
|
+
// const response = await HTTP.post("/log", data);
|
|
6
5
|
}
|
|
7
6
|
catch (error) {
|
|
8
7
|
console.error("Failed to send log:", error);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LevelsColors.d.ts","sourceRoot":"","sources":["../../../../../src/core/constants/Levels/LevelsColors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAMlD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LogLevels } from "../../enum/LogLevels.js";
|
|
2
|
+
export const LEVEL_COLORS = {
|
|
3
|
+
[LogLevels.DEBUG]: "\x1b[90m", // gray
|
|
4
|
+
[LogLevels.INFO]: "\x1b[32m", // green
|
|
5
|
+
[LogLevels.WARN]: "\x1b[33m", // yellow
|
|
6
|
+
[LogLevels.ERROR]: "\x1b[31m", // red
|
|
7
|
+
[LogLevels.CRITICAL]: "\x1b[35m" // magenta
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LevelsSeverity.d.ts","sourceRoot":"","sources":["../../../../../src/core/constants/Levels/LevelsSeverity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAM/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestContext.d.ts","sourceRoot":"","sources":["../../../../src/core/context/RequestContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RequestContext.d.ts","sourceRoot":"","sources":["../../../../src/core/context/RequestContext.ts"],"names":[],"mappings":"AAUA,qBAAa,cAAc;IACzB,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;IAuBxD,MAAM,CAAC,gBAAgB,IAAI,MAAM,GAAG,SAAS;CAc9C"}
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
|
+
import { throwError } from "../../errors/ThrowError.js";
|
|
4
|
+
import { validateRequestContext } from "../../validator/ValidateRequestContext.js";
|
|
3
5
|
const storage = new AsyncLocalStorage();
|
|
4
6
|
export class RequestContext {
|
|
5
7
|
static run(fn, correlationId) {
|
|
6
|
-
|
|
7
|
-
if (typeof fn !== "function") {
|
|
8
|
-
throw new Error("RequestContext.run() requires a function as the first parameter. " +
|
|
9
|
-
"Usage: RequestContext.run(() => { ... }, correlationId?)");
|
|
10
|
-
}
|
|
11
|
-
// Validate correlationId if provided
|
|
12
|
-
if (correlationId !== undefined && typeof correlationId !== "string") {
|
|
13
|
-
throw new Error("RequestContext.run(): correlationId must be a string if provided. " +
|
|
14
|
-
`Received: ${typeof correlationId}`);
|
|
15
|
-
}
|
|
16
|
-
if (correlationId && correlationId.length > 100) {
|
|
17
|
-
throw new Error("RequestContext.run(): correlationId cannot exceed 100 characters.");
|
|
18
|
-
}
|
|
8
|
+
validateRequestContext(fn, correlationId);
|
|
19
9
|
// Generate UUID if not provided
|
|
20
10
|
const id = correlationId ?? randomUUID();
|
|
21
11
|
try {
|
|
@@ -24,7 +14,7 @@ export class RequestContext {
|
|
|
24
14
|
}, fn);
|
|
25
15
|
}
|
|
26
16
|
catch (error) {
|
|
27
|
-
|
|
17
|
+
throwError(`RequestContext.run(): Failed to run function in context. ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
28
18
|
}
|
|
29
19
|
}
|
|
30
20
|
static getCorrelationId() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LogPayLoads.d.ts","sourceRoot":"","sources":["../../../../src/core/enum/LogPayLoads.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormatLogs.d.ts","sourceRoot":"","sources":["../../../../../src/core/formatters/winston/FormatLogs.ts"],"names":[],"mappings":"AAAA,OAAO,OAAwD,MAAM,SAAS,CAAC;AAK/E,MAAM,CAAC,OAAO,UAAU,UAAU,2BAejC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { format } from "winston";
|
|
2
|
+
import { ConsoleFormatter } from "../../../services/formatters/ConsoleFormatter.js";
|
|
3
|
+
const consoleFormatter = new ConsoleFormatter();
|
|
4
|
+
export default function formatLogs() {
|
|
5
|
+
return format.combine(format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), format.printf(({ timestamp, level, message, component, ...meta }) => {
|
|
6
|
+
const formatted = consoleFormatter.format({
|
|
7
|
+
level: level,
|
|
8
|
+
message: String(message),
|
|
9
|
+
timestamp: String(timestamp),
|
|
10
|
+
component: component,
|
|
11
|
+
...meta,
|
|
12
|
+
});
|
|
13
|
+
return formatted;
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LogLevels } from "../enum/LogLevels.js";
|
|
2
|
+
export interface CorrelationSession {
|
|
3
|
+
projectName: string;
|
|
4
|
+
environment: string;
|
|
5
|
+
correlationId: string;
|
|
6
|
+
component?: string;
|
|
7
|
+
startedAt: string;
|
|
8
|
+
endedAt?: string;
|
|
9
|
+
durationMs?: number;
|
|
10
|
+
request?: {
|
|
11
|
+
method?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
statusCode?: number;
|
|
14
|
+
};
|
|
15
|
+
logs: Array<{
|
|
16
|
+
timestamp: string;
|
|
17
|
+
level: LogLevels;
|
|
18
|
+
message: string;
|
|
19
|
+
meta?: Record<string, unknown>;
|
|
20
|
+
component: string;
|
|
21
|
+
}>;
|
|
22
|
+
}
|
|
23
|
+
export interface NonCorrelationSession {
|
|
24
|
+
projectName: string;
|
|
25
|
+
timestamp: string;
|
|
26
|
+
level: LogLevels;
|
|
27
|
+
message: string;
|
|
28
|
+
meta?: Record<string, unknown>;
|
|
29
|
+
component: string;
|
|
30
|
+
correlationId?: string;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=CorrelationSession.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CorrelationSession.d.ts","sourceRoot":"","sources":["../../../../src/core/interface/CorrelationSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IAEF,IAAI,EAAE,KAAK,CAAC;QACV,SAAS,EAAE,MAAM,CAAC;QAClB,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;CACJ;AAED,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAC,MAAM,CAAA;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonzierConfig.d.ts","sourceRoot":"","sources":["../../../../src/core/interface/JsonzierConfig.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RequestContext.d.ts","sourceRoot":"","sources":["../../../../src/core/interface/RequestContext.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,aAAa,EAAE,MAAM,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LogPayloadType } from "../../enum/LogPayLoads.js";
|
|
2
|
+
import { CorrelationSession, NonCorrelationSession } from "../CorrelationSession.js";
|
|
3
|
+
export interface BackendLogPayload {
|
|
4
|
+
type: LogPayloadType.SESSION;
|
|
5
|
+
data: CorrelationSession;
|
|
6
|
+
}
|
|
7
|
+
export interface FrontendLogPayload {
|
|
8
|
+
type: LogPayloadType.SINGLE;
|
|
9
|
+
data: NonCorrelationSession;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Payloads.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Payloads.d.ts","sourceRoot":"","sources":["../../../../../src/core/interface/payloads/Payloads.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC;IAC7B,IAAI,EAAE,kBAAkB,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,qBAAqB,CAAC;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { CorrelationSession } from "../interface/CorrelationSession.js";
|
|
2
|
+
export declare function getOrCreateSession(correlationId: string, base: Omit<CorrelationSession, "logs" | "startedAt">): CorrelationSession;
|
|
3
|
+
export declare function endSession(correlationId: string): CorrelationSession | undefined;
|
|
4
|
+
export declare function removeSession(correlationId: string): void;
|
|
5
|
+
//# sourceMappingURL=CorrelationStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CorrelationStore.d.ts","sourceRoot":"","sources":["../../../../src/core/store/CorrelationStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAIxE,wBAAgB,kBAAkB,CAChC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,IAAI,CAAC,kBAAkB,EAAE,MAAM,GAAG,WAAW,CAAC,GACnD,kBAAkB,CASpB;AAED,wBAAgB,UAAU,CAAC,aAAa,EAAE,MAAM,kCAU/C;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,QAElD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const sessions = new Map();
|
|
2
|
+
export function getOrCreateSession(correlationId, base) {
|
|
3
|
+
if (!sessions.has(correlationId)) {
|
|
4
|
+
sessions.set(correlationId, {
|
|
5
|
+
...base,
|
|
6
|
+
startedAt: new Date().toISOString(),
|
|
7
|
+
logs: [],
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return sessions.get(correlationId);
|
|
11
|
+
}
|
|
12
|
+
export function endSession(correlationId) {
|
|
13
|
+
const session = sessions.get(correlationId);
|
|
14
|
+
if (!session)
|
|
15
|
+
return;
|
|
16
|
+
session.endedAt = new Date().toISOString();
|
|
17
|
+
session.durationMs =
|
|
18
|
+
new Date(session.endedAt).getTime() -
|
|
19
|
+
new Date(session.startedAt).getTime();
|
|
20
|
+
return session;
|
|
21
|
+
}
|
|
22
|
+
export function removeSession(correlationId) {
|
|
23
|
+
sessions.delete(correlationId);
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThrowError.d.ts","sourceRoot":"","sources":["../../../src/errors/ThrowError.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAEjD"}
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
headers?: Record<string, string | string[] | undefined>;
|
|
3
|
-
get?: (header: string) => string | undefined;
|
|
4
|
-
}
|
|
5
|
-
interface ResponseLike {
|
|
6
|
-
setHeader?: (name: string, value: string) => void;
|
|
7
|
-
locals?: Record<string, unknown>;
|
|
8
|
-
}
|
|
9
|
-
interface NextFunction {
|
|
10
|
-
(err?: Error): void;
|
|
11
|
-
}
|
|
12
|
-
interface MiddlewareHandler {
|
|
13
|
-
(req: RequestLike, res: ResponseLike, next: NextFunction): void;
|
|
14
|
-
}
|
|
15
|
-
export declare const createCorrelationMiddleware: () => MiddlewareHandler;
|
|
16
|
-
export {};
|
|
1
|
+
export declare function createCorrelationMiddleware(): (req: any, res: any, next: any) => void;
|
|
17
2
|
//# sourceMappingURL=correlationMiddleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"correlationMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middlewares/correlationMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"correlationMiddleware.d.ts","sourceRoot":"","sources":["../../../src/middlewares/correlationMiddleware.ts"],"names":[],"mappings":"AAYA,wBAAgB,2BAA2B,KACjC,KAAK,GAAG,EAAE,KAAK,GAAG,EAAE,MAAM,GAAG,UAgCtC"}
|