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, 06:00 UTC
| 1 | import * as Output from "alchemy/Output"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as AWSBindings from "../AWSBindings.ts"; |
| 4 | import type { DeliveryStream } from "./DeliveryStream.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared scaffolding for AWS Firehose HTTP bindings. |
| 8 | * |
| 9 | * NOT exported from `index.ts` — every near-identical `{Op}Http.ts` in this |
| 10 | * service is a thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of |
| 11 | * the builders below. Everything except the operation, the IAM action list, |
| 12 | * and the granted ARNs is boilerplate. Genuinely-different bindings (the |
| 13 | * batched `DeliveryStreamSink`) stay bespoke. |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Build the impl Effect for a delivery-stream-scoped operation |
| 18 | * (`PutRecord`, `PutRecordBatch`): the runtime callable injects the bound |
| 19 | * {@link DeliveryStream}'s physical name as `DeliveryStreamName` and the |
| 20 | * deploy-time half grants `actions` on the delivery stream's ARN. |
| 21 | */ |
| 22 | export const makeDeliveryStreamHttpBinding = < |
| 23 | I extends { DeliveryStreamName?: string }, |
| 24 | A, |
| 25 | E, |
| 26 | R, |
| 27 | >(options: { |
| 28 | /** Fully-qualified binding tag, e.g. `AWS.Firehose.PutRecord`. */ |
| 29 | tag: string; |
| 30 | /** The distilled operation; `DeliveryStreamName` is injected. */ |
| 31 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 32 | /** IAM actions granted on the delivery stream 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* (deliveryStream: DeliveryStream) { |
| 40 | const DeliveryStreamName = yield* deliveryStream.deliveryStreamName; |
| 41 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 42 | yield* bind`${options.tag}(${deliveryStream})`({ |
| 43 | policyStatements: [ |
| 44 | { |
| 45 | Effect: "Allow", |
| 46 | Action: [...options.actions], |
| 47 | Resource: [Output.interpolate`${deliveryStream.deliveryStreamArn}`], |
| 48 | }, |
| 49 | ], |
| 50 | }); |
| 51 | } |
| 52 | return Effect.fn(`${options.tag}(${deliveryStream.LogicalId})`)(function* ( |
| 53 | request: Omit<I, "DeliveryStreamName">, |
| 54 | ) { |
| 55 | return yield* op({ |
| 56 | ...request, |
| 57 | DeliveryStreamName: yield* DeliveryStreamName, |
| 58 | } as I); |
| 59 | }); |
| 60 | }); |
| 61 | }); |
| 62 | |
| 63 | /** |
| 64 | * Build the impl Effect for an account-level operation |
| 65 | * (`ListDeliveryStreams`): the runtime callable passes the caller's request |
| 66 | * through unchanged and the deploy-time half grants `actions` on `*` |
| 67 | * (these Firehose actions do not support resource-level permissions). |
| 68 | */ |
| 69 | export const makeFirehoseAccountHttpBinding = <I, A, E, R>(options: { |
| 70 | /** Fully-qualified binding tag, e.g. `AWS.Firehose.ListDeliveryStreams`. */ |
| 71 | tag: string; |
| 72 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 73 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 74 | /** IAM actions granted on `*`. */ |
| 75 | actions: readonly string[]; |
| 76 | }) => |
| 77 | Effect.gen(function* () { |
| 78 | const bind = yield* AWSBindings.Bind; |
| 79 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 80 | |
| 81 | return Effect.fn(function* () { |
| 82 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 83 | yield* bind`${options.tag}()`({ |
| 84 | policyStatements: [ |
| 85 | { |
| 86 | Effect: "Allow", |
| 87 | Action: [...options.actions], |
| 88 | Resource: ["*"], |
| 89 | }, |
| 90 | ], |
| 91 | }); |
| 92 | } |
| 93 | return Effect.fn(options.tag)(function* (request?: I) { |
| 94 | return yield* op((request ?? {}) as I); |
| 95 | }); |
| 96 | }); |
| 97 | }); |