- Added AccessControl to ComboHandler for role-based access management. - Implemented gas estimation for plan execution and improved gas limit checks. - Updated execution and preparation methods to enforce step count limits and role restrictions. - Enhanced error handling in orchestrator API endpoints with AppError for better validation feedback. - Integrated request timeout middleware for improved request management. - Updated Swagger documentation to reflect new API structure and parameters.
89 lines
1.9 KiB
TypeScript
89 lines
1.9 KiB
TypeScript
import { query } from "../db/postgres";
|
|
|
|
/**
|
|
* Data retention and deletion service (GDPR compliance)
|
|
*/
|
|
export class DataRetentionService {
|
|
/**
|
|
* Delete user data (GDPR right to be forgotten)
|
|
*/
|
|
async deleteUserData(userId: string): Promise<void> {
|
|
// Delete in transaction
|
|
await query("BEGIN");
|
|
|
|
try {
|
|
// Anonymize plans
|
|
await query(
|
|
`UPDATE plans SET creator = $1 WHERE creator = $2`,
|
|
[`deleted-${Date.now()}`, userId]
|
|
);
|
|
|
|
// Delete compliance status
|
|
await query(
|
|
`DELETE FROM compliance_status WHERE user_id = $1`,
|
|
[userId]
|
|
);
|
|
|
|
// Anonymize audit logs
|
|
await query(
|
|
`UPDATE audit_logs SET user_id = $1 WHERE user_id = $2`,
|
|
[`deleted-${Date.now()}`, userId]
|
|
);
|
|
|
|
await query("COMMIT");
|
|
} catch (error) {
|
|
await query("ROLLBACK");
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Export user data (GDPR data portability)
|
|
*/
|
|
async exportUserData(userId: string) {
|
|
const plans = await query(
|
|
`SELECT * FROM plans WHERE creator = $1`,
|
|
[userId]
|
|
);
|
|
|
|
const compliance = await query(
|
|
`SELECT * FROM compliance_status WHERE user_id = $1`,
|
|
[userId]
|
|
);
|
|
|
|
const auditLogs = await query(
|
|
`SELECT * FROM audit_logs WHERE user_id = $1`,
|
|
[userId]
|
|
);
|
|
|
|
return {
|
|
userId,
|
|
exportedAt: new Date().toISOString(),
|
|
plans,
|
|
compliance,
|
|
auditLogs,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Apply retention policies
|
|
*/
|
|
async applyRetentionPolicies() {
|
|
const retentionDays = 90;
|
|
const cutoffDate = new Date();
|
|
cutoffDate.setDate(cutoffDate.getDate() - retentionDays);
|
|
|
|
// Archive old plans
|
|
await query(
|
|
`UPDATE plans SET status = 'archived'
|
|
WHERE status != 'archived'
|
|
AND created_at < $1
|
|
AND status IN ('complete', 'failed', 'aborted')`,
|
|
[cutoffDate.toISOString()]
|
|
);
|
|
}
|
|
}
|
|
|
|
export const dataRetention = new DataRetentionService();
|
|
|