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
| 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 RAM runtime bindings. |
| 7 | * |
| 8 | * RAM (Resource Access Manager) is an account-scoped sharing service: every |
| 9 | * runtime operation targets resource shares, invitations, permissions, or |
| 10 | * shared resources that are chosen per request at runtime (invitation ARNs |
| 11 | * arrive from *other* accounts and are unknowable at deploy time), so every |
| 12 | * binding is account-level and grants its action(s) on `Resource: ["*"]`. |
| 13 | * |
| 14 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 15 | * a `Layer.effect(Cap, makeRAMHttpBinding({ … }))` over the builder below. |
| 16 | * Everything except the operation and the IAM action list is boilerplate. |
| 17 | */ |
| 18 | export const makeRAMHttpBinding = <I, A, E, R>(options: { |
| 19 | /** |
| 20 | * Short capability name used in the binding sid and runtime span, e.g. |
| 21 | * `"GetResourceShares"`. |
| 22 | */ |
| 23 | capability: string; |
| 24 | /** |
| 25 | * IAM actions granted on `Resource: ["*"]` (the target shares/invitations |
| 26 | * are chosen per request at runtime and unknowable at deploy time). |
| 27 | */ |
| 28 | iamActions: readonly string[]; |
| 29 | /** |
| 30 | * The distilled operation implementing the capability. |
| 31 | */ |
| 32 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 33 | }) => |
| 34 | Effect.gen(function* () { |
| 35 | const bind = yield* AWSBindings.Bind; |
| 36 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 37 | |
| 38 | return Effect.fn(function* () { |
| 39 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 40 | const policyStatements: PolicyStatement[] = [ |
| 41 | { |
| 42 | Effect: "Allow", |
| 43 | Action: [...options.iamActions], |
| 44 | // The target shares/invitations/permissions are chosen per |
| 45 | // request at runtime. |
| 46 | Resource: ["*"], |
| 47 | }, |
| 48 | ]; |
| 49 | yield* bind`AWS.RAM.${options.capability}()`({ |
| 50 | policyStatements, |
| 51 | }); |
| 52 | } |
| 53 | return Effect.fn(`AWS.RAM.${options.capability}`)(function* (request?: I) { |
| 54 | return yield* op((request ?? {}) as I); |
| 55 | }); |
| 56 | }); |
| 57 | }); |