@hackylabs/deep-redact 3.0.3 → 3.0.4
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/{cjs/index.js → index.js} +5 -5
- package/dist/{esm/index.mjs → index.mjs} +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/utils/index.d.ts +1 -18
- package/dist/types/utils/standardTransformers/bigint.d.ts +1 -1
- package/dist/types/utils/standardTransformers/date.d.ts +1 -1
- package/dist/types/utils/standardTransformers/error.d.ts +1 -1
- package/dist/types/utils/standardTransformers/index.d.ts +1 -1
- package/dist/types/utils/standardTransformers/map.d.ts +1 -1
- package/dist/types/utils/standardTransformers/regex.d.ts +1 -1
- package/dist/types/utils/standardTransformers/set.d.ts +1 -1
- package/dist/types/utils/standardTransformers/url.d.ts +1 -1
- package/dist/{cjs/utils → utils}/index.js +31 -53
- package/dist/{esm/utils → utils}/index.mjs +21 -41
- package/dist/utils/standardTransformers/index.js +38 -0
- package/dist/{esm/utils/standardTransformers/index.js → utils/standardTransformers/index.mjs} +7 -7
- package/package.json +42 -41
- package/dist/cjs/utils/standardTransformers/index.js +0 -38
- /package/dist/{cjs/types.js → types.js} +0 -0
- /package/dist/{esm/types.mjs → types.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/TransformerRegistry.js +0 -0
- /package/dist/{esm/utils → utils}/TransformerRegistry.mjs +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/bigint.js +0 -0
- /package/dist/{esm/utils/standardTransformers/bigint.js → utils/standardTransformers/bigint.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/date.js +0 -0
- /package/dist/{esm/utils/standardTransformers/date.js → utils/standardTransformers/date.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/error.js +0 -0
- /package/dist/{esm/utils/standardTransformers/error.js → utils/standardTransformers/error.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/map.js +0 -0
- /package/dist/{esm/utils/standardTransformers/map.js → utils/standardTransformers/map.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/regex.js +0 -0
- /package/dist/{esm/utils/standardTransformers/regex.js → utils/standardTransformers/regex.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/set.js +0 -0
- /package/dist/{esm/utils/standardTransformers/set.js → utils/standardTransformers/set.mjs} +0 -0
- /package/dist/{cjs/utils → utils}/standardTransformers/url.js +0 -0
- /package/dist/{esm/utils/standardTransformers/url.js → utils/standardTransformers/url.mjs} +0 -0
|
@@ -15,10 +15,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.organisedStandardTransformers = exports.standardTransformers = exports.default = exports.DeepRedact = void 0;
|
|
18
|
-
const
|
|
19
|
-
Object.defineProperty(exports, "organisedStandardTransformers", { enumerable: true, get: function () { return
|
|
20
|
-
Object.defineProperty(exports, "standardTransformers", { enumerable: true, get: function () { return
|
|
21
|
-
const
|
|
18
|
+
const index_js_1 = require("./utils/standardTransformers/index.js");
|
|
19
|
+
Object.defineProperty(exports, "organisedStandardTransformers", { enumerable: true, get: function () { return index_js_1.organisedStandardTransformers; } });
|
|
20
|
+
Object.defineProperty(exports, "standardTransformers", { enumerable: true, get: function () { return index_js_1.standardTransformers; } });
|
|
21
|
+
const index_js_2 = __importDefault(require("./utils/index.js"));
|
|
22
22
|
class DeepRedact {
|
|
23
23
|
/**
|
|
24
24
|
* Create a new DeepRedact instance with the provided configuration.
|
|
@@ -48,7 +48,7 @@ class DeepRedact {
|
|
|
48
48
|
const englishSerialise = serialise !== null && serialise !== void 0 ? serialise : serialize;
|
|
49
49
|
if (typeof englishSerialise === 'boolean')
|
|
50
50
|
this.config.serialise = englishSerialise;
|
|
51
|
-
this.redactorUtils = new
|
|
51
|
+
this.redactorUtils = new index_js_2.default(Object.assign({}, rest));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
exports.DeepRedact = DeepRedact;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { organisedStandardTransformers, standardTransformers } from './utils/standardTransformers';
|
|
2
|
-
import RedactorUtils from './utils';
|
|
1
|
+
import { organisedStandardTransformers, standardTransformers } from './utils/standardTransformers/index.mjs';
|
|
2
|
+
import RedactorUtils from './utils/index.mjs';
|
|
3
3
|
class DeepRedact {
|
|
4
4
|
/**
|
|
5
5
|
* The redactorUtils instance to handle the redaction.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DeepRedactConfig, RedactorUtilsConfig, BlacklistKeyConfig, Types, Transformer, ComplexStringTest, BaseDeepRedactConfig, OrganisedTransformers, TransformerConfig } from './types';
|
|
2
|
-
import { organisedStandardTransformers, standardTransformers } from './utils/standardTransformers';
|
|
1
|
+
import type { DeepRedactConfig, RedactorUtilsConfig, BlacklistKeyConfig, Types, Transformer, ComplexStringTest, BaseDeepRedactConfig, OrganisedTransformers, TransformerConfig } from './types.js';
|
|
2
|
+
import { organisedStandardTransformers, standardTransformers } from './utils/standardTransformers/index.js';
|
|
3
3
|
declare class DeepRedact {
|
|
4
4
|
/**
|
|
5
5
|
* The redactorUtils instance to handle the redaction.
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
import type { RedactorUtilsConfig } from '../types';
|
|
1
|
+
import type { RedactorUtilsConfig } from '../types.js';
|
|
2
2
|
declare class RedactorUtils {
|
|
3
3
|
/**
|
|
4
4
|
* The configuration for the redaction.
|
|
5
5
|
* @private
|
|
6
6
|
*/
|
|
7
7
|
private readonly config;
|
|
8
|
-
/**
|
|
9
|
-
* The computed regex pattern generated from sanitised blacklist keys of flat strings
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
private readonly computedRegex;
|
|
13
|
-
/**
|
|
14
|
-
* Regex to sanitise strings for the computed regex
|
|
15
|
-
* @private
|
|
16
|
-
*/
|
|
17
|
-
private readonly sanitiseRegex;
|
|
18
8
|
/**
|
|
19
9
|
* The transformed blacklist keys of flat regex patterns and complex config objects
|
|
20
10
|
* @private
|
|
@@ -41,13 +31,6 @@ declare class RedactorUtils {
|
|
|
41
31
|
* @private
|
|
42
32
|
*/
|
|
43
33
|
private applyTransformers;
|
|
44
|
-
/**
|
|
45
|
-
* Sanitises a string for the computed regex
|
|
46
|
-
* @param key - The string to sanitise
|
|
47
|
-
* @returns The sanitised string
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
private sanitiseStringForRegex;
|
|
51
34
|
/**
|
|
52
35
|
* Checks if a key should be redacted
|
|
53
36
|
* @param key - The key to check
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from '../../types';
|
|
1
|
+
import type { Transformer } from '../../types.js';
|
|
2
2
|
export declare const _bigint: Transformer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from "../../types";
|
|
1
|
+
import type { Transformer } from "../../types.js";
|
|
2
2
|
export declare const _date: Transformer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from "../../types";
|
|
1
|
+
import type { Transformer } from "../../types.js";
|
|
2
2
|
export declare const _error: Transformer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from "../../types";
|
|
1
|
+
import type { Transformer } from "../../types.js";
|
|
2
2
|
export declare const _map: Transformer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from "../../types";
|
|
1
|
+
import type { Transformer } from "../../types.js";
|
|
2
2
|
export declare const _regex: Transformer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from "../../types";
|
|
1
|
+
import type { Transformer } from "../../types.js";
|
|
2
2
|
export declare const _set: Transformer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Transformer } from
|
|
1
|
+
import type { Transformer } from "../../types.js";
|
|
2
2
|
export declare const _url: Transformer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const index_js_1 = require("./standardTransformers/index.js");
|
|
4
|
+
const TransformerRegistry_js_1 = require("./TransformerRegistry.js");
|
|
5
5
|
const defaultConfig = {
|
|
6
6
|
stringTests: [],
|
|
7
7
|
blacklistedKeys: [],
|
|
@@ -12,26 +12,16 @@ const defaultConfig = {
|
|
|
12
12
|
replaceStringByLength: false,
|
|
13
13
|
replacement: '[REDACTED]',
|
|
14
14
|
types: ['string'],
|
|
15
|
-
transformers:
|
|
15
|
+
transformers: index_js_1.standardTransformers,
|
|
16
16
|
};
|
|
17
17
|
class RedactorUtils {
|
|
18
18
|
constructor(customConfig) {
|
|
19
|
-
var _a
|
|
19
|
+
var _a;
|
|
20
20
|
/**
|
|
21
21
|
* The configuration for the redaction.
|
|
22
22
|
* @private
|
|
23
23
|
*/
|
|
24
24
|
this.config = defaultConfig;
|
|
25
|
-
/**
|
|
26
|
-
* The computed regex pattern generated from sanitised blacklist keys of flat strings
|
|
27
|
-
* @private
|
|
28
|
-
*/
|
|
29
|
-
this.computedRegex = null;
|
|
30
|
-
/**
|
|
31
|
-
* Regex to sanitise strings for the computed regex
|
|
32
|
-
* @private
|
|
33
|
-
*/
|
|
34
|
-
this.sanitiseRegex = /[^a-zA-Z0-9_\-\$]/g;
|
|
35
25
|
/**
|
|
36
26
|
* The transformed blacklist keys of flat regex patterns and complex config objects
|
|
37
27
|
* @private
|
|
@@ -41,9 +31,9 @@ class RedactorUtils {
|
|
|
41
31
|
* The transformer registry for efficient transformer lookup
|
|
42
32
|
* @private
|
|
43
33
|
*/
|
|
44
|
-
this.transformerRegistry = new
|
|
34
|
+
this.transformerRegistry = new TransformerRegistry_js_1.TransformerRegistry();
|
|
45
35
|
this.createTransformedBlacklistedKey = (key, customConfig) => {
|
|
46
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
47
37
|
if (key instanceof RegExp) {
|
|
48
38
|
return {
|
|
49
39
|
key,
|
|
@@ -55,13 +45,24 @@ class RedactorUtils {
|
|
|
55
45
|
remove: (_f = customConfig.remove) !== null && _f !== void 0 ? _f : defaultConfig.remove,
|
|
56
46
|
};
|
|
57
47
|
}
|
|
48
|
+
if (typeof key === 'string') {
|
|
49
|
+
return {
|
|
50
|
+
key,
|
|
51
|
+
fuzzyKeyMatch: (_g = customConfig.fuzzyKeyMatch) !== null && _g !== void 0 ? _g : defaultConfig.fuzzyKeyMatch,
|
|
52
|
+
caseSensitiveKeyMatch: (_h = customConfig.caseSensitiveKeyMatch) !== null && _h !== void 0 ? _h : defaultConfig.caseSensitiveKeyMatch,
|
|
53
|
+
retainStructure: (_j = customConfig.retainStructure) !== null && _j !== void 0 ? _j : defaultConfig.retainStructure,
|
|
54
|
+
replacement: (_k = customConfig.replacement) !== null && _k !== void 0 ? _k : defaultConfig.replacement,
|
|
55
|
+
replaceStringByLength: (_l = customConfig.replaceStringByLength) !== null && _l !== void 0 ? _l : defaultConfig.replaceStringByLength,
|
|
56
|
+
remove: (_m = customConfig.remove) !== null && _m !== void 0 ? _m : defaultConfig.remove,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
58
59
|
return {
|
|
59
|
-
fuzzyKeyMatch: (
|
|
60
|
-
caseSensitiveKeyMatch: (
|
|
61
|
-
retainStructure: (
|
|
62
|
-
replacement: (
|
|
63
|
-
replaceStringByLength: (
|
|
64
|
-
remove: (
|
|
60
|
+
fuzzyKeyMatch: (_p = (_o = key.fuzzyKeyMatch) !== null && _o !== void 0 ? _o : customConfig.fuzzyKeyMatch) !== null && _p !== void 0 ? _p : defaultConfig.fuzzyKeyMatch,
|
|
61
|
+
caseSensitiveKeyMatch: (_r = (_q = key.caseSensitiveKeyMatch) !== null && _q !== void 0 ? _q : customConfig.caseSensitiveKeyMatch) !== null && _r !== void 0 ? _r : defaultConfig.caseSensitiveKeyMatch,
|
|
62
|
+
retainStructure: (_t = (_s = key.retainStructure) !== null && _s !== void 0 ? _s : customConfig.retainStructure) !== null && _t !== void 0 ? _t : defaultConfig.retainStructure,
|
|
63
|
+
replacement: (_v = (_u = key.replacement) !== null && _u !== void 0 ? _u : customConfig.replacement) !== null && _v !== void 0 ? _v : defaultConfig.replacement,
|
|
64
|
+
replaceStringByLength: (_x = (_w = key.replaceStringByLength) !== null && _w !== void 0 ? _w : customConfig.replaceStringByLength) !== null && _x !== void 0 ? _x : defaultConfig.replaceStringByLength,
|
|
65
|
+
remove: (_z = (_y = key.remove) !== null && _y !== void 0 ? _y : customConfig.remove) !== null && _z !== void 0 ? _z : defaultConfig.remove,
|
|
65
66
|
key: key.key,
|
|
66
67
|
};
|
|
67
68
|
};
|
|
@@ -75,13 +76,6 @@ class RedactorUtils {
|
|
|
75
76
|
this.applyTransformers = (value, key, referenceMap) => {
|
|
76
77
|
return this.transformerRegistry.applyTransformers(value, key, referenceMap);
|
|
77
78
|
};
|
|
78
|
-
/**
|
|
79
|
-
* Sanitises a string for the computed regex
|
|
80
|
-
* @param key - The string to sanitise
|
|
81
|
-
* @returns The sanitised string
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
this.sanitiseStringForRegex = (key) => key.replace(this.sanitiseRegex, '');
|
|
85
79
|
/**
|
|
86
80
|
* Checks if a key should be redacted
|
|
87
81
|
* @param key - The key to check
|
|
@@ -89,17 +83,14 @@ class RedactorUtils {
|
|
|
89
83
|
* @private
|
|
90
84
|
*/
|
|
91
85
|
this.shouldRedactKey = (key) => {
|
|
92
|
-
var _a;
|
|
93
|
-
if ((_a = this.computedRegex) === null || _a === void 0 ? void 0 : _a.test(this.sanitiseStringForRegex(key)))
|
|
94
|
-
return true;
|
|
95
86
|
return this.blacklistedKeysTransformed.some(config => {
|
|
96
87
|
const pattern = config.key;
|
|
97
88
|
if (pattern instanceof RegExp)
|
|
98
89
|
return pattern.test(key);
|
|
99
90
|
if (!config.fuzzyKeyMatch && !config.caseSensitiveKeyMatch)
|
|
100
|
-
return key.toLowerCase() === pattern.toLowerCase();
|
|
91
|
+
return key.toLowerCase().trim().replace(/[_-]/g, '') === pattern.toLowerCase().trim().replace(/[_-]/g, '');
|
|
101
92
|
if (config.fuzzyKeyMatch && !config.caseSensitiveKeyMatch)
|
|
102
|
-
return key.toLowerCase().includes(pattern.toLowerCase());
|
|
93
|
+
return key.toLowerCase().trim().replace(/[_-]/g, '').includes(pattern.toLowerCase().trim().replace(/[_-]/g, ''));
|
|
103
94
|
if (config.fuzzyKeyMatch && config.caseSensitiveKeyMatch)
|
|
104
95
|
return key.includes(pattern);
|
|
105
96
|
if (!config.fuzzyKeyMatch && config.caseSensitiveKeyMatch)
|
|
@@ -186,10 +177,7 @@ class RedactorUtils {
|
|
|
186
177
|
return output;
|
|
187
178
|
};
|
|
188
179
|
this.config = Object.assign(Object.assign({}, defaultConfig), customConfig);
|
|
189
|
-
this.blacklistedKeysTransformed = ((_a = customConfig.blacklistedKeys) !== null && _a !== void 0 ? _a : []).
|
|
190
|
-
const stringKeys = ((_b = customConfig.blacklistedKeys) !== null && _b !== void 0 ? _b : []).filter(key => typeof key === 'string');
|
|
191
|
-
if (stringKeys.length > 0)
|
|
192
|
-
this.computedRegex = new RegExp(stringKeys.map(this.sanitiseStringForRegex).filter(Boolean).join('|'));
|
|
180
|
+
this.blacklistedKeysTransformed = ((_a = customConfig.blacklistedKeys) !== null && _a !== void 0 ? _a : []).map((key) => this.createTransformedBlacklistedKey(key, customConfig));
|
|
193
181
|
this.setupTransformerRegistry(this.config.transformers);
|
|
194
182
|
}
|
|
195
183
|
/**
|
|
@@ -352,28 +340,18 @@ class RedactorUtils {
|
|
|
352
340
|
* @private
|
|
353
341
|
*/
|
|
354
342
|
findMatchingKeyConfig(key) {
|
|
355
|
-
var _a;
|
|
356
|
-
if ((_a = this.computedRegex) === null || _a === void 0 ? void 0 : _a.test(key)) {
|
|
357
|
-
return {
|
|
358
|
-
key,
|
|
359
|
-
fuzzyKeyMatch: this.config.fuzzyKeyMatch,
|
|
360
|
-
caseSensitiveKeyMatch: this.config.caseSensitiveKeyMatch,
|
|
361
|
-
replaceStringByLength: this.config.replaceStringByLength,
|
|
362
|
-
replacement: this.config.replacement,
|
|
363
|
-
retainStructure: this.config.retainStructure,
|
|
364
|
-
remove: this.config.remove,
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
343
|
return this.blacklistedKeysTransformed.find(config => {
|
|
368
344
|
const pattern = config.key;
|
|
369
345
|
if (pattern instanceof RegExp)
|
|
370
346
|
return pattern.test(key);
|
|
347
|
+
const normalisedKey = key.toLowerCase().trim().replace(/[_-]/g, '');
|
|
348
|
+
const normalisedPattern = pattern.toLowerCase().trim().replace(/[_-]/g, '');
|
|
371
349
|
if (config.fuzzyKeyMatch) {
|
|
372
|
-
const compareKey = config.caseSensitiveKeyMatch ? key :
|
|
373
|
-
const comparePattern = config.caseSensitiveKeyMatch ? pattern :
|
|
350
|
+
const compareKey = config.caseSensitiveKeyMatch ? key : normalisedKey;
|
|
351
|
+
const comparePattern = config.caseSensitiveKeyMatch ? pattern : normalisedPattern;
|
|
374
352
|
return compareKey.includes(comparePattern);
|
|
375
353
|
}
|
|
376
|
-
return config.caseSensitiveKeyMatch ? key === pattern :
|
|
354
|
+
return config.caseSensitiveKeyMatch ? key === pattern : normalisedKey === normalisedPattern;
|
|
377
355
|
});
|
|
378
356
|
}
|
|
379
357
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { standardTransformers } from './standardTransformers';
|
|
2
|
-
import { TransformerRegistry } from './TransformerRegistry';
|
|
1
|
+
import { standardTransformers } from './standardTransformers/index.mjs';
|
|
2
|
+
import { TransformerRegistry } from './TransformerRegistry.mjs';
|
|
3
3
|
const defaultConfig = {
|
|
4
4
|
stringTests: [],
|
|
5
5
|
blacklistedKeys: [],
|
|
@@ -18,16 +18,6 @@ class RedactorUtils {
|
|
|
18
18
|
* @private
|
|
19
19
|
*/
|
|
20
20
|
config = defaultConfig;
|
|
21
|
-
/**
|
|
22
|
-
* The computed regex pattern generated from sanitised blacklist keys of flat strings
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
computedRegex = null;
|
|
26
|
-
/**
|
|
27
|
-
* Regex to sanitise strings for the computed regex
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
|
-
sanitiseRegex = /[^a-zA-Z0-9_\-\$]/g;
|
|
31
21
|
/**
|
|
32
22
|
* The transformed blacklist keys of flat regex patterns and complex config objects
|
|
33
23
|
* @private
|
|
@@ -43,10 +33,7 @@ class RedactorUtils {
|
|
|
43
33
|
...defaultConfig,
|
|
44
34
|
...customConfig,
|
|
45
35
|
};
|
|
46
|
-
this.blacklistedKeysTransformed = (customConfig.blacklistedKeys ?? []).
|
|
47
|
-
const stringKeys = (customConfig.blacklistedKeys ?? []).filter(key => typeof key === 'string');
|
|
48
|
-
if (stringKeys.length > 0)
|
|
49
|
-
this.computedRegex = new RegExp(stringKeys.map(this.sanitiseStringForRegex).filter(Boolean).join('|'));
|
|
36
|
+
this.blacklistedKeysTransformed = (customConfig.blacklistedKeys ?? []).map((key) => this.createTransformedBlacklistedKey(key, customConfig));
|
|
50
37
|
this.setupTransformerRegistry(this.config.transformers);
|
|
51
38
|
}
|
|
52
39
|
/**
|
|
@@ -103,6 +90,17 @@ class RedactorUtils {
|
|
|
103
90
|
remove: customConfig.remove ?? defaultConfig.remove,
|
|
104
91
|
};
|
|
105
92
|
}
|
|
93
|
+
if (typeof key === 'string') {
|
|
94
|
+
return {
|
|
95
|
+
key,
|
|
96
|
+
fuzzyKeyMatch: customConfig.fuzzyKeyMatch ?? defaultConfig.fuzzyKeyMatch,
|
|
97
|
+
caseSensitiveKeyMatch: customConfig.caseSensitiveKeyMatch ?? defaultConfig.caseSensitiveKeyMatch,
|
|
98
|
+
retainStructure: customConfig.retainStructure ?? defaultConfig.retainStructure,
|
|
99
|
+
replacement: customConfig.replacement ?? defaultConfig.replacement,
|
|
100
|
+
replaceStringByLength: customConfig.replaceStringByLength ?? defaultConfig.replaceStringByLength,
|
|
101
|
+
remove: customConfig.remove ?? defaultConfig.remove,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
106
104
|
return {
|
|
107
105
|
fuzzyKeyMatch: key.fuzzyKeyMatch ?? customConfig.fuzzyKeyMatch ?? defaultConfig.fuzzyKeyMatch,
|
|
108
106
|
caseSensitiveKeyMatch: key.caseSensitiveKeyMatch ?? customConfig.caseSensitiveKeyMatch ?? defaultConfig.caseSensitiveKeyMatch,
|
|
@@ -123,13 +121,6 @@ class RedactorUtils {
|
|
|
123
121
|
applyTransformers = (value, key, referenceMap) => {
|
|
124
122
|
return this.transformerRegistry.applyTransformers(value, key, referenceMap);
|
|
125
123
|
};
|
|
126
|
-
/**
|
|
127
|
-
* Sanitises a string for the computed regex
|
|
128
|
-
* @param key - The string to sanitise
|
|
129
|
-
* @returns The sanitised string
|
|
130
|
-
* @private
|
|
131
|
-
*/
|
|
132
|
-
sanitiseStringForRegex = (key) => key.replace(this.sanitiseRegex, '');
|
|
133
124
|
/**
|
|
134
125
|
* Checks if a key should be redacted
|
|
135
126
|
* @param key - The key to check
|
|
@@ -137,16 +128,14 @@ class RedactorUtils {
|
|
|
137
128
|
* @private
|
|
138
129
|
*/
|
|
139
130
|
shouldRedactKey = (key) => {
|
|
140
|
-
if (this.computedRegex?.test(this.sanitiseStringForRegex(key)))
|
|
141
|
-
return true;
|
|
142
131
|
return this.blacklistedKeysTransformed.some(config => {
|
|
143
132
|
const pattern = config.key;
|
|
144
133
|
if (pattern instanceof RegExp)
|
|
145
134
|
return pattern.test(key);
|
|
146
135
|
if (!config.fuzzyKeyMatch && !config.caseSensitiveKeyMatch)
|
|
147
|
-
return key.toLowerCase() === pattern.toLowerCase();
|
|
136
|
+
return key.toLowerCase().trim().replace(/[_-]/g, '') === pattern.toLowerCase().trim().replace(/[_-]/g, '');
|
|
148
137
|
if (config.fuzzyKeyMatch && !config.caseSensitiveKeyMatch)
|
|
149
|
-
return key.toLowerCase().includes(pattern.toLowerCase());
|
|
138
|
+
return key.toLowerCase().trim().replace(/[_-]/g, '').includes(pattern.toLowerCase().trim().replace(/[_-]/g, ''));
|
|
150
139
|
if (config.fuzzyKeyMatch && config.caseSensitiveKeyMatch)
|
|
151
140
|
return key.includes(pattern);
|
|
152
141
|
if (!config.fuzzyKeyMatch && config.caseSensitiveKeyMatch)
|
|
@@ -309,27 +298,18 @@ class RedactorUtils {
|
|
|
309
298
|
* @private
|
|
310
299
|
*/
|
|
311
300
|
findMatchingKeyConfig(key) {
|
|
312
|
-
if (this.computedRegex?.test(key)) {
|
|
313
|
-
return {
|
|
314
|
-
key,
|
|
315
|
-
fuzzyKeyMatch: this.config.fuzzyKeyMatch,
|
|
316
|
-
caseSensitiveKeyMatch: this.config.caseSensitiveKeyMatch,
|
|
317
|
-
replaceStringByLength: this.config.replaceStringByLength,
|
|
318
|
-
replacement: this.config.replacement,
|
|
319
|
-
retainStructure: this.config.retainStructure,
|
|
320
|
-
remove: this.config.remove,
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
301
|
return this.blacklistedKeysTransformed.find(config => {
|
|
324
302
|
const pattern = config.key;
|
|
325
303
|
if (pattern instanceof RegExp)
|
|
326
304
|
return pattern.test(key);
|
|
305
|
+
const normalisedKey = key.toLowerCase().trim().replace(/[_-]/g, '');
|
|
306
|
+
const normalisedPattern = pattern.toLowerCase().trim().replace(/[_-]/g, '');
|
|
327
307
|
if (config.fuzzyKeyMatch) {
|
|
328
|
-
const compareKey = config.caseSensitiveKeyMatch ? key :
|
|
329
|
-
const comparePattern = config.caseSensitiveKeyMatch ? pattern :
|
|
308
|
+
const compareKey = config.caseSensitiveKeyMatch ? key : normalisedKey;
|
|
309
|
+
const comparePattern = config.caseSensitiveKeyMatch ? pattern : normalisedPattern;
|
|
330
310
|
return compareKey.includes(comparePattern);
|
|
331
311
|
}
|
|
332
|
-
return config.caseSensitiveKeyMatch ? key === pattern :
|
|
312
|
+
return config.caseSensitiveKeyMatch ? key === pattern : normalisedKey === normalisedPattern;
|
|
333
313
|
});
|
|
334
314
|
}
|
|
335
315
|
/**
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.organisedStandardTransformers = exports.standardTransformers = void 0;
|
|
4
|
+
const bigint_js_1 = require("./bigint.js");
|
|
5
|
+
const date_js_1 = require("./date.js");
|
|
6
|
+
const error_js_1 = require("./error.js");
|
|
7
|
+
const map_js_1 = require("./map.js");
|
|
8
|
+
const regex_js_1 = require("./regex.js");
|
|
9
|
+
const set_js_1 = require("./set.js");
|
|
10
|
+
const url_js_1 = require("./url.js");
|
|
11
|
+
/**
|
|
12
|
+
* Standard transformers in array for legacy support
|
|
13
|
+
*/
|
|
14
|
+
exports.standardTransformers = [
|
|
15
|
+
bigint_js_1._bigint,
|
|
16
|
+
date_js_1._date,
|
|
17
|
+
error_js_1._error,
|
|
18
|
+
map_js_1._map,
|
|
19
|
+
regex_js_1._regex,
|
|
20
|
+
set_js_1._set,
|
|
21
|
+
url_js_1._url,
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Standard transformers organised by type and constructor for performance reasons
|
|
25
|
+
*/
|
|
26
|
+
exports.organisedStandardTransformers = {
|
|
27
|
+
byType: {
|
|
28
|
+
bigint: [bigint_js_1._bigint],
|
|
29
|
+
},
|
|
30
|
+
byConstructor: {
|
|
31
|
+
URL: [url_js_1._url],
|
|
32
|
+
Date: [date_js_1._date],
|
|
33
|
+
Error: [error_js_1._error],
|
|
34
|
+
Map: [map_js_1._map],
|
|
35
|
+
Set: [set_js_1._set],
|
|
36
|
+
RegExp: [regex_js_1._regex],
|
|
37
|
+
},
|
|
38
|
+
};
|
package/dist/{esm/utils/standardTransformers/index.js → utils/standardTransformers/index.mjs}
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { _bigint } from
|
|
2
|
-
import { _date } from
|
|
3
|
-
import { _error } from
|
|
4
|
-
import { _map } from
|
|
5
|
-
import { _regex } from
|
|
6
|
-
import { _set } from
|
|
7
|
-
import { _url } from
|
|
1
|
+
import { _bigint } from "./bigint.mjs";
|
|
2
|
+
import { _date } from "./date.mjs";
|
|
3
|
+
import { _error } from "./error.mjs";
|
|
4
|
+
import { _map } from "./map.mjs";
|
|
5
|
+
import { _regex } from "./regex.mjs";
|
|
6
|
+
import { _set } from "./set.mjs";
|
|
7
|
+
import { _url } from "./url.mjs";
|
|
8
8
|
/**
|
|
9
9
|
* Standard transformers in array for legacy support
|
|
10
10
|
*/
|
package/package.json
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hackylabs/deep-redact",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
4
4
|
"description": "A fast, safe and configurable zero-dependency library for redacting strings or deeply redacting arrays and objects.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Benjamin Green (https://bengreen.dev)",
|
|
8
8
|
"funding": "https://ko-fi.com/hackylabs",
|
|
9
9
|
"types": "./dist/types/index.d.ts",
|
|
10
|
-
"main": "./dist/
|
|
11
|
-
"module": "./dist/
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.mjs",
|
|
12
12
|
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"import": "./dist/
|
|
15
|
-
"require": "./dist/
|
|
13
|
+
"./index.ts": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
16
|
"types": "./dist/types/index.d.ts"
|
|
17
17
|
},
|
|
18
|
-
"./types": {
|
|
19
|
-
"import": "./dist/
|
|
20
|
-
"require": "./dist/
|
|
18
|
+
"./types.ts": {
|
|
19
|
+
"import": "./dist/types.mjs",
|
|
20
|
+
"require": "./dist/types.js",
|
|
21
21
|
"types": "./dist/types/types.d.ts"
|
|
22
22
|
},
|
|
23
|
-
"./utils/TransformerRegistry": {
|
|
24
|
-
"import": "./dist/
|
|
25
|
-
"require": "./dist/
|
|
23
|
+
"./utils/TransformerRegistry.ts": {
|
|
24
|
+
"import": "./dist/utils/TransformerRegistry.mjs",
|
|
25
|
+
"require": "./dist/utils/TransformerRegistry.js",
|
|
26
26
|
"types": "./dist/types/utils/TransformerRegistry.d.ts"
|
|
27
27
|
},
|
|
28
|
-
"./utils": {
|
|
29
|
-
"import": "./dist/
|
|
30
|
-
"require": "./dist/
|
|
31
|
-
"types": "./dist/types/utils.d.ts"
|
|
28
|
+
"./utils/index.ts": {
|
|
29
|
+
"import": "./dist/utils/index.mjs",
|
|
30
|
+
"require": "./dist/utils/index.js",
|
|
31
|
+
"types": "./dist/types/utils/index.d.ts"
|
|
32
32
|
},
|
|
33
|
-
"./utils/standardTransformers/bigint": {
|
|
34
|
-
"import": "./dist/
|
|
35
|
-
"require": "./dist/
|
|
33
|
+
"./utils/standardTransformers/bigint.ts": {
|
|
34
|
+
"import": "./dist/utils/standardTransformers/bigint.mjs",
|
|
35
|
+
"require": "./dist/utils/standardTransformers/bigint.js",
|
|
36
36
|
"types": "./dist/types/utils/standardTransformers/bigint.d.ts"
|
|
37
37
|
},
|
|
38
|
-
"./utils/standardTransformers/date": {
|
|
39
|
-
"import": "./dist/
|
|
40
|
-
"require": "./dist/
|
|
38
|
+
"./utils/standardTransformers/date.ts": {
|
|
39
|
+
"import": "./dist/utils/standardTransformers/date.mjs",
|
|
40
|
+
"require": "./dist/utils/standardTransformers/date.js",
|
|
41
41
|
"types": "./dist/types/utils/standardTransformers/date.d.ts"
|
|
42
42
|
},
|
|
43
|
-
"./utils/standardTransformers/error": {
|
|
44
|
-
"import": "./dist/
|
|
45
|
-
"require": "./dist/
|
|
43
|
+
"./utils/standardTransformers/error.ts": {
|
|
44
|
+
"import": "./dist/utils/standardTransformers/error.mjs",
|
|
45
|
+
"require": "./dist/utils/standardTransformers/error.js",
|
|
46
46
|
"types": "./dist/types/utils/standardTransformers/error.d.ts"
|
|
47
47
|
},
|
|
48
|
-
"./utils/standardTransformers": {
|
|
49
|
-
"import": "./dist/
|
|
50
|
-
"require": "./dist/
|
|
51
|
-
"types": "./dist/types/utils/standardTransformers.d.ts"
|
|
48
|
+
"./utils/standardTransformers/index.ts": {
|
|
49
|
+
"import": "./dist/utils/standardTransformers/index.mjs",
|
|
50
|
+
"require": "./dist/utils/standardTransformers/index.js",
|
|
51
|
+
"types": "./dist/types/utils/standardTransformers/index.d.ts"
|
|
52
52
|
},
|
|
53
|
-
"./utils/standardTransformers/map": {
|
|
54
|
-
"import": "./dist/
|
|
55
|
-
"require": "./dist/
|
|
53
|
+
"./utils/standardTransformers/map.ts": {
|
|
54
|
+
"import": "./dist/utils/standardTransformers/map.mjs",
|
|
55
|
+
"require": "./dist/utils/standardTransformers/map.js",
|
|
56
56
|
"types": "./dist/types/utils/standardTransformers/map.d.ts"
|
|
57
57
|
},
|
|
58
|
-
"./utils/standardTransformers/regex": {
|
|
59
|
-
"import": "./dist/
|
|
60
|
-
"require": "./dist/
|
|
58
|
+
"./utils/standardTransformers/regex.ts": {
|
|
59
|
+
"import": "./dist/utils/standardTransformers/regex.mjs",
|
|
60
|
+
"require": "./dist/utils/standardTransformers/regex.js",
|
|
61
61
|
"types": "./dist/types/utils/standardTransformers/regex.d.ts"
|
|
62
62
|
},
|
|
63
|
-
"./utils/standardTransformers/set": {
|
|
64
|
-
"import": "./dist/
|
|
65
|
-
"require": "./dist/
|
|
63
|
+
"./utils/standardTransformers/set.ts": {
|
|
64
|
+
"import": "./dist/utils/standardTransformers/set.mjs",
|
|
65
|
+
"require": "./dist/utils/standardTransformers/set.js",
|
|
66
66
|
"types": "./dist/types/utils/standardTransformers/set.d.ts"
|
|
67
67
|
},
|
|
68
|
-
"./utils/standardTransformers/url": {
|
|
69
|
-
"import": "./dist/
|
|
70
|
-
"require": "./dist/
|
|
68
|
+
"./utils/standardTransformers/url.ts": {
|
|
69
|
+
"import": "./dist/utils/standardTransformers/url.mjs",
|
|
70
|
+
"require": "./dist/utils/standardTransformers/url.js",
|
|
71
71
|
"types": "./dist/types/utils/standardTransformers/url.d.ts"
|
|
72
72
|
}
|
|
73
73
|
},
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"scripts": {
|
|
103
103
|
"lint": "eslint",
|
|
104
104
|
"build": "npm run lint && npm run test && npm run bench && npm run build:esm && npm run build:cjs && npm run update-exports && npm run test:build && npm run update-readme && npm run update-license",
|
|
105
|
+
"build:dev": "rm -rf dist && npm run build:esm && npm run build:cjs && npm run update-exports",
|
|
105
106
|
"build:esm": "tsc --project tsconfig.esm.json && ./scripts/js-to-mjs.sh",
|
|
106
107
|
"build:cjs": "tsc --project tsconfig.cjs.json",
|
|
107
108
|
"bench": "npx vitest bench --watch=false",
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.organisedStandardTransformers = exports.standardTransformers = void 0;
|
|
4
|
-
const bigint_1 = require("./bigint");
|
|
5
|
-
const date_1 = require("./date");
|
|
6
|
-
const error_1 = require("./error");
|
|
7
|
-
const map_1 = require("./map");
|
|
8
|
-
const regex_1 = require("./regex");
|
|
9
|
-
const set_1 = require("./set");
|
|
10
|
-
const url_1 = require("./url");
|
|
11
|
-
/**
|
|
12
|
-
* Standard transformers in array for legacy support
|
|
13
|
-
*/
|
|
14
|
-
exports.standardTransformers = [
|
|
15
|
-
bigint_1._bigint,
|
|
16
|
-
date_1._date,
|
|
17
|
-
error_1._error,
|
|
18
|
-
map_1._map,
|
|
19
|
-
regex_1._regex,
|
|
20
|
-
set_1._set,
|
|
21
|
-
url_1._url,
|
|
22
|
-
];
|
|
23
|
-
/**
|
|
24
|
-
* Standard transformers organised by type and constructor for performance reasons
|
|
25
|
-
*/
|
|
26
|
-
exports.organisedStandardTransformers = {
|
|
27
|
-
byType: {
|
|
28
|
-
bigint: [bigint_1._bigint],
|
|
29
|
-
},
|
|
30
|
-
byConstructor: {
|
|
31
|
-
URL: [url_1._url],
|
|
32
|
-
Date: [date_1._date],
|
|
33
|
-
Error: [error_1._error],
|
|
34
|
-
Map: [map_1._map],
|
|
35
|
-
Set: [set_1._set],
|
|
36
|
-
RegExp: [regex_1._regex],
|
|
37
|
-
},
|
|
38
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/{esm/utils/standardTransformers/bigint.js → utils/standardTransformers/bigint.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/{esm/utils/standardTransformers/date.js → utils/standardTransformers/date.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/{esm/utils/standardTransformers/error.js → utils/standardTransformers/error.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/{esm/utils/standardTransformers/regex.js → utils/standardTransformers/regex.mjs}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|