@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.
Files changed (280) hide show
  1. package/build/{esnext → cjs}/config.d.ts +0 -1
  2. package/build/{src → cjs}/config.js +0 -1
  3. package/build/{esnext → cjs}/index.d.ts +0 -1
  4. package/build/{src → cjs}/index.js +0 -1
  5. package/build/{esnext → cjs}/servers/server.builder.d.ts +0 -1
  6. package/build/{src → cjs}/servers/server.builder.js +10 -13
  7. package/build/{src → cjs}/servers/server.d.ts +0 -1
  8. package/build/{src → cjs}/servers/server.js +83 -75
  9. package/build/{src → cjs}/types/api-response.d.ts +0 -1
  10. package/build/{src → cjs}/types/api-response.js +0 -1
  11. package/build/{src → cjs}/types/index.d.ts +0 -1
  12. package/build/{src → cjs}/types/index.js +0 -1
  13. package/build/{src → cjs}/types/server.d.ts +0 -1
  14. package/build/{src → cjs}/types/server.js +0 -1
  15. package/build/{src → cjs}/utils/array.utils.d.ts +0 -1
  16. package/build/{src → cjs}/utils/array.utils.js +0 -1
  17. package/build/{src → cjs}/utils/async.utils.d.ts +0 -1
  18. package/build/{src → cjs}/utils/async.utils.js +2 -3
  19. package/build/{esnext → cjs}/utils/cache.utils.d.ts +0 -1
  20. package/build/{src → cjs}/utils/cache.utils.js +7 -6
  21. package/build/{esnext → cjs}/utils/context-store.utils.d.ts +1 -2
  22. package/build/{src → cjs}/utils/context-store.utils.js +10 -9
  23. package/build/{esnext → cjs}/utils/crypto.utils.d.ts +0 -1
  24. package/build/{src → cjs}/utils/crypto.utils.js +5 -3
  25. package/build/{src → cjs}/utils/date.utils.d.ts +0 -1
  26. package/build/{src → cjs}/utils/date.utils.js +1 -2
  27. package/build/{src → cjs}/utils/decorators.utils.d.ts +30 -27
  28. package/build/{src → cjs}/utils/decorators.utils.js +169 -30
  29. package/build/{esnext → cjs}/utils/dir.utils.d.ts +0 -1
  30. package/build/{src → cjs}/utils/dir.utils.js +6 -7
  31. package/build/{esnext → cjs}/utils/env.utils.d.ts +0 -1
  32. package/build/{src → cjs}/utils/env.utils.js +5 -8
  33. package/build/{src → cjs}/utils/exception.utils.d.ts +0 -1
  34. package/build/{src → cjs}/utils/exception.utils.js +2 -1
  35. package/build/{src → cjs}/utils/fs.utils.d.ts +0 -1
  36. package/build/{src → cjs}/utils/fs.utils.js +12 -13
  37. package/build/{esnext → cjs}/utils/http-status-codes.d.ts +0 -1
  38. package/build/{src → cjs}/utils/http-status-codes.js +0 -1
  39. package/build/{esnext → cjs}/utils/id.utils.d.ts +0 -1
  40. package/build/{src → cjs}/utils/id.utils.js +0 -1
  41. package/build/{src → cjs}/utils/logger.utils.d.ts +0 -1
  42. package/build/{src → cjs}/utils/logger.utils.js +10 -6
  43. package/build/{esnext → cjs}/utils/middleware.utils.d.ts +0 -1
  44. package/build/{src → cjs}/utils/middleware.utils.js +16 -17
  45. package/build/{esnext → cjs}/utils/obj.utils.d.ts +0 -1
  46. package/build/{src → cjs}/utils/obj.utils.js +1 -2
  47. package/build/{src → cjs}/utils/performance.utils.d.ts +0 -1
  48. package/build/{src → cjs}/utils/performance.utils.js +6 -4
  49. package/build/{esnext → cjs}/utils/request.utils.d.ts +0 -1
  50. package/build/{src → cjs}/utils/request.utils.js +7 -3
  51. package/build/{esnext → cjs}/utils/response.utils.d.ts +0 -1
  52. package/build/{src → cjs}/utils/response.utils.js +42 -28
  53. package/build/{esnext → cjs}/utils/stream.utils.d.ts +0 -1
  54. package/build/{src → cjs}/utils/stream.utils.js +0 -1
  55. package/build/{esnext → cjs}/utils/string.utils.d.ts +0 -1
  56. package/build/{src → cjs}/utils/string.utils.js +0 -1
  57. package/build/{src → cjs}/utils/type.utils.d.ts +0 -1
  58. package/build/{src → cjs}/utils/type.utils.js +2 -3
  59. package/build/{src → cjs}/utils/url.utils.d.ts +0 -1
  60. package/build/{src → cjs}/utils/url.utils.js +8 -9
  61. package/build/{src → cjs}/utils/validate.utils.d.ts +0 -1
  62. package/build/{src → cjs}/utils/validate.utils.js +2 -3
  63. package/build/esm/config.d.ts +0 -1
  64. package/build/esm/config.js +6 -7
  65. package/build/esm/index.d.ts +0 -1
  66. package/build/esm/index.js +0 -1
  67. package/build/esm/servers/server.builder.d.ts +0 -1
  68. package/build/esm/servers/server.builder.js +99 -147
  69. package/build/esm/servers/server.d.ts +0 -1
  70. package/build/esm/servers/server.js +591 -876
  71. package/build/esm/types/api-response.d.ts +0 -1
  72. package/build/esm/types/api-response.js +0 -1
  73. package/build/esm/types/index.d.ts +0 -1
  74. package/build/esm/types/index.js +0 -1
  75. package/build/esm/types/server.d.ts +0 -1
  76. package/build/esm/types/server.js +0 -1
  77. package/build/esm/utils/array.utils.d.ts +0 -1
  78. package/build/esm/utils/array.utils.js +48 -86
  79. package/build/esm/utils/async.utils.d.ts +0 -1
  80. package/build/esm/utils/async.utils.js +247 -524
  81. package/build/esm/utils/cache.utils.d.ts +0 -1
  82. package/build/esm/utils/cache.utils.js +96 -301
  83. package/build/esm/utils/context-store.utils.d.ts +1 -2
  84. package/build/esm/utils/context-store.utils.js +62 -79
  85. package/build/esm/utils/crypto.utils.d.ts +0 -1
  86. package/build/esm/utils/crypto.utils.js +78 -175
  87. package/build/esm/utils/date.utils.d.ts +0 -1
  88. package/build/esm/utils/date.utils.js +47 -53
  89. package/build/esm/utils/decorators.utils.d.ts +30 -27
  90. package/build/esm/utils/decorators.utils.js +417 -461
  91. package/build/esm/utils/dir.utils.d.ts +0 -1
  92. package/build/esm/utils/dir.utils.js +264 -786
  93. package/build/esm/utils/env.utils.d.ts +0 -1
  94. package/build/esm/utils/env.utils.js +180 -271
  95. package/build/esm/utils/exception.utils.d.ts +0 -1
  96. package/build/esm/utils/exception.utils.js +112 -289
  97. package/build/esm/utils/fs.utils.d.ts +0 -1
  98. package/build/esm/utils/fs.utils.js +169 -401
  99. package/build/esm/utils/http-status-codes.d.ts +0 -1
  100. package/build/esm/utils/http-status-codes.js +0 -1
  101. package/build/esm/utils/id.utils.d.ts +0 -1
  102. package/build/esm/utils/id.utils.js +5 -9
  103. package/build/esm/utils/logger.utils.d.ts +0 -1
  104. package/build/esm/utils/logger.utils.js +34 -71
  105. package/build/esm/utils/middleware.utils.d.ts +0 -1
  106. package/build/esm/utils/middleware.utils.js +65 -155
  107. package/build/esm/utils/obj.utils.d.ts +0 -1
  108. package/build/esm/utils/obj.utils.js +69 -176
  109. package/build/esm/utils/performance.utils.d.ts +0 -1
  110. package/build/esm/utils/performance.utils.js +92 -195
  111. package/build/esm/utils/request.utils.d.ts +0 -1
  112. package/build/esm/utils/request.utils.js +41 -74
  113. package/build/esm/utils/response.utils.d.ts +0 -1
  114. package/build/esm/utils/response.utils.js +84 -107
  115. package/build/esm/utils/stream.utils.d.ts +0 -1
  116. package/build/esm/utils/stream.utils.js +38 -113
  117. package/build/esm/utils/string.utils.d.ts +0 -1
  118. package/build/esm/utils/string.utils.js +6 -11
  119. package/build/esm/utils/type.utils.d.ts +0 -1
  120. package/build/esm/utils/type.utils.js +8 -12
  121. package/build/esm/utils/url.utils.d.ts +0 -1
  122. package/build/esm/utils/url.utils.js +49 -127
  123. package/build/esm/utils/validate.utils.d.ts +0 -1
  124. package/build/esm/utils/validate.utils.js +23 -40
  125. package/package.json +288 -63
  126. package/build/esm/config.js.map +0 -1
  127. package/build/esm/index.js.map +0 -1
  128. package/build/esm/servers/server.builder.js.map +0 -1
  129. package/build/esm/servers/server.js.map +0 -1
  130. package/build/esm/types/api-response.js.map +0 -1
  131. package/build/esm/types/index.js.map +0 -1
  132. package/build/esm/types/server.js.map +0 -1
  133. package/build/esm/utils/array.utils.js.map +0 -1
  134. package/build/esm/utils/async.utils.js.map +0 -1
  135. package/build/esm/utils/cache.utils.js.map +0 -1
  136. package/build/esm/utils/context-store.utils.js.map +0 -1
  137. package/build/esm/utils/crypto.utils.js.map +0 -1
  138. package/build/esm/utils/date.utils.js.map +0 -1
  139. package/build/esm/utils/decorators.utils.js.map +0 -1
  140. package/build/esm/utils/dir.utils.js.map +0 -1
  141. package/build/esm/utils/env.utils.js.map +0 -1
  142. package/build/esm/utils/exception.utils.js.map +0 -1
  143. package/build/esm/utils/fs.utils.js.map +0 -1
  144. package/build/esm/utils/http-status-codes.js.map +0 -1
  145. package/build/esm/utils/id.utils.js.map +0 -1
  146. package/build/esm/utils/logger.utils.js.map +0 -1
  147. package/build/esm/utils/middleware.utils.js.map +0 -1
  148. package/build/esm/utils/obj.utils.js.map +0 -1
  149. package/build/esm/utils/performance.utils.js.map +0 -1
  150. package/build/esm/utils/request.utils.js.map +0 -1
  151. package/build/esm/utils/response.utils.js.map +0 -1
  152. package/build/esm/utils/stream.utils.js.map +0 -1
  153. package/build/esm/utils/string.utils.js.map +0 -1
  154. package/build/esm/utils/type.utils.js.map +0 -1
  155. package/build/esm/utils/url.utils.js.map +0 -1
  156. package/build/esm/utils/validate.utils.js.map +0 -1
  157. package/build/esnext/config.js +0 -133
  158. package/build/esnext/config.js.map +0 -1
  159. package/build/esnext/index.js +0 -50
  160. package/build/esnext/index.js.map +0 -1
  161. package/build/esnext/servers/server.builder.js +0 -657
  162. package/build/esnext/servers/server.builder.js.map +0 -1
  163. package/build/esnext/servers/server.d.ts +0 -256
  164. package/build/esnext/servers/server.js +0 -955
  165. package/build/esnext/servers/server.js.map +0 -1
  166. package/build/esnext/types/api-response.d.ts +0 -152
  167. package/build/esnext/types/api-response.js +0 -34
  168. package/build/esnext/types/api-response.js.map +0 -1
  169. package/build/esnext/types/index.d.ts +0 -125
  170. package/build/esnext/types/index.js +0 -25
  171. package/build/esnext/types/index.js.map +0 -1
  172. package/build/esnext/types/server.d.ts +0 -268
  173. package/build/esnext/types/server.js +0 -25
  174. package/build/esnext/types/server.js.map +0 -1
  175. package/build/esnext/utils/array.utils.d.ts +0 -168
  176. package/build/esnext/utils/array.utils.js +0 -345
  177. package/build/esnext/utils/array.utils.js.map +0 -1
  178. package/build/esnext/utils/async.utils.d.ts +0 -265
  179. package/build/esnext/utils/async.utils.js +0 -620
  180. package/build/esnext/utils/async.utils.js.map +0 -1
  181. package/build/esnext/utils/cache.utils.js +0 -293
  182. package/build/esnext/utils/cache.utils.js.map +0 -1
  183. package/build/esnext/utils/context-store.utils.js +0 -289
  184. package/build/esnext/utils/context-store.utils.js.map +0 -1
  185. package/build/esnext/utils/crypto.utils.js +0 -276
  186. package/build/esnext/utils/crypto.utils.js.map +0 -1
  187. package/build/esnext/utils/date.utils.d.ts +0 -159
  188. package/build/esnext/utils/date.utils.js +0 -384
  189. package/build/esnext/utils/date.utils.js.map +0 -1
  190. package/build/esnext/utils/decorators.utils.d.ts +0 -508
  191. package/build/esnext/utils/decorators.utils.js +0 -877
  192. package/build/esnext/utils/decorators.utils.js.map +0 -1
  193. package/build/esnext/utils/dir.utils.js +0 -477
  194. package/build/esnext/utils/dir.utils.js.map +0 -1
  195. package/build/esnext/utils/env.utils.js +0 -785
  196. package/build/esnext/utils/env.utils.js.map +0 -1
  197. package/build/esnext/utils/exception.utils.d.ts +0 -230
  198. package/build/esnext/utils/exception.utils.js +0 -381
  199. package/build/esnext/utils/exception.utils.js.map +0 -1
  200. package/build/esnext/utils/fs.utils.d.ts +0 -164
  201. package/build/esnext/utils/fs.utils.js +0 -349
  202. package/build/esnext/utils/fs.utils.js.map +0 -1
  203. package/build/esnext/utils/http-status-codes.js +0 -295
  204. package/build/esnext/utils/http-status-codes.js.map +0 -1
  205. package/build/esnext/utils/id.utils.js +0 -84
  206. package/build/esnext/utils/id.utils.js.map +0 -1
  207. package/build/esnext/utils/logger.utils.d.ts +0 -160
  208. package/build/esnext/utils/logger.utils.js +0 -300
  209. package/build/esnext/utils/logger.utils.js.map +0 -1
  210. package/build/esnext/utils/middleware.utils.js +0 -236
  211. package/build/esnext/utils/middleware.utils.js.map +0 -1
  212. package/build/esnext/utils/obj.utils.js +0 -413
  213. package/build/esnext/utils/obj.utils.js.map +0 -1
  214. package/build/esnext/utils/performance.utils.d.ts +0 -136
  215. package/build/esnext/utils/performance.utils.js +0 -271
  216. package/build/esnext/utils/performance.utils.js.map +0 -1
  217. package/build/esnext/utils/request.utils.js +0 -186
  218. package/build/esnext/utils/request.utils.js.map +0 -1
  219. package/build/esnext/utils/response.utils.js +0 -247
  220. package/build/esnext/utils/response.utils.js.map +0 -1
  221. package/build/esnext/utils/stream.utils.js +0 -210
  222. package/build/esnext/utils/stream.utils.js.map +0 -1
  223. package/build/esnext/utils/string.utils.js +0 -165
  224. package/build/esnext/utils/string.utils.js.map +0 -1
  225. package/build/esnext/utils/type.utils.d.ts +0 -90
  226. package/build/esnext/utils/type.utils.js +0 -187
  227. package/build/esnext/utils/type.utils.js.map +0 -1
  228. package/build/esnext/utils/url.utils.d.ts +0 -141
  229. package/build/esnext/utils/url.utils.js +0 -304
  230. package/build/esnext/utils/url.utils.js.map +0 -1
  231. package/build/esnext/utils/validate.utils.d.ts +0 -177
  232. package/build/esnext/utils/validate.utils.js +0 -320
  233. package/build/esnext/utils/validate.utils.js.map +0 -1
  234. package/build/src/config.d.ts +0 -122
  235. package/build/src/config.js.map +0 -1
  236. package/build/src/index.d.ts +0 -27
  237. package/build/src/index.js.map +0 -1
  238. package/build/src/servers/server.builder.d.ts +0 -508
  239. package/build/src/servers/server.builder.js.map +0 -1
  240. package/build/src/servers/server.js.map +0 -1
  241. package/build/src/types/api-response.js.map +0 -1
  242. package/build/src/types/index.js.map +0 -1
  243. package/build/src/types/server.js.map +0 -1
  244. package/build/src/utils/array.utils.js.map +0 -1
  245. package/build/src/utils/async.utils.js.map +0 -1
  246. package/build/src/utils/cache.utils.d.ts +0 -153
  247. package/build/src/utils/cache.utils.js.map +0 -1
  248. package/build/src/utils/context-store.utils.d.ts +0 -189
  249. package/build/src/utils/context-store.utils.js.map +0 -1
  250. package/build/src/utils/crypto.utils.d.ts +0 -160
  251. package/build/src/utils/crypto.utils.js.map +0 -1
  252. package/build/src/utils/date.utils.js.map +0 -1
  253. package/build/src/utils/decorators.utils.js.map +0 -1
  254. package/build/src/utils/dir.utils.d.ts +0 -196
  255. package/build/src/utils/dir.utils.js.map +0 -1
  256. package/build/src/utils/env.utils.d.ts +0 -377
  257. package/build/src/utils/env.utils.js.map +0 -1
  258. package/build/src/utils/exception.utils.js.map +0 -1
  259. package/build/src/utils/fs.utils.js.map +0 -1
  260. package/build/src/utils/http-status-codes.d.ts +0 -266
  261. package/build/src/utils/http-status-codes.js.map +0 -1
  262. package/build/src/utils/id.utils.d.ts +0 -36
  263. package/build/src/utils/id.utils.js.map +0 -1
  264. package/build/src/utils/logger.utils.js.map +0 -1
  265. package/build/src/utils/middleware.utils.d.ts +0 -100
  266. package/build/src/utils/middleware.utils.js.map +0 -1
  267. package/build/src/utils/obj.utils.d.ts +0 -124
  268. package/build/src/utils/obj.utils.js.map +0 -1
  269. package/build/src/utils/performance.utils.js.map +0 -1
  270. package/build/src/utils/request.utils.d.ts +0 -86
  271. package/build/src/utils/request.utils.js.map +0 -1
  272. package/build/src/utils/response.utils.d.ts +0 -163
  273. package/build/src/utils/response.utils.js.map +0 -1
  274. package/build/src/utils/stream.utils.d.ts +0 -88
  275. package/build/src/utils/stream.utils.js.map +0 -1
  276. package/build/src/utils/string.utils.d.ts +0 -93
  277. package/build/src/utils/string.utils.js.map +0 -1
  278. package/build/src/utils/type.utils.js.map +0 -1
  279. package/build/src/utils/url.utils.js.map +0 -1
  280. package/build/src/utils/validate.utils.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"http-status-codes.js","sourceRoot":"","sources":["../../../src/utils/http-status-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;GAGG;AACH,MAAM,CAAN,IAAY,eAwUX;AAxUD,WAAY,eAAe;IACzB,oBAAoB;IACpB;;OAEG;IACH,+DAAc,CAAA;IAEd;;OAEG;IACH,qFAAyB,CAAA;IAEzB;;OAEG;IACH,mEAAgB,CAAA;IAEhB;;OAEG;IACH,qEAAiB,CAAA;IAEjB,cAAc;IACd;;OAEG;IAC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OAEG;IACH,qEAAiB,CAAA;IAEjB;;OAEG;IACH,2GAAoC,CAAA;IAEpC;;;OAGG;IACH,2EAAoB,CAAA;IAEpB;;OAEG;IACH,qFAAyB,CAAA;IAEzB;;OAEG;IACH,uFAA0B,CAAA;IAE1B;;OAEG;IACH,2DAAY,CAAA;IAEZ;;OAEG;IACH,iFAAuB,CAAA;IAEvB;;OAEG;IACH,+EAAsB,CAAA;IAEtB;;OAEG;IACH,yFAA2B,CAAA;IAE3B;;OAEG;IACH,iFAAuB,CAAA;IAEvB;;OAEG;IACH,6GAAqC,CAAA;IAErC;;OAEG;IACH,yGAAmC,CAAA;IAEnC,mBAAmB;IACnB;;OAEG;IACH,yFAA2B,CAAA;IAE3B;;OAEG;IACH,6EAAqB,CAAA;IAErB;;OAEG;IACH,qEAAiB,CAAA;IAEjB;;OAEG;IACH,qFAAyB,CAAA;IAEzB;;OAEG;IACH,6EAAqB,CAAA;IAErB;;OAEG;IACH,mGAAgC,CAAA;IAEhC;;OAEG;IACH,6FAA6B,CAAA;IAE7B;;OAEG;IACH,uFAA0B,CAAA;IAE1B;;OAEG;IACH,yEAAmB,CAAA;IAEnB;;OAEG;IACH,uEAAkB,CAAA;IAElB;;OAEG;IACH,6GAAqC,CAAA;AACvC,CAAC,EAxUW,eAAe,KAAf,eAAe,QAwU1B","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Complete HTTP status codes enum with descriptions.\n * For use with API responses and error handling.\n */\nexport enum HttpStatusCodes {\n // 1xx Informational\n /**\n * The server has received the request headers and the client should proceed to send the request body.\n */\n CONTINUE = 100,\n\n /**\n * The server is switching protocols according to the client's request.\n */\n SWITCHING_PROTOCOLS = 101,\n\n /**\n * Server has received the request and is still processing it.\n */\n PROCESSING = 102,\n\n /**\n * The server is sending preliminary headers while preparing the final response.\n */\n EARLY_HINTS = 103,\n\n // 2xx Success\n /**\n * The request succeeded. The result meaning depends on the HTTP method used.\n */\n OK = 200,\n\n /**\n * The request succeeded and a new resource was created as a result.\n */\n CREATED = 201,\n\n /**\n * The request has been received but not yet acted upon.\n */\n ACCEPTED = 202,\n\n /**\n * The returned information is from a third-party source, not the origin server.\n */\n NON_AUTHORITATIVE_INFORMATION = 203,\n\n /**\n * The request succeeded but there's no content to send in the response.\n */\n NO_CONTENT = 204,\n\n /**\n * The client should reset the document view that caused this request.\n */\n RESET_CONTENT = 205,\n\n /**\n * The server is delivering only part of the resource due to a range header sent by the client.\n */\n PARTIAL_CONTENT = 206,\n\n /**\n * Conveys information about multiple resources, for complex operations.\n */\n MULTI_STATUS = 207,\n\n /**\n * The members of a DAV binding have already been enumerated and are not included in the response.\n */\n ALREADY_REPORTED = 208,\n\n /**\n * The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.\n */\n IM_USED = 226,\n\n // 3xx Redirection\n /**\n * The request has more than one possible response and the client should choose one.\n */\n MULTIPLE_CHOICES = 300,\n\n /**\n * The resource has been permanently moved to a new URL.\n */\n MOVED_PERMANENTLY = 301,\n\n /**\n * The resource has been temporarily moved to another URL.\n */\n MOVED_TEMPORARILY = 302,\n\n /**\n * The response to the request can be found under another URI using the GET method.\n */\n SEE_OTHER = 303,\n\n /**\n * The resource hasn't been modified since the last request.\n */\n NOT_MODIFIED = 304,\n\n /**\n * @deprecated\n * Response must be accessed through a proxy.\n */\n USE_PROXY = 305,\n\n /**\n * The resource is temporarily available at a different URI, using the same HTTP method.\n */\n TEMPORARY_REDIRECT = 307,\n\n /**\n * The resource has been permanently moved to another URL, using the same HTTP method.\n */\n PERMANENT_REDIRECT = 308,\n\n // 4xx Client Error\n /**\n * The server cannot process the request due to a client error (malformed request).\n */\n BAD_REQUEST = 400,\n\n /**\n * Authentication is required and has failed or not been provided.\n */\n UNAUTHORIZED = 401,\n\n /**\n * Reserved for future use, originally intended for digital payment systems.\n */\n PAYMENT_REQUIRED = 402,\n\n /**\n * The client doesn't have permission to access the requested resource.\n */\n FORBIDDEN = 403,\n\n /**\n * The requested resource could not be found on the server.\n */\n NOT_FOUND = 404,\n\n /**\n * The request method is not supported for the requested resource.\n */\n METHOD_NOT_ALLOWED = 405,\n\n /**\n * The server can't provide a response matching the list of acceptable values in the client's headers.\n */\n NOT_ACCEPTABLE = 406,\n\n /**\n * Authentication by a proxy is required.\n */\n PROXY_AUTHENTICATION_REQUIRED = 407,\n\n /**\n * The server timed out waiting for the request.\n */\n REQUEST_TIMEOUT = 408,\n\n /**\n * The request conflicts with the current state of the server.\n */\n CONFLICT = 409,\n\n /**\n * The resource has been permanently deleted with no forwarding address.\n */\n GONE = 410,\n\n /**\n * The server requires a Content-Length header field.\n */\n LENGTH_REQUIRED = 411,\n\n /**\n * Preconditions in the client's headers failed.\n */\n PRECONDITION_FAILED = 412,\n\n /**\n * Request entity is larger than limits defined by server.\n */\n REQUEST_TOO_LONG = 413,\n\n /**\n * The request payload exceeds server size limits.\n * Modern equivalent of REQUEST_TOO_LONG.\n */\n PAYLOAD_TOO_LARGE = 413,\n\n /**\n * The URI requested is too long for the server to interpret.\n */\n REQUEST_URI_TOO_LONG = 414,\n\n /**\n * The server does not support the media type requested by the client.\n */\n UNSUPPORTED_MEDIA_TYPE = 415,\n\n /**\n * The range specified by the Range header cannot be fulfilled.\n */\n REQUESTED_RANGE_NOT_SATISFIABLE = 416,\n\n /**\n * The server cannot meet the expectations given in the Expect header.\n */\n EXPECTATION_FAILED = 417,\n\n /**\n * The server refuses to brew coffee because it is a teapot. (April Fools' joke)\n */\n IM_A_TEAPOT = 418,\n\n /**\n * The server cannot store the representation needed to complete the request.\n */\n INSUFFICIENT_SPACE_ON_RESOURCE = 419,\n\n /**\n * @deprecated\n * A method has failed - specific to Spring Framework.\n */\n METHOD_FAILURE = 420,\n\n /**\n * The server cannot produce a response for the requested URI scheme and authority.\n */\n MISDIRECTED_REQUEST = 421,\n\n /**\n * The request was well-formed but has semantic errors preventing processing.\n */\n UNPROCESSABLE_ENTITY = 422,\n\n /**\n * The requested resource is locked against access.\n */\n LOCKED = 423,\n\n /**\n * The request failed due to the failure of a previous request.\n */\n FAILED_DEPENDENCY = 424,\n\n /**\n * The client should switch to a different protocol.\n */\n UPGRADE_REQUIRED = 426,\n\n /**\n * The server requires conditional requests to prevent lost updates.\n */\n PRECONDITION_REQUIRED = 428,\n\n /**\n * The client has sent too many requests in a given time period (rate limiting).\n */\n TOO_MANY_REQUESTS = 429,\n\n /**\n * Request headers are too large for the server to process.\n */\n REQUEST_HEADER_FIELDS_TOO_LARGE = 431,\n\n /**\n * Resource cannot be legally provided (e.g., censored by government).\n */\n UNAVAILABLE_FOR_LEGAL_REASONS = 451,\n\n // 5xx Server Error\n /**\n * The server encountered an unexpected error preventing it from fulfilling the request.\n */\n INTERNAL_SERVER_ERROR = 500,\n\n /**\n * The server does not support the functionality required to fulfill the request.\n */\n NOT_IMPLEMENTED = 501,\n\n /**\n * The server, acting as a gateway, received an invalid response from an upstream server.\n */\n BAD_GATEWAY = 502,\n\n /**\n * The server is currently unable to handle the request due to temporary overload or maintenance.\n */\n SERVICE_UNAVAILABLE = 503,\n\n /**\n * The server, acting as a gateway, did not receive a timely response from an upstream server.\n */\n GATEWAY_TIMEOUT = 504,\n\n /**\n * The server does not support the HTTP protocol version used in the request.\n */\n HTTP_VERSION_NOT_SUPPORTED = 505,\n\n /**\n * Transparent content negotiation for the request resulted in circular reference.\n */\n VARIANT_ALSO_NEGOTIATES = 506,\n\n /**\n * The server cannot store the representation needed to complete the request.\n */\n INSUFFICIENT_STORAGE = 507,\n\n /**\n * The server detected an infinite loop while processing the request.\n */\n LOOP_DETECTED = 508,\n\n /**\n * Further extensions to the request are required for the server to fulfill it.\n */\n NOT_EXTENDED = 510,\n\n /**\n * The client needs to authenticate to gain network access.\n */\n NETWORK_AUTHENTICATION_REQUIRED = 511\n}\n"]}
