field-redactor 1.5.0 → 1.6.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 (224) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/CONTRIBUTING.md +64 -0
  3. package/README.md +3 -0
  4. package/dist/api/fieldRedactor.d.ts +53 -0
  5. package/dist/api/fieldRedactor.d.ts.map +1 -0
  6. package/dist/api/fieldRedactor.js +169 -0
  7. package/dist/api/fieldRedactor.js.map +1 -0
  8. package/dist/api/fieldRedactorConfigBuilder.d.ts +57 -0
  9. package/dist/api/fieldRedactorConfigBuilder.d.ts.map +1 -0
  10. package/dist/api/fieldRedactorConfigBuilder.js +115 -0
  11. package/dist/api/fieldRedactorConfigBuilder.js.map +1 -0
  12. package/dist/api/fieldRedactorDeps.d.ts +19 -0
  13. package/dist/api/fieldRedactorDeps.d.ts.map +1 -0
  14. package/dist/api/fieldRedactorDeps.js +45 -0
  15. package/dist/api/fieldRedactorDeps.js.map +1 -0
  16. package/dist/arrayRedaction.d.ts +12 -0
  17. package/dist/arrayRedaction.d.ts.map +1 -0
  18. package/dist/arrayRedaction.js +70 -0
  19. package/dist/arrayRedaction.js.map +1 -0
  20. package/dist/config/configValidator.d.ts +9 -0
  21. package/dist/config/configValidator.d.ts.map +1 -0
  22. package/dist/config/configValidator.js +77 -0
  23. package/dist/config/configValidator.js.map +1 -0
  24. package/dist/config/customObjectSchemas.d.ts +7 -0
  25. package/dist/config/customObjectSchemas.d.ts.map +1 -0
  26. package/dist/config/customObjectSchemas.js +35 -0
  27. package/dist/config/customObjectSchemas.js.map +1 -0
  28. package/dist/config/presets.d.ts +22 -0
  29. package/dist/config/presets.d.ts.map +1 -0
  30. package/dist/config/presets.js +50 -0
  31. package/dist/config/presets.js.map +1 -0
  32. package/dist/config/redactionRules.d.ts +25 -0
  33. package/dist/config/redactionRules.d.ts.map +1 -0
  34. package/dist/config/redactionRules.js +108 -0
  35. package/dist/config/redactionRules.js.map +1 -0
  36. package/dist/configValidator.d.ts +3 -4
  37. package/dist/configValidator.d.ts.map +1 -1
  38. package/dist/configValidator.js +9 -26
  39. package/dist/configValidator.js.map +1 -1
  40. package/dist/customObjectFieldHandler.d.ts +21 -0
  41. package/dist/customObjectFieldHandler.d.ts.map +1 -0
  42. package/dist/customObjectFieldHandler.js +159 -0
  43. package/dist/customObjectFieldHandler.js.map +1 -0
  44. package/dist/customObjectManager.d.ts +1 -1
  45. package/dist/customObjectManager.js +3 -3
  46. package/dist/customObjectManager.js.map +1 -1
  47. package/dist/customObjectSchemas.d.ts +7 -0
  48. package/dist/customObjectSchemas.d.ts.map +1 -0
  49. package/dist/customObjectSchemas.js +35 -0
  50. package/dist/customObjectSchemas.js.map +1 -0
  51. package/dist/dryRun.d.ts +2 -1
  52. package/dist/dryRun.d.ts.map +1 -1
  53. package/dist/dryRun.js +2 -2
  54. package/dist/dryRun.js.map +1 -1
  55. package/dist/dryRunAttribution.d.ts +5 -3
  56. package/dist/dryRunAttribution.d.ts.map +1 -1
  57. package/dist/dryRunAttribution.js +9 -101
  58. package/dist/dryRunAttribution.js.map +1 -1
  59. package/dist/dryrun/dryRun.d.ts +9 -0
  60. package/dist/dryrun/dryRun.d.ts.map +1 -0
  61. package/dist/dryrun/dryRun.js +75 -0
  62. package/dist/dryrun/dryRun.js.map +1 -0
  63. package/dist/dryrun/dryRunAttribution.d.ts +10 -0
  64. package/dist/dryrun/dryRunAttribution.d.ts.map +1 -0
  65. package/dist/dryrun/dryRunAttribution.js +14 -0
  66. package/dist/dryrun/dryRunAttribution.js.map +1 -0
  67. package/dist/engine/arrayRedaction.d.ts +12 -0
  68. package/dist/engine/arrayRedaction.d.ts.map +1 -0
  69. package/dist/engine/arrayRedaction.js +70 -0
  70. package/dist/engine/arrayRedaction.js.map +1 -0
  71. package/dist/engine/customObjectFieldHandler.d.ts +35 -0
  72. package/dist/engine/customObjectFieldHandler.d.ts.map +1 -0
  73. package/dist/engine/customObjectFieldHandler.js +167 -0
  74. package/dist/engine/customObjectFieldHandler.js.map +1 -0
  75. package/dist/engine/objectRedactor.d.ts +18 -0
  76. package/dist/engine/objectRedactor.d.ts.map +1 -0
  77. package/dist/engine/objectRedactor.js +38 -0
  78. package/dist/engine/objectRedactor.js.map +1 -0
  79. package/dist/engine/objectRedactorCustomObject.d.ts +27 -0
  80. package/dist/engine/objectRedactorCustomObject.d.ts.map +1 -0
  81. package/dist/engine/objectRedactorCustomObject.js +54 -0
  82. package/dist/engine/objectRedactorCustomObject.js.map +1 -0
  83. package/dist/engine/objectRedactorHelpers.d.ts +9 -0
  84. package/dist/engine/objectRedactorHelpers.d.ts.map +1 -0
  85. package/dist/engine/objectRedactorHelpers.js +61 -0
  86. package/dist/engine/objectRedactorHelpers.js.map +1 -0
  87. package/dist/engine/objectRedactorMutation.d.ts +10 -0
  88. package/dist/engine/objectRedactorMutation.d.ts.map +1 -0
  89. package/dist/engine/objectRedactorMutation.js +89 -0
  90. package/dist/engine/objectRedactorMutation.js.map +1 -0
  91. package/dist/engine/objectRedactorSync.d.ts +2 -0
  92. package/dist/engine/objectRedactorSync.d.ts.map +1 -0
  93. package/dist/engine/objectRedactorSync.js +7 -0
  94. package/dist/engine/objectRedactorSync.js.map +1 -0
  95. package/dist/engine/objectRedactorTraversal.d.ts +41 -0
  96. package/dist/engine/objectRedactorTraversal.d.ts.map +1 -0
  97. package/dist/engine/objectRedactorTraversal.js +201 -0
  98. package/dist/engine/objectRedactorTraversal.js.map +1 -0
  99. package/dist/engine/primitiveRedactor.d.ts +33 -0
  100. package/dist/engine/primitiveRedactor.d.ts.map +1 -0
  101. package/dist/engine/primitiveRedactor.js +75 -0
  102. package/dist/engine/primitiveRedactor.js.map +1 -0
  103. package/dist/engine/traversalServices.d.ts +21 -0
  104. package/dist/engine/traversalServices.d.ts.map +1 -0
  105. package/dist/engine/traversalServices.js +3 -0
  106. package/dist/engine/traversalServices.js.map +1 -0
  107. package/dist/fieldDisposition.d.ts +3 -0
  108. package/dist/fieldDisposition.d.ts.map +1 -0
  109. package/dist/fieldDisposition.js +6 -0
  110. package/dist/fieldDisposition.js.map +1 -0
  111. package/dist/fieldRedactor.d.ts +6 -21
  112. package/dist/fieldRedactor.d.ts.map +1 -1
  113. package/dist/fieldRedactor.js +37 -56
  114. package/dist/fieldRedactor.js.map +1 -1
  115. package/dist/fieldRedactorConfigBuilder.d.ts +7 -1
  116. package/dist/fieldRedactorConfigBuilder.d.ts.map +1 -1
  117. package/dist/fieldRedactorConfigBuilder.js +14 -1
  118. package/dist/fieldRedactorConfigBuilder.js.map +1 -1
  119. package/dist/fieldRedactorDeps.d.ts +2 -0
  120. package/dist/fieldRedactorDeps.d.ts.map +1 -1
  121. package/dist/fieldRedactorDeps.js +11 -9
  122. package/dist/fieldRedactorDeps.js.map +1 -1
  123. package/dist/index.d.ts +7 -7
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +5 -5
  126. package/dist/index.js.map +1 -1
  127. package/dist/jsonWalk.d.ts +1 -1
  128. package/dist/jsonWalk.d.ts.map +1 -1
  129. package/dist/jsonWalk.js +2 -33
  130. package/dist/jsonWalk.js.map +1 -1
  131. package/dist/maybeAsync.d.ts +7 -0
  132. package/dist/maybeAsync.d.ts.map +1 -0
  133. package/dist/maybeAsync.js +56 -0
  134. package/dist/maybeAsync.js.map +1 -0
  135. package/dist/objectRedactor.d.ts +2 -1
  136. package/dist/objectRedactor.d.ts.map +1 -1
  137. package/dist/objectRedactor.js +2 -2
  138. package/dist/objectRedactor.js.map +1 -1
  139. package/dist/objectRedactorCustomObject.d.ts +19 -40
  140. package/dist/objectRedactorCustomObject.d.ts.map +1 -1
  141. package/dist/objectRedactorCustomObject.js +20 -101
  142. package/dist/objectRedactorCustomObject.js.map +1 -1
  143. package/dist/objectRedactorHelpers.d.ts.map +1 -1
  144. package/dist/objectRedactorHelpers.js +3 -0
  145. package/dist/objectRedactorHelpers.js.map +1 -1
  146. package/dist/objectRedactorTraversal.d.ts +20 -36
  147. package/dist/objectRedactorTraversal.d.ts.map +1 -1
  148. package/dist/objectRedactorTraversal.js +141 -516
  149. package/dist/objectRedactorTraversal.js.map +1 -1
  150. package/dist/pathParsing.d.ts +11 -0
  151. package/dist/pathParsing.d.ts.map +1 -0
  152. package/dist/pathParsing.js +53 -0
  153. package/dist/pathParsing.js.map +1 -0
  154. package/dist/pathRuleMatcher.d.ts +19 -0
  155. package/dist/pathRuleMatcher.d.ts.map +1 -0
  156. package/dist/pathRuleMatcher.js +42 -0
  157. package/dist/pathRuleMatcher.js.map +1 -0
  158. package/dist/redactionRules.d.ts +3 -4
  159. package/dist/redactionRules.d.ts.map +1 -1
  160. package/dist/redactionRules.js +7 -9
  161. package/dist/redactionRules.js.map +1 -1
  162. package/dist/ruleResolver.d.ts +65 -0
  163. package/dist/ruleResolver.d.ts.map +1 -0
  164. package/dist/ruleResolver.js +193 -0
  165. package/dist/ruleResolver.js.map +1 -0
  166. package/dist/rules/customObjectManager.d.ts +28 -0
  167. package/dist/rules/customObjectManager.d.ts.map +1 -0
  168. package/dist/rules/customObjectManager.js +60 -0
  169. package/dist/rules/customObjectManager.js.map +1 -0
  170. package/dist/rules/fieldDisposition.d.ts +3 -0
  171. package/dist/rules/fieldDisposition.d.ts.map +1 -0
  172. package/dist/rules/fieldDisposition.js +6 -0
  173. package/dist/rules/fieldDisposition.js.map +1 -0
  174. package/dist/rules/pathRuleMatcher.d.ts +19 -0
  175. package/dist/rules/pathRuleMatcher.d.ts.map +1 -0
  176. package/dist/rules/pathRuleMatcher.js +40 -0
  177. package/dist/rules/pathRuleMatcher.js.map +1 -0
  178. package/dist/rules/ruleResolver.d.ts +65 -0
  179. package/dist/rules/ruleResolver.d.ts.map +1 -0
  180. package/dist/rules/ruleResolver.js +194 -0
  181. package/dist/rules/ruleResolver.js.map +1 -0
  182. package/dist/rules/secretManager.d.ts +32 -0
  183. package/dist/rules/secretManager.d.ts.map +1 -0
  184. package/dist/rules/secretManager.js +85 -0
  185. package/dist/rules/secretManager.js.map +1 -0
  186. package/dist/rules/valuePatternMatcher.d.ts +15 -0
  187. package/dist/rules/valuePatternMatcher.d.ts.map +1 -0
  188. package/dist/rules/valuePatternMatcher.js +30 -0
  189. package/dist/rules/valuePatternMatcher.js.map +1 -0
  190. package/dist/secretManager.d.ts +6 -19
  191. package/dist/secretManager.d.ts.map +1 -1
  192. package/dist/secretManager.js +19 -30
  193. package/dist/secretManager.js.map +1 -1
  194. package/dist/traversalServices.d.ts +21 -0
  195. package/dist/traversalServices.d.ts.map +1 -0
  196. package/dist/traversalServices.js +3 -0
  197. package/dist/traversalServices.js.map +1 -0
  198. package/dist/types.d.ts +41 -5
  199. package/dist/types.d.ts.map +1 -1
  200. package/dist/types.js +8 -1
  201. package/dist/types.js.map +1 -1
  202. package/dist/util/jsonWalk.d.ts +10 -0
  203. package/dist/util/jsonWalk.d.ts.map +1 -0
  204. package/dist/util/jsonWalk.js +53 -0
  205. package/dist/util/jsonWalk.js.map +1 -0
  206. package/dist/util/maybeAsync.d.ts +7 -0
  207. package/dist/util/maybeAsync.d.ts.map +1 -0
  208. package/dist/util/maybeAsync.js +56 -0
  209. package/dist/util/maybeAsync.js.map +1 -0
  210. package/dist/util/pathParsing.d.ts +11 -0
  211. package/dist/util/pathParsing.d.ts.map +1 -0
  212. package/dist/util/pathParsing.js +53 -0
  213. package/dist/util/pathParsing.js.map +1 -0
  214. package/dist/util/regexUtils.d.ts +3 -0
  215. package/dist/util/regexUtils.d.ts.map +1 -0
  216. package/dist/util/regexUtils.js +8 -0
  217. package/dist/util/regexUtils.js.map +1 -0
  218. package/docs/guides/migration-1.5-to-1.6.md +56 -0
  219. package/docs/guides/path-rules.md +47 -0
  220. package/docs/reference/config.md +5 -1
  221. package/docs/release-notes/README.md +3 -1
  222. package/docs/release-notes/v1.6.0.md +59 -0
  223. package/jest.config.js +3 -1
  224. package/package.json +8 -2
