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

Function withPlatformView

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

Source from the content-addressed store, hash-verified

126 * I/O isolation forbids sharing across requests.
127 */
128const withPlatformView = <A, E extends AdminUsersError | AdminUserNotFound = AdminUsersError>(
129 headers: AdminUsersHeaders,
130 body: (executor: Executor, organizationId: string) => Effect.Effect<A, E>,
131): Effect.Effect<
132 A,
133 // `AdminUsersError` unconditionally: opening the platform view can fail that
134 // way regardless of what `body` itself raises.
135 E | AdminUsersError | AdminUsersUnauthorized | AdminUsersForbidden,
136 | WorkOSClient
137 | ApiKeyService
138 | UserStoreService
139 | MemberDirectory
140 | WorkOsMirror
141 | DbProvider
142 | PluginsProvider
143 | HostConfig
144> =>
145 Effect.gen(function* () {
146 const organizationId = yield* authorizeTenant(
147 new Request("https://admin.invalid", { headers }),
148 );
149 const executor = yield* makePlatformExecutor(organizationId).pipe(
150 Effect.mapError(() => new AdminUsersError({ message: "Failed to open the platform view" })),
151 );
152 // The authorized tenant is handed to the body so the directory reads the
153 // SAME org the storage reads are scoped to — never one named by client
154 // input.
155 return yield* Effect.ensuring(
156 body(executor, organizationId),
157 executor.close().pipe(Effect.ignore),
158 );
159 });
160
161/**
162 * 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