lesgo 2.1.11 → 3.0.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/README.md +7 -8
- package/dist/middlewares/httpResponseMiddleware.js +3 -3
- package/dist/services/JWTService/sign.js +5 -2
- package/dist/services/LoggerService.d.ts +7 -0
- package/dist/services/LoggerService.js +52 -1
- package/dist/services/S3Service/getObject.d.ts +0 -1
- package/dist/services/S3Service/putObject.d.ts +0 -1
- package/dist/utils/cache/redis/getClient.d.ts +1 -1
- package/dist/utils/s3/getObject.d.ts +1 -2
- package/dist/utils/s3/putObject.d.ts +0 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Lesgo!
|
|
1
|
+
# Lesgo! Framework
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|
[](https://coveralls.io/github/reflex-media/lesgo-framework?branch=master)
|
|
@@ -13,22 +13,22 @@ This framework uses Jest test framework for unit testing.
|
|
|
13
13
|
|
|
14
14
|
All test files exist in the respective `src/**/__tests__/*.test.ts` directory.
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
### Install dependencies
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
|
|
19
|
+
npm ci
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
### Run test
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
|
|
25
|
+
npm test
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### Run code coverage report
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
|
|
31
|
+
npm run coverage
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
View the generated html report in `coverage/index.html`.
|
|
@@ -40,4 +40,3 @@ Declare testing environment configurations in `jest.setup.ts` directory.
|
|
|
40
40
|
## Contributing
|
|
41
41
|
|
|
42
42
|
You may contribute to the core framework by submitting a PR to the `develop` branch. Refer to the official [Docs](https://reflex-media.github.io/lesgo-docs/stable/prologue/contribution-guide/) for more information.
|
|
43
|
-
|
|
@@ -89,7 +89,7 @@ const httpResponseMiddleware = (opts = {}) => {
|
|
|
89
89
|
});
|
|
90
90
|
const httpResponseMiddlewareOnError = request =>
|
|
91
91
|
__awaiter(void 0, void 0, void 0, function* () {
|
|
92
|
-
var
|
|
92
|
+
var _a;
|
|
93
93
|
const error = request.error;
|
|
94
94
|
if (error.extra && error.extra.statusCode) {
|
|
95
95
|
delete error.extra.statusCode;
|
|
@@ -98,9 +98,9 @@ const httpResponseMiddleware = (opts = {}) => {
|
|
|
98
98
|
statusCode: error.statusCode || 500,
|
|
99
99
|
headers: Object.assign(
|
|
100
100
|
Object.assign({}, options.headers),
|
|
101
|
-
(
|
|
101
|
+
(_a = request.response) === null || _a === void 0
|
|
102
102
|
? void 0
|
|
103
|
-
:
|
|
103
|
+
: _a.headers
|
|
104
104
|
),
|
|
105
105
|
body: Object.assign(
|
|
106
106
|
{
|
|
@@ -3,6 +3,7 @@ import { jwt as jwtConfig } from '../../config';
|
|
|
3
3
|
import { generateUid } from '../../utils';
|
|
4
4
|
import getJwtSecret from './getJwtSecret';
|
|
5
5
|
const sign = (payload, secret, opts) => {
|
|
6
|
+
var _a;
|
|
6
7
|
const jwtSecret = getJwtSecret({
|
|
7
8
|
secret,
|
|
8
9
|
keyid: opts === null || opts === void 0 ? void 0 : opts.keyid,
|
|
@@ -12,8 +13,10 @@ const sign = (payload, secret, opts) => {
|
|
|
12
13
|
(opts === null || opts === void 0 ? void 0 : opts.algorithm) ||
|
|
13
14
|
jwtConfig.algorithm,
|
|
14
15
|
expiresIn:
|
|
15
|
-
(opts === null || opts === void 0 ? void 0 : opts.expiresIn)
|
|
16
|
-
|
|
16
|
+
(_a = opts === null || opts === void 0 ? void 0 : opts.expiresIn) !==
|
|
17
|
+
null && _a !== void 0
|
|
18
|
+
? _a
|
|
19
|
+
: jwtConfig.expiresIn,
|
|
17
20
|
issuer:
|
|
18
21
|
(opts === null || opts === void 0 ? void 0 : opts.issuer) ||
|
|
19
22
|
jwtConfig.issuer,
|
|
@@ -42,5 +42,12 @@ export default class LoggerService {
|
|
|
42
42
|
};
|
|
43
43
|
refineMessagePerTransport(transportName: string, message: any): any;
|
|
44
44
|
getTransportByName(transportName: string): Transport | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Sanitizes an object for JSON serialization by:
|
|
47
|
+
* - Replacing functions with a string representation (similar to console.log behavior)
|
|
48
|
+
* - Handling circular references
|
|
49
|
+
* - Preserving other values
|
|
50
|
+
*/
|
|
51
|
+
sanitizeForJson(obj: any, seen?: WeakSet<object>): any;
|
|
45
52
|
}
|
|
46
53
|
export {};
|
|
@@ -58,7 +58,8 @@ export default class LoggerService {
|
|
|
58
58
|
if (!this.checkIsLogRequired('console', level)) return null;
|
|
59
59
|
const refinedMessage = this.refineMessagePerTransport('console', message);
|
|
60
60
|
const consoleFunc = level === 'notice' ? 'log' : level;
|
|
61
|
-
|
|
61
|
+
const sanitizedMessage = this.sanitizeForJson(refinedMessage);
|
|
62
|
+
return console[consoleFunc](JSON.stringify(sanitizedMessage));
|
|
62
63
|
}
|
|
63
64
|
checkIsLogRequired(transportName, level) {
|
|
64
65
|
const transport = this.getTransportByName(transportName);
|
|
@@ -117,4 +118,54 @@ export default class LoggerService {
|
|
|
117
118
|
transport => transport.logType === transportName
|
|
118
119
|
);
|
|
119
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Sanitizes an object for JSON serialization by:
|
|
123
|
+
* - Replacing functions with a string representation (similar to console.log behavior)
|
|
124
|
+
* - Handling circular references
|
|
125
|
+
* - Preserving other values
|
|
126
|
+
*/
|
|
127
|
+
sanitizeForJson(obj, seen = new WeakSet()) {
|
|
128
|
+
// Handle null and undefined
|
|
129
|
+
if (obj === null || obj === undefined) {
|
|
130
|
+
return obj;
|
|
131
|
+
}
|
|
132
|
+
// Handle functions - replace with string representation like console.log does
|
|
133
|
+
if (typeof obj === 'function') {
|
|
134
|
+
const funcName = obj.name || 'anonymous';
|
|
135
|
+
return `[Function: ${funcName}]`;
|
|
136
|
+
}
|
|
137
|
+
// Handle primitives
|
|
138
|
+
if (typeof obj !== 'object') {
|
|
139
|
+
return obj;
|
|
140
|
+
}
|
|
141
|
+
// Handle circular references
|
|
142
|
+
if (seen.has(obj)) {
|
|
143
|
+
return '[Circular]';
|
|
144
|
+
}
|
|
145
|
+
// Handle Date objects
|
|
146
|
+
if (obj instanceof Date) {
|
|
147
|
+
return obj.toISOString();
|
|
148
|
+
}
|
|
149
|
+
// Handle arrays
|
|
150
|
+
if (Array.isArray(obj)) {
|
|
151
|
+
seen.add(obj);
|
|
152
|
+
return obj.map(item => this.sanitizeForJson(item, seen));
|
|
153
|
+
}
|
|
154
|
+
// Handle objects
|
|
155
|
+
seen.add(obj);
|
|
156
|
+
const sanitized = {};
|
|
157
|
+
for (const key in obj) {
|
|
158
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
159
|
+
try {
|
|
160
|
+
sanitized[key] = this.sanitizeForJson(obj[key], seen);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
// If we can't serialize a property, replace it with error message
|
|
163
|
+
sanitized[key] = `[Error: ${
|
|
164
|
+
error instanceof Error ? error.message : 'Unknown error'
|
|
165
|
+
}]`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return sanitized;
|
|
170
|
+
}
|
|
120
171
|
}
|
|
@@ -26,5 +26,5 @@ import { ClientOptions } from '../../../types/aws';
|
|
|
26
26
|
* await client.set(key, value);
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
declare const getClient: (clientOpts?: ClientOptions) => Promise<import("ioredis
|
|
29
|
+
declare const getClient: (clientOpts?: ClientOptions) => Promise<import("ioredis").Cluster>;
|
|
30
30
|
export default getClient;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { GetObjectOptions } from '../../services/S3Service/getObject';
|
|
3
2
|
import { ClientOptions } from '../../types/aws';
|
|
4
3
|
/**
|
|
@@ -9,5 +8,5 @@ import { ClientOptions } from '../../types/aws';
|
|
|
9
8
|
* @param clientOpts - Optional client options for the S3 client.
|
|
10
9
|
* @returns A Promise that resolves to the body of the retrieved object.
|
|
11
10
|
*/
|
|
12
|
-
declare const getObject: (key: string, opts?: GetObjectOptions, clientOpts?: ClientOptions) => Promise<Buffer
|
|
11
|
+
declare const getObject: (key: string, opts?: GetObjectOptions, clientOpts?: ClientOptions) => Promise<Buffer<ArrayBufferLike>>;
|
|
13
12
|
export default getObject;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { PutObjectOptions } from '../../services/S3Service/putObject';
|
|
3
2
|
import { ClientOptions } from '../../types/aws';
|
|
4
3
|
declare const putObject: (key: string, file: Buffer | Uint8Array | Blob | string, opts?: PutObjectOptions, clientOpts?: ClientOptions) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lesgo",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Core framework for lesgo node.js serverless framework.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
},
|
|
178
178
|
"engineStrict": true,
|
|
179
179
|
"engines": {
|
|
180
|
-
"node": ">=
|
|
180
|
+
"node": ">=20.17.0"
|
|
181
181
|
},
|
|
182
182
|
"peerDependencies": {
|
|
183
183
|
"serverless": "^3.0.0"
|