Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): write credentials under the factory's auth-dir base
Yudhi Armyndharisea372fd718d9
diff --git a/src/engine/builtin/baileys/index.spec.ts b/src/engine/builtin/baileys/index.spec.tsindex 5f0b23aed..ffa728ef7 100644--- a/src/engine/builtin/baileys/index.spec.ts+++ b/src/engine/builtin/baileys/index.spec.ts@@ -93,4 +93,18 @@ describe('BaileysPlugin.createEngine (opaque config)', () => {expect.objectContaining({ sessionId: 'sess-4', authDir: '/context/baileys' }),);});++ // The factory hardens and purges credential dirs under its own base, so the engine must write there+ // even when a persisted plugin-config override names another directory.+ it('Prefers the per-call authDir over a context.config override', () => {+ const plugin = new BaileysPlugin();+ void plugin.onLoad({+ config: { baileys: { authDir: '/override/baileys' } },+ logger: { log: jest.fn() },+ } as unknown as PluginContext);+ plugin.createEngine({ sessionId: 'sess-5', authDir: '/factory/baileys' });+ expect(BaileysAdapter).toHaveBeenCalledWith(+ expect.objectContaining({ sessionId: 'sess-5', authDir: '/factory/baileys' }),+ );+ });});diff --git a/src/engine/builtin/baileys/index.ts b/src/engine/builtin/baileys/index.tsindex 580f470ea..8885f5ac0 100644--- a/src/engine/builtin/baileys/index.ts+++ b/src/engine/builtin/baileys/index.ts@@ -47,10 +47,11 @@ export class BaileysPlugin implements IEnginePlugin {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 only- // engine-neutral fields (sessionId, proxy).+ // context.config (the `engine` sub-tree in configuration.ts). Per-call config carries+ // engine-neutral fields (sessionId, proxy) plus authDir, the base the factory hardens and purges,+ // which wins over context.config.const engineConfig = (this.context?.config ?? this.registeredConfig ?? {}) as { baileys?: { authDir?: string } };- const authDir = engineConfig.baileys?.authDir ?? './data/baileys';+ const authDir = (config.authDir as string | undefined) ?? engineConfig.baileys?.authDir ?? './data/baileys';return new BaileysAdapter({sessionId,diff --git a/src/engine/builtin/whatsapp-web-js/index.spec.ts b/src/engine/builtin/whatsapp-web-js/index.spec.tsindex 3b921c95a..9db3bf5df 100644--- a/src/engine/builtin/whatsapp-web-js/index.spec.ts+++ b/src/engine/builtin/whatsapp-web-js/index.spec.ts@@ -104,6 +104,19 @@ describe('WhatsAppWebJsPlugin.createEngine (opaque config)', () => {expect.objectContaining({ sessionId: 'sess-4', sessionDataPath: '/context/path' }),);});++ // The factory hardens and purges credential dirs under its own base, so the engine must write there+ // even when a persisted plugin-config override names another directory.+ it('Prefers the per-call sessionDataPath over a context.config override', () => {+ const plugin = new WhatsAppWebJsPlugin();+ withContext(plugin, { sessionDataPath: '/override/sessions' });++ plugin.createEngine({ sessionId: 'sess-5', sessionDataPath: '/factory/sessions' });++ expect(WhatsAppWebJsAdapter).toHaveBeenCalledWith(+ expect.objectContaining({ sessionId: 'sess-5', sessionDataPath: '/factory/sessions' }),+ );+ });});describe('WhatsAppWebJsPlugin.getFeatures', () => {diff --git a/src/engine/builtin/whatsapp-web-js/index.ts b/src/engine/builtin/whatsapp-web-js/index.tsindex 74af6709e..e5c769aaa 100644--- a/src/engine/builtin/whatsapp-web-js/index.ts+++ b/src/engine/builtin/whatsapp-web-js/index.ts@@ -45,13 +45,15 @@ export class WhatsAppWebJsPlugin implements IEnginePlugin {// Browser config is this engine's OWN namespace, read from the opaque per-engine blob the// factory supplies via context.config (the `engine` sub-tree in configuration.ts). The- // per-call config carries only engine-neutral fields (sessionId, proxy).+ // per-call config carries engine-neutral fields (sessionId, proxy) plus sessionDataPath, the base+ // the factory hardens and purges, which wins over context.config.const engineConfig = (this.context?.config ?? this.registeredConfig ?? {}) as {sessionDataPath?: string;puppeteer?: { headless?: boolean; args?: string[]; executablePath?: string; protocolTimeoutMs?: number };};const puppeteer = engineConfig.puppeteer ?? {};- const sessionDataPath = engineConfig.sessionDataPath ?? './data/sessions';+ const sessionDataPath =+ (config.sessionDataPath as string | undefined) ?? engineConfig.sessionDataPath ?? './data/sessions';const headless = puppeteer.headless ?? true;// No default here: the adapter owns the fallback flag list (DEFAULT_PUPPETEER_ARGS), so a persisted// plugin config whose `puppeteer` object has no `args` still launches with the documented flags.