@catbee/utils 0.0.1 → 0.0.2

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 (197) hide show
  1. package/README.md +303 -107
  2. package/build/esm/config.d.ts +12 -0
  3. package/build/esm/config.js +12 -0
  4. package/build/esm/config.js.map +1 -1
  5. package/build/esm/index.d.ts +1 -0
  6. package/build/esm/index.js +1 -0
  7. package/build/esm/index.js.map +1 -1
  8. package/build/esm/types/api-response.d.ts +82 -0
  9. package/build/esm/types/api-response.js.map +1 -1
  10. package/build/esm/utils/array.utils.d.ts +64 -1
  11. package/build/esm/utils/array.utils.js +139 -2
  12. package/build/esm/utils/array.utils.js.map +1 -1
  13. package/build/esm/utils/async.utils.d.ts +60 -1
  14. package/build/esm/utils/async.utils.js +160 -2
  15. package/build/esm/utils/async.utils.js.map +1 -1
  16. package/build/esm/utils/cache.utils.d.ts +67 -4
  17. package/build/esm/utils/cache.utils.js +210 -28
  18. package/build/esm/utils/cache.utils.js.map +1 -1
  19. package/build/esm/utils/context-store.utils.d.ts +101 -0
  20. package/build/esm/utils/context-store.utils.js +182 -0
  21. package/build/esm/utils/context-store.utils.js.map +1 -1
  22. package/build/esm/utils/crypto.utils.d.ts +110 -8
  23. package/build/esm/utils/crypto.utils.js +298 -15
  24. package/build/esm/utils/crypto.utils.js.map +1 -1
  25. package/build/esm/utils/decorators.utils.d.ts +40 -0
  26. package/build/esm/utils/decorators.utils.js +312 -0
  27. package/build/esm/utils/decorators.utils.js.map +1 -0
  28. package/build/esm/utils/dir.utils.d.ts +121 -0
  29. package/build/esm/utils/dir.utils.js +577 -0
  30. package/build/esm/utils/dir.utils.js.map +1 -1
  31. package/build/esm/utils/env.utils.d.ts +83 -0
  32. package/build/esm/utils/env.utils.js +233 -0
  33. package/build/esm/utils/env.utils.js.map +1 -1
  34. package/build/esm/utils/exception.utils.d.ts +116 -0
  35. package/build/esm/utils/exception.utils.js +322 -0
  36. package/build/esm/utils/exception.utils.js.map +1 -1
  37. package/build/esm/utils/fs.utils.d.ts +132 -0
  38. package/build/esm/utils/fs.utils.js +421 -0
  39. package/build/esm/utils/fs.utils.js.map +1 -1
  40. package/build/esm/utils/http-status-codes.d.ts +87 -178
  41. package/build/esm/utils/http-status-codes.js +92 -178
  42. package/build/esm/utils/http-status-codes.js.map +1 -1
  43. package/build/esm/utils/id.utils.d.ts +11 -10
  44. package/build/esm/utils/id.utils.js +29 -20
  45. package/build/esm/utils/id.utils.js.map +1 -1
  46. package/build/esm/utils/logger.utils.d.ts +24 -0
  47. package/build/esm/utils/logger.utils.js +54 -0
  48. package/build/esm/utils/logger.utils.js.map +1 -1
  49. package/build/esm/utils/middleware.utils.d.ts +72 -0
  50. package/build/esm/utils/middleware.utils.js +158 -0
  51. package/build/esm/utils/middleware.utils.js.map +1 -0
  52. package/build/esm/utils/obj.utils.d.ts +65 -3
  53. package/build/esm/utils/obj.utils.js +205 -6
  54. package/build/esm/utils/obj.utils.js.map +1 -1
  55. package/build/esm/utils/response.utils.d.ts +101 -0
  56. package/build/esm/utils/response.utils.js +153 -0
  57. package/build/esm/utils/response.utils.js.map +1 -1
  58. package/build/esm/utils/string.utils.d.ts +61 -5
  59. package/build/esm/utils/string.utils.js +101 -11
  60. package/build/esm/utils/string.utils.js.map +1 -1
  61. package/build/esm/utils/url.utils.d.ts +117 -0
  62. package/build/esm/utils/url.utils.js +287 -0
  63. package/build/esm/utils/url.utils.js.map +1 -1
  64. package/build/esm/utils/validate.utils.d.ts +110 -0
  65. package/build/esm/utils/validate.utils.js +186 -0
  66. package/build/esm/utils/validate.utils.js.map +1 -1
  67. package/build/esnext/config.d.ts +12 -0
  68. package/build/esnext/config.js +12 -0
  69. package/build/esnext/config.js.map +1 -1
  70. package/build/esnext/index.d.ts +1 -0
  71. package/build/esnext/index.js +1 -0
  72. package/build/esnext/index.js.map +1 -1
  73. package/build/esnext/types/api-response.d.ts +82 -0
  74. package/build/esnext/types/api-response.js.map +1 -1
  75. package/build/esnext/utils/array.utils.d.ts +64 -1
  76. package/build/esnext/utils/array.utils.js +129 -2
  77. package/build/esnext/utils/array.utils.js.map +1 -1
  78. package/build/esnext/utils/async.utils.d.ts +60 -1
  79. package/build/esnext/utils/async.utils.js +117 -1
  80. package/build/esnext/utils/async.utils.js.map +1 -1
  81. package/build/esnext/utils/cache.utils.d.ts +67 -4
  82. package/build/esnext/utils/cache.utils.js +137 -9
  83. package/build/esnext/utils/cache.utils.js.map +1 -1
  84. package/build/esnext/utils/context-store.utils.d.ts +101 -0
  85. package/build/esnext/utils/context-store.utils.js +168 -0
  86. package/build/esnext/utils/context-store.utils.js.map +1 -1
  87. package/build/esnext/utils/crypto.utils.d.ts +110 -8
  88. package/build/esnext/utils/crypto.utils.js +205 -15
  89. package/build/esnext/utils/crypto.utils.js.map +1 -1
  90. package/build/esnext/utils/decorators.utils.d.ts +40 -0
  91. package/build/esnext/utils/decorators.utils.js +155 -0
  92. package/build/esnext/utils/decorators.utils.js.map +1 -0
  93. package/build/esnext/utils/dir.utils.d.ts +121 -0
  94. package/build/esnext/utils/dir.utils.js +306 -0
  95. package/build/esnext/utils/dir.utils.js.map +1 -1
  96. package/build/esnext/utils/env.utils.d.ts +83 -0
  97. package/build/esnext/utils/env.utils.js +185 -0
  98. package/build/esnext/utils/env.utils.js.map +1 -1
  99. package/build/esnext/utils/exception.utils.d.ts +116 -0
  100. package/build/esnext/utils/exception.utils.js +213 -0
  101. package/build/esnext/utils/exception.utils.js.map +1 -1
  102. package/build/esnext/utils/fs.utils.d.ts +132 -0
  103. package/build/esnext/utils/fs.utils.js +268 -0
  104. package/build/esnext/utils/fs.utils.js.map +1 -1
  105. package/build/esnext/utils/http-status-codes.d.ts +87 -178
  106. package/build/esnext/utils/http-status-codes.js +92 -178
  107. package/build/esnext/utils/http-status-codes.js.map +1 -1
  108. package/build/esnext/utils/id.utils.d.ts +11 -10
  109. package/build/esnext/utils/id.utils.js +27 -19
  110. package/build/esnext/utils/id.utils.js.map +1 -1
  111. package/build/esnext/utils/logger.utils.d.ts +24 -0
  112. package/build/esnext/utils/logger.utils.js +42 -0
  113. package/build/esnext/utils/logger.utils.js.map +1 -1
  114. package/build/esnext/utils/middleware.utils.d.ts +72 -0
  115. package/build/esnext/utils/middleware.utils.js +157 -0
  116. package/build/esnext/utils/middleware.utils.js.map +1 -0
  117. package/build/esnext/utils/obj.utils.d.ts +65 -3
  118. package/build/esnext/utils/obj.utils.js +167 -3
  119. package/build/esnext/utils/obj.utils.js.map +1 -1
  120. package/build/esnext/utils/response.utils.d.ts +101 -0
  121. package/build/esnext/utils/response.utils.js +138 -0
  122. package/build/esnext/utils/response.utils.js.map +1 -1
  123. package/build/esnext/utils/string.utils.d.ts +61 -5
  124. package/build/esnext/utils/string.utils.js +110 -14
  125. package/build/esnext/utils/string.utils.js.map +1 -1
  126. package/build/esnext/utils/url.utils.d.ts +117 -0
  127. package/build/esnext/utils/url.utils.js +248 -0
  128. package/build/esnext/utils/url.utils.js.map +1 -1
  129. package/build/esnext/utils/validate.utils.d.ts +110 -0
  130. package/build/esnext/utils/validate.utils.js +184 -0
  131. package/build/esnext/utils/validate.utils.js.map +1 -1
  132. package/build/src/config.d.ts +12 -0
  133. package/build/src/config.js +12 -0
  134. package/build/src/config.js.map +1 -1
  135. package/build/src/index.d.ts +1 -0
  136. package/build/src/index.js +1 -0
  137. package/build/src/index.js.map +1 -1
  138. package/build/src/types/api-response.d.ts +82 -0
  139. package/build/src/types/api-response.js.map +1 -1
  140. package/build/src/utils/array.utils.d.ts +64 -1
  141. package/build/src/utils/array.utils.js +137 -4
  142. package/build/src/utils/array.utils.js.map +1 -1
  143. package/build/src/utils/async.utils.d.ts +60 -1
  144. package/build/src/utils/async.utils.js +124 -4
  145. package/build/src/utils/async.utils.js.map +1 -1
  146. package/build/src/utils/cache.utils.d.ts +67 -4
  147. package/build/src/utils/cache.utils.js +137 -9
  148. package/build/src/utils/cache.utils.js.map +1 -1
  149. package/build/src/utils/context-store.utils.d.ts +101 -0
  150. package/build/src/utils/context-store.utils.js +171 -1
  151. package/build/src/utils/context-store.utils.js.map +1 -1
  152. package/build/src/utils/crypto.utils.d.ts +110 -8
  153. package/build/src/utils/crypto.utils.js +224 -27
  154. package/build/src/utils/crypto.utils.js.map +1 -1
  155. package/build/src/utils/decorators.utils.d.ts +40 -0
  156. package/build/src/utils/decorators.utils.js +165 -0
  157. package/build/src/utils/decorators.utils.js.map +1 -0
  158. package/build/src/utils/dir.utils.d.ts +121 -0
  159. package/build/src/utils/dir.utils.js +316 -0
  160. package/build/src/utils/dir.utils.js.map +1 -1
  161. package/build/src/utils/env.utils.d.ts +83 -0
  162. package/build/src/utils/env.utils.js +186 -1
  163. package/build/src/utils/env.utils.js.map +1 -1
  164. package/build/src/utils/exception.utils.d.ts +116 -0
  165. package/build/src/utils/exception.utils.js +226 -1
  166. package/build/src/utils/exception.utils.js.map +1 -1
  167. package/build/src/utils/fs.utils.d.ts +132 -0
  168. package/build/src/utils/fs.utils.js +282 -0
  169. package/build/src/utils/fs.utils.js.map +1 -1
  170. package/build/src/utils/http-status-codes.d.ts +87 -178
  171. package/build/src/utils/http-status-codes.js +92 -178
  172. package/build/src/utils/http-status-codes.js.map +1 -1
  173. package/build/src/utils/id.utils.d.ts +11 -10
  174. package/build/src/utils/id.utils.js +27 -19
  175. package/build/src/utils/id.utils.js.map +1 -1
  176. package/build/src/utils/logger.utils.d.ts +24 -0
  177. package/build/src/utils/logger.utils.js +45 -0
  178. package/build/src/utils/logger.utils.js.map +1 -1
  179. package/build/src/utils/middleware.utils.d.ts +72 -0
  180. package/build/src/utils/middleware.utils.js +163 -0
  181. package/build/src/utils/middleware.utils.js.map +1 -0
  182. package/build/src/utils/obj.utils.d.ts +65 -3
  183. package/build/src/utils/obj.utils.js +177 -7
  184. package/build/src/utils/obj.utils.js.map +1 -1
  185. package/build/src/utils/response.utils.d.ts +101 -0
  186. package/build/src/utils/response.utils.js +146 -1
  187. package/build/src/utils/response.utils.js.map +1 -1
  188. package/build/src/utils/string.utils.d.ts +61 -5
  189. package/build/src/utils/string.utils.js +122 -20
  190. package/build/src/utils/string.utils.js.map +1 -1
  191. package/build/src/utils/url.utils.d.ts +117 -0
  192. package/build/src/utils/url.utils.js +257 -0
  193. package/build/src/utils/url.utils.js.map +1 -1
  194. package/build/src/utils/validate.utils.d.ts +110 -0
  195. package/build/src/utils/validate.utils.js +198 -0
  196. package/build/src/utils/validate.utils.js.map +1 -1
  197. package/package.json +20 -12
