@openplanr/protocol 0.2.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/LICENSE +21 -0
- package/README.md +82 -0
- package/lib/dashboard/closed-json-contract.mjs +141 -0
- package/lib/dashboard/generated/operate-experience-surface-schema-data.mjs +67 -0
- package/lib/dashboard/generated/operate-review-schema-data.mjs +35 -0
- package/lib/dashboard/generated/operate-schema-token-codec.mjs +127 -0
- package/lib/dashboard/operate-experience-audit-display-contract.d.mts +196 -0
- package/lib/dashboard/operate-experience-audit-display-contract.mjs +700 -0
- package/lib/dashboard/operate-experience-display-contract.d.mts +572 -0
- package/lib/dashboard/operate-experience-display-contract.mjs +1007 -0
- package/lib/dashboard/operate-experience-surface-contract.d.mts +157 -0
- package/lib/dashboard/operate-experience-surface-contract.mjs +91 -0
- package/lib/dashboard/operate-review-contract.d.mts +34 -0
- package/lib/dashboard/operate-review-contract.mjs +175 -0
- package/lib/dashboard/operate-review-display-workspace-contract.d.mts +54 -0
- package/lib/dashboard/operate-review-display-workspace-contract.mjs +258 -0
- package/lib/dashboard/operate-review-payload-safety.d.mts +7 -0
- package/lib/dashboard/operate-review-payload-safety.mjs +42 -0
- package/lib/dashboard/operate-review-workspace-projection-v2.d.mts +218 -0
- package/lib/protocol/index.d.ts +2638 -0
- package/package.json +115 -0
- package/registries/commands.json +1952 -0
- package/registries/diagram-grammars.json +2407 -0
- package/registries/diagram-semantic-patterns.json +111 -0
- package/registries/output-paths.json +40 -0
- package/registries/outputs.json +864 -0
- package/registries/roles.json +661 -0
- package/registries/rules.json +261 -0
- package/registries/skill-host-profiles.json +247 -0
- package/registries/skill-modules.json +1112 -0
- package/registries/skill-routing.json +389 -0
- package/registries/skills.json +1545 -0
- package/registries/task-kinds.json +220 -0
- package/registry/adapters.json +110 -0
- package/registry/artifact-theme.json +60 -0
- package/registry/evaluation-graders.json +303 -0
- package/registry/evaluation-host-profiles.json +131 -0
- package/registry/frozen-commands.json +15 -0
- package/registry/landing-operations.json +20 -0
- package/registry/landing-workflows.json +70 -0
- package/registry/live-evidence-providers.json +1 -0
- package/registry/operate-v2-contracts.json +5965 -0
- package/registry/professional-skills.json +115 -0
- package/registry/roles.json +14 -0
- package/registry/ship-review-specialists.json +42 -0
- package/schemas/v1.0.0/design-approved.schema.json +35 -0
- package/schemas/v1.0.0/design-feedback.schema.json +169 -0
- package/schemas/v1.0.0/design-manifest.schema.json +90 -0
- package/schemas/v1.0.0/design-session.schema.json +73 -0
- package/schemas/v1.0.0/graph.schema.json +100 -0
- package/schemas/v1.0.0/pipeline-shipped.schema.json +154 -0
- package/schemas/v1.0.0/run-manifest.schema.json +81 -0
- package/schemas/v1.0.0/spec.schema.json +120 -0
- package/schemas/v1.0.0/stack.schema.json +184 -0
- package/schemas/v1.0.0/story.schema.json +95 -0
- package/schemas/v1.0.0/task.schema.json +171 -0
- package/schemas/v1.0.0/taste-profile.schema.json +96 -0
- package/schemas/v1.1.0/adapter-registry.schema.json +72 -0
- package/schemas/v1.1.0/artifact-envelope.schema.json +142 -0
- package/schemas/v1.1.0/artifact-paste.schema.json +49 -0
- package/schemas/v1.1.0/artifact-review.schema.json +97 -0
- package/schemas/v1.1.0/artifact-room-descriptor.schema.json +39 -0
- package/schemas/v1.1.0/artifact-room-event.schema.json +184 -0
- package/schemas/v1.1.0/artifact-room-signed-event.schema.json +58 -0
- package/schemas/v1.1.0/artifact-theme.schema.json +139 -0
- package/schemas/v1.1.0/browser-qa-gate.schema.json +21 -0
- package/schemas/v1.1.0/browser-qa-result.schema.json +24 -0
- package/schemas/v1.1.0/browser-qa-session.schema.json +12 -0
- package/schemas/v1.1.0/ecosystem-manifest.schema.json +46 -0
- package/schemas/v1.1.0/investigation-diagnosis.schema.json +12 -0
- package/schemas/v1.1.0/investigation-event.schema.json +15 -0
- package/schemas/v1.1.0/investigation-experiment.schema.json +17 -0
- package/schemas/v1.1.0/investigation-fix.schema.json +11 -0
- package/schemas/v1.1.0/investigation-hypothesis.schema.json +6 -0
- package/schemas/v1.1.0/investigation-observation.schema.json +10 -0
- package/schemas/v1.1.0/investigation-receipt.schema.json +7 -0
- package/schemas/v1.1.0/investigation-record.schema.json +7 -0
- package/schemas/v1.1.0/investigation-request.schema.json +34 -0
- package/schemas/v1.1.0/planning-review-event.schema.json +64 -0
- package/schemas/v1.1.0/planning-review-receipt.schema.json +19 -0
- package/schemas/v1.1.0/planning-review-record.schema.json +176 -0
- package/schemas/v1.1.0/planning-review-state.schema.json +19 -0
- package/schemas/v1.1.0/professional-skills.schema.json +105 -0
- package/schemas/v1.1.0/professional-specification.schema.json +111 -0
- package/schemas/v1.1.0/provenance-event.schema.json +82 -0
- package/schemas/v1.1.0/role-registry.schema.json +28 -0
- package/schemas/v1.1.0/runtime-lock.schema.json +39 -0
- package/schemas/v1.1.0/ship-closure.schema.json +353 -0
- package/schemas/v1.1.0/ship-review-specialist-registry.schema.json +29 -0
- package/schemas/v1.1.0/ship-risk-classification.schema.json +48 -0
- package/schemas/v1.1.0/specialist-review-result.schema.json +19 -0
- package/schemas/v1.10.0/design-review-bundle.schema.json +584 -0
- package/schemas/v1.10.0/design-review-context.schema.json +191 -0
- package/schemas/v1.10.0/design-review-handoff.schema.json +407 -0
- package/schemas/v1.10.0/design-review-metadata-payload.schema.json +106 -0
- package/schemas/v1.11.0/design-review-metadata-payload.schema.json +107 -0
- package/schemas/v1.12.0/enterprise-access-context.schema.json +217 -0
- package/schemas/v1.12.0/enterprise-agent-handoff.schema.json +508 -0
- package/schemas/v1.12.0/enterprise-artifact-revision.schema.json +87 -0
- package/schemas/v1.12.0/enterprise-change-proposal.schema.json +359 -0
- package/schemas/v1.12.0/enterprise-evidence-reference.schema.json +147 -0
- package/schemas/v1.12.0/enterprise-review-thread.schema.json +278 -0
- package/schemas/v1.12.0/enterprise-sync-state.schema.json +169 -0
- package/schemas/v1.2.0/adapter-registry.schema.json +83 -0
- package/schemas/v1.2.0/dashboard-bootstrap.schema.json +219 -0
- package/schemas/v1.2.0/ecosystem-release-operation.schema.json +90 -0
- package/schemas/v1.2.0/ecosystem-saga.schema.json +54 -0
- package/schemas/v1.2.0/evidence-diagnostic.schema.json +77 -0
- package/schemas/v1.2.0/guided-answer-envelope.schema.json +73 -0
- package/schemas/v1.2.0/guided-confirmation.schema.json +128 -0
- package/schemas/v1.2.0/guided-question.schema.json +242 -0
- package/schemas/v1.2.0/guided-questionnaire.schema.json +278 -0
- package/schemas/v1.2.0/guided-session.schema.json +141 -0
- package/schemas/v1.2.0/landing-confirmation.schema.json +17 -0
- package/schemas/v1.2.0/landing-event.schema.json +12 -0
- package/schemas/v1.2.0/landing-operation-registry.schema.json +16 -0
- package/schemas/v1.2.0/landing-phase-receipt.schema.json +19 -0
- package/schemas/v1.2.0/landing-plan.schema.json +36 -0
- package/schemas/v1.2.0/landing-receipt.schema.json +12 -0
- package/schemas/v1.2.0/landing-workflow-catalog.schema.json +143 -0
- package/schemas/v1.2.0/operate-action-display-workspace.schema.json +119 -0
- package/schemas/v1.2.0/operate-cycle-display-workspace.schema.json +109 -0
- package/schemas/v1.2.0/operate-executive-board-display-surface.schema.json +72 -0
- package/schemas/v1.2.0/operate-experience-audit-display-surface.schema.json +328 -0
- package/schemas/v1.2.0/operate-experience-display-surface.schema.json +46 -0
- package/schemas/v1.2.0/operate-experience-surface.schema.json +590 -0
- package/schemas/v1.2.0/operate-recovery-display-surface.schema.json +85 -0
- package/schemas/v1.2.0/structured-action.schema.json +91 -0
- package/schemas/v1.3.0/adapter-registry.schema.json +84 -0
- package/schemas/v1.3.0/ecosystem-manifest.schema.json +120 -0
- package/schemas/v1.3.0/release-compatibility-claim.schema.json +46 -0
- package/schemas/v1.3.0/release-ledger-receipt.schema.json +45 -0
- package/schemas/v1.3.0/release-ledger.schema.json +60 -0
- package/schemas/v1.4.0/adapter-registry.schema.json +62 -0
- package/schemas/v1.4.0/evaluation-aggregate-report.schema.json +166 -0
- package/schemas/v1.4.0/evaluation-budget.schema.json +49 -0
- package/schemas/v1.4.0/evaluation-corpus.schema.json +93 -0
- package/schemas/v1.4.0/evaluation-fixture.schema.json +64 -0
- package/schemas/v1.4.0/evaluation-gate-policy.schema.json +33 -0
- package/schemas/v1.4.0/evaluation-grader-registration.schema.json +141 -0
- package/schemas/v1.4.0/evaluation-grader-registry.schema.json +20 -0
- package/schemas/v1.4.0/evaluation-host-profile-registry.schema.json +20 -0
- package/schemas/v1.4.0/evaluation-host-profile.schema.json +73 -0
- package/schemas/v1.4.0/evaluation-observation.schema.json +76 -0
- package/schemas/v1.4.0/evaluation-run-result.schema.json +84 -0
- package/schemas/v1.4.0/evaluation-scenario.schema.json +231 -0
- package/schemas/v1.4.0/evaluation-waiver.schema.json +65 -0
- package/schemas/v1.4.0/skill-certification-receipt.schema.json +103 -0
- package/schemas/v1.5.0/command-catalog.schema.json +296 -0
- package/schemas/v1.5.0/common.schema.json +261 -0
- package/schemas/v1.5.0/generated-asset-manifest.schema.json +313 -0
- package/schemas/v1.5.0/implementation-result.schema.json +152 -0
- package/schemas/v1.5.0/migration-preservation-manifest.schema.json +749 -0
- package/schemas/v1.5.0/output-catalog.schema.json +210 -0
- package/schemas/v1.5.0/output-path-catalog.schema.json +81 -0
- package/schemas/v1.5.0/role-registry.schema.json +261 -0
- package/schemas/v1.5.0/rule-catalog.schema.json +130 -0
- package/schemas/v1.5.0/skill-catalog.schema.json +303 -0
- package/schemas/v1.5.0/task-kind-registry.schema.json +167 -0
- package/schemas/v1.5.0/task-manifest.schema.json +373 -0
- package/schemas/v1.5.0/task-output-manifest.schema.json +462 -0
- package/schemas/v1.6.0/common.schema.json +462 -0
- package/schemas/v1.6.0/diagram-consumer-reference.schema.json +167 -0
- package/schemas/v1.6.0/diagram-document.schema.json +699 -0
- package/schemas/v1.6.0/diagram-fidelity-report.schema.json +137 -0
- package/schemas/v1.6.0/diagram-manifest.schema.json +162 -0
- package/schemas/v1.6.0/diagram-quality-report.schema.json +148 -0
- package/schemas/v1.6.0/diagram-review-binding.schema.json +132 -0
- package/schemas/v1.6.0/diagram-semantic-pattern-registry.schema.json +90 -0
- package/schemas/v1.6.0/diagram-type-registry.schema.json +373 -0
- package/schemas/v1.6.0/generated-asset-manifest.schema.json +103 -0
- package/schemas/v1.6.0/skill-catalog.schema.json +84 -0
- package/schemas/v1.6.0/skill-completion-receipt.schema.json +72 -0
- package/schemas/v1.6.0/skill-consent-record.schema.json +74 -0
- package/schemas/v1.6.0/skill-host-profile-registry.schema.json +526 -0
- package/schemas/v1.6.0/skill-learning-record.schema.json +116 -0
- package/schemas/v1.6.0/skill-module-registry.schema.json +108 -0
- package/schemas/v1.6.0/skill-routing-registry.schema.json +93 -0
- package/schemas/v1.6.0/skill-session.schema.json +73 -0
- package/schemas/v1.6.0/skill-source.schema.json +169 -0
- package/schemas/v1.7.0/common.schema.json +464 -0
- package/schemas/v1.7.0/generated-asset-manifest.schema.json +103 -0
- package/schemas/v1.7.0/planning-id-sequence.schema.json +50 -0
- package/schemas/v1.7.0/request-authority.schema.json +71 -0
- package/schemas/v1.7.0/skill-catalog.schema.json +84 -0
- package/schemas/v1.7.0/skill-completion-receipt.schema.json +72 -0
- package/schemas/v1.7.0/skill-consent-record.schema.json +74 -0
- package/schemas/v1.7.0/skill-host-profile-registry.schema.json +526 -0
- package/schemas/v1.7.0/skill-learning-record.schema.json +116 -0
- package/schemas/v1.7.0/skill-module-registry.schema.json +108 -0
- package/schemas/v1.7.0/skill-routing-registry.schema.json +93 -0
- package/schemas/v1.7.0/skill-session.schema.json +73 -0
- package/schemas/v1.7.0/skill-source.schema.json +169 -0
- package/schemas/v1.7.0/spec.schema.json +117 -0
- package/schemas/v1.7.0/story.schema.json +107 -0
- package/schemas/v1.7.0/task.schema.json +217 -0
- package/schemas/v1.8.0/common.schema.json +96 -0
- package/schemas/v1.8.0/skill-package.schema.json +63 -0
- package/schemas/v1.8.0/utility-command-catalog.schema.json +82 -0
- package/schemas/v1.9.0/design-document.schema.json +306 -0
- package/schemas/v1.9.0/design-review-bundle.schema.json +346 -0
- package/schemas/v1.9.0/design-review-workspace.schema.json +108 -0
- package/schemas/v1.9.0/design-workspace-create.schema.json +170 -0
- package/schemas/v1.9.0/design-workspace-event.schema.json +97 -0
- package/schemas/v1.9.0/design-workspace-revision.schema.json +56 -0
- package/schemas/v2.0.0/agent-runtime-manifest.schema.json +59 -0
- package/schemas/v2.0.0/business-operating-snapshot-projection.schema.json +14 -0
- package/schemas/v2.0.0/operate-allowed-action.schema.json +181 -0
- package/schemas/v2.0.0/operate-api-envelope.schema.json +225 -0
- package/schemas/v2.0.0/operate-capability-provider-registration.schema.json +30 -0
- package/schemas/v2.0.0/operate-domain-registration.schema.json +284 -0
- package/schemas/v2.0.0/operate-evidence-provider-registration.schema.json +55 -0
- package/schemas/v2.0.0/operate-evidence-resolver-registration.schema.json +46 -0
- package/schemas/v2.0.0/operate-executor-registration.schema.json +27 -0
- package/schemas/v2.0.0/operate-experience-live-patch.schema.json +47 -0
- package/schemas/v2.0.0/operate-experience-preview.schema.json +51 -0
- package/schemas/v2.0.0/operate-experience-view.schema.json +281 -0
- package/schemas/v2.0.0/operate-live-evidence-provider-registration.schema.json +48 -0
- package/schemas/v2.0.0/operate-live-evidence-provider-registry.schema.json +17 -0
- package/schemas/v2.0.0/operate-metric-provider-registration.schema.json +12 -0
- package/schemas/v2.0.0/operate-policy-provider-registration.schema.json +33 -0
- package/schemas/v2.0.0/operate-review-bound-submission.schema.json +29 -0
- package/schemas/v2.0.0/operate-review-display-workspace.schema.json +390 -0
- package/schemas/v2.0.0/operate-snapshot-provider-registration.schema.json +16 -0
- package/schemas/v2.0.0/operate-tool-call.schema.json +172 -0
- package/schemas/v2.0.0/operate-verification-provider-registration.schema.json +12 -0
- package/schemas/v2.0.0/operating-action-policy.schema.json +31 -0
- package/schemas/v2.0.0/operating-action-verification-plan.schema.json +13 -0
- package/schemas/v2.0.0/operating-action.schema.json +86 -0
- package/schemas/v2.0.0/operating-advisor-result.schema.json +394 -0
- package/schemas/v2.0.0/operating-approval-record.schema.json +23 -0
- package/schemas/v2.0.0/operating-approval-requirement.schema.json +31 -0
- package/schemas/v2.0.0/operating-artifact.schema.json +52 -0
- package/schemas/v2.0.0/operating-assignment.schema.json +437 -0
- package/schemas/v2.0.0/operating-assumption.schema.json +16 -0
- package/schemas/v2.0.0/operating-capability-availability.schema.json +15 -0
- package/schemas/v2.0.0/operating-capability-grant.schema.json +14 -0
- package/schemas/v2.0.0/operating-challenger-review.schema.json +204 -0
- package/schemas/v2.0.0/operating-checkpoint.schema.json +43 -0
- package/schemas/v2.0.0/operating-claim.schema.json +17 -0
- package/schemas/v2.0.0/operating-connector-checkpoint.schema.json +28 -0
- package/schemas/v2.0.0/operating-context-capture.schema.json +74 -0
- package/schemas/v2.0.0/operating-cycle-input-binding.schema.json +30 -0
- package/schemas/v2.0.0/operating-cycle.schema.json +42 -0
- package/schemas/v2.0.0/operating-decision-ledger.schema.json +237 -0
- package/schemas/v2.0.0/operating-decision.schema.json +137 -0
- package/schemas/v2.0.0/operating-delivery-evidence.schema.json +46 -0
- package/schemas/v2.0.0/operating-delivery-route.schema.json +43 -0
- package/schemas/v2.0.0/operating-delta.schema.json +13 -0
- package/schemas/v2.0.0/operating-domain-projection.schema.json +15 -0
- package/schemas/v2.0.0/operating-event-trigger.schema.json +11 -0
- package/schemas/v2.0.0/operating-event.schema.json +505 -0
- package/schemas/v2.0.0/operating-evidence-candidate.schema.json +88 -0
- package/schemas/v2.0.0/operating-evidence-edge.schema.json +39 -0
- package/schemas/v2.0.0/operating-evidence-graph.schema.json +25 -0
- package/schemas/v2.0.0/operating-evidence-observation.schema.json +48 -0
- package/schemas/v2.0.0/operating-evidence-ref.schema.json +51 -0
- package/schemas/v2.0.0/operating-evidence-resolution.schema.json +54 -0
- package/schemas/v2.0.0/operating-execution-result.schema.json +23 -0
- package/schemas/v2.0.0/operating-executive-board.schema.json +78 -0
- package/schemas/v2.0.0/operating-finding.schema.json +116 -0
- package/schemas/v2.0.0/operating-governed-operation.schema.json +54 -0
- package/schemas/v2.0.0/operating-intelligence-input-bundle.schema.json +128 -0
- package/schemas/v2.0.0/operating-intelligence-plan.schema.json +302 -0
- package/schemas/v2.0.0/operating-learning-receipt.schema.json +31 -0
- package/schemas/v2.0.0/operating-learning.schema.json +13 -0
- package/schemas/v2.0.0/operating-live-evidence-consent-record.schema.json +42 -0
- package/schemas/v2.0.0/operating-live-evidence-ingestion.schema.json +31 -0
- package/schemas/v2.0.0/operating-measurement-plan.schema.json +18 -0
- package/schemas/v2.0.0/operating-measurement-schedule-receipt.schema.json +7 -0
- package/schemas/v2.0.0/operating-measurement-schedule.schema.json +16 -0
- package/schemas/v2.0.0/operating-metric-observation.schema.json +15 -0
- package/schemas/v2.0.0/operating-metric.schema.json +18 -0
- package/schemas/v2.0.0/operating-model-state.schema.json +36 -0
- package/schemas/v2.0.0/operating-objective.schema.json +21 -0
- package/schemas/v2.0.0/operating-origin.schema.json +31 -0
- package/schemas/v2.0.0/operating-outcome-evaluation.schema.json +46 -0
- package/schemas/v2.0.0/operating-outcome.schema.json +13 -0
- package/schemas/v2.0.0/operating-planning-proposal.schema.json +45 -0
- package/schemas/v2.0.0/operating-policy-evaluation.schema.json +28 -0
- package/schemas/v2.0.0/operating-review-read.schema.json +217 -0
- package/schemas/v2.0.0/operating-review-receipt.schema.json +64 -0
- package/schemas/v2.0.0/operating-review.schema.json +47 -0
- package/schemas/v2.0.0/operating-risk.schema.json +96 -0
- package/schemas/v2.0.0/operating-rollback-plan.schema.json +10 -0
- package/schemas/v2.0.0/operating-rollback-result.schema.json +20 -0
- package/schemas/v2.0.0/operating-runtime-state.schema.json +289 -0
- package/schemas/v2.0.0/operating-scenario.schema.json +13 -0
- package/schemas/v2.0.0/operating-snapshot.schema.json +38 -0
- package/schemas/v2.0.0/operating-submission.schema.json +34 -0
- package/schemas/v2.0.0/operating-trace-matrix.schema.json +176 -0
- package/schemas/v2.0.0/operating-work-change-set.schema.json +89 -0
- package/schemas/v2.0.0/operating-work-ledger.schema.json +40 -0
- package/schemas/v2.0.0/software-operating-snapshot-projection.schema.json +14 -0
- package/src/browser-contracts.d.mts +5 -0
- package/src/browser-contracts.mjs +40 -0
- package/src/canonical-json.d.mts +5 -0
- package/src/canonical-json.mjs +142 -0
- package/src/compat/live-evidence-v2.mjs +1019 -0
- package/src/compat/operate-experience-live-patch.mjs +66 -0
- package/src/compat/operating-planning-contracts.mjs +114 -0
- package/src/contracts.d.mts +42 -0
- package/src/contracts.mjs +990 -0
- package/src/design-contracts.d.mts +62 -0
- package/src/design-contracts.mjs +186 -0
- package/src/design-publication-contracts.d.mts +4 -0
- package/src/design-publication-contracts.mjs +85 -0
- package/src/diagram-contracts.d.mts +19 -0
- package/src/diagram-contracts.mjs +28 -0
- package/src/enterprise-contracts.d.mts +107 -0
- package/src/enterprise-contracts.mjs +463 -0
- package/src/errors.d.mts +11 -0
- package/src/errors.mjs +109 -0
- package/src/generated/canonical-registries.mjs +5554 -0
- package/src/generated/contract-catalog-v2.mjs +7076 -0
- package/src/generated/diagram-registries.mjs +2529 -0
- package/src/index.d.mts +10 -0
- package/src/index.mjs +40 -0
- package/src/json-schema.d.mts +7 -0
- package/src/json-schema.mjs +283 -0
- package/src/planning-contracts.d.mts +10 -0
- package/src/planning-contracts.mjs +53 -0
- package/src/registries.d.mts +40 -0
- package/src/registries.mjs +261 -0
- package/src/review-experience-contracts.d.mts +11 -0
- package/src/review-experience-contracts.mjs +103 -0
- package/src/semver.d.mts +2 -0
- package/src/semver.mjs +7 -0
- package/src/skill-source-contracts.d.mts +25 -0
- package/src/skill-source-contracts.mjs +105 -0
- package/src/task-contracts.d.mts +7 -0
- package/src/task-contracts.mjs +130 -0
- package/src/workspace-contracts.d.mts +26 -0
- package/src/workspace-contracts.mjs +83 -0
|
@@ -0,0 +1,700 @@
|
|
|
1
|
+
import { validateJson } from '../../src/json-schema.mjs';
|
|
2
|
+
import {
|
|
3
|
+
contentHash,
|
|
4
|
+
deepFreeze,
|
|
5
|
+
exactEventHead,
|
|
6
|
+
exactJson,
|
|
7
|
+
hasOwn,
|
|
8
|
+
safeDataClone,
|
|
9
|
+
withoutContentHash,
|
|
10
|
+
} from "./closed-json-contract.mjs";
|
|
11
|
+
import {
|
|
12
|
+
OPERATE_EXPERIENCE_AUDIT_DISPLAY_SURFACE_SCHEMA as auditDisplaySchema,
|
|
13
|
+
OPERATE_REVIEW_DISPLAY_WORKSPACE_SCHEMA as reviewWorkspaceSchema,
|
|
14
|
+
OPERATE_EXPERIENCE_VIEW_SCHEMA as experienceViewSchema,
|
|
15
|
+
OPERATE_EXPERIENCE_SURFACE_SCHEMA as surfaceSchema,
|
|
16
|
+
OPERATING_TRACE_MATRIX_SCHEMA as traceMatrixSchema,
|
|
17
|
+
} from "./generated/operate-experience-surface-schema-data.mjs";
|
|
18
|
+
import { assertOperateExperienceSurfaceV1 } from "./operate-experience-surface-contract.mjs";
|
|
19
|
+
|
|
20
|
+
const AUDIT_DISPLAY_DOMAIN =
|
|
21
|
+
"openplanr:operate-experience-audit-display-surface:1.0.0";
|
|
22
|
+
const AUDIT_SURFACES = new Set([
|
|
23
|
+
"evidence",
|
|
24
|
+
"outcomes",
|
|
25
|
+
"outcome",
|
|
26
|
+
"history",
|
|
27
|
+
"search",
|
|
28
|
+
"export",
|
|
29
|
+
]);
|
|
30
|
+
const schemas = new Map([
|
|
31
|
+
["operate-experience-audit-display-surface.schema.json", auditDisplaySchema],
|
|
32
|
+
["operate-experience-surface.schema.json", surfaceSchema],
|
|
33
|
+
["operate-experience-view.schema.json", experienceViewSchema],
|
|
34
|
+
["operate-review-display-workspace.schema.json", reviewWorkspaceSchema],
|
|
35
|
+
["operating-trace-matrix.schema.json", traceMatrixSchema],
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
function jsonPointer(root, fragment) {
|
|
39
|
+
if (!fragment || fragment === "#") return root;
|
|
40
|
+
if (!fragment.startsWith("#/")) return null;
|
|
41
|
+
return fragment
|
|
42
|
+
.slice(2)
|
|
43
|
+
.split("/")
|
|
44
|
+
.map((part) => part.replaceAll("~1", "/").replaceAll("~0", "~"))
|
|
45
|
+
.reduce((value, part) => value?.[part], root);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveSchemaRef(reference) {
|
|
49
|
+
const [path, pointer = ""] = reference.split("#");
|
|
50
|
+
const filename = path.split("/").at(-1);
|
|
51
|
+
const rootSchema = schemas.get(filename);
|
|
52
|
+
if (!rootSchema) return null;
|
|
53
|
+
return {
|
|
54
|
+
schema: jsonPointer(rootSchema, pointer ? `#${pointer}` : "#"),
|
|
55
|
+
rootSchema,
|
|
56
|
+
base: filename,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function validationFailure() {
|
|
61
|
+
return [
|
|
62
|
+
{
|
|
63
|
+
path: "$",
|
|
64
|
+
rule: "closedContract",
|
|
65
|
+
detail: "does not satisfy the closed audit display contract",
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function validCanonicalSubjectSegment(segment) {
|
|
71
|
+
try {
|
|
72
|
+
const decoded = decodeURIComponent(segment);
|
|
73
|
+
return (
|
|
74
|
+
decoded.length > 0 &&
|
|
75
|
+
decoded !== "." &&
|
|
76
|
+
decoded !== ".." &&
|
|
77
|
+
!decoded.includes("/") &&
|
|
78
|
+
!decoded.includes("\\") &&
|
|
79
|
+
encodeURIComponent(decoded) === segment
|
|
80
|
+
);
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function validOwnedLink(value) {
|
|
87
|
+
if (value === null) return true;
|
|
88
|
+
return ownedLinkDestination(value) !== null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function exactOwnedLink(value, surface, subjectId) {
|
|
92
|
+
if (value === null) return true;
|
|
93
|
+
if (typeof subjectId !== "string") return false;
|
|
94
|
+
if (surface === "action") {
|
|
95
|
+
return value === `#/operate/actions/${encodeURIComponent(subjectId)}`;
|
|
96
|
+
}
|
|
97
|
+
if (surface === "cycle") {
|
|
98
|
+
return value === `#/operate/cycles/${encodeURIComponent(subjectId)}`;
|
|
99
|
+
}
|
|
100
|
+
const route = surface === "evidence" ? "evidence" : "outcomes";
|
|
101
|
+
return value === `#/operate/${route}/${encodeURIComponent(subjectId)}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function ownedLinkDestination(value) {
|
|
105
|
+
if (typeof value !== "string") return null;
|
|
106
|
+
const match = /^#\/operate\/(evidence|outcomes)\/([^/?#]+)$/u.exec(value);
|
|
107
|
+
if (match !== null && validCanonicalSubjectSegment(match[2])) {
|
|
108
|
+
return {
|
|
109
|
+
surface: match[1] === "evidence" ? "evidence" : "outcome",
|
|
110
|
+
subjectId: decodeURIComponent(match[2]),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const actionMatch = /^#\/operate\/actions\/([^/?#]+)$/u.exec(value);
|
|
114
|
+
if (actionMatch !== null && validCanonicalSubjectSegment(actionMatch[1])) {
|
|
115
|
+
return {
|
|
116
|
+
surface: "action",
|
|
117
|
+
subjectId: decodeURIComponent(actionMatch[1]),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const cycleMatch = /^#\/operate\/cycles\/([^/?#]+)$/u.exec(value);
|
|
121
|
+
if (cycleMatch !== null && validCanonicalSubjectSegment(cycleMatch[1])) {
|
|
122
|
+
return {
|
|
123
|
+
surface: "cycle",
|
|
124
|
+
subjectId: decodeURIComponent(cycleMatch[1]),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function validLinkProjection(value, seen = new Set()) {
|
|
131
|
+
if (value === null || typeof value !== "object") return true;
|
|
132
|
+
if (seen.has(value)) return false;
|
|
133
|
+
seen.add(value);
|
|
134
|
+
try {
|
|
135
|
+
if (Array.isArray(value))
|
|
136
|
+
return value.every((entry) => validLinkProjection(entry, seen));
|
|
137
|
+
for (const [key, child] of Object.entries(value)) {
|
|
138
|
+
if (key === "deepLink") {
|
|
139
|
+
if (!validOwnedLink(child)) return false;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (key === "deepLinks") {
|
|
143
|
+
if (!Array.isArray(child) || !child.every(validOwnedLink)) return false;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (!validLinkProjection(child, seen)) return false;
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
} finally {
|
|
150
|
+
seen.delete(value);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function restoreLegacyLinks(value, seen = new Set()) {
|
|
155
|
+
if (value === null || typeof value !== "object" || seen.has(value)) return;
|
|
156
|
+
seen.add(value);
|
|
157
|
+
if (Array.isArray(value)) {
|
|
158
|
+
for (const entry of value) restoreLegacyLinks(entry, seen);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
for (const [key, child] of Object.entries(value)) {
|
|
162
|
+
if (key === "deepLink" && child === null) {
|
|
163
|
+
value[key] = "#/operate/history/redacted";
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
restoreLegacyLinks(child, seen);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function legacyCompatibleSearchData(data) {
|
|
171
|
+
return {
|
|
172
|
+
...data,
|
|
173
|
+
results: data.results.map((entry) => {
|
|
174
|
+
if (
|
|
175
|
+
!["evidence", "claim", "outcome"].includes(entry.kind) &&
|
|
176
|
+
hasOwn(entry, "deepLink")
|
|
177
|
+
) {
|
|
178
|
+
const { deepLink: _deepLink, ...rest } = entry;
|
|
179
|
+
return rest;
|
|
180
|
+
}
|
|
181
|
+
return entry;
|
|
182
|
+
}),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function validLegacyPayload(payload) {
|
|
187
|
+
try {
|
|
188
|
+
const legacy = safeDataClone(payload);
|
|
189
|
+
legacy.mutationEnabled = legacy.status === "ready";
|
|
190
|
+
if (legacy.surface === "search") {
|
|
191
|
+
legacy.data = legacyCompatibleSearchData(legacy.data);
|
|
192
|
+
}
|
|
193
|
+
restoreLegacyLinks(legacy.data);
|
|
194
|
+
assertOperateExperienceSurfaceV1(legacy);
|
|
195
|
+
return true;
|
|
196
|
+
} catch {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function uniqueRows(records, field) {
|
|
202
|
+
const ids = records.map((entry) => entry[field]);
|
|
203
|
+
return (
|
|
204
|
+
ids.every((id) => typeof id === "string") &&
|
|
205
|
+
new Set(ids).size === ids.length
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function restrictedEvidenceIsClosed(entry) {
|
|
210
|
+
if (entry.accessState === "available") return entry.accessReason === null;
|
|
211
|
+
return (
|
|
212
|
+
entry.accessState === "restricted" &&
|
|
213
|
+
entry.claimStatus === "restricted" &&
|
|
214
|
+
entry.evidenceKind === null &&
|
|
215
|
+
entry.resolvedAt === null &&
|
|
216
|
+
entry.source === null &&
|
|
217
|
+
entry.producer === null &&
|
|
218
|
+
entry.observedAt === null &&
|
|
219
|
+
entry.provenance === null &&
|
|
220
|
+
entry.confidence === null &&
|
|
221
|
+
entry.accessReason === "access-denied" &&
|
|
222
|
+
entry.supportClaimIds.length === 0 &&
|
|
223
|
+
entry.contradictClaimIds.length === 0 &&
|
|
224
|
+
entry.gaps.length === 0 &&
|
|
225
|
+
entry.errors.length === 0 &&
|
|
226
|
+
entry.causalLinks.length === 0
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function restrictedClaimIsClosed(entry) {
|
|
231
|
+
if (entry.accessReason === null) return entry.statement !== null;
|
|
232
|
+
return (
|
|
233
|
+
entry.status === "restricted" &&
|
|
234
|
+
entry.accessReason === "access-denied" &&
|
|
235
|
+
entry.statement === null &&
|
|
236
|
+
entry.source === null &&
|
|
237
|
+
entry.producer === null &&
|
|
238
|
+
entry.provenance === null &&
|
|
239
|
+
entry.confidence === null &&
|
|
240
|
+
entry.supportEvidenceRefIds.length === 0 &&
|
|
241
|
+
entry.contradictEvidenceRefIds.length === 0 &&
|
|
242
|
+
entry.gaps.length === 0 &&
|
|
243
|
+
entry.errors.length === 0 &&
|
|
244
|
+
entry.causalLinks.length === 0
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function validCausalLink(link) {
|
|
249
|
+
return link.kind === "outcome"
|
|
250
|
+
? exactOwnedLink(link.deepLink, "outcome", link.subjectId)
|
|
251
|
+
: link.deepLink === null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function validEvidenceData(data) {
|
|
255
|
+
const evidence = new Map(
|
|
256
|
+
data.evidence.map((entry) => [entry.evidenceRefId, entry]),
|
|
257
|
+
);
|
|
258
|
+
const claims = new Map(data.claims.map((entry) => [entry.claimId, entry]));
|
|
259
|
+
if (
|
|
260
|
+
!uniqueRows(data.evidence, "evidenceRefId") ||
|
|
261
|
+
!uniqueRows(data.claims, "claimId") ||
|
|
262
|
+
!data.evidence.every(
|
|
263
|
+
(entry) =>
|
|
264
|
+
restrictedEvidenceIsClosed(entry) &&
|
|
265
|
+
exactOwnedLink(entry.deepLink, "evidence", entry.evidenceRefId) &&
|
|
266
|
+
entry.causalLinks.every(validCausalLink),
|
|
267
|
+
) ||
|
|
268
|
+
!data.claims.every(
|
|
269
|
+
(entry) =>
|
|
270
|
+
restrictedClaimIsClosed(entry) &&
|
|
271
|
+
exactOwnedLink(entry.deepLink, "evidence", entry.claimId) &&
|
|
272
|
+
entry.causalLinks.every(validCausalLink),
|
|
273
|
+
)
|
|
274
|
+
)
|
|
275
|
+
return false;
|
|
276
|
+
for (const entry of data.evidence) {
|
|
277
|
+
if (
|
|
278
|
+
!entry.supportClaimIds.every((id) =>
|
|
279
|
+
claims.get(id)?.supportEvidenceRefIds.includes(entry.evidenceRefId),
|
|
280
|
+
) ||
|
|
281
|
+
!entry.contradictClaimIds.every((id) =>
|
|
282
|
+
claims.get(id)?.contradictEvidenceRefIds.includes(entry.evidenceRefId),
|
|
283
|
+
)
|
|
284
|
+
)
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return data.claims.every(
|
|
288
|
+
(entry) =>
|
|
289
|
+
entry.supportEvidenceRefIds.every((id) =>
|
|
290
|
+
evidence.get(id)?.supportClaimIds.includes(entry.claimId),
|
|
291
|
+
) &&
|
|
292
|
+
entry.contradictEvidenceRefIds.every((id) =>
|
|
293
|
+
evidence.get(id)?.contradictClaimIds.includes(entry.claimId),
|
|
294
|
+
),
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function visibleAffirmativeOutcome(outcome) {
|
|
299
|
+
return (
|
|
300
|
+
outcome.accessReason === null &&
|
|
301
|
+
outcome.observationIds.length > 0 &&
|
|
302
|
+
outcome.evidenceRefIds.length > 0 &&
|
|
303
|
+
outcome.metric.observed !== null &&
|
|
304
|
+
outcome.metric.freshness === "current" &&
|
|
305
|
+
outcome.verification.accessReason === null
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function restrictedOutcome(outcome) {
|
|
310
|
+
return (
|
|
311
|
+
outcome.accessReason === "access-denied" &&
|
|
312
|
+
outcome.observationIds.length === 0 &&
|
|
313
|
+
outcome.evidenceRefIds.length === 0 &&
|
|
314
|
+
outcome.metric.baseline === null &&
|
|
315
|
+
outcome.metric.target === null &&
|
|
316
|
+
outcome.metric.observed === null &&
|
|
317
|
+
outcome.metric.unit === null &&
|
|
318
|
+
outcome.metric.window === null &&
|
|
319
|
+
outcome.metric.confidence === null &&
|
|
320
|
+
outcome.verification.accessReason === "access-denied" &&
|
|
321
|
+
outcome.verification.method === null &&
|
|
322
|
+
outcome.verification.evaluationRules.length === 0 &&
|
|
323
|
+
outcome.verification.observationRequest === null &&
|
|
324
|
+
outcome.nextObservation === null &&
|
|
325
|
+
outcome.revisit === null
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function restrictedAffirmativeOutcome(outcome) {
|
|
330
|
+
return (
|
|
331
|
+
["succeeded", "failed"].includes(outcome.status) &&
|
|
332
|
+
restrictedOutcome(outcome)
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function validOutcomeTuple(outcome) {
|
|
337
|
+
const metric = outcome.metric;
|
|
338
|
+
const verification = outcome.verification;
|
|
339
|
+
if (
|
|
340
|
+
metric === null ||
|
|
341
|
+
verification === null ||
|
|
342
|
+
outcome.verificationPlanId !== verification.verificationPlanId ||
|
|
343
|
+
metric.metricId !== verification.metricId ||
|
|
344
|
+
metric.metricHash !== verification.metricHash ||
|
|
345
|
+
!exactOwnedLink(outcome.deepLink, "outcome", outcome.outcomeId) ||
|
|
346
|
+
(outcome.decision !== null && outcome.decision.deepLink !== null) ||
|
|
347
|
+
!outcome.execution.every((entry) => entry.deepLink === null) ||
|
|
348
|
+
!outcome.rollback.every((entry) => entry.deepLink === null)
|
|
349
|
+
)
|
|
350
|
+
return false;
|
|
351
|
+
if (
|
|
352
|
+
(outcome.accessReason === "access-denied" ||
|
|
353
|
+
verification.accessReason === "access-denied") &&
|
|
354
|
+
!restrictedOutcome(outcome)
|
|
355
|
+
)
|
|
356
|
+
return false;
|
|
357
|
+
if (outcome.status === "insufficient-evidence") {
|
|
358
|
+
return (
|
|
359
|
+
metric.observed === null &&
|
|
360
|
+
outcome.observationIds.length === 0 &&
|
|
361
|
+
outcome.evidenceRefIds.length === 0 &&
|
|
362
|
+
outcome.snapshot === null &&
|
|
363
|
+
outcome.delta === null
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return (
|
|
367
|
+
!["succeeded", "failed"].includes(outcome.status) ||
|
|
368
|
+
visibleAffirmativeOutcome(outcome) ||
|
|
369
|
+
restrictedAffirmativeOutcome(outcome)
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function validOutcomesData(data, detail = false) {
|
|
374
|
+
const outcomes = detail ? [data.outcome] : data.outcomes;
|
|
375
|
+
if (!uniqueRows(outcomes, "outcomeId") || !outcomes.every(validOutcomeTuple))
|
|
376
|
+
return false;
|
|
377
|
+
if (
|
|
378
|
+
!detail &&
|
|
379
|
+
!data.domainMetrics.every((entry) =>
|
|
380
|
+
entry.dueVerification.every((item) => item.deepLink === null),
|
|
381
|
+
)
|
|
382
|
+
)
|
|
383
|
+
return false;
|
|
384
|
+
const outcomeIds = new Set(outcomes.map((entry) => entry.outcomeId));
|
|
385
|
+
return (
|
|
386
|
+
uniqueRows(data.learnings, "learningId") &&
|
|
387
|
+
data.learnings.every((entry) => outcomeIds.has(entry.outcomeId))
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function validHistoryData(data, eventHead) {
|
|
392
|
+
return (
|
|
393
|
+
uniqueRows(data.history, "eventId") &&
|
|
394
|
+
data.history.every((entry) =>
|
|
395
|
+
entry.deepLinks.every((deepLink) => {
|
|
396
|
+
const destination = ownedLinkDestination(deepLink);
|
|
397
|
+
return destination?.surface === "evidence"
|
|
398
|
+
? destination.subjectId === entry.entityId ||
|
|
399
|
+
entry.evidenceRefIds.includes(destination.subjectId)
|
|
400
|
+
: destination?.surface === "outcome" &&
|
|
401
|
+
destination.subjectId === entry.entityId;
|
|
402
|
+
}),
|
|
403
|
+
) &&
|
|
404
|
+
data.replay.liveAccessUsed === false &&
|
|
405
|
+
exactEventHead(data.replay.finalHead, eventHead) &&
|
|
406
|
+
data.replay.parityProof.finalEventHashMatches === true
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function validSearchData(data) {
|
|
411
|
+
return data.results.every((entry) => {
|
|
412
|
+
if (!hasOwn(entry, "deepLink")) return true;
|
|
413
|
+
if (entry.kind === "evidence" || entry.kind === "claim")
|
|
414
|
+
return exactOwnedLink(entry.deepLink, "evidence", entry.subjectId);
|
|
415
|
+
if (entry.kind === "outcome")
|
|
416
|
+
return exactOwnedLink(entry.deepLink, "outcome", entry.subjectId);
|
|
417
|
+
if (entry.kind === "action")
|
|
418
|
+
return exactOwnedLink(entry.deepLink, "action", entry.subjectId);
|
|
419
|
+
if (entry.kind === "cycle")
|
|
420
|
+
return exactOwnedLink(entry.deepLink, "cycle", entry.subjectId);
|
|
421
|
+
if (entry.kind === "assignment") {
|
|
422
|
+
if (entry.deepLink === null) return true;
|
|
423
|
+
const match = /^#\/operate\/cycles\/([^/?#]+)$/u.exec(entry.deepLink);
|
|
424
|
+
return match !== null && validCanonicalSubjectSegment(match[1]);
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const EXPORT_ROOT_KEYS = [
|
|
431
|
+
"kind",
|
|
432
|
+
"schemaVersion",
|
|
433
|
+
"protocolVersion",
|
|
434
|
+
"scopeId",
|
|
435
|
+
"domainId",
|
|
436
|
+
"domainVersion",
|
|
437
|
+
"generatedAt",
|
|
438
|
+
"eventHead",
|
|
439
|
+
"status",
|
|
440
|
+
"attention",
|
|
441
|
+
"domainMetrics",
|
|
442
|
+
"cycles",
|
|
443
|
+
"inbox",
|
|
444
|
+
"actions",
|
|
445
|
+
"evidence",
|
|
446
|
+
"claims",
|
|
447
|
+
"rationale",
|
|
448
|
+
"outcomes",
|
|
449
|
+
"learnings",
|
|
450
|
+
"history",
|
|
451
|
+
"replay",
|
|
452
|
+
"omissions",
|
|
453
|
+
].sort();
|
|
454
|
+
const FORBIDDEN_EXPORT_FIELDS = new Set([
|
|
455
|
+
"ownerActorId",
|
|
456
|
+
"actorId",
|
|
457
|
+
"partyId",
|
|
458
|
+
"requiredCapability",
|
|
459
|
+
"source",
|
|
460
|
+
"producer",
|
|
461
|
+
"provenance",
|
|
462
|
+
"authority",
|
|
463
|
+
"actionLocator",
|
|
464
|
+
"rawHash",
|
|
465
|
+
"canonicalHash",
|
|
466
|
+
]);
|
|
467
|
+
|
|
468
|
+
function validExportTree(value, seen = new Set()) {
|
|
469
|
+
if (value === null || typeof value !== "object") return true;
|
|
470
|
+
if (seen.has(value)) return false;
|
|
471
|
+
seen.add(value);
|
|
472
|
+
try {
|
|
473
|
+
if (Array.isArray(value))
|
|
474
|
+
return value.every((entry) => validExportTree(entry, seen));
|
|
475
|
+
for (const [key, child] of Object.entries(value)) {
|
|
476
|
+
if (FORBIDDEN_EXPORT_FIELDS.has(key)) return false;
|
|
477
|
+
if (key === "errors" && (!Array.isArray(child) || child.length !== 0))
|
|
478
|
+
return false;
|
|
479
|
+
if (!validExportTree(child, seen)) return false;
|
|
480
|
+
}
|
|
481
|
+
return true;
|
|
482
|
+
} finally {
|
|
483
|
+
seen.delete(value);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function escapeHtml(value) {
|
|
488
|
+
return value
|
|
489
|
+
.replaceAll("&", "&")
|
|
490
|
+
.replaceAll("<", "<")
|
|
491
|
+
.replaceAll(">", ">");
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function unescapeHtml(value) {
|
|
495
|
+
return value
|
|
496
|
+
.replaceAll("<", "<")
|
|
497
|
+
.replaceAll(">", ">")
|
|
498
|
+
.replaceAll("&", "&");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function validExportValue(value) {
|
|
502
|
+
return (
|
|
503
|
+
value !== null &&
|
|
504
|
+
typeof value === "object" &&
|
|
505
|
+
!Array.isArray(value) &&
|
|
506
|
+
exactJson(Object.keys(value).sort(), EXPORT_ROOT_KEYS) &&
|
|
507
|
+
validExportTree(value) &&
|
|
508
|
+
validLinkProjection(value)
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function canonicalizeExportValue(value) {
|
|
513
|
+
if (Array.isArray(value))
|
|
514
|
+
return value.map((entry) => canonicalizeExportValue(entry));
|
|
515
|
+
if (value === null || typeof value !== "object") return value;
|
|
516
|
+
return Object.fromEntries(
|
|
517
|
+
Object.keys(value)
|
|
518
|
+
.sort()
|
|
519
|
+
.map((key) => [key, canonicalizeExportValue(value[key])]),
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function validExportData(data) {
|
|
524
|
+
try {
|
|
525
|
+
if (data.format === "json") {
|
|
526
|
+
if (data.mediaType !== "application/json") return false;
|
|
527
|
+
const value = JSON.parse(data.content);
|
|
528
|
+
return (
|
|
529
|
+
validExportValue(value) &&
|
|
530
|
+
JSON.stringify(canonicalizeExportValue(value)) === data.content
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
if (data.mediaType !== "text/html; charset=utf-8") return false;
|
|
534
|
+
const prefix =
|
|
535
|
+
'<!doctype html><html lang="en"><meta charset="utf-8"><title>OpenPlanr Operate audit export</title><body><main><h1>Operate audit export</h1><p>';
|
|
536
|
+
const marker = "</p><pre>";
|
|
537
|
+
const suffix = "</pre></main></body></html>";
|
|
538
|
+
if (!data.content.startsWith(prefix) || !data.content.endsWith(suffix))
|
|
539
|
+
return false;
|
|
540
|
+
const markerIndex = data.content.indexOf(marker, prefix.length);
|
|
541
|
+
if (markerIndex < 0) return false;
|
|
542
|
+
const escapedJson = data.content.slice(
|
|
543
|
+
markerIndex + marker.length,
|
|
544
|
+
-suffix.length,
|
|
545
|
+
);
|
|
546
|
+
const value = JSON.parse(unescapeHtml(escapedJson));
|
|
547
|
+
if (!validExportValue(value)) return false;
|
|
548
|
+
const canonicalValue = canonicalizeExportValue(value);
|
|
549
|
+
const expected = `${prefix}${escapeHtml(`${canonicalValue.domainId} / ${canonicalValue.scopeId}`)}${marker}${escapeHtml(JSON.stringify(canonicalValue, null, 2))}${suffix}`;
|
|
550
|
+
return data.content === expected;
|
|
551
|
+
} catch {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function validAuditPayloadSemantics(payload) {
|
|
557
|
+
if (payload.surface === "evidence") return validEvidenceData(payload.data);
|
|
558
|
+
if (payload.surface === "outcomes") return validOutcomesData(payload.data);
|
|
559
|
+
if (payload.surface === "outcome")
|
|
560
|
+
return validOutcomesData(payload.data, true);
|
|
561
|
+
if (payload.surface === "history")
|
|
562
|
+
return validHistoryData(payload.data, payload.eventHead);
|
|
563
|
+
if (payload.surface === "search") return validSearchData(payload.data);
|
|
564
|
+
if (payload.surface === "export") return validExportData(payload.data);
|
|
565
|
+
return false;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function validApplicableBinding(binding, payload) {
|
|
569
|
+
if (
|
|
570
|
+
binding.actorId !== payload.actorId ||
|
|
571
|
+
binding.scopeId !== payload.scopeId ||
|
|
572
|
+
binding.domainId !== payload.domainId ||
|
|
573
|
+
binding.domainVersion !== payload.domainVersion ||
|
|
574
|
+
binding.generatedAt !== payload.generatedAt ||
|
|
575
|
+
binding.viewHash !== payload.viewHash ||
|
|
576
|
+
binding.surface !== payload.surface ||
|
|
577
|
+
!exactEventHead(binding.eventHead, payload.eventHead)
|
|
578
|
+
)
|
|
579
|
+
return false;
|
|
580
|
+
if (binding.surface === "outcome") {
|
|
581
|
+
return (
|
|
582
|
+
typeof binding.subjectId === "string" &&
|
|
583
|
+
binding.query === null &&
|
|
584
|
+
binding.format === null &&
|
|
585
|
+
payload.data.outcome?.outcomeId === binding.subjectId
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
if (binding.surface === "evidence") {
|
|
589
|
+
const subjectMatches =
|
|
590
|
+
binding.subjectId === null ||
|
|
591
|
+
payload.data.evidence?.some(
|
|
592
|
+
(item) => item.evidenceRefId === binding.subjectId,
|
|
593
|
+
) ||
|
|
594
|
+
payload.data.claims?.some((item) => item.claimId === binding.subjectId);
|
|
595
|
+
return subjectMatches && binding.query === null && binding.format === null;
|
|
596
|
+
}
|
|
597
|
+
if (binding.surface === "search") {
|
|
598
|
+
return (
|
|
599
|
+
binding.subjectId === null &&
|
|
600
|
+
typeof binding.query === "string" &&
|
|
601
|
+
binding.query === payload.data.query &&
|
|
602
|
+
binding.format === null
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
if (binding.surface === "export") {
|
|
606
|
+
return (
|
|
607
|
+
binding.subjectId === null &&
|
|
608
|
+
binding.query === null &&
|
|
609
|
+
binding.format === payload.data.format
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
return (
|
|
613
|
+
binding.subjectId === null &&
|
|
614
|
+
binding.query === null &&
|
|
615
|
+
binding.format === null
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function validAuditSemantics(value, expected) {
|
|
620
|
+
return (
|
|
621
|
+
AUDIT_SURFACES.has(value.payload.surface) &&
|
|
622
|
+
value.payload.readOnly === true &&
|
|
623
|
+
value.payload.mutationEnabled === false &&
|
|
624
|
+
value.integrity.sourceViewHash === value.payload.viewHash &&
|
|
625
|
+
value.integrity.sourceViewHash === value.requestBinding.viewHash &&
|
|
626
|
+
value.payload.truthSummary.sourceViewHash === value.payload.viewHash &&
|
|
627
|
+
exactEventHead(value.payload.truthSummary.sourceEventHead, value.payload.eventHead) &&
|
|
628
|
+
validApplicableBinding(value.requestBinding, value.payload) &&
|
|
629
|
+
(expected === undefined || exactJson(value.requestBinding, expected)) &&
|
|
630
|
+
validLinkProjection(value.payload.data) &&
|
|
631
|
+
validAuditPayloadSemantics(value.payload) &&
|
|
632
|
+
validLegacyPayload(value.payload)
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export function validateOperateExperienceAuditDisplaySurfaceV1(
|
|
637
|
+
value,
|
|
638
|
+
expected,
|
|
639
|
+
) {
|
|
640
|
+
try {
|
|
641
|
+
const clone = safeDataClone(value);
|
|
642
|
+
const errors = validateJson(clone, auditDisplaySchema, {
|
|
643
|
+
base: "schemas/v1.2.0/operate-experience-audit-display-surface.schema.json",
|
|
644
|
+
resolveRef: resolveSchemaRef,
|
|
645
|
+
});
|
|
646
|
+
if (errors.length > 0 || !validAuditSemantics(clone, expected))
|
|
647
|
+
return errors.length > 0 ? errors : validationFailure();
|
|
648
|
+
return clone.integrity.contentHash ===
|
|
649
|
+
contentHash(withoutContentHash(clone), clone.integrity.domain)
|
|
650
|
+
? []
|
|
651
|
+
: validationFailure();
|
|
652
|
+
} catch {
|
|
653
|
+
return validationFailure();
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
export function assertOperateExperienceAuditDisplaySurfaceV1(value, expected) {
|
|
658
|
+
if (
|
|
659
|
+
validateOperateExperienceAuditDisplaySurfaceV1(value, expected).length > 0
|
|
660
|
+
) {
|
|
661
|
+
const error = new TypeError(
|
|
662
|
+
"The Operate audit display surface does not satisfy its closed integrity contract.",
|
|
663
|
+
);
|
|
664
|
+
error.code = "E_OPERATE_EXPERIENCE_AUDIT_DISPLAY_INVALID";
|
|
665
|
+
throw error;
|
|
666
|
+
}
|
|
667
|
+
return value;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export function issueOperateExperienceAuditDisplaySurfaceV1(payload, binding) {
|
|
671
|
+
const selected = safeDataClone(payload);
|
|
672
|
+
selected.readOnly = true;
|
|
673
|
+
selected.mutationEnabled = false;
|
|
674
|
+
const requestBinding = safeDataClone(binding);
|
|
675
|
+
const base = {
|
|
676
|
+
kind: "operate-experience-audit-display-surface",
|
|
677
|
+
schemaVersion: "1.0.0",
|
|
678
|
+
protocolVersion: "2.0.0",
|
|
679
|
+
requestBinding,
|
|
680
|
+
payload: selected,
|
|
681
|
+
integrity: {
|
|
682
|
+
algorithm: "sha-256-jcs",
|
|
683
|
+
domain: AUDIT_DISPLAY_DOMAIN,
|
|
684
|
+
sourceViewHash: selected.viewHash,
|
|
685
|
+
},
|
|
686
|
+
};
|
|
687
|
+
const issued = {
|
|
688
|
+
...base,
|
|
689
|
+
integrity: {
|
|
690
|
+
...base.integrity,
|
|
691
|
+
contentHash: contentHash(base, AUDIT_DISPLAY_DOMAIN),
|
|
692
|
+
},
|
|
693
|
+
};
|
|
694
|
+
assertOperateExperienceAuditDisplaySurfaceV1(issued, requestBinding);
|
|
695
|
+
return deepFreeze(issued);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export const OPERATE_EXPERIENCE_AUDIT_DISPLAY_SURFACE_SCHEMA_V1 = Object.freeze(
|
|
699
|
+
structuredClone(auditDisplaySchema),
|
|
700
|
+
);
|