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}.`);
}
}| Key | Default | What it does |
|---|---|---|
name | Required | The listener name. |
event | Required | The event to listen for. |
once | false | Stop listening after the first time. |
A listener that throws is logged and does not stop the others.
Events
| Event | Payload | When |
|---|---|---|
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.recorded | The entry | Something is added to the audit log. |
module.registered | The module | A module is registered. |
module.loaded | The module | A module finishes loading. |
module.failed | The module | A module fails to load. |
module.toggled | { id, enabled } | A module is turned on or off. |
module.deloaded | The module | A module is unloaded. |
modules.ready | Every module has loaded. | |
kora.ready | Kora 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.