import { api as client } from "../auth/http"; import { unwrap } from "@/utils/endpoint"; export type ContactChannel = "email" | "phone"; export interface ChangePasswordPayload { oldPassword: string; newPassword: string; confirmPassword: string; } export interface SendContactOtpPayload { channel: ContactChannel; /** The NEW email/phone to verify — the OTP is sent here, not to the current one. */ value: string; } export interface UpdateContactPayload extends SendContactOtpPayload { otp: string; } export const accountService = { /** PATCH /auth/change-password — generic IAM route, works for any user type. */ changePassword: async (payload: ChangePasswordPayload): Promise => { const response = await client.patch("/auth/change-password", payload); unwrap(response.data); }, /** POST /me/contact/otp — sends a code to the new email/phone to prove ownership. */ sendContactOtp: async ( payload: SendContactOtpPayload, ): Promise<{ sentTo: string }> => { const response = await client.post<{ sentTo: string }>( "/me/contact/otp", payload, ); return unwrap(response.data); }, /** PATCH /me/contact — verifies the OTP and writes the new email/phone. */ updateContact: async ( payload: UpdateContactPayload, ): Promise<{ success: true; value: string }> => { const response = await client.patch<{ success: true; value: string }>( "/me/contact", payload, ); return unwrap(response.data); }, };