@lidofinance/api-logger 0.11.0 → 0.13.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 +43 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +43 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -5
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var $dDFU1$darkobitsmaskstring = require("@darkobits/mask-string");
|
|
2
|
-
|
|
3
1
|
function $parcel$exportWildcard(dest, source) {
|
|
4
2
|
Object.keys(source).forEach(function(key) {
|
|
5
3
|
if (key === 'default' || key === '__esModule' || dest.hasOwnProperty(key)) {
|
|
@@ -16,18 +14,36 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
16
14
|
|
|
17
15
|
return dest;
|
|
18
16
|
}
|
|
19
|
-
function $parcel$interopDefault(a) {
|
|
20
|
-
return a && a.__esModule ? a.default : a;
|
|
21
|
-
}
|
|
22
17
|
function $parcel$export(e, n, v, s) {
|
|
23
18
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
24
19
|
}
|
|
25
20
|
var $2b0676a8d7ac44c3$exports = {};
|
|
26
21
|
|
|
27
22
|
$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
|
+
|
|
28
46
|
|
|
29
|
-
const $2b0676a8d7ac44c3$var$anyHex = new RegExp("0x[a-fA-F0-9]+", "ig");
|
|
30
|
-
const $2b0676a8d7ac44c3$var$anyEthAddress = new RegExp("[a-zA-Z0-9.]+\\.eth", "ig");
|
|
31
47
|
let $2b0676a8d7ac44c3$var$LEVEL;
|
|
32
48
|
(function(LEVEL) {
|
|
33
49
|
LEVEL["error"] = "error";
|
|
@@ -36,37 +52,43 @@ let $2b0676a8d7ac44c3$var$LEVEL;
|
|
|
36
52
|
LEVEL["debug"] = "debug";
|
|
37
53
|
LEVEL["log"] = "log";
|
|
38
54
|
})($2b0676a8d7ac44c3$var$LEVEL || ($2b0676a8d7ac44c3$var$LEVEL = {}));
|
|
39
|
-
const $2b0676a8d7ac44c3$var$
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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);
|
|
43
62
|
const $2b0676a8d7ac44c3$export$937ae38af6b48c0f = (secrets)=>{
|
|
44
63
|
const patterns = [
|
|
45
64
|
...secrets,
|
|
46
65
|
$2b0676a8d7ac44c3$var$anyHex,
|
|
47
66
|
$2b0676a8d7ac44c3$var$anyEthAddress
|
|
48
67
|
].filter(Boolean);
|
|
49
|
-
|
|
50
|
-
const mask = (message)=>(0, ($parcel$interopDefault($dDFU1$darkobitsmaskstring)))(patterns, message);
|
|
68
|
+
const mask = (0, $adb32885d633c259$export$d03f901feec039d7)(patterns);
|
|
51
69
|
const log = (level)=>(...output)=>{
|
|
52
70
|
try {
|
|
53
|
-
console[level](
|
|
71
|
+
console[level](// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
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)));
|
|
54
74
|
} catch (error) {
|
|
55
|
-
|
|
56
|
-
console.
|
|
75
|
+
// We can't show an actual error here because it may contain secrets
|
|
76
|
+
console.error("Failed to sanitize output");
|
|
57
77
|
}
|
|
58
78
|
};
|
|
59
79
|
return process.env.NODE_ENV === "production" ? {
|
|
60
|
-
error: log(
|
|
61
|
-
warn: log(
|
|
62
|
-
info: log(
|
|
63
|
-
debug: log(
|
|
64
|
-
log: log(
|
|
80
|
+
error: log("error"),
|
|
81
|
+
warn: log("warn"),
|
|
82
|
+
info: log("info"),
|
|
83
|
+
debug: log("debug"),
|
|
84
|
+
log: log("log")
|
|
65
85
|
} : console;
|
|
66
86
|
};
|
|
67
87
|
|
|
68
88
|
|
|
89
|
+
|
|
69
90
|
$parcel$exportWildcard(module.exports, $2b0676a8d7ac44c3$exports);
|
|
91
|
+
$parcel$exportWildcard(module.exports, $adb32885d633c259$exports);
|
|
70
92
|
|
|
71
93
|
|
|
72
94
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AEAA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAInI,kDAAkD;AAClD,MAAM,uCAAiB,CAAC,UACtB,mBAAmB,SAAS,IAAI,OAAO,QAAQ,MAAM,EAAE,OAAO,IAAI,OAAO,mCAAa,UAAU,IAAI;AAEtG,MAAM,qCAAe,CAAC,OAAe,QACnC,MAAM,IAAI,CAAC,MAAM,QAAQ,CAAC,QACvB,MAAM,CAAC,CAAC,OAAS,QAAQ,IAAI,CAC9B,uEAAuE;KACtE,GAAG,CAAC,CAAC,QAAU;YAAC,MAAM,KAAK;YAAa,MAAM,KAAK,GAAc,KAAK,CAAC,EAAE,CAAC,MAAM;SAAC;AAEtF,MAAM,gCAAU,CAAC,SAAmB,MAAM,IAAI,CAAC;gBAAE;IAAO,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;AAE1E,MAAM,oCAAc,CAAC,WAAwB,CAAC,UAC5C,SACG,GAAG,CAAC,sCACJ,OAAO,CAAC,CAAC,QAAU,mCAAa,OAA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AtCL;QAuCF,MAAM,IAtCL;QAuCD,MAAM,IAtCL;QAuCD,OAAO,IAtCL;QAuCF,KAAK,IAtCL;IAuCF,IACA,OAAO;AACb;;AD1DA","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts","packages/api/logger/src/maskString.ts"],"sourcesContent":["export * from './serverLoggerFactory'\nexport * from './maskString'\n","import { maskString } from './maskString'\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\nconst anyHex = new RegExp('0x[a-fA-F0-9]+')\nconst anyEthAddress = new RegExp('[a-zA-Z0-9.]+\\\\.eth')\n\nconst errorToObj = <T extends Error>(error: T) =>\n Object.getOwnPropertyNames(error).reduce((acc, cur) => ({ ...acc, [cur]: error[cur as keyof T] }), {})\n\nconst stringify = (data: unknown) => JSON.stringify(data instanceof Error ? errorToObj(data) : data)\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...secrets, anyHex, anyEthAddress].filter(Boolean)\n const mask = maskString(patterns)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n ...output\n .map(stringify)\n .map(mask)\n // can't pass just JSON.parse because it takes second argument\n .map((masked): unknown => JSON.parse(masked)),\n )\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","// Escape string to be safely used in RegExp constructor\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nconst escapeRegExp = (string: string): string => string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // $& means the whole matched string\n\nexport type Pattern = RegExp | string\n\n// Need to make regex global to work with MatchAll\nconst patternToRegex = (pattern: Pattern): RegExp =>\n pattern instanceof RegExp ? new RegExp(pattern.source, 'g') : new RegExp(escapeRegExp(pattern), 'g')\n\nconst matchIndexes = (regex: RegExp, input: string) =>\n Array.from(input.matchAll(regex))\n .filter((item) => item != null)\n // Need to force types, because ts doesn't know it is exactly the match\n .map((match) => [match.index as number, (match.index as number) + match[0].length])\n\nconst getMask = (length: number) => Array.from({ length }).fill('*').join('')\n\nconst maskFactory = (patterns: Pattern[]) => (message: string) =>\n patterns\n .map(patternToRegex)\n .flatMap((regex) => matchIndexes(regex, message))\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), message)\n\n// overload type definition to accept both types of call\nexport function maskString(pattern: Pattern[]): (input: string) => string\nexport function maskString(pattern: Pattern[], input: string): string\nexport function maskString(patterns: Pattern[], ...args: [] | [string]) {\n if (args.length === 1) {\n return maskFactory(patterns)(args[0])\n }\n return maskFactory(patterns)\n}\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type Pattern = RegExp | string;
|
|
2
|
+
export function maskString(pattern: Pattern[]): (input: string) => string;
|
|
3
|
+
export function maskString(pattern: Pattern[], input: string): string;
|
|
1
4
|
export type Logger = (...messages: unknown[]) => void;
|
|
2
5
|
export type ServerLogger = {
|
|
3
6
|
error: Logger;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":"AAIA,sBAAsB,MAAM,GAAG,MAAM,CAAA;AAqBrC,2BAA2B,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AACzE,2BAA2B,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;ACxBrE,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;AAkBD,OAAO,MAAM,+BAAgC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAG,YA8BrE,CAAA","sources":["packages/api/logger/src/src/maskString.ts","packages/api/logger/src/src/serverLoggerFactory.ts","packages/api/logger/src/src/index.ts","packages/api/logger/src/index.ts"],"sourcesContent":[null,null,null,"export * from './serverLoggerFactory'\nexport * from './maskString'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,33 @@
|
|
|
1
|
-
import $2Az7d$darkobitsmaskstring from "@darkobits/mask-string";
|
|
2
|
-
|
|
3
1
|
function $parcel$export(e, n, v, s) {
|
|
4
2
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
5
3
|
}
|
|
6
4
|
var $3e685537995feb8a$exports = {};
|
|
7
5
|
|
|
8
6
|
$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
|
+
|
|
9
30
|
|
|
10
|
-
const $3e685537995feb8a$var$anyHex = new RegExp("0x[a-fA-F0-9]+", "ig");
|
|
11
|
-
const $3e685537995feb8a$var$anyEthAddress = new RegExp("[a-zA-Z0-9.]+\\.eth", "ig");
|
|
12
31
|
let $3e685537995feb8a$var$LEVEL;
|
|
13
32
|
(function(LEVEL) {
|
|
14
33
|
LEVEL["error"] = "error";
|
|
@@ -17,37 +36,42 @@ let $3e685537995feb8a$var$LEVEL;
|
|
|
17
36
|
LEVEL["debug"] = "debug";
|
|
18
37
|
LEVEL["log"] = "log";
|
|
19
38
|
})($3e685537995feb8a$var$LEVEL || ($3e685537995feb8a$var$LEVEL = {}));
|
|
20
|
-
const $3e685537995feb8a$var$
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
24
46
|
const $3e685537995feb8a$export$937ae38af6b48c0f = (secrets)=>{
|
|
25
47
|
const patterns = [
|
|
26
48
|
...secrets,
|
|
27
49
|
$3e685537995feb8a$var$anyHex,
|
|
28
50
|
$3e685537995feb8a$var$anyEthAddress
|
|
29
51
|
].filter(Boolean);
|
|
30
|
-
|
|
31
|
-
const mask = (message)=>(0, $2Az7d$darkobitsmaskstring)(patterns, message);
|
|
52
|
+
const mask = (0, $4b57be4bc5b1d261$export$d03f901feec039d7)(patterns);
|
|
32
53
|
const log = (level)=>(...output)=>{
|
|
33
54
|
try {
|
|
34
|
-
console[level](
|
|
55
|
+
console[level](// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
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)));
|
|
35
58
|
} catch (error) {
|
|
36
|
-
|
|
37
|
-
console.
|
|
59
|
+
// We can't show an actual error here because it may contain secrets
|
|
60
|
+
console.error("Failed to sanitize output");
|
|
38
61
|
}
|
|
39
62
|
};
|
|
40
63
|
return process.env.NODE_ENV === "production" ? {
|
|
41
|
-
error: log(
|
|
42
|
-
warn: log(
|
|
43
|
-
info: log(
|
|
44
|
-
debug: log(
|
|
45
|
-
log: log(
|
|
64
|
+
error: log("error"),
|
|
65
|
+
warn: log("warn"),
|
|
66
|
+
info: log("info"),
|
|
67
|
+
debug: log("debug"),
|
|
68
|
+
log: log("log")
|
|
46
69
|
} : console;
|
|
47
70
|
};
|
|
48
71
|
|
|
49
72
|
|
|
50
73
|
|
|
51
74
|
|
|
52
|
-
|
|
75
|
+
|
|
76
|
+
export {$3e685537995feb8a$export$937ae38af6b48c0f as serverLoggerFactory, $4b57be4bc5b1d261$export$d03f901feec039d7 as maskString};
|
|
53
77
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;AEAA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAInI,kDAAkD;AAClD,MAAM,uCAAiB,CAAC,UACtB,mBAAmB,SAAS,IAAI,OAAO,QAAQ,MAAM,EAAE,OAAO,IAAI,OAAO,mCAAa,UAAU,IAAI;AAEtG,MAAM,qCAAe,CAAC,OAAe,QACnC,MAAM,IAAI,CAAC,MAAM,QAAQ,CAAC,QACvB,MAAM,CAAC,CAAC,OAAS,QAAQ,IAAI,CAC9B,uEAAuE;KACtE,GAAG,CAAC,CAAC,QAAU;YAAC,MAAM,KAAK;YAAa,MAAM,KAAK,GAAc,KAAK,CAAC,EAAE,CAAC,MAAM;SAAC;AAEtF,MAAM,gCAAU,CAAC,SAAmB,MAAM,IAAI,CAAC;gBAAE;IAAO,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC;AAE1E,MAAM,oCAAc,CAAC,WAAwB,CAAC,UAC5C,SACG,GAAG,CAAC,sCACJ,OAAO,CAAC,CAAC,QAAU,mCAAa,OAAO,UACvC,MAAM,CAAC,CAAC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;QAuCD,MAAM,IAtCL;QAuCD,OAAO,IAtCL;QAuCF,KAAK,IAtCL;IAuCF,IACA,OAAO;AACb;;AD1DA","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts","packages/api/logger/src/maskString.ts"],"sourcesContent":["export * from './serverLoggerFactory'\nexport * from './maskString'\n","import { maskString } from './maskString'\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\nconst anyHex = new RegExp('0x[a-fA-F0-9]+')\nconst anyEthAddress = new RegExp('[a-zA-Z0-9.]+\\\\.eth')\n\nconst errorToObj = <T extends Error>(error: T) =>\n Object.getOwnPropertyNames(error).reduce((acc, cur) => ({ ...acc, [cur]: error[cur as keyof T] }), {})\n\nconst stringify = (data: unknown) => JSON.stringify(data instanceof Error ? errorToObj(data) : data)\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...secrets, anyHex, anyEthAddress].filter(Boolean)\n const mask = maskString(patterns)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n ...output\n .map(stringify)\n .map(mask)\n // can't pass just JSON.parse because it takes second argument\n .map((masked): unknown => JSON.parse(masked)),\n )\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","// Escape string to be safely used in RegExp constructor\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nconst escapeRegExp = (string: string): string => string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // $& means the whole matched string\n\nexport type Pattern = RegExp | string\n\n// Need to make regex global to work with MatchAll\nconst patternToRegex = (pattern: Pattern): RegExp =>\n pattern instanceof RegExp ? new RegExp(pattern.source, 'g') : new RegExp(escapeRegExp(pattern), 'g')\n\nconst matchIndexes = (regex: RegExp, input: string) =>\n Array.from(input.matchAll(regex))\n .filter((item) => item != null)\n // Need to force types, because ts doesn't know it is exactly the match\n .map((match) => [match.index as number, (match.index as number) + match[0].length])\n\nconst getMask = (length: number) => Array.from({ length }).fill('*').join('')\n\nconst maskFactory = (patterns: Pattern[]) => (message: string) =>\n patterns\n .map(patternToRegex)\n .flatMap((regex) => matchIndexes(regex, message))\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), message)\n\n// overload type definition to accept both types of call\nexport function maskString(pattern: Pattern[]): (input: string) => string\nexport function maskString(pattern: Pattern[], input: string): string\nexport function maskString(patterns: Pattern[], ...args: [] | [string]) {\n if (args.length === 1) {\n return maskFactory(patterns)(args[0])\n }\n return maskFactory(patterns)\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.13.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -21,11 +21,8 @@
|
|
|
21
21
|
"types": "tsc --noEmit",
|
|
22
22
|
"test": "jest"
|
|
23
23
|
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@darkobits/mask-string": "^2.0.1"
|
|
26
|
-
},
|
|
27
24
|
"devDependencies": {
|
|
28
|
-
"@lidofinance/config-prettier": "~0.
|
|
25
|
+
"@lidofinance/config-prettier": "~0.13.0",
|
|
29
26
|
"@types/jest": "^29.2.4",
|
|
30
27
|
"@types/node": "^18.11.17",
|
|
31
28
|
"jest": "^29.3.1",
|