(data: unknown, ctx: RedactionContext)
| 440 | } |
| 441 | |
| 442 | function redactAsyncStorageItem(data: unknown, ctx: RedactionContext): unknown { |
| 443 | const sensitiveKeysLower = ctx.parsed.sensitiveKeysLower |
| 444 | |
| 445 | // [key, value] tuple from a multiSet/multiMerge `pairs` entry. |
| 446 | if (Array.isArray(data) && data.length === 2 && typeof data[0] === "string") { |
| 447 | const [key, value] = data as [string, unknown] |
| 448 | if (storageKeyIsSensitive(key, sensitiveKeysLower)) return [key, REDACTED] |
| 449 | if (typeof value === "string") return [key, redactStringValue(value, ctx)] |
| 450 | return data |
| 451 | } |
| 452 | |
| 453 | if (typeof data === "object" && data !== null) { |
| 454 | const obj = data as Record<string, unknown> |
| 455 | |
| 456 | // multiSet / multiMerge: { pairs: [[key, value], ...] } |
| 457 | if (Array.isArray(obj.pairs)) { |
| 458 | return { ...obj, pairs: obj.pairs.map((p) => redactAsyncStorageItem(p, ctx)) } |
| 459 | } |
| 460 | |
| 461 | // setItem / mergeItem: { key, value } |
| 462 | if ("key" in obj && typeof obj.key === "string") { |
| 463 | const result = { ...obj } |
| 464 | if (storageKeyIsSensitive(obj.key, sensitiveKeysLower) && "value" in obj) { |
| 465 | result.value = REDACTED |
| 466 | } else if ("value" in obj && typeof obj.value === "string") { |
| 467 | result.value = redactStringValue(obj.value as string, ctx) |
| 468 | } |
| 469 | return result |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return data |
| 474 | } |
no test coverage detected