Skip to main content
Version: 3.2.1

Events

Introduction

You can subscribe to different events the SDK publishes during it's lifecycle. This way, you can plug in your own logic at these different points.

info

Events emitted by the SDK are scoped to the instance on which the eventEmitter object is configured. There is no possiblilty of naming collision with global events, or even with the same event subscribed on multiple SDK instances.

Subscribing to events

Lifecycle

eventEmitter.on('ready')

Fired when the SDK finishes initialization by authorizing the client. This event is not fired if the credentials provided are incorrect.

mySDKInstance.eventEmitter.on('ready', (data) => {
/**
* data:
* deploymentId: number;
*/
});

eventEmitter.on('did-load-integrations')

Fired when the SDK successfully fetches the list of integrations associated with the configured deployment.

mySDKInstance.eventEmitter.on('did-load-integrations', (data) => {
console.log('These integrations were loaded: ', data);
});

eventEmitter.on('did-load-flows')

Fired when the SDK successfully fetches the list of guided flows associated with the configured deployment.

mySDKInstance.eventEmitter.on('did-load-flows', (data) => {
console.log('These flows were loaded: ', data);
});

eventEmitter.on('should-load-flow')

Fired when the user attempts to set up a flow in the DETACHED rendering mode.

mySDKInstance.eventEmitter.on('should-load-flow') => {
Spinner.show();
});

eventEmitter.on('did-load-flow')

Fired when the SDK successfully fetches the data associated with a flow.

mySDKInstance.eventEmitter.on('did-load-flow', (data) => {
console.log(`This Flow is named: ${data.templateTitle}!`);
/**
* data:
* flowId: string;
* flowTitle: number;
* flowDescription: string;
*/
});

Integration Creation

eventEmitter.on('did-save-integration')

Fired when an integration is saved successfully.

mySDKInstance.eventEmitter.on('did-save-integration', (data) => {
console.log(`Hey, we set up integration ${data.integrationId} successfully!`);
/**
* data:
* flowId: number;
* integrationId: number;
*/
});

eventEmitter.on('did-delete-integration')

Fired when an integration is deleted successfully.

mySDKInstance.eventEmitter.on('did-delete-integration', (data) => {
console.log(
`Hey, we deleted integration ${data.integrationId} successfully!`,
);
/**
* data:
* flowId: number;
* integrationId: number;
*/
});

Authorization

eventEmitter.on('did-add-authorization')

Fired when an authorization is added successfully in the flow setup form. You can use the alreadyExists key to check if a user is adding a previously connected account again.

mySDKInstance.eventEmitter.on('did-add-authorization', (data) => {
/**
* data:
* identity: string;
* authorizationId: number;
* flowId: number;
* alreadyExists: boolean;
*/
});

eventEmitter.on('did-remove-authorization')

Fired when an authorization is deleted in the flow setup form.

mySDKInstance.eventEmitter.on('did-remove-authorization', (data) => {
/**
* data:
* authorizationId: number;
*/
});

eventEmitter.on('did-select-authorization')

Fired when an authorization is selected in an integration authorization selection step.

mySDKInstance.eventEmitter.on('did-select-authorization', (data) => {
/**
* data:
* authorizationId: number;
*/
});

Unsubscribing from events

It is easy to un-subscribe from a subscribe event. Just use the unsub method on the eventEmitter object that is available on every SDK instance.

function flowLoadCallback(data: CallbackData) {
console.log(`This flow has ${data.steps.length} steps!`);
}
// subscribe
mySDKInstance.eventEmitter.on('did-load-flow', flowLoadCallback);

// unsubscribe
mySDKInstance.eventEmitter.unsub('did-load-flow', flowLoadCallback);