chore(admin): remove useless config diff (#12545)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Added a GraphQL mutation to validate multiple app configuration updates, returning detailed validation results for each item.
  - Extended the API schema to support validation feedback, enabling client-side checks before applying changes.
  - Introduced a detailed, parameterized error message system for configuration validation errors.
  - Enabled validation of configuration inputs via the admin UI with clear, descriptive error messages.

- **Improvements**
  - Enhanced error reporting with specific, context-rich messages for invalid app configurations.
  - Simplified admin settings UI by removing the confirmation dialog and streamlining save actions.
  - Improved clarity and maintainability of validation logic and error handling components.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
forehalo
2025-05-27 06:07:26 +00:00
parent eed95366c9
commit 2f139bd02c
19 changed files with 291 additions and 185 deletions
@@ -1,6 +1,7 @@
import test from 'ava';
import { createModule } from '../../../__tests__/create-module';
import { InvalidAppConfig } from '../../error';
import { ConfigFactory, ConfigModule } from '..';
import { Config } from '../config';
import { override } from '../register';
@@ -64,30 +65,29 @@ test('should override config', async t => {
test('should validate config', t => {
const config = module.get(ConfigFactory);
t.notThrows(() =>
t.is(
config.validate([
{
module: 'auth',
key: 'passwordRequirements',
value: { max: 10, min: 6 },
},
])
]),
null
);
t.throws(
() =>
config.validate([
{
module: 'auth',
key: 'passwordRequirements',
value: { max: 10, min: 10 },
},
]),
const [error] = config.validate([
{
message: `Invalid config for module [auth] with key [passwordRequirements]
Value: {"max":10,"min":10}
Error: Minimum length of password must be less than maximum length`,
}
module: 'auth',
key: 'passwordRequirements',
value: { max: 10, min: 10 },
},
])!;
t.true(error instanceof InvalidAppConfig);
t.is(
error.message,
'Invalid app config for module `auth` with key `passwordRequirements`. Minimum length of password must be less than maximum length.'
);
});
@@ -33,13 +33,17 @@ export class ConfigFactory {
}
validate(updates: Array<{ module: string; key: string; value: any }>) {
const errors: string[] = [];
const errors: InvalidAppConfig[] = [];
updates.forEach(update => {
const descriptor = APP_CONFIG_DESCRIPTORS[update.module]?.[update.key];
if (!descriptor) {
errors.push(
`Invalid config for module [${update.module}] with unknown key [${update.key}]`
new InvalidAppConfig({
module: update.module,
key: update.key,
hint: `Unknown config [${update.key}]`,
})
);
return;
}
@@ -47,16 +51,18 @@ export class ConfigFactory {
const { success, error } = descriptor.validate(update.value);
if (!success) {
error.issues.forEach(issue => {
errors.push(`Invalid config for module [${update.module}] with key [${update.key}]
Value: ${JSON.stringify(update.value)}
Error: ${issue.message}`);
errors.push(
new InvalidAppConfig({
module: update.module,
key: update.key,
hint: issue.message,
})
);
});
}
});
if (errors.length > 0) {
throw new InvalidAppConfig(errors.join('\n'));
}
return errors.length > 0 ? errors : null;
}
private loadDefault() {