import * as Effect from "effect/Effect";
import * as AWSBindings from "../AWSBindings.ts";
/**
* Shared scaffolding for Amazon Inspector (Inspector2) HTTP bindings.
*
* NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
* a `Layer.effect(Cap, makeInspector2AccountHttpBinding({ … }))` over the
* builder below. Everything except the operation and the IAM action list is
* boilerplate.
*
* All Inspector2 runtime operations are account-scoped: the service's IAM
* actions do not support resource-level scoping (Inspector evaluates them
* against `*`), so the deploy-time half always grants `actions` on `*`.
*/
export const makeInspector2AccountHttpBinding = <I, A, E, R>(options: {
/** Fully-qualified binding tag, e.g. `AWS.Inspector2.ListFindings`. */
tag: string;
/** The distilled operation, invoked with the caller's request as-is. */
operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
/** IAM actions granted on `*`. */
actions: readonly string[];
}) =>
Effect.gen(function* () {
const bind = yield* AWSBindings.Bind;
const op = yield* AWSBindings.withCredentials(options.operation);
return Effect.fn(function* () {
if (!globalThis.__ALCHEMY_RUNTIME__) {
yield* bind`${options.tag}()`({
policyStatements: [
{
Effect: "Allow",
Action: [...options.actions],
Resource: ["*"],
},
],
});
}
return Effect.fn(options.tag)(function* (request?: I) {
return yield* op((request ?? {}) as I);
});
});
});