feat(billing): rating engine, fechamento de periodo, dashboard platform (fase 22)

Fecha a orquestracao de Billing (agente.md secao 120-139) sobre o schema/
RatingEngine puro ja existentes: escritores do ledger UsageEvent
(CALL_SECONDS no CDR, ACTIVE_DAY via sweep diario), closeBillingPeriod/
reopenBillingPeriod (fechamento imutavel com audit trail), e os
controllers de price books/rate decks/plan versions/subscriptions/
periods/statements. Corrige 2 bugs reais de RLS achados no teste ponta a
ponta (reopen sem tenant context, subscriptions sem withTenantContext) e
adiciona teste unitario do RatingEngine (17 casos).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EWHKmcVJtstQFErbZ1AanY
This commit is contained in:
2026-08-29 00:28:35 -03:00
parent d4e2513764
commit b27cfaab02
35 changed files with 4705 additions and 34 deletions

View File

@@ -9,8 +9,10 @@ import rateLimit from "@fastify/rate-limit";
import { AppModule } from "./app.module";
import { DomainExceptionFilter } from "./common/filters/domain-exception.filter";
import { runRetentionSweep } from "./recordings/retention-sweep";
import { runActiveDaySweep } from "./billing/active-day-sweep";
const RETENTION_SWEEP_INTERVAL_MS = 60 * 60 * 1000;
const ACTIVE_DAY_SWEEP_INTERVAL_MS = 60 * 60 * 1000;
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
@@ -63,6 +65,13 @@ async function bootstrap() {
setInterval(() => {
runRetentionSweep().catch((err) => console.error("falha na varredura de retencao", err));
}, RETENTION_SWEEP_INTERVAL_MS);
// Usage metering diario (agente.md secao 131: EXTENSION/AGENT/TRUNK
// ACTIVE_DAY) — mesmo padrao da varredura de retencao acima.
runActiveDaySweep().catch((err) => console.error("falha na varredura de uso diario (boot)", err));
setInterval(() => {
runActiveDaySweep().catch((err) => console.error("falha na varredura de uso diario", err));
}, ACTIVE_DAY_SWEEP_INTERVAL_MS);
}
bootstrap();