const baseUrl = process.env.API_BASE_URL || "http://127.0.0.1:3040"; const apiPath = process.env.API_PATH || "/v1/profile"; const token = process.env.API_TOKEN; async function fetchJson(path) { const url = new URL(path, baseUrl); const headers = { Accept: "application/json" }; if (token) { headers.Authorization = `Bearer ${token}`; } const response = await fetch(url, { headers, signal: AbortSignal.timeout(5000), }); const contentType = response.headers.get("content-type") || ""; const body = contentType.includes("application/json") ? await response.json() : await response.text(); if (!response.ok) { const detail = typeof body === "string" ? body : JSON.stringify(body); throw new Error(`Request failed with ${response.status}: ${detail}`); } return { status: response.status, body }; } try { const { status, body } = await fetchJson(apiPath); console.log(`status=${status}`); console.log(`name=${body.name}`); console.log(`plan=${body.plan}`); } catch (error) { console.error(error.message); process.exitCode = 1; }