( headers: AdminUsersHeaders, body: (executor: Executor, organizationId: string) => Effect.Effect<A, E>, )
| 248 | * I/O isolation forbids sharing across requests. |
| 249 | */ |
| 250 | const 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 |
no test coverage detected