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, 04:45 UTC
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { View } from "./View.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared HTTP scaffolding for the AWS Resource Explorer runtime bindings. |
| 7 | * |
| 8 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service |
| 9 | * is a `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two |
| 10 | * builders below. Everything except the operation and the IAM action list |
| 11 | * is boilerplate. |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * Build the impl Effect for a Resource Explorer operation scoped to a |
| 16 | * {@link View}: the deploy-time half grants `actions` on the bound view's |
| 17 | * ARN, and the runtime half injects the view's `ViewArn` into every |
| 18 | * request. |
| 19 | */ |
| 20 | export const makeResourceExplorerViewHttpBinding = < |
| 21 | I extends { ViewArn?: string }, |
| 22 | A, |
| 23 | E, |
| 24 | R, |
| 25 | >(options: { |
| 26 | /** Fully-qualified binding tag, e.g. `AWS.ResourceExplorer.Search`. */ |
| 27 | tag: string; |
| 28 | /** The distilled operation. */ |
| 29 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 30 | /** IAM actions granted on the view 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* <V extends View>(view: V) { |
| 38 | const ViewArn = yield* view.viewArn; |
| 39 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 40 | yield* bind`${options.tag}(${view})`({ |
| 41 | policyStatements: [ |
| 42 | { |
| 43 | Effect: "Allow", |
| 44 | Action: [...options.actions], |
| 45 | Resource: [view.viewArn], |
| 46 | }, |
| 47 | ], |
| 48 | }); |
| 49 | } |
| 50 | return Effect.fn(`${options.tag}(${view.LogicalId})`)(function* ( |
| 51 | request?: Omit<I, "ViewArn">, |
| 52 | ) { |
| 53 | const viewArn = yield* ViewArn; |
| 54 | return yield* op({ ...request, ViewArn: viewArn } as I); |
| 55 | }); |
| 56 | }); |
| 57 | }); |
| 58 | |
| 59 | /** |
| 60 | * Build the impl Effect for an account-level Resource Explorer operation |
| 61 | * (e.g. enumerating the searchable resource types). The deploy-time half |
| 62 | * grants `actions` on `*` — these operations are not scoped to a single |
| 63 | * Resource Explorer resource. |
| 64 | */ |
| 65 | export const makeResourceExplorerAccountHttpBinding = <I, A, E, R>(options: { |
| 66 | /** |
| 67 | * Fully-qualified binding tag, e.g. |
| 68 | * `AWS.ResourceExplorer.ListSupportedResourceTypes`. |
| 69 | */ |
| 70 | tag: string; |
| 71 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 72 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 73 | /** IAM actions granted on `*`. */ |
| 74 | actions: readonly string[]; |
| 75 | }) => |
| 76 | Effect.gen(function* () { |
| 77 | const bind = yield* AWSBindings.Bind; |
| 78 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 79 | |
| 80 | return Effect.fn(function* () { |
| 81 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 82 | yield* bind`${options.tag}()`({ |
| 83 | policyStatements: [ |
| 84 | { |
| 85 | Effect: "Allow", |
| 86 | Action: [...options.actions], |
| 87 | Resource: ["*"], |
| 88 | }, |
| 89 | ], |
| 90 | }); |
| 91 | } |
| 92 | return Effect.fn(options.tag)(function* (request?: I) { |
| 93 | return yield* op((request ?? {}) as I); |
| 94 | }); |
| 95 | }); |
| 96 | }); |