unnbound-logger-sdk 2.0.10 → 3.0.1
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 +151 -229
- package/dist/axios.d.ts +9 -0
- package/dist/axios.js +74 -0
- package/dist/http.d.ts +0 -0
- package/dist/http.js +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +9 -11
- package/dist/logger.d.ts +15 -0
- package/dist/logger.js +44 -0
- package/dist/middleware.d.ts +3 -0
- package/dist/middleware.js +70 -0
- package/dist/sftp.d.ts +10 -0
- package/dist/sftp.js +13 -0
- package/dist/span.d.ts +16 -0
- package/dist/span.js +41 -0
- package/dist/storage.d.ts +10 -0
- package/dist/storage.js +10 -0
- package/dist/types.d.ts +32 -101
- package/dist/types.js +3 -0
- package/dist/unnbound-logger.d.ts +6 -16
- package/dist/unnbound-logger.js +58 -55
- package/dist/utils/http-status-messages.js +140 -35
- package/dist/utils/logger-utils.d.ts +1 -1
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +53 -0
- package/package.json +22 -38
package/dist/unnbound-logger.js
CHANGED
|
@@ -3,7 +3,7 @@ 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.UnnboundLogger = void 0;
|
|
6
|
+
exports.UnnboundLogger = exports.logger = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Core logger implementation
|
|
9
9
|
*/
|
|
@@ -13,6 +13,33 @@ const uuid_1 = require("uuid");
|
|
|
13
13
|
const trace_context_1 = require("./utils/trace-context");
|
|
14
14
|
const axios_1 = require("axios");
|
|
15
15
|
const http_status_messages_1 = require("./utils/http-status-messages");
|
|
16
|
+
const storage_1 = require("./storage");
|
|
17
|
+
exports.logger = (0, pino_1.default)({
|
|
18
|
+
level: process.env.LOG_LEVEL ?? 'info',
|
|
19
|
+
base: {
|
|
20
|
+
environment: process.env.ENVIRONMENT,
|
|
21
|
+
workflowId: process.env.UNNBOUND_WORKFLOW_ID,
|
|
22
|
+
workflowUrl: process.env.UNNBOUND_WORKFLOW_URL,
|
|
23
|
+
serviceId: process.env.UNNBOUND_SERVICE_ID,
|
|
24
|
+
deploymentId: process.env.UNNBOUND_DEPLOYMENT_ID,
|
|
25
|
+
},
|
|
26
|
+
mixin: () => {
|
|
27
|
+
console.log('storage', storage_1.storage.getStore());
|
|
28
|
+
return storage_1.storage.getStore() ?? {};
|
|
29
|
+
},
|
|
30
|
+
serializers: {
|
|
31
|
+
req: pino_1.default.stdSerializers.req,
|
|
32
|
+
res: pino_1.default.stdSerializers.res,
|
|
33
|
+
err: pino_1.default.stdSerializers.err,
|
|
34
|
+
},
|
|
35
|
+
// Let CloudWatch handle timestamps
|
|
36
|
+
timestamp: false,
|
|
37
|
+
// Change message field from 'msg' to 'messages'
|
|
38
|
+
messageKey: 'messages',
|
|
39
|
+
formatters: {
|
|
40
|
+
level: (level) => ({ level }),
|
|
41
|
+
},
|
|
42
|
+
});
|
|
16
43
|
/**
|
|
17
44
|
* UnnboundLogger provides typed, structured logging using Pino
|
|
18
45
|
*/
|
|
@@ -73,18 +100,18 @@ class UnnboundLogger {
|
|
|
73
100
|
ip: 'outgoing', // Mark as outgoing request
|
|
74
101
|
protocol: 'https', // Default for outgoing
|
|
75
102
|
secure: true,
|
|
76
|
-
get: () => undefined // Mock get method for constructFullUrl
|
|
103
|
+
get: () => undefined, // Mock get method for constructFullUrl
|
|
77
104
|
};
|
|
78
105
|
this.httpRequest(mockReq, {
|
|
79
106
|
traceId,
|
|
80
107
|
requestId,
|
|
81
|
-
startTime
|
|
108
|
+
startTime,
|
|
82
109
|
});
|
|
83
110
|
return config;
|
|
84
111
|
},
|
|
85
112
|
onRejected: (error) => {
|
|
86
113
|
return Promise.reject(error);
|
|
87
|
-
}
|
|
114
|
+
},
|
|
88
115
|
};
|
|
89
116
|
// Axios response interceptor (should be used separately)
|
|
90
117
|
this.axiosResponseInterceptor = {
|
|
@@ -106,7 +133,7 @@ class UnnboundLogger {
|
|
|
106
133
|
ip: 'outgoing', // Mark as outgoing request
|
|
107
134
|
protocol: 'https', // Default for outgoing
|
|
108
135
|
secure: true,
|
|
109
|
-
get: () => undefined // Mock get method for constructFullUrl
|
|
136
|
+
get: () => undefined, // Mock get method for constructFullUrl
|
|
110
137
|
};
|
|
111
138
|
const mockRes = {
|
|
112
139
|
statusCode: response.status,
|
|
@@ -114,14 +141,14 @@ class UnnboundLogger {
|
|
|
114
141
|
body: (0, logger_utils_1.safeJsonParse)(response.data),
|
|
115
142
|
startTime: startTime,
|
|
116
143
|
traceId: trace_context_1.traceContext.getTraceId(),
|
|
117
|
-
requestId: requestId
|
|
144
|
+
requestId: requestId,
|
|
118
145
|
},
|
|
119
|
-
getHeaders: () => response.headers || {}
|
|
146
|
+
getHeaders: () => response.headers || {},
|
|
120
147
|
};
|
|
121
148
|
this.httpResponse(mockRes, mockReq, {
|
|
122
149
|
requestId,
|
|
123
150
|
duration,
|
|
124
|
-
traceId: trace_context_1.traceContext.getTraceId()
|
|
151
|
+
traceId: trace_context_1.traceContext.getTraceId(),
|
|
125
152
|
});
|
|
126
153
|
return response;
|
|
127
154
|
},
|
|
@@ -144,7 +171,7 @@ class UnnboundLogger {
|
|
|
144
171
|
ip: 'outgoing', // Mark as outgoing request
|
|
145
172
|
protocol: 'https', // Default for outgoing
|
|
146
173
|
secure: true,
|
|
147
|
-
get: () => undefined // Mock get method for constructFullUrl
|
|
174
|
+
get: () => undefined, // Mock get method for constructFullUrl
|
|
148
175
|
};
|
|
149
176
|
const mockRes = {
|
|
150
177
|
statusCode: error.response.status,
|
|
@@ -152,14 +179,14 @@ class UnnboundLogger {
|
|
|
152
179
|
body: (0, logger_utils_1.safeJsonParse)(error.response.data),
|
|
153
180
|
startTime: startTime,
|
|
154
181
|
traceId: trace_context_1.traceContext.getTraceId(),
|
|
155
|
-
requestId: requestId
|
|
182
|
+
requestId: requestId,
|
|
156
183
|
},
|
|
157
|
-
getHeaders: () => error.response.headers || {}
|
|
184
|
+
getHeaders: () => error.response.headers || {},
|
|
158
185
|
};
|
|
159
186
|
this.httpResponse(mockRes, mockReq, {
|
|
160
187
|
requestId,
|
|
161
188
|
duration,
|
|
162
|
-
traceId: trace_context_1.traceContext.getTraceId()
|
|
189
|
+
traceId: trace_context_1.traceContext.getTraceId(),
|
|
163
190
|
});
|
|
164
191
|
}
|
|
165
192
|
else {
|
|
@@ -172,11 +199,11 @@ class UnnboundLogger {
|
|
|
172
199
|
},
|
|
173
200
|
error: error.message,
|
|
174
201
|
requestId,
|
|
175
|
-
traceId: trace_context_1.traceContext.getTraceId()
|
|
202
|
+
traceId: trace_context_1.traceContext.getTraceId(),
|
|
176
203
|
});
|
|
177
204
|
}
|
|
178
205
|
return Promise.reject(error);
|
|
179
|
-
}
|
|
206
|
+
},
|
|
180
207
|
};
|
|
181
208
|
this.workflowId = process.env.UNNBOUND_WORKFLOW_ID || '';
|
|
182
209
|
this.workflowUrl = process.env.UNNBOUND_WORKFLOW_URL || '';
|
|
@@ -188,13 +215,18 @@ class UnnboundLogger {
|
|
|
188
215
|
// Create Pino logger
|
|
189
216
|
this.logger = (0, pino_1.default)({
|
|
190
217
|
level: 'info',
|
|
191
|
-
base: {
|
|
192
|
-
|
|
193
|
-
|
|
218
|
+
base: {
|
|
219
|
+
// Disable all default base fields (pid, hostname) and add our own
|
|
220
|
+
workflowId: this.workflowId,
|
|
221
|
+
serviceId: this.serviceId,
|
|
222
|
+
deploymentId: this.deploymentId,
|
|
223
|
+
},
|
|
224
|
+
// Let CloudWatch handle timestamps
|
|
225
|
+
timestamp: false,
|
|
226
|
+
// Change message field from 'msg' to 'messages'
|
|
227
|
+
messageKey: 'messages',
|
|
194
228
|
formatters: {
|
|
195
|
-
level: (
|
|
196
|
-
return { level: label };
|
|
197
|
-
},
|
|
229
|
+
level: (level) => ({ level }),
|
|
198
230
|
},
|
|
199
231
|
});
|
|
200
232
|
}
|
|
@@ -205,7 +237,7 @@ class UnnboundLogger {
|
|
|
205
237
|
* @returns boolean indicating if the path should be ignored
|
|
206
238
|
*/
|
|
207
239
|
shouldIgnorePath(path, patterns) {
|
|
208
|
-
return patterns.some(pattern => {
|
|
240
|
+
return patterns.some((pattern) => {
|
|
209
241
|
// Convert glob pattern to regex
|
|
210
242
|
const regexPattern = pattern
|
|
211
243
|
.replace(/\./g, '\\.') // Escape dots
|
|
@@ -239,15 +271,10 @@ class UnnboundLogger {
|
|
|
239
271
|
deploymentId: this.deploymentId,
|
|
240
272
|
};
|
|
241
273
|
if (message instanceof Error) {
|
|
242
|
-
const error = {
|
|
243
|
-
name: message.name,
|
|
244
|
-
message: message.message,
|
|
245
|
-
stack: message.stack,
|
|
246
|
-
};
|
|
247
274
|
logEntry = {
|
|
248
275
|
...baseEntry,
|
|
249
276
|
message: message.name,
|
|
250
|
-
error,
|
|
277
|
+
error: message,
|
|
251
278
|
...(hasRestOptions && { data: restOptions }),
|
|
252
279
|
};
|
|
253
280
|
}
|
|
@@ -380,7 +407,7 @@ class UnnboundLogger {
|
|
|
380
407
|
const workflowId = res.locals.workflowId || this.workflowId;
|
|
381
408
|
const serviceId = res.locals.serviceId || this.serviceId;
|
|
382
409
|
const traceId = res.locals.traceId || options.traceId || trace_context_1.traceContext.getTraceId() || (0, uuid_1.v4)();
|
|
383
|
-
const duration = options.duration ||
|
|
410
|
+
const duration = options.duration || Date.now() - startTime;
|
|
384
411
|
// Determine log level based on status code
|
|
385
412
|
let level = options.level || 'info';
|
|
386
413
|
if (!options.level) {
|
|
@@ -414,33 +441,6 @@ class UnnboundLogger {
|
|
|
414
441
|
this.logger[level](logData, logMessage);
|
|
415
442
|
return logEntry;
|
|
416
443
|
}
|
|
417
|
-
/**
|
|
418
|
-
* Logs an SFTP transaction
|
|
419
|
-
* @param operation - SFTP operation details
|
|
420
|
-
* @param options - Additional logging options
|
|
421
|
-
*/
|
|
422
|
-
sftpTransaction(operation, options = {}) {
|
|
423
|
-
const logId = (0, uuid_1.v4)();
|
|
424
|
-
const traceId = options.traceId || trace_context_1.traceContext.getTraceId() || (0, uuid_1.v4)();
|
|
425
|
-
const requestId = options.requestId || (0, uuid_1.v4)();
|
|
426
|
-
const duration = options.duration || (options.startTime ? Date.now() - options.startTime : 0);
|
|
427
|
-
const level = operation.status === 'success' ? 'info' : 'error';
|
|
428
|
-
const logEntry = {
|
|
429
|
-
logId,
|
|
430
|
-
type: 'sftpTransaction',
|
|
431
|
-
message: `SFTP ${operation.operation} ${operation.status} - ${operation.path}`,
|
|
432
|
-
workflowId: this.workflowId,
|
|
433
|
-
serviceId: this.serviceId,
|
|
434
|
-
traceId,
|
|
435
|
-
requestId,
|
|
436
|
-
deploymentId: this.deploymentId,
|
|
437
|
-
duration,
|
|
438
|
-
sftp: operation,
|
|
439
|
-
};
|
|
440
|
-
const { message: logMessage, ...logData } = logEntry;
|
|
441
|
-
this.logger[level](logData, logMessage);
|
|
442
|
-
return logEntry;
|
|
443
|
-
}
|
|
444
444
|
/**
|
|
445
445
|
* Logs a database query transaction
|
|
446
446
|
* @param query - Database query details
|
|
@@ -470,3 +470,6 @@ class UnnboundLogger {
|
|
|
470
470
|
}
|
|
471
471
|
}
|
|
472
472
|
exports.UnnboundLogger = UnnboundLogger;
|
|
473
|
+
process.on('uncaughtException', (err, origin) => {
|
|
474
|
+
exports.logger.error({ err, origin }, `Uncaught exception.`);
|
|
475
|
+
});
|
|
@@ -3,48 +3,153 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.httpStatusDetails = void 0;
|
|
4
4
|
exports.getStatusMessage = getStatusMessage;
|
|
5
5
|
exports.httpStatusDetails = {
|
|
6
|
-
100: {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
100: {
|
|
7
|
+
message: 'Continue',
|
|
8
|
+
description: 'The server has received the request headers, and the client should proceed to send the request body',
|
|
9
|
+
},
|
|
10
|
+
101: {
|
|
11
|
+
message: 'Switching Protocols',
|
|
12
|
+
description: 'The requester has asked the server to switch protocols',
|
|
13
|
+
},
|
|
14
|
+
103: {
|
|
15
|
+
message: 'Early Hints',
|
|
16
|
+
description: 'Used with the Link header to allow the browser to start preloading resources while the server prepares a response',
|
|
17
|
+
},
|
|
9
18
|
200: { message: 'OK', description: 'The request is OK' },
|
|
10
|
-
201: {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
201: {
|
|
20
|
+
message: 'Created',
|
|
21
|
+
description: 'The request has been fulfilled, and a new resource is created',
|
|
22
|
+
},
|
|
23
|
+
202: {
|
|
24
|
+
message: 'Accepted',
|
|
25
|
+
description: 'The request has been accepted for processing, but the processing has not been completed',
|
|
26
|
+
},
|
|
27
|
+
203: {
|
|
28
|
+
message: 'Non-Authoritative Information',
|
|
29
|
+
description: 'The request has been successfully processed, but is returning information that may be from another source',
|
|
30
|
+
},
|
|
31
|
+
204: {
|
|
32
|
+
message: 'No Content',
|
|
33
|
+
description: 'The request has been successfully processed, but is not returning any content',
|
|
34
|
+
},
|
|
35
|
+
205: {
|
|
36
|
+
message: 'Reset Content',
|
|
37
|
+
description: 'The request has been successfully processed, but is not returning any content, and requires that the requester reset the document view',
|
|
38
|
+
},
|
|
39
|
+
206: {
|
|
40
|
+
message: 'Partial Content',
|
|
41
|
+
description: 'The server is delivering only part of the resource due to a range header sent by the client',
|
|
42
|
+
},
|
|
43
|
+
300: {
|
|
44
|
+
message: 'Multiple Choices',
|
|
45
|
+
description: 'A link list. The user can select a link and go to that location. Maximum five addresses',
|
|
46
|
+
},
|
|
17
47
|
301: { message: 'Moved Permanently', description: 'The requested page has moved to a new URL' },
|
|
18
48
|
302: { message: 'Found', description: 'The requested page has moved temporarily to a new URL' },
|
|
19
|
-
303: {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
49
|
+
303: {
|
|
50
|
+
message: 'See Other',
|
|
51
|
+
description: 'The requested page can be found under a different URL',
|
|
52
|
+
},
|
|
53
|
+
304: {
|
|
54
|
+
message: 'Not Modified',
|
|
55
|
+
description: 'Indicates the requested page has not been modified since last requested',
|
|
56
|
+
},
|
|
57
|
+
307: {
|
|
58
|
+
message: 'Temporary Redirect',
|
|
59
|
+
description: 'The requested page has moved temporarily to a new URL',
|
|
60
|
+
},
|
|
61
|
+
308: {
|
|
62
|
+
message: 'Permanent Redirect',
|
|
63
|
+
description: 'The requested page has moved permanently to a new URL',
|
|
64
|
+
},
|
|
23
65
|
400: { message: 'Bad Request', description: 'The request cannot be fulfilled due to bad syntax' },
|
|
24
|
-
401: {
|
|
66
|
+
401: {
|
|
67
|
+
message: 'Unauthorized',
|
|
68
|
+
description: 'The request was a legal request, but the server is refusing to respond to it. For use when authentication is possible but has failed or not yet been provided',
|
|
69
|
+
},
|
|
25
70
|
402: { message: 'Payment Required', description: 'Reserved for future use' },
|
|
26
|
-
403: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
71
|
+
403: {
|
|
72
|
+
message: 'Forbidden',
|
|
73
|
+
description: 'The request was a legal request, but the server is refusing to respond to it',
|
|
74
|
+
},
|
|
75
|
+
404: {
|
|
76
|
+
message: 'Not Found',
|
|
77
|
+
description: 'The requested page could not be found but may be available again in the future',
|
|
78
|
+
},
|
|
79
|
+
405: {
|
|
80
|
+
message: 'Method Not Allowed',
|
|
81
|
+
description: 'A request was made of a page using a request method not supported by that page',
|
|
82
|
+
},
|
|
83
|
+
406: {
|
|
84
|
+
message: 'Not Acceptable',
|
|
85
|
+
description: 'The server can only generate a response that is not accepted by the client',
|
|
86
|
+
},
|
|
87
|
+
407: {
|
|
88
|
+
message: 'Proxy Authentication Required',
|
|
89
|
+
description: 'The client must first authenticate itself with the proxy',
|
|
90
|
+
},
|
|
31
91
|
408: { message: 'Request Timeout', description: 'The server timed out waiting for the request' },
|
|
32
|
-
409: {
|
|
92
|
+
409: {
|
|
93
|
+
message: 'Conflict',
|
|
94
|
+
description: 'The request could not be completed because of a conflict in the request',
|
|
95
|
+
},
|
|
33
96
|
410: { message: 'Gone', description: 'The requested page is no longer available' },
|
|
34
|
-
411: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
97
|
+
411: {
|
|
98
|
+
message: 'Length Required',
|
|
99
|
+
description: 'The "Content-Length" is not defined. The server will not accept the request without it',
|
|
100
|
+
},
|
|
101
|
+
412: {
|
|
102
|
+
message: 'Precondition Failed',
|
|
103
|
+
description: 'The precondition given in the request evaluated to false by the server',
|
|
104
|
+
},
|
|
105
|
+
413: {
|
|
106
|
+
message: 'Request Too Large',
|
|
107
|
+
description: 'The server will not accept the request, because the request entity is too large',
|
|
108
|
+
},
|
|
109
|
+
414: {
|
|
110
|
+
message: 'Request-URI Too Long',
|
|
111
|
+
description: 'The server will not accept the request, because the URI is too long. Occurs when you convert a POST request to a GET request with a long query information',
|
|
112
|
+
},
|
|
113
|
+
415: {
|
|
114
|
+
message: 'Unsupported Media Type',
|
|
115
|
+
description: 'The server will not accept the request, because the media type is not supported',
|
|
116
|
+
},
|
|
117
|
+
416: {
|
|
118
|
+
message: 'Range Not Satisfiable',
|
|
119
|
+
description: 'The client has asked for a portion of the file, but the server cannot supply that portion',
|
|
120
|
+
},
|
|
121
|
+
417: {
|
|
122
|
+
message: 'Expectation Failed',
|
|
123
|
+
description: 'The server cannot meet the requirements of the Expect request-header field',
|
|
124
|
+
},
|
|
125
|
+
500: {
|
|
126
|
+
message: 'Internal Server Error',
|
|
127
|
+
description: 'A generic error message, given when no more specific message is suitable',
|
|
128
|
+
},
|
|
129
|
+
501: {
|
|
130
|
+
message: 'Not Implemented',
|
|
131
|
+
description: 'The server either does not recognize the request method, or it lacks the ability to fulfill the request',
|
|
132
|
+
},
|
|
133
|
+
502: {
|
|
134
|
+
message: 'Bad Gateway',
|
|
135
|
+
description: 'The server was acting as a gateway or proxy and received an invalid response from the upstream server',
|
|
136
|
+
},
|
|
137
|
+
503: {
|
|
138
|
+
message: 'Service Unavailable',
|
|
139
|
+
description: 'The server is currently unavailable (overloaded or down)',
|
|
140
|
+
},
|
|
141
|
+
504: {
|
|
142
|
+
message: 'Gateway Timeout',
|
|
143
|
+
description: 'The server was acting as a gateway or proxy and did not receive a timely response from the upstream server',
|
|
144
|
+
},
|
|
145
|
+
505: {
|
|
146
|
+
message: 'HTTP Version Not Supported',
|
|
147
|
+
description: 'The server does not support the HTTP protocol version used in the request',
|
|
148
|
+
},
|
|
149
|
+
511: {
|
|
150
|
+
message: 'Network Authentication Required',
|
|
151
|
+
description: 'The client needs to authenticate to gain network access',
|
|
152
|
+
},
|
|
48
153
|
};
|
|
49
154
|
function getStatusMessage(statusCode) {
|
|
50
155
|
const status = exports.httpStatusDetails[statusCode];
|
|
@@ -19,7 +19,7 @@ export declare function clearTraceId(workflowId: string): void;
|
|
|
19
19
|
* @param headers The original headers object.
|
|
20
20
|
* @returns A new object containing only the headers from the allow-list.
|
|
21
21
|
*/
|
|
22
|
-
export declare function filterHeaders(headers
|
|
22
|
+
export declare function filterHeaders(headers?: Record<string, any>): Record<string, string>;
|
|
23
23
|
/**
|
|
24
24
|
* Safely parses JSON strings, returning the original data if parsing fails or if it's not a string.
|
|
25
25
|
* @param data The data to potentially parse as JSON.
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a path matches any of the ignore patterns
|
|
3
|
+
* @param path - The path to check
|
|
4
|
+
* @param patterns - Array of glob patterns to match against
|
|
5
|
+
* @returns boolean indicating if the path should be ignored
|
|
6
|
+
*/
|
|
7
|
+
export declare const shouldIgnorePath: (path: string, patterns: string[]) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Safely parses JSON strings, returning the original data if parsing fails or if it's not a string.
|
|
10
|
+
* @param data The data to potentially parse as JSON.
|
|
11
|
+
* @returns Parsed JSON object or the original data.
|
|
12
|
+
*/
|
|
13
|
+
export declare function safeJsonParse(data: any): any;
|
|
14
|
+
/**
|
|
15
|
+
* Normalizes IP addresses by removing IPv6 mapping prefix for IPv4 addresses.
|
|
16
|
+
* @param ip The IP address to normalize.
|
|
17
|
+
* @returns Normalized IP address string.
|
|
18
|
+
*/
|
|
19
|
+
export declare function normalizeIp(ip: string | undefined): string | undefined;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldIgnorePath = void 0;
|
|
4
|
+
exports.safeJsonParse = safeJsonParse;
|
|
5
|
+
exports.normalizeIp = normalizeIp;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a path matches any of the ignore patterns
|
|
8
|
+
* @param path - The path to check
|
|
9
|
+
* @param patterns - Array of glob patterns to match against
|
|
10
|
+
* @returns boolean indicating if the path should be ignored
|
|
11
|
+
*/
|
|
12
|
+
const shouldIgnorePath = (path, patterns) => {
|
|
13
|
+
return patterns.some((pattern) => {
|
|
14
|
+
// Convert glob pattern to regex
|
|
15
|
+
const regexPattern = pattern
|
|
16
|
+
.replace(/\./g, '\\.') // Escape dots
|
|
17
|
+
.replace(/\*/g, '.*') // Convert * to .*
|
|
18
|
+
.replace(/\?/g, '.'); // Convert ? to .
|
|
19
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
20
|
+
return regex.test(path);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
exports.shouldIgnorePath = shouldIgnorePath;
|
|
24
|
+
/**
|
|
25
|
+
* Safely parses JSON strings, returning the original data if parsing fails or if it's not a string.
|
|
26
|
+
* @param data The data to potentially parse as JSON.
|
|
27
|
+
* @returns Parsed JSON object or the original data.
|
|
28
|
+
*/
|
|
29
|
+
function safeJsonParse(data) {
|
|
30
|
+
if (typeof data === 'string') {
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(data);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes IP addresses by removing IPv6 mapping prefix for IPv4 addresses.
|
|
42
|
+
* @param ip The IP address to normalize.
|
|
43
|
+
* @returns Normalized IP address string.
|
|
44
|
+
*/
|
|
45
|
+
function normalizeIp(ip) {
|
|
46
|
+
if (!ip)
|
|
47
|
+
return ip;
|
|
48
|
+
// Remove IPv4-mapped IPv6 prefix (::ffff:) to get clean IPv4 address
|
|
49
|
+
if (ip.startsWith('::ffff:')) {
|
|
50
|
+
return ip.substring(7);
|
|
51
|
+
}
|
|
52
|
+
return ip;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unnbound-logger-sdk",
|
|
3
|
-
"version": "2.0.10",
|
|
4
3
|
"description": "A structured logging library with TypeScript support using Pino. Provides consistent, well-typed logging with automatic logId, workflowId, traceId, and deploymentId tracking across operational contexts.",
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc",
|
|
9
|
-
"test": "npx jest",
|
|
10
|
-
"test:coverage": "npx jest --coverage",
|
|
11
|
-
"test:watch": "npx jest --watch",
|
|
12
|
-
"lint": "eslint src/**/*.ts",
|
|
13
|
-
"lint:fix": "eslint . --ext .ts --fix",
|
|
14
|
-
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
15
|
-
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
16
|
-
"prepublishOnly": "npm run build && npm test",
|
|
17
|
-
"check-coverage": "ts-node scripts/check-coverage.ts",
|
|
18
|
-
"start:example:node-app": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' examples/node-app.ts",
|
|
19
|
-
"start:example:basic-usage": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' examples/basic-usage.ts"
|
|
20
|
-
},
|
|
21
7
|
"keywords": [
|
|
22
8
|
"logging",
|
|
23
9
|
"typescript",
|
|
@@ -33,11 +19,11 @@
|
|
|
33
19
|
"license": "MIT",
|
|
34
20
|
"repository": {
|
|
35
21
|
"type": "git",
|
|
36
|
-
"url": "https://github.com/unnbound
|
|
22
|
+
"url": "https://github.com/unnbounddev/unnbound-sdks.git"
|
|
37
23
|
},
|
|
38
|
-
"homepage": "https://github.com/unnbound
|
|
24
|
+
"homepage": "https://github.com/unnbounddev/unnbound-sdks#readme",
|
|
39
25
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/unnbound/
|
|
26
|
+
"url": "https://github.com/unnbounddev/unnbound-sdks/issues"
|
|
41
27
|
},
|
|
42
28
|
"dependencies": {
|
|
43
29
|
"axios": "^1.0.0",
|
|
@@ -49,19 +35,7 @@
|
|
|
49
35
|
"@types/express": "^4.17.21",
|
|
50
36
|
"@types/jest": "^29.5.12",
|
|
51
37
|
"@types/node": "^20.11.24",
|
|
52
|
-
"@types/uuid": "^9.0.8"
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^7.1.0",
|
|
54
|
-
"@typescript-eslint/parser": "^7.1.0",
|
|
55
|
-
"cors": "^2.8.5",
|
|
56
|
-
"dotenv": "^16.5.0",
|
|
57
|
-
"eslint": "^8.57.0",
|
|
58
|
-
"eslint-config-prettier": "^10.1.5",
|
|
59
|
-
"jest": "^29.7.0",
|
|
60
|
-
"nodemon": "^3.1.10",
|
|
61
|
-
"prettier": "^3.2.5",
|
|
62
|
-
"ts-jest": "^29.1.2",
|
|
63
|
-
"ts-node": "^10.9.2",
|
|
64
|
-
"typescript": "^5.3.3"
|
|
38
|
+
"@types/uuid": "^9.0.8"
|
|
65
39
|
},
|
|
66
40
|
"peerDependencies": {
|
|
67
41
|
"axios": "^1.0.0",
|
|
@@ -76,15 +50,25 @@
|
|
|
76
50
|
}
|
|
77
51
|
},
|
|
78
52
|
"files": [
|
|
79
|
-
"dist
|
|
80
|
-
"dist/index.*",
|
|
81
|
-
"dist/types.*",
|
|
82
|
-
"dist/unnbound-logger.*",
|
|
83
|
-
"dist/utils/**/*",
|
|
53
|
+
"dist/**/*",
|
|
84
54
|
"README.md",
|
|
85
55
|
"LICENSE"
|
|
86
56
|
],
|
|
87
57
|
"engines": {
|
|
88
|
-
"node": ">=
|
|
58
|
+
"node": ">=22.0.0"
|
|
59
|
+
},
|
|
60
|
+
"sideEffects": false,
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc",
|
|
63
|
+
"test": "jest",
|
|
64
|
+
"test:coverage": "jest --coverage",
|
|
65
|
+
"test:watch": "jest --watch",
|
|
66
|
+
"typecheck": "tsc -noEmit",
|
|
67
|
+
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
|
|
68
|
+
"lint:fix": "pnpm lint --fix",
|
|
69
|
+
"format": "prettier --write .",
|
|
70
|
+
"format:check": "prettier --check .",
|
|
71
|
+
"start:example:node-app": "npx tsx --watch examples/node-app.ts",
|
|
72
|
+
"start:example:basic-usage": "npx tsx --watch examples/basic-usage.ts"
|
|
89
73
|
}
|
|
90
|
-
}
|
|
74
|
+
}
|