dt-common-device
Version:
A secure and robust device management library for IoT applications
37 lines (36 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildAuditProperties = buildAuditProperties;
const AUDIT_FIELDS = [
"resource",
"propertyId",
"propertyName",
"userId",
"userName",
"deviceId",
"deviceName",
"zoneId",
"zoneName",
"accessGroupId",
"accessGroupName",
"scheduleId",
"scheduleName",
];
function buildAuditProperties(input) {
// Normalize keys to camelCase for matching
const normalized = { ...input };
// Build the audit object with all standard fields
const audit = {};
for (const field of AUDIT_FIELDS) {
// Try to find a matching key in input (case-insensitive)
const foundKey = Object.keys(normalized).find((k) => k.toLowerCase() === field.toLowerCase());
audit[field] = foundKey ? normalized[foundKey] : undefined;
}
// Merge in all other event-specific data (but don't overwrite audit fields)
for (const key of Object.keys(normalized)) {
if (!audit.hasOwnProperty(key)) {
audit[key] = normalized[key];
}
}
return audit;
}