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

main
ts 49 lines 1.78 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared HTTP scaffolding for the Lake Formation runtime bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeLakeFormationHttpBinding({ … }))` over the
9 * builder below. Everything except the operation and the IAM action list is
10 * boilerplate.
11 *
12 * Per the `lakeformation` service authorization reference, Lake Formation
13 * IAM actions support no resource types (authorization beyond IAM is
14 * enforced by Lake Formation's own permission grants — see
15 * `AWS.LakeFormation.Permissions`), so every binding grants its actions on
16 * `Resource: ["*"]`.
17 */
18 export const makeLakeFormationHttpBinding = <I extends object, A, E, R>(options: {
19 /**
20 * Short capability name used in the binding sid and runtime span, e.g.
21 * `"GetDataLakePrincipal"`.
22 */
23 capability: string;
24 /** IAM actions granted on `Resource: ["*"]`. */
25 iamActions: readonly string[];
26 /** The distilled operation implementing the capability. */
27 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
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* () {
34 if (!globalThis.__ALCHEMY_RUNTIME__) {
35 yield* bind`AWS.LakeFormation.${options.capability}()`({
36 policyStatements: [
37 {
38 Effect: "Allow",
39 Action: [...options.iamActions],
40 Resource: ["*"],
41 },
42 ],
43 });
44 }
45 return Effect.fn(`AWS.LakeFormation.${options.capability}`)(function* (request?: I) {
46 return yield* op((request ?? {}) as I);
47 });
48 });
49 });