(organizationId: string, context: Context.Context<WorkOSClient>)
| 206 | */ |
| 207 | export const emailResolver = |
| 208 | (organizationId: string, context: Context.Context<WorkOSClient>): AdminEmailResolver => |
| 209 | (email) => |
| 210 | Effect.gen(function* () { |
| 211 | const workos = yield* WorkOSClient; |
| 212 | |
| 213 | if (!env.WORKOS_API_URL) { |
| 214 | const users = yield* workos.listUsers({ email, organizationId }); |
| 215 | return users.data[0]?.id ?? null; |
| 216 | } |
| 217 | |
| 218 | const memberships = yield* workos.listOrgMembers(organizationId); |
| 219 | const userIds = memberships.data.map((membership) => membership.userId); |
| 220 | |
| 221 | // Emulator compatibility only. Short-circuit once the normalized email |
| 222 | // matches so the fallback makes as few unsupported-detail reads as it can. |
| 223 | const match = yield* Effect.findFirst(userIds, (userId) => |
| 224 | workos.getUser(userId).pipe( |
| 225 | Effect.map((user) => normalizeAdminUserEmail(user.email ?? "") === email), |
| 226 | // One unreadable user must not fail the whole lookup — it simply |
| 227 | // cannot be the match. |
| 228 | Effect.catchCause(() => Effect.succeed(false)), |
| 229 | ), |
| 230 | ); |
| 231 | return Option.getOrNull(match); |
| 232 | }).pipe(Effect.provideContext(context)); |
| 233 | |
| 234 | /** Both directions of cloud's directory, built once per authorized request. */ |
| 235 | const userDirectory = ( |
no outgoing calls