The best way to control Claude Code, Codex and more from any computer or phone

main
ts 46 lines 1.71 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared scaffolding for AWS Shield HTTP bindings.
6 *
7 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
8 * a `Layer.effect(Cap, makeShieldHttpBinding({ … }))` over the builder below.
9 * Everything except the operation and the IAM action list is boilerplate.
10 *
11 * Shield is an account-level, us-east-1-pinned service: its IAM actions do
12 * not support resource-level permissions for the visibility operations bound
13 * here (attacks, subscription state, DRT access), and the group-membership
14 * read targets groups whose ids are only known at runtime — so the
15 * deploy-time half grants `actions` on `*` and the caller's request passes
16 * through as-is.
17 */
18 export const makeShieldHttpBinding = <I, A, E, R>(options: {
19 /** Fully-qualified binding tag, e.g. `AWS.Shield.ListAttacks`. */
20 tag: string;
21 /** The distilled operation, invoked with the caller's request as-is. */
22 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
23 /** IAM actions granted on `*`. */
24 actions: readonly string[];
25 }) =>
26 Effect.gen(function* () {
27 const bind = yield* AWSBindings.Bind;
28 const op = yield* AWSBindings.withCredentials(options.operation);
29
30 return Effect.fn(function* () {
31 if (!globalThis.__ALCHEMY_RUNTIME__) {
32 yield* bind`${options.tag}()`({
33 policyStatements: [
34 {
35 Effect: "Allow",
36 Action: [...options.actions],
37 Resource: ["*"],
38 },
39 ],
40 });
41 }
42 return Effect.fn(options.tag)(function* (request?: I) {
43 return yield* op((request ?? {}) as I);
44 });
45 });
46 });