netriskscan-cli 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -10,6 +10,7 @@ import { Command, CommanderError } from "commander";
10
10
  import ora from "ora";
11
11
 
12
12
  // src/client/errors.ts
13
+ var ANONYMOUS_DAILY_LIMIT_CODE = "anonymous_daily_limit_reached";
13
14
  var NetRiskScanError = class extends Error {
14
15
  constructor(message) {
15
16
  super(message);
@@ -27,6 +28,8 @@ var NetRiskScanApiError = class extends NetRiskScanError {
27
28
  code;
28
29
  requestId;
29
30
  retryAfter;
31
+ /** Present when the server reported anonymous-trial allowance alongside the error. */
32
+ anonymousUsage;
30
33
  constructor(message, options) {
31
34
  super(message);
32
35
  this.name = "NetRiskScanApiError";
@@ -34,6 +37,7 @@ var NetRiskScanApiError = class extends NetRiskScanError {
34
37
  this.code = options.code;
35
38
  this.requestId = options.requestId;
36
39
  this.retryAfter = options.retryAfter;
40
+ this.anonymousUsage = options.anonymousUsage;
37
41
  }
38
42
  };
39
43
  var NetRiskScanNetworkError = class extends NetRiskScanError {
@@ -80,6 +84,10 @@ function parseQuota(headers) {
80
84
  function isRetryableStatus(status) {
81
85
  return status === 429 || status === 503;
82
86
  }
87
+ function isRetryableFailure(status, code) {
88
+ if (code === ANONYMOUS_DAILY_LIMIT_CODE) return false;
89
+ return isRetryableStatus(status);
90
+ }
83
91
  var BASE_DELAY_MS = 1e3;
84
92
  var MAX_JITTER_MS = 250;
85
93
  function computeBackoffMs(attempt, retryAfterSeconds) {
@@ -108,18 +116,22 @@ async function safeJson(res) {
108
116
  return void 0;
109
117
  }
110
118
  }
119
+ function parseAnonymousLimitInfo(body) {
120
+ const error = body?.error;
121
+ if (!error) return void 0;
122
+ const { dailyLimit, used, remaining, resetAt, signupUrl } = error;
123
+ if (dailyLimit === void 0 && used === void 0 && remaining === void 0 && resetAt === void 0 && signupUrl === void 0) {
124
+ return void 0;
125
+ }
126
+ return { dailyLimit, used, remaining, resetAt, signupUrl };
127
+ }
111
128
  var NetRiskScanClient = class {
112
129
  apiKey;
113
130
  baseUrl;
114
131
  timeout;
115
132
  maxRetries;
116
- constructor(options) {
117
- if (!options.apiKey) {
118
- throw new NetRiskScanConfigError(
119
- "NetRiskScan API key is required.\n\nSet NETRISKSCAN_API_KEY or use --api-key."
120
- );
121
- }
122
- this.apiKey = options.apiKey;
133
+ constructor(options = {}) {
134
+ this.apiKey = options.apiKey || void 0;
123
135
  this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
124
136
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
125
137
  this.maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
@@ -127,7 +139,14 @@ var NetRiskScanClient = class {
127
139
  async checkIp(ip, options = {}) {
128
140
  return this.request(`/v1/ip-risk/${encodeURIComponent(ip)}`, options);
129
141
  }
142
+ /**
143
+ * Account plan, billing period and quota. Unlike {@link checkIp} this is account data, so it
144
+ * has no anonymous equivalent and requires an API key.
145
+ */
130
146
  async getUsage(options = {}) {
147
+ if (!this.apiKey) {
148
+ throw new NetRiskScanConfigError("An API key is required to query account usage.");
149
+ }
131
150
  return this.request("/v1/usage", options);
132
151
  }
133
152
  async request(path, options) {
@@ -139,13 +158,16 @@ var NetRiskScanClient = class {
139
158
  const onExternalAbort = () => timeoutController.abort();
140
159
  options.signal?.addEventListener("abort", onExternalAbort);
141
160
  try {
161
+ const headers = {
162
+ Accept: "application/json",
163
+ "X-Request-Id": requestId
164
+ };
165
+ if (this.apiKey) {
166
+ headers.Authorization = `Bearer ${this.apiKey}`;
167
+ }
142
168
  const res = await fetch(`${this.baseUrl}${path}`, {
143
169
  method: "GET",
144
- headers: {
145
- Authorization: `Bearer ${this.apiKey}`,
146
- Accept: "application/json",
147
- "X-Request-Id": requestId
148
- },
170
+ headers,
149
171
  signal: timeoutController.signal
150
172
  });
151
173
  const rateLimit = parseRateLimit(res.headers);
@@ -158,7 +180,7 @@ var NetRiskScanClient = class {
158
180
  const body = await safeJson(res);
159
181
  const retryAfterHeader = res.headers.get("retry-after");
160
182
  const retryAfter = retryAfterHeader !== null ? Number(retryAfterHeader) : void 0;
161
- if (isRetryableStatus(res.status) && attempt < this.maxRetries) {
183
+ if (isRetryableFailure(res.status, body?.error?.code) && attempt < this.maxRetries) {
162
184
  attempt += 1;
163
185
  await sleep(computeBackoffMs(attempt, retryAfter));
164
186
  continue;
@@ -167,7 +189,8 @@ var NetRiskScanClient = class {
167
189
  status: res.status,
168
190
  code: body?.error?.code ?? "unknown_error",
169
191
  requestId: body?.error?.requestId ?? responseRequestId,
170
- retryAfter
192
+ retryAfter,
193
+ anonymousUsage: parseAnonymousLimitInfo(body)
171
194
  });
172
195
  } catch (err) {
173
196
  if (err instanceof NetRiskScanApiError) {
@@ -182,10 +205,13 @@ var NetRiskScanClient = class {
182
205
  requestId
183
206
  });
184
207
  }
185
- throw new NetRiskScanNetworkError(err instanceof Error ? err.message : "Network request failed", {
186
- cause: err,
187
- requestId
188
- });
208
+ throw new NetRiskScanNetworkError(
209
+ err instanceof Error ? err.message : "Network request failed",
210
+ {
211
+ cause: err,
212
+ requestId
213
+ }
214
+ );
189
215
  } finally {
190
216
  clearTimeout(timer);
191
217
  options.signal?.removeEventListener("abort", onExternalAbort);
@@ -195,11 +221,14 @@ var NetRiskScanClient = class {
195
221
  };
196
222
 
197
223
  // src/utils/env.ts
198
- function resolveApiKey(cliValue) {
199
- const apiKey = cliValue ?? process.env.NETRISKSCAN_API_KEY;
224
+ function resolveOptionalApiKey(cliValue) {
225
+ return cliValue || process.env.NETRISKSCAN_API_KEY || void 0;
226
+ }
227
+ function resolveRequiredApiKey(cliValue) {
228
+ const apiKey = resolveOptionalApiKey(cliValue);
200
229
  if (!apiKey) {
201
230
  throw new NetRiskScanConfigError(
202
- "NetRiskScan API key is required.\n\nSet NETRISKSCAN_API_KEY or use --api-key."
231
+ "An API key is required for the usage command.\n\nSet NETRISKSCAN_API_KEY or use --api-key."
203
232
  );
204
233
  }
205
234
  return apiKey;
@@ -231,8 +260,11 @@ function exitCodeForApiErrorCode(code) {
231
260
  case "api_key_disabled":
232
261
  case "scope_not_allowed":
233
262
  return ExitCode.AuthError;
263
+ // The anonymous daily trial is an allowance like any other, so it reuses code 5 rather than
264
+ // adding an eighth exit code that every script would have to learn.
234
265
  case "rate_limit_exceeded":
235
266
  case "quota_exceeded":
267
+ case "anonymous_daily_limit_reached":
236
268
  return ExitCode.RateLimitOrQuota;
237
269
  default:
238
270
  return ExitCode.ApiError;
@@ -260,12 +292,33 @@ function formatNumber(value) {
260
292
  function formatDate(iso) {
261
293
  return iso.slice(0, 10);
262
294
  }
263
-
264
- // src/output/human.ts
265
295
  var LABEL_WIDTH = 18;
266
296
  function row(label, value) {
267
297
  return `${label.padEnd(LABEL_WIDTH)}${value}`;
268
298
  }
299
+ function formatUtcTimestamp(iso) {
300
+ if (!iso) return void 0;
301
+ const date = new Date(iso);
302
+ if (Number.isNaN(date.getTime())) return void 0;
303
+ const pad = (n) => String(n).padStart(2, "0");
304
+ return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())} UTC`;
305
+ }
306
+
307
+ // src/output/human.ts
308
+ function anonymousUsageLines(usage) {
309
+ const lines = [];
310
+ if (typeof usage.remaining === "number") {
311
+ lines.push(row("Available", formatNumber(usage.remaining)));
312
+ }
313
+ if (typeof usage.dailyLimit === "number") {
314
+ lines.push(row("Daily Limit", formatNumber(usage.dailyLimit)));
315
+ }
316
+ const reset = formatUtcTimestamp(usage.resetAt);
317
+ if (reset !== void 0) {
318
+ lines.push(row("Reset", reset));
319
+ }
320
+ return lines;
321
+ }
269
322
  function bandColor(band) {
270
323
  switch (band) {
271
324
  case "excellent":
@@ -286,7 +339,9 @@ function renderCheckResult(ip, data) {
286
339
  lines.push("");
287
340
  lines.push(row("IP", ip));
288
341
  lines.push(row("Index", formatIndex(data.risk.index)));
289
- lines.push(row("Band", data.risk.band ? bandColor(data.risk.band)(data.risk.band) : chalk.gray("N/A")));
342
+ lines.push(
343
+ row("Band", data.risk.band ? bandColor(data.risk.band)(data.risk.band) : chalk.gray("N/A"))
344
+ );
290
345
  lines.push(row("Assessment", data.risk.assessmentGrade));
291
346
  lines.push("");
292
347
  if (data.risk.assessmentGrade === "insufficient" && data.risk.index === null) {
@@ -313,7 +368,19 @@ function renderCheckResult(ip, data) {
313
368
  lines.push(row("Scanner", formatTriState(data.flags.scanner)));
314
369
  lines.push(row("Abuse", formatTriState(data.flags.abuse)));
315
370
  lines.push("");
371
+ if (data.usage?.mode === "anonymous") {
372
+ const usageLines = anonymousUsageLines(data.usage);
373
+ if (usageLines.length > 0) {
374
+ lines.push(chalk.bold("Usage"));
375
+ lines.push(...usageLines);
376
+ lines.push("");
377
+ }
378
+ }
316
379
  lines.push(row("Request ID", data.requestId));
380
+ lines.push("");
381
+ lines.push(chalk.bold("Explore"));
382
+ lines.push(row("Web", "https://www.netriskscan.com"));
383
+ lines.push(row("GitHub", "https://github.com/TeamQQ/netriskscan-cli"));
317
384
  process.stdout.write(`${lines.join("\n")}
318
385
  `);
319
386
  }
@@ -321,11 +388,19 @@ function renderVerboseMeta(meta) {
321
388
  const lines = [""];
322
389
  if (meta.rateLimit.remaining !== void 0 && meta.rateLimit.limit !== void 0) {
323
390
  lines.push(
324
- row("Rate limit", `${formatNumber(meta.rateLimit.remaining)} / ${formatNumber(meta.rateLimit.limit)} remaining`)
391
+ row(
392
+ "Rate limit",
393
+ `${formatNumber(meta.rateLimit.remaining)} / ${formatNumber(meta.rateLimit.limit)} remaining`
394
+ )
325
395
  );
326
396
  }
327
397
  if (meta.quota.remaining !== void 0 && meta.quota.limit !== void 0) {
328
- lines.push(row("Quota", `${formatNumber(meta.quota.remaining)} / ${formatNumber(meta.quota.limit)} remaining`));
398
+ lines.push(
399
+ row(
400
+ "Quota",
401
+ `${formatNumber(meta.quota.remaining)} / ${formatNumber(meta.quota.limit)} remaining`
402
+ )
403
+ );
329
404
  }
330
405
  lines.push(row("Request ID", meta.requestId));
331
406
  process.stdout.write(`${lines.join("\n")}
@@ -359,8 +434,40 @@ function printJson(data) {
359
434
 
360
435
  // src/output/errors.ts
361
436
  import chalk2 from "chalk";
437
+ var SIGNUP_URL = "https://www.netriskscan.com/developers";
362
438
  function printConfigError(err) {
363
439
  process.stderr.write(`Error: ${err.message}
440
+ `);
441
+ if (err.message.includes("API key")) {
442
+ process.stderr.write(
443
+ "\nGet a free API key (no credit card required): https://www.netriskscan.com\n"
444
+ );
445
+ }
446
+ }
447
+ function printAnonymousLimitError(err) {
448
+ const usage = err.anonymousUsage;
449
+ const lines = [
450
+ "",
451
+ chalk2.bold("NetRiskScan"),
452
+ "",
453
+ chalk2.yellow("Anonymous daily trial limit reached."),
454
+ ""
455
+ ];
456
+ const usageLines = [
457
+ // The request that returned this error was refused, so nothing is left regardless of what the
458
+ // body reports; `remaining` is only trusted when the server actually sent it.
459
+ row("Available", formatNumber(typeof usage?.remaining === "number" ? usage.remaining : 0))
460
+ ];
461
+ if (typeof usage?.dailyLimit === "number") {
462
+ usageLines.push(row("Daily Limit", formatNumber(usage.dailyLimit)));
463
+ }
464
+ const reset = formatUtcTimestamp(usage?.resetAt);
465
+ if (reset !== void 0) {
466
+ usageLines.push(row("Reset", reset));
467
+ }
468
+ lines.push(chalk2.bold("Usage"), ...usageLines, "");
469
+ lines.push(chalk2.bold("Get more queries"), usage?.signupUrl || SIGNUP_URL, "");
470
+ process.stderr.write(`${lines.join("\n")}
364
471
  `);
365
472
  }
366
473
  var LABEL_WIDTH2 = 11;
@@ -401,12 +508,22 @@ ${err.message}
401
508
  }
402
509
 
403
510
  // src/commands/check.ts
404
- var KNOWN_FLAGS = ["proxy", "vpn", "tor", "datacenter", "scanner", "abuse"];
511
+ var KNOWN_FLAGS = [
512
+ "proxy",
513
+ "vpn",
514
+ "tor",
515
+ "datacenter",
516
+ "scanner",
517
+ "abuse"
518
+ ];
405
519
  function collect(value, previous) {
406
520
  return [...previous, value];
407
521
  }
408
522
  function registerCheckCommand(program2) {
409
- program2.command("check <ip>").description("Check IP risk and network intelligence").option("--api-key <key>", "NetRiskScan API key (overrides NETRISKSCAN_API_KEY)").option("--base-url <url>", "Override the API base URL (advanced)").option("--json", "Output machine-readable JSON").option("--verbose", "Show rate limit, quota and request id").option("--debug", "Show debug information on failure").option("--timeout <ms>", "Request timeout in milliseconds", "10000").option("--max-retries <n>", "Maximum automatic retries for 429/503", "3").option("--fail-below <index>", "Exit non-zero if risk.index is below this threshold (CI use)").option(
523
+ program2.command("check <ip>").description("Check IP risk and network intelligence").option(
524
+ "--api-key <key>",
525
+ "NetRiskScan API key (optional; uses the anonymous trial when omitted)"
526
+ ).option("--base-url <url>", "Override the API base URL (advanced)").option("--json", "Output machine-readable JSON").option("--verbose", "Show rate limit, quota and request id").option("--debug", "Show debug information on failure").option("--timeout <ms>", "Request timeout in milliseconds", "10000").option("--max-retries <n>", "Maximum automatic retries for 429/503", "3").option("--fail-below <index>", "Exit non-zero if risk.index is below this threshold (CI use)").option(
410
527
  "--fail-on <flag>",
411
528
  "Exit non-zero if the given flag is true (repeatable): proxy, vpn, tor, datacenter, scanner, abuse",
412
529
  collect,
@@ -419,6 +536,10 @@ Examples:
419
536
  $ netriskscan check 1.1.1.1 --json
420
537
  $ netriskscan check 1.2.3.4 --fail-below 60
421
538
  $ netriskscan check 1.2.3.4 --fail-on tor --fail-on proxy
539
+
540
+ Notes:
541
+ An API key is optional. Without one, requests use the anonymous daily trial,
542
+ metered by public IP; the response reports how many are left.
422
543
  `
423
544
  ).action(async (ip, options) => {
424
545
  await runCheck(ip, options);
@@ -428,8 +549,10 @@ async function runCheck(ip, options) {
428
549
  const useJson = Boolean(options.json);
429
550
  for (const flag of options.failOn) {
430
551
  if (!KNOWN_FLAGS.includes(flag)) {
431
- process.stderr.write(`Error: unknown --fail-on flag "${flag}". Expected one of: ${KNOWN_FLAGS.join(", ")}
432
- `);
552
+ process.stderr.write(
553
+ `Error: unknown --fail-on flag "${flag}". Expected one of: ${KNOWN_FLAGS.join(", ")}
554
+ `
555
+ );
433
556
  process.exitCode = ExitCode.InvalidArgument;
434
557
  return;
435
558
  }
@@ -440,24 +563,17 @@ async function runCheck(ip, options) {
440
563
  process.exitCode = ExitCode.InvalidArgument;
441
564
  return;
442
565
  }
443
- let apiKey;
444
- try {
445
- apiKey = resolveApiKey(options.apiKey);
446
- } catch (err) {
447
- if (err instanceof NetRiskScanConfigError) {
448
- printConfigError(err);
449
- process.exitCode = ExitCode.AuthError;
450
- return;
451
- }
452
- throw err;
453
- }
454
566
  const client = new NetRiskScanClient({
455
- apiKey,
567
+ apiKey: resolveOptionalApiKey(options.apiKey),
456
568
  baseUrl: resolveBaseUrl(options.baseUrl),
457
569
  timeout: Number(options.timeout),
458
570
  maxRetries: Number(options.maxRetries)
459
571
  });
460
- const spinner = useJson ? void 0 : ora({ text: `Checking ${ip}...`, stream: process.stderr, isEnabled: process.stderr.isTTY }).start();
572
+ const spinner = useJson ? void 0 : ora({
573
+ text: `Checking ${ip}...`,
574
+ stream: process.stderr,
575
+ isEnabled: process.stderr.isTTY
576
+ }).start();
461
577
  try {
462
578
  const { data, meta } = await client.checkIp(ip);
463
579
  spinner?.stop();
@@ -495,7 +611,11 @@ function evaluateCiPolicy(data, options) {
495
611
  }
496
612
  function handleCheckError(err, options) {
497
613
  if (err instanceof NetRiskScanApiError) {
498
- printApiError(err, { debug: options.debug });
614
+ if (err.code === ANONYMOUS_DAILY_LIMIT_CODE) {
615
+ printAnonymousLimitError(err);
616
+ } else {
617
+ printApiError(err, { debug: options.debug });
618
+ }
499
619
  process.exitCode = exitCodeForApiErrorCode(err.code);
500
620
  return;
501
621
  }
@@ -517,7 +637,15 @@ function handleCheckError(err, options) {
517
637
  // src/commands/usage.ts
518
638
  import ora2 from "ora";
519
639
  function registerUsageCommand(program2) {
520
- program2.command("usage").description("Show API usage and quota for the current billing period").option("--api-key <key>", "NetRiskScan API key (overrides NETRISKSCAN_API_KEY)").option("--base-url <url>", "Override the API base URL (advanced)").option("--json", "Output machine-readable JSON").option("--verbose", "Show rate limit and request id").option("--debug", "Show debug information on failure").option("--timeout <ms>", "Request timeout in milliseconds", "10000").option("--max-retries <n>", "Maximum automatic retries for 429/503", "3").action(async (options) => {
640
+ program2.command("usage").description("Show API usage and quota for the current billing period (requires an API key)").option("--api-key <key>", "NetRiskScan API key (required for this command)").option("--base-url <url>", "Override the API base URL (advanced)").option("--json", "Output machine-readable JSON").option("--verbose", "Show rate limit and request id").option("--debug", "Show debug information on failure").option("--timeout <ms>", "Request timeout in milliseconds", "10000").option("--max-retries <n>", "Maximum automatic retries for 429/503", "3").addHelpText(
641
+ "after",
642
+ `
643
+ Notes:
644
+ Requires a Developer API key. This reports Developer Account plan, billing
645
+ period and quota, which has no anonymous equivalent - unlike check and batch,
646
+ which work without a key.
647
+ `
648
+ ).action(async (options) => {
521
649
  await runUsage(options);
522
650
  });
523
651
  }
@@ -525,7 +653,7 @@ async function runUsage(options) {
525
653
  const useJson = Boolean(options.json);
526
654
  let apiKey;
527
655
  try {
528
- apiKey = resolveApiKey(options.apiKey);
656
+ apiKey = resolveRequiredApiKey(options.apiKey);
529
657
  } catch (err) {
530
658
  if (err instanceof NetRiskScanConfigError) {
531
659
  printConfigError(err);
@@ -540,7 +668,11 @@ async function runUsage(options) {
540
668
  timeout: Number(options.timeout),
541
669
  maxRetries: Number(options.maxRetries)
542
670
  });
543
- const spinner = useJson ? void 0 : ora2({ text: "Fetching usage...", stream: process.stderr, isEnabled: process.stderr.isTTY }).start();
671
+ const spinner = useJson ? void 0 : ora2({
672
+ text: "Fetching usage...",
673
+ stream: process.stderr,
674
+ isEnabled: process.stderr.isTTY
675
+ }).start();
544
676
  try {
545
677
  const { data, meta } = await client.getUsage();
546
678
  spinner?.stop();
@@ -596,6 +728,30 @@ function printJsonLine(data) {
596
728
  // src/output/table.ts
597
729
  import Table from "cli-table3";
598
730
  import chalk3 from "chalk";
731
+ function anonymousSummaryLines(results) {
732
+ const remainings = [];
733
+ const dailyLimits = [];
734
+ let exhausted = false;
735
+ for (const item of results) {
736
+ if (item.ok) {
737
+ const usage = item.result.usage;
738
+ if (usage?.mode !== "anonymous") continue;
739
+ if (typeof usage.remaining === "number") remainings.push(usage.remaining);
740
+ if (typeof usage.dailyLimit === "number") dailyLimits.push(usage.dailyLimit);
741
+ } else if (item.error.code === ANONYMOUS_DAILY_LIMIT_CODE) {
742
+ exhausted = true;
743
+ const limit = item.error.anonymousUsage?.dailyLimit;
744
+ if (typeof limit === "number") dailyLimits.push(limit);
745
+ }
746
+ }
747
+ if (!exhausted && remainings.length === 0) return [];
748
+ const available = exhausted ? 0 : Math.min(...remainings);
749
+ const lines = ["", chalk3.bold("Anonymous trial"), row("Available", formatNumber(available))];
750
+ if (dailyLimits.length > 0) {
751
+ lines.push(row("Daily Limit", formatNumber(Math.max(...dailyLimits))));
752
+ }
753
+ return lines;
754
+ }
599
755
  function renderBatchTable(results) {
600
756
  const table = new Table({
601
757
  head: ["IP", "Index", "Band", "Proxy", "VPN", "Tor", "Status"],
@@ -624,13 +780,21 @@ function renderBatchTable(results) {
624
780
  process.stdout.write(`
625
781
  ${okCount} succeeded, ${failCount} failed
626
782
  `);
783
+ const anonymous = anonymousSummaryLines(results);
784
+ if (anonymous.length > 0) {
785
+ process.stdout.write(`${anonymous.join("\n")}
786
+ `);
787
+ }
627
788
  }
628
789
 
629
790
  // src/commands/batch.ts
630
791
  var MAX_CONCURRENCY = 20;
631
792
  var DEFAULT_CONCURRENCY = 5;
632
793
  function registerBatchCommand(program2) {
633
- program2.command("batch <file>").description("Check multiple IP addresses (client-side batch over GET /v1/ip-risk/{ip})").option("--api-key <key>", "NetRiskScan API key (overrides NETRISKSCAN_API_KEY)").option("--base-url <url>", "Override the API base URL (advanced)").option(
794
+ program2.command("batch <file>").description("Check multiple IP addresses (client-side batch over GET /v1/ip-risk/{ip})").option(
795
+ "--api-key <key>",
796
+ "NetRiskScan API key (optional; uses the anonymous trial when omitted)"
797
+ ).option("--base-url <url>", "Override the API base URL (advanced)").option(
634
798
  "--concurrency <n>",
635
799
  `Number of concurrent requests (default: ${DEFAULT_CONCURRENCY}, max: ${MAX_CONCURRENCY})`,
636
800
  String(DEFAULT_CONCURRENCY)
@@ -643,6 +807,10 @@ Notes:
643
807
  offer a server-side batch endpoint. Make sure the selected concurrency
644
808
  complies with the limits shown in your NetRiskScan Developer Dashboard.
645
809
 
810
+ An API key is optional. Without an API key, requests use the anonymous daily
811
+ trial, metered by public IP. How many remain is decided by the server, not by
812
+ this CLI, and is reported in the summary after the table.
813
+
646
814
  Input format:
647
815
  One IP per line. Blank lines and lines starting with # are ignored.
648
816
 
@@ -681,7 +849,12 @@ Check your NetRiskScan Developer Dashboard for your plan's concurrency limit.
681
849
  }
682
850
  function toBatchError(err) {
683
851
  if (err instanceof NetRiskScanApiError) {
684
- return { code: err.code, message: err.message, requestId: err.requestId };
852
+ return {
853
+ code: err.code,
854
+ message: err.message,
855
+ requestId: err.requestId,
856
+ anonymousUsage: err.anonymousUsage
857
+ };
685
858
  }
686
859
  if (err instanceof NetRiskScanNetworkError) {
687
860
  return { code: "network_error", message: err.message, requestId: err.requestId };
@@ -689,17 +862,6 @@ function toBatchError(err) {
689
862
  return { code: "unknown_error", message: err instanceof Error ? err.message : String(err) };
690
863
  }
691
864
  async function runBatch(file, options) {
692
- let apiKey;
693
- try {
694
- apiKey = resolveApiKey(options.apiKey);
695
- } catch (err) {
696
- if (err instanceof NetRiskScanConfigError) {
697
- printConfigError(err);
698
- process.exitCode = ExitCode.AuthError;
699
- return;
700
- }
701
- throw err;
702
- }
703
865
  const ips = await readIps(file);
704
866
  if (ips.length === 0) {
705
867
  process.stderr.write("Error: no IP addresses found in input.\n");
@@ -707,7 +869,7 @@ async function runBatch(file, options) {
707
869
  return;
708
870
  }
709
871
  const client = new NetRiskScanClient({
710
- apiKey,
872
+ apiKey: resolveOptionalApiKey(options.apiKey),
711
873
  baseUrl: resolveBaseUrl(options.baseUrl),
712
874
  timeout: Number(options.timeout),
713
875
  maxRetries: Number(options.maxRetries)
@@ -750,17 +912,23 @@ function computeBatchExitCode(results) {
750
912
  var __dirname = dirname(fileURLToPath(import.meta.url));
751
913
  var pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf8"));
752
914
  var program = new Command();
753
- program.name("netriskscan").description("Query IP risk, network intelligence and reputation data from the NetRiskScan Developer API.").version(pkg.version, "-V, --version", "Show the CLI version").addHelpText(
915
+ program.name("netriskscan").description(
916
+ "Query IP risk, network intelligence and reputation data from the NetRiskScan Developer API."
917
+ ).version(pkg.version, "-V, --version", "Show the CLI version").addHelpText(
754
918
  "after",
755
919
  `
756
920
  Examples:
757
- $ netriskscan check 1.1.1.1
921
+ $ netriskscan check 1.1.1.1 # no account or API key needed
758
922
  $ netriskscan check 1.1.1.1 --json
759
- $ netriskscan usage
923
+ $ netriskscan usage # needs an API key
760
924
  $ netriskscan batch ips.txt --jsonl
761
925
 
926
+ check and batch work with no setup at all: without an API key they use the
927
+ anonymous daily trial, metered by public IP. The server reports how many
928
+ requests are left; the CLI never estimates it.
929
+
762
930
  Environment variables:
763
- NETRISKSCAN_API_KEY API key used when --api-key is not provided
931
+ NETRISKSCAN_API_KEY Optional for check/batch; required for account usage.
764
932
 
765
933
  NetRiskScan provides diagnostic network intelligence. Results should not be
766
934
  treated as proof of malicious activity or used as the sole basis for legal,