@@ -1,6 +1,4 @@
1
- import { randomUUID } from "crypto";
2
- import { ulid } from "ulid";
3
- import { nanoid } from "nanoid";
1
+ import { randomUUID, randomBytes } from "crypto";
4
2
  /**
5
3
  * Generates a UUID v4 string (RFC 4122).
6
4
  *
@@ -10,21 +8,21 @@ export function uuid() {
10
8
  return randomUUID();
11
9
  }
12
10
  /**
13
- * Generates a ULID (Universally Unique Lexicographically Sortable Identifier).
11
+ * Generates a nanoid-style random ID (URL-safe, customizable length).
14
12
  *
15
- * @returns {string} ULID string (26 chars, Crockford Base32, e.g., '01H7ZXS9FJKPX06P1AYZKCGHQF').
13
+ * @param {number} length - Length of the ID (default: 21).
14
+ * @returns {string} Nanoid-style random string.
16
15
  */
17
- export function ulidString() {
18
- return ulid();
19
- }
20
- /**
21
- * Generates a nanoid string (URL-friendly, collision-resistant, customizable size).
22
- *
23
- * @param {number} [size=21] - Number of characters for the ID (default: 21).
24
- * @returns {string} nanoid string.
25
- */
26
- export function nanoId(size = 21) {
27
- return nanoid(size);
16
+ export function nanoId(length = 21) {
17
+ if (length <= 0)
18
+ return "";
19
+ let id = "";
20
+ while (id.length < length) {
21
+ id += randomBytes(Math.ceil((length * 3) / 4))
22
+ .toString("base64url")
23
+ .replace(/[+/=]/g, "");
24
+ }
25
+ return id.slice(0, length);
28
26
  }
29
27
  /**
30
28
  * Generates a cryptographically strong random hex string.
@@ -33,10 +31,11 @@ export function nanoId(size = 21) {
33
31
  * @returns {string} Random hex string.
34
32
  */
35
33
  export function randomHex(byteLength = 16) {
36
- // Node: crypto.getRandomValues is not available; use randomBytes if needed.
37
- // If using browser target, replace this impl accordingly.
38
- return Buffer.from(crypto.getRandomValues(new Uint8Array(byteLength)))
34
+ // Use Node.js crypto for both Node and browser compatibility
35
+ // Prefer randomBytes if available (Node), fallback to getRandomValues for browser (not used here)
36
+ return randomBytes(byteLength)
39
37
  .toString("hex")
38
+ .padStart(byteLength * 2, "0")
40
39
  .slice(0, byteLength * 2);
41
40
  }
42
41
  /**
@@ -50,4 +49,13 @@ export function randomInt(min, max) {
50
49
  const range = max - min + 1;
51
50
  return Math.floor(Math.random() * range) + min;
52
51
  }
52
+ /**
53
+ * Generates a cryptographically strong random base64 string.
54
+ *
55
+ * @param {number} byteLength - Number of random bytes (default: 16).
56
+ * @returns {string} Random base64 string (URL-safe, no padding).
57
+ */
58
+ export function randomBase64(byteLength = 16) {
59
+ return randomBytes(byteLength).toString("base64url");
60
+ }
53
61
  //# sourceMappingURL=id.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"id.utils.js","sourceRoot":"","sources":["../../../src/utils/id.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;GAIG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,IAAI,EAAE,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe,EAAE;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,aAAqB,EAAE;IAC/C,4EAA4E;IAC5E,0DAA0D;IAC1D,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;SACnE,QAAQ,CAAC,KAAK,CAAC;SACf,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AACjD,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { ulid } from \"ulid\";\nimport { nanoid } from \"nanoid\";\n\n/**\n * Generates a UUID v4 string (RFC 4122).\n *\n * @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')\n */\nexport function uuid(): string {\n return randomUUID();\n}\n\n/**\n * Generates a ULID (Universally Unique Lexicographically Sortable Identifier).\n *\n * @returns {string} ULID string (26 chars, Crockford Base32, e.g., '01H7ZXS9FJKPX06P1AYZKCGHQF').\n */\nexport function ulidString(): string {\n return ulid();\n}\n\n/**\n * Generates a nanoid string (URL-friendly, collision-resistant, customizable size).\n *\n * @param {number} [size=21] - Number of characters for the ID (default: 21).\n * @returns {string} nanoid string.\n */\nexport function nanoId(size: number = 21): string {\n return nanoid(size);\n}\n\n/**\n * Generates a cryptographically strong random hex string.\n *\n * @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).\n * @returns {string} Random hex string.\n */\nexport function randomHex(byteLength: number = 16): string {\n // Node: crypto.getRandomValues is not available; use randomBytes if needed.\n // If using browser target, replace this impl accordingly.\n return Buffer.from(crypto.getRandomValues(new Uint8Array(byteLength)))\n .toString(\"hex\")\n .slice(0, byteLength * 2);\n}\n\n/**\n * Generates a random integer between min (inclusive) and max (inclusive).\n *\n * @param {number} min - Minimum value.\n * @param {number} max - Maximum value.\n * @returns {number} Random integer in range.\n */\nexport function randomInt(min: number, max: number): number {\n const range = max - min + 1;\n return Math.floor(Math.random() * range) + min;\n}\n"]}
1
+ {"version":3,"file":"id.utils.js","sourceRoot":"","sources":["../../../src/utils/id.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEjD;;;;GAIG;AACH,MAAM,UAAU,IAAI;IAClB,OAAO,UAAU,EAAE,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,SAAiB,EAAE;IACxC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAC3B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC1B,EAAE,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;aAC3C,QAAQ,CAAC,WAAW,CAAC;aACrB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,aAAqB,EAAE;IAC/C,6DAA6D;IAC7D,kGAAkG;IAClG,OAAO,WAAW,CAAC,UAAU,CAAC;SAC3B,QAAQ,CAAC,KAAK,CAAC;SACf,QAAQ,CAAC,UAAU,GAAG,CAAC,EAAE,GAAG,CAAC;SAC7B,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,aAAqB,EAAE;IAClD,OAAO,WAAW,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { randomUUID, randomBytes } from \"crypto\";\n\n/**\n * Generates a UUID v4 string (RFC 4122).\n *\n * @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')\n */\nexport function uuid(): string {\n return randomUUID();\n}\n\n/**\n * Generates a nanoid-style random ID (URL-safe, customizable length).\n *\n * @param {number} length - Length of the ID (default: 21).\n * @returns {string} Nanoid-style random string.\n */\nexport function nanoId(length: number = 21): string {\n if (length <= 0) return \"\";\n let id = \"\";\n while (id.length < length) {\n id += randomBytes(Math.ceil((length * 3) / 4))\n .toString(\"base64url\")\n .replace(/[+/=]/g, \"\");\n }\n return id.slice(0, length);\n}\n\n/**\n * Generates a cryptographically strong random hex string.\n *\n * @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).\n * @returns {string} Random hex string.\n */\nexport function randomHex(byteLength: number = 16): string {\n // Use Node.js crypto for both Node and browser compatibility\n // Prefer randomBytes if available (Node), fallback to getRandomValues for browser (not used here)\n return randomBytes(byteLength)\n .toString(\"hex\")\n .padStart(byteLength * 2, \"0\")\n .slice(0, byteLength * 2);\n}\n\n/**\n * Generates a random integer between min (inclusive) and max (inclusive).\n *\n * @param {number} min - Minimum value.\n * @param {number} max - Maximum value.\n * @returns {number} Random integer in range.\n */\nexport function randomInt(min: number, max: number): number {\n const range = max - min + 1;\n return Math.floor(Math.random() * range) + min;\n}\n\n/**\n * Generates a cryptographically strong random base64 string.\n *\n * @param {number} byteLength - Number of random bytes (default: 16).\n * @returns {string} Random base64 string (URL-safe, no padding).\n */\nexport function randomBase64(byteLength: number = 16): string {\n return randomBytes(byteLength).toString(\"base64url\");\n}\n"]}
@@ -12,4 +12,28 @@ export declare const _globalThis: typeof globalThis;
12
12
  * @returns {Logger} The logger instance (request-bound or global root logger)
13
13
  */
14
14
  export declare function getLogger(): Logger;
15
+ /**
16
+ * Creates a child logger with additional context.
17
+ *
18
+ * @param {Record<string, any>} bindings - Properties to attach to all log records
19
+ * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global)
20
+ * @returns {Logger} Child logger with merged context
21
+ */
22
+ export declare function createChildLogger(bindings: Record<string, any>, parentLogger?: Logger): Logger;
23
+ /**
24
+ * Creates a request-scoped logger with request ID and stores it in context
25
+ *
26
+ * @param {string} requestId - Unique request identifier
27
+ * @param {object} [additionalContext] - Additional context to include in logs
28
+ * @returns {Logger} Request-scoped logger instance
29
+ */
30
+ export declare function createRequestLogger(requestId: string, additionalContext?: Record<string, any>): Logger;
31
+ /**
32
+ * Utility to safely log errors with proper stack trace extraction
33
+ *
34
+ * @param {Error|unknown} error - Error object to log
35
+ * @param {string} [message] - Optional message to include
36
+ * @param {Record<string, any>} [context] - Additional context properties
37
+ */
38
+ export declare function logError(error: Error | unknown, message?: string, context?: Record<string, any>): void;
15
39
  //# sourceMappingURL=logger.utils.d.ts.map
@@ -56,4 +56,46 @@ export function getLogger() {
56
56
  }
57
57
  return _global[GLOBAL_LOGGER_KEY];
58
58
  }
