import * as Effect from "effect/Effect"; import * as Binding from "../../Binding.ts"; import { isBindingHost } from "../Lambda/Function.ts"; /** * Shared scaffolding for AWS Rekognition HTTP bindings. * * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a * thin `Layer.effect(Cap, makeRekognitionHttpBinding({ … }))` over the * builder below. Everything except the operation and the IAM action list is * boilerplate: Rekognition's image/video analysis and collection data-plane * IAM actions are granted on `*` because the resources they touch * (collections, users, jobs) are routinely created at runtime — e.g. a * collection per application tenant — so their identifiers are unknown at * deploy time. */ export const makeRekognitionHttpBinding = (options: { /** Fully-qualified binding tag, e.g. `AWS.Rekognition.DetectLabels`. */ tag: string; /** The distilled operation, invoked with the caller's request as-is. */ operation: Effect.Effect<(input: I) => Effect.Effect, never, R>; /** IAM actions granted on `*`. */ actions: readonly string[]; }) => Effect.gen(function* () { const op = yield* options.operation; return Effect.fn(function* () { if (!globalThis.__ALCHEMY_RUNTIME__) { const host = yield* Binding.Host; if (isBindingHost(host)) { yield* host.bind`Allow(${host}, ${options.tag}())`({ policyStatements: [ { Effect: "Allow", Action: [...options.actions], Resource: ["*"], }, ], }); } } return Effect.fn(options.tag)(function* (request?: I) { return yield* op((request ?? {}) as I); }); }); });