2026-01-14 13:54:01 +09:00
|
|
|
/**
|
|
|
|
|
* Get Started API Client
|
|
|
|
|
*
|
|
|
|
|
* API calls for the unified get-started flow
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { apiClient, getDataOrThrow } from "@/core/api";
|
|
|
|
|
import {
|
|
|
|
|
sendVerificationCodeResponseSchema,
|
|
|
|
|
verifyCodeResponseSchema,
|
|
|
|
|
quickEligibilityResponseSchema,
|
2026-01-14 17:14:07 +09:00
|
|
|
guestEligibilityResponseSchema,
|
2026-01-14 13:54:01 +09:00
|
|
|
maybeLaterResponseSchema,
|
|
|
|
|
type SendVerificationCodeRequest,
|
|
|
|
|
type SendVerificationCodeResponse,
|
|
|
|
|
type VerifyCodeRequest,
|
|
|
|
|
type VerifyCodeResponse,
|
|
|
|
|
type QuickEligibilityRequest,
|
|
|
|
|
type QuickEligibilityResponse,
|
2026-01-14 17:14:07 +09:00
|
|
|
type GuestEligibilityRequest,
|
|
|
|
|
type GuestEligibilityResponse,
|
2026-01-14 13:54:01 +09:00
|
|
|
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<SendVerificationCodeResponse> {
|
|
|
|
|
const response = await apiClient.POST<SendVerificationCodeResponse>(`${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<VerifyCodeResponse> {
|
|
|
|
|
const response = await apiClient.POST<VerifyCodeResponse>(`${BASE_PATH}/verify-code`, {
|
|
|
|
|
body: request,
|
|
|
|
|
});
|
|
|
|
|
const data = getDataOrThrow(response, "Failed to verify code");
|
|
|
|
|
return verifyCodeResponseSchema.parse(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-14 17:14:07 +09:00
|
|
|
* Quick eligibility check (guest flow) - requires OTP verification
|
2026-01-14 13:54:01 +09:00
|
|
|
*/
|
|
|
|
|
export async function quickEligibilityCheck(
|
|
|
|
|
request: QuickEligibilityRequest
|
|
|
|
|
): Promise<QuickEligibilityResponse> {
|
|
|
|
|
const response = await apiClient.POST<QuickEligibilityResponse>(`${BASE_PATH}/quick-check`, {
|
|
|
|
|
body: request,
|
|
|
|
|
});
|
|
|
|
|
const data = getDataOrThrow(response, "Failed to submit eligibility check");
|
|
|
|
|
return quickEligibilityResponseSchema.parse(data);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 17:14:07 +09:00
|
|
|
/**
|
|
|
|
|
* 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<GuestEligibilityResponse> {
|
|
|
|
|
const response = await apiClient.POST<GuestEligibilityResponse>(
|
|
|
|
|
`${BASE_PATH}/guest-eligibility`,
|
|
|
|
|
{ body: request }
|
|
|
|
|
);
|
|
|
|
|
const data = getDataOrThrow(response, "Failed to submit eligibility check");
|
|
|
|
|
return guestEligibilityResponseSchema.parse(data);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-14 13:54:01 +09:00
|
|
|
/**
|
|
|
|
|
* Maybe later flow - create SF account and eligibility case
|
|
|
|
|
*/
|
|
|
|
|
export async function maybeLater(request: MaybeLaterRequest): Promise<MaybeLaterResponse> {
|
|
|
|
|
const response = await apiClient.POST<MaybeLaterResponse>(`${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<AuthResponse> {
|
|
|
|
|
const response = await apiClient.POST<AuthResponse>(`${BASE_PATH}/complete-account`, {
|
|
|
|
|
body: request,
|
|
|
|
|
});
|
|
|
|
|
const data = getDataOrThrow(response, "Failed to complete account");
|
|
|
|
|
return authResponseSchema.parse(data);
|
|
|
|
|
}
|