@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 50 lines 1.89 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-places runtime bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeGeoPlacesHttpBinding({ … }))` over the builder
9 * below. Everything except the operation and the IAM action is boilerplate.
10 *
11 * geo-places is a standalone, pay-per-call Amazon Location API with no
12 * resource to manage: every action authorizes account-wide through the
13 * singleton `provider/default`, so the builder always grants on
14 * `Resource: ["*"]` and the capability takes no arguments.
15 */
16 export const makeGeoPlacesHttpBinding = <I extends object, A, E, R>(options: {
17 /**
18 * Short capability name used in the binding sid and runtime span, e.g.
19 * `"Geocode"`.
20 */
21 capability: string;
22 /** IAM actions granted on `Resource: ["*"]`. */
23 iamActions: readonly string[];
24 /** The distilled operation implementing the capability. */
25 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
26 }) =>
27 Effect.gen(function* () {
28 const bind = yield* AWSBindings.Bind;
29 const op = yield* AWSBindings.withCredentials(options.operation);
30
31 return Effect.fn(function* () {
32 if (!globalThis.__ALCHEMY_RUNTIME__) {
33 yield* bind`AWS.GeoPlaces.${options.capability}()`({
34 policyStatements: [
35 {
36 Effect: "Allow",
37 Action: [...options.iamActions],
38 // geo-places is a standalone, account-wide pay-per-call API
39 // scoped through the singleton `provider/default`; the
40 // operations have no per-resource ARN.
41 Resource: ["*"],
42 },
43 ],
44 });
45 }
46 return Effect.fn(`AWS.GeoPlaces.${options.capability}`)(function* (request: I) {
47 return yield* op(request);
48 });
49 });
50 });