MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / emailResolver

Function emailResolver

apps/cloud/src/admin/admin-users-api.ts:215–234  ·  view source on GitHub ↗
(organizationId: string, context: Context.Context<WorkOSClient>)

Source from the content-addressed store, hash-verified

213 */
214export 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. */
237const userDirectory = (

Callers 3

resolveFunction · 0.90
userDirectoryFunction · 0.85

Calls

no outgoing calls

Tested by 1

resolveFunction · 0.72