| 1 | import type * as AVP from "@distilled.cloud/aws/verifiedpermissions"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { PolicyStore } from "./PolicyStore.ts"; |
| 5 | |
| 6 | /** |
| 7 | * A batch policy-retrieval request scoped to the bound policy store — the |
| 8 | * store's `policyStoreId` is injected into every item. |
| 9 | */ |
| 10 | export interface GetPoliciesRequest { |
| 11 | /** |
| 12 | * Up to 100 policy IDs to retrieve from the bound policy store. |
| 13 | */ |
| 14 | policyIds: string[]; |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * The runtime client returned by binding `GetPolicies` to a `PolicyStore`. |
| 19 | */ |
| 20 | export interface GetPoliciesClient { |
| 21 | /** |
| 22 | * Retrieve up to 100 policies from the bound store in one call |
| 23 | * (`BatchGetPolicy`). Unknown IDs are reported in the output's `errors` |
| 24 | * list rather than failing the call. |
| 25 | */ |
| 26 | batchGetPolicy( |
| 27 | request: GetPoliciesRequest, |
| 28 | ): Effect.Effect<AVP.BatchGetPolicyOutput, AVP.BatchGetPolicyError>; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Runtime binding for bulk policy retrieval — bind it to a `PolicyStore` |
| 33 | * inside a function runtime to fetch policy definitions (e.g. for admin / |
| 34 | * audit surfaces) without granting mutation rights. |
| 35 | * ### Reading Policies at Runtime |
| 36 | * **Example:** Fetch Policies by ID |
| 37 | * ```typescript |
| 38 | * // init |
| 39 | * const policies = yield* AWS.VerifiedPermissions.GetPolicies(store); |
| 40 | * |
| 41 | * // runtime |
| 42 | * const { results, errors } = yield* policies.batchGetPolicy({ |
| 43 | * policyIds: ["9wYixMplbbZQb5fcZHyJhY"], |
| 44 | * }); |
| 45 | * ``` |
| 46 | * |
| 47 | * @binding |
| 48 | */ |
| 49 | export interface GetPolicies extends Binding.Service< |
| 50 | GetPolicies, |
| 51 | "AWS.VerifiedPermissions.GetPolicies", |
| 52 | <S extends PolicyStore>(store: S) => Effect.Effect<GetPoliciesClient> |
| 53 | > {} |
| 54 | export const GetPolicies = Binding.Service<GetPolicies>( |
| 55 | "AWS.VerifiedPermissions.GetPolicies", |
| 56 | ); |