feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint

This commit is contained in:
Dave
2025-11-05 11:14:54 -05:00
parent bedca60744
commit f2faa5b686
10 changed files with 381 additions and 466 deletions

View File

@@ -0,0 +1,43 @@
// File: server/rr/rr-logger-event.js
// Fortellis-style log helper for RR flows.
// Usage: CreateRRLogEvent(socket, "DEBUG"|"INFO"|"WARN"|"ERROR", message, details?)
const RRLogger = require("../rr/rr-logger");
// Normalize level to upper + provide console + socket event with coherent payload
function CreateRRLogEvent(socket, level = "DEBUG", message = "", details = {}) {
const lvl = String(level || "DEBUG").toUpperCase();
const ts = Date.now();
// Console (uses existing RRLogger, which also emits "RR:LOG" to sockets for live tail)
try {
const log = RRLogger(socket);
const fn = lvl === "ERROR" ? "error" : lvl === "WARN" ? "warn" : lvl === "INFO" ? "info" : "debug";
log(fn, message, { ts, ...safeJson(details) });
} catch {
/* ignore console/log failures */
}
// Structured RR event for FE debug panel (parity with Fortellis' CreateFortellisLogEvent)
try {
socket?.emit?.("rr-log-event", {
level: lvl,
message,
ts,
...safeJson(details)
});
} catch {
/* ignore socket emit failures */
}
}
// Best-effort ensure details are JSON-safe (avoid circular / BigInt)
function safeJson(obj) {
try {
return JSON.parse(JSON.stringify(obj ?? {}));
} catch {
return { _unsafe: true };
}
}
module.exports = CreateRRLogEvent;