1import * as agw2 from "@distilled.cloud/aws/apigatewayv2";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Output from "../../Output.ts";
5import type { Api } from "./Api.ts";
6import { registerApiGatewayV2Binding } from "./BindingHttp.ts";
7import { ExportApi, type ExportApiRequest } from "./ExportApi.ts";
8
9/**
10 * HTTP implementation of the {@link ExportApi} binding. Grants
11 * `apigateway:GET` on the API's `/exports/*` path and calls the API with
12 * the host Function's credentials.
13 */
14export const ExportApiHttp = Layer.effect(
15 ExportApi,
16 Effect.gen(function* () {
17 const exportApi = yield* agw2.exportApi;
18 return Effect.fn(function* <A extends Api>(api: A) {
19 const ApiId = yield* api.apiId;
20 yield* registerApiGatewayV2Binding({
21 cap: "AWS.ApiGatewayV2.ExportApi",
22 target: api,
23 verb: "GET",
24 paths: (region) => [
25 Output.interpolate`arn:aws:apigateway:${region}::/apis/${api.apiId}/exports/*`,
26 ],
27 });
28 return Effect.fn(`AWS.ApiGatewayV2.ExportApi(${api.LogicalId})`)(
29 function* (request?: ExportApiRequest) {
30 return yield* exportApi({
31 ...request,
32 ApiId: yield* ApiId,
33 Specification: request?.Specification ?? "OAS30",
34 });
35 },
36 );
37 });
38 }),
39);