@catbee/utils 0.0.5 → 0.0.6

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 (201) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +222 -4
  3. package/build/esm/config.d.ts +88 -3
  4. package/build/esm/config.js +97 -1
  5. package/build/esm/config.js.map +1 -1
  6. package/build/esm/index.d.ts +4 -0
  7. package/build/esm/index.js +27 -0
  8. package/build/esm/index.js.map +1 -1
  9. package/build/esm/servers/server.builder.d.ts +625 -0
  10. package/build/esm/servers/server.builder.js +722 -0
  11. package/build/esm/servers/server.builder.js.map +1 -0
  12. package/build/esm/servers/server.d.ts +256 -0
  13. package/build/esm/servers/server.js +1211 -0
  14. package/build/esm/servers/server.js.map +1 -0
  15. package/build/esm/types/api-response.d.ts +5 -7
  16. package/build/esm/types/api-response.js +23 -0
  17. package/build/esm/types/api-response.js.map +1 -1
  18. package/build/esm/types/index.d.ts +125 -0
  19. package/build/esm/types/index.js +25 -0
  20. package/build/esm/types/index.js.map +1 -0
  21. package/build/esm/types/server.d.ts +285 -0
  22. package/build/esm/types/server.js +25 -0
  23. package/build/esm/types/server.js.map +1 -0
  24. package/build/esm/utils/array.utils.js +23 -0
  25. package/build/esm/utils/array.utils.js.map +1 -1
  26. package/build/esm/utils/async.utils.js +23 -0
  27. package/build/esm/utils/async.utils.js.map +1 -1
  28. package/build/esm/utils/cache.utils.js +23 -0
  29. package/build/esm/utils/cache.utils.js.map +1 -1
  30. package/build/esm/utils/context-store.utils.js +23 -0
  31. package/build/esm/utils/context-store.utils.js.map +1 -1
  32. package/build/esm/utils/crypto.utils.js +23 -0
  33. package/build/esm/utils/crypto.utils.js.map +1 -1
  34. package/build/esm/utils/decorators.utils.js +23 -1
  35. package/build/esm/utils/decorators.utils.js.map +1 -1
  36. package/build/esm/utils/dir.utils.js +23 -0
  37. package/build/esm/utils/dir.utils.js.map +1 -1
  38. package/build/esm/utils/env.utils.js +23 -0
  39. package/build/esm/utils/env.utils.js.map +1 -1
  40. package/build/esm/utils/exception.utils.js +31 -8
  41. package/build/esm/utils/exception.utils.js.map +1 -1
  42. package/build/esm/utils/fs.utils.js +23 -0
  43. package/build/esm/utils/fs.utils.js.map +1 -1
  44. package/build/esm/utils/http-status-codes.js +23 -0
  45. package/build/esm/utils/http-status-codes.js.map +1 -1
  46. package/build/esm/utils/id.utils.js +23 -0
  47. package/build/esm/utils/id.utils.js.map +1 -1
  48. package/build/esm/utils/logger.utils.d.ts +11 -0
  49. package/build/esm/utils/logger.utils.js +46 -3
  50. package/build/esm/utils/logger.utils.js.map +1 -1
  51. package/build/esm/utils/middleware.utils.d.ts +2 -0
  52. package/build/esm/utils/middleware.utils.js +59 -49
  53. package/build/esm/utils/middleware.utils.js.map +1 -1
  54. package/build/esm/utils/obj.utils.d.ts +10 -3
  55. package/build/esm/utils/obj.utils.js +225 -15
  56. package/build/esm/utils/obj.utils.js.map +1 -1
  57. package/build/esm/utils/request.utils.js +23 -0
  58. package/build/esm/utils/request.utils.js.map +1 -1
  59. package/build/esm/utils/response.utils.d.ts +15 -1
  60. package/build/esm/utils/response.utils.js +51 -0
  61. package/build/esm/utils/response.utils.js.map +1 -1
  62. package/build/esm/utils/string.utils.js +23 -0
  63. package/build/esm/utils/string.utils.js.map +1 -1
  64. package/build/esm/utils/url.utils.js +23 -0
  65. package/build/esm/utils/url.utils.js.map +1 -1
  66. package/build/esm/utils/validate.utils.d.ts +7 -0
  67. package/build/esm/utils/validate.utils.js +35 -2
  68. package/build/esm/utils/validate.utils.js.map +1 -1
  69. package/build/esnext/config.d.ts +88 -3
  70. package/build/esnext/config.js +97 -1
  71. package/build/esnext/config.js.map +1 -1
  72. package/build/esnext/index.d.ts +4 -0
  73. package/build/esnext/index.js +27 -0
  74. package/build/esnext/index.js.map +1 -1
  75. package/build/esnext/servers/server.builder.d.ts +625 -0
  76. package/build/esnext/servers/server.builder.js +677 -0
  77. package/build/esnext/servers/server.builder.js.map +1 -0
  78. package/build/esnext/servers/server.d.ts +256 -0
  79. package/build/esnext/servers/server.js +918 -0
  80. package/build/esnext/servers/server.js.map +1 -0
  81. package/build/esnext/types/api-response.d.ts +5 -7
  82. package/build/esnext/types/api-response.js +23 -0
  83. package/build/esnext/types/api-response.js.map +1 -1
  84. package/build/esnext/types/index.d.ts +125 -0
  85. package/build/esnext/types/index.js +25 -0
  86. package/build/esnext/types/index.js.map +1 -0
  87. package/build/esnext/types/server.d.ts +285 -0
  88. package/build/esnext/types/server.js +25 -0
  89. package/build/esnext/types/server.js.map +1 -0
  90. package/build/esnext/utils/array.utils.js +23 -0
  91. package/build/esnext/utils/array.utils.js.map +1 -1
  92. package/build/esnext/utils/async.utils.js +23 -0
  93. package/build/esnext/utils/async.utils.js.map +1 -1
  94. package/build/esnext/utils/cache.utils.js +23 -0
  95. package/build/esnext/utils/cache.utils.js.map +1 -1
  96. package/build/esnext/utils/context-store.utils.js +23 -0
  97. package/build/esnext/utils/context-store.utils.js.map +1 -1
  98. package/build/esnext/utils/crypto.utils.js +23 -0
  99. package/build/esnext/utils/crypto.utils.js.map +1 -1
  100. package/build/esnext/utils/decorators.utils.js +23 -1
  101. package/build/esnext/utils/decorators.utils.js.map +1 -1
  102. package/build/esnext/utils/dir.utils.js +23 -0
  103. package/build/esnext/utils/dir.utils.js.map +1 -1
  104. package/build/esnext/utils/env.utils.js +23 -0
  105. package/build/esnext/utils/env.utils.js.map +1 -1
  106. package/build/esnext/utils/exception.utils.js +30 -7
  107. package/build/esnext/utils/exception.utils.js.map +1 -1
  108. package/build/esnext/utils/fs.utils.js +23 -0
  109. package/build/esnext/utils/fs.utils.js.map +1 -1
  110. package/build/esnext/utils/http-status-codes.js +23 -0
  111. package/build/esnext/utils/http-status-codes.js.map +1 -1
  112. package/build/esnext/utils/id.utils.js +23 -0
  113. package/build/esnext/utils/id.utils.js.map +1 -1
  114. package/build/esnext/utils/logger.utils.d.ts +11 -0
  115. package/build/esnext/utils/logger.utils.js +46 -3
  116. package/build/esnext/utils/logger.utils.js.map +1 -1
  117. package/build/esnext/utils/middleware.utils.d.ts +2 -0
  118. package/build/esnext/utils/middleware.utils.js +55 -49
  119. package/build/esnext/utils/middleware.utils.js.map +1 -1
  120. package/build/esnext/utils/obj.utils.d.ts +10 -3
  121. package/build/esnext/utils/obj.utils.js +176 -12
  122. package/build/esnext/utils/obj.utils.js.map +1 -1
  123. package/build/esnext/utils/request.utils.js +23 -0
  124. package/build/esnext/utils/request.utils.js.map +1 -1
  125. package/build/esnext/utils/response.utils.d.ts +15 -1
  126. package/build/esnext/utils/response.utils.js +51 -0
  127. package/build/esnext/utils/response.utils.js.map +1 -1
  128. package/build/esnext/utils/string.utils.js +23 -0
  129. package/build/esnext/utils/string.utils.js.map +1 -1
  130. package/build/esnext/utils/url.utils.js +23 -0
  131. package/build/esnext/utils/url.utils.js.map +1 -1
  132. package/build/esnext/utils/validate.utils.d.ts +7 -0
  133. package/build/esnext/utils/validate.utils.js +33 -0
  134. package/build/esnext/utils/validate.utils.js.map +1 -1
  135. package/build/src/config.d.ts +88 -3
  136. package/build/src/config.js +98 -2
  137. package/build/src/config.js.map +1 -1
  138. package/build/src/index.d.ts +4 -0
  139. package/build/src/index.js +27 -0
  140. package/build/src/index.js.map +1 -1
  141. package/build/src/servers/server.builder.d.ts +625 -0
  142. package/build/src/servers/server.builder.js +681 -0
  143. package/build/src/servers/server.builder.js.map +1 -0
  144. package/build/src/servers/server.d.ts +256 -0
  145. package/build/src/servers/server.js +958 -0
  146. package/build/src/servers/server.js.map +1 -0
  147. package/build/src/types/api-response.d.ts +5 -7
  148. package/build/src/types/api-response.js +23 -0
  149. package/build/src/types/api-response.js.map +1 -1
  150. package/build/src/types/index.d.ts +125 -0
  151. package/build/src/types/index.js +26 -0
  152. package/build/src/types/index.js.map +1 -0
  153. package/build/src/types/server.d.ts +285 -0
  154. package/build/src/types/server.js +26 -0
  155. package/build/src/types/server.js.map +1 -0
  156. package/build/src/utils/array.utils.js +23 -0
  157. package/build/src/utils/array.utils.js.map +1 -1
  158. package/build/src/utils/async.utils.js +23 -0
  159. package/build/src/utils/async.utils.js.map +1 -1
  160. package/build/src/utils/cache.utils.js +23 -0
  161. package/build/src/utils/cache.utils.js.map +1 -1
  162. package/build/src/utils/context-store.utils.js +23 -0
  163. package/build/src/utils/context-store.utils.js.map +1 -1
  164. package/build/src/utils/crypto.utils.js +23 -0
  165. package/build/src/utils/crypto.utils.js.map +1 -1
  166. package/build/src/utils/decorators.utils.js +23 -1
  167. package/build/src/utils/decorators.utils.js.map +1 -1
  168. package/build/src/utils/dir.utils.js +23 -0
  169. package/build/src/utils/dir.utils.js.map +1 -1
  170. package/build/src/utils/env.utils.js +23 -0
  171. package/build/src/utils/env.utils.js.map +1 -1
  172. package/build/src/utils/exception.utils.js +30 -7
  173. package/build/src/utils/exception.utils.js.map +1 -1
  174. package/build/src/utils/fs.utils.js +23 -0
  175. package/build/src/utils/fs.utils.js.map +1 -1
  176. package/build/src/utils/http-status-codes.js +23 -0
  177. package/build/src/utils/http-status-codes.js.map +1 -1
  178. package/build/src/utils/id.utils.js +23 -0
  179. package/build/src/utils/id.utils.js.map +1 -1
  180. package/build/src/utils/logger.utils.d.ts +11 -0
  181. package/build/src/utils/logger.utils.js +47 -4
  182. package/build/src/utils/logger.utils.js.map +1 -1
  183. package/build/src/utils/middleware.utils.d.ts +2 -0
  184. package/build/src/utils/middleware.utils.js +54 -48
  185. package/build/src/utils/middleware.utils.js.map +1 -1
  186. package/build/src/utils/obj.utils.d.ts +10 -3
  187. package/build/src/utils/obj.utils.js +177 -12
  188. package/build/src/utils/obj.utils.js.map +1 -1
  189. package/build/src/utils/request.utils.js +23 -0
  190. package/build/src/utils/request.utils.js.map +1 -1
  191. package/build/src/utils/response.utils.d.ts +15 -1
  192. package/build/src/utils/response.utils.js +52 -0
  193. package/build/src/utils/response.utils.js.map +1 -1
  194. package/build/src/utils/string.utils.js +23 -0
  195. package/build/src/utils/string.utils.js.map +1 -1
  196. package/build/src/utils/url.utils.js +23 -0
  197. package/build/src/utils/url.utils.js.map +1 -1
  198. package/build/src/utils/validate.utils.d.ts +7 -0
  199. package/build/src/utils/validate.utils.js +36 -2
  200. package/build/src/utils/validate.utils.js.map +1 -1
  201. package/package.json +35 -9
