feat(client-registrations): busca automática de CNPJ (dados, sócios, IE)
Ao digitar/já ter um CNPJ num cadastro de cliente PJ, busca automática contra a Receita Federal (cnpj.ws primário, BrasilAPI fallback) e preenche razão social, endereço e inscrição estadual, além de criar os sócios encontrados (sem duplicar em buscas repetidas) — pra usar depois na confecção do contrato/assinatura. Fecha uma lacuna real que já estava prevista mas nunca implementada: pj_cnpj não tinha nenhuma forma de ser gravado (UpdateClientRegistrationDto o excluía deliberadamente, esperando por "a dedicated re-verification flow" — exatamente o que este endpoint é). O servidor sempre refaz a própria consulta autoritativa a partir do CNPJ recebido, nunca confia em dado "já encontrado" vindo do cliente. Suíte: 100/100 (95→100). pnpm turbo run typecheck build: 28/28. Testado ao vivo contra CNPJs reais (Petrobras, Banco do Brasil) e em navegador real via Playwright. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -264,3 +264,28 @@ export function updateClientRegistrationPartner(
|
||||
{ accessToken },
|
||||
);
|
||||
}
|
||||
|
||||
/** Result of `POST /v1/client-registrations/:id/cnpj-lookup` on a match (201). */
|
||||
export interface ClientRegistrationCnpjLookupResult {
|
||||
registration: ClientRegistration;
|
||||
partners: ClientRegistrationPartner[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up a CNPJ against the external source and applies the result to the
|
||||
* registration (company data, address, partners) server-side. 404 means the
|
||||
* CNPJ wasn't found — caller should surface the API's message and leave the
|
||||
* registration untouched (no exception-free "not found" sentinel here, the
|
||||
* caller catches `ApiError` and inspects `.status`/`.message` as elsewhere).
|
||||
*/
|
||||
export function applyClientRegistrationCnpjLookup(
|
||||
id: string,
|
||||
cnpj: string,
|
||||
accessToken: string,
|
||||
): Promise<ClientRegistrationCnpjLookupResult> {
|
||||
return apiRequest<ClientRegistrationCnpjLookupResult>(
|
||||
`/client-registrations/${id}/cnpj-lookup`,
|
||||
{ method: "POST", body: JSON.stringify({ cnpj }) },
|
||||
{ accessToken },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user