The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | /** |
| 3 | * Shared scaffolding for EventBridge Pipes HTTP bindings. |
| 4 | * |
| 5 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 6 | * a `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the builders |
| 7 | * below. Everything except the operation and the IAM action list is |
| 8 | * boilerplate: |
| 9 | * |
| 10 | * - Pipe-scoped operations (`pipes:DescribePipe`, `pipes:StartPipe`, |
| 11 | * `pipes:StopPipe`) inject the bound {@link Pipe}'s name as the request's |
| 12 | * `Name` field and are granted on the pipe ARN. |
| 13 | * - Account-level operations (`pipes:ListPipes`) take the caller's request |
| 14 | * as-is and are granted on `*`. |
| 15 | */ |
| 16 | import * as AWSBindings from "../AWSBindings.ts"; |
| 17 | import type { Pipe } from "./Pipe.ts"; |
| 18 | |
| 19 | /** |
| 20 | * Build the impl Effect for a Pipes operation scoped to a {@link Pipe}: the |
| 21 | * deploy-time half grants `actions` on the bound pipe's ARN, and the runtime |
| 22 | * half injects the pipe's name as the request's `Name` field. |
| 23 | */ |
| 24 | export const makePipesHttpBinding = <I extends { Name: string }, A, E, R>(options: { |
| 25 | /** Fully-qualified binding tag, e.g. `AWS.Pipes.StartPipe`. */ |
| 26 | tag: string; |
| 27 | /** The distilled operation; `Name` is injected from the pipe. */ |
| 28 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 29 | /** IAM actions granted on the pipe ARN. */ |
| 30 | actions: readonly string[]; |
| 31 | }) => |
| 32 | Effect.gen(function* () { |
| 33 | const bind = yield* AWSBindings.Bind; |
| 34 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 35 | |
| 36 | return Effect.fn(function* (pipe: Pipe) { |
| 37 | const PipeName = yield* pipe.pipeName; |
| 38 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 39 | yield* bind`${options.tag}(${pipe})`({ |
| 40 | policyStatements: [ |
| 41 | { |
| 42 | Effect: "Allow", |
| 43 | Action: [...options.actions], |
| 44 | Resource: [pipe.pipeArn], |
| 45 | }, |
| 46 | ], |
| 47 | }); |
| 48 | } |
| 49 | return Effect.fn(`${options.tag}(${pipe.LogicalId})`)(function* (request?: Omit<I, "Name">) { |
| 50 | return yield* op({ |
| 51 | ...request, |
| 52 | Name: yield* PipeName, |
| 53 | } as I); |
| 54 | }); |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | /** |
| 59 | * Build the impl Effect for an account-level Pipes operation (pipe listing). |
| 60 | * The deploy-time half grants `actions` on `*` — these operations are not |
| 61 | * scoped to a single pipe resource. |
| 62 | */ |
| 63 | export const makePipesAccountHttpBinding = <I, A, E, R>(options: { |
| 64 | /** Fully-qualified binding tag, e.g. `AWS.Pipes.ListPipes`. */ |
| 65 | tag: string; |
| 66 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 67 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 68 | /** IAM actions granted on `*`. */ |
| 69 | actions: readonly string[]; |
| 70 | }) => |
| 71 | Effect.gen(function* () { |
| 72 | const bind = yield* AWSBindings.Bind; |
| 73 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 74 | |
| 75 | return Effect.fn(function* () { |
| 76 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 77 | yield* bind`${options.tag}()`({ |
| 78 | policyStatements: [ |
| 79 | { |
| 80 | Effect: "Allow", |
| 81 | Action: [...options.actions], |
| 82 | Resource: ["*"], |
| 83 | }, |
| 84 | ], |
| 85 | }); |
| 86 | } |
| 87 | return Effect.fn(options.tag)(function* (request?: I) { |
| 88 | return yield* op((request ?? {}) as I); |
| 89 | }); |
| 90 | }); |
| 91 | }); |