mirror of
https://github.com/jakejarvis/rdapper.git
synced 2025-10-18 20:14:27 -04:00
Make the (very minimal) CLI official
This commit is contained in:
11
README.md
11
README.md
@@ -53,6 +53,15 @@ toRegistrableDomain("192.168.0.1"); // => null
|
|||||||
- `isRegistered(domain, options?) => Promise<boolean>`
|
- `isRegistered(domain, options?) => Promise<boolean>`
|
||||||
- `isAvailable(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)
|
### 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:
|
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/whois/` – WHOIS TCP client, discovery/referral, normalization, exceptions
|
||||||
- `src/lib/` – utilities for dates, text parsing, domain processing, async
|
- `src/lib/` – utilities for dates, text parsing, domain processing, async
|
||||||
- `src/types.ts` – public types; `src/index.ts` re‑exports API and types
|
- `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
|
## Caveats
|
||||||
|
|
||||||
|
32
bin/cli.js
Executable file
32
bin/cli.js
Executable 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
28
cli.mjs
@@ -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));
|
|
||||||
}
|
|
@@ -15,15 +15,19 @@
|
|||||||
"email": "jake@jarv.is",
|
"email": "jake@jarv.is",
|
||||||
"url": "https://jarv.is"
|
"url": "https://jarv.is"
|
||||||
},
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.js",
|
"module": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
|
"bin": "./bin/cli.js",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"default": "./dist/index.js",
|
||||||
"import": "./dist/index.js",
|
"import": "./dist/index.js",
|
||||||
"default": "./dist/index.js"
|
"types": "./dist/index.d.ts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -32,6 +36,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsdown",
|
"build": "tsdown",
|
||||||
"dev": "tsdown --watch",
|
"dev": "tsdown --watch",
|
||||||
|
"cli": "node bin/cli.cjs",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"test": "vitest",
|
"test": "vitest",
|
||||||
"test:run": "vitest run",
|
"test:run": "vitest run",
|
||||||
|
@@ -34,10 +34,9 @@ async function queryTcp(
|
|||||||
query: string,
|
query: string,
|
||||||
options?: LookupOptions,
|
options?: LookupOptions,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
let net: typeof import("net") | null;
|
let net: typeof import("node:net") | null;
|
||||||
try {
|
try {
|
||||||
// biome-ignore lint/style/useNodejsImportProtocol: compatibility
|
net = await import("node:net");
|
||||||
net = await import("net");
|
|
||||||
} catch {
|
} catch {
|
||||||
net = null;
|
net = null;
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,9 @@
|
|||||||
import { defineConfig } from "tsdown";
|
import { defineConfig } from "tsdown";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
entry: ["src/index.ts"],
|
|
||||||
platform: "node",
|
platform: "node",
|
||||||
|
entry: ["src/index.ts"],
|
||||||
dts: true,
|
dts: true,
|
||||||
|
nodeProtocol: "strip",
|
||||||
external: ["tldts"],
|
external: ["tldts"],
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user