rl-core-api 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -78,7 +78,7 @@ Swagger, o remetente dos emails e o emissor exibido no app autenticador:
78
78
  |---|---|---|
79
79
  | `APP_NAME` | Nome do sistema | `Core App` |
80
80
  | `APP_LOGO_URL` | Logo no cabeçalho dos emails — **URL absoluta e pública**, porque o cliente de email busca a imagem do servidor dele | só o nome, em texto |
81
- | `APP_BRAND_COLOR` | Cor dos botões e do cabeçalho dos emails (`#RRGGBB`) | `#007bff` |
81
+ | `APP_BRAND_COLOR` | Cor **dos emails** — botões, código 2FA e o nome no cabeçalho. Não é a cor da interface, que vem do `tailwind-preset`. Escreva entre aspas: `APP_BRAND_COLOR="#16A34A"`, senão o dotenv lê o `#` como comentário e o valor chega vazio | `#007bff` |
82
82
  | `TOTP_ISSUER` | Emissor no app autenticador | segue o `APP_NAME` |
83
83
  | `EMAIL_FROM_NAME` | Nome do remetente | segue o `APP_NAME` |
84
84
 
@@ -59,6 +59,7 @@ export declare const envSchema: z.ZodObject<{
59
59
  TOKEN_CLEANUP_CRON: z.ZodDefault<z.ZodString>;
60
60
  AUDIT_LOG_CLEANUP_CRON: z.ZodDefault<z.ZodString>;
61
61
  AUDIT_LOG_RETENTION_DAYS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
62
+ AUDIT_DATA_RETENTION_DAYS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
62
63
  NOTIFICATION_RETENTION_DAYS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
63
64
  SEED_ADMIN_NAME: z.ZodDefault<z.ZodString>;
64
65
  SEED_ADMIN_EMAIL: z.ZodDefault<z.ZodString>;
@@ -18,7 +18,7 @@ exports.envSchema = zod_1.z
18
18
  APP_LOGO_URL: zod_1.z.string().url().optional(),
19
19
  APP_BRAND_COLOR: zod_1.z
20
20
  .string()
21
- .regex(/^#[0-9a-fA-F]{6}$/, "APP_BRAND_COLOR deve ser hex (#RRGGBB)")
21
+ .regex(/^#[0-9a-fA-F]{6}$/, 'APP_BRAND_COLOR deve ser hex (#RRGGBB) e entre aspas no .env: APP_BRAND_COLOR="#007bff"')
22
22
  .default("#007bff"),
23
23
  DB_HOST: zod_1.z.string().min(1),
24
24
  DB_PORT: zod_1.z.coerce.number().int().positive().default(3306),
@@ -69,7 +69,8 @@ exports.envSchema = zod_1.z
69
69
  PASSWORD_MAX_AGE_DAYS: zod_1.z.coerce.number().int().positive().default(90),
70
70
  TOKEN_CLEANUP_CRON: zod_1.z.string().default("0 */6 * * *"),
71
71
  AUDIT_LOG_CLEANUP_CRON: zod_1.z.string().default("0 3 * * *"),
72
- AUDIT_LOG_RETENTION_DAYS: zod_1.z.coerce.number().int().positive().default(30),
72
+ AUDIT_LOG_RETENTION_DAYS: zod_1.z.coerce.number().int().positive().default(15),
73
+ AUDIT_DATA_RETENTION_DAYS: zod_1.z.coerce.number().int().positive().default(30),
73
74
  NOTIFICATION_RETENTION_DAYS: zod_1.z.coerce
74
75
  .number()
75
76
  .int()
@@ -23,6 +23,7 @@ export declare class AuditService {
23
23
  constructor(changeRepo: AuditChangeRepository, errorRepo: ErrorLogRepository, dataChangeRepo: AuditDataChangeRepository, userRepo: UserRepository);
24
24
  recordChange(data: Partial<AuditChange>): Promise<void>;
25
25
  recordError(data: Partial<ErrorLog>): Promise<void>;
26
+ cleanupOldDataChanges(retentionDays: number): Promise<number>;
26
27
  cleanupOldLogs(retentionDays: number): Promise<{
27
28
  changes: number;
28
29
  errors: number;
@@ -42,6 +42,13 @@ let AuditService = AuditService_1 = class AuditService {
42
42
  this.logger.warn(`Falha ao gravar ErrorLog: ${err.message}`);
43
43
  }
44
44
  }
45
+ async cleanupOldDataChanges(retentionDays) {
46
+ const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
47
+ const removed = await this.dataChangeRepo.delete({
48
+ createdAt: (0, typeorm_1.LessThan)(cutoff),
49
+ });
50
+ return removed.affected ?? 0;
51
+ }
45
52
  async cleanupOldLogs(retentionDays) {
46
53
  const cutoff = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000);
47
54
  const changes = await this.changeRepo.delete({
@@ -46,6 +46,11 @@ let CleanupService = CleanupService_1 = class CleanupService {
46
46
  if (changes > 0 || errors > 0) {
47
47
  this.logger.log(`Logs operacionais removidos (> ${retentionDays}d): ${changes} requisições, ${errors} erros`);
48
48
  }
49
+ const dataRetentionDays = this.env.get("AUDIT_DATA_RETENTION_DAYS");
50
+ const dataChanges = await this.audit.cleanupOldDataChanges(dataRetentionDays);
51
+ if (dataChanges > 0) {
52
+ this.logger.log(`Trilha de dados removida (> ${dataRetentionDays}d): ${dataChanges} registros`);
53
+ }
49
54
  });
50
55
  }
51
56
  async handleNotificationCleanup() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rl-core-api",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Core NestJS: autenticação com 2FA, RBAC, auditoria, notificações e listagens com filtro dinâmico",
5
5
  "author": "Rodrigo Liberti",
6
6
  "license": "MIT",