field-redactor 1.2.0 → 1.5.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.
Files changed (123) hide show
  1. package/.github/workflows/ci.yml +38 -0
  2. package/CHANGELOG.md +156 -0
  3. package/README.md +64 -670
  4. package/dist/configValidator.d.ts +10 -0
  5. package/dist/configValidator.d.ts.map +1 -0
  6. package/dist/configValidator.js +94 -0
  7. package/dist/configValidator.js.map +1 -0
  8. package/dist/copyOnWriteHelpers.d.ts +20 -0
  9. package/dist/copyOnWriteHelpers.d.ts.map +1 -0
  10. package/dist/copyOnWriteHelpers.js +58 -0
  11. package/dist/copyOnWriteHelpers.js.map +1 -0
  12. package/dist/customObjectManager.d.ts +13 -7
  13. package/dist/customObjectManager.d.ts.map +1 -1
  14. package/dist/customObjectManager.js +30 -29
  15. package/dist/customObjectManager.js.map +1 -1
  16. package/dist/dryRun.d.ts +8 -0
  17. package/dist/dryRun.d.ts.map +1 -0
  18. package/dist/dryRun.js +75 -0
  19. package/dist/dryRun.js.map +1 -0
  20. package/dist/dryRunAttribution.d.ts +8 -0
  21. package/dist/dryRunAttribution.d.ts.map +1 -0
  22. package/dist/dryRunAttribution.js +106 -0
  23. package/dist/dryRunAttribution.js.map +1 -0
  24. package/dist/fieldRedactor.d.ts +43 -5
  25. package/dist/fieldRedactor.d.ts.map +1 -1
  26. package/dist/fieldRedactor.js +124 -24
  27. package/dist/fieldRedactor.js.map +1 -1
  28. package/dist/fieldRedactorConfigBuilder.d.ts +49 -0
  29. package/dist/fieldRedactorConfigBuilder.d.ts.map +1 -0
  30. package/dist/fieldRedactorConfigBuilder.js +98 -0
  31. package/dist/fieldRedactorConfigBuilder.js.map +1 -0
  32. package/dist/fieldRedactorDeps.d.ts +17 -0
  33. package/dist/fieldRedactorDeps.d.ts.map +1 -0
  34. package/dist/fieldRedactorDeps.js +41 -0
  35. package/dist/fieldRedactorDeps.js.map +1 -0
  36. package/dist/index.d.ts +7 -1
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +14 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/jsonWalk.d.ts +11 -0
  41. package/dist/jsonWalk.d.ts.map +1 -0
  42. package/dist/jsonWalk.js +86 -0
  43. package/dist/jsonWalk.js.map +1 -0
  44. package/dist/objectRedactor.d.ts +9 -34
  45. package/dist/objectRedactor.d.ts.map +1 -1
  46. package/dist/objectRedactor.js +11 -298
  47. package/dist/objectRedactor.js.map +1 -1
  48. package/dist/objectRedactorCow.d.ts +35 -0
  49. package/dist/objectRedactorCow.d.ts.map +1 -0
  50. package/dist/objectRedactorCow.js +300 -0
  51. package/dist/objectRedactorCow.js.map +1 -0
  52. package/dist/objectRedactorCustomObject.d.ts +49 -0
  53. package/dist/objectRedactorCustomObject.d.ts.map +1 -0
  54. package/dist/objectRedactorCustomObject.js +138 -0
  55. package/dist/objectRedactorCustomObject.js.map +1 -0
  56. package/dist/objectRedactorHelpers.d.ts +9 -0
  57. package/dist/objectRedactorHelpers.d.ts.map +1 -0
  58. package/dist/objectRedactorHelpers.js +58 -0
  59. package/dist/objectRedactorHelpers.js.map +1 -0
  60. package/dist/objectRedactorMutation.d.ts +10 -0
  61. package/dist/objectRedactorMutation.d.ts.map +1 -0
  62. package/dist/objectRedactorMutation.js +89 -0
  63. package/dist/objectRedactorMutation.js.map +1 -0
  64. package/dist/objectRedactorSync.d.ts +2 -0
  65. package/dist/objectRedactorSync.d.ts.map +1 -0
  66. package/dist/objectRedactorSync.js +7 -0
  67. package/dist/objectRedactorSync.js.map +1 -0
  68. package/dist/objectRedactorTraversal.d.ts +57 -0
  69. package/dist/objectRedactorTraversal.d.ts.map +1 -0
  70. package/dist/objectRedactorTraversal.js +576 -0
  71. package/dist/objectRedactorTraversal.js.map +1 -0
  72. package/dist/presets.d.ts +22 -0
  73. package/dist/presets.d.ts.map +1 -0
  74. package/dist/presets.js +50 -0
  75. package/dist/presets.js.map +1 -0
  76. package/dist/primitiveRedactor.d.ts +13 -8
  77. package/dist/primitiveRedactor.d.ts.map +1 -1
  78. package/dist/primitiveRedactor.js +32 -27
  79. package/dist/primitiveRedactor.js.map +1 -1
  80. package/dist/redactionRules.d.ts +23 -0
  81. package/dist/redactionRules.d.ts.map +1 -0
  82. package/dist/redactionRules.js +76 -0
  83. package/dist/redactionRules.js.map +1 -0
  84. package/dist/regexUtils.d.ts +3 -0
  85. package/dist/regexUtils.d.ts.map +1 -0
  86. package/dist/regexUtils.js +8 -0
  87. package/dist/regexUtils.js.map +1 -0
  88. package/dist/secretManager.d.ts +12 -6
  89. package/dist/secretManager.d.ts.map +1 -1
  90. package/dist/secretManager.js +40 -14
  91. package/dist/secretManager.js.map +1 -1
  92. package/dist/types.d.ts +103 -2
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js +7 -1
  95. package/dist/types.js.map +1 -1
  96. package/dist/valuePatternMatcher.d.ts +15 -0
  97. package/dist/valuePatternMatcher.d.ts.map +1 -0
  98. package/dist/valuePatternMatcher.js +30 -0
  99. package/dist/valuePatternMatcher.js.map +1 -0
  100. package/docs/guides/anti-patterns.md +107 -0
  101. package/docs/guides/metadata-redaction.md +112 -0
  102. package/docs/guides/migration-1.2-to-1.5.md +106 -0
  103. package/docs/guides/secret-key-modes.md +108 -0
  104. package/docs/guides/value-pattern-redaction.md +58 -0
  105. package/docs/reference/config.md +135 -0
  106. package/docs/release-notes/2.0.0.md +19 -0
  107. package/docs/release-notes/2.1.0.md +17 -0
  108. package/docs/release-notes/2.2.0.md +16 -0
  109. package/docs/release-notes/2.3.0.md +17 -0
  110. package/docs/release-notes/2.3.1.md +17 -0
  111. package/docs/release-notes/2.4.0.md +30 -0
  112. package/docs/release-notes/2.5.0.md +33 -0
  113. package/docs/release-notes/2.5.1.md +17 -0
  114. package/docs/release-notes/README.md +30 -0
  115. package/docs/release-notes/v1.0.0.md +17 -0
  116. package/docs/release-notes/v1.1.0.md +18 -0
  117. package/docs/release-notes/v1.2.0.md +18 -0
  118. package/docs/release-notes/v1.2.1.md +16 -0
  119. package/docs/release-notes/v1.2.2.md +19 -0
  120. package/docs/release-notes/v1.3.0.md +112 -0
  121. package/docs/release-notes/v1.5.0.md +88 -0
  122. package/jest.config.js +4 -1
  123. package/package.json +3 -3
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.walkTraversableJson = exports.isTraversableJson = exports.joinPath = exports.getParentContext = exports.getJsonValueAtPath = exports.parseJsonPath = void 0;
4
+ const types_1 = require("./types");
5
+ const parseJsonPath = (path) => {
6
+ if (!path) {
7
+ return [];
8
+ }
9
+ const segments = [];
10
+ let current = '';
11
+ for (let index = 0; index < path.length; index++) {
12
+ const char = path[index];
13
+ if (char === '.') {
14
+ if (current) {
15
+ segments.push(current);
16
+ current = '';
17
+ }
18
+ continue;
19
+ }
20
+ if (char === '[') {
21
+ if (current) {
22
+ segments.push(current);
23
+ current = '';
24
+ }
25
+ const close = path.indexOf(']', index);
26
+ segments.push(Number(path.slice(index + 1, close)));
27
+ index = close;
28
+ continue;
29
+ }
30
+ current += char;
31
+ }
32
+ if (current) {
33
+ segments.push(current);
34
+ }
35
+ return segments;
36
+ };
37
+ exports.parseJsonPath = parseJsonPath;
38
+ const getJsonValueAtPath = (value, segments) => {
39
+ let current = value;
40
+ for (const segment of segments) {
41
+ if (current === undefined || current === null || typeof current !== 'object') {
42
+ return undefined;
43
+ }
44
+ if (Array.isArray(current) && typeof segment === 'number') {
45
+ current = current[segment];
46
+ continue;
47
+ }
48
+ if ((0, types_1.isJsonObject)(current) && typeof segment === 'string') {
49
+ current = current[segment];
50
+ continue;
51
+ }
52
+ return undefined;
53
+ }
54
+ return current;
55
+ };
56
+ exports.getJsonValueAtPath = getJsonValueAtPath;
57
+ const getParentContext = (value, segments) => {
58
+ if (segments.length === 0) {
59
+ return { parent: undefined, leaf: undefined };
60
+ }
61
+ const leaf = segments.at(-1);
62
+ const parent = segments.length === 1 ? value : (0, exports.getJsonValueAtPath)(value, segments.slice(0, -1));
63
+ return (0, exports.isTraversableJson)(parent) ? { parent, leaf } : { parent: undefined, leaf };
64
+ };
65
+ exports.getParentContext = getParentContext;
66
+ const joinPath = (base, segment) => typeof segment === 'number' ? (base ? `${base}[${segment}]` : `[${segment}]`) : base ? `${base}.${segment}` : segment;
67
+ exports.joinPath = joinPath;
68
+ const isTraversableJson = (value) => !!value && typeof value === 'object' && !(value instanceof Date);
69
+ exports.isTraversableJson = isTraversableJson;
70
+ const walkTraversableJson = (value, path, visit) => {
71
+ if (!(0, exports.isTraversableJson)(value)) {
72
+ return;
73
+ }
74
+ if (Array.isArray(value)) {
75
+ value.forEach((item, index) => (0, exports.walkTraversableJson)(item, (0, exports.joinPath)(path, index), visit));
76
+ return;
77
+ }
78
+ if ((0, types_1.isJsonObject)(value)) {
79
+ visit(value, path);
80
+ for (const key of Object.keys(value)) {
81
+ (0, exports.walkTraversableJson)(value[key], (0, exports.joinPath)(path, key), visit);
82
+ }
83
+ }
84
+ };
85
+ exports.walkTraversableJson = walkTraversableJson;
86
+ //# sourceMappingURL=jsonWalk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonWalk.js","sourceRoot":"","sources":["../src/jsonWalk.ts"],"names":[],"mappings":";;;AAAA,mCAAyE;AAElE,MAAM,aAAa,GAAG,CAAC,IAAY,EAA0B,EAAE;IACpE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,QAAQ,GAA2B,EAAE,CAAC;IAC5C,IAAI,OAAO,GAAG,EAAE,CAAC;IAEjB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAEzB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,IAAI,OAAO,EAAE,CAAC;gBACZ,Q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ACmG;AAEjH,MAAM,iBAAiB,GAAG,CAAC,KAA4B,EAAqC,EAAE,CACnG,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC;AADtD,QAAA,iBAAiB,qBACqC;AAE5D,MAAM,mBAAmB,GAAG,CACjC,KAA4B,EAC5B,IAAY,EACZ,KAA+C,EACzC,EAAE;IACR,IAAI,CAAC,IAAA,yBAAiB,EAAC,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO;IACT,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAA,2BAAmB,EAAC,IAAI,EAAE,IAAA,gBAAQ,EAAC,IAAI,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;QACxF,OAAO;IACT,CAAC;IAED,IAAI,IAAA,oBAAY,EAAC,KAAK,CAAC,EAAE,CAAC;QACxB,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACnB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,IAAA,2BAAmB,EAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAA,gBAAQ,EAAC,IAAI,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AApBW,QAAA,mBAAmB,uBAoB9B"}
@@ -1,42 +1,17 @@
1
- import { SecretManager } from './secretManager';
1
+ import { TraversableJson } from './types';
2
2
  import { CustomObjectManager } from './customObjectManager';
