|
| 1 | +// |
| 2 | +// Copyright Amazon.com Inc. or its affiliates. |
| 3 | +// All Rights Reserved. |
| 4 | +// |
| 5 | +// SPDX-License-Identifier: Apache-2.0 |
| 6 | +// |
| 7 | + |
| 8 | +import Amplify |
| 9 | +import Foundation |
| 10 | + |
| 11 | +/// A utility class meant to provide |
| 12 | +public enum PreviewFactory { |
| 13 | + public enum States { |
| 14 | + /// Returns an empty and no-op ``SignInState``. |
| 15 | + public static func signIn() -> SignInState { |
| 16 | + return .init(credentials: .init()) |
| 17 | + } |
| 18 | + |
| 19 | + /// Returns an empty and no-op ``ConfirmSignInWithCodeState``. |
| 20 | + /// - Parameter deliveryDetails: The ``AuthCodeDeliveryDetails`` associated with this state |
| 21 | + public static func confirmSignInWithCode(deliveryDetails: AuthCodeDeliveryDetails? = nil) -> ConfirmSignInWithCodeState { |
| 22 | + return ConfirmSignInWithCodeState( |
| 23 | + authenticatorState: .empty(with: .confirmSignInWithMFACode(deliveryDetails: deliveryDetails)) |
| 24 | + ) |
| 25 | + } |
| 26 | + |
| 27 | + /// Returns an empty and no-op ``ConfirmSignInWithNewPasswordState``. |
| 28 | + public static func confirmSignInWithNewPassword() -> ConfirmSignInWithNewPasswordState { |
| 29 | + return .init(credentials: .init()) |
| 30 | + } |
| 31 | + |
| 32 | + /// Returns an empty and no-op ``ContinueSignInWithMFASelectionState``. |
| 33 | + /// - Parameter allowedMFATypes: The ``AllowedMFATypes`` associated with this state |
| 34 | + public static func continueSignInWithMFASelection(allowedMFATypes: AllowedMFATypes) -> ContinueSignInWithMFASelectionState { |
| 35 | + return .init( |
| 36 | + authenticatorState: .empty, |
| 37 | + allowedMFATypes: allowedMFATypes |
| 38 | + ) |
| 39 | + } |
| 40 | + |
| 41 | + /// Returns an empty and no-op ``ContinueSignInWithTOTPSetupState``. |
| 42 | + /// - Parameter issuer: The issuer associated with this state |
| 43 | + /// - Parameter totpSetupDetails: The ``TOTPSetupDetails`` associated with this state |
| 44 | + public static func continueSignInWithTOTPSetup( |
| 45 | + issuer: String? = nil, |
| 46 | + totpSetupDetails: TOTPSetupDetails |
| 47 | + ) -> ContinueSignInWithTOTPSetupState { |
| 48 | + return .init( |
| 49 | + authenticatorState: .empty, |
| 50 | + issuer: issuer, |
| 51 | + totpSetupDetails: totpSetupDetails |
| 52 | + ) |
| 53 | + } |
| 54 | + |
| 55 | + /// Returns an empty and no-op ``SignUpState``. |
| 56 | + /// - Parameter signUpFields: The list of ``SignUpField``s associated with this state |
| 57 | + public static func signUp(signUpFields: [SignUpField] = []) -> SignUpState { |
| 58 | + let state = SignUpState(credentials: .init()) |
| 59 | + state.configure(with: signUpFields) |
| 60 | + return state |
| 61 | + } |
| 62 | + |
| 63 | + /// Returns an empty and no-op ``ConfirmSignUpState``. |
| 64 | + /// - Parameter deliveryDetails: The ``AuthCodeDeliveryDetails`` associated with this state |
| 65 | + public static func confirmSignUp(deliveryDetails: AuthCodeDeliveryDetails? = nil) -> ConfirmSignUpState { |
| 66 | + return .init( |
| 67 | + authenticatorState: .empty(with: .confirmSignUp(deliveryDetails: deliveryDetails)), |
| 68 | + credentials: .init() |
| 69 | + ) |
| 70 | + } |
| 71 | + |
| 72 | + /// Returns an empty and no-op ``ResetPasswordState``. |
| 73 | + public static func resetPasword() -> ResetPasswordState { |
| 74 | + return .init(credentials: .init()) |
| 75 | + } |
| 76 | + |
| 77 | + /// Returns an empty and no-op ``ConfirmResetPasswordState``. |
| 78 | + /// - Parameter deliveryDetails: The ``AuthCodeDeliveryDetails`` associated with this state |
| 79 | + public static func confirmResetPassword(deliveryDetails: AuthCodeDeliveryDetails? = nil) -> ConfirmResetPasswordState { |
| 80 | + return .init( |
| 81 | + authenticatorState: .empty(with: .confirmResetPassword(deliveryDetails: deliveryDetails)), |
| 82 | + credentials: .init() |
| 83 | + ) |
| 84 | + } |
| 85 | + |
| 86 | + /// Returns an empty and no-op ``VerifyUserState``. |
| 87 | + /// - Parameter unverifiedFields: The list of ``AuthUserAttributeKey``s associated with this state |
| 88 | + public static func verifyUser(unverifiedFields: [AuthUserAttributeKey] = []) -> VerifyUserState { |
| 89 | + return .init( |
| 90 | + authenticatorState: .empty(with: .verifyUser(attributes: unverifiedFields)), |
| 91 | + credentials: .init() |
| 92 | + ) |
| 93 | + } |
| 94 | + |
| 95 | + /// Returns an empty and no-op ``ConfirmVerifyUserState``. |
| 96 | + /// - Parameter userAttributeKey: The ``AuthUserAttributeKey`` associated with this state |
| 97 | + /// - Parameter deliveryDetails: The ``AuthCodeDeliveryDetails`` associated with this state |
| 98 | + public static func confirmVerifyUser( |
| 99 | + userAttributeKey: AuthUserAttributeKey, |
| 100 | + deliveryDetails: AuthCodeDeliveryDetails? = nil |
| 101 | + ) -> ConfirmVerifyUserState { |
| 102 | + return .init( |
| 103 | + authenticatorState: .empty( |
| 104 | + with: .confirmVerifyUser( |
| 105 | + attribute: userAttributeKey, |
| 106 | + deliveryDetails: deliveryDetails |
| 107 | + ) |
| 108 | + ), |
| 109 | + credentials: .init() |
| 110 | + ) |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +private extension AuthenticatorStateProtocol where Self == EmptyAuthenticatorState { |
| 116 | + static func empty(with step: Step) -> AuthenticatorStateProtocol { |
| 117 | + return EmptyAuthenticatorState(step: step) |
| 118 | + } |
| 119 | +} |
| 120 | + |
0 commit comments