@lidofinance/satanizer 0.16.0 → 0.17.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/README.md +0 -1
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +2 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -60,20 +60,17 @@ $parcel$export($2f2af15db2572749$exports, "blockchainAddress", () => $2f2af15db2
|
|
|
60
60
|
$parcel$export($2f2af15db2572749$exports, "ensAddress", () => $2f2af15db2572749$export$6a3b35e38f46684a);
|
|
61
61
|
$parcel$export($2f2af15db2572749$exports, "ipAddress", () => $2f2af15db2572749$export$450e57019586b28f);
|
|
62
62
|
$parcel$export($2f2af15db2572749$exports, "macAddress", () => $2f2af15db2572749$export$4aae620858fd13ea);
|
|
63
|
-
$parcel$export($2f2af15db2572749$exports, "emailAddress", () => $2f2af15db2572749$export$642aeeb6efe3bed1);
|
|
64
63
|
$parcel$export($2f2af15db2572749$exports, "commonPatterns", () => $2f2af15db2572749$export$a83d9d00fb7126e2);
|
|
65
64
|
// May caught ids, maybe needs to test this a bit more
|
|
66
65
|
const $2f2af15db2572749$export$1e20809441cc69a = /(0x)?[a-zA-Z0-9]{40,}/;
|
|
67
66
|
const $2f2af15db2572749$export$6a3b35e38f46684a = /[a-zA-Z0-9.]+\.eth/;
|
|
68
67
|
const $2f2af15db2572749$export$450e57019586b28f = /\d+\.\d+\.\d+\.\d+/;
|
|
69
68
|
const $2f2af15db2572749$export$4aae620858fd13ea = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/;
|
|
70
|
-
const $2f2af15db2572749$export$642aeeb6efe3bed1 = /[^@\s]+@[^@\s]+\.[^@\s]+/;
|
|
71
69
|
const $2f2af15db2572749$export$a83d9d00fb7126e2 = [
|
|
72
70
|
$2f2af15db2572749$export$1e20809441cc69a,
|
|
73
71
|
$2f2af15db2572749$export$6a3b35e38f46684a,
|
|
74
72
|
$2f2af15db2572749$export$450e57019586b28f,
|
|
75
|
-
$2f2af15db2572749$export$4aae620858fd13ea
|
|
76
|
-
$2f2af15db2572749$export$642aeeb6efe3bed1
|
|
73
|
+
$2f2af15db2572749$export$4aae620858fd13ea
|
|
77
74
|
];
|
|
78
75
|
|
|
79
76
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -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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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.cjs.map","sourceRoot":"../../../../"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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":"../../../../"}
|
package/dist/index.mjs
CHANGED
|
@@ -44,24 +44,21 @@ $parcel$export($a4f22c43dff7d58a$exports, "blockchainAddress", () => $a4f22c43df
|
|
|
44
44
|
$parcel$export($a4f22c43dff7d58a$exports, "ensAddress", () => $a4f22c43dff7d58a$export$6a3b35e38f46684a);
|
|
45
45
|
$parcel$export($a4f22c43dff7d58a$exports, "ipAddress", () => $a4f22c43dff7d58a$export$450e57019586b28f);
|
|
46
46
|
$parcel$export($a4f22c43dff7d58a$exports, "macAddress", () => $a4f22c43dff7d58a$export$4aae620858fd13ea);
|
|
47
|
-
$parcel$export($a4f22c43dff7d58a$exports, "emailAddress", () => $a4f22c43dff7d58a$export$642aeeb6efe3bed1);
|
|
48
47
|
$parcel$export($a4f22c43dff7d58a$exports, "commonPatterns", () => $a4f22c43dff7d58a$export$a83d9d00fb7126e2);
|
|
49
48
|
// May caught ids, maybe needs to test this a bit more
|
|
50
49
|
const $a4f22c43dff7d58a$export$1e20809441cc69a = /(0x)?[a-zA-Z0-9]{40,}/;
|
|
51
50
|
const $a4f22c43dff7d58a$export$6a3b35e38f46684a = /[a-zA-Z0-9.]+\.eth/;
|
|
52
51
|
const $a4f22c43dff7d58a$export$450e57019586b28f = /\d+\.\d+\.\d+\.\d+/;
|
|
53
52
|
const $a4f22c43dff7d58a$export$4aae620858fd13ea = /([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})/;
|
|
54
|
-
const $a4f22c43dff7d58a$export$642aeeb6efe3bed1 = /[^@\s]+@[^@\s]+\.[^@\s]+/;
|
|
55
53
|
const $a4f22c43dff7d58a$export$a83d9d00fb7126e2 = [
|
|
56
54
|
$a4f22c43dff7d58a$export$1e20809441cc69a,
|
|
57
55
|
$a4f22c43dff7d58a$export$6a3b35e38f46684a,
|
|
58
56
|
$a4f22c43dff7d58a$export$450e57019586b28f,
|
|
59
|
-
$a4f22c43dff7d58a$export$4aae620858fd13ea
|
|
60
|
-
$a4f22c43dff7d58a$export$642aeeb6efe3bed1
|
|
57
|
+
$a4f22c43dff7d58a$export$4aae620858fd13ea
|
|
61
58
|
];
|
|
62
59
|
|
|
63
60
|
|
|
64
61
|
|
|
65
62
|
|
|
66
|
-
export {$634bfa66b85378ba$export$4aabe16cd431674e as satanizer, $a4f22c43dff7d58a$export$1e20809441cc69a as blockchainAddress, $a4f22c43dff7d58a$export$6a3b35e38f46684a as ensAddress, $a4f22c43dff7d58a$export$450e57019586b28f as ipAddress, $a4f22c43dff7d58a$export$4aae620858fd13ea as macAddress, $a4f22c43dff7d58a$export$
|
|
63
|
+
export {$634bfa66b85378ba$export$4aabe16cd431674e as satanizer, $a4f22c43dff7d58a$export$1e20809441cc69a as blockchainAddress, $a4f22c43dff7d58a$export$6a3b35e38f46684a as ensAddress, $a4f22c43dff7d58a$export$450e57019586b28f as ipAddress, $a4f22c43dff7d58a$export$4aae620858fd13ea as macAddress, $a4f22c43dff7d58a$export$a83d9d00fb7126e2 as commonPatterns};
|
|
67
64
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,C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ClB,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":"../../../../"}
|
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.
|
|
6
|
+
"version": "0.17.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.
|
|
25
|
+
"@lidofinance/config-prettier": "~0.17.0",
|
|
26
26
|
"@types/jest": "^29.2.4",
|
|
27
27
|
"@types/node": "^18.11.17",
|
|
28
28
|
"jest": "^29.3.1",
|