SDK
SDK Javascript v7.x
2

Read-only properties #

Property nameTypeDescription
authenticated
boolean
Returns true if the SDK holds a valid token
connected
boolean
Returns true if the SDK is currently connected to a Kuzzle server.
offlineQueue
object[]
Contains the queued requests during offline mode
protocol
Protocol
Protocol used by the SDK
events
string[]
List of every events emitted by the SDK

connected #

The connected property wraps the underlying protocol connected property. See the associated documentation:

Writable properties #

Property nameTypeDescription
authenticator
function
Authenticator function to authenticate the SDK. (After called, the jwt property of the SDK has to be set.)
autoQueue
boolean
If true, automatically queues all requests during offline mode
autoReplay
boolean
If true, automatically replays queued requests on a reconnected event
autoResubscribe
boolean
If true, automatically renews all subscriptions on a reconnected event
jwt
string
Authentication token
offlineQueueLoader
function
Called before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queue
queueFilter
function
Custom function called during offline mode to filter queued requests on-the-fly
queueMaxSize
number
Number of maximum requests kept during offline mode
queueTTL
number
Time a queued request is kept during offline mode, in milliseconds
replayInterval
number
Delay between each replayed requests
volatile
object
Common volatile data, will be sent to all future requests

authenticator #

The authenticator property can be set to a function returning a promise.

This function will be called after a successful reconnection if the current authentication token is not valid anymore.

This function has to authenticate the SDK. It can be a call to auth.login for example.

kuzzle.authenticator = async () => {
  await kuzzle.auth.login('local', { username: 'user', password: 'pass' });
}

If the authenticator function fail to authenticate the SDK, then the reconnected event is never emitted and a reconnectionError event is emitted.

offlineQueueLoader #

The offlineQueueLoader property must be set with a function of one of the following formats:

Object[] offlineQueueLoader()

Promise<Object[]> offlineQueueLoader()

The returned (or resolved) array must contain objects, each with the following properties:

PropertyTypeDescription
query
object
Object representing the request that is about to be sent to Kuzzle, following the Kuzzle API format
reject
function
A Promise.reject function
resolve
function
A Promise.resolve function

queueFilter #

The queueFilter property must be set with a function of the following form:

boolean queueFilter(request)

The request argument is an object representing the request that is about to be sent to Kuzzle, following the Kuzzle API format.

queueMaxSize #

This property defines the size of the offline buffer, which is a first-in first-out (FIFO) queue.

This means that if the queueMaxSize limit is reached, older requests are discarded to make room for newer requests.

If queueMaxSize is set to a number lower than, or equal to 0, then an unlimited number of requests is kept in the offline buffer. Note that doing so may lead to a crash due to memory saturation, if there are too many requests held in memory.

queueTTL #

If the queueTTL property is set to a number lower than, or equal to 0, then requests never expire and are kept indefinitely.

volatile #

Multiple methods allow passing specific volatile data.

These volatile data will be merged with the global Kuzzle volatile object when sending the request, with the request specific volatile taking priority over the global ones.