@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{esnext → cjs}/config.d.ts +0 -1
- package/build/{src → cjs}/config.js +0 -1
- package/build/{esnext → cjs}/index.d.ts +0 -1
- package/build/{src → cjs}/index.js +0 -1
- package/build/{esnext → cjs}/servers/server.builder.d.ts +0 -1
- package/build/{src → cjs}/servers/server.builder.js +10 -13
- package/build/{src → cjs}/servers/server.d.ts +0 -1
- package/build/{src → cjs}/servers/server.js +83 -75
- package/build/{src → cjs}/types/api-response.d.ts +0 -1
- package/build/{src → cjs}/types/api-response.js +0 -1
- package/build/{src → cjs}/types/index.d.ts +0 -1
- package/build/{src → cjs}/types/index.js +0 -1
- package/build/{src → cjs}/types/server.d.ts +0 -1
- package/build/{src → cjs}/types/server.js +0 -1
- package/build/{src → cjs}/utils/array.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/array.utils.js +0 -1
- package/build/{src → cjs}/utils/async.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/async.utils.js +2 -3
- package/build/{esnext → cjs}/utils/cache.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/cache.utils.js +7 -6
- package/build/{esnext → cjs}/utils/context-store.utils.d.ts +1 -2
- package/build/{src → cjs}/utils/context-store.utils.js +10 -9
- package/build/{esnext → cjs}/utils/crypto.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/crypto.utils.js +5 -3
- package/build/{src → cjs}/utils/date.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/date.utils.js +1 -2
- package/build/{src → cjs}/utils/decorators.utils.d.ts +30 -27
- package/build/{src → cjs}/utils/decorators.utils.js +169 -30
- package/build/{esnext → cjs}/utils/dir.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/dir.utils.js +6 -7
- package/build/{esnext → cjs}/utils/env.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/env.utils.js +5 -8
- package/build/{src → cjs}/utils/exception.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/exception.utils.js +2 -1
- package/build/{src → cjs}/utils/fs.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/fs.utils.js +12 -13
- package/build/{esnext → cjs}/utils/http-status-codes.d.ts +0 -1
- package/build/{src → cjs}/utils/http-status-codes.js +0 -1
- package/build/{esnext → cjs}/utils/id.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/id.utils.js +0 -1
- package/build/{src → cjs}/utils/logger.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/logger.utils.js +10 -6
- package/build/{esnext → cjs}/utils/middleware.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/middleware.utils.js +16 -17
- package/build/{esnext → cjs}/utils/obj.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/obj.utils.js +1 -2
- package/build/{src → cjs}/utils/performance.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/performance.utils.js +6 -4
- package/build/{esnext → cjs}/utils/request.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/request.utils.js +7 -3
- package/build/{esnext → cjs}/utils/response.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/response.utils.js +42 -28
- package/build/{esnext → cjs}/utils/stream.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/stream.utils.js +0 -1
- package/build/{esnext → cjs}/utils/string.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/string.utils.js +0 -1
- package/build/{src → cjs}/utils/type.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/type.utils.js +2 -3
- package/build/{src → cjs}/utils/url.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/url.utils.js +8 -9
- package/build/{src → cjs}/utils/validate.utils.d.ts +0 -1
- package/build/{src → cjs}/utils/validate.utils.js +2 -3
- package/build/esm/config.d.ts +0 -1
- package/build/esm/config.js +6 -7
- package/build/esm/index.d.ts +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/servers/server.builder.d.ts +0 -1
- package/build/esm/servers/server.builder.js +99 -147
- package/build/esm/servers/server.d.ts +0 -1
- package/build/esm/servers/server.js +591 -876
- package/build/esm/types/api-response.d.ts +0 -1
- package/build/esm/types/api-response.js +0 -1
- package/build/esm/types/index.d.ts +0 -1
- package/build/esm/types/index.js +0 -1
- package/build/esm/types/server.d.ts +0 -1
- package/build/esm/types/server.js +0 -1
- package/build/esm/utils/array.utils.d.ts +0 -1
- package/build/esm/utils/array.utils.js +48 -86
- package/build/esm/utils/async.utils.d.ts +0 -1
- package/build/esm/utils/async.utils.js +247 -524
- package/build/esm/utils/cache.utils.d.ts +0 -1
- package/build/esm/utils/cache.utils.js +96 -301
- package/build/esm/utils/context-store.utils.d.ts +1 -2
- package/build/esm/utils/context-store.utils.js +62 -79
- package/build/esm/utils/crypto.utils.d.ts +0 -1
- package/build/esm/utils/crypto.utils.js +78 -175
- package/build/esm/utils/date.utils.d.ts +0 -1
- package/build/esm/utils/date.utils.js +47 -53
- package/build/esm/utils/decorators.utils.d.ts +30 -27
- package/build/esm/utils/decorators.utils.js +417 -461
- package/build/esm/utils/dir.utils.d.ts +0 -1
- package/build/esm/utils/dir.utils.js +264 -786
- package/build/esm/utils/env.utils.d.ts +0 -1
- package/build/esm/utils/env.utils.js +180 -271
- package/build/esm/utils/exception.utils.d.ts +0 -1
- package/build/esm/utils/exception.utils.js +112 -289
- package/build/esm/utils/fs.utils.d.ts +0 -1
- package/build/esm/utils/fs.utils.js +169 -401
- package/build/esm/utils/http-status-codes.d.ts +0 -1
- package/build/esm/utils/http-status-codes.js +0 -1
- package/build/esm/utils/id.utils.d.ts +0 -1
- package/build/esm/utils/id.utils.js +5 -9
- package/build/esm/utils/logger.utils.d.ts +0 -1
- package/build/esm/utils/logger.utils.js +34 -71
- package/build/esm/utils/middleware.utils.d.ts +0 -1
- package/build/esm/utils/middleware.utils.js +65 -155
- package/build/esm/utils/obj.utils.d.ts +0 -1
- package/build/esm/utils/obj.utils.js +69 -176
- package/build/esm/utils/performance.utils.d.ts +0 -1
- package/build/esm/utils/performance.utils.js +92 -195
- package/build/esm/utils/request.utils.d.ts +0 -1
- package/build/esm/utils/request.utils.js +41 -74
- package/build/esm/utils/response.utils.d.ts +0 -1
- package/build/esm/utils/response.utils.js +84 -107
- package/build/esm/utils/stream.utils.d.ts +0 -1
- package/build/esm/utils/stream.utils.js +38 -113
- package/build/esm/utils/string.utils.d.ts +0 -1
- package/build/esm/utils/string.utils.js +6 -11
- package/build/esm/utils/type.utils.d.ts +0 -1
- package/build/esm/utils/type.utils.js +8 -12
- package/build/esm/utils/url.utils.d.ts +0 -1
- package/build/esm/utils/url.utils.js +49 -127
- package/build/esm/utils/validate.utils.d.ts +0 -1
- package/build/esm/utils/validate.utils.js +23 -40
- package/package.json +288 -63
- package/build/esm/config.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/servers/server.builder.js.map +0 -1
- package/build/esm/servers/server.js.map +0 -1
- package/build/esm/types/api-response.js.map +0 -1
- package/build/esm/types/index.js.map +0 -1
- package/build/esm/types/server.js.map +0 -1
- package/build/esm/utils/array.utils.js.map +0 -1
- package/build/esm/utils/async.utils.js.map +0 -1
- package/build/esm/utils/cache.utils.js.map +0 -1
- package/build/esm/utils/context-store.utils.js.map +0 -1
- package/build/esm/utils/crypto.utils.js.map +0 -1
- package/build/esm/utils/date.utils.js.map +0 -1
- package/build/esm/utils/decorators.utils.js.map +0 -1
- package/build/esm/utils/dir.utils.js.map +0 -1
- package/build/esm/utils/env.utils.js.map +0 -1
- package/build/esm/utils/exception.utils.js.map +0 -1
- package/build/esm/utils/fs.utils.js.map +0 -1
- package/build/esm/utils/http-status-codes.js.map +0 -1
- package/build/esm/utils/id.utils.js.map +0 -1
- package/build/esm/utils/logger.utils.js.map +0 -1
- package/build/esm/utils/middleware.utils.js.map +0 -1
- package/build/esm/utils/obj.utils.js.map +0 -1
- package/build/esm/utils/performance.utils.js.map +0 -1
- package/build/esm/utils/request.utils.js.map +0 -1
- package/build/esm/utils/response.utils.js.map +0 -1
- package/build/esm/utils/stream.utils.js.map +0 -1
- package/build/esm/utils/string.utils.js.map +0 -1
- package/build/esm/utils/type.utils.js.map +0 -1
- package/build/esm/utils/url.utils.js.map +0 -1
- package/build/esm/utils/validate.utils.js.map +0 -1
- package/build/esnext/config.js +0 -133
- package/build/esnext/config.js.map +0 -1
- package/build/esnext/index.js +0 -50
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/servers/server.builder.js +0 -657
- package/build/esnext/servers/server.builder.js.map +0 -1
- package/build/esnext/servers/server.d.ts +0 -256
- package/build/esnext/servers/server.js +0 -955
- package/build/esnext/servers/server.js.map +0 -1
- package/build/esnext/types/api-response.d.ts +0 -152
- package/build/esnext/types/api-response.js +0 -34
- package/build/esnext/types/api-response.js.map +0 -1
- package/build/esnext/types/index.d.ts +0 -125
- package/build/esnext/types/index.js +0 -25
- package/build/esnext/types/index.js.map +0 -1
- package/build/esnext/types/server.d.ts +0 -268
- package/build/esnext/types/server.js +0 -25
- package/build/esnext/types/server.js.map +0 -1
- package/build/esnext/utils/array.utils.d.ts +0 -168
- package/build/esnext/utils/array.utils.js +0 -345
- package/build/esnext/utils/array.utils.js.map +0 -1
- package/build/esnext/utils/async.utils.d.ts +0 -265
- package/build/esnext/utils/async.utils.js +0 -620
- package/build/esnext/utils/async.utils.js.map +0 -1
- package/build/esnext/utils/cache.utils.js +0 -293
- package/build/esnext/utils/cache.utils.js.map +0 -1
- package/build/esnext/utils/context-store.utils.js +0 -289
- package/build/esnext/utils/context-store.utils.js.map +0 -1
- package/build/esnext/utils/crypto.utils.js +0 -276
- package/build/esnext/utils/crypto.utils.js.map +0 -1
- package/build/esnext/utils/date.utils.d.ts +0 -159
- package/build/esnext/utils/date.utils.js +0 -384
- package/build/esnext/utils/date.utils.js.map +0 -1
- package/build/esnext/utils/decorators.utils.d.ts +0 -508
- package/build/esnext/utils/decorators.utils.js +0 -877
- package/build/esnext/utils/decorators.utils.js.map +0 -1
- package/build/esnext/utils/dir.utils.js +0 -477
- package/build/esnext/utils/dir.utils.js.map +0 -1
- package/build/esnext/utils/env.utils.js +0 -785
- package/build/esnext/utils/env.utils.js.map +0 -1
- package/build/esnext/utils/exception.utils.d.ts +0 -230
- package/build/esnext/utils/exception.utils.js +0 -381
- package/build/esnext/utils/exception.utils.js.map +0 -1
- package/build/esnext/utils/fs.utils.d.ts +0 -164
- package/build/esnext/utils/fs.utils.js +0 -349
- package/build/esnext/utils/fs.utils.js.map +0 -1
- package/build/esnext/utils/http-status-codes.js +0 -295
- package/build/esnext/utils/http-status-codes.js.map +0 -1
- package/build/esnext/utils/id.utils.js +0 -84
- package/build/esnext/utils/id.utils.js.map +0 -1
- package/build/esnext/utils/logger.utils.d.ts +0 -160
- package/build/esnext/utils/logger.utils.js +0 -300
- package/build/esnext/utils/logger.utils.js.map +0 -1
- package/build/esnext/utils/middleware.utils.js +0 -236
- package/build/esnext/utils/middleware.utils.js.map +0 -1
- package/build/esnext/utils/obj.utils.js +0 -413
- package/build/esnext/utils/obj.utils.js.map +0 -1
- package/build/esnext/utils/performance.utils.d.ts +0 -136
- package/build/esnext/utils/performance.utils.js +0 -271
- package/build/esnext/utils/performance.utils.js.map +0 -1
- package/build/esnext/utils/request.utils.js +0 -186
- package/build/esnext/utils/request.utils.js.map +0 -1
- package/build/esnext/utils/response.utils.js +0 -247
- package/build/esnext/utils/response.utils.js.map +0 -1
- package/build/esnext/utils/stream.utils.js +0 -210
- package/build/esnext/utils/stream.utils.js.map +0 -1
- package/build/esnext/utils/string.utils.js +0 -165
- package/build/esnext/utils/string.utils.js.map +0 -1
- package/build/esnext/utils/type.utils.d.ts +0 -90
- package/build/esnext/utils/type.utils.js +0 -187
- package/build/esnext/utils/type.utils.js.map +0 -1
- package/build/esnext/utils/url.utils.d.ts +0 -141
- package/build/esnext/utils/url.utils.js +0 -304
- package/build/esnext/utils/url.utils.js.map +0 -1
- package/build/esnext/utils/validate.utils.d.ts +0 -177
- package/build/esnext/utils/validate.utils.js +0 -320
- package/build/esnext/utils/validate.utils.js.map +0 -1
- package/build/src/config.d.ts +0 -122
- package/build/src/config.js.map +0 -1
- package/build/src/index.d.ts +0 -27
- package/build/src/index.js.map +0 -1
- package/build/src/servers/server.builder.d.ts +0 -508
- package/build/src/servers/server.builder.js.map +0 -1
- package/build/src/servers/server.js.map +0 -1
- package/build/src/types/api-response.js.map +0 -1
- package/build/src/types/index.js.map +0 -1
- package/build/src/types/server.js.map +0 -1
- package/build/src/utils/array.utils.js.map +0 -1
- package/build/src/utils/async.utils.js.map +0 -1
- package/build/src/utils/cache.utils.d.ts +0 -153
- package/build/src/utils/cache.utils.js.map +0 -1
- package/build/src/utils/context-store.utils.d.ts +0 -189
- package/build/src/utils/context-store.utils.js.map +0 -1
- package/build/src/utils/crypto.utils.d.ts +0 -160
- package/build/src/utils/crypto.utils.js.map +0 -1
- package/build/src/utils/date.utils.js.map +0 -1
- package/build/src/utils/decorators.utils.js.map +0 -1
- package/build/src/utils/dir.utils.d.ts +0 -196
- package/build/src/utils/dir.utils.js.map +0 -1
- package/build/src/utils/env.utils.d.ts +0 -377
- package/build/src/utils/env.utils.js.map +0 -1
- package/build/src/utils/exception.utils.js.map +0 -1
- package/build/src/utils/fs.utils.js.map +0 -1
- package/build/src/utils/http-status-codes.d.ts +0 -266
- package/build/src/utils/http-status-codes.js.map +0 -1
- package/build/src/utils/id.utils.d.ts +0 -36
- package/build/src/utils/id.utils.js.map +0 -1
- package/build/src/utils/logger.utils.js.map +0 -1
- package/build/src/utils/middleware.utils.d.ts +0 -100
- package/build/src/utils/middleware.utils.js.map +0 -1
- package/build/src/utils/obj.utils.d.ts +0 -124
- package/build/src/utils/obj.utils.js.map +0 -1
- package/build/src/utils/performance.utils.js.map +0 -1
- package/build/src/utils/request.utils.d.ts +0 -86
- package/build/src/utils/request.utils.js.map +0 -1
- package/build/src/utils/response.utils.d.ts +0 -163
- package/build/src/utils/response.utils.js.map +0 -1
- package/build/src/utils/stream.utils.d.ts +0 -88
- package/build/src/utils/stream.utils.js.map +0 -1
- package/build/src/utils/string.utils.d.ts +0 -93
- package/build/src/utils/string.utils.js.map +0 -1
- package/build/src/utils/type.utils.js.map +0 -1
- package/build/src/utils/url.utils.js.map +0 -1
- package/build/src/utils/validate.utils.js.map +0 -1
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Complete HTTP status codes enum with descriptions.
|
|
3
|
-
* For use with API responses and error handling.
|
|
4
|
-
*/
|
|
5
|
-
export declare enum HttpStatusCodes {
|
|
6
|
-
/**
|
|
7
|
-
* The server has received the request headers and the client should proceed to send the request body.
|
|
8
|
-
*/
|
|
9
|
-
CONTINUE = 100,
|
|
10
|
-
/**
|
|
11
|
-
* The server is switching protocols according to the client's request.
|
|
12
|
-
*/
|
|
13
|
-
SWITCHING_PROTOCOLS = 101,
|
|
14
|
-
/**
|
|
15
|
-
* Server has received the request and is still processing it.
|
|
16
|
-
*/
|
|
17
|
-
PROCESSING = 102,
|
|
18
|
-
/**
|
|
19
|
-
* The server is sending preliminary headers while preparing the final response.
|
|
20
|
-
*/
|
|
21
|
-
EARLY_HINTS = 103,
|
|
22
|
-
/**
|
|
23
|
-
* The request succeeded. The result meaning depends on the HTTP method used.
|
|
24
|
-
*/
|
|
25
|
-
OK = 200,
|
|
26
|
-
/**
|
|
27
|
-
* The request succeeded and a new resource was created as a result.
|
|
28
|
-
*/
|
|
29
|
-
CREATED = 201,
|
|
30
|
-
/**
|
|
31
|
-
* The request has been received but not yet acted upon.
|
|
32
|
-
*/
|
|
33
|
-
ACCEPTED = 202,
|
|
34
|
-
/**
|
|
35
|
-
* The returned information is from a third-party source, not the origin server.
|
|
36
|
-
*/
|
|
37
|
-
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
38
|
-
/**
|
|
39
|
-
* The request succeeded but there's no content to send in the response.
|
|
40
|
-
*/
|
|
41
|
-
NO_CONTENT = 204,
|
|
42
|
-
/**
|
|
43
|
-
* The client should reset the document view that caused this request.
|
|
44
|
-
*/
|
|
45
|
-
RESET_CONTENT = 205,
|
|
46
|
-
/**
|
|
47
|
-
* The server is delivering only part of the resource due to a range header sent by the client.
|
|
48
|
-
*/
|
|
49
|
-
PARTIAL_CONTENT = 206,
|
|
50
|
-
/**
|
|
51
|
-
* Conveys information about multiple resources, for complex operations.
|
|
52
|
-
*/
|
|
53
|
-
MULTI_STATUS = 207,
|
|
54
|
-
/**
|
|
55
|
-
* The members of a DAV binding have already been enumerated and are not included in the response.
|
|
56
|
-
*/
|
|
57
|
-
ALREADY_REPORTED = 208,
|
|
58
|
-
/**
|
|
59
|
-
* The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.
|
|
60
|
-
*/
|
|
61
|
-
IM_USED = 226,
|
|
62
|
-
/**
|
|
63
|
-
* The request has more than one possible response and the client should choose one.
|
|
64
|
-
*/
|
|
65
|
-
MULTIPLE_CHOICES = 300,
|
|
66
|
-
/**
|
|
67
|
-
* The resource has been permanently moved to a new URL.
|
|
68
|
-
*/
|
|
69
|
-
MOVED_PERMANENTLY = 301,
|
|
70
|
-
/**
|
|
71
|
-
* The resource has been temporarily moved to another URL.
|
|
72
|
-
*/
|
|
73
|
-
MOVED_TEMPORARILY = 302,
|
|
74
|
-
/**
|
|
75
|
-
* The response to the request can be found under another URI using the GET method.
|
|
76
|
-
*/
|
|
77
|
-
SEE_OTHER = 303,
|
|
78
|
-
/**
|
|
79
|
-
* The resource hasn't been modified since the last request.
|
|
80
|
-
*/
|
|
81
|
-
NOT_MODIFIED = 304,
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated
|
|
84
|
-
* Response must be accessed through a proxy.
|
|
85
|
-
*/
|
|
86
|
-
USE_PROXY = 305,
|
|
87
|
-
/**
|
|
88
|
-
* The resource is temporarily available at a different URI, using the same HTTP method.
|
|
89
|
-
*/
|
|
90
|
-
TEMPORARY_REDIRECT = 307,
|
|
91
|
-
/**
|
|
92
|
-
* The resource has been permanently moved to another URL, using the same HTTP method.
|
|
93
|
-
*/
|
|
94
|
-
PERMANENT_REDIRECT = 308,
|
|
95
|
-
/**
|
|
96
|
-
* The server cannot process the request due to a client error (malformed request).
|
|
97
|
-
*/
|
|
98
|
-
BAD_REQUEST = 400,
|
|
99
|
-
/**
|
|
100
|
-
* Authentication is required and has failed or not been provided.
|
|
101
|
-
*/
|
|
102
|
-
UNAUTHORIZED = 401,
|
|
103
|
-
/**
|
|
104
|
-
* Reserved for future use, originally intended for digital payment systems.
|
|
105
|
-
*/
|
|
106
|
-
PAYMENT_REQUIRED = 402,
|
|
107
|
-
/**
|
|
108
|
-
* The client doesn't have permission to access the requested resource.
|
|
109
|
-
*/
|
|
110
|
-
FORBIDDEN = 403,
|
|
111
|
-
/**
|
|
112
|
-
* The requested resource could not be found on the server.
|
|
113
|
-
*/
|
|
114
|
-
NOT_FOUND = 404,
|
|
115
|
-
/**
|
|
116
|
-
* The request method is not supported for the requested resource.
|
|
117
|
-
*/
|
|
118
|
-
METHOD_NOT_ALLOWED = 405,
|
|
119
|
-
/**
|
|
120
|
-
* The server can't provide a response matching the list of acceptable values in the client's headers.
|
|
121
|
-
*/
|
|
122
|
-
NOT_ACCEPTABLE = 406,
|
|
123
|
-
/**
|
|
124
|
-
* Authentication by a proxy is required.
|
|
125
|
-
*/
|
|
126
|
-
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
127
|
-
/**
|
|
128
|
-
* The server timed out waiting for the request.
|
|
129
|
-
*/
|
|
130
|
-
REQUEST_TIMEOUT = 408,
|
|
131
|
-
/**
|
|
132
|
-
* The request conflicts with the current state of the server.
|
|
133
|
-
*/
|
|
134
|
-
CONFLICT = 409,
|
|
135
|
-
/**
|
|
136
|
-
* The resource has been permanently deleted with no forwarding address.
|
|
137
|
-
*/
|
|
138
|
-
GONE = 410,
|
|
139
|
-
/**
|
|
140
|
-
* The server requires a Content-Length header field.
|
|
141
|
-
*/
|
|
142
|
-
LENGTH_REQUIRED = 411,
|
|
143
|
-
/**
|
|
144
|
-
* Preconditions in the client's headers failed.
|
|
145
|
-
*/
|
|
146
|
-
PRECONDITION_FAILED = 412,
|
|
147
|
-
/**
|
|
148
|
-
* Request entity is larger than limits defined by server.
|
|
149
|
-
*/
|
|
150
|
-
REQUEST_TOO_LONG = 413,
|
|
151
|
-
/**
|
|
152
|
-
* The request payload exceeds server size limits.
|
|
153
|
-
* Modern equivalent of REQUEST_TOO_LONG.
|
|
154
|
-
*/
|
|
155
|
-
PAYLOAD_TOO_LARGE = 413,
|
|
156
|
-
/**
|
|
157
|
-
* The URI requested is too long for the server to interpret.
|
|
158
|
-
*/
|
|
159
|
-
REQUEST_URI_TOO_LONG = 414,
|
|
160
|
-
/**
|
|
161
|
-
* The server does not support the media type requested by the client.
|
|
162
|
-
*/
|
|
163
|
-
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
164
|
-
/**
|
|
165
|
-
* The range specified by the Range header cannot be fulfilled.
|
|
166
|
-
*/
|
|
167
|
-
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
168
|
-
/**
|
|
169
|
-
* The server cannot meet the expectations given in the Expect header.
|
|
170
|
-
*/
|
|
171
|
-
EXPECTATION_FAILED = 417,
|
|
172
|
-
/**
|
|
173
|
-
* The server refuses to brew coffee because it is a teapot. (April Fools' joke)
|
|
174
|
-
*/
|
|
175
|
-
IM_A_TEAPOT = 418,
|
|
176
|
-
/**
|
|
177
|
-
* The server cannot store the representation needed to complete the request.
|
|
178
|
-
*/
|
|
179
|
-
INSUFFICIENT_SPACE_ON_RESOURCE = 419,
|
|
180
|
-
/**
|
|
181
|
-
* @deprecated
|
|
182
|
-
* A method has failed - specific to Spring Framework.
|
|
183
|
-
*/
|
|
184
|
-
METHOD_FAILURE = 420,
|
|
185
|
-
/**
|
|
186
|
-
* The server cannot produce a response for the requested URI scheme and authority.
|
|
187
|
-
*/
|
|
188
|
-
MISDIRECTED_REQUEST = 421,
|
|
189
|
-
/**
|
|
190
|
-
* The request was well-formed but has semantic errors preventing processing.
|
|
191
|
-
*/
|
|
192
|
-
UNPROCESSABLE_ENTITY = 422,
|
|
193
|
-
/**
|
|
194
|
-
* The requested resource is locked against access.
|
|
195
|
-
*/
|
|
196
|
-
LOCKED = 423,
|
|
197
|
-
/**
|
|
198
|
-
* The request failed due to the failure of a previous request.
|
|
199
|
-
*/
|
|
200
|
-
FAILED_DEPENDENCY = 424,
|
|
201
|
-
/**
|
|
202
|
-
* The client should switch to a different protocol.
|
|
203
|
-
*/
|
|
204
|
-
UPGRADE_REQUIRED = 426,
|
|
205
|
-
/**
|
|
206
|
-
* The server requires conditional requests to prevent lost updates.
|
|
207
|
-
*/
|
|
208
|
-
PRECONDITION_REQUIRED = 428,
|
|
209
|
-
/**
|
|
210
|
-
* The client has sent too many requests in a given time period (rate limiting).
|
|
211
|
-
*/
|
|
212
|
-
TOO_MANY_REQUESTS = 429,
|
|
213
|
-
/**
|
|
214
|
-
* Request headers are too large for the server to process.
|
|
215
|
-
*/
|
|
216
|
-
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
217
|
-
/**
|
|
218
|
-
* Resource cannot be legally provided (e.g., censored by government).
|
|
219
|
-
*/
|
|
220
|
-
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
221
|
-
/**
|
|
222
|
-
* The server encountered an unexpected error preventing it from fulfilling the request.
|
|
223
|
-
*/
|
|
224
|
-
INTERNAL_SERVER_ERROR = 500,
|
|
225
|
-
/**
|
|
226
|
-
* The server does not support the functionality required to fulfill the request.
|
|
227
|
-
*/
|
|
228
|
-
NOT_IMPLEMENTED = 501,
|
|
229
|
-
/**
|
|
230
|
-
* The server, acting as a gateway, received an invalid response from an upstream server.
|
|
231
|
-
*/
|
|
232
|
-
BAD_GATEWAY = 502,
|
|
233
|
-
/**
|
|
234
|
-
* The server is currently unable to handle the request due to temporary overload or maintenance.
|
|
235
|
-
*/
|
|
236
|
-
SERVICE_UNAVAILABLE = 503,
|
|
237
|
-
/**
|
|
238
|
-
* The server, acting as a gateway, did not receive a timely response from an upstream server.
|
|
239
|
-
*/
|
|
240
|
-
GATEWAY_TIMEOUT = 504,
|
|
241
|
-
/**
|
|
242
|
-
* The server does not support the HTTP protocol version used in the request.
|
|
243
|
-
*/
|
|
244
|
-
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
245
|
-
/**
|
|
246
|
-
* Transparent content negotiation for the request resulted in circular reference.
|
|
247
|
-
*/
|
|
248
|
-
VARIANT_ALSO_NEGOTIATES = 506,
|
|
249
|
-
/**
|
|
250
|
-
* The server cannot store the representation needed to complete the request.
|
|
251
|
-
*/
|
|
252
|
-
INSUFFICIENT_STORAGE = 507,
|
|
253
|
-
/**
|
|
254
|
-
* The server detected an infinite loop while processing the request.
|
|
255
|
-
*/
|
|
256
|
-
LOOP_DETECTED = 508,
|
|
257
|
-
/**
|
|
258
|
-
* Further extensions to the request are required for the server to fulfill it.
|
|
259
|
-
*/
|
|
260
|
-
NOT_EXTENDED = 510,
|
|
261
|
-
/**
|
|
262
|
-
* The client needs to authenticate to gain network access.
|
|
263
|
-
*/
|
|
264
|
-
NETWORK_AUTHENTICATION_REQUIRED = 511
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=http-status-codes.d.ts.map
|
|
@@ -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,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;IACH,mDAAQ,CAAA;IAER;;OAEG;IACH,6DAAa,CAAA;IAEb;;OAEG;IACH,+DAAc,CAAA;IAEd;;OAEG;IACH,yGAAmC,CAAA;I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,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,+BAAf,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,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generates a UUID v4 string (RFC 4122).
|
|
3
|
-
*
|
|
4
|
-
* @returns {string} UUID v4 (e.g., 'c0de1234-5678-9abc-def0-123456789abc')
|
|
5
|
-
*/
|
|
6
|
-
export declare function uuid(): string;
|
|
7
|
-
/**
|
|
8
|
-
* Generates a nanoid-style random ID (URL-safe, customizable length).
|
|
9
|
-
*
|
|
10
|
-
* @param {number} length - Length of the ID (default: 21).
|
|
11
|
-
* @returns {string} Nanoid-style random string.
|
|
12
|
-
*/
|
|
13
|
-
export declare function nanoId(length?: number): string;
|
|
14
|
-
/**
|
|
15
|
-
* Generates a cryptographically strong random hex string.
|
|
16
|
-
*
|
|
17
|
-
* @param {number} byteLength - Number of random bytes (default: 16 → 32 hex chars).
|
|
18
|
-
* @returns {string} Random hex string.
|
|
19
|
-
*/
|
|
20
|
-
export declare function randomHex(byteLength?: number): string;
|
|
21
|
-
/**
|
|
22
|
-
* Generates a random integer between min (inclusive) and max (inclusive).
|
|
23
|
-
*
|
|
24
|
-
* @param {number} min - Minimum value.
|
|
25
|
-
* @param {number} max - Maximum value.
|
|
26
|
-
* @returns {number} Random integer in range.
|
|
27
|
-
*/
|
|
28
|
-
export declare function randomInt(min: number, max: number): number;
|
|
29
|
-
/**
|
|
30
|
-
* Generates a cryptographically strong random base64 string.
|
|
31
|
-
*
|
|
32
|
-
* @param {number} byteLength - Number of random bytes (default: 16).
|
|
33
|
-
* @returns {string} Random base64 string (URL-safe, no padding).
|
|
34
|
-
*/
|
|
35
|
-
export declare function randomBase64(byteLength?: number): string;
|
|
36
|
-
//# sourceMappingURL=id.utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id.utils.js","sourceRoot":"","sources":["../../../src/utils/id.utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AASH,oBAEC;AAQD,wBASC;AAQD,8BAOC;AASD,8BAGC;AAQD,oCAEC;AA/DD,mCAAiD;AAEjD;;;;GAIG;AACH,SAAgB,IAAI;IAClB,OAAO,IAAA,mBAAU,GAAE,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,MAAM,CAAC,SAAiB,EAAE;IACxC,IAAI,MAAM,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAC3B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC1B,EAAE,IAAI,IAAA,oBAAW,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;aAC3C,QAAQ,CAAC,WAAW,CAAC;aACrB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,aAAqB,EAAE;IAC/C,6DAA6D;IAC7D,kGAAkG;IAClG,OAAO,IAAA,oBAAW,EAAC,UAAU,CAAC;SAC3B,QAAQ,CAAC,KAAK,CAAC;SACf,QAAQ,CAAC,UAAU,GAAG,CAAC,EAAE,GAAG,CAAC;SAC7B,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,SAAS,CAAC,GAAW,EAAE,GAAW;IAChD,MAAM,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;IAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,aAAqB,EAAE;IAClD,OAAO,IAAA,oBAAW,EAAC,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.utils.js","sourceRoot":"","sources":["../../../src/utils/logger.utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+FH,0CAEC;AAsBD,0CAEC;AAmBD,wBAEC;AAgBD,0CAIC;AAgBD,gDAEC;AAgBD,gDAE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KAAK,CAAC,uEAAuE,CAAC,CAAC;IACxF,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,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"]}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Request, Response, NextFunction } from 'express';
|
|
2
|
-
export type Middleware = (req: Request, res: Response, next: NextFunction) => void | Promise<void>;
|
|
3
|
-
/**
|
|
4
|
-
* Attaches a unique request ID to each request.
|
|
5
|
-
* Useful for request tracing and correlation between logs.
|
|
6
|
-
*
|
|
7
|
-
* @param {object} [options] - Configuration options
|
|
8
|
-
* @param {string} [options.headerName='X-Request-ID'] - Header name for request ID
|
|
9
|
-
* @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response
|
|
10
|
-
* @param {() => string} [options.generator] - Custom ID generator function
|
|
11
|
-
* @returns {Middleware} Express-compatible middleware
|
|
12
|
-
*/
|
|
13
|
-
export declare function requestId(options?: {
|
|
14
|
-
headerName?: string;
|
|
15
|
-
exposeHeader?: boolean;
|
|
16
|
-
generator?: () => string;
|
|
17
|
-
}): Middleware;
|
|
18
|
-
/**
|
|
19
|
-
* Measures request processing time and logs or adds it to response headers.
|
|
20
|
-
*
|
|
21
|
-
* @param {object} [options] - Configuration options
|
|
22
|
-
* @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header
|
|
23
|
-
* @param {boolean} [options.logOnComplete=false] - Whether to log timing info
|
|
24
|
-
* @returns {Middleware} Express-compatible middleware
|
|
25
|
-
*/
|
|
26
|
-
export declare function responseTime(options?: {
|
|
27
|
-
addHeader?: boolean;
|
|
28
|
-
logOnComplete?: boolean;
|
|
29
|
-
}): (req: Request, res: Response, next: NextFunction) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Request timeout middleware.
|
|
32
|
-
* Aborts requests that take too long to process.
|
|
33
|
-
*
|
|
34
|
-
* @param {number} [timeoutMs=30000] - Timeout in milliseconds
|
|
35
|
-
* @returns {Middleware} Express-compatible middleware
|
|
36
|
-
*/
|
|
37
|
-
export declare function timeout(timeoutMs?: number): Middleware;
|
|
38
|
-
/**
|
|
39
|
-
* Creates an Express middleware that initializes a per-request context.
|
|
40
|
-
*
|
|
41
|
-
* @param {object} [options] - Optional configuration
|
|
42
|
-
* @param {string} [options.headerName='x-request-id'] - Header to look for request ID
|
|
43
|
-
* @param {boolean} [options.autoLog=true] - Whether to log automatically when context is initialized
|
|
44
|
-
* @returns {(req: Request, res: Response, next: NextFunction) => void} Express middleware function
|
|
45
|
-
*/
|
|
46
|
-
export declare function setupRequestContext(options?: {
|
|
47
|
-
headerName?: string;
|
|
48
|
-
autoLog?: boolean;
|
|
49
|
-
}): Middleware;
|
|
50
|
-
export interface ErrorHandlerOptions {
|
|
51
|
-
/** Whether to log errors (default: true) */
|
|
52
|
-
logErrors?: boolean;
|
|
53
|
-
/** Whether to include error details in non-production (default: false) */
|
|
54
|
-
includeDetails?: boolean;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Global error handling middleware with enhanced features.
|
|
58
|
-
*
|
|
59
|
-
* @param {ErrorHandlerOptions} options - Error handler options
|
|
60
|
-
* @param {boolean} [options.logErrors=true] - Whether to log errors
|
|
61
|
-
* @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production
|
|
62
|
-
* @returns Error middleware
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* import express from 'express';
|
|
66
|
-
* import { errorHandler } from '@catbee/utils';
|
|
67
|
-
*
|
|
68
|
-
* const app = express();
|
|
69
|
-
*
|
|
70
|
-
* // Your routes
|
|
71
|
-
* app.get('/ping', (req, res) => {
|
|
72
|
-
* throw new Error('Something went wrong');
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* // Error handler (must be last middleware)
|
|
76
|
-
* app.use(errorHandler({ includeDetails: true }));
|
|
77
|
-
*
|
|
78
|
-
* app.listen(3000, () => {
|
|
79
|
-
* console.log('Server running on port 3000');
|
|
80
|
-
* });
|
|
81
|
-
*/
|
|
82
|
-
export declare function errorHandler(options?: ErrorHandlerOptions): (err: any, req: Request, res: Response, _next: NextFunction) => Response<any, Record<string, any>>;
|
|
83
|
-
/**
|
|
84
|
-
* Health check middleware for service status and custom checks.
|
|
85
|
-
*
|
|
86
|
-
* @param {object} [options] - Health check options
|
|
87
|
-
* @param {string} [options.path='/healthz'] - Health check endpoint path
|
|
88
|
-
* @param {Array<{name: string; check: () => Promise<boolean> | boolean}>} [options.checks] - Custom health checks
|
|
89
|
-
* @param {boolean} [options.detailed=true] - Show detailed check results
|
|
90
|
-
* @returns {Middleware} Express-compatible middleware
|
|
91
|
-
*/
|
|
92
|
-
export declare function healthCheck(options?: {
|
|
93
|
-
path?: string;
|
|
94
|
-
checks?: Array<{
|
|
95
|
-
name: string;
|
|
96
|
-
check: () => Promise<boolean> | boolean;
|
|
97
|
-
}>;
|
|
98
|
-
detailed?: boolean;
|
|
99
|
-
}): Middleware;
|
|
100
|
-
//# sourceMappingURL=middleware.utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.utils.js","sourceRoot":"","sources":["../../../src/utils/middleware.utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AAuBH,8BAwBC;AAUD,oCA8BC;AASD,0BAeC;AAUD,kDA0BC;AAmCD,oCAmCC;AAWD,kCA6BC;AA/PD,yCAAkC;AAClC,2DAAsD;AACtD,qDAA2E;AAC3E,iDAA2C;AAE3C,+DAAgE;AAChE,uDAA4D;AAK5D;;;;;;;;;GASG;AACH,SAAgB,SAAS,CAAC,OAIzB;IACC,MAAM,UAAU,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,KAAI,cAAc,CAAC;IACzD,MAAM,YAAY,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,MAAK,KAAK,CAAC;IACrD,MAAM,UAAU,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,KAAI,eAAI,CAAC;IAE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AI,CAAC,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE;YACnG,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAChD,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,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 { uuid } from './id.utils';\nimport { HttpStatusCodes } from './http-status-codes';\nimport { createFinalErrorResponse, ErrorResponse } from './response.utils';\nimport { getLogger } from './logger.utils';\nimport type { Request, Response, NextFunction } from 'express';\nimport { ContextStore, StoreKeys } from './context-store.utils';\nimport { RequestTimeoutException } from './exception.utils';\nimport { ApiErrorResponse } from '../types/api-response';\n\nexport type Middleware = (req: Request, res: Response, next: NextFunction) => void | Promise<void>;\n\n/**\n * Attaches a unique request ID to each request.\n * Useful for request tracing and correlation between logs.\n *\n * @param {object} [options] - Configuration options\n * @param {string} [options.headerName='X-Request-ID'] - Header name for request ID\n * @param {boolean} [options.exposeHeader=true] - Whether to expose the header in response\n * @param {() => string} [options.generator] - Custom ID generator function\n * @returns {Middleware} Express-compatible middleware\n */\nexport function requestId(options?: {\n headerName?: string;\n exposeHeader?: boolean;\n generator?: () => string;\n}): Middleware {\n const headerName = options?.headerName || 'X-Request-ID';\n const exposeHeader = options?.exposeHeader !== false;\n const generateId = options?.generator || uuid;\n\n return (req, res, next) => {\n // Use existing request ID from header or generate a new one\n const existingId = req.headers[headerName.toLowerCase()];\n const id = (existingId as string) || generateId();\n\n // Attach ID to request object\n req.id = id;\n\n // Add ID to response headers\n if (exposeHeader) {\n res.setHeader(headerName, id);\n }\n\n next();\n };\n}\n\n/**\n * Measures request processing time and logs or adds it to response headers.\n *\n * @param {object} [options] - Configuration options\n * @param {boolean} [options.addHeader=true] - Whether to add X-Response-Time header\n * @param {boolean} [options.logOnComplete=false] - Whether to log timing info\n * @returns {Middleware} Express-compatible middleware\n */\nexport function responseTime(options?: { addHeader?: boolean; logOnComplete?: boolean }) {\n const addHeader = options?.addHeader !== false;\n const logOnComplete = options?.logOnComplete === true;\n\n return (req: Request, res: Response, next: NextFunction) => {\n const start = process.hrtime();\n\n // Function to calculate duration\n const getDuration = () => {\n const diff = process.hrtime(start);\n return (diff[0] * 1e3 + diff[1] * 1e-6).toFixed(2);\n };\n\n if (addHeader) {\n // Ensure header is set before response is sent\n const originalWriteHead = res.writeHead;\n res.writeHead = function (...args: any[]) {\n res.setHeader('X-Response-Time', `${getDuration()}ms`);\n return originalWriteHead.apply(this, args as any);\n };\n }\n\n if (logOnComplete) {\n res.on('finish', () => {\n getLogger().info(`${req.method} ${req.url} - ${getDuration()}ms`);\n });\n }\n\n next();\n };\n}\n\n/**\n * Request timeout middleware.\n * Aborts requests that take too long to process.\n *\n * @param {number} [timeoutMs=30000] - Timeout in milliseconds\n * @returns {Middleware} Express-compatible middleware\n */\nexport function timeout(timeoutMs: number = 30000): Middleware {\n return (_req, res, next) => {\n // Set timeout for the request\n const timer = setTimeout(() => {\n const response = new RequestTimeoutException('Request timed out');\n res.status(HttpStatusCodes.REQUEST_TIMEOUT).json(response);\n }, timeoutMs);\n\n // Clear timeout when response is sent\n res.on('finish', () => {\n clearTimeout(timer);\n });\n\n next();\n };\n}\n\n/**\n * Creates an Express middleware that initializes a per-request context.\n *\n * @param {object} [options] - Optional configuration\n * @param {string} [options.headerName='x-request-id'] - Header to look for request ID\n * @param {boolean} [options.autoLog=true] - Whether to log automatically when context is initialized\n * @returns {(req: Request, res: Response, next: NextFunction) => void} Express middleware function\n */\nexport function setupRequestContext(options: { headerName?: string; autoLog?: boolean } = {}): Middleware {\n const { headerName = 'x-request-id', autoLog = true } = options;\n return (req, _res, next) => {\n // Generate or use existing request ID\n const requestId = (req.headers[headerName] as string) || req?.['id'] || uuid();\n\n ContextStore.run({ [StoreKeys.REQUEST_ID]: requestId }, () => {\n // Create a child logger for this request\n const childLogger = getLogger().child({\n requestId,\n method: req.method,\n url: req.originalUrl || req.url\n });\n\n req.logger = childLogger;\n\n // Store logger in context\n ContextStore.set(StoreKeys.LOGGER, childLogger);\n\n if (autoLog) {\n req.logger.info('Request context initialized');\n }\n\n next();\n });\n };\n}\n\nexport interface ErrorHandlerOptions {\n /** Whether to log errors (default: true) */\n logErrors?: boolean;\n /** Whether to include error details in non-production (default: false) */\n includeDetails?: boolean;\n}\n\n/**\n * Global error handling middleware with enhanced features.\n *\n * @param {ErrorHandlerOptions} options - Error handler options\n * @param {boolean} [options.logErrors=true] - Whether to log errors\n * @param {boolean} [options.includeDetails=false] - Whether to include error details in non-production\n * @returns Error middleware\n *\n * @example\n * import express from 'express';\n * import { errorHandler } from '@catbee/utils';\n *\n * const app = express();\n *\n * // Your routes\n * app.get('/ping', (req, res) => {\n * throw new Error('Something went wrong');\n * });\n *\n * // Error handler (must be last middleware)\n * app.use(errorHandler({ includeDetails: true }));\n *\n * app.listen(3000, () => {\n * console.log('Server running on port 3000');\n * });\n */\nexport function errorHandler(options?: ErrorHandlerOptions) {\n const logErrors = options?.logErrors !== false;\n const includeDetails = options?.includeDetails === true;\n\n return (err: any, req: Request, res: Response, _next: NextFunction) => {\n // Determine status code\n const status = err?.status || err?.statusCode || HttpStatusCodes.INTERNAL_SERVER_ERROR;\n\n // Log error if enabled\n if (logErrors) {\n getLogger().error({ err }, `${err.message || 'Unknown error'}`);\n }\n\n // Handle ErrorResponse instances (our custom error class)\n if (err instanceof ErrorResponse) {\n const result: ApiErrorResponse = {\n error: true,\n message: err.message,\n timestamp: err.timestamp,\n requestId: err?.requestId || req?.id || uuid(),\n status,\n path: req.originalUrl || req.url\n };\n\n if (includeDetails && err?.stack) {\n result.stack = err.stack.split('\\n').map((line: string) => line.trim());\n }\n return res.status(status).json(result);\n }\n\n // Handle any other errors\n return res\n .status(status)\n .json(createFinalErrorResponse(req, status, err?.message || 'Internal Server Error', err, { includeDetails }));\n };\n}\n\n/**\n * Health check middleware for service status and custom checks.\n *\n * @param {object} [options] - Health check options\n * @param {string} [options.path='/healthz'] - Health check endpoint path\n * @param {Array<{name: string; check: () => Promise<boolean> | boolean}>} [options.checks] - Custom health checks\n * @param {boolean} [options.detailed=true] - Show detailed check results\n * @returns {Middleware} Express-compatible middleware\n */\nexport function healthCheck(options?: {\n path?: string;\n checks?: Array<{ name: string; check: () => Promise<boolean> | boolean }>;\n detailed?: boolean;\n}): Middleware {\n const path = options?.path || '/healthz';\n const checks = options?.checks || [];\n const detailed = options?.detailed !== false;\n\n return async (req, res, next) => {\n if (req.path !== path) return next();\n const results: Record<string, boolean> = {};\n let allHealthy = true;\n for (const check of checks) {\n try {\n const result = await Promise.resolve(check.check());\n results[check.name] = !!result;\n if (!result) allHealthy = false;\n } catch {\n results[check.name] = false;\n allHealthy = false;\n }\n }\n const status = allHealthy ? HttpStatusCodes.OK : HttpStatusCodes.SERVICE_UNAVAILABLE;\n const response = detailed\n ? { status: allHealthy ? 'ok' : 'unhealthy', checks: results, timestamp: new Date().toISOString() }\n : { status: allHealthy ? 'ok' : 'unhealthy' };\n res.status(status).json(response);\n };\n}\n"]}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks whether the object has no own enumerable properties.
|
|
3
|
-
*
|
|
4
|
-
* @param {Record<any, any>} obj - The object to check.
|
|
5
|
-
* @returns {boolean} True if the object is empty, false otherwise.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isObjEmpty(obj: Record<any, any>): boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Returns a new object with only the specified keys picked.
|
|
10
|
-
*
|
|
11
|
-
* @template T
|
|
12
|
-
* @template K
|
|
13
|
-
* @param {T} obj - The source object.
|
|
14
|
-
* @param {K[]} keys - Keys to pick from the object.
|
|
15
|
-
* @returns {Pick<T, K>} New object with picked keys.
|
|
16
|
-
*/
|
|
17
|
-
export declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
18
|
-
/**
|
|
19
|
-
* Returns a new object with the specified keys omitted.
|
|
20
|
-
*
|
|
21
|
-
* @template T
|
|
22
|
-
* @template K
|
|
23
|
-
* @param {T} obj - The source object.
|
|
24
|
-
* @param {K[]} keys - Keys to omit from the object.
|
|
25
|
-
* @returns {Omit<T, K>} New object without omitted keys.
|
|
26
|
-
*/
|
|
27
|
-
export declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
28
|
-
/**
|
|
29
|
-
* Deeply merges multiple objects into the target object (mutates and returns the target object, not pure).
|
|
30
|
-
*
|
|
31
|
-
* @template T
|
|
32
|
-
* @param {T} target - The object to merge into (will be mutated).
|
|
33
|
-
* @param {...any[]} sources - The objects to merge from.
|
|
34
|
-
* @returns {T} The merged object (same as target).
|
|
35
|
-
*/
|
|
36
|
-
export declare function deepObjMerge<T extends object>(target: T, ...sources: any[]): T;
|
|
37
|
-
/**
|
|
38
|
-
* Checks if a value is a plain object (i.e., not an array, null, or a built-in object).
|
|
39
|
-
*
|
|
40
|
-
* @param value - The value to check.
|
|
41
|
-
* @returns True if the value is a plain object, false otherwise.
|
|
42
|
-
*/
|
|
43
|
-
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
44
|
-
/**
|
|
45
|
-
* Flattens a nested object using dot notation for keys (e.g., `{a: {b: 1}}` → `{ "a.b": 1 }`).
|
|
46
|
-
*
|
|
47
|
-
* @template T
|
|
48
|
-
* @param {T} obj - The object to flatten.
|
|
49
|
-
* @param {string} [prefix=""] - Optional prefix for nested keys (used internally).
|
|
50
|
-
* @returns {Record<string, any>} A new object with flattened keys.
|
|
51
|
-
*/
|
|
52
|
-
export declare function flattenObject<T extends Record<string, any>>(obj: T, prefix?: string): Record<string, any>;
|
|
53
|
-
/**
|
|
54
|
-
* Safely gets the value of a deeply nested key in an object using dot/bracket notation path.
|
|
55
|
-
*
|
|
56
|
-
* @template T
|
|
57
|
-
* @param {T} obj - The object to extract from.
|
|
58
|
-
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
59
|
-
* @returns {any} The value at the given path, or undefined if not found.
|
|
60
|
-
*/
|
|
61
|
-
export declare function getValueByPath<T extends object>(obj: T, path: string): any;
|
|
62
|
-
/**
|
|
63
|
-
* Sets a value at a deeply nested key in an object using dot/bracket notation path.
|
|
64
|
-
* Creates intermediate objects and arrays as needed.
|
|
65
|
-
*
|
|
66
|
-
* @template T
|
|
67
|
-
* @param {T} obj - The object to modify.
|
|
68
|
-
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
69
|
-
* @param {any} value - The value to set at the path.
|
|
70
|
-
* @returns {T} The modified object.
|
|
71
|
-
*/
|
|
72
|
-
export declare function setValueByPath<T extends object>(obj: T, path: string, value: any): T;
|
|
73
|
-
/**
|
|
74
|
-
* Performs a deep equality check between two objects.
|
|
75
|
-
*
|
|
76
|
-
* @param {any} a - First value to compare.
|
|
77
|
-
* @param {any} b - Second value to compare.
|
|
78
|
-
* @returns {boolean} True if values are deeply equal.
|
|
79
|
-
*/
|
|
80
|
-
export declare function isEqual(a: any, b: any): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Filters object properties based on a predicate function.
|
|
83
|
-
*
|
|
84
|
-
* @template T
|
|
85
|
-
* @param {T} obj - The source object.
|
|
86
|
-
* @param {(value: any, key: string, obj: T) => boolean} predicate - Filter function.
|
|
87
|
-
* @returns {Partial<T>} New object with filtered properties.
|
|
88
|
-
*/
|
|
89
|
-
export declare function filterObject<T extends object>(obj: T, predicate: (value: any, key: string, obj: T) => boolean): Partial<T>;
|
|
90
|
-
/**
|
|
91
|
-
* Maps object values to new values using a mapping function.
|
|
92
|
-
*
|
|
93
|
-
* @template T
|
|
94
|
-
* @template U
|
|
95
|
-
* @param {T} obj - The source object.
|
|
96
|
-
* @param {(value: any, key: string, obj: T) => U} mapFn - Mapping function.
|
|
97
|
-
* @returns {Record<keyof T, U>} New object with mapped values.
|
|
98
|
-
*/
|
|
99
|
-
export declare function mapObject<T extends object, U>(obj: T, mapFn: (value: any, key: string, obj: T) => U): Record<keyof T, U>;
|
|
100
|
-
/**
|
|
101
|
-
* Recursively freezes an object and all its properties.
|
|
102
|
-
* Makes an object immutable.
|
|
103
|
-
*
|
|
104
|
-
* @template T
|
|
105
|
-
* @param {T} obj - The object to freeze.
|
|
106
|
-
* @returns {Readonly<T>} The frozen object.
|
|
107
|
-
*/
|
|
108
|
-
export declare function deepFreeze<T extends object>(obj: T): Readonly<T>;
|
|
109
|
-
/**
|
|
110
|
-
* Safely checks if a value is an object (not null, not array).
|
|
111
|
-
*
|
|
112
|
-
* @param {unknown} value - Value to check.
|
|
113
|
-
* @returns {boolean} True if value is a non-null, non-array object.
|
|
114
|
-
*/
|
|
115
|
-
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
116
|
-
/**
|
|
117
|
-
* Gets all paths in an object using dot notation.
|
|
118
|
-
*
|
|
119
|
-
* @param {Record<string, any>} obj - Object to analyze.
|
|
120
|
-
* @param {string} [parentPath=""] - Internal param for recursion.
|
|
121
|
-
* @returns {string[]} Array of all paths in dot notation.
|
|
122
|
-
*/
|
|
123
|
-
export declare function getAllPaths(obj: Record<string, any>, parentPath?: string): string[];
|
|
124
|
-
//# sourceMappingURL=obj.utils.d.ts.map
|