import axios from "axios"; import { CustomError } from "@nimee/error-handler"; const port = process.env.USER_PORT; const basePath = process.env.IS_LOCAL === "true" ? `http://127.0.0.1:${port}` : "http://user"; const baseUrl = `${basePath}/user`; /** * Client for the user-service voucher-source routes (external voucher redemption, #801). * Only the internal `resolve` is used by the backend — it returns the source WITH credentials and is * gated to the fixed JWT_ADMIN service token. (The public grid is read by the FE directly.) */ export class VoucherSourceClient { /** Fetch a voucher source WITH its decrypted credentials via the internal JWT_ADMIN-only resolve route. */ async resolve(params: { jwt: string; id: string }) { const { jwt, id } = params; if (!jwt || !id) { throw new CustomError("params_missing_voucher_source_resolve", 400, `id: ${id}`); } const response = await axios.get(`${baseUrl}/voucher-source/${id}/resolve`, { headers: { jwt } }); return response?.data; } }