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 { Canary } from "./Canary.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared scaffolding for CloudWatch Synthetics HTTP bindings. |
| 7 | * |
| 8 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 9 | * thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two |
| 10 | * builders below. Everything except the operation and the IAM action is |
| 11 | * boilerplate: |
| 12 | * |
| 13 | * - {@link makeSyntheticsCanaryHttpBinding} — operations scoped to one bound |
| 14 | * {@link Canary} (`GetCanary`, `GetCanaryRuns`, `StartCanary`, |
| 15 | * `StopCanary`). The runtime callable injects the canary's name as the |
| 16 | * request's `Name`; the deploy-time half grants `actions` on the canary |
| 17 | * ARN. |
| 18 | * - {@link makeSyntheticsAccountHttpBinding} — account-level operations |
| 19 | * (`DescribeCanariesLastRun`), granted on `*`. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * Build the impl Effect for an operation scoped to a single bound |
| 24 | * {@link Canary}. The runtime callable injects the canary's name as the |
| 25 | * request's `Name`; the deploy-time half grants `actions` on the canary ARN. |
| 26 | */ |
| 27 | export const makeSyntheticsCanaryHttpBinding = <I extends { Name: string }, A, E, R>(options: { |
| 28 | /** Fully-qualified binding tag, e.g. `AWS.Synthetics.GetCanaryRuns`. */ |
| 29 | tag: string; |
| 30 | /** The distilled operation; `Name` is injected from the resource. */ |
| 31 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 32 | /** IAM actions granted on the canary ARN. */ |
| 33 | actions: readonly string[]; |
| 34 | }) => |
| 35 | Effect.gen(function* () { |
| 36 | const bind = yield* AWSBindings.Bind; |
| 37 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 38 | |
| 39 | return Effect.fn(function* (canary: Canary) { |
| 40 | const Name = yield* canary.canaryName; |
| 41 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 42 | yield* bind`${options.tag}(${canary})`({ |
| 43 | policyStatements: [ |
| 44 | { |
| 45 | Effect: "Allow", |
| 46 | Action: [...options.actions], |
| 47 | Resource: [canary.canaryArn], |
| 48 | }, |
| 49 | ], |
| 50 | }); |
| 51 | } |
| 52 | return Effect.fn(`${options.tag}(${canary.LogicalId})`)(function* ( |
| 53 | request?: Omit<I, "Name">, |
| 54 | ) { |
| 55 | return yield* op({ ...request, Name: yield* Name } as I); |
| 56 | }); |
| 57 | }); |
| 58 | }); |
| 59 | |
| 60 | /** |
| 61 | * Build the impl Effect for an account-level Synthetics operation. The |
| 62 | * runtime callable passes the caller's request through unchanged; the |
| 63 | * deploy-time half grants `actions` on `*` (account-level reads such as |
| 64 | * `DescribeCanariesLastRun` are not resource-addressable). |
| 65 | */ |
| 66 | export const makeSyntheticsAccountHttpBinding = <I, A, E, R>(options: { |
| 67 | /** Fully-qualified binding tag, e.g. `AWS.Synthetics.DescribeCanariesLastRun`. */ |
| 68 | tag: string; |
| 69 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 70 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 71 | /** IAM actions granted on `*`. */ |
| 72 | actions: readonly string[]; |
| 73 | }) => |
| 74 | Effect.gen(function* () { |
| 75 | const bind = yield* AWSBindings.Bind; |
| 76 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 77 | |
| 78 | return Effect.fn(function* () { |
| 79 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 80 | yield* bind`${options.tag}()`({ |
| 81 | policyStatements: [ |
| 82 | { |
| 83 | Effect: "Allow", |
| 84 | Action: [...options.actions], |
| 85 | Resource: ["*"], |
| 86 | }, |
| 87 | ], |
| 88 | }); |
| 89 | } |
| 90 | return Effect.fn(options.tag)(function* (request?: I) { |
| 91 | return yield* op((request ?? {}) as I); |
| 92 | }); |
| 93 | }); |
| 94 | }); |