Kora/developer documentation/Events

Events

Run code when licenses, products, customers or modules change.

An event class listens for one event on this.kora.events. Put them in src/events/.

modules/example/src/events/licenseCreated.js
import { Events } from "#kora/modules";

export class LicenseCreated extends Events {
    constructor(kora) {
        super(kora, { name: "licenseCreated", event: "license.created" });
    }

    async run({ license }) {
        this.kora.console.log(this.kora.console.levels.info, `New license ${license.key} for ${license.customer_name}.`);
    }
}
KeyDefaultWhat it does
nameRequiredThe listener name.
eventRequiredThe event to listen for.
oncefalseStop listening after the first time.

A listener that throws is logged and does not stop the others.

Events

EventPayloadWhen
license.created{ license, input }A license is issued.
license.updated{ license, input }A license is edited.
license.removed{ license }A license is deleted.
license.validated{ body, result, ip }A key is checked, activated or tested.
license.deactivated{ license, removed, ip }A product frees a device seat through POST /api/v1/licenses/deactivate.
license.activated{ license, values }Activation took new seats for the values in values.
product.created{ product, input }A product is created.
product.updated{ product, input }A product is edited.
product.removed{ product }A product is deleted.
customer.created{ customer, input }A customer is created.
customer.updated{ customer, input }A customer is edited.
customer.removed{ customer }A customer is deleted.
customer.merged{ customer, duplicate }A duplicate is merged into customer and deleted. Move any rows your module keeps for duplicate.id.
config.saved{ module, group, values }A module's settings are saved.
audit.recordedThe entrySomething is added to the audit log.
module.registeredThe moduleA module is registered.
module.loadedThe moduleA module finishes loading.
module.failedThe moduleA module fails to load.
module.toggled{ id, enabled }A module is turned on or off.
module.deloadedThe moduleA module is unloaded.
modules.readyEvery module has loaded.
kora.readyKora has finished starting.

Firing Your Own

From a handler:

this.emit("example.synced", { count });
await this.emitAsync("example.synced", { count });

emitAsync waits for every listener to finish. Prefix event names with your module ID.