MCPcopy
hub / github.com/npmx-dev/npmx.dev / getNpmxProfile

Function getNpmxProfile

server/api/auth/atproto.get.ts:287–318  ·  view source on GitHub ↗
(handle: string, authSession: OAuthSession)

Source from the content-addressed store, hash-verified

285}
286
287async function getNpmxProfile(handle: string, authSession: OAuthSession) {
288 const client = new Client(authSession)
289
290 // get existing npmx profile OR create a new one
291 const profileUri = `at://${client.did}/dev.npmx.actor.profile/self`
292 if (!isAtUriString(profileUri)) {
293 throw new Error(`Invalid at-uri: ${profileUri}`)
294 }
295
296 const profileResult = await slingshotClient.xrpcSafe(blue.microcosm.repo.getRecordByUri, {
297 headers: { 'User-Agent': 'npmx' },
298 params: { at_uri: profileUri },
299 })
300
301 if (profileResult.success) {
302 return profileResult.body.value
303 } else {
304 const profile = {
305 displayName: handle,
306 }
307
308 await client.createRecord(
309 {
310 $type: 'dev.npmx.actor.profile',
311 ...profile,
312 },
313 'self',
314 )
315
316 return profile
317 }
318}

Callers 1

atproto.get.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected