#!/usr/bin/env node // domaroo on the command line (plan 15, f38: t409). One file, no packages: Node 18 or newer. // It reads your account through the domaroo API (https://domaroo.com/api) with a token from Settings, AI agents (MCP). // // export DOMAROO_TOKEN=dmr_... // node domaroo.mjs renewals --days 60 // // Commands: domains [text], domain , renewals [--days N], forecast, savings, attention. Add --json for the raw answer. // It only reads. The source is this file: read it before you run it. const VERSION = "1.0.0"; const HELP = `domaroo ${VERSION}: your domains, renewals and costs from domaroo.com Usage: node domaroo.mjs [options] domains [text] your domains, with expiration date, registrar and renewal price domain everything about one domain renewals what renews in the next 30 days, with the total (--days N, up to 730) forecast what renewals cost next month, quarter and year savings domains that renew for less elsewhere attention what needs you now Options: --json (the API's answer as it is), --help Token: DOMAROO_TOKEN, made in Settings, AI agents (MCP). Address: DOMAROO_URL (default https://domaroo.com).`; const money = (n, cur) => (n == null ? "no price" : new Intl.NumberFormat("en-US", { style: "currency", currency: cur || "USD" }).format(n)); const pad = (s, n) => String(s ?? "").padEnd(n); function table(rows, cols) { const widths = cols.map(([h, f]) => Math.min(40, Math.max(h.length, ...rows.map((r) => String(f(r) ?? "").length)))); const line = (cells) => cells.map((c, i) => pad(String(c ?? "").slice(0, widths[i]), widths[i])).join(" ").trimEnd(); return [line(cols.map(([h]) => h)), line(widths.map((w) => "-".repeat(w))), ...rows.map((r) => line(cols.map(([, f]) => f(r))))].join("\n"); } const domainCols = (cur) => [["Domain", (d) => d.name], ["Expires", (d) => d.expires || "no date"], ["Registrar", (d) => d.registrar || ""], ["Renewal", (d) => (d.renewal_price ? money(d.renewal_price.amount, d.renewal_price.currency) : "no price")], ["Cheaper at", (d) => (d.cheaper_at ? `${d.cheaper_at.registrar}, saves ${money(d.cheaper_at.saves_per_year, cur)}/yr` : "")]]; export function render(command, out) { const cur = out.currency; if (command === "domains") return `${table(out.domains, domainCols(cur))}\n\n${out.total} domains${out.total > out.domains.length ? `, ${out.domains.length} shown` : ""}`; if (command === "renewals") return `${out.renewals.length ? table(out.renewals, domainCols(cur)) : `Nothing renews in the next ${out.days} days.`}\n\nTotal: ${money(out.total, cur)}${out.renewals_without_price ? `, and ${out.renewals_without_price} with no price` : ""}`; if (command === "savings") return out.savings.length ? `${table(out.savings, domainCols(cur))}\n\nSaves ${money(out.total_per_year, cur)} a year on ${out.domains} domains` : "No domain renews for less elsewhere."; if (command === "forecast") { const p = (label, x) => `${pad(label, 14)}${money(x.total, cur)} (${x.renewals} renewals${x.without_price ? `, ${x.without_price} with no price` : ""})`; return [p("Next month", out.next_month), p("Next quarter", out.next_quarter), p("Next year", out.next_year), `${pad("Per year", 14)}${money(out.cost_per_year, cur)}`].join("\n"); } if (command === "attention") return out.items.length ? out.items.map((i) => `${i.title}: ${i.count}${i.hint ? `\n ${i.hint}` : ""}\n ${i.domains.join(", ")}`).join("\n") : "Nothing needs you now."; if (command === "domain") { const d = out; return [`${d.name}`, `Expires ${d.expires || "no date"} (${d.state})`, `Registrar ${d.registrar || "unknown"}`, `Renewal ${d.renewal_price ? `${money(d.renewal_price.amount, d.renewal_price.currency)} every ${d.renewal_price.years} year(s)` : "no price"}`, `Auto-renew ${d.auto_renew}`, `Decision ${d.decision}`, d.tags.length ? `Tags ${d.tags.join(", ")}` : null, d.cheaper_at ? `Cheaper at ${d.cheaper_at.registrar}, saves ${money(d.cheaper_at.saves_per_year, cur)} a year` : null, d.certificate_ends ? `Certificate ends ${d.certificate_ends}` : null, d.note ? `Note ${d.note}` : null].filter(Boolean).join("\n"); } return JSON.stringify(out, null, 2); } export function address(command, args) { const days = args.indexOf("--days"); if (command === "domains") return `/api/v1/domains?limit=1000${args[0] && !args[0].startsWith("--") ? `&query=${encodeURIComponent(args[0])}` : ""}`; if (command === "domain") return args[0] ? `/api/v1/domains/${encodeURIComponent(args[0])}` : null; if (command === "renewals") return `/api/v1/renewals${days >= 0 && /^\d{1,3}$/.test(args[days + 1] || "") ? `?days=${args[days + 1]}` : ""}`; return { forecast: "/api/v1/forecast", savings: "/api/v1/savings", attention: "/api/v1/attention" }[command] || null; } export async function main(argv, { env = process.env, fetchFn = fetch, write = (s) => process.stdout.write(`${s}\n`), fail = (s) => process.stderr.write(`${s}\n`) } = {}) { const [command, ...args] = argv; if (!command || command === "--help" || command === "help") { write(HELP); return 0; } if (command === "--version") { write(VERSION); return 0; } const path = address(command, args); if (!path) { fail(command === "domain" ? "Which domain? For example: node domaroo.mjs domain example.com" : `Unknown command: ${command}. Try --help.`); return 2; } const token = env.DOMAROO_TOKEN; if (!token) { fail("Set DOMAROO_TOKEN to a token from domaroo Settings, AI agents (MCP)."); return 2; } const base = (env.DOMAROO_URL || "https://domaroo.com").replace(/\/$/, ""); let res; try { res = await fetchFn(base + path, { headers: { Authorization: `Bearer ${token}`, Accept: "application/json", "User-Agent": `domaroo-cli/${VERSION}` }, signal: AbortSignal.timeout(30000) }); } catch (err) { fail(`Couldn't reach ${base}: ${err.message}`); return 1; } const out = await res.json().catch(() => null); if (!res.ok || !out) { fail(out?.error || `domaroo answered ${res.status}.`); return 1; } write(args.includes("--json") ? JSON.stringify(out, null, 2) : render(command, out)); return 0; } if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("domaroo.mjs")) { main(process.argv.slice(2)).then((code) => { process.exitCode = code; }); }