@smthrs/journal 0.0.0-stage → 1.0.0-rc.12

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 (257) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/LICENSE +21 -0
  3. package/README.md +208 -2
  4. package/dist/cjs/CallFact.d.ts +129 -0
  5. package/dist/cjs/CallFact.d.ts.map +1 -0
  6. package/dist/cjs/CallFact.js +106 -0
  7. package/dist/cjs/CallFact.js.map +7 -0
  8. package/dist/cjs/Consensus.d.ts +492 -0
  9. package/dist/cjs/Consensus.d.ts.map +1 -0
  10. package/dist/cjs/Consensus.js +308 -0
  11. package/dist/cjs/Consensus.js.map +7 -0
  12. package/dist/cjs/EngineEvent.d.ts +890 -0
  13. package/dist/cjs/EngineEvent.d.ts.map +1 -0
  14. package/dist/cjs/EngineEvent.js +383 -0
  15. package/dist/cjs/EngineEvent.js.map +7 -0
  16. package/dist/cjs/ExecutionFact.d.ts +216 -0
  17. package/dist/cjs/ExecutionFact.d.ts.map +1 -0
  18. package/dist/cjs/ExecutionFact.js +303 -0
  19. package/dist/cjs/ExecutionFact.js.map +7 -0
  20. package/dist/cjs/Journal.d.ts +617 -0
  21. package/dist/cjs/Journal.d.ts.map +1 -0
  22. package/dist/cjs/Journal.js +190 -0
  23. package/dist/cjs/Journal.js.map +7 -0
  24. package/dist/cjs/JournalEvent.d.ts +421 -0
  25. package/dist/cjs/JournalEvent.d.ts.map +1 -0
  26. package/dist/cjs/JournalEvent.js +281 -0
  27. package/dist/cjs/JournalEvent.js.map +7 -0
  28. package/dist/cjs/JournalGeneration.d.ts +34 -0
  29. package/dist/cjs/JournalGeneration.d.ts.map +1 -0
  30. package/dist/cjs/JournalGeneration.js +73 -0
  31. package/dist/cjs/JournalGeneration.js.map +7 -0
  32. package/dist/cjs/JournalMetrics.d.ts +72 -0
  33. package/dist/cjs/JournalMetrics.d.ts.map +1 -0
  34. package/dist/cjs/JournalMetrics.js +55 -0
  35. package/dist/cjs/JournalMetrics.js.map +7 -0
  36. package/dist/cjs/Migrations.d.ts +42 -0
  37. package/dist/cjs/Migrations.d.ts.map +1 -0
  38. package/dist/cjs/Migrations.js +58 -0
  39. package/dist/cjs/Migrations.js.map +7 -0
  40. package/dist/cjs/OwnerId.d.ts +40 -0
  41. package/dist/cjs/OwnerId.d.ts.map +1 -0
  42. package/dist/cjs/OwnerId.js +40 -0
  43. package/dist/cjs/OwnerId.js.map +7 -0
  44. package/dist/cjs/Projection.d.ts +29 -0
  45. package/dist/cjs/Projection.d.ts.map +1 -0
  46. package/dist/cjs/Projection.js +25 -0
  47. package/dist/cjs/Projection.js.map +7 -0
  48. package/dist/cjs/RedactedLogger.d.ts +121 -0
  49. package/dist/cjs/RedactedLogger.d.ts.map +1 -0
  50. package/dist/cjs/RedactedLogger.js +235 -0
  51. package/dist/cjs/RedactedLogger.js.map +7 -0
  52. package/dist/cjs/Redaction.d.ts +350 -0
  53. package/dist/cjs/Redaction.d.ts.map +1 -0
  54. package/dist/cjs/Redaction.js +955 -0
  55. package/dist/cjs/Redaction.js.map +7 -0
  56. package/dist/cjs/SqlConsensus.d.ts +44 -0
  57. package/dist/cjs/SqlConsensus.d.ts.map +1 -0
  58. package/dist/cjs/SqlConsensus.js +273 -0
  59. package/dist/cjs/SqlConsensus.js.map +7 -0
  60. package/dist/cjs/SqlJournal.d.ts +173 -0
  61. package/dist/cjs/SqlJournal.d.ts.map +1 -0
  62. package/dist/cjs/SqlJournal.js +1568 -0
  63. package/dist/cjs/SqlJournal.js.map +7 -0
  64. package/dist/cjs/StepFact.d.ts +66 -0
  65. package/dist/cjs/StepFact.d.ts.map +1 -0
  66. package/dist/cjs/StepFact.js +68 -0
  67. package/dist/cjs/StepFact.js.map +7 -0
  68. package/dist/cjs/index.d.ts +95 -0
  69. package/dist/cjs/index.d.ts.map +1 -0
  70. package/dist/cjs/index.js +63 -0
  71. package/dist/cjs/index.js.map +7 -0
  72. package/dist/cjs/internal/JournalInternalFault.d.ts +37 -0
  73. package/dist/cjs/internal/JournalInternalFault.d.ts.map +1 -0
  74. package/dist/cjs/internal/JournalInternalFault.js +43 -0
  75. package/dist/cjs/internal/JournalInternalFault.js.map +7 -0
  76. package/dist/cjs/migrations/0001_initial.d.ts +15 -0
  77. package/dist/cjs/migrations/0001_initial.d.ts.map +1 -0
  78. package/dist/cjs/migrations/0001_initial.js +54 -0
  79. package/dist/cjs/migrations/0001_initial.js.map +7 -0
  80. package/dist/cjs/migrations/0002_checkpoints.d.ts +27 -0
  81. package/dist/cjs/migrations/0002_checkpoints.d.ts.map +1 -0
  82. package/dist/cjs/migrations/0002_checkpoints.js +48 -0
  83. package/dist/cjs/migrations/0002_checkpoints.js.map +7 -0
  84. package/dist/cjs/migrations/0003_startup_index.d.ts +15 -0
  85. package/dist/cjs/migrations/0003_startup_index.d.ts.map +1 -0
  86. package/dist/cjs/migrations/0003_startup_index.js +40 -0
  87. package/dist/cjs/migrations/0003_startup_index.js.map +7 -0
  88. package/dist/cjs/migrations/0004_dedup.d.ts +15 -0
  89. package/dist/cjs/migrations/0004_dedup.d.ts.map +1 -0
  90. package/dist/cjs/migrations/0004_dedup.js +57 -0
  91. package/dist/cjs/migrations/0004_dedup.js.map +7 -0
  92. package/dist/cjs/migrations/0005_run_event_type.d.ts +15 -0
  93. package/dist/cjs/migrations/0005_run_event_type.d.ts.map +1 -0
  94. package/dist/cjs/migrations/0005_run_event_type.js +40 -0
  95. package/dist/cjs/migrations/0005_run_event_type.js.map +7 -0
  96. package/dist/cjs/migrations/0006_consensus.d.ts +22 -0
  97. package/dist/cjs/migrations/0006_consensus.d.ts.map +1 -0
  98. package/dist/cjs/migrations/0006_consensus.js +84 -0
  99. package/dist/cjs/migrations/0006_consensus.js.map +7 -0
  100. package/dist/cjs/package.json +1 -0
  101. package/dist/cjs/test/Notifying.d.ts +65 -0
  102. package/dist/cjs/test/Notifying.d.ts.map +1 -0
  103. package/dist/cjs/test/Notifying.js +62 -0
  104. package/dist/cjs/test/Notifying.js.map +7 -0
  105. package/dist/cjs/test/TestJournal.d.ts +43 -0
  106. package/dist/cjs/test/TestJournal.d.ts.map +1 -0
  107. package/dist/cjs/test/TestJournal.js +43 -0
  108. package/dist/cjs/test/TestJournal.js.map +7 -0
  109. package/dist/esm/CallFact.d.ts +129 -0
  110. package/dist/esm/CallFact.d.ts.map +1 -0
  111. package/dist/esm/CallFact.js +96 -0
  112. package/dist/esm/CallFact.js.map +1 -0
  113. package/dist/esm/Consensus.d.ts +492 -0
  114. package/dist/esm/Consensus.d.ts.map +1 -0
  115. package/dist/esm/Consensus.js +536 -0
  116. package/dist/esm/Consensus.js.map +1 -0
  117. package/dist/esm/EngineEvent.d.ts +890 -0
  118. package/dist/esm/EngineEvent.d.ts.map +1 -0
  119. package/dist/esm/EngineEvent.js +614 -0
  120. package/dist/esm/EngineEvent.js.map +1 -0
  121. package/dist/esm/ExecutionFact.d.ts +216 -0
  122. package/dist/esm/ExecutionFact.d.ts.map +1 -0
  123. package/dist/esm/ExecutionFact.js +374 -0
  124. package/dist/esm/ExecutionFact.js.map +1 -0
  125. package/dist/esm/Journal.d.ts +617 -0
  126. package/dist/esm/Journal.d.ts.map +1 -0
  127. package/dist/esm/Journal.js +323 -0
  128. package/dist/esm/Journal.js.map +1 -0
  129. package/dist/esm/JournalEvent.d.ts +421 -0
  130. package/dist/esm/JournalEvent.d.ts.map +1 -0
  131. package/dist/esm/JournalEvent.js +517 -0
  132. package/dist/esm/JournalEvent.js.map +1 -0
  133. package/dist/esm/JournalGeneration.d.ts +34 -0
  134. package/dist/esm/JournalGeneration.d.ts.map +1 -0
  135. package/dist/esm/JournalGeneration.js +71 -0
  136. package/dist/esm/JournalGeneration.js.map +1 -0
  137. package/dist/esm/JournalMetrics.d.ts +72 -0
  138. package/dist/esm/JournalMetrics.d.ts.map +1 -0
  139. package/dist/esm/JournalMetrics.js +79 -0
  140. package/dist/esm/JournalMetrics.js.map +1 -0
  141. package/dist/esm/Migrations.d.ts +42 -0
  142. package/dist/esm/Migrations.d.ts.map +1 -0
  143. package/dist/esm/Migrations.js +59 -0
  144. package/dist/esm/Migrations.js.map +1 -0
  145. package/dist/esm/OwnerId.d.ts +40 -0
  146. package/dist/esm/OwnerId.d.ts.map +1 -0
  147. package/dist/esm/OwnerId.js +33 -0
  148. package/dist/esm/OwnerId.js.map +1 -0
  149. package/dist/esm/Projection.d.ts +29 -0
  150. package/dist/esm/Projection.d.ts.map +1 -0
  151. package/dist/esm/Projection.js +13 -0
  152. package/dist/esm/Projection.js.map +1 -0
  153. package/dist/esm/RedactedLogger.d.ts +121 -0
  154. package/dist/esm/RedactedLogger.d.ts.map +1 -0
  155. package/dist/esm/RedactedLogger.js +445 -0
  156. package/dist/esm/RedactedLogger.js.map +1 -0
  157. package/dist/esm/Redaction.d.ts +350 -0
  158. package/dist/esm/Redaction.d.ts.map +1 -0
  159. package/dist/esm/Redaction.js +1619 -0
  160. package/dist/esm/Redaction.js.map +1 -0
  161. package/dist/esm/SqlConsensus.d.ts +44 -0
  162. package/dist/esm/SqlConsensus.d.ts.map +1 -0
  163. package/dist/esm/SqlConsensus.js +273 -0
  164. package/dist/esm/SqlConsensus.js.map +1 -0
  165. package/dist/esm/SqlJournal.d.ts +173 -0
  166. package/dist/esm/SqlJournal.d.ts.map +1 -0
  167. package/dist/esm/SqlJournal.js +1858 -0
  168. package/dist/esm/SqlJournal.js.map +1 -0
  169. package/dist/esm/StepFact.d.ts +66 -0
  170. package/dist/esm/StepFact.d.ts.map +1 -0
  171. package/dist/esm/StepFact.js +50 -0
  172. package/dist/esm/StepFact.js.map +1 -0
  173. package/dist/esm/index.d.ts +95 -0
  174. package/dist/esm/index.d.ts.map +1 -0
  175. package/dist/esm/index.js +95 -0
  176. package/dist/esm/index.js.map +1 -0
  177. package/dist/esm/internal/JournalInternalFault.d.ts +37 -0
  178. package/dist/esm/internal/JournalInternalFault.d.ts.map +1 -0
  179. package/dist/esm/internal/JournalInternalFault.js +28 -0
  180. package/dist/esm/internal/JournalInternalFault.js.map +1 -0
  181. package/dist/esm/migrations/0001_initial.d.ts +15 -0
  182. package/dist/esm/migrations/0001_initial.d.ts.map +1 -0
  183. package/dist/esm/migrations/0001_initial.js +32 -0
  184. package/dist/esm/migrations/0001_initial.js.map +1 -0
  185. package/dist/esm/migrations/0002_checkpoints.d.ts +27 -0
  186. package/dist/esm/migrations/0002_checkpoints.d.ts.map +1 -0
  187. package/dist/esm/migrations/0002_checkpoints.js +38 -0
  188. package/dist/esm/migrations/0002_checkpoints.js.map +1 -0
  189. package/dist/esm/migrations/0003_startup_index.d.ts +15 -0
  190. package/dist/esm/migrations/0003_startup_index.d.ts.map +1 -0
  191. package/dist/esm/migrations/0003_startup_index.js +18 -0
  192. package/dist/esm/migrations/0003_startup_index.js.map +1 -0
  193. package/dist/esm/migrations/0004_dedup.d.ts +15 -0
  194. package/dist/esm/migrations/0004_dedup.d.ts.map +1 -0
  195. package/dist/esm/migrations/0004_dedup.js +38 -0
  196. package/dist/esm/migrations/0004_dedup.js.map +1 -0
  197. package/dist/esm/migrations/0005_run_event_type.d.ts +15 -0
  198. package/dist/esm/migrations/0005_run_event_type.d.ts.map +1 -0
  199. package/dist/esm/migrations/0005_run_event_type.js +18 -0
  200. package/dist/esm/migrations/0005_run_event_type.js.map +1 -0
  201. package/dist/esm/migrations/0006_consensus.d.ts +22 -0
  202. package/dist/esm/migrations/0006_consensus.d.ts.map +1 -0
  203. package/dist/esm/migrations/0006_consensus.js +69 -0
  204. package/dist/esm/migrations/0006_consensus.js.map +1 -0
  205. package/dist/esm/test/Notifying.d.ts +65 -0
  206. package/dist/esm/test/Notifying.d.ts.map +1 -0
  207. package/dist/esm/test/Notifying.js +62 -0
  208. package/dist/esm/test/Notifying.js.map +1 -0
  209. package/dist/esm/test/TestJournal.d.ts +43 -0
  210. package/dist/esm/test/TestJournal.d.ts.map +1 -0
  211. package/dist/esm/test/TestJournal.js +27 -0
  212. package/dist/esm/test/TestJournal.js.map +1 -0
  213. package/docs/README.md +166 -0
  214. package/docs/api.md +650 -0
  215. package/docs/concepts/compaction.md +157 -0
  216. package/docs/concepts/idempotency.md +127 -0
  217. package/docs/concepts/owner-fence.md +128 -0
  218. package/docs/concepts/redaction.md +222 -0
  219. package/docs/concepts/state-event-authority.md +159 -0
  220. package/docs/concepts/two-channels.md +167 -0
  221. package/docs/guides/commit-state-and-entry.md +114 -0
  222. package/docs/guides/compact-a-run.md +134 -0
  223. package/docs/guides/fold-a-projection.md +106 -0
  224. package/docs/guides/read-a-run.md +139 -0
  225. package/docs/guides/redact-log-output.md +94 -0
  226. package/docs/guides/testing.md +124 -0
  227. package/docs/guides/write-lifecycle-events.md +110 -0
  228. package/docs/installation.md +137 -0
  229. package/docs/quickstart.md +146 -0
  230. package/docs/troubleshooting.md +214 -0
  231. package/package.json +263 -3
  232. package/src/CallFact.ts +117 -0
  233. package/src/Consensus.ts +800 -0
  234. package/src/EngineEvent.ts +823 -0
  235. package/src/ExecutionFact.ts +433 -0
  236. package/src/Journal.ts +688 -0
  237. package/src/JournalEvent.ts +654 -0
  238. package/src/JournalGeneration.ts +83 -0
  239. package/src/JournalMetrics.ts +89 -0
  240. package/src/Migrations.ts +62 -0
  241. package/src/OwnerId.ts +42 -0
  242. package/src/Projection.ts +31 -0
  243. package/src/RedactedLogger.ts +483 -0
  244. package/src/Redaction.ts +1820 -0
  245. package/src/SqlConsensus.ts +384 -0
  246. package/src/SqlJournal.ts +2732 -0
  247. package/src/StepFact.ts +69 -0
  248. package/src/index.ts +109 -0
  249. package/src/internal/JournalInternalFault.ts +40 -0
  250. package/src/migrations/0001_initial.ts +41 -0
  251. package/src/migrations/0002_checkpoints.ts +46 -0
  252. package/src/migrations/0003_startup_index.ts +19 -0
  253. package/src/migrations/0004_dedup.ts +43 -0
  254. package/src/migrations/0005_run_event_type.ts +19 -0
  255. package/src/migrations/0006_consensus.ts +83 -0
  256. package/src/test/Notifying.ts +101 -0
  257. package/src/test/TestJournal.ts +52 -0
