@catbee/utils 1.1.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.
- package/LICENSE +1 -1
- package/README.md +79 -43
- package/array/index.cjs +355 -0
- package/array/index.d.ts +317 -0
- package/array/index.mjs +327 -0
- package/async/index.cjs +484 -0
- package/async/index.d.ts +299 -0
- package/async/index.mjs +463 -0
- package/cache/index.cjs +292 -0
- package/cache/index.d.ts +179 -0
- package/cache/index.mjs +290 -0
- package/config/index.cjs +150 -0
- package/config/index.d.ts +88 -0
- package/config/index.mjs +143 -0
- package/context-store/index.cjs +267 -0
- package/context-store/index.d.ts +216 -0
- package/context-store/index.mjs +261 -0
- package/crypto/index.cjs +182 -0
- package/crypto/index.d.ts +187 -0
- package/crypto/index.mjs +166 -0
- package/date/index.cjs +340 -0
- package/date/index.d.ts +214 -0
- package/date/index.mjs +326 -0
- package/decorators/index.cjs +2051 -0
- package/decorators/index.d.ts +708 -0
- package/decorators/index.mjs +2010 -0
- package/dir/index.cjs +417 -0
- package/dir/index.d.ts +219 -0
- package/dir/index.mjs +390 -0
- package/env/index.cjs +745 -0
- package/env/index.d.ts +403 -0
- package/env/index.mjs +742 -0
- package/exception/index.cjs +362 -0
- package/exception/index.d.ts +256 -0
- package/exception/index.mjs +338 -0
- package/fs/index.cjs +287 -0
- package/fs/index.d.ts +229 -0
- package/fs/index.mjs +258 -0
- package/http-status-codes/index.cjs +96 -0
- package/http-status-codes/index.d.ts +291 -0
- package/http-status-codes/index.mjs +94 -0
- package/id/index.cjs +62 -0
- package/id/index.d.ts +61 -0
- package/id/index.mjs +56 -0
- package/index.cjs +218 -0
- package/index.d.ts +51 -0
- package/index.mjs +51 -0
- package/logger/index.cjs +334 -0
- package/logger/index.d.ts +213 -0
- package/logger/index.mjs +313 -0
- package/middleware/index.cjs +177 -0
- package/middleware/index.d.ts +127 -0
- package/middleware/index.mjs +170 -0
- package/obj/index.cjs +305 -0
- package/obj/index.d.ts +160 -0
- package/obj/index.mjs +289 -0
- package/package.json +172 -20
- package/performance/index.cjs +231 -0
- package/performance/index.d.ts +162 -0
- package/performance/index.mjs +225 -0
- package/request/index.cjs +202 -0
- package/request/index.d.ts +265 -0
- package/request/index.mjs +194 -0
- package/response/index.cjs +234 -0
- package/response/index.d.ts +342 -0
- package/response/index.mjs +222 -0
- package/server/index.cjs +1631 -0
- package/server/index.d.ts +809 -0
- package/server/index.mjs +1622 -0
- package/stream/index.cjs +151 -0
- package/stream/index.d.ts +114 -0
- package/stream/index.mjs +144 -0
- package/string/index.cjs +109 -0
- package/string/index.d.ts +126 -0
- package/string/index.mjs +95 -0
- package/type/index.cjs +129 -0
- package/type/index.d.ts +131 -0
- package/type/index.mjs +119 -0
- package/types/index.cjs +34 -0
- package/types/index.d.ts +798 -0
- package/types/index.mjs +32 -0
- package/url/index.cjs +199 -0
- package/url/index.d.ts +166 -0
- package/url/index.mjs +187 -0
- package/validation/index.cjs +259 -0
- package/validation/index.d.ts +209 -0
- package/validation/index.mjs +231 -0
- package/build/index.cjs +0 -7694
- package/build/index.d.ts +0 -5792
- package/build/index.mjs +0 -7386
package/index.cjs
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
var config = require("./config/index.cjs");
|
|
28
|
+
var server = require("./server/index.cjs");
|
|
29
|
+
var types = require("./types/index.cjs");
|
|
30
|
+
var array = require("./array/index.cjs");
|
|
31
|
+
var async = require("./async/index.cjs");
|
|
32
|
+
var cache = require("./cache/index.cjs");
|
|
33
|
+
var contextStore = require("./context-store/index.cjs");
|
|
34
|
+
var crypto = require("./crypto/index.cjs");
|
|
35
|
+
var date = require("./date/index.cjs");
|
|
36
|
+
var decorators = require("./decorators/index.cjs");
|
|
37
|
+
var dir = require("./dir/index.cjs");
|
|
38
|
+
var env = require("./env/index.cjs");
|
|
39
|
+
var exception = require("./exception/index.cjs");
|
|
40
|
+
var fs = require("./fs/index.cjs");
|
|
41
|
+
var httpStatusCodes = require("./http-status-codes/index.cjs");
|
|
42
|
+
var id = require("./id/index.cjs");
|
|
43
|
+
var logger = require("./logger/index.cjs");
|
|
44
|
+
var middleware = require("./middleware/index.cjs");
|
|
45
|
+
var obj = require("./obj/index.cjs");
|
|
46
|
+
var performance = require("./performance/index.cjs");
|
|
47
|
+
var request = require("./request/index.cjs");
|
|
48
|
+
var response = require("./response/index.cjs");
|
|
49
|
+
var stream = require("./stream/index.cjs");
|
|
50
|
+
var string = require("./string/index.cjs");
|
|
51
|
+
var type = require("./type/index.cjs");
|
|
52
|
+
var url = require("./url/index.cjs");
|
|
53
|
+
var validation = require("./validation/index.cjs");
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
Object.keys(config).forEach(function (k) {
|
|
58
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () { return config[k]; }
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
Object.keys(server).forEach(function (k) {
|
|
64
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return server[k]; }
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
Object.keys(types).forEach(function (k) {
|
|
70
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () { return types[k]; }
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
Object.keys(array).forEach(function (k) {
|
|
76
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return array[k]; }
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
Object.keys(async).forEach(function (k) {
|
|
82
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () { return async[k]; }
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
Object.keys(cache).forEach(function (k) {
|
|
88
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return cache[k]; }
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
Object.keys(contextStore).forEach(function (k) {
|
|
94
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function () { return contextStore[k]; }
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
Object.keys(crypto).forEach(function (k) {
|
|
100
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () { return crypto[k]; }
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
Object.keys(date).forEach(function (k) {
|
|
106
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function () { return date[k]; }
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
Object.keys(decorators).forEach(function (k) {
|
|
112
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function () { return decorators[k]; }
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
Object.keys(dir).forEach(function (k) {
|
|
118
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function () { return dir[k]; }
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
Object.keys(env).forEach(function (k) {
|
|
124
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function () { return env[k]; }
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
Object.keys(exception).forEach(function (k) {
|
|
130
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
131
|
+
enumerable: true,
|
|
132
|
+
get: function () { return exception[k]; }
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
Object.keys(fs).forEach(function (k) {
|
|
136
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
137
|
+
enumerable: true,
|
|
138
|
+
get: function () { return fs[k]; }
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
Object.keys(httpStatusCodes).forEach(function (k) {
|
|
142
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function () { return httpStatusCodes[k]; }
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
Object.keys(id).forEach(function (k) {
|
|
148
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
149
|
+
enumerable: true,
|
|
150
|
+
get: function () { return id[k]; }
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
Object.keys(logger).forEach(function (k) {
|
|
154
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
get: function () { return logger[k]; }
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
Object.keys(middleware).forEach(function (k) {
|
|
160
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: function () { return middleware[k]; }
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
Object.keys(obj).forEach(function (k) {
|
|
166
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
167
|
+
enumerable: true,
|
|
168
|
+
get: function () { return obj[k]; }
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
Object.keys(performance).forEach(function (k) {
|
|
172
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
173
|
+
enumerable: true,
|
|
174
|
+
get: function () { return performance[k]; }
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
Object.keys(request).forEach(function (k) {
|
|
178
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
179
|
+
enumerable: true,
|
|
180
|
+
get: function () { return request[k]; }
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
Object.keys(response).forEach(function (k) {
|
|
184
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
185
|
+
enumerable: true,
|
|
186
|
+
get: function () { return response[k]; }
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
Object.keys(stream).forEach(function (k) {
|
|
190
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
191
|
+
enumerable: true,
|
|
192
|
+
get: function () { return stream[k]; }
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
Object.keys(string).forEach(function (k) {
|
|
196
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
get: function () { return string[k]; }
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
Object.keys(type).forEach(function (k) {
|
|
202
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
get: function () { return type[k]; }
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
Object.keys(url).forEach(function (k) {
|
|
208
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function () { return url[k]; }
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
Object.keys(validation).forEach(function (k) {
|
|
214
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
215
|
+
enumerable: true,
|
|
216
|
+
get: function () { return validation[k]; }
|
|
217
|
+
});
|
|
218
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
export * from './config';
|
|
26
|
+
export * from './server';
|
|
27
|
+
export * from './types';
|
|
28
|
+
export * from './array';
|
|
29
|
+
export * from './async';
|
|
30
|
+
export * from './cache';
|
|
31
|
+
export * from './context-store';
|
|
32
|
+
export * from './crypto';
|
|
33
|
+
export * from './date';
|
|
34
|
+
export * from './decorators';
|
|
35
|
+
export * from './dir';
|
|
36
|
+
export * from './env';
|
|
37
|
+
export * from './exception';
|
|
38
|
+
export * from './fs';
|
|
39
|
+
export * from './http-status-codes';
|
|
40
|
+
export * from './id';
|
|
41
|
+
export * from './logger';
|
|
42
|
+
export * from './middleware';
|
|
43
|
+
export * from './obj';
|
|
44
|
+
export * from './performance';
|
|
45
|
+
export * from './request';
|
|
46
|
+
export * from './response';
|
|
47
|
+
export * from './stream';
|
|
48
|
+
export * from './string';
|
|
49
|
+
export * from './type';
|
|
50
|
+
export * from './url';
|
|
51
|
+
export * from './validation';
|
package/index.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
export * from "./config/index.mjs";
|
|
26
|
+
export * from "./server/index.mjs";
|
|
27
|
+
export * from "./types/index.mjs";
|
|
28
|
+
export * from "./array/index.mjs";
|
|
29
|
+
export * from "./async/index.mjs";
|
|
30
|
+
export * from "./cache/index.mjs";
|
|
31
|
+
export * from "./context-store/index.mjs";
|
|
32
|
+
export * from "./crypto/index.mjs";
|
|
33
|
+
export * from "./date/index.mjs";
|
|
34
|
+
export * from "./decorators/index.mjs";
|
|
35
|
+
export * from "./dir/index.mjs";
|
|
36
|
+
export * from "./env/index.mjs";
|
|
37
|
+
export * from "./exception/index.mjs";
|
|
38
|
+
export * from "./fs/index.mjs";
|
|
39
|
+
export * from "./http-status-codes/index.mjs";
|
|
40
|
+
export * from "./id/index.mjs";
|
|
41
|
+
export * from "./logger/index.mjs";
|
|
42
|
+
export * from "./middleware/index.mjs";
|
|
43
|
+
export * from "./obj/index.mjs";
|
|
44
|
+
export * from "./performance/index.mjs";
|
|
45
|
+
export * from "./request/index.mjs";
|
|
46
|
+
export * from "./response/index.mjs";
|
|
47
|
+
export * from "./stream/index.mjs";
|
|
48
|
+
export * from "./string/index.mjs";
|
|
49
|
+
export * from "./type/index.mjs";
|
|
50
|
+
export * from "./url/index.mjs";
|
|
51
|
+
export * from "./validation/index.mjs";
|
package/logger/index.cjs
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
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
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
var pino = require('pino');
|
|
28
|
+
var config = require('@catbee/utils/config');
|
|
29
|
+
var contextStore = require('@catbee/utils/context-store');
|
|
30
|
+
|
|
31
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
32
|
+
|
|
33
|
+
var pino__default = /*#__PURE__*/_interopDefault(pino);
|
|
34
|
+
|
|
35
|
+
var __defProp = Object.defineProperty;
|
|
36
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
37
|
+
var GLOBAL_LOGGER_KEY = Symbol.for("logger");
|
|
38
|
+
var defaultSensitiveFields = [
|
|
39
|
+
"password",
|
|
40
|
+
"secret",
|
|
41
|
+
"token",
|
|
42
|
+
"api_key",
|
|
43
|
+
"auth",
|
|
44
|
+
"private_key",
|
|
45
|
+
"public_key",
|
|
46
|
+
"jwt",
|
|
47
|
+
"access_token",
|
|
48
|
+
"refresh_token",
|
|
49
|
+
"session_token",
|
|
50
|
+
"csrf_token",
|
|
51
|
+
"authorization",
|
|
52
|
+
"bearer",
|
|
53
|
+
"x-api-key",
|
|
54
|
+
"x-auth-token",
|
|
55
|
+
"x-access-token",
|
|
56
|
+
"client_secret",
|
|
57
|
+
"passphrase",
|
|
58
|
+
"otp",
|
|
59
|
+
"api_secret",
|
|
60
|
+
"token_secret"
|
|
61
|
+
];
|
|
62
|
+
var defaultRedactPaths = [
|
|
63
|
+
"req.authorization",
|
|
64
|
+
"req.headers.authorization",
|
|
65
|
+
"req.headers.cookie",
|
|
66
|
+
'req.headers["x-api-key"]',
|
|
67
|
+
'req.headers["x-auth-token"]',
|
|
68
|
+
'req.headers["x-access-token"]',
|
|
69
|
+
"req.body.password",
|
|
70
|
+
"req.body.token",
|
|
71
|
+
"req.body.secret",
|
|
72
|
+
"req.query.token",
|
|
73
|
+
"req.query.api_key",
|
|
74
|
+
"req.query.apiKey",
|
|
75
|
+
"res.authorization",
|
|
76
|
+
"res.headers.authorization",
|
|
77
|
+
'res.headers["set-cookie"]',
|
|
78
|
+
"headers.authorization",
|
|
79
|
+
"headers.cookies",
|
|
80
|
+
'headers["set-cookie"]',
|
|
81
|
+
'headers["x-api-key"]',
|
|
82
|
+
'headers["x-auth-token"]',
|
|
83
|
+
'headers["x-access-token"]',
|
|
84
|
+
"url",
|
|
85
|
+
"uri",
|
|
86
|
+
"href",
|
|
87
|
+
"redirect_uri",
|
|
88
|
+
"redirectUri"
|
|
89
|
+
];
|
|
90
|
+
var globalRedactCensor = /* @__PURE__ */ __name((value, path, sensitiveFields = getExpandedSensitiveFields()) => {
|
|
91
|
+
if (typeof value !== "string") return "***";
|
|
92
|
+
const lowerPath = path.filter((p) => typeof p === "string").map((p) => p.toLowerCase());
|
|
93
|
+
const lowerSensitiveFields = sensitiveFields.map((f) => f.toLowerCase());
|
|
94
|
+
if (lowerPath.some((p) => lowerSensitiveFields.includes(p))) return "***";
|
|
95
|
+
if (lowerPath[0] === "url" || lowerPath[0] === "uri" || lowerPath[0] === "href" || lowerPath.includes("redirect_uri") || lowerPath.includes("redirecturi")) {
|
|
96
|
+
return value.replace(new RegExp(`([?&](${lowerSensitiveFields.join("|")})=)[^&#]*`, "gi"), "$1***");
|
|
97
|
+
}
|
|
98
|
+
if (lowerPath.some((p) => p.includes("authorization") || p.includes("auth"))) {
|
|
99
|
+
return value.replace(/^(\S+)\s+.+$/, "$1 ***") || "***";
|
|
100
|
+
}
|
|
101
|
+
if (lowerPath.some((p) => lowerSensitiveFields.some((f) => p.includes(f)))) {
|
|
102
|
+
return "***";
|
|
103
|
+
}
|
|
104
|
+
if (path.length > 0 && ![
|
|
105
|
+
"req",
|
|
106
|
+
"res",
|
|
107
|
+
"headers"
|
|
108
|
+
].includes(lowerPath[0])) {
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
return value;
|
|
112
|
+
}, "globalRedactCensor");
|
|
113
|
+
function setRedactCensor(fn) {
|
|
114
|
+
globalRedactCensor = fn;
|
|
115
|
+
}
|
|
116
|
+
__name(setRedactCensor, "setRedactCensor");
|
|
117
|
+
function getRedactCensor() {
|
|
118
|
+
return globalRedactCensor;
|
|
119
|
+
}
|
|
120
|
+
__name(getRedactCensor, "getRedactCensor");
|
|
121
|
+
function redact(value, path, sensitiveFields) {
|
|
122
|
+
return globalRedactCensor(value, path, sensitiveFields);
|
|
123
|
+
}
|
|
124
|
+
__name(redact, "redact");
|
|
125
|
+
function addRedactFields(fields) {
|
|
126
|
+
const prev = globalRedactCensor;
|
|
127
|
+
globalRedactCensor = /* @__PURE__ */ __name((value, path, sensitiveFields = getExpandedSensitiveFields()) => prev(value, path, [
|
|
128
|
+
...sensitiveFields || [],
|
|
129
|
+
...fields
|
|
130
|
+
]), "globalRedactCensor");
|
|
131
|
+
cachedExpandedFields = null;
|
|
132
|
+
}
|
|
133
|
+
__name(addRedactFields, "addRedactFields");
|
|
134
|
+
var cachedExpandedFields = null;
|
|
135
|
+
function getExpandedSensitiveFields() {
|
|
136
|
+
if (!cachedExpandedFields) {
|
|
137
|
+
cachedExpandedFields = expandSensitiveFields(defaultSensitiveFields);
|
|
138
|
+
}
|
|
139
|
+
return cachedExpandedFields;
|
|
140
|
+
}
|
|
141
|
+
__name(getExpandedSensitiveFields, "getExpandedSensitiveFields");
|
|
142
|
+
function setSensitiveFields(fields) {
|
|
143
|
+
defaultSensitiveFields.splice(0, defaultSensitiveFields.length, ...fields);
|
|
144
|
+
cachedExpandedFields = null;
|
|
145
|
+
}
|
|
146
|
+
__name(setSensitiveFields, "setSensitiveFields");
|
|
147
|
+
function addSensitiveFields(fields) {
|
|
148
|
+
defaultSensitiveFields.push(...fields);
|
|
149
|
+
cachedExpandedFields = null;
|
|
150
|
+
}
|
|
151
|
+
__name(addSensitiveFields, "addSensitiveFields");
|
|
152
|
+
var _globalThis = typeof globalThis === "object" ? globalThis : global;
|
|
153
|
+
var _global = _globalThis;
|
|
154
|
+
function setupLogger(isGlobal = true) {
|
|
155
|
+
const sensitiveFields = getExpandedSensitiveFields();
|
|
156
|
+
const paths = /* @__PURE__ */ new Set([
|
|
157
|
+
...defaultRedactPaths,
|
|
158
|
+
...sensitiveFields.flatMap((field) => generateDeepPaths(field, 2))
|
|
159
|
+
]);
|
|
160
|
+
const logParams = {
|
|
161
|
+
name: config.getCatbeeGlobalConfig().logger?.name || "@catbee/utils",
|
|
162
|
+
level: config.getCatbeeGlobalConfig().logger?.level || "info",
|
|
163
|
+
redact: {
|
|
164
|
+
paths: Array.from(paths),
|
|
165
|
+
censor: /* @__PURE__ */ __name((value, path) => redact(value, path), "censor")
|
|
166
|
+
},
|
|
167
|
+
serializers: {
|
|
168
|
+
req: pino__default.default.stdSerializers.req,
|
|
169
|
+
request: pino__default.default.stdSerializers.req,
|
|
170
|
+
res: pino__default.default.stdSerializers.res,
|
|
171
|
+
response: pino__default.default.stdSerializers.res,
|
|
172
|
+
err: pino__default.default.stdSerializers.err,
|
|
173
|
+
error: pino__default.default.stdSerializers.err
|
|
174
|
+
},
|
|
175
|
+
timestamp: pino.stdTimeFunctions.isoTime
|
|
176
|
+
};
|
|
177
|
+
let logger;
|
|
178
|
+
const logDir = config.getCatbeeGlobalConfig().logger?.dir?.trim();
|
|
179
|
+
const hasFileLogging = Boolean(logDir);
|
|
180
|
+
if (hasFileLogging && config.getCatbeeGlobalConfig().logger?.pretty) {
|
|
181
|
+
logger = pino__default.default(logParams, pino__default.default.transport({
|
|
182
|
+
targets: [
|
|
183
|
+
{
|
|
184
|
+
target: "pino-pretty",
|
|
185
|
+
level: config.getCatbeeGlobalConfig().logger?.level ?? "info",
|
|
186
|
+
options: {
|
|
187
|
+
colorize: config.getCatbeeGlobalConfig().logger?.colorize,
|
|
188
|
+
translateTime: "SYS:standard",
|
|
189
|
+
ignore: "pid,hostname",
|
|
190
|
+
singleLine: config.getCatbeeGlobalConfig().logger?.singleLine,
|
|
191
|
+
levelFirst: true
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
target: "pino/file",
|
|
196
|
+
level: config.getCatbeeGlobalConfig().logger?.level ?? "info",
|
|
197
|
+
options: {
|
|
198
|
+
destination: `${logDir}/app.log`,
|
|
199
|
+
mkdir: true
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
}));
|
|
204
|
+
} else if (hasFileLogging) {
|
|
205
|
+
logger = pino__default.default(logParams, pino__default.default.transport({
|
|
206
|
+
target: "pino/file",
|
|
207
|
+
options: {
|
|
208
|
+
destination: `${logDir}/app.log`,
|
|
209
|
+
mkdir: true
|
|
210
|
+
}
|
|
211
|
+
}));
|
|
212
|
+
} else if (config.getCatbeeGlobalConfig().logger?.pretty) {
|
|
213
|
+
logger = pino__default.default(logParams, pino__default.default.transport({
|
|
214
|
+
target: "pino-pretty",
|
|
215
|
+
options: {
|
|
216
|
+
colorize: config.getCatbeeGlobalConfig().logger?.colorize,
|
|
217
|
+
translateTime: "SYS:standard",
|
|
218
|
+
ignore: "pid,hostname",
|
|
219
|
+
singleLine: config.getCatbeeGlobalConfig().logger?.singleLine,
|
|
220
|
+
levelFirst: true
|
|
221
|
+
}
|
|
222
|
+
}));
|
|
223
|
+
} else {
|
|
224
|
+
logger = pino__default.default(logParams);
|
|
225
|
+
}
|
|
226
|
+
if (isGlobal) {
|
|
227
|
+
_global[GLOBAL_LOGGER_KEY] = logger;
|
|
228
|
+
_global[GLOBAL_LOGGER_KEY]?.debug({
|
|
229
|
+
logDir: logDir || "none"
|
|
230
|
+
}, "Global Logger Initialized");
|
|
231
|
+
}
|
|
232
|
+
return logger;
|
|
233
|
+
}
|
|
234
|
+
__name(setupLogger, "setupLogger");
|
|
235
|
+
function getLogger(newInstance = false) {
|
|
236
|
+
if (newInstance) {
|
|
237
|
+
return setupLogger(false);
|
|
238
|
+
}
|
|
239
|
+
const logger = contextStore.ContextStore.get(contextStore.StoreKeys.LOGGER);
|
|
240
|
+
if (logger) return logger;
|
|
241
|
+
if (!_global[GLOBAL_LOGGER_KEY]) {
|
|
242
|
+
setupLogger();
|
|
243
|
+
}
|
|
244
|
+
return _global[GLOBAL_LOGGER_KEY];
|
|
245
|
+
}
|
|
246
|
+
__name(getLogger, "getLogger");
|
|
247
|
+
function createChildLogger(bindings, parentLogger) {
|
|
248
|
+
const logger = parentLogger || getLogger();
|
|
249
|
+
return logger.child(bindings);
|
|
250
|
+
}
|
|
251
|
+
__name(createChildLogger, "createChildLogger");
|
|
252
|
+
function createRequestLogger(requestId, additionalContext = {}) {
|
|
253
|
+
const logger = createChildLogger({
|
|
254
|
+
requestId,
|
|
255
|
+
...additionalContext
|
|
256
|
+
});
|
|
257
|
+
try {
|
|
258
|
+
contextStore.ContextStore.set(contextStore.StoreKeys.LOGGER, logger);
|
|
259
|
+
} catch {
|
|
260
|
+
logger.debug("Failed to store logger in context - AsyncLocalStorage not initialized");
|
|
261
|
+
}
|
|
262
|
+
return logger;
|
|
263
|
+
}
|
|
264
|
+
__name(createRequestLogger, "createRequestLogger");
|
|
265
|
+
function logError(error, message, context) {
|
|
266
|
+
const logger = getLogger();
|
|
267
|
+
const errObj = error instanceof Error ? error : new Error(String(error));
|
|
268
|
+
const logContext = {
|
|
269
|
+
...context,
|
|
270
|
+
error: errObj
|
|
271
|
+
};
|
|
272
|
+
logger.error(logContext, message || errObj.message);
|
|
273
|
+
}
|
|
274
|
+
__name(logError, "logError");
|
|
275
|
+
function expandSensitiveFields(fields) {
|
|
276
|
+
const set = /* @__PURE__ */ new Set();
|
|
277
|
+
for (const field of fields) {
|
|
278
|
+
for (const v of expandSensitiveField(field)) {
|
|
279
|
+
set.add(v);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return Array.from(set);
|
|
283
|
+
}
|
|
284
|
+
__name(expandSensitiveFields, "expandSensitiveFields");
|
|
285
|
+
function expandSensitiveField(field) {
|
|
286
|
+
const parts = field.split(/[_-]/g).filter(Boolean);
|
|
287
|
+
const camel = parts[0].toLowerCase() + parts.slice(1).map((p) => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()).join("");
|
|
288
|
+
const mergedLower = parts.join("").toLowerCase();
|
|
289
|
+
const mergedUpper = parts.join("").toUpperCase();
|
|
290
|
+
const kebab = parts.map((p) => p.toLowerCase()).join("-");
|
|
291
|
+
const snakeLower = parts.map((p) => p.toLowerCase()).join("_");
|
|
292
|
+
const snakeUpper = parts.map((p) => p.toUpperCase()).join("_");
|
|
293
|
+
return Array.from(/* @__PURE__ */ new Set([
|
|
294
|
+
field,
|
|
295
|
+
camel,
|
|
296
|
+
mergedLower,
|
|
297
|
+
mergedUpper,
|
|
298
|
+
kebab,
|
|
299
|
+
snakeLower,
|
|
300
|
+
snakeUpper
|
|
301
|
+
]));
|
|
302
|
+
}
|
|
303
|
+
__name(expandSensitiveField, "expandSensitiveField");
|
|
304
|
+
function generateDeepPaths(field, depth) {
|
|
305
|
+
const set = /* @__PURE__ */ new Set([
|
|
306
|
+
field
|
|
307
|
+
]);
|
|
308
|
+
let prefix = "";
|
|
309
|
+
for (let i = 1; i <= depth; i++) {
|
|
310
|
+
prefix = prefix ? `${prefix}.*` : "*";
|
|
311
|
+
set.add(`${prefix}.${field}`);
|
|
312
|
+
}
|
|
313
|
+
return [
|
|
314
|
+
...set
|
|
315
|
+
];
|
|
316
|
+
}
|
|
317
|
+
__name(generateDeepPaths, "generateDeepPaths");
|
|
318
|
+
|
|
319
|
+
exports._globalThis = _globalThis;
|
|
320
|
+
exports.addRedactFields = addRedactFields;
|
|
321
|
+
exports.addSensitiveFields = addSensitiveFields;
|
|
322
|
+
exports.createChildLogger = createChildLogger;
|
|
323
|
+
exports.createRequestLogger = createRequestLogger;
|
|
324
|
+
exports.defaultSensitiveFields = defaultSensitiveFields;
|
|
325
|
+
exports.expandSensitiveField = expandSensitiveField;
|
|
326
|
+
exports.expandSensitiveFields = expandSensitiveFields;
|
|
327
|
+
exports.generateDeepPaths = generateDeepPaths;
|
|
328
|
+
exports.getExpandedSensitiveFields = getExpandedSensitiveFields;
|
|
329
|
+
exports.getLogger = getLogger;
|
|
330
|
+
exports.getRedactCensor = getRedactCensor;
|
|
331
|
+
exports.logError = logError;
|
|
332
|
+
exports.redact = redact;
|
|
333
|
+
exports.setRedactCensor = setRedactCensor;
|
|
334
|
+
exports.setSensitiveFields = setSensitiveFields;
|