MCPcopy
hub / github.com/simstudioai/sim / redactPIIFromExecution

Function redactPIIFromExecution

apps/sim/lib/logs/execution/pii-redaction.ts:205–243  ·  view source on GitHub ↗
(
  payload: RedactablePayload,
  options: PiiRedactionOptions
)

Source from the content-addressed store, hash-verified

203 * the failure path.
204 */
205export async function redactPIIFromExecution(
206 payload: RedactablePayload,
207 options: PiiRedactionOptions
208): Promise<RedactablePayload> {
209 const startedAt = performance.now()
210
211 const units = REDACTABLE_KEYS.filter((key) => payload[key] !== undefined).map((key) => ({
212 key,
213 value: payload[key],
214 }))
215
216 const collected: string[] = []
217 let totalBytes = 0
218 for (const unit of units) {
219 transformUnit(unit.key, unit.value, (s) => {
220 collected.push(s)
221 totalBytes += Buffer.byteLength(s, 'utf8')
222 return s
223 })
224 }
225
226 if (collected.length === 0) return payload
227
228 const { masked, scrubbed } = await maskCollected(collected, options)
229
230 let index = 0
231 const result: RedactablePayload = { ...payload }
232 for (const unit of units) {
233 result[unit.key] = transformUnit(unit.key, unit.value, () => masked[index++])
234 }
235
236 logger.info('PII redaction completed', {
237 stringCount: collected.length,
238 totalBytes,
239 durationMs: Math.round(performance.now() - startedAt),
240 scrubbed,
241 })
242 return result
243}

Callers 2

applyPiiRedactionMethod · 0.90

Calls 4

transformUnitFunction · 0.85
maskCollectedFunction · 0.85
infoMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected