/** * Get Started API Client * * API calls for the unified get-started flow */ import { apiClient, getDataOrThrow } from "@/core/api"; import { sendVerificationCodeResponseSchema, verifyCodeResponseSchema, quickEligibilityResponseSchema, guestEligibilityResponseSchema, maybeLaterResponseSchema, type SendVerificationCodeRequest, type SendVerificationCodeResponse, type VerifyCodeRequest, type VerifyCodeResponse, type QuickEligibilityRequest, type QuickEligibilityResponse, type GuestEligibilityRequest, type GuestEligibilityResponse, type CompleteAccountRequest, type MaybeLaterRequest, type MaybeLaterResponse, } from "@customer-portal/domain/get-started"; import { authResponseSchema, type AuthResponse } from "@customer-portal/domain/auth"; const BASE_PATH = "/api/auth/get-started"; /** * Send OTP verification code to email */ export async function sendVerificationCode( request: SendVerificationCodeRequest ): Promise { const response = await apiClient.POST(`${BASE_PATH}/send-code`, { body: request, }); const data = getDataOrThrow(response, "Failed to send verification code"); return sendVerificationCodeResponseSchema.parse(data); } /** * Verify OTP code and get account status */ export async function verifyCode(request: VerifyCodeRequest): Promise { const response = await apiClient.POST(`${BASE_PATH}/verify-code`, { body: request, }); const data = getDataOrThrow(response, "Failed to verify code"); return verifyCodeResponseSchema.parse(data); } /** * Quick eligibility check (guest flow) - requires OTP verification */ export async function quickEligibilityCheck( request: QuickEligibilityRequest ): Promise { const response = await apiClient.POST(`${BASE_PATH}/quick-check`, { body: request, }); const data = getDataOrThrow(response, "Failed to submit eligibility check"); return quickEligibilityResponseSchema.parse(data); } /** * Guest eligibility check - NO OTP verification required * Allows users to check availability without verifying email first * Email verification happens later when user creates an account */ export async function guestEligibilityCheck( request: GuestEligibilityRequest ): Promise { const response = await apiClient.POST( `${BASE_PATH}/guest-eligibility`, { body: request } ); const data = getDataOrThrow(response, "Failed to submit eligibility check"); return guestEligibilityResponseSchema.parse(data); } /** * Maybe later flow - create SF account and eligibility case */ export async function maybeLater(request: MaybeLaterRequest): Promise { const response = await apiClient.POST(`${BASE_PATH}/maybe-later`, { body: request, }); const data = getDataOrThrow(response, "Failed to submit request"); return maybeLaterResponseSchema.parse(data); } /** * Complete account for SF-only users * Returns auth response with user and session */ export async function completeAccount(request: CompleteAccountRequest): Promise { const response = await apiClient.POST(`${BASE_PATH}/complete-account`, { body: request, }); const data = getDataOrThrow(response, "Failed to complete account"); return authResponseSchema.parse(data); }