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

Function emailResolver

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

Source from the content-addressed store, hash-verified

206 */
207export 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. */
235const userDirectory = (

Callers 2

resolveFunction · 0.90
userDirectoryFunction · 0.85

Calls

no outgoing calls

Tested by 1

resolveFunction · 0.72