feat(newwhats): envia x-nw-clinica do workspace ativo (modelo de canal)

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 <noreply@anthropic.com>
This commit is contained in:
VPS 4 Builder
2026-07-02 05:19:44 +02:00
parent 3e1001b7c7
commit ecf52d961a
2 changed files with 13 additions and 1 deletions
+2
View File
@@ -35,6 +35,8 @@ export function createRestProxy() {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'x-nw-key': cfg.integrationKey, 'x-nw-key': cfg.integrationKey,
'x-nw-email': email, '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) { if (!['GET', 'HEAD'].includes(req.method) && req.body && Object.keys(req.body).length) {
opts.body = JSON.stringify(req.body); opts.body = JSON.stringify(req.body);
+11 -1
View File
@@ -9,9 +9,19 @@ export function nwToken(): string | null {
try { return localStorage.getItem(TOKEN_KEY); } catch { return 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<string, string>): Record<string, string> { function authHeaders(extra?: Record<string, string>): Record<string, string> {
const t = nwToken(); 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<any> { async function req(method: string, path: string, body?: any): Promise<any> {