import { Configuration , configurationRecursiveSchema , Plugin } from '@mia-platform/core' ; import { DecoratedFastify , Handler } from '@mia-platform/custom-plugin-lib' ; import { readValidateConfiguration } from '../utils/configurationManager' ; import { aclExpressionEvaluator } from '../utils/aclExpressionEvaluator' ; const readPluginConfiguration = async ( fastifyInstance ) => { const configurationPath = fastifyInstance . config . MICROLC_CONFIGURATION_PATH as string ; const validateConfiguration = await readValidateConfiguration ( configurationPath , configurationRecursiveSchema ) ; return validateConfiguration as Configuration ; } ; const buildNewConfiguration = ( oldConfiguration , allowedPlugins ) => { return { ... oldConfiguration , plugins : allowedPlugins , } ; } ; export const configurationApiHandlerBuilder = async ( fastifyInstance ) => { const configuration = await readPluginConfiguration ( fastifyInstance ) ; return ( request , reply ) => { const userGroups = request . getGroups ( ) ; const allowedPlugins = aclExpressionEvaluator ( configuration . plugins || [ ] , userGroups ) ; const configurationForUser = buildNewConfiguration ( configuration , allowedPlugins ) ; reply . send ( configurationForUser ) ; } ; } ; export const configurationApiSchema = { summary : 'Expose the configurations of micro-lc' , response : { 200 : { description : 'Configuration of micro-lc' , type : 'object' , properties : { } , additionalProperties : true , } , } , } as const ;