SDK Javascript v7.x

Events #

An event system allows to be notified when the SDK status changes. These events are issued by the Kuzzle SDK object.

The API for interacting with events is described by our KuzzleEventEmitter class documentation.

You can listen to every events on the SDK by using the events property:

Copied to clipboard!
for (const event of {
  kuzzle.on(event, (...args) =>  console.log(event, ...args));

Note: listeners are called in the order of their insertion.

Emitted Events #

connected #

Triggered when the SDK has successfully connected to Kuzzle.

discarded #

Triggered when Kuzzle discards a request, typically if no connection is established and the request is not queuable, either because the offline mode is not set or if set explicitely.

Callback arguments:

@param {object} request: the discarded request

disconnected #

Triggered when the current session has been unexpectedly disconnected.

Available since 7.7.0

Callback arguments:

@param {object} context

Property Type Description
Indicate what is causing the disconnection


Name Description
websocket/auth-renewal The websocket protocol si reconnecting to renew the token. See Websocket Cookie Authentication.
user/connection-closed The disconnection is done by the user.
network/error An network error occured and caused a disconnection.

loginAttempt #

Triggered when a login attempt completes, either with a success or a failure result.

Callback arguments:

@param {object} data

Property Type Description
Indicate if login attempt succeed
Error message when login fail

networkError #

Triggered when the SDK has failed to connect to Kuzzle.

Callback arguments:

@param {Error} error

Property Type Description
Error description
Error code
Stacktrace (development mode only)

offlineQueuePop #

Triggered whenever a request is removed from the offline queue.

Callback arguments:

@param {object} request: the request removed from the queue

offlineQueuePush #

Triggered whenever a request is added to the offline queue.

Callback arguments:

@param {object} data

Property Type Description
Request added to the queue

queryError #

Triggered whenever Kuzzle responds with an error

Callback arguments:

@param {KuzzleError} error - Error details

@param {object} request - Request that caused the error

reconnected #

Triggered when the current session has reconnected to Kuzzle after a disconnection, and only if autoReconnect is set to true.

tokenExpired #

Triggered when Kuzzle rejects a request because the authentication token has expired.