import { JSONObject } from "kuzzle-sdk"; import { PluginContext } from "../core/plugin/pluginContext"; import { ControllerDefinition } from "./controllers/ControllerDefinition"; import { PluginManifest } from "./PluginManifest"; import { StrategyDefinition } from "./StrategyDefinition"; import { PipeEventHandler, HookEventHandler } from "./EventHandler"; import { ImportConfig } from "./Kuzzle"; /** * Allows to define plugins controllers and actions */ export type PluginApiDefinition = { /** * Name of the API controller. */ [controller: string]: ControllerDefinition; }; /** * Allows to define hooks on events */ export type PluginHookDefinition = { /** * Event name or wildcard event. */ [event: string]: HookEventHandler | HookEventHandler[]; }; /** * Allows to define pipes on events */ export type PluginPipeDefinition = { /** * Event name or wildcard event. */ [event: string]: PipeEventHandler | PipeEventHandler[]; }; /** * Plugins must implements this abstract class. */ export declare abstract class Plugin { _manifest: PluginManifest; /** * Plugin context. */ context: PluginContext; /** * Plugin config. */ config: JSONObject; /** * Define new API controllers. * * @example * * this.api = { * email: { * actions: { * send: { * handler: async request => ..., * http: [{ verb: 'post', path: '/email/send' }] * } * } * } * } */ api?: PluginApiDefinition; /** * Define hooks on Kuzzle events. * * @see https://docs.kuzzle.io/core/2/plugins/guides/hooks/ * * @example * * this.hooks = { * 'security:afterCreateUser': async (request: Request) => ... * } */ hooks?: PluginHookDefinition; /** * Define pipes on Kuzzle events. * * @see https://docs.kuzzle.io/core/2/guides/write-plugins/4-old-guides/pipes * * @example * * this.pipes = { * 'document:afterCreate': async (request: Request) => ... * } */ pipes?: PluginPipeDefinition; /** * Define authenticator classes used by strategies. * * @see https://docs.kuzzle.io/core/2/plugins/guides/strategies/overview */ authenticators?: { /** * The key is the authenticator name and the value is the class. */ [name: string]: any; }; /** * Define authentications strategies. * * @see https://docs.kuzzle.io/core/2/plugins/guides/strategies/overview */ strategies?: StrategyDefinition; /** * Define default imports */ imports?: ImportConfig; /** * Plugin initialization method. * * Will be called during plugin initialization before Kuzzle starts to serve * requests. * * @see https://docs.kuzzle.io/core/2/plugins/guides/manual-setup/init-function/ */ abstract init(config: JSONObject, context: PluginContext): Promise | any; /** * @param manifest Manifest containing the required kuzzleVersion number */ constructor(manifest: PluginManifest); }