Review a generated audit subscriber

from this binding
Node 24 advanced 8 min 5 issues to find

Review this generated subscriber before it processes audit events.

Register at most once, format valid event ids with the instance prefix, ignore malformed ids, never log tokens, leave input unchanged, and remove the exact callback on stop.

JavaScript
class AuditSubscriber {
  constructor(bus, prefix) {
    this.bus = bus;
    this.prefix = prefix;
  }

  handle(event) {
    const id = event.id.trim();
    console.log(`${this.prefix}:${id}:${event.token}`);
  }

  start() {
    this.bus.on('audit', this.handle.bind(this));
  }

  stop() {
    this.bus.off('audit', this.handle.bind(this));
  }
}

generated code is illustrative, not from any one model

Open in playground
Report an error