@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 45 lines 1.61 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared scaffolding for X-Ray HTTP bindings.
6 *
7 * NOT exported from `index.ts` — every single-operation `{Op}Http.ts` in
8 * this service is a thin `Layer.effect(Cap, makeXRayHttpBinding({ … }))`
9 * over the builder below. Everything except the operation and the IAM
10 * action is boilerplate.
11 *
12 * X-Ray's trace, sampling, graph, and insight actions do not support
13 * resource-level permissions, so the deploy-time half of every binding
14 * grants its `actions` on `*` and the runtime callable passes the caller's
15 * request through unchanged.
16 */
17 export const makeXRayHttpBinding = <I, A, E, R>(options: {
18 /** Fully-qualified binding tag, e.g. `AWS.XRay.GetServiceGraph`. */
19 tag: string;
20 /** The distilled operation, invoked with the caller's request as-is. */
21 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
22 /** IAM actions granted on `*` (X-Ray has no resource-level permissions). */
23 actions: readonly string[];
24 }) =>
25 Effect.gen(function* () {
26 const bind = yield* AWSBindings.Bind;
27 const op = yield* AWSBindings.withCredentials(options.operation);
28
29 return Effect.fn(function* () {
30 if (!globalThis.__ALCHEMY_RUNTIME__) {
31 yield* bind`${options.tag}()`({
32 policyStatements: [
33 {
34 Effect: "Allow",
35 Action: [...options.actions],
36 Resource: ["*"],
37 },
38 ],
39 });
40 }
41 return Effect.fn(options.tag)(function* (request?: I) {
42 return yield* op((request ?? {}) as I);
43 });
44 });
45 });