From 16857e71799ea453227426dc8bb46a4d5df04c79 Mon Sep 17 00:00:00 2001 From: Danilo Leone Date: Wed, 2 Dec 2026 13:17:43 -0300 Subject: [PATCH 1/3] fix(licensing): try EVOLUTION_OPERATOR_EMAIL when the global API key is not a license AUTHENTICATION_API_KEY always has a value (it falls back to a default), so the boot never reached the branch that tries the operator e-mail. When the global key is rejected by the licensing server, try the e-mail activation before falling back to the browser registration flow. --- src/licensing/runtime.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/licensing/runtime.ts b/src/licensing/runtime.ts index f99d026bc0..bdf878e7e1 100644 --- a/src/licensing/runtime.ts +++ b/src/licensing/runtime.ts @@ -119,7 +119,8 @@ export function trackMessageRecv(): void { * 1. Load or create instance ID (hardware-based, persistent) * 2. If license exists in DB → activate locally (works even if licensing server is down) * 3. If no license but globalApiKey is set → try to use it as api_key - * 4. Otherwise → inactive; gate middleware will return 503 until activation + * 4. Otherwise → try EVOLUTION_OPERATOR_EMAIL auto-activation + * 5. Otherwise → inactive; gate middleware will return 503 until activation */ export async function initializeRuntime(opts: InitializeOptions = {}): Promise { const tier = opts.tier || 'evolution-api'; @@ -176,29 +177,31 @@ export async function initializeRuntime(opts: InitializeOptions = {}): Promise { + if (await tryAutoRegisterFromEnv(rc)) { + logger.info('License activated automatically via EVOLUTION_OPERATOR_EMAIL'); + return; + } + printRegistrationBanner(rc); + rc.setActive(false); +} + /** * tryAutoRegisterFromEnv attempts a silent license activation using only the * operator email from EVOLUTION_OPERATOR_EMAIL. The customer must have completed From c33a0ae547dc8186a1fa49102c754b30a5b35d7d Mon Sep 17 00:00:00 2001 From: Danilo Leone Date: Wed, 2 Dec 2026 13:51:19 -0300 Subject: [PATCH 2/3] docs(licensing): stop claiming EVOLUTION_OPERATOR_EMAIL needs a past registration --- src/licensing/runtime.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/licensing/runtime.ts b/src/licensing/runtime.ts index bdf878e7e1..8d87bf03ee 100644 --- a/src/licensing/runtime.ts +++ b/src/licensing/runtime.ts @@ -204,8 +204,8 @@ async function autoRegisterOrWait(rc: RuntimeContext): Promise { /** * tryAutoRegisterFromEnv attempts a silent license activation using only the - * operator email from EVOLUTION_OPERATOR_EMAIL. The customer must have completed - * at least one manual registration in the past. + * operator email from EVOLUTION_OPERATOR_EMAIL. Whether the email alone is enough + * to get a key is decided by the licensing server. * * Returns true on success. Returns false on any failure — the caller is expected * to fall back to the manual flow. Non-fatal best-effort path. From bc2798642c51150aba1e77abea31655466885ffe Mon Sep 17 00:00:00 2001 From: Danilo Leone Date: Wed, 2 Dec 2026 14:27:18 -0300 Subject: [PATCH 3/3] fix(licensing): fall back to EVOLUTION_OPERATOR_EMAIL only when the global key is refused A licensing outage or a failed save while activating a valid global key also reached the e-mail activation, which could replace the operator's key with an e-mail issued one and doubled the startup wait on timeouts. Only a 401/403 from the licensing server now leads to the e-mail activation; other errors keep the previous behaviour. --- env.example | 8 ++++---- src/licensing/runtime.ts | 11 +++++++++-- src/licensing/transport.ts | 6 ++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/env.example b/env.example index 60d0ef115a..30cc85c340 100644 --- a/env.example +++ b/env.example @@ -66,10 +66,10 @@ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=false # =========================================== # LICENÇA — ATIVAÇÃO AUTOMÁTICA POR E-MAIL # =========================================== -# Defina este valor com o e-mail usado no seu primeiro registro manual. -# Na inicialização, o serviço chama silenciosamente /v1/register/auto e pula -# a etapa do navegador. Cai para o fluxo manual se o e-mail ainda não estiver -# registrado no servidor de licenciamento. +# Na inicialização sem licença salva, se AUTHENTICATION_API_KEY for recusada +# como chave de licença, o serviço chama /v1/register/auto com este e-mail e +# pula a etapa do navegador. O servidor de licenciamento decide se o e-mail +# basta; se ele recusar, cai para o fluxo manual. # Deixe vazio (ou não defina) para manter o comportamento padrão (registro manual). # EVOLUTION_OPERATOR_EMAIL=operator@example.com diff --git a/src/licensing/runtime.ts b/src/licensing/runtime.ts index 8d87bf03ee..9a624332c6 100644 --- a/src/licensing/runtime.ts +++ b/src/licensing/runtime.ts @@ -15,7 +15,7 @@ import { NextFunction, Request, Response } from 'express'; import { activateIntegrity } from './integrity'; import { RegisterExchangeResponse, RuntimeContextSnapshot } from './model'; import { loadOrCreateInstanceID, loadRuntimeData, saveRuntimeData } from './store'; -import { postSigned, postUnsigned, readErrorMessage } from './transport'; +import { isRejectedCredential, postSigned, postUnsigned, readErrorMessage } from './transport'; const logger = new Logger('Licensing'); @@ -179,7 +179,14 @@ export async function initializeRuntime(opts: InitializeOptions = {}): Promise(path: string): Promise(resolveEndpoint() + path); } +/** True when the licensing server answered and refused the credential (401/403). */ +export function isRejectedCredential(err: unknown): boolean { + const status = axios.isAxiosError(err) ? err.response?.status : undefined; + return status === 401 || status === 403; +} + export function readErrorMessage(err: unknown): string { if (axios.isAxiosError(err)) { const data = err.response?.data as { message?: string; error?: string } | undefined;