feat(system-config): sync configs with .env and add 7-day retention cron jobs
Summary of Changes
1. 7-Day Retention Cleanup Cron Jobs
-
BullMQ Cron Implementation: Added
cleanup-exportsscheduled job running daily at 03:00 AM (0 3 * * *), complementing the existingcleanup-audit-logsjob at 02:00 AM (0 2 * * *). -
Retention Period: Updated default retention policy from 30 days to 7 days (
DEFAULT_AUDIT_LOG_RETENTION_DAYS = 7,DEFAULT_EXPORT_RETENTION_DAYS = 7). -
Storage Cleanup: Automatically deletes both database records and physical export files via
StorageService.deleteFile()(supporting AWS S3, Supabase Storage, and local disk). -
Dynamic Configuration & Feature Flags: Integrated
SystemConfigServicedynamic checks forretention.audit_logs_days,retention.exports_days,feature.cron.cleanup_audit_logs.enabled, andfeature.cron.cleanup_exports.enabled.
2. Synchronization of System Configs & Feature Flags with .env
-
Environment Driven Defaults: Updated
DEFAULT_SYSTEM_CONFIGSinsystem-config.constant.tsto dynamically resolve values fromprocess.env.*:- Supabase Storage / S3 configs:
S3_ENDPOINT,S3_REGION,S3_BUCKET,S3_FORCE_PATH_STYLE,STORAGE_DRIVER,STORAGE_EXPORT_DIR. - Crawler, JWT, Quota, Rate Limit, SMTP, and Firecrawl configurations.
- Supabase Storage / S3 configs:
-
Upsert Value Sync: Updated
ensureDefaultinsystem-config.repository.tsandensureDefaultConfigs(syncValues = true)insystem-config.service.tsto update existing database values during initialization or synchronization. -
New API Endpoint: Added
POST /api/v1/system/configs/sync-envprotected bysystem_configs.managepermission to trigger immediate sync and flush Redis cache on demand. -
Migration Script: Enhanced
scripts/sync-system-configs.ts(pnpm config:sync) to upsert values into Postgres.