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 { PolicyStatement } from "../IAM/Policy.ts"; |
| 5 | import type { Transformer } from "./Transformer.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Shared scaffolding for B2BI HTTP bindings. |
| 9 | * |
| 10 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 11 | * thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two |
| 12 | * builders below. Everything except the operation, the IAM action list, and |
| 13 | * the injected identifier is boilerplate. |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Build the impl Effect for a transformer-scoped operation: the runtime |
| 18 | * callable injects the bound {@link Transformer}'s ID as `transformerId` and |
| 19 | * the deploy-time half grants `actions` on the transformer ARN. |
| 20 | */ |
| 21 | export const makeTransformerScopedHttpBinding = < |
| 22 | I extends { transformerId: string }, |
| 23 | A, |
| 24 | E, |
| 25 | R, |
| 26 | >(options: { |
| 27 | /** Fully-qualified binding tag, e.g. `AWS.B2BI.StartTransformerJob`. */ |
| 28 | tag: string; |
| 29 | /** The distilled operation; `transformerId` is injected from the resource. */ |
| 30 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 31 | /** IAM actions granted on the transformer ARN. */ |
| 32 | actions: readonly string[]; |
| 33 | /** |
| 34 | * Companion statements the operation needs beyond the transformer-scoped |
| 35 | * b2bi action — B2BI reaches into S3 through the caller's session |
| 36 | * (forward-access), so e.g. `StartTransformerJob` needs S3 access on the |
| 37 | * host. |
| 38 | */ |
| 39 | companionStatements?: readonly PolicyStatement[]; |
| 40 | }) => |
| 41 | Effect.gen(function* () { |
| 42 | const bind = yield* AWSBindings.Bind; |
| 43 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 44 | |
| 45 | return Effect.fn(function* (transformer: Transformer) { |
| 46 | const TransformerId = yield* transformer.transformerId; |
| 47 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 48 | yield* bind`${options.tag}(${transformer})`({ |
| 49 | policyStatements: [ |
| 50 | { |
| 51 | Effect: "Allow", |
| 52 | Action: [...options.actions], |
| 53 | Resource: [Output.interpolate`${transformer.transformerArn}`], |
| 54 | }, |
| 55 | ...(options.companionStatements ?? []), |
| 56 | ], |
| 57 | }); |
| 58 | } |
| 59 | return Effect.fn(`${options.tag}(${transformer.LogicalId})`)(function* ( |
| 60 | request: Omit<I, "transformerId">, |
| 61 | ) { |
| 62 | return yield* op({ |
| 63 | ...request, |
| 64 | transformerId: yield* TransformerId, |
| 65 | } as I); |
| 66 | }); |
| 67 | }); |
| 68 | }); |
| 69 | |
| 70 | /** |
| 71 | * Build the impl Effect for an account-level operation (no target resource). |
| 72 | * The deploy-time half grants `actions` on `*` — B2BI's test/generate |
| 73 | * operations don't support resource-level scoping. |
| 74 | */ |
| 75 | export const makeB2biAccountHttpBinding = <I, A, E, R>(options: { |
| 76 | /** Fully-qualified binding tag, e.g. `AWS.B2BI.TestMapping`. */ |
| 77 | tag: string; |
| 78 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 79 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 80 | /** IAM actions granted on `*`. */ |
| 81 | actions: readonly string[]; |
| 82 | }) => |
| 83 | Effect.gen(function* () { |
| 84 | const bind = yield* AWSBindings.Bind; |
| 85 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 86 | |
| 87 | return Effect.fn(function* () { |
| 88 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 89 | yield* bind`${options.tag}()`({ |
| 90 | policyStatements: [ |
| 91 | { |
| 92 | Effect: "Allow", |
| 93 | Action: [...options.actions], |
| 94 | Resource: ["*"], |
| 95 | }, |
| 96 | ], |
| 97 | }); |
| 98 | } |
| 99 | return Effect.fn(options.tag)(function* (request: I) { |
| 100 | return yield* op(request); |
| 101 | }); |
| 102 | }); |
| 103 | }); |