import axios, { AxiosInstance } from "axios"; import { createApiClient } from "../../auth/src"; /** * We expose a singleton-like getter/setter for the API clients */ let _api: AxiosInstance | null = null; let _auth: AxiosInstance | null = null; export const api = { get: (...args: Parameters) => { if (!_api) throw new Error("API client not initialized"); return _api.get(...args); }, post: (...args: Parameters) => { if (!_api) throw new Error("API client not initialized"); return _api.post(...args); }, put: (...args: Parameters) => { if (!_api) throw new Error("API client not initialized"); return _api.put(...args); }, delete: (...args: Parameters) => { if (!_api) throw new Error("API client not initialized"); return _api.delete(...args); }, }; export const auth = { post: (...args: Parameters) => { if (!_auth) throw new Error("Auth client not initialized"); return _auth.post(...args); }, get: (...args: Parameters) => { if (!_auth) throw new Error("Auth client not initialized"); return _auth.get(...args); }, }; export function initializeApiClients(baseUrl: string, authBaseUrl: string) { _api = createApiClient(baseUrl); _auth = createApiClient(authBaseUrl); }