3
3
  import { PrimitiveRedactor } from './primitiveRedactor';
4
+ import { SecretManager } from './secretManager';
5
+ import { ValuePatternMatcher } from './valuePatternMatcher';
4
6
  /**
5
7
  * Redacts fields in a JSON object using the secretManager, primitiveRedactor, and CustomObjectChecker provided in the
6
- * constructor. The redaction is done in place and the redacted object is returned. CustomObjects take highest precedence,
7
- * followed by fullSecretKeys, then deepSecretKeys, and finally secretKeys. If a field is an object or an array it is
8
- * assessed recursively unless otherwise configured by a CustomObject or deepSecretKey.
8
+ * constructor. CustomObjects take highest precedence, followed by fullSecretKeys, then deepSecretKeys, and finally secretKeys.
9
9
  */
10
10
  export declare class ObjectRedactor {
11
- private readonly primitiveRedactor;
12
- private readonly secretManager;
13
- private readonly customObjManager;
14
- constructor(primitiveRedactor: PrimitiveRedactor, secretManager: SecretManager, customObjManager: CustomObjectManager);
15
- /**
16
- * Conditionally redacts fields in the JSON object in place based on the configuration using the
17
- * primitive redactor, custom object checker, and secret manager provided in the constructor.
18
- * @param value The JSON value to redact in place.
19
- * @returns The JSON value provided in the argument.
20
- */
21
- redactInPlace(value: any): Promise<any>;
22
- private redactSecretObjectFieldsInPlace;
23
- private redactArrayInObject;
24
- private redactObjectsInArray;
25
- private redactAllArrayValues;
26
- private redactObjectInObject;
27
- private handleCustomObjectInPlace;
28
- private handleCustomObjectValueIfArray;
29
- private getStringSpecifiedCustomObjectSecretKeyValueIfExists;
30
- private handleCustomObjectArrayValueIfStringKeySpecified;
31
- private handleCustomObjectArrayValueIfMatchTypeSpecified;
32
- private handlecustomObjectValueIfObject;
33
- private handleCustomObjectObjectValueIfStringKeySpecified;
34
- private handleCustomObjectOjectValueIfMatchTypeSpecified;
35
- private handleCustomObjectValueIfPrimitive;
36
- private handleCustomObjectPrimitiveValueIfMatchTypeSpecified;
37
- private handleCustomObjectPrimitiveValueIfStringKeySpecified;
38
- private getStringValue;
39
- private isObject;
40
- private redactPrimitiveValueIfSecret;
11
+ private readonly traversal;
12
+ constructor(primitiveRedactor: PrimitiveRedactor, secretManager: SecretManager, customObjManager: CustomObjectManager, valuePatternMatcher: ValuePatternMatcher);
13
+ redactInPlace<T extends TraversableJson>(value: T): Promise<T>;
14
+ redactInPlaceSync<T extends TraversableJson>(value: T): T;
15
+ redactCopyOnWrite<T extends TraversableJson>(value: T): T;
41
16
  }
