| 430 | * the `getUser` contract docs for why. |
| 431 | */ |
| 432 | export const getUser = ( |
| 433 | admin: ExecutorAdmin, |
| 434 | identifier: string, |
| 435 | directory?: AdminIdentityDirectory | AdminUserDirectory, |
| 436 | ): Effect.Effect<typeof AdminUserResponse.Type, AdminUsersError | AdminUserNotFound> => |
| 437 | Effect.gen(function* () { |
| 438 | const dir = asDirectory(directory); |
| 439 | const read = (externalId: string) => |
| 440 | admin.getSubjectWithConnections(externalId).pipe(Effect.mapError(readFailed("user"))); |
| 441 | |
| 442 | const subject = yield* identifier.includes("@") |
| 443 | ? Effect.gen(function* () { |
| 444 | const resolved = yield* resolveEmailFilter(dir, normalizeEmail(identifier)); |
| 445 | const byEmail = resolved === null ? null : yield* read(resolved); |
| 446 | return byEmail ?? (yield* read(identifier)); |
| 447 | }) |
| 448 | : read(identifier); |
| 449 | |
| 450 | if (subject === null) return yield* new AdminUserNotFound(); |
| 451 | |
| 452 | // Identity is joined through the SAME batched seam the list uses, so the |
| 453 | // single read reports exactly the fields the list would for this row. |
| 454 | const identities = yield* resolveIdentities(dir.identities, [subject.externalId]); |
| 455 | return { user: toUserWithConnections(subject, identities) }; |
| 456 | }); |
| 457 | |
| 458 | export const listUserConnections = ( |
| 459 | admin: ExecutorAdmin, |