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

main
ts 44 lines 1.63 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared scaffolding for AWS Rekognition HTTP bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeRekognitionHttpBinding({ … }))` over the
9 * builder below. Everything except the operation and the IAM action list is
10 * boilerplate: Rekognition's image/video analysis and collection data-plane
11 * IAM actions are granted on `*` because the resources they touch
12 * (collections, users, jobs) are routinely created at runtime — e.g. a
13 * collection per application tenant — so their identifiers are unknown at
14 * deploy time.
15 */
16 export const makeRekognitionHttpBinding = <I, A, E, R>(options: {
17 /** Fully-qualified binding tag, e.g. `AWS.Rekognition.DetectLabels`. */
18 tag: string;
19 /** The distilled operation, invoked with the caller's request as-is. */
20 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
21 /** IAM actions granted on `*`. */
22 actions: readonly string[];
23 }) =>
24 Effect.gen(function* () {
25 const bind = yield* AWSBindings.Bind;
26 const op = yield* AWSBindings.withCredentials(options.operation);
27
28 return Effect.fn(function* () {
29 if (!globalThis.__ALCHEMY_RUNTIME__) {
30 yield* bind`${options.tag}()`({
31 policyStatements: [
32 {
33 Effect: "Allow",
34 Action: [...options.actions],
35 Resource: ["*"],
36 },
37 ],
38 });
39 }
40 return Effect.fn(options.tag)(function* (request?: I) {
41 return yield* op((request ?? {}) as I);
42 });
43 });
44 });