diff --git a/README.md b/README.md index 156bdcd..a226a3c 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,15 @@ toRegistrableDomain("192.168.0.1"); // => null - `isRegistered(domain, options?) => Promise` - `isAvailable(domain, options?) => Promise` +### CLI + +For quick checks, a minimal CLI is included: + +```bash +npx rdapper example.com +echo "example.com" | npx rdapper +``` + ### Edge runtimes (e.g., Vercel Edge) WHOIS requires a raw TCP connection over port 43 via `node:net`, which is not available on edge runtimes. This package lazily loads `node:net` only when the WHOIS code path runs. To use rdapper safely on edge: @@ -196,7 +205,7 @@ Project layout: - `src/whois/` – WHOIS TCP client, discovery/referral, normalization, exceptions - `src/lib/` – utilities for dates, text parsing, domain processing, async - `src/types.ts` – public types; `src/index.ts` re‑exports API and types -- `cli.mjs` – local CLI helper for quick testing +- `bin/cli.js` – simple CLI for quick checks ## Caveats diff --git a/bin/cli.js b/bin/cli.js new file mode 100755 index 0000000..875163b --- /dev/null +++ b/bin/cli.js @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +// Quick informal command-line interface for rdapper +// Usage: +// npx rdapper example.com +// echo "example.com" | npx rdapper + +import { createInterface } from "node:readline"; +import { lookupDomain } from "../dist/index.js"; + +async function main() { + if (process.argv.length > 2) { + // URL(s) specified in the command arguments + console.log( + JSON.stringify( + await lookupDomain(process.argv[process.argv.length - 1]), + null, + 2, + ), + ); + } else { + // No domain passed as argument, read from each line of stdin + const rlInterface = createInterface({ + input: process.stdin, + }); + rlInterface.on("line", async (line) => { + console.log(JSON.stringify(await lookupDomain(line), null, 2)); + }); + } +} + +main(); diff --git a/cli.mjs b/cli.mjs deleted file mode 100755 index 5d5e6e1..0000000 --- a/cli.mjs +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env node - -// Quick informal test runner for rdapper -// Usage: -// npm run build && node cli.mjs example.com -// Env: -// RDAP_ONLY=1 | WHOIS_ONLY=1 | TIMEOUT_MS=15000 | FOLLOW_REFERRAL=0 | INCLUDE_RAW=1 - -import { lookupDomain } from "./dist/index.js"; - -const domain = process.argv[2] ?? "example.com"; - -const options = { - timeoutMs: process.env.TIMEOUT_MS ? Number(process.env.TIMEOUT_MS) : 15000, - followWhoisReferral: process.env.FOLLOW_REFERRAL !== "0", - rdapOnly: process.env.RDAP_ONLY === "1", - whoisOnly: process.env.WHOIS_ONLY === "1", - includeRaw: process.env.INCLUDE_RAW === "1", -}; - -const result = await lookupDomain(domain, options); - -if (!result.ok) { - console.error("Error:", result.error); - process.exitCode = 1; -} else { - console.log(JSON.stringify(result.record, null, 2)); -} diff --git a/package.json b/package.json index a07e295..24b9411 100644 --- a/package.json +++ b/package.json @@ -15,15 +15,19 @@ "email": "jake@jarv.is", "url": "https://jarv.is" }, + "publishConfig": { + "access": "public" + }, "type": "module", "main": "./dist/index.js", "module": "./dist/index.js", "types": "./dist/index.d.ts", + "bin": "./bin/cli.js", "exports": { ".": { - "types": "./dist/index.d.ts", + "default": "./dist/index.js", "import": "./dist/index.js", - "default": "./dist/index.js" + "types": "./dist/index.d.ts" } }, "files": [ @@ -32,6 +36,7 @@ "scripts": { "build": "tsdown", "dev": "tsdown --watch", + "cli": "node bin/cli.cjs", "typecheck": "tsc --noEmit", "test": "vitest", "test:run": "vitest run", diff --git a/src/whois/client.ts b/src/whois/client.ts index 20ebb02..40ceca4 100644 --- a/src/whois/client.ts +++ b/src/whois/client.ts @@ -34,10 +34,9 @@ async function queryTcp( query: string, options?: LookupOptions, ): Promise { - let net: typeof import("net") | null; + let net: typeof import("node:net") | null; try { - // biome-ignore lint/style/useNodejsImportProtocol: compatibility - net = await import("net"); + net = await import("node:net"); } catch { net = null; } diff --git a/tsdown.config.ts b/tsdown.config.ts index 512c2d1..669c5ca 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -1,8 +1,9 @@ import { defineConfig } from "tsdown"; export default defineConfig({ - entry: ["src/index.ts"], platform: "node", + entry: ["src/index.ts"], dts: true, + nodeProtocol: "strip", external: ["tldts"], });