profileFields
What a Bluesky profile record says, as the registry shows it: its display name and bio (trimmed, and cut short), and
its picture, served by its owner's PDS (com.atproto.sync.getBlob). What isn't a string, or a blob's CID, isn't
taken.
import type { Someone } from "#codebase/tcmts/registry"; export function profileFields(record: unknown, pds: string, did: string): Omit<Someone, "did"> { const r = (record && typeof record === "object" ? record : {}) as { displayName?: unknown; description?: unknown; avatar?: { ref?: unknown }; }; const text = (v: unknown, most: number) => typeof v === "string" && v.trim() ? v.trim().slice(0, most) : undefined; const ref = r.avatar?.ref; const cid = ref && typeof ref === "object" && typeof (ref as { $link?: unknown }).$link === "string" ? (ref as { $link: string }).$link : ref ? String(ref) : undefined; const name = text(r.displayName, 64); const bio = text(r.description, 300); return { ...(name ? { name } : {}), ...(bio ? { bio } : {}), ...(cid && /^b[a-z2-7]{20,}$/.test(cid) ? { avatar: `${pds}/xrpc/com.atproto.sync.getBlob?${new URLSearchParams({ did, cid })}` } : {}), }; }