import { DecoratedFastify , Handler } from '@mia-platform/custom-plugin-lib' ; import { CONFIGURATION_NAME } from '../constants' ; import { aclExpressionEvaluator } from '../utils/aclExpressionEvaluator' ; import { readConfigurationFile } from '../utils/configurationManager' ; import { referencesReplacer } from '../utils/referencesReplacer' ; const retrieveConfigurationFile = async ( instanceConfig , configurationName ) => { const configurationPath = `${ instanceConfig . PLUGINS_CONFIGURATIONS_PATH }/${ configurationName }.json` ; return readConfigurationFile ( configurationPath ) ; } ; export const configurationFileApiHandlerBuilder = ( fastifyInstance ) => { return async ( request , reply ) => { const instanceConfig = fastifyInstance . config ; if ( instanceConfig . PLUGINS_CONFIGURATIONS_PATH ) { const userGroups = request . getGroups ( ) ; const configurationContent = await retrieveConfigurationFile ( instanceConfig , request . params [ CONFIGURATION_NAME ] ) ; const configurationContentFiltered = aclExpressionEvaluator ( configurationContent , userGroups ) ; reply . send ( referencesReplacer ( configurationContentFiltered ) ) ; } else { reply . status ( 404 ) . send ( ) ; } } ; } ; export const configurationFileApiSchema = { summary : 'Expose a configuration file' , params : { type : 'object' , properties : { [ CONFIGURATION_NAME ] : { type : 'string' , } , } , required : [ CONFIGURATION_NAME ] , } , } as const ;