import { CompatibleOperationOrTombstone, defs, IndexedEntry, processIndexedEntryLog, } from "@atcute/did-plc"; import { createResource, createSignal, For, Show } from "solid-js"; import Tooltip from "../components/tooltip.jsx"; import { localDateFromTimestamp } from "../utils/date.js"; import { createOperationHistory, DiffEntry, groupBy } from "../utils/plc-logs.js"; type PlcEvent = "handle" | "rotation_key" | "service" | "verification_method"; export const PlcLogView = (props: { did: string }) => { const [activePlcEvent, setActivePlcEvent] = createSignal(); const fetchPlcLogs = async () => { const res = await fetch( `${localStorage.plcDirectory ?? "https://plc.directory"}/${props.did}/log/audit`, ); const json = await res.json(); const logs = defs.indexedEntryLog.parse(json); try { await processIndexedEntryLog(props.did as any, logs); } catch (e) { console.error(e); } const opHistory = createOperationHistory(logs).reverse(); return Array.from(groupBy(opHistory, (item) => item.orig)); }; const [plcOps] = createResource<[IndexedEntry, DiffEntry[]][]>(fetchPlcLogs); const FilterButton = (props: { icon: string; event: PlcEvent }) => ( ); const DiffItem = (props: { diff: DiffEntry }) => { const diff = props.diff; let title = "Unknown log entry"; let icon = "lucide--circle-help"; let value = ""; if (diff.type === "identity_created") { icon = "lucide--bell"; title = `Identity created`; } else if (diff.type === "identity_tombstoned") { icon = "lucide--skull"; title = `Identity tombstoned`; } else if (diff.type === "handle_added" || diff.type === "handle_removed") { icon = "lucide--at-sign"; title = diff.type === "handle_added" ? "Alias added" : "Alias removed"; value = diff.handle; } else if (diff.type === "handle_changed") { icon = "lucide--at-sign"; title = "Alias updated"; value = `${diff.prev_handle} → ${diff.next_handle}`; } else if (diff.type === "rotation_key_added" || diff.type === "rotation_key_removed") { icon = "lucide--key-round"; title = diff.type === "rotation_key_added" ? "Rotation key added" : "Rotation key removed"; value = diff.rotation_key; } else if (diff.type === "service_added" || diff.type === "service_removed") { icon = "lucide--hard-drive"; title = `Service ${diff.service_id} ${diff.type === "service_added" ? "added" : "removed"}`; value = `${diff.service_endpoint}`; } else if (diff.type === "service_changed") { icon = "lucide--hard-drive"; title = `Service ${diff.service_id} updated`; value = `${diff.prev_service_endpoint} → ${diff.next_service_endpoint}`; } else if ( diff.type === "verification_method_added" || diff.type === "verification_method_removed" ) { icon = "lucide--shield-check"; title = `Verification method ${diff.method_id} ${diff.type === "verification_method_added" ? "added" : "removed"}`; value = `${diff.method_key}`; } else if (diff.type === "verification_method_changed") { icon = "lucide--shield-check"; title = `Verification method ${diff.method_id} updated`; value = `${diff.prev_method_key} → ${diff.next_method_key}`; } return (

{title}

{value}
); }; return (
{([entry, diffs]) => ( d.type.startsWith(activePlcEvent()!))} >
{localDateFromTimestamp(new Date(entry.createdAt).getTime())} {diffs.map((diff) => ( ))}
)}
); };