@togatherlabs/shared-utils 1.1.0 → 1.4.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.
Files changed (39) hide show
  1. package/README.md +52 -35
  2. package/dist/constants/index.d.ts +2 -0
  3. package/dist/constants/index.d.ts.map +1 -0
  4. package/dist/constants/index.js +2 -0
  5. package/dist/constants/index.js.map +1 -0
  6. package/dist/constants/sample.d.ts +4 -0
  7. package/dist/constants/sample.d.ts.map +1 -0
  8. package/dist/constants/sample.js +4 -0
  9. package/dist/constants/sample.js.map +1 -0
  10. package/dist/helpers/formatDate.d.ts +2 -0
  11. package/dist/helpers/formatDate.d.ts.map +1 -0
  12. package/dist/helpers/formatDate.js +11 -0
  13. package/dist/helpers/formatDate.js.map +1 -0
  14. package/dist/helpers/index.d.ts +2 -0
  15. package/dist/helpers/index.d.ts.map +1 -0
  16. package/dist/helpers/index.js +2 -0
  17. package/dist/helpers/index.js.map +1 -0
  18. package/dist/logger/ILogger.d.ts +0 -1
  19. package/dist/logger/ILogger.d.ts.map +1 -1
  20. package/dist/logger/index.d.ts +1 -1
  21. package/dist/logger/index.d.ts.map +1 -1
  22. package/dist/logger/index.js +1 -1
  23. package/dist/logger/index.js.map +1 -1
  24. package/dist/logger/logger.d.ts +51 -0
  25. package/dist/logger/logger.d.ts.map +1 -0
  26. package/dist/logger/{PinoLogger.js → logger.js} +27 -17
  27. package/dist/logger/logger.js.map +1 -0
  28. package/dist/types/index.d.ts +2 -0
  29. package/dist/types/index.d.ts.map +1 -0
  30. package/dist/types/index.js +2 -0
  31. package/dist/types/index.js.map +1 -0
  32. package/dist/types/user.d.ts +6 -0
  33. package/dist/types/user.d.ts.map +1 -0
  34. package/dist/types/user.js +2 -0
  35. package/dist/types/user.js.map +1 -0
  36. package/package.json +1 -1
  37. package/dist/logger/PinoLogger.d.ts +0 -31
  38. package/dist/logger/PinoLogger.d.ts.map +0 -1
  39. package/dist/logger/PinoLogger.js.map +0 -1
package/README.md CHANGED
@@ -2,30 +2,34 @@
2
2
 
3
3
  Shared utilities library for Togather services, providing production-grade utilities including logger, validators, and common helpers.
4
4
 
5
- ## 📦 Installation
5
+ # Togather Shared Utilities
6
+
7
+ A collection of shared utilities and helpers for Togather services. This library provides production-ready, reusable components to maintain consistency across the infrastructure.
8
+
9
+ ## Installation
6
10
 
7
11
  ```bash
8
12
  pnpm add @togatherlabs/shared-utils
9
13
  ```
10
14
 
