Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(hooks): correct the reachability claim on the gate's undefined branch
Yudhi Armyndharis9abf5ca2fba7
diff --git a/src/core/hooks/sending-gate.spec.ts b/src/core/hooks/sending-gate.spec.tsindex 8bdce4a1e..31f42f694 100644--- a/src/core/hooks/sending-gate.spec.ts+++ b/src/core/hooks/sending-gate.spec.ts@@ -26,6 +26,10 @@ describe('applySendingGate', () => {await expect(gate({ continue: true, data: { input: rewritten } })).resolves.toEqual(rewritten);});+ // A stub manager, deliberately: HookManager itself always answers with an envelope (runHandlers+ // returns the data it was given when no handler is registered), so this branch is defensive rather+ // than a path production reaches. Pinned anyway — it is what stops a manager that answers with+ // nothing from being read as a veto.it('returns the original input when the chain replies with no data at all', async () => {await expect(gate({ continue: true })).resolves.toEqual(dto);});diff --git a/src/core/hooks/sending-gate.ts b/src/core/hooks/sending-gate.tsindex daef22d4d..c40dddfe8 100644--- a/src/core/hooks/sending-gate.ts+++ b/src/core/hooks/sending-gate.ts@@ -44,9 +44,12 @@ export async function applySendingGate<T extends object>(if (!shouldContinue) {throw new BadRequestException('Message sending blocked by plugin');}- // No data at all means nothing in the chain rewrote the input, so keep the caller's own. This- // covers both the ordinary no-plugin path and a handler that deliberately returned nothing;- // neither is a malformed reply.+ // Defensive, and unreachable through HookManager: `runHandlers` returns `{ continue: true, data }`+ // with the envelope it was given when no handler is registered, and only replaces it when a+ // handler returns `data !== undefined` — so neither the no-plugin path nor a handler that returns+ // nothing produces `undefined` here. It stays because "the manager returned no data" is not+ // evidence a plugin wanted this send stopped, so the safe reading is the caller's own input; the+ // fail-CLOSED rule below applies to a reply that IS present and cannot be read.if (hookData === undefined) {return input;}