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