2026-01-14 13:54:01 +09:00
|
|
|
/**
|
|
|
|
|
* Get Started Domain - Contract
|
|
|
|
|
*
|
|
|
|
|
* Types and constants for the unified "Get Started" flow that handles:
|
|
|
|
|
* - Email verification (OTP)
|
|
|
|
|
* - Account status detection
|
2026-01-15 16:11:11 +09:00
|
|
|
* - Guest eligibility check (no OTP required)
|
2026-01-14 13:54:01 +09:00
|
|
|
* - Account completion for SF-only accounts
|
2026-01-15 16:11:11 +09:00
|
|
|
* - Signup with eligibility (full flow)
|
2026-01-14 13:54:01 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import type { z } from "zod";
|
|
|
|
|
|
|
|
|
|
import type {
|
|
|
|
|
sendVerificationCodeRequestSchema,
|
|
|
|
|
sendVerificationCodeResponseSchema,
|
|
|
|
|
verifyCodeRequestSchema,
|
|
|
|
|
verifyCodeResponseSchema,
|
2026-01-15 12:38:16 +09:00
|
|
|
bilingualEligibilityAddressSchema,
|
2026-01-14 17:14:07 +09:00
|
|
|
guestEligibilityRequestSchema,
|
|
|
|
|
guestEligibilityResponseSchema,
|
|
|
|
|
guestHandoffTokenSchema,
|
2026-01-14 13:54:01 +09:00
|
|
|
completeAccountRequestSchema,
|
2026-01-15 11:28:25 +09:00
|
|
|
signupWithEligibilityRequestSchema,
|
|
|
|
|
signupWithEligibilityResponseSchema,
|
2026-01-14 13:54:01 +09:00
|
|
|
getStartedSessionSchema,
|
|
|
|
|
} from "./schema.js";
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Constants
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Account status after email verification
|
|
|
|
|
* Determines which flow the user should follow
|
|
|
|
|
*/
|
|
|
|
|
export const ACCOUNT_STATUS = {
|
|
|
|
|
/** User has a portal account - redirect to login */
|
|
|
|
|
PORTAL_EXISTS: "portal_exists",
|
|
|
|
|
/** User has WHMCS account but no portal - migrate flow */
|
|
|
|
|
WHMCS_UNMAPPED: "whmcs_unmapped",
|
|
|
|
|
/** User has SF account but no WHMCS/portal - complete account flow */
|
|
|
|
|
SF_UNMAPPED: "sf_unmapped",
|
|
|
|
|
/** No account exists - full signup flow */
|
|
|
|
|
NEW_CUSTOMER: "new_customer",
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
export type AccountStatus = (typeof ACCOUNT_STATUS)[keyof typeof ACCOUNT_STATUS];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* OTP verification error codes
|
|
|
|
|
*/
|
|
|
|
|
export const OTP_ERROR_CODE = {
|
|
|
|
|
/** Code has expired */
|
|
|
|
|
EXPIRED: "otp_expired",
|
|
|
|
|
/** Invalid code entered */
|
|
|
|
|
INVALID: "otp_invalid",
|
|
|
|
|
/** Too many failed attempts */
|
|
|
|
|
MAX_ATTEMPTS: "otp_max_attempts",
|
|
|
|
|
/** Rate limit exceeded for sending codes */
|
|
|
|
|
RATE_LIMITED: "otp_rate_limited",
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
export type OtpErrorCode = (typeof OTP_ERROR_CODE)[keyof typeof OTP_ERROR_CODE];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Started flow error codes
|
|
|
|
|
*/
|
|
|
|
|
export const GET_STARTED_ERROR_CODE = {
|
|
|
|
|
/** Session token is invalid or expired */
|
|
|
|
|
INVALID_SESSION: "invalid_session",
|
|
|
|
|
/** Email not verified yet */
|
|
|
|
|
EMAIL_NOT_VERIFIED: "email_not_verified",
|
|
|
|
|
/** SF account creation failed */
|
|
|
|
|
SF_CREATION_FAILED: "sf_creation_failed",
|
|
|
|
|
/** WHMCS account creation failed */
|
|
|
|
|
WHMCS_CREATION_FAILED: "whmcs_creation_failed",
|
|
|
|
|
} as const;
|
|
|
|
|
|
|
|
|
|
export type GetStartedErrorCode =
|
|
|
|
|
(typeof GET_STARTED_ERROR_CODE)[keyof typeof GET_STARTED_ERROR_CODE];
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Request Types
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export type SendVerificationCodeRequest = z.infer<typeof sendVerificationCodeRequestSchema>;
|
|
|
|
|
export type VerifyCodeRequest = z.infer<typeof verifyCodeRequestSchema>;
|
2026-01-15 12:38:16 +09:00
|
|
|
export type BilingualEligibilityAddress = z.infer<typeof bilingualEligibilityAddressSchema>;
|
2026-01-14 17:14:07 +09:00
|
|
|
export type GuestEligibilityRequest = z.infer<typeof guestEligibilityRequestSchema>;
|
2026-01-14 13:54:01 +09:00
|
|
|
export type CompleteAccountRequest = z.infer<typeof completeAccountRequestSchema>;
|
2026-01-15 11:28:25 +09:00
|
|
|
export type SignupWithEligibilityRequest = z.infer<typeof signupWithEligibilityRequestSchema>;
|
2026-01-14 13:54:01 +09:00
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Response Types
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export type SendVerificationCodeResponse = z.infer<typeof sendVerificationCodeResponseSchema>;
|
|
|
|
|
export type VerifyCodeResponse = z.infer<typeof verifyCodeResponseSchema>;
|
2026-01-14 17:14:07 +09:00
|
|
|
export type GuestEligibilityResponse = z.infer<typeof guestEligibilityResponseSchema>;
|
2026-01-15 11:28:25 +09:00
|
|
|
export type SignupWithEligibilityResponse = z.infer<typeof signupWithEligibilityResponseSchema>;
|
2026-01-14 13:54:01 +09:00
|
|
|
|
2026-01-14 17:14:07 +09:00
|
|
|
// ============================================================================
|
|
|
|
|
// Handoff Token Types
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export type GuestHandoffToken = z.infer<typeof guestHandoffTokenSchema>;
|
|
|
|
|
|
2026-01-14 13:54:01 +09:00
|
|
|
// ============================================================================
|
|
|
|
|
// Session Types
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export type GetStartedSession = z.infer<typeof getStartedSessionSchema>;
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
// Error Types
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
|
|
export interface GetStartedError {
|
|
|
|
|
code: OtpErrorCode | GetStartedErrorCode;
|
|
|
|
|
message: string;
|
|
|
|
|
}
|