| 1 | import type * as ag from "@distilled.cloud/aws/api-gateway"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { UsagePlan } from "./UsagePlan.ts"; |
| 5 | |
| 6 | export interface GetUsageRequest extends Omit< |
| 7 | ag.GetUsageRequest, |
| 8 | "usagePlanId" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for reading usage data of a {@link UsagePlan} |
| 13 | * (`apigateway:GET` on `/usageplans/{id}/usage`). |
| 14 | * |
| 15 | * Bind a usage plan inside a function runtime to meter per-key API |
| 16 | * consumption — the primitive for building billing or quota dashboards. |
| 17 | * Provide `ApiGateway.GetUsageHttp` on the Function effect to implement |
| 18 | * the binding. |
| 19 | * |
| 20 | * ### Metering usage |
| 21 | * **Example:** Read this month's usage for a key |
| 22 | * ```typescript |
| 23 | * // init |
| 24 | * const getUsage = yield* ApiGateway.GetUsage(plan); |
| 25 | * |
| 26 | * // runtime |
| 27 | * const usage = yield* getUsage({ |
| 28 | * keyId, |
| 29 | * startDate: "2026-07-01", |
| 30 | * endDate: "2026-07-14", |
| 31 | * }); |
| 32 | * ``` |
| 33 | * |
| 34 | * @binding |
| 35 | */ |
| 36 | export interface GetUsage extends Binding.Service< |
| 37 | GetUsage, |
| 38 | "AWS.ApiGateway.GetUsage", |
| 39 | <P extends UsagePlan>( |
| 40 | usagePlan: P, |
| 41 | ) => Effect.Effect< |
| 42 | (request: GetUsageRequest) => Effect.Effect<ag.Usage, ag.GetUsageError> |
| 43 | > |
| 44 | > {} |
| 45 | export const GetUsage = Binding.Service<GetUsage>("AWS.ApiGateway.GetUsage"); |