The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type * as cip from "@distilled.cloud/aws/cognito-identity-provider"; |
| 2 | import * as Binding from "alchemy/Binding"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import type { UserPoolClient } from "./UserPoolClient.ts"; |
| 5 | |
| 6 | export interface SignUpRequest extends Omit<cip.SignUpRequest, "ClientId"> {} |
| 7 | export interface ConfirmSignUpRequest extends Omit<cip.ConfirmSignUpRequest, "ClientId"> {} |
| 8 | export interface ResendConfirmationCodeRequest extends Omit< |
| 9 | cip.ResendConfirmationCodeRequest, |
| 10 | "ClientId" |
| 11 | > {} |
| 12 | export interface InitiateAuthRequest extends Omit<cip.InitiateAuthRequest, "ClientId"> {} |
| 13 | export interface RespondToAuthChallengeRequest extends Omit< |
| 14 | cip.RespondToAuthChallengeRequest, |
| 15 | "ClientId" |
| 16 | > {} |
| 17 | export interface ForgotPasswordRequest extends Omit<cip.ForgotPasswordRequest, "ClientId"> {} |
| 18 | export interface ConfirmForgotPasswordRequest extends Omit< |
| 19 | cip.ConfirmForgotPasswordRequest, |
| 20 | "ClientId" |
| 21 | > {} |
| 22 | export interface RevokeTokenRequest extends Omit< |
| 23 | cip.RevokeTokenRequest, |
| 24 | "ClientId" | "ClientSecret" |
| 25 | > {} |
| 26 | export interface GetTokensFromRefreshTokenRequest extends Omit< |
| 27 | cip.GetTokensFromRefreshTokenRequest, |
| 28 | "ClientId" |
| 29 | > {} |
| 30 | |
| 31 | /** |
| 32 | * The typed client returned by binding {@link UserPoolAuth} to a |
| 33 | * `UserPoolClient`. Every method automatically injects the app client ID. |
| 34 | */ |
| 35 | export interface UserPoolAuthClient { |
| 36 | /** Register a new user (public sign-up flow). */ |
| 37 | signUp: (request: SignUpRequest) => Effect.Effect<cip.SignUpResponse, cip.SignUpError>; |
| 38 | /** Confirm a sign-up with the emailed/SMSed confirmation code. */ |
| 39 | confirmSignUp: ( |
| 40 | request: ConfirmSignUpRequest, |
| 41 | ) => Effect.Effect<cip.ConfirmSignUpResponse, cip.ConfirmSignUpError>; |
| 42 | /** Resend the sign-up confirmation code. */ |
| 43 | resendConfirmationCode: ( |
| 44 | request: ResendConfirmationCodeRequest, |
| 45 | ) => Effect.Effect<cip.ResendConfirmationCodeResponse, cip.ResendConfirmationCodeError>; |
| 46 | /** Start an authentication flow (e.g. `USER_PASSWORD_AUTH`). */ |
| 47 | initiateAuth: ( |
| 48 | request: InitiateAuthRequest, |
| 49 | ) => Effect.Effect<cip.InitiateAuthResponse, cip.InitiateAuthError>; |
| 50 | /** Answer an auth challenge returned by `initiateAuth`. */ |
| 51 | respondToAuthChallenge: ( |
| 52 | request: RespondToAuthChallengeRequest, |
| 53 | ) => Effect.Effect<cip.RespondToAuthChallengeResponse, cip.RespondToAuthChallengeError>; |
| 54 | /** Start the forgot-password flow. */ |
| 55 | forgotPassword: ( |
| 56 | request: ForgotPasswordRequest, |
| 57 | ) => Effect.Effect<cip.ForgotPasswordResponse, cip.ForgotPasswordError>; |
| 58 | /** Complete the forgot-password flow with the confirmation code. */ |
| 59 | confirmForgotPassword: ( |
| 60 | request: ConfirmForgotPasswordRequest, |
| 61 | ) => Effect.Effect<cip.ConfirmForgotPasswordResponse, cip.ConfirmForgotPasswordError>; |
| 62 | /** Fetch the signed-in user's profile from an access token. */ |
| 63 | getUser: (request: cip.GetUserRequest) => Effect.Effect<cip.GetUserResponse, cip.GetUserError>; |
| 64 | /** Sign the user out of all devices (invalidates tokens). */ |
| 65 | globalSignOut: ( |
| 66 | request: cip.GlobalSignOutRequest, |
| 67 | ) => Effect.Effect<cip.GlobalSignOutResponse, cip.GlobalSignOutError>; |
| 68 | /** Revoke a refresh token and all access tokens derived from it. */ |
| 69 | revokeToken: ( |
| 70 | request: RevokeTokenRequest, |
| 71 | ) => Effect.Effect<cip.RevokeTokenResponse, cip.RevokeTokenError>; |
| 72 | /** Exchange a refresh token for fresh access/ID tokens (refresh-token |
| 73 | * rotation aware). */ |
| 74 | getTokensFromRefreshToken: ( |
| 75 | request: GetTokensFromRefreshTokenRequest, |
| 76 | ) => Effect.Effect<cip.GetTokensFromRefreshTokenResponse, cip.GetTokensFromRefreshTokenError>; |
| 77 | /** Change the signed-in user's password. */ |
| 78 | changePassword: ( |
| 79 | request: cip.ChangePasswordRequest, |
| 80 | ) => Effect.Effect<cip.ChangePasswordResponse, cip.ChangePasswordError>; |
| 81 | /** Update the signed-in user's attributes. */ |
| 82 | updateUserAttributes: ( |
| 83 | request: cip.UpdateUserAttributesRequest, |
| 84 | ) => Effect.Effect<cip.UpdateUserAttributesResponse, cip.UpdateUserAttributesError>; |
| 85 | /** Delete attributes from the signed-in user's profile. */ |
| 86 | deleteUserAttributes: ( |
| 87 | request: cip.DeleteUserAttributesRequest, |
| 88 | ) => Effect.Effect<cip.DeleteUserAttributesResponse, cip.DeleteUserAttributesError>; |
| 89 | /** Send a verification code for an updated attribute (email/phone). */ |
| 90 | getUserAttributeVerificationCode: ( |
| 91 | request: cip.GetUserAttributeVerificationCodeRequest, |
| 92 | ) => Effect.Effect< |
| 93 | cip.GetUserAttributeVerificationCodeResponse, |
| 94 | cip.GetUserAttributeVerificationCodeError |
| 95 | >; |
| 96 | /** Verify an attribute with the code delivered to it. */ |
| 97 | verifyUserAttribute: ( |
| 98 | request: cip.VerifyUserAttributeRequest, |
| 99 | ) => Effect.Effect<cip.VerifyUserAttributeResponse, cip.VerifyUserAttributeError>; |
| 100 | /** Set the signed-in user's MFA preferences (SMS / TOTP / email). */ |
| 101 | setUserMFAPreference: ( |
| 102 | request: cip.SetUserMFAPreferenceRequest, |
| 103 | ) => Effect.Effect<cip.SetUserMFAPreferenceResponse, cip.SetUserMFAPreferenceError>; |
| 104 | /** Begin TOTP enrollment: returns the shared secret to seed the |
| 105 | * authenticator app. */ |
| 106 | associateSoftwareToken: ( |
| 107 | request: cip.AssociateSoftwareTokenRequest, |
| 108 | ) => Effect.Effect<cip.AssociateSoftwareTokenResponse, cip.AssociateSoftwareTokenError>; |
| 109 | /** Complete TOTP enrollment by verifying a generated code. */ |
| 110 | verifySoftwareToken: ( |
| 111 | request: cip.VerifySoftwareTokenRequest, |
| 112 | ) => Effect.Effect<cip.VerifySoftwareTokenResponse, cip.VerifySoftwareTokenError>; |
| 113 | /** List the auth factors configured for the signed-in user. */ |
| 114 | getUserAuthFactors: ( |
| 115 | request: cip.GetUserAuthFactorsRequest, |
| 116 | ) => Effect.Effect<cip.GetUserAuthFactorsResponse, cip.GetUserAuthFactorsError>; |
| 117 | /** Delete the signed-in user's own account. */ |
| 118 | deleteUser: ( |
| 119 | request: cip.DeleteUserRequest, |
| 120 | ) => Effect.Effect<cip.DeleteUserResponse, cip.DeleteUserError>; |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Runtime binding for the public (client-side) Cognito user pool auth flows. |
| 125 | * |
| 126 | * Bind this to a `UserPoolClient` inside a function runtime to get a typed |
| 127 | * client for sign-up, sign-in, and token flows. These operations are |
| 128 | * unauthenticated (Cognito does not evaluate IAM for them), so the binding |
| 129 | * grants no IAM policy — it injects the app client ID into every call. |
| 130 | * ### Authenticating Users |
| 131 | * **Example:** Username/Password Sign-In |
| 132 | * ```typescript |
| 133 | * const auth = yield* Cognito.UserPoolAuth(client); |
| 134 | * |
| 135 | * const result = yield* auth.initiateAuth({ |
| 136 | * AuthFlow: "USER_PASSWORD_AUTH", |
| 137 | * AuthParameters: { USERNAME: username, PASSWORD: password }, |
| 138 | * }); |
| 139 | * const idToken = result.AuthenticationResult?.IdToken; |
| 140 | * ``` |
| 141 | * |
| 142 | * **Example:** Sign-Up and Confirmation |
| 143 | * ```typescript |
| 144 | * yield* auth.signUp({ |
| 145 | * Username: "user@example.com", |
| 146 | * Password: "Sup3r-secret!", |
| 147 | * UserAttributes: [{ Name: "email", Value: "user@example.com" }], |
| 148 | * }); |
| 149 | * yield* auth.confirmSignUp({ |
| 150 | * Username: "user@example.com", |
| 151 | * ConfirmationCode: code, |
| 152 | * }); |
| 153 | * ``` |
| 154 | * |
| 155 | * **Example:** Read the Signed-In User |
| 156 | * ```typescript |
| 157 | * const user = yield* auth.getUser({ AccessToken: accessToken }); |
| 158 | * ``` |
| 159 | * |
| 160 | * ### Self-Service Account Management |
| 161 | * **Example:** Change Password and Update Attributes |
| 162 | * ```typescript |
| 163 | * yield* auth.changePassword({ |
| 164 | * AccessToken: accessToken, |
| 165 | * PreviousPassword: oldPassword, |
| 166 | * ProposedPassword: newPassword, |
| 167 | * }); |
| 168 | * yield* auth.updateUserAttributes({ |
| 169 | * AccessToken: accessToken, |
| 170 | * UserAttributes: [{ Name: "nickname", Value: "sam" }], |
| 171 | * }); |
| 172 | * ``` |
| 173 | * |
| 174 | * **Example:** Refresh Tokens |
| 175 | * ```typescript |
| 176 | * const refreshed = yield* auth.getTokensFromRefreshToken({ |
| 177 | * RefreshToken: refreshToken, |
| 178 | * }); |
| 179 | * ``` |
| 180 | * |
| 181 | * @binding |
| 182 | */ |
| 183 | export interface UserPoolAuth extends Binding.Service< |
| 184 | UserPoolAuth, |
| 185 | "AWS.Cognito.UserPoolAuth", |
| 186 | <C extends UserPoolClient>(client: C) => Effect.Effect<UserPoolAuthClient> |
| 187 | > {} |
| 188 | export const UserPoolAuth = Binding.Service<UserPoolAuth>("AWS.Cognito.UserPoolAuth"); |