42
17
  //# sourceMappingURL=objectRedactor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"objectRedactor.d.ts","sourceRoot":"","sources":["../src/objectRedactor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;GAKG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAFhB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,mBAAmB;IAGxD;;;;;OAKG;IACU,aAAa,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;YAWtC,+BAA+B;YAoB/B,mBAAmB;YASnB,oBAAoB;YAkBpB,oBAAoB;YAqBpB,oBAAoB;YAUpB,yBAAyB;YAYzB,8BAA8B;IAa5C,OAAO,CAAC,oDAAoD;YAS9C,gDAAgD;YAahD,gDAAgD;YAyBhD,+BAA+B;YAa/B,iDAAiD;YAejD,gDAAgD;YAsBhD,kCAAkC;YAalC,oDAAoD;YAsBpD,oDAAoD;IAQlE,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,QAAQ;YAIF,4BAA4B;CAS3C"}
1
+ {"version":3,"file":"objectRedactor.d.ts","sourceRoot":"","sources":["../src/objectRedactor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D;;;GAGG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;gBAGlD,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,mBAAmB,EACrC,mBAAmB,EAAE,mBAAmB;IAU7B,aAAa,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAQpE,iBAAiB,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IAIzD,iBAAiB,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;CAGjE"}
@@ -10,315 +10,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ObjectRedactor = void 0;
13
- const types_1 = require("./types");
13
+ const objectRedactorTraversal_1 = require("./objectRedactorTraversal");
14
14
  /**
15
15
  * Redacts fields in a JSON object using the secretManager, primitiveRedactor, and CustomObjectChecker provided in the
16
- * constructor. The redaction is done in place and the redacted object is returned. CustomObjects take highest precedence,
17
- * followed by fullSecretKeys, then deepSecretKeys, and finally secretKeys. If a field is an object or an array it is
18
- * assessed recursively unless otherwise configured by a CustomObject or deepSecretKey.
16
+ * constructor. CustomObjects take highest precedence, followed by fullSecretKeys, then deepSecretKeys, and finally secretKeys.
19
17
  */
20
18
  class ObjectRedactor {
21
- constructor(primitiveRedactor, secretManager, customObjManager) {
22
- this.primitiveRedactor = primitiveRedactor;
23
- this.secretManager = secretManager;
24
- this.customObjManager = customObjManager;
19
+ constructor(primitiveRedactor, secretManager, customObjManager, valuePatternMatcher) {
20
+ this.traversal = new objectRedactorTraversal_1.ObjectRedactorTraversal(primitiveRedactor, secretManager, customObjManager, valuePatternMatcher);
25
21
  }
26
- /**
27
- * Conditionally redacts fields in the JSON object in place based on the configuration using the
28
- * primitive redactor, custom object checker, and secret manager provided in the constructor.
29
- * @param value The JSON value to redact in place.
30
- * @returns The JSON value provided in the argument.
31
- */
32
22
  redactInPlace(value) {
33
23
  return __awaiter(this, void 0, void 0, function* () {
34
- const customObject = this.customObjManager.getMatchingCustomObject(value);
35
- if (customObject) {
36
- yield this.handleCustomObjectInPlace(value, customObject);
37
- }
38
- else {
39
- yield this.redactSecretObjectFieldsInPlace(value);
40
- }
41
- return value;
42
- });
43
- }
44
- redactSecretObjectFieldsInPlace(object_1) {
45
- return __awaiter(this, arguments, void 0, function* (object, forceDeepRedaction = false) {
46
- for (const key of Object.keys(object)) {
47
- const value = object[key];
48
- const customObject = this.customObjManager.getMatchingCustomObject(value);
49
- if (customObject) {
50
- yield this.handleCustomObjectInPlace(value, customObject);
51
- }
52
- else if (this.secretManager.isDeleteSecretKey(key)) {
53
- delete object[key];
54
- }
55
- else if (this.secretManager.isFullSecretKey(key)) {
56
- object[key] = yield this.primitiveRedactor.redactValue(this.getStringValue(value));
57
- }
58
- else if (Array.isArray(object[key])) {
59
- object[key] = yield this.redactArrayInObject(value, key, forceDeepRedaction);
60
- }
61
- else if (this.isObject(object[key])) {
62
- yield this.redactObjectInObject(object[key], key, forceDeepRedaction);
63
- }
64
- else {
65
- object[key] = yield this.redactPrimitiveValueIfSecret(key, value, forceDeepRedaction);
66
- }
67
- }
68
- });
69
- }
70
- redactArrayInObject(array, key, forceDeepRedaction) {
71
- return __awaiter(this, void 0, void 0, function* () {
72
- const deepSecretKey = this.secretManager.isDeepSecretKey(key);
73
- if (this.secretManager.isSecretKey(key) || deepSecretKey || forceDeepRedaction) {
74
- return this.redactAllArrayValues(array, forceDeepRedaction || deepSecretKey);
75
- }
76
- else {
77
- return yield this.redactObjectsInArray(array);
78
- }
79
- });
80
- }
81
- redactObjectsInArray(array) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- const promises = array.map((value) => __awaiter(this, void 0, void 0, function* () {
84
- if (this.isObject(value)) {
85
- const customObject = this.customObjManager.getMatchingCustomObject(value);
86
- if (customObject) {
87
- yield this.handleCustomObjectInPlace(value, customObject);
88
- return value;
89
- }
90
- else {
91
- yield this.redactSecretObjectFieldsInPlace(value, false);
92
- }
93
- }
94
- return value;
95
- }));
96
- return Promise.all(promises);
97
- });
98
- }
99
- redactAllArrayValues(array, forceDeepRedaction) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- const promises = array.map((value) => __awaiter(this, void 0, void 0, function* () {
102
- if (Array.isArray(value)) {
103
- return this.redactAllArrayValues(value, forceDeepRedaction);
104
- }
105
- else if (!this.isObject(value)) {
106
- return this.primitiveRedactor.redactValue(value);
107
- }
108
- else {
109
- const customObject = this.customObjManager.getMatchingCustomObject(value);
110
- if (customObject) {
111
- yield this.handleCustomObjectInPlace(value, customObject);
112
- return Promise.resolve(value);
113
- }
114
- else {
115
- yield this.redactSecretObjectFieldsInPlace(value, forceDeepRedaction);
116
- return Promise.resolve(value);
117
- }
118
- }
119
- }));
120
- return Promise.all(promises);
121
- });
122
- }
123
- redactObjectInObject(value, key, forceDeepRedaction) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const customObject = this.customObjManager.getMatchingCustomObject(value);
126
- if (customObject) {
127
- yield this.handleCustomObjectInPlace(value, customObject);
128
- }
129
- else {
130
- const secretObject = forceDeepRedaction || this.secretManager.isDeepSecretKey(key);
131
- yield this.redactSecretObjectFieldsInPlace(value, secretObject);
24
+ if (!this.traversal.usesAsyncRedactor()) {
25
+ return Promise.resolve(this.redactInPlaceSync(value));
132
26
  }
27
+ return this.traversal.redactInPlaceAsync(value);
133
28
  });
