'use client'; import { useEffect, useState } from 'react'; import { diffOps, formatPlcTime, getPlcAuditLog, type PlcAuditEntry, } from '@/utils/atproto/plc'; import type { IdentityBundle } from '@/utils/atproto/identity'; export default function AuditTab({ identity }: { identity: IdentityBundle }) { const { did } = identity; const isPlc = did.startsWith('did:plc:'); const [log, setLog] = useState(null); const [error, setError] = useState(null); useEffect(() => { if (!isPlc) return undefined; let cancelled = false; setLog(null); setError(null); getPlcAuditLog(did) .then((l) => { if (!cancelled) setLog(Array.isArray(l) ? l : []); }) .catch((err) => { if (!cancelled) setError(err instanceof Error ? err.message : String(err)); }); return () => { cancelled = true; }; }, [did, isPlc]); if (!isPlc) { return (

Audit log only available for did:plc: DIDs.

); } if (error) return

{error}

; if (!log) return

Loading audit log…

; if (log.length === 0) return

No PLC operations recorded.

; // Newest first; pass the chronologically-previous operation so diffs can // surface what changed. const ordered = [...log].reverse(); return (
    {ordered.map((entry, i) => ( ))}
); } function AuditEntryRow({ entry, prev, }: { entry: PlcAuditEntry; prev?: PlcAuditEntry; }) { const op = entry.operation || {}; const type = op.type || (op.prev === null ? 'create' : 'update'); const changes = diffOps(prev?.operation, op); return (
  • {type}
    {changes.length > 0 && (
      {changes.map((c, idx) => (
    • {c}
    • ))}
    )}
    Raw operation
    {JSON.stringify(entry, null, 2)}
  • ); }