import { Response } from 'express'; import { OpenApiService } from 'lib/services'; import { IAuthRequest } from '../unleash-types'; import { IUnleashConfig } from '../../types/option'; import Controller from '../controller'; import { NONE } from '../../types/permissions'; import { IUnleashServices } from 'lib/types'; import { createResponseSchema } from '../../openapi/util/create-response-schema'; import { telemetrySettingsSchema, TelemetrySettingsSchema, } from '../../openapi/spec/telemetry-settings-schema'; class TelemetryController extends Controller { config: IUnleashConfig; openApiService: OpenApiService; constructor( config: IUnleashConfig, { openApiService }: Pick, ) { super(config); this.config = config; this.openApiService = openApiService; this.route({ method: 'get', path: '/settings', handler: this.getTelemetrySettings, permission: NONE, middleware: [ openApiService.validPath({ tags: ['Telemetry'], summary: 'Get telemetry settings', description: 'Provides the configured settings for [telemetry information collection](https://docs.getunleash.io/topics/data-collection)', operationId: 'getTelemetrySettings', responses: { 200: createResponseSchema('telemetrySettingsSchema'), }, }), ], }); } async getTelemetrySettings( req: IAuthRequest, res: Response, ): Promise { this.openApiService.respondWithValidation( 200, res, telemetrySettingsSchema.$id, { versionInfoCollectionEnabled: this.config.versionCheck.enable, featureInfoCollectionEnabled: this.config.telemetry, }, ); } } export default TelemetryController;