134
29
  }
135
- handleCustomObjectInPlace(value, customObject) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- for (const key of Object.keys(customObject)) {
138
- if (Array.isArray(value[key])) {
139
- yield this.handleCustomObjectValueIfArray(value, key, customObject);
140
- }
141
- else if (this.isObject(value[key])) {
142
- yield this.handlecustomObjectValueIfObject(value, key, customObject);
143
- }
144
- else {
145
- yield this.handleCustomObjectValueIfPrimitive(value, customObject, key);
146
- }
147
- }
148
- });
149
- }
150
- handleCustomObjectValueIfArray(value, key, customObject) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const stringKey = this.getStringSpecifiedCustomObjectSecretKeyValueIfExists(value, customObject, key);
153
- if (stringKey) {
154
- yield this.handleCustomObjectArrayValueIfStringKeySpecified(value, key, stringKey);
155
- }
156
- else {
157
- yield this.handleCustomObjectArrayValueIfMatchTypeSpecified(value, key, customObject[key]);
158
- }
159
- });
160
- }
161
- getStringSpecifiedCustomObjectSecretKeyValueIfExists(value, customObject, key) {
162
- const hasSecretKey = typeof customObject[key] === 'string' && !!value[customObject[key]];
163
- return hasSecretKey ? value[customObject[key]] : null;
164
- }
165
- handleCustomObjectArrayValueIfStringKeySpecified(value, key, stringKey) {
166
- return __awaiter(this, void 0, void 0, function* () {
167
- if (this.secretManager.isDeleteSecretKey(stringKey)) {
168
- delete value[key];
169
- }
170
- else if (this.secretManager.isFullSecretKey(stringKey)) {
171
- value[key] = yield this.primitiveRedactor.redactValue(this.getStringValue(value[key]));
172
- }
173
- else {
174
- const isDeepSecretKey = this.secretManager.isDeepSecretKey(stringKey);
175
- if (isDeepSecretKey || this.secretManager.isSecretKey(stringKey)) {
176
- value[key] = yield this.redactAllArrayValues(value[key], isDeepSecretKey);
177
- }
178
- }
179
- });
180
- }
181
- handleCustomObjectArrayValueIfMatchTypeSpecified(value, key, matchType) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- switch (matchType) {
184
- case types_1.CustomObjectMatchType.Delete:
185
- delete value[key];
186
- return Promise.resolve();
187
- case types_1.CustomObjectMatchType.Full:
188
- value[key] = yield this.primitiveRedactor.redactValue(this.getStringValue(value[key]));
189
- return Promise.resolve();
190
- case types_1.CustomObjectMatchType.Deep:
191
- value[key] = yield this.redactAllArrayValues(value[key], true);
192
- return Promise.resolve();
193
- case types_1.CustomObjectMatchType.Shallow:
194
- value[key] = yield this.redactAllArrayValues(value[key], false);
195
- return Promise.resolve();
196
- case types_1.CustomObjectMatchType.Pass:
197
- value[key] = yield this.redactArrayInObject(value[key], key, false);
198
- default:
199
- return Promise.resolve();
200
- }
201
- });
30
+ redactInPlaceSync(value) {
31
+ return this.traversal.redactInPlace(value);
202
32
  }
