@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

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