import { ad as logAuditEventAsync, g as getHeader } from '../nitro/nitro.mjs';
import { g as getAuditActorFromEvent } from './audit-log-actor.mjs';

function getRequestIp(event) {
  var _a, _b;
  const forwardedFor = event.node.req.headers["x-forwarded-for"];
  if (typeof forwardedFor === "string" && forwardedFor.trim() !== "") {
    return forwardedFor.split(",")[0].trim();
  }
  return (_b = (_a = event.node.req.socket) == null ? void 0 : _a.remoteAddress) != null ? _b : void 0;
}
function auditFromEvent(event, action, options = {}) {
  var _a;
  const actor = getAuditActorFromEvent(event);
  logAuditEventAsync({
    action,
    actor,
    target: options.target,
    ip: getRequestIp(event),
    userAgent: getHeader(event, "user-agent"),
    metadata: options.metadata,
    outcome: (_a = options.outcome) != null ? _a : "success"
  });
}

export { auditFromEvent as a };
//# sourceMappingURL=audit-log-helpers.mjs.map
