1import * as Effect from "effect/Effect";
2import * as Binding from "../../Binding.ts";
3import { isBindingHost } from "../Lambda/Function.ts";
4
5/**
6 * Shared HTTP scaffolding for the geo-routes runtime bindings.
7 *
8 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
9 * thin `Layer.effect(Cap, makeGeoRoutesHttpBinding({ … }))` over the builder
10 * below. Everything except the operation and the IAM action is boilerplate.
11 *
12 * geo-routes is a standalone, pay-per-call Amazon Location API with no
13 * resource to manage: every capability takes no arguments, and per the
14 * `geo-routes` service authorization reference all actions authorize through
15 * the singleton `provider/default` pseudo-resource, so grants use
16 * `Resource: ["*"]`.
17 */
18export const makeGeoRoutesHttpBinding = <I extends object, A, E, R>(options: {
19 /**
20 * Short capability name used in the binding sid and runtime span, e.g.
21 * `"CalculateRoutes"`.
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 op = yield* options.operation;
31
32 return Effect.fn(function* () {
33 if (!globalThis.__ALCHEMY_RUNTIME__) {
34 const host = yield* Binding.Host;
35 if (isBindingHost(host)) {
36 yield* host.bind`Allow(${host}, AWS.GeoRoutes.${options.capability}())`(
37 {
38 policyStatements: [
39 {
40 Effect: "Allow",
41 Action: [...options.iamActions],
42 Resource: ["*"],
43 },
44 ],
45 },
46 );
47 }
48 }
49 return Effect.fn(`AWS.GeoRoutes.${options.capability}`)(function* (
50 request: I,
51 ) {
52 return yield* op(request);
53 });
54 });
55 });