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 | |
| 4 | /** |
| 5 | * Shared scaffolding for AWS CloudHSM (v2) HTTP bindings. |
| 6 | * |
| 7 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 8 | * thin `Layer.effect(Cap, makeCloudHsmHttpBinding({ … }))` over the builder |
| 9 | * below. Everything except the operation and the IAM action list is |
| 10 | * boilerplate. |
| 11 | * |
| 12 | * All CloudHSM bindings are account-level: the identifiers the operations |
| 13 | * act on (cluster ids, backup ids, backup ARNs) are runtime data produced by |
| 14 | * the service itself — backups are auto-created, ids are auto-assigned and |
| 15 | * the API exposes no resource ARNs on clusters — so the deploy-time half |
| 16 | * grants `actions` on `*`. |
| 17 | */ |
| 18 | export const makeCloudHsmHttpBinding = <I, A, E, R>(options: { |
| 19 | /** Fully-qualified binding tag, e.g. `AWS.CloudHSMV2.DescribeClusters`. */ |
| 20 | tag: string; |
| 21 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 22 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 23 | /** IAM actions granted on `*`. */ |
| 24 | actions: readonly string[]; |
| 25 | }) => |
| 26 | Effect.gen(function* () { |
| 27 | const bind = yield* AWSBindings.Bind; |
| 28 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 29 | |
| 30 | return Effect.fn(function* () { |
| 31 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 32 | yield* bind`${options.tag}()`({ |
| 33 | policyStatements: [ |
| 34 | { |
| 35 | Effect: "Allow", |
| 36 | Action: [...options.actions], |
| 37 | Resource: ["*"], |
| 38 | }, |
| 39 | ], |
| 40 | }); |
| 41 | } |
| 42 | return Effect.fn(options.tag)(function* (request?: I) { |
| 43 | return yield* op((request ?? {}) as I); |
| 44 | }); |
| 45 | }); |
| 46 | }); |