@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 60 lines 2.2 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3 import type { PolicyStatement } from "../IAM/Policy.ts";
4
5 /**
6 * Shared HTTP scaffolding for the AWS Account Management runtime bindings.
7 *
8 * Account Management is an account-singleton global service: every runtime
9 * operation reads settings of the calling account (account information,
10 * primary/alternate contacts, Region opt statuses), so every binding is
11 * account-level and grants its action(s) on `Resource: ["*"]` (the account
12 * ARN is the caller's own account, fixed by the credentials rather than
13 * chosen per resource).
14 *
15 * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is
16 * a `Layer.effect(Cap, makeAccountHttpBinding({ … }))` over the builder
17 * below. Everything except the operation and the IAM action list is
18 * boilerplate.
19 */
20 export const makeAccountHttpBinding = <I, A, E, R>(options: {
21 /**
22 * Short capability name used in the binding sid and runtime span, e.g.
23 * `"GetContactInformation"`.
24 */
25 capability: string;
26 /**
27 * IAM actions granted on `Resource: ["*"]` (Account Management operations
28 * target the calling account itself).
29 */
30 iamActions: readonly string[];
31 /**
32 * The distilled operation implementing the capability.
33 */
34 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
35 }) =>
36 Effect.gen(function* () {
37 const bind = yield* AWSBindings.Bind;
38 const op = yield* AWSBindings.withCredentials(options.operation);
39
40 return Effect.fn(function* () {
41 if (!globalThis.__ALCHEMY_RUNTIME__) {
42 const policyStatements: PolicyStatement[] = [
43 {
44 Effect: "Allow",
45 Action: [...options.iamActions],
46 // Account Management operations act on the calling account
47 // itself (identified by the credentials, not a per-resource
48 // ARN chosen at deploy time).
49 Resource: ["*"],
50 },
51 ];
52 yield* bind`AWS.Account.${options.capability}()`({
53 policyStatements,
54 });
55 }
56 return Effect.fn(`AWS.Account.${options.capability}`)(function* (request?: I) {
57 return yield* op((request ?? {}) as I);
58 });
59 });
60 });