@@ -0,0 +1,1619 @@
1
+ /**
2
+ * Payload redaction for durable journal writes.
3
+ *
4
+ * The journal is permanent and broadly readable: every entry is replayed to
5
+ * sync subscribers and to time-travel consumers. A secret that reaches
6
+ * `payload_json` is therefore not a transient leak, so redaction happens once,
7
+ * on the journal write path, rather than at each reader.
8
+ *
9
+ * Redaction is an **observability** concern and is confined to journal events
10
+ * and export/display surfaces. It is deliberately not applied to executable
11
+ * state, `flows_runs.state_json`, attempt checkpoints, errors, outcomes, and
12
+ * cache results, because those are decoded and re-entered on resume: a
13
+ * placeholder there resumes the flow with the wrong data, and replacing a
14
+ * non-string value with a placeholder string makes the persisted state fail
15
+ * schema decode outright, leaving the run undrivable (issue #72). A value
16
+ * that must never reach durable executable state is a `Redacted` field in the
17
+ * caller's own schema, not a name-suffix guess made at the storage seam.
18
+ *
19
+ * The rule set is a best-effort textual net over credential shapes seen in
20
+ * real bug reports, plus structural redaction by sensitive field name. It is
21
+ * finite, so a value that must never persist belongs in a `Redacted` field of
22
+ * the caller's own schema. See https://journal.smithers.sh/concepts/redaction/
23
+ * for the rule set and how to replace it.
24
+ *
25
+ * @since 0.1.0
26
+ */
27
+ import * as Result from "effect/Result";
28
+ import * as Schema from "effect/Schema";
29
+ /** JSON text carrying an arbitrary decoded value. */
30
+ const UnknownFromJsonString = Schema.fromJsonString(Schema.Unknown);
31
+ /**
32
+ * The placeholder written in place of a redacted value.
33
+ *
34
+ * @since 0.1.0
35
+ * @category constants
36
+ */
37
+ export const placeholder = "[REDACTED]";
38
+ const isQuote = (char) => char === "\"" || char === "'" || char === "`";
39
+ const closers = { "{": "}", "[": "]", "(": ")" };
40
+ /**
41
+ * Whether the last {@link skipQuoted} or {@link skipContainer} found its
42
+ * closer. Both return the end of the text for a value that never closes, and
43
+ * for one that closes on the text's last character, so the end alone cannot
44
+ * say which.
45
+ */
46
+ let lastClosed = false;
47
+ /**
48
+ * The index just past the quote that closes the string opened at `open`. A
49
+ * quote nested n strings deep sits behind `depth` = 2^n - 1 backslashes, and
50
+ * the quote that closes it has that count modulo 2^(n+1). A string that is
51
+ * never closed, cut by a bound or by its producer, runs to the end of the
52
+ * text. A caller that knows the backslashes were doubled again passes a larger
53
+ * `modulus`.
54
+ */
55
+ const skipQuoted = (text, open, depth, modulus = 2 * (depth + 1), limit = text.length) => {
56
+ let end = open + 1;
57
+ while (end < limit) {
58
+ if (text[end] === text[open]) {
59
+ let slashes = 0;
60
+ for (let i = end - 1; i > open && text[i] === "\\"; i--)
61
+ slashes++;
62
+ if (slashes % modulus === depth) {
63
+ lastClosed = true;
64
+ return end + 1;
65
+ }
66
+ }
67
+ end++;
68
+ }
69
+ lastClosed = false;
70
+ return end;
71
+ };
72
+ /**
73
+ * The index just past the bracket that balances the one at `open`, skipping
74
+ * quoted strings at any escape depth. An unbalanced container runs to the end
75
+ * of the text.
76
+ */
77
+ const skipContainer = (text, open, limit = text.length) => {
78
+ const pending = [];
79
+ let end = open;
80
+ while (end < limit) {
81
+ const char = text[end];
82
+ if (isQuote(char)) {
83
+ let depth = 0;
84
+ while (text[end - 1 - depth] === "\\")
85
+ depth++;
86
+ end = skipQuoted(text, end, depth, 2 * (depth + 1), limit);
87
+ if (!lastClosed)
88
+ return end;
89
+ continue;
90
+ }
91
+ const closer = closers[char];
92
+ if (closer !== undefined)
93
+ pending.push(closer);
94
+ else if (char === pending.at(-1)) {
95
+ pending.pop();
96
+ if (pending.length === 0) {
97
+ lastClosed = true;
98
+ return end + 1;
99
+ }
100
+ }
101
+ end++;
102
+ }
103
+ lastClosed = false;
104
+ return end;
105
+ };
106
+ /**
107
+ * The escape depth of a quote behind `slashes` backslashes: 2^k - 1 for its k
108
+ * trailing escaped levels, so `\\"` (an escaped backslash, then a quote) is
109
+ * depth 0 and `\\\"` is depth 1.
110
+ */
111
+ const escapeDepth = (slashes) => (slashes ^ (slashes + 1)) >> 1;
112
+ const innermostString = (stack) => stack.at(-1)?.string ?? -1;
113
+ /**
114
+ * Updates `stack` with the brackets and strings that `text[from, to)` opens
115
+ * and closes. A quote closes the innermost open string it can close at that
116
+ * string's escape depth, and otherwise opens a string at its own depth. The
117
+ * other quote characters inside a string are content (`"don't"`).
118
+ */
119
+ const track = (stack, text, from, to) => {
120
+ for (let i = from; i < to; i++) {
121
+ const char = text[i];
122
+ if (isQuote(char)) {
123
+ let slashes = 0;
124
+ while (text[i - 1 - slashes] === "\\")
125
+ slashes++;
126
+ const inner = innermostString(stack);
127
+ if (inner === -1) {
128
+ stack.push({ close: char, depth: escapeDepth(slashes), string: stack.length });
129
+ continue;
130
+ }
131
+ if (stack[inner].close !== char)
132
+ continue;
133
+ // Only strings can close, so walk the strings alone, innermost first.
134
+ let closes = inner;
135
+ while (closes !== -1) {
136
+ const depth = stack[closes].depth;
137
+ if (slashes % (2 * (depth + 1)) === depth)
138
+ break;
139
+ closes = closes === 0 ? -1 : stack[closes - 1].string;
140
+ }
141
+ if (closes === -1)
142
+ stack.push({ close: char, depth: escapeDepth(slashes), string: stack.length });
143
+ else
144
+ stack.length = closes;
145
+ continue;
146
+ }
147
+ const closer = closers[char];
148
+ if (closer !== undefined)
149
+ stack.push({ close: closer, string: innermostString(stack) });
150
+ else if (stack.at(-1)?.depth === undefined && char === stack.at(-1)?.close)
151
+ stack.pop();
152
+ }
153
+ };
154
+ /**
155
+ * Whether the closer at `end` closes the bracket open before the name: it and
156
+ * any closers right after it balance the enclosing brackets, and a separator
157
+ * or the end of the text follows (`[{token:abc}]`, not `Tr0ub4dor)]&3`).
158
+ */
159
+ const closesEnclosing = (text, end, stack) => {
160
+ let at = end;
161
+ for (let k = stack.length - 1; k >= 0 && stack[k].depth === undefined && text[at] === stack[k].close; k--)
162
+ at++;
163
+ return at > end && /^(?:[\s,;"'`]|\\+["'`]|$)/.test(text.slice(at, at + 2));
164
+ };
165
+ /** Credential words a name ends in. */
166
+ const credentialWord = "(?:KEY|TOKEN|SECRET|PASSWORD|PASSPHRASE|CREDENTIAL)S?";
167
+ /**
168
+ * A name's separator: `=`, `:` or `=>`, after any quote that closes the name.
169
+ * In a durable row it stays on the name's line; a diagnostic also reads a
170
+ * value on the next line (`password:` then the value), which is how a stream
171
+ * redactor sees it arrive.
172
+ */
173
+ const separator = (space) => String.raw `(?:\\*["'\x60])?${space}(?:=>|[=:])${space}`;
174
+ /**
175
+ * A credential name and its separator. Start once per identifier, including
176
+ * leading underscores, so a name containing many underscores cannot force
177
+ * repeated scans of its suffix. The name may close a quote of its own
178
+ * (`'password':`, `\"token\":`), so a key in a Python repr, an inspected
179
+ * `Map` or escaped JSON meets the rule too.
180
+ */
181
+ const credentialName = String.raw `(?<![A-Za-z0-9_-])([A-Za-z0-9_-]*${credentialWord})`;
182
+ const credentialNames = new RegExp(credentialName + separator("[ \\t]*"), "gi");
183
+ const diagnosticNames = new RegExp(credentialName + separator(String.raw `\s*`), "gi");
184
+ /** Case-insensitive authorization names, without making scheme words prose matches. */
185
+ const authorizationName = "(?:proxy-)?authorization".replace(/[a-z]/g, (char) => `[${char}${char.toUpperCase()}]`);
186
+ /** Complete header names whose whole value is a credential whatever its scheme. */
187
+ const headerWord = String.raw `${authorizationName}|${"(?:set-)?cookies?".replace(/[a-z]/g, (char) => `[${char}${char.toUpperCase()}]`)}`;
188
+ // Apostrophes and backticks open quoted names only outside a header token.
189
+ const headerName = String
190
+ .raw `(?<![A-Za-z0-9!#$%&*+.^_|~-])(?<![A-Za-z0-9!#$%&'*+.^_\x60|~-]['\x60])(${headerWord})`;
191
+ const headerNames = new RegExp(String.raw `((?:proxy-)?authorization|(?:set-)?cookies?)${separator(String.raw `\s*`)}`, "gi");
192
+ /** Whitespace headers require a scheme spelling, so ordinary authorization prose survives. */
193
+ const diagnosticHeaderNames = new RegExp(
194
+ // A trailing token quote requires an opener; double quotes are never token characters.
195
+ `${headerName}(?:` +
196
+ String.raw `(?:(?<=["'\x60](?:${headerWord}))|(?!\\*['\x60]))${separator(String.raw `\s*`)}|` +
197
+ String.raw `(?<=${authorizationName})\s+(?=(?:Token|TOKEN|[Bb]earer|BEARER|Basic|BASIC)[ \t]+\S))`, "g");
198
+ /** Any credential or header name, to stop a bare value before the next pair. */
199
+ const anyName = new RegExp(`${credentialNames.source}|${headerNames.source}`, "gi");
200
+ /** A credential or header name and its separator ending the text before a quote. */
201
+ const nameBefore = new RegExp(`(?:${credentialNames.source}|${headerNames.source})$`, "i");
202
+ /**
203
+ * The index of the next credential or header name at or after `from`; with
204
+ * `quoted`, only a name written right after a quote.
205
+ */
206
+ const nextName = (text, from, quoted) => {
207
+ // No name starts between a search's start and what it found, so a later
208
+ // search from inside that span has the same answer. Values are read left to
209
+ // right, so this keeps every search over one text linear in total.
210
+ const cached = nameSearches[quoted ? 1 : 0];
211
+ if (cached.text === text && from >= cached.from && from <= cached.found)
212
+ return cached.found;
213
+ let found = text.length;
214
+ anyName.lastIndex = from;
215
+ for (let match = anyName.exec(text); match !== null; match = anyName.exec(text)) {
216
+ if (!quoted || isQuote(text[match.index - 1])) {
217
+ found = match.index;
218
+ break;
219
+ }
220
+ }
221
+ nameSearches[quoted ? 1 : 0] = { text, from, found };
222
+ return found;
223
+ };
224
+ /** The last search for any name and for a quoted name. */
225
+ const nameSearches = [{ text: "", from: 0, found: 0 }, { text: "", from: 0, found: 0 }];
226
+ /** The end of the line `index` is on. */
227
+ const lineEnd = (text, index) => {
228
+ // Every index up to a line's end shares that end, so the last answer serves
229
+ // each later value on the same line.
230
+ if (lastLine.text === text && index >= lastLine.from && index <= lastLine.end)
231
+ return lastLine.end;
232
+ newline.lastIndex = index;
233
+ const end = newline.exec(text)?.index ?? text.length;
234
+ lastLine = { text, from: index, end };
235
+ return end;
236
+ };
237
+ const newline = /[\r\n]/g;
238
+ let lastLine = { text: "", from: 0, end: 0 };
239
+ /**
240
+ * Whether the whitespace at `end` continues the one-token value that began at
241
+ * `start`: `util.inspect` separates a constructor or a marker from its
242
+ * contents (`Foo {`, `Map(1) {`, `[Object: null prototype] {`, `<ref *1> {`,
243
+ * `new Password(`).
244
+ */
245
+ const continuesAcrossSpace = (text, start, end) => {
246
+ const run = text.slice(start, end);
247
+ let next = end;
248
+ while (text[next] === " " || text[next] === "\t")
249
+ next++;
250
+ if (run === "new")
251
+ return next;
252
+ const prefix = /^[\w$.]+$/.test(run) || /[)\]>]$/.test(run);
253
+ return prefix && closers[text[next] ?? ""] !== undefined ? next : undefined;
254
+ };
255
+ /**
256
+ * Whether the `,`, `;` or `&` at `end` separates pairs rather than sitting
257
+ * inside a value (`Zq7;Syn,thetic`, `Tr0ub(4dor)&3`): a space or another name
258
+ * follows it, and for `&`, a query parameter (`&page=2`).
259
+ */
260
+ const separatesPairs = (text, end) => text[end] === "&"
261
+ ? /^&[A-Za-z_][\w.-]*=/.test(text.slice(end, end + 64))
262
+ : /^[,;](?:\s|$|\s*\\*["'`]?[A-Za-z_][\w.-]*\\*["'`]?\s*(?:=>|[=:]))/.test(text.slice(end, end + 64));
263
+ /**
264
+ * How far past its line every durable container may read, whatever the
265
+ * {@link Budget} has left: a pretty-printed credential object of this size
266
+ * is read whole on any row.
267
+ */
268
+ const containerWindow = 4096;
269
+ const containerBudget = 4;
270
+ /**
271
+ * The end of the bare value at `start`, read as a run of tokens: words,
272
+ * balanced containers anywhere in it (`{bcrypt}$2a$...`, `Tr0ub(4dor)&3`,
273
+ * `Some("x")`), inspect markers (`<Buffer 73 65>`, `<ref *1>`), and quoted
274
+ * parts. `stack` is what is open before the name: the value stops at a quote
275
+ * that closes the enclosing string, at a closer that closes the enclosing
276
+ * bracket, and before the next credential name.
277
+ */
278
+ const bareValueEnd = (text, start, scope, stack, budget) => {
279
+ const inner = stack[innermostString(stack)];
280
+ // A durable value never reads an unclosed quote past its line, and one it
281
+ // cannot close stops at its line. A bracket reads past 4 KiB only while
282
+ // the text's scan budget lasts: each unbalanced bracket costs a bounded
283
+ // scan, and all of them together a bounded multiple of the text.
284
+ const bound = scope.diagnostic ? text.length : lineEnd(text, start);
285
+ const window = scope.diagnostic
286
+ ? text.length
287
+ : Math.min(text.length, start + Math.max(containerWindow, budget.remaining));
288
+ // Never before the opener: a closed container may already have carried the
289
+ // value past its first line.
290
+ const unclosed = (open, end) => Math.max(open, Math.min(end, bound));
291
+ // A durable container first reads its own line. A pretty-printer only
292
+ // continues one on the next line after the opener or a member's comma
293
+ // (`apiKey: {`, `credentials: { a: 1,`), so only then does the scan read on
294
+ // through the window.
295
+ const container = (open) => {
296
+ if (scope.diagnostic)
297
+ return skipContainer(text, open, window);
298
+ const end = skipContainer(text, open, bound);
299
+ if (lastClosed || !/[[{(,]\s*$/.test(text.slice(open, bound)))
300
+ return end;
301
+ const past = skipContainer(text, open, window);
302
+ budget.remaining -= past - open;
303
+ return past;
304
+ };
305
+ let end = start;
306
+ // The value's own first token is never the next name: in
307
+ // `api_key=lowercase-secret:end` the value only looks like a `name:` pair.
308
+ let limit = nextName(text, start + 1, scope.header);
309
+ // A header value that is one container ends with it: `"cookie":["sid=a"],`.
310
+ if (scope.header && closers[text[start]] !== undefined) {
311
+ end = container(start);
312
+ if (!/^[^\s,;"'`\\)\]}]/.test(text[end] ?? " "))
313
+ return lastClosed ? end : unclosed(start, end);
314
+ }
315
+ while (end < text.length) {
316
+ if (end >= limit) {
317
+ if (end === limit)
318
+ break;
319
+ limit = nextName(text, end, scope.header);
320
+ continue;
321
+ }
322
+ const char = text[end];
323
+ if (closers[char] !== undefined) {
324
+ const open = end;
325
+ end = container(open);
326
+ // An unbalanced container runs on, spaces included.
327
+ if (!lastClosed)
328
+ return unclosed(open, end);
329
+ continue;
330
+ }
331
+ if (char === "<") {
332
+ angleClose.lastIndex = end;
333
+ const close = angleClose.exec(text)?.index;
334
+ if (close !== undefined && text[close] === ">") {
335
+ end = close + 1;
336
+ continue;
337
+ }
338
+ }
339
+ let depth = 0;
340
+ while (text[end + depth] === "\\")
341
+ depth++;
342
+ const quote = text[end + depth];
343
+ if (isQuote(quote)) {
344
+ // A quote at the enclosing string's depth or shallower closes it,
345
+ // whatever precedes it (`Basic abc=`), unless a credential name and
346
+ // separator precede it (`credential:"`). Inside a bracket, a field's
347
+ // value ends at a quote (`{\"token\":abc\"}`). Any other quote opens a
348
+ // quoted part of the value (`username="admin"`, `it's`).
349
+ const closesString = inner !== undefined && quote === inner.close &&
350
+ depth % (2 * (inner.depth + 1)) <= inner.depth &&
351
+ !nameBefore.test(text.slice(Math.max(start, end - 256), end));
352
+ if (closesString || (!scope.header && inner === undefined && stack.length > 0))
353
+ break;
354
+ // A quote between two word characters is an apostrophe (`it's`).
355
+ if (depth === 0 && /\w/.test(text[end - 1] ?? "") && /\w/.test(text[end + 1] ?? "")) {
356
+ end++;
357
+ continue;
358
+ }
359
+ const open = end;
360
+ end = skipQuoted(text, end + depth, depth, 2 * (depth + 1), bound);
361
+ if (!lastClosed)
362
+ return unclosed(open, end);
363
+ continue;
364
+ }
365
+ if (char === "\r" || char === "\n")
366
+ break;
367
+ // Inside a bracket a `,` or `;` separates members; in raw text it does
368
+ // when a space or another name follows.
369
+ if (!scope.header &&
370
+ ((char === "&" && separatesPairs(text, end)) ||
371
+ ((char === "," || char === ";") && (stack.length > 0 || separatesPairs(text, end)))))
372
+ break;
373
+ if (!scope.header && !scope.diagnostic && (char === " " || char === "\t")) {
374
+ const next = continuesAcrossSpace(text, start, end);
375
+ if (next === undefined)
376
+ break;
377
+ end = next;
378
+ continue;
379
+ }
380
+ if (closesEnclosing(text, end, stack))
381
+ break;
382
+ end++;
383
+ }
384
+ while (end > start && /\s/.test(text[end - 1]))
385
+ end--;
386
+ return end;
387
+ };
388
+ /**
389
+ * Whether a name ending in `key` or `keys` is not a credential's: it counts
390
+ * only where {@link isSensitiveKey} agrees, as it does for the same name as an
391
+ * object key (`apiKeys` counts; `keys`, `sortKeys`, `idempotencyKey` and
392
+ * `monkey` do not).
393
+ */
394
+ const plainKeyName = (name) => /keys?$/i.test(name) && !isSensitiveKey(name);
395
+ /**
396
+ * The end of a credential that is a URL's password (`//x-access-token:secret@`):
397
+ * the `@` that closes the userinfo, so the host and path stay readable. Any
398
+ * other bare value keeps its end.
399
+ */
400
+ const userinfoEnd = (text, start, end) => {
401
+ if (!/\/\/[^\s/@?#]*[:=]$/.test(text.slice(Math.max(0, start - 128), start)))
402
+ return end;
403
+ const value = text.slice(start, end);
404
+ const authority = value.search(/[/?#]/);
405
+ const at = value.lastIndexOf("@", authority < 0 ? value.length : authority);
406
+ return at > 0 ? start + at : end;
407
+ };
408
+ /**
409
+ * Whether a name that matched a credential word names a credential: not a
410
+ * {@link plainKeyName}, and not a count under a plural `tokens` name
411
+ * (`max_tokens: 4096`), which is accounting.
412
+ */
413
+ const namesCredential = (name, value) => !plainKeyName(name) &&
414
+ !(/tokens$/i.test(name) && /^["'`]?\d+(?![\w.])/.test(value));
415
+ /** The `>` that closes an inspect marker, or the line end that means there is none. */
416
+ const angleClose = /[>\r\n]/g;
417
+ /**
418
+ * The `+` with which `util.inspect` continues a long string on the next line,
419
+ * its newline raw or escaped (`\\n`) when the inspected text was itself
420
+ * written into a string.
421
+ */
422
+ const continuation = /(?:\s|\\+[nrt])*\+(?:\s|\\+[nrt])*/y;
423
+ /** A value an earlier pass already replaced. */
424
+ const alreadyRedacted = /^\[REDACTED\]$/;
425
+ /**
426
+ * Redacts the value after each name `names` matches. A quoted value is
427
+ * consumed whole at any string-escape depth, with the pieces `util.inspect`
428
+ * joins with `+` across lines, and its quotes are kept around the
429
+ * placeholder; a bare value is consumed as a run of tokens. A name that ends
430
+ * in `key` counts only where {@link isSensitiveKey} agrees, so `sortKey` and
431
+ * `idempotencyKey` keep their values, and a count under a plural `tokens`
432
+ * name, `max_tokens: 4096`, is accounting and is kept too.
433
+ */
434
+ const redactValues = (text, names, scope) => {
435
+ const keys = new RegExp(names.source, names.flags);
436
+ let output = "";
437
+ let position = 0;
438
+ // What is open before the current value. Values are skipped, so a bracket
439
+ // or quote inside a credential never counts.
440
+ const stack = [];
441
+ const budget = { remaining: containerBudget * text.length };
442
+ let scanned = 0;
443
+ for (let match = keys.exec(text); match !== null; match = keys.exec(text)) {
444
+ const name = match[1];
445
+ if (!scope.header && plainKeyName(name))
446
+ continue;
447
+ track(stack, text, scanned, keys.lastIndex);
448
+ scanned = keys.lastIndex;
449
+ // A call's `key=` naming a function (`sorted(xs, key=lambda m: m[0])`)
450
+ // is code: a literal credential there would be quoted.
451
+ if (!scope.diagnostic && name === "key" && text[keys.lastIndex - 1] === "=" &&
452
+ stack.at(-1)?.close === ")" && stack.at(-1)?.depth === undefined &&
453
+ /^[A-Za-z_][\w.]*(?=[\s(),])/.test(text.slice(keys.lastIndex, keys.lastIndex + 256)))
454
+ continue;
455
+ let start = keys.lastIndex;
456
+ let depth = 0;
457
+ while (text[start + depth] === "\\")
458
+ depth++;
459
+ const opener = text[start + depth];
460
+ const quote = isQuote(opener) ? opener : undefined;
461
+ let end;
462
+ if (quote !== undefined) {
463
+ start += depth;
464
+ const inner = stack[innermostString(stack)];
465
+ if (inner !== undefined) {
466
+ // Inside a string written with another quote character, every
467
+ // backslash is doubled again: `inspect` renders `"a\"b"` as
468
+ // `'"a\\"b"'`.
469
+ end = skipQuoted(text, start, depth, (inner.close === quote ? 1 : 2 * (inner.depth + 1)) * 2 * (depth + 1));
470
+ }
471
+ else {
472
+ // No enclosing string is visible: raw text, or a string `track` cannot
473
+ // see. Close no earlier than a doubled string would, but never past the
474
+ // next credential name: at the undoubled close when only separators
475
+ // precede that name (`"abc\\", password=`), else at the name.
476
+ const undoubled = skipQuoted(text, start, depth);
477
+ end = skipQuoted(text, start, depth, Math.max(4, 2 * (depth + 1)));
478
+ const next = nextName(text, undoubled, false);
479
+ if (next < end)
480
+ end = /^[\s,;&]*$/.test(text.slice(undoubled, next)) ? undoubled : next;
481
+ }
482
+ const closed = end - start > 1 && text[end - 1] === quote;
483
+ if (!closed && !scope.diagnostic)
484
+ end = Math.min(end, lineEnd(text, start));
485
+ // `util.inspect` continues a long string on the next line with `+`.
486
+ if (depth === 0) {
487
+ for (continuation.lastIndex = end; continuation.test(text); continuation.lastIndex = end) {
488
+ const piece = continuation.lastIndex;
489
+ if (!isQuote(text[piece]))
490
+ break;
491
+ end = skipQuoted(text, piece, 0);
492
+ }
493
+ }
494
+ if (alreadyRedacted.test(text.slice(start + 1, end - (text[end - 1] === quote ? 1 + depth : 0))))
495
+ continue;
496
+ }
497
+ else {
498
+ end = bareValueEnd(text, start, scope, stack, budget);
499
+ end = userinfoEnd(text, start, end);
500
+ // In a journal row a placeholder then a space is a value an earlier pass
501
+ // already bounded: what follows it is the next part of the line,
502
+ // `{"statusCode":401}`. A diagnostic value runs over several words, so
503
+ // there the words after a placeholder are still the value.
504
+ const bounded = !scope.diagnostic && text.startsWith(placeholder, start) &&
505
+ /\s/.test(text[start + placeholder.length] ?? "");
506
+ const kept = end === start || bounded || alreadyRedacted.test(text.slice(start, end)) ||
507
+ (/tokens$/i.test(name) && /^\d+(?![\w.])/.test(text.slice(start, end))) ||
508
+ // A Bearer or Basic value the default rules already replaced keeps its scheme.
509
+ (scope.header && /^(?:bearer|basic)\s+\[REDACTED/i.test(text.slice(start, start + 24)));
510
+ if (kept)
511
+ continue;
512
+ }
513
+ const escape = quote === undefined ? "" : "\\".repeat(depth);
514
+ const closed = quote !== undefined && end - start > 1 && text[end - 1] === quote;
515
+ output += text.slice(position, keys.lastIndex) + escape + (quote ?? "") + placeholder +
516
+ (closed ? escape + quote : "");
517
+ position = end;
518
+ scanned = end;
519
+ keys.lastIndex = end;
520
+ }
521
+ return output + text.slice(position);
522
+ };
523
+ /**
524
+ * What separates a flag from its value: whitespace on a command line, or
525
+ * `", "` between two elements of a JSON or inspected array.
526
+ */
527
+ const argumentSeparator = String.raw `(?:\s+|["'\x60]\s*,\s*["'\x60])`;
528
+ /** A credential flag and the separator before its value. */
529
+ const credentialFlag = new RegExp(String.raw `(?<![A-Za-z0-9_-])(--?[A-Za-z0-9_-]*${credentialWord})${argumentSeparator}`, "gi");
530
+ /** `-p` and the separator before its value, unless the value is a path or a long option. */
531
+ const shortPasswordFlag = new RegExp(String.raw `(?<![^\s"'\x60,[(])-p${argumentSeparator}(?!(?:\.{0,2}|~)\/|--)`, "g");
532
+ /**
533
+ * A flag that always takes a password, and the separator before it: `plink
534
+ * -pw`, openssl's `-pass`, `-passin` and `-passout` (`pass:secret`), `-passwd`.
535
+ */
536
+ const passwordFlag = new RegExp(String.raw `(?<![^\s"'\x60,[(])-p(?:w|ass(?:in|out|wd)?)${argumentSeparator}`, "g");
537
+ /** `-p` with a value attached, unless the word is a known single-dash option. */
538
+ const attachedPasswordFlag = new RegExp(String
539
+ .raw `(?<![^\s"'\x60,[(])-p(?!(?:rint\w*|rune|erm|ath|threads?|edantic[\w-]*|ipe|ie|g|retty|lain|rogress|rofile|arents|reserve|ass(?:in|out|wd)?|w)(?![^\s"'\x60,\]]))(?=[^\s,\]])`, "g");
540
+ /** `-u` or `--user` and the separator before its value, or `-u` with its value attached (`-uadmin:pw`). */
541
+ const userFlag = new RegExp(String.raw `(?<![^\s"'\x60,[(])(?:(?:-u|--user)(?:=|${argumentSeparator})|-u(?=[^\s=-]))`, "g");
542
+ /**
543
+ * A flag that takes a password only under one command, and the separator
544
+ * before its value: `zip -P` (a port to `ssh` and `mysql`) and `redis-cli -a`
545
+ * or `--pass`. The command is looked for at most 256 characters back on the
546
+ * same command line.
547
+ */
548
+ const commandPasswordFlag = new RegExp(String
549
+ .raw `\b(?:(?:(?:un)?zip|zipcloak)\b[^\r\n|;&]{0,256}?[\s"'\x60,[(]-P|redis-cli\b[^\r\n|;&]{0,256}?[\s"'\x60,[(](?:-a|--pass))${argumentSeparator}`, "g");
550
+ /**
551
+ * An HTTP header written as a name and value pair of an array
552
+ * (`[['Authorization', 'Token x']]`), the shape `Headers` entries and many
553
+ * clients log, up to the quote that opens the value.
554
+ */
555
+ const headerPair = /(?<![A-Za-z0-9_-])(?:(?:proxy-)?authorization|(?:set-)?cookies?)\\*["'`]\s*,\s*(?=\\*["'`])/gi;
556
+ /** Redacts the quoted value of each {@link headerPair}, keeping its quotes. */
557
+ const redactHeaderPairs = (text) => {
558
+ const pattern = new RegExp(headerPair.source, headerPair.flags);
559
+ let output = "";
560
+ let position = 0;
561
+ for (let match = pattern.exec(text); match !== null; match = pattern.exec(text)) {
562
+ let depth = 0;
563
+ while (text[pattern.lastIndex + depth] === "\\")
564
+ depth++;
565
+ const open = pattern.lastIndex + depth;
566
+ const end = skipQuoted(text, open, depth);
567
+ const close = lastClosed ? end - 1 - depth : end;
568
+ if (alreadyRedacted.test(text.slice(open + 1, close)))
569
+ continue;
570
+ output += text.slice(position, open + 1) + placeholder;
571
+ position = close;
572
+ pattern.lastIndex = end;
573
+ }
574
+ return output + text.slice(position);
575
+ };
576
+ /** The placeholder alone, bare, quoted or escaped: a second pass leaves it alone. */
577
+ const redactedArgument = /^(?:\\*(["'`]))?\[REDACTED\](?:\\*\1)?$/;
578
+ /**
579
+ * The end of the unquoted argument at `start`. It runs to whitespace or a
580
+ * quote, and on through a quoted part written against it (`abc'def'`, which a
581
+ * shell reads as one argument) when that part closes before any whitespace
582
+ * and holds none of `,:{}[]`. Any other quote ends it: the close of a string
583
+ * the command line sits in (`{"cmd":"mysql -p abc","next":1}`).
584
+ */
585
+ const wordEnd = (text, start) => {
586
+ let end = start;
587
+ while (end < text.length && !/\s/.test(text[end])) {
588
+ const quote = text[end];
589
+ if (!isQuote(quote)) {
590
+ end++;
591
+ continue;
592
+ }
593
+ let close = end + 1;
594
+ while (close < text.length && !/[\s"'`,:{}[\]]/.test(text[close]))
595
+ close++;
596
+ if (close === end + 1 || text[close] !== quote)
597
+ break;
598
+ end = close + 1;
599
+ }
600
+ return end;
601
+ };
602
+ /**
603
+ * Redacts the value after each flag `flags` matches: a quoted value, or one
604
+ * argv word, which ends at whitespace or a quote, so the same rule reads a
605
+ * command line joined by spaces, a JSON array and an inspected array. A comma
606
+ * or a `]` is part of a password on a command line (`-p abc,def`); in an
607
+ * array the element's closing quote ends it first.
608
+ */
609
+ const redactArguments = (text, flags,
610
+ /** Whether this flag and value are a credential at all. */
611
+ accept) => {
612
+ const pattern = new RegExp(flags.source, flags.flags);
613
+ let output = "";
614
+ let position = 0;
615
+ for (let match = pattern.exec(text); match !== null; match = pattern.exec(text)) {
616
+ const start = pattern.lastIndex;
617
+ let depth = 0;
618
+ while (text[start + depth] === "\\")
619
+ depth++;
620
+ let end = start;
621
+ if (isQuote(text[start + depth]))
622
+ end = skipQuoted(text, start + depth, depth);
623
+ else
624
+ end = wordEnd(text, start);
625
+ const value = text.slice(start, end);
626
+ if (end === start || redactedArgument.test(value) || accept?.(match, value) === false)
627
+ continue;
628
+ output += text.slice(position, start) + placeholder;
629
+ position = end;
630
+ pattern.lastIndex = end;
631
+ }
632
+ return output + text.slice(position);
633
+ };
634
+ const durable = { header: false, diagnostic: false };
635
+ /**
636
+ * Best-effort textual rules for credential shapes observed in real reports.
637
+ * Every replacement reaches a fixed point so replaying or exporting an entry
638
+ * cannot mutate it again.
639
+ *
640
+ * @since 0.1.0
641
+ * @category constants
642
+ */
643
+ export const defaultRules = [
644
+ {
645
+ id: "private-key-block",
646
+ // Stop an unterminated block at the next header so repeated headers cannot
647
+ // each rescan the remaining input. A valid PEM body contains no headers.
648
+ // A block with no footer is a key a bound or a producer truncated, and its
649
+ // body is as secret as a whole one's, so it runs to the next header or to
650
+ // the end of the text. It runs first: a block inside URL userinfo, once
651
+ // replaced, is userinfo the URL rule then reads whole, so a second pass
652
+ // finds nothing left to change.
653
+ pattern: /-----BEGIN[^-]*PRIVATE KEY(?: BLOCK)?-----(?:(?!-----BEGIN)[\s\S])*?(?:-----END[^-]*-----|(?=-----BEGIN)|$)/g
654
+ },
655
+ // Git HTTPS OAuth credentials place the secret in the username. Match
656
+ // before password rewriting removes the x-oauth-basic marker.
657
+ {
658
+ id: "git-oauth-userinfo",
659
+ pattern: /(https?:\/\/)[^\s/@:"'\\]+:x-oauth-basic@/gi,
660
+ replace: "$1[REDACTED]@"
661
+ },
662
+ {
663
+ id: "url-credentials",
664
+ // The scheme is bounded rather than open. `-` is not a word character, so
665
+ // `\b[a-z][a-z0-9+.-]*` starts a fresh scan after every hyphen, and on a
666
+ // long run of that shape the rule rescanned the tail from each one: 400 kB
667
+ // of `aaaaaaaa-` cost 11 seconds, on the path every journal write and every
668
+ // log line takes. A scheme longer than 30 characters is not one this net is
669
+ // for, and the cap makes each start position cost a constant.
670
+ //
671
+ // The username may be empty (`redis://:password@host`), and the password
672
+ // runs to the LAST `@` before the authority ends, as a URL parser reads
673
+ // it: RFC 3986 allows `:` in a password and a raw `@` is common in
674
+ // connection strings. Stopping at the first `:` or `@` left the tail of
675
+ // such a password in the row. Quotes and backslashes end the scan so a
676
+ // URL inside JSON text never swallows the next string.
677
+ pattern: /\b([a-z][a-z0-9+.-]{0,30}:\/\/[^\s:@/]*):(?!\[REDACTED\]@)[^\s/?#"'`\\]*@/gi,
678
+ replace: "$1:[REDACTED]@"
679
+ },
680
+ {
681
+ id: "bearer-token",
682
+ pattern: /\bBearer\s+[A-Za-z0-9._~+/-]{4,}=*/gi,
683
+ replace: "Bearer [REDACTED_TOKEN]"
684
+ },
685
+ {
686
+ id: "basic-authorization",
687
+ // Only the scheme's own spellings: a lowercase `basic` is a word or a
688
+ // module (`module_utils.basic import`).
689
+ pattern: /\b(?:Basic|BASIC)\s+[A-Za-z0-9+/]{4,}={0,2}/g,
690
+ replace: "Basic [REDACTED_TOKEN]"
691
+ },
692
+ {
693
+ id: "jwt",
694
+ // Check the three segments once per token before looking for a header.
695
+ // Starting at every `-eyJ` would rescan a malformed token's entire tail.
696
+ // Preserve any prefix so a JWT following a hyphen still gets redacted.
697
+ pattern: /(?<![A-Za-z0-9_-])(?=[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-])([A-Za-z0-9_-]*?)\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
698
+ replace: "$1[REDACTED_TOKEN]"
699
+ },
700
+ {
701
+ id: "api-key",
702
+ // Not `\b`, for the reason the assignment rule below gives: an underscore
703
+ // is a word character, so `\bsk` never fires after `ANTHROPIC_` or after
704
+ // Effect's log-span sanitizer folds `token=` into `token_`. The lookbehind
705
+ // excludes only letters and digits, so a key still reads as a key when an
706
+ // underscore or a hyphen runs into it.
707
+ pattern: /(?<![A-Za-z0-9])(?:sk|pk)[-_][A-Za-z0-9][A-Za-z0-9_-]{7,}/g,
708
+ replace: "[REDACTED_API_KEY]"
709
+ },
710
+ {
711
+ id: "github-token",
712
+ pattern: /\bgh[pousr]_[A-Za-z0-9]{20,}(?![A-Za-z0-9])/g,
713
+ replace: "[REDACTED]"
714
+ },
715
+ {
716
+ id: "github-fine-grained-token",
717
+ pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}(?![A-Za-z0-9_])/g,
718
+ replace: "[REDACTED]"
719
+ },
720
+ {
721
+ id: "aws-access-key",
722
+ pattern: /\bAKIA[0-9A-Z]{16}\b/g,
723
+ replace: "[REDACTED]"
724
+ },
725
+ {
726
+ id: "slack-token",
727
+ pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,}(?![A-Za-z0-9-])/g,
728
+ replace: "[REDACTED]"
729
+ },
730
+ {
731
+ id: "google-api-key",
732
+ pattern: /\bAIza[0-9A-Za-z_-]{35,}(?![0-9A-Za-z_-])/g,
733
+ replace: "[REDACTED]"
734
+ },
735
+ {
736
+ id: "gitlab-token",
737
+ pattern: /\bglpat-[A-Za-z0-9_-]{20,}(?![A-Za-z0-9_-])/g,
738
+ replace: "[REDACTED]"
739
+ },
740
+ {
741
+ id: "npm-token",
742
+ pattern: /\bnpm_[A-Za-z0-9]{36}(?![A-Za-z0-9])/g,
743
+ replace: "[REDACTED]"
744
+ },
745
+ {
746
+ // The webhook path is the whole credential: anyone holding it can post
747
+ // to the channel. The host stays so a failed delivery is still readable.
748
+ id: "slack-webhook",
749
+ pattern: /(\bhooks\.slack\.com\/services\/)T[A-Z0-9]+\/B[A-Z0-9]+\/[A-Za-z0-9]+/g,
750
+ replace: "$1[REDACTED]"
751
+ },
752
+ {
753
+ id: "assignment",
754
+ // A credential name, `:`, `=` or `=>`, and its whole value: quoted at any
755
+ // escape depth, a container, or several bare words. See `redactValues`.
756
+ pattern: credentialNames,
757
+ rewrite: (text) => redactValues(text, credentialNames, durable)
758
+ },
759
+ {
760
+ id: "credential-flag",
761
+ // `--password hunter2`, `--api-key "a b"`, or the same pair as two argv
762
+ // elements. `--token=x` is an assignment above; this is the spelling a
763
+ // command line separates with a space. The next word is the value even
764
+ // when it starts with `-`: a credential flag always takes one.
765
+ pattern: credentialFlag,
766
+ rewrite: (text) => redactArguments(text, credentialFlag, (match, value) => namesCredential(match[1].replace(/^-+/, ""), value))
767
+ },
768
+ {
769
+ id: "cookie-session-assignment",
770
+ pattern: /(?<![A-Za-z0-9-])((?:COOKIE|SESSION)S?)(\s*=\s*)(?!\[REDACTED\])("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|(?!["'])[^\s;,]+)/gi,
771
+ replace: "$1$2[REDACTED]"
772
+ }
773
+ ];
774
+ /**
775
+ * The rules for a diagnostic: {@link defaultRules} and the spellings too broad
776
+ * for a durable row.
777
+ *
778
+ * A log line, a stderr message, and an error handed to a remote caller are
779
+ * read once, so a false positive costs a word of context. A journal row is
780
+ * permanent, so the same false positive destroys data. These rules sit on the
781
+ * diagnostic side of that line: an authorization header in any scheme, bare
782
+ * URL userinfo (`https://token@host`), a signed query parameter, and the value
783
+ * of a `-p` flag, which is a password to `mysql` and `sshpass` and a path to
784
+ * `mkdir`. A path, a port and a lowercase word attached to `-p` (`-print`,
785
+ * `-path`) are left alone.
786
+ *
787
+ * @since 1.0.0
788
+ * @category constants
789
+ */
790
+ export const diagnosticRules = [
791
+ ...defaultRules.map((rule) => rule.id === "assignment"
792
+ ? {
793
+ id: "assignment",
794
+ pattern: diagnosticNames,
795
+ rewrite: (text) => redactValues(text, diagnosticNames, { header: false, diagnostic: true })
796
+ }
797
+ : rule),
798
+ {
799
+ id: "authorization-header",
800
+ // The header value is a credential whatever its scheme (`Token`, a cookie
801
+ // list, `Digest` with quoted parameters), so the value runs to the end of
802
+ // its line or the close of the string it was written in.
803
+ // A lookbehind-free superset lets the compiled prefilter skip ordinary prose.
804
+ pattern: /(?:proxy-)?authorization|(?:set-)?cookies?/gi,
805
+ rewrite: (text) => redactValues(text, diagnosticHeaderNames, { header: true, diagnostic: true })
806
+ },
807
+ {
808
+ id: "bearer-or-basic",
809
+ // A token shorter than the default rules' minimum. A lowercase `basic` is
810
+ // prose ("a basic example"), so only the scheme's own spellings count.
811
+ pattern: /(\b(?:[Bb]earer|BEARER|Basic|BASIC)\s+)(?!\[REDACTED)[^\s,;"'\\]+/g,
812
+ replace: "$1[REDACTED]"
813
+ },
814
+ {
815
+ id: "password-flag",
816
+ // The whole next argument, a path or a leading `-` included.
817
+ pattern: passwordFlag,
818
+ rewrite: (text) => redactArguments(text, passwordFlag)
819
+ },
820
+ {
821
+ id: "sshpass-password",
822
+ // `sshpass -p` always takes a value, even one that starts with `--`,
823
+ // which `mysql -p --database x` reads as the next option.
824
+ pattern: /(\bsshpass(?:\s+-[^\sp]\S*){0,8}\s+-p\s+)--(?!\[REDACTED\])[^\s"'`]*/g,
825
+ replace: "$1[REDACTED]"
826
+ },
827
+ {
828
+ id: "user-flag",
829
+ // `curl -u user:pass`, `--user=user:pass`, quoted or not: the whole
830
+ // argument, commas included, when it carries a `:`.
831
+ pattern: userFlag,
832
+ rewrite: (text) => redactArguments(text, userFlag, (_match, value) => value.includes(":"))
833
+ },
834
+ {
835
+ id: "header-pair",
836
+ pattern: headerPair,
837
+ rewrite: redactHeaderPairs
838
+ },
839
+ {
840
+ id: "command-password-flag",
841
+ // The whole next argument, whatever it starts with.
842
+ pattern: commandPasswordFlag,
843
+ rewrite: (text) => redactArguments(text, commandPasswordFlag)
844
+ },
845
+ {
846
+ id: "url-userinfo",
847
+ pattern: /(\/\/)(?!\[REDACTED\]@)(?![^/@\s"'\\]*:\[REDACTED\]@)[^/@\s"'\\]+@/g,
848
+ replace: "$1[REDACTED]@"
849
+ },
850
+ {
851
+ id: "signed-query",
852
+ pattern: /([?&][\w.-]*(?:key|sig|signature|auth|credential)=)(?!\[REDACTED\])[^&#\s"'\\]+/gi,
853
+ replace: "$1[REDACTED]"
854
+ },
855
+ {
856
+ id: "short-password-flag",
857
+ // A path is kept, and so is a flag: `mysql -p --database x` prompts for
858
+ // the password rather than taking one.
859
+ pattern: shortPasswordFlag,
860
+ rewrite: (text) => redactArguments(text, shortPasswordFlag)
861
+ },
862
+ {
863
+ id: "attached-password-flag",
864
+ // `-psecret`. The single-dash words that start with `p` and are not a
865
+ // password, `find -print` and the compilers' `-pthread` among them, are kept.
866
+ pattern: attachedPasswordFlag,
867
+ rewrite: (text) => redactArguments(text, attachedPasswordFlag)
868
+ }
869
+ ];
870
+ /**
871
+ * Redacts one diagnostic value with {@link diagnosticRules}: a log line, a
872
+ * stderr message, an error handed back to a caller.
873
+ *
874
+ * Every diagnostic path shares this one function, and it runs on the value
875
+ * before anything renders or bounds it. Redacting a rendering line by line, or
876
+ * after a bound, is how a secret escaped: `util.inspect` splits a long string
877
+ * over several lines, and a bound cuts a quoted value before its closing
878
+ * quote. A value past {@link maxDepth} is named rather than thrown.
879
+ *
880
+ * @since 1.0.0
881
+ * @category redaction
882
+ */
883
+ export const redactDiagnostic = (value) => redact(value, { rules: diagnosticRules, onTooDeep: "name" });
884
+ /**
885
+ * Credential names this module refuses to persist, matched as suffixes of the
886
+ * separator-free lowercase form of a key.
887
+ *
888
+ * The list is the union of the names `packages/smithers/src/Bug.ts` redacts
889
+ * structurally, because the journal is the PERMANENT side of that pair: a bug
890
+ * report is one upload an operator reviews before it leaves the machine, while
891
+ * `flows_journal_events.payload_json` is replayed verbatim to every sync
892
+ * subscriber and time-travel consumer forever. The journal redacting less than
893
+ * the report inverts the risk, and it did: `credential`, `credentials`, `dsn`,
894
+ * and `connectionString` all round-tripped through a durable row in clear.
895
+ *
896
+ * Two families are spelled out rather than reduced to a shorter word, because
897
+ * these are SUFFIX tests: `connectionString` does not end in `connection`, and
898
+ * `secretKey` does not end in `secret`. A bare `key` suffix is not on the list
899
+ * for the opposite reason: it would redact `monkey` and `turkey`.
900
+ *
901
+ * `signature` stays, and a field it costs is renamed rather than excused. A
902
+ * name test cannot tell a MAC computed with a secret from a digest over public
903
+ * input, and both are called `signature`: `WorkspaceShare` signs its claims
904
+ * with `ShareSigner.signHmac` and that value IS the share's authorization,
905
+ * `GrantStore` carries envelope signatures, and the GitHub, Linear and
906
+ * Telegram webhook readers all verify a header by that name. Against those, a
907
+ * digest whose whole purpose is to be reconciled costs nothing to rename and
908
+ * everything to leave unreadable -- see
909
+ * `AgentEvent.VacuousVerificationObserved.callDigest`, which was `signature`
910
+ * and reached durable rows as the placeholder.
911
+ */
912
+ const sensitiveKeySuffixes = [
913
+ "auth",
914
+ "authorization",
915
+ "cookie",
916
+ "apikey",
917
+ "token",
918
+ "password",
919
+ "passphrase",
920
+ "secret",
921
+ "secretaccesskey",
922
+ "credential",
923
+ "dsn",
924
+ "connection",
925
+ "connectionstring",
926
+ "connectionuri",
927
+ "connectionurl",
928
+ "secretkey",
929
+ "privatekey",
930
+ "sshkey",
931
+ "signingkey",
932
+ "signature",
933
+ "encryptionkey",
934
+ "session",
935
+ "sessionkey"
936
+ ];
937
+ /**
938
+ * A trailing `key` that is a word of its own.
939
+ *
940
+ * Read against the ORIGINAL key, where the separators that make `key` a word
941
+ * still exist: `key`, `api_key`, `x-api-key`, `signing-key`. This is the shape
942
+ * `packages/smithers/src/Bug.ts` matches, and stopping here is deliberate. Treating
943
+ * a camel-case hump as a separator too, `/[a-z0-9]Key$/`, looks equivalent and
944
+ * is not: it redacted `idempotencyKey`, the durable identity an effect boundary
945
+ * replays on, out of `@smthrs/engine-store`'s journal rows. A credential-named
946
+ * key is covered by {@link sensitiveKeySuffixes} instead, where the word before
947
+ * `key` has to be one that names a secret.
948
+ */
949
+ const trailingKeyWord = /(?:^|[^A-Za-z0-9])key$/i;
950
+ const canonicalKey = (key) => key.toLowerCase().replace(/[^a-z0-9]/g, "").replace(/s$/, "");
951
+ /** Numeric accounting fields that contain counts, never bearer material. */
952
+ const tokenCounterKeys = new Set([
953
+ "inputtoken",
954
+ "outputtoken",
955
+ "cachedinputtoken",
956
+ "reasoningtoken",
957
+ "totaltoken"
958
+ ]);
959
+ /**
960
+ * Any name ending in a plural `tokens` holds a count too, the rule the textual
961
+ * pass applies in {@link namesCredential}: `Envelope.budget.tokens` is the
962
+ * run's token ceiling, and `usage.cacheWriteTokens`, `maxTokens`, and
963
+ * `contextWindowTokens` are accounting; redacting them erased every journaled
964
+ * budget and cache-write count (#3846). A bare singular `token` stays bearer
965
+ * material even when it is numeric.
966
+ */
967
+ const isTokenCount = (key, value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 &&
968
+ (tokenCounterKeys.has(canonicalKey(key)) || /tokens$/i.test(key));
969
+ /**
970
+ * Whether a field name names a credential.
971
+ *
972
+ * Case and separators are ignored, so `api_key`, `apiKey`, and `x-api-key` are
973
+ * all recognised, one trailing plural `s` is stripped so `credentials` reads as
974
+ * `credential`, and a trailing `key` counts where it is a word of its own or
975
+ * where the word before it names a secret.
976
+ *
977
+ * The rule is a suffix test, not a substring test. `tokenizer`, `secretary`,
978
+ * `monkey`, and `idempotencyKey` are ordinary field names, and replacing their
979
+ * values would destroy data in a permanent row without protecting anything.
980
+ * That is the one place this rule is deliberately narrower than
981
+ * `packages/smithers/src/Bug.ts`'s substring form, which can afford the false
982
+ * positives because its output is a single report an operator reads once.
983
+ *
984
+ * @since 0.1.0
985
+ * @category predicates
986
+ */
987
+ export const isSensitiveKey = (key) => {
988
+ if (trailingKeyWord.test(key))
989
+ return true;
990
+ const canonical = canonicalKey(key);
991
+ return sensitiveKeySuffixes.some((suffix) => canonical.endsWith(suffix));
992
+ };
993
+ const redactMember = (key, value, walk) => isSensitiveKey(key) && !isTokenCount(key, value) ? placeholder : walk(value);
994
+ /**
995
+ * A field name with a credential in it replaced outright, not rewritten in place.
996
+ *
997
+ * Redacting part of a key changes what the key reads as. `secret=sk-` rewrites
998
+ * to `secret=[REDACTED]`, which now ENDS in a sensitive name, so a second
999
+ * application would replace a value the first one left alone and redaction
1000
+ * would stop being a fixed point. Naming the whole key holds the verdict still:
1001
+ * `[REDACTED]` matches no rule and names no credential. Two such keys collapse
1002
+ * into one and the later member wins, which is the fidelity trade every other
1003
+ * marker here makes.
1004
+ */
1005
+ const redactKey = (key, rules) => {
1006
+ const redacted = redactString(key, rules);
1007
+ return redacted === key ? key : placeholder;
1008
+ };
1009
+ /**
1010
+ * How many times {@link redactString} re-applies the rules to reach a fixed
1011
+ * point. Rules feed each other: an assignment redacted inside URL userinfo
1012
+ * leaves userinfo the URL rule only then matches. Text no rule touches costs
1013
+ * one pass, and the default rules settle within three. Text that has not
1014
+ * settled after the last pass is replaced whole.
1015
+ */
1016
+ const fixedPointPasses = 8;
1017
+ /**
1018
+ * A copy of `pattern` that matches wherever `pattern` does, with no
1019
+ * lookbehind, or `null`. JavaScriptCore runs a pattern that has a lookbehind
1020
+ * in its interpreter, 30 to 70 times slower than compiled: 40 kB of prose cost
1021
+ * a Bun process 300 ms per diagnostic, where Node took 1 ms. Text the copy
1022
+ * never matches is text the rule cannot change, so the rule is skipped.
1023
+ *
1024
+ * Only a one-character negative lookbehind that starts the pattern is
1025
+ * rewritten, as a character the copy consumes, which keeps a name scan
1026
+ * starting once per identifier. Anywhere else, after `\b` or inside a
1027
+ * repeated group, the consumed character would make the copy stricter than
1028
+ * the rule, so any other lookbehind or a backreference leaves the rule
1029
+ * unfiltered.
1030
+ */
1031
+ const candidate = (pattern) => {
1032
+ const cached = candidates.get(pattern);
1033
+ if (cached !== undefined)
1034
+ return cached;
1035
+ const leading = /^\(\?<!\[(\^?)((?:\\.|[^\]\\])*)\]\)/.exec(pattern.source);
1036
+ const rest = leading === null ? pattern.source : pattern.source.slice(leading[0].length);
1037
+ const compiled = /\(\?<[!=]|\\(?:[1-9]|k<)/.test(rest)
1038
+ ? null
1039
+ : new RegExp(leading === null ? rest : `(?:^|[${leading[1] === "" ? "^" : ""}${leading[2]}])${rest}`, pattern.flags.replace(/[gy]/g, ""));
1040
+ candidates.set(pattern, compiled);
1041
+ return compiled;
1042
+ };
1043
+ const candidates = new WeakMap();
1044
+ const applyRule = (text, rule) => {
1045
+ if (candidate(rule.pattern)?.test(text) === false)
1046
+ return text;
1047
+ return rule.rewrite === undefined ? text.replace(rule.pattern, rule.replace ?? placeholder) : rule.rewrite(text);
1048
+ };
1049
+ const redactString = (value, rules) => {
1050
+ let text = value;
1051
+ for (let pass = 0; pass < fixedPointPasses; pass++) {
1052
+ const next = rules.reduce(applyRule, text);
1053
+ if (next === text)
1054
+ return text;
1055
+ text = next;
1056
+ }
1057
+ // Rules that never settle would let an exported row keep changing, and
1058
+ // what they left may still hold a credential. Fail closed.
1059
+ return placeholder;
1060
+ };
1061
+ /**
1062
+ * Maximum number of container edges traversed from a redaction root.
1063
+ *
1064
+ * Journal event schemas never approach 256 nested containers. This bound is
1065
+ * far above practical payloads while keeping traversal safely below Node's
1066
+ * call-stack limit for hostile input.
1067
+ *
1068
+ * @since 1.0.0
1069
+ * @category constants
1070
+ */
1071
+ export const maxDepth = 256;
1072
+ /**
1073
+ * A payload nested deeper than {@link maxDepth}, under `onTooDeep: "throw"`.
1074
+ * `code` is always `depth_exceeded`; `maxDepth` is the bound that was crossed.
1075
+ *
1076
+ * @since 1.0.0
1077
+ * @category errors
1078
+ */
1079
+ export class RedactionDepthError extends Schema.TaggedError()("@smthrs/journal/RedactionDepthError", { code: Schema.Literal("depth_exceeded"), maxDepth: Schema.Number, message: Schema.String }) {
1080
+ name = "RedactionDepthError";
1081
+ }
1082
+ /**
1083
+ * How many bytes a view may hold, and how many own members {@link redact} reads
1084
+ * off it, before it stops reading them.
1085
+ *
1086
+ * Enumerating a view's own properties materialises one pair per byte, so the
1087
+ * walk costs the buffer's size even though the rendering does not. Both halves
1088
+ * of the bound carry load, and neither is a bound on its own. A size alone is
1089
+ * not, because `byteLength` was read as an ordinary property and an ordinary
1090
+ * property can be shadowed: a pooled chunk that reports the bytes it has used
1091
+ * rather than the bytes it holds is a plain pattern, not an adversarial one,
1092
+ * and a 4 MB chunk reporting 12 walked one property per byte anyway. A count
1093
+ * alone is not, because a caller can hang a million properties on a ten-byte
1094
+ * view. So the size is read from the value's own internal slot, where nothing
1095
+ * a caller writes can answer for it, and the members are counted as they are
1096
+ * walked.
1097
+ *
1098
+ * @since 0.1.0
1099
+ * @category redaction
1100
+ */
1101
+ export const binaryWalkLimit = 65_536;
1102
+ /**
1103
+ * The byte-length getters, taken from the prototypes rather than from a value.
1104
+ *
1105
+ * `%TypedArray%.prototype`, `DataView.prototype` and `ArrayBuffer.prototype`
1106
+ * each define `byteLength` as an accessor over an internal slot, and applying
1107
+ * one to a value that has no such slot throws. Reading the size this way is
1108
+ * therefore a brand check as well as a measurement: a caller's own `byteLength`
1109
+ * property, accessor or not, never answers it.
1110
+ */
1111
+ const byteLengthGetters = [
1112
+ Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype), "byteLength").get,
1113
+ Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength").get,
1114
+ Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get
1115
+ ];
1116
+ /** A value's byte length from its own internal slot, or `undefined` when it has none. */
1117
+ const byteLength = (node) => {
1118
+ for (const getter of byteLengthGetters) {
1119
+ try {
1120
+ return Reflect.apply(getter, node, []);
1121
+ }
1122
+ catch {
1123
+ // Not that kind of view. Another getter answers, or none does and the
1124
+ // bytes are named without the members being read.
1125
+ }
1126
+ }
1127
+ return undefined;
1128
+ };
1129
+ /** The prototypes every binary view inherits from. */
1130
+ const binaryPrototypes = new Set([
1131
+ Object.getPrototypeOf(Uint8Array.prototype),
1132
+ DataView.prototype,
1133
+ ArrayBuffer.prototype
1134
+ ]);
1135
+ /** How many prototypes {@link isBinary} climbs before it stops asking. */
1136
+ const prototypeWalkLimit = 64;
1137
+ /**
1138
+ * Whether `node` is a binary view, including one held behind a proxy.
1139
+ *
1140
+ * `ArrayBuffer.isView` reads an internal slot, and a proxy has none of its own,
1141
+ * so it answers `false` for a proxy over a view. That sent a proxied 2 MB
1142
+ * buffer to the object branch, which rebuilt it one key per byte: 2,000 ms and
1143
+ * 22.9 million characters for one logged value. A proxy forwards
1144
+ * `getPrototypeOf` to its target, so the prototype chain answers where the
1145
+ * brand check cannot. The climb is capped because a proxy is free to hand back
1146
+ * a fresh object every time it is asked, which is an endless chain.
1147
+ */
1148
+ const isBinary = (node) => {
1149
+ if (ArrayBuffer.isView(node) || node instanceof ArrayBuffer)
1150
+ return true;
1151
+ try {
1152
+ let prototype = Object.getPrototypeOf(node);
1153
+ for (let step = 0; prototype !== null && step < prototypeWalkLimit; step++) {
1154
+ if (binaryPrototypes.has(prototype))
1155
+ return true;
1156
+ prototype = Object.getPrototypeOf(prototype);
1157
+ }
1158
+ }
1159
+ catch {
1160
+ // A revoked proxy refuses to be asked. It is not a view, and the object
1161
+ // branch names it.
1162
+ }
1163
+ return false;
1164
+ };
1165
+ /** Own keys of a binary view that name one of its bytes rather than a property. */
1166
+ const indexKey = /^(?:0|[1-9][0-9]*)$/;
1167
+ /** `Uint8Array 1024 bytes`, or the bare marker when the value will not say. */
1168
+ const describeBinary = (node, size) => {
1169
+ if (size === undefined)
1170
+ return binaryMarker;
1171
+ try {
1172
+ return `${node.constructor.name} ${size} bytes`;
1173
+ }
1174
+ catch {
1175
+ return binaryMarker;
1176
+ }
1177
+ };
1178
+ /**
1179
+ * The key {@link redact} files a binary view's size under.
1180
+ *
1181
+ * @since 0.1.0
1182
+ * @category redaction
1183
+ */
1184
+ export const binaryMarker = "[Binary]";
1185
+ /**
1186
+ * What {@link redact} writes in place of a function or a class object.
1187
+ *
1188
+ * @since 0.1.0
1189
+ * @category redaction
1190
+ */
1191
+ export const functionMarker = "[Function]";
1192
+ /**
1193
+ * What {@link redact} writes in place of a symbol.
1194
+ *
1195
+ * @since 0.1.0
1196
+ * @category redaction
1197
+ */
1198
+ export const symbolMarker = "[Symbol]";
1199
+ /**
1200
+ * What {@link redact} writes past {@link maxDepth} under `onTooDeep: "name"`.
1201
+ *
1202
+ * @since 0.1.0
1203
+ * @category redaction
1204
+ */
1205
+ export const depthMarker = "[Deep]";
1206
+ /**
1207
+ * Returns `value` with credentials removed.
1208
+ *
1209
+ * Objects and arrays are rebuilt: a field whose name {@link isSensitiveKey}
1210
+ * is replaced wholesale, every other string is run through the textual rules,
1211
+ * and a cycle is collapsed to `"[Circular]"` so the result always encodes.
1212
+ * A number, a boolean, `null` and `undefined` are returned untouched, because
1213
+ * redacting one destroys data without protecting anything. A function and a
1214
+ * symbol are NAMED, {@link functionMarker} and {@link symbolMarker}: a body, an
1215
+ * own property and a description are all text a renderer prints, and none of it
1216
+ * can be rewritten in place.
1217
+ *
1218
+ * Traversal accepts at most {@link maxDepth} container edges. A deeper value
1219
+ * throws by default, so the journal boundary can report a typed `invalid_event`
1220
+ * instead of overflowing the runtime stack. {@link Options.onTooDeep} set to
1221
+ * `"name"` writes {@link depthMarker} in its place instead, which is what a
1222
+ * logger wants.
1223
+ *
1224
+ * @since 0.1.0
1225
+ * @category redaction
1226
+ */
1227
+ export const redact = (value, options) => {
1228
+ const onTooDeep = options?.onTooDeep ?? "throw";
1229
+ const rules = globalRules(options?.rules ?? defaultRules);
1230
+ /**
1231
+ * A binary view named by its type and size, with its own properties walked.
1232
+ *
1233
+ * Its bytes are not text the rules can read, and rebuilding it from its
1234
+ * entries wrote one key per byte: a 100 kB buffer rendered 1.4 MB. Handing
1235
+ * the view back untouched is not the answer either, because `redact` is the
1236
+ * journal's own write path, so a caller's `apiKey` property hung on a buffer
1237
+ * went into a durable row in clear. Name the bytes, keep walking the text.
1238
+ */
1239
+ const binary = (node, ancestors, depth) => {
1240
+ const size = byteLength(node);
1241
+ // The description is text read off the value, so it meets the rules like
1242
+ // any other text: a class name is caller data, and a view whose
1243
+ // constructor is named after a credential wrote it into a durable row.
1244
+ const entries = [[binaryMarker, redactString(describeBinary(node, size), rules)]];
1245
+ // `Object.entries` on a view materialises one pair per byte before the
1246
+ // index filter can discard them, which cost 312 ms for 1 MB on the journal
1247
+ // write path. Past the bound the bytes are named and nothing else is read,
1248
+ // so a member a caller hung on a large view is dropped rather than shown.
1249
+ // A value that will not answer from its internal slot, such as a proxy over
1250
+ // a view, is named and never enumerated at all.
1251
+ if (size !== undefined && size <= binaryWalkLimit) {
1252
+ let walked = 0;
1253
+ for (const [key, field] of Object.entries(node)) {
1254
+ // An index is one of the bytes just named, not a property a caller set.
1255
+ if (indexKey.test(key))
1256
+ continue;
1257
+ // The size bounds the bytes, not the properties: a caller can hang a
1258
+ // million members on a ten-byte view, and each one costs three rule
1259
+ // scans over its name and a walk of its value.
1260
+ if (walked >= binaryWalkLimit)
1261
+ break;
1262
+ walked++;
1263
+ entries.push([
1264
+ redactKey(key, rules),
1265
+ redactMember(key, field, (value) => walk(value, ancestors, depth + 1, key))
1266
+ ]);
1267
+ }
1268
+ }
1269
+ // `Object.fromEntries`, not `named[key] = …`, for the reason the object
1270
+ // branch below gives: a literal `__proto__` key would route through the
1271
+ // inherited setter and the member would vanish from the row.
1272
+ return Object.fromEntries(entries);
1273
+ };
1274
+ const walk = (node, ancestors, depth, key) => {
1275
+ if (depth > maxDepth) {
1276
+ if (onTooDeep === "name")
1277
+ return depthMarker;
1278
+ throw new RedactionDepthError({
1279
+ code: "depth_exceeded",
1280
+ maxDepth,
1281
+ message: `redaction depth exceeds ${maxDepth}`
1282
+ });
1283
+ }
1284
+ if (typeof node === "string")
1285
+ return redactString(node, rules);
1286
+ // A function, a class object or a symbol carries text a walk never reaches
1287
+ // (own properties, a description, a body), and the renderer prints it. None
1288
+ // of it can be redacted in place, so the value is named instead.
1289
+ if (typeof node === "function")
1290
+ return functionMarker;
1291
+ if (typeof node === "symbol")
1292
+ return symbolMarker;
1293
+ if (node === null || typeof node !== "object")
1294
+ return node;
1295
+ if (isBinary(node))
1296
+ return binary(node, ancestors, depth);
1297
+ if (ancestors.has(node))
1298
+ return "[Circular]";
1299
+ // A journal row is bounded by its schema, but a LOGGED value is arbitrary:
1300
+ // the logger sends every non-Error value here, and a chain deep enough to
1301
+ // exhaust the stack would throw while the line is rendering, killing the
1302
+ // run the line describes. Past the cap the value is named, the way a cycle
1303
+ // is named.
1304
+ ancestors.add(node);
1305
+ try {
1306
+ const toJSON = node.toJSON;
1307
+ // JSON.stringify passes the containing key (or "" at the root) to toJSON.
1308
+ // Reuse it when walking the replacement; siblings may share this object.
1309
+ if (typeof toJSON === "function")
1310
+ return walk(toJSON.call(node, key), ancestors, depth, key);
1311
+ if (Array.isArray(node)) {
1312
+ // `map` invokes the input's species constructor, which can restore
1313
+ // credential fields and inspection hooks after the elements are walked.
1314
+ // Rebuild a plain array, preserving the original length and holes.
1315
+ const length = node.length;
1316
+ const result = new Array(length);
1317
+ const elements = new Array(length);
1318
+ for (let index = 0; index < length; index++) {
1319
+ if (!(index in node))
1320
+ continue;
1321
+ elements[index] = node[index];
1322
+ result[index] = walk(elements[index], ancestors, depth + 1, String(index));
1323
+ }
1324
+ // An argv keeps a flag and its value in two elements, so no rule sees
1325
+ // `--password hunter2` whole. The element after a flag is a credential
1326
+ // when its name says so (`--token=x` carries its own, and a count under
1327
+ // `--max-tokens` is kept), or when the active rules redact it read
1328
+ // after the flag and the elements before it (`-p`, `-pw`, `-passin`,
1329
+ // `sshpass -p`) differently than alone.
1330
+ for (let index = 0; index + 1 < length; index++) {
1331
+ // The values the first loop read, never a second read: a proxy may
1332
+ // answer a second `get` differently.
1333
+ const flag = elements[index];
1334
+ const value = elements[index + 1];
1335
+ if (typeof flag !== "string" || typeof value !== "string" || !/^-[^=\s]+$/.test(flag))
1336
+ continue;
1337
+ const name = flag.replace(/^-+/, "");
1338
+ const before = elements.slice(Math.max(0, index - 3), index + 1).filter((element) => typeof element === "string").join(" ");
1339
+ const consumes = (isSensitiveKey(name) && namesCredential(name, value)) ||
1340
+ redactString(`${before} ${value}`, rules) !== `${redactString(before, rules)} ${redactString(value, rules)}`;
1341
+ if (consumes)
1342
+ result[index + 1] = placeholder;
1343
+ }
1344
+ return result;
1345
+ }
1346
+ // `result[key] = …` routes a literal `__proto__` key through the
1347
+ // inherited setter, so the field would silently become the result's
1348
+ // prototype instead of a member: the payload loses data and redaction
1349
+ // stops being a fixed point. `Object.fromEntries` defines own data
1350
+ // properties and has no such hole.
1351
+ return Object.fromEntries(Object.entries(node).map(([key, field]) => [
1352
+ // The KEY is text too. Rewriting only values let a credential used as
1353
+ // a log annotation key reach the operator, since Effect renders an
1354
+ // annotation as `key=value`, and become an OTLP span attribute name.
1355
+ redactKey(key, rules),
1356
+ redactMember(key, field, (value) => walk(value, ancestors, depth + 1, key))
1357
+ ]));
1358
+ }
1359
+ finally {
1360
+ ancestors.delete(node);
1361
+ }
1362
+ };
1363
+ return walk(value, new WeakSet(), 0, "");
1364
+ };
1365
+ /**
1366
+ * Builds a redactor over a rule set.
1367
+ *
1368
+ * @since 0.1.0
1369
+ * @category constructors
1370
+ */
1371
+ export const make = (options) => (value) => redact(value, options);
1372
+ /**
1373
+ * Applies a redactor to an already-encoded JSON string, returning the
1374
+ * re-encoded result.
1375
+ *
1376
+ * For export and display surfaces that hold a column verbatim, a rendered
1377
+ * `state_json`, a support bundle, where the value is already encoded and must
1378
+ * not be decoded into the executable path. A string that does not parse is
1379
+ * returned untouched: validation is the caller's, and rejecting here would
1380
+ * turn a redaction concern into a schema error. Once parsing succeeds, a
1381
+ * throwing redactor or an encoding failure returns the valid JSON string
1382
+ * `"[REDACTED]"`; the original parsed text is never returned.
1383
+ *
1384
+ * @since 0.1.0
1385
+ * @category redaction
1386
+ */
1387
+ export const redactJsonString = (json, redactor) => {
1388
+ const decoded = Schema.decodeUnknownResult(UnknownFromJsonString)(json);
1389
+ if (Result.isFailure(decoded))
1390
+ return json;
1391
+ const attempted = Result.try(() => Schema.encodeUnknownResult(UnknownFromJsonString)(redactor(decoded.success)));
1392
+ if (Result.isFailure(attempted))
1393
+ return JSON.stringify(placeholder);
1394
+ return Result.isSuccess(attempted.success) ? attempted.success.success : JSON.stringify(placeholder);
1395
+ };
1396
+ /**
1397
+ * Lines a {@link lineRedactor} holds for one open value. Past this, or past
1398
+ * 64 KiB, it stops holding: it emits what it held, redacted, and withholds
1399
+ * every later line until the stream ends, when one placeholder stands for
1400
+ * them. Dropping lines from the middle instead changed which brackets and
1401
+ * quotes were open, and released a later secret in clear.
1402
+ *
1403
+ * @since 1.0.0
1404
+ * @category constants
1405
+ */
1406
+ export const maxHeldLines = 256;
1407
+ const maxHeldBytes = 64 * 1024;
1408
+ /** Held lines a {@link lineRedactor} asks about one by one before it asks only as the block grows by half. */
1409
+ const eagerHeldLines = 16;
1410
+ /**
1411
+ * The most brackets and strings the dropped middle of an overlong line may
1412
+ * leave open before a {@link lineRedactor} stops reading it and treats the
1413
+ * line as leaving a value open. Without it the middle's state grew by one
1414
+ * entry per bracket: 32 MiB of `[` held 1.7 GB (#3088).
1415
+ */
1416
+ const maxDroppedDepth = 1024;
1417
+ /**
1418
+ * The longest line a {@link lineRedactor} reads whole. A longer line keeps
1419
+ * its first and last 16 KiB; its middle is scanned for what it leaves open
1420
+ * and dropped.
1421
+ *
1422
+ * @since 1.0.0
1423
+ * @category constants
1424
+ */
1425
+ export const maxPartialLine = 32 * 1024;
1426
+ /**
1427
+ * What a {@link lineRedactor} emits in place of a line longer than
1428
+ * {@link maxPartialLine}.
1429
+ *
1430
+ * @since 1.0.0
1431
+ * @category constants
1432
+ */
1433
+ export const omittedLine = "[overlong line omitted]";
1434
+ /**
1435
+ * A next line no rule redacts alone, which an open value swallows. The value
1436
+ * is open when the redacted text no longer ENDS with it: text before it may
1437
+ * contain the same word.
1438
+ */
1439
+ const continuationProbe = "\n'probe'";
1440
+ /** Rules with the global flag each rule needs to replace every match. */
1441
+ const globalRules = (rules) => rules.map((rule) => rule.pattern.flags.includes("g")
1442
+ ? rule
1443
+ : { ...rule, pattern: new RegExp(rule.pattern.source, `${rule.pattern.flags}g`) });
1444
+ /**
1445
+ * A redactor for a stream that must be emitted line by line: a live build
1446
+ * log, a child's stderr.
1447
+ *
1448
+ * Redacting each line alone is the flaw that leaked a private key's body, and
1449
+ * the tail of every string `util.inspect` split over several lines: only the
1450
+ * line holding the name was redacted. This one asks the rules themselves
1451
+ * whether a line leaves a value open, by checking whether the value swallows
1452
+ * a probe placed on the next line, and holds lines until it closes. The held
1453
+ * block is then redacted whole, exactly as {@link redact} redacts a string.
1454
+ *
1455
+ * A line longer than {@link maxPartialLine} is read as its first and last
1456
+ * 16 KiB. Its middle is dropped, but a bracket, quote or key block the middle
1457
+ * leaves open would have opened a value the kept ends cannot show, so then
1458
+ * the rest of the stream is withheld. Such a line is never emitted, only
1459
+ * {@link omittedLine}, and neither is any block it was held in.
1460
+ *
1461
+ * Its state is bounded whatever the stream does: the line still arriving is
1462
+ * a 16 KiB head, a 16 KiB tail and at most 1024 open brackets or strings of
1463
+ * its middle, a middle nested deeper counting as one left open; the held
1464
+ * block is bounded by {@link maxHeldLines} and 64 KiB. Its cost is linear:
1465
+ * past the first 16 held lines the block is re-read only once it has grown
1466
+ * by half, on Node and on Bun alike (#3088).
1467
+ *
1468
+ * `rules` defaults to {@link diagnosticRules}. The array is read on every
1469
+ * line, so a caller may add a rule, a session secret, as the stream runs.
1470
+ *
1471
+ * @since 1.0.0
1472
+ * @category constructors
1473
+ */
1474
+ export const lineRedactor = (rules = diagnosticRules) => {
1475
+ const held = [];
1476
+ let heldBytes = 0;
1477
+ let askAt = 0;
1478
+ let heldOverlong = false;
1479
+ let withheld = false;
1480
+ // The line still arriving: whole up to the bound, then a head, a rolling
1481
+ // tail, and what the dropped middle leaves open.
1482
+ const edge = maxPartialLine / 2;
1483
+ let head = "";
1484
+ let tail = "";
1485
+ let overlong = false;
1486
+ let middle = [];
1487
+ let middleDeep = false;
1488
+ let middleKey = false;
1489
+ let carry = "";
1490
+ const resetPartial = () => {
1491
+ head = "";
1492
+ tail = "";
1493
+ overlong = false;
1494
+ middle = [];
1495
+ middleDeep = false;
1496
+ middleKey = false;
1497
+ carry = "";
1498
+ };
1499
+ const scanDropped = (dropped) => {
1500
+ // What the middle leaves open is read in slices, and once it is nested
1501
+ // past `maxDroppedDepth` it is not read at all: the line is then already
1502
+ // risky, and the stack held one entry per bracket of a line of any length.
1503
+ for (let from = 0; from < dropped.length && !middleDeep; from += edge) {
1504
+ track(middle, dropped, from, Math.min(dropped.length, from + edge));
1505
+ if (middle.length > maxDroppedDepth) {
1506
+ middleDeep = true;
1507
+ middle = [];
1508
+ }
1509
+ }
1510
+ const seen = carry + dropped;
1511
+ const begin = seen.search(/-----BEGIN[^-]*PRIVATE KEY/);
1512
+ const lastBegin = seen.lastIndexOf("-----BEGIN");
1513
+ const lastEnd = seen.lastIndexOf("-----END");
1514
+ if (begin !== -1 || lastEnd !== -1)
1515
+ middleKey = lastBegin > lastEnd;
1516
+ carry = seen.slice(-64);
1517
+ };
1518
+ const redacted = (text) => redactString(text, globalRules(rules));
1519
+ const release = () => {
1520
+ const text = redacted(held.join("\n"));
1521
+ const overlongBlock = heldOverlong;
1522
+ held.length = 0;
1523
+ heldBytes = 0;
1524
+ askAt = 0;
1525
+ heldOverlong = false;
1526
+ return overlongBlock ? [omittedLine] : text.split("\n");
1527
+ };
1528
+ const part = (text) => {
1529
+ if (withheld)
1530
+ return;
1531
+ if (!overlong) {
1532
+ head += text;
1533
+ if (head.length <= maxPartialLine)
1534
+ return;
1535
+ overlong = true;
1536
+ tail = head.slice(edge);
1537
+ head = head.slice(0, edge);
1538
+ }
1539
+ else
1540
+ tail += text;
1541
+ if (tail.length > edge) {
1542
+ scanDropped(tail.slice(0, tail.length - edge));
1543
+ tail = tail.slice(-edge);
1544
+ }
1545
+ };
1546
+ const line = (rest) => {
1547
+ if (withheld) {
1548
+ resetPartial();
1549
+ return [];
1550
+ }
1551
+ part(rest);
1552
+ let text = head;
1553
+ if (overlong) {
1554
+ const risky = middle.length > 0 || middleDeep || middleKey;
1555
+ text = `${head} ${tail}`;
1556
+ resetPartial();
1557
+ if (risky) {
1558
+ const before = held.length === 0 ? [] : [placeholder];
1559
+ held.length = 0;
1560
+ heldBytes = 0;
1561
+ askAt = 0;
1562
+ heldOverlong = false;
1563
+ withheld = true;
1564
+ return [...before, omittedLine];
1565
+ }
1566
+ heldOverlong = true;
1567
+ }
1568
+ else
1569
+ resetPartial();
1570
+ held.push(text);
1571
+ heldBytes += text.length + 1;
1572
+ // Asking after every line re-redacted the whole block per line, so a
1573
+ // block of n bytes cost n² (#3088). Past the first lines the question is
1574
+ // asked again only once the block has grown by half, which keeps the
1575
+ // cost linear; a block that closed in between is released with the
1576
+ // lines after it, redacted as one block, which hides no less.
1577
+ if (held.length <= eagerHeldLines || heldBytes >= askAt) {
1578
+ if (redacted(held.join("\n") + continuationProbe).endsWith(continuationProbe))
1579
+ return release();
1580
+ askAt = heldBytes + (heldBytes >> 1);
1581
+ }
1582
+ if (held.length <= maxHeldLines && heldBytes <= maxHeldBytes)
1583
+ return [];
1584
+ withheld = true;
1585
+ return release();
1586
+ };
1587
+ const peek = () => {
1588
+ if (withheld)
1589
+ return [placeholder];
1590
+ const pending = overlong ? [omittedLine] : head === "" ? [] : [head];
1591
+ if (heldOverlong)
1592
+ return [omittedLine];
1593
+ const text = [...held, ...(overlong ? [] : pending)];
1594
+ const out = text.length === 0 ? [] : redacted(text.join("\n")).split("\n");
1595
+ return overlong ? [...out, omittedLine] : out;
1596
+ };
1597
+ return {
1598
+ line,
1599
+ part,
1600
+ peek,
1601
+ flush: () => {
1602
+ const out = head !== "" || overlong ? [...line("")] : [];
1603
+ if (withheld) {
1604
+ withheld = false;
1605
+ return [...out, placeholder];
1606
+ }
1607
+ return held.length === 0 ? out : [...out, ...release()];
1608
+ }
1609
+ };
1610
+ };
1611
+ /**
1612
+ * The identity redactor, for a caller that persists payloads verbatim by
1613
+ * choice: a trusted single-tenant store, or a suite asserting on raw input.
1614
+ *
1615
+ * @since 0.1.0
1616
+ * @category constructors
1617
+ */
1618
+ export const makeNoop = () => (value) => value;
1619
+ //# sourceMappingURL=Redaction.js.map