@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 51 lines 1.83 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared scaffolding for Amazon DevOps Guru HTTP bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeDevOpsGuruAccountHttpBinding({ … }))` over the
9 * builder below. Everything except the operation and the IAM action is
10 * boilerplate.
11 *
12 * All DevOps Guru actions are account-level: the service does not support
13 * resource-level IAM permissions (insights, anomalies, and health summaries
14 * are account/region-scoped API objects, not ARN-addressable resources), so
15 * the deploy-time half always grants the action on `*`.
16 */
17
18 /**
19 * Build the impl Effect for an account-level DevOps Guru operation. The
20 * runtime callable passes the caller's request through unchanged; the
21 * deploy-time half grants `actions` on `*`.
22 */
23 export const makeDevOpsGuruAccountHttpBinding = <I, A, E, R>(options: {
24 /** Fully-qualified binding tag, e.g. `AWS.DevOpsGuru.ListInsights`. */
25 tag: string;
26 /** The distilled operation, invoked with the caller's request as-is. */
27 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
28 /** IAM actions granted on `*`. */
29 actions: readonly string[];
30 }) =>
31 Effect.gen(function* () {
32 const bind = yield* AWSBindings.Bind;
33 const op = yield* AWSBindings.withCredentials(options.operation);
34
35 return Effect.fn(function* () {
36 if (!globalThis.__ALCHEMY_RUNTIME__) {
37 yield* bind`${options.tag}()`({
38 policyStatements: [
39 {
40 Effect: "Allow",
41 Action: [...options.actions],
42 Resource: ["*"],
43 },
44 ],
45 });
46 }
47 return Effect.fn(options.tag)(function* (request?: I) {
48 return yield* op((request ?? {}) as I);
49 });
50 });
51 });