1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/src/lib/ui-config/ui-config-controller.ts
unleash-bot[bot] 8d00eea66a
chore(AI): newUiConfigService flag cleanup (#10910)
This PR cleans up the newUiConfigService flag. These changes were
automatically generated by AI and should be reviewed carefully.

Fixes #10909

## 🧹 AI Flag Cleanup Summary
This PR removes the `newUiConfigService` feature flag and makes its
functionality permanent. The `UiConfigController` now exclusively uses
the
`UiConfigService` to generate the UI configuration, removing the old,
now-dead
code path.
As a result of this change, several services that were only used in the
old
implementation have been removed from `UiConfigController`, along with
their
associated types and imports, simplifying the controller significantly.
### 🚮 Removed
- **Flag Definitions**
- `newUiConfigService` flag definition from
`src/lib/types/experimental.ts`.
- Development override for `newUiConfigService` in `src/server-dev.ts`.
- **Conditional Logic**
- The `if` block checking for `newUiConfigService` in
`UiConfigController.getUiConfig`.
- **Dead Code**
- The legacy implementation of building the UI config object inside
`UiConfigController`.
- Several unused service dependencies (`VersionService`,
`SettingService`,
`EmailService`, `SessionService`, `MaintenanceService`) and
`IFlagResolver` from
`UiConfigController`.
### 🛠 Kept
- **New `getUiConfig` implementation**
- The `UiConfigController.getUiConfig` method now solely relies on
`UiConfigService` to fetch the UI configuration.
### 📝 Why
The `newUiConfigService` feature flag was fully rolled out and marked as
completed. This cleanup removes the flag and the legacy code path,
simplifying
the `UiConfigController` and making the new UI config service the
standard way
of providing UI configuration.

Co-authored-by: unleash-bot <194219037+unleash-bot[bot]@users.noreply.github.com>
2025-11-04 15:49:44 +00:00

117 lines
3.8 KiB
TypeScript

import type { Response } from 'express';
import type { AuthedRequest } from '../types/core.js';
import type { IUnleashServices } from '../services/index.js';
import type { IUnleashConfig } from '../types/option.js';
import Controller from '../routes/controller.js';
import { ADMIN, NONE, UPDATE_CORS } from '../types/permissions.js';
import { createResponseSchema } from '../openapi/util/create-response-schema.js';
import {
uiConfigSchema,
type UiConfigSchema,
} from '../openapi/spec/ui-config-schema.js';
import type { OpenApiService } from '../services/openapi-service.js';
import { emptyResponse } from '../openapi/util/standard-responses.js';
import type { IAuthRequest } from '../routes/unleash-types.js';
import NotFoundError from '../error/notfound-error.js';
import type { SetCorsSchema } from '../openapi/spec/set-cors-schema.js';
import { createRequestSchema } from '../openapi/util/create-request-schema.js';
import type { FrontendApiService } from '../services/index.js';
import type { UiConfigService } from './ui-config-service.js';
class UiConfigController extends Controller {
private frontendApiService: FrontendApiService;
private uiConfigService: UiConfigService;
private readonly openApiService: OpenApiService;
constructor(
config: IUnleashConfig,
{
openApiService,
frontendApiService,
uiConfigService,
}: Pick<
IUnleashServices,
| 'openApiService'
| 'frontendApiService'
| 'clientInstanceService'
| 'uiConfigService'
>,
) {
super(config);
this.openApiService = openApiService;
this.uiConfigService = uiConfigService;
this.frontendApiService = frontendApiService;
this.route({
method: 'get',
path: '',
handler: this.getUiConfig,
permission: NONE,
middleware: [
openApiService.validPath({
tags: ['Admin UI'],
summary: 'Get UI configuration',
description:
'Retrieves the full configuration used to set up the Unleash Admin UI.',
operationId: 'getUiConfig',
responses: {
200: createResponseSchema('uiConfigSchema'),
},
}),
],
});
this.route({
method: 'post',
path: '/cors',
handler: this.setCors,
permission: [ADMIN, UPDATE_CORS],
middleware: [
openApiService.validPath({
tags: ['Admin UI'],
summary: 'Sets allowed CORS origins',
description:
'Sets Cross-Origin Resource Sharing headers for Frontend SDK API.',
operationId: 'setCors',
requestBody: createRequestSchema('setCorsSchema'),
responses: { 204: emptyResponse },
}),
],
});
}
async getUiConfig(
req: AuthedRequest,
res: Response<UiConfigSchema>,
): Promise<void> {
const uiConfig = await this.uiConfigService.getUiConfig(req.user);
this.openApiService.respondWithValidation(
200,
res,
uiConfigSchema.$id,
uiConfig,
);
}
async setCors(
req: IAuthRequest<void, void, SetCorsSchema>,
res: Response<string>,
): Promise<void> {
if (req.body.frontendApiOrigins) {
await this.frontendApiService.setFrontendCorsSettings(
req.body.frontendApiOrigins,
req.audit,
);
res.sendStatus(204);
return;
}
throw new NotFoundError();
}
}
export default UiConfigController;