(section: ConfigSection, data: unknown)
| 1070 | |
| 1071 | /** Validate and write a config section to disk. Returns the validated config. */ |
| 1072 | export async function writeConfigSection(section: ConfigSection, data: unknown): Promise<unknown> { |
| 1073 | const schema = sectionSchemas[section] |
| 1074 | const validated = schema.parse(data) |
| 1075 | await mkdir(CONFIG_DIR, { recursive: true }) |
| 1076 | await writeFile(resolve(CONFIG_DIR, sectionFiles[section]), JSON.stringify(validated, null, 2) + '\n') |
| 1077 | if (section === 'marketData') { |
| 1078 | const keys = (validated as { providerKeys?: Record<string, string | undefined> }).providerKeys |
| 1079 | if (keys) await mirrorProviderKeysToGlobal(keys) |
| 1080 | } |
| 1081 | return validated |
| 1082 | } |
| 1083 | |
| 1084 | /** Read web sub-channel definitions from disk. Returns empty array if file missing. */ |
| 1085 | export async function readWebSubchannels(): Promise<WebChannel[]> { |
no test coverage detected