chainlesschain 0.145.0 → 0.156.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/README.md +52 -3
- package/package.json +1 -1
- package/src/commands/a2a.js +201 -0
- package/src/commands/activitypub.js +207 -0
- package/src/commands/agent-network.js +217 -0
- package/src/commands/agent.js +1250 -0
- package/src/commands/automation.js +201 -0
- package/src/commands/bi.js +203 -0
- package/src/commands/browse.js +213 -0
- package/src/commands/chat.js +605 -0
- package/src/commands/cli-anything.js +426 -0
- package/src/commands/codegen.js +207 -0
- package/src/commands/collab.js +211 -0
- package/src/commands/compliance.js +822 -0
- package/src/commands/config.js +213 -0
- package/src/commands/cowork.js +1666 -0
- package/src/commands/crosschain.js +203 -0
- package/src/commands/dao.js +203 -0
- 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 +213 -0
- package/src/commands/economy.js +199 -0
- package/src/commands/encrypt.js +201 -0
- package/src/commands/evolution.js +199 -0
- package/src/commands/evomap.js +830 -0
- package/src/commands/export.js +213 -0
- package/src/commands/federation.js +209 -0
- package/src/commands/fusion.js +205 -0
- package/src/commands/governance.js +209 -0
- package/src/commands/hmemory.js +203 -0
- package/src/commands/hook.js +209 -0
- package/src/commands/import.js +209 -0
- package/src/commands/inference.js +207 -0
- package/src/commands/infra.js +203 -0
- package/src/commands/instinct.js +209 -0
- package/src/commands/ipfs.js +207 -0
- package/src/commands/kg.js +195 -0
- package/src/commands/llm.js +426 -0
- package/src/commands/matrix.js +207 -0
- package/src/commands/mcp.js +217 -0
- package/src/commands/memory.js +412 -0
- package/src/commands/multimodal.js +203 -0
- package/src/commands/nlprog.js +225 -0
- package/src/commands/nostr.js +209 -0
- package/src/commands/note.js +205 -0
- package/src/commands/ops.js +219 -0
- package/src/commands/orchestrate.js +406 -0
- package/src/commands/org.js +209 -0
- package/src/commands/p2p.js +209 -0
- package/src/commands/perception.js +209 -0
- package/src/commands/permmem.js +203 -0
- package/src/commands/pipeline.js +199 -0
- package/src/commands/planmode.js +426 -0
- package/src/commands/plugin-ecosystem.js +209 -0
- package/src/commands/plugin.js +209 -0
- package/src/commands/pqc.js +213 -0
- package/src/commands/quantization.js +207 -0
- package/src/commands/rcache.js +205 -0
- package/src/commands/recommend.js +233 -0
- package/src/commands/runtime.js +205 -0
- package/src/commands/scim.js +209 -0
- package/src/commands/services.js +207 -0
- package/src/commands/session.js +209 -0
- package/src/commands/setup.js +205 -0
- package/src/commands/skill.js +414 -0
- package/src/commands/social.js +201 -0
- package/src/commands/sso.js +209 -0
- package/src/commands/start.js +209 -0
- package/src/commands/stream.js +213 -0
- package/src/commands/sync.js +209 -0
- package/src/commands/tech.js +209 -0
- package/src/commands/tenant.js +217 -0
- package/src/commands/tokens.js +209 -0
- package/src/commands/trust.js +217 -0
- package/src/commands/ui.js +225 -0
- package/src/commands/wallet.js +209 -0
- package/src/commands/workflow.js +412 -0
- package/src/index.js +252 -0
- package/src/lib/a2a-protocol.js +332 -0
- package/src/lib/activitypub-bridge.js +334 -0
- package/src/lib/agent-coordinator.js +334 -0
- package/src/lib/agent-economy.js +334 -0
- package/src/lib/agent-network.js +341 -0
- package/src/lib/agent-router.js +333 -0
- package/src/lib/aiops.js +346 -0
- package/src/lib/automation-engine.js +335 -0
- package/src/lib/autonomous-agent.js +332 -0
- package/src/lib/autonomous-developer.js +332 -0
- package/src/lib/bi-engine.js +333 -0
- package/src/lib/browser-automation.js +334 -0
- package/src/lib/chat-core.js +335 -0
- package/src/lib/cli-anything-bridge.js +341 -0
- package/src/lib/cli-context-engineering.js +351 -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-manager.js +334 -0
- package/src/lib/content-recommendation.js +351 -0
- package/src/lib/cowork-adapter.js +336 -0
- package/src/lib/cowork-evomap-adapter.js +341 -0
- package/src/lib/cowork-mcp-tools.js +341 -0
- package/src/lib/cowork-observe-html.js +341 -0
- package/src/lib/cowork-observe.js +341 -0
- package/src/lib/cowork-share.js +338 -0
- package/src/lib/cowork-task-templates.js +342 -1
- package/src/lib/cowork-template-marketplace.js +340 -0
- package/src/lib/cross-chain.js +339 -0
- package/src/lib/crypto-manager.js +334 -0
- package/src/lib/dao-governance.js +339 -0
- 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 +339 -0
- package/src/lib/downloader.js +334 -0
- package/src/lib/evolution-system.js +334 -0
- package/src/lib/evomap-client.js +342 -0
- package/src/lib/evomap-federation.js +338 -0
- package/src/lib/evomap-governance.js +334 -0
- package/src/lib/evomap-manager.js +330 -0
- package/src/lib/execution-backend.js +330 -0
- package/src/lib/federation-hardening.js +340 -0
- package/src/lib/hashline.js +338 -0
- package/src/lib/hierarchical-memory.js +334 -0
- package/src/lib/hook-manager.js +341 -0
- package/src/lib/inference-network.js +341 -0
- package/src/lib/instinct-manager.js +346 -0
- package/src/lib/interaction-adapter.js +330 -0
- package/src/lib/interactive-planner.js +354 -0
- package/src/lib/ipfs-storage.js +334 -0
- package/src/lib/knowledge-exporter.js +341 -0
- package/src/lib/knowledge-graph.js +331 -0
- package/src/lib/knowledge-importer.js +341 -0
- package/src/lib/llm-providers.js +346 -0
- package/src/lib/matrix-bridge.js +339 -0
- package/src/lib/mcp-registry.js +346 -0
- 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 +336 -0
- package/src/lib/note-versioning.js +339 -0
- package/src/lib/org-manager.js +336 -0
- package/src/lib/p2p-manager.js +341 -0
- package/src/lib/perception.js +346 -0
- package/src/lib/permanent-memory.js +327 -0
- package/src/lib/pipeline-orchestrator.js +332 -0
- package/src/lib/plan-mode.js +336 -0
- package/src/lib/plugin-autodiscovery.js +334 -0
- package/src/lib/plugin-ecosystem.js +346 -0
- package/src/lib/pqc-manager.js +346 -0
- package/src/lib/process-manager.js +336 -0
- package/src/lib/protocol-fusion.js +338 -0
- package/src/lib/provider-options.js +346 -0
- package/src/lib/provider-stream.js +348 -0
- package/src/lib/quantization.js +337 -0
- package/src/lib/response-cache.js +333 -0
- package/src/lib/scim-manager.js +346 -0
- package/src/lib/service-manager.js +337 -0
- package/src/lib/session-core-singletons.js +341 -0
- package/src/lib/session-manager.js +334 -0
- package/src/lib/skill-loader.js +334 -0
- package/src/lib/skill-mcp.js +336 -0
- package/src/lib/social-manager.js +330 -0
- package/src/lib/sso-manager.js +340 -0
- package/src/lib/stix-parser.js +346 -0
- package/src/lib/sub-agent-context.js +343 -0
- package/src/lib/sub-agent-profiles.js +335 -0
- package/src/lib/sub-agent-registry.js +336 -0
- package/src/lib/sync-manager.js +336 -0
- package/src/lib/tech-learning-engine.js +341 -0
- package/src/lib/tenant-saas.js +341 -0
- package/src/lib/threat-intel.js +330 -0
- package/src/lib/todo-manager.js +336 -0
- package/src/lib/token-tracker.js +336 -0
- 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/wallet-manager.js +336 -0
- package/src/lib/web-ui-server.js +348 -0
- package/src/lib/workflow-engine.js +330 -0
- package/src/lib/workflow-expr.js +346 -0
- package/src/lib/ws-chat-handler.js +337 -0
package/src/lib/did-manager.js
CHANGED
|
@@ -635,3 +635,344 @@ export function _resetStateDidManagerV2() {
|
|
|
635
635
|
_identityIdleMsV2 = DID_DEFAULT_IDENTITY_IDLE_MS;
|
|
636
636
|
_issuanceStuckMsV2 = DID_DEFAULT_ISSUANCE_STUCK_MS;
|
|
637
637
|
}
|
|
638
|
+
|
|
639
|
+
// =====================================================================
|
|
640
|
+
// did-manager V2 governance overlay (iter19)
|
|
641
|
+
// =====================================================================
|
|
642
|
+
export const DIDGOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
643
|
+
PENDING: "pending",
|
|
644
|
+
ACTIVE: "active",
|
|
645
|
+
SUSPENDED: "suspended",
|
|
646
|
+
ARCHIVED: "archived",
|
|
647
|
+
});
|
|
648
|
+
export const DIDGOV_RESOLUTION_LIFECYCLE_V2 = Object.freeze({
|
|
649
|
+
QUEUED: "queued",
|
|
650
|
+
RESOLVING: "resolving",
|
|
651
|
+
RESOLVED: "resolved",
|
|
652
|
+
FAILED: "failed",
|
|
653
|
+
CANCELLED: "cancelled",
|
|
654
|
+
});
|
|
655
|
+
const _didgovPTrans = new Map([
|
|
656
|
+
[
|
|
657
|
+
DIDGOV_PROFILE_MATURITY_V2.PENDING,
|
|
658
|
+
new Set([
|
|
659
|
+
DIDGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
660
|
+
DIDGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
661
|
+
]),
|
|
662
|
+
],
|
|
663
|
+
[
|
|
664
|
+
DIDGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
665
|
+
new Set([
|
|
666
|
+
DIDGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
667
|
+
DIDGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
668
|
+
]),
|
|
669
|
+
],
|
|
670
|
+
[
|
|
671
|
+
DIDGOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
672
|
+
new Set([
|
|
673
|
+
DIDGOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
674
|
+
DIDGOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
675
|
+
]),
|
|
676
|
+
],
|
|
677
|
+
[DIDGOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
678
|
+
]);
|
|
679
|
+
const _didgovPTerminal = new Set([DIDGOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
680
|
+
const _didgovJTrans = new Map([
|
|
681
|
+
[
|
|
682
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.QUEUED,
|
|
683
|
+
new Set([
|
|
684
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVING,
|
|
685
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.CANCELLED,
|
|
686
|
+
]),
|
|
687
|
+
],
|
|
688
|
+
[
|
|
689
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVING,
|
|
690
|
+
new Set([
|
|
691
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVED,
|
|
692
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.FAILED,
|
|
693
|
+
DIDGOV_RESOLUTION_LIFECYCLE_V2.CANCELLED,
|
|
694
|
+
]),
|
|
695
|
+
],
|
|
696
|
+
[DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVED, new Set()],
|
|
697
|
+
[DIDGOV_RESOLUTION_LIFECYCLE_V2.FAILED, new Set()],
|
|
698
|
+
[DIDGOV_RESOLUTION_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
699
|
+
]);
|
|
700
|
+
const _didgovPsV2 = new Map();
|
|
701
|
+
const _didgovJsV2 = new Map();
|
|
702
|
+
let _didgovMaxActive = 10,
|
|
703
|
+
_didgovMaxPending = 25,
|
|
704
|
+
_didgovIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
705
|
+
_didgovStuckMs = 60 * 1000;
|
|
706
|
+
function _didgovPos(n, label) {
|
|
707
|
+
const v = Math.floor(Number(n));
|
|
708
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
709
|
+
throw new Error(`${label} must be positive integer`);
|
|
710
|
+
return v;
|
|
711
|
+
}
|
|
712
|
+
function _didgovCheckP(from, to) {
|
|
713
|
+
const a = _didgovPTrans.get(from);
|
|
714
|
+
if (!a || !a.has(to))
|
|
715
|
+
throw new Error(`invalid didgov profile transition ${from} → ${to}`);
|
|
716
|
+
}
|
|
717
|
+
function _didgovCheckJ(from, to) {
|
|
718
|
+
const a = _didgovJTrans.get(from);
|
|
719
|
+
if (!a || !a.has(to))
|
|
720
|
+
throw new Error(`invalid didgov resolution transition ${from} → ${to}`);
|
|
721
|
+
}
|
|
722
|
+
function _didgovCountActive(owner) {
|
|
723
|
+
let c = 0;
|
|
724
|
+
for (const p of _didgovPsV2.values())
|
|
725
|
+
if (p.owner === owner && p.status === DIDGOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
726
|
+
c++;
|
|
727
|
+
return c;
|
|
728
|
+
}
|
|
729
|
+
function _didgovCountPending(profileId) {
|
|
730
|
+
let c = 0;
|
|
731
|
+
for (const j of _didgovJsV2.values())
|
|
732
|
+
if (
|
|
733
|
+
j.profileId === profileId &&
|
|
734
|
+
(j.status === DIDGOV_RESOLUTION_LIFECYCLE_V2.QUEUED ||
|
|
735
|
+
j.status === DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVING)
|
|
736
|
+
)
|
|
737
|
+
c++;
|
|
738
|
+
return c;
|
|
739
|
+
}
|
|
740
|
+
export function setMaxActiveDidgovProfilesPerOwnerV2(n) {
|
|
741
|
+
_didgovMaxActive = _didgovPos(n, "maxActiveDidgovProfilesPerOwner");
|
|
742
|
+
}
|
|
743
|
+
export function getMaxActiveDidgovProfilesPerOwnerV2() {
|
|
744
|
+
return _didgovMaxActive;
|
|
745
|
+
}
|
|
746
|
+
export function setMaxPendingDidgovResolutionsPerProfileV2(n) {
|
|
747
|
+
_didgovMaxPending = _didgovPos(n, "maxPendingDidgovResolutionsPerProfile");
|
|
748
|
+
}
|
|
749
|
+
export function getMaxPendingDidgovResolutionsPerProfileV2() {
|
|
750
|
+
return _didgovMaxPending;
|
|
751
|
+
}
|
|
752
|
+
export function setDidgovProfileIdleMsV2(n) {
|
|
753
|
+
_didgovIdleMs = _didgovPos(n, "didgovProfileIdleMs");
|
|
754
|
+
}
|
|
755
|
+
export function getDidgovProfileIdleMsV2() {
|
|
756
|
+
return _didgovIdleMs;
|
|
757
|
+
}
|
|
758
|
+
export function setDidgovResolutionStuckMsV2(n) {
|
|
759
|
+
_didgovStuckMs = _didgovPos(n, "didgovResolutionStuckMs");
|
|
760
|
+
}
|
|
761
|
+
export function getDidgovResolutionStuckMsV2() {
|
|
762
|
+
return _didgovStuckMs;
|
|
763
|
+
}
|
|
764
|
+
export function _resetStateDidManagerGovV2() {
|
|
765
|
+
_didgovPsV2.clear();
|
|
766
|
+
_didgovJsV2.clear();
|
|
767
|
+
_didgovMaxActive = 10;
|
|
768
|
+
_didgovMaxPending = 25;
|
|
769
|
+
_didgovIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
770
|
+
_didgovStuckMs = 60 * 1000;
|
|
771
|
+
}
|
|
772
|
+
export function registerDidgovProfileV2({ id, owner, method, metadata } = {}) {
|
|
773
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
774
|
+
if (_didgovPsV2.has(id))
|
|
775
|
+
throw new Error(`didgov profile ${id} already exists`);
|
|
776
|
+
const now = Date.now();
|
|
777
|
+
const p = {
|
|
778
|
+
id,
|
|
779
|
+
owner,
|
|
780
|
+
method: method || "key",
|
|
781
|
+
status: DIDGOV_PROFILE_MATURITY_V2.PENDING,
|
|
782
|
+
createdAt: now,
|
|
783
|
+
updatedAt: now,
|
|
784
|
+
lastTouchedAt: now,
|
|
785
|
+
activatedAt: null,
|
|
786
|
+
archivedAt: null,
|
|
787
|
+
metadata: { ...(metadata || {}) },
|
|
788
|
+
};
|
|
789
|
+
_didgovPsV2.set(id, p);
|
|
790
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
791
|
+
}
|
|
792
|
+
export function activateDidgovProfileV2(id) {
|
|
793
|
+
const p = _didgovPsV2.get(id);
|
|
794
|
+
if (!p) throw new Error(`didgov profile ${id} not found`);
|
|
795
|
+
const isInitial = p.status === DIDGOV_PROFILE_MATURITY_V2.PENDING;
|
|
796
|
+
_didgovCheckP(p.status, DIDGOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
797
|
+
if (isInitial && _didgovCountActive(p.owner) >= _didgovMaxActive)
|
|
798
|
+
throw new Error(`max active didgov profiles for owner ${p.owner} reached`);
|
|
799
|
+
const now = Date.now();
|
|
800
|
+
p.status = DIDGOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
801
|
+
p.updatedAt = now;
|
|
802
|
+
p.lastTouchedAt = now;
|
|
803
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
804
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
805
|
+
}
|
|
806
|
+
export function suspendDidgovProfileV2(id) {
|
|
807
|
+
const p = _didgovPsV2.get(id);
|
|
808
|
+
if (!p) throw new Error(`didgov profile ${id} not found`);
|
|
809
|
+
_didgovCheckP(p.status, DIDGOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
810
|
+
p.status = DIDGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
811
|
+
p.updatedAt = Date.now();
|
|
812
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
813
|
+
}
|
|
814
|
+
export function archiveDidgovProfileV2(id) {
|
|
815
|
+
const p = _didgovPsV2.get(id);
|
|
816
|
+
if (!p) throw new Error(`didgov profile ${id} not found`);
|
|
817
|
+
_didgovCheckP(p.status, DIDGOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
818
|
+
const now = Date.now();
|
|
819
|
+
p.status = DIDGOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
820
|
+
p.updatedAt = now;
|
|
821
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
822
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
823
|
+
}
|
|
824
|
+
export function touchDidgovProfileV2(id) {
|
|
825
|
+
const p = _didgovPsV2.get(id);
|
|
826
|
+
if (!p) throw new Error(`didgov profile ${id} not found`);
|
|
827
|
+
if (_didgovPTerminal.has(p.status))
|
|
828
|
+
throw new Error(`cannot touch terminal didgov profile ${id}`);
|
|
829
|
+
const now = Date.now();
|
|
830
|
+
p.lastTouchedAt = now;
|
|
831
|
+
p.updatedAt = now;
|
|
832
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
833
|
+
}
|
|
834
|
+
export function getDidgovProfileV2(id) {
|
|
835
|
+
const p = _didgovPsV2.get(id);
|
|
836
|
+
if (!p) return null;
|
|
837
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
838
|
+
}
|
|
839
|
+
export function listDidgovProfilesV2() {
|
|
840
|
+
return [..._didgovPsV2.values()].map((p) => ({
|
|
841
|
+
...p,
|
|
842
|
+
metadata: { ...p.metadata },
|
|
843
|
+
}));
|
|
844
|
+
}
|
|
845
|
+
export function createDidgovResolutionV2({
|
|
846
|
+
id,
|
|
847
|
+
profileId,
|
|
848
|
+
identifier,
|
|
849
|
+
metadata,
|
|
850
|
+
} = {}) {
|
|
851
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
852
|
+
if (_didgovJsV2.has(id))
|
|
853
|
+
throw new Error(`didgov resolution ${id} already exists`);
|
|
854
|
+
if (!_didgovPsV2.has(profileId))
|
|
855
|
+
throw new Error(`didgov profile ${profileId} not found`);
|
|
856
|
+
if (_didgovCountPending(profileId) >= _didgovMaxPending)
|
|
857
|
+
throw new Error(
|
|
858
|
+
`max pending didgov resolutions for profile ${profileId} reached`,
|
|
859
|
+
);
|
|
860
|
+
const now = Date.now();
|
|
861
|
+
const j = {
|
|
862
|
+
id,
|
|
863
|
+
profileId,
|
|
864
|
+
identifier: identifier || "",
|
|
865
|
+
status: DIDGOV_RESOLUTION_LIFECYCLE_V2.QUEUED,
|
|
866
|
+
createdAt: now,
|
|
867
|
+
updatedAt: now,
|
|
868
|
+
startedAt: null,
|
|
869
|
+
settledAt: null,
|
|
870
|
+
metadata: { ...(metadata || {}) },
|
|
871
|
+
};
|
|
872
|
+
_didgovJsV2.set(id, j);
|
|
873
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
874
|
+
}
|
|
875
|
+
export function resolvingDidgovResolutionV2(id) {
|
|
876
|
+
const j = _didgovJsV2.get(id);
|
|
877
|
+
if (!j) throw new Error(`didgov resolution ${id} not found`);
|
|
878
|
+
_didgovCheckJ(j.status, DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVING);
|
|
879
|
+
const now = Date.now();
|
|
880
|
+
j.status = DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVING;
|
|
881
|
+
j.updatedAt = now;
|
|
882
|
+
if (!j.startedAt) j.startedAt = now;
|
|
883
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
884
|
+
}
|
|
885
|
+
export function completeResolutionDidgovV2(id) {
|
|
886
|
+
const j = _didgovJsV2.get(id);
|
|
887
|
+
if (!j) throw new Error(`didgov resolution ${id} not found`);
|
|
888
|
+
_didgovCheckJ(j.status, DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVED);
|
|
889
|
+
const now = Date.now();
|
|
890
|
+
j.status = DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVED;
|
|
891
|
+
j.updatedAt = now;
|
|
892
|
+
if (!j.settledAt) j.settledAt = now;
|
|
893
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
894
|
+
}
|
|
895
|
+
export function failDidgovResolutionV2(id, reason) {
|
|
896
|
+
const j = _didgovJsV2.get(id);
|
|
897
|
+
if (!j) throw new Error(`didgov resolution ${id} not found`);
|
|
898
|
+
_didgovCheckJ(j.status, DIDGOV_RESOLUTION_LIFECYCLE_V2.FAILED);
|
|
899
|
+
const now = Date.now();
|
|
900
|
+
j.status = DIDGOV_RESOLUTION_LIFECYCLE_V2.FAILED;
|
|
901
|
+
j.updatedAt = now;
|
|
902
|
+
if (!j.settledAt) j.settledAt = now;
|
|
903
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
904
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
905
|
+
}
|
|
906
|
+
export function cancelDidgovResolutionV2(id, reason) {
|
|
907
|
+
const j = _didgovJsV2.get(id);
|
|
908
|
+
if (!j) throw new Error(`didgov resolution ${id} not found`);
|
|
909
|
+
_didgovCheckJ(j.status, DIDGOV_RESOLUTION_LIFECYCLE_V2.CANCELLED);
|
|
910
|
+
const now = Date.now();
|
|
911
|
+
j.status = DIDGOV_RESOLUTION_LIFECYCLE_V2.CANCELLED;
|
|
912
|
+
j.updatedAt = now;
|
|
913
|
+
if (!j.settledAt) j.settledAt = now;
|
|
914
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
915
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
916
|
+
}
|
|
917
|
+
export function getDidgovResolutionV2(id) {
|
|
918
|
+
const j = _didgovJsV2.get(id);
|
|
919
|
+
if (!j) return null;
|
|
920
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
921
|
+
}
|
|
922
|
+
export function listDidgovResolutionsV2() {
|
|
923
|
+
return [..._didgovJsV2.values()].map((j) => ({
|
|
924
|
+
...j,
|
|
925
|
+
metadata: { ...j.metadata },
|
|
926
|
+
}));
|
|
927
|
+
}
|
|
928
|
+
export function autoSuspendIdleDidgovProfilesV2({ now } = {}) {
|
|
929
|
+
const t = now ?? Date.now();
|
|
930
|
+
const flipped = [];
|
|
931
|
+
for (const p of _didgovPsV2.values())
|
|
932
|
+
if (
|
|
933
|
+
p.status === DIDGOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
934
|
+
t - p.lastTouchedAt >= _didgovIdleMs
|
|
935
|
+
) {
|
|
936
|
+
p.status = DIDGOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
937
|
+
p.updatedAt = t;
|
|
938
|
+
flipped.push(p.id);
|
|
939
|
+
}
|
|
940
|
+
return { flipped, count: flipped.length };
|
|
941
|
+
}
|
|
942
|
+
export function autoFailStuckDidgovResolutionsV2({ now } = {}) {
|
|
943
|
+
const t = now ?? Date.now();
|
|
944
|
+
const flipped = [];
|
|
945
|
+
for (const j of _didgovJsV2.values())
|
|
946
|
+
if (
|
|
947
|
+
j.status === DIDGOV_RESOLUTION_LIFECYCLE_V2.RESOLVING &&
|
|
948
|
+
j.startedAt != null &&
|
|
949
|
+
t - j.startedAt >= _didgovStuckMs
|
|
950
|
+
) {
|
|
951
|
+
j.status = DIDGOV_RESOLUTION_LIFECYCLE_V2.FAILED;
|
|
952
|
+
j.updatedAt = t;
|
|
953
|
+
if (!j.settledAt) j.settledAt = t;
|
|
954
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
955
|
+
flipped.push(j.id);
|
|
956
|
+
}
|
|
957
|
+
return { flipped, count: flipped.length };
|
|
958
|
+
}
|
|
959
|
+
export function getDidManagerGovStatsV2() {
|
|
960
|
+
const profilesByStatus = {};
|
|
961
|
+
for (const v of Object.values(DIDGOV_PROFILE_MATURITY_V2))
|
|
962
|
+
profilesByStatus[v] = 0;
|
|
963
|
+
for (const p of _didgovPsV2.values()) profilesByStatus[p.status]++;
|
|
964
|
+
const resolutionsByStatus = {};
|
|
965
|
+
for (const v of Object.values(DIDGOV_RESOLUTION_LIFECYCLE_V2))
|
|
966
|
+
resolutionsByStatus[v] = 0;
|
|
967
|
+
for (const j of _didgovJsV2.values()) resolutionsByStatus[j.status]++;
|
|
968
|
+
return {
|
|
969
|
+
totalDidgovProfilesV2: _didgovPsV2.size,
|
|
970
|
+
totalDidgovResolutionsV2: _didgovJsV2.size,
|
|
971
|
+
maxActiveDidgovProfilesPerOwner: _didgovMaxActive,
|
|
972
|
+
maxPendingDidgovResolutionsPerProfile: _didgovMaxPending,
|
|
973
|
+
didgovProfileIdleMs: _didgovIdleMs,
|
|
974
|
+
didgovResolutionStuckMs: _didgovStuckMs,
|
|
975
|
+
profilesByStatus,
|
|
976
|
+
resolutionsByStatus,
|
|
977
|
+
};
|
|
978
|
+
}
|
|
@@ -1125,3 +1125,344 @@ export function getConfig() {
|
|
|
1125
1125
|
vpDefaultTTLMs: VP_DEFAULT_TTL_MS,
|
|
1126
1126
|
};
|
|
1127
1127
|
}
|
|
1128
|
+
|
|
1129
|
+
// =====================================================================
|
|
1130
|
+
// did-v2-manager V2 governance overlay (iter22)
|
|
1131
|
+
// =====================================================================
|
|
1132
|
+
export const DV2GOV_PROFILE_MATURITY_V2 = Object.freeze({
|
|
1133
|
+
PENDING: "pending",
|
|
1134
|
+
ACTIVE: "active",
|
|
1135
|
+
SUSPENDED: "suspended",
|
|
1136
|
+
ARCHIVED: "archived",
|
|
1137
|
+
});
|
|
1138
|
+
export const DV2GOV_CREDENTIAL_LIFECYCLE_V2 = Object.freeze({
|
|
1139
|
+
QUEUED: "queued",
|
|
1140
|
+
ISSUING: "issuing",
|
|
1141
|
+
ISSUED: "issued",
|
|
1142
|
+
FAILED: "failed",
|
|
1143
|
+
CANCELLED: "cancelled",
|
|
1144
|
+
});
|
|
1145
|
+
const _dv2govPTrans = new Map([
|
|
1146
|
+
[
|
|
1147
|
+
DV2GOV_PROFILE_MATURITY_V2.PENDING,
|
|
1148
|
+
new Set([
|
|
1149
|
+
DV2GOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1150
|
+
DV2GOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1151
|
+
]),
|
|
1152
|
+
],
|
|
1153
|
+
[
|
|
1154
|
+
DV2GOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1155
|
+
new Set([
|
|
1156
|
+
DV2GOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1157
|
+
DV2GOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1158
|
+
]),
|
|
1159
|
+
],
|
|
1160
|
+
[
|
|
1161
|
+
DV2GOV_PROFILE_MATURITY_V2.SUSPENDED,
|
|
1162
|
+
new Set([
|
|
1163
|
+
DV2GOV_PROFILE_MATURITY_V2.ACTIVE,
|
|
1164
|
+
DV2GOV_PROFILE_MATURITY_V2.ARCHIVED,
|
|
1165
|
+
]),
|
|
1166
|
+
],
|
|
1167
|
+
[DV2GOV_PROFILE_MATURITY_V2.ARCHIVED, new Set()],
|
|
1168
|
+
]);
|
|
1169
|
+
const _dv2govPTerminal = new Set([DV2GOV_PROFILE_MATURITY_V2.ARCHIVED]);
|
|
1170
|
+
const _dv2govJTrans = new Map([
|
|
1171
|
+
[
|
|
1172
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.QUEUED,
|
|
1173
|
+
new Set([
|
|
1174
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUING,
|
|
1175
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.CANCELLED,
|
|
1176
|
+
]),
|
|
1177
|
+
],
|
|
1178
|
+
[
|
|
1179
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUING,
|
|
1180
|
+
new Set([
|
|
1181
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUED,
|
|
1182
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.FAILED,
|
|
1183
|
+
DV2GOV_CREDENTIAL_LIFECYCLE_V2.CANCELLED,
|
|
1184
|
+
]),
|
|
1185
|
+
],
|
|
1186
|
+
[DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUED, new Set()],
|
|
1187
|
+
[DV2GOV_CREDENTIAL_LIFECYCLE_V2.FAILED, new Set()],
|
|
1188
|
+
[DV2GOV_CREDENTIAL_LIFECYCLE_V2.CANCELLED, new Set()],
|
|
1189
|
+
]);
|
|
1190
|
+
const _dv2govPsV2 = new Map();
|
|
1191
|
+
const _dv2govJsV2 = new Map();
|
|
1192
|
+
let _dv2govMaxActive = 8,
|
|
1193
|
+
_dv2govMaxPending = 20,
|
|
1194
|
+
_dv2govIdleMs = 30 * 24 * 60 * 60 * 1000,
|
|
1195
|
+
_dv2govStuckMs = 60 * 1000;
|
|
1196
|
+
function _dv2govPos(n, label) {
|
|
1197
|
+
const v = Math.floor(Number(n));
|
|
1198
|
+
if (!Number.isFinite(v) || v <= 0)
|
|
1199
|
+
throw new Error(`${label} must be positive integer`);
|
|
1200
|
+
return v;
|
|
1201
|
+
}
|
|
1202
|
+
function _dv2govCheckP(from, to) {
|
|
1203
|
+
const a = _dv2govPTrans.get(from);
|
|
1204
|
+
if (!a || !a.has(to))
|
|
1205
|
+
throw new Error(`invalid dv2gov profile transition ${from} → ${to}`);
|
|
1206
|
+
}
|
|
1207
|
+
function _dv2govCheckJ(from, to) {
|
|
1208
|
+
const a = _dv2govJTrans.get(from);
|
|
1209
|
+
if (!a || !a.has(to))
|
|
1210
|
+
throw new Error(`invalid dv2gov credential transition ${from} → ${to}`);
|
|
1211
|
+
}
|
|
1212
|
+
function _dv2govCountActive(owner) {
|
|
1213
|
+
let c = 0;
|
|
1214
|
+
for (const p of _dv2govPsV2.values())
|
|
1215
|
+
if (p.owner === owner && p.status === DV2GOV_PROFILE_MATURITY_V2.ACTIVE)
|
|
1216
|
+
c++;
|
|
1217
|
+
return c;
|
|
1218
|
+
}
|
|
1219
|
+
function _dv2govCountPending(profileId) {
|
|
1220
|
+
let c = 0;
|
|
1221
|
+
for (const j of _dv2govJsV2.values())
|
|
1222
|
+
if (
|
|
1223
|
+
j.profileId === profileId &&
|
|
1224
|
+
(j.status === DV2GOV_CREDENTIAL_LIFECYCLE_V2.QUEUED ||
|
|
1225
|
+
j.status === DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUING)
|
|
1226
|
+
)
|
|
1227
|
+
c++;
|
|
1228
|
+
return c;
|
|
1229
|
+
}
|
|
1230
|
+
export function setMaxActiveDv2govProfilesPerOwnerV2(n) {
|
|
1231
|
+
_dv2govMaxActive = _dv2govPos(n, "maxActiveDv2govProfilesPerOwner");
|
|
1232
|
+
}
|
|
1233
|
+
export function getMaxActiveDv2govProfilesPerOwnerV2() {
|
|
1234
|
+
return _dv2govMaxActive;
|
|
1235
|
+
}
|
|
1236
|
+
export function setMaxPendingDv2govCredentialsPerProfileV2(n) {
|
|
1237
|
+
_dv2govMaxPending = _dv2govPos(n, "maxPendingDv2govCredentialsPerProfile");
|
|
1238
|
+
}
|
|
1239
|
+
export function getMaxPendingDv2govCredentialsPerProfileV2() {
|
|
1240
|
+
return _dv2govMaxPending;
|
|
1241
|
+
}
|
|
1242
|
+
export function setDv2govProfileIdleMsV2(n) {
|
|
1243
|
+
_dv2govIdleMs = _dv2govPos(n, "dv2govProfileIdleMs");
|
|
1244
|
+
}
|
|
1245
|
+
export function getDv2govProfileIdleMsV2() {
|
|
1246
|
+
return _dv2govIdleMs;
|
|
1247
|
+
}
|
|
1248
|
+
export function setDv2govCredentialStuckMsV2(n) {
|
|
1249
|
+
_dv2govStuckMs = _dv2govPos(n, "dv2govCredentialStuckMs");
|
|
1250
|
+
}
|
|
1251
|
+
export function getDv2govCredentialStuckMsV2() {
|
|
1252
|
+
return _dv2govStuckMs;
|
|
1253
|
+
}
|
|
1254
|
+
export function _resetStateDidV2ManagerGovV2() {
|
|
1255
|
+
_dv2govPsV2.clear();
|
|
1256
|
+
_dv2govJsV2.clear();
|
|
1257
|
+
_dv2govMaxActive = 8;
|
|
1258
|
+
_dv2govMaxPending = 20;
|
|
1259
|
+
_dv2govIdleMs = 30 * 24 * 60 * 60 * 1000;
|
|
1260
|
+
_dv2govStuckMs = 60 * 1000;
|
|
1261
|
+
}
|
|
1262
|
+
export function registerDv2govProfileV2({ id, owner, method, metadata } = {}) {
|
|
1263
|
+
if (!id || !owner) throw new Error("id and owner required");
|
|
1264
|
+
if (_dv2govPsV2.has(id))
|
|
1265
|
+
throw new Error(`dv2gov profile ${id} already exists`);
|
|
1266
|
+
const now = Date.now();
|
|
1267
|
+
const p = {
|
|
1268
|
+
id,
|
|
1269
|
+
owner,
|
|
1270
|
+
method: method || "web",
|
|
1271
|
+
status: DV2GOV_PROFILE_MATURITY_V2.PENDING,
|
|
1272
|
+
createdAt: now,
|
|
1273
|
+
updatedAt: now,
|
|
1274
|
+
lastTouchedAt: now,
|
|
1275
|
+
activatedAt: null,
|
|
1276
|
+
archivedAt: null,
|
|
1277
|
+
metadata: { ...(metadata || {}) },
|
|
1278
|
+
};
|
|
1279
|
+
_dv2govPsV2.set(id, p);
|
|
1280
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1281
|
+
}
|
|
1282
|
+
export function activateDv2govProfileV2(id) {
|
|
1283
|
+
const p = _dv2govPsV2.get(id);
|
|
1284
|
+
if (!p) throw new Error(`dv2gov profile ${id} not found`);
|
|
1285
|
+
const isInitial = p.status === DV2GOV_PROFILE_MATURITY_V2.PENDING;
|
|
1286
|
+
_dv2govCheckP(p.status, DV2GOV_PROFILE_MATURITY_V2.ACTIVE);
|
|
1287
|
+
if (isInitial && _dv2govCountActive(p.owner) >= _dv2govMaxActive)
|
|
1288
|
+
throw new Error(`max active dv2gov profiles for owner ${p.owner} reached`);
|
|
1289
|
+
const now = Date.now();
|
|
1290
|
+
p.status = DV2GOV_PROFILE_MATURITY_V2.ACTIVE;
|
|
1291
|
+
p.updatedAt = now;
|
|
1292
|
+
p.lastTouchedAt = now;
|
|
1293
|
+
if (!p.activatedAt) p.activatedAt = now;
|
|
1294
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1295
|
+
}
|
|
1296
|
+
export function suspendDv2govProfileV2(id) {
|
|
1297
|
+
const p = _dv2govPsV2.get(id);
|
|
1298
|
+
if (!p) throw new Error(`dv2gov profile ${id} not found`);
|
|
1299
|
+
_dv2govCheckP(p.status, DV2GOV_PROFILE_MATURITY_V2.SUSPENDED);
|
|
1300
|
+
p.status = DV2GOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1301
|
+
p.updatedAt = Date.now();
|
|
1302
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1303
|
+
}
|
|
1304
|
+
export function archiveDv2govProfileV2(id) {
|
|
1305
|
+
const p = _dv2govPsV2.get(id);
|
|
1306
|
+
if (!p) throw new Error(`dv2gov profile ${id} not found`);
|
|
1307
|
+
_dv2govCheckP(p.status, DV2GOV_PROFILE_MATURITY_V2.ARCHIVED);
|
|
1308
|
+
const now = Date.now();
|
|
1309
|
+
p.status = DV2GOV_PROFILE_MATURITY_V2.ARCHIVED;
|
|
1310
|
+
p.updatedAt = now;
|
|
1311
|
+
if (!p.archivedAt) p.archivedAt = now;
|
|
1312
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1313
|
+
}
|
|
1314
|
+
export function touchDv2govProfileV2(id) {
|
|
1315
|
+
const p = _dv2govPsV2.get(id);
|
|
1316
|
+
if (!p) throw new Error(`dv2gov profile ${id} not found`);
|
|
1317
|
+
if (_dv2govPTerminal.has(p.status))
|
|
1318
|
+
throw new Error(`cannot touch terminal dv2gov profile ${id}`);
|
|
1319
|
+
const now = Date.now();
|
|
1320
|
+
p.lastTouchedAt = now;
|
|
1321
|
+
p.updatedAt = now;
|
|
1322
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1323
|
+
}
|
|
1324
|
+
export function getDv2govProfileV2(id) {
|
|
1325
|
+
const p = _dv2govPsV2.get(id);
|
|
1326
|
+
if (!p) return null;
|
|
1327
|
+
return { ...p, metadata: { ...p.metadata } };
|
|
1328
|
+
}
|
|
1329
|
+
export function listDv2govProfilesV2() {
|
|
1330
|
+
return [..._dv2govPsV2.values()].map((p) => ({
|
|
1331
|
+
...p,
|
|
1332
|
+
metadata: { ...p.metadata },
|
|
1333
|
+
}));
|
|
1334
|
+
}
|
|
1335
|
+
export function createDv2govCredentialV2({
|
|
1336
|
+
id,
|
|
1337
|
+
profileId,
|
|
1338
|
+
subject,
|
|
1339
|
+
metadata,
|
|
1340
|
+
} = {}) {
|
|
1341
|
+
if (!id || !profileId) throw new Error("id and profileId required");
|
|
1342
|
+
if (_dv2govJsV2.has(id))
|
|
1343
|
+
throw new Error(`dv2gov credential ${id} already exists`);
|
|
1344
|
+
if (!_dv2govPsV2.has(profileId))
|
|
1345
|
+
throw new Error(`dv2gov profile ${profileId} not found`);
|
|
1346
|
+
if (_dv2govCountPending(profileId) >= _dv2govMaxPending)
|
|
1347
|
+
throw new Error(
|
|
1348
|
+
`max pending dv2gov credentials for profile ${profileId} reached`,
|
|
1349
|
+
);
|
|
1350
|
+
const now = Date.now();
|
|
1351
|
+
const j = {
|
|
1352
|
+
id,
|
|
1353
|
+
profileId,
|
|
1354
|
+
subject: subject || "",
|
|
1355
|
+
status: DV2GOV_CREDENTIAL_LIFECYCLE_V2.QUEUED,
|
|
1356
|
+
createdAt: now,
|
|
1357
|
+
updatedAt: now,
|
|
1358
|
+
startedAt: null,
|
|
1359
|
+
settledAt: null,
|
|
1360
|
+
metadata: { ...(metadata || {}) },
|
|
1361
|
+
};
|
|
1362
|
+
_dv2govJsV2.set(id, j);
|
|
1363
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1364
|
+
}
|
|
1365
|
+
export function issuingDv2govCredentialV2(id) {
|
|
1366
|
+
const j = _dv2govJsV2.get(id);
|
|
1367
|
+
if (!j) throw new Error(`dv2gov credential ${id} not found`);
|
|
1368
|
+
_dv2govCheckJ(j.status, DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUING);
|
|
1369
|
+
const now = Date.now();
|
|
1370
|
+
j.status = DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUING;
|
|
1371
|
+
j.updatedAt = now;
|
|
1372
|
+
if (!j.startedAt) j.startedAt = now;
|
|
1373
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1374
|
+
}
|
|
1375
|
+
export function completeCredentialDv2govV2(id) {
|
|
1376
|
+
const j = _dv2govJsV2.get(id);
|
|
1377
|
+
if (!j) throw new Error(`dv2gov credential ${id} not found`);
|
|
1378
|
+
_dv2govCheckJ(j.status, DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUED);
|
|
1379
|
+
const now = Date.now();
|
|
1380
|
+
j.status = DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUED;
|
|
1381
|
+
j.updatedAt = now;
|
|
1382
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1383
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1384
|
+
}
|
|
1385
|
+
export function failDv2govCredentialV2(id, reason) {
|
|
1386
|
+
const j = _dv2govJsV2.get(id);
|
|
1387
|
+
if (!j) throw new Error(`dv2gov credential ${id} not found`);
|
|
1388
|
+
_dv2govCheckJ(j.status, DV2GOV_CREDENTIAL_LIFECYCLE_V2.FAILED);
|
|
1389
|
+
const now = Date.now();
|
|
1390
|
+
j.status = DV2GOV_CREDENTIAL_LIFECYCLE_V2.FAILED;
|
|
1391
|
+
j.updatedAt = now;
|
|
1392
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1393
|
+
if (reason) j.metadata.failReason = String(reason);
|
|
1394
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1395
|
+
}
|
|
1396
|
+
export function cancelDv2govCredentialV2(id, reason) {
|
|
1397
|
+
const j = _dv2govJsV2.get(id);
|
|
1398
|
+
if (!j) throw new Error(`dv2gov credential ${id} not found`);
|
|
1399
|
+
_dv2govCheckJ(j.status, DV2GOV_CREDENTIAL_LIFECYCLE_V2.CANCELLED);
|
|
1400
|
+
const now = Date.now();
|
|
1401
|
+
j.status = DV2GOV_CREDENTIAL_LIFECYCLE_V2.CANCELLED;
|
|
1402
|
+
j.updatedAt = now;
|
|
1403
|
+
if (!j.settledAt) j.settledAt = now;
|
|
1404
|
+
if (reason) j.metadata.cancelReason = String(reason);
|
|
1405
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1406
|
+
}
|
|
1407
|
+
export function getDv2govCredentialV2(id) {
|
|
1408
|
+
const j = _dv2govJsV2.get(id);
|
|
1409
|
+
if (!j) return null;
|
|
1410
|
+
return { ...j, metadata: { ...j.metadata } };
|
|
1411
|
+
}
|
|
1412
|
+
export function listDv2govCredentialsV2() {
|
|
1413
|
+
return [..._dv2govJsV2.values()].map((j) => ({
|
|
1414
|
+
...j,
|
|
1415
|
+
metadata: { ...j.metadata },
|
|
1416
|
+
}));
|
|
1417
|
+
}
|
|
1418
|
+
export function autoSuspendIdleDv2govProfilesV2({ now } = {}) {
|
|
1419
|
+
const t = now ?? Date.now();
|
|
1420
|
+
const flipped = [];
|
|
1421
|
+
for (const p of _dv2govPsV2.values())
|
|
1422
|
+
if (
|
|
1423
|
+
p.status === DV2GOV_PROFILE_MATURITY_V2.ACTIVE &&
|
|
1424
|
+
t - p.lastTouchedAt >= _dv2govIdleMs
|
|
1425
|
+
) {
|
|
1426
|
+
p.status = DV2GOV_PROFILE_MATURITY_V2.SUSPENDED;
|
|
1427
|
+
p.updatedAt = t;
|
|
1428
|
+
flipped.push(p.id);
|
|
1429
|
+
}
|
|
1430
|
+
return { flipped, count: flipped.length };
|
|
1431
|
+
}
|
|
1432
|
+
export function autoFailStuckDv2govCredentialsV2({ now } = {}) {
|
|
1433
|
+
const t = now ?? Date.now();
|
|
1434
|
+
const flipped = [];
|
|
1435
|
+
for (const j of _dv2govJsV2.values())
|
|
1436
|
+
if (
|
|
1437
|
+
j.status === DV2GOV_CREDENTIAL_LIFECYCLE_V2.ISSUING &&
|
|
1438
|
+
j.startedAt != null &&
|
|
1439
|
+
t - j.startedAt >= _dv2govStuckMs
|
|
1440
|
+
) {
|
|
1441
|
+
j.status = DV2GOV_CREDENTIAL_LIFECYCLE_V2.FAILED;
|
|
1442
|
+
j.updatedAt = t;
|
|
1443
|
+
if (!j.settledAt) j.settledAt = t;
|
|
1444
|
+
j.metadata.failReason = "auto-fail-stuck";
|
|
1445
|
+
flipped.push(j.id);
|
|
1446
|
+
}
|
|
1447
|
+
return { flipped, count: flipped.length };
|
|
1448
|
+
}
|
|
1449
|
+
export function getDidV2ManagerGovStatsV2() {
|
|
1450
|
+
const profilesByStatus = {};
|
|
1451
|
+
for (const v of Object.values(DV2GOV_PROFILE_MATURITY_V2))
|
|
1452
|
+
profilesByStatus[v] = 0;
|
|
1453
|
+
for (const p of _dv2govPsV2.values()) profilesByStatus[p.status]++;
|
|
1454
|
+
const credentialsByStatus = {};
|
|
1455
|
+
for (const v of Object.values(DV2GOV_CREDENTIAL_LIFECYCLE_V2))
|
|
1456
|
+
credentialsByStatus[v] = 0;
|
|
1457
|
+
for (const j of _dv2govJsV2.values()) credentialsByStatus[j.status]++;
|
|
1458
|
+
return {
|
|
1459
|
+
totalDv2govProfilesV2: _dv2govPsV2.size,
|
|
1460
|
+
totalDv2govCredentialsV2: _dv2govJsV2.size,
|
|
1461
|
+
maxActiveDv2govProfilesPerOwner: _dv2govMaxActive,
|
|
1462
|
+
maxPendingDv2govCredentialsPerProfile: _dv2govMaxPending,
|
|
1463
|
+
dv2govProfileIdleMs: _dv2govIdleMs,
|
|
1464
|
+
dv2govCredentialStuckMs: _dv2govStuckMs,
|
|
1465
|
+
profilesByStatus,
|
|
1466
|
+
credentialsByStatus,
|
|
1467
|
+
};
|
|
1468
|
+
}
|