(organizationId: string, context: Context.Context<WorkOSClient>)
| 213 | */ |
| 214 | export const emailResolver = |
| 215 | (organizationId: string, context: Context.Context<WorkOSClient>): AdminEmailResolver => |
| 216 | (email) => |
| 217 | Effect.gen(function* () { |
| 218 | const workos = yield* WorkOSClient; |
| 219 | const memberships = yield* workos.listOrgMembers(organizationId); |
| 220 | const userIds = memberships.data.map((membership) => membership.userId); |
| 221 | |
| 222 | // Short-circuits on the first match: `Effect.findFirst` stops fetching |
| 223 | // once a user's email matches, so the common case costs far fewer reads |
| 224 | // than the member count. |
| 225 | const match = yield* Effect.findFirst(userIds, (userId) => |
| 226 | workos.getUser(userId).pipe( |
| 227 | Effect.map((user) => normalizeAdminUserEmail(user.email ?? "") === email), |
| 228 | // One unreadable user must not fail the whole lookup — it simply |
| 229 | // cannot be the match. |
| 230 | Effect.catchCause(() => Effect.succeed(false)), |
| 231 | ), |
| 232 | ); |
| 233 | return Option.getOrNull(match); |
| 234 | }).pipe(Effect.provideContext(context)); |
| 235 | |
| 236 | /** Both directions of cloud's directory, built once per authorized request. */ |
| 237 | const userDirectory = ( |
no outgoing calls