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

main
ts 48 lines 1.72 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared HTTP scaffolding for the geo-maps runtime bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeGeoMapsHttpBinding({ … }))` over the builder
9 * below. Everything except the operation and the IAM action is boilerplate.
10 *
11 * geo-maps is a standalone, pay-per-call Amazon Location API with no
12 * resource to manage: every capability takes no arguments, and per the
13 * `geo-maps` service authorization reference all actions authorize through
14 * the singleton `provider/default` pseudo-resource, so grants use
15 * `Resource: ["*"]`.
16 */
17 export const makeGeoMapsHttpBinding = <I extends object, A, E, R>(options: {
18 /**
19 * Short capability name used in the binding sid and runtime span, e.g.
20 * `"GetStaticMap"`.
21 */
22 capability: string;
23 /** IAM actions granted on `Resource: ["*"]`. */
24 iamActions: readonly string[];
25 /** The distilled operation implementing the capability. */
26 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
27 }) =>
28 Effect.gen(function* () {
29 const bind = yield* AWSBindings.Bind;
30 const op = yield* AWSBindings.withCredentials(options.operation);
31
32 return Effect.fn(function* () {
33 if (!globalThis.__ALCHEMY_RUNTIME__) {
34 yield* bind`AWS.GeoMaps.${options.capability}()`({
35 policyStatements: [
36 {
37 Effect: "Allow",
38 Action: [...options.iamActions],
39 Resource: ["*"],
40 },
41 ],
42 });
43 }
44 return Effect.fn(`AWS.GeoMaps.${options.capability}`)(function* (request: I) {
45 return yield* op(request);
46 });
47 });
48 });