chainlesschain 0.143.0 → 0.152.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/package.json +1 -1
- package/src/commands/a2a.js +196 -28
- package/src/commands/activitypub.js +364 -27
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +587 -103
- package/src/commands/audit.js +206 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +355 -27
- package/src/commands/bm25.js +111 -27
- package/src/commands/browse.js +403 -29
- package/src/commands/ccron.js +128 -28
- package/src/commands/chat.js +207 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +824 -34
- package/src/commands/compt.js +127 -29
- package/src/commands/consol.js +8 -2
- package/src/commands/cowork.js +783 -34
- package/src/commands/crosschain.js +182 -28
- package/src/commands/dao.js +182 -28
- package/src/commands/dbevo.js +227 -0
- package/src/commands/dev.js +207 -0
- package/src/commands/did-v2.js +217 -0
- package/src/commands/did.js +221 -0
- package/src/commands/dlp.js +385 -27
- package/src/commands/economy.js +205 -50
- package/src/commands/evolution.js +203 -50
- package/src/commands/evomap.js +387 -27
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fflag.js +74 -22
- package/src/commands/fusion.js +205 -0
- package/src/commands/git.js +177 -37
- package/src/commands/governance.js +209 -0
- package/src/commands/hardening.js +209 -0
- package/src/commands/hmemory.js +204 -50
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/incentive.js +209 -0
- package/src/commands/inference.js +170 -34
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/itbudget.js +149 -33
- package/src/commands/kg.js +206 -0
- package/src/commands/llm.js +217 -0
- package/src/commands/lowcode.js +195 -38
- package/src/commands/marketplace.js +206 -0
- package/src/commands/matrix.js +386 -27
- package/src/commands/mcp.js +217 -0
- package/src/commands/mcpscaf.js +145 -33
- package/src/commands/meminj.js +145 -33
- package/src/commands/memory.js +209 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +387 -27
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +217 -0
- package/src/commands/orchgov.js +144 -33
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/pdfp.js +109 -27
- package/src/commands/perception.js +209 -0
- package/src/commands/perf.js +169 -32
- package/src/commands/perm.js +144 -33
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +207 -52
- package/src/commands/planmode.js +141 -32
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/privacy.js +203 -0
- package/src/commands/promcomp.js +111 -27
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +410 -34
- package/src/commands/reputation.js +208 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/sandbox.js +206 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/seshhook.js +145 -33
- package/src/commands/seshsearch.js +141 -33
- package/src/commands/seshtail.js +144 -33
- package/src/commands/seshu.js +152 -33
- package/src/commands/session.js +209 -0
- package/src/commands/sganal.js +123 -29
- package/src/commands/siem.js +201 -34
- package/src/commands/skill.js +207 -0
- package/src/commands/sla.js +212 -0
- package/src/commands/slotfill.js +146 -33
- package/src/commands/social.js +358 -32
- package/src/commands/sso.js +209 -0
- package/src/commands/stress.js +206 -0
- package/src/commands/svccont.js +145 -33
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/terraform.js +206 -0
- package/src/commands/tms.js +171 -33
- package/src/commands/tokens.js +209 -0
- package/src/commands/topiccls.js +146 -33
- package/src/commands/trust.js +217 -0
- package/src/commands/uprof.js +141 -32
- package/src/commands/vcheck.js +122 -28
- package/src/commands/wallet.js +209 -0
- package/src/commands/webfetch.js +141 -32
- package/src/commands/workflow.js +203 -0
- package/src/commands/zkp.js +184 -28
- package/src/index.js +180 -0
- package/src/lib/a2a-protocol.js +319 -51
- package/src/lib/activitypub-bridge.js +622 -50
- package/src/lib/agent-economy.js +304 -51
- package/src/lib/agent-network.js +341 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/app-builder.js +279 -46
- package/src/lib/audit-logger.js +321 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +284 -48
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +616 -49
- package/src/lib/bm25-search.js +301 -49
- package/src/lib/browser-automation.js +630 -49
- package/src/lib/chat-core.js +336 -0
- package/src/lib/claude-code-bridge.js +341 -0
- package/src/lib/code-agent.js +339 -0
- package/src/lib/collaboration-governance.js +334 -0
- package/src/lib/community-governance.js +346 -0
- package/src/lib/compliance-framework-reporter.js +305 -51
- package/src/lib/compliance-manager.js +330 -0
- package/src/lib/compression-telemetry.js +301 -49
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/content-recommender.js +317 -52
- package/src/lib/cowork-cron.js +298 -49
- package/src/lib/cowork-learning.js +333 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-runner.js +308 -51
- package/src/lib/cowork-workflow.js +327 -0
- package/src/lib/cross-chain.js +311 -51
- package/src/lib/dao-governance.js +280 -46
- package/src/lib/dbevo.js +351 -0
- package/src/lib/decentral-infra.js +330 -0
- package/src/lib/did-manager.js +341 -0
- package/src/lib/did-v2-manager.js +341 -0
- package/src/lib/dlp-engine.js +626 -49
- package/src/lib/evolution-system.js +278 -47
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +280 -46
- package/src/lib/execution-backend.js +294 -48
- package/src/lib/feature-flags.js +294 -49
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/git-integration.js +285 -47
- package/src/lib/hardening-manager.js +341 -0
- package/src/lib/hierarchical-memory.js +284 -48
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +308 -51
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/iteration-budget.js +302 -50
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +333 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +620 -47
- package/src/lib/mcp-registry.js +346 -0
- package/src/lib/mcp-scaffold.js +318 -54
- package/src/lib/memory-injection.js +288 -49
- package/src/lib/memory-manager.js +336 -0
- package/src/lib/multimodal.js +330 -0
- package/src/lib/nl-programming.js +341 -0
- package/src/lib/nostr-bridge.js +622 -49
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/orchestrator.js +293 -48
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/pdf-parser.js +298 -49
- package/src/lib/perception.js +346 -0
- package/src/lib/perf-tuning.js +309 -50
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/permission-engine.js +287 -49
- package/src/lib/pipeline-orchestrator.js +289 -49
- package/src/lib/plan-mode.js +298 -51
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/privacy-computing.js +335 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/reputation-optimizer.js +340 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/sandbox-v2.js +327 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-container.js +313 -52
- package/src/lib/session-consolidator.js +296 -49
- package/src/lib/session-hooks.js +312 -53
- package/src/lib/session-manager.js +334 -0
- package/src/lib/session-search.js +304 -51
- package/src/lib/session-tail.js +288 -49
- package/src/lib/session-usage.js +298 -52
- package/src/lib/siem-exporter.js +298 -51
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-marketplace.js +345 -0
- package/src/lib/sla-manager.js +341 -0
- package/src/lib/slot-filler.js +303 -51
- package/src/lib/social-graph-analytics.js +295 -49
- package/src/lib/social-graph.js +272 -49
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stress-tester.js +342 -0
- package/src/lib/sub-agent-registry.js +302 -53
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/task-model-selector.js +302 -50
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/terraform-manager.js +333 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +281 -47
- package/src/lib/token-incentive.js +341 -0
- package/src/lib/token-tracker.js +336 -0
- package/src/lib/topic-classifier.js +297 -49
- package/src/lib/trust-security.js +343 -0
- package/src/lib/ueba.js +340 -0
- package/src/lib/universal-runtime.js +330 -0
- package/src/lib/user-profile.js +294 -50
- package/src/lib/version-checker.js +304 -50
- package/src/lib/wallet-manager.js +336 -0
- package/src/lib/web-fetch.js +292 -51
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/zkp-engine.js +286 -49
package/src/lib/siem-exporter.js
CHANGED
|
@@ -469,25 +469,56 @@ export function listTargetsByStatus(status) {
|
|
|
469
469
|
|
|
470
470
|
export { _severityCEF, _allowedTargetTransitions };
|
|
471
471
|
|
|
472
|
-
|
|
473
472
|
// ===== V2 Surface: SIEM Exporter governance overlay (CLI v0.138.0) =====
|
|
474
473
|
export const SIEM_TARGET_MATURITY_V2 = Object.freeze({
|
|
475
|
-
PENDING: "pending",
|
|
474
|
+
PENDING: "pending",
|
|
475
|
+
ACTIVE: "active",
|
|
476
|
+
DEGRADED: "degraded",
|
|
477
|
+
RETIRED: "retired",
|
|
476
478
|
});
|
|
477
479
|
export const SIEM_EXPORT_LIFECYCLE_V2 = Object.freeze({
|
|
478
|
-
QUEUED: "queued",
|
|
480
|
+
QUEUED: "queued",
|
|
481
|
+
SENDING: "sending",
|
|
482
|
+
DELIVERED: "delivered",
|
|
483
|
+
FAILED: "failed",
|
|
484
|
+
CANCELLED: "cancelled",
|
|
479
485
|
});
|
|
480
486
|
|
|
481
487
|
const _siemTargetTrans = new Map([
|
|
482
|
-
[
|
|
483
|
-
|
|
484
|
-
|
|
488
|
+
[
|
|
489
|
+
SIEM_TARGET_MATURITY_V2.PENDING,
|
|
490
|
+
new Set([SIEM_TARGET_MATURITY_V2.ACTIVE, SIEM_TARGET_MATURITY_V2.RETIRED]),
|
|
491
|
+
],
|
|
492
|
+
[
|
|
493
|
+
SIEM_TARGET_MATURITY_V2.ACTIVE,
|
|
494
|
+
new Set([
|
|
495
|
+
SIEM_TARGET_MATURITY_V2.DEGRADED,
|
|
496
|
+
SIEM_TARGET_MATURITY_V2.RETIRED,
|
|
497
|
+
]),
|
|
498
|
+
],
|
|
499
|
+
[
|
|
500
|
+
SIEM_TARGET_MATURITY_V2.DEGRADED,
|
|
501
|
+
new Set([SIEM_TARGET_MATURITY_V2.ACTIVE, SIEM_TARGET_MATURITY_V2.RETIRED]),
|
|
502
|
+
],
|
|
485
503
|
[SIEM_TARGET_MATURITY_V2.RETIRED, new Set()],
|
|
486
504
|
]);
|
|
487
505
|
const _siemTargetTerminal = new Set([SIEM_TARGET_MATURITY_V2.RETIRED]);
|
|
488
506
|
const _siemExportTrans = new Map([
|
|
489
|
-
[
|
|
490
|
-
|
|
507
|
+
[
|
|
508
|
+
SIEM_EXPORT_LIFECYCLE_V2.QUEUED,
|
|
509
|
+
new Set([
|
|
510
|
+
SIEM_EXPORT_LIFECYCLE_V2.SENDING,
|
|
511
|
+
SIEM_EXPORT_LIFECYCLE_V2.CANCELLED,
|
|
512
|
+
]),
|
|
513
|
+
],
|
|
514
|
+
[
|
|
515
|
+
SIEM_EXPORT_LIFECYCLE_V2.SENDING,
|
|
516
|
+
new Set([
|
|
517
|
+
SIEM_EXPORT_LIFECYCLE_V2.DELIVERED,
|
|
518
|
+
SIEM_EXPORT_LIFECYCLE_V2.FAILED,
|
|
519
|
+
SIEM_EXPORT_LIFECYCLE_V2.CANCELLED,
|
|
520
|
+
]),
|
|
521
|
+
],
|
|
491
522
|
[SIEM_EXPORT_LIFECYCLE_V2.DELIVERED, new Set()],
|
|
492
523
|
[SIEM_EXPORT_LIFECYCLE_V2.FAILED, new Set()],
|
|
493
524
|
[SIEM_EXPORT_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
@@ -500,76 +531,292 @@ let _siemMaxPendingExportsPerTarget = 50;
|
|
|
500
531
|
let _siemTargetIdleMs = 24 * 60 * 60 * 1000;
|
|
501
532
|
let _siemExportStuckMs = 5 * 60 * 1000;
|
|
502
533
|
|
|
503
|
-
function _siemPos(n, lbl) {
|
|
534
|
+
function _siemPos(n, lbl) {
|
|
535
|
+
const v = Math.floor(Number(n));
|
|
536
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
537
|
+
throw new Error(`${lbl} must be positive integer`);
|
|
538
|
+
return v;
|
|
539
|
+
}
|
|
504
540
|
|
|
505
|
-
export function setMaxActiveSiemTargetsPerOperatorV2(n) {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
export function
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
export function
|
|
512
|
-
|
|
541
|
+
export function setMaxActiveSiemTargetsPerOperatorV2(n) {
|
|
542
|
+
_siemMaxActivePerOperator = _siemPos(n, "maxActiveSiemTargetsPerOperator");
|
|
543
|
+
}
|
|
544
|
+
export function getMaxActiveSiemTargetsPerOperatorV2() {
|
|
545
|
+
return _siemMaxActivePerOperator;
|
|
546
|
+
}
|
|
547
|
+
export function setMaxPendingSiemExportsPerTargetV2(n) {
|
|
548
|
+
_siemMaxPendingExportsPerTarget = _siemPos(
|
|
549
|
+
n,
|
|
550
|
+
"maxPendingSiemExportsPerTarget",
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
export function getMaxPendingSiemExportsPerTargetV2() {
|
|
554
|
+
return _siemMaxPendingExportsPerTarget;
|
|
555
|
+
}
|
|
556
|
+
export function setSiemTargetIdleMsV2(n) {
|
|
557
|
+
_siemTargetIdleMs = _siemPos(n, "siemTargetIdleMs");
|
|
558
|
+
}
|
|
559
|
+
export function getSiemTargetIdleMsV2() {
|
|
560
|
+
return _siemTargetIdleMs;
|
|
561
|
+
}
|
|
562
|
+
export function setSiemExportStuckMsV2(n) {
|
|
563
|
+
_siemExportStuckMs = _siemPos(n, "siemExportStuckMs");
|
|
564
|
+
}
|
|
565
|
+
export function getSiemExportStuckMsV2() {
|
|
566
|
+
return _siemExportStuckMs;
|
|
567
|
+
}
|
|
513
568
|
|
|
514
569
|
export function _resetStateSiemExporterV2() {
|
|
515
|
-
_siemTargets.clear();
|
|
516
|
-
|
|
517
|
-
|
|
570
|
+
_siemTargets.clear();
|
|
571
|
+
_siemExportJobs.clear();
|
|
572
|
+
_siemMaxActivePerOperator = 8;
|
|
573
|
+
_siemMaxPendingExportsPerTarget = 50;
|
|
574
|
+
_siemTargetIdleMs = 24 * 60 * 60 * 1000;
|
|
575
|
+
_siemExportStuckMs = 5 * 60 * 1000;
|
|
518
576
|
}
|
|
519
577
|
|
|
520
578
|
export function registerSiemTargetV2({ id, operator, kind, metadata } = {}) {
|
|
521
579
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
522
|
-
if (!operator || typeof operator !== "string")
|
|
523
|
-
|
|
580
|
+
if (!operator || typeof operator !== "string")
|
|
581
|
+
throw new Error("operator is required");
|
|
582
|
+
if (_siemTargets.has(id))
|
|
583
|
+
throw new Error(`siem target ${id} already registered`);
|
|
524
584
|
const now = Date.now();
|
|
525
|
-
const t = {
|
|
585
|
+
const t = {
|
|
586
|
+
id,
|
|
587
|
+
operator,
|
|
588
|
+
kind: kind || "splunk_hec",
|
|
589
|
+
status: SIEM_TARGET_MATURITY_V2.PENDING,
|
|
590
|
+
createdAt: now,
|
|
591
|
+
updatedAt: now,
|
|
592
|
+
activatedAt: null,
|
|
593
|
+
retiredAt: null,
|
|
594
|
+
lastTouchedAt: now,
|
|
595
|
+
metadata: { ...(metadata || {}) },
|
|
596
|
+
};
|
|
526
597
|
_siemTargets.set(id, t);
|
|
527
598
|
return { ...t, metadata: { ...t.metadata } };
|
|
528
599
|
}
|
|
529
|
-
function _siemCheckT(from, to) {
|
|
530
|
-
|
|
600
|
+
function _siemCheckT(from, to) {
|
|
601
|
+
const a = _siemTargetTrans.get(from);
|
|
602
|
+
if (!a || !a.has(to))
|
|
603
|
+
throw new Error(`invalid siem target transition ${from} → ${to}`);
|
|
604
|
+
}
|
|
605
|
+
function _siemCountActive(operator) {
|
|
606
|
+
let n = 0;
|
|
607
|
+
for (const t of _siemTargets.values())
|
|
608
|
+
if (t.operator === operator && t.status === SIEM_TARGET_MATURITY_V2.ACTIVE)
|
|
609
|
+
n++;
|
|
610
|
+
return n;
|
|
611
|
+
}
|
|
531
612
|
|
|
532
613
|
export function activateSiemTargetV2(id) {
|
|
533
|
-
const t = _siemTargets.get(id);
|
|
614
|
+
const t = _siemTargets.get(id);
|
|
615
|
+
if (!t) throw new Error(`siem target ${id} not found`);
|
|
534
616
|
_siemCheckT(t.status, SIEM_TARGET_MATURITY_V2.ACTIVE);
|
|
535
617
|
const recovery = t.status === SIEM_TARGET_MATURITY_V2.DEGRADED;
|
|
536
|
-
if (!recovery) {
|
|
537
|
-
|
|
618
|
+
if (!recovery) {
|
|
619
|
+
const c = _siemCountActive(t.operator);
|
|
620
|
+
if (c >= _siemMaxActivePerOperator)
|
|
621
|
+
throw new Error(
|
|
622
|
+
`max active siem targets per operator (${_siemMaxActivePerOperator}) reached for ${t.operator}`,
|
|
623
|
+
);
|
|
624
|
+
}
|
|
625
|
+
const now = Date.now();
|
|
626
|
+
t.status = SIEM_TARGET_MATURITY_V2.ACTIVE;
|
|
627
|
+
t.updatedAt = now;
|
|
628
|
+
t.lastTouchedAt = now;
|
|
629
|
+
if (!t.activatedAt) t.activatedAt = now;
|
|
538
630
|
return { ...t, metadata: { ...t.metadata } };
|
|
539
631
|
}
|
|
540
|
-
export function degradeSiemTargetV2(id) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
632
|
+
export function degradeSiemTargetV2(id) {
|
|
633
|
+
const t = _siemTargets.get(id);
|
|
634
|
+
if (!t) throw new Error(`siem target ${id} not found`);
|
|
635
|
+
_siemCheckT(t.status, SIEM_TARGET_MATURITY_V2.DEGRADED);
|
|
636
|
+
t.status = SIEM_TARGET_MATURITY_V2.DEGRADED;
|
|
637
|
+
t.updatedAt = Date.now();
|
|
638
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
639
|
+
}
|
|
640
|
+
export function retireSiemTargetV2(id) {
|
|
641
|
+
const t = _siemTargets.get(id);
|
|
642
|
+
if (!t) throw new Error(`siem target ${id} not found`);
|
|
643
|
+
_siemCheckT(t.status, SIEM_TARGET_MATURITY_V2.RETIRED);
|
|
644
|
+
const now = Date.now();
|
|
645
|
+
t.status = SIEM_TARGET_MATURITY_V2.RETIRED;
|
|
646
|
+
t.updatedAt = now;
|
|
647
|
+
if (!t.retiredAt) t.retiredAt = now;
|
|
648
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
649
|
+
}
|
|
650
|
+
export function touchSiemTargetV2(id) {
|
|
651
|
+
const t = _siemTargets.get(id);
|
|
652
|
+
if (!t) throw new Error(`siem target ${id} not found`);
|
|
653
|
+
if (_siemTargetTerminal.has(t.status))
|
|
654
|
+
throw new Error(`cannot touch terminal siem target ${id}`);
|
|
655
|
+
const now = Date.now();
|
|
656
|
+
t.lastTouchedAt = now;
|
|
657
|
+
t.updatedAt = now;
|
|
658
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
659
|
+
}
|
|
660
|
+
export function getSiemTargetV2(id) {
|
|
661
|
+
const t = _siemTargets.get(id);
|
|
662
|
+
if (!t) return null;
|
|
663
|
+
return { ...t, metadata: { ...t.metadata } };
|
|
664
|
+
}
|
|
665
|
+
export function listSiemTargetsV2() {
|
|
666
|
+
return [..._siemTargets.values()].map((t) => ({
|
|
667
|
+
...t,
|
|
668
|
+
metadata: { ...t.metadata },
|
|
669
|
+
}));
|
|
670
|
+
}
|
|
545
671
|
|
|
546
|
-
function _siemCountPendingExports(tid) {
|
|
672
|
+
function _siemCountPendingExports(tid) {
|
|
673
|
+
let n = 0;
|
|
674
|
+
for (const e of _siemExportJobs.values())
|
|
675
|
+
if (
|
|
676
|
+
e.targetId === tid &&
|
|
677
|
+
(e.status === SIEM_EXPORT_LIFECYCLE_V2.QUEUED ||
|
|
678
|
+
e.status === SIEM_EXPORT_LIFECYCLE_V2.SENDING)
|
|
679
|
+
)
|
|
680
|
+
n++;
|
|
681
|
+
return n;
|
|
682
|
+
}
|
|
547
683
|
|
|
548
684
|
export function createSiemExportV2({ id, targetId, format, metadata } = {}) {
|
|
549
685
|
if (!id || typeof id !== "string") throw new Error("id is required");
|
|
550
|
-
if (!targetId || typeof targetId !== "string")
|
|
551
|
-
|
|
552
|
-
if (
|
|
686
|
+
if (!targetId || typeof targetId !== "string")
|
|
687
|
+
throw new Error("targetId is required");
|
|
688
|
+
if (_siemExportJobs.has(id))
|
|
689
|
+
throw new Error(`siem export ${id} already exists`);
|
|
690
|
+
if (!_siemTargets.has(targetId))
|
|
691
|
+
throw new Error(`siem target ${targetId} not found`);
|
|
553
692
|
const pending = _siemCountPendingExports(targetId);
|
|
554
|
-
if (pending >= _siemMaxPendingExportsPerTarget)
|
|
693
|
+
if (pending >= _siemMaxPendingExportsPerTarget)
|
|
694
|
+
throw new Error(
|
|
695
|
+
`max pending siem exports per target (${_siemMaxPendingExportsPerTarget}) reached for ${targetId}`,
|
|
696
|
+
);
|
|
555
697
|
const now = Date.now();
|
|
556
|
-
const e = {
|
|
698
|
+
const e = {
|
|
699
|
+
id,
|
|
700
|
+
targetId,
|
|
701
|
+
format: format || "json",
|
|
702
|
+
status: SIEM_EXPORT_LIFECYCLE_V2.QUEUED,
|
|
703
|
+
createdAt: now,
|
|
704
|
+
updatedAt: now,
|
|
705
|
+
startedAt: null,
|
|
706
|
+
settledAt: null,
|
|
707
|
+
metadata: { ...(metadata || {}) },
|
|
708
|
+
};
|
|
557
709
|
_siemExportJobs.set(id, e);
|
|
558
710
|
return { ...e, metadata: { ...e.metadata } };
|
|
559
711
|
}
|
|
560
|
-
function _siemCheckE(from, to) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
export function
|
|
566
|
-
|
|
712
|
+
function _siemCheckE(from, to) {
|
|
713
|
+
const a = _siemExportTrans.get(from);
|
|
714
|
+
if (!a || !a.has(to))
|
|
715
|
+
throw new Error(`invalid siem export transition ${from} → ${to}`);
|
|
716
|
+
}
|
|
717
|
+
export function startSiemExportV2(id) {
|
|
718
|
+
const e = _siemExportJobs.get(id);
|
|
719
|
+
if (!e) throw new Error(`siem export ${id} not found`);
|
|
720
|
+
_siemCheckE(e.status, SIEM_EXPORT_LIFECYCLE_V2.SENDING);
|
|
721
|
+
const now = Date.now();
|
|
722
|
+
e.status = SIEM_EXPORT_LIFECYCLE_V2.SENDING;
|
|
723
|
+
e.updatedAt = now;
|
|
724
|
+
if (!e.startedAt) e.startedAt = now;
|
|
725
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
726
|
+
}
|
|
727
|
+
export function deliverSiemExportV2(id) {
|
|
728
|
+
const e = _siemExportJobs.get(id);
|
|
729
|
+
if (!e) throw new Error(`siem export ${id} not found`);
|
|
730
|
+
_siemCheckE(e.status, SIEM_EXPORT_LIFECYCLE_V2.DELIVERED);
|
|
731
|
+
const now = Date.now();
|
|
732
|
+
e.status = SIEM_EXPORT_LIFECYCLE_V2.DELIVERED;
|
|
733
|
+
e.updatedAt = now;
|
|
734
|
+
if (!e.settledAt) e.settledAt = now;
|
|
735
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
736
|
+
}
|
|
737
|
+
export function failSiemExportV2(id, reason) {
|
|
738
|
+
const e = _siemExportJobs.get(id);
|
|
739
|
+
if (!e) throw new Error(`siem export ${id} not found`);
|
|
740
|
+
_siemCheckE(e.status, SIEM_EXPORT_LIFECYCLE_V2.FAILED);
|
|
741
|
+
const now = Date.now();
|
|
742
|
+
e.status = SIEM_EXPORT_LIFECYCLE_V2.FAILED;
|
|
743
|
+
e.updatedAt = now;
|
|
744
|
+
if (!e.settledAt) e.settledAt = now;
|
|
745
|
+
if (reason) e.metadata.failReason = String(reason);
|
|
746
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
747
|
+
}
|
|
748
|
+
export function cancelSiemExportV2(id, reason) {
|
|
749
|
+
const e = _siemExportJobs.get(id);
|
|
750
|
+
if (!e) throw new Error(`siem export ${id} not found`);
|
|
751
|
+
_siemCheckE(e.status, SIEM_EXPORT_LIFECYCLE_V2.CANCELLED);
|
|
752
|
+
const now = Date.now();
|
|
753
|
+
e.status = SIEM_EXPORT_LIFECYCLE_V2.CANCELLED;
|
|
754
|
+
e.updatedAt = now;
|
|
755
|
+
if (!e.settledAt) e.settledAt = now;
|
|
756
|
+
if (reason) e.metadata.cancelReason = String(reason);
|
|
757
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
758
|
+
}
|
|
759
|
+
export function getSiemExportV2(id) {
|
|
760
|
+
const e = _siemExportJobs.get(id);
|
|
761
|
+
if (!e) return null;
|
|
762
|
+
return { ...e, metadata: { ...e.metadata } };
|
|
763
|
+
}
|
|
764
|
+
export function listSiemExportsV2() {
|
|
765
|
+
return [..._siemExportJobs.values()].map((e) => ({
|
|
766
|
+
...e,
|
|
767
|
+
metadata: { ...e.metadata },
|
|
768
|
+
}));
|
|
769
|
+
}
|
|
567
770
|
|
|
568
|
-
export function autoDegradeIdleSiemTargetsV2({ now } = {}) {
|
|
569
|
-
|
|
771
|
+
export function autoDegradeIdleSiemTargetsV2({ now } = {}) {
|
|
772
|
+
const t = now ?? Date.now();
|
|
773
|
+
const flipped = [];
|
|
774
|
+
for (const tgt of _siemTargets.values())
|
|
775
|
+
if (
|
|
776
|
+
tgt.status === SIEM_TARGET_MATURITY_V2.ACTIVE &&
|
|
777
|
+
t - tgt.lastTouchedAt >= _siemTargetIdleMs
|
|
778
|
+
) {
|
|
779
|
+
tgt.status = SIEM_TARGET_MATURITY_V2.DEGRADED;
|
|
780
|
+
tgt.updatedAt = t;
|
|
781
|
+
flipped.push(tgt.id);
|
|
782
|
+
}
|
|
783
|
+
return { flipped, count: flipped.length };
|
|
784
|
+
}
|
|
785
|
+
export function autoFailStuckSiemExportsV2({ now } = {}) {
|
|
786
|
+
const t = now ?? Date.now();
|
|
787
|
+
const flipped = [];
|
|
788
|
+
for (const e of _siemExportJobs.values())
|
|
789
|
+
if (
|
|
790
|
+
e.status === SIEM_EXPORT_LIFECYCLE_V2.SENDING &&
|
|
791
|
+
e.startedAt != null &&
|
|
792
|
+
t - e.startedAt >= _siemExportStuckMs
|
|
793
|
+
) {
|
|
794
|
+
e.status = SIEM_EXPORT_LIFECYCLE_V2.FAILED;
|
|
795
|
+
e.updatedAt = t;
|
|
796
|
+
if (!e.settledAt) e.settledAt = t;
|
|
797
|
+
e.metadata.failReason = "auto-fail-stuck";
|
|
798
|
+
flipped.push(e.id);
|
|
799
|
+
}
|
|
800
|
+
return { flipped, count: flipped.length };
|
|
801
|
+
}
|
|
570
802
|
|
|
571
803
|
export function getSiemExporterGovStatsV2() {
|
|
572
|
-
const targetsByStatus = {};
|
|
573
|
-
|
|
574
|
-
|
|
804
|
+
const targetsByStatus = {};
|
|
805
|
+
for (const s of Object.values(SIEM_TARGET_MATURITY_V2))
|
|
806
|
+
targetsByStatus[s] = 0;
|
|
807
|
+
for (const t of _siemTargets.values()) targetsByStatus[t.status]++;
|
|
808
|
+
const exportsByStatus = {};
|
|
809
|
+
for (const s of Object.values(SIEM_EXPORT_LIFECYCLE_V2))
|
|
810
|
+
exportsByStatus[s] = 0;
|
|
811
|
+
for (const e of _siemExportJobs.values()) exportsByStatus[e.status]++;
|
|
812
|
+
return {
|
|
813
|
+
totalSiemTargetsV2: _siemTargets.size,
|
|
814
|
+
totalSiemExportsV2: _siemExportJobs.size,
|
|
815
|
+
maxActiveSiemTargetsPerOperator: _siemMaxActivePerOperator,
|
|
816
|
+
maxPendingSiemExportsPerTarget: _siemMaxPendingExportsPerTarget,
|
|
817
|
+
siemTargetIdleMs: _siemTargetIdleMs,
|
|
818
|
+
siemExportStuckMs: _siemExportStuckMs,
|
|
819
|
+
targetsByStatus,
|
|
820
|
+
exportsByStatus,
|
|
821
|
+
};
|
|
575
822
|
}
|