86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
|
|
/**
|
||
|
|
* Get Started API Client
|
||
|
|
*
|
||
|
|
* API calls for the unified get-started flow
|
||
|
|
*/
|
||
|
|
|
||
|
|
import { apiClient, getDataOrThrow } from "@/core/api";
|
||
|
|
import {
|
||
|
|
sendVerificationCodeResponseSchema,
|
||
|
|
verifyCodeResponseSchema,
|
||
|
|
quickEligibilityResponseSchema,
|
||
|
|
maybeLaterResponseSchema,
|
||
|
|
type SendVerificationCodeRequest,
|
||
|
|
type SendVerificationCodeResponse,
|
||
|
|
type VerifyCodeRequest,
|
||
|
|
type VerifyCodeResponse,
|
||
|
|
type QuickEligibilityRequest,
|
||
|
|
type QuickEligibilityResponse,
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Quick eligibility check (guest flow)
|
||
|
|
*/
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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);
|
||
|
|
}
|