Core
Framework v2.x
2

PluginContext #

The PluginContext class is passed to the plugins as an argument of the init method.

It contains various accessors, constructors and helpers that allow to interact with Kuzzle.

accessors #

This property is an instance of the PluginContextAccessors and contains various methods to interact with Kuzzle.

TypeDescription
PluginContextAccessors
PluginContextAccessors instance

constructors #

This property is an instance of the PluginContextConstructors and contains various constructors to interact with Kuzzle.

TypeDescription
PluginContextConstructors
PluginContextConstructors instance

errors #

Deprecated since 2.8.0

This property contains constructors that represent Kuzzle Errors Types.

The usage of this property is deprecated and Kuzzle Errors should be required from the kuzzle package instead.

This property is not available in Typescript.

Available errors:

BadRequestError
ExternalServiceError
ForbiddenError
GatewayTimeoutError
InternalError
KuzzleError
NotFoundError
PartialError
PluginImplementationError
PreconditionError
ServiceUnavailableError
SizeLimitError
TooManyRequestsError
UnauthorizedError

config #

A frozen copy of the whole Kuzzle configuration.

TypeDescription
JSONObject
Kuzzle configuration (read-only)

errorsManager #

Deprecated since 2.8.0

Alias of kerror. Use kerror instead.

kerror #

Errors manager bound to the plugin domain and to a subdomain named after the plugin. It creates the errors declared in the errors section of the plugin's manifest.json.

TypeDescription
any
Errors manager

It exposes the following methods:

MethodDescription
get(name: string, ...placeholders): KuzzleErrorReturns the error defined under name
getFrom(source: Error, name: string, ...placeholders): KuzzleErrorSame as get, keeping the stack trace of source
reject(name: string, ...placeholders): Promise<never>Returns a promise rejected with the error

Usage #

throw context.kerror.get('some_error', 'placeholder value');

log #

Deprecated since 2.48.0

Kept for backward compatibility only: use logger instead.

A plain object with the debug, error, info, silly, verbose and warn methods. Each one takes a single message and forwards it to logger, prefixed with [<plugin name>]. silly and verbose log with the trace level.

TypeDescription
JSONObject
Backward-compatible logging methods

logger #

Available since 2.48.0

A child of the Kuzzle logger, with the plugin name as namespace.

It has the trace, debug, info, warn, error, fatal, flush and child methods, and the level property, of the Logger class. It does not have getLevel, setLevel, silly or verbose.

TypeDescription
KuzzleLogger
Plugin logger (KuzzleLogger from the kuzzle-logger package)

Usage #

context.logger.info('Plugin initialized');

secrets #

This property contains the application secrets that have been made available with the Secrets Vault.

TypeDescription
JSONObject
Decrypted application secrets