The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { Profile } from "./Profile.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared scaffolding for Route 53 Profiles HTTP bindings. |
| 7 | * |
| 8 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 9 | * a `Layer.effect(Cap, makeProfilesHttpBinding({ … }))` over the builder |
| 10 | * below. Everything except the operation, the IAM action list, and the grant |
| 11 | * scope is boilerplate. |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * Build the impl Effect for a Route 53 Profiles operation scoped to a |
| 16 | * {@link Profile}: the deploy-time half grants `actions`, and the runtime |
| 17 | * half injects the profile's `ProfileId` into every request. |
| 18 | * |
| 19 | * The grant is on `*` — the Route 53 Profiles list actions follow the |
| 20 | * common AWS List-action pattern of not supporting resource-level |
| 21 | * permissions (a profile-ARN-scoped grant is rejected with AccessDenied). |
| 22 | */ |
| 23 | export const makeProfilesHttpBinding = <I extends { ProfileId?: string }, A, E, R>(options: { |
| 24 | /** Fully-qualified binding tag, e.g. `AWS.Route53Profiles.ListProfileAssociations`. */ |
| 25 | tag: string; |
| 26 | /** The distilled operation. */ |
| 27 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 28 | /** IAM actions granted by the binding. */ |
| 29 | actions: readonly string[]; |
| 30 | }) => |
| 31 | Effect.gen(function* () { |
| 32 | const bind = yield* AWSBindings.Bind; |
| 33 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 34 | |
| 35 | return Effect.fn(function* (profile: Profile) { |
| 36 | const ProfileId = yield* profile.profileId; |
| 37 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 38 | yield* bind`${options.tag}(${profile})`({ |
| 39 | policyStatements: [ |
| 40 | { |
| 41 | Effect: "Allow", |
| 42 | Action: [...options.actions], |
| 43 | Resource: ["*"], |
| 44 | }, |
| 45 | ], |
| 46 | }); |
| 47 | } |
| 48 | return Effect.fn(`${options.tag}(${profile.LogicalId})`)(function* ( |
| 49 | request?: Omit<I, "ProfileId">, |
| 50 | ) { |
| 51 | const profileId = yield* ProfileId; |
| 52 | return yield* op({ ...request, ProfileId: profileId } as I); |
| 53 | }); |
| 54 | }); |
| 55 | }); |