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

Function identityDirectory

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

Source from the content-addressed store, hash-verified

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