@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.3
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/build/{esnext → cjs}/config.d.ts +0 -1
- package/build/{src → cjs}/config.js +0 -1
- package/build/{esnext → cjs}/index.d.ts +0 -1
- package/build/{src → cjs}/index.js +0 -1
- package/build/{esnext → cjs}/servers/server.builder.d.ts +0 -1
- package/build/{src → cjs}/servers/server.builder.js +10 -13
- package/build/{src → cjs}/servers/server.d.ts +0 -1
- package/build/{src → cjs}/servers/server.js +83 -75
- package/build/{src → cjs}/types/api-response.d.ts +0 -1
- package/build/{src → cjs}/types/api-response.js +0 -1
- package/build/{src → cjs}/types/index.d.ts +0 -1
- package/build/{src → cjs}/types/index.js +0 -1
- package/build/{src → cjs}/types/server.d.ts +0 -1
- package/build/{src → cjs}/types/server.js +0 -1
- package/build/{src → cjs}/utils/array.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/array.utils.js +0 -1
- package/build/{src → cjs}/utils/async.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/async.utils.js +2 -3
- package/build/{esnext → cjs}/utils/cache.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/cache.utils.js +7 -6
- package/build/{esnext → cjs}/utils/context-store.utils.d.ts +1 -2
- package/build/{src → cjs}/utils/context-store.utils.js +10 -9
- package/build/{esnext → cjs}/utils/crypto.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/crypto.utils.js +5 -3
- package/build/{src → cjs}/utils/date.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/date.utils.js +1 -2
- package/build/{src → cjs}/utils/decorators.utils.d.ts +30 -27
- package/build/{src → cjs}/utils/decorators.utils.js +169 -30
- package/build/{esnext → cjs}/utils/dir.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/dir.utils.js +6 -7
- package/build/{esnext → cjs}/utils/env.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/env.utils.js +5 -8
- package/build/{src → cjs}/utils/exception.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/exception.utils.js +2 -1
- package/build/{src → cjs}/utils/fs.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/fs.utils.js +12 -13
- package/build/{esnext → cjs}/utils/http-status-codes.d.ts +0 -1
- package/build/{src → cjs}/utils/http-status-codes.js +0 -1
- package/build/{esnext → cjs}/utils/id.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/id.utils.js +0 -1
- package/build/{src → cjs}/utils/logger.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/logger.utils.js +10 -6
- package/build/{esnext → cjs}/utils/middleware.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/middleware.utils.js +16 -17
- package/build/{esnext → cjs}/utils/obj.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/obj.utils.js +1 -2
- package/build/{src → cjs}/utils/performance.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/performance.utils.js +6 -4
- package/build/{esnext → cjs}/utils/request.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/request.utils.js +7 -3
- package/build/{esnext → cjs}/utils/response.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/response.utils.js +42 -28
- package/build/{esnext → cjs}/utils/stream.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/stream.utils.js +0 -1
- package/build/{esnext → cjs}/utils/string.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/string.utils.js +0 -1
- package/build/{src → cjs}/utils/type.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/type.utils.js +2 -3
- package/build/{src → cjs}/utils/url.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/url.utils.js +8 -9
- package/build/{src → cjs}/utils/validate.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/validate.utils.js +2 -3
- package/build/esm/config.d.ts +0 -1
- package/build/esm/config.js +6 -7
- package/build/esm/index.d.ts +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/servers/server.builder.d.ts +0 -1
- package/build/esm/servers/server.builder.js +99 -147
- package/build/esm/servers/server.d.ts +0 -1
- package/build/esm/servers/server.js +591 -876
- package/build/esm/types/api-response.d.ts +0 -1
- package/build/esm/types/api-response.js +0 -1
- package/build/esm/types/index.d.ts +0 -1
- package/build/esm/types/index.js +0 -1
- package/build/esm/types/server.d.ts +0 -1
- package/build/esm/types/server.js +0 -1
- package/build/esm/utils/array.utils.d.ts +0 -1
- package/build/esm/utils/array.utils.js +48 -86
- package/build/esm/utils/async.utils.d.ts +0 -1
- package/build/esm/utils/async.utils.js +247 -524
- package/build/esm/utils/cache.utils.d.ts +0 -1
- package/build/esm/utils/cache.utils.js +96 -301
- package/build/esm/utils/context-store.utils.d.ts +1 -2
- package/build/esm/utils/context-store.utils.js +62 -79
- package/build/esm/utils/crypto.utils.d.ts +0 -1
- package/build/esm/utils/crypto.utils.js +78 -175
- package/build/esm/utils/date.utils.d.ts +0 -1
- package/build/esm/utils/date.utils.js +47 -53
- package/build/esm/utils/decorators.utils.d.ts +30 -27
- package/build/esm/utils/decorators.utils.js +417 -461
- package/build/esm/utils/dir.utils.d.ts +0 -1
- package/build/esm/utils/dir.utils.js +264 -786
- package/build/esm/utils/env.utils.d.ts +0 -1
- package/build/esm/utils/env.utils.js +180 -271
- package/build/esm/utils/exception.utils.d.ts +0 -1
- package/build/esm/utils/exception.utils.js +112 -289
- package/build/esm/utils/fs.utils.d.ts +0 -1
- package/build/esm/utils/fs.utils.js +169 -401
- package/build/esm/utils/http-status-codes.d.ts +0 -1
- package/build/esm/utils/http-status-codes.js +0 -1
- package/build/esm/utils/id.utils.d.ts +0 -1
- package/build/esm/utils/id.utils.js +5 -9
- package/build/esm/utils/logger.utils.d.ts +0 -1
- package/build/esm/utils/logger.utils.js +34 -71
- package/build/esm/utils/middleware.utils.d.ts +0 -1
- package/build/esm/utils/middleware.utils.js +65 -155
- package/build/esm/utils/obj.utils.d.ts +0 -1
- package/build/esm/utils/obj.utils.js +69 -176
- package/build/esm/utils/performance.utils.d.ts +0 -1
- package/build/esm/utils/performance.utils.js +92 -195
- package/build/esm/utils/request.utils.d.ts +0 -1
- package/build/esm/utils/request.utils.js +41 -74
- package/build/esm/utils/response.utils.d.ts +0 -1
- package/build/esm/utils/response.utils.js +84 -107
- package/build/esm/utils/stream.utils.d.ts +0 -1
- package/build/esm/utils/stream.utils.js +38 -113
- package/build/esm/utils/string.utils.d.ts +0 -1
- package/build/esm/utils/string.utils.js +6 -11
- package/build/esm/utils/type.utils.d.ts +0 -1
- package/build/esm/utils/type.utils.js +8 -12
- package/build/esm/utils/url.utils.d.ts +0 -1
- package/build/esm/utils/url.utils.js +49 -127
- package/build/esm/utils/validate.utils.d.ts +0 -1
- package/build/esm/utils/validate.utils.js +23 -40
- package/package.json +288 -63
- package/build/esm/config.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/servers/server.builder.js.map +0 -1
- package/build/esm/servers/server.js.map +0 -1
- package/build/esm/types/api-response.js.map +0 -1
- package/build/esm/types/index.js.map +0 -1
- package/build/esm/types/server.js.map +0 -1
- package/build/esm/utils/array.utils.js.map +0 -1
- package/build/esm/utils/async.utils.js.map +0 -1
- package/build/esm/utils/cache.utils.js.map +0 -1
- package/build/esm/utils/context-store.utils.js.map +0 -1
- package/build/esm/utils/crypto.utils.js.map +0 -1
- package/build/esm/utils/date.utils.js.map +0 -1
- package/build/esm/utils/decorators.utils.js.map +0 -1
- package/build/esm/utils/dir.utils.js.map +0 -1
- package/build/esm/utils/env.utils.js.map +0 -1
- package/build/esm/utils/exception.utils.js.map +0 -1
- package/build/esm/utils/fs.utils.js.map +0 -1
- package/build/esm/utils/http-status-codes.js.map +0 -1
- package/build/esm/utils/id.utils.js.map +0 -1
- package/build/esm/utils/logger.utils.js.map +0 -1
- package/build/esm/utils/middleware.utils.js.map +0 -1
- package/build/esm/utils/obj.utils.js.map +0 -1
- package/build/esm/utils/performance.utils.js.map +0 -1
- package/build/esm/utils/request.utils.js.map +0 -1
- package/build/esm/utils/response.utils.js.map +0 -1
- package/build/esm/utils/stream.utils.js.map +0 -1
- package/build/esm/utils/string.utils.js.map +0 -1
- package/build/esm/utils/type.utils.js.map +0 -1
- package/build/esm/utils/url.utils.js.map +0 -1
- package/build/esm/utils/validate.utils.js.map +0 -1
- package/build/esnext/config.js +0 -133
- package/build/esnext/config.js.map +0 -1
- package/build/esnext/index.js +0 -50
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/servers/server.builder.js +0 -657
- package/build/esnext/servers/server.builder.js.map +0 -1
- package/build/esnext/servers/server.d.ts +0 -256
- package/build/esnext/servers/server.js +0 -955
- package/build/esnext/servers/server.js.map +0 -1
- package/build/esnext/types/api-response.d.ts +0 -152
- package/build/esnext/types/api-response.js +0 -34
- package/build/esnext/types/api-response.js.map +0 -1
- package/build/esnext/types/index.d.ts +0 -125
- package/build/esnext/types/index.js +0 -25
- package/build/esnext/types/index.js.map +0 -1
- package/build/esnext/types/server.d.ts +0 -268
- package/build/esnext/types/server.js +0 -25
- package/build/esnext/types/server.js.map +0 -1
- package/build/esnext/utils/array.utils.d.ts +0 -168
- package/build/esnext/utils/array.utils.js +0 -345
- package/build/esnext/utils/array.utils.js.map +0 -1
- package/build/esnext/utils/async.utils.d.ts +0 -265
- package/build/esnext/utils/async.utils.js +0 -620
- package/build/esnext/utils/async.utils.js.map +0 -1
- package/build/esnext/utils/cache.utils.js +0 -293
- package/build/esnext/utils/cache.utils.js.map +0 -1
- package/build/esnext/utils/context-store.utils.js +0 -289
- package/build/esnext/utils/context-store.utils.js.map +0 -1
- package/build/esnext/utils/crypto.utils.js +0 -276
- package/build/esnext/utils/crypto.utils.js.map +0 -1
- package/build/esnext/utils/date.utils.d.ts +0 -159
- package/build/esnext/utils/date.utils.js +0 -384
- package/build/esnext/utils/date.utils.js.map +0 -1
- package/build/esnext/utils/decorators.utils.d.ts +0 -508
- package/build/esnext/utils/decorators.utils.js +0 -877
- package/build/esnext/utils/decorators.utils.js.map +0 -1
- package/build/esnext/utils/dir.utils.js +0 -477
- package/build/esnext/utils/dir.utils.js.map +0 -1
- package/build/esnext/utils/env.utils.js +0 -785
- package/build/esnext/utils/env.utils.js.map +0 -1
- package/build/esnext/utils/exception.utils.d.ts +0 -230
- package/build/esnext/utils/exception.utils.js +0 -381
- package/build/esnext/utils/exception.utils.js.map +0 -1
- package/build/esnext/utils/fs.utils.d.ts +0 -164
- package/build/esnext/utils/fs.utils.js +0 -349
- package/build/esnext/utils/fs.utils.js.map +0 -1
- package/build/esnext/utils/http-status-codes.js +0 -295
- package/build/esnext/utils/http-status-codes.js.map +0 -1
- package/build/esnext/utils/id.utils.js +0 -84
- package/build/esnext/utils/id.utils.js.map +0 -1
- package/build/esnext/utils/logger.utils.d.ts +0 -160
- package/build/esnext/utils/logger.utils.js +0 -300
- package/build/esnext/utils/logger.utils.js.map +0 -1
- package/build/esnext/utils/middleware.utils.js +0 -236
- package/build/esnext/utils/middleware.utils.js.map +0 -1
- package/build/esnext/utils/obj.utils.js +0 -413
- package/build/esnext/utils/obj.utils.js.map +0 -1
- package/build/esnext/utils/performance.utils.d.ts +0 -136
- package/build/esnext/utils/performance.utils.js +0 -271
- package/build/esnext/utils/performance.utils.js.map +0 -1
- package/build/esnext/utils/request.utils.js +0 -186
- package/build/esnext/utils/request.utils.js.map +0 -1
- package/build/esnext/utils/response.utils.js +0 -247
- package/build/esnext/utils/response.utils.js.map +0 -1
- package/build/esnext/utils/stream.utils.js +0 -210
- package/build/esnext/utils/stream.utils.js.map +0 -1
- package/build/esnext/utils/string.utils.js +0 -165
- package/build/esnext/utils/string.utils.js.map +0 -1
- package/build/esnext/utils/type.utils.d.ts +0 -90
- package/build/esnext/utils/type.utils.js +0 -187
- package/build/esnext/utils/type.utils.js.map +0 -1
- package/build/esnext/utils/url.utils.d.ts +0 -141
- package/build/esnext/utils/url.utils.js +0 -304
- package/build/esnext/utils/url.utils.js.map +0 -1
- package/build/esnext/utils/validate.utils.d.ts +0 -177
- package/build/esnext/utils/validate.utils.js +0 -320
- package/build/esnext/utils/validate.utils.js.map +0 -1
- package/build/src/config.d.ts +0 -122
- package/build/src/config.js.map +0 -1
- package/build/src/index.d.ts +0 -27
- package/build/src/index.js.map +0 -1
- package/build/src/servers/server.builder.d.ts +0 -508
- package/build/src/servers/server.builder.js.map +0 -1
- package/build/src/servers/server.js.map +0 -1
- package/build/src/types/api-response.js.map +0 -1
- package/build/src/types/index.js.map +0 -1
- package/build/src/types/server.js.map +0 -1
- package/build/src/utils/array.utils.js.map +0 -1
- package/build/src/utils/async.utils.js.map +0 -1
- package/build/src/utils/cache.utils.d.ts +0 -153
- package/build/src/utils/cache.utils.js.map +0 -1
- package/build/src/utils/context-store.utils.d.ts +0 -189
- package/build/src/utils/context-store.utils.js.map +0 -1
- package/build/src/utils/crypto.utils.d.ts +0 -160
- package/build/src/utils/crypto.utils.js.map +0 -1
- package/build/src/utils/date.utils.js.map +0 -1
- package/build/src/utils/decorators.utils.js.map +0 -1
- package/build/src/utils/dir.utils.d.ts +0 -196
- package/build/src/utils/dir.utils.js.map +0 -1
- package/build/src/utils/env.utils.d.ts +0 -377
- package/build/src/utils/env.utils.js.map +0 -1
- package/build/src/utils/exception.utils.js.map +0 -1
- package/build/src/utils/fs.utils.js.map +0 -1
- package/build/src/utils/http-status-codes.d.ts +0 -266
- package/build/src/utils/http-status-codes.js.map +0 -1
- package/build/src/utils/id.utils.d.ts +0 -36
- package/build/src/utils/id.utils.js.map +0 -1
- package/build/src/utils/logger.utils.js.map +0 -1
- package/build/src/utils/middleware.utils.d.ts +0 -100
- package/build/src/utils/middleware.utils.js.map +0 -1
- package/build/src/utils/obj.utils.d.ts +0 -124
- package/build/src/utils/obj.utils.js.map +0 -1
- package/build/src/utils/performance.utils.js.map +0 -1
- package/build/src/utils/request.utils.d.ts +0 -86
- package/build/src/utils/request.utils.js.map +0 -1
- package/build/src/utils/response.utils.d.ts +0 -163
- package/build/src/utils/response.utils.js.map +0 -1
- package/build/src/utils/stream.utils.d.ts +0 -88
- package/build/src/utils/stream.utils.js.map +0 -1
- package/build/src/utils/string.utils.d.ts +0 -93
- package/build/src/utils/string.utils.js.map +0 -1
- package/build/src/utils/type.utils.js.map +0 -1
- package/build/src/utils/url.utils.js.map +0 -1
- package/build/src/utils/validate.utils.js.map +0 -1
|
@@ -36,11 +36,10 @@ export function uuid() {
|
|
|
36
36
|
* @param {number} length - Length of the ID (default: 21).
|
|
37
37
|
* @returns {string} Nanoid-style random string.
|
|
38
38
|
*/
|
|
39
|
-
export function nanoId(length) {
|
|
40
|
-
if (length === void 0) { length = 21; }
|
|
39
|
+
export function nanoId(length = 21) {
|
|
41
40
|
if (length <= 0)
|
|
42
41
|
return '';
|
|
43
|
-
|
|
42
|
+
let id = '';
|
|
44
43
|
while (id.length < length) {
|
|
45
44
|
id += randomBytes(Math.ceil((length * 3) / 4))
|
|
46
45
|
.toString('base64url')
|
|
@@ -54,8 +53,7 @@ export function nanoId(length) {
|
|
|
54
53
|
* @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).
|
|
55
54
|
* @returns {string} Random hex string.
|
|
56
55
|
*/
|
|
57
|
-
export function randomHex(byteLength) {
|
|
58
|
-
if (byteLength === void 0) { byteLength = 16; }
|
|
56
|
+
export function randomHex(byteLength = 16) {
|
|
59
57
|
// Use Node.js crypto for both Node and browser compatibility
|
|
60
58
|
// Prefer randomBytes if available (Node), fallback to getRandomValues for browser (not used here)
|
|
61
59
|
return randomBytes(byteLength)
|
|
@@ -71,7 +69,7 @@ export function randomHex(byteLength) {
|
|
|
71
69
|
* @returns {number} Random integer in range.
|
|
72
70
|
*/
|
|
73
71
|
export function randomInt(min, max) {
|
|
74
|
-
|
|
72
|
+
const range = max - min + 1;
|
|
75
73
|
return Math.floor(Math.random() * range) + min;
|
|
76
74
|
}
|
|
77
75
|
/**
|
|
@@ -80,8 +78,6 @@ export function randomInt(min, max) {
|
|
|
80
78
|
* @param {number} byteLength - Number of random bytes (default: 16).
|
|
81
79
|
* @returns {string} Random base64 string (URL-safe, no padding).
|
|
82
80
|
*/
|
|
83
|
-
export function randomBase64(byteLength) {
|
|
84
|
-
if (byteLength === void 0) { byteLength = 16; }
|
|
81
|
+
export function randomBase64(byteLength = 16) {
|
|
85
82
|
return randomBytes(byteLength).toString('base64url');
|
|
86
83
|
}
|
|
87
|
-
//# sourceMappingURL=id.utils.js.map
|
|
@@ -157,4 +157,3 @@ export declare function createRequestLogger(requestId: string, additionalContext
|
|
|
157
157
|
* @param {Record<string, any>} [context] - Additional context properties
|
|
158
158
|
*/
|
|
159
159
|
export declare function logError(error: Error | unknown, message?: string, context?: Record<string, any>): void;
|
|
160
|
-
//# sourceMappingURL=logger.utils.d.ts.map
|
|
@@ -21,42 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
var __assign = (this && this.__assign) || function () {
|
|
25
|
-
__assign = Object.assign || function(t) {
|
|
26
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
-
s = arguments[i];
|
|
28
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
29
|
-
t[p] = s[p];
|
|
30
|
-
}
|
|
31
|
-
return t;
|
|
32
|
-
};
|
|
33
|
-
return __assign.apply(this, arguments);
|
|
34
|
-
};
|
|
35
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
36
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
37
|
-
if (!m) return o;
|
|
38
|
-
var i = m.call(o), r, ar = [], e;
|
|
39
|
-
try {
|
|
40
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
41
|
-
}
|
|
42
|
-
catch (error) { e = { error: error }; }
|
|
43
|
-
finally {
|
|
44
|
-
try {
|
|
45
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
46
|
-
}
|
|
47
|
-
finally { if (e) throw e.error; }
|
|
48
|
-
}
|
|
49
|
-
return ar;
|
|
50
|
-
};
|
|
51
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
52
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
53
|
-
if (ar || !(i in from)) {
|
|
54
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
55
|
-
ar[i] = from[i];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
59
|
-
};
|
|
60
24
|
import pino, { stdTimeFunctions } from 'pino';
|
|
61
25
|
import { config } from '../config';
|
|
62
26
|
import { ContextStore, StoreKeys } from './context-store.utils';
|
|
@@ -64,9 +28,9 @@ import { Env } from './env.utils';
|
|
|
64
28
|
/**
|
|
65
29
|
* Symbol used to store the root logger in the Node.js global object.
|
|
66
30
|
*/
|
|
67
|
-
|
|
31
|
+
const GLOBAL_LOGGER_KEY = Symbol.for('logger');
|
|
68
32
|
// Default sensitive fields
|
|
69
|
-
export
|
|
33
|
+
export const defaultSensitiveFields = [
|
|
70
34
|
'password',
|
|
71
35
|
'secret',
|
|
72
36
|
'token',
|
|
@@ -82,23 +46,22 @@ export var defaultSensitiveFields = [
|
|
|
82
46
|
/**
|
|
83
47
|
* The global censor function used by the logger.
|
|
84
48
|
*/
|
|
85
|
-
|
|
86
|
-
if (sensitiveFields === void 0) { sensitiveFields = defaultSensitiveFields; }
|
|
49
|
+
let globalRedactCensor = (value, path, sensitiveFields = defaultSensitiveFields) => {
|
|
87
50
|
if (typeof value !== 'string')
|
|
88
51
|
return '***';
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (lowerPath.some(
|
|
52
|
+
const lowerPath = path.map(p => p.toLowerCase());
|
|
53
|
+
const lowerSensitiveFields = sensitiveFields.map(f => f.toLowerCase());
|
|
54
|
+
if (lowerPath.some(p => lowerSensitiveFields.includes(p)))
|
|
92
55
|
return '***';
|
|
93
56
|
// Redact URLs
|
|
94
57
|
if (lowerPath[0] === 'url') {
|
|
95
|
-
return value.replace(new RegExp(
|
|
58
|
+
return value.replace(new RegExp(`([?&](${lowerSensitiveFields.join('|')})=)[^&#]*`, 'gi'), '$1***');
|
|
96
59
|
}
|
|
97
|
-
if (lowerPath.some(
|
|
60
|
+
if (lowerPath.some(p => p.includes('authorization') || p.includes('auth'))) {
|
|
98
61
|
return value.replace(/^(\S+)\s+.+$/, '$1 ***') || '***';
|
|
99
62
|
}
|
|
100
63
|
// Redact sensitive fields - check each path segment against each sensitive field
|
|
101
|
-
if (lowerPath.some(
|
|
64
|
+
if (lowerPath.some(pathPart => lowerSensitiveFields.some(field => pathPart.includes(field)))) {
|
|
102
65
|
return '***';
|
|
103
66
|
}
|
|
104
67
|
if (path.length > 0 && !['req', 'res', 'headers'].includes(lowerPath[0])) {
|
|
@@ -188,11 +151,8 @@ export function redact(value, path, sensitiveFields) {
|
|
|
188
151
|
* @param fields - Array of additional field names to redact
|
|
189
152
|
*/
|
|
190
153
|
export function addRedactFields(fields) {
|
|
191
|
-
|
|
192
|
-
globalRedactCensor =
|
|
193
|
-
if (sensitiveFields === void 0) { sensitiveFields = defaultSensitiveFields; }
|
|
194
|
-
return prev(value, path, __spreadArray(__spreadArray([], __read((sensitiveFields || [])), false), __read(fields), false));
|
|
195
|
-
};
|
|
154
|
+
const prev = globalRedactCensor;
|
|
155
|
+
globalRedactCensor = (value, path, sensitiveFields = defaultSensitiveFields) => prev(value, path, [...(sensitiveFields || []), ...fields]);
|
|
196
156
|
}
|
|
197
157
|
/**
|
|
198
158
|
* Replaces the default list of sensitive fields with a new list.
|
|
@@ -209,7 +169,7 @@ export function addRedactFields(fields) {
|
|
|
209
169
|
* @param fields - Array of field names to set as the new default sensitive fields
|
|
210
170
|
*/
|
|
211
171
|
export function setSensitiveFields(fields) {
|
|
212
|
-
defaultSensitiveFields.splice
|
|
172
|
+
defaultSensitiveFields.splice(0, defaultSensitiveFields.length, ...fields);
|
|
213
173
|
}
|
|
214
174
|
/**
|
|
215
175
|
* Adds additional field names to the default sensitive fields list.
|
|
@@ -226,13 +186,13 @@ export function setSensitiveFields(fields) {
|
|
|
226
186
|
* @param fields - Array of additional field names to add to the sensitive fields list
|
|
227
187
|
*/
|
|
228
188
|
export function addSensitiveFields(fields) {
|
|
229
|
-
defaultSensitiveFields.push
|
|
189
|
+
defaultSensitiveFields.push(...fields);
|
|
230
190
|
}
|
|
231
191
|
/**
|
|
232
192
|
* Use an object compatible with either modern or legacy global scopes.
|
|
233
193
|
*/
|
|
234
|
-
export
|
|
235
|
-
|
|
194
|
+
export const _globalThis = typeof globalThis === 'object' ? globalThis : global;
|
|
195
|
+
const _global = _globalThis;
|
|
236
196
|
/**
|
|
237
197
|
* Initializes the global root logger according to app configuration.
|
|
238
198
|
*
|
|
@@ -240,13 +200,12 @@ var _global = _globalThis;
|
|
|
240
200
|
* - Uses singleton in global symbol registry.
|
|
241
201
|
*/
|
|
242
202
|
function setupLogger() {
|
|
243
|
-
|
|
244
|
-
var logParams = {
|
|
203
|
+
const logParams = {
|
|
245
204
|
name: config.logger.name || '@catbee/utils',
|
|
246
205
|
level: config.logger.level || 'info',
|
|
247
206
|
redact: {
|
|
248
207
|
paths: ['req.authorization', 'res.authorization', 'url', 'headers.authorization', 'headers.cookies'],
|
|
249
|
-
censor:
|
|
208
|
+
censor: (value, path) => redact(value, path)
|
|
250
209
|
},
|
|
251
210
|
// serializers: {
|
|
252
211
|
// req: pino.stdSerializers.req,
|
|
@@ -258,7 +217,7 @@ function setupLogger() {
|
|
|
258
217
|
// },
|
|
259
218
|
timestamp: stdTimeFunctions.isoTime
|
|
260
219
|
};
|
|
261
|
-
|
|
220
|
+
const logger = config.logger.pretty && Env.isDev()
|
|
262
221
|
? pino(logParams, pino.transport({
|
|
263
222
|
target: 'pino-pretty',
|
|
264
223
|
options: {
|
|
@@ -271,7 +230,7 @@ function setupLogger() {
|
|
|
271
230
|
}))
|
|
272
231
|
: pino(logParams);
|
|
273
232
|
_global[GLOBAL_LOGGER_KEY] = logger;
|
|
274
|
-
|
|
233
|
+
_global[GLOBAL_LOGGER_KEY]?.debug('Logger initialized');
|
|
275
234
|
}
|
|
276
235
|
/**
|
|
277
236
|
* Retrieves the current logger instance:
|
|
@@ -282,7 +241,7 @@ function setupLogger() {
|
|
|
282
241
|
* @returns {Logger} The logger instance (request-bound or global root logger)
|
|
283
242
|
*/
|
|
284
243
|
export function getLogger() {
|
|
285
|
-
|
|
244
|
+
const logger = ContextStore.get(StoreKeys.LOGGER);
|
|
286
245
|
if (logger)
|
|
287
246
|
return logger;
|
|
288
247
|
if (!_global[GLOBAL_LOGGER_KEY]) {
|
|
@@ -294,7 +253,7 @@ export function getLogger() {
|
|
|
294
253
|
* Logger instance for the global context.
|
|
295
254
|
* This logger is used for logging messages that are not tied to a specific request.
|
|
296
255
|
*/
|
|
297
|
-
export
|
|
256
|
+
export const logger = getLogger();
|
|
298
257
|
/**
|
|
299
258
|
* Creates a child logger with additional context.
|
|
300
259
|
*
|
|
@@ -303,7 +262,7 @@ export var logger = getLogger();
|
|
|
303
262
|
* @returns {Logger} Child logger with merged context
|
|
304
263
|
*/
|
|
305
264
|
export function createChildLogger(bindings, parentLogger) {
|
|
306
|
-
|
|
265
|
+
const logger = parentLogger || getLogger();
|
|
307
266
|
return logger.child(bindings);
|
|
308
267
|
}
|
|
309
268
|
/**
|
|
@@ -313,13 +272,15 @@ export function createChildLogger(bindings, parentLogger) {
|
|
|
313
272
|
* @param {object} [additionalContext] - Additional context to include in logs
|
|
314
273
|
* @returns {Logger} Request-scoped logger instance
|
|
315
274
|
*/
|
|
316
|
-
export function createRequestLogger(requestId, additionalContext) {
|
|
317
|
-
|
|
318
|
-
|
|
275
|
+
export function createRequestLogger(requestId, additionalContext = {}) {
|
|
276
|
+
const logger = createChildLogger({
|
|
277
|
+
requestId,
|
|
278
|
+
...additionalContext
|
|
279
|
+
});
|
|
319
280
|
try {
|
|
320
281
|
ContextStore.set(StoreKeys.LOGGER, logger);
|
|
321
282
|
}
|
|
322
|
-
catch
|
|
283
|
+
catch {
|
|
323
284
|
// Context not initialized, can't store logger
|
|
324
285
|
logger.debug('Failed to store logger in context - AsyncLocalStorage not initialized');
|
|
325
286
|
}
|
|
@@ -333,9 +294,11 @@ export function createRequestLogger(requestId, additionalContext) {
|
|
|
333
294
|
* @param {Record<string, any>} [context] - Additional context properties
|
|
334
295
|
*/
|
|
335
296
|
export function logError(error, message, context) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
297
|
+
const logger = getLogger();
|
|
298
|
+
const errObj = error instanceof Error ? error : new Error(String(error));
|
|
299
|
+
const logContext = {
|
|
300
|
+
...context,
|
|
301
|
+
error: errObj
|
|
302
|
+
};
|
|
339
303
|
logger.error(logContext, message || errObj.message);
|
|
340
304
|
}
|
|
341
|
-
//# sourceMappingURL=logger.utils.js.map
|
|
@@ -21,53 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
34
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
35
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
36
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
37
|
-
function step(op) {
|
|
38
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
39
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
40
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
41
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
42
|
-
switch (op[0]) {
|
|
43
|
-
case 0: case 1: t = op; break;
|
|
44
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
45
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
46
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
47
|
-
default:
|
|
48
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
49
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
50
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
51
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
52
|
-
if (t[2]) _.ops.pop();
|
|
53
|
-
_.trys.pop(); continue;
|
|
54
|
-
}
|
|
55
|
-
op = body.call(thisArg, _);
|
|
56
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
57
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var __values = (this && this.__values) || function(o) {
|
|
61
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
62
|
-
if (m) return m.call(o);
|
|
63
|
-
if (o && typeof o.length === "number") return {
|
|
64
|
-
next: function () {
|
|
65
|
-
if (o && i >= o.length) o = void 0;
|
|
66
|
-
return { value: o && o[i++], done: !o };
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
70
|
-
};
|
|
71
24
|
import { uuid } from './id.utils';
|
|
72
25
|
import { HttpStatusCodes } from './http-status-codes';
|
|
73
26
|
import { createFinalErrorResponse, ErrorResponse } from './response.utils';
|
|
@@ -85,13 +38,13 @@ import { RequestTimeoutException } from './exception.utils';
|
|
|
85
38
|
* @returns {Middleware} Express-compatible middleware
|
|
86
39
|
*/
|
|
87
40
|
export function requestId(options) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return
|
|
41
|
+
const headerName = options?.headerName || 'X-Request-ID';
|
|
42
|
+
const exposeHeader = options?.exposeHeader !== false;
|
|
43
|
+
const generateId = options?.generator || uuid;
|
|
44
|
+
return (req, res, next) => {
|
|
92
45
|
// Use existing request ID from header or generate a new one
|
|
93
|
-
|
|
94
|
-
|
|
46
|
+
const existingId = req.headers[headerName.toLowerCase()];
|
|
47
|
+
const id = existingId || generateId();
|
|
95
48
|
// Attach ID to request object
|
|
96
49
|
req.id = id;
|
|
97
50
|
// Add ID to response headers
|
|
@@ -110,30 +63,26 @@ export function requestId(options) {
|
|
|
110
63
|
* @returns {Middleware} Express-compatible middleware
|
|
111
64
|
*/
|
|
112
65
|
export function responseTime(options) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return
|
|
116
|
-
|
|
66
|
+
const addHeader = options?.addHeader !== false;
|
|
67
|
+
const logOnComplete = options?.logOnComplete === true;
|
|
68
|
+
return (req, res, next) => {
|
|
69
|
+
const start = process.hrtime();
|
|
117
70
|
// Function to calculate duration
|
|
118
|
-
|
|
119
|
-
|
|
71
|
+
const getDuration = () => {
|
|
72
|
+
const diff = process.hrtime(start);
|
|
120
73
|
return (diff[0] * 1e3 + diff[1] * 1e-6).toFixed(2);
|
|
121
74
|
};
|
|
122
75
|
if (addHeader) {
|
|
123
76
|
// Ensure header is set before response is sent
|
|
124
|
-
|
|
125
|
-
res.writeHead = function () {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
args[_i] = arguments[_i];
|
|
129
|
-
}
|
|
130
|
-
res.setHeader('X-Response-Time', "".concat(getDuration(), "ms"));
|
|
131
|
-
return originalWriteHead_1.apply(this, args);
|
|
77
|
+
const originalWriteHead = res.writeHead;
|
|
78
|
+
res.writeHead = function (...args) {
|
|
79
|
+
res.setHeader('X-Response-Time', `${getDuration()}ms`);
|
|
80
|
+
return originalWriteHead.apply(this, args);
|
|
132
81
|
};
|
|
133
82
|
}
|
|
134
83
|
if (logOnComplete) {
|
|
135
|
-
res.on('finish',
|
|
136
|
-
getLogger().info(
|
|
84
|
+
res.on('finish', () => {
|
|
85
|
+
getLogger().info(`${req.method} ${req.url} - ${getDuration()}ms`);
|
|
137
86
|
});
|
|
138
87
|
}
|
|
139
88
|
next();
|
|
@@ -146,16 +95,15 @@ export function responseTime(options) {
|
|
|
146
95
|
* @param {number} [timeoutMs=30000] - Timeout in milliseconds
|
|
147
96
|
* @returns {Middleware} Express-compatible middleware
|
|
148
97
|
*/
|
|
149
|
-
export function timeout(timeoutMs) {
|
|
150
|
-
|
|
151
|
-
return function (_req, res, next) {
|
|
98
|
+
export function timeout(timeoutMs = 30000) {
|
|
99
|
+
return (_req, res, next) => {
|
|
152
100
|
// Set timeout for the request
|
|
153
|
-
|
|
154
|
-
|
|
101
|
+
const timer = setTimeout(() => {
|
|
102
|
+
const response = new RequestTimeoutException('Request timed out');
|
|
155
103
|
res.status(HttpStatusCodes.REQUEST_TIMEOUT).json(response);
|
|
156
104
|
}, timeoutMs);
|
|
157
105
|
// Clear timeout when response is sent
|
|
158
|
-
res.on('finish',
|
|
106
|
+
res.on('finish', () => {
|
|
159
107
|
clearTimeout(timer);
|
|
160
108
|
});
|
|
161
109
|
next();
|
|
@@ -169,17 +117,15 @@ export function timeout(timeoutMs) {
|
|
|
169
117
|
* @param {boolean} [options.autoLog=true] - Whether to log automatically when context is initialized
|
|
170
118
|
* @returns {(req: Request, res: Response, next: NextFunction) => void} Express middleware function
|
|
171
119
|
*/
|
|
172
|
-
export function setupRequestContext(options) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return function (req, _res, next) {
|
|
176
|
-
var _a;
|
|
120
|
+
export function setupRequestContext(options = {}) {
|
|
121
|
+
const { headerName = 'x-request-id', autoLog = true } = options;
|
|
122
|
+
return (req, _res, next) => {
|
|
177
123
|
// Generate or use existing request ID
|
|
178
|
-
|
|
179
|
-
ContextStore.run(
|
|
124
|
+
const requestId = req.headers[headerName] || req?.['id'] || uuid();
|
|
125
|
+
ContextStore.run({ [StoreKeys.REQUEST_ID]: requestId }, () => {
|
|
180
126
|
// Create a child logger for this request
|
|
181
|
-
|
|
182
|
-
requestId
|
|
127
|
+
const childLogger = getLogger().child({
|
|
128
|
+
requestId,
|
|
183
129
|
method: req.method,
|
|
184
130
|
url: req.originalUrl || req.url
|
|
185
131
|
});
|
|
@@ -220,34 +166,34 @@ export function setupRequestContext(options) {
|
|
|
220
166
|
* });
|
|
221
167
|
*/
|
|
222
168
|
export function errorHandler(options) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return
|
|
169
|
+
const logErrors = options?.logErrors !== false;
|
|
170
|
+
const includeDetails = options?.includeDetails === true;
|
|
171
|
+
return (err, req, res, _next) => {
|
|
226
172
|
// Determine status code
|
|
227
|
-
|
|
173
|
+
const status = err?.status || err?.statusCode || HttpStatusCodes.INTERNAL_SERVER_ERROR;
|
|
228
174
|
// Log error if enabled
|
|
229
175
|
if (logErrors) {
|
|
230
|
-
getLogger().error({ err
|
|
176
|
+
getLogger().error({ err }, `${err.message || 'Unknown error'}`);
|
|
231
177
|
}
|
|
232
178
|
// Handle ErrorResponse instances (our custom error class)
|
|
233
179
|
if (err instanceof ErrorResponse) {
|
|
234
|
-
|
|
180
|
+
const result = {
|
|
235
181
|
error: true,
|
|
236
182
|
message: err.message,
|
|
237
183
|
timestamp: err.timestamp,
|
|
238
|
-
requestId:
|
|
239
|
-
status
|
|
184
|
+
requestId: err?.requestId || req?.id || uuid(),
|
|
185
|
+
status,
|
|
240
186
|
path: req.originalUrl || req.url
|
|
241
187
|
};
|
|
242
|
-
if (includeDetails &&
|
|
243
|
-
result.stack = err.stack.split('\n').map(
|
|
188
|
+
if (includeDetails && err?.stack) {
|
|
189
|
+
result.stack = err.stack.split('\n').map((line) => line.trim());
|
|
244
190
|
}
|
|
245
191
|
return res.status(status).json(result);
|
|
246
192
|
}
|
|
247
193
|
// Handle any other errors
|
|
248
194
|
return res
|
|
249
195
|
.status(status)
|
|
250
|
-
.json(createFinalErrorResponse(req, status,
|
|
196
|
+
.json(createFinalErrorResponse(req, status, err?.message || 'Internal Server Error', err, { includeDetails }));
|
|
251
197
|
};
|
|
252
198
|
}
|
|
253
199
|
/**
|
|
@@ -260,66 +206,30 @@ export function errorHandler(options) {
|
|
|
260
206
|
* @returns {Middleware} Express-compatible middleware
|
|
261
207
|
*/
|
|
262
208
|
export function healthCheck(options) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
allHealthy = true;
|
|
277
|
-
_c.label = 1;
|
|
278
|
-
case 1:
|
|
279
|
-
_c.trys.push([1, 8, 9, 10]);
|
|
280
|
-
checks_1 = __values(checks), checks_1_1 = checks_1.next();
|
|
281
|
-
_c.label = 2;
|
|
282
|
-
case 2:
|
|
283
|
-
if (!!checks_1_1.done) return [3 /*break*/, 7];
|
|
284
|
-
check = checks_1_1.value;
|
|
285
|
-
_c.label = 3;
|
|
286
|
-
case 3:
|
|
287
|
-
_c.trys.push([3, 5, , 6]);
|
|
288
|
-
return [4 /*yield*/, Promise.resolve(check.check())];
|
|
289
|
-
case 4:
|
|
290
|
-
result = _c.sent();
|
|
291
|
-
results[check.name] = !!result;
|
|
292
|
-
if (!result)
|
|
293
|
-
allHealthy = false;
|
|
294
|
-
return [3 /*break*/, 6];
|
|
295
|
-
case 5:
|
|
296
|
-
_a = _c.sent();
|
|
297
|
-
results[check.name] = false;
|
|
209
|
+
const path = options?.path || '/healthz';
|
|
210
|
+
const checks = options?.checks || [];
|
|
211
|
+
const detailed = options?.detailed !== false;
|
|
212
|
+
return async (req, res, next) => {
|
|
213
|
+
if (req.path !== path)
|
|
214
|
+
return next();
|
|
215
|
+
const results = {};
|
|
216
|
+
let allHealthy = true;
|
|
217
|
+
for (const check of checks) {
|
|
218
|
+
try {
|
|
219
|
+
const result = await Promise.resolve(check.check());
|
|
220
|
+
results[check.name] = !!result;
|
|
221
|
+
if (!result)
|
|
298
222
|
allHealthy = false;
|
|
299
|
-
return [3 /*break*/, 6];
|
|
300
|
-
case 6:
|
|
301
|
-
checks_1_1 = checks_1.next();
|
|
302
|
-
return [3 /*break*/, 2];
|
|
303
|
-
case 7: return [3 /*break*/, 10];
|
|
304
|
-
case 8:
|
|
305
|
-
e_1_1 = _c.sent();
|
|
306
|
-
e_1 = { error: e_1_1 };
|
|
307
|
-
return [3 /*break*/, 10];
|
|
308
|
-
case 9:
|
|
309
|
-
try {
|
|
310
|
-
if (checks_1_1 && !checks_1_1.done && (_b = checks_1.return)) _b.call(checks_1);
|
|
311
|
-
}
|
|
312
|
-
finally { if (e_1) throw e_1.error; }
|
|
313
|
-
return [7 /*endfinally*/];
|
|
314
|
-
case 10:
|
|
315
|
-
status = allHealthy ? HttpStatusCodes.OK : HttpStatusCodes.SERVICE_UNAVAILABLE;
|
|
316
|
-
response = detailed
|
|
317
|
-
? { status: allHealthy ? 'ok' : 'unhealthy', checks: results, timestamp: new Date().toISOString() }
|
|
318
|
-
: { status: allHealthy ? 'ok' : 'unhealthy' };
|
|
319
|
-
res.status(status).json(response);
|
|
320
|
-
return [2 /*return*/];
|
|
321
223
|
}
|
|
322
|
-
|
|
323
|
-
|
|
224
|
+
catch {
|
|
225
|
+
results[check.name] = false;
|
|
226
|
+
allHealthy = false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const status = allHealthy ? HttpStatusCodes.OK : HttpStatusCodes.SERVICE_UNAVAILABLE;
|
|
230
|
+
const response = detailed
|
|
231
|
+
? { status: allHealthy ? 'ok' : 'unhealthy', checks: results, timestamp: new Date().toISOString() }
|
|
232
|
+
: { status: allHealthy ? 'ok' : 'unhealthy' };
|
|
233
|
+
res.status(status).json(response);
|
|
234
|
+
};
|
|
324
235
|
}
|
|
325
|
-
//# sourceMappingURL=middleware.utils.js.map
|
|
@@ -121,4 +121,3 @@ export declare function isObject(value: unknown): value is Record<string, any>;
|
|
|
121
121
|
* @returns {string[]} Array of all paths in dot notation.
|
|
122
122
|
*/
|
|
123
123
|
export declare function getAllPaths(obj: Record<string, any>, parentPath?: string): string[];
|
|
124
|
-
//# sourceMappingURL=obj.utils.d.ts.map
|