(path: string)
| 42 | * Unknown top-level keys are rejected unless explicitly allowed by the caller. |
| 43 | */ |
| 44 | export function validateConfigKeyPath(path: string): { valid: boolean; reason?: string } { |
| 45 | const rawKeys = path.split('.'); |
| 46 | |
| 47 | if (rawKeys.length === 0 || rawKeys.some((key) => key.trim() === '')) { |
| 48 | return { valid: false, reason: 'Key path must not be empty' }; |
| 49 | } |
| 50 | |
| 51 | const rootKey = rawKeys[0]; |
| 52 | if (!KNOWN_TOP_LEVEL_KEYS.has(rootKey)) { |
| 53 | return { valid: false, reason: `Unknown top-level key "${rootKey}"` }; |
| 54 | } |
| 55 | |
| 56 | if (rootKey === 'featureFlags') { |
| 57 | if (rawKeys.length > 2) { |
| 58 | return { valid: false, reason: 'featureFlags values are booleans and do not support nested keys' }; |
| 59 | } |
| 60 | return { valid: true }; |
| 61 | } |
| 62 | |
| 63 | if (rawKeys.length > 1) { |
| 64 | return { valid: false, reason: `"${rootKey}" does not support nested keys` }; |
| 65 | } |
| 66 | |
| 67 | return { valid: true }; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get a nested value from an object using dot notation. |
no test coverage detected