@onlineapps/service-common 1.0.18 → 1.0.19

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/service-common",
3
- "version": "1.0.18",
3
+ "version": "1.0.19",
4
4
  "description": "Common utilities for both infrastructure services and business services",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ // See: docs/standards/error-handling-contract.md
3
4
  const ERROR_TYPES = {
4
5
  TRANSIENT: 'TRANSIENT',
5
6
  BUSINESS: 'BUSINESS',
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ // See: docs/standards/error-handling-contract.md
3
4
  const { BusinessError, isBusinessError } = require('./BusinessError');
4
5
 
5
6
  function businessErrorHandler(err, req, res, next) {
package/src/index.js CHANGED
@@ -24,6 +24,8 @@ const {
24
24
  } = require('./postgresClient');
25
25
  const {
26
26
  requireEnv,
27
+ requireNumberEnv,
28
+ requireBoolEnv,
27
29
  optionalEnv,
28
30
  optionalNumberEnv,
29
31
  getCriticalConfig,
@@ -61,6 +63,8 @@ module.exports = {
61
63
 
62
64
  // Configuration helpers (NO FALLBACKS for critical infrastructure)
63
65
  requireEnv,
66
+ requireNumberEnv,
67
+ requireBoolEnv,
64
68
  optionalEnv,
65
69
  optionalNumberEnv,
66
70
  getCriticalConfig,
@@ -29,6 +29,38 @@ function requireEnv(name, description) {
29
29
  }
30
30
  }
31
31
 
32
+ /**
33
+ * Require a numeric environment variable (fail-fast, no default).
34
+ * @param {string} name - Environment variable name
35
+ * @param {string} description - Human-readable description for error messages
36
+ * @returns {number} Parsed number
37
+ * @throws {Error} If variable is missing or not a valid number
38
+ */
39
+ function requireNumberEnv(name, description) {
40
+ const raw = requireEnv(name, description);
41
+ const num = Number(raw);
42
+ if (isNaN(num)) {
43
+ throw new Error(`[ServiceConfig] ${name} must be a number, got: "${raw}"`);
44
+ }
45
+ return num;
46
+ }
47
+
48
+ /**
49
+ * Require a boolean environment variable (fail-fast, no default).
50
+ * Accepts only literal "true" or "false".
51
+ * @param {string} name - Environment variable name
52
+ * @param {string} description - Human-readable description for error messages
53
+ * @returns {boolean} Parsed boolean
54
+ * @throws {Error} If variable is missing or not "true"/"false"
55
+ */
56
+ function requireBoolEnv(name, description) {
57
+ const raw = requireEnv(name, description);
58
+ if (raw !== 'true' && raw !== 'false') {
59
+ throw new Error(`[ServiceConfig] ${name} must be "true" or "false", got: "${raw}"`);
60
+ }
61
+ return raw === 'true';
62
+ }
63
+
32
64
  /**
33
65
  * Get optional environment variable with default
34
66
  * Use ONLY for non-critical values (ports, timeouts, log levels)
@@ -103,6 +135,8 @@ function getInfrastructureHealthConfig() {
103
135
 
104
136
  module.exports = {
105
137
  requireEnv,
138
+ requireNumberEnv,
139
+ requireBoolEnv,
106
140
  optionalEnv,
107
141
  optionalNumberEnv,
108
142
  getCriticalConfig,