203
- handlecustomObjectValueIfObject(value, key, customObject) {
204
- return __awaiter(this, void 0, void 0, function* () {
205
- const stringKey = this.getStringSpecifiedCustomObjectSecretKeyValueIfExists(value, customObject, key);
206
- if (stringKey) {
207
- yield this.handleCustomObjectObjectValueIfStringKeySpecified(value, key, stringKey);
208
- }
209
- else {
210
- yield this.handleCustomObjectOjectValueIfMatchTypeSpecified(value, key, customObject[key]);
211
- }
212
- });
213
- }
214
- handleCustomObjectObjectValueIfStringKeySpecified(value, key, stringKey) {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- const customObject = this.customObjManager.getMatchingCustomObject(value[key]);
217
- if (customObject) {
218
- yield this.handleCustomObjectInPlace(value[key], customObject);
219
- }
220
- else if (this.secretManager.isDeleteSecretKey(stringKey)) {
221
- delete value[key];
222
- }
223
- else if (this.secretManager.isFullSecretKey(stringKey)) {
224
- value[key] = yield this.primitiveRedactor.redactValue(this.getStringValue(value[key]));
225
- }
226
- else if (this.secretManager.isDeepSecretKey(stringKey)) {
227
- yield this.redactSecretObjectFieldsInPlace(value[key], true);
228
- }
229
- else if (this.secretManager.isSecretKey(stringKey)) {
230
- yield this.redactSecretObjectFieldsInPlace(value[key], false);
231
- }
232
- });
233
- }
234
- handleCustomObjectOjectValueIfMatchTypeSpecified(value, key, matchType) {
235
- return __awaiter(this, void 0, void 0, function* () {
236
- switch (matchType) {
237
- case types_1.CustomObjectMatchType.Delete:
238
- delete value[key];
239
- return Promise.resolve();
240
- case types_1.CustomObjectMatchType.Full:
241
- value[key] = yield this.primitiveRedactor.redactValue(this.getStringValue(value[key]));
242
- return Promise.resolve();
243
- case types_1.CustomObjectMatchType.Deep:
244
- return this.redactSecretObjectFieldsInPlace(value[key], true);
245
- case types_1.CustomObjectMatchType.Shallow:
246
- case types_1.CustomObjectMatchType.Pass:
247
- return this.redactSecretObjectFieldsInPlace(value[key], false);
248
- case types_1.CustomObjectMatchType.Ignore:
249
- return Promise.resolve();
250
- }
251
- });
252
- }
253
- handleCustomObjectValueIfPrimitive(value, customObject, key) {
254
- return __awaiter(this, void 0, void 0, function* () {
255
- if (typeof customObject[key] === 'number') {
256
- return this.handleCustomObjectPrimitiveValueIfMatchTypeSpecified(value, key, customObject[key]);
257
- }
258
- else {
259
- const secretKey = this.getStringSpecifiedCustomObjectSecretKeyValueIfExists(value, customObject, key);
260
- if (!secretKey) {
261
- return;
262
- }
263
- yield this.handleCustomObjectPrimitiveValueIfStringKeySpecified(value, secretKey, key);
264
- }
265
- });
266
- }
267
- handleCustomObjectPrimitiveValueIfMatchTypeSpecified(value, key, matchValue) {
268
- return __awaiter(this, void 0, void 0, function* () {
269
- switch (matchValue) {
270
- case types_1.CustomObjectMatchType.Delete:
271
- delete value[key];
272
- return;
273
- case types_1.CustomObjectMatchType.Full:
274
- value[key] = yield this.primitiveRedactor.redactValue(this.getStringValue(value[key]));
275
- return;
276
- case types_1.CustomObjectMatchType.Deep:
277
- case types_1.CustomObjectMatchType.Shallow:
278
- value[key] = yield this.primitiveRedactor.redactValue(value[key]);
279
- return;
280
- case types_1.CustomObjectMatchType.Pass:
281
- default:
282
- return Promise.resolve();
283
- }
284
- });
285
- }
286
- handleCustomObjectPrimitiveValueIfStringKeySpecified(value, secretKey, key) {
287
- return __awaiter(this, void 0, void 0, function* () {
288
- if (this.secretManager.isDeleteSecretKey(secretKey)) {
289
- delete value[key];
290
- }
291
- else {
292
- value[key] = yield this.redactPrimitiveValueIfSecret(secretKey, value[key], false);
293
- }
294
- });
295
- }
296
- getStringValue(val) {
297
- if (this.isObject(val) || Array.isArray(val)) {
298
- return JSON.stringify(val);
299
- }
300
- else if (val === null || val === undefined) {
301
- return val;
302
- }
303
- else {
304
- return val.toString();
305
- }
306
- }
307
- isObject(value) {
308
- return !!value && typeof value === 'object' && !(value instanceof Date) && !Array.isArray(value);
309
- }
310
- redactPrimitiveValueIfSecret(key, value, forceDeepRedaction) {
311
- return __awaiter(this, void 0, void 0, function* () {
312
- if (this.secretManager.isFullSecretKey(key)) {
313
- return this.primitiveRedactor.redactValue(this.getStringValue(value));
314
- }
315
- else if (forceDeepRedaction || this.secretManager.isSecretKey(key) || this.secretManager.isDeepSecretKey(key)) {
316
- return this.primitiveRedactor.redactValue(value);
317
- }
318
- else {
319
- return value;
320
- }
321
- });
33
+ redactCopyOnWrite(value) {
34
+ return this.traversal.redactCopyOnWrite(value);
322
35
  }
323
36
  }
