refactor: switch SDK methods to asynchronous

Migrate SDK interactions to asynchronous calls, relax admin setup email constraints, and add event retrieval functionality.
This commit is contained in:
Team Dark Devil committed 2026-11-17 20:05:00 +06:00
1 parent 81c5e4e2fd
commit bb938c33c0
36 files changed
+1679 -754

No files matched your search

+38 -1
View File
@@ -167,6 +167,38 @@ export class CSVStorageManager {
return results.sort((a, b) => b.modifiedAt.getTime() - a.modifiedAt.getTime());
}
/**
* Prune CSV partitions older than autoPruneDays
*/
public static pruneExpiredPartitions(autoPruneDays: number): number {
if (!Number.isFinite(autoPruneDays) || autoPruneDays <= 0) {
return 0;
}
const cutoffDate = new Date(
Date.now() - Math.floor(autoPruneDays) * 86_400_000,
)
.toISOString()
.split('T')[0];
let prunedCount = 0;
const files = this.listAllFiles();
for (const file of files) {
if (/^\d{4}-\d{2}-\d{2}$/.test(file.date) && file.date < cutoffDate) {
try {
if (fs.existsSync(file.filePath)) {
fs.unlinkSync(file.filePath);
prunedCount += 1;
}
} catch {
// Ignore file removal error
}
}
}
return prunedCount;
}
/**
* Get aggregate storage statistics
*/
@@ -175,6 +207,10 @@ export class CSVStorageManager {
const totalBytes = files.reduce((acc, f) => acc + f.sizeBytes, 0);
const totalRows = files.reduce((acc, f) => acc + f.linesCount, 0);
const uniqueClients = new Set(files.map((f) => f.clientId)).size;
const rotationMb = Math.max(
1,
Math.round(this.maxFileSizeBytes / (1024 * 1024)),
);
return {
totalFiles: files.length,
@@ -183,7 +219,8 @@ export class CSVStorageManager {
totalRows,
uniqueClients,
storageDirectory: this.baseStorageDir,
rotationRule: 'Per-day OR per-100MB rotation',
rotationMb,
rotationRule: `${rotationMb}MB / Daily`,
};
}