Core
Framework v2.x
2

Plugin #

Base class for External Plugins.

Plugins registered with the BackendPlugin.use method must extends this abstract class.

Some properties of the Plugin class allows to define a set of features that will be integrated to the plugin.

api #

This property allows to define plugin features.

Type Description
PluginApiDefinition
Define new API controllers PluginApiDefinition

The PluginApiDefinition type is an object with each key as a controller name and the value is a valid ControllerDefinition.

Copied to clipboard!
type PluginApiDefinition = {
  /**
   * Name of the API controller.
   */
  [controller: string]: ControllerDefinition
}

config #

Type Description
JSONObject
Plugin configuration

context #

Type Description
PluginContext
PluginContext instance

hooks #

This property allows to define plugin features.

Type Description
PluginHookDefinition
Allows to define hooks on events

The PluginHookDefinition type is an object with each key as an event name and the value is a valid HookEventHandler.

Copied to clipboard!
export type PluginHookDefinition = {
  /**
   * Event name or wildcard event.
   */
  [event: string]: HookEventHandler | HookEventHandler[]
}

pipes #

This property allows to define plugin features.

Type Description
PluginPipeDefinition
Allows to define pipess on events

The PluginPipeDefinition type is an object with each key as an event name and the value is a valid PipeEventHandler.

Copied to clipboard!
export type PluginPipeDefinition = {
  /**
   * Event name or wildcard event.
   */
  [event: string]: PipeEventHandler | PipeEventHandler[]
}

strategies #

This property allows to define plugin features.

Type Description
StrategyDefinition
A valid StrategyDefinition object.

controllers #

Deprecated since 2.8.0
Not available in Typescript

Controllers should be defined in the api property.

This property is not available in Typescript.

Type Description
object
Controllers definition object

Example:

Copied to clipboard!
class MyPlugin {
  init (config, context) {
    this.controllers = {
      greeting: {
        sayHello: request => `Hello, ${request.input.args.name}`,
        sayGoodbye: 'greetingSayGoodbye'
      }
    };
  }

  async greetingSayGoodbye (request) {
    return `Goodbye, ${request.input.args.name}`
  }
}

routes #

Deprecated since 2.8.0
Not available in Typescript

Routes should be defined in the api property.

This property is not available in Typescript.

Type Description
object
Routes definition object

Example:

Copied to clipboard!
class MyPlugin {
  init (config, context) {
    this.controllers = {
      greeting: {
        sayHello: request => `Hello, ${request.input.args.name}`
      }
    };

    this.routes = [
      { verb: 'get', path: '/greeting/:name', controller: 'greeting', action: 'sayHello' }
    ];
  }
}