The best way to control Claude Code, Codex and more from any computer or phone

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