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 Output from "alchemy/Output"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as AWSBindings from "../AWSBindings.ts"; |
| 4 | import type { Vault } from "./Vault.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared scaffolding for the Glacier runtime bindings. |
| 8 | * |
| 9 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 10 | * thin `Layer.effect(Cap, makeGlacierVaultHttpBinding({ … }))` over the |
| 11 | * builder below. Everything except the operation and the IAM action list is |
| 12 | * boilerplate: Glacier's REST API scopes every data-plane operation to a |
| 13 | * vault, so the runtime callable injects the bound {@link Vault}'s name (and |
| 14 | * the `-` account-id path segment, meaning "the account that signed the |
| 15 | * request") and the deploy-time half grants `actions` on the vault's ARN. |
| 16 | */ |
| 17 | export const makeGlacierVaultHttpBinding = < |
| 18 | I extends { accountId: string; vaultName: string }, |
| 19 | A, |
| 20 | E, |
| 21 | R, |
| 22 | >(options: { |
| 23 | /** Fully-qualified binding tag, e.g. `AWS.Glacier.UploadArchive`. */ |
| 24 | tag: string; |
| 25 | /** |
| 26 | * The distilled operation; `accountId` (always `-`) and `vaultName` are |
| 27 | * injected from the bound vault. |
| 28 | */ |
| 29 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 30 | /** IAM actions granted on the vault ARN. */ |
| 31 | actions: readonly string[]; |
| 32 | }) => |
| 33 | Effect.gen(function* () { |
| 34 | const bind = yield* AWSBindings.Bind; |
| 35 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 36 | |
| 37 | return Effect.fn(function* (vault: Vault) { |
| 38 | const vaultName = yield* vault.vaultName; |
| 39 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 40 | yield* bind`${options.tag}(${vault})`({ |
| 41 | policyStatements: [ |
| 42 | { |
| 43 | Effect: "Allow", |
| 44 | Action: [...options.actions], |
| 45 | Resource: [Output.interpolate`${vault.vaultArn}`], |
| 46 | }, |
| 47 | ], |
| 48 | }); |
| 49 | } |
| 50 | return Effect.fn(`${options.tag}(${vault.LogicalId})`)(function* ( |
| 51 | request?: Omit<I, "accountId" | "vaultName">, |
| 52 | ) { |
| 53 | return yield* op({ |
| 54 | ...request, |
| 55 | accountId: "-", |
| 56 | vaultName: yield* vaultName, |
| 57 | } as I); |
| 58 | }); |
| 59 | }); |
| 60 | }); |