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

main
ts 40 lines 1.51 KB
Raw
1 import * as ag from "@distilled.cloud/aws/api-gateway";
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 { RegisterApiGatewayBinding } from "./BindingHttp.ts";
7 import { GetUsagePlanKey, type GetUsagePlanKeyRequest } from "./GetUsagePlanKey.ts";
8 import type { UsagePlan } from "./UsagePlan.ts";
9
10 /**
11 * HTTP implementation of the {@link GetUsagePlanKey} binding. Grants
12 * `apigateway:GET` on the plan's per-key paths and calls the API with the
13 * host Function's credentials.
14 */
15 export const GetUsagePlanKeyHttp = Layer.effect(
16 GetUsagePlanKey,
17 Effect.gen(function* () {
18 const registerApiGatewayBinding = yield* RegisterApiGatewayBinding;
19 const getUsagePlanKey = yield* AWSBindings.withCredentials(ag.getUsagePlanKey);
20 return Effect.fn(function* <P extends UsagePlan>(usagePlan: P) {
21 const UsagePlanId = yield* usagePlan.id;
22 yield* registerApiGatewayBinding({
23 cap: "AWS.ApiGateway.GetUsagePlanKey",
24 target: usagePlan,
25 verb: "GET",
26 paths: (region) => [
27 Output.interpolate`arn:aws:apigateway:${region}::/usageplans/${usagePlan.id}/keys/*`,
28 ],
29 });
30 return Effect.fn(`AWS.ApiGateway.GetUsagePlanKey(${usagePlan.LogicalId})`)(function* (
31 request: GetUsagePlanKeyRequest,
32 ) {
33 return yield* getUsagePlanKey({
34 ...request,
35 usagePlanId: yield* UsagePlanId,
36 });
37 });
38 });
39 }),
40 );