@profullstack/threatcrush 0.13.58 → 0.13.59

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
@@ -44704,6 +44704,13 @@ var RemediationConsumer = class {
44704
44704
  }, 3e3).unref?.();
44705
44705
  return { status: "executed", executed_at };
44706
44706
  }
44707
+ case "update": {
44708
+ if (!this.opts.updateNow) return failed("update not supported by this daemon");
44709
+ this.opts.log("[cloud] dashboard requested an update");
44710
+ const outcome = await this.opts.updateNow();
44711
+ if (outcome.startsWith("updated to") || outcome.startsWith("up to date")) return { status: "executed", executed_at };
44712
+ return failed(outcome);
44713
+ }
44707
44714
  default:
44708
44715
  return failed(`unsupported action_type: ${action.action_type}`);
44709
44716
  }
@@ -44871,8 +44878,13 @@ var AutoUpdate = class {
44871
44878
  }, ms);
44872
44879
  this.timer.unref?.();
44873
44880
  }
44874
- /** One check; returns what it did, for logs and tests. */
44875
- async check() {
44881
+ /**
44882
+ * One check; returns what it did, for logs and tests.
44883
+ * `force` is the dashboard's "Update now": no min_age wait and no
44884
+ * retry-after-a-day for a version that failed before. `restartDelayMs`
44885
+ * restarts that much later, so the action's result is reported first.
44886
+ */
44887
+ async check(opts = {}) {
44876
44888
  if (this.busy) return "busy";
44877
44889
  this.busy = true;
44878
44890
  try {
@@ -44889,13 +44901,13 @@ var AutoUpdate = class {
44889
44901
  }
44890
44902
  const pick = pickUpdate(doc, this.opts.version, {
44891
44903
  allowMajor: this.opts.settings.allowMajor,
44892
- minAgeMs: this.opts.settings.minAgeMs,
44904
+ minAgeMs: opts.force ? 0 : this.opts.settings.minAgeMs,
44893
44905
  now: this.now()
44894
44906
  });
44895
44907
  if (pick.version === null) return this.note(pick.reason, !pick.reason.startsWith("up to date"));
44896
44908
  const target = pick.version;
44897
44909
  const last = this.lastAttempt();
44898
- if (last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
44910
+ if (!opts.force && last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
44899
44911
  return this.note(`${target} was tried at ${new Date(last.at).toISOString()} and did not take; retrying after a day`);
44900
44912
  }
44901
44913
  const plan = installPlan({
@@ -44918,7 +44930,8 @@ var AutoUpdate = class {
44918
44930
  return this.note(`install of ${target} failed (exit ${code}): ${tail}`);
44919
44931
  }
44920
44932
  this.opts.log(`[update] ${target} installed; restarting onto it`);
44921
- this.opts.restartDaemon();
44933
+ if (opts.restartDelayMs) setTimeout(() => this.opts.restartDaemon(), opts.restartDelayMs).unref?.();
44934
+ else this.opts.restartDaemon();
44922
44935
  return `updated to ${target}`;
44923
44936
  } finally {
44924
44937
  this.busy = false;
@@ -47446,6 +47459,7 @@ async function runDaemon() {
47446
47459
  }
47447
47460
  let cloudSync = null;
47448
47461
  let remediationConsumer = null;
47462
+ let autoUpdateRef = null;
47449
47463
  let allowlistSync = null;
47450
47464
  if (config.cloud?.enabled === false) {
47451
47465
  logLine("[cloud] disabled by [cloud] enabled = false");
@@ -47462,7 +47476,12 @@ async function runDaemon() {
47462
47476
  runHardening: runHardeningChecks
47463
47477
  });
47464
47478
  cloudSync.start();
47465
- remediationConsumer = new RemediationConsumer(remediation, { log: logLine, restartDaemon });
47479
+ remediationConsumer = new RemediationConsumer(remediation, {
47480
+ log: logLine,
47481
+ restartDaemon,
47482
+ // autoUpdate is created below; the action only runs once polling starts.
47483
+ updateNow: () => autoUpdateRef ? autoUpdateRef.check({ force: true, restartDelayMs: 3e3 }) : Promise.resolve("updater not started")
47484
+ });
47466
47485
  remediationConsumer.start();
47467
47486
  allowlistSync = new AllowlistSync(remediation, { log: logLine });
47468
47487
  allowlistSync.start();
@@ -47472,7 +47491,7 @@ async function runDaemon() {
47472
47491
  const abuseReporter = new AbuseReporter({ bus, section: config.abuse_reporter, log: logLine });
47473
47492
  abuseReporter.start();
47474
47493
  const watchdog = startWatchdog({ bus, config: config.watchdog, stateDir: PATHS.stateDir, log: logLine });
47475
- const autoUpdate = new AutoUpdate({
47494
+ const autoUpdate = autoUpdateRef = new AutoUpdate({
47476
47495
  version,
47477
47496
  settings: updateSettings(config.update),
47478
47497
  pkgRoot: (0, import_node_path33.join)(__dirname, ".."),