Plugins Features #
Embedded SDK #
Plugins have access to an instance of the EmbeddedSDK to interact with Kuzzle throught the Plugin.context.accessors.sdk property.
API #
Plugins can declare new controllers and actions through the Plugin.api property.
API definition must be done in the constructor or in the plugin init method.
The PluginApiDefinition
is an object which each key is a controller name and each value is a ControllerDefinition
class EmailPlugin extends Plugin {
constructor () {
super({ kuzzleVersion: '>=2.8 <3' });
this.api = {
greeting: {
actions: {
sayHello: {
handler: async request => `Hello, ${request.input.args.name}`
}
}
}
};
}
}
Plugin controller names will be prefixed by the plugin name.
With the example above, the controller name will be email/greeting
Like standard API actions, plugin custom API action will also trigger events.
See also the API Controllers guide.
Pipes and Hooks #
Plugins can register hooks and pipes on the Event System.
Hooks and pipes registration must be done in the constructor or in the plugin init method.
class MyPlugin extends Plugin {
constructor () {
super({ kuzzleVersion: '>=2.8 <3' });
this.hooks = {
'document:beforeCreate': async request => {}
};
this.pipes = {
'server:afterNow': async request => request
};
}
}
Default imports #
Plugins can declare defaults documents to be loaded before Kuzzle open it's API.
The following imports are available:
users
roles
profiles
mappings
(indexes and collections)usersMappings
See also Backend.import.