@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 59 lines 2.12 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as AWSBindings from "../AWSBindings.ts";
3
4 /**
5 * Shared scaffolding for AWS OpenSearch Service HTTP bindings.
6 *
7 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
8 * thin `Layer.effect(Cap, makeOpenSearchHttpBinding({ … }))` over the builder
9 * below. Everything except the operation and the IAM action list is
10 * boilerplate.
11 *
12 * The bindings are account-level (the runtime request carries the
13 * `DomainName`) rather than domain-scoped: domain names are frequently
14 * runtime data — an operator Lambda watches every domain in the account, not
15 * one resource-bound domain — and OpenSearch domains take 15-25 minutes to
16 * provision, so a deploy-time resource resolution would gate every consumer
17 * on a live domain.
18 */
19
20 /**
21 * Build the impl Effect for an OpenSearch configuration-API operation. The
22 * deploy-time half grants `actions` on `resources` (default `*` — domain
23 * names addressed at runtime are data, so the grant cannot be narrowed to a
24 * deploy-time ARN).
25 */
26 export const makeOpenSearchHttpBinding = <I, A, E, R>(options: {
27 /** Fully-qualified binding tag, e.g. `AWS.OpenSearch.DescribeDomain`. */
28 tag: string;
29 /** The distilled operation, invoked with the caller's request as-is. */
30 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
31 /** IAM actions granted. */
32 actions: readonly string[];
33 /**
34 * IAM resources the actions are granted on.
35 * @default ["*"]
36 */
37 resources?: readonly string[];
38 }) =>
39 Effect.gen(function* () {
40 const bind = yield* AWSBindings.Bind;
41 const op = yield* AWSBindings.withCredentials(options.operation);
42
43 return Effect.fn(function* () {
44 if (!globalThis.__ALCHEMY_RUNTIME__) {
45 yield* bind`${options.tag}()`({
46 policyStatements: [
47 {
48 Effect: "Allow",
49 Action: [...options.actions],
50 Resource: [...(options.resources ?? ["*"])],
51 },
52 ],
53 });
54 }
55 return Effect.fn(options.tag)(function* (request?: I) {
56 return yield* op((request ?? {}) as I);
57 });
58 });
59 });