Categories:
Aura mocks server plugins
aura-mocks-server plugins are components that provide different functionalities to this component
Introduction
aura-mocks-server is composed of plugins, which provide functionality to the tool. Plugins work independently, the same way as a service in a microservices oriented architecture: isolated, self-contained and without affecting other existing functionality in the system.
Discover in the current documents detailed information regarding aura-mocks-server plugins:
-
Descriptive information regarding plugins: types of plugins, plugins management, plugin basic structure, plugins modules
-
Available plugins in the aura-mocks-server global plugins catalog
Global plugins catalog
The available global plugins of aura-mocks-server are included in the Github global plugins repository.
Aura Platform Team is progressively documenting each plugin within the current documents. Check the already documented ones in the left sidebar index.
Types of plugins
There are different types of plugins:
-
Api. REST services that perform specific tasks not associated with the communication with a channel.
-
Client. These plugins define clients that can be used to communicate with a channel. These clients are normally used by processor plugins.
-
Processor. Plugins in charge of communicating with a channel, transforming the message received from a source channel to a destination channel.
-
Service. Utility plugins to be used by the rest of plugins.
Plugins management
As indicated in the previous section, aura-mocks-server uses the library@architect/architect for the management of plugins, so it is the architect library that is responsible for managing the dependencies injection in each module.
To create the architect application, aura-mocks-server uses the PluginManager module (located in the modules/plugin-manager folder). This module starts as the rest of modules at the aura-mocks-server start-up.
The PluginManager performs the following tasks:
- It starts the architect application with the plugins defined in
plugin-config.jsonfile, located at the root of the aura-mocks-server component. - It adds the core modules to the IOC context. See the section modules added by aura-mocks-server.
- It stores the information of each module defined in the plugins.
An example to define aura-mocks-server-example-service plugin of the previous section is shown below:
/* file: plugin-config.json */
[
"./lib/plugins/aura-mocks-server-example-service",
]
Currently, the plugins are in the src/plugins folder of aura-mocks-server, but in the future these plugins should be independent libraries and could be charged by library name (for example: @telefonica/aura-mocks-server-example-service).
Apart from the aura-mocks-server core environment variables, each plugin can define its own specific variables.
Plugin basic structure
Currently, aura-mocks-server uses @architect/architect library for plugins management.
A basic plugin must define at least:
- A
package.jsonfile defining the library, like any other JavaScript library, with apluginsection defining which modules it consumes and supplies. - A source code file that defines the modules that it supplies (
index.tsfor example).
The structure of this basic plugin is as follows:
aura-mocks-server-example-service
├── index.ts
└── package.json
A couple of examples with the content of each file are included below:
/* file: index.ts */
import { PluginType, registerPlugin } from '@telefonica/xxxx-server-common';
import { v4 as uuidv4 } from 'uuid';
import { Services } from './example-consume-services';
export = registerPlugin([
{
type: PluginType.Service, // Plugin service type
name: 'exampleService', // Name of the plugin service
instance: { // [provides] Instance that provides the module
getUniqueId() {
return uuidv4();
}
},
services: Services // [consumes] Needed modules are added here
}
]);
/* file: package.json */
{
"name": "@telefonica/aura-mocks-server-example-service",
"version": "1.0.0",
"main": "index.js",
"private": true,
"plugin": {
"consumes": [
"configurationManager"
],
"provides": [
"exampleService"
]
}
}
The modules specified in the plugin.consumes field define the services that are needed by this plugin. The modules specified in the plugin.provides field define the modules that this plugin offers.
Plugins modules
aura-mocks-server currently adds three modules that can be used by the different plugins. To use them, it is only necessary to add the package.json dependencies on plugin.consumes (like any other module/component).
- configurationManager: Module with the aura-mocks-server configuration information.
- auramocks-serverCache: Module to manage the aura-mocks-server cache.
- prometheus: Service for metrics management.
A plugin can provide one or more plugin modules and each plugin module can be of a different type. Each type of module is intended to add a specific functionality to aura-mocks-server.
The existing types are defined in PluginType, which are described in the following sections.
export enum PluginType {
Api = 'Api',
Client = 'Client',
Processor = 'Processor',
Service = 'Service'
}