@togatherlabs/shared-utils 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/dist/constants/index.d.ts +0 -2
- package/dist/constants/index.d.ts.map +0 -1
- package/dist/constants/index.js +0 -2
- package/dist/constants/index.js.map +0 -1
- package/dist/constants/sample.d.ts +0 -4
- package/dist/constants/sample.d.ts.map +0 -1
- package/dist/constants/sample.js +0 -4
- package/dist/constants/sample.js.map +0 -1
- package/dist/helpers/formatDate.d.ts +0 -2
- package/dist/helpers/formatDate.d.ts.map +0 -1
- package/dist/helpers/formatDate.js +0 -11
- package/dist/helpers/formatDate.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -2
- package/dist/helpers/index.d.ts.map +0 -1
- package/dist/helpers/index.js +0 -2
- package/dist/helpers/index.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/logger/ILogger.d.ts +0 -97
- package/dist/logger/ILogger.d.ts.map +0 -1
- package/dist/logger/ILogger.js +0 -2
- package/dist/logger/ILogger.js.map +0 -1
- package/dist/logger/index.d.ts +0 -3
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js +0 -2
- package/dist/logger/index.js.map +0 -1
- package/dist/logger/logger.d.ts +0 -54
- package/dist/logger/logger.d.ts.map +0 -1
- package/dist/logger/logger.js +0 -141
- package/dist/logger/logger.js.map +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/user.d.ts +0 -6
- package/dist/types/user.d.ts.map +0 -1
- package/dist/types/user.js +0 -2
- package/dist/types/user.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@togatherlabs/shared-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Shared utilities for Togather services including logger, validators, and common helpers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
+
"@tsconfig/node22": "^22.0.5",
|
|
52
53
|
"inversify": "^7.10.4",
|
|
53
54
|
"pino": "^10.1.0"
|
|
54
55
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
package/dist/constants/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample.d.ts","sourceRoot":"","sources":["../../src/constants/sample.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;CAElB,CAAC"}
|
package/dist/constants/sample.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sample.js","sourceRoot":"","sources":["../../src/constants/sample.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,IAAI,EAAE,GAAG;CACT,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/helpers/formatDate.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,SAAU,GAAG,MAAM,CAU/D"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function formatDate(date, locale = 'en-IN') {
|
|
2
|
-
if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
|
|
3
|
-
throw new Error('Invalid Date');
|
|
4
|
-
}
|
|
5
|
-
return date.toLocaleDateString(locale, {
|
|
6
|
-
year: 'numeric',
|
|
7
|
-
month: 'short',
|
|
8
|
-
day: 'numeric',
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=formatDate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.js","sourceRoot":"","sources":["../../src/helpers/formatDate.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,MAAM,GAAG,OAAO;IACtD,IAAI,CAAC,CAAC,IAAI,YAAY,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;IACjC,CAAC;IAED,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE;QACtC,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,OAAO;QACd,GAAG,EAAE,SAAS;KACd,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/helpers/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/helpers/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AACvB,cAAc,mBAAmB,CAAC"}
|
package/dist/logger/ILogger.d.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger interface for structured logging.
|
|
3
|
-
*/
|
|
4
|
-
export interface ILogger {
|
|
5
|
-
/**
|
|
6
|
-
* Log informational messages
|
|
7
|
-
*
|
|
8
|
-
* @param labels - Context object that can include:
|
|
9
|
-
* - `label`: string | string[] - Categorization labels (e.g., class name, method name, operation type)
|
|
10
|
-
* - Any other contextual data (userId, requestId, etc.)
|
|
11
|
-
* @param msg - Human-readable log message (supports string interpolation with args)
|
|
12
|
-
* @param args - Values for string interpolation in the message (e.g., logger.info({}, 'User %s logged in', userId))
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* logger.info({ label: 'UserService' }, 'User created');
|
|
16
|
-
* logger.info({ label: ['UserService', 'createUser'] }, 'Creating user');
|
|
17
|
-
* logger.info({ userId: '123', label: 'UserService.createUser' }, 'User created successfully');
|
|
18
|
-
* logger.info({ label: 'UserService' }, 'User %s created with email %s', userId, email);
|
|
19
|
-
*/
|
|
20
|
-
info(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
21
|
-
/**
|
|
22
|
-
* Log warning messages
|
|
23
|
-
*
|
|
24
|
-
* @param labels - Context object that can include:
|
|
25
|
-
* - `label`: string | string[] - Categorization labels (e.g., class name, method name, operation type)
|
|
26
|
-
* - Any other contextual data (userId, requestId, etc.)
|
|
27
|
-
* @param msg - Human-readable log message (supports string interpolation with args)
|
|
28
|
-
* @param args - Values for string interpolation in the message
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* logger.warn({ label: 'RateLimiter' }, 'Rate limit approaching');
|
|
32
|
-
* logger.warn({ userId: '123', label: ['AuthService', 'login'] }, 'Multiple failed attempts');
|
|
33
|
-
* logger.warn({ label: 'RateLimiter' }, 'User %s exceeded %d requests', userId, maxRequests);
|
|
34
|
-
*/
|
|
35
|
-
warn(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
36
|
-
/**
|
|
37
|
-
* Log error messages
|
|
38
|
-
*
|
|
39
|
-
* @param labels - Context object that can include:
|
|
40
|
-
* - `label`: string | string[] - Categorization labels (e.g., class name, method name, operation type)
|
|
41
|
-
* - `err`: Error - The error object for proper serialization
|
|
42
|
-
* - Any other contextual data (userId, requestId, etc.)
|
|
43
|
-
* @param msg - Human-readable log message (supports string interpolation with args)
|
|
44
|
-
* @param args - Values for string interpolation in the message
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* logger.error({ err, label: 'DatabaseService' }, 'Connection failed');
|
|
48
|
-
* logger.error({ err, userId: '123', label: ['UserRepository', 'findById'] }, 'Query failed');
|
|
49
|
-
* logger.error({ err, label: 'DatabaseService' }, 'Failed to connect to %s on port %d', host, port);
|
|
50
|
-
*/
|
|
51
|
-
error(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
52
|
-
/**
|
|
53
|
-
* Log debug messages
|
|
54
|
-
*
|
|
55
|
-
* @param labels - Context object that can include:
|
|
56
|
-
* - `label`: string | string[] - Categorization labels (e.g., class name, method name, operation type)
|
|
57
|
-
* - Any other contextual data (userId, requestId, etc.)
|
|
58
|
-
* @param msg - Human-readable log message (supports string interpolation with args)
|
|
59
|
-
* @param args - Values for string interpolation in the message
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* logger.debug({ label: 'CacheService' }, 'Cache hit');
|
|
63
|
-
* logger.debug({ cacheKey: 'user:123', label: ['CacheService', 'get'] }, 'Retrieved from cache');
|
|
64
|
-
* logger.debug({ label: 'CacheService' }, 'Cache hit for key %s in %dms', cacheKey, duration);
|
|
65
|
-
*/
|
|
66
|
-
debug(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
67
|
-
/**
|
|
68
|
-
* Log fatal messages (highest severity)
|
|
69
|
-
*
|
|
70
|
-
* @param labels - Context object that can include:
|
|
71
|
-
* - `label`: string | string[] - Categorization labels (e.g., class name, method name, operation type)
|
|
72
|
-
* - `err`: Error - The error object for proper serialization
|
|
73
|
-
* - Any other contextual data (userId, requestId, etc.)
|
|
74
|
-
* @param msg - Human-readable log message (supports string interpolation with args)
|
|
75
|
-
* @param args - Values for string interpolation in the message
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* logger.fatal({ err, label: 'Application' }, 'Critical system failure');
|
|
79
|
-
* logger.fatal({ err, label: 'Application' }, 'System crashed after %d retries', retryCount);
|
|
80
|
-
*/
|
|
81
|
-
fatal(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
82
|
-
/**
|
|
83
|
-
* Log trace messages (lowest severity)
|
|
84
|
-
*
|
|
85
|
-
* @param labels - Context object that can include:
|
|
86
|
-
* - `label`: string | string[] - Categorization labels (e.g., class name, method name, operation type)
|
|
87
|
-
* - Any other contextual data (userId, requestId, etc.)
|
|
88
|
-
* @param msg - Human-readable log message (supports string interpolation with args)
|
|
89
|
-
* @param args - Values for string interpolation in the message
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* logger.trace({ label: ['UserService', 'createUser', 'validation'] }, 'Validating input');
|
|
93
|
-
* logger.trace({ label: 'UserService' }, 'Step %d: %s', stepNumber, stepName);
|
|
94
|
-
*/
|
|
95
|
-
trace(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=ILogger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ILogger.d.ts","sourceRoot":"","sources":["../../src/logger/ILogger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB;;;;;;;;;;;;;;OAcG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEtE;;;;;;;;;;;;;OAaG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEtE;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEvE;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEvE;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAEvE;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACvE"}
|
package/dist/logger/ILogger.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ILogger.js","sourceRoot":"","sources":["../../src/logger/ILogger.ts"],"names":[],"mappings":""}
|
package/dist/logger/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/logger/index.js
DELETED
package/dist/logger/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAqB,MAAM,aAAa,CAAC"}
|
package/dist/logger/logger.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type LoggerOptions } from 'pino';
|
|
2
|
-
import type { ILogger } from './ILogger.js';
|
|
3
|
-
export interface LoggerConfig {
|
|
4
|
-
/** Node environment (e.g., 'development', 'production', 'test') */
|
|
5
|
-
nodeEnv?: string;
|
|
6
|
-
/** Log level (e.g., 'info', 'debug', 'warn', 'error') */
|
|
7
|
-
logLevel?: string;
|
|
8
|
-
/** Service name for log context */
|
|
9
|
-
serviceName?: string;
|
|
10
|
-
/** Hostname override */
|
|
11
|
-
hostname?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface LoggerParams {
|
|
14
|
-
options?: LoggerOptions;
|
|
15
|
-
config?: LoggerConfig;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Minimal - uses defaults
|
|
21
|
-
* const logger = new Logger();
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* // With environment config from service
|
|
25
|
-
* const logger = new Logger(undefined, {
|
|
26
|
-
* nodeEnv: process.env.NODE_ENV,
|
|
27
|
-
* logLevel: process.env.LOG_LEVEL,
|
|
28
|
-
* serviceName: process.env.SERVICE_NAME
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* // With custom logger options
|
|
33
|
-
* const logger = new Logger({
|
|
34
|
-
* level: 'debug',
|
|
35
|
-
* base: { service: 'my-service', version: '1.0.0' }
|
|
36
|
-
* });
|
|
37
|
-
*/
|
|
38
|
-
export declare class Logger implements ILogger {
|
|
39
|
-
private logger;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a new Logger instance.
|
|
42
|
-
*
|
|
43
|
-
* @param options - logger options for advanced configuration
|
|
44
|
-
* @param config - Environment configuration passed from the service
|
|
45
|
-
*/
|
|
46
|
-
constructor(params?: LoggerParams);
|
|
47
|
-
info(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
48
|
-
warn(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
49
|
-
error(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
50
|
-
debug(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
51
|
-
fatal(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
52
|
-
trace(labels: object | string, msg?: string, ...args: unknown[]): void;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAa,EAAqC,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAEnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,MAAM,WAAW,YAAY;IAC5B,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;CACtB;AACD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBACa,MAAO,YAAW,OAAO;IACrC,OAAO,CAAC,MAAM,CAAqB;IAEnC;;;;;OAKG;gBACS,MAAM,CAAC,EAAE,YAAY;IAoFjC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIrE,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAIrE,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAItE,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAItE,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAItE,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CAGtE"}
|
package/dist/logger/logger.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import pino from 'pino';
|
|
11
|
-
import { injectable } from 'inversify';
|
|
12
|
-
import { hostname } from 'node:os';
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Minimal - uses defaults
|
|
17
|
-
* const logger = new Logger();
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // With environment config from service
|
|
21
|
-
* const logger = new Logger(undefined, {
|
|
22
|
-
* nodeEnv: process.env.NODE_ENV,
|
|
23
|
-
* logLevel: process.env.LOG_LEVEL,
|
|
24
|
-
* serviceName: process.env.SERVICE_NAME
|
|
25
|
-
* });
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* // With custom logger options
|
|
29
|
-
* const logger = new Logger({
|
|
30
|
-
* level: 'debug',
|
|
31
|
-
* base: { service: 'my-service', version: '1.0.0' }
|
|
32
|
-
* });
|
|
33
|
-
*/
|
|
34
|
-
let Logger = class Logger {
|
|
35
|
-
logger;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new Logger instance.
|
|
38
|
-
*
|
|
39
|
-
* @param options - logger options for advanced configuration
|
|
40
|
-
* @param config - Environment configuration passed from the service
|
|
41
|
-
*/
|
|
42
|
-
constructor(params) {
|
|
43
|
-
const { options, config } = params || {};
|
|
44
|
-
const nodeEnv = config?.nodeEnv || 'development';
|
|
45
|
-
const isDevelopment = nodeEnv === 'development';
|
|
46
|
-
const isProduction = nodeEnv === 'production';
|
|
47
|
-
// Build base object conditionally to avoid undefined values
|
|
48
|
-
const baseObject = {
|
|
49
|
-
hostname: config?.hostname || hostname(),
|
|
50
|
-
environment: nodeEnv,
|
|
51
|
-
};
|
|
52
|
-
// Only add service if it's provided
|
|
53
|
-
if (config?.serviceName) {
|
|
54
|
-
baseObject.service = config.serviceName;
|
|
55
|
-
}
|
|
56
|
-
const defaultOptions = {
|
|
57
|
-
level: config?.logLevel || 'info',
|
|
58
|
-
base: baseObject,
|
|
59
|
-
timestamp: pino.stdTimeFunctions.isoTime,
|
|
60
|
-
// Error serialization for proper error logging
|
|
61
|
-
serializers: {
|
|
62
|
-
err: pino.stdSerializers.err,
|
|
63
|
-
error: pino.stdSerializers.err,
|
|
64
|
-
req: pino.stdSerializers.req,
|
|
65
|
-
res: pino.stdSerializers.res,
|
|
66
|
-
},
|
|
67
|
-
// Redact sensitive information in production
|
|
68
|
-
redact: {
|
|
69
|
-
paths: [
|
|
70
|
-
'password',
|
|
71
|
-
'*.password',
|
|
72
|
-
'token',
|
|
73
|
-
'*.token',
|
|
74
|
-
'accessToken',
|
|
75
|
-
'*.accessToken',
|
|
76
|
-
'refreshToken',
|
|
77
|
-
'*.refreshToken',
|
|
78
|
-
'secret',
|
|
79
|
-
'*.secret',
|
|
80
|
-
'authorization',
|
|
81
|
-
'*.authorization',
|
|
82
|
-
'cookie',
|
|
83
|
-
'*.cookie',
|
|
84
|
-
'apiKey',
|
|
85
|
-
'*.apiKey',
|
|
86
|
-
],
|
|
87
|
-
remove: isProduction, // Remove in production, mask in development
|
|
88
|
-
},
|
|
89
|
-
// Pretty printing for development
|
|
90
|
-
transport: isDevelopment
|
|
91
|
-
? {
|
|
92
|
-
target: 'pino-pretty',
|
|
93
|
-
options: {
|
|
94
|
-
colorize: true,
|
|
95
|
-
translateTime: 'HH:MM:ss',
|
|
96
|
-
ignore: 'pid,hostname',
|
|
97
|
-
singleLine: false,
|
|
98
|
-
},
|
|
99
|
-
}
|
|
100
|
-
: undefined,
|
|
101
|
-
};
|
|
102
|
-
const mergedOptions = {
|
|
103
|
-
...defaultOptions,
|
|
104
|
-
...options,
|
|
105
|
-
base: {
|
|
106
|
-
...defaultOptions.base,
|
|
107
|
-
...(options?.base || {}),
|
|
108
|
-
},
|
|
109
|
-
serializers: {
|
|
110
|
-
...defaultOptions.serializers,
|
|
111
|
-
...(options?.serializers || {}),
|
|
112
|
-
},
|
|
113
|
-
redact: options?.redact !== undefined ? options.redact : defaultOptions.redact,
|
|
114
|
-
};
|
|
115
|
-
this.logger = pino(mergedOptions);
|
|
116
|
-
}
|
|
117
|
-
info(labels, msg, ...args) {
|
|
118
|
-
this.logger.info(labels, msg, ...args);
|
|
119
|
-
}
|
|
120
|
-
warn(labels, msg, ...args) {
|
|
121
|
-
this.logger.warn(labels, msg, ...args);
|
|
122
|
-
}
|
|
123
|
-
error(labels, msg, ...args) {
|
|
124
|
-
this.logger.error(labels, msg, ...args);
|
|
125
|
-
}
|
|
126
|
-
debug(labels, msg, ...args) {
|
|
127
|
-
this.logger.debug(labels, msg, ...args);
|
|
128
|
-
}
|
|
129
|
-
fatal(labels, msg, ...args) {
|
|
130
|
-
this.logger.fatal(labels, msg, ...args);
|
|
131
|
-
}
|
|
132
|
-
trace(labels, msg, ...args) {
|
|
133
|
-
this.logger.trace(labels, msg, ...args);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
Logger = __decorate([
|
|
137
|
-
injectable(),
|
|
138
|
-
__metadata("design:paramtypes", [Object])
|
|
139
|
-
], Logger);
|
|
140
|
-
export { Logger };
|
|
141
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger/logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,IAA+D,MAAM,MAAM,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAiBnC;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,MAAM,GAAZ,MAAM,MAAM;IACV,MAAM,CAAqB;IAEnC;;;;;OAKG;IACH,YAAY,MAAqB;QAChC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,EAAE,CAAC;QACzC,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,aAAa,CAAC;QACjD,MAAM,aAAa,GAAG,OAAO,KAAK,aAAa,CAAC;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C,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,MAAuB,EAAE,GAAY,EAAE,GAAG,IAAe;QAC9D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC;CACD,CAAA;AApHY,MAAM;IADlB,UAAU,EAAE;;GACA,MAAM,CAoHlB"}
|
package/dist/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
package/dist/types/index.js
DELETED
package/dist/types/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
|
package/dist/types/user.d.ts
DELETED
package/dist/types/user.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.d.ts","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types/user.js
DELETED
package/dist/types/user.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":""}
|