Prism/developer documentation/Events

Events

Run code when products, purchases, settings or modules change.

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

modules/example/src/events/checkoutFulfilled.js
import { Events } from "#prism/modules";

export class CheckoutFulfilledEvent extends Events {
    constructor(prism) {
        super(prism, { name: "checkoutFulfilled", event: "checkout.fulfilled" });
    }

    async run({ customerEmail, items, licenses }) {
        this.prism.console.log(this.prism.console.levels.info, `${customerEmail} bought ${items.length} items.`);
    }
}
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
product.created{ product, input }A product is created.
product.updated{ product, input }A product is edited.
product.removed{ product }A product is deleted.
checkout.fulfilled{ customerEmail, customerId, customerName, customerDiscord, items, licenses }A purchase is paid and its licenses are issued.
purchase.completedThe sameFired right after checkout.fulfilled.
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>.readyThe moduleThe same, named after the module, such as core.ready.
module.failed{ folder, module, error }A module fails to load.
module.toggled{ id, enabled }A module is turned on or off.
module.deloadedThe moduleA module is unloaded.
<module>.shutdownThe moduleThe same, named after the module.
modules.readyThe loaded modulesEvery module has loaded.
prism.readyPrism has finished starting.

In checkout.fulfilled, items holds { productId, quantity, addons } for each product bought, and licenses holds only newly issued licenses. Addons added to an existing license are in items but not licenses.

Purchase Webhook

To send purchases to another service without a module, set webhookUrl and webhookSecret in the CHECKOUT setting through POST /api/settings. Prism posts { event: "checkout.fulfilled", ...payload, timestamp } to the URL after each purchase, with an x-prism-signature header holding the HMAC-SHA256 of the body using the secret, in hex.

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.