1import * as Redacted from "effect/Redacted";
2
3/**
4 * Distilled decodes `smithy.api#sensitive` strings to `Redacted<string>` on
5 * responses while accepting plain strings on requests. Attributes expose
6 * plain strings, so unwrap defensively.
7 */
8export const unredact = (
9 value: string | Redacted.Redacted<string> | undefined,
10): string | undefined =>
11 value === undefined
12 ? undefined
13 : Redacted.isRedacted(value)
14 ? Redacted.value(value)
15 : value;
16
17/**
18 * Audit Manager tag maps arrive as `{ [key]: string | undefined }` — narrow
19 * to the `Record<string, string>` shape the Tags helpers expect.
20 */
21export const toTagRecord = (
22 tags: { [key: string]: string | undefined } | undefined,
23): Record<string, string> =>
24 Object.fromEntries(
25 Object.entries(tags ?? {}).filter(
26 (entry): entry is [string, string] => entry[1] !== undefined,
27 ),
28 );