lambda-essentials-ts 5.1.7 → 5.1.8
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/CHANGELOG.md +6 -0
- package/lib/logger/logger.js +2 -4
- package/lib/openApi/openApiWrapper.js +1 -1
- package/lib/util.d.ts +2 -1
- package/lib/util.js +11 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
6
6
|
|
|
7
|
+
## [5.1.8] - 2022-12-15
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
Removed client_secret from API response
|
|
12
|
+
|
|
7
13
|
## [5.1.7] - 2022-12-13
|
|
8
14
|
|
|
9
15
|
### Changed
|
package/lib/logger/logger.js
CHANGED
|
@@ -30,6 +30,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
30
30
|
const uuid = __importStar(require("uuid"));
|
|
31
31
|
const fast_safe_stringify_1 = __importDefault(require("fast-safe-stringify"));
|
|
32
32
|
const is_error_1 = __importDefault(require("is-error"));
|
|
33
|
+
const util_1 = require("../util");
|
|
33
34
|
class Logger {
|
|
34
35
|
constructor(configuration) {
|
|
35
36
|
var _a, _b;
|
|
@@ -74,12 +75,9 @@ class Logger {
|
|
|
74
75
|
const truncateToken = (innerPayload) => {
|
|
75
76
|
return innerPayload.replace(/(eyJ[a-zA-Z0-9_-]{5,}\.eyJ[a-zA-Z0-9_-]{5,})\.[a-zA-Z0-9_-]*/gi, (m, p1) => `${p1}.<sig>`);
|
|
76
77
|
};
|
|
77
|
-
const truncateSecret = (data) => {
|
|
78
|
-
return data.replace(/(\\*"client_secret\\*":\\*")([a-zA-Z0-9_+=.@/-]{60,})(\\*")/gi, (m, p1, p2, p3) => `${p1}<REDACTED>${p3}`);
|
|
79
|
-
};
|
|
80
78
|
const replacer = (key, value) => ((0, is_error_1.default)(value) ? Logger.errorToObject(value) : value);
|
|
81
79
|
let stringifiedPayload = truncateToken((0, fast_safe_stringify_1.default)(payload, replacer, this.jsonSpace));
|
|
82
|
-
stringifiedPayload =
|
|
80
|
+
stringifiedPayload = (0, util_1.redactSecret)(stringifiedPayload);
|
|
83
81
|
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch_limits_cwl.html 256KB => 32768 characters
|
|
84
82
|
if (stringifiedPayload.length >= 32768) {
|
|
85
83
|
const replacementPayload = {
|
|
@@ -83,7 +83,7 @@ class OpenApiWrapper {
|
|
|
83
83
|
errorMiddleware: (request, error) => {
|
|
84
84
|
const { correlationId } = this;
|
|
85
85
|
this.clearContext();
|
|
86
|
-
const serializedError = (0, util_1.serializeObject)(error);
|
|
86
|
+
const serializedError = (0, util_1.serializeObject)(error, true);
|
|
87
87
|
if (error instanceof exception_1.Exception) {
|
|
88
88
|
if (error.statusCode === 500) {
|
|
89
89
|
requestLogger.log({ title: 'ErrorLogger', level: 'ERROR', ...serializedError });
|
package/lib/util.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AxiosError } from 'axios';
|
|
2
2
|
export declare function safeJwtCanonicalIdParse(jwtToken: string): string | undefined;
|
|
3
3
|
export declare function safeJsonParse(input: any, defaultValue: unknown): unknown;
|
|
4
|
-
export declare
|
|
4
|
+
export declare const redactSecret: (data: string) => string;
|
|
5
|
+
export declare function serializeObject(obj: unknown, redact?: boolean): object;
|
|
5
6
|
export declare function serializeAxiosError(error: AxiosError): SerializedAxiosError | undefined;
|
|
6
7
|
export interface SerializedAxiosError {
|
|
7
8
|
status: number;
|
package/lib/util.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.serializeAxiosError = exports.serializeObject = exports.safeJsonParse = exports.safeJwtCanonicalIdParse = void 0;
|
|
6
|
+
exports.serializeAxiosError = exports.serializeObject = exports.redactSecret = exports.safeJsonParse = exports.safeJwtCanonicalIdParse = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
8
|
function safeJwtCanonicalIdParse(jwtToken) {
|
|
9
9
|
var _a;
|
|
@@ -24,15 +24,22 @@ function safeJsonParse(input, defaultValue) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
exports.safeJsonParse = safeJsonParse;
|
|
27
|
-
|
|
27
|
+
const redactSecret = (data) => {
|
|
28
|
+
return data.replace(/(\\*"*'*client_secret\\*"*'*:\s*\\*"*'*)([^"'\\]+)(\\*"*'*)/gi, (m, p1, p2, p3) => `${p1}<REDACTED>${p3}`);
|
|
29
|
+
};
|
|
30
|
+
exports.redactSecret = redactSecret;
|
|
31
|
+
function serializeObject(obj, redact) {
|
|
32
|
+
let modObj = obj;
|
|
28
33
|
if (obj && typeof obj === 'object') {
|
|
29
|
-
|
|
34
|
+
modObj = Object.getOwnPropertyNames(obj).reduce((map, key) => {
|
|
30
35
|
// eslint-disable-next-line no-param-reassign
|
|
31
36
|
map[key] = obj[key];
|
|
32
37
|
return map;
|
|
33
38
|
}, {});
|
|
34
39
|
}
|
|
35
|
-
return
|
|
40
|
+
return redact
|
|
41
|
+
? JSON.parse((0, exports.redactSecret)(JSON.stringify(modObj)))
|
|
42
|
+
: JSON.parse(JSON.stringify(modObj));
|
|
36
43
|
}
|
|
37
44
|
exports.serializeObject = serializeObject;
|
|
38
45
|
function serializeAxiosError(error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lambda-essentials-ts",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.8",
|
|
4
4
|
"description": "A selection of the finest modules supporting authorization, API routing, error handling, logging and sending HTTP requests.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"private": false,
|