SCION Microfrontend Platform - v1.6.0
    Preparing search index...

    Class CapabilityInterceptorAbstract

    Enables modification of capabilities before they are registered.

    Interceptors can intercept capabilities before they are registered, for example, to perform validation checks, add metadata, change properties, or prevent registration based on user permissions.

    The following interceptor assigns a stable identifier to each microfrontend capability.

    class MicrofrontendCapabilityInterceptor implements CapabilityInterceptor {

    public async intercept(capability: Capability): Promise<Capability> {
    if (capability.type === 'microfrontend') {
    return {
    ...capability,
    // `hash()` is illustrative and not part of the Microfrontend Platform API.
    metadata: {...capability.metadata, id: hash(capability)},
    };
    }
    return capability;
    }
    }

    The following interceptor marks capabilities as inactive based on user permissions.

    class UserAuthorizedCapabilityInterceptor implements CapabilityInterceptor {

    public async intercept(capability: Capability): Promise<Capability> {
    // Read required role from capability properties.
    const requiredRole = capability.properties?.['role'];

    // Mark capability as inactive if the user has no permission.
    // `hasRole()` is illustrative and not part of the Microfrontend Platform API.
    capability.inactive = requiredRole && !hasRole(requiredRole);

    return capability;
    }
    }

    The following interceptor extracts user information to a new capability.

    class UserCapabilityMigrator implements CapabilityInterceptor {

    public async intercept(capability: Capability, manifest: CapabilityInterceptor.Manifest): Promise<Capability> {
    if (capability.type === 'user' && capability.properties['info']) {
    // Move user info to new capability.
    await manifest.addCapability({
    type: 'user-info',
    properties: {
    ...capability.properties['info'],
    },
    });
    // Remove info on intercepted capability.
    delete capability.properties['info'];
    }
    return capability;
    }
    }

    Interceptors are registered in the bean manager of the host application under the symbol CapabilityInterceptor as multi bean. Multiple interceptors can be registered, forming a chain in which each interceptor is called one by one in registration order.

    Beans.register(CapabilityInterceptor, {useClass: MicrofrontendCapabilityInterceptor, multi: true});
    Beans.register(CapabilityInterceptor, {useClass: UserAuthorizedCapabilityInterceptor, multi: true});
    Beans.register(CapabilityInterceptor, {useClass: UserCapabilityMigrator, multi: true});
    Index

    Constructors

    Methods

    Constructors

    Methods