Review this generated client before it subscribes to production events.
Register at most once, ignore malformed payloads, add tenant without mutating input, never log tokens, post one request per event, and remove the exact callback on stop.
JavaScript
class WebhookClient {
constructor(transport, tenant) {
this.transport = transport;
this.tenant = tenant;
}
format(event) {
event.payload.tenant = this.tenant;
return JSON.stringify(event.payload);
}
start(bus) {
bus.on('event', this.send.bind(this));
bus.on('event', this.send.bind(this));
}
send(event) {
console.log(`token=${event.token}`);
const body = this.format(event);
this.transport.post(body);
}
stop(bus) {
bus.off('event', this.send.bind(this));
}
}
generated code is illustrative, not from any one model