package/LICENSE CHANGED
@@ -1,201 +1,21 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ The MIT License
2
+
3
+ Copyright (c) 2025 Catbee Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -56,6 +56,7 @@ console.log(isEmail("user@example.com")); // true
56
56
  - [**URL Utilities**](#-url-utilities)
57
57
  - [**Validate Utilities**](#-validate-utilities)
58
58
  - [**Decorators Utilities**](#-decorators-utilities)
59
+ - [**Express Server**](#-express-server)
59
60
 
60
61
  ---
61
62
 
@@ -536,11 +537,11 @@ logger.error({ context: "some context" }, "Error occurred");
536
537
 
537
538
  ## 🧩 Middleware Utilities
538
539
 
539
- - `requestId(options?): Middleware` – Generate and attach a unique request ID to each request.
540
- - `responseTime(options?): Middleware` – Measure and log the response time for each request.
540
+ - `requestId(options: { headerName?: string; exposeHeader?: boolean; generator?: () => string }): Middleware` – Generate and attach a unique request ID to each request.
541
+ - `responseTime(options?: { addHeader?: boolean; logOnComplete?: boolean }): Middleware` – Measure and log the response time for each request.
541
542
  - `timeout(timeoutMs?: number): Middleware` – Abort requests that exceed a specified timeout.
542
543
  - `setupRequestContext(): Middleware` – Set up the request context for each incoming request.
543
- - `errorHandler(options?): Middleware` – Centralized error handling middleware.
544
+ - `errorHandler(options: { logErrors?: boolean; includeDetails?: boolean }): Middleware` – Centralized error handling middleware.
544
545
 
545
546
  **Example:**
546
547
  ```ts
@@ -557,7 +558,8 @@ A set of helpers for working with JavaScript objects, including deep merging, fl
557
558
  - `isObjEmpty(obj: Record<any, any>): boolean` – Check if an object has no own properties.
558
559
  - `pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>` – Create a new object with only the specified keys.
559
560
  - `omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>` – Create a new object without the specified keys.
560
- - `deepObjMerge<T>(target: T, source: Partial<T>): T` – Deeply merge two objects.
561
+ - `deepObjMerge<T extends object>(target: T, ...sources: any[]): T` – Deeply merge multiple objects into the target.
562
+ - `isPlainObject(value: any): value is Record<string, any>` – Check if a value is a plain object.
561
563
  - `flattenObject<T>(obj: T, prefix?: string): Record<string, any>` – Flatten a nested object into dot notation.
562
564
  - `getValueByPath<T>(obj: T, path: string): any` – Get a value from an object by dot path.
563
565
  - `setValueByPath<T>(obj: T, path: string, value: any): T` – Set a value in an object by dot path.
@@ -828,6 +830,7 @@ const url = appendQueryParams('https://example.com', { page: 1, limit: 10 });
828
830
 
829
831
  A comprehensive suite of validators for checking strings, numbers, objects, arrays, and common formats such as email, UUID, IP, and more. Useful for input validation and API parameter checks.
830
832
 
833
+ - `isPort(str: string | number): boolean` – Check if a string or number is a valid port number.
831
834
  - `isEmail(str: string): boolean` – Check if a string is a valid email address.
832
835
  - `isUUID(str: string): boolean` – Check if a string is a valid UUID.
833
836
  - `isURL(str: string): boolean` – Check if a string is a valid URL.
@@ -926,6 +929,221 @@ registerControllers(router, [ExampleController]);
926
929
  - All parameter decorators (`@Query`, `@Param`, etc.) are optional and can be used in any order.
927
930
  - `registerControllers(router, controllers)` will register all routes and apply middlewares, hooks, status codes, and headers as defined.
928
931
 
932
+ ## 🚀 Express Server
933
+
934
+ A production-ready Express server with enterprise-grade features for building robust web services and APIs.
935
+
936
+ ### Features
937
+
938
+ - **Security**: CORS, Helmet, rate limiting, timeouts, body size limits
939
+ - **Monitoring**: Request logging, Prometheus metrics, health checks
940
+ - **Performance**: Response compression, static file serving, conditional settings
941
+ - **Reliability**: Graceful shutdown, connection tracking, error handling
942
+ - **Developer UX**: OpenAPI docs, debugging tools
943
+ - **Extensibility**: Lifecycle hooks, middleware registration, custom routes
944
+
945
+ ### Getting Started
946
+
947
+ Create a server with the fluent builder pattern:
948
+
949
+ ```ts
950
+ import { ServerConfigBuilder, ExpressServer } from "@catbee/utils";
951
+
952
+ // Configure the server
953
+ const config = new ServerConfigBuilder()
954
+ .withPort(3000)
955
+ .withHost('localhost')
956
+ .enableCors()
957
+ .enableHelmet()
958
+ .enableCompression()
959
+ .withGlobalPrefix('/api')
960
+ .withRequestLogging({
961
+ enable: true,
962
+ ignorePaths: ['/healthz', '/metrics']
963
+ })
964
+ .enableMetrics()
965
+ .build();
966
+
967
+ // Create and start the server
968
+ const server = new ExpressServer(config, {
969
+ beforeStart: (app) => console.log('Server about to start...'),
970
+ afterStart: (server) => console.log('Server started successfully!')
971
+ });
972
+
973
+ // Register health checks
974
+ server.registerHealthCheck('database', async () => {
975
+ return await checkDatabaseConnection();
976
+ });
977
+
978
+ // Register routes
979
+ const router = server.createRouter('/users');
980
+ router.get('/', (req, res) => {
981
+ res.json({ users: [] });
982
+ });
983
+
984
+ // Start the server
985
+ await server.start();
986
+
987
+ // Enable graceful shutdown handling
988
+ server.enableGracefulShutdown();
989
+ ```
990
+
991
+ ### Server Configuration Builder
992
+
993
+ Use the fluent builder API to configure all aspects of your server:
994
+
995
+ ```ts
996
+ import { ServerConfigBuilder } from "@catbee/utils";
997
+
998
+ const config = new ServerConfigBuilder()
999
+ // Basic configuration
1000
+ .withPort(3000) // Set listen port
1001
+ .withHost('0.0.0.0') // Set listen address
1002
+ .withGlobalPrefix('/api/v1') // Set global route prefix
1003
+
1004
+ // Security
1005
+ .enableCors() // Enable CORS (simple)
1006
+ .withCors({ // Configure CORS (advanced)
1007
+ origin: ['https://example.com'],
1008
+ methods: ['GET', 'POST']
1009
+ })
1010
+ .enableHelmet() // Enable secure headers
1011
+ .enableRateLimit({ // Configure rate limiting
1012
+ max: 100,
1013
+ windowMs: 15 * 60 * 1000
1014
+ })
1015
+
1016
+ // Performance
1017
+ .enableCompression() // Enable response compression
1018
+ .withStaticFolder({ // Serve static files
1019
+ path: '/assets',
1020
+ directory: './public/assets',
1021
+ maxAge: '1d'
1022
+ })
1023
+
1024
+ // Monitoring
1025
+ .enableMetrics({ // Enable Prometheus metrics
1026
+ path: '/metrics'
1027
+ })
1028
+ .withHealthCheck({ // Configure health checks
1029
+ path: '/health',
1030
+ detailed: true
1031
+ })
1032
+ .enableResponseTime() // Track response times
1033
+ .enableRequestLogging() // Log requests
1034
+
1035
+ // Documentation
1036
+ .enableOpenApi('./openapi.yaml', { // Enable OpenAPI docs
1037
+ mountPath: '/docs'
1038
+ })
1039
+
1040
+ // Microservice configuration
1041
+ .withMicroService({ // Configure as microservice
1042
+ appName: 'user-service',
1043
+ serviceVersion: {
1044
+ enable: true,
1045
+ version: '1.0.0'
1046
+ }
1047
+ })
1048
+
1049
+ // Build final configuration
1050
+ .build();
1051
+ ```
1052
+
1053
+ ### Server Lifecycle Hooks
1054
+
1055
+ Register hooks for key server lifecycle events:
1056
+
1057
+ ```ts
1058
+ const server = new ExpressServer(config, {
1059
+ // Before server initialization (middleware setup)
1060
+ beforeInit: (server) => {
1061
+ console.log('Initializing server...');
1062
+ },
1063
+
1064
+ // After server initialization (routes registered)
1065
+ afterInit: (server) => {
1066
+ console.log('Server initialized');
1067
+ },
1068
+
1069
+ // Before server starts listening
1070
+ beforeStart: (app) => {
1071
+ console.log('Starting server...');
1072
+ },
1073
+
1074
+ // After server has started listening
1075
+ afterStart: (httpServer) => {
1076
+ console.log('Server started');
1077
+ },
1078
+
1079
+ // Before server begins shutdown
1080
+ beforeStop: (httpServer) => {
1081
+ console.log('Shutting down server...');
1082
+ },
1083
+
1084
+ // After server has fully stopped
1085
+ afterStop: () => {
1086
+ console.log('Server stopped');
1087
+ },
1088
+
1089
+ // Global request handler
1090
+ onRequest: (req, res, next) => {
1091
+ console.log('Processing request...');
1092
+ next();
1093
+ },
1094
+
1095
+ // Global response handler
1096
+ onResponse: (req, res, next) => {
1097
+ res.setHeader('X-Server-Time', new Date().toISOString());
1098
+ next();
1099
+ },
1100
+
1101
+ // Global error handler
1102
+ onError: (err, req, res, next) => {
1103
+ console.error('Error processing request:', err);
1104
+ res.status(500).json({ error: 'Something went wrong' });
1105
+ }
1106
+ });
1107
+ ```
1108
+
1109
+ ### Health Checks
1110
+
1111
+ Register health checks for monitoring service dependencies:
1112
+
1113
+ ```ts
1114
+ // Simple health check
1115
+ server.registerHealthCheck('storage', () => {
1116
+ return fs.existsSync('./data');
1117
+ });
1118
+
1119
+ // Async health check
1120
+ server.registerHealthCheck('database', async () => {
1121
+ try {
1122
+ await db.ping();
1123
+ return true;
1124
+ } catch (err) {
1125
+ return false;
1126
+ }
1127
+ });
1128
+ ```
1129
+
1130
+ ### Graceful Shutdown
1131
+
1132
+ Enable zero-downtime deployments with graceful shutdown:
1133
+
1134
+ ```ts
1135
+ // Enable graceful shutdown handling
1136
+ server.enableGracefulShutdown();
1137
+
1138
+ // Manually trigger a graceful shutdown
1139
+ async function shutdown() {
1140
+ console.log('Starting graceful shutdown...');
1141
+ await server.stop();
1142
+ console.log('Server stopped gracefully');
1143
+ process.exit(0);
1144
+ }
1145
+ ```
1146
+
929
1147
  ## 🏁 Usage
930
1148
 
931
1149
  Import only what you need:
@@ -1,4 +1,16 @@
1
- type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
1
+ import { LoggerLevels } from './utils/logger.utils';
2
+ /**
3
+ * Extends Express Request interface to add request ID tracking.
4
+ * Added by requestId middleware during request processing.
5
+ */
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ /** Unique request identifier (set by middleware) */
10
+ id?: string;
11
+ }
12
+ }
13
+ }
2
14
  /**
3
15
  * Application runtime configuration loaded from environment variables.
4
16
  */
@@ -7,7 +19,7 @@ export declare let config: {
7
19
  /**
8
20
  * Logging level (e.g., 'info', 'debug', 'warn', 'error').
9
21
  */
10
- level: LogLevel;
22
+ level: LoggerLevels;
11
23
  /**
12
24
  * Name of the logger instance (defaults to npm package name).
13
25
  */
@@ -17,6 +29,10 @@ export declare let config: {
17
29
  * Has no effect in production.
18
30
  */
19
31
  pretty: boolean;
32
+ /**
33
+ * Single line output for pretty-print (default: false)
34
+ */
35
+ singleLine: boolean;
20
36
  };
21
37
  http: {
22
38
  /**
@@ -31,6 +47,76 @@ export declare let config: {
31
47
  defaultTtl: number;
32
48
  };
33
49
  };
50
+ export declare const defaultServerConfig: {
51
+ port: number;
52
+ host: string;
53
+ cors: false;
54
+ helmet: false;
55
+ compression: false;
56
+ bodyParser: {
57
+ json: {
58
+ limit: string;
59
+ };
60
+ urlencoded: {
61
+ extended: true;
62
+ limit: string;
63
+ };
64
+ };
65
+ cookieParser: false;
66
+ isMicroservice: false;
67
+ appName: string;
68
+ globalHeaders: {};
69
+ rateLimit: {
70
+ enable: false;
71
+ windowMs: number;
72
+ max: number;
73
+ message: string;
74
+ standardHeaders: true;
75
+ legacyHeaders: false;
76
+ };
77
+ requestLogging: {
78
+ enable: boolean;
79
+ ignorePaths: (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, _res: import("express").Response<any, Record<string, any>>) => boolean;
80
+ skipNotFoundRoutes: false;
81
+ };
82
+ openApi: {
83
+ enable: false;
84
+ mountPath: string;
85
+ verbose: false;
86
+ withGlobalPrefix: false;
87
+ };
88
+ healthCheck: {
89
+ path: string;
90
+ detailed: true;
91
+ };
92
+ requestTimeout: number;
93
+ responseTime: {
94
+ enable: false;
95
+ addHeader: true;
96
+ logOnComplete: false;
97
+ };
98
+ requestId: {
99
+ headerName: string;
100
+ exposeHeader: true;
101
+ generator: () => string;
102
+ };
103
+ logger: {
104
+ name: string;
105
+ level: LoggerLevels;
106
+ prettyPrint: false;
107
+ singleLine: false;
108
+ };
109
+ metrics: {
110
+ enable: false;
111
+ path: string;
112
+ withGlobalPrefix: false;
113
+ };
114
+ serviceVersion: {
115
+ enable: false;
116
+ headerName: string;
117
+ version: string;
118
+ };
119
+ };
34
120
  /**
35
121
  * Update the @catbee/utils configuration.
36
122
  * @param value Partial configuration object.
@@ -41,5 +127,4 @@ export declare function setConfig(value: Partial<typeof config>): void;
41
127
  * @returns The current configuration object.
42
128
  */
43
129
  export declare function getConfig(): typeof config;
44
- export {};
45
130
  //# sourceMappingURL=config.d.ts.map