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

main
ts 49 lines 1.82 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { DataLake } from "./DataLake.ts";
4
5 /**
6 * Shared scaffolding for Amazon Security Lake HTTP bindings.
7 *
8 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
9 * a `Layer.effect(Cap, makeSecurityLakeDataLakeHttpBinding({ … }))` over the
10 * builder below. Everything except the operation and the IAM action list is
11 * boilerplate.
12 */
13
14 /**
15 * Build the impl Effect for a Security Lake operation scoped to the account's
16 * {@link DataLake}: the deploy-time half grants `actions` on the bound data
17 * lake's ARN, and the runtime half invokes the operation with the caller's
18 * request as-is (Security Lake's monitoring operations take no resource
19 * parameter — the data lake is implicit in the account/Region).
20 */
21 export const makeSecurityLakeDataLakeHttpBinding = <I, A, E, R>(options: {
22 /** Fully-qualified binding tag, e.g. `AWS.SecurityLake.GetDataLakeSources`. */
23 tag: string;
24 /** The distilled operation. */
25 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
26 /** IAM actions granted on the data lake ARN. */
27 actions: readonly string[];
28 }) =>
29 Effect.gen(function* () {
30 const bind = yield* AWSBindings.Bind;
31 const op = yield* AWSBindings.withCredentials(options.operation);
32
33 return Effect.fn(function* (lake: DataLake) {
34 if (!globalThis.__ALCHEMY_RUNTIME__) {
35 yield* bind`${options.tag}(${lake})`({
36 policyStatements: [
37 {
38 Effect: "Allow",
39 Action: [...options.actions],
40 Resource: [lake.dataLakeArn],
41 },
42 ],
43 });
44 }
45 return Effect.fn(`${options.tag}(${lake.LogicalId})`)(function* (request?: I) {
46 return yield* op((request ?? {}) as I);
47 });
48 });
49 });