From ecf52d961a6814d4d4ab86cacf846af84e01eab3 Mon Sep 17 00:00:00 2001 From: VPS 4 Builder Date: Thu, 2 Jul 2026 05:19:44 +0200 Subject: [PATCH] feat(newwhats): envia x-nw-clinica do workspace ativo (modelo de canal) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nwClient inclui o header x-nw-clinica (id do SCOREODONTO_ACTIVE_WORKSPACE) e o proxy REST o encaminha ao motor — assim as ações manuais escopam a ponte de agenda para a clínica do workspace ativo (por-requisição). Co-Authored-By: Claude Opus 4.8 --- backend/newwhats/proxy.js | 2 ++ frontend/views/newwhats/services/nwClient.ts | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/newwhats/proxy.js b/backend/newwhats/proxy.js index c5ffa24..5a4f405 100644 --- a/backend/newwhats/proxy.js +++ b/backend/newwhats/proxy.js @@ -35,6 +35,8 @@ export function createRestProxy() { 'Content-Type': 'application/json', 'x-nw-key': cfg.integrationKey, 'x-nw-email': email, + // clínica do workspace ativo (modelo de canal) — repassa ao motor se veio. + ...(req.headers['x-nw-clinica'] ? { 'x-nw-clinica': String(req.headers['x-nw-clinica']) } : {}), } }; if (!['GET', 'HEAD'].includes(req.method) && req.body && Object.keys(req.body).length) { opts.body = JSON.stringify(req.body); diff --git a/frontend/views/newwhats/services/nwClient.ts b/frontend/views/newwhats/services/nwClient.ts index c05ee40..35e1e79 100644 --- a/frontend/views/newwhats/services/nwClient.ts +++ b/frontend/views/newwhats/services/nwClient.ts @@ -9,9 +9,19 @@ export function nwToken(): string | null { try { return localStorage.getItem(TOKEN_KEY); } catch { return null; } } +// Clínica do workspace ativo — escopo por-requisição (modelo de canal). +function activeClinicaId(): string | null { + try { return JSON.parse(localStorage.getItem('SCOREODONTO_ACTIVE_WORKSPACE') || '{}')?.id || null; } catch { return null; } +} + function authHeaders(extra?: Record): Record { const t = nwToken(); - return { ...(t ? { Authorization: `Bearer ${t}` } : {}), ...(extra || {}) }; + const c = activeClinicaId(); + return { + ...(t ? { Authorization: `Bearer ${t}` } : {}), + ...(c ? { 'x-nw-clinica': c } : {}), + ...(extra || {}), + }; } async function req(method: string, path: string, body?: any): Promise {