@catbee/utils 1.0.2 → 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 CHANGED
@@ -20,9 +20,8 @@ A modular, production-grade utility toolkit for Node.js and TypeScript, designed
20
20
  <img src="https://img.shields.io/npm/v/@catbee/utils/next" alt="NPM Next Version" /> -->
21
21
  <img src="https://img.shields.io/npm/dt/@catbee/utils" alt="NPM Downloads" />
22
22
  <img src="https://img.shields.io/npm/types/@catbee/utils" alt="TypeScript Types" />
23
- <img src="https://img.shields.io/librariesio/release/npm/@catbee%2Futils" alt="Dependencies" />
24
23
  <img src="https://img.shields.io/maintenance/yes/2025" alt="Maintenance" />
25
- <img src="https://snyk.io/test/github/<owner>/<repo>/badge.svg" alt="Snyk Vulnerabilities" />
24
+ <img src="https://snyk.io/test/github/catbee-technologies/catbee-utils/badge.svg" alt="Snyk Vulnerabilities" />
26
25
  <img src="https://sonarcloud.io/api/project_badges/measure?project=catbee-technologies_catbee-utils&metric=alert_status&token=93da835f2d48d37b41fa628cc7fc764c873bd700" alt="Quality Gate Status" />
27
26
  <img src="https://sonarcloud.io/api/project_badges/measure?project=catbee-technologies_catbee-utils&metric=ncloc&token=93da835f2d48d37b41fa628cc7fc764c873bd700" alt="Lines of Code" />
28
27
  <img src="https://sonarcloud.io/api/project_badges/measure?project=catbee-technologies_catbee-utils&metric=security_rating&token=93da835f2d48d37b41fa628cc7fc764c873bd700" alt="Security Rating" />
