@profullstack/threatcrush 0.13.56 → 0.13.58

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/README.md CHANGED
@@ -229,6 +229,17 @@ enabled = true # false: the daemon neither reports to nor takes actio
229
229
  min_severity = "medium" # info | low | medium | high | critical
230
230
  ```
231
231
 
232
+ ### Every machine, with what it costs
233
+
234
+ The Fleet panel lists linked daemons. To also list the machines that do not run one, and what each box costs a month, upload an [OpenDevice](https://logicsrc.com/docs/opendevice) inventory (org owners and admins):
235
+
236
+ ```bash
237
+ threatcrush fleet import opendevice.json # or an https:// URL; --org <slug> to pick the org
238
+ threatcrush fleet cost # per-box $/mo, provider, daemon status and the total
239
+ ```
240
+
241
+ Devices are matched to linked servers by hostname, name or IP. A device with no daemon shows as "no agent"; a cost the inventory does not state shows as "unstated" and is never guessed. Totals are per currency, never converted. `GET /api/fleet/costs` returns the recurring costs in the shape CoinPay imports.
242
+
232
243
  ## Automatic updates
233
244
 
234
245
  The daemon keeps itself on the latest release. About every 6 hours (plus up to an hour of jitter, so a fleet does not restart in step) it asks the npm registry for `latest`. When a newer version has been published for at least 2 hours, and is on the same major version, it installs it and restarts onto it. The update shows in the live feed as an info event (`auto-update`).
package/dist/index.js CHANGED
@@ -36459,9 +36459,9 @@ function urlAuthority(text) {
36459
36459
  return found ? found[1] : null;
36460
36460
  }
36461
36461
  function requestHostIsConstant(line2, fileText) {
36462
- const call = /(?:urlopen|requests\.(?:get|request|head)|httpx\.get)\s*\(\s*([A-Za-z_]\w*)\s*[,)]/.exec(line2);
36463
- if (!call) return false;
36464
- const assignment = new RegExp(String.raw`^[ \t]*${call[1]}[ \t]*=[ \t]*(.+)$`, "gm");
36462
+ const call2 = /(?:urlopen|requests\.(?:get|request|head)|httpx\.get)\s*\(\s*([A-Za-z_]\w*)\s*[,)]/.exec(line2);
36463
+ if (!call2) return false;
36464
+ const assignment = new RegExp(String.raw`^[ \t]*${call2[1]}[ \t]*=[ \t]*(.+)$`, "gm");
36465
36465
  const values = [...fileText.matchAll(assignment)].map((m) => m[1]);
36466
36466
  if (!values.length) return false;
36467
36467
  return values.every((value) => {
@@ -36484,7 +36484,7 @@ function hasSafeRedirectValue(line2, fileText) {
36484
36484
  }
36485
36485
  const equals = candidate.indexOf("=", at + declaration.length);
36486
36486
  const initializer = candidate.slice(equals + 1);
36487
- if (equals !== -1 && ["safeRedirectPath(", "safeRedirectUrl(", "safeRedirectURL("].some((call) => initializer.includes(call))) {
36487
+ if (equals !== -1 && ["safeRedirectPath(", "safeRedirectUrl(", "safeRedirectURL("].some((call2) => initializer.includes(call2))) {
36488
36488
  return true;
36489
36489
  }
36490
36490
  }
@@ -40445,15 +40445,15 @@ function httpSender(cfg) {
40445
40445
  });
40446
40446
  const raw = await resp.text();
40447
40447
  if (cfg.responsePath === "text") return raw;
40448
- let json;
40448
+ let json2;
40449
40449
  try {
40450
- json = JSON.parse(raw);
40450
+ json2 = JSON.parse(raw);
40451
40451
  } catch {
40452
40452
  return raw;
40453
40453
  }
40454
- if (cfg.responsePath) return String(dig(json, cfg.responsePath) ?? "");
40454
+ if (cfg.responsePath) return String(dig(json2, cfg.responsePath) ?? "");
40455
40455
  return String(
40456
- dig(json, "choices.0.message.content") ?? dig(json, "choices.0.text") ?? dig(json, "message.content") ?? dig(json, "content") ?? dig(json, "output") ?? dig(json, "response") ?? dig(json, "text") ?? raw
40456
+ dig(json2, "choices.0.message.content") ?? dig(json2, "choices.0.text") ?? dig(json2, "message.content") ?? dig(json2, "content") ?? dig(json2, "output") ?? dig(json2, "response") ?? dig(json2, "text") ?? raw
40457
40457
  );
40458
40458
  };
40459
40459
  }
@@ -40914,6 +40914,102 @@ async function invitesCommand(action = "list", arg, f = fetch) {
40914
40914
  }
40915
40915
  }
40916
40916
 
40917
+ // src/commands/fleet.ts
40918
+ var import_promises = require("fs/promises");
40919
+ init_cli_config();
40920
+ async function call(path2, init = {}) {
40921
+ const res = await cloudFetch(path2, init);
40922
+ const body = await res.json().catch(() => ({}));
40923
+ return { ok: res.ok, status: res.status, body };
40924
+ }
40925
+ function fail2(message) {
40926
+ console.error(source_default.red(` ${message}`));
40927
+ process.exitCode = 1;
40928
+ }
40929
+ async function resolveOrg(wanted) {
40930
+ const r = await call("/api/orgs");
40931
+ if (r.status === 401) {
40932
+ fail2("Not signed in. Run `threatcrush login` first.");
40933
+ return null;
40934
+ }
40935
+ if (!r.ok) {
40936
+ fail2(String(r.body.error ?? `Could not list organizations (${r.status})`));
40937
+ return null;
40938
+ }
40939
+ const orgs = r.body.organizations ?? [];
40940
+ const pick = wanted ?? readCliConfig().current_org_id;
40941
+ if (pick) {
40942
+ const org = orgs.find((o) => o.id === pick || o.slug === pick);
40943
+ if (!org) fail2(`No organization "${pick}". See: threatcrush orgs list`);
40944
+ return org ?? null;
40945
+ }
40946
+ const admin = orgs.filter((o) => o.user_role === "owner" || o.user_role === "admin");
40947
+ if (admin.length === 1) return admin[0];
40948
+ fail2(admin.length === 0 ? "You administer no organization. Create one: threatcrush orgs create <name>" : `Pick an organization: --org <slug> (${admin.map((o) => o.slug).join(", ")})`);
40949
+ return null;
40950
+ }
40951
+ async function readInventorySource(source, f = fetch) {
40952
+ if (/^https?:\/\//i.test(source)) {
40953
+ const res = await f(source, { signal: AbortSignal.timeout(3e4) });
40954
+ if (!res.ok) throw new Error(`${source} answered ${res.status}`);
40955
+ return res.text();
40956
+ }
40957
+ return (0, import_promises.readFile)(source, "utf-8");
40958
+ }
40959
+ async function fleetImportCommand(source, opts = {}) {
40960
+ let text;
40961
+ try {
40962
+ text = await readInventorySource(source);
40963
+ JSON.parse(text);
40964
+ } catch (err) {
40965
+ return fail2(`Could not read ${source}: ${err instanceof Error ? err.message : String(err)}`);
40966
+ }
40967
+ const org = await resolveOrg(opts.org);
40968
+ if (!org) return;
40969
+ const r = await call(`/api/orgs/${encodeURIComponent(org.id)}/inventory`, { method: "PUT", body: text });
40970
+ const warnings = r.body.warnings ?? [];
40971
+ if (!r.ok) {
40972
+ fail2(String(r.body.error ?? `Import failed (${r.status})`));
40973
+ for (const e of r.body.errors ?? []) console.error(source_default.red(` - ${e}`));
40974
+ for (const w of warnings) console.error(source_default.yellow(` ! ${w}`));
40975
+ return;
40976
+ }
40977
+ const cost = r.body.cost;
40978
+ console.log(source_default.green(` Imported ${cost.devices} device${cost.devices === 1 ? "" : "s"} into ${org.name} (/${org.slug}).`));
40979
+ console.log(` Monthly: ${source_default.bold(formatTotal(cost.monthly))} (${cost.counted} counted, ${cost.unstated.length} unstated)`);
40980
+ if (cost.unstated.length > 0) console.log(source_default.dim(` Unstated: ${cost.unstated.join(", ")}`));
40981
+ for (const w of warnings) console.log(source_default.yellow(` ! ${w}`));
40982
+ console.log(source_default.dim(" See it: threatcrush fleet cost, or threatcrush.com/dashboard"));
40983
+ }
40984
+ async function fleetCostCommand(opts = {}) {
40985
+ const r = await call("/api/fleet");
40986
+ if (r.status === 401) return fail2("Not signed in. Run `threatcrush login` first.");
40987
+ if (!r.ok) return fail2(String(r.body.error ?? `Could not load the fleet (${r.status})`));
40988
+ if (opts.json) {
40989
+ console.log(JSON.stringify(r.body, null, 2));
40990
+ return;
40991
+ }
40992
+ const servers = r.body.servers ?? [];
40993
+ const s = r.body.summary;
40994
+ if (s.inventories === 0) {
40995
+ console.log(source_default.yellow(" No OpenDevice inventory yet. Import one: threatcrush fleet import <file|url>"));
40996
+ }
40997
+ const width = Math.max(6, ...servers.map((x) => x.name.length));
40998
+ console.log(source_default.dim(` ${"SERVER".padEnd(width)} ${"STATUS".padEnd(8)} ${"PROVIDER".padEnd(14)} $/MO`));
40999
+ for (const x of servers) {
41000
+ const status = x.connection === "online" ? source_default.green("online ") : x.connection === "no-agent" ? source_default.dim("no agent") : source_default.red("offline ");
41001
+ const cost = !x.device ? source_default.dim("\u2014") : x.device.monthly.amount == null ? source_default.dim(x.device.monthly_label) : x.device.monthly_label;
41002
+ console.log(` ${x.name.padEnd(width)} ${status} ${(x.device?.provider ?? "\u2014").slice(0, 14).padEnd(14)} ${cost}`);
41003
+ }
41004
+ console.log();
41005
+ console.log(` Total: ${source_default.bold(s.monthly_total_label)}/mo (${s.cost_counted} counted, ${s.cost_unstated} unstated)`);
41006
+ console.log(source_default.dim(` ${s.installs} with a daemon, ${s.no_agent} without${s.no_agent > 0 ? " (install: threatcrush login && threatcrush servers link)" : ""}`));
41007
+ }
41008
+ function formatTotal(monthly) {
41009
+ const parts = Object.entries(monthly ?? {}).map(([cur, n]) => new Intl.NumberFormat("en-US", { style: "currency", currency: cur }).format(n));
41010
+ return parts.length ? parts.join(" + ") : "\u2014";
41011
+ }
41012
+
40917
41013
  // src/commands/servers.ts
40918
41014
  var import_node_readline2 = __toESM(require("readline"));
40919
41015
  var import_node_os11 = require("os");
@@ -43653,7 +43749,7 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
43653
43749
 
43654
43750
  // src/daemon/workers/cloud-spool.ts
43655
43751
  var import_node_fs34 = require("fs");
43656
- var import_promises = require("fs/promises");
43752
+ var import_promises2 = require("fs/promises");
43657
43753
  var import_node_path25 = require("path");
43658
43754
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43659
43755
  var CloudSpool = class {
@@ -43761,13 +43857,13 @@ var CloudSpool = class {
43761
43857
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
43762
43858
  ` : "";
