* Sanitizes a provider config by resetting invalid/removed apiProvider values. * Returns the sanitized config and a warning message if the provider was invalid.
(configName: string, apiConfig: unknown)
| 44 | * Returns the sanitized config and a warning message if the provider was invalid. |
| 45 | */ |
| 46 | function sanitizeProviderConfig(configName: string, apiConfig: unknown): { config: unknown; warning?: string } { |
| 47 | if (typeof apiConfig !== "object" || apiConfig === null) { |
| 48 | return { config: apiConfig } |
| 49 | } |
| 50 | |
| 51 | const { config, migrated } = downgradeLegacyRooConfig(apiConfig as Record<string, unknown>) |
| 52 | |
| 53 | if (migrated) { |
| 54 | return { |
| 55 | config, |
| 56 | warning: `Profile "${configName}": ${ROUTER_REMOVAL_IMPORT_WARNING}`, |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Check if apiProvider is set and if it's still valid |
| 61 | if (config.apiProvider !== undefined && !isProviderName(config.apiProvider)) { |
| 62 | const invalidProvider = config.apiProvider |
| 63 | // Return a new config object without the invalid apiProvider |
| 64 | const { apiProvider, ...restConfig } = config |
| 65 | return { |
| 66 | config: restConfig, |
| 67 | warning: `Profile "${configName}": Invalid provider "${invalidProvider}" was removed. Please reconfigure this profile.`, |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return { config: apiConfig } |
| 72 | } |
| 73 | |
| 74 | const globalSettingsShape = globalSettingsSchema.shape as Record<keyof GlobalSettings, z.ZodTypeAny> |
| 75 |
no test coverage detected