import { RequestHandler , KibanaRequest , RouteMethod , KibanaResponseFactory } from 'src/core/server' ; import { ILicense } from '../common/types' ; import type { LicensingRequestHandlerContext } from './types' ; export type CheckLicense = ( license : ILicense ) => { valid : false ; message : string ; } | { valid : true ; message : null ; } ; export function wrapRouteWithLicenseCheck < P , Q , B , Context extends LicensingRequestHandlerContext > ( checkLicense , handler ) { return async ( context , request , response ) => { const licenseCheckResult = checkLicense ( context . licensing . license ) ; if ( licenseCheckResult . valid ) { return handler ( context , request , response ) ; } else { return response . forbidden ( { body : licenseCheckResult . message , } ) ; } } ; }