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
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { Space } from "./Space.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared scaffolding for the re:Post Private runtime bindings. |
| 7 | * |
| 8 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 9 | * thin `Layer.effect(Cap, makeRePostSpaceHttpBinding({ … }))` over the |
| 10 | * builder below. Everything except the operation and the IAM action list is |
| 11 | * boilerplate: every re:Post Private data-plane operation is scoped to a |
| 12 | * space, so the runtime callable injects the bound {@link Space}'s `spaceId` |
| 13 | * and the deploy-time half grants `actions` on the space's ARN (re:Post |
| 14 | * Private has a single `space` IAM resource type — channel- and |
| 15 | * admin-scoped actions are all authorized against the space ARN). |
| 16 | */ |
| 17 | export const makeRePostSpaceHttpBinding = <I extends { spaceId: string }, A, E, R>(options: { |
| 18 | /** Fully-qualified binding tag, e.g. `AWS.RePostSpace.SendInvites`. */ |
| 19 | tag: string; |
| 20 | /** The distilled operation; `spaceId` is injected from the bound space. */ |
| 21 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 22 | /** IAM actions granted on the space ARN. */ |
| 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* (space: Space) { |
| 30 | const spaceId = yield* space.spaceId; |
| 31 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 32 | yield* bind`${options.tag}(${space})`({ |
| 33 | policyStatements: [ |
| 34 | { |
| 35 | Effect: "Allow", |
| 36 | Action: [...options.actions], |
| 37 | Resource: [space.spaceArn], |
| 38 | }, |
| 39 | ], |
| 40 | }); |
| 41 | } |
| 42 | return Effect.fn(`${options.tag}(${space.LogicalId})`)(function* ( |
| 43 | request?: Omit<I, "spaceId">, |
| 44 | ) { |
| 45 | return yield* op({ |
| 46 | ...request, |
| 47 | spaceId: yield* spaceId, |
| 48 | } as I); |
| 49 | }); |
| 50 | }); |
| 51 | }); |