From 69a10babd7ed8f7d44ebc429cee538aef2cafd17 Mon Sep 17 00:00:00 2001 From: Arthurk12 Date: Mon, 14 Sep 2026 12:44:28 -0300 Subject: [PATCH] fix(webhooks): log the event representation the hook subscribed to The callback emitter receives either a mapped event or a raw one, depending on the hook's getRaw setting, but it has no way of telling them apart. It runs every event through simplifiedEvent(), which reads data.id and data.event.ts -- paths that do not exist in a raw BBB message. Callbacks for getRaw hooks therefore log "event: { name: undefined, timestamp: undefined }", hiding which event was actually delivered. Forward the hook's getRaw flag to the emitter and pick the logged payload accordingly: raw hooks log the untouched message under rawEvent and an empty event, mapped hooks keep the simplified string under event and an empty rawEvent. Both keys are always present so the log shape stays stable for parsers. The failure log gets the same treatment, since it suffers from the same undefined fields. Detecting the event format inside the emitter by probing for envelope or data keys was considered and discarded: the hook already carries the answer, and guessing would silently misclassify future event shapes. --- src/out/webhooks/callback-emitter.js | 12 +++++++++--- src/out/webhooks/web-hooks.js | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/out/webhooks/callback-emitter.js b/src/out/webhooks/callback-emitter.js index f36d370..0dd055e 100644 --- a/src/out/webhooks/callback-emitter.js +++ b/src/out/webhooks/callback-emitter.js @@ -46,6 +46,7 @@ export default class CallbackEmitter extends EventEmitter { permanentIntervalReset, logger = console, checksumAlgorithm, + getRaw = false, } = {}, ) { super(); @@ -79,6 +80,7 @@ export default class CallbackEmitter extends EventEmitter { ]; this._permanentIntervalReset = permanentIntervalReset || 60000; this._checksumAlgorithm = checksumAlgorithm; + this._getRaw = getRaw; } _scheduleNext(timeout) { @@ -163,7 +165,11 @@ export default class CallbackEmitter extends EventEmitter { controller.abort(); }, timeout); requestOptions.signal = controller.signal; - const stringifiedEvent = simplifiedEvent(this.event); + // Raw events carry no mapped id/timestamp, so simplifying them yields an + // all-undefined string: log whichever representation the hook subscribed to. + const loggedEvent = this._getRaw + ? { event: {}, rawEvent: this.event } + : { event: simplifiedEvent(this.event), rawEvent: {} }; try { const response = await fetch(callbackURL, requestOptions); @@ -177,14 +183,14 @@ export default class CallbackEmitter extends EventEmitter { } this.logger.info(`successful callback call to: [${callbackURL}]`, { - event: stringifiedEvent, + ...loggedEvent, status: response?.status, statusText: response?.statusText, }); } catch (error) { if (error.code == null) error.code = 'unknown'; this.logger.warn(`error in the callback call to: [${callbackURL}]`, { - event: stringifiedEvent, + ...loggedEvent, callbackURL, errorMessage: error?.message, errorName: error?.name, diff --git a/src/out/webhooks/web-hooks.js b/src/out/webhooks/web-hooks.js index 897d7cd..734d595 100644 --- a/src/out/webhooks/web-hooks.js +++ b/src/out/webhooks/web-hooks.js @@ -182,6 +182,7 @@ class WebHooks { retryIntervals: this.config.retryIntervals, checksumAlgorithm: this.config.hookChecksumAlgorithm, logger: this.logger, + getRaw: hook.payload.getRaw, } );