MCPcopy Create free account
hub / github.com/anomalyco/opencode / redactJsonFields

Function redactJsonFields

packages/http-recorder/src/redactor.ts:85–94  ·  view source on GitHub ↗
(value: unknown, fields: ReadonlySet<string>)

Source from the content-addressed store, hash-verified

83const normalizeField = (field: string) => field.replace(/[^a-z0-9]/gi, "").toLowerCase()
84
85const redactJsonFields = (value: unknown, fields: ReadonlySet<string>): unknown => {
86 if (Array.isArray(value)) return value.map((item) => redactJsonFields(item, fields))
87 if (!value || typeof value !== "object") return value
88 return Object.fromEntries(
89 Object.entries(value).map(([key, child]) => [
90 key,
91 fields.has(normalizeField(key)) ? REDACTED : redactJsonFields(child, fields),
92 ]),
93 )
94}
95
96const redactBody = (value: string, fields: ReadonlySet<string>, transform: ((body: string) => string) | undefined) => {
97 const redacted = Option.match(decodeJson(value), {

Callers 1

redactBodyFunction · 0.85

Calls 1

normalizeFieldFunction · 0.85

Tested by

no test coverage detected