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

Function withPlatformView

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

Source from the content-addressed store, hash-verified

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