1import * as polly from "@distilled.cloud/aws/polly";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Binding from "../../Binding.ts";
5import { isBindingHost } from "../Lambda/Function.ts";
6import { GetLexicon } from "./GetLexicon.ts";
7import type { Lexicon } from "./Lexicon.ts";
8
9// GetLexicon is one of the few Polly actions with resource-level IAM (the
10// `lexicon` resource type), so the grant is scoped to the lexicon's ARN
11// rather than `*` — that's why this binding is bespoke instead of a
12// makePollyHttpBinding thin call.
13export const GetLexiconHttp = Layer.effect(
14 GetLexicon,
15 Effect.gen(function* () {
16 const getLexicon = yield* polly.getLexicon;
17
18 return Effect.fn(function* <L extends Lexicon>(lexicon: L) {
19 const Name = yield* lexicon.lexiconName;
20 if (!globalThis.__ALCHEMY_RUNTIME__) {
21 const host = yield* Binding.Host;
22 if (isBindingHost(host)) {
23 yield* host.bind`Allow(${host}, AWS.Polly.GetLexicon(${lexicon}))`({
24 policyStatements: [
25 {
26 Effect: "Allow",
27 Action: ["polly:GetLexicon"],
28 Resource: [lexicon.lexiconArn],
29 },
30 ],
31 });
32 }
33 }
34 return Effect.fn(`AWS.Polly.GetLexicon(${lexicon.LogicalId})`)(
35 function* () {
36 return yield* getLexicon({ Name: yield* Name });
37 },
38 );
39 });
40 }),
41);