| 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 CreateUsagePlanKeyRequest extends Omit< |
| 7 | ag.CreateUsagePlanKeyRequest, |
| 8 | "usagePlanId" | "keyType" |
| 9 | > { |
| 10 | /** |
| 11 | * Type of the key being enrolled. |
| 12 | * @default "API_KEY" |
| 13 | */ |
| 14 | keyType?: string; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Runtime binding for enrolling an API key in a {@link UsagePlan} |
| 19 | * (`apigateway:POST` on `/usageplans/{id}/keys`). |
| 20 | * |
| 21 | * The core of a self-service API-key onboarding flow: issue a key with |
| 22 | * `ApiGateway.CreateApiKey`, then attach it to the plan that throttles |
| 23 | * and meters it. Provide `ApiGateway.CreateUsagePlanKeyHttp` on the |
| 24 | * Function effect to implement the binding. |
| 25 | * |
| 26 | * ### Managing plan keys |
| 27 | * **Example:** Enroll a freshly issued key |
| 28 | * ```typescript |
| 29 | * // init |
| 30 | * const createApiKey = yield* ApiGateway.CreateApiKey(); |
| 31 | * const createUsagePlanKey = yield* ApiGateway.CreateUsagePlanKey(plan); |
| 32 | * |
| 33 | * // runtime |
| 34 | * const key = yield* createApiKey({ name: customerId, enabled: true }); |
| 35 | * yield* createUsagePlanKey({ keyId: key.id! }); |
| 36 | * ``` |
| 37 | * |
| 38 | * @binding |
| 39 | */ |
| 40 | export interface CreateUsagePlanKey extends Binding.Service< |
| 41 | CreateUsagePlanKey, |
| 42 | "AWS.ApiGateway.CreateUsagePlanKey", |
| 43 | <P extends UsagePlan>( |
| 44 | usagePlan: P, |
| 45 | ) => Effect.Effect< |
| 46 | ( |
| 47 | request: CreateUsagePlanKeyRequest, |
| 48 | ) => Effect.Effect<ag.UsagePlanKey, ag.CreateUsagePlanKeyError> |
| 49 | > |
| 50 | > {} |
| 51 | export const CreateUsagePlanKey = Binding.Service<CreateUsagePlanKey>( |
| 52 | "AWS.ApiGateway.CreateUsagePlanKey", |
| 53 | ); |