| 1 | import type * as ci from "@distilled.cloud/aws/cognito-identity"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { IdentityPool } from "./IdentityPool.ts"; |
| 5 | |
| 6 | export interface ListIdentitiesRequest extends Omit< |
| 7 | ci.ListIdentitiesInput, |
| 8 | "IdentityPoolId" |
| 9 | > {} |
| 10 | export interface LookupDeveloperIdentityRequest extends Omit< |
| 11 | ci.LookupDeveloperIdentityInput, |
| 12 | "IdentityPoolId" |
| 13 | > {} |
| 14 | export interface MergeDeveloperIdentitiesRequest extends Omit< |
| 15 | ci.MergeDeveloperIdentitiesInput, |
| 16 | "IdentityPoolId" |
| 17 | > {} |
| 18 | export interface UnlinkDeveloperIdentityRequest extends Omit< |
| 19 | ci.UnlinkDeveloperIdentityInput, |
| 20 | "IdentityPoolId" |
| 21 | > {} |
| 22 | export interface GetOpenIdTokenForDeveloperIdentityRequest extends Omit< |
| 23 | ci.GetOpenIdTokenForDeveloperIdentityInput, |
| 24 | "IdentityPoolId" |
| 25 | > {} |
| 26 | |
| 27 | /** |
| 28 | * The typed client returned by binding {@link IdentityPoolAdmin} to an |
| 29 | * `IdentityPool`. Pool-scoped calls automatically inject the identity pool |
| 30 | * ID and are authorized by IAM (`cognito-identity:*` on the pool's ARN). |
| 31 | */ |
| 32 | export interface IdentityPoolAdminClient { |
| 33 | /** Fetch an identity's linked logins and metadata. */ |
| 34 | describeIdentity: ( |
| 35 | request: ci.DescribeIdentityInput, |
| 36 | ) => Effect.Effect<ci.IdentityDescription, ci.DescribeIdentityError>; |
| 37 | /** Page through the identities registered in the pool. */ |
| 38 | listIdentities: ( |
| 39 | request: ListIdentitiesRequest, |
| 40 | ) => Effect.Effect<ci.ListIdentitiesResponse, ci.ListIdentitiesError>; |
| 41 | /** Permanently delete identities from the pool. */ |
| 42 | deleteIdentities: ( |
| 43 | request: ci.DeleteIdentitiesInput, |
| 44 | ) => Effect.Effect<ci.DeleteIdentitiesResponse, ci.DeleteIdentitiesError>; |
| 45 | /** Look up an identity by developer user identifier (or vice versa). */ |
| 46 | lookupDeveloperIdentity: ( |
| 47 | request: LookupDeveloperIdentityRequest, |
| 48 | ) => Effect.Effect< |
| 49 | ci.LookupDeveloperIdentityResponse, |
| 50 | ci.LookupDeveloperIdentityError |
| 51 | >; |
| 52 | /** Merge two developer-authenticated identities into one. */ |
| 53 | mergeDeveloperIdentities: ( |
| 54 | request: MergeDeveloperIdentitiesRequest, |
| 55 | ) => Effect.Effect< |
| 56 | ci.MergeDeveloperIdentitiesResponse, |
| 57 | ci.MergeDeveloperIdentitiesError |
| 58 | >; |
| 59 | /** Unlink a developer user identifier from an identity. */ |
| 60 | unlinkDeveloperIdentity: ( |
| 61 | request: UnlinkDeveloperIdentityRequest, |
| 62 | ) => Effect.Effect< |
| 63 | ci.UnlinkDeveloperIdentityResponse, |
| 64 | ci.UnlinkDeveloperIdentityError |
| 65 | >; |
| 66 | /** Mint an OpenID Connect token for a developer-authenticated identity |
| 67 | * (server-side developer provider flow). */ |
| 68 | getOpenIdTokenForDeveloperIdentity: ( |
| 69 | request: GetOpenIdTokenForDeveloperIdentityRequest, |
| 70 | ) => Effect.Effect< |
| 71 | ci.GetOpenIdTokenForDeveloperIdentityResponse, |
| 72 | ci.GetOpenIdTokenForDeveloperIdentityError |
| 73 | >; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Runtime binding for administrative Cognito identity pool operations — |
| 78 | * identity management and the developer-authenticated identities flow. |
| 79 | * |
| 80 | * Bind this to an `IdentityPool` inside a function runtime to get a typed |
| 81 | * client for listing/deleting identities and for developer-provider token |
| 82 | * minting. The binding grants the corresponding `cognito-identity:*` IAM |
| 83 | * actions scoped to the pool's ARN and injects the pool ID into pool-scoped |
| 84 | * calls. |
| 85 | * ### Managing Identities |
| 86 | * **Example:** List and Describe Identities |
| 87 | * ```typescript |
| 88 | * const identities = yield* Cognito.IdentityPoolAdmin(identityPool); |
| 89 | * |
| 90 | * const page = yield* identities.listIdentities({ MaxResults: 20 }); |
| 91 | * const first = page.Identities?.[0]; |
| 92 | * if (first?.IdentityId) { |
| 93 | * const detail = yield* identities.describeIdentity({ |
| 94 | * IdentityId: first.IdentityId, |
| 95 | * }); |
| 96 | * } |
| 97 | * ``` |
| 98 | * |
| 99 | * ### Developer-Authenticated Identities |
| 100 | * **Example:** Mint a Token for a Backend-Authenticated User |
| 101 | * ```typescript |
| 102 | * const token = yield* identities.getOpenIdTokenForDeveloperIdentity({ |
| 103 | * Logins: { "my.developer.provider": userId }, |
| 104 | * }); |
| 105 | * ``` |
| 106 | * |
| 107 | * @binding |
| 108 | */ |
| 109 | export interface IdentityPoolAdmin extends Binding.Service< |
| 110 | IdentityPoolAdmin, |
| 111 | "AWS.Cognito.IdentityPoolAdmin", |
| 112 | <P extends IdentityPool>(pool: P) => Effect.Effect<IdentityPoolAdminClient> |
| 113 | > {} |
| 114 | export const IdentityPoolAdmin = Binding.Service<IdentityPoolAdmin>( |
| 115 | "AWS.Cognito.IdentityPoolAdmin", |
| 116 | ); |