dsh-server-connector 0.2.3 → 0.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/lib/routes.js CHANGED
@@ -32,6 +32,7 @@
32
32
  import { stat } from 'node:fs/promises'
33
33
 
34
34
  import { AuditError } from './audit.js'
35
+ import { readConfig } from './config.js'
35
36
  import { PendingError } from './pending.js'
36
37
  import { PoolError } from './pool.js'
37
38
  import { MAX_CUSTOM_RULES, RULES, RULES_BY_ID, RuleError, check as checkPolicy, effectiveDecision, validateCustomRule } from './policy.js'
@@ -478,7 +479,17 @@ export function createApi(options) {
478
479
  const config = options.config ?? {}
479
480
  const onChange = typeof options.onChange === 'function' ? options.onChange : null
480
481
  const getCredentials = typeof options.getCredentials === 'function' ? options.getCredentials : () => null
481
- const probeTimeoutMs = Math.min(Number(config.commandTimeoutMs ?? 60000), 15000)
482
+
483
+ /**
484
+ * The current §10 values. Read per request: a volatile settings edit lands in
485
+ * `options.config` without remounting, so a value captured once here would go
486
+ * stale the first time someone opened the settings form.
487
+ * @returns {import('./index.js').PluginConfig}
488
+ */
489
+ const settings = () => readConfig(config)
490
+
491
+ /** The probe budget is the command timeout, capped so "Test" stays interactive. */
492
+ const probeTimeoutMs = () => Math.min(Number(settings().commandTimeoutMs), 15000)
482
493
 
483
494
  /**
484
495
  * Report one non-fatal failure without changing the request outcome.
@@ -664,17 +675,7 @@ export function createApi(options) {
664
675
  body: {
665
676
  servers: present,
666
677
  rules: ruleCatalog(),
667
- config: {
668
- connectTimeoutMs: config.connectTimeoutMs ?? 15000,
669
- commandTimeoutMs: config.commandTimeoutMs ?? 60000,
670
- syncTimeoutMs: config.syncTimeoutMs ?? 20000,
671
- maxOutputChars: config.maxOutputChars ?? 200000,
672
- idleTimeoutMs: config.idleTimeoutMs ?? 600000,
673
- auditEnabled: config.auditEnabled ?? true,
674
- auditMaxBytes: config.auditMaxBytes ?? 0,
675
- pendingTtlHours: config.pendingTtlHours ?? 24,
676
- maxListedServers: config.maxListedServers ?? 8,
677
- },
678
+ config: settings(),
678
679
  hostKeyModes: [...HOST_KEY_MODES],
679
680
  decisions: [...DECISION_VALUES],
680
681
  pendingCount: Array.isArray(queued) ? queued.length : 0,
@@ -1112,7 +1113,7 @@ export function createApi(options) {
1112
1113
  const probe = async (server) => {
1113
1114
  const startedAt = Date.now()
1114
1115
  await pool.connect(server)
1115
- const result = await pool.exec(server, { command: CONNECT_PROBE, timeoutMs: probeTimeoutMs })
1116
+ const result = await pool.exec(server, { command: CONNECT_PROBE, timeoutMs: probeTimeoutMs() })
1116
1117
  return { ...parseProbe(String(result.stdout ?? '')), durationMs: Date.now() - startedAt }
1117
1118
  }
1118
1119