59
+ /**
60
+ * Creates a child logger with additional context.
61
+ *
62
+ * @param {Record<string, any>} bindings - Properties to attach to all log records
63
+ * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global)
64
+ * @returns {Logger} Child logger with merged context
65
+ */
66
+ export function createChildLogger(bindings, parentLogger) {
67
+ const logger = parentLogger || getLogger();
68
+ return logger.child(bindings);
69
+ }
70
+ /**
71
+ * Creates a request-scoped logger with request ID and stores it in context
72
+ *
73
+ * @param {string} requestId - Unique request identifier
74
+ * @param {object} [additionalContext] - Additional context to include in logs
75
+ * @returns {Logger} Request-scoped logger instance
76
+ */
77
+ export function createRequestLogger(requestId, additionalContext = {}) {
78
+ const logger = createChildLogger(Object.assign({ requestId }, additionalContext));
79
+ try {
80
+ ContextStore.set(StoreKeys.LOGGER, logger);
81
+ }
82
+ catch (_a) {
83
+ // Context not initialized, can't store logger
84
+ logger.debug("Failed to store logger in context - AsyncLocalStorage not initialized");
85
+ }
86
+ return logger;
87
+ }
88
+ /**
89
+ * Utility to safely log errors with proper stack trace extraction
90
+ *
91
+ * @param {Error|unknown} error - Error object to log
92
+ * @param {string} [message] - Optional message to include
93
+ * @param {Record<string, any>} [context] - Additional context properties
94
+ */
95
+ export function logError(error, message, context) {
96
+ const logger = getLogger();
97
+ const errObj = error instanceof Error ? error : new Error(String(error));
98
+ const logContext = Object.assign(Object.assign({}, context), { err: errObj });
99
+ logger.error(logContext, message || errObj.message);
100
+ }
59
101
  //# sourceMappingURL=logger.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.utils.js","sourceRoot":"","sources":["../../../src/utils/logger.utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAiB,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;GAEG;AACH,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;AAChF,MAAM,OAAO,GAAG,WAAyD,CAAC;AAE1E;;;;;GAKG;AACH,SAAS,WAAW;IAClB,MAAM,SAAS,GAAkB;QAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI;QACxB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK;QAC1B,MAAM,EAAE;YACN,KAAK,EAAE,CAAC,mBAAmB,EAAE,KAAK,CAAC;YACnC,MAAM,CAAC,KAAK,EAAE,IAAI;gBAChB,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;oBACtB,OAAO,KAAK,CAAC,OAAO,CAClB,6BAA6B,EAC7B,kBAAkB,CACnB,CAAC;gBACJ,CAAC;qBAAM,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,eAAe,EAAE,CAAC;oBACvC,OAAO,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;gBAC5C,CAAC;gBACD,OAAO,KAAK,CAAC;YACf,CAAC;SACF;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAC/B,SAAS,CAAC,SAAS,GAAG,gBAAgB,CAAC,OAAO,CAAC;IACjD,CAAC;IAED,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAC7C,OAAO,CAAC,iBAAiB,CAAC,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAS,SAAS,CAAC,MAAM,CAAC,CAAC;IAC1D,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChC,WAAW,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import pino, { LoggerOptions, stdTimeFunctions } from \"pino\";\nimport type { Logger } from \"pino\"; // Type-only import\nimport { Config } from \"../config\";\nimport { ContextStore, StoreKeys } from \"./context-store.utils\";\n\n/**\n * Symbol used to store the root logger in the Node.js global object.\n */\nconst GLOBAL_LOGGER_KEY = Symbol.for(\"logger\");\n\n/**\n * Use an object compatible with either modern or legacy global scopes.\n */\nexport const _globalThis = typeof globalThis === \"object\" ? globalThis : global;\nconst _global = _globalThis as unknown as { [GLOBAL_LOGGER_KEY]: Logger };\n\n/**\n * Initializes the global root logger according to app configuration.\n *\n * - Sets log name, level, timestamp, and redaction for sensitive fields.\n * - Uses singleton in global symbol registry.\n */\nfunction setupLogger(): void {\n const logParams: LoggerOptions = {\n name: Config.Logger.name,\n level: Config.Logger.level,\n redact: {\n paths: [\"req.authorization\", \"url\"],\n censor(value, path) {\n if (path[0] === \"url\") {\n return value.replace(\n /access_token=[a-zA-Z0-9_-]*/,\n \"access_token=***\",\n );\n } else if (path[1] === \"authorization\") {\n return value.replace(/\\s+(\\S+)$/, \" ***\");\n }\n return \"***\";\n },\n },\n };\n\n if (Config.Logger.isoTimestamp) {\n logParams.timestamp = stdTimeFunctions.isoTime;\n }\n\n _global[GLOBAL_LOGGER_KEY] = pino(logParams);\n _global[GLOBAL_LOGGER_KEY].debug(\"Logger initialized\");\n}\n\n/**\n * Retrieves the current logger instance:\n * - Returns a request-scoped logger from AsyncLocalStorage if available\n * - Falls back to the global (singleton) logger\n * - Initializes the global logger if not created yet\n *\n * @returns {Logger} The logger instance (request-bound or global root logger)\n */\nexport function getLogger(): Logger {\n const logger = ContextStore.get<Logger>(StoreKeys.LOGGER);\n if (logger) return logger;\n\n if (!_global[GLOBAL_LOGGER_KEY]) {\n setupLogger();\n }\n\n return _global[GLOBAL_LOGGER_KEY];\n}\n"]}
