@lidofinance/satanizer 0.24.0 → 0.26.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
@@ -40,10 +40,11 @@ const $6181fcac47f6fbd9$var$errorToObj = (error)=>Object.getOwnPropertyNames(err
40
40
  }), {});
41
41
  const $6181fcac47f6fbd9$var$stringify = (data)=>JSON.stringify(data instanceof Error ? $6181fcac47f6fbd9$var$errorToObj(data) : data);
42
42
  const $6181fcac47f6fbd9$var$satanizerFactory = (patterns)=>(message)=>{
43
+ const clearPatterns = patterns.filter((pattern)=>pattern != null);
43
44
  // This is a bit dirty workaround right now, just to not iterate over all keys/values and all possible edge cases.
44
45
  // There are a few issues with it, added tests about it and marked them as failing.
45
46
  const stringified = $6181fcac47f6fbd9$var$stringify(message ?? null);
46
- const safeStringifiedMessage = patterns.map($6181fcac47f6fbd9$var$patternToRegex)// Need to find all indexes first, otherwise we may miss overlaps
47
+ const safeStringifiedMessage = clearPatterns.map($6181fcac47f6fbd9$var$patternToRegex)// Need to find all indexes first, otherwise we may miss overlaps
47
48
  .flatMap((regex)=>$6181fcac47f6fbd9$var$matchIndexes(regex, stringified))// Now it's safe to replace every match with the mask
48
49
  .reduce((acc, [start, end])=>acc.slice(0, start) + $6181fcac47f6fbd9$var$getMask(end - start) + acc.slice(end), stringified);
49
50
  return JSON.parse(safeStringifiedMessage);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;ACEA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAInI,MAAM,uCAAiB,CAAC,UACtB,kDAAkD;IAClD,mBAAmB,SAAS,IAAI,OAAO,QAAQ,MAAM,EAAE,OAAO,IAAI,OAAO,mCAAa,UAAU,IAAI;AAEtG,MAAM,qCAAe,CAAC,OAAe,QACnC,MAAM,IAAI,CAAC,MA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AAiB;IAAC;IAAmB;IAAY;IAAW;CAAW;","sources":["packages/core/satanazier/src/index.ts","packages/core/satanazier/src/satanizer.ts","packages/core/satanazier/src/common-patterns.ts"],"sourcesContent":["export * from './satanizer'\nexport * from './common-patterns'\n","import { OmitFunctions } from './omit-functions'\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\nconst patternToRegex = (pattern: Pattern): RegExp =>\n // Need to make regex global to work with MatchAll\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 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 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\nconst satanizerFactory = (patterns: Pattern[]) => (message: any) => {\n // This is a bit dirty workaround right now, just to not iterate over all keys/values and all possible edge cases.\n // There are a few issues with it, added tests about it and marked them as failing.\n const stringified = stringify(message ?? null)\n const safeStringifiedMessage = patterns\n .map(patternToRegex)\n // Need to find all indexes first, otherwise we may miss overlaps\n .flatMap((regex) => matchIndexes(regex, stringified))\n // Now it's safe to replace every match with the mask\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), stringified)\n return JSON.parse(safeStringifiedMessage)\n}\n\n// Overload type definition to accept both types of call.\nexport function satanizer<T>(pattern: Pattern[]): (input: T) => OmitFunctions<T> // this is a bit incorrect since we don't perserve methods\nexport function satanizer<T>(pattern: Pattern[], input: T): OmitFunctions<T>\nexport function satanizer<T>(patterns: Pattern[], ...args: [] | [OmitFunctions<T>]) {\n if (args.length === 1) {\n return satanizerFactory(patterns)(args[0])\n }\n return satanizerFactory(patterns)\n}\n","// May caught ids, maybe needs to test this a bit more\nexport const blockchainAddress = /(0x)?[a-zA-Z0-9]{40,}/\nexport const ensAddress = /[a-zA-Z0-9.]+\\.eth/\n// It's not really valid, but it's still ok for secrets\nexport const ipAddress = /\\d+\\.\\d+\\.\\d+\\.\\d+/\nexport const macAddress = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/\n\nexport const commonPatterns = [blockchainAddress, ensAddress, ipAddress, macAddress]\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;ACEA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAKnI,MAAM,uCAAiB,CAAC,UACtB,kDAAkD;IAClD,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,+DAA+D;KAC9D,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,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;AAEnG,MAAM,yCAAmB,CAAC,WAAwB,CAAC,UAAiB;QAClE,MAAM,gBAAgB,SAAS,MAAM,CAAC,CAAC,UAAqC,WAAW,IAAI;QAC3F,kHAAkH;QAClH,mFAAmF;QACnF,MAAM,cAAc,gCAAU,WAAW,IAAI;QAC7C,MAAM,yBAAyB,cAC5B,GAAG,CAAC,qCACL,iEAAiE;SAChE,OAAO,CAAC,CAAC,QAAU,mCAAa,OAAO,aACxC,qDAAqD;SACpD,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,GAAK,IAAI,KAAK,CAAC,GAAG,SAAS,8BAAQ,MAAM,SAAS,IAAI,KAAK,CAAC,MAAM;QAC9F,OAAO,KAAK,KAAK,CAAC;IACpB;AAKO,SAAS,0CAAa,QAAmB,EAAE,GAAG,IAA6B,EAAE;IAClF,IAAI,KAAK,MAAM,KAAK,GAClB,OAAO,uCAAiB,UAAU,IAAI,CAAC,EAAE;IAE3C,OAAO,uCAAiB;AAC1B;;ADhDA;;;;;;;;AEAA,sDAAsD;AAC/C,MAAM,2CAAoB;AAC1B,MAAM,4CAAa;AAEnB,MAAM,4CAAY;AAClB,MAAM,4CAAa;AAEnB,MAAM,4CAAiB;IAAC;IAAmB;IAAY;IAAW;CAAW;","sources":["packages/core/satanazier/src/index.ts","packages/core/satanazier/src/satanizer.ts","packages/core/satanazier/src/common-patterns.ts"],"sourcesContent":["export * from './satanizer'\nexport * from './common-patterns'\n","import { OmitFunctions } from './omit-functions'\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 ClearPattern = RegExp | string\nexport type Pattern = ClearPattern | null | undefined\n\nconst patternToRegex = (pattern: ClearPattern): RegExp =>\n // Need to make regex global to work with MatchAll\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 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 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\nconst satanizerFactory = (patterns: Pattern[]) => (message: any) => {\n const clearPatterns = patterns.filter((pattern): pattern is ClearPattern => pattern != null)\n // This is a bit dirty workaround right now, just to not iterate over all keys/values and all possible edge cases.\n // There are a few issues with it, added tests about it and marked them as failing.\n const stringified = stringify(message ?? null)\n const safeStringifiedMessage = clearPatterns\n .map(patternToRegex)\n // Need to find all indexes first, otherwise we may miss overlaps\n .flatMap((regex) => matchIndexes(regex, stringified))\n // Now it's safe to replace every match with the mask\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), stringified)\n return JSON.parse(safeStringifiedMessage)\n}\n\n// Overload type definition to accept both types of call.\nexport function satanizer<T>(pattern: Pattern[]): (input: T) => OmitFunctions<T> // this is a bit incorrect since we don't perserve methods\nexport function satanizer<T>(pattern: Pattern[], input: T): OmitFunctions<T>\nexport function satanizer<T>(patterns: Pattern[], ...args: [] | [OmitFunctions<T>]) {\n if (args.length === 1) {\n return satanizerFactory(patterns)(args[0])\n }\n return satanizerFactory(patterns)\n}\n","// May caught ids, maybe needs to test this a bit more\nexport const blockchainAddress = /(0x)?[a-zA-Z0-9]{40,}/\nexport const ensAddress = /[a-zA-Z0-9.]+\\.eth/\n// It's not really valid, but it's still ok for secrets\nexport const ipAddress = /\\d+\\.\\d+\\.\\d+\\.\\d+/\nexport const macAddress = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/\n\nexport const commonPatterns = [blockchainAddress, ensAddress, ipAddress, macAddress]\n"],"names":[],"version":3,"file":"index.cjs.map","sourceRoot":"../../../../"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { OmitFunctions } from "./omit-functions";
2
- export type Pattern = RegExp | string;
2
+ export type ClearPattern = RegExp | string;
3
+ export type Pattern = ClearPattern | null | undefined;
3
4
  export function satanizer<T>(pattern: Pattern[]): (input: T) => OmitFunctions<T>;
4
5
  export function satanizer<T>(pattern: Pattern[], input: T): OmitFunctions<T>;
5
6
  export const blockchainAddress: RegExp;
@@ -1 +1 @@
1
- {"mappings":";AAMA,sBAAsB,MAAM,GAAG,MAAM,CAAA;AAiCrC,0BAA0B,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,cAAc,CAAC,CAAC,CAAA;AAChF,0BAA0B,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAA;ACvC5E,OAAO,MAAM,yBAA2C,CAAA;AACxD,OAAO,MAAM,kBAAiC,CAAA;AAE9C,OAAO,MAAM,iBAAgC,CAAA;AAC7C,OAAO,MAAM,kBAAsD,CAAA;AAEnE,OAAO,MAAM,wBAAuE,CAAA","sources":["packages/core/satanazier/src/src/satanizer.ts","packages/core/satanazier/src/src/common-patterns.ts","packages/core/satanazier/src/src/index.ts","packages/core/satanazier/src/index.ts"],"sourcesContent":[null,null,null,"export * from './satanizer'\nexport * from './common-patterns'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
1
+ {"mappings":";AAMA,2BAA2B,MAAM,GAAG,MAAM,CAAA;AAC1C,sBAAsB,YAAY,GAAG,IAAI,GAAG,SAAS,CAAA;AAkCrD,0BAA0B,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,KAAK,cAAc,CAAC,CAAC,CAAA;AAChF,0BAA0B,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAA;ACzC5E,OAAO,MAAM,yBAA2C,CAAA;AACxD,OAAO,MAAM,kBAAiC,CAAA;AAE9C,OAAO,MAAM,iBAAgC,CAAA;AAC7C,OAAO,MAAM,kBAAsD,CAAA;AAEnE,OAAO,MAAM,wBAAuE,CAAA","sources":["packages/core/satanazier/src/src/satanizer.ts","packages/core/satanazier/src/src/common-patterns.ts","packages/core/satanazier/src/src/index.ts","packages/core/satanazier/src/index.ts"],"sourcesContent":[null,null,null,"export * from './satanizer'\nexport * from './common-patterns'\n"],"names":[],"version":3,"file":"index.d.ts.map","sourceRoot":"../../../../"}
package/dist/index.mjs CHANGED
@@ -24,10 +24,11 @@ const $634bfa66b85378ba$var$errorToObj = (error)=>Object.getOwnPropertyNames(err
24
24
  }), {});
25
25
  const $634bfa66b85378ba$var$stringify = (data)=>JSON.stringify(data instanceof Error ? $634bfa66b85378ba$var$errorToObj(data) : data);
26
26
  const $634bfa66b85378ba$var$satanizerFactory = (patterns)=>(message)=>{
27
+ const clearPatterns = patterns.filter((pattern)=>pattern != null);
27
28
  // This is a bit dirty workaround right now, just to not iterate over all keys/values and all possible edge cases.
28
29
  // There are a few issues with it, added tests about it and marked them as failing.
29
30
  const stringified = $634bfa66b85378ba$var$stringify(message ?? null);
30
- const safeStringifiedMessage = patterns.map($634bfa66b85378ba$var$patternToRegex)// Need to find all indexes first, otherwise we may miss overlaps
31
+ const safeStringifiedMessage = clearPatterns.map($634bfa66b85378ba$var$patternToRegex)// Need to find all indexes first, otherwise we may miss overlaps
31
32
  .flatMap((regex)=>$634bfa66b85378ba$var$matchIndexes(regex, stringified))// Now it's safe to replace every match with the mask
32
33
  .reduce((acc, [start, end])=>acc.slice(0, start) + $634bfa66b85378ba$var$getMask(end - start) + acc.slice(end), stringified);
33
34
  return JSON.parse(safeStringifiedMessage);
@@ -1 +1 @@
1
- {"mappings":";;;;;;ACEA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAInI,MAAM,uCAAiB,CAAC,UACtB,kDAAkD;IAClD,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,+DAA+D;KAC9D,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,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;AAEnG,MAAM,yCAAmB,CAAC,WAAwB,CAAC,UAAiB;QAClE,kHAAkH;QAClH,mFAAmF;QACnF,MAAM,cAAc,gCAAU,WAAW,IAAI;QAC7C,MAAM,yBAAyB,SAC5B,GAAG,CAAC,qCACL,iEAAiE;SAChE,OAAO,CAAC,CAAC,QAAU,mCAAa,OAAO,aACxC,qDAAqD;SACpD,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,GAAK,IAAI,KAAK,CAAC,GAAG,SAAS,8BAAQ,MAAM,SAAS,IAAI,KAAK,CAAC,MAAM;QAC9F,OAAO,KAAK,KAAK,CAAC;IACpB;AAKO,SAAS,0CAAa,QAAmB,EAAE,GAAG,IAA6B,EAAE;IAClF,IAAI,KAAK,MAAM,KAAK,GAClB,OAAO,uCAAiB,UAAU,IAAI,CAAC,EAAE;IAE3C,OAAO,uCAAiB;AAC1B;;AD9CA;;;;;;;;AEAA,sDAAsD;AAC/C,MAAM,2CAAoB;AAC1B,MAAM,4CAAa;AAEnB,MAAM,4CAAY;AAClB,MAAM,4CAAa;AAEnB,MAAM,4CAAiB;IAAC;IAAmB;IAAY;IAAW;CAAW;","sources":["packages/core/satanazier/src/index.ts","packages/core/satanazier/src/satanizer.ts","packages/core/satanazier/src/common-patterns.ts"],"sourcesContent":["export * from './satanizer'\nexport * from './common-patterns'\n","import { OmitFunctions } from './omit-functions'\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\nconst patternToRegex = (pattern: Pattern): RegExp =>\n // Need to make regex global to work with MatchAll\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 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 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\nconst satanizerFactory = (patterns: Pattern[]) => (message: any) => {\n // This is a bit dirty workaround right now, just to not iterate over all keys/values and all possible edge cases.\n // There are a few issues with it, added tests about it and marked them as failing.\n const stringified = stringify(message ?? null)\n const safeStringifiedMessage = patterns\n .map(patternToRegex)\n // Need to find all indexes first, otherwise we may miss overlaps\n .flatMap((regex) => matchIndexes(regex, stringified))\n // Now it's safe to replace every match with the mask\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), stringified)\n return JSON.parse(safeStringifiedMessage)\n}\n\n// Overload type definition to accept both types of call.\nexport function satanizer<T>(pattern: Pattern[]): (input: T) => OmitFunctions<T> // this is a bit incorrect since we don't perserve methods\nexport function satanizer<T>(pattern: Pattern[], input: T): OmitFunctions<T>\nexport function satanizer<T>(patterns: Pattern[], ...args: [] | [OmitFunctions<T>]) {\n if (args.length === 1) {\n return satanizerFactory(patterns)(args[0])\n }\n return satanizerFactory(patterns)\n}\n","// May caught ids, maybe needs to test this a bit more\nexport const blockchainAddress = /(0x)?[a-zA-Z0-9]{40,}/\nexport const ensAddress = /[a-zA-Z0-9.]+\\.eth/\n// It's not really valid, but it's still ok for secrets\nexport const ipAddress = /\\d+\\.\\d+\\.\\d+\\.\\d+/\nexport const macAddress = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/\n\nexport const commonPatterns = [blockchainAddress, ensAddress, ipAddress, macAddress]\n"],"names":[],"version":3,"file":"index.mjs.map","sourceRoot":"../../../../"}
1
+ {"mappings":";;;;;;ACEA,wDAAwD;AACxD,6FAA6F;AAC7F,MAAM,qCAAe,CAAC,SAA2B,OAAO,OAAO,CAAC,uBAAuB,QAAQ,oCAAoC;;AAKnI,MAAM,uCAAiB,CAAC,UACtB,kDAAkD;IAClD,mBAAmB,SAAS,IAAI,OAAO,QAAQ,MAAM,EAAE,OAAO,IAAI,OAAO,mCAAa,UAA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1B;;ADhDA;;;;;;;;AEAA,sDAAsD;AAC/C,MAAM,2CAAoB;AAC1B,MAAM,4CAAa;AAEnB,MAAM,4CAAY;AAClB,MAAM,4CAAa;AAEnB,MAAM,4CAAiB;IAAC;IAAmB;IAAY;IAAW;CAAW;","sources":["packages/core/satanazier/src/index.ts","packages/core/satanazier/src/satanizer.ts","packages/core/satanazier/src/common-patterns.ts"],"sourcesContent":["export * from './satanizer'\nexport * from './common-patterns'\n","import { OmitFunctions } from './omit-functions'\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 ClearPattern = RegExp | string\nexport type Pattern = ClearPattern | null | undefined\n\nconst patternToRegex = (pattern: ClearPattern): RegExp =>\n // Need to make regex global to work with MatchAll\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 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 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\nconst satanizerFactory = (patterns: Pattern[]) => (message: any) => {\n const clearPatterns = patterns.filter((pattern): pattern is ClearPattern => pattern != null)\n // This is a bit dirty workaround right now, just to not iterate over all keys/values and all possible edge cases.\n // There are a few issues with it, added tests about it and marked them as failing.\n const stringified = stringify(message ?? null)\n const safeStringifiedMessage = clearPatterns\n .map(patternToRegex)\n // Need to find all indexes first, otherwise we may miss overlaps\n .flatMap((regex) => matchIndexes(regex, stringified))\n // Now it's safe to replace every match with the mask\n .reduce((acc, [start, end]) => acc.slice(0, start) + getMask(end - start) + acc.slice(end), stringified)\n return JSON.parse(safeStringifiedMessage)\n}\n\n// Overload type definition to accept both types of call.\nexport function satanizer<T>(pattern: Pattern[]): (input: T) => OmitFunctions<T> // this is a bit incorrect since we don't perserve methods\nexport function satanizer<T>(pattern: Pattern[], input: T): OmitFunctions<T>\nexport function satanizer<T>(patterns: Pattern[], ...args: [] | [OmitFunctions<T>]) {\n if (args.length === 1) {\n return satanizerFactory(patterns)(args[0])\n }\n return satanizerFactory(patterns)\n}\n","// May caught ids, maybe needs to test this a bit more\nexport const blockchainAddress = /(0x)?[a-zA-Z0-9]{40,}/\nexport const ensAddress = /[a-zA-Z0-9.]+\\.eth/\n// It's not really valid, but it's still ok for secrets\nexport const ipAddress = /\\d+\\.\\d+\\.\\d+\\.\\d+/\nexport const macAddress = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/\n\nexport const commonPatterns = [blockchainAddress, ensAddress, ipAddress, macAddress]\n"],"names":[],"version":3,"file":"index.mjs.map","sourceRoot":"../../../../"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Tool, which mask secrets",
4
4
  "repository": "git@github.com:lidofinance/warehouse.git",
5
5
  "license": "MIT",
6
- "version": "0.24.0",
6
+ "version": "0.26.0",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
@@ -22,7 +22,7 @@
22
22
  "test": "jest && tsd -f 'src/*.test-d.ts'"
23
23
  },
24
24
  "devDependencies": {
25
- "@lidofinance/config-prettier": "~0.24.0",
25
+ "@lidofinance/config-prettier": "~0.26.0",
26
26
  "@types/jest": "^29.2.4",
27
27
  "@types/node": "^18.11.17",
28
28
  "jest": "^29.3.1",