import { GuardResult, ActivatedRouteSnapshot, MaybeAsync, Router, RouterStateSnapshot, CanActivateFn, CanActivate, CanDeactivateFn, CanDeactivate, Route } from '@angular/router'; import * as i0 from '@angular/core'; import { Type, OnDestroy } from '@angular/core'; declare global { interface Window { '@onecx/angular-utils': { guards?: { debug?: boolean; }; }; } } /** * Logs debug information for Guards. * It checks if the debug mode is enabled and logs the provided arguments. * This is useful for debugging guard checks and navigation state. * @param args - the arguments to log */ declare function logGuardsDebug(...args: any[]): void; /** * Execute router sync operation. * Immediately returns true to indicate that the operation was successful. */ declare function executeRouterSyncGuard(): boolean; /** * Returns false if any guard returned false. * Returns UrTree or RedirectCommand if any guard returned this value type (the first value is returned). * Else it returns true. */ declare function combineToGuardResult(results: GuardResult[]): GuardResult; /** * Returns false if any guard returned false. * Else it returns true. */ declare function combineToBoolean(results: GuardResult[]): boolean; /** * Resolves MaybeAsync to Promise. * @param maybeAsync - the value to resolve * @returns Promise */ declare function resolveToPromise(maybeAsync: MaybeAsync): Promise; /** * Gets the URL from the ActivatedRouteSnapshot. * @param route - the route to get URL from * @returns string - the URL of the route */ declare function getUrlFromSnapshot(route: ActivatedRouteSnapshot): string; /** * Wrapper for canActivate guards that handles the navigation state and executes guards accordingly. * * It performs the activation checks in different scenarios based on the navigation state. */ declare class ActivateGuardsWrapper { private readonly injector; private readonly guardsGatherer; protected router: Router; private readonly guardsNavigationStateController; canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot, guards: Array>): MaybeAsync; private executeActivateGuards; private mapActivateGuardToFunctionReturningPromise; private isCanActivateClassBasedGuard; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Wrapper for canDeactivate guards that handles the navigation state and executes guards accordingly. * * It performs the deactivation checks in different scenarios based on the navigation state */ declare class DeactivateGuardsWrapper { private readonly injector; private readonly guardsGatherer; protected router: Router; private readonly guardsNavigationStateController; canDeactivate(component: any, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot, guards: Array | Type>>): MaybeAsync; private executeDeactivateGuards; private mapDeactivateGuardToFunctionReturningPromise; private isCanDeactivateClassBasedGuard; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Extended Route interface to hold original guards. * This interface extends the Angular Route interface to include lists for original guards. */ interface OnecxRoute extends Route { canActivateGuardList?: Array>; canDeactivateGuardList?: Array | Type>>; canActivateChildGuardList?: Array>; } declare const WRAPPED_GUARD_TAG: unique symbol; /** * Wraps the guards for a given route. * This function will wrap CanActivate, CanDeactivate and CanActivateChild guards and force the route to always run guards and resolvers. * It ensures that in a multi-router environment, the guards are properly executed. * @param route - The route to wrap guards for. */ declare function wrapGuards(route: Route): void; /** * Scattered guards navigation state model. * Used to check if the guard checks are requested in the navigation state by different application. * This is used to perform guard checks without navigating. */ interface GuardsNavigationState { [IS_ROUTER_SYNC]?: boolean; [IS_INITIAL_ROUTER_SYNC]?: boolean; [GUARD_CHECK]?: boolean; [GUARD_CHECK_PROMISE]?: GuardCheckPromise; } type GuardCheckPromise = Promise; /** * Indicates that the router is in sync mode. */ declare const IS_ROUTER_SYNC = "isRouterSync"; /** * Indicates that the router is in initial sync mode. */ declare const IS_INITIAL_ROUTER_SYNC = "isInitialRouterSync"; /** * Indicates that the guard check is requested. */ declare const GUARD_CHECK = "guardCheck"; /** * Indicates that the guard check promise was requested by this application. * This is used to wait for the external guard checks to be completed before proceeding with the navigation. */ declare const GUARD_CHECK_PROMISE = "guardCheckPromise"; declare enum GUARD_MODE { INITIAL_ROUTER_SYNC = "initialRouterSync", ROUTER_SYNC = "routerSync", GUARD_CHECK = "guardCheck", NAVIGATION_REQUESTED = "navigationRequested" } /** * GuardsNavigationController is a service that manages the navigation state for guards. */ declare class GuardsNavigationStateController { /** * Retrieves the current mode of the guards navigation state. * @param guardsNavigationState - the GuardsNavigationState to check * @returns GUARD_MODE indicating the current mode of the guards navigation state */ getMode(guardsNavigationState: GuardsNavigationState): GUARD_MODE; /** * Creates an initial router sync state for guards navigation. * @param guardsNavigationState - optional GuardsNavigationState to modify * @returns GuardsNavigationState with initial router sync state */ createInitialRouterSyncState(guardsNavigationState?: GuardsNavigationState): GuardsNavigationState; /** * Creates a router sync state for guards navigation. * @param guardsNavigationState - optional GuardsNavigationState to modify * @returns GuardsNavigationState with router sync state */ createGuardCheckState(guardsNavigationState?: GuardsNavigationState): GuardsNavigationState; /** * Creates a navigation requested state for guards navigation. * @param guardsCheckPromise - the promise to resolve guard checks * @param guardsNavigationState - optional GuardsNavigationState to modify * @returns GuardsNavigationState with navigation requested state */ createNavigationRequestedState(guardsCheckPromise: GuardCheckPromise, guardsNavigationState?: GuardsNavigationState): GuardsNavigationState; /** * Retrieves the GuardCheckPromise from the provided GuardsNavigationState. * @param state - the GuardsNavigationState to check * @returns GuardCheckPromise if it exists, undefined otherwise */ getGuardCheckPromise(state: GuardsNavigationState): GuardCheckPromise | undefined; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Request for performing guard checks. * It contains the URL of the route for which the guard checks are requested. */ type GuardResultRequest = { url: string; }; /** * Response for the guard checks. * It indicates whether the guard checks were successful or not. */ type GuardResultResponse = boolean; declare const GUARDS_GATHERER_NAME = "GuardGatherer"; /** * GuardsGatherer is used to gather results of navigation guards. * It allows to perform guard checks of the application. * GuardsGatherer adds information in the navigation state to request guard checks. * It is expected that guards wrappers will use this information to perform checks and respond if checks are not successful. Otherwise, it will proceed with the navigation and navigation will be rejected on GuardsCheckEnd and results will be reported. * It uses a Gatherer to manage the requests and responses. */ declare class GuardsGatherer implements OnDestroy { private guardsGatherer; private guardsChecks; private readonly guardsNavigationStateController; private readonly router; ngOnDestroy(): void; /** * Schedules a request to gather guard results. * @param request - the request to gather guard results * @returns Promise that resolves with the response of the guard results. */ gather(request: GuardResultRequest): Promise; /** * Resolves the guard results for a specific route. * @param routeUrl - the URL of the route for which the guard results are resolved * @param response - the response of the guard result */ resolveRoute(routeUrl: string, response: GuardResultResponse): void; /** * Activates the GuardsGatherer service. * It initializes the Gatherer and sets up the callback to execute guard checks. */ activate(): void; /** * Deactivates the GuardsGatherer service. * It destroys the Gatherer and clears the checks. */ deactivate(): void; private executeGuardsCallback; private normalizeUrl; private throwNotActiveError; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } export { ActivateGuardsWrapper, DeactivateGuardsWrapper, GUARDS_GATHERER_NAME, GUARD_CHECK, GUARD_CHECK_PROMISE, GUARD_MODE, GuardsGatherer, GuardsNavigationStateController, IS_INITIAL_ROUTER_SYNC, IS_ROUTER_SYNC, WRAPPED_GUARD_TAG, combineToBoolean, combineToGuardResult, executeRouterSyncGuard, getUrlFromSnapshot, logGuardsDebug, resolveToPromise, wrapGuards }; export type { GuardCheckPromise, GuardResultRequest, GuardResultResponse, GuardsNavigationState, OnecxRoute };