feat: Implement Phase 2 cross-cutting services with email and notification enhancements
- Refactor email verification and password reset utilities to use new email service. - Introduce email delivery queue and notification delivery model for better tracking. - Enhance file validation and storage services for improved security and ownership management. - Add cron job for cleaning inactive notifications with retention policy. - Update document worker to handle document generation and storage more efficiently. - Implement logging improvements in activity and log workers. - Create comprehensive documentation for new API endpoints and services. - Add unit tests for file validation and notification policies to ensure robustness.
This commit is contained in:
@@ -15,21 +15,33 @@ const logActivity = async ({
|
||||
user,
|
||||
description,
|
||||
type = "ACTION",
|
||||
module
|
||||
module,
|
||||
eventId,
|
||||
targetType,
|
||||
targetId,
|
||||
requestId,
|
||||
ipAddress,
|
||||
userAgent,
|
||||
metadata,
|
||||
}) => {
|
||||
try {
|
||||
const safeMetadata = metadata && JSON.parse(JSON.stringify(metadata, (key, value) => /password|otp|token|authorization|cookie/i.test(key) ? "[REDACTED]" : value));
|
||||
const id = eventId || require("crypto").randomUUID();
|
||||
await activityQueue.add("log-activity", {
|
||||
user_id: user.id || user.user_id,
|
||||
username: user.firstName,
|
||||
event_id: id,
|
||||
user_id: user?.id || user?.user_id || null,
|
||||
username: user?.firstName || "System",
|
||||
activity_description: description,
|
||||
module: module,
|
||||
activity_type: type,
|
||||
activity_time: new Date(),
|
||||
activity_date: new Date().toISOString().split("T")[0]
|
||||
});
|
||||
activity_date: new Date().toISOString().split("T")[0],
|
||||
target_type: targetType, target_id: targetId, request_id: requestId,
|
||||
ip_address: ipAddress, user_agent: userAgent, metadata: safeMetadata, occurred_at: new Date(),
|
||||
}, { jobId: `activity-${id}` });
|
||||
} catch (err) {
|
||||
console.error("Queue push error:", err.message);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { logActivity };
|
||||
module.exports = { logActivity };
|
||||
|
||||
Reference in New Issue
Block a user