1
+ {"version":3,"file":"logger.utils.js","sourceRoot":"","sources":["../../../src/utils/logger.utils.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAiB,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAE7D,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;GAEG;AACH,MAAM,iBAAiB,GAAG,MAAM,CAAC,GAAG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C;IAE1B,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChC,WAAW,EAAE,CAAC;IAChB,CAAC;IAED,OAAO,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACpC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAA6B,EAC7B,YAAqB;IAErB,MAAM,MAAM,GAAG,YAAY,IAAI,SAAS,EAAE,CAAC;IAC3C,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAiB,EACjB,oBAAyC,EAAE;IAE3C,MAAM,MAAM,GAAG,iBAAiB,iBAC9B,SAAS,IACN,iBAAiB,EACpB,CAAC;IAEH,IAAI,CAAC;QACH,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAAC,WAAM,CAAC;QACP,8CAA8C;QAC9C,MAAM,CAAC,KAAK,CACV,uEAAuE,CACxE,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAsB,EACtB,OAAgB,EAChB,OAA6B;IAE7B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAE3B,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACzE,MAAM,UAAU,mCACX,OAAO,KACV,GAAG,EAAE,MAAM,GACZ,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import pino, { LoggerOptions, stdTimeFunctions } from \"pino\";\nimport type { Logger } from \"pino\"; // Type-only import\nimport { Config } from \"../config\";\nimport { ContextStore, StoreKeys } from \"./context-store.utils\";\n\n/**\n * Symbol used to store the root logger in the Node.js global object.\n */\nconst GLOBAL_LOGGER_KEY = Symbol.for(\"logger\");\n\n/**\n * Use an object compatible with either modern or legacy global scopes.\n */\nexport const _globalThis = typeof globalThis === \"object\" ? globalThis : global;\nconst _global = _globalThis as unknown as { [GLOBAL_LOGGER_KEY]: Logger };\n\n/**\n * Initializes the global root logger according to app configuration.\n *\n * - Sets log name, level, timestamp, and redaction for sensitive fields.\n * - Uses singleton in global symbol registry.\n */\nfunction setupLogger(): void {\n const logParams: LoggerOptions = {\n name: Config.Logger.name,\n level: Config.Logger.level,\n redact: {\n paths: [\"req.authorization\", \"url\"],\n censor(value, path) {\n if (path[0] === \"url\") {\n return value.replace(\n /access_token=[a-zA-Z0-9_-]*/,\n \"access_token=***\",\n );\n } else if (path[1] === \"authorization\") {\n return value.replace(/\\s+(\\S+)$/, \" ***\");\n }\n return \"***\";\n },\n },\n };\n\n if (Config.Logger.isoTimestamp) {\n logParams.timestamp = stdTimeFunctions.isoTime;\n }\n\n _global[GLOBAL_LOGGER_KEY] = pino(logParams);\n _global[GLOBAL_LOGGER_KEY].debug(\"Logger initialized\");\n}\n\n/**\n * Retrieves the current logger instance:\n * - Returns a request-scoped logger from AsyncLocalStorage if available\n * - Falls back to the global (singleton) logger\n * - Initializes the global logger if not created yet\n *\n * @returns {Logger} The logger instance (request-bound or global root logger)\n */\nexport function getLogger(): Logger {\n const logger = ContextStore.get<Logger>(StoreKeys.LOGGER);\n if (logger) return logger;\n\n if (!_global[GLOBAL_LOGGER_KEY]) {\n setupLogger();\n }\n\n return _global[GLOBAL_LOGGER_KEY];\n}\n\n/**\n * Creates a child logger with additional context.\n *\n * @param {Record<string, any>} bindings - Properties to attach to all log records\n * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global)\n * @returns {Logger} Child logger with merged context\n */\nexport function createChildLogger(\n bindings: Record<string, any>,\n parentLogger?: Logger,\n): Logger {\n const logger = parentLogger || getLogger();\n return logger.child(bindings);\n}\n\n/**\n * Creates a request-scoped logger with request ID and stores it in context\n *\n * @param {string} requestId - Unique request identifier\n * @param {object} [additionalContext] - Additional context to include in logs\n * @returns {Logger} Request-scoped logger instance\n */\nexport function createRequestLogger(\n requestId: string,\n additionalContext: Record<string, any> = {},\n): Logger {\n const logger = createChildLogger({\n requestId,\n ...additionalContext,\n });\n\n try {\n ContextStore.set(StoreKeys.LOGGER, logger);\n } catch {\n // Context not initialized, can't store logger\n logger.debug(\n \"Failed to store logger in context - AsyncLocalStorage not initialized\",\n );\n }\n\n return logger;\n}\n\n/**\n * Utility to safely log errors with proper stack trace extraction\n *\n * @param {Error|unknown} error - Error object to log\n * @param {string} [message] - Optional message to include\n * @param {Record<string, any>} [context] - Additional context properties\n */\nexport function logError(\n error: Error | unknown,\n message?: string,\n context?: Record<string, any>,\n): void {\n const logger = getLogger();\n\n const errObj = error instanceof Error ? error : new Error(String(error));\n const logContext = {\n ...context,\n err: errObj,\n };\n\n logger.error(logContext, message || errObj.message);\n}\n"]}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Type definitions for Express-compatible middleware
3
+ */
4
+ export type Request = {
5
+ headers: Record<string, string | string[] | undefined>;
6
+ method: string;
7
+ url: string;
8
+ ip?: string;
9
+ body?: any;
10
+ query?: Record<string, any>;
11
+ params?: Record<string, any>;
12
+ [key: string]: any;
13
+ };
14
+ export type Response = {
15
+ status: (code: number) => Response;
16
+ json: (data: any) => void;
17
+ send: (data: any) => void;
18
+ setHeader: (name: string, value: string | string[]) => void;
19
+ end: (data?: any) => void;
20
+ on: (event: string, callback: (...args: any[]) => void) => void;
21
+ [key: string]: any;
22
+ };
23
+ export type NextFunction = (err?: Error | any) => void;
24
+ export type Middleware = (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
25
+ /**
26
+ * Attaches a unique request ID to each request.
27
+ * Useful for request tracing and correlation between logs.
28
+ *
29
+ * @param {object} [options] - Configuration options
30
+ * @param {string} [options.headerName='X-Request-ID'] - Header name for request ID
31
+ * @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response
32
+ * @returns {Middleware} Express-compatible middleware
33
+ */
34
+ export declare function requestId(options?: {
35
+ headerName?: string;
36
+ exposeHeader?: boolean;
37
+ }): Middleware;
38
+ /**
39
+ * Measures request processing time and logs or adds it to response headers.
40
+ *
41
+ * @param {object} [options] - Configuration options
42
+ * @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header
43
+ * @param {boolean} [options.logOnComplete=false] - Whether to log timing info
44
+ * @returns {Middleware} Express-compatible middleware
45
+ */
46
+ export declare function responseTime(options?: {
47
+ addHeader?: boolean;
48
+ logOnComplete?: boolean;
49
+ }): Middleware;
50
+ /**
51
+ * Request timeout middleware.
52
+ * Aborts requests that take too long to process.
53
+ *
54
+ * @param {number} [timeoutMs=30000] - Timeout in milliseconds
55
+ * @returns {Middleware} Express-compatible middleware
56
+ */
57
+ export declare function timeout(timeoutMs?: number): Middleware;
58
+ /**
59
+ * Global error handling middleware with enhanced features.
60
+ *
61
+ * @param {object} [options] - Error handler options
62
+ * @param {boolean} [options.logErrors=true] - Whether to log errors
63
+ * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production
64
+ * @param {Function} [options.logger=getLogger().error] - Custom logging function
65
+ * @returns {(err: any, req: Request, res: Response, next: NextFunction) => void} Error middleware
66
+ */
67
+ export declare function errorHandler(options?: {
68
+ logErrors?: boolean;
69
+ includeDetails?: boolean;
70
+ logger?: (message: string, error: any) => void;
71
+ }): (err: any, req: Request, res: Response, _next: NextFunction) => void;
72
+ //# sourceMappingURL=middleware.utils.d.ts.map
@@ -0,0 +1,157 @@
1
+ import { randomUUID } from "crypto";
2
+ import { Config } from "../config";
3
+ import { uuid } from "./id.utils";
4
+ import { HttpStatusCodes } from "./http-status-codes";
5
+ import { ErrorResponse } from "./response.utils";
6
+ import { Env } from "./env.utils";
7
+ import { getLogger } from "./logger.utils";
8
+ /**
9
+ * Attaches a unique request ID to each request.
10
+ * Useful for request tracing and correlation between logs.
11
+ *
12
+ * @param {object} [options] - Configuration options
13
+ * @param {string} [options.headerName='X-Request-ID'] - Header name for request ID
14
+ * @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response
15
+ * @returns {Middleware} Express-compatible middleware
16
+ */
17
+ export function requestId(options) {
18
+ const headerName = (options === null || options === void 0 ? void 0 : options.headerName) || "X-Request-ID";
19
+ const exposeHeader = (options === null || options === void 0 ? void 0 : options.exposeHeader) !== false;
20
+ return (req, res, next) => {
21
+ // Use existing request ID from header or generate a new one
22
+ const existingId = req.headers[headerName.toLowerCase()];
23
+ const id = existingId || randomUUID();
24
+ // Attach ID to request object
25
+ req.id = id;
26
+ // Add ID to response headers
27
+ if (exposeHeader) {
28
+ res.setHeader(headerName, id);
29
+ }
30
+ next();
31
+ };
32
+ }
33
+ /**
34
+ * Measures request processing time and logs or adds it to response headers.
35
+ *
36
+ * @param {object} [options] - Configuration options
37
+ * @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header
38
+ * @param {boolean} [options.logOnComplete=false] - Whether to log timing info
39
+ * @returns {Middleware} Express-compatible middleware
40
+ */
41
+ export function responseTime(options) {
42
+ const addHeader = (options === null || options === void 0 ? void 0 : options.addHeader) !== false;
43
+ const logOnComplete = (options === null || options === void 0 ? void 0 : options.logOnComplete) === true;
44
+ return (req, res, next) => {
45
+ const start = process.hrtime();
46
+ // Function to calculate elapsed time
47
+ const calculateDuration = () => {
48
+ const diff = process.hrtime(start);
49
+ return diff[0] * 1e3 + diff[1] * 1e-6; // Convert to ms
50
+ };
51
+ // Handle response completion
52
+ res.on("finish", () => {
53
+ const duration = calculateDuration();
54
+ if (addHeader) {
55
+ res.setHeader("X-Response-Time", `${duration.toFixed(2)}ms`);
56
+ }
57
+ if (logOnComplete) {
58
+ const { method, url } = req;
59
+ getLogger().info(`${method} ${url} - ${duration.toFixed(2)}ms`);
60
+ }
61
+ });
62
+ next();
63
+ };
64
+ }
65
+ /**
66
+ * Request timeout middleware.
67
+ * Aborts requests that take too long to process.
68
+ *
69
+ * @param {number} [timeoutMs=30000] - Timeout in milliseconds
70
+ * @returns {Middleware} Express-compatible middleware
71
+ */
72
+ export function timeout(timeoutMs = Config.Http.timeout) {
73
+ return (req, res, next) => {
74
+ // Set timeout for the request
75
+ const timer = setTimeout(() => {
76
+ res.status(408).json({
77
+ error: true,
78
+ message: "Request timeout",
79
+ status: 408,
80
+ timestamp: new Date().toISOString(),
81
+ });
82
+ }, timeoutMs);
83
+ // Clear timeout when response is sent
84
+ res.on("finish", () => {
85
+ clearTimeout(timer);
86
+ });
87
+ next();
88
+ };
89
+ }
90
+ /**
91
+ * Creates a standardized error response object for API errors.
92
+ *
93
+ * @param {string} message - Error message
94
+ * @param {Request} req - Express request object
95
+ * @param {any} error - Original error object
96
+ * @param {object} [options] - Additional options
97
+ * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production
98
+ * @returns {object} Formatted error response
99
+ */
100
+ const createErrorResponse = (message, req, error, options) => {
101
+ const isDev = Env.isDev();
102
+ const includeDetails = (options === null || options === void 0 ? void 0 : options.includeDetails) && isDev;
103
+ const response = {
104
+ error: true,
105
+ message,
106
+ timestamp: new Date().toISOString(),
107
+ requestId: (error === null || error === void 0 ? void 0 : error.requestId) || req.id || uuid(),
108
+ path: req.originalUrl || req.url,
109
+ };
110
+ // Include error code if present
111
+ if (error === null || error === void 0 ? void 0 : error.code) {
112
+ response.code = error.code;
113
+ }
114
+ // Include stack trace in development mode if requested
115
+ if (includeDetails && (error === null || error === void 0 ? void 0 : error.stack)) {
116
+ response.stack = error.stack.split("\n").map((line) => line.trim());
117
+ }
118
+ return response;
119
+ };
120
+ /**
121
+ * Global error handling middleware with enhanced features.
122
+ *
123
+ * @param {object} [options] - Error handler options
124
+ * @param {boolean} [options.logErrors=true] - Whether to log errors
125
+ * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production
126
+ * @param {Function} [options.logger=getLogger().error] - Custom logging function
127
+ * @returns {(err: any, req: Request, res: Response, next: NextFunction) => void} Error middleware
128
+ */
129
+ export function errorHandler(options) {
130
+ const logErrors = (options === null || options === void 0 ? void 0 : options.logErrors) !== false;
131
+ const includeDetails = (options === null || options === void 0 ? void 0 : options.includeDetails) === true;
132
+ const logger = (options === null || options === void 0 ? void 0 : options.logger) || getLogger().error;
133
+ return (err, req, res, _next) => {
134
+ // Determine status code
135
+ const status = (err === null || err === void 0 ? void 0 : err.status) || (err === null || err === void 0 ? void 0 : err.statusCode) || HttpStatusCodes.INTERNAL_SERVER_ERROR;
136
+ // Log error if enabled
137
+ if (logErrors) {
138
+ const logMessage = `[ERROR] ${req.method} ${req.originalUrl || req.url}: ${err.message || "Unknown error"}`;
139
+ logger(logMessage, err);
140
+ }
141
+ // Handle ErrorResponse instances (our custom error class)
142
+ if (err instanceof ErrorResponse) {
143
+ return res.status(status).json({
144
+ error: err.error,
145
+ message: err.message,
146
+ timestamp: err.timestamp,
147
+ requestId: err.requestId || req.id || uuid(),
148
+ path: req.originalUrl || req.url,
149
+ });
150
+ }
151
+ // Handle any other errors
152
+ return res.status(status).json(createErrorResponse((err === null || err === void 0 ? void 0 : err.message) || "Internal Server Error", req, err, {
153
+ includeDetails,
154
+ }));
155
+ };
156
+ }
157
+ //# sourceMappingURL=middleware.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.utils.js","sourceRoot":"","sources":["../../../src/utils/middleware.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE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AO,KAAI,uBAAuB,EAAE,GAAG,EAAE,GAAG,EAAE;YACrE,cAAc;SACf,CAAC,CACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"crypto\";\nimport { Config } from \"../config\";\nimport { uuid } from \"./id.utils\";\nimport { HttpStatusCodes } from \"./http-status-codes\";\nimport { ErrorResponse } from \"./response.utils\";\nimport { Env } from \"./env.utils\";\nimport { getLogger } from \"./logger.utils\";\n\n/**\n * Type definitions for Express-compatible middleware\n */\nexport type Request = {\n headers: Record<string, string | string[] | undefined>;\n method: string;\n url: string;\n ip?: string;\n body?: any;\n query?: Record<string, any>;\n params?: Record<string, any>;\n [key: string]: any;\n};\n\nexport type Response = {\n status: (code: number) => Response;\n json: (data: any) => void;\n send: (data: any) => void;\n setHeader: (name: string, value: string | string[]) => void;\n end: (data?: any) => void;\n on: (event: string, callback: (...args: any[]) => void) => void;\n [key: string]: any;\n};\n\nexport type NextFunction = (err?: Error | any) => void;\n\nexport type Middleware = (\n req: Request,\n res: Response,\n next: NextFunction,\n) => void | Promise<void>;\n\n/**\n * Attaches a unique request ID to each request.\n * Useful for request tracing and correlation between logs.\n *\n * @param {object} [options] - Configuration options\n * @param {string} [options.headerName='X-Request-ID'] - Header name for request ID\n * @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response\n * @returns {Middleware} Express-compatible middleware\n */\nexport function requestId(options?: {\n headerName?: string;\n exposeHeader?: boolean;\n}): Middleware {\n const headerName = options?.headerName || \"X-Request-ID\";\n const exposeHeader = options?.exposeHeader !== false;\n\n return (req, res, next) => {\n // Use existing request ID from header or generate a new one\n const existingId = req.headers[headerName.toLowerCase()];\n const id = (existingId as string) || randomUUID();\n\n // Attach ID to request object\n req.id = id;\n\n // Add ID to response headers\n if (exposeHeader) {\n res.setHeader(headerName, id);\n }\n\n next();\n };\n}\n\n/**\n * Measures request processing time and logs or adds it to response headers.\n *\n * @param {object} [options] - Configuration options\n * @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header\n * @param {boolean} [options.logOnComplete=false] - Whether to log timing info\n * @returns {Middleware} Express-compatible middleware\n */\nexport function responseTime(options?: {\n addHeader?: boolean;\n logOnComplete?: boolean;\n}): Middleware {\n const addHeader = options?.addHeader !== false;\n const logOnComplete = options?.logOnComplete === true;\n\n return (req, res, next) => {\n const start = process.hrtime();\n\n // Function to calculate elapsed time\n const calculateDuration = (): number => {\n const diff = process.hrtime(start);\n return diff[0] * 1e3 + diff[1] * 1e-6; // Convert to ms\n };\n\n // Handle response completion\n res.on(\"finish\", () => {\n const duration = calculateDuration();\n\n if (addHeader) {\n res.setHeader(\"X-Response-Time\", `${duration.toFixed(2)}ms`);\n }\n\n if (logOnComplete) {\n const { method, url } = req;\n getLogger().info(`${method} ${url} - ${duration.toFixed(2)}ms`);\n }\n });\n\n next();\n };\n}\n\n/**\n * Request timeout middleware.\n * Aborts requests that take too long to process.\n *\n * @param {number} [timeoutMs=30000] - Timeout in milliseconds\n * @returns {Middleware} Express-compatible middleware\n */\nexport function timeout(timeoutMs: number = Config.Http.timeout): Middleware {\n return (req, res, next) => {\n // Set timeout for the request\n const timer = setTimeout(() => {\n res.status(408).json({\n error: true,\n message: \"Request timeout\",\n status: 408,\n timestamp: new Date().toISOString(),\n });\n }, timeoutMs);\n\n // Clear timeout when response is sent\n res.on(\"finish\", () => {\n clearTimeout(timer);\n });\n\n next();\n };\n}\n\n/**\n * Creates a standardized error response object for API errors.\n *\n * @param {string} message - Error message\n * @param {Request} req - Express request object\n * @param {any} error - Original error object\n * @param {object} [options] - Additional options\n * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production\n * @returns {object} Formatted error response\n */\nconst createErrorResponse = (\n message: string,\n req: Request,\n error: any,\n options?: { includeDetails?: boolean },\n) => {\n const isDev = Env.isDev();\n const includeDetails = options?.includeDetails && isDev;\n\n const response: Record<string, any> = {\n error: true,\n message,\n timestamp: new Date().toISOString(),\n requestId: error?.requestId || req.id || uuid(),\n path: req.originalUrl || req.url,\n };\n\n // Include error code if present\n if (error?.code) {\n response.code = error.code;\n }\n\n // Include stack trace in development mode if requested\n if (includeDetails && error?.stack) {\n response.stack = error.stack.split(\"\\n\").map((line: string) => line.trim());\n }\n\n return response;\n};\n\n/**\n * Global error handling middleware with enhanced features.\n *\n * @param {object} [options] - Error handler options\n * @param {boolean} [options.logErrors=true] - Whether to log errors\n * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production\n * @param {Function} [options.logger=getLogger().error] - Custom logging function\n * @returns {(err: any, req: Request, res: Response, next: NextFunction) => void} Error middleware\n */\nexport function errorHandler(options?: {\n logErrors?: boolean;\n includeDetails?: boolean;\n logger?: (message: string, error: any) => void;\n}) {\n const logErrors = options?.logErrors !== false;\n const includeDetails = options?.includeDetails === true;\n const logger = options?.logger || getLogger().error;\n\n return (err: any, req: Request, res: Response, _next: NextFunction) => {\n // Determine status code\n const status =\n err?.status || err?.statusCode || HttpStatusCodes.INTERNAL_SERVER_ERROR;\n\n // Log error if enabled\n if (logErrors) {\n const logMessage = `[ERROR] ${req.method} ${req.originalUrl || req.url}: ${err.message || \"Unknown error\"}`;\n logger(logMessage, err);\n }\n\n // Handle ErrorResponse instances (our custom error class)\n if (err instanceof ErrorResponse) {\n return res.status(status).json({\n error: err.error,\n message: err.message,\n timestamp: err.timestamp,\n requestId: err.requestId || req.id || uuid(),\n path: req.originalUrl || req.url,\n });\n }\n\n // Handle any other errors\n return res.status(status).json(\n createErrorResponse(err?.message || \"Internal Server Error\", req, err, {\n includeDetails,\n }),\n );\n };\n}\n"]}
@@ -4,7 +4,7 @@
4
4
  * @param {Record<any, any>} obj - The object to check.
5
5
  * @returns {boolean} True if the object is empty, false otherwise.
6
6
  */
7
- export declare const isObjEmpty: (obj: Record<any, any>) => boolean;
7
+ export declare function isObjEmpty(obj: Record<any, any>): boolean;
8
8
  /**
9
9
  * Returns a new object with only the specified keys picked.
10
10
  *
@@ -14,7 +14,7 @@ export declare const isObjEmpty: (obj: Record<any, any>) => boolean;
14
14
  * @param {K[]} keys - Keys to pick from the object.
15
15
  * @returns {Pick<T, K>} New object with picked keys.
16
16
  */
17
- export declare const pick: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
17
+ export declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
18
18
  /**
19
19
  * Returns a new object with the specified keys omitted.
20
20
  *
@@ -24,7 +24,7 @@ export declare const pick: <T extends object, K extends keyof T>(obj: T, keys: K
24
24
  * @param {K[]} keys - Keys to omit from the object.
25
25
  * @returns {Omit<T, K>} New object without omitted keys.
26
26
  */
27
- export declare const omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
27
+ export declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
28
28
  /**
29
29
  * Deeply merges two objects (mutates and returns the target object, not pure).
30
30
  *
@@ -52,4 +52,66 @@ export declare function flattenObject<T extends Record<string, any>>(obj: T, pre
52
52
  * @returns {any} The value at the given path, or undefined if not found.
53
53
  */
54
54
  export declare function getValueByPath<T extends object>(obj: T, path: string): any;
55
+ /**
56
+ * Sets a value at a deeply nested key in an object using dot/bracket notation path.
57
+ * Creates intermediate objects and arrays as needed.
58
+ *
59
+ * @template T
60
+ * @param {T} obj - The object to modify.
61
+ * @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
62
+ * @param {any} value - The value to set at the path.
63
+ * @returns {T} The modified object.
64
+ */
65
+ export declare function setValueByPath<T extends object>(obj: T, path: string, value: any): T;
66
+ /**
67
+ * Performs a deep equality check between two objects.
68
+ *
69
+ * @param {any} a - First value to compare.
70
+ * @param {any} b - Second value to compare.
71
+ * @returns {boolean} True if values are deeply equal.
72
+ */
73
+ export declare function isEqual(a: any, b: any): boolean;
74
+ /**
75
+ * Filters object properties based on a predicate function.
76
+ *
77
+ * @template T
78
+ * @param {T} obj - The source object.
79
+ * @param {(value: any, key: string, obj: T) => boolean} predicate - Filter function.
80
+ * @returns {Partial<T>} New object with filtered properties.
81
+ */
82
+ export declare function filterObject<T extends object>(obj: T, predicate: (value: any, key: string, obj: T) => boolean): Partial<T>;
83
+ /**
84
+ * Maps object values to new values using a mapping function.
85
+ *
86
+ * @template T
87
+ * @template U
88
+ * @param {T} obj - The source object.
89
+ * @param {(value: any, key: string, obj: T) => U} mapFn - Mapping function.
90
+ * @returns {Record<keyof T, U>} New object with mapped values.
91
+ */
92
+ export declare function mapObject<T extends object, U>(obj: T, mapFn: (value: any, key: string, obj: T) => U): Record<keyof T, U>;
93
+ /**
94
+ * Recursively freezes an object and all its properties.
95
+ * Makes an object immutable.
96
+ *
97
+ * @template T
98
+ * @param {T} obj - The object to freeze.
99
+ * @returns {Readonly<T>} The frozen object.
100
+ */
101
+ export declare function deepFreeze<T extends object>(obj: T): Readonly<T>;
102
+ /**
103
+ * Safely checks if a value is an object (not null, not array).
104
+ *
105
+ * @param {unknown} value - Value to check.
106
+ * @returns {boolean} True if value is a non-null, non-array object.
107
+ */
108
+ export declare function isObject(value: unknown): value is Record<string, any>;
109
+ /**
110
+ * Gets all paths in an object using dot notation.
111
+ *
112
+ * @param {Record<string, any>} obj - Object to analyze.
113
+ * @param {string} [parentPath=""] - Internal param for recursion.
114
+ * @returns {string[]} Array of all paths in dot notation.
115
+ */
116
+ export declare function getAllPaths(obj: Record<string, any>, parentPath?: string): string[];
55
117
  //# sourceMappingURL=obj.utils.d.ts.map