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

Function identityDirectory

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

Source from the content-addressed store, hash-verified

151 */
152const identityDirectory =
153 (organizationId: string, context: Context.Context<WorkOSClient>): AdminIdentityDirectory =>
154 (externalIds) =>
155 Effect.gen(function* () {
156 const workos = yield* WorkOSClient;
157 const memberships = yield* workos.listOrgMembers(organizationId);
158 const wanted = new Set(externalIds);
159 const memberIds = memberships.data
160 .map((membership) => membership.userId)
161 .filter((userId) => wanted.has(userId));
162
163 const resolved = yield* Effect.all(
164 memberIds.map((userId) =>
165 workos.getUser(userId).pipe(
166 Effect.map(
167 (user) =>
168 [
169 userId,
170 {
171 email: user.email,
172 displayName: [user.firstName, user.lastName].filter(Boolean).join(" ") || null,
173 },
174 ] as const,
175 ),
176 // One unreadable user must not cost the whole page its names.
177 Effect.catchCause(() => Effect.succeed(null)),
178 ),
179 ),
180 { concurrency: IDENTITY_CONCURRENCY },
181 );
182
183 const identities = new Map<string, AdminUserIdentity>();
184 for (const entry of resolved) if (entry) identities.set(entry[0], entry[1]);
185 return identities;
186 }).pipe(Effect.provideContext(context));
187
188/**
189 * Cloud's REVERSE directory lookup: email → the WorkOS `user_...` id.

Callers 1

userDirectoryFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected