@lidofinance/api-logger 0.11.0 → 0.12.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 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$stringify = (data)=>data instanceof Error ? JSON.stringify({
40
- message: data.message,
41
- stack: data.stack
42
- }) : JSON.stringify(data);
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
- // TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}
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](...output.map($2b0676a8d7ac44c3$var$stringify).map(mask));
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
- console.error(error);
56
- console.warn("Failed to sanitize output");
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($2b0676a8d7ac44c3$var$LEVEL.error),
61
- warn: log($2b0676a8d7ac44c3$var$LEVEL.warn),
62
- info: log($2b0676a8d7ac44c3$var$LEVEL.info),
63
- debug: log($2b0676a8d7ac44c3$var$LEVEL.debug),
64
- log: log($2b0676a8d7ac44c3$var$LEVEL.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
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;ACAA;AAEA,MAAM,+BAAS,IAAI,OAAO,kBAAkB;AAC5C,MAAM,sCAAgB,IAAI,OAAO,uBAAuB;IAExD;UAAK,KAAK;IAAL,MACH,WAAA;IADG,MAEH,UAAA;IAFG,MAGH,UAAA;IAHG,MAIH,WAAA;IAJG,MAKH,SAAA;GALG,gCAAA;AAQL,MAAM,kCAAY,CAAC,OACjB,gBAAgB,QAEZ,KAAK,SAAS,CAAC;QACb,SAAS,KAAK,OAAO;QACrB,OAAO,KAAK,KAAK;IACnB,KACA,KAAK,SAAS,CAAC,KAAK;AAWnB,MAAM,4CAAsB,CAAC,UAAkD;IACpF,MAAM,WAAW;WAAI;QAAS;QAAQ;KAAc,CAAC,MAAM,CAAC;IAC5D,mGAAmG;IACnG,MAAM,OAAO,CAAC,UAA4B,CAAA,GAAA,oDAAS,EAAE,UAAU;IAE/D,MAAM,MACJ,CAAC,QACD,CAAC,GAAG,SAA4B;YAC9B,IAAI;gBACF,OAAO,CAAC,MAAM,IAAI,OAAO,GAAG,CAAC,iCAAW,GAAG,CAAC;YAC9C,EAAE,OAAO,OAAO;gBACd,QAAQ,KAAK,CAAC;gBACd,QAAQ,IAAI,CAAC;YACf;QACF;IACF,OAAO,QAAQ,GAAG,CAAC,QAAQ,KAAK,eAC5B;QACE,OAAO,IAAI,4BAAM,KAAK;QACtB,MAAM,IAAI,4BAAM,IAAI;QACpB,MAAM,IAAI,4BAAM,IAAI;QACpB,OAAO,IAAI,4BAAM,KAAK;QACtB,KAAK,IAAI,4BAAM,GAAG;IACpB,IACA,OAAO;AACb;;ADvDA","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts"],"sourcesContent":["export * from './serverLoggerFactory'\n","import maskString from '@darkobits/mask-string'\n\nconst anyHex = new RegExp('0x[a-fA-F0-9]+', 'ig')\nconst anyEthAddress = new RegExp('[a-zA-Z0-9.]+\\\\.eth', 'ig')\n\nenum LEVEL {\n error = 'error',\n warn = 'warn',\n info = 'info',\n debug = 'debug',\n log = 'log',\n}\n\nconst stringify = (data: unknown) =>\n data instanceof Error\n ? // extract Error's non-enumerable props before stringifying\n JSON.stringify({\n message: data.message,\n stack: data.stack,\n })\n : JSON.stringify(data)\n\nexport type Logger = (...messages: unknown[]) => void\nexport type ServerLogger = {\n error: Logger\n warn: Logger\n info: Logger\n debug: Logger\n log: Logger\n}\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...secrets, anyHex, anyEthAddress].filter(Boolean)\n // TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}\n const mask = (message: string): string => maskString(patterns, message)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](...output.map(stringify).map(mask))\n } catch (error) {\n console.error(error)\n console.warn('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":"../../../../"}
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,CAA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OAAO,OAAO;gBACd,oEAAoE;gBACpE,QAAQ,KAAK,CAAC;YAChB;QACF;IACF,OAAO,QAAQ,GAAG,CAAC,QAAQ,KAAK,eAC5B;QACE,OAAO,IAtCL;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;
@@ -1 +1 @@
1
- {"mappings":"AAsBA,qBAAqB,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;AACrD,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;AAED,OAAO,MAAM,+BAAgC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAG,YAwBrE,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":"../../../../"}
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$stringify = (data)=>data instanceof Error ? JSON.stringify({
21
- message: data.message,
22
- stack: data.stack
23
- }) : JSON.stringify(data);
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
- // TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}
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](...output.map($3e685537995feb8a$var$stringify).map(mask));
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
- console.error(error);
37
- console.warn("Failed to sanitize output");
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($3e685537995feb8a$var$LEVEL.error),
42
- warn: log($3e685537995feb8a$var$LEVEL.warn),
43
- info: log($3e685537995feb8a$var$LEVEL.info),
44
- debug: log($3e685537995feb8a$var$LEVEL.debug),
45
- log: log($3e685537995feb8a$var$LEVEL.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
- export {$3e685537995feb8a$export$937ae38af6b48c0f as serverLoggerFactory};
75
+
76
+ export {$3e685537995feb8a$export$937ae38af6b48c0f as serverLoggerFactory, $4b57be4bc5b1d261$export$d03f901feec039d7 as maskString};
53
77
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;ACAA;AAEA,MAAM,+BAAS,IAAI,OAAO,kBAAkB;AAC5C,MAAM,sCAAgB,IAAI,OAAO,uBAAuB;IAExD;UAAK,KAAK;IAAL,MACH,WAAA;IADG,MAEH,UAAA;IAFG,MAGH,UAAA;IAHG,MAIH,WAAA;IAJG,MAKH,SAAA;GALG,gCAAA;AAQL,MAAM,kCAAY,CAAC,OACjB,gBAAgB,QAEZ,KAAK,SAAS,CAAC;QACb,SAAS,KAAK,OAAO;QACrB,OAAO,KAAK,KAAK;IACnB,KACA,KAAK,SAAS,CAAC,KAAK;AAWnB,MAAM,4CAAsB,CAAC,UAAkD;IACpF,MAAM,WAAW;WAAI;QAAS;QAAQ;KAAc,CAAC,MAAM,CAAC;IAC5D,mGAAmG;IACnG,MAAM,OAAO,CAAC,UAA4B,CAAA,GAAA,0BAAS,EAAE,UAAU;IAE/D,MAAM,MACJ,CAAC,QACD,CAAC,GAAG,SAA4B;YAC9B,IAAI;gBACF,OAAO,CAAC,MAAM,IAAI,OAAO,GAAG,CAAC,iCAAW,GAAG,CAAC;YAC9C,EAAE,OAAO,OAAO;gBACd,QAAQ,KAAK,CAAC;gBACd,QAAQ,IAAI,CAAC;YACf;QACF;IACF,OAAO,QAAQ,GAAG,CAAC,QAAQ,KAAK,eAC5B;QACE,OAAO,IAAI,4BAAM,KAAK;QACtB,MAAM,IAAI,4BAAM,IAAI;QACpB,MAAM,IAAI,4BAAM,IAAI;QACpB,OAAO,IAAI,4BAAM,KAAK;QACtB,KAAK,IAAI,4BAAM,GAAG;IACpB,IACA,OAAO;AACb;;ADvDA","sources":["packages/api/logger/src/index.ts","packages/api/logger/src/serverLoggerFactory.ts"],"sourcesContent":["export * from './serverLoggerFactory'\n","import maskString from '@darkobits/mask-string'\n\nconst anyHex = new RegExp('0x[a-fA-F0-9]+', 'ig')\nconst anyEthAddress = new RegExp('[a-zA-Z0-9.]+\\\\.eth', 'ig')\n\nenum LEVEL {\n error = 'error',\n warn = 'warn',\n info = 'info',\n debug = 'debug',\n log = 'log',\n}\n\nconst stringify = (data: unknown) =>\n data instanceof Error\n ? // extract Error's non-enumerable props before stringifying\n JSON.stringify({\n message: data.message,\n stack: data.stack,\n })\n : JSON.stringify(data)\n\nexport type Logger = (...messages: unknown[]) => void\nexport type ServerLogger = {\n error: Logger\n warn: Logger\n info: Logger\n debug: Logger\n log: Logger\n}\n\nexport const serverLoggerFactory = (secrets: Array<RegExp | string>): ServerLogger => {\n const patterns = [...secrets, anyHex, anyEthAddress].filter(Boolean)\n // TODO: replace not with *** but with name of masked pattern e.g. https://example.com/{INFURA_KEY}\n const mask = (message: string): string => maskString(patterns, message)\n\n const log =\n (level: LEVEL) =>\n (...output: unknown[]): void => {\n try {\n console[level](...output.map(stringify).map(mask))\n } catch (error) {\n console.error(error)\n console.warn('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(L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AM,+BAAS,IAAI,OAAO;AAC1B,MAAM,sCAAgB,IAAI,OAAO;AAEjC,MAAM,mCAAa,CAAkB,QACnC,OAAO,mBAAmB,CAAC,OAAO,MAAM,CAAC,CAAC,KAAK,MAAS,CAAA;YAAE,GAAG,GAAG;YAAE,CAAC,IAAI,EAAE,KAAK,CAAC,IAAe;QAAC,CAAA,GAAI,CAAC;AAEtG,MAAM,kCAAY,CAAC,OAAkB,KAAK,SAAS,CAAC,gBAAgB,QAAQ,iCAAW,QAAQ,IAAI;AAE5F,MAAM,4CAAsB,CAAC,UAAkD;IACpF,MAAM,WAAW;WAAI;QAAS;QAAQ;KAAc,CAAC,MAAM,CAAC;IAC5D,MAAM,OAAO,CAAA,GAAA,yCAAS,EAAE;IAExB,MAAM,MACJ,CAAC,QACD,CAAC,GAAG,SAA4B;YAC9B,IAAI;gBACF,OAAO,CAAC,MAAM,CACZ,iEAAiE;mBAC9D,OACA,GAAG,CAAC,iCACJ,GAAG,CAAC,KACL,8DAA8D;iBAC7D,GAAG,CAAC,CAAC,SAAoB,KAAK,KAAK,CAAC;YAE3C,EAAE,OAAO,OAAO;gBACd,oEAAoE;gBACpE,QAAQ,KAAK,CAAC;YAChB;QACF;IACF,OAAO,QAAQ,GAAG,CAAC,QAAQ,KAAK,eAC5B;QACE,OAAO,IAtCL;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.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.11.0",
6
+ "version": "0.12.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.11.0",
25
+ "@lidofinance/config-prettier": "~0.12.0",
29
26
  "@types/jest": "^29.2.4",
30
27
  "@types/node": "^18.11.17",
31
28
  "jest": "^29.3.1",