@catbee/utils 2.0.0-next.0 → 2.0.0-next.1

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 (97) hide show
  1. package/README.md +52 -16
  2. package/array/index.cjs +180 -71
  3. package/array/index.d.ts +293 -1
  4. package/array/index.mjs +171 -72
  5. package/async/index.cjs +92 -36
  6. package/async/index.d.ts +275 -1
  7. package/async/index.mjs +92 -36
  8. package/cache/index.cjs +1 -1
  9. package/cache/index.d.ts +155 -1
  10. package/cache/index.mjs +2 -2
  11. package/config/index.cjs +78 -64
  12. package/config/index.d.ts +64 -2
  13. package/config/index.mjs +76 -64
  14. package/context-store/index.d.ts +192 -1
  15. package/crypto/index.d.ts +163 -1
  16. package/date/index.cjs +46 -1
  17. package/date/index.d.ts +190 -1
  18. package/date/index.mjs +45 -2
  19. package/decorators/index.cjs +1156 -18
  20. package/decorators/index.d.ts +684 -1
  21. package/decorators/index.mjs +1156 -18
  22. package/dir/index.cjs +4 -3
  23. package/dir/index.d.ts +195 -1
  24. package/dir/index.mjs +4 -3
  25. package/env/index.cjs +10 -26
  26. package/env/index.d.ts +379 -1
  27. package/env/index.mjs +10 -26
  28. package/exception/index.d.ts +232 -1
  29. package/fs/index.cjs +70 -36
  30. package/fs/index.d.ts +205 -1
  31. package/fs/index.mjs +64 -34
  32. package/http-status-codes/index.d.ts +267 -1
  33. package/id/index.d.ts +37 -1
  34. package/index.cjs +3 -3
  35. package/index.d.ts +1 -1
  36. package/index.mjs +1 -1
  37. package/logger/index.cjs +11 -11
  38. package/logger/index.d.ts +189 -1
  39. package/logger/index.mjs +12 -12
  40. package/middleware/index.d.ts +103 -1
  41. package/obj/index.cjs +150 -162
  42. package/obj/index.d.ts +136 -1
  43. package/obj/index.mjs +150 -162
  44. package/package.json +11 -11
  45. package/performance/index.cjs +2 -2
  46. package/performance/index.d.ts +138 -1
  47. package/performance/index.mjs +2 -2
  48. package/request/index.cjs +1 -1
  49. package/request/index.d.ts +241 -2
  50. package/request/index.mjs +1 -1
  51. package/response/index.d.ts +318 -2
  52. package/server/index.cjs +27 -23
  53. package/server/index.d.ts +785 -4
  54. package/server/index.mjs +28 -23
  55. package/stream/index.d.ts +90 -1
  56. package/string/index.d.ts +102 -1
  57. package/type/index.cjs +1 -1
  58. package/type/index.d.ts +107 -1
  59. package/type/index.mjs +1 -1
  60. package/types/index.d.ts +774 -4
  61. package/url/index.cjs +2 -4
  62. package/url/index.d.ts +142 -1
  63. package/url/index.mjs +2 -4
  64. package/{validate → validation}/index.cjs +89 -42
  65. package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
  66. package/{validate → validation}/index.mjs +85 -42
  67. package/array/array.utils.d.ts +0 -191
  68. package/async/async.utils.d.ts +0 -296
  69. package/cache/cache.utils.d.ts +0 -176
  70. package/config/config.d.ts +0 -57
  71. package/context-store/context-store.utils.d.ts +0 -212
  72. package/crypto/crypto.utils.d.ts +0 -183
  73. package/date/date.utils.d.ts +0 -190
  74. package/decorators/decorators.utils.d.ts +0 -705
  75. package/dir/dir.utils.d.ts +0 -216
  76. package/env/env.utils.d.ts +0 -400
  77. package/exception/exception.utils.d.ts +0 -253
  78. package/fs/fs.utils.d.ts +0 -196
  79. package/http-status-codes/http-status-codes.d.ts +0 -289
  80. package/id/id.utils.d.ts +0 -59
  81. package/logger/logger.utils.d.ts +0 -210
  82. package/middleware/middleware.utils.d.ts +0 -123
  83. package/obj/obj.utils.d.ts +0 -156
  84. package/performance/performance.utils.d.ts +0 -159
  85. package/request/request.utils.d.ts +0 -109
  86. package/response/response.utils.d.ts +0 -186
  87. package/server/server.builder.d.ts +0 -531
  88. package/server/server.d.ts +0 -303
  89. package/stream/stream.utils.d.ts +0 -111
  90. package/string/string.utils.d.ts +0 -124
  91. package/type/type.utils.d.ts +0 -129
  92. package/types/api-response.d.ts +0 -175
  93. package/types/common.d.ts +0 -148
  94. package/types/config.d.ts +0 -88
  95. package/types/server.d.ts +0 -291
  96. package/url/url.utils.d.ts +0 -164
  97. package/validate/index.d.ts +0 -25
