| 313 | * the `getUser` contract docs for why. |
| 314 | */ |
| 315 | export const getUser = ( |
| 316 | admin: ExecutorAdmin, |
| 317 | identifier: string, |
| 318 | directory?: AdminIdentityDirectory | AdminUserDirectory, |
| 319 | ): Effect.Effect<typeof AdminUserResponse.Type, AdminUsersError | AdminUserNotFound> => |
| 320 | Effect.gen(function* () { |
| 321 | const dir = asDirectory(directory); |
| 322 | const read = (externalId: string) => |
| 323 | admin.getSubjectWithConnections(externalId).pipe(Effect.mapError(readFailed("user"))); |
| 324 | |
| 325 | const subject = yield* identifier.includes("@") |
| 326 | ? Effect.gen(function* () { |
| 327 | const resolved = yield* resolveEmailFilter(dir, normalizeEmail(identifier)); |
| 328 | const byEmail = resolved === null ? null : yield* read(resolved); |
| 329 | return byEmail ?? (yield* read(identifier)); |
| 330 | }) |
| 331 | : read(identifier); |
| 332 | |
| 333 | if (subject === null) return yield* new AdminUserNotFound(); |
| 334 | |
| 335 | // Identity is joined through the SAME batched seam the list uses, so the |
| 336 | // single read reports exactly the fields the list would for this row. |
| 337 | const identities = yield* resolveIdentities(dir.identities, [subject.externalId]); |
| 338 | return { user: toUserWithConnections(subject, identities) }; |
| 339 | }); |
| 340 | |
| 341 | export const listUserConnections = ( |
| 342 | admin: ExecutorAdmin, |