Official Plugins (Kuzzle v2.x)
Device Manager v0.x
2

validate #

Validate the payload format before processing.

This method must throw an error if the payload is not valid.

Copied to clipboard!
validate (payload: JSONObject, request: KuzzleRequest): Promise<void> | never

Arguments Type Description
payload
JSONObject
Raw payload received in the API action body
request
KuzzleRequest
Original request

Returns #

Returns a promise resolving if the payload is valid.

Usage #

Considering the following payload:

Copied to clipboard!
{
  deviceEUI: '12345',
  register55: 23.3,
  batteryLevel: 0.8,
}

The following validate method could be implemented:

Copied to clipboard!
import { JSONObject, KuzzleRequest, BadRequestError } from 'kuzzle';
import { Decoder } from 'kuzzle-plugin-device-manager';

class KarakoyDecoder extends Decoder {
  // [...]
  async validate (payload: JSONObject, request: KuzzleRequest): Promise<void> | never {
    if (typeof payload.deviceEUI !== 'string') {
      throw new BadRequestError('Missing "deviceEUI" property');
    }
  }
}