43763
43859
  const tmp = `${this.path}.tmp`;
43764
- await (0, import_promises.writeFile)(tmp, body, { mode: 384 });
43765
- await (0, import_promises.rename)(tmp, this.path);
43860
+ await (0, import_promises2.writeFile)(tmp, body, { mode: 384 });
43861
+ await (0, import_promises2.rename)(tmp, this.path);
43766
43862
  } else if (this.pendingAppend.length > 0) {
43767
43863
  const chunk2 = `${this.pendingAppend.join("\n")}
43768
43864
  `;
43769
43865
  this.pendingAppend = [];
43770
- await (0, import_promises.appendFile)(this.path, chunk2, { mode: 384 });
43866
+ await (0, import_promises2.appendFile)(this.path, chunk2, { mode: 384 });
43771
43867
  }
43772
43868
  }).catch(() => {
43773
43869
  this.needsRewrite = true;
@@ -44126,12 +44222,12 @@ async function reportToAbuseIPDB(payload, apiKey) {
44126
44222
  if (res.status === 429) {
44127
44223
  return { destination: "abuseipdb", ok: false, detail: "rate-limited by AbuseIPDB (daily cap)" };
44128
44224
  }
44129
- const json = await res.json().catch(() => ({}));
44225
+ const json2 = await res.json().catch(() => ({}));
44130
44226
  if (!res.ok) {
44131
- const detail = json.errors?.map((e) => e.detail).filter(Boolean).join("; ") || `HTTP ${res.status}`;
44227
+ const detail = json2.errors?.map((e) => e.detail).filter(Boolean).join("; ") || `HTTP ${res.status}`;
44132
44228
  return { destination: "abuseipdb", ok: false, detail };
44133
44229
  }
44134
- const score = json.data?.abuseConfidenceScore;
44230
+ const score = json2.data?.abuseConfidenceScore;
44135
44231
  return { destination: "abuseipdb", ok: true, detail: score !== void 0 ? `confidence ${score}` : "reported" };
44136
44232
  } catch (err) {
44137
44233
  return { destination: "abuseipdb", ok: false, detail: err.message };
@@ -48912,11 +49008,11 @@ function computeScore(results) {
48912
49008
  if (maxScore === 0) return 100;
48913
49009
  return Math.max(0, Math.round((maxScore - deductions) / maxScore * 100));
48914
49010
  }
48915
- async function uploadFindings(results, json) {
48916
- const say = (line2) => json ? console.error(line2) : console.log(line2);
49011
+ async function uploadFindings(results, json2) {
49012
+ const say = (line2) => json2 ? console.error(line2) : console.log(line2);
48917
49013
  const link = currentLink();
48918
49014
  if (!link) {
48919
- if (!json) say(source_default.gray(" Not linked to the dashboard; run `threatcrush servers link` to upload findings.\n"));
49015
+ if (!json2) say(source_default.gray(" Not linked to the dashboard; run `threatcrush servers link` to upload findings.\n"));
48920
49016
  return;
48921
49017
  }
48922
49018
  let res;
@@ -50173,7 +50269,7 @@ init_ipc_client();
50173
50269
  // src/core/user-agent.ts
50174
50270
  init_cli_config();
50175
50271
  var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
50176
- function isOurHost(url, api3 = apiUrl()) {
50272
+ function isOurHost(url, api4 = apiUrl()) {
50177
50273
  let host;
50178
50274
  try {
50179
50275
  host = new URL(url).hostname.toLowerCase();
@@ -50182,7 +50278,7 @@ function isOurHost(url, api3 = apiUrl()) {
50182
50278
  }
50183
50279
  let apiHost = "";
50184
50280
  try {
50185
- apiHost = new URL(api3).hostname.toLowerCase();
50281
+ apiHost = new URL(api4).hostname.toLowerCase();
50186
50282
  } catch {
50187
50283
  }
50188
50284
  return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
@@ -50311,6 +50407,135 @@ async function uploadResult(result, opts) {
50311
50407
  }
50312
50408
  }
50313
50409
 
50410
+ // src/commands/webhooks.ts
50411
+ init_cli_config();
50412
+ function orgOrExplain() {
50413
+ if (!hasSession()) {
50414
+ console.log(source_default.red(` Not signed in. Run ${source_default.white("threatcrush login")} first.
50415
+ `));
50416
+ process.exitCode = 1;
50417
+ return null;
50418
+ }
50419
+ const org = readCliConfig().current_org_id;
50420
+ if (!org) {
50421
+ console.log(source_default.red(` No current org. Run ${source_default.white("threatcrush orgs use <slug>")}.
50422
+ `));
50423
+ process.exitCode = 1;
50424
+ return null;
50425
+ }
50426
+ return org;
50427
+ }
50428
+ async function api2(path2, init) {
50429
+ const org = orgOrExplain();
50430
+ if (!org) return null;
50431
+ const res = await cloudFetch(`/api/v1/webhooks${path2}?org_id=${encodeURIComponent(org)}`, init);
50432
+ const data = await res.json().catch(() => ({}));
50433
+ if (!res.ok) {
50434
+ console.log(source_default.red(` ${data.error || `HTTP ${res.status}`}${res.status === 401 ? ` \u2014 run ${source_default.white("threatcrush login")}` : ""}
50435
+ `));
50436
+ process.exitCode = 1;
50437
+ return null;
50438
+ }
50439
+ return data;
50440
+ }
50441
+ var json = (v) => console.log(JSON.stringify(v, null, 2));
50442
+ function printSecret(id, secret) {
50443
+ console.log(source_default.green(`
50444
+ Signing secret for ${id} (shown once, keep it in your vault):`));
50445
+ console.log(` ${source_default.white(secret)}`);
50446
+ console.log(source_default.dim(" Verify the webhook-signature header with any Standard Webhooks library.\n"));
50447
+ }
50448
+ async function webhooksListCommand(opts = {}) {
50449
+ const data = await api2("");
50450
+ if (!data) return;
50451
+ if (opts.json) return json(data);
50452
+ console.log(source_default.bold("\n Webhook endpoints") + source_default.dim(` events: ${data.event_types.join(", ")}
50453
+ `));
50454
+ if (!data.endpoints.length) {
50455
+ console.log(source_default.dim(` None yet. Add one: threatcrush webhooks add <https-url> [--events detection.created,findings.*]
50456
+ `));
50457
+ return;
50458
+ }
50459
+ for (const e of data.endpoints) {
50460
+ const state = e.enabled ? source_default.green("on ") : source_default.gray("off");
50461
+ console.log(` ${source_default.gray(e.id)} ${state} ${e.url}`);
50462
+ console.log(source_default.dim(` ${e.events.join(", ")}${e.description ? ` \xB7 ${e.description}` : ""}${e.failures ? ` \xB7 ${e.failures} failures in a row` : ""}${e.disabled_reason ? ` \xB7 ${e.disabled_reason}` : ""}`));
50463
+ }
50464
+ console.log();
50465
+ }
50466
+ async function webhooksAddCommand(url, opts) {
50467
+ const body = {
50468
+ url,
50469
+ ...opts.events ? { events: opts.events.split(",").map((s) => s.trim()).filter(Boolean) } : {},
50470
+ ...opts.description ? { description: opts.description } : {}
50471
+ };
50472
+ const data = await api2("", { method: "POST", body: JSON.stringify(body) });
50473
+ if (!data) return;
50474
+ if (opts.json) return json(data);
50475
+ console.log(source_default.green(` Added ${data.endpoint.id} \u2192 ${data.endpoint.url} (${data.endpoint.events.join(", ")})`));
50476
+ printSecret(data.endpoint.id, data.secret);
50477
+ }
50478
+ async function webhooksUpdateCommand(id, opts) {
50479
+ const patch = {};
50480
+ if (opts.url) patch.url = opts.url;
50481
+ if (opts.events) patch.events = opts.events.split(",").map((s) => s.trim()).filter(Boolean);
50482
+ if (opts.description !== void 0) patch.description = opts.description;
50483
+ if (opts.enable) patch.enabled = true;
50484
+ if (opts.disable) patch.enabled = false;
50485
+ const data = await api2(`/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify(patch) });
50486
+ if (!data) return;
50487
+ if (opts.json) return json(data);
50488
+ console.log(source_default.green(` Updated ${data.id}: ${data.enabled ? "on" : "off"}, ${data.url}, ${data.events.join(", ")}
50489
+ `));
50490
+ }
50491
+ async function webhooksRemoveCommand(id) {
50492
+ if (await api2(`/${encodeURIComponent(id)}`, { method: "DELETE" })) console.log(source_default.green(` Removed ${id}
50493
+ `));
50494
+ }
50495
+ async function webhooksTestCommand(id) {
50496
+ const r = await api2(`/${encodeURIComponent(id)}/test`, { method: "POST" });
50497
+ if (!r) return;
50498
+ if (r.ok) console.log(source_default.green(` Test delivered (HTTP ${r.status})
50499
+ `));
50500
+ else {
50501
+ console.log(source_default.red(` Test failed: ${r.error ?? `HTTP ${r.status}`}
50502
+ `));
50503
+ process.exitCode = 1;
50504
+ }
50505
+ }
50506
+ async function webhooksSecretCommand(id, opts) {
50507
+ const r = opts.rotate ? await api2(`/${encodeURIComponent(id)}/rotate`, { method: "POST" }) : await api2(`/${encodeURIComponent(id)}/secret`);
50508
+ if (r) printSecret(id, r.secret);
50509
+ }
50510
+ async function webhooksDeliveriesCommand(id, opts) {
50511
+ const limit = Math.min(200, Number(opts.limit) || 20);
50512
+ const path2 = id ? `/${encodeURIComponent(id)}/deliveries` : "/deliveries";
50513
+ const org = readCliConfig().current_org_id;
50514
+ if (!org) return void orgOrExplain();
50515
+ const res = await cloudFetch(`/api/v1/webhooks${path2}?org_id=${encodeURIComponent(org)}&limit=${limit}`);
50516
+ const data = await res.json().catch(() => ({}));
50517
+ if (!res.ok) {
50518
+ console.log(source_default.red(` ${data.error || `HTTP ${res.status}`}
50519
+ `));
50520
+ process.exitCode = 1;
50521
+ return;
50522
+ }
50523
+ if (opts.json) return json(data);
50524
+ const rows2 = data.deliveries ?? [];
50525
+ if (!rows2.length) return void console.log(source_default.dim(" No deliveries yet.\n"));
50526
+ for (const d of rows2) {
50527
+ const color = d.status === "delivered" ? source_default.green : d.status === "failed" ? source_default.red : source_default.yellow;
50528
+ console.log(` ${source_default.gray(d.created_at.slice(0, 19).replace("T", " "))} ${color(d.status.padEnd(9))} ${d.event_type.padEnd(20)} ${d.attempts} tries${d.last_status ? `, HTTP ${d.last_status}` : ""}${d.last_error ? source_default.dim(` \xB7 ${d.last_error}`) : ""}`);
50529
+ }
50530
+ console.log(source_default.dim(`
50531
+ Resend one: threatcrush webhooks retry <delivery-id>
50532
+ `));
50533
+ }
50534
+ async function webhooksRetryCommand(deliveryId) {
50535
+ if (await api2(`/deliveries/${encodeURIComponent(deliveryId)}/retry`, { method: "POST" })) console.log(source_default.green(` Queued ${deliveryId} again
50536
+ `));
50537
+ }
50538
+
50314
50539
  // src/commands/findings.ts
50315
50540
  init_cli_config();
50316
50541
  var TRIAGE = {
@@ -50334,7 +50559,7 @@ var STATUS_LABEL = {
50334
50559
  false_positive: "false+",
50335
50560
  ignored: "ignored"
50336
50561
  };
50337
- function orgOrExplain() {
50562
+ function orgOrExplain2() {
50338
50563
  if (!hasSession()) {
50339
50564
  console.log(source_default.red(` Not signed in. Run ${source_default.white("threatcrush login")} first.
50340
50565
  `));
@@ -50350,7 +50575,7 @@ function orgOrExplain() {
50350
50575
  }
50351
50576
  return org;
50352
50577
  }
50353
- async function api2(path2, init) {
50578
+ async function api3(path2, init) {
50354
50579
  const res = await cloudFetch(path2, init);
50355
50580
  const data = await res.json().catch(() => ({}));
50356
50581
  if (!res.ok) {
@@ -50364,14 +50589,14 @@ async function api2(path2, init) {
50364
50589
  var short = (id) => id.slice(0, 8);
50365
50590
  var day = (iso) => iso.slice(0, 10);
50366
50591
  async function findingsListCommand(opts) {
50367
- const org = orgOrExplain();
50592
+ const org = orgOrExplain2();
50368
50593
  if (!org) return;
50369
50594
  const qs = new URLSearchParams();
50370
50595
  if (opts.status) qs.set("status", opts.status);
50371
50596
  if (opts.severity) qs.set("severity", opts.severity);
50372
50597
  if (opts.source) qs.set("source", opts.source);
50373
50598
  qs.set("limit", String(Math.min(500, Number(opts.limit) || 100)));
50374
- const data = await api2(`/api/orgs/${org}/scan-findings?${qs}`);
50599
+ const data = await api3(`/api/orgs/${org}/scan-findings?${qs}`);
50375
50600
  if (!data) return;
50376
50601
  if (opts.json) {
50377
50602
  console.log(JSON.stringify(data, null, 2));
@@ -50401,7 +50626,7 @@ async function resolveIds(org, prefixes) {
50401
50626
  const full = prefixes.filter((p) => /^[0-9a-f-]{36}$/i.test(p));
50402
50627
  const partial = prefixes.filter((p) => !full.includes(p));
50403
50628
  if (!partial.length) return full;
50404
- const data = await api2(`/api/orgs/${org}/scan-findings?status=all&limit=500`);
50629
+ const data = await api3(`/api/orgs/${org}/scan-findings?status=all&limit=500`);
50405
50630
  if (!data) return null;
50406
50631
  for (const p of partial) {
50407
50632
  const hits = data.findings.filter((f) => f.id.startsWith(p.toLowerCase()));
@@ -50416,11 +50641,11 @@ async function resolveIds(org, prefixes) {
50416
50641
  return full;
50417
50642
  }
50418
50643
  async function findingsShowCommand(id, opts) {
50419
- const org = orgOrExplain();
50644
+ const org = orgOrExplain2();
50420
50645
  if (!org) return;
50421
50646
  const [full] = await resolveIds(org, [id]) ?? [];
50422
50647
  if (!full) return;
50423
- const data = await api2(`/api/orgs/${org}/scan-findings/${full}`);
50648
+ const data = await api3(`/api/orgs/${org}/scan-findings/${full}`);
50424
50649
  if (!data) return;
50425
50650
  if (opts.json) {
50426
50651
  console.log(JSON.stringify(data.finding, null, 2));
@@ -50440,7 +50665,7 @@ async function findingsShowCommand(id, opts) {
50440
50665
  console.log();
50441
50666
  }
50442
50667
  async function findingsTriageCommand(verb, ids, opts) {
50443
- const org = orgOrExplain();
50668
+ const org = orgOrExplain2();
50444
50669
  if (!org) return;
50445
50670
  if (!ids.length) {
50446
50671
  console.log(source_default.red(` Give at least one finding id (see threatcrush findings).
@@ -50452,7 +50677,7 @@ async function findingsTriageCommand(verb, ids, opts) {
50452
50677
  if (!full) return;
50453
50678
  const body = { ids: full, status: TRIAGE[verb] };
50454
50679
  if (opts.note !== void 0) body.note = opts.note;
50455
- const data = await api2(`/api/orgs/${org}/scan-findings`, { method: "PATCH", body: JSON.stringify(body) });
50680
+ const data = await api3(`/api/orgs/${org}/scan-findings`, { method: "PATCH", body: JSON.stringify(body) });
50456
50681
  if (!data) return;
50457
50682
  console.log(source_default.green(` \u2713 ${data.updated.length} finding(s) \u2192 ${TRIAGE[verb].replace("_", " ")}
50458
50683
  `));
@@ -50814,6 +51039,33 @@ for (const verb of Object.keys(TRIAGE)) {
50814
51039
  await findingsTriageCommand(verb, ids, opts);
50815
51040
  });
50816
51041
  }
51042
+ var webhooks = program2.command("webhooks").description("Your org's webhook endpoints: detection.created, findings.raised, reputation.changed (also on the web app and MCP)").option("--json", "emit JSON").action(async (opts) => {
51043
+ await webhooksListCommand(opts);
51044
+ });
51045
+ webhooks.command("list").description("List endpoints").option("--json", "emit JSON").action(async (opts) => {
51046
+ await webhooksListCommand(opts);
51047
+ });
51048
+ webhooks.command("add <url>").description("Add an endpoint (prints its signing secret once)").option("--events <list>", "comma list of patterns: *, detection.created, findings.*, ... (default *)").option("--description <text>", "a note for you").option("--json", "emit JSON").action(async (url, opts) => {
51049
+ await webhooksAddCommand(url, opts);
51050
+ });
51051
+ webhooks.command("update <id>").description("Change url, events, description, or switch on/off").option("--url <url>").option("--events <list>").option("--description <text>").option("--enable", "switch on (clears the failure count)").option("--disable", "switch off").option("--json", "emit JSON").action(async (id, opts) => {
51052
+ await webhooksUpdateCommand(id, opts);
51053
+ });
51054
+ webhooks.command("rm <id>").alias("remove").description("Remove an endpoint").action(async (id) => {
51055
+ await webhooksRemoveCommand(id);
51056
+ });
51057
+ webhooks.command("test <id>").description("Send a signed webhook.test now").action(async (id) => {
51058
+ await webhooksTestCommand(id);
51059
+ });
51060
+ webhooks.command("secret <id>").description("Show the signing secret (--rotate replaces it; the old one stops working)").option("--rotate", "make a new secret").action(async (id, opts) => {
51061
+ await webhooksSecretCommand(id, opts);
51062
+ });
51063
+ webhooks.command("deliveries [id]").description("Recent deliveries, for one endpoint or all").option("--limit <n>", "how many (max 200)").option("--json", "emit JSON").action(async (id, opts) => {
51064
+ await webhooksDeliveriesCommand(id, opts);
51065
+ });
51066
+ webhooks.command("retry <deliveryId>").description("Send one delivery again").action(async (id) => {
51067
+ await webhooksRetryCommand(id);
51068
+ });
50817
51069
  program2.command("status").description("Show daemon status and loaded modules").action(async () => {
50818
51070
  await statusCommand();
50819
51071
  });
@@ -51173,6 +51425,15 @@ orgsCmd.command("create <name>").description("Create a new organization").action
51173
51425
  orgsCmd.command("use <slug>").description("Switch to an organization").action(async (slug) => {
51174
51426
  await orgsCommand({ action: "use", name: slug });
51175
51427
  });
51428
+ var fleetCmd = program2.command("fleet").description("Every machine you run (OpenDevice inventory) with monthly cost, daemon or not").action(async () => {
51429
+ await fleetCostCommand({});
51430
+ });
51431
+ fleetCmd.command("import <source>").description("Upload an OpenDevice inventory (file or https URL) to your organization").option("--org <slug>", "Organization slug or id (default: the `orgs use` org, or the only one you administer)").action(async (source, opts) => {
51432
+ await fleetImportCommand(source, opts);
51433
+ });
51434
+ fleetCmd.command("cost").alias("costs").description("Per-box monthly cost and the fleet total").option("--json", "Print the raw /api/fleet response").action(async (opts) => {
51435
+ await fleetCostCommand(opts);
51436
+ });
51176
51437
  var serversCmd = program2.command("servers").alias("server").alias("srv").description("Manage servers").action(async () => {
51177
51438
  await serversCommand({ action: "list" });
51178
51439
  });