Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

refactor(engine): remove unused adapter members

Yudhi Armyndharis261defce5461
diff --git a/src/engine/adapters/baileys-events.ts b/src/engine/adapters/baileys-events.ts
index a4b0f7a28..1ed0765e5 100644
--- a/src/engine/adapters/baileys-events.ts
+++ b/src/engine/adapters/baileys-events.ts
@@ -463,9 +463,11 @@ export class BaileysEvents {
// Throttle through the limiter so a burst of media messages can't run unbounded parallel
// downloads (each a full decrypted buffer in heap). Ordering stays correct — the message store
// keeps the newest by timestamp. The queue is unbounded, so a burst parks rather than shedding
- // and the message keeps its media either way. The catch below is the teardown path: the
- // limiter rejects only when it has been closed, since processInboundMessage handles its own
- // failures (a media download that fails emits the omitted marker rather than throwing).
+ // and the message keeps its media either way. Nothing rejects here today: the limiter is never
+ // closed, and processInboundMessage handles its own failures (a media download that fails emits
+ // the omitted marker rather than throwing). The catch below is a net for the day something does,
+ // a closed or bounded limiter, so the message is still emitted rather than lost to an unhandled
+ // rejection.
const generation = this.storeGeneration;
// Where the session holds a message until its row is written (PostgreSQL), admit it now, in
// arrival order: its chat's order, and a slot of the session's room when it downloads media.
@@ -473,12 +475,9 @@ export class BaileysEvents {
const processed = this.host.inboundLimiter
.run(yieldSlot => this.processInboundMessage(msg, { generation, ticket, yieldSlot }))
.catch((error: unknown) => {
- // Only one failure can actually land here today: the limiter closing, an orderly teardown.
- // Its queue is unbounded so it never sheds, and processInboundMessage swallows its own
- // errors, so nothing else rejects. The other arm is defence in depth against a rejection
- // shape that does not exist yet, and it names the error rather than calling it
- // "saturated", which used to send operators to look at concurrency settings for a problem
- // that was never there. The retry below cannot reject either, for the same reason.
+ // Names the failure rather than calling it "saturated", which used to send operators to look
+ // at concurrency settings for a problem that was never there. The retry below skips the
+ // limiter and processInboundMessage handles its own errors, so it cannot reject.
const closed = error instanceof Error && error.message.startsWith('ConcurrencyLimiter closed');
this.host.logger.warn(
closed
diff --git a/src/engine/adapters/inbound-hold.spec.ts b/src/engine/adapters/inbound-hold.spec.ts
index 814e990f4..08b76604a 100644
--- a/src/engine/adapters/inbound-hold.spec.ts
+++ b/src/engine/adapters/inbound-hold.spec.ts
@@ -7,6 +7,7 @@ import type { WAMessage, WASocket } from '@whiskeysockets/baileys';
import { BaileysEvents, type BaileysEventsHost } from './baileys-events';
import { WhatsAppWebJsAdapter } from './whatsapp-web-js.adapter';
import { plannedInboundDownload } from './wwebjs-messaging';
+import type { WwebjsLifecycle } from './wwebjs-lifecycle';
import { ConcurrencyLimiter } from '../../common/utils/concurrency-limiter';
import { createLogger } from '../../common/services/logger.service';
import { EngineRegistry } from '../engine-registry.service';
@@ -1153,7 +1154,7 @@ describe('whatsapp-web.js inbound messages held for storage', () => {
});
(adapter as unknown as { client: unknown }).client = client;
(adapter as unknown as { callbacks: unknown }).callbacks = callbacks;
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { adapter, client };
};
const incoming = (id: string, from: string, page?: jest.Mock, body = '') => ({
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
index e32bada73..bec83a973 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts
@@ -1,28 +1,32 @@
import { Client, MessageMedia, WAState } from 'whatsapp-web.js';
import { EventEmitter } from 'events';
+import { WhatsAppWebJsAdapter } from './whatsapp-web-js.adapter';
+import { extractLinkedParentJID } from './wwebjs-groups';
import {
- WhatsAppWebJsAdapter,
- extractLinkedParentJID,
+ downloadMediaInPage,
isHttpUrl,
- isSupportedProxyUrl,
- isExecutionContextDestroyedError,
- buildProxyLaunchConfig,
loadRemoteMedia,
+ extractWwebjsCall,
+ wwebjsAckToDeliveryStatus,
+} from './wwebjs-messaging';
+import { isSupportedProxyUrl, buildProxyLaunchConfig } from './wwebjs-proxy';
+import { LoggerService } from '../../common/services/logger.service';
+import {
+ resolveOnboardingContinueLabels,
probeOnboardingModal,
collectDialogDiagnostics,
- resolveAuthTimeoutMs,
- wwebjsAckToDeliveryStatus,
- extractWwebjsCall,
- READY_RECONCILE_TIMEOUT_MS,
- READY_RECONCILE_BRIDGE_RELOAD_GRACE_MS,
+ type WwebjsOnboardingWatcher,
+} from './wwebjs-onboarding';
+import {
+ isExecutionContextDestroyedError,
NAVIGATION_REINJECT_GRACE_MS,
NAVIGATION_EPISODE_CAP_MS,
-} from './whatsapp-web-js.adapter';
-import { downloadMediaInPage } from './wwebjs-messaging';
-import { LoggerService } from '../../common/services/logger.service';
-import { resolveOnboardingContinueLabels } from './wwebjs-onboarding';
+ type WwebjsLifecycle,
+} from './wwebjs-lifecycle';
+import { READY_RECONCILE_TIMEOUT_MS, READY_RECONCILE_BRIDGE_RELOAD_GRACE_MS } from './wwebjs-reconcile';
+import { type WwebjsCalls } from './wwebjs-calls';
import { getEffectiveWebVersionInfo, resolveWebVersionPin, __resetWebVersionCache } from '../wa-web-version';
-import { resolveEngineInitTimeoutMs } from '../engine-init-timeout';
+import { resolveAuthTimeoutMs, resolveEngineInitTimeoutMs } from '../engine-init-timeout';
import * as fs from 'fs';
import { createHash } from 'crypto';
import * as path from 'path';
@@ -1796,7 +1800,7 @@ describe('WhatsAppWebJsAdapter credential-teardown observation', () => {
const onCredentialTeardownStarted = jest.fn();
(adapter as unknown as { client: unknown }).client = client;
(adapter as unknown as { callbacks: unknown }).callbacks = { onCredentialTeardownStarted };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { client, onCredentialTeardownStarted };
};
@@ -1996,7 +2000,7 @@ describe('WhatsAppWebJsAdapter credential-teardown observation', () => {
onDisconnected,
onStateChanged,
};
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
(adapter as unknown as { tearingDown: boolean }).tearingDown = true;
client.emit('disconnected', 'LOGOUT');
@@ -2036,7 +2040,7 @@ describe('WhatsAppWebJsAdapter ready reconciliation (#251/#273)', () => {
(adapter as unknown as { client: unknown }).client = client;
(adapter as unknown as { callbacks: unknown }).callbacks = { onReady, onStateChanged };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { client, onReady, onStateChanged };
};
@@ -2704,7 +2708,7 @@ describe('WhatsAppWebJsAdapter ready reconciliation (#251/#273)', () => {
const pupPage = Object.assign(new EventEmitter(), { evaluate: jest.fn().mockResolvedValue(true) });
const { client } = attachFakeClient(adapter, { pupPage: pupPage as unknown as FakeClient['pupPage'] });
// The death listeners are armed by runInitAttempt, not by setupEventHandlers.
- (adapter as unknown as { attachPuppeteerLifecycleListeners: () => void }).attachPuppeteerLifecycleListeners();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.attachPuppeteerLifecycleListeners();
const qrDone = deferredVoid();
(adapter as unknown as { callbacks: { onQRCode: jest.Mock } }).callbacks.onQRCode = jest.fn(() => qrDone.resolve());
@@ -3122,7 +3126,7 @@ describe('WhatsAppWebJsAdapter ready reconciliation (#251/#273)', () => {
destroy: jest.fn().mockResolvedValue(undefined),
} as never);
(adapter as unknown as { lifecycle: { status: EngineStatus } }).lifecycle.status = EngineStatus.AUTHENTICATING;
- (adapter as unknown as { attachPuppeteerLifecycleListeners: () => void }).attachPuppeteerLifecycleListeners();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.attachPuppeteerLifecycleListeners();
const onDisconnected = jest.fn();
Object.assign((adapter as unknown as { callbacks: object }).callbacks, {
onDisconnected,
@@ -3665,7 +3669,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
(adapter as unknown as { client: unknown }).client = client;
const onMessage = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessage };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
const mockMsg = {
id: { _serialized: 'MEDIA_OFF_1' },
@@ -3711,7 +3715,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
(adapter as unknown as { client: unknown }).client = client;
const onMessage = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessage };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
const mockMsg = {
id: { _serialized: 'CALL_1' },
@@ -3753,7 +3757,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
(adapter as unknown as { client: unknown }).client = client;
const onMessageCreate = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageCreate };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
const mockMsg = {
id: { _serialized: 'OWN_MEDIA_1' },
@@ -3806,7 +3810,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
const onMessageCreate = jest.fn();
const admitInbound = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageCreate, admitInbound };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
client.emit('message_create', {
id: { _serialized: 'OWN_UNREADABLE_1' },
@@ -3844,7 +3848,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
(adapter as unknown as { client: unknown }).client = client;
const onMessageCreate = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageCreate };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
const mockMsg = {
id: { _serialized: 'OWN_STATUS_1' },
@@ -3888,7 +3892,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
(adapter as unknown as { client: unknown }).client = client;
const onMessageCreate = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageCreate };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
const mockMsg = {
id: { _serialized: 'OWN_MEDIA_2' },
@@ -3936,7 +3940,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()
(adapter as unknown as { client: unknown }).client = client;
const onMessage = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessage };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
const mockMsg = {
id: { _serialized: 'IN_MEDIA_FAIL_1' },
@@ -3982,7 +3986,7 @@ describe('WhatsAppWebJsAdapter message_reaction (id resolution across WA Web bui
(adapter as unknown as { client: unknown }).client = client;
const onMessageReaction = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageReaction };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { onMessageReaction, client };
};
@@ -4044,7 +4048,7 @@ describe('WhatsAppWebJsAdapter message_revoke_everyone (forwards the original de
(adapter as unknown as { client: unknown }).client = client;
const onMessageRevoked = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageRevoked };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { onMessageRevoked, client };
};
@@ -4123,7 +4127,7 @@ describe('WhatsAppWebJsAdapter message_edit', () => {
(adapter as unknown as { client: unknown }).client = client;
const onMessageEdited = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageEdited };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { onMessageEdited, client };
};
@@ -4188,7 +4192,7 @@ describe('WhatsAppWebJsAdapter group notifications (group_join / group_leave / g
(adapter as unknown as { client: unknown }).client = client;
const onGroupEvent = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onGroupEvent };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { onGroupEvent, client };
};
@@ -4490,7 +4494,7 @@ describe('WhatsAppWebJsAdapter call event + rejectCall', () => {
(adapter as unknown as { client: unknown }).client = client;
const onCall = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onCall };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { adapter, onCall, client };
};
@@ -4633,7 +4637,7 @@ describe('WhatsAppWebJsAdapter call event + rejectCall', () => {
it('teardown clears the ringing call cache', async () => {
const { adapter, client } = wireCallHandler();
client.emit('call', liveCall());
- const cache = (adapter as unknown as { liveCalls: Map<string, number> }).liveCalls;
+ const cache = (adapter as unknown as { calls: WwebjsCalls }).calls.liveCalls;
expect(cache.has('CALL1')).toBe(true);
await adapter.disconnect();
@@ -6260,7 +6264,7 @@ describe('WhatsAppWebJsAdapter message_ack (unreadable id)', () => {
(adapter as unknown as { client: unknown }).client = client;
const onMessageAck = jest.fn();
(adapter as unknown as { callbacks: unknown }).callbacks = { onMessageAck };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { onMessageAck, client };
};
@@ -6366,7 +6370,7 @@ describe('WhatsAppWebJsAdapter puppeteer death detection (browser/page silent de
(adapter as unknown as { callbacks: unknown }).callbacks = { onDisconnected };
(adapter as unknown as { status: EngineStatus }).status = overrides.status ?? EngineStatus.READY;
(adapter as unknown as { tearingDown: boolean }).tearingDown = overrides.tearingDown ?? false;
- (adapter as unknown as { attachPuppeteerLifecycleListeners: () => void }).attachPuppeteerLifecycleListeners();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.attachPuppeteerLifecycleListeners();
return { adapter, client, onDisconnected };
};
@@ -6549,8 +6553,8 @@ describe('WhatsAppWebJsAdapter navigation re-inject grace (#1081)', () => {
(adapter as unknown as { callbacks: unknown }).callbacks = {};
(adapter as unknown as { status: EngineStatus }).status = EngineStatus.READY;
// Mirror the real init order: event handlers first, puppeteer listeners after initialize().
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
- (adapter as unknown as { attachPuppeteerLifecycleListeners: () => void }).attachPuppeteerLifecycleListeners();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.attachPuppeteerLifecycleListeners();
return { adapter, client };
};
@@ -7979,7 +7983,7 @@ describe('WhatsAppWebJsAdapter honest outcomes (no phantom success)', () => {
const onStateChanged = jest.fn();
(adapter as unknown as { client: unknown }).client = client;
(adapter as unknown as { callbacks: unknown }).callbacks = { onActionRequired, onStateChanged };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
// Default: window.WWebJS present (reconcile probe) AND no modal (watcher ticks that aren't
// overridden). mockResolvedValueOnce in a test takes precedence for exactly the next call.
evaluate.mockResolvedValue(true);
@@ -8334,7 +8338,7 @@ describe('WhatsAppWebJsAdapter honest outcomes (no phantom success)', () => {
const logger = (adapter as unknown as { logger: { debug: (m: string, meta?: unknown) => void } }).logger;
const debugSpy = jest.spyOn(logger, 'debug').mockImplementation(() => undefined);
- (adapter as unknown as { reportActionRequired: (reason: string) => void }).reportActionRequired(
+ (adapter as unknown as { onboardingWatcher: WwebjsOnboardingWatcher }).onboardingWatcher.reportActionRequired(
'modal stuck after five clicks',
);
@@ -8816,7 +8820,7 @@ describe('WhatsAppWebJsAdapter account-restriction reporting', () => {
const onDisconnected = jest.fn();
(adapter as unknown as { client: unknown }).client = client;
(adapter as unknown as { callbacks: unknown }).callbacks = { onAccountRestriction, onDisconnected };
- (adapter as unknown as { setupEventHandlers: () => void }).setupEventHandlers();
+ (adapter as unknown as { lifecycle: WwebjsLifecycle }).lifecycle.setupEventHandlers();
return { client, onAccountRestriction, onDisconnected };
};
diff --git a/src/engine/adapters/whatsapp-web-js.adapter.ts b/src/engine/adapters/whatsapp-web-js.adapter.ts
index 0e1e84503..423d2045c 100644
--- a/src/engine/adapters/whatsapp-web-js.adapter.ts
+++ b/src/engine/adapters/whatsapp-web-js.adapter.ts
@@ -1,4 +1,3 @@
-import { EventEmitter } from 'events';
import { type Client, type Message } from 'whatsapp-web.js';
import {
CallLinkType,
@@ -36,7 +35,6 @@ import {
GroupJoinInfo,
} from '../interfaces/whatsapp-engine.interface';
import { EngineNotSupportedError } from '../../common/errors/engine-not-supported.error';
-import { resolveAuthTimeoutMs } from '../engine-init-timeout';
import { isChannelJid } from '../identity/wa-id';
import { LidMappingStore } from '../identity/lid-mapping-store.service';
import { createLogger } from '../../common/services/logger.service';
@@ -101,39 +99,7 @@ export interface WhatsAppWebJsConfig {
// status can import it without loading whatsapp-web.js (engine lazy-loading). The lifecycle delegate
// imports resolveWebVersionPin for use in initialize().
-// resolveAuthTimeoutMs now lives in ../engine-init-timeout, next to the outer init deadline derived
-// from it: that deadline is engine-agnostic, so deriving it here made the session lifecycle import
-// this adapter just to size a timeout. Re-exported because callers still reach it through the engine
-// they are configuring.
-export { resolveAuthTimeoutMs };
-
-// extractLinkedParentJID moved to ./wwebjs-groups with the group operations; re-exported because
-// existing callers (the adapter spec) still import it from here.
-export { extractLinkedParentJID } from './wwebjs-groups';
-
-// Messaging helpers moved to ./wwebjs-messaging with the messaging operations; re-exported because
-// existing callers (the adapter spec) still import them from here.
-export { isHttpUrl, loadRemoteMedia, extractWwebjsCall, wwebjsAckToDeliveryStatus } from './wwebjs-messaging';
-
-// Proxy launch helpers moved to ./wwebjs-proxy; re-exported because existing callers (the adapter
-// spec) still import them from here.
-export { isSupportedProxyUrl, buildProxyLaunchConfig } from './wwebjs-proxy';
-
-// The onboarding-modal probe moved to ./wwebjs-onboarding with its label resolution; re-exported
-// because existing callers (the adapter spec) still import it from here.
-export { probeOnboardingModal, collectDialogDiagnostics } from './wwebjs-onboarding';
-
-// Connection lifecycle moved to ./wwebjs-lifecycle (with the navigation re-inject constants) and the
-// readiness reconciliation to ./wwebjs-reconcile; re-exported because existing callers (the adapter
-// spec) still import them from here.
-export {
- isExecutionContextDestroyedError,
- NAVIGATION_REINJECT_GRACE_MS,
- NAVIGATION_EPISODE_CAP_MS,
-} from './wwebjs-lifecycle';
-export { READY_RECONCILE_TIMEOUT_MS, READY_RECONCILE_BRIDGE_RELOAD_GRACE_MS } from './wwebjs-reconcile';
-
-export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngine {
+export class WhatsAppWebJsAdapter implements IWhatsAppEngine {
private readonly logger = createLogger('WhatsAppWebJsAdapter');
// Bound concurrent inbound media downloads: each one holds the whole decrypted file in the browser
// page and, when within the cap, its base64 in Node, so an unbounded burst could stack many multi-MB
@@ -163,9 +129,8 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin
private readonly onboardingWatcher: WwebjsOnboardingWatcher;
// Connection-lifecycle state is owned by the lifecycle delegate (./wwebjs-lifecycle); these
- // accessors alias it by reference so the host closures below — and an unmodified spec poking
- // `adapter.client` / `adapter.status` / `adapter.tearingDown` / … through a cast — keep working
- // byte-identically. The live-call cache below is the same pattern for ./wwebjs-calls.
+ // accessors alias it by reference so the host closures below, and a spec poking `adapter.client`,
+ // `adapter.status` or `adapter.tearingDown` through a cast, all see the delegate's state.
private get client(): Client | null {
return this.lifecycle.client;
}
@@ -199,15 +164,8 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin
private set disconnectReported(value: boolean) {
this.lifecycle.disconnectReported = value;
}
- /** Ringing call ids and their expiry, owned by the calls delegate, which uses them to announce each
- * call once; lifecycle teardown clears them. The adapter keeps this alias for the spec, which reads
- * `adapter.liveCalls` through a cast. */
- private get liveCalls(): Map<string, number> {
- return this.calls.liveCalls;
- }
constructor(private readonly config: WhatsAppWebJsConfig) {
- super();
// API-surface clusters live in ./wwebjs-* delegates; the public methods below forward to them.
// The host is one object literal shared by every delegate, and closures (not a `this` reference)
// keep the delegates' surface exactly this narrow. Built in the constructor, not as a field
@@ -276,7 +234,6 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin
logger: this.logger,
config: this.config,
getCallbacks: () => this.callbacks,
- emitState: status => this.emit('stateChanged', status),
scheduleReadyReconcile: () => this.reconcile.scheduleReadyReconcile(),
clearReadyReconcile: () => this.reconcile.clearReadyReconcile(),
startOnboardingWatcher: () => this.onboardingWatcher.startOnboardingWatcher(),
@@ -448,14 +405,6 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin
return this.lifecycle.initialize();
}
- private setupEventHandlers(): void {
- this.lifecycle.setupEventHandlers();
- }
-
- private attachPuppeteerLifecycleListeners(): void {
- this.lifecycle.attachPuppeteerLifecycleListeners();
- }
-
private isPageTransportError(error: unknown): boolean {
return this.lifecycle.isPageTransportError(error);
}
@@ -512,10 +461,6 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin
return this.stuckAuth.clearLocalAuth();
}
- private reportActionRequired(reason: string): void {
- this.onboardingWatcher.reportActionRequired(reason);
- }
-
/**
* Register the message/group/call domain events on a freshly built client — the one seam the
* lifecycle's setupEventHandlers() uses for everything that is pure payload mapping. The
diff --git a/src/engine/adapters/wwebjs-call-hook-gate.spec.ts b/src/engine/adapters/wwebjs-call-hook-gate.spec.ts
index 830a6f429..a2510bfde 100644
--- a/src/engine/adapters/wwebjs-call-hook-gate.spec.ts
+++ b/src/engine/adapters/wwebjs-call-hook-gate.spec.ts
@@ -25,7 +25,6 @@ function makeLifecycle(): WwebjsLifecycle {
config: { sessionId: 'sess', sessionDataPath: './data' },
clearReadyReconcile: jest.fn(),
startOnboardingWatcher: jest.fn(),
- emitState: jest.fn(),
getCallbacks: () => ({}),
} as unknown as WwebjsLifecycleHost;
const lc = new WwebjsLifecycle(host);
diff --git a/src/engine/adapters/wwebjs-calls.ts b/src/engine/adapters/wwebjs-calls.ts
index 7a79d9f2d..e4f0491af 100644
--- a/src/engine/adapters/wwebjs-calls.ts
+++ b/src/engine/adapters/wwebjs-calls.ts
@@ -22,9 +22,7 @@ export class WwebjsCalls {
* covers the ringing window with margin without pinning dead calls for long. */
private static readonly LIVE_CALL_TTL_MS = 2 * 60_000;
- /** Expiry time of each ringing call, by call id. Public so the adapter's `liveCalls` alias keeps
- * working (the spec reads `adapter.liveCalls` through a cast) and lifecycle teardown can clear it
- * when the client goes away. */
+ /** Expiry time of each ringing call, by call id. Cleared when the client goes away (clearLiveCalls). */
readonly liveCalls = new Map<string, number>();
constructor(private readonly host: WwebjsCallsHost) {}
diff --git a/src/engine/adapters/wwebjs-lifecycle.ts b/src/engine/adapters/wwebjs-lifecycle.ts
index d51f59b4c..b0704c93a 100644
--- a/src/engine/adapters/wwebjs-lifecycle.ts
+++ b/src/engine/adapters/wwebjs-lifecycle.ts
@@ -169,15 +169,14 @@ const WA_STATE_RESTRICTIONS: Readonly<Record<string, AccountRestriction['kind']>
* Host surface for {@link WwebjsLifecycle}. The adapter keeps the public engine methods as thin
* forwarders and builds ONE object literal of these closures, so the delegate drives connection
* state only through the seams named here: the sibling delegates it coordinates (reconcile,
- * onboarding watcher, call cache, stuck-auth) and the adapter-owned event surface.
+ * onboarding watcher, call cache, stuck-auth) and the adapter-owned callbacks and domain-event
+ * registration.
*/
export interface WwebjsLifecycleHost {
readonly logger: ReturnType<typeof createLogger>;
readonly config: WhatsAppWebJsConfig;
/** Live callbacks bag — read per event, since initialize() installs it after delegates are built. */
getCallbacks(): EngineEventCallbacks;
- /** Re-emit a status transition on the adapter's EventEmitter (`stateChanged`). */
- emitState(status: EngineStatus): void;
/** Arm / disarm the post-authentication readiness reconciliation (./wwebjs-reconcile). */
scheduleReadyReconcile(): void;
clearReadyReconcile(): void;
@@ -920,9 +919,9 @@ export class WwebjsLifecycle {
void reportRunningWebBuild(page, this.host.logger, this.host.config.sessionId, this.requestedWebVersion);
}
- /** The single status-transition funnel: latches disconnectReported, fires the callback, re-emits
- * on the adapter's EventEmitter. Public because the sibling delegates (reconcile, stuck-auth,
- * onboarding watcher) drive transitions through their host slices. */
+ /** The single status-transition funnel: latches disconnectReported and fires the callback. Public
+ * because the sibling delegates (reconcile, stuck-auth, onboarding watcher) drive transitions
+ * through their host slices. */
setStatus(status: EngineStatus): void {
// Latch before anything observes the transition. The constructor's initial DISCONNECTED is a field
// initializer and never reaches here, so this only ever fires on a real transition — startup is
@@ -939,7 +938,6 @@ export class WwebjsLifecycle {
}
this.status = status;
this.host.getCallbacks().onStateChanged?.(status);
- this.host.emitState(status);
}
private beginClientTeardown(): Client | null {
diff --git a/src/engine/adapters/wwebjs-running-build-ready.spec.ts b/src/engine/adapters/wwebjs-running-build-ready.spec.ts
index 297465b65..ec47a4157 100644
--- a/src/engine/adapters/wwebjs-running-build-ready.spec.ts
+++ b/src/engine/adapters/wwebjs-running-build-ready.spec.ts
@@ -43,7 +43,6 @@ describe('the running-build probe at READY', () => {
logger: { log: jest.fn(), warn: jest.fn(), error: jest.fn(), debug: jest.fn() },
config: { sessionId: 'sess', sessionDataPath: './data/sessions' },
getCallbacks: () => ({ onReady }),
- emitState: jest.fn(),
scheduleReadyReconcile: jest.fn(),
clearReadyReconcile: jest.fn(),
startOnboardingWatcher: jest.fn(),
diff --git a/src/engine/adapters/wwebjs-startup-diagnostics.spec.ts b/src/engine/adapters/wwebjs-startup-diagnostics.spec.ts
index 28e9f3883..d7d49afab 100644
--- a/src/engine/adapters/wwebjs-startup-diagnostics.spec.ts
+++ b/src/engine/adapters/wwebjs-startup-diagnostics.spec.ts
@@ -33,7 +33,6 @@ describe('the patch diagnostics at whatsapp-web.js start', () => {
logger,
config: { sessionId: 'sess', sessionDataPath: './data/sessions' },
getCallbacks: () => ({}),
- emitState: jest.fn(),
scheduleReadyReconcile: jest.fn(),
clearReadyReconcile: jest.fn(),
startOnboardingWatcher: jest.fn(),
diff --git a/src/engine/builtin/baileys/index.spec.ts b/src/engine/builtin/baileys/index.spec.ts
index e45f7020a..eacc218d1 100644
--- a/src/engine/builtin/baileys/index.spec.ts
+++ b/src/engine/builtin/baileys/index.spec.ts
@@ -19,7 +19,7 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {
logger: { log: jest.fn() },
} as unknown as PluginContext);
- plugin.createEngine({ sessionId: 'sess-1', dbSessionId: 'db-1', proxyUrl: 'http://p', proxyType: 'http' });
+ plugin.createEngine({ sessionId: 'sess-1', dbSessionId: 'db-1', proxyUrl: 'http://p' });
expect(BaileysAdapter).toHaveBeenCalledWith(
expect.objectContaining({
@@ -27,7 +27,6 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {
dbSessionId: 'db-1',
authDir: '/data/baileys',
proxyUrl: 'http://p',
- proxyType: 'http',
}),
);
});
diff --git a/src/engine/builtin/baileys/index.ts b/src/engine/builtin/baileys/index.ts
index 8885f5ac0..d3a9ec7e5 100644
--- a/src/engine/builtin/baileys/index.ts
+++ b/src/engine/builtin/baileys/index.ts
@@ -44,7 +44,6 @@ export class BaileysPlugin implements IEnginePlugin {
const sessionId = config.sessionId as string;
const dbSessionId = config.dbSessionId as string;
const proxyUrl = config.proxyUrl as string | undefined;
- const proxyType = config.proxyType as 'http' | 'https' | 'socks4' | 'socks5' | undefined;
// Baileys' own config namespace, read from the opaque per-engine blob the factory supplies via
// context.config (the `engine` sub-tree in configuration.ts). Per-call config carries
@@ -58,7 +57,6 @@ export class BaileysPlugin implements IEnginePlugin {
dbSessionId,
authDir,
proxyUrl,
- proxyType,
messageStore: this.messageStore,
lidMappingStore: this.lidMappingStore,
chatStateStore: this.chatStateStore,
diff --git a/src/engine/types/baileys.types.ts b/src/engine/types/baileys.types.ts
index 88767ffc6..79a25cc7e 100644
--- a/src/engine/types/baileys.types.ts
+++ b/src/engine/types/baileys.types.ts
@@ -46,7 +46,6 @@ export interface BaileysAdapterConfig {
dbSessionId: string;
authDir: string;
proxyUrl?: string;
- proxyType?: 'http' | 'https' | 'socks4' | 'socks5';
/** Persisted store for reply/forward/react/delete. Provided by the plugin; the four ops require it. */
messageStore?: BaileysMessageStore;
/** Persisted, cross-session lid->phone resolution table. Backs lid resolution beyond the in-memory map. */