1
mirror of https://github.com/jakejarvis/rdapper.git synced 2025-10-18 14:24:29 -04:00

Make the (very minimal) CLI official

This commit is contained in:
2025-10-12 17:14:37 -04:00
parent 35c73e2bb2
commit 08a5b9a576
6 changed files with 53 additions and 35 deletions

View File

@@ -53,6 +53,15 @@ toRegistrableDomain("192.168.0.1"); // => null
- `isRegistered(domain, options?) => Promise<boolean>`
- `isAvailable(domain, options?) => Promise<boolean>`
### 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` reexports API and types
- `cli.mjs` local CLI helper for quick testing
- `bin/cli.js` simple CLI for quick checks
## Caveats

32
bin/cli.js Executable file
View File

@@ -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();

28
cli.mjs
View File

@@ -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));
}

View File

@@ -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",

View File

@@ -34,10 +34,9 @@ async function queryTcp(
query: string,
options?: LookupOptions,
): Promise<string> {
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;
}

View File

@@ -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"],
});