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 { Flow } from "./Flow.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared scaffolding for AWS Elemental MediaConnect HTTP 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: flow-scoped bindings inject the bound flow's ARN as the |
| 12 | * request's `FlowArn` and grant `actions` on that ARN; account-scoped |
| 13 | * bindings pass the request through and grant `actions` on `*`. |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Build the impl Effect for a MediaConnect operation scoped to a |
| 18 | * {@link Flow}: the deploy-time half grants `actions` on the bound flow's |
| 19 | * ARN (plus any `extraResources` — e.g. the entitlement wildcard for |
| 20 | * Grant/RevokeFlowEntitlement, whose IAM resource types are both the flow |
| 21 | * AND the entitlement, a sibling ARN not derived from the flow ARN), and |
| 22 | * the runtime half injects the flow's ARN into every request as `FlowArn`. |
| 23 | */ |
| 24 | export const makeMediaConnectFlowHttpBinding = <I extends { FlowArn: string }, A, E, R>(options: { |
| 25 | /** Fully-qualified binding tag, e.g. `AWS.MediaConnect.StartFlow`. */ |
| 26 | tag: string; |
| 27 | /** The distilled operation; `FlowArn` is injected from the flow. */ |
| 28 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 29 | /** IAM actions granted on the flow ARN + `extraResources`. */ |
| 30 | actions: readonly string[]; |
| 31 | /** |
| 32 | * Additional IAM resource ARNs granted alongside the flow ARN — for |
| 33 | * operations whose IAM resource types include more than the flow (e.g. |
| 34 | * entitlement ops act on `…:entitlement:*` ARNs too). |
| 35 | */ |
| 36 | extraResources?: readonly string[]; |
| 37 | }) => |
| 38 | Effect.gen(function* () { |
| 39 | const bind = yield* AWSBindings.Bind; |
| 40 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 41 | |
| 42 | return Effect.fn(function* (flow: Flow) { |
| 43 | const FlowArn = yield* flow.flowArn; |
| 44 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 45 | yield* bind`${options.tag}(${flow})`({ |
| 46 | policyStatements: [ |
| 47 | { |
| 48 | Effect: "Allow", |
| 49 | Action: [...options.actions], |
| 50 | Resource: [flow.flowArn, ...(options.extraResources ?? [])], |
| 51 | }, |
| 52 | ], |
| 53 | }); |
| 54 | } |
| 55 | return Effect.fn(`${options.tag}(${flow.LogicalId})`)(function* ( |
| 56 | request?: Omit<I, "FlowArn">, |
| 57 | ) { |
| 58 | const flowArn = yield* FlowArn; |
| 59 | return yield* op({ ...request, FlowArn: flowArn } as I); |
| 60 | }); |
| 61 | }); |
| 62 | }); |
| 63 | |
| 64 | /** |
| 65 | * Build the impl Effect for an account-level MediaConnect operation (e.g. |
| 66 | * enumerating the account's flows or granted entitlements). The |
| 67 | * deploy-time half grants `actions` on `*` — these list operations are |
| 68 | * not scoped to a single flow resource. |
| 69 | */ |
| 70 | export const makeMediaConnectAccountHttpBinding = <I, A, E, R>(options: { |
| 71 | /** Fully-qualified binding tag, e.g. `AWS.MediaConnect.ListFlows`. */ |
| 72 | tag: string; |
| 73 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 74 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 75 | /** IAM actions granted on `*`. */ |
| 76 | actions: readonly string[]; |
| 77 | }) => |
| 78 | Effect.gen(function* () { |
| 79 | const bind = yield* AWSBindings.Bind; |
| 80 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 81 | |
| 82 | return Effect.fn(function* () { |
| 83 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 84 | yield* bind`${options.tag}()`({ |
| 85 | policyStatements: [ |
| 86 | { |
| 87 | Effect: "Allow", |
| 88 | Action: [...options.actions], |
| 89 | Resource: ["*"], |
| 90 | }, |
| 91 | ], |
| 92 | }); |
| 93 | } |
| 94 | return Effect.fn(options.tag)(function* (request?: I) { |
| 95 | return yield* op((request ?? {}) as I); |
| 96 | }); |
| 97 | }); |
| 98 | }); |