| 352 | * the `getUser` contract docs for why. |
| 353 | */ |
| 354 | export const getUser = ( |
| 355 | admin: ExecutorAdmin, |
| 356 | identifier: string, |
| 357 | directory?: AdminIdentityDirectory | AdminUserDirectory, |
| 358 | ): Effect.Effect<typeof AdminUserResponse.Type, AdminUsersError | AdminUserNotFound> => |
| 359 | Effect.gen(function* () { |
| 360 | const dir = asDirectory(directory); |
| 361 | const read = (externalId: string) => |
| 362 | admin.getSubjectWithConnections(externalId).pipe(Effect.mapError(readFailed("user"))); |
| 363 | |
| 364 | const subject = yield* identifier.includes("@") |
| 365 | ? Effect.gen(function* () { |
| 366 | const resolved = yield* resolveEmailFilter(dir, normalizeEmail(identifier)); |
| 367 | const byEmail = resolved === null ? null : yield* read(resolved); |
| 368 | return byEmail ?? (yield* read(identifier)); |
| 369 | }) |
| 370 | : read(identifier); |
| 371 | |
| 372 | if (subject === null) return yield* new AdminUserNotFound(); |
| 373 | |
| 374 | // Identity is joined through the SAME batched seam the list uses, so the |
| 375 | // single read reports exactly the fields the list would for this row. |
| 376 | const identities = yield* resolveIdentities(dir.identities, [subject.externalId]); |
| 377 | return { user: toUserWithConnections(subject, identities) }; |
| 378 | }); |
| 379 | |
| 380 | export const listUserConnections = ( |
| 381 | admin: ExecutorAdmin, |