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