Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(audit): audit the Baileys spelling of a remote unlink too
Yudhi Armyndharis855cdbb322ef
diff --git a/src/modules/session/session-engine-lifecycle.service.ts b/src/modules/session/session-engine-lifecycle.service.tsindex cf75c7651..9ab70fbe9 100644--- a/src/modules/session/session-engine-lifecycle.service.ts+++ b/src/modules/session/session-engine-lifecycle.service.ts@@ -124,10 +124,15 @@ function isAuthTimeoutRejection(err: unknown): boolean {** Deliberately not CONFLICT (another device took over, and takeover is recoverable), not* DEPRECATED_VERSION (our own client is too old), and not TIMEOUT (a fault, and the single most- * common reconnect-storm reason). Mirrors how the whatsapp-web.js adapter classifies the same- * states; the Baileys adapter reports its own logout through the same callback.+ * common reconnect-storm reason). The first three mirror how the whatsapp-web.js adapter classifies+ * the same states.+ *+ * BOTH engines are covered, and they spell it differently: `'logged out'` is the only reason the+ * Baileys adapter ever passes to this callback, emitted for a WhatsApp-originated loggedOut (401)+ * close — the same event, so it must audit the same way. Baileys' other two terminal closes (403+ * forbidden, 440 connectionReplaced) report through onError instead and are not unlinks.*/-const TERMINAL_UNLINK_REASONS = new Set(['LOGOUT', 'UNPAIRED', 'UNPAIRED_IDLE']);+const TERMINAL_UNLINK_REASONS = new Set(['LOGOUT', 'UNPAIRED', 'UNPAIRED_IDLE', 'logged out']);/*** Owns the live WhatsApp engines and every state machine around them: start/stop/logout/forceKill,diff --git a/src/modules/session/session.service.spec.ts b/src/modules/session/session.service.spec.tsindex 935cf0c95..6bad3fc67 100644--- a/src/modules/session/session.service.spec.ts+++ b/src/modules/session/session.service.spec.ts@@ -2648,7 +2648,11 @@ describe('SessionService', () => {await new Promise(resolve => setImmediate(resolve));};- it.each(['LOGOUT', 'UNPAIRED', 'UNPAIRED_IDLE'])(+ // 'logged out' is the Baileys spelling: baileys-lifecycle reports a WhatsApp-originated+ // loggedOut (401) close through this same callback with that exact string, and it is the ONLY+ // reason that adapter ever passes here. Without it the audit row would exist for whatsapp-web.js+ // sessions and silently not for Baileys ones — the engine asymmetry this test exists to prevent.+ it.each(['LOGOUT', 'UNPAIRED', 'UNPAIRED_IDLE', 'logged out'])('writes a durable audit record for a terminal unlink (%s)',async reason => {const callbacks = await startAndCapture();