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

Function withPlatformView

apps/cloud/src/admin/admin-users-api.ts:252–275  ·  view source on GitHub ↗
(
  headers: AdminUsersHeaders,
  body: (executor: Executor, organizationId: string) => Effect.Effect<A, E>,
)

Source from the content-addressed store, hash-verified

250 * I/O isolation forbids sharing across requests.
251 */
252const withPlatformView = <A, E extends AdminUsersError | AdminUserNotFound = AdminUsersError>(
253 headers: AdminUsersHeaders,
254 body: (executor: Executor, organizationId: string) => Effect.Effect<A, E>,
255): Effect.Effect<
256 A,
257 // `AdminUsersError` unconditionally: opening the platform view can fail that
258 // way regardless of what `body` itself raises.
259 E | AdminUsersError | AdminUsersUnauthorized | AdminUsersForbidden,
260 WorkOSClient | ApiKeyService | UserStoreService | DbProvider | PluginsProvider | HostConfig
261> =>
262 Effect.gen(function* () {
263 const organizationId = yield* authorizeTenant(
264 new Request("https://admin.invalid", { headers }),
265 );
266 const executor = yield* makePlatformExecutor(organizationId).pipe(
267 Effect.mapError(() => new AdminUsersError({ message: "Failed to open the platform view" })),
268 );
269 // The authorized tenant is handed to the body so an identity join reads the
270 // SAME org the reads are scoped to — never one named by client input.
271 return yield* Effect.ensuring(
272 body(executor, organizationId),
273 executor.close().pipe(Effect.ignore),
274 );
275 });
276
277/**
278 * Cloud's `AdminUsersProvider`, built per request so the platform executor

Callers 1

admin-users-api.tsFile · 0.70

Calls 3

makePlatformExecutorFunction · 0.90
authorizeTenantFunction · 0.85
closeMethod · 0.65

Tested by

no test coverage detected