| 285 | } |
| 286 | |
| 287 | async 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 | } |