@lidofinance/api-logger 0.14.0 → 0.16.0
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/dist/index.cjs +6 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +7 -39
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var $dDFU1$lidofinancesatanizer = require("@lidofinance/satanizer");
|
|
2
|
+
|
|
1
3
|
function $parcel$exportWildcard(dest, source) {
|
|
2
4
|
Object.keys(source).forEach(function(key) {
|
|
3
5
|
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
@@ -20,29 +22,6 @@ function $parcel$export(e, n, v, s) {
|
|
|
20
22
|
var $2b0676a8d7ac44c3$exports = {};
|
|
21
23
|
|
|
22
24
|
$parcel$export($2b0676a8d7ac44c3$exports, "serverLoggerFactory", () => $2b0676a8d7ac44c3$export$937ae38af6b48c0f);
|
|
23
|
-
var $adb32885d633c259$exports = {};
|
|
24
|
-
|
|
25
|
-
$parcel$export($adb32885d633c259$exports, "maskString", () => $adb32885d633c259$export$d03f901feec039d7);
|
|
26
|
-
// Escape string to be safely used in RegExp constructor
|
|
27
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
28
|
-
const $adb32885d633c259$var$escapeRegExp = (string)=>string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
|
29
|
-
;
|
|
30
|
-
// Need to make regex global to work with MatchAll
|
|
31
|
-
const $adb32885d633c259$var$patternToRegex = (pattern)=>pattern instanceof RegExp ? new RegExp(pattern.source, "g") : new RegExp($adb32885d633c259$var$escapeRegExp(pattern), "g");
|
|
32
|
-
const $adb32885d633c259$var$matchIndexes = (regex, input)=>Array.from(input.matchAll(regex)).filter((item)=>item != null)// Need to force types, because ts doesn't know it is exactly the match
|
|
33
|
-
.map((match)=>[
|
|
34
|
-
match.index,
|
|
35
|
-
match.index + match[0].length
|
|
36
|
-
]);
|
|
37
|
-
const $adb32885d633c259$var$getMask = (length)=>Array.from({
|
|
38
|
-
length: length
|
|
39
|
-
}).fill("*").join("");
|
|
40
|
-
const $adb32885d633c259$var$maskFactory = (patterns)=>(message)=>patterns.map($adb32885d633c259$var$patternToRegex).flatMap((regex)=>$adb32885d633c259$var$matchIndexes(regex, message)).reduce((acc, [start, end])=>acc.slice(0, start) + $adb32885d633c259$var$getMask(end - start) + acc.slice(end), message);
|
|
41
|
-
function $adb32885d633c259$export$d03f901feec039d7(patterns, ...args) {
|
|
42
|
-
if (args.length === 1) return $adb32885d633c259$var$maskFactory(patterns)(args[0]);
|
|
43
|
-
return $adb32885d633c259$var$maskFactory(patterns);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
25
|
|
|
47
26
|
let $2b0676a8d7ac44c3$var$LEVEL;
|
|
48
27
|
(function(LEVEL) {
|
|
@@ -52,25 +31,15 @@ let $2b0676a8d7ac44c3$var$LEVEL;
|
|
|
52
31
|
LEVEL["debug"] = "debug";
|
|
53
32
|
LEVEL["log"] = "log";
|
|
54
33
|
})($2b0676a8d7ac44c3$var$LEVEL || ($2b0676a8d7ac44c3$var$LEVEL = {}));
|
|
55
|
-
const $2b0676a8d7ac44c3$var$anyHex = new RegExp("0x[a-fA-F0-9]+");
|
|
56
|
-
const $2b0676a8d7ac44c3$var$anyEthAddress = new RegExp("[a-zA-Z0-9.]+\\.eth");
|
|
57
|
-
const $2b0676a8d7ac44c3$var$errorToObj = (error)=>Object.getOwnPropertyNames(error).reduce((acc, cur)=>({
|
|
58
|
-
...acc,
|
|
59
|
-
[cur]: error[cur]
|
|
60
|
-
}), {});
|
|
61
|
-
const $2b0676a8d7ac44c3$var$stringify = (data)=>JSON.stringify(data instanceof Error ? $2b0676a8d7ac44c3$var$errorToObj(data) : data);
|
|
62
34
|
const $2b0676a8d7ac44c3$export$937ae38af6b48c0f = (secrets)=>{
|
|
63
35
|
const patterns = [
|
|
64
|
-
...
|
|
65
|
-
|
|
66
|
-
$2b0676a8d7ac44c3$var$anyEthAddress
|
|
36
|
+
...(0, $dDFU1$lidofinancesatanizer.commonPatterns),
|
|
37
|
+
...secrets
|
|
67
38
|
].filter(Boolean);
|
|
68
|
-
const mask = (0, $
|
|
39
|
+
const mask = (0, $dDFU1$lidofinancesatanizer.satanizer)(patterns);
|
|
69
40
|
const log = (level)=>(...output)=>{
|
|
70
41
|
try {
|
|
71
|
-
console[level](
|
|
72
|
-
...output.map($2b0676a8d7ac44c3$var$stringify).map(mask)// can't pass just JSON.parse because it takes second argument
|
|
73
|
-
.map((masked)=>JSON.parse(masked)));
|
|
42
|
+
console[level](...output.map(mask));
|
|
74
43
|
} catch (error) {
|
|
75
44
|
// We can't show an actual error here because it may contain secrets
|
|
76
45
|
console.error("Failed to sanitize output");
|
|
@@ -86,9 +55,7 @@ const $2b0676a8d7ac44c3$export$937ae38af6b48c0f = (secrets)=>{
|
|
|
86
55
|
};
|
|
87
56
|
|
|
88
57
|
|
|
89
|
-
|
|
90
58
|
$parcel$exportWildcard(module.exports, $2b0676a8d7ac44c3$exports);
|
|
91
|
-
$parcel$exportWildcard(module.exports, $adb32885d633c259$exports);
|
|
92
59
|
|
|
93
60
|
|
|
94
61
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACAA;IAYA;UAAW,KAAK;IAAL,MACT,WAAA;IADS,MAET,UAAA;IAFS,MAGT,UAAA;IAHS,MAIT,WAAA;IAJS,MAKT,SAAA;GALS,gCAAA;AAQJ,MAAM,4CAAsB,CAAC,UAAkD;IACpF,MAAM,WAAW;WAAI,CAAA,GAAA,0CAAa;WAAM;KAAQ,CAAC,MAAM,CAAC;IACxD,MAAM,OAAO,CAAA,GAAA,qCAAQ,EAAE;IAEvB,MAAM,MACJ,CAAC,QACD,CAAC,GAAG,SAA4B;YAC9B,IAAI;gBACF,OAAO,CAAC,MAAM,IAAI,OAAO,GAAG,CAAC;YAC/B,EAAE,OAAO,OAAO;gBACd,oEAAoE;gBACpE,QAAQ,KAAK,CAAC;YAChB;QACF;IACF,OAAO,QAAQ,GAAG,CAAC,QAAQ,KAAK,eAC5B;QACE,OAAO,IAvBL;QAwBF,MAAM,IAvBL;QAwBD,MAAM,IAvBL;QAwBD,OAAO,IAvBL;QAwBF,KAAK,IAvBL;IAwBF,IACA,OAAO;AACb;;AD3CA","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts"],"sourcesContent":["export * from './serverLoggerFactory'\n","import { satanizer, commonPatterns } from '@lidofinance/satanizer'\n\nexport type Logger = (...messages: unknown[]) => void\n\nexport type ServerLogger = {\n error: Logger\n warn: Logger\n info: Logger\n debug: Logger\n log: Logger\n}\n\nconst enum LEVEL {\n error = 'error',\n warn = 'warn',\n info = 'info',\n debug = 'debug',\n log = 'log',\n}\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...commonPatterns, ...secrets].filter(Boolean)\n const mask = satanizer(patterns)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](...output.map(mask))\n } catch (error) {\n // We can't show an actual error here because it may contain secrets\n console.error('Failed to sanitize output')\n }\n }\n return process.env.NODE_ENV === 'production'\n ? {\n error: log(LEVEL.error),\n warn: log(LEVEL.warn),\n info: log(LEVEL.info),\n debug: log(LEVEL.debug),\n log: log(LEVEL.log),\n }\n : console\n}\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
export type Pattern = RegExp | string;
|
|
2
|
-
export function maskString(pattern: Pattern[]): (input: string) => string;
|
|
3
|
-
export function maskString(pattern: Pattern[], input: string): string;
|
|
4
1
|
export type Logger = (...messages: unknown[]) => void;
|
|
5
2
|
export type ServerLogger = {
|
|
6
3
|
error: Logger;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAEA,qBAAqB,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AAErD,2BAA2B;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAUD,OAAO,MAAM,+BAAgC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAG,YAuBrE,CAAA","sources":["packages/api/logger/src/src/serverLoggerFactory.ts","packages/api/logger/src/src/index.ts","packages/api/logger/src/index.ts"],"sourcesContent":[null,null,"export * from './serverLoggerFactory'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,32 +1,11 @@
|
|
|
1
|
+
import {commonPatterns as $2Az7d$commonPatterns, satanizer as $2Az7d$satanizer} from "@lidofinance/satanizer";
|
|
2
|
+
|
|
1
3
|
function $parcel$export(e, n, v, s) {
|
|
2
4
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
3
5
|
}
|
|
4
6
|
var $3e685537995feb8a$exports = {};
|
|
5
7
|
|
|
6
8
|
$parcel$export($3e685537995feb8a$exports, "serverLoggerFactory", () => $3e685537995feb8a$export$937ae38af6b48c0f);
|
|
7
|
-
var $4b57be4bc5b1d261$exports = {};
|
|
8
|
-
|
|
9
|
-
$parcel$export($4b57be4bc5b1d261$exports, "maskString", () => $4b57be4bc5b1d261$export$d03f901feec039d7);
|
|
10
|
-
// Escape string to be safely used in RegExp constructor
|
|
11
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping
|
|
12
|
-
const $4b57be4bc5b1d261$var$escapeRegExp = (string)=>string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") // $& means the whole matched string
|
|
13
|
-
;
|
|
14
|
-
// Need to make regex global to work with MatchAll
|
|
15
|
-
const $4b57be4bc5b1d261$var$patternToRegex = (pattern)=>pattern instanceof RegExp ? new RegExp(pattern.source, "g") : new RegExp($4b57be4bc5b1d261$var$escapeRegExp(pattern), "g");
|
|
16
|
-
const $4b57be4bc5b1d261$var$matchIndexes = (regex, input)=>Array.from(input.matchAll(regex)).filter((item)=>item != null)// Need to force types, because ts doesn't know it is exactly the match
|
|
17
|
-
.map((match)=>[
|
|
18
|
-
match.index,
|
|
19
|
-
match.index + match[0].length
|
|
20
|
-
]);
|
|
21
|
-
const $4b57be4bc5b1d261$var$getMask = (length)=>Array.from({
|
|
22
|
-
length: length
|
|
23
|
-
}).fill("*").join("");
|
|
24
|
-
const $4b57be4bc5b1d261$var$maskFactory = (patterns)=>(message)=>patterns.map($4b57be4bc5b1d261$var$patternToRegex).flatMap((regex)=>$4b57be4bc5b1d261$var$matchIndexes(regex, message)).reduce((acc, [start, end])=>acc.slice(0, start) + $4b57be4bc5b1d261$var$getMask(end - start) + acc.slice(end), message);
|
|
25
|
-
function $4b57be4bc5b1d261$export$d03f901feec039d7(patterns, ...args) {
|
|
26
|
-
if (args.length === 1) return $4b57be4bc5b1d261$var$maskFactory(patterns)(args[0]);
|
|
27
|
-
return $4b57be4bc5b1d261$var$maskFactory(patterns);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
9
|
|
|
31
10
|
let $3e685537995feb8a$var$LEVEL;
|
|
32
11
|
(function(LEVEL) {
|
|
@@ -36,25 +15,15 @@ let $3e685537995feb8a$var$LEVEL;
|
|
|
36
15
|
LEVEL["debug"] = "debug";
|
|
37
16
|
LEVEL["log"] = "log";
|
|
38
17
|
})($3e685537995feb8a$var$LEVEL || ($3e685537995feb8a$var$LEVEL = {}));
|
|
39
|
-
const $3e685537995feb8a$var$anyHex = new RegExp("0x[a-fA-F0-9]+");
|
|
40
|
-
const $3e685537995feb8a$var$anyEthAddress = new RegExp("[a-zA-Z0-9.]+\\.eth");
|
|
41
|
-
const $3e685537995feb8a$var$errorToObj = (error)=>Object.getOwnPropertyNames(error).reduce((acc, cur)=>({
|
|
42
|
-
...acc,
|
|
43
|
-
[cur]: error[cur]
|
|
44
|
-
}), {});
|
|
45
|
-
const $3e685537995feb8a$var$stringify = (data)=>JSON.stringify(data instanceof Error ? $3e685537995feb8a$var$errorToObj(data) : data);
|
|
46
18
|
const $3e685537995feb8a$export$937ae38af6b48c0f = (secrets)=>{
|
|
47
19
|
const patterns = [
|
|
48
|
-
...
|
|
49
|
-
|
|
50
|
-
$3e685537995feb8a$var$anyEthAddress
|
|
20
|
+
...(0, $2Az7d$commonPatterns),
|
|
21
|
+
...secrets
|
|
51
22
|
].filter(Boolean);
|
|
52
|
-
const mask = (0, $
|
|
23
|
+
const mask = (0, $2Az7d$satanizer)(patterns);
|
|
53
24
|
const log = (level)=>(...output)=>{
|
|
54
25
|
try {
|
|
55
|
-
console[level](
|
|
56
|
-
...output.map($3e685537995feb8a$var$stringify).map(mask)// can't pass just JSON.parse because it takes second argument
|
|
57
|
-
.map((masked)=>JSON.parse(masked)));
|
|
26
|
+
console[level](...output.map(mask));
|
|
58
27
|
} catch (error) {
|
|
59
28
|
// We can't show an actual error here because it may contain secrets
|
|
60
29
|
console.error("Failed to sanitize output");
|
|
@@ -72,6 +41,5 @@ const $3e685537995feb8a$export$937ae38af6b48c0f = (secrets)=>{
|
|
|
72
41
|
|
|
73
42
|
|
|
74
43
|
|
|
75
|
-
|
|
76
|
-
export {$3e685537995feb8a$export$937ae38af6b48c0f as serverLoggerFactory, $4b57be4bc5b1d261$export$d03f901feec039d7 as maskString};
|
|
44
|
+
export {$3e685537995feb8a$export$937ae38af6b48c0f as serverLoggerFactory};
|
|
77
45
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;ACAA;IAYA;UAAW,KAAK;IAAL,MACT,WAAA;IADS,MAET,UAAA;IAFS,MAGT,UAAA;IAHS,MAIT,WAAA;IAJS,MAKT,SAAA;GALS,gCAAA;AAQJ,MAAM,4CAAsB,CAAC,UAAkD;IACpF,MAAM,WAAW;WAAI,CAAA,GAAA,qBAAa;WAAM;KAAQ,CAAC,MAAM,CAAC;IACxD,MAAM,OAAO,CAAA,GAAA,gBAAQ,EAAE;IAEvB,MAAM,MACJ,CAAC,QACD,CAAC,GAAG,SAA4B;YAC9B,IAAI;gBACF,OAAO,CAAC,MAAM,IAAI,OAAO,GAAG,CAAC;YAC/B,EAAE,OAAO,OAAO;gBACd,oEAAoE;gBACpE,QAAQ,KAAK,CAAC;YAChB;QACF;IACF,OAAO,QAAQ,GAAG,CAAC,QAAQ,KAAK,eAC5B;QACE,OAAO,IAvBL;QAwBF,MAAM,IAvBL;QAwBD,MAAM,IAvBL;QAwBD,OAAO,IAvBL;QAwBF,KAAK,IAvBL;IAwBF,IACA,OAAO;AACb;;AD3CA","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts"],"sourcesContent":["export * from './serverLoggerFactory'\n","import { satanizer, commonPatterns } from '@lidofinance/satanizer'\n\nexport type Logger = (...messages: unknown[]) => void\n\nexport type ServerLogger = {\n error: Logger\n warn: Logger\n info: Logger\n debug: Logger\n log: Logger\n}\n\nconst enum LEVEL {\n error = 'error',\n warn = 'warn',\n info = 'info',\n debug = 'debug',\n log = 'log',\n}\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...commonPatterns, ...secrets].filter(Boolean)\n const mask = satanizer(patterns)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](...output.map(mask))\n } catch (error) {\n // We can't show an actual error here because it may contain secrets\n console.error('Failed to sanitize output')\n }\n }\n return process.env.NODE_ENV === 'production'\n ? {\n error: log(LEVEL.error),\n warn: log(LEVEL.warn),\n info: log(LEVEL.info),\n debug: log(LEVEL.debug),\n log: log(LEVEL.log),\n }\n : console\n}\n"],"names":[],"version":3,"file":"index.mjs.map","sourceRoot":"../../../../"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "API logger, which hides secrets",
|
|
4
4
|
"repository": "git@github.com:lidofinance/warehouse.git",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.16.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -21,8 +21,11 @@
|
|
|
21
21
|
"types": "tsc --noEmit",
|
|
22
22
|
"test": "jest"
|
|
23
23
|
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@lidofinance/satanizer": "~0.16.0"
|
|
26
|
+
},
|
|
24
27
|
"devDependencies": {
|
|
25
|
-
"@lidofinance/config-prettier": "~0.
|
|
28
|
+
"@lidofinance/config-prettier": "~0.16.0",
|
|
26
29
|
"@types/jest": "^29.2.4",
|
|
27
30
|
"@types/node": "^18.11.17",
|
|
28
31
|
"jest": "^29.3.1",
|