@profullstack/threatcrush 0.13.57 → 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/dist/index.js CHANGED
@@ -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
  }
@@ -44222,12 +44222,12 @@ async function reportToAbuseIPDB(payload, apiKey) {
44222
44222
  if (res.status === 429) {
44223
44223
  return { destination: "abuseipdb", ok: false, detail: "rate-limited by AbuseIPDB (daily cap)" };
44224
44224
  }
44225
- const json = await res.json().catch(() => ({}));
44225
+ const json2 = await res.json().catch(() => ({}));
44226
44226
  if (!res.ok) {
44227
- 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}`;
44228
44228
  return { destination: "abuseipdb", ok: false, detail };
44229
44229
  }
44230
- const score = json.data?.abuseConfidenceScore;
44230
+ const score = json2.data?.abuseConfidenceScore;
44231
44231
  return { destination: "abuseipdb", ok: true, detail: score !== void 0 ? `confidence ${score}` : "reported" };
44232
44232
  } catch (err) {
44233
44233
  return { destination: "abuseipdb", ok: false, detail: err.message };
@@ -49008,11 +49008,11 @@ function computeScore(results) {
49008
49008
  if (maxScore === 0) return 100;
49009
49009
  return Math.max(0, Math.round((maxScore - deductions) / maxScore * 100));
49010
49010
  }
49011
- async function uploadFindings(results, json) {
49012
- 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);
49013
49013
  const link = currentLink();
49014
49014
  if (!link) {
49015
- 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"));
49016
49016
  return;
49017
49017
  }
49018
49018
  let res;
@@ -50269,7 +50269,7 @@ init_ipc_client();
50269
50269
  // src/core/user-agent.ts
50270
50270
  init_cli_config();
50271
50271
  var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
50272
- function isOurHost(url, api3 = apiUrl()) {
50272
+ function isOurHost(url, api4 = apiUrl()) {
50273
50273
  let host;
50274
50274
  try {
50275
50275
  host = new URL(url).hostname.toLowerCase();
@@ -50278,7 +50278,7 @@ function isOurHost(url, api3 = apiUrl()) {
50278
50278
  }
50279
50279
  let apiHost = "";
50280
50280
  try {
50281
- apiHost = new URL(api3).hostname.toLowerCase();
50281
+ apiHost = new URL(api4).hostname.toLowerCase();
50282
50282
  } catch {
50283
50283
  }
50284
50284
  return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
@@ -50407,6 +50407,135 @@ async function uploadResult(result, opts) {
50407
50407
  }
50408
50408
  }
50409
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
+
50410
50539
  // src/commands/findings.ts
50411
50540
  init_cli_config();
50412
50541
  var TRIAGE = {
@@ -50430,7 +50559,7 @@ var STATUS_LABEL = {
50430
50559
  false_positive: "false+",
50431
50560
  ignored: "ignored"
50432
50561
  };
50433
- function orgOrExplain() {
50562
+ function orgOrExplain2() {
50434
50563
  if (!hasSession()) {
50435
50564
  console.log(source_default.red(` Not signed in. Run ${source_default.white("threatcrush login")} first.
50436
50565
  `));
@@ -50446,7 +50575,7 @@ function orgOrExplain() {
50446
50575
  }
50447
50576
  return org;
50448
50577
  }
50449
- async function api2(path2, init) {
50578
+ async function api3(path2, init) {
50450
50579
  const res = await cloudFetch(path2, init);
50451
50580
  const data = await res.json().catch(() => ({}));
50452
50581
  if (!res.ok) {
@@ -50460,14 +50589,14 @@ async function api2(path2, init) {
50460
50589
  var short = (id) => id.slice(0, 8);
50461
50590
  var day = (iso) => iso.slice(0, 10);
50462
50591
  async function findingsListCommand(opts) {
50463
- const org = orgOrExplain();
50592
+ const org = orgOrExplain2();
50464
50593
  if (!org) return;
50465
50594
  const qs = new URLSearchParams();
50466
50595
  if (opts.status) qs.set("status", opts.status);
50467
50596
  if (opts.severity) qs.set("severity", opts.severity);
50468
50597
  if (opts.source) qs.set("source", opts.source);
50469
50598
  qs.set("limit", String(Math.min(500, Number(opts.limit) || 100)));
50470
- const data = await api2(`/api/orgs/${org}/scan-findings?${qs}`);
50599
+ const data = await api3(`/api/orgs/${org}/scan-findings?${qs}`);
50471
50600
  if (!data) return;
50472
50601
  if (opts.json) {
50473
50602
  console.log(JSON.stringify(data, null, 2));
@@ -50497,7 +50626,7 @@ async function resolveIds(org, prefixes) {
50497
50626
  const full = prefixes.filter((p) => /^[0-9a-f-]{36}$/i.test(p));
50498
50627
  const partial = prefixes.filter((p) => !full.includes(p));
50499
50628
  if (!partial.length) return full;
50500
- 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`);
50501
50630
  if (!data) return null;
50502
50631
  for (const p of partial) {
50503
50632
  const hits = data.findings.filter((f) => f.id.startsWith(p.toLowerCase()));
@@ -50512,11 +50641,11 @@ async function resolveIds(org, prefixes) {
50512
50641
  return full;
50513
50642
  }
50514
50643
  async function findingsShowCommand(id, opts) {
50515
- const org = orgOrExplain();
50644
+ const org = orgOrExplain2();
50516
50645
  if (!org) return;
50517
50646
  const [full] = await resolveIds(org, [id]) ?? [];
50518
50647
  if (!full) return;
50519
- const data = await api2(`/api/orgs/${org}/scan-findings/${full}`);
50648
+ const data = await api3(`/api/orgs/${org}/scan-findings/${full}`);
50520
50649
  if (!data) return;
50521
50650
  if (opts.json) {
50522
50651
  console.log(JSON.stringify(data.finding, null, 2));
@@ -50536,7 +50665,7 @@ async function findingsShowCommand(id, opts) {
50536
50665
  console.log();
50537
50666
  }
50538
50667
  async function findingsTriageCommand(verb, ids, opts) {
50539
- const org = orgOrExplain();
50668
+ const org = orgOrExplain2();
50540
50669
  if (!org) return;
50541
50670
  if (!ids.length) {
50542
50671
  console.log(source_default.red(` Give at least one finding id (see threatcrush findings).
@@ -50548,7 +50677,7 @@ async function findingsTriageCommand(verb, ids, opts) {
50548
50677
  if (!full) return;
50549
50678
  const body = { ids: full, status: TRIAGE[verb] };
50550
50679
  if (opts.note !== void 0) body.note = opts.note;
50551
- 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) });
50552
50681
  if (!data) return;
50553
50682
  console.log(source_default.green(` \u2713 ${data.updated.length} finding(s) \u2192 ${TRIAGE[verb].replace("_", " ")}
50554
50683
  `));
@@ -50910,6 +51039,33 @@ for (const verb of Object.keys(TRIAGE)) {
50910
51039
  await findingsTriageCommand(verb, ids, opts);
50911
51040
  });
50912
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
+ });
50913
51069
  program2.command("status").description("Show daemon status and loaded modules").action(async () => {
50914
51070
  await statusCommand();
50915
51071
  });