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, 06:00 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import { withRoute53DomainsRegion } from "./internal.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared HTTP scaffolding for the Route 53 Domains runtime bindings. |
| 7 | * |
| 8 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 9 | * thin `Layer.effect(Cap, makeRoute53DomainsHttpBinding({ … }))` over the |
| 10 | * builder below. Everything except the operation and the IAM action is |
| 11 | * boilerplate. |
| 12 | * |
| 13 | * Route 53 Domains is a global registration API with no resource-level IAM: |
| 14 | * every action authorizes account-wide, so the builder always grants on |
| 15 | * `Resource: ["*"]` and the capability takes no arguments. The API is only |
| 16 | * served from `us-east-1`, so the captured client is pinned to that region |
| 17 | * regardless of where the calling function runs. |
| 18 | */ |
| 19 | export const makeRoute53DomainsHttpBinding = <I extends object, A, E, R>(options: { |
| 20 | /** |
| 21 | * Short capability name used in the binding sid and runtime span, e.g. |
| 22 | * `"CheckDomainAvailability"`. |
| 23 | */ |
| 24 | capability: string; |
| 25 | /** IAM actions granted on `Resource: ["*"]`. */ |
| 26 | iamActions: readonly string[]; |
| 27 | /** The distilled operation implementing the capability. */ |
| 28 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 29 | }) => |
| 30 | Effect.gen(function* () { |
| 31 | const bind = yield* AWSBindings.Bind; |
| 32 | // Capture the client with the region pinned to us-east-1 — the Route 53 |
| 33 | // Domains API is not served from any other region. |
| 34 | const op = yield* options.operation.pipe(withRoute53DomainsRegion, AWSBindings.withCredentials); |
| 35 | |
| 36 | return Effect.fn(function* () { |
| 37 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 38 | yield* bind`AWS.Route53Domains.${options.capability}()`({ |
| 39 | policyStatements: [ |
| 40 | { |
| 41 | Effect: "Allow", |
| 42 | Action: [...options.iamActions], |
| 43 | // route53domains has no resource-level IAM |
| 44 | Resource: ["*"], |
| 45 | }, |
| 46 | ], |
| 47 | }); |
| 48 | } |
| 49 | return Effect.fn(`AWS.Route53Domains.${options.capability}`)(function* (request: I) { |
| 50 | // The region must also be pinned at the call site: the yield-time |
| 51 | // snapshot is only a fallback — the calling fiber's ambient Region |
| 52 | // (the host Function's own region) wins over it. |
| 53 | return yield* withRoute53DomainsRegion(op(request)); |
| 54 | }); |
| 55 | }); |
| 56 | }); |