sdk

Available since 1.6.0

Accessor to the embedded SDK.

The embedded SDK is a custom version of our Javascript SDK that uses a custom protocol plugged directly into Kuzzle core.

All the documented controllers can be used, except the realtime one. Also, the low-level query method is available for use.

The embedded SDK methods do not trigger API events or request:on* events.

Request context

By default, when using the embedded SDK, requests made to Kuzzle API don't have the same context as the original request received by the plugin.

Typically, the request.context.user property is not set and thus Kuzzle metadata will not be set when creating or updating documents.

It is possible to use the same user context as the original request with the embedded SDK, for this purpose it is necessary to use the as() impersonation method.

When the complete original context is needed to execute your request, plugin developers can use the accessors.execute method.


controllers

The following controllers are available in the embedded SDK:

Available since 1.9.1

The following controllers and methods are partially available in the embedded SDK:

Example

Copied to clipboard!
async myAwesomePipe (request) {
  await this.context.accessors.sdk.document.create(
    'nyc-open-data',
    'yellow-taxi',
    { licence: 'B' }
  );

  return request;
}

Notes:

  • The created document will have the author metadata property set to null.

query

Available since 1.6.0

Accessor to the query method. This can be useful to call plugins custom controller action.

Example

Copied to clipboard!
async myAwesomePipe (request) {
  await this.context.accessors.sdk.query({
    controller: 'custom-plugin/derbyController',
    action: 'play',
    body: {
      type: 'roller',
      playerIds: [21, 42, 84]
    }
  });

  return request;
}

as

Available since 1.7.0

Execute the following query as the original request user.

Arguments

Copied to clipboard!
as(user);

Arguments Type Description
user
User
Valid User object

Example

Copied to clipboard!
async myAwesomePipe (request) {
  await this.context.accessors.sdk.as(request.context.user).document.create(
    'nyc-open-data',
    'yellow-taxi',
    { licence: 'B' }
  );

  return request;
}

Notes:

  • The created document will have the author metadata property set to the impersonated user ID.

Return

Returns the embedded SDK contextualized with the provided user.