@smthrs/journal 0.0.0-stage → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +149 -0
- package/LICENSE +21 -0
- package/README.md +206 -2
- package/dist/cjs/CallFact.d.ts +129 -0
- package/dist/cjs/CallFact.d.ts.map +1 -0
- package/dist/cjs/CallFact.js +106 -0
- package/dist/cjs/CallFact.js.map +7 -0
- package/dist/cjs/Consensus.d.ts +440 -0
- package/dist/cjs/Consensus.d.ts.map +1 -0
- package/dist/cjs/Consensus.js +251 -0
- package/dist/cjs/Consensus.js.map +7 -0
- package/dist/cjs/EngineEvent.d.ts +890 -0
- package/dist/cjs/EngineEvent.d.ts.map +1 -0
- package/dist/cjs/EngineEvent.js +383 -0
- package/dist/cjs/EngineEvent.js.map +7 -0
- package/dist/cjs/ExecutionFact.d.ts +216 -0
- package/dist/cjs/ExecutionFact.d.ts.map +1 -0
- package/dist/cjs/ExecutionFact.js +303 -0
- package/dist/cjs/ExecutionFact.js.map +7 -0
- package/dist/cjs/Journal.d.ts +617 -0
- package/dist/cjs/Journal.d.ts.map +1 -0
- package/dist/cjs/Journal.js +190 -0
- package/dist/cjs/Journal.js.map +7 -0
- package/dist/cjs/JournalEvent.d.ts +421 -0
- package/dist/cjs/JournalEvent.d.ts.map +1 -0
- package/dist/cjs/JournalEvent.js +281 -0
- package/dist/cjs/JournalEvent.js.map +7 -0
- package/dist/cjs/JournalGeneration.d.ts +34 -0
- package/dist/cjs/JournalGeneration.d.ts.map +1 -0
- package/dist/cjs/JournalGeneration.js +72 -0
- package/dist/cjs/JournalGeneration.js.map +7 -0
- package/dist/cjs/JournalMetrics.d.ts +72 -0
- package/dist/cjs/JournalMetrics.d.ts.map +1 -0
- package/dist/cjs/JournalMetrics.js +55 -0
- package/dist/cjs/JournalMetrics.js.map +7 -0
- package/dist/cjs/Migrations.d.ts +42 -0
- package/dist/cjs/Migrations.d.ts.map +1 -0
- package/dist/cjs/Migrations.js +58 -0
- package/dist/cjs/Migrations.js.map +7 -0
- package/dist/cjs/OwnerId.d.ts +40 -0
- package/dist/cjs/OwnerId.d.ts.map +1 -0
- package/dist/cjs/OwnerId.js +40 -0
- package/dist/cjs/OwnerId.js.map +7 -0
- package/dist/cjs/Projection.d.ts +29 -0
- package/dist/cjs/Projection.d.ts.map +1 -0
- package/dist/cjs/Projection.js +25 -0
- package/dist/cjs/Projection.js.map +7 -0
- package/dist/cjs/RedactedLogger.d.ts +121 -0
- package/dist/cjs/RedactedLogger.d.ts.map +1 -0
- package/dist/cjs/RedactedLogger.js +235 -0
- package/dist/cjs/RedactedLogger.js.map +7 -0
- package/dist/cjs/Redaction.d.ts +350 -0
- package/dist/cjs/Redaction.d.ts.map +1 -0
- package/dist/cjs/Redaction.js +928 -0
- package/dist/cjs/Redaction.js.map +7 -0
- package/dist/cjs/SqlConsensus.d.ts +44 -0
- package/dist/cjs/SqlConsensus.d.ts.map +1 -0
- package/dist/cjs/SqlConsensus.js +243 -0
- package/dist/cjs/SqlConsensus.js.map +7 -0
- package/dist/cjs/SqlJournal.d.ts +173 -0
- package/dist/cjs/SqlJournal.d.ts.map +1 -0
- package/dist/cjs/SqlJournal.js +1568 -0
- package/dist/cjs/SqlJournal.js.map +7 -0
- package/dist/cjs/StepFact.d.ts +66 -0
- package/dist/cjs/StepFact.d.ts.map +1 -0
- package/dist/cjs/StepFact.js +68 -0
- package/dist/cjs/StepFact.js.map +7 -0
- package/dist/cjs/index.d.ts +95 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/internal/JournalInternalFault.d.ts +37 -0
- package/dist/cjs/internal/JournalInternalFault.d.ts.map +1 -0
- package/dist/cjs/internal/JournalInternalFault.js +43 -0
- package/dist/cjs/internal/JournalInternalFault.js.map +7 -0
- package/dist/cjs/migrations/0001_initial.d.ts +15 -0
- package/dist/cjs/migrations/0001_initial.d.ts.map +1 -0
- package/dist/cjs/migrations/0001_initial.js +54 -0
- package/dist/cjs/migrations/0001_initial.js.map +7 -0
- package/dist/cjs/migrations/0002_checkpoints.d.ts +27 -0
- package/dist/cjs/migrations/0002_checkpoints.d.ts.map +1 -0
- package/dist/cjs/migrations/0002_checkpoints.js +48 -0
- package/dist/cjs/migrations/0002_checkpoints.js.map +7 -0
- package/dist/cjs/migrations/0003_startup_index.d.ts +15 -0
- package/dist/cjs/migrations/0003_startup_index.d.ts.map +1 -0
- package/dist/cjs/migrations/0003_startup_index.js +40 -0
- package/dist/cjs/migrations/0003_startup_index.js.map +7 -0
- package/dist/cjs/migrations/0004_dedup.d.ts +15 -0
- package/dist/cjs/migrations/0004_dedup.d.ts.map +1 -0
- package/dist/cjs/migrations/0004_dedup.js +57 -0
- package/dist/cjs/migrations/0004_dedup.js.map +7 -0
- package/dist/cjs/migrations/0005_run_event_type.d.ts +15 -0
- package/dist/cjs/migrations/0005_run_event_type.d.ts.map +1 -0
- package/dist/cjs/migrations/0005_run_event_type.js +40 -0
- package/dist/cjs/migrations/0005_run_event_type.js.map +7 -0
- package/dist/cjs/migrations/0006_consensus.d.ts +22 -0
- package/dist/cjs/migrations/0006_consensus.d.ts.map +1 -0
- package/dist/cjs/migrations/0006_consensus.js +84 -0
- package/dist/cjs/migrations/0006_consensus.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/test/Notifying.d.ts +65 -0
- package/dist/cjs/test/Notifying.d.ts.map +1 -0
- package/dist/cjs/test/Notifying.js +62 -0
- package/dist/cjs/test/Notifying.js.map +7 -0
- package/dist/cjs/test/TestJournal.d.ts +43 -0
- package/dist/cjs/test/TestJournal.d.ts.map +1 -0
- package/dist/cjs/test/TestJournal.js +43 -0
- package/dist/cjs/test/TestJournal.js.map +7 -0
- package/dist/esm/CallFact.d.ts +129 -0
- package/dist/esm/CallFact.d.ts.map +1 -0
- package/dist/esm/CallFact.js +96 -0
- package/dist/esm/CallFact.js.map +1 -0
- package/dist/esm/Consensus.d.ts +440 -0
- package/dist/esm/Consensus.d.ts.map +1 -0
- package/dist/esm/Consensus.js +454 -0
- package/dist/esm/Consensus.js.map +1 -0
- package/dist/esm/EngineEvent.d.ts +890 -0
- package/dist/esm/EngineEvent.d.ts.map +1 -0
- package/dist/esm/EngineEvent.js +614 -0
- package/dist/esm/EngineEvent.js.map +1 -0
- package/dist/esm/ExecutionFact.d.ts +216 -0
- package/dist/esm/ExecutionFact.d.ts.map +1 -0
- package/dist/esm/ExecutionFact.js +374 -0
- package/dist/esm/ExecutionFact.js.map +1 -0
- package/dist/esm/Journal.d.ts +617 -0
- package/dist/esm/Journal.d.ts.map +1 -0
- package/dist/esm/Journal.js +323 -0
- package/dist/esm/Journal.js.map +1 -0
- package/dist/esm/JournalEvent.d.ts +421 -0
- package/dist/esm/JournalEvent.d.ts.map +1 -0
- package/dist/esm/JournalEvent.js +517 -0
- package/dist/esm/JournalEvent.js.map +1 -0
- package/dist/esm/JournalGeneration.d.ts +34 -0
- package/dist/esm/JournalGeneration.d.ts.map +1 -0
- package/dist/esm/JournalGeneration.js +65 -0
- package/dist/esm/JournalGeneration.js.map +1 -0
- package/dist/esm/JournalMetrics.d.ts +72 -0
- package/dist/esm/JournalMetrics.d.ts.map +1 -0
- package/dist/esm/JournalMetrics.js +79 -0
- package/dist/esm/JournalMetrics.js.map +1 -0
- package/dist/esm/Migrations.d.ts +42 -0
- package/dist/esm/Migrations.d.ts.map +1 -0
- package/dist/esm/Migrations.js +59 -0
- package/dist/esm/Migrations.js.map +1 -0
- package/dist/esm/OwnerId.d.ts +40 -0
- package/dist/esm/OwnerId.d.ts.map +1 -0
- package/dist/esm/OwnerId.js +33 -0
- package/dist/esm/OwnerId.js.map +1 -0
- package/dist/esm/Projection.d.ts +29 -0
- package/dist/esm/Projection.d.ts.map +1 -0
- package/dist/esm/Projection.js +13 -0
- package/dist/esm/Projection.js.map +1 -0
- package/dist/esm/RedactedLogger.d.ts +121 -0
- package/dist/esm/RedactedLogger.d.ts.map +1 -0
- package/dist/esm/RedactedLogger.js +445 -0
- package/dist/esm/RedactedLogger.js.map +1 -0
- package/dist/esm/Redaction.d.ts +350 -0
- package/dist/esm/Redaction.d.ts.map +1 -0
- package/dist/esm/Redaction.js +1584 -0
- package/dist/esm/Redaction.js.map +1 -0
- package/dist/esm/SqlConsensus.d.ts +44 -0
- package/dist/esm/SqlConsensus.d.ts.map +1 -0
- package/dist/esm/SqlConsensus.js +252 -0
- package/dist/esm/SqlConsensus.js.map +1 -0
- package/dist/esm/SqlJournal.d.ts +173 -0
- package/dist/esm/SqlJournal.d.ts.map +1 -0
- package/dist/esm/SqlJournal.js +1858 -0
- package/dist/esm/SqlJournal.js.map +1 -0
- package/dist/esm/StepFact.d.ts +66 -0
- package/dist/esm/StepFact.d.ts.map +1 -0
- package/dist/esm/StepFact.js +50 -0
- package/dist/esm/StepFact.js.map +1 -0
- package/dist/esm/index.d.ts +95 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +95 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal/JournalInternalFault.d.ts +37 -0
- package/dist/esm/internal/JournalInternalFault.d.ts.map +1 -0
- package/dist/esm/internal/JournalInternalFault.js +28 -0
- package/dist/esm/internal/JournalInternalFault.js.map +1 -0
- package/dist/esm/migrations/0001_initial.d.ts +15 -0
- package/dist/esm/migrations/0001_initial.d.ts.map +1 -0
- package/dist/esm/migrations/0001_initial.js +32 -0
- package/dist/esm/migrations/0001_initial.js.map +1 -0
- package/dist/esm/migrations/0002_checkpoints.d.ts +27 -0
- package/dist/esm/migrations/0002_checkpoints.d.ts.map +1 -0
- package/dist/esm/migrations/0002_checkpoints.js +38 -0
- package/dist/esm/migrations/0002_checkpoints.js.map +1 -0
- package/dist/esm/migrations/0003_startup_index.d.ts +15 -0
- package/dist/esm/migrations/0003_startup_index.d.ts.map +1 -0
- package/dist/esm/migrations/0003_startup_index.js +18 -0
- package/dist/esm/migrations/0003_startup_index.js.map +1 -0
- package/dist/esm/migrations/0004_dedup.d.ts +15 -0
- package/dist/esm/migrations/0004_dedup.d.ts.map +1 -0
- package/dist/esm/migrations/0004_dedup.js +38 -0
- package/dist/esm/migrations/0004_dedup.js.map +1 -0
- package/dist/esm/migrations/0005_run_event_type.d.ts +15 -0
- package/dist/esm/migrations/0005_run_event_type.d.ts.map +1 -0
- package/dist/esm/migrations/0005_run_event_type.js +18 -0
- package/dist/esm/migrations/0005_run_event_type.js.map +1 -0
- package/dist/esm/migrations/0006_consensus.d.ts +22 -0
- package/dist/esm/migrations/0006_consensus.d.ts.map +1 -0
- package/dist/esm/migrations/0006_consensus.js +69 -0
- package/dist/esm/migrations/0006_consensus.js.map +1 -0
- package/dist/esm/test/Notifying.d.ts +65 -0
- package/dist/esm/test/Notifying.d.ts.map +1 -0
- package/dist/esm/test/Notifying.js +62 -0
- package/dist/esm/test/Notifying.js.map +1 -0
- package/dist/esm/test/TestJournal.d.ts +43 -0
- package/dist/esm/test/TestJournal.d.ts.map +1 -0
- package/dist/esm/test/TestJournal.js +27 -0
- package/dist/esm/test/TestJournal.js.map +1 -0
- package/docs/README.md +164 -0
- package/docs/api.md +639 -0
- package/docs/concepts/compaction.md +157 -0
- package/docs/concepts/idempotency.md +127 -0
- package/docs/concepts/owner-fence.md +124 -0
- package/docs/concepts/redaction.md +218 -0
- package/docs/concepts/state-event-authority.md +159 -0
- package/docs/concepts/two-channels.md +167 -0
- package/docs/guides/commit-state-and-entry.md +114 -0
- package/docs/guides/compact-a-run.md +134 -0
- package/docs/guides/fold-a-projection.md +106 -0
- package/docs/guides/read-a-run.md +139 -0
- package/docs/guides/redact-log-output.md +94 -0
- package/docs/guides/testing.md +124 -0
- package/docs/guides/write-lifecycle-events.md +110 -0
- package/docs/installation.md +133 -0
- package/docs/quickstart.md +143 -0
- package/docs/troubleshooting.md +214 -0
- package/package.json +263 -3
- package/src/CallFact.ts +117 -0
- package/src/Consensus.ts +683 -0
- package/src/EngineEvent.ts +823 -0
- package/src/ExecutionFact.ts +433 -0
- package/src/Journal.ts +688 -0
- package/src/JournalEvent.ts +654 -0
- package/src/JournalGeneration.ts +77 -0
- package/src/JournalMetrics.ts +89 -0
- package/src/Migrations.ts +62 -0
- package/src/OwnerId.ts +42 -0
- package/src/Projection.ts +31 -0
- package/src/RedactedLogger.ts +483 -0
- package/src/Redaction.ts +1784 -0
- package/src/SqlConsensus.ts +344 -0
- package/src/SqlJournal.ts +2732 -0
- package/src/StepFact.ts +69 -0
- package/src/index.ts +109 -0
- package/src/internal/JournalInternalFault.ts +40 -0
- package/src/migrations/0001_initial.ts +41 -0
- package/src/migrations/0002_checkpoints.ts +46 -0
- package/src/migrations/0003_startup_index.ts +19 -0
- package/src/migrations/0004_dedup.ts +43 -0
- package/src/migrations/0005_run_event_type.ts +19 -0
- package/src/migrations/0006_consensus.ts +83 -0
- package/src/test/Notifying.ts +101 -0
- package/src/test/TestJournal.ts +52 -0
|
@@ -0,0 +1,350 @@
|
|
|
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 Schema from "effect/Schema";
|
|
28
|
+
/**
|
|
29
|
+
* A textual redaction rule.
|
|
30
|
+
*
|
|
31
|
+
* `replace` is the substitution for a matched span; when omitted the whole
|
|
32
|
+
* match is replaced by the placeholder.
|
|
33
|
+
*
|
|
34
|
+
* `rewrite`, when set, rewrites the text itself instead. It is for a rule
|
|
35
|
+
* whose extent is not regular: where a credential's value ends depends on
|
|
36
|
+
* quotes, escapes and brackets a regular expression cannot count. `pattern`
|
|
37
|
+
* then names what the rule looks for, and text `pattern` does not match is
|
|
38
|
+
* left unchanged without calling `rewrite`.
|
|
39
|
+
*
|
|
40
|
+
* @since 0.1.0
|
|
41
|
+
* @category models
|
|
42
|
+
*/
|
|
43
|
+
export interface Rule {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly pattern: RegExp;
|
|
46
|
+
readonly replace?: string | undefined;
|
|
47
|
+
readonly rewrite?: ((text: string) => string) | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The placeholder written in place of a redacted value.
|
|
51
|
+
*
|
|
52
|
+
* @since 0.1.0
|
|
53
|
+
* @category constants
|
|
54
|
+
*/
|
|
55
|
+
export declare const placeholder = "[REDACTED]";
|
|
56
|
+
/**
|
|
57
|
+
* Best-effort textual rules for credential shapes observed in real reports.
|
|
58
|
+
* Every replacement reaches a fixed point so replaying or exporting an entry
|
|
59
|
+
* cannot mutate it again.
|
|
60
|
+
*
|
|
61
|
+
* @since 0.1.0
|
|
62
|
+
* @category constants
|
|
63
|
+
*/
|
|
64
|
+
export declare const defaultRules: ReadonlyArray<Rule>;
|
|
65
|
+
/**
|
|
66
|
+
* The rules for a diagnostic: {@link defaultRules} and the spellings too broad
|
|
67
|
+
* for a durable row.
|
|
68
|
+
*
|
|
69
|
+
* A log line, a stderr message, and an error handed to a remote caller are
|
|
70
|
+
* read once, so a false positive costs a word of context. A journal row is
|
|
71
|
+
* permanent, so the same false positive destroys data. These rules sit on the
|
|
72
|
+
* diagnostic side of that line: an authorization header in any scheme, bare
|
|
73
|
+
* URL userinfo (`https://token@host`), a signed query parameter, and the value
|
|
74
|
+
* of a `-p` flag, which is a password to `mysql` and `sshpass` and a path to
|
|
75
|
+
* `mkdir`. A path, a port and a lowercase word attached to `-p` (`-print`,
|
|
76
|
+
* `-path`) are left alone.
|
|
77
|
+
*
|
|
78
|
+
* @since 1.0.0
|
|
79
|
+
* @category constants
|
|
80
|
+
*/
|
|
81
|
+
export declare const diagnosticRules: ReadonlyArray<Rule>;
|
|
82
|
+
/**
|
|
83
|
+
* Redacts one diagnostic value with {@link diagnosticRules}: a log line, a
|
|
84
|
+
* stderr message, an error handed back to a caller.
|
|
85
|
+
*
|
|
86
|
+
* Every diagnostic path shares this one function, and it runs on the value
|
|
87
|
+
* before anything renders or bounds it. Redacting a rendering line by line, or
|
|
88
|
+
* after a bound, is how a secret escaped: `util.inspect` splits a long string
|
|
89
|
+
* over several lines, and a bound cuts a quoted value before its closing
|
|
90
|
+
* quote. A value past {@link maxDepth} is named rather than thrown.
|
|
91
|
+
*
|
|
92
|
+
* @since 1.0.0
|
|
93
|
+
* @category redaction
|
|
94
|
+
*/
|
|
95
|
+
export declare const redactDiagnostic: (value: unknown) => unknown;
|
|
96
|
+
/**
|
|
97
|
+
* Whether a field name names a credential.
|
|
98
|
+
*
|
|
99
|
+
* Case and separators are ignored, so `api_key`, `apiKey`, and `x-api-key` are
|
|
100
|
+
* all recognised, one trailing plural `s` is stripped so `credentials` reads as
|
|
101
|
+
* `credential`, and a trailing `key` counts where it is a word of its own or
|
|
102
|
+
* where the word before it names a secret.
|
|
103
|
+
*
|
|
104
|
+
* The rule is a suffix test, not a substring test. `tokenizer`, `secretary`,
|
|
105
|
+
* `monkey`, and `idempotencyKey` are ordinary field names, and replacing their
|
|
106
|
+
* values would destroy data in a permanent row without protecting anything.
|
|
107
|
+
* That is the one place this rule is deliberately narrower than
|
|
108
|
+
* `packages/smithers/src/Bug.ts`'s substring form, which can afford the false
|
|
109
|
+
* positives because its output is a single report an operator reads once.
|
|
110
|
+
*
|
|
111
|
+
* @since 0.1.0
|
|
112
|
+
* @category predicates
|
|
113
|
+
*/
|
|
114
|
+
export declare const isSensitiveKey: (key: string) => boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Maximum number of container edges traversed from a redaction root.
|
|
117
|
+
*
|
|
118
|
+
* Journal event schemas never approach 256 nested containers. This bound is
|
|
119
|
+
* far above practical payloads while keeping traversal safely below Node's
|
|
120
|
+
* call-stack limit for hostile input.
|
|
121
|
+
*
|
|
122
|
+
* @since 1.0.0
|
|
123
|
+
* @category constants
|
|
124
|
+
*/
|
|
125
|
+
export declare const maxDepth = 256;
|
|
126
|
+
declare const RedactionDepthError_base: Schema.Class<RedactionDepthError, Schema.TaggedStruct<"@smthrs/journal/RedactionDepthError", {
|
|
127
|
+
readonly code: Schema.Literal<"depth_exceeded">;
|
|
128
|
+
readonly maxDepth: Schema.Number;
|
|
129
|
+
readonly message: Schema.String;
|
|
130
|
+
}>, import("effect/Cause").YieldableError>;
|
|
131
|
+
/**
|
|
132
|
+
* A payload nested deeper than {@link maxDepth}, under `onTooDeep: "throw"`.
|
|
133
|
+
* `code` is always `depth_exceeded`; `maxDepth` is the bound that was crossed.
|
|
134
|
+
*
|
|
135
|
+
* @since 1.0.0
|
|
136
|
+
* @category errors
|
|
137
|
+
*/
|
|
138
|
+
export declare class RedactionDepthError extends RedactionDepthError_base {
|
|
139
|
+
readonly name = "RedactionDepthError";
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Options for {@link redact}.
|
|
143
|
+
*
|
|
144
|
+
* @since 0.1.0
|
|
145
|
+
* @category models
|
|
146
|
+
*/
|
|
147
|
+
export interface Options {
|
|
148
|
+
readonly rules?: ReadonlyArray<Rule> | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* What a value nested past {@link maxDepth} does.
|
|
151
|
+
*
|
|
152
|
+
* `"throw"`, the default, is the journal's contract: a payload that deep is a
|
|
153
|
+
* caller bug, and a durable row quietly truncated to a marker is worse than a
|
|
154
|
+
* refused write. `"name"` is what a LOGGER wants, because a throw there is
|
|
155
|
+
* caught one frame up and replaces EVERY argument on the line with
|
|
156
|
+
* `[Unrenderable]`, so one deep member would cost the operator the whole line.
|
|
157
|
+
*/
|
|
158
|
+
readonly onTooDeep?: "throw" | "name" | undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* How many bytes a view may hold, and how many own members {@link redact} reads
|
|
162
|
+
* off it, before it stops reading them.
|
|
163
|
+
*
|
|
164
|
+
* Enumerating a view's own properties materialises one pair per byte, so the
|
|
165
|
+
* walk costs the buffer's size even though the rendering does not. Both halves
|
|
166
|
+
* of the bound carry load, and neither is a bound on its own. A size alone is
|
|
167
|
+
* not, because `byteLength` was read as an ordinary property and an ordinary
|
|
168
|
+
* property can be shadowed: a pooled chunk that reports the bytes it has used
|
|
169
|
+
* rather than the bytes it holds is a plain pattern, not an adversarial one,
|
|
170
|
+
* and a 4 MB chunk reporting 12 walked one property per byte anyway. A count
|
|
171
|
+
* alone is not, because a caller can hang a million properties on a ten-byte
|
|
172
|
+
* view. So the size is read from the value's own internal slot, where nothing
|
|
173
|
+
* a caller writes can answer for it, and the members are counted as they are
|
|
174
|
+
* walked.
|
|
175
|
+
*
|
|
176
|
+
* @since 0.1.0
|
|
177
|
+
* @category redaction
|
|
178
|
+
*/
|
|
179
|
+
export declare const binaryWalkLimit = 65536;
|
|
180
|
+
/**
|
|
181
|
+
* The key {@link redact} files a binary view's size under.
|
|
182
|
+
*
|
|
183
|
+
* @since 0.1.0
|
|
184
|
+
* @category redaction
|
|
185
|
+
*/
|
|
186
|
+
export declare const binaryMarker = "[Binary]";
|
|
187
|
+
/**
|
|
188
|
+
* What {@link redact} writes in place of a function or a class object.
|
|
189
|
+
*
|
|
190
|
+
* @since 0.1.0
|
|
191
|
+
* @category redaction
|
|
192
|
+
*/
|
|
193
|
+
export declare const functionMarker = "[Function]";
|
|
194
|
+
/**
|
|
195
|
+
* What {@link redact} writes in place of a symbol.
|
|
196
|
+
*
|
|
197
|
+
* @since 0.1.0
|
|
198
|
+
* @category redaction
|
|
199
|
+
*/
|
|
200
|
+
export declare const symbolMarker = "[Symbol]";
|
|
201
|
+
/**
|
|
202
|
+
* What {@link redact} writes past {@link maxDepth} under `onTooDeep: "name"`.
|
|
203
|
+
*
|
|
204
|
+
* @since 0.1.0
|
|
205
|
+
* @category redaction
|
|
206
|
+
*/
|
|
207
|
+
export declare const depthMarker = "[Deep]";
|
|
208
|
+
/**
|
|
209
|
+
* Returns `value` with credentials removed.
|
|
210
|
+
*
|
|
211
|
+
* Objects and arrays are rebuilt: a field whose name {@link isSensitiveKey}
|
|
212
|
+
* is replaced wholesale, every other string is run through the textual rules,
|
|
213
|
+
* and a cycle is collapsed to `"[Circular]"` so the result always encodes.
|
|
214
|
+
* A number, a boolean, `null` and `undefined` are returned untouched, because
|
|
215
|
+
* redacting one destroys data without protecting anything. A function and a
|
|
216
|
+
* symbol are NAMED, {@link functionMarker} and {@link symbolMarker}: a body, an
|
|
217
|
+
* own property and a description are all text a renderer prints, and none of it
|
|
218
|
+
* can be rewritten in place.
|
|
219
|
+
*
|
|
220
|
+
* Traversal accepts at most {@link maxDepth} container edges. A deeper value
|
|
221
|
+
* throws by default, so the journal boundary can report a typed `invalid_event`
|
|
222
|
+
* instead of overflowing the runtime stack. {@link Options.onTooDeep} set to
|
|
223
|
+
* `"name"` writes {@link depthMarker} in its place instead, which is what a
|
|
224
|
+
* logger wants.
|
|
225
|
+
*
|
|
226
|
+
* @since 0.1.0
|
|
227
|
+
* @category redaction
|
|
228
|
+
*/
|
|
229
|
+
export declare const redact: (value: unknown, options?: Options) => unknown;
|
|
230
|
+
/**
|
|
231
|
+
* A redaction function, as the journal consumes it.
|
|
232
|
+
*
|
|
233
|
+
* @since 0.1.0
|
|
234
|
+
* @category models
|
|
235
|
+
*/
|
|
236
|
+
export type Redactor = (value: unknown) => unknown;
|
|
237
|
+
/**
|
|
238
|
+
* Builds a redactor over a rule set.
|
|
239
|
+
*
|
|
240
|
+
* @since 0.1.0
|
|
241
|
+
* @category constructors
|
|
242
|
+
*/
|
|
243
|
+
export declare const make: (options?: Options) => Redactor;
|
|
244
|
+
/**
|
|
245
|
+
* Applies a redactor to an already-encoded JSON string, returning the
|
|
246
|
+
* re-encoded result.
|
|
247
|
+
*
|
|
248
|
+
* For export and display surfaces that hold a column verbatim, a rendered
|
|
249
|
+
* `state_json`, a support bundle, where the value is already encoded and must
|
|
250
|
+
* not be decoded into the executable path. A string that does not parse is
|
|
251
|
+
* returned untouched: validation is the caller's, and rejecting here would
|
|
252
|
+
* turn a redaction concern into a schema error. Once parsing succeeds, a
|
|
253
|
+
* throwing redactor or an encoding failure returns the valid JSON string
|
|
254
|
+
* `"[REDACTED]"`; the original parsed text is never returned.
|
|
255
|
+
*
|
|
256
|
+
* @since 0.1.0
|
|
257
|
+
* @category redaction
|
|
258
|
+
*/
|
|
259
|
+
export declare const redactJsonString: (json: string, redactor: Redactor) => string;
|
|
260
|
+
/**
|
|
261
|
+
* Redacts a stream one line at a time.
|
|
262
|
+
*
|
|
263
|
+
* @since 1.0.0
|
|
264
|
+
* @category models
|
|
265
|
+
*/
|
|
266
|
+
export interface LineRedactor {
|
|
267
|
+
/**
|
|
268
|
+
* Takes the rest of the current line, without its newline, and returns the
|
|
269
|
+
* lines now safe to emit: none while a value is still open.
|
|
270
|
+
*/
|
|
271
|
+
readonly line: (line: string) => ReadonlyArray<string>;
|
|
272
|
+
/**
|
|
273
|
+
* Takes part of a line whose newline has not arrived. A line longer than
|
|
274
|
+
* {@link maxPartialLine} is never emitted: {@link omittedLine} stands for it.
|
|
275
|
+
*/
|
|
276
|
+
readonly part: (text: string) => void;
|
|
277
|
+
/** What {@link LineRedactor.flush} would emit now, without ending the stream: for a rendered snapshot. */
|
|
278
|
+
readonly peek: () => ReadonlyArray<string>;
|
|
279
|
+
/** Ends the stream and returns whatever is still held, redacted as one block. */
|
|
280
|
+
readonly flush: () => ReadonlyArray<string>;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Lines a {@link lineRedactor} holds for one open value. Past this, or past
|
|
284
|
+
* 64 KiB, it stops holding: it emits what it held, redacted, and withholds
|
|
285
|
+
* every later line until the stream ends, when one placeholder stands for
|
|
286
|
+
* them. Dropping lines from the middle instead changed which brackets and
|
|
287
|
+
* quotes were open, and released a later secret in clear.
|
|
288
|
+
*
|
|
289
|
+
* @since 1.0.0
|
|
290
|
+
* @category constants
|
|
291
|
+
*/
|
|
292
|
+
export declare const maxHeldLines = 256;
|
|
293
|
+
/**
|
|
294
|
+
* The longest line a {@link lineRedactor} reads whole. A longer line keeps
|
|
295
|
+
* its first and last 16 KiB; its middle is scanned for what it leaves open
|
|
296
|
+
* and dropped.
|
|
297
|
+
*
|
|
298
|
+
* @since 1.0.0
|
|
299
|
+
* @category constants
|
|
300
|
+
*/
|
|
301
|
+
export declare const maxPartialLine: number;
|
|
302
|
+
/**
|
|
303
|
+
* What a {@link lineRedactor} emits in place of a line longer than
|
|
304
|
+
* {@link maxPartialLine}.
|
|
305
|
+
*
|
|
306
|
+
* @since 1.0.0
|
|
307
|
+
* @category constants
|
|
308
|
+
*/
|
|
309
|
+
export declare const omittedLine = "[overlong line omitted]";
|
|
310
|
+
/**
|
|
311
|
+
* A redactor for a stream that must be emitted line by line: a live build
|
|
312
|
+
* log, a child's stderr.
|
|
313
|
+
*
|
|
314
|
+
* Redacting each line alone is the flaw that leaked a private key's body, and
|
|
315
|
+
* the tail of every string `util.inspect` split over several lines: only the
|
|
316
|
+
* line holding the name was redacted. This one asks the rules themselves
|
|
317
|
+
* whether a line leaves a value open, by checking whether the value swallows
|
|
318
|
+
* a probe placed on the next line, and holds lines until it closes. The held
|
|
319
|
+
* block is then redacted whole, exactly as {@link redact} redacts a string.
|
|
320
|
+
*
|
|
321
|
+
* A line longer than {@link maxPartialLine} is read as its first and last
|
|
322
|
+
* 16 KiB. Its middle is dropped, but a bracket, quote or key block the middle
|
|
323
|
+
* leaves open would have opened a value the kept ends cannot show, so then
|
|
324
|
+
* the rest of the stream is withheld. Such a line is never emitted, only
|
|
325
|
+
* {@link omittedLine}, and neither is any block it was held in.
|
|
326
|
+
*
|
|
327
|
+
* Its state is bounded whatever the stream does: the line still arriving is
|
|
328
|
+
* a 16 KiB head, a 16 KiB tail and at most 1024 open brackets or strings of
|
|
329
|
+
* its middle, a middle nested deeper counting as one left open; the held
|
|
330
|
+
* block is bounded by {@link maxHeldLines} and 64 KiB. Its cost is linear:
|
|
331
|
+
* past the first 16 held lines the block is re-read only once it has grown
|
|
332
|
+
* by half, on Node and on Bun alike (#3088).
|
|
333
|
+
*
|
|
334
|
+
* `rules` defaults to {@link diagnosticRules}. The array is read on every
|
|
335
|
+
* line, so a caller may add a rule, a session secret, as the stream runs.
|
|
336
|
+
*
|
|
337
|
+
* @since 1.0.0
|
|
338
|
+
* @category constructors
|
|
339
|
+
*/
|
|
340
|
+
export declare const lineRedactor: (rules?: ReadonlyArray<Rule>) => LineRedactor;
|
|
341
|
+
/**
|
|
342
|
+
* The identity redactor, for a caller that persists payloads verbatim by
|
|
343
|
+
* choice: a trusted single-tenant store, or a suite asserting on raw input.
|
|
344
|
+
*
|
|
345
|
+
* @since 0.1.0
|
|
346
|
+
* @category constructors
|
|
347
|
+
*/
|
|
348
|
+
export declare const makeNoop: () => Redactor;
|
|
349
|
+
export {};
|
|
350
|
+
//# sourceMappingURL=Redaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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