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.

TypeDescription
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.

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

config #

TypeDescription
JSONObject
Plugin configuration

context #

TypeDescription
PluginContext
PluginContext instance

hooks #

This property allows to define plugin features.

TypeDescription
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.

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

pipes #

This property allows to define plugin features.

TypeDescription
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.

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

strategies #

This property allows to define plugin features.

TypeDescription
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.

TypeDescription
object
Controllers definition object

Example:

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.

TypeDescription
object
Routes definition object

Example:

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' }
    ];
  }
}