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 Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { ResponsePlan } from "./ResponsePlan.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared scaffolding for AWS Systems Manager Incident Manager HTTP bindings. |
| 7 | * |
| 8 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 9 | * a `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two builders |
| 10 | * below. Everything except the operation and the IAM action list is |
| 11 | * boilerplate. |
| 12 | */ |
| 13 | |
| 14 | /** |
| 15 | * Build the impl Effect for an operation scoped to a {@link ResponsePlan} |
| 16 | * (`StartIncident`): the deploy-time half grants `actions` on the bound |
| 17 | * response plan's ARN and the runtime half injects the plan's |
| 18 | * `responsePlanArn` into every request. |
| 19 | */ |
| 20 | export const makeIncidentsResponsePlanHttpBinding = < |
| 21 | I extends { responsePlanArn: string }, |
| 22 | A, |
| 23 | E, |
| 24 | R, |
| 25 | >(options: { |
| 26 | /** Fully-qualified binding tag, e.g. `AWS.SSMIncidents.StartIncident`. */ |
| 27 | tag: string; |
| 28 | /** The distilled operation; `responsePlanArn` is injected from the plan. */ |
| 29 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 30 | /** IAM actions granted on the response plan 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* (plan: ResponsePlan) { |
| 38 | const ResponsePlanArn = yield* plan.arn; |
| 39 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 40 | yield* bind`${options.tag}(${plan})`({ |
| 41 | policyStatements: [ |
| 42 | { |
| 43 | Effect: "Allow", |
| 44 | Action: [...options.actions], |
| 45 | Resource: [plan.arn], |
| 46 | }, |
| 47 | ], |
| 48 | }); |
| 49 | } |
| 50 | return Effect.fn(`${options.tag}(${plan.LogicalId})`)(function* ( |
| 51 | request?: Omit<I, "responsePlanArn">, |
| 52 | ) { |
| 53 | return yield* op({ |
| 54 | ...request, |
| 55 | responsePlanArn: yield* ResponsePlanArn, |
| 56 | } as I); |
| 57 | }); |
| 58 | }); |
| 59 | }); |
| 60 | |
| 61 | /** |
| 62 | * Build the impl Effect for an incident-record-plane operation (incident |
| 63 | * records, timeline events, related items, findings). Incident records are |
| 64 | * runtime entities — their ARNs embed the response-plan name plus a UUID |
| 65 | * minted when the incident starts — so there is no deployed resource to |
| 66 | * scope the grant to and the deploy-time half grants `actions` on `*`. The |
| 67 | * runtime callable passes the caller's request through unchanged. |
| 68 | */ |
| 69 | export const makeIncidentsAccountHttpBinding = <I, A, E, R>(options: { |
| 70 | /** Fully-qualified binding tag, e.g. `AWS.SSMIncidents.GetIncidentRecord`. */ |
| 71 | tag: string; |
| 72 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 73 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 74 | /** IAM actions granted on `*`. */ |
| 75 | actions: readonly string[]; |
| 76 | }) => |
| 77 | Effect.gen(function* () { |
| 78 | const bind = yield* AWSBindings.Bind; |
| 79 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 80 | |
| 81 | return Effect.fn(function* () { |
| 82 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 83 | yield* bind`${options.tag}()`({ |
| 84 | policyStatements: [ |
| 85 | { |
| 86 | Effect: "Allow", |
| 87 | Action: [...options.actions], |
| 88 | Resource: ["*"], |
| 89 | }, |
| 90 | ], |
| 91 | }); |
| 92 | } |
| 93 | return Effect.fn(options.tag)(function* (request: I) { |
| 94 | return yield* op(request); |
| 95 | }); |
| 96 | }); |
| 97 | }); |