11
- ## 🚀 Features
12
-
13
- ### Logger Module
14
- Production-ready logging built on [Pino](https://getpino.io/) with:
15
- - 🔒 Automatic sensitive data redaction
16
- - 📊 Structured logging with context
17
- - 🎨 Environment-aware (pretty dev logs, JSON production logs)
18
- - 🔧 Fully configurable
19
- - ⚡ High performance
20
-
21
- ## 📚 Available Modules
15
+ ## Available Modules
22
16
 
23
17
  ### Logger
24
18
 
19
+ Production-ready structured logging built on [Pino](https://getpino.io/). Features include automatic sensitive data redaction, environment-aware formatting (pretty logs in development, JSON in production), and full configurability.
20
+
25
21
  ```typescript
26
- import { PinoLogger, ILogger } from '@togatherlabs/shared-utils/logger';
22
+ import { Logger, type LoggerConfig } from '@togatherlabs/shared-utils/logger';
23
+
24
+ // Minimal - uses defaults
25
+ const logger = new Logger();
27
26
 
28
- const logger = new PinoLogger();
27
+ // With environment config from service (recommended)
28
+ const logger = new Logger(undefined, {
29
+ nodeEnv: process.env.NODE_ENV,
30
+ logLevel: process.env.LOG_LEVEL,
31
+ serviceName: process.env.SERVICE_NAME
32
+ });
29
33
 
30
34
  logger.info({ label: 'app' }, 'Application started');
31
35
  logger.error({ err, label: 'database' }, 'Connection failed');
@@ -33,26 +37,39 @@ logger.error({ err, label: 'database' }, 'Connection failed');
33
37
 
34
38
  **Full documentation**: [Logger README](./src/logger/README.md)
35
39
 
36
- ## 🔧 Usage
40
+ ## Usage
37
41
 
38
42
  ### Basic Import
39
43
 
40
44
  ```typescript
41
45
  // Import from main entry point
42
- import { PinoLogger, ILogger } from '@togatherlabs/shared-utils';
46
+ import { Logger, ILogger, type LoggerConfig } from '@togatherlabs/shared-utils';
43
47
 
44
48
  // Or import from specific module
45
- import { PinoLogger, ILogger } from '@togatherlabs/shared-utils/logger';
49
+ import { Logger, ILogger, type LoggerConfig } from '@togatherlabs/shared-utils/logger';
46
50
  ```
47
51
 
48
- ### Environment Variables
52
+ ### Configuration
49
53
 
50
- **All environment variables are optional.** The logger works with sensible defaults:
54
+ **Services pass environment variables via LoggerConfig:**
55
+
56
+ ```typescript
57
+ import { Logger, type LoggerConfig } from '@togatherlabs/shared-utils/logger';
58
+
59
+ const config: LoggerConfig = {
60
+ nodeEnv: process.env.NODE_ENV,
61
+ logLevel: process.env.LOG_LEVEL,
62
+ serviceName: process.env.SERVICE_NAME
63
+ };
64
+
65
+ const logger = new Logger(undefined, config);
66
+ ```
51
67
 
52
- - `NODE_ENV` - Set to `production` in production (default: `development`)
53
- - `SERVICE_NAME` - Your service name for log context (default: `undefined`)
54
- - `LOG_LEVEL` - Log level: `trace`, `debug`, `info`, `warn`, `error`, `fatal` (default: `info`)
55
- - `HOSTNAME` - Override hostname (default: OS hostname)
68
+ **LoggerConfig fields:**
69
+ - `nodeEnv` - Environment: `'development'` (pretty logs) or `'production'` (JSON logs)
70
+ - `logLevel` - Log level (default: `'info'`)
71
+ - `serviceName` - Service name for context
72
+ - `hostname` - Hostname override (optional)
56
73
 
57
74
  See the [Logger README](./src/logger/README.md) for detailed configuration options.
58
75
 
@@ -75,7 +92,7 @@ class UserService {
75
92
  }
76
93
  ```
77
94
 
78
- ## 🛠️ Development
95
+ ## Development
79
96
 
80
97
  ### Setup
81
98
 
@@ -103,7 +120,7 @@ togather-shared-utils/
103
120
  ├── src/
104
121
  │ ├── logger/ # Logger module
105
122
  │ │ ├── ILogger.ts # Logger interface
106
- │ │ ├── PinoLogger.ts # Pino implementation
123
+ │ │ ├── logger.ts # Logger implementation
107
124
  │ │ ├── index.ts # Module exports
108
125
  │ │ └── README.md # Logger documentation
109
126
  │ └── index.ts # Main library exports
@@ -117,7 +134,7 @@ togather-shared-utils/
117
134
  └── README.md
118
135
  ```
119
136
 
120
- ## 📤 Publishing
137
+ ## Publishing
121
138
 
122
139
  ### Version Bumping
123
140
 
@@ -154,7 +171,7 @@ The publish script automatically:
154
171
  - ✅ Publishes to npm
155
172
  - ✅ Creates and pushes git tag
156
173
 
157
- ## 🔄 Workflow
174
+ ## Workflow
158
175
 
159
176
  ### Adding a New Feature
160
177
 
@@ -185,7 +202,7 @@ The publish script automatically:
185
202
  pnpm run publish:npm
186
203
  ```
187
204
 
188
- ## 📋 Commit Convention
205
+ ## Commit Convention
189
206
 
190
207
  This project uses [Conventional Commits](https://www.conventionalcommits.org/):
191
208
 
@@ -208,14 +225,14 @@ This project uses [Conventional Commits](https://www.conventionalcommits.org/):
208
225
  ```
209
226
  feat(logger): Add support for custom log formatters
210
227
 
211
- Added a new option to PinoLogger constructor that allows users to
228
+ Added a new option to Logger constructor that allows users to
212
229
  provide custom formatters for log messages. This enables better
213
230
  integration with external logging services.
214
231
  ```
215
232
 
216
233
  Use `pnpm run commit` for an interactive commit prompt.
217
234
 
218
- ## 🧪 Testing
235
+ ## Testing
219
236
 
220
237
  ```bash
221
238
  # Run tests (when available)
@@ -225,26 +242,26 @@ pnpm test
225
242
  pnpm test:coverage
226
243
  ```
227
244
 
228
- ## 📖 Documentation
245
+ ## Documentation
229
246
 
230
247
  - [Logger Documentation](./src/logger/README.md)
231
248
 
232
- ## 🤝 Contributing
249
+ ## Contributing
233
250
 
234
251
  1. Follow the commit convention
235
252
  2. Write tests for new features
236
253
  3. Update documentation
237
254
  4. Ensure all checks pass before publishing
238
255
 
239
- ## 📄 License
256
+ ## License
240
257
 
241
258
  Internal use only - Togather Infrastructure
242
259
 
243
- ## 🆘 Support
260
+ ## Support
244
261
 
245
262
  For questions or issues, contact the platform team.
246
263
 
247
- ## 🔗 Related Packages
264
+ ## Related Packages
248
265
 
249
266
  - [@togatherlabs/shared-protos](../togather-shared-protos) - Shared Protocol Buffers
250
267
  - [@togatherlabs/event-sdk](../togather-shared-events) - Event handling SDK
@@ -0,0 +1,2 @@
1
+ export * from './sample.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './sample.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const SAMPLE: {
2
+ Char: string;
3
+ };
4
+ //# sourceMappingURL=sample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample.d.ts","sourceRoot":"","sources":["../../src/constants/sample.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM;;CAElB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const SAMPLE = {
2
+ Char: 'A',
3
+ };
4
+ //# sourceMappingURL=sample.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export declare function formatDate(date: Date, locale?: string): string;
2
+ //# sourceMappingURL=formatDate.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export * from './formatDate.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './formatDate.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Logger interface for structured logging.
3
- * Supports all standard log levels and child logger creation for contextual logging.
4
3
  */
5
4
  export interface ILogger {
6
5
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ILogger.d.ts","sourceRoot":"","sources":["../../src/logger/ILogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,OAAO;IACvB;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E;;;;;;;;;;;;;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"}
@@ -1,3 +1,3 @@
1
1
  export { ILogger } from './ILogger.js';
2
- export { PinoLogger } from './PinoLogger.js';
2
+ export { Logger, type LoggerConfig } from './logger.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
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"}
@@ -1,2 +1,2 @@
1
- export { PinoLogger } from './PinoLogger.js';
1
+ export { Logger } from './logger.js';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAqB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,51 @@
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
+ /**
14
+ * Pino logger implementation with configurable options.
15
+ *
16
+ * @example
17
+ * // Minimal - uses defaults
18
+ * const logger = new Logger();
19
+ *
20
+ * @example
21
+ * // With environment config from service
22
+ * const logger = new Logger(undefined, {
23
+ * nodeEnv: process.env.NODE_ENV,
24
+ * logLevel: process.env.LOG_LEVEL,
25
+ * serviceName: process.env.SERVICE_NAME
26
+ * });
27
+ *
28
+ * @example
29
+ * // With custom Pino options
30
+ * const logger = new Logger({
31
+ * level: 'debug',
32
+ * base: { service: 'my-service', version: '1.0.0' }
33
+ * });
34
+ */
35
+ export declare class Logger implements ILogger {
36
+ private logger;
37
+ /**
38
+ * Creates a new Logger instance.
39
+ *
40
+ * @param options - logger options for advanced configuration
41
+ * @param config - Environment configuration passed from the service
42
+ */
43
+ constructor(options?: LoggerOptions, config?: LoggerConfig);
44
+ info(labels: object | string, msg?: string, ...args: unknown[]): void;
45
+ warn(labels: object | string, msg?: string, ...args: unknown[]): void;
46
+ error(labels: object | string, msg?: string, ...args: unknown[]): void;
47
+ debug(labels: object | string, msg?: string, ...args: unknown[]): void;
48
+ fatal(labels: object | string, msg?: string, ...args: unknown[]): void;
49
+ trace(labels: object | string, msg?: string, ...args: unknown[]): void;
50
+ }
51
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
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;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBACa,MAAO,YAAW,OAAO;IACrC,OAAO,CAAC,MAAM,CAAqB;IAEnC;;;;;OAKG;gBACS,OAAO,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,YAAY;IA8E1D,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"}
@@ -14,35 +14,45 @@ import { hostname } from 'node:os';
14
14
  * Pino logger implementation with configurable options.
15
15
  *
16
16
  * @example
17
- * const logger = new PinoLogger();
17
+ * // Minimal - uses defaults
18
+ * const logger = new Logger();
18
19
  *
19
20
  * @example
20
- * const logger = new PinoLogger({
21
+ * // With environment config from service
22
+ * const logger = new Logger(undefined, {
23
+ * nodeEnv: process.env.NODE_ENV,
24
+ * logLevel: process.env.LOG_LEVEL,
25
+ * serviceName: process.env.SERVICE_NAME
26
+ * });
27
+ *
28
+ * @example
29
+ * // With custom Pino options
30
+ * const logger = new Logger({
21
31
  * level: 'debug',
22
32
  * base: { service: 'my-service', version: '1.0.0' }
23
33
  * });
24
34
  */
25
- let PinoLogger = class PinoLogger {
35
+ let Logger = class Logger {
26
36
  logger;
27
37
  /**
28
- * Creates a new PinoLogger instance.
38
+ * Creates a new Logger instance.
29
39
  *
30
- * @param options - Pino logger options. If not provided, uses environment-aware defaults.
31
- * Any options passed will be merged with defaults, with passed options taking precedence.
40
+ * @param options - logger options for advanced configuration
41
+ * @param config - Environment configuration passed from the service
32
42
  */
33
- constructor(options) {
34
- const nodeEnv = process.env.NODE_ENV || 'development';
43
+ constructor(options, config) {
44
+ const nodeEnv = config?.nodeEnv || 'development';
35
45
  const isDevelopment = nodeEnv === 'development';
36
46
  const isProduction = nodeEnv === 'production';
37
47
  const defaultOptions = {
38
- level: process.env.LOG_LEVEL || 'info',
48
+ level: config?.logLevel || 'info',
39
49
  base: {
40
50
  pid: process.pid,
41
- hostname: process.env.HOSTNAME || hostname(),
42
- service: process.env.SERVICE_NAME,
51
+ hostname: config?.hostname || hostname(),
52
+ service: config?.serviceName,
43
53
  environment: nodeEnv,
44
54
  },
45
- timestamp: isDevelopment ? pino.stdTimeFunctions.isoTime : pino.stdTimeFunctions.isoTime,
55
+ timestamp: pino.stdTimeFunctions.isoTime,
46
56
  // Error serialization for proper error logging
47
57
  serializers: {
48
58
  err: pino.stdSerializers.err,
@@ -120,9 +130,9 @@ let PinoLogger = class PinoLogger {
120
130
  this.logger.trace(labels, msg, ...args);
121
131
  }
122
132
  };
123
- PinoLogger = __decorate([
133
+ Logger = __decorate([
124
134
  injectable(),
125
- __metadata("design:paramtypes", [Object])
126
- ], PinoLogger);
127
- export { PinoLogger };
128
- //# sourceMappingURL=PinoLogger.js.map
135
+ __metadata("design:paramtypes", [Object, Object])
136
+ ], Logger);
137
+ export { Logger };
138
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
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;AAanC;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,MAAM,GAAZ,MAAM,MAAM;IACV,MAAM,CAAqB;IAEnC;;;;;OAKG;IACH,YAAY,OAAuB,EAAE,MAAqB;QACzD,MAAM,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,aAAa,CAAC;QACjD,MAAM,aAAa,GAAG,OAAO,KAAK,aAAa,CAAC;QAChD,MAAM,YAAY,GAAG,OAAO,KAAK,YAAY,CAAC;QAE9C,MAAM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AAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACzC,CAAC;CACD,CAAA;AA9GY,MAAM;IADlB,UAAU,EAAE;;GACA,MAAM,CA8GlB"}
@@ -0,0 +1,2 @@
1
+ export * from './user.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './user.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface UserDTO {
2
+ id: string;
3
+ name: string;
4
+ email: string;
5
+ }
6
+ //# sourceMappingURL=user.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@togatherlabs/shared-utils",
3
- "version": "1.1.0",
3
+ "version": "1.4.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",
@@ -1,31 +0,0 @@
1
- import { type LoggerOptions } from 'pino';
2
- import type { ILogger } from './ILogger.js';
3
- /**
4
- * Pino logger implementation with configurable options.
5
- *
6
- * @example
7
- * const logger = new PinoLogger();
8
- *
9
- * @example
10
- * const logger = new PinoLogger({
11
- * level: 'debug',
12
- * base: { service: 'my-service', version: '1.0.0' }
13
- * });
14
- */
15
- export declare class PinoLogger implements ILogger {
16
- private logger;
17
- /**
18
- * Creates a new PinoLogger instance.
19
- *
20
- * @param options - Pino logger options. If not provided, uses environment-aware defaults.
21
- * Any options passed will be merged with defaults, with passed options taking precedence.
22
- */
23
- constructor(options?: LoggerOptions);
24
- info(labels: object | string, msg?: string, ...args: unknown[]): void;
25
- warn(labels: object | string, msg?: string, ...args: unknown[]): void;
26
- error(labels: object | string, msg?: string, ...args: unknown[]): void;
27
- debug(labels: object | string, msg?: string, ...args: unknown[]): void;
28
- fatal(labels: object | string, msg?: string, ...args: unknown[]): void;
29
- trace(labels: object | string, msg?: string, ...args: unknown[]): void;
30
- }
31
- //# sourceMappingURL=PinoLogger.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PinoLogger.d.ts","sourceRoot":"","sources":["../../src/logger/PinoLogger.ts"],"names":[],"mappings":"AAAA,OAAa,EAAqC,KAAK,aAAa,EAAE,MAAM,MAAM,CAAC;AAEnF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C;;;;;;;;;;;GAWG;AACH,qBACa,UAAW,YAAW,OAAO;IACzC,OAAO,CAAC,MAAM,CAAqB;IAEnC;;;;;OAKG;gBACS,OAAO,CAAC,EAAE,aAAa;IA8EnC,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,GAA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