@@ -1,84 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { randomUUID, randomBytes } from 'crypto';
25
- /**
26
- * Generates a UUID v4 string (RFC 4122).
27
- *
28
- * @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')
29
- */
30
- export function uuid() {
31
- return randomUUID();
32
- }
33
- /**
34
- * Generates a nanoid-style random ID (URL-safe, customizable length).
35
- *
36
- * @param {number} length - Length of the ID (default: 21).
37
- * @returns {string} Nanoid-style random string.
38
- */
39
- export function nanoId(length = 21) {
40
- if (length <= 0)
41
- return '';
42
- let id = '';
43
- while (id.length < length) {
44
- id += randomBytes(Math.ceil((length * 3) / 4))
45
- .toString('base64url')
46
- .replace(/[+/=]/g, '');
47
- }
48
- return id.slice(0, length);
49
- }
50
- /**
51
- * Generates a cryptographically strong random hex string.
52
- *
53
- * @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).
54
- * @returns {string} Random hex string.
55
- */
56
- export function randomHex(byteLength = 16) {
57
- // Use Node.js crypto for both Node and browser compatibility
58
- // Prefer randomBytes if available (Node), fallback to getRandomValues for browser (not used here)
59
- return randomBytes(byteLength)
60
- .toString('hex')
61
- .padStart(byteLength * 2, '0')
62
- .slice(0, byteLength * 2);
63
- }
64
- /**
65
- * Generates a random integer between min (inclusive) and max (inclusive).
66
- *
67
- * @param {number} min - Minimum value.
68
- * @param {number} max - Maximum value.
69
- * @returns {number} Random integer in range.
70
- */
71
- export function randomInt(min, max) {
72
- const range = max - min + 1;
73
- return Math.floor(Math.random() * range) + min;
74
- }
75
- /**
76
- * Generates a cryptographically strong random base64 string.
77
- *
78
- * @param {number} byteLength - Number of random bytes (default: 16).
79
- * @returns {string} Random base64 string (URL-safe, no padding).
80
- */
81
- export function randomBase64(byteLength = 16) {
82
- return randomBytes(byteLength).toString('base64url');
83
- }
84
- //# sourceMappingURL=id.utils.js.map
@@ -1 +0,0 @@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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":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { 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"]}
@@ -1,160 +0,0 @@
1
- import pino from 'pino';
2
- import type { Logger as PinoLogger } from 'pino';
3
- /**
4
- * Logger type for application-wide logging.
5
- */
6
- export type Logger = pino.Logger;
7
- /**
8
- * Logger levels for application-wide logging.
9
- */
10
- export type LoggerLevels = pino.Level;
11
- export declare const defaultSensitiveFields: string[];
12
- /**
13
- * Sets the global redaction censor function used throughout the application for log redaction.
14
- *
15
- * Use this function to customize how sensitive data is redacted in logs. The provided function
16
- * will replace the default censor implementation.
17
- *
18
- * @example
19
- * ```typescript
20
- * // Custom censor that redacts only specific values
21
- * setRedactCensor((value, path, sensitiveFields) => {
22
- * if (path.includes('password')) return '***';
23
- * return value;
24
- * });
25
- * ```
26
- *
27
- * @param fn - The redaction censor function to use globally. This function receives:
28
- * - value: The data value to potentially redact
29
- * - path: Array of strings representing the path to the value in the object
30
- * - sensitiveFields: Optional array of field names to consider sensitive
31
- * @returns void
32
- */
33
- export declare function setRedactCensor(fn: (value: unknown, path: string[], sensitiveFields?: string[]) => string): void;
34
- /**
35
- * Gets the current global redaction censor function used for log redaction.
36
- *
37
- * This function is called internally by the logger when determining how to redact
38
- * sensitive information. It can also be used to access the current censor implementation
39
- * for composition or extension.
40
- *
41
- * @example
42
- * ```typescript
43
- * const currentCensor = getRedactCensor();
44
- * // Create an enhanced censor that extends the current one
45
- * setRedactCensor((value, path, fields) => {
46
- * // Add custom logic before delegating to current censor
47
- * if (someCondition) return customHandling();
48
- * return currentCensor(value, path, fields);
49
- * });
50
- * ```
51
- *
52
- * @returns The current redaction censor function
53
- */
54
- export declare function getRedactCensor(): (value: unknown, path: string[], sensitiveFields?: string[]) => string;
55
- /**
56
- * Convenience function to redact sensitive data using the current global redact censor.
57
- *
58
- * This is a direct wrapper around the global censor function that simplifies usage
59
- * in application code without needing to access the censor function directly.
60
- *
61
- * @example
62
- * ```typescript
63
- * // Redact a potential sensitive value
64
- * const safeValue = redact(value, ['user', 'apiKey']);
65
- * ```
66
- *
67
- * @param value - The value to potentially redact
68
- * @param path - Array of strings representing the path to the value in the object
69
- * @param sensitiveFields - Optional array of field names to consider sensitive
70
- * @returns The redacted string value or "***" for redacted content
71
- */
72
- export declare function redact(value: unknown, path: string[], sensitiveFields?: string[]): string;
73
- /**
74
- * Extends the current redaction function with additional fields to redact.
75
- *
76
- * This function wraps the existing censor while adding more fields to be considered
77
- * sensitive without replacing the entire redaction logic.
78
- *
79
- * @example
80
- * ```typescript
81
- * // Add custom fields to be redacted in all future redaction operations
82
- * addRedactFields(['customerId', 'accountNumber']);
83
- * ```
84
- *
85
- * @param fields - Array of additional field names to redact
86
- */
87
- export declare function addRedactFields(fields: string[]): void;
88
- /**
89
- * Replaces the default list of sensitive fields with a new list.
90
- *
91
- * This is useful when you want complete control over what fields are considered
92
- * sensitive by default, rather than using the library's built-in list.
93
- *
94
- * @example
95
- * ```typescript
96
- * // Replace default sensitive fields with a custom list
97
- * setSensitiveFields(['password', 'ssn', 'creditCard']);
98
- * ```
99
- *
100
- * @param fields - Array of field names to set as the new default sensitive fields
101
- */
102
- export declare function setSensitiveFields(fields: string[]): void;
103
- /**
104
- * Adds additional field names to the default sensitive fields list.
105
- *
106
- * This preserves the existing sensitive fields while adding new ones for
107
- * application-specific sensitive data.
108
- *
109
- * @example
110
- * ```typescript
111
- * // Add domain-specific sensitive fields to the default list
112
- * addSensitiveFields(['socialSecurityNumber', 'medicalRecordNumber']);
113
- * ```
114
- *
115
- * @param fields - Array of additional field names to add to the sensitive fields list
116
- */
117
- export declare function addSensitiveFields(fields: string[]): void;
118
- /**
119
- * Use an object compatible with either modern or legacy global scopes.
120
- */
121
- export declare const _globalThis: typeof globalThis;
122
- /**
123
- * Retrieves the current logger instance:
124
- * - Returns a request-scoped logger from AsyncLocalStorage if available
125
- * - Falls back to the global (singleton) logger
126
- * - Initializes the global logger if not created yet
127
- *
128
- * @returns {Logger} The logger instance (request-bound or global root logger)
129
- */
130
- export declare function getLogger(): PinoLogger;
131
- /**
132
- * Logger instance for the global context.
133
- * This logger is used for logging messages that are not tied to a specific request.
134
- */
135
- export declare const logger: pino.Logger;
136
- /**
137
- * Creates a child logger with additional context.
138
- *
139
- * @param {Record<string, any>} bindings - Properties to attach to all log records
140
- * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global)
141
- * @returns {Logger} Child logger with merged context
142
- */
143
- export declare function createChildLogger(bindings: Record<string, any>, parentLogger?: PinoLogger): PinoLogger;
144
- /**
145
- * Creates a request-scoped logger with request ID and stores it in context
146
- *
147
- * @param {string} requestId - Unique request identifier
148
- * @param {object} [additionalContext] - Additional context to include in logs
149
- * @returns {Logger} Request-scoped logger instance
150
- */
151
- export declare function createRequestLogger(requestId: string, additionalContext?: Record<string, any>): PinoLogger;
152
- /**
153
- * Utility to safely log errors with proper stack trace extraction
154
- *
155
- * @param {Error|unknown} error - Error object to log
156
- * @param {string} [message] - Optional message to include
157
- * @param {Record<string, any>} [context] - Additional context properties
158
- */
159
- export declare function logError(error: Error | unknown, message?: string, context?: Record<string, any>): void;
160
- //# sourceMappingURL=logger.utils.d.ts.map
@@ -1,300 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import pino, { stdTimeFunctions } from 'pino';
25
- import { config } from '../config';
26
- import { ContextStore, StoreKeys } from './context-store.utils';
27
- import { Env } from './env.utils';
28
- /**
29
- * Symbol used to store the root logger in the Node.js global object.
30
- */
31
- const GLOBAL_LOGGER_KEY = Symbol.for('logger');
32
- // Default sensitive fields
33
- export const defaultSensitiveFields = [
34
- 'password',
35
- 'secret',
36
- 'token',
37
- 'apiKey',
38
- 'api_key',
39
- 'auth',
40
- 'jwt',
41
- 'access_token',
42
- 'client_secret',
43
- 'session_token',
44
- 'refresh_token'
45
- ];
46
- /**
47
- * The global censor function used by the logger.
48
- */
49
- let globalRedactCensor = (value, path, sensitiveFields = defaultSensitiveFields) => {
50
- if (typeof value !== 'string')
51
- return '***';
52
- const lowerPath = path.map(p => p.toLowerCase());
53
- const lowerSensitiveFields = sensitiveFields.map(f => f.toLowerCase());
54
- if (lowerPath.some(p => lowerSensitiveFields.includes(p)))
55
- return '***';
56
- // Redact URLs
57
- if (lowerPath[0] === 'url') {
58
- return value.replace(new RegExp(`([?&](${lowerSensitiveFields.join('|')})=)[^&#]*`, 'gi'), '$1***');
59
- }
60
- if (lowerPath.some(p => p.includes('authorization') || p.includes('auth'))) {
61
- return value.replace(/^(\S+)\s+.+$/, '$1 ***') || '***';
62
- }
63
- // Redact sensitive fields - check each path segment against each sensitive field
64
- if (lowerPath.some(pathPart => lowerSensitiveFields.some(field => pathPart.includes(field)))) {
65
- return '***';
66
- }
67
- if (path.length > 0 && !['req', 'res', 'headers'].includes(lowerPath[0])) {
68
- return value;
69
- }
70
- return value;
71
- };
72
- /**
73
- * Sets the global redaction censor function used throughout the application for log redaction.
74
- *
75
- * Use this function to customize how sensitive data is redacted in logs. The provided function
76
- * will replace the default censor implementation.
77
- *
78
- * @example
79
- * ```typescript
80
- * // Custom censor that redacts only specific values
81
- * setRedactCensor((value, path, sensitiveFields) => {
82
- * if (path.includes('password')) return '***';
83
- * return value;
84
- * });
85
- * ```
86
- *
87
- * @param fn - The redaction censor function to use globally. This function receives:
88
- * - value: The data value to potentially redact
89
- * - path: Array of strings representing the path to the value in the object
90
- * - sensitiveFields: Optional array of field names to consider sensitive
91
- * @returns void
92
- */
93
- export function setRedactCensor(fn) {
94
- globalRedactCensor = fn;
95
- }
96
- /**
97
- * Gets the current global redaction censor function used for log redaction.
98
- *
99
- * This function is called internally by the logger when determining how to redact
100
- * sensitive information. It can also be used to access the current censor implementation
101
- * for composition or extension.
102
- *
103
- * @example
104
- * ```typescript
105
- * const currentCensor = getRedactCensor();
106
- * // Create an enhanced censor that extends the current one
107
- * setRedactCensor((value, path, fields) => {
108
- * // Add custom logic before delegating to current censor
109
- * if (someCondition) return customHandling();
110
- * return currentCensor(value, path, fields);
111
- * });
112
- * ```
113
- *
114
- * @returns The current redaction censor function
115
- */
116
- export function getRedactCensor() {
117
- return globalRedactCensor;
118
- }
119
- /**
120
- * Convenience function to redact sensitive data using the current global redact censor.
121
- *
122
- * This is a direct wrapper around the global censor function that simplifies usage
123
- * in application code without needing to access the censor function directly.
124
- *
125
- * @example
126
- * ```typescript
127
- * // Redact a potential sensitive value
128
- * const safeValue = redact(value, ['user', 'apiKey']);
129
- * ```
130
- *
131
- * @param value - The value to potentially redact
132
- * @param path - Array of strings representing the path to the value in the object
133
- * @param sensitiveFields - Optional array of field names to consider sensitive
134
- * @returns The redacted string value or "***" for redacted content
135
- */
136
- export function redact(value, path, sensitiveFields) {
137
- return globalRedactCensor(value, path, sensitiveFields);
138
- }
139
- /**
140
- * Extends the current redaction function with additional fields to redact.
141
- *
142
- * This function wraps the existing censor while adding more fields to be considered
143
- * sensitive without replacing the entire redaction logic.
144
- *
145
- * @example
146
- * ```typescript
147
- * // Add custom fields to be redacted in all future redaction operations
148
- * addRedactFields(['customerId', 'accountNumber']);
149
- * ```
150
- *
151
- * @param fields - Array of additional field names to redact
152
- */
153
- export function addRedactFields(fields) {
154
- const prev = globalRedactCensor;
155
- globalRedactCensor = (value, path, sensitiveFields = defaultSensitiveFields) => prev(value, path, [...(sensitiveFields || []), ...fields]);
156
- }
157
- /**
158
- * Replaces the default list of sensitive fields with a new list.
159
- *
160
- * This is useful when you want complete control over what fields are considered
161
- * sensitive by default, rather than using the library's built-in list.
162
- *
163
- * @example
164
- * ```typescript
165
- * // Replace default sensitive fields with a custom list
166
- * setSensitiveFields(['password', 'ssn', 'creditCard']);
167
- * ```
168
- *
169
- * @param fields - Array of field names to set as the new default sensitive fields
170
- */
171
- export function setSensitiveFields(fields) {
172
- defaultSensitiveFields.splice(0, defaultSensitiveFields.length, ...fields);
173
- }
174
- /**
175
- * Adds additional field names to the default sensitive fields list.
176
- *
177
- * This preserves the existing sensitive fields while adding new ones for
178
- * application-specific sensitive data.
179
- *
180
- * @example
181
- * ```typescript
182
- * // Add domain-specific sensitive fields to the default list
183
- * addSensitiveFields(['socialSecurityNumber', 'medicalRecordNumber']);
184
- * ```
185
- *
186
- * @param fields - Array of additional field names to add to the sensitive fields list
187
- */
188
- export function addSensitiveFields(fields) {
189
- defaultSensitiveFields.push(...fields);
190
- }
191
- /**
192
- * Use an object compatible with either modern or legacy global scopes.
193
- */
194
- export const _globalThis = typeof globalThis === 'object' ? globalThis : global;
195
- const _global = _globalThis;
196
- /**
197
- * Initializes the global root logger according to app configuration.
198
- *
199
- * - Sets log name, level, timestamp, and redaction for sensitive fields.
200
- * - Uses singleton in global symbol registry.
201
- */
202
- function setupLogger() {
203
- var _a;
204
- const logParams = {
205
- name: config.logger.name || '@catbee/utils',
206
- level: config.logger.level || 'info',
207
- redact: {
208
- paths: ['req.authorization', 'res.authorization', 'url', 'headers.authorization', 'headers.cookies'],
209
- censor: (value, path) => redact(value, path)
210
- },
211
- // serializers: {
212
- // req: pino.stdSerializers.req,
213
- // request: pino.stdSerializers.req,
214
- // res: pino.stdSerializers.res,
215
- // response: pino.stdSerializers.res,
216
- // err: pino.stdSerializers.err,
217
- // error: pino.stdSerializers.err
218
- // },
219
- timestamp: stdTimeFunctions.isoTime
220
- };
221
- const logger = config.logger.pretty && Env.isDev()
222
- ? pino(logParams, pino.transport({
223
- target: 'pino-pretty',
224
- options: {
225
- colorize: true,
226
- translateTime: 'SYS:standard',
227
- ignore: 'pid,hostname',
228
- singleLine: config.logger.singleLine,
229
- levelFirst: true
230
- }
231
- }))
232
- : pino(logParams);
233
- _global[GLOBAL_LOGGER_KEY] = logger;
234
- (_a = _global[GLOBAL_LOGGER_KEY]) === null || _a === void 0 ? void 0 : _a.debug('Logger initialized');
235
- }
236
- /**
237
- * Retrieves the current logger instance:
238
- * - Returns a request-scoped logger from AsyncLocalStorage if available
239
- * - Falls back to the global (singleton) logger
240
- * - Initializes the global logger if not created yet
241
- *
242
- * @returns {Logger} The logger instance (request-bound or global root logger)
243
- */
244
- export function getLogger() {
245
- const logger = ContextStore.get(StoreKeys.LOGGER);
246
- if (logger)
247
- return logger;
248
- if (!_global[GLOBAL_LOGGER_KEY]) {
249
- setupLogger();
250
- }
251
- return _global[GLOBAL_LOGGER_KEY];
252
- }
253
- /**
254
- * Logger instance for the global context.
255
- * This logger is used for logging messages that are not tied to a specific request.
256
- */
257
- export const logger = getLogger();
258
- /**
259
- * Creates a child logger with additional context.
260
- *
261
- * @param {Record<string, any>} bindings - Properties to attach to all log records
262
- * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global)
263
- * @returns {Logger} Child logger with merged context
264
- */
265
- export function createChildLogger(bindings, parentLogger) {
266
- const logger = parentLogger || getLogger();
267
- return logger.child(bindings);
268
- }
269
- /**
270
- * Creates a request-scoped logger with request ID and stores it in context
271
- *
272
- * @param {string} requestId - Unique request identifier
273
- * @param {object} [additionalContext] - Additional context to include in logs
274
- * @returns {Logger} Request-scoped logger instance
275
- */
276
- export function createRequestLogger(requestId, additionalContext = {}) {
277
- const logger = createChildLogger(Object.assign({ requestId }, additionalContext));
278
- try {
279
- ContextStore.set(StoreKeys.LOGGER, logger);
280
- }
281
- catch (_a) {
282
- // Context not initialized, can't store logger
283
- logger.debug('Failed to store logger in context - AsyncLocalStorage not initialized');
284
- }
285
- return logger;
286
- }
287
- /**
288
- * Utility to safely log errors with proper stack trace extraction
289
- *
290
- * @param {Error|unknown} error - Error object to log
291
- * @param {string} [message] - Optional message to include
292
- * @param {Record<string, any>} [context] - Additional context properties
293
- */
294
- export function logError(error, message, context) {
295
- const logger = getLogger();
296
- const errObj = error instanceof Error ? error : new Error(String(error));
297
- const logContext = Object.assign(Object.assign({}, context), { error: errObj });
298
- logger.error(logContext, message || errObj.message);
299
- }
300
- //# sourceMappingURL=logger.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.utils.js","sourceRo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AAC,SAAiB,EAAE,oBAAyC,EAAE;IAChG,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,CAAC,uEAAuE,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAsB,EAAE,OAAgB,EAAE,OAA6B;IAC9F,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,KAAK,EAAE,MAAM,GACd,CAAC;IAEF,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport pino, { LoggerOptions, stdTimeFunctions } from 'pino';\nimport type { Logger as PinoLogger } from 'pino'; // Type-only import\nimport { config } from '../config';\nimport { ContextStore, StoreKeys } from './context-store.utils';\nimport { Env } from './env.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 * Logger type for application-wide logging.\n */\nexport type Logger = pino.Logger;\n\n/**\n * Logger levels for application-wide logging.\n */\nexport type LoggerLevels = pino.Level;\n\n// Default sensitive fields\nexport const defaultSensitiveFields = [\n 'password',\n 'secret',\n 'token',\n 'apiKey',\n 'api_key',\n 'auth',\n 'jwt',\n 'access_token',\n 'client_secret',\n 'session_token',\n 'refresh_token'\n];\n\n/**\n * The global censor function used by the logger.\n */\nlet globalRedactCensor: (value: unknown, path: string[], sensitiveFields?: string[]) => string = (\n value,\n path,\n sensitiveFields = defaultSensitiveFields\n) => {\n if (typeof value !== 'string') return '***';\n\n const lowerPath = path.map(p => p.toLowerCase());\n const lowerSensitiveFields = sensitiveFields.map(f => f.toLowerCase());\n\n if (lowerPath.some(p => lowerSensitiveFields.includes(p))) return '***';\n\n // Redact URLs\n if (lowerPath[0] === 'url') {\n return value.replace(new RegExp(`([?&](${lowerSensitiveFields.join('|')})=)[^&#]*`, 'gi'), '$1***');\n }\n\n if (lowerPath.some(p => p.includes('authorization') || p.includes('auth'))) {\n return value.replace(/^(\\S+)\\s+.+$/, '$1 ***') || '***';\n }\n\n // Redact sensitive fields - check each path segment against each sensitive field\n if (lowerPath.some(pathPart => lowerSensitiveFields.some(field => pathPart.includes(field)))) {\n return '***';\n }\n\n if (path.length > 0 && !['req', 'res', 'headers'].includes(lowerPath[0])) {\n return value;\n }\n\n return value;\n};\n\n/**\n * Sets the global redaction censor function used throughout the application for log redaction.\n *\n * Use this function to customize how sensitive data is redacted in logs. The provided function\n * will replace the default censor implementation.\n *\n * @example\n * ```typescript\n * // Custom censor that redacts only specific values\n * setRedactCensor((value, path, sensitiveFields) => {\n * if (path.includes('password')) return '***';\n * return value;\n * });\n * ```\n *\n * @param fn - The redaction censor function to use globally. This function receives:\n * - value: The data value to potentially redact\n * - path: Array of strings representing the path to the value in the object\n * - sensitiveFields: Optional array of field names to consider sensitive\n * @returns void\n */\nexport function setRedactCensor(fn: (value: unknown, path: string[], sensitiveFields?: string[]) => string) {\n globalRedactCensor = fn;\n}\n\n/**\n * Gets the current global redaction censor function used for log redaction.\n *\n * This function is called internally by the logger when determining how to redact\n * sensitive information. It can also be used to access the current censor implementation\n * for composition or extension.\n *\n * @example\n * ```typescript\n * const currentCensor = getRedactCensor();\n * // Create an enhanced censor that extends the current one\n * setRedactCensor((value, path, fields) => {\n * // Add custom logic before delegating to current censor\n * if (someCondition) return customHandling();\n * return currentCensor(value, path, fields);\n * });\n * ```\n *\n * @returns The current redaction censor function\n */\nexport function getRedactCensor() {\n return globalRedactCensor;\n}\n\n/**\n * Convenience function to redact sensitive data using the current global redact censor.\n *\n * This is a direct wrapper around the global censor function that simplifies usage\n * in application code without needing to access the censor function directly.\n *\n * @example\n * ```typescript\n * // Redact a potential sensitive value\n * const safeValue = redact(value, ['user', 'apiKey']);\n * ```\n *\n * @param value - The value to potentially redact\n * @param path - Array of strings representing the path to the value in the object\n * @param sensitiveFields - Optional array of field names to consider sensitive\n * @returns The redacted string value or \"***\" for redacted content\n */\nexport function redact(value: unknown, path: string[], sensitiveFields?: string[]) {\n return globalRedactCensor(value, path, sensitiveFields);\n}\n\n/**\n * Extends the current redaction function with additional fields to redact.\n *\n * This function wraps the existing censor while adding more fields to be considered\n * sensitive without replacing the entire redaction logic.\n *\n * @example\n * ```typescript\n * // Add custom fields to be redacted in all future redaction operations\n * addRedactFields(['customerId', 'accountNumber']);\n * ```\n *\n * @param fields - Array of additional field names to redact\n */\nexport function addRedactFields(fields: string[]) {\n const prev = globalRedactCensor;\n globalRedactCensor = (value, path, sensitiveFields = defaultSensitiveFields) =>\n prev(value, path, [...(sensitiveFields || []), ...fields]);\n}\n\n/**\n * Replaces the default list of sensitive fields with a new list.\n *\n * This is useful when you want complete control over what fields are considered\n * sensitive by default, rather than using the library's built-in list.\n *\n * @example\n * ```typescript\n * // Replace default sensitive fields with a custom list\n * setSensitiveFields(['password', 'ssn', 'creditCard']);\n * ```\n *\n * @param fields - Array of field names to set as the new default sensitive fields\n */\nexport function setSensitiveFields(fields: string[]) {\n defaultSensitiveFields.splice(0, defaultSensitiveFields.length, ...fields);\n}\n\n/**\n * Adds additional field names to the default sensitive fields list.\n *\n * This preserves the existing sensitive fields while adding new ones for\n * application-specific sensitive data.\n *\n * @example\n * ```typescript\n * // Add domain-specific sensitive fields to the default list\n * addSensitiveFields(['socialSecurityNumber', 'medicalRecordNumber']);\n * ```\n *\n * @param fields - Array of additional field names to add to the sensitive fields list\n */\nexport function addSensitiveFields(fields: string[]) {\n defaultSensitiveFields.push(...fields);\n}\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]: PinoLogger };\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 || '@catbee/utils',\n level: config.logger.level || 'info',\n redact: {\n paths: ['req.authorization', 'res.authorization', 'url', 'headers.authorization', 'headers.cookies'],\n censor: (value, path) => redact(value, path)\n },\n // serializers: {\n // req: pino.stdSerializers.req,\n // request: pino.stdSerializers.req,\n // res: pino.stdSerializers.res,\n // response: pino.stdSerializers.res,\n // err: pino.stdSerializers.err,\n // error: pino.stdSerializers.err\n // },\n timestamp: stdTimeFunctions.isoTime\n };\n\n const logger =\n config.logger.pretty && Env.isDev()\n ? pino(\n logParams,\n pino.transport({\n target: 'pino-pretty',\n options: {\n colorize: true,\n translateTime: 'SYS:standard',\n ignore: 'pid,hostname',\n singleLine: config.logger.singleLine,\n levelFirst: true\n }\n })\n )\n : pino(logParams);\n\n _global[GLOBAL_LOGGER_KEY] = logger;\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(): PinoLogger {\n const logger = ContextStore.get<PinoLogger>(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 * Logger instance for the global context.\n * This logger is used for logging messages that are not tied to a specific request.\n */\nexport const logger = getLogger();\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(bindings: Record<string, any>, parentLogger?: PinoLogger): PinoLogger {\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(requestId: string, additionalContext: Record<string, any> = {}): PinoLogger {\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('Failed to store logger in context - AsyncLocalStorage not initialized');\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(error: Error | unknown, message?: string, context?: Record<string, any>): void {\n const logger = getLogger();\n\n const errObj = error instanceof Error ? error : new Error(String(error));\n const logContext = {\n ...context,\n error: errObj\n };\n\n logger.error(logContext, message || errObj.message);\n}\n"]}