feat: read-only internal endpoint for GTI Fiscal to mirror clients

GET /internal/fiscal/clients returns every CLIENTE (active and inactive)
as {external_client_id, code, display_name, active} — CLIENTE.ID is the
identity (CODIGO is editable, same reasoning as FUNCIONARIO_PAINEL.ID in
SSO). Authenticated by a dedicated bearer token (FISCAL_INTERNAL_API_TOKEN,
never reused from SESSION_SECRET/SSO key/admin password), rate-limited per
IP, returns 503 rather than opening anonymously when the token isn't
configured. GTI Gerenciador stays the single source of truth: the Fiscal
Hub never receives MySQL credentials.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Gustavo
2026-09-23 22:36:40 -03:00
co-authored by Claude Sonnet 5
parent 161da90e02
commit b1f93c2d68
5 changed files with 178 additions and 0 deletions
+22
View File
@@ -87,6 +87,28 @@ def listar_clientes(
conn.close()
def listar_clientes_para_fiscal() -> list[dict]:
"""Para o endpoint interno GET /internal/fiscal/clients (app/internal_fiscal.py):
o Fiscal espelha TODOS os clientes (ativos e inativos — inativo continua
aparecendo em histórico do lado de lá), nunca só uma página. Payload
mínimo: ID é a PK técnica estável (CODIGO é editável, não serve de
identidade — mesma razão de FUNCIONARIO_PAINEL.ID no SSO). Sem CNPJ/
endereço/contato: o Fiscal não precisa desses campos hoje."""
conn = get_connection()
try:
with conn.cursor() as cur:
cur.execute(
"SELECT ID, CODIGO, COALESCE(NULLIF(FANTASIA, ''), RAZAO) AS NOME, ATIVO "
"FROM CLIENTE ORDER BY ID"
)
return [
{"external_client_id": row["ID"], "code": row["CODIGO"], "display_name": row["NOME"], "active": bool(row["ATIVO"])}
for row in cur.fetchall()
]
finally:
conn.close()
def proximo_codigo_sugerido() -> str:
"""
Sugere o próximo CODIGO sequencial (maior CODIGO numérico + 1, com zeros