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