···11+import { Agent } from '@atproto/api'
22+import { ProfileViewDetailed } from '@atproto/api/dist/client/types/app/bsky/actor/defs'
33+44+export function parseProfile(profile: ProfileViewDetailed) {
55+ return profile.handle !== 'handle.invalid' ? null : profile
66+}
77+88+export async function getProfile(agent: Agent, didOrHandle: string) {
99+ // if no 'app.bsky.actor.profile' record is found on the user's PDS, this method will not return an error
1010+ // instead it will return an empty skeleton of a profile record with "handle" set to "handle.invalid"
1111+ const profile = await agent.getProfile({ actor: didOrHandle })
1212+ if (!profile.success) {
1313+ throw new Error('Failed to fetch profile')
1414+ }
1515+1616+ const data = profile.data.handle === 'handle.invalid' ? null : profile.data
1717+ return data
1818+}