const fs = require("fs"); const path = require("path"); const env = fs.readFileSync(path.join(__dirname, "..", ".env"), "utf8"); const m = env.match(/BASELINKER_API_TOKEN\s*=\s*(\S+)/); if (!m) throw new Error("brak tokenu"); const TOKEN = m[1]; const API = "https://api.baselinker.com/connector.php"; async function bl(method, parameters) { const body = new URLSearchParams({ method, parameters: JSON.stringify(parameters || {}) }); const r = await fetch(API, { method: "POST", headers: { "X-BLToken": TOKEN, "Content-Type": "application/x-www-form-urlencoded" }, body }); return r.json(); } (async () => { const [method, paramsJson] = [process.argv[2], process.argv[3] || "{}"]; const j = await bl(method, JSON.parse(paramsJson)); console.log(JSON.stringify(j, null, 1)); })().catch(e => { console.error("ERR", e.message); process.exit(1); });