The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | |
| 4 | /** |
| 5 | * Shared scaffolding for Amazon Macie HTTP bindings. |
| 6 | * |
| 7 | * NOT exported from `index.ts` — every thin `{Op}Http.ts` in this service is |
| 8 | * a `Layer.effect(Cap, makeMacie2HttpBinding({ … }))` over the builder below. |
| 9 | * Everything except the operation and the IAM action list is boilerplate. |
| 10 | * |
| 11 | * Macie is an account/region singleton service: every operation is implicitly |
| 12 | * scoped to the caller's Macie session, so there is no identifier to inject — |
| 13 | * the caller's request is passed through as-is. Macie2 IAM actions do not |
| 14 | * support resource-level permissions (the session has no bindable ARN), so |
| 15 | * the deploy-time half grants `actions` on `*`. |
| 16 | */ |
| 17 | export const makeMacie2HttpBinding = <I, A, E, R>(options: { |
| 18 | /** Fully-qualified binding tag, e.g. `AWS.Macie2.ListFindings`. */ |
| 19 | tag: string; |
| 20 | /** The distilled operation, invoked with the caller's request as-is. */ |
| 21 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 22 | /** IAM actions granted on `*`. */ |
| 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* () { |
| 30 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 31 | yield* bind`${options.tag}()`({ |
| 32 | policyStatements: [ |
| 33 | { |
| 34 | Effect: "Allow", |
| 35 | Action: [...options.actions], |
| 36 | Resource: ["*"], |
| 37 | }, |
| 38 | ], |
| 39 | }); |
| 40 | } |
| 41 | return Effect.fn(options.tag)(function* (request?: I) { |
| 42 | return yield* op((request ?? {}) as I); |
| 43 | }); |
| 44 | }); |
| 45 | }); |