|
| 1 | +import type { SignUpStatus } from '@clerk/types'; |
| 2 | + |
| 3 | +import type { SignUpVerificationNextAction } from './Enums'; |
| 4 | +import type { SignUpJSON, SignUpVerificationJSON, SignUpVerificationsJSON } from './JSON'; |
| 5 | + |
| 6 | +export class SignUpAttemptVerification { |
| 7 | + constructor( |
| 8 | + readonly nextAction: SignUpVerificationNextAction, |
| 9 | + readonly supportedStrategies: string[], |
| 10 | + ) {} |
| 11 | + |
| 12 | + static fromJSON(data: SignUpVerificationJSON): SignUpAttemptVerification { |
| 13 | + return new SignUpAttemptVerification(data.next_action, data.supported_strategies); |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +export class SignUpAttemptVerifications { |
| 18 | + constructor( |
| 19 | + readonly emailAddress: SignUpAttemptVerification | null, |
| 20 | + readonly phoneNumber: SignUpAttemptVerification | null, |
| 21 | + readonly web3Wallet: SignUpAttemptVerification | null, |
| 22 | + readonly externalAccount: object | null, |
| 23 | + ) {} |
| 24 | + |
| 25 | + static fromJSON(data: SignUpVerificationsJSON): SignUpAttemptVerifications { |
| 26 | + return new SignUpAttemptVerifications( |
| 27 | + data.email_address && SignUpAttemptVerification.fromJSON(data.email_address), |
| 28 | + data.phone_number && SignUpAttemptVerification.fromJSON(data.phone_number), |
| 29 | + data.web3_wallet && SignUpAttemptVerification.fromJSON(data.web3_wallet), |
| 30 | + data.external_account, |
| 31 | + ); |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +export class SignUpAttempt { |
| 36 | + constructor( |
| 37 | + readonly id: string, |
| 38 | + readonly status: SignUpStatus, |
| 39 | + readonly requiredFields: string[], |
| 40 | + readonly optionalFields: string[], |
| 41 | + readonly missingFields: string[], |
| 42 | + readonly unverifiedFields: string[], |
| 43 | + readonly verifications: SignUpAttemptVerifications | null, |
| 44 | + readonly username: string | null, |
| 45 | + readonly emailAddress: string | null, |
| 46 | + readonly phoneNumber: string | null, |
| 47 | + readonly web3Wallet: string | null, |
| 48 | + readonly passwordEnabled: boolean, |
| 49 | + readonly firstName: string | null, |
| 50 | + readonly lastName: string | null, |
| 51 | + readonly customAction: boolean, |
| 52 | + readonly externalId: string | null, |
| 53 | + readonly createdSessionId: string | null, |
| 54 | + readonly createdUserId: string | null, |
| 55 | + readonly abandonAt: number | null, |
| 56 | + readonly legalAcceptedAt: number | null, |
| 57 | + readonly publicMetadata?: Record<string, unknown> | null, |
| 58 | + readonly unsafeMetadata?: Record<string, unknown> | null, |
| 59 | + ) {} |
| 60 | + |
| 61 | + static fromJSON(data: SignUpJSON): SignUpAttempt { |
| 62 | + return new SignUpAttempt( |
| 63 | + data.id, |
| 64 | + data.status, |
| 65 | + data.required_fields, |
| 66 | + data.optional_fields, |
| 67 | + data.missing_fields, |
| 68 | + data.unverified_fields, |
| 69 | + data.verifications ? SignUpAttemptVerifications.fromJSON(data.verifications) : null, |
| 70 | + data.username, |
| 71 | + data.email_address, |
| 72 | + data.phone_number, |
| 73 | + data.web3_wallet, |
| 74 | + data.password_enabled, |
| 75 | + data.first_name, |
| 76 | + data.last_name, |
| 77 | + data.custom_action, |
| 78 | + data.external_id, |
| 79 | + data.created_session_id, |
| 80 | + data.created_user_id, |
| 81 | + data.abandon_at, |
| 82 | + data.legal_accepted_at, |
| 83 | + data.public_metadata, |
| 84 | + data.unsafe_metadata, |
| 85 | + ); |
| 86 | + } |
| 87 | +} |
0 commit comments