import BaseService from '..'; import type { ISetupProgress } from './setup-progress.interface'; import { GET_SETUP_PROGRESS, updateSetupProgressStep, } from './setup-progress.routes'; interface ISetupProgressResponse { setup_progress?: ISetupProgress; success?: boolean; error?: string; } /** * Read the merchant's onboarding state from dashboard-api. * * @return {Promise} */ export const getSetupProgress = async (): Promise => { const response: ISetupProgressResponse = await BaseService.get(GET_SETUP_PROGRESS); return response?.setup_progress ?? null; }; /** * Flip a single step. Idempotent. Returns null on transport error so call * sites can stay fire-and-forget. * * @param {string} step * @param {boolean} completed * @return {Promise} */ export const setSetupProgressStep = async ( step: string, completed: boolean = true ): Promise => { if (!step) return null; const response: ISetupProgressResponse = await BaseService.patch( updateSetupProgressStep(step), { completed } ); if (response?.error) return null; return response?.setup_progress ?? null; };