AEP 1: Apiman policy plugins with full Angular UI/UX #1245
Replies: 3 comments 6 replies
-
/CC: @EricWittmann @volkflo @outofcoffee @kahboom @BastianGem (and anyone else interested :-)). |
Beta Was this translation helpful? Give feedback.
-
Marc thank you for the detailed proposal. If you develop such a policy plugin you will certainly have a development environment and a production environment. For the development environment I see no problem for using some resources for compiling and Internet access for package resolution. |
Beta Was this translation helpful? Give feedback.
-
Off this thread Eric provided me a couple of pointers for the new Webpack 5 federated modules stuff (mentioned in the other subthread briefly): https://webpack.js.org/concepts/module-federation/ I also found a couple of others that are relevant for Angular: https://www.angulararchitects.io/aktuelles/the-microfrontend-revolution-part-2-module-federation-with-angular/ An approach that definitely deserves some attention. In some ways it's half way between recompilation and a fully dynamic approach -- but Web itself provides support for this. When I have more time I'll do a small PoC for both approaches (perhaps weekend, we'll see). |
Beta Was this translation helpful? Give feedback.
-
Enhancement Proposal: Apiman policy plugins with full Angular UI/UX
Background
Apiman offers the ability to extend the functionality of Apiman via policy plugins. These plugins are a WAR file (essentially a ZIP with bundled dependencies and some metadata), comprising of two components:
Google doc version available here for those prefer that layout
Motivation
For simple policies JSON Schema is more than sufficient. It provides quite a rich range of sanity checking and even some simple conditional logic (e.g. oneOf, anyOf, or, etc), however for more sophisticated use-cases it simply can’t provide the level of customisation that is needed in several areas:
Existing solution
As some important background, I will outline the runtime program flow for the existing JSON Schema based Apiman policy plugins solution. As this proposal mainly focuses on the Apiman Manager, we will largely omit the gateway aspects.
Proposal
For fully customisable Angular UI in policy plugins
Considered approaches
Previously, we had been primarily considering whether it was possible to bundle a full Angular module into Apiman policy plugins somehow and load this dynamically. This would essentially involve serving a static version of the Angular application to the client, and then dynamically enriching it when a plugin is loaded.
This proved to be challenging for several reasons. Foremostly, this does not seem to be well supported in the Angular community or codebase. Whilst Angular templates are capable of being compiled dynamically in the browser, the other aspects (e.g. components, pipes, directives, etc), generally expect to be compiled during a discrete compilation phase. Pursuing this approach would likely be complex and potentially fragile, breaking between Angular releases.
Goals
In brief summary, the functionality has the following requirements and characteristics:
Non-Goals
In reviewing these requirements, it became clear that the following are **not **requirements:
Proposed approach
Given these requirements and non-requirements, I propose the use of code injection and recompilation. The flow would be approximately as follows:
Benefits of this approach
Risks & mitigation
Browsers must be reloaded to see the new UI reflected.
We will display a notification to users of the application when a new version has been deployed, prompting them to reload when they are able to. This allows users to save any in-progress work before reloading.
As outlined in the following section, installation of new plugins is not frequent, so should a reload not prove overly burdensome to users.
In certain cases we can safely automate this process. For example, if the user navigates to a policy that is not built into the version of the application they are running, then reloading the application and navigating back to the same location would be acceptable and relatively transparent.
We may need to force a reload at a safe point if the user does not take any action after an extended period of time.
Recompilation is slower than dynamic/on-demand code extension.
This issue is not critical as loading of policy plugins is an administrator action and tends to be infrequent (occasional loading of plugins and version upgrades).
Full JS stack required to enable rebuilding process
This is a key area to manage.
Javascript, Node, NPM/Yarn, etc, will be required. There are issues around ensuring the appropriate tooling with the correct versions is available in the environment (Apiman runs on a wide variety of platforms, so the assumptions we can make are fairly minimal).
Furthermore, substantial memory resources can be consumed temporarily during compilation, which should be accounted for.
Potential approaches were outlined above, but could include use of a pre-packaged “known good” build setup of some sort (e.g. via a docker container).
JS dependency resolution will be required during build
The contributed UI module may have its own dependencies which will need to be resolved during the recompilation.
We will need to ensure:
Build failures and dependency/interface issues
A variety of build issues are possible during the JS build process which could result in a recompilation failure, they include:
To mitigate this we should:
Beta Was this translation helpful? Give feedback.
All reactions