324
37
  exports.ObjectRedactor = ObjectRedactor;
@@ -1 +1 @@
1
- {"version":3,"file":"objectRedactor.js","sourceRoot":"","sources":["../src/objectRedactor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA8D;AAK9D;;;;;GAKG;AACH,MAAa,cAAc;IACzB,YACmB,iBAAoC,EACpC,aAA4B,EAC5B,gBAAqC;QAFrC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,kBAAa,GAAb,aAAa,CAAe;QAC5B,qBAAgB,GAAhB,gBAAgB,CAAqB;IACrD,CAAC;IAEJ;;;;;OAKG;IACU,aAAa,CAAC,KAAU;;YACnC,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;YAC1E,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YAC5D,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,CAAC,+BAA+B,CAAC,KAAK,CAAC,CAAC;YACpD,CAAC;YAED,OAAO,KAAK,CAAC;QACf,CAAC;KAAA;IA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,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAClD,CAAC;KAAA;IAEM,iBAAiB,CAA4B,KAAQ;QAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC7C,CAAC;IAEM,iBAAiB,CAA4B,KAAQ;QAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACjD,CAAC;CACF;AAhCD,wCAgCC"}
@@ -0,0 +1,35 @@
1
+ import { TraversableJson } from './types';
2
+ import { SecretManager } from './secretManager';
3
+ import { CustomObjectManager } from './customObjectManager';
4
+ import { PrimitiveRedactor } from './primitiveRedactor';
5
+ /**
6
+ * Copy-on-write JSON traversal: clones only branches that are mutated so unredacted
7
+ * subtrees are shared with the input.
8
+ */
9
+ export declare class ObjectRedactorCowTraversal {
10
+ private readonly primitiveRedactor;
11
+ private readonly secretManager;
12
+ private readonly customObjManager;
13
+ constructor(primitiveRedactor: PrimitiveRedactor, secretManager: SecretManager, customObjManager: CustomObjectManager);
14
+ redactCopyOnWrite<T extends TraversableJson>(value: T): T;
15
+ private redactSecretObjectFields;
16
+ private redactSecretArrayRecord;
17
+ private redactSecretObjectRecord;
18
+ private redactArrayInObject;
19
+ private redactObjectsInArray;
20
+ private redactAllArrayValues;
21
+ private redactNestedObject;
22
+ private handleCustomObject;
23
+ private handleCustomObjectValueIfArray;
24
+ private handleCustomObjectArrayValueIfStringKeySpecified;
25
+ private handleCustomObjectArrayValueIfMatchTypeSpecified;
26
+ private handleCustomObjectValueIfObject;
27
+ private handleCustomObjectObjectValueIfStringKeySpecified;
28
+ private handleCustomObjectObjectValueIfMatchTypeSpecified;
29
+ private handleCustomObjectValueIfPrimitive;
30
+ private handleCustomObjectPrimitiveValueIfMatchTypeSpecified;
31
+ private handleCustomObjectPrimitiveValueIfStringKeySpecified;
32
+ private redactPrimitiveValueIfSecret;
33
+ private redactPrimitive;
34
+ }
35
+ //# sourceMappingURL=objectRedactorCow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectRedactorCow.d.ts","sourceRoot":"","sources":["../src/objectRedactorCow.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,eAAe,EAChB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAkBxD;;;GAGG;AACH,qBAAa,0BAA0B;IAEnC,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAFhB,iBAAiB,EAAE,iBAAiB,EACpC,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,mBAAmB;IAGxD,iBAAiB,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC;IASzD,OAAO,CAAC,wBAAwB;IAQhC,OAAO,CAAC,uBAAuB;IAyB/B,OAAO,CAAC,wBAAwB;IAwBhC,OAAO,CAAC,mBAAmB;IAS3B,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,oBAAoB;IAsB5B,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,8BAA8B;IAStC,OAAO,CAAC,gDAAgD;IAsBxD,OAAO,CAAC,gDAAgD;IA8BxD,OAAO,CAAC,+BAA+B;IASvC,OAAO,CAAC,iDAAiD;IAwBzD,OAAO,CAAC,iDAAiD;IA6BzD,OAAO,CAAC,kCAAkC;IAkB1C,OAAO,CAAC,oDAAoD;IAsB5D,OAAO,CAAC,oDAAoD;IAgB5D,OAAO,CAAC,4BAA4B;IAcpC,OAAO,CAAC,eAAe;CAGxB"}