refactor(engine): move JID construction into the engine (#265)
Part of #265 (engine-pluggability decoupling). Item 3 of the roadmap: get the whatsapp-web.js JID scheme out of engine-neutral code so a different engine (e.g. Baileys) can supply its own.
What leaked
Two sites hard-coded wwebjs's JID format:
- Check-number endpoint — the controller hand-built
${number}@c.us. - session.service — the status/story skip matched the
status@broadcastpseudo-JID directly.
Changes
IWhatsAppEngine.getNumberId(number)— new contract returning the engine's canonical chat id (ornull). The wwebjs adapter resolves it viaclient.getNumberId(...)?._serialized, andcheckNumberExistsnow delegates to it (DRY; identicalensureReady→ HTTP 409 contract).- contact.controller returns the engine-resolved
whatsappIdinstead of a hand-built…@c.us. - Neutral
isStatusBroadcastflag — set by the message-mapper (same predicate as the old literal check); session.service branches on the flag. Thestatus@broadcastliteral is now confined to the adapter.getChatHistoryrecomputes the chatId-derived flags (isGroup,isStatusBroadcast) after its chatId override, mirroring the existing pattern. - Docs — fixed the stale check-number response shape in
docs/06anddocs/07({ number, exists, whatsappId }, no envelope, correctcheck/:numberpath).
⚠️ Behavior note
whatsappId is now the engine-resolved canonical id, not an echo of the input. It may be normalized and differ from ${input}@c.us (e.g. a @lid identifier). exists is unchanged (still "engine returned a non-null id"). Documented in CHANGELOG + the endpoint docs.
Live-verified against a real linked account:
check/6281270008896→{exists:true, whatsappId:"262813461250071@lid"}— proves the canonical id is returned (and is more correct than the old@c.usguess for@lidcontacts).check/19999999999→{exists:false, whatsappId:null}.
Review
Adversarial multi-agent review (getNumberId-contract: holds; status-flag-equivalence: equivalence exact). It caught a real CI blocker — a 121-char lint violation in the status spec — now fixed. The doc/CHANGELOG drift it flagged is addressed here too.
Verification
npm run build✓npm run lint✓- 439/439 tests pass ✓
Deferred
dashboard/.../MessageTester.tsx still builds a @c.us JID — needs a dashboard checkNumber call + i18n error path. Tracked under #265.