(params: {
orgSettings: DataRetentionSettings | null | undefined
workspaceId: string
})
| 66 | * workspace-exemption / off shape). Defensive about the loosely-typed JSON column. |
| 67 | */ |
| 68 | export function resolveEffectivePiiRedaction(params: { |
| 69 | orgSettings: DataRetentionSettings | null | undefined |
| 70 | workspaceId: string |
| 71 | }): EffectivePiiRedaction { |
| 72 | const rules = params.orgSettings?.piiRedaction?.rules |
| 73 | if (!Array.isArray(rules) || rules.length === 0) return DEFAULT_PII_REDACTION |
| 74 | |
| 75 | const rule = |
| 76 | rules.find((r) => r?.workspaceId === params.workspaceId) ?? |
| 77 | rules.find((r) => r?.workspaceId == null) |
| 78 | if (!rule) return DEFAULT_PII_REDACTION |
| 79 | |
| 80 | if (!rule.stages) { |
| 81 | const types = sanitizeEntityTypes(rule.entityTypes) |
| 82 | if (types.length === 0) return DEFAULT_PII_REDACTION |
| 83 | return { |
| 84 | input: DISABLED_STAGE, |
| 85 | blockOutputs: DISABLED_STAGE, |
| 86 | logs: { |
| 87 | enabled: true, |
| 88 | entityTypes: types, |
| 89 | language: coercePiiLanguage(rule.language) ?? DEFAULT_PII_LANGUAGE, |
| 90 | }, |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return { |
| 95 | input: toEffectiveStage(rule.stages.input), |
| 96 | blockOutputs: toEffectiveStage(rule.stages.blockOutputs), |
| 97 | logs: toEffectiveStage(rule.stages.logs), |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | export type RetentionHoursKey = |
| 102 | | 'logRetentionHours' |
no test coverage detected