@@ -1,575 +1,200 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.ObjectRedactorTraversal = void 0;
13
4
  const types_1 = require("./types");
14
5
  const objectRedactorMutation_1 = require("./objectRedactorMutation");
15
6
  const objectRedactorHelpers_1 = require("./objectRedactorHelpers");
16
- const objectRedactorCustomObject_1 = require("./objectRedactorCustomObject");
7
+ const ruleResolver_1 = require("./ruleResolver");
8
+ const maybeAsync_1 = require("./maybeAsync");
9
+ const arrayRedaction_1 = require("./arrayRedaction");
10
+ const customObjectFieldHandler_1 = require("./customObjectFieldHandler");
17
11
  /**
18
12
  * Unified JSON traversal for in-place and copy-on-write redaction.
19
- * Sync paths avoid Promise allocation; async paths use the same ContainerMutation adapter.
13
+ * Sync and async paths share one implementation; async mode propagates Promises only when configured.
20
14
  */
21
15
  class ObjectRedactorTraversal {
22
- constructor(primitiveRedactor, secretManager, customObjManager, valuePatternMatcher) {
16
+ constructor(primitiveRedactor, secretManager, customObjManager, valuePatternMatcher, pathRuleMatcher) {
23
17
  this.primitiveRedactor = primitiveRedactor;
24
18
  this.secretManager = secretManager;
25
- this.customObjManager = customObjManager;
26
19
  this.valuePatternMatcher = valuePatternMatcher;
20
+ this.ruleResolver = new ruleResolver_1.RuleResolver(secretManager, pathRuleMatcher, valuePatternMatcher, customObjManager);
21
+ this.services = {
22
+ get asyncMode() {
23
+ return primitiveRedactor.usesAsyncRedactor();
24
+ },
25
+ ruleResolver: this.ruleResolver,
26
+ secretManager,
27
+ valuePatternMatcher,
28
+ setPrimitive: (container, key, primitive) => this.setPrimitive(container, key, primitive),
29
+ setPrimitiveFromValue: (container, key, value) => this.setPrimitiveFromValue(container, key, value),
30
+ setPrimitiveValueIfSecret: (container, key, secretKey, value, forceDeepRedaction) => this.setPrimitiveValueIfSecret(container, key, secretKey, value, forceDeepRedaction),
31
+ redactSecretFields: (container, forceDeepRedaction, pathSegments) => this.redactSecretFields(container, forceDeepRedaction, pathSegments),
32
+ handleCustomObject: (container, customObject) => this.handleCustomObject(container, customObject),
33
+ redactArrayInObject: (array, key, forceDeepRedaction, parent, pathSegments) => this.redactArrayInObject(array, key, forceDeepRedaction, parent, pathSegments),
34
+ redactAllArrayValues: (array, forceDeepRedaction, copyOnWrite, pathSegments) => this.redactAllArrayValues(array, forceDeepRedaction, copyOnWrite, pathSegments)
35
+ };
36
+ this.arrayRedactor = new arrayRedaction_1.ArrayRedactor(this.services);
37
+ this.customObjectHandler = new customObjectFieldHandler_1.CustomObjectFieldHandler(this.services);
27
38
  }
28
39
  usesAsyncRedactor() {
29
40
  return this.primitiveRedactor.usesAsyncRedactor();
30
41
  }
31
42
  redactInPlace(value) {
32
- return this.redact(value, false);
43
+ const result = this.traverseRedact(value, false);
44
+ if (result instanceof Promise) {
45
+ throw new Error('Unexpected async work on sync traversal path');
46
+ }
47
+ return result;
33
48
  }
34
49
  redactCopyOnWrite(value) {
35
- return this.redact(value, true);
50
+ const result = this.traverseRedact(value, true);
51
+ if (result instanceof Promise) {
52
+ throw new Error('Unexpected async work on sync traversal path');
53
+ }
54
+ return result;
36
55
  }
37
56
  redactInPlaceAsync(value) {
38
- return this.redactAsync(value, false);
57
+ return Promise.resolve(this.traverseRedact(value, false));
39
58
  }
40
- redact(value, copyOnWrite) {
41
- const container = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
42
- const customObject = this.customObjManager.getMatchingCustomObject(value);
43
- if (customObject && (0, types_1.isJsonObject)(value)) {
44
- this.handleCustomObject(container, customObject);
45
- }
46
- else {
47
- this.redactSecretFields(container, false);
48
- }
49
- return (copyOnWrite ? container.result() : value);
59
+ get asyncMode() {
60
+ return this.primitiveRedactor.usesAsyncRedactor();
50
61
  }
51
- redactSecretFields(container, forceDeepRedaction) {
52
- const record = container.source;
53
- for (const key of Object.keys(record)) {
54
- const value = record[key];
55
- const customObject = (0, types_1.isJsonObject)(value) ? this.customObjManager.getMatchingCustomObject(value) : undefined;
56
- if (customObject && (0, types_1.isJsonObject)(value)) {
57
- const child = (0, objectRedactorMutation_1.createContainerMutation)(value, container.copyOnWrite);
58
- this.handleCustomObject(child, customObject);
59
- if (container.copyOnWrite) {
60
- container.set(key, child.result());
61
- }
62
- }
63
- else if (this.secretManager.isDeleteSecretKey(key)) {
64
- container.remove(key);
65
- }
66
- else if (this.secretManager.isFullSecretKey(key)) {
67
- container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(value)));
68
- }
69
- else if (Array.isArray(value)) {
70
- this.redactArrayInObject(value, key, forceDeepRedaction, container);
71
- }
72
- else if ((0, types_1.isJsonObject)(value)) {
73
- this.redactNestedObject(value, key, forceDeepRedaction, container);
74
- }
75
- else {
76
- container.set(key, this.redactPrimitiveValueIfSecret(key, value, forceDeepRedaction));
77
- }
78
- }
62
+ traverseRedact(value, copyOnWrite) {
63
+ const container = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
64
+ const customObject = this.ruleResolver.getMatchingSchema(value);
65
+ const work = customObject && (0, types_1.isJsonObject)(value)
66
+ ? this.handleCustomObject(container, customObject)
67
+ : this.redactSecretFields(container, false, []);
68
+ return (0, maybeAsync_1.finalizeMaybeAsync)(work, () => (copyOnWrite ? container.result() : value), this.asyncMode);
79
69
  }
80
- redactArrayInObject(array, key, forceDeepRedaction, parent) {
81
- const deepSecretKey = this.secretManager.isDeepSecretKey(key);
82
- const result = this.secretManager.isSecretKey(key) || deepSecretKey || forceDeepRedaction
83
- ? this.redactAllArrayValues(array, forceDeepRedaction || deepSecretKey, parent.copyOnWrite)
84
- : this.redactObjectsInArray(array, parent.copyOnWrite);
85
- parent.set(key, result);
70
+ handleCustomObject(container, customObject) {
71
+ return this.customObjectHandler.handleCustomObject(container, customObject);
86
72
  }
87
- redactObjectsInArray(array, copyOnWrite) {
88
- const container = (0, objectRedactorMutation_1.createContainerMutation)(array, copyOnWrite);
89
- for (let index = 0; index < array.length; index++) {
90
- const value = array[index];
91
- if ((0, types_1.isJsonObject)(value)) {
92
- const customObject = this.customObjManager.getMatchingCustomObject(value);
93
- const child = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
94
- if (customObject) {
95
- this.handleCustomObject(child, customObject);
96
- }
97
- else {
98
- this.redactSecretFields(child, false);
99
- }
100
- container.set(String(index), child.result());
101
- }
102
- }
103
- return container.result();
73
+ redactArrayInObject(array, key, forceDeepRedaction, parent, pathSegments) {
74
+ return this.arrayRedactor.redactArrayInObject(array, key, forceDeepRedaction, parent, pathSegments);
104
75
  }
105
- redactAllArrayValues(array, forceDeepRedaction, copyOnWrite) {
106
- const container = (0, objectRedactorMutation_1.createContainerMutation)(array, copyOnWrite);
107
- for (let index = 0; index < array.length; index++) {
108
- const value = array[index];
109
- const key = String(index);
110
- if (Array.isArray(value)) {
111
- container.set(key, this.redactAllArrayValues(value, forceDeepRedaction, copyOnWrite));
112
- }
113
- else if (!(0, types_1.isJsonObject)(value)) {
114
- container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.toRedactablePrimitive)(value)));
115
- }
116
- else {
117
- const customObject = this.customObjManager.getMatchingCustomObject(value);
118
- const child = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
119
- if (customObject) {
120
- this.handleCustomObject(child, customObject);
121
- }
122
- else {
123
- this.redactSecretFields(child, forceDeepRedaction);
124
- }
125
- container.set(key, child.result());
126
- }
127
- }
128
- return container.result();
76
+ redactAllArrayValues(array, forceDeepRedaction, copyOnWrite, pathSegments) {
77
+ return this.arrayRedactor.redactAllArrayValues(array, forceDeepRedaction, copyOnWrite, pathSegments);
129
78
  }
130
- redactNestedObject(value, key, forceDeepRedaction, parent) {
131
- const child = (0, objectRedactorMutation_1.createContainerMutation)(value, parent.copyOnWrite);
132
- const customObject = this.customObjManager.getMatchingCustomObject(value);
133
- if (customObject) {
134
- this.handleCustomObject(child, customObject);
135
- }
136
- else {
137
- this.redactSecretFields(child, forceDeepRedaction || this.secretManager.isDeepSecretKey(key));
138
- }
139
- if (parent.copyOnWrite) {
140
- parent.set(key, child.result());
141
- }
79
+ redactPrimitive(value) {
80
+ return this.asyncMode ? this.primitiveRedactor.redactValue(value) : this.primitiveRedactor.redactValueSync(value);
142
81
  }
143
- handleCustomObject(container, customObject) {
144
- for (const key of Object.keys(customObject)) {
145
- const fieldValue = container.source[key];
146
- if (Array.isArray(fieldValue)) {
147
- this.handleCustomObjectValueIfArray(container, key, customObject);
148
- }
149
- else if ((0, types_1.isJsonObject)(fieldValue)) {
150
- this.handleCustomObjectValueIfObject(container, key, customObject);
151
- }
152
- else {
153
- this.handleCustomObjectValueIfPrimitive(container, customObject, key);
154
- }
82
+ setPrimitive(container, key, primitive) {
83
+ const redacted = this.redactPrimitive(primitive);
84
+ if (redacted instanceof Promise) {
85
+ return redacted.then((result) => {
86
+ container.set(key, result);
87
+ });
155
88
  }
89
+ container.set(key, redacted);
156
90
  }
157
- handleCustomObjectValueIfArray(container, key, customObject) {
158
- const stringKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
159
- if (stringKey !== undefined) {
160
- this.handleCustomObjectArrayValueIfStringKeySpecified(container, key, stringKey);
161
- }
162
- else {
163
- this.handleCustomObjectArrayValueIfMatchTypeSpecified(container, key, customObject[key]);
164
- }
91
+ setPrimitiveFromValue(container, key, value) {
92
+ return this.setPrimitive(container, key, (0, objectRedactorHelpers_1.getStringValue)(value));
165
93
  }
166
- handleCustomObjectArrayValueIfStringKeySpecified(container, key, stringKey) {
167
- const fieldValue = container.source[key];
168
- if (!Array.isArray(fieldValue)) {
169
- return;
170
- }
171
- if (this.secretManager.isDeleteSecretKey(stringKey)) {
172
- container.remove(key);
173
- }
174
- else if (this.secretManager.isFullSecretKey(stringKey)) {
175
- container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
176
- }
177
- else {
178
- const isDeepSecretKey = this.secretManager.isDeepSecretKey(stringKey);
179
- if (isDeepSecretKey || this.secretManager.isSecretKey(stringKey)) {
180
- container.set(key, this.redactAllArrayValues(fieldValue, isDeepSecretKey, container.copyOnWrite));
181
- }
94
+ chainHandled(work) {
95
+ if (work instanceof Promise) {
96
+ return work.then(() => 'handled');
182
97
  }
98
+ return 'handled';
183
99
  }
184
- handleCustomObjectArrayValueIfMatchTypeSpecified(container, key, matchType) {
185
- const fieldValue = container.source[key];
186
- if (!Array.isArray(fieldValue)) {
187
- return;
100
+ applyFieldDisposition(disposition, value, key, fieldPath, container) {
101
+ switch (disposition.action) {
102
+ case 'skip':
103
+ return 'handled';
104
+ case 'remove':
105
+ container.remove(key);
106
+ return 'handled';
107
+ case 'opaque':
108
+ return this.chainHandled(this.setPrimitiveFromValue(container, key, value));
109
+ case 'deep':
110
+ return this.chainHandled(this.redactFieldValue(value, key, true, container, fieldPath));
111
+ case 'shallow':
112
+ if (Array.isArray(value) || (0, types_1.isJsonObject)(value)) {
113
+ return this.chainHandled(this.redactFieldValue(value, key, false, container, fieldPath));
114
+ }
115
+ return this.chainHandled(this.setPrimitive(container, key, (0, objectRedactorHelpers_1.toRedactablePrimitive)(value)));
116
+ case 'pass-key-recurse':
117
+ if (Array.isArray(value) || (0, types_1.isJsonObject)(value)) {
118
+ return this.chainHandled(this.redactFieldValue(value, key, false, container, fieldPath));
119
+ }
120
+ return 'handled';
121
+ default:
122
+ return 'default';
188
123
  }
189
- (0, objectRedactorCustomObject_1.applyCustomObjectArrayMatchType)(matchType, {
190
- deleteKey: () => container.remove(key),
191
- redactFull: () => container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue))),
192
- redactDeep: () => container.set(key, this.redactAllArrayValues(fieldValue, true, container.copyOnWrite)),
193
- redactShallow: () => container.set(key, this.redactAllArrayValues(fieldValue, false, container.copyOnWrite)),
194
- passThrough: () => {
195
- this.redactArrayInObject(fieldValue, key, false, container);
196
- }
197
- });
198
124
  }
199
- handleCustomObjectValueIfObject(container, key, customObject) {
200
- const stringKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
201
- if (stringKey !== undefined) {
202
- this.handleCustomObjectObjectValueIfStringKeySpecified(container, key, stringKey);
125
+ redactFieldValue(value, key, forceDeepRedaction, container, fieldPath) {
126
+ if (Array.isArray(value)) {
127
+ return this.redactArrayInObject(value, key, forceDeepRedaction, container, fieldPath);
203
128
  }
204
- else {
205
- this.handleCustomObjectObjectValueIfMatchTypeSpecified(container, key, customObject[key]);
129
+ if ((0, types_1.isJsonObject)(value)) {
130
+ return this.redactNestedObject(value, key, forceDeepRedaction, container, fieldPath);
206
131
  }
132
+ return this.setPrimitiveValueIfSecret(container, key, key, value, forceDeepRedaction);
207
133
  }
208
- handleCustomObjectObjectValueIfStringKeySpecified(container, key, stringKey) {
209
- const fieldValue = container.source[key];
210
- if (!(0, types_1.isJsonObject)(fieldValue)) {
211
- return;
212
- }
213
- const customObject = this.customObjManager.getMatchingCustomObject(fieldValue);
214
- if (customObject) {
215
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
216
- this.handleCustomObject(child, customObject);
217
- container.set(key, child.result());
218
- }
219
- else if (this.secretManager.isDeleteSecretKey(stringKey)) {
220
- container.remove(key);
221
- }
222
- else if (this.secretManager.isFullSecretKey(stringKey)) {
223
- container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
224
- }
225
- else if (this.secretManager.isDeepSecretKey(stringKey)) {
134
+ redactSecretFields(container, forceDeepRedaction, pathSegments) {
135
+ const record = container.source;
136
+ return (0, maybeAsync_1.runSequential)(Object.keys(record), (key) => this.processSecretField(record, key, forceDeepRedaction, pathSegments, container), this.asyncMode);
137
+ }
138
+ processSecretField(record, key, forceDeepRedaction, pathSegments, container) {
139
+ const fieldValue = record[key];
140
+ const fieldPath = [...pathSegments, key];
141
+ const customObject = (0, types_1.isJsonObject)(fieldValue) ? this.ruleResolver.getMatchingSchema(fieldValue) : undefined;
142
+ if (customObject && (0, types_1.isJsonObject)(fieldValue)) {
226
143
  const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
227
- this.redactSecretFields(child, true);
228
- container.set(key, child.result());
144
+ return (0, maybeAsync_1.finalizeMaybeAsync)(this.handleCustomObject(child, customObject), () => {
145
+ if (container.copyOnWrite) {
146
+ container.set(key, child.result());
147
+ }
148
+ }, this.asyncMode);
229
149
  }
230
- else if (this.secretManager.isSecretKey(stringKey)) {
231
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
232
- this.redactSecretFields(child, false);
233
- container.set(key, child.result());
150
+ const disposition = this.ruleResolver.resolvePathDisposition(pathSegments, key, forceDeepRedaction);
151
+ const dispositionResult = this.applyFieldDisposition(disposition, fieldValue, key, fieldPath, container);
152
+ if (dispositionResult instanceof Promise) {
153
+ return dispositionResult.then((handled) => handled === 'handled'
154
+ ? undefined
155
+ : this.applyDefaultSecretRules(fieldValue, key, forceDeepRedaction, container, fieldPath));
234
156
  }
235
- }
236
- handleCustomObjectObjectValueIfMatchTypeSpecified(container, key, matchType) {
237
- const fieldValue = container.source[key];
238
- if (!(0, types_1.isJsonObject)(fieldValue)) {
157
+ if (dispositionResult === 'handled') {
239
158
  return;
240
159
  }
241
- (0, objectRedactorCustomObject_1.applyCustomObjectObjectMatchType)(matchType, {
242
- deleteKey: () => container.remove(key),
243
- redactFull: () => container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(fieldValue))),
244
- redactDeep: () => {
245
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
246
- this.redactSecretFields(child, true);
247
- container.set(key, child.result());
248
- },
249
- redactShallowOrPass: () => {
250
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
251
- this.redactSecretFields(child, false);
252
- container.set(key, child.result());
253
- },
254
- ignore: () => undefined
255
- });
160
+ return this.applyDefaultSecretRules(fieldValue, key, forceDeepRedaction, container, fieldPath);
256
161
  }
257
- handleCustomObjectValueIfPrimitive(container, customObject, key) {
258
- if (typeof customObject[key] === 'number') {
259
- this.handleCustomObjectPrimitiveValueIfMatchTypeSpecified(container, key, customObject[key]);
162
+ applyDefaultSecretRules(fieldValue, key, forceDeepRedaction, container, fieldPath) {
163
+ if (this.ruleResolver.shouldRemoveByKey(key)) {
164
+ container.remove(key);
260
165
  return;
261
166
  }
262
- const secretKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
263
- if (secretKey === undefined) {
264
- return;
167
+ if (this.ruleResolver.shouldOpaqueByKey(key)) {
168
+ return this.setPrimitiveFromValue(container, key, fieldValue);
265
169
  }
266
- this.handleCustomObjectPrimitiveValueIfStringKeySpecified(container, secretKey, key);
267
- }
268
- handleCustomObjectPrimitiveValueIfMatchTypeSpecified(container, key, matchValue) {
269
- (0, objectRedactorCustomObject_1.applyCustomObjectPrimitiveMatchType)(matchValue, {
270
- deleteKey: () => container.remove(key),
271
- redactFull: () => container.set(key, this.redactPrimitive((0, objectRedactorHelpers_1.getStringValue)(container.source[key]))),
272
- redactScalar: () => container.set(key, this.redactPrimitive(container.source[key])),
273
- passThrough: () => undefined
274
- });
275
- }
276
- handleCustomObjectPrimitiveValueIfStringKeySpecified(container, secretKey, key) {
277
- if (this.secretManager.isDeleteSecretKey(secretKey)) {
278
- container.remove(key);
170
+ if (Array.isArray(fieldValue)) {
171
+ return this.redactArrayInObject(fieldValue, key, forceDeepRedaction, container, fieldPath);
279
172
  }
280
- else {
281
- container.set(key, this.redactPrimitiveValueIfSecret(secretKey, container.source[key], false));
173
+ if ((0, types_1.isJsonObject)(fieldValue)) {
174
+ return this.redactNestedObject(fieldValue, key, forceDeepRedaction, container, fieldPath);
282
175
  }
176
+ return this.setPrimitiveValueIfSecret(container, key, key, fieldValue, forceDeepRedaction);
283
177
  }
284
- redactPrimitiveValueIfSecret(key, value, forceDeepRedaction) {
285
- return (0, objectRedactorHelpers_1.redactPrimitiveValueIfSecret)(this.secretManager, this.valuePatternMatcher, (primitive) => this.redactPrimitive(primitive), key, value, forceDeepRedaction);
286
- }
287
- redactPrimitive(value) {
288
- return this.primitiveRedactor.redactValueSync(value);
289
- }
290
- redactAsync(value, copyOnWrite) {
291
- return __awaiter(this, void 0, void 0, function* () {
292
- const container = (0, objectRedactorMutation_1.createContainerMutation)(value, copyOnWrite);
293
- const customObject = this.customObjManager.getMatchingCustomObject(value);
294
- if (customObject && (0, types_1.isJsonObject)(value)) {
295
- yield this.handleCustomObjectAsync(container, customObject);
296
- }
297
- else {
298
- yield this.redactSecretFieldsAsync(container, false);
299
- }
300
- return (copyOnWrite ? container.result() : value);
301
- });
302
- }
303
- redactSecretFieldsAsync(container, forceDeepRedaction) {
304
- return __awaiter(this, void 0, void 0, function* () {
305
- const record = container.source;
306
- for (const key of Object.keys(record)) {
307
- const fieldValue = record[key];
308
- const customObject = (0, types_1.isJsonObject)(fieldValue) ? this.customObjManager.getMatchingCustomObject(fieldValue) : undefined;
309
- if (customObject && (0, types_1.isJsonObject)(fieldValue)) {
310
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
311
- yield this.handleCustomObjectAsync(child, customObject);
312
- if (container.copyOnWrite) {
313
- container.set(key, child.result());
314
- }
315
- }
316
- else if (this.secretManager.isDeleteSecretKey(key)) {
317
- container.remove(key);
318
- }
319
- else if (this.secretManager.isFullSecretKey(key)) {
320
- container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
321
- }
322
- else if (Array.isArray(fieldValue)) {
323
- yield this.redactArrayInObjectAsync(fieldValue, key, forceDeepRedaction, container);
324
- }
325
- else if ((0, types_1.isJsonObject)(fieldValue)) {
326
- yield this.redactNestedObjectAsync(fieldValue, key, forceDeepRedaction, container);
327
- }
328
- else {
329
- container.set(key, yield this.redactPrimitiveValueIfSecretAsync(key, fieldValue, forceDeepRedaction));
330
- }
331
- }
332
- });
333
- }
334
- redactArrayInObjectAsync(array, key, forceDeepRedaction, parent) {
335
- return __awaiter(this, void 0, void 0, function* () {
336
- const deepSecretKey = this.secretManager.isDeepSecretKey(key);
337
- const result = this.secretManager.isSecretKey(key) || deepSecretKey || forceDeepRedaction
338
- ? yield this.redactAllArrayValuesAsync(array, forceDeepRedaction || deepSecretKey, parent.copyOnWrite)
339
- : yield this.redactObjectsInArrayAsync(array, parent.copyOnWrite);
340
- parent.set(key, result);
341
- });
342
- }
343
- redactObjectsInArrayAsync(array, copyOnWrite) {
344
- return __awaiter(this, void 0, void 0, function* () {
345
- const container = (0, objectRedactorMutation_1.createContainerMutation)(array, copyOnWrite);
346
- for (let index = 0; index < array.length; index++) {
347
- const item = array[index];
348
- if ((0, types_1.isJsonObject)(item)) {
349
- const customObject = this.customObjManager.getMatchingCustomObject(item);
350
- const child = (0, objectRedactorMutation_1.createContainerMutation)(item, copyOnWrite);
351
- if (customObject) {
352
- yield this.handleCustomObjectAsync(child, customObject);
353
- }
354
- else {
355
- yield this.redactSecretFieldsAsync(child, false);
356
- }
357
- container.set(String(index), child.result());
358
- }
359
- }
360
- return container.result();
361
- });
362
- }
363
- redactAllArrayValuesAsync(array, forceDeepRedaction, copyOnWrite) {
364
- return __awaiter(this, void 0, void 0, function* () {
365
- const container = (0, objectRedactorMutation_1.createContainerMutation)(array, copyOnWrite);
366
- for (let index = 0; index < array.length; index++) {
367
- const item = array[index];
368
- const key = String(index);
369
- if (Array.isArray(item)) {
370
- container.set(key, yield this.redactAllArrayValuesAsync(item, forceDeepRedaction, copyOnWrite));
371
- }
372
- else if (!(0, types_1.isJsonObject)(item)) {
373
- container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.toRedactablePrimitive)(item)));
374
- }
375
- else {
376
- const customObject = this.customObjManager.getMatchingCustomObject(item);
377
- const child = (0, objectRedactorMutation_1.createContainerMutation)(item, copyOnWrite);
378
- if (customObject) {
379
- yield this.handleCustomObjectAsync(child, customObject);
380
- }
381
- else {
382
- yield this.redactSecretFieldsAsync(child, forceDeepRedaction);
383
- }
384
- container.set(key, child.result());
385
- }
386
- }
387
- return container.result();
388
- });
389
- }
390
- redactNestedObjectAsync(value, key, forceDeepRedaction, parent) {
391
- return __awaiter(this, void 0, void 0, function* () {
392
- const child = (0, objectRedactorMutation_1.createContainerMutation)(value, parent.copyOnWrite);
393
- const customObject = this.customObjManager.getMatchingCustomObject(value);
394
- if (customObject) {
395
- yield this.handleCustomObjectAsync(child, customObject);
396
- }
397
- else {
398
- yield this.redactSecretFieldsAsync(child, forceDeepRedaction || this.secretManager.isDeepSecretKey(key));
399
- }
178
+ redactNestedObject(value, key, forceDeepRedaction, parent, pathSegments) {
179
+ const child = (0, objectRedactorMutation_1.createContainerMutation)(value, parent.copyOnWrite);
180
+ const customObject = this.ruleResolver.getMatchingSchema(value);
181
+ const work = customObject
182
+ ? this.handleCustomObject(child, customObject)
183
+ : this.redactSecretFields(child, this.ruleResolver.nestedObjectForceDeepRedaction(key, forceDeepRedaction), pathSegments);
184
+ return (0, maybeAsync_1.finalizeMaybeAsync)(work, () => {
400
185
  if (parent.copyOnWrite) {
401
186
  parent.set(key, child.result());
402
187
  }
403
- });
404
- }
405
- handleCustomObjectAsync(container, customObject) {
406
- return __awaiter(this, void 0, void 0, function* () {
407
- for (const key of Object.keys(customObject)) {
408
- const fieldValue = container.source[key];
409
- if (Array.isArray(fieldValue)) {
410
- yield this.handleCustomObjectValueIfArrayAsync(container, key, customObject);
411
- }
412
- else if ((0, types_1.isJsonObject)(fieldValue)) {
413
- yield this.handleCustomObjectValueIfObjectAsync(container, key, customObject);
414
- }
415
- else {
416
- yield this.handleCustomObjectValueIfPrimitiveAsync(container, customObject, key);
417
- }
418
- }
419
- });
420
- }
421
- handleCustomObjectValueIfArrayAsync(container, key, customObject) {
422
- return __awaiter(this, void 0, void 0, function* () {
423
- const stringKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
424
- if (stringKey !== undefined) {
425
- yield this.handleCustomObjectArrayValueIfStringKeySpecifiedAsync(container, key, stringKey);
426
- }
427
- else {
428
- yield this.handleCustomObjectArrayValueIfMatchTypeSpecifiedAsync(container, key, customObject[key]);
429
- }
430
- });
188
+ }, this.asyncMode);
431
189
  }
432
- handleCustomObjectArrayValueIfStringKeySpecifiedAsync(container, key, stringKey) {
433
- return __awaiter(this, void 0, void 0, function* () {
434
- const fieldValue = container.source[key];
435
- if (!Array.isArray(fieldValue)) {
436
- return;
437
- }
438
- if (this.secretManager.isDeleteSecretKey(stringKey)) {
439
- container.remove(key);
440
- }
441
- else if (this.secretManager.isFullSecretKey(stringKey)) {
442
- container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
443
- }
444
- else {
445
- const isDeepSecretKey = this.secretManager.isDeepSecretKey(stringKey);
446
- if (isDeepSecretKey || this.secretManager.isSecretKey(stringKey)) {
447
- container.set(key, yield this.redactAllArrayValuesAsync(fieldValue, isDeepSecretKey, container.copyOnWrite));
448
- }
449
- }
450
- });
451
- }
452
- handleCustomObjectArrayValueIfMatchTypeSpecifiedAsync(container, key, matchType) {
453
- return __awaiter(this, void 0, void 0, function* () {
454
- const fieldValue = container.source[key];
455
- if (!Array.isArray(fieldValue)) {
456
- return;
457
- }
458
- yield (0, objectRedactorCustomObject_1.applyCustomObjectArrayMatchTypeAsync)(matchType, {
459
- deleteKey: () => __awaiter(this, void 0, void 0, function* () { return container.remove(key); }),
460
- redactFull: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue))); }),
461
- redactDeep: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactAllArrayValuesAsync(fieldValue, true, container.copyOnWrite)); }),
462
- redactShallow: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactAllArrayValuesAsync(fieldValue, false, container.copyOnWrite)); }),
463
- passThrough: () => __awaiter(this, void 0, void 0, function* () {
464
- yield this.redactArrayInObjectAsync(fieldValue, key, false, container);
465
- })
466
- });
467
- });
468
- }
469
- handleCustomObjectValueIfObjectAsync(container, key, customObject) {
470
- return __awaiter(this, void 0, void 0, function* () {
471
- const stringKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
472
- if (stringKey !== undefined) {
473
- yield this.handleCustomObjectObjectValueIfStringKeySpecifiedAsync(container, key, stringKey);
474
- }
475
- else {
476
- yield this.handleCustomObjectObjectValueIfMatchTypeSpecifiedAsync(container, key, customObject[key]);
477
- }
478
- });
479
- }
480
- handleCustomObjectObjectValueIfStringKeySpecifiedAsync(container, key, stringKey) {
481
- return __awaiter(this, void 0, void 0, function* () {
482
- const fieldValue = container.source[key];
483
- if (!(0, types_1.isJsonObject)(fieldValue)) {
484
- return;
485
- }
486
- const customObject = this.customObjManager.getMatchingCustomObject(fieldValue);
487
- if (customObject) {
488
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
489
- yield this.handleCustomObjectAsync(child, customObject);
490
- container.set(key, child.result());
491
- }
492
- else if (this.secretManager.isDeleteSecretKey(stringKey)) {
493
- container.remove(key);
494
- }
495
- else if (this.secretManager.isFullSecretKey(stringKey)) {
496
- container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue)));
497
- }
498
- else if (this.secretManager.isDeepSecretKey(stringKey)) {
499
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
500
- yield this.redactSecretFieldsAsync(child, true);
501
- container.set(key, child.result());
502
- }
503
- else if (this.secretManager.isSecretKey(stringKey)) {
504
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
505
- yield this.redactSecretFieldsAsync(child, false);
506
- container.set(key, child.result());
507
- }
508
- });
509
- }
510
- handleCustomObjectObjectValueIfMatchTypeSpecifiedAsync(container, key, matchType) {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- const fieldValue = container.source[key];
513
- if (!(0, types_1.isJsonObject)(fieldValue)) {
514
- return;
515
- }
516
- yield (0, objectRedactorCustomObject_1.applyCustomObjectObjectMatchTypeAsync)(matchType, {
517
- deleteKey: () => __awaiter(this, void 0, void 0, function* () { return container.remove(key); }),
518
- redactFull: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(fieldValue))); }),
519
- redactDeep: () => __awaiter(this, void 0, void 0, function* () {
520
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
521
- yield this.redactSecretFieldsAsync(child, true);
522
- container.set(key, child.result());
523
- }),
524
- redactShallowOrPass: () => __awaiter(this, void 0, void 0, function* () {
525
- const child = (0, objectRedactorMutation_1.createContainerMutation)(fieldValue, container.copyOnWrite);
526
- yield this.redactSecretFieldsAsync(child, false);
527
- container.set(key, child.result());
528
- }),
529
- ignore: () => __awaiter(this, void 0, void 0, function* () { return undefined; })
530
- });
531
- });
532
- }
533
- handleCustomObjectValueIfPrimitiveAsync(container, customObject, key) {
534
- return __awaiter(this, void 0, void 0, function* () {
535
- if (typeof customObject[key] === 'number') {
536
- yield this.handleCustomObjectPrimitiveValueIfMatchTypeSpecifiedAsync(container, key, customObject[key]);
537
- return;
538
- }
539
- const secretKey = (0, objectRedactorHelpers_1.getStringSpecifiedCustomObjectSecretKeyValueIfExists)(container.source, customObject, key);
540
- if (secretKey === undefined) {
541
- return;
542
- }
543
- yield this.handleCustomObjectPrimitiveValueIfStringKeySpecifiedAsync(container, secretKey, key);
544
- });
545
- }
546
- handleCustomObjectPrimitiveValueIfMatchTypeSpecifiedAsync(container, key, matchValue) {
547
- return __awaiter(this, void 0, void 0, function* () {
548
- yield (0, objectRedactorCustomObject_1.applyCustomObjectPrimitiveMatchTypeAsync)(matchValue, {
549
- deleteKey: () => __awaiter(this, void 0, void 0, function* () { return container.remove(key); }),
550
- redactFull: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync((0, objectRedactorHelpers_1.getStringValue)(container.source[key]))); }),
551
- redactScalar: () => __awaiter(this, void 0, void 0, function* () { return container.set(key, yield this.redactPrimitiveAsync(container.source[key])); }),
552
- passThrough: () => __awaiter(this, void 0, void 0, function* () { return undefined; })
190
+ setPrimitiveValueIfSecret(container, key, secretKey, value, forceDeepRedaction) {
191
+ const redacted = (0, objectRedactorHelpers_1.redactPrimitiveValueIfSecret)(this.secretManager, this.valuePatternMatcher, (primitive) => this.redactPrimitive(primitive), secretKey, value, forceDeepRedaction);
192
+ if (redacted instanceof Promise) {
193
+ return redacted.then((result) => {
194
+ container.set(key, result);
553
195
  });
554
- });
555
- }
556
- handleCustomObjectPrimitiveValueIfStringKeySpecifiedAsync(container, secretKey, key) {
557
- return __awaiter(this, void 0, void 0, function* () {
558
- if (this.secretManager.isDeleteSecretKey(secretKey)) {
559
- container.remove(key);
560
- }
561
- else {
562
- container.set(key, yield this.redactPrimitiveValueIfSecretAsync(secretKey, container.source[key], false));
563
- }
564
- });
565
- }
566
- redactPrimitiveValueIfSecretAsync(key, value, forceDeepRedaction) {
567
- return __awaiter(this, void 0, void 0, function* () {
568
- return (0, objectRedactorHelpers_1.redactPrimitiveValueIfSecret)(this.secretManager, this.valuePatternMatcher, (primitive) => this.redactPrimitiveAsync(primitive), key, value, forceDeepRedaction);
569
- });
570
- }
571
- redactPrimitiveAsync(value) {
572
- return this.primitiveRedactor.redactValue(value);
196
+ }
197
+ container.set(key, redacted);
573
198
  }
574
199
  }
575
200
  exports.ObjectRedactorTraversal = ObjectRedactorTraversal;