import type { NavigationGuard } from '@tinkoff/router' ; import type { BUNDLE_MANAGER_TOKEN , COMPONENT_REGISTRY_TOKEN , ACTION_REGISTRY_TOKEN , LOGGER_TOKEN , RESPONSE_MANAGER_TOKEN , } from '@tramvai/tokens-common' ; export const loadBundle = ( { bundleManager , logger , actionRegistry , responseManager , } ) : NavigationGuard => { const log = logger ( 'route:load-bundles' ) ; return async ( { to } ) => { log . debug ( { event : 'load-bundle' , route : to , } ) ; const { bundle , pageComponent } = to . config ; if ( ! bundleManager . has ( bundle , pageComponent ) ) { log . info ( { event : 'load-bundle-not-found' , bundle , pageComponent , } ) ; responseManager . setStatus ( 404 ) ; return false ; } try { await bundleManager . get ( bundle , pageComponent ) ; } catch ( error ) { log . error ( { event : 'load-bundle-failed' , error , } ) ; return false ; } } ; } ;