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
package/README.md
CHANGED
|
@@ -1 +1,193 @@
|
|
|
1
|
-
# Logiscout
|
|
1
|
+
# Logiscout
|
|
2
|
+
|
|
3
|
+
A structured logging library for Node.js applications with correlation tracking, Winston integration, and multi-environment support.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/logiscout)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Structured Logging** - JSON-formatted logs with consistent schema
|
|
11
|
+
- **Correlation IDs** - Track requests across your application with automatic correlation ID propagation
|
|
12
|
+
- **Multiple Log Levels** - `info`, `warn`, `error`, `debug`, and `critical`
|
|
13
|
+
- **Express Middleware** - Built-in middleware for automatic request correlation
|
|
14
|
+
- **Winston Powered** - Built on top of Winston for reliable, extensible logging
|
|
15
|
+
- **TypeScript Support** - Full TypeScript support with exported types
|
|
16
|
+
- **ESM & CommonJS** - Dual module support
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install logiscout
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### 1. Initialize Logiscout
|
|
27
|
+
|
|
28
|
+
Initialize once at your application's entry point:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { initLogiscout } from 'logiscout';
|
|
32
|
+
|
|
33
|
+
initLogiscout({
|
|
34
|
+
projectName: 'my-app',
|
|
35
|
+
environment: 'dev', // 'dev' | 'staging' | 'prod'
|
|
36
|
+
apiKey: 'your-api-key' // optional
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 2. Create a Logger
|
|
41
|
+
|
|
42
|
+
Create component-specific loggers:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { createLogger } from 'logiscout';
|
|
46
|
+
|
|
47
|
+
const logger = createLogger('UserService');
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 3. Start Logging
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
// Basic logging
|
|
54
|
+
logger.info('User logged in');
|
|
55
|
+
logger.warn('Rate limit approaching');
|
|
56
|
+
logger.error('Failed to process request');
|
|
57
|
+
logger.debug('Processing user data');
|
|
58
|
+
logger.critical('Database connection lost');
|
|
59
|
+
|
|
60
|
+
// With metadata
|
|
61
|
+
logger.info('User created', { userId: '123', email: 'user@example.com' });
|
|
62
|
+
|
|
63
|
+
// Control server transport (in production)
|
|
64
|
+
logger.error('Payment failed', { orderId: '456' }, { send: true });
|
|
65
|
+
logger.debug('Debug info', { data: 'value' }, { send: false });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Express Integration
|
|
69
|
+
|
|
70
|
+
Use the correlation middleware to automatically track requests:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import express from 'express';
|
|
74
|
+
import { initLogiscout, createLogger, createCorrelationMiddleware } from 'logiscout';
|
|
75
|
+
|
|
76
|
+
const app = express();
|
|
77
|
+
|
|
78
|
+
// Initialize Logiscout
|
|
79
|
+
initLogiscout({
|
|
80
|
+
projectName: 'my-api',
|
|
81
|
+
environment: 'prod'
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Add correlation middleware
|
|
85
|
+
app.use(createCorrelationMiddleware());
|
|
86
|
+
|
|
87
|
+
// Create logger
|
|
88
|
+
const logger = createLogger('API');
|
|
89
|
+
|
|
90
|
+
app.get('/users', (req, res) => {
|
|
91
|
+
// Correlation ID is automatically attached to all logs
|
|
92
|
+
logger.info('Fetching users');
|
|
93
|
+
res.json({ users: [] });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
app.listen(3000);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The middleware:
|
|
100
|
+
- Generates a unique correlation ID for each request (or uses `x-correlation-id` header if provided)
|
|
101
|
+
- Attaches the correlation ID to all logs within the request context
|
|
102
|
+
- Sets `x-correlation-id` response header
|
|
103
|
+
- Tracks request method, path, and status code
|
|
104
|
+
|
|
105
|
+
## API Reference
|
|
106
|
+
|
|
107
|
+
### `initLogiscout(config)`
|
|
108
|
+
|
|
109
|
+
Initialize the Logiscout SDK. Must be called before creating any loggers.
|
|
110
|
+
|
|
111
|
+
| Parameter | Type | Required | Description |
|
|
112
|
+
|-----------|------|----------|-------------|
|
|
113
|
+
| `projectName` | `string` | Yes | Name of your project |
|
|
114
|
+
| `environment` | `'dev' \| 'staging' \| 'prod' \| string` | Yes | Current environment |
|
|
115
|
+
| `apiKey` | `string` | No | API key for server transport |
|
|
116
|
+
|
|
117
|
+
### `createLogger(componentName)`
|
|
118
|
+
|
|
119
|
+
Create a new logger instance for a specific component.
|
|
120
|
+
|
|
121
|
+
| Parameter | Type | Required | Description |
|
|
122
|
+
|-----------|------|----------|-------------|
|
|
123
|
+
| `componentName` | `string` | Yes | Name of the component/service |
|
|
124
|
+
|
|
125
|
+
Returns a logger instance with the following methods:
|
|
126
|
+
|
|
127
|
+
### Logger Methods
|
|
128
|
+
|
|
129
|
+
All logging methods have the same signature:
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
logger.info(message: string, meta?: Record<string, unknown>, options?: { send?: boolean }): void
|
|
133
|
+
logger.warn(message: string, meta?: Record<string, unknown>, options?: { send?: boolean }): void
|
|
134
|
+
logger.error(message: string, meta?: Record<string, unknown>, options?: { send?: boolean }): void
|
|
135
|
+
logger.debug(message: string, meta?: Record<string, unknown>, options?: { send?: boolean }): void
|
|
136
|
+
logger.critical(message: string, meta?: Record<string, unknown>, options?: { send?: boolean }): void
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| Parameter | Type | Required | Description |
|
|
140
|
+
|-----------|------|----------|-------------|
|
|
141
|
+
| `message` | `string` | Yes | Log message |
|
|
142
|
+
| `meta` | `Record<string, unknown>` | No | Additional metadata |
|
|
143
|
+
| `options.send` | `boolean` | No | Whether to send to server (default: `true`, only active in `prod`) |
|
|
144
|
+
|
|
145
|
+
### `createCorrelationMiddleware()`
|
|
146
|
+
|
|
147
|
+
Creates an Express middleware for request correlation tracking.
|
|
148
|
+
|
|
149
|
+
## Log Levels
|
|
150
|
+
|
|
151
|
+
| Level | Severity | Use Case |
|
|
152
|
+
|-------|----------|----------|
|
|
153
|
+
| `debug` | 0 | Detailed debugging information |
|
|
154
|
+
| `info` | 1 | General operational information |
|
|
155
|
+
| `warn` | 2 | Warning conditions |
|
|
156
|
+
| `error` | 3 | Error conditions |
|
|
157
|
+
| `critical` | 4 | Critical conditions requiring immediate attention |
|
|
158
|
+
|
|
159
|
+
## TypeScript
|
|
160
|
+
|
|
161
|
+
Logiscout exports types for TypeScript users:
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import {
|
|
165
|
+
LogLevels, // Enum of log levels
|
|
166
|
+
LoggerInterface, // Logger interface
|
|
167
|
+
LogEntry, // Log entry type
|
|
168
|
+
Levels, // Logger class (if you need to extend)
|
|
169
|
+
BaseLogger // Base logger class
|
|
170
|
+
} from 'logiscout';
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Log Output
|
|
174
|
+
|
|
175
|
+
Logs are output to the console in a formatted structure:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
[2024-01-15T10:30:00.000Z] [INFO] [UserService] User logged in
|
|
179
|
+
correlationId: "abc-123-def"
|
|
180
|
+
userId: "user_456"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Requirements
|
|
184
|
+
|
|
185
|
+
- Node.js >= 18
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT
|
|
190
|
+
|
|
191
|
+
## Contributing
|
|
192
|
+
|
|
193
|
+
Issues and pull requests are welcome at [GitHub](https://github.com/saadakmal460/Logiscout).
|
|
@@ -3,13 +3,72 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HTTP = exports.APP_URL = exports.IMAGE_BASE_URL = void 0;
|
|
6
7
|
const axios_1 = __importDefault(require("axios"));
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
// Determine the environment and set base URLs
|
|
9
|
+
const environment = "local";
|
|
10
|
+
console.log("Environment:", environment);
|
|
11
|
+
let IMAGE_BASE_URL = "";
|
|
12
|
+
exports.IMAGE_BASE_URL = IMAGE_BASE_URL;
|
|
13
|
+
let APP_URL = "";
|
|
14
|
+
exports.APP_URL = APP_URL;
|
|
15
|
+
if (environment === "local") {
|
|
16
|
+
exports.APP_URL = APP_URL = "https://practice-backend-new.thedoclinq.com/api/";
|
|
17
|
+
}
|
|
18
|
+
else if (environment === "prod") {
|
|
19
|
+
exports.APP_URL = APP_URL = "https://practicebackend-uat.thedoclinq.com/api/";
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
exports.APP_URL = APP_URL = "http://127.0.0.1:8000/logs/";
|
|
23
|
+
}
|
|
24
|
+
// Axios base config
|
|
25
|
+
const baseURL = `${APP_URL}`;
|
|
26
|
+
const headers = {
|
|
27
|
+
accept: "application/json",
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
};
|
|
30
|
+
// Create instance
|
|
31
|
+
exports.HTTP = axios_1.default.create({
|
|
32
|
+
baseURL,
|
|
33
|
+
headers,
|
|
13
34
|
withCredentials: false,
|
|
14
35
|
});
|
|
15
|
-
|
|
36
|
+
// // Token getter (matches Postman `auth_token`)
|
|
37
|
+
// const getToken = () => {
|
|
38
|
+
// if (typeof window !== "undefined") {
|
|
39
|
+
// return (
|
|
40
|
+
// localStorage.getItem("auth_token") ||
|
|
41
|
+
// localStorage.getItem("token") ||
|
|
42
|
+
// localStorage.getItem("clientaccesstoken")
|
|
43
|
+
// );
|
|
44
|
+
// }
|
|
45
|
+
// // 👇 Hardcoded fallback for build time or SSR
|
|
46
|
+
// return "2|G3Y7woZ55m7W0vHHm0UZbTGO34i1bQJRsLUQqPEY04c662f9";
|
|
47
|
+
// };
|
|
48
|
+
// // Request interceptor for attaching Authorization header
|
|
49
|
+
// HTTP.interceptors.request.use(
|
|
50
|
+
// (config) => {
|
|
51
|
+
// const token = getToken();
|
|
52
|
+
// if (token) {
|
|
53
|
+
// config.headers["Authorization"] = `Bearer ${token}`;
|
|
54
|
+
// }
|
|
55
|
+
// return config;
|
|
56
|
+
// },
|
|
57
|
+
// (error) => Promise.reject(error)
|
|
58
|
+
// );
|
|
59
|
+
// // Response interceptor for handling 401 unauthorized
|
|
60
|
+
// HTTP.interceptors.response.use(
|
|
61
|
+
// (response) => response,
|
|
62
|
+
// (error) => {
|
|
63
|
+
// if (error.response?.status === 401 || message === "Unauthenticated.") {
|
|
64
|
+
// console.error("Unauthorized, redirecting to login...");
|
|
65
|
+
// localStorage.removeItem("auth_token");
|
|
66
|
+
// localStorage.removeItem("token");
|
|
67
|
+
// localStorage.removeItem("clientaccesstoken");
|
|
68
|
+
// localStorage.removeItem("healthcare_user");
|
|
69
|
+
// window.location.reload();
|
|
70
|
+
// // window.location.href = "/doctor-signin";
|
|
71
|
+
// }
|
|
72
|
+
// return Promise.reject(error);
|
|
73
|
+
// }
|
|
74
|
+
// );
|
|
@@ -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"}
|
package/dist/cjs/api/LogApi.cjs
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.LogApi = LogApi;
|
|
7
|
-
const Interceptor_js_1 = __importDefault(require("./Interceptor.cjs"));
|
|
8
4
|
async function LogApi(data) {
|
|
9
5
|
try {
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// console.log(data);
|
|
7
|
+
// const response = await HTTP.post("/log", data);
|
|
12
8
|
}
|
|
13
9
|
catch (error) {
|
|
14
10
|
console.error("Failed to send log:", error);
|
package/dist/cjs/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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LEVEL_COLORS = void 0;
|
|
4
|
+
const LogLevels_js_1 = require("../../enum/LogLevels.cjs");
|
|
5
|
+
exports.LEVEL_COLORS = {
|
|
6
|
+
[LogLevels_js_1.LogLevels.DEBUG]: "\x1b[90m", // gray
|
|
7
|
+
[LogLevels_js_1.LogLevels.INFO]: "\x1b[32m", // green
|
|
8
|
+
[LogLevels_js_1.LogLevels.WARN]: "\x1b[33m", // yellow
|
|
9
|
+
[LogLevels_js_1.LogLevels.ERROR]: "\x1b[31m", // red
|
|
10
|
+
[LogLevels_js_1.LogLevels.CRITICAL]: "\x1b[35m" // magenta
|
|
11
|
+
};
|
|
@@ -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,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOG_LEVEL_SEVERITY = void 0;
|
|
4
|
+
const LogLevels_js_1 = require("../../enum/LogLevels.cjs");
|
|
5
|
+
exports.LOG_LEVEL_SEVERITY = {
|
|
6
|
+
[LogLevels_js_1.LogLevels.CRITICAL]: 0,
|
|
7
|
+
[LogLevels_js_1.LogLevels.ERROR]: 1,
|
|
8
|
+
[LogLevels_js_1.LogLevels.WARN]: 2,
|
|
9
|
+
[LogLevels_js_1.LogLevels.INFO]: 3,
|
|
10
|
+
[LogLevels_js_1.LogLevels.DEBUG]: 4,
|
|
11
|
+
};
|
|
@@ -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"}
|
|
@@ -3,22 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RequestContext = void 0;
|
|
4
4
|
const async_hooks_1 = require("async_hooks");
|
|
5
5
|
const crypto_1 = require("crypto");
|
|
6
|
+
const ThrowError_js_1 = require("../../errors/ThrowError.cjs");
|
|
7
|
+
const ValidateRequestContext_js_1 = require("../../validator/ValidateRequestContext.cjs");
|
|
6
8
|
const storage = new async_hooks_1.AsyncLocalStorage();
|
|
7
9
|
class RequestContext {
|
|
8
10
|
static run(fn, correlationId) {
|
|
9
|
-
|
|
10
|
-
if (typeof fn !== "function") {
|
|
11
|
-
throw new Error("RequestContext.run() requires a function as the first parameter. " +
|
|
12
|
-
"Usage: RequestContext.run(() => { ... }, correlationId?)");
|
|
13
|
-
}
|
|
14
|
-
// Validate correlationId if provided
|
|
15
|
-
if (correlationId !== undefined && typeof correlationId !== "string") {
|
|
16
|
-
throw new Error("RequestContext.run(): correlationId must be a string if provided. " +
|
|
17
|
-
`Received: ${typeof correlationId}`);
|
|
18
|
-
}
|
|
19
|
-
if (correlationId && correlationId.length > 100) {
|
|
20
|
-
throw new Error("RequestContext.run(): correlationId cannot exceed 100 characters.");
|
|
21
|
-
}
|
|
11
|
+
(0, ValidateRequestContext_js_1.validateRequestContext)(fn, correlationId);
|
|
22
12
|
// Generate UUID if not provided
|
|
23
13
|
const id = correlationId ?? (0, crypto_1.randomUUID)();
|
|
24
14
|
try {
|
|
@@ -27,7 +17,7 @@ class RequestContext {
|
|
|
27
17
|
}, fn);
|
|
28
18
|
}
|
|
29
19
|
catch (error) {
|
|
30
|
-
|
|
20
|
+
(0, ThrowError_js_1.throwError)(`RequestContext.run(): Failed to run function in context. ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
31
21
|
}
|
|
32
22
|
}
|
|
33
23
|
static getCorrelationId() {
|
|
@@ -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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogPayloadType = void 0;
|
|
4
|
+
var LogPayloadType;
|
|
5
|
+
(function (LogPayloadType) {
|
|
6
|
+
LogPayloadType["SESSION"] = "session";
|
|
7
|
+
LogPayloadType["SINGLE"] = "single";
|
|
8
|
+
})(LogPayloadType || (exports.LogPayloadType = LogPayloadType = {}));
|
|
@@ -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,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = formatLogs;
|
|
4
|
+
const winston_1 = require("winston");
|
|
5
|
+
const ConsoleFormatter_js_1 = require("../../../services/formatters/ConsoleFormatter.cjs");
|
|
6
|
+
const consoleFormatter = new ConsoleFormatter_js_1.ConsoleFormatter();
|
|
7
|
+
function formatLogs() {
|
|
8
|
+
return winston_1.format.combine(winston_1.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston_1.format.printf(({ timestamp, level, message, component, ...meta }) => {
|
|
9
|
+
const formatted = consoleFormatter.format({
|
|
10
|
+
level: level,
|
|
11
|
+
message: String(message),
|
|
12
|
+
timestamp: String(timestamp),
|
|
13
|
+
component: component,
|
|
14
|
+
...meta,
|
|
15
|
+
});
|
|
16
|
+
return formatted;
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
@@ -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,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
|
+
{"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
|
+
{"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,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,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrCreateSession = getOrCreateSession;
|
|
4
|
+
exports.endSession = endSession;
|
|
5
|
+
exports.removeSession = removeSession;
|
|
6
|
+
const sessions = new Map();
|
|
7
|
+
function getOrCreateSession(correlationId, base) {
|
|
8
|
+
if (!sessions.has(correlationId)) {
|
|
9
|
+
sessions.set(correlationId, {
|
|
10
|
+
...base,
|
|
11
|
+
startedAt: new Date().toISOString(),
|
|
12
|
+
logs: [],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return sessions.get(correlationId);
|
|
16
|
+
}
|
|
17
|
+
function endSession(correlationId) {
|
|
18
|
+
const session = sessions.get(correlationId);
|
|
19
|
+
if (!session)
|
|
20
|
+
return;
|
|
21
|
+
session.endedAt = new Date().toISOString();
|
|
22
|
+
session.durationMs =
|
|
23
|
+
new Date(session.endedAt).getTime() -
|
|
24
|
+
new Date(session.startedAt).getTime();
|
|
25
|
+
return session;
|
|
26
|
+
}
|
|
27
|
+
function removeSession(correlationId) {
|
|
28
|
+
sessions.delete(correlationId);
|
|
29
|
+
}
|
|
@@ -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 @@
|
|
|
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"}
|