@@ -1,289 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
-
25
- /**
26
- * Complete HTTP status codes enum with descriptions.
27
- * For use with API responses and error handling.
28
- */
29
- export declare enum HttpStatusCodes {
30
- /**
31
- * The server has received the request headers and the client should proceed to send the request body.
32
- */
33
- CONTINUE = 100,
34
- /**
35
- * The server is switching protocols according to the client's request.
36
- */
37
- SWITCHING_PROTOCOLS = 101,
38
- /**
39
- * Server has received the request and is still processing it.
40
- */
41
- PROCESSING = 102,
42
- /**
43
- * The server is sending preliminary headers while preparing the final response.
44
- */
45
- EARLY_HINTS = 103,
46
- /**
47
- * The request succeeded. The result meaning depends on the HTTP method used.
48
- */
49
- OK = 200,
50
- /**
51
- * The request succeeded and a new resource was created as a result.
52
- */
53
- CREATED = 201,
54
- /**
55
- * The request has been received but not yet acted upon.
56
- */
57
- ACCEPTED = 202,
58
- /**
59
- * The returned information is from a third-party source, not the origin server.
60
- */
61
- NON_AUTHORITATIVE_INFORMATION = 203,
62
- /**
63
- * The request succeeded but there's no content to send in the response.
64
- */
65
- NO_CONTENT = 204,
66
- /**
67
- * The client should reset the document view that caused this request.
68
- */
69
- RESET_CONTENT = 205,
70
- /**
71
- * The server is delivering only part of the resource due to a range header sent by the client.
72
- */
73
- PARTIAL_CONTENT = 206,
74
- /**
75
- * Conveys information about multiple resources, for complex operations.
76
- */
77
- MULTI_STATUS = 207,
78
- /**
79
- * The members of a DAV binding have already been enumerated and are not included in the response.
80
- */
81
- ALREADY_REPORTED = 208,
82
- /**
83
- * The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.
84
- */
85
- IM_USED = 226,
86
- /**
87
- * The request has more than one possible response and the client should choose one.
88
- */
89
- MULTIPLE_CHOICES = 300,
90
- /**
91
- * The resource has been permanently moved to a new URL.
92
- */
93
- MOVED_PERMANENTLY = 301,
94
- /**
95
- * The resource has been temporarily moved to another URL.
96
- */
97
- MOVED_TEMPORARILY = 302,
98
- /**
99
- * The response to the request can be found under another URI using the GET method.
100
- */
101
- SEE_OTHER = 303,
102
- /**
103
- * The resource hasn't been modified since the last request.
104
- */
105
- NOT_MODIFIED = 304,
106
- /**
107
- * @deprecated
108
- * Response must be accessed through a proxy.
109
- */
110
- USE_PROXY = 305,
111
- /**
112
- * The resource is temporarily available at a different URI, using the same HTTP method.
113
- */
114
- TEMPORARY_REDIRECT = 307,
115
- /**
116
- * The resource has been permanently moved to another URL, using the same HTTP method.
117
- */
118
- PERMANENT_REDIRECT = 308,
119
- /**
120
- * The server cannot process the request due to a client error (malformed request).
121
- */
122
- BAD_REQUEST = 400,
123
- /**
124
- * Authentication is required and has failed or not been provided.
125
- */
126
- UNAUTHORIZED = 401,
127
- /**
128
- * Reserved for future use, originally intended for digital payment systems.
129
- */
130
- PAYMENT_REQUIRED = 402,
131
- /**
132
- * The client doesn't have permission to access the requested resource.
133
- */
134
- FORBIDDEN = 403,
135
- /**
136
- * The requested resource could not be found on the server.
137
- */
138
- NOT_FOUND = 404,
139
- /**
140
- * The request method is not supported for the requested resource.
141
- */
142
- METHOD_NOT_ALLOWED = 405,
143
- /**
144
- * The server can't provide a response matching the list of acceptable values in the client's headers.
145
- */
146
- NOT_ACCEPTABLE = 406,
147
- /**
148
- * Authentication by a proxy is required.
149
- */
150
- PROXY_AUTHENTICATION_REQUIRED = 407,
151
- /**
152
- * The server timed out waiting for the request.
153
- */
154
- REQUEST_TIMEOUT = 408,
155
- /**
156
- * The request conflicts with the current state of the server.
157
- */
158
- CONFLICT = 409,
159
- /**
160
- * The resource has been permanently deleted with no forwarding address.
161
- */
162
- GONE = 410,
163
- /**
164
- * The server requires a Content-Length header field.
165
- */
166
- LENGTH_REQUIRED = 411,
167
- /**
168
- * Preconditions in the client's headers failed.
169
- */
170
- PRECONDITION_FAILED = 412,
171
- /**
172
- * Request entity is larger than limits defined by server.
173
- */
174
- REQUEST_TOO_LONG = 413,
175
- /**
176
- * The request payload exceeds server size limits.
177
- * Modern equivalent of REQUEST_TOO_LONG.
178
- */
179
- PAYLOAD_TOO_LARGE = 413,
180
- /**
181
- * The URI requested is too long for the server to interpret.
182
- */
183
- REQUEST_URI_TOO_LONG = 414,
184
- /**
185
- * The server does not support the media type requested by the client.
186
- */
187
- UNSUPPORTED_MEDIA_TYPE = 415,
188
- /**
189
- * The range specified by the Range header cannot be fulfilled.
190
- */
191
- REQUESTED_RANGE_NOT_SATISFIABLE = 416,
192
- /**
193
- * The server cannot meet the expectations given in the Expect header.
194
- */
195
- EXPECTATION_FAILED = 417,
196
- /**
197
- * The server refuses to brew coffee because it is a teapot. (April Fools' joke)
198
- */
199
- IM_A_TEAPOT = 418,
200
- /**
201
- * The server cannot store the representation needed to complete the request.
202
- */
203
- INSUFFICIENT_SPACE_ON_RESOURCE = 419,
204
- /**
205
- * @deprecated
206
- * A method has failed - specific to Spring Framework.
207
- */
208
- METHOD_FAILURE = 420,
209
- /**
210
- * The server cannot produce a response for the requested URI scheme and authority.
211
- */
212
- MISDIRECTED_REQUEST = 421,
213
- /**
214
- * The request was well-formed but has semantic errors preventing processing.
215
- */
216
- UNPROCESSABLE_ENTITY = 422,
217
- /**
218
- * The requested resource is locked against access.
219
- */
220
- LOCKED = 423,
221
- /**
222
- * The request failed due to the failure of a previous request.
223
- */
224
- FAILED_DEPENDENCY = 424,
225
- /**
226
- * The client should switch to a different protocol.
227
- */
228
- UPGRADE_REQUIRED = 426,
229
- /**
230
- * The server requires conditional requests to prevent lost updates.
231
- */
232
- PRECONDITION_REQUIRED = 428,
233
- /**
234
- * The client has sent too many requests in a given time period (rate limiting).
235
- */
236
- TOO_MANY_REQUESTS = 429,
237
- /**
238
- * Request headers are too large for the server to process.
239
- */
240
- REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
241
- /**
242
- * Resource cannot be legally provided (e.g., censored by government).
243
- */
244
- UNAVAILABLE_FOR_LEGAL_REASONS = 451,
245
- /**
246
- * The server encountered an unexpected error preventing it from fulfilling the request.
247
- */
248
- INTERNAL_SERVER_ERROR = 500,
249
- /**
250
- * The server does not support the functionality required to fulfill the request.
251
- */
252
- NOT_IMPLEMENTED = 501,
253
- /**
254
- * The server, acting as a gateway, received an invalid response from an upstream server.
255
- */
256
- BAD_GATEWAY = 502,
257
- /**
258
- * The server is currently unable to handle the request due to temporary overload or maintenance.
259
- */
260
- SERVICE_UNAVAILABLE = 503,
261
- /**
262
- * The server, acting as a gateway, did not receive a timely response from an upstream server.
263
- */
264
- GATEWAY_TIMEOUT = 504,
265
- /**
266
- * The server does not support the HTTP protocol version used in the request.
267
- */
268
- HTTP_VERSION_NOT_SUPPORTED = 505,
269
- /**
270
- * Transparent content negotiation for the request resulted in circular reference.
271
- */
272
- VARIANT_ALSO_NEGOTIATES = 506,
273
- /**
274
- * The server cannot store the representation needed to complete the request.
275
- */
276
- INSUFFICIENT_STORAGE = 507,
277
- /**
278
- * The server detected an infinite loop while processing the request.
279
- */
280
- LOOP_DETECTED = 508,
281
- /**
282
- * Further extensions to the request are required for the server to fulfill it.
283
- */
284
- NOT_EXTENDED = 510,
285
- /**
286
- * The client needs to authenticate to gain network access.
287
- */
288
- NETWORK_AUTHENTICATION_REQUIRED = 511
289
- }
package/id/id.utils.d.ts DELETED
@@ -1,59 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
-
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 declare function uuid(): string;
31
- /**
32
- * Generates a nanoid-style random ID (URL-safe, customizable length).
33
- *
34
- * @param {number} length - Length of the ID (default: 21).
35
- * @returns {string} Nanoid-style random string.
36
- */
37
- export declare function nanoId(length?: number): string;
38
- /**
39
- * Generates a cryptographically strong random hex string.
40
- *
41
- * @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).
42
- * @returns {string} Random hex string.
43
- */
44
- export declare function randomHex(byteLength?: number): string;
45
- /**
46
- * Generates a random integer between min (inclusive) and max (inclusive).
47
- *
48
- * @param {number} min - Minimum value.
49
- * @param {number} max - Maximum value.
50
- * @returns {number} Random integer in range.
51
- */
52
- export declare function randomInt(min: number, max: number): number;
53
- /**
54
- * Generates a cryptographically strong random base64 string.
55
- *
56
- * @param {number} byteLength - Number of random bytes (default: 16).
57
- * @returns {string} Random base64 string (URL-safe, no padding).
58
- */
59
- export declare function randomBase64(byteLength?: number): string;
@@ -1,210 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
-
25
- import pino from 'pino';
26
- import type { Logger as PinoLogger } from 'pino';
27
- /**
28
- * Logger type for application-wide logging.
29
- */
30
- export type Logger = PinoLogger;
31
- /**
32
- * Logger levels for application-wide logging.
33
- */
34
- export type LoggerLevels = pino.Level;
35
- export declare const defaultSensitiveFields: string[];
36
- /**
37
- * Sets the global redaction censor function used throughout the application for log redaction.
38
- *
39
- * Use this function to customize how sensitive data is redacted in logs. The provided function
40
- * will replace the default censor implementation.
41
- *
42
- * @example
43
- * ```typescript
44
- * // Custom censor that redacts only specific values
45
- * setRedactCensor((value, path, sensitiveFields) => {
46
- * if (path.includes('password')) return '***';
47
- * return value;
48
- * });
49
- * ```
50
- *
51
- * @param fn - The redaction censor function to use globally. This function receives:
52
- * - value: The data value to potentially redact
53
- * - path: Array of strings representing the path to the value in the object
54
- * - sensitiveFields: Optional array of field names to consider sensitive
55
- * @returns void
56
- */
57
- export declare function setRedactCensor(fn: (value: unknown, path: string[], sensitiveFields?: string[]) => string): void;
58
- /**
59
- * Gets the current global redaction censor function used for log redaction.
60
- *
61
- * This function is called internally by the logger when determining how to redact
62
- * sensitive information. It can also be used to access the current censor implementation
63
- * for composition or extension.
64
- *
65
- * @example
66
- * ```typescript
67
- * const currentCensor = getRedactCensor();
68
- * // Create an enhanced censor that extends the current one
69
- * setRedactCensor((value, path, fields) => {
70
- * // Add custom logic before delegating to current censor
71
- * if (someCondition) return customHandling();
72
- * return currentCensor(value, path, fields);
73
- * });
74
- * ```
75
- *
76
- * @returns The current redaction censor function
77
- */
78
- export declare function getRedactCensor(): (value: unknown, path: string[], sensitiveFields?: string[]) => string;
79
- /**
80
- * Convenience function to redact sensitive data using the current global redact censor.
81
- *
82
- * This is a direct wrapper around the global censor function that simplifies usage
83
- * in application code without needing to access the censor function directly.
84
- *
85
- * @example
86
- * ```typescript
87
- * // Redact a potential sensitive value
88
- * const safeValue = redact(value, ['user', 'apiKey']);
89
- * ```
90
- *
91
- * @param value - The value to potentially redact
92
- * @param path - Array of strings representing the path to the value in the object
93
- * @param sensitiveFields - Optional array of field names to consider sensitive
94
- * @returns The redacted string value or "***" for redacted content
95
- */
96
- export declare function redact(value: unknown, path: string[], sensitiveFields?: string[]): string;
97
- /**
98
- * @deprecated Use addSensitiveFields instead.
99
- *
100
- * Extends the current redaction function with additional fields to redact.
101
- *
102
- * This function wraps the existing censor while adding more fields to be considered
103
- * sensitive without replacing the entire redaction logic.
104
- *
105
- * @example
106
- * ```typescript
107
- * // Add custom fields to be redacted in all future redaction operations
108
- * addRedactFields(['customerId', 'accountNumber']);
109
- * ```
110
- *
111
- * @param fields - Array of additional field names to redact
112
- */
113
- export declare function addRedactFields(fields: string[]): void;
114
- /**
115
- * Retrieves the expanded list of sensitive fields.
116
- *
117
- * This function expands the default sensitive fields into their various naming
118
- * conventions (e.g., camelCase, snake_case) and caches the result for efficiency.
119
- *
120
- * @returns Array of expanded sensitive field names
121
- */
122
- export declare function getExpandedSensitiveFields(): string[];
123
- /**
124
- * Replaces the default list of sensitive fields with a new list.
125
- *
126
- * This is useful when you want complete control over what fields are considered
127
- * sensitive by default, rather than using the library's built-in list.
128
- *
129
- * @example
130
- * ```typescript
131
- * // Replace default sensitive fields with a custom list
132
- * setSensitiveFields(['password', 'ssn', 'creditCard']);
133
- * ```
134
- *
135
- * @param fields - Array of field names to set as the new default sensitive fields
136
- */
137
- export declare function setSensitiveFields(fields: string[]): void;
138
- /**
139
- * Adds additional field names to the default sensitive fields list.
140
- *
141
- * This preserves the existing sensitive fields while adding new ones for
142
- * application-specific sensitive data.
143
- *
144
- * @example
145
- * ```typescript
146
- * // Add domain-specific sensitive fields to the default list
147
- * addSensitiveFields(['socialSecurityNumber', 'medicalRecordNumber']);
148
- * ```
149
- *
150
- * @param fields - Array of additional field names to add to the sensitive fields list
151
- */
152
- export declare function addSensitiveFields(fields: string[]): void;
153
- /**
154
- * Use an object compatible with either modern or legacy global scopes.
155
- */
156
- export declare const _globalThis: typeof globalThis;
157
- /**
158
- * Retrieves the current logger instance:
159
- * - Returns a request-scoped logger from AsyncLocalStorage if available
160
- * - Falls back to the global (singleton) logger
161
- * - Initializes the global logger if not created yet
162
- * - If newInstance is true, returns a fresh logger without any context
163
- *
164
- * @param {boolean} newInstance - If true, returns a fresh logger without any context
165
- * @returns {Logger} The logger instance (request-bound or global root logger or fresh instance)
166
- */
167
- export declare function getLogger(newInstance?: boolean): PinoLogger;
168
- /**
169
- * Creates a child logger with additional context.
170
- *
171
- * @param {Record<string, any>} bindings - Properties to attach to all log records
172
- * @param {Logger} [parentLogger] - Parent logger (defaults to current context logger or global)
173
- * @returns {Logger} Child logger with merged context
174
- */
175
- export declare function createChildLogger(bindings: Record<string, any>, parentLogger?: PinoLogger): PinoLogger;
176
- /**
177
- * Creates a request-scoped logger with request ID and stores it in context
178
- *
179
- * @param {string} requestId - Unique request identifier
180
- * @param {object} [additionalContext] - Additional context to include in logs
181
- * @returns {Logger} Request-scoped logger instance
182
- */
183
- export declare function createRequestLogger(requestId: string, additionalContext?: Record<string, any>): PinoLogger;
184
- /**
185
- * Utility to safely log errors with proper stack trace extraction
186
- *
187
- * @param {Error|unknown} error - Error object to log
188
- * @param {string} [message] - Optional message to include
189
- * @param {Record<string, any>} [context] - Additional context properties
190
- */
191
- export declare function logError(error: Error | unknown, message?: string, context?: Record<string, any>): void;
192
- /**
193
- * Expands multiple sensitive field names into their variants.
194
- * Useful to match fields like `api_key`, `apiKey`, `apikey`, `APIKEY`, etc.
195
- */
196
- export declare function expandSensitiveFields(fields: string[]): string[];
197
- /**
198
- * Generates multiple variants of a sensitive field name.
199
- * Useful to match fields like `api_key`, `apiKey`, `apikey`, `APIKEY`, etc.
200
- */
201
- export declare function expandSensitiveField(field: string): string[];
202
- /**
203
- * Generates wildcard paths up to the given depth.
204
- *
205
- * depth = 2 →
206
- * password
207
- * *.password
208
- * *.*.password
209
- */
210
- export declare function generateDeepPaths(field: string, depth: number): string[];
@@ -1,123 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
-
25
- import type { Request, Response, NextFunction } from 'express';
26
- export type Middleware = (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
27
- /**
28
- * Attaches a unique request ID to each request.
29
- * Useful for request tracing and correlation between logs.
30
- *
31
- * @param {object} [options] - Configuration options
32
- * @param {string} [options.headerName='X-Request-ID'] - Header name for request ID
33
- * @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response
34
- * @param {() => string} [options.generator] - Custom ID generator function
35
- * @returns {Middleware} Express-compatible middleware
36
- */
37
- export declare function requestId(options?: {
38
- headerName?: string;
39
- exposeHeader?: boolean;
40
- generator?: () => string;
41
- }): Middleware;
42
- /**
43
- * Measures request processing time and logs or adds it to response headers.
44
- *
45
- * @param {object} [options] - Configuration options
46
- * @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header
47
- * @param {boolean} [options.logOnComplete=false] - Whether to log timing info
48
- * @returns {Middleware} Express-compatible middleware
49
- */
50
- export declare function responseTime(options?: {
51
- addHeader?: boolean;
52
- logOnComplete?: boolean;
53
- }): (req: Request, res: Response, next: NextFunction) => void;
54
- /**
55
- * Request timeout middleware.
56
- * Aborts requests that take too long to process.
57
- *
58
- * @param {number} [timeoutMs=30000] - Timeout in milliseconds
59
- * @returns {Middleware} Express-compatible middleware
60
- */
61
- export declare function timeout(timeoutMs?: number): Middleware;
62
- /**
63
- * Creates an Express middleware that initializes a per-request context.
64
- *
65
- * @param {object} [options] - Optional configuration
66
- * @param {string} [options.headerName='x-request-id'] - Header to look for request ID
67
- * @param {boolean} [options.autoLog=true] - Whether to log automatically when context is initialized
68
- * @returns {(req: Request, res: Response, next: NextFunction) => void} Express middleware function
69
- */
70
- export declare function setupRequestContext(options?: {
71
- headerName?: string;
72
- autoLog?: boolean;
73
- }): Middleware;
74
- export interface ErrorHandlerOptions {
75
- /** Whether to log errors (default: true) */
76
- logErrors?: boolean;
77
- /** Whether to include error details in non-production (default: false) */
78
- includeDetails?: boolean;
79
- }
80
- /**
81
- * Global error handling middleware with enhanced features.
82
- *
83
- * @param {ErrorHandlerOptions} options - Error handler options
84
- * @param {boolean} [options.logErrors=true] - Whether to log errors
85
- * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production
86
- * @returns Error middleware
87
- *
88
- * @example
89
- * import express from 'express';
90
- * import { errorHandler } from '@catbee/utils';
91
- *
92
- * const app = express();
93
- *
94
- * // Your routes
95
- * app.get('/ping', (req, res) => {
96
- * throw new Error('Something went wrong');
97
- * });
98
- *
99
- * // Error handler (must be last middleware)
100
- * app.use(errorHandler({ includeDetails: true }));
101
- *
102
- * app.listen(3000, () => {
103
- * console.log('Server running on port 3000');
104
- * });
105
- */
106
- export declare function errorHandler(options?: ErrorHandlerOptions): (err: any, req: Request, res: Response, _next: NextFunction) => Response<any, Record<string, any>>;
107
- /**
108
- * Health check middleware for service status and custom checks.
109
- *
110
- * @param {object} [options] - Health check options
111
- * @param {string} [options.path='/healthz'] - Health check endpoint path
112
- * @param {Array<{name: string; check: () => Promise<boolean> | boolean}>} [options.checks] - Custom health checks
113
- * @param {boolean} [options.detailed=true] - Show detailed check results
114
- * @returns {Middleware} Express-compatible middleware
115
- */
116
- export declare function healthCheck(options?: {
117
- path?: string;
118
- checks?: Array<{
119
- name: string;
120
- check: () => Promise<boolean> | boolean;
121
- }>;
122
- detailed?: boolean;
123
- }): Middleware;