package/build/index.cjs CHANGED
@@ -402,17 +402,17 @@ var Env = class _Env {
402
402
  *
403
403
  * @typeParam T - The allowed value type (string literal types).
404
404
  * @param {string} key - The environment variable key.
405
- * @param {T[]} allowedValues - Array of accepted string values.
406
405
  * @param {T} [defaultValue] - Optional fallback value.
406
+ * @param {T[]} allowedValues - Array of accepted string values.
407
407
  * @returns {T} The validated environment value.
408
408
  * @throws {Error} If missing or invalid.
409
409
  *
410
410
  * @example
411
411
  * // If LOG_LEVEL=debug
412
- * const level = Env.getEnum('LOG_LEVEL', ['debug', 'info', 'warn', 'error'] as const, 'info');
412
+ * const level = Env.getEnum('LOG_LEVEL', 'info', ['debug', 'info', 'warn', 'error'] as const);
413
413
  * // 'debug' (typed as 'debug' | 'info' | 'warn' | 'error')
414
414
  */
415
- static getEnum(key, allowedValues, defaultValue) {
415
+ static getEnum(key, defaultValue, allowedValues) {
416
416
  const value = process.env[key];
417
417
  if (!value) {
418
418
  return defaultValue;
@@ -426,15 +426,15 @@ var Env = class _Env {
426
426
  * Retrieves an enum-like numeric environment variable.
427
427
  *
428
428
  * @param {string} key - The environment variable key.
429
- * @param {number[]} allowedValues - Array of accepted values.
430
429
  * @param {number} defaultValue - Default value if not present.
430
+ * @param {number[]} allowedValues - Array of accepted values.
431
431
  * @returns {number} The validated value.
432
432
  *
433
433
  * @example
434
434
  * // If NODE_VERSION=16
435
- * const version = Env.getNumberEnum('NODE_VERSION', [14, 16, 18], 16);
435
+ * const version = Env.getNumberEnum('NODE_VERSION', 16, [14, 16, 18]);
436
436
  */
437
- static getNumberEnum(key, allowedValues, defaultValue) {
437
+ static getNumberEnum(key, defaultValue, allowedValues) {
438
438
  const value = _Env.getNumber(key, defaultValue);
439
439
  if (!allowedValues.includes(value)) {
440
440
  throw new Error(`Environment variable '${key}' must be one of: ${allowedValues.join(", ")}. Received: ${value}`);
@@ -1073,6 +1073,10 @@ var config = {
1073
1073
  */
1074
1074
  pretty: Env.getBoolean("LOGGER_PRETTY", true),
1075
1075
  /**
1076
+ * Enables colorized output for pretty-print (default: true)
1077
+ */
1078
+ colorize: Env.getBoolean("LOGGER_PRETTY_COLORIZE", true),
1079
+ /**
1076
1080
  * Single line output for pretty-print (default: false)
1077
1081
  */
1078
1082
  singleLine: Env.getBoolean("LOGGER_PRETTY_SINGLE_LINE", false)
@@ -1082,6 +1086,20 @@ var config = {
1082
1086
  * Default TTL (time to live) for cache entries in seconds
1083
1087
  */
1084
1088
  defaultTtl: Env.getNumber("CACHE_DEFAULT_TTL_SECONDS", 3600) * 1e3
1089
+ },
1090
+ server: {
1091
+ /**
1092
+ * Skip healthz endpoint even if health checks are configured
1093
+ * Default: false
1094
+ * Set to true to return 200 OK for /healthz without checks
1095
+ * Useful in environments where a simple liveness probe is needed
1096
+ * without performing actual health checks
1097
+ * Example: Kubernetes liveness probe
1098
+ * Note: This does not disable the health check functionality itself
1099
+ * Health checks can still be performed programmatically
1100
+ * or via other endpoints if needed
1101
+ */
1102
+ skipHealthz: Env.getBoolean("SERVER_SKIP_HEALTHZ", false)
1085
1103
  }
1086
1104
  };
1087
1105
  var defaultServerConfig = {
@@ -1685,10 +1703,10 @@ function setupLogger(isGlobal = true) {
1685
1703
  },
1686
1704
  timestamp: pino.stdTimeFunctions.isoTime
1687
1705
  };
1688
- const logger2 = config.logger.pretty && Env.isDev() ? pino__default.default(logParams, pino__default.default.transport({
1706
+ const logger2 = config.logger.pretty ? pino__default.default(logParams, pino__default.default.transport({
1689
1707
  target: "pino-pretty",
1690
1708
  options: {
1691
- colorize: true,
1709
+ colorize: config.logger.colorize,
1692
1710
  translateTime: "SYS:standard",
1693
1711
  ignore: "pid,hostname",
1694
1712
  singleLine: config.logger.singleLine,
@@ -6800,7 +6818,7 @@ var ExpressServer = class _ExpressServer {
6800
6818
  const healthCheckPath = this.normalizePath(this.config.healthCheck?.path || "/healthz", this.config.healthCheck?.withGlobalPrefix);
6801
6819
  this.app.get(healthCheckPath, async (_req, res) => {
6802
6820
  try {
6803
- if (!this.healthChecks.length) {
6821
+ if (!this.healthChecks.length || config.server.skipHealthz) {
6804
6822
  return res.status(HttpStatusCodes.OK).json(new SuccessResponse("OK"));
6805
6823
  }
6806
6824
  const checkResults = await Promise.allSettled(this.healthChecks.map(async ({ name, check }) => {
package/build/index.d.ts CHANGED
@@ -229,6 +229,10 @@ declare let config: {
229
229
  * Has no effect in production.
230
230
  */
231
231
  pretty: boolean;
232
+ /**
233
+ * Enables colorized output for pretty-print (default: true)
234
+ */
235
+ colorize: boolean;
232
236
  /**
233
237
  * Single line output for pretty-print (default: false)
234
238
  */
@@ -240,6 +244,20 @@ declare let config: {
240
244
  */
241
245
  defaultTtl: number;
242
246
  };
247
+ server: {
248
+ /**
249
+ * Skip healthz endpoint even if health checks are configured
250
+ * Default: false
251
+ * Set to true to return 200 OK for /healthz without checks
252
+ * Useful in environments where a simple liveness probe is needed
253
+ * without performing actual health checks
254
+ * Example: Kubernetes liveness probe
255
+ * Note: This does not disable the health check functionality itself
256
+ * Health checks can still be performed programmatically
257
+ * or via other endpoints if needed
258
+ */
259
+ skipHealthz: boolean;
260
+ };
243
261
  };
244
262
  /**
245
263
  * Update the @catbee/utils configuration.
@@ -2419,30 +2437,30 @@ declare class Env {
2419
2437
  *
2420
2438
  * @typeParam T - The allowed value type (string literal types).
2421
2439
  * @param {string} key - The environment variable key.
2422
- * @param {T[]} allowedValues - Array of accepted string values.
2423
2440
  * @param {T} [defaultValue] - Optional fallback value.
2441
+ * @param {T[]} allowedValues - Array of accepted string values.
2424
2442
  * @returns {T} The validated environment value.
2425
2443
  * @throws {Error} If missing or invalid.
2426
2444
  *
2427
2445
  * @example
2428
2446
  * // If LOG_LEVEL=debug
2429
- * const level = Env.getEnum('LOG_LEVEL', ['debug', 'info', 'warn', 'error'] as const, 'info');
2447
+ * const level = Env.getEnum('LOG_LEVEL', 'info', ['debug', 'info', 'warn', 'error'] as const);
2430
2448
  * // 'debug' (typed as 'debug' | 'info' | 'warn' | 'error')
2431
2449
  */
2432
- static getEnum<T extends string>(key: string, allowedValues: readonly T[], defaultValue: T): T;
2450
+ static getEnum<T extends string>(key: string, defaultValue: T, allowedValues: readonly T[]): T;
2433
2451
  /**
2434
2452
  * Retrieves an enum-like numeric environment variable.
2435
2453
  *
2436
2454
  * @param {string} key - The environment variable key.
2437
- * @param {number[]} allowedValues - Array of accepted values.
2438
2455
  * @param {number} defaultValue - Default value if not present.
2456
+ * @param {number[]} allowedValues - Array of accepted values.
2439
2457
  * @returns {number} The validated value.
2440
2458
  *
2441
2459
  * @example
2442
2460
  * // If NODE_VERSION=16
2443
- * const version = Env.getNumberEnum('NODE_VERSION', [14, 16, 18], 16);
2461
+ * const version = Env.getNumberEnum('NODE_VERSION', 16, [14, 16, 18]);
2444
2462
  */
2445
- static getNumberEnum(key: string, allowedValues: number[], defaultValue: number): number;
2463
+ static getNumberEnum(key: string, defaultValue: number, allowedValues: number[]): number;
2446
2464
  /**
2447
2465
  * Retrieves a URL environment variable and validates it.
2448
2466
  *
package/build/index.mjs CHANGED
@@ -390,17 +390,17 @@ var Env = class _Env {
390
390
  *
391
391
  * @typeParam T - The allowed value type (string literal types).
392
392
  * @param {string} key - The environment variable key.
393
- * @param {T[]} allowedValues - Array of accepted string values.
394
393
  * @param {T} [defaultValue] - Optional fallback value.
394
+ * @param {T[]} allowedValues - Array of accepted string values.
395
395
  * @returns {T} The validated environment value.
396
396
  * @throws {Error} If missing or invalid.
397
397
  *
398
398
  * @example
399
399
  * // If LOG_LEVEL=debug
400
- * const level = Env.getEnum('LOG_LEVEL', ['debug', 'info', 'warn', 'error'] as const, 'info');
400
+ * const level = Env.getEnum('LOG_LEVEL', 'info', ['debug', 'info', 'warn', 'error'] as const);
401
401
  * // 'debug' (typed as 'debug' | 'info' | 'warn' | 'error')
402
402
  */
403
- static getEnum(key, allowedValues, defaultValue) {
403
+ static getEnum(key, defaultValue, allowedValues) {
404
404
  const value = process.env[key];
405
405
  if (!value) {
406
406
  return defaultValue;
@@ -414,15 +414,15 @@ var Env = class _Env {
414
414
  * Retrieves an enum-like numeric environment variable.
415
415
  *
416
416
  * @param {string} key - The environment variable key.
417
- * @param {number[]} allowedValues - Array of accepted values.
418
417
  * @param {number} defaultValue - Default value if not present.
418
+ * @param {number[]} allowedValues - Array of accepted values.
419
419
  * @returns {number} The validated value.
420
420
  *
421
421
  * @example
422
422
  * // If NODE_VERSION=16
423
- * const version = Env.getNumberEnum('NODE_VERSION', [14, 16, 18], 16);
423
+ * const version = Env.getNumberEnum('NODE_VERSION', 16, [14, 16, 18]);
424
424
  */
425
- static getNumberEnum(key, allowedValues, defaultValue) {
425
+ static getNumberEnum(key, defaultValue, allowedValues) {
426
426
  const value = _Env.getNumber(key, defaultValue);
427
427
  if (!allowedValues.includes(value)) {
428
428
  throw new Error(`Environment variable '${key}' must be one of: ${allowedValues.join(", ")}. Received: ${value}`);
@@ -1061,6 +1061,10 @@ var config = {
1061
1061
  */
1062
1062
  pretty: Env.getBoolean("LOGGER_PRETTY", true),
1063
1063
  /**
1064
+ * Enables colorized output for pretty-print (default: true)
1065
+ */
1066
+ colorize: Env.getBoolean("LOGGER_PRETTY_COLORIZE", true),
1067
+ /**
1064
1068
  * Single line output for pretty-print (default: false)
1065
1069
  */
1066
1070
  singleLine: Env.getBoolean("LOGGER_PRETTY_SINGLE_LINE", false)
@@ -1070,6 +1074,20 @@ var config = {
1070
1074
  * Default TTL (time to live) for cache entries in seconds
1071
1075
  */
1072
1076
  defaultTtl: Env.getNumber("CACHE_DEFAULT_TTL_SECONDS", 3600) * 1e3
1077
+ },
1078
+ server: {
1079
+ /**
1080
+ * Skip healthz endpoint even if health checks are configured
1081
+ * Default: false
1082
+ * Set to true to return 200 OK for /healthz without checks
1083
+ * Useful in environments where a simple liveness probe is needed
1084
+ * without performing actual health checks
1085
+ * Example: Kubernetes liveness probe
1086
+ * Note: This does not disable the health check functionality itself
1087
+ * Health checks can still be performed programmatically
1088
+ * or via other endpoints if needed
1089
+ */
1090
+ skipHealthz: Env.getBoolean("SERVER_SKIP_HEALTHZ", false)
1073
1091
  }
1074
1092
  };
1075
1093
  var defaultServerConfig = {
@@ -1673,10 +1691,10 @@ function setupLogger(isGlobal = true) {
1673
1691
  },
1674
1692
  timestamp: stdTimeFunctions.isoTime
1675
1693
  };
1676
- const logger2 = config.logger.pretty && Env.isDev() ? pino(logParams, pino.transport({
1694
+ const logger2 = config.logger.pretty ? pino(logParams, pino.transport({
1677
1695
  target: "pino-pretty",
1678
1696
  options: {
1679
- colorize: true,
1697
+ colorize: config.logger.colorize,
1680
1698
  translateTime: "SYS:standard",
1681
1699
  ignore: "pid,hostname",
1682
1700
  singleLine: config.logger.singleLine,
@@ -6788,7 +6806,7 @@ var ExpressServer = class _ExpressServer {
6788
6806
  const healthCheckPath = this.normalizePath(this.config.healthCheck?.path || "/healthz", this.config.healthCheck?.withGlobalPrefix);
6789
6807
  this.app.get(healthCheckPath, async (_req, res) => {
6790
6808
  try {
6791
- if (!this.healthChecks.length) {
6809
+ if (!this.healthChecks.length || config.server.skipHealthz) {
6792
6810
  return res.status(HttpStatusCodes.OK).json(new SuccessResponse("OK"));
6793
6811
  }
6794
6812
  const checkResults = await Promise.allSettled(this.healthChecks.map(async ({ name, check }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catbee/utils",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications (including Express-based services). All utilities are tree-shakable and can be imported independently.",
5
5
  "main": "build/index.cjs",
6
6
  "module": "build/index.mjs",
@@ -14,14 +14,14 @@
14
14
  },
15
15
  "license": "MIT",
16
16
  "optionalDependencies": {
17
- "@scalar/express-api-reference": "^0.8.18",
17
+ "@scalar/express-api-reference": "^0.8.20",
18
18
  "abort-controller": "^3.0.0",
19
19
  "compression": "^1.8.1",
20
20
  "cookie-parser": "^1.4.7",
21
21
  "cors": "^2.8.5",
22
22
  "express-rate-limit": "^8.1.0",
23
23
  "helmet": "^8.1.0",
24
- "pino": "^9.10.0",
24
+ "pino": "^10.0.0",
25
25
  "pino-pretty": "^13.1.1",
26
26
  "prom-client": "^15.1.3"
27
27
  },