1import type * as ag from "@distilled.cloud/aws/api-gateway";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { UsagePlan } from "./UsagePlan.ts";
5
6export interface GetUsagePlanKeyRequest extends Omit<
7 ag.GetUsagePlanKeyRequest,
8 "usagePlanId"
9> {}
10
11/**
12 * Runtime binding for reading a single API key enrolled in a
13 * {@link UsagePlan} (`apigateway:GET` on `/usageplans/{id}/keys/{keyId}`).
14 *
15 * Provide `ApiGateway.GetUsagePlanKeyHttp` on the Function effect to
16 * implement the binding.
17 *
18 * ### Managing plan keys
19 * **Example:** Check a key's enrollment
20 * ```typescript
21 * // init
22 * const getUsagePlanKey = yield* ApiGateway.GetUsagePlanKey(plan);
23 *
24 * // runtime
25 * const enrolled = yield* getUsagePlanKey({ keyId }).pipe(
26 * Effect.map(() => true),
27 * Effect.catchTag("NotFoundException", () => Effect.succeed(false)),
28 * );
29 * ```
30 *
31 * @binding
32 */
33export interface GetUsagePlanKey extends Binding.Service<
34 GetUsagePlanKey,
35 "AWS.ApiGateway.GetUsagePlanKey",
36 <P extends UsagePlan>(
37 usagePlan: P,
38 ) => Effect.Effect<
39 (
40 request: GetUsagePlanKeyRequest,
41 ) => Effect.Effect<ag.UsagePlanKey, ag.GetUsagePlanKeyError>
42 >
43> {}
44export const GetUsagePlanKey = Binding.Service<GetUsagePlanKey>(
45 "AWS.ApiGateway.GetUsagePlanKey",
46);