import { schema } from '@kbn/config-schema' ; import { wrapError } from '../../../lib/errors' ; import { createLicensedRouteHandler } from '../../lib' ; import type { ExternalRouteDeps } from './' ; export function initDisableLegacyUrlAliasesApi ( deps ) { const { externalRouter , getSpacesService , usageStatsServicePromise } = deps ; const usageStatsClientPromise = usageStatsServicePromise . then ( ( { getClient } ) => getClient ( ) ) ; externalRouter . post ( { path : '/api/spaces/_disable_legacy_url_aliases' , validate : { body : schema . object ( { aliases : schema . arrayOf ( schema . object ( { targetSpace : schema . string ( ) , targetType : schema . string ( ) , sourceId : schema . string ( ) , } ) ) , } ) , } , } , createLicensedRouteHandler ( async ( _context , request , response ) => { const spacesClient = getSpacesService ( ) . createSpacesClient ( request ) ; const { aliases } = request . body ; usageStatsClientPromise . then ( ( usageStatsClient ) => usageStatsClient . incrementDisableLegacyUrlAliases ( ) ) ; try { await spacesClient . disableLegacyUrlAliases ( aliases ) ; return response . noContent ( ) ; } catch ( error ) { return response . customError ( wrapError ( error ) ) ; } } ) ) ; }