@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 59 lines 2.09 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { PolicyStatement } from "../IAM/Policy.ts";
4
5 /**
6 * Shared HTTP scaffolding for the AWS Organizations runtime bindings.
7 *
8 * Organizations is a management-account-scoped global service: every runtime
9 * operation targets the caller's organization or entities within it (roots,
10 * OUs, accounts, policies, handshakes) that are chosen per request at
11 * runtime, so every binding is account-level and grants its action(s) on
12 * `Resource: ["*"]`.
13 *
14 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
15 * a `Layer.effect(Cap, makeOrganizationsHttpBinding({ … }))` over the builder
16 * below. Everything except the operation and the IAM action list is
17 * boilerplate.
18 */
19 export const makeOrganizationsHttpBinding = <I, A, E, R>(options: {
20 /**
21 * Short capability name used in the binding sid and runtime span, e.g.
22 * `"ListAccounts"`.
23 */
24 capability: string;
25 /**
26 * IAM actions granted on `Resource: ["*"]` (the target organization
27 * entities are chosen per request at runtime and unknowable at deploy
28 * time).
29 */
30 iamActions: readonly string[];
31 /**
32 * The distilled operation implementing the capability.
33 */
34 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
35 }) =>
36 Effect.gen(function* () {
37 const bind = yield* AWSBindings.Bind;
38 const op = yield* AWSBindings.withCredentials(options.operation);
39
40 return Effect.fn(function* () {
41 if (!globalThis.__ALCHEMY_RUNTIME__) {
42 const policyStatements: PolicyStatement[] = [
43 {
44 Effect: "Allow",
45 Action: [...options.iamActions],
46 // The target organization entities are chosen per request at
47 // runtime.
48 Resource: ["*"],
49 },
50 ];
51 yield* bind`AWS.Organizations.${options.capability}()`({
52 policyStatements,
53 });
54 }
55 return Effect.fn(`AWS.Organizations.${options.capability}`)(function* (request?: I) {
56 return yield* op((request ?? {}) as I);
57 });
58 });
59 });