51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Helpers for audit logs with before/after snapshots of changed fields.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.diffFields = diffFields;
|
|
exports.pickFields = pickFields;
|
|
exports.userAccountFlagsSnapshot = userAccountFlagsSnapshot;
|
|
exports.userSecurityFlagsSnapshot = userSecurityFlagsSnapshot;
|
|
/** Builds a before/after diff for the given keys when values differ. */
|
|
function diffFields(before, after, keys) {
|
|
const changed = [];
|
|
const beforeOut = {};
|
|
const afterOut = {};
|
|
for (const key of keys) {
|
|
const b = before[key];
|
|
const a = after[key];
|
|
if (Object.is(b, a))
|
|
continue;
|
|
changed.push(String(key));
|
|
beforeOut[key] = b;
|
|
afterOut[key] = a;
|
|
}
|
|
if (changed.length === 0)
|
|
return null;
|
|
return { changed, before: beforeOut, after: afterOut };
|
|
}
|
|
/** Picks a subset of fields from a settings or config object. */
|
|
function pickFields(source, keys) {
|
|
const out = {};
|
|
for (const key of keys) {
|
|
out[key] = source[key];
|
|
}
|
|
return out;
|
|
}
|
|
function userAccountFlagsSnapshot(user) {
|
|
return {
|
|
is_enabled: user.is_enabled,
|
|
is_account_non_expired: user.is_account_non_expired,
|
|
is_account_non_locked: user.is_account_non_locked,
|
|
is_credentials_non_expired: user.is_credentials_non_expired,
|
|
};
|
|
}
|
|
function userSecurityFlagsSnapshot(user) {
|
|
return {
|
|
withdrawals_suspended: user.withdrawals_suspended,
|
|
under_surveillance: user.under_surveillance,
|
|
security_suspended_at: user.security_suspended_at?.toISOString() ?? null,
|
|
};
|
|
}
|
|
//# sourceMappingURL=auditDiff.js.map
|