create-windy 0.3.2 → 0.3.5
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 +27 -9
- package/dist/cli.js +825 -117
- package/package.json +1 -1
- package/template/.agents/skills/windy-business-module/SKILL.md +16 -3
- package/template/.windy-template.json +2 -2
- package/template/AGENTS.md +4 -0
- package/template/README.md +18 -11
- package/template/_gitignore +1 -0
- package/template/apps/agent-server/README.md +2 -0
- package/template/apps/agent-server/pyproject.toml +8 -0
- package/template/apps/agent-server/src/southwind_agent_server/adk_adapter.py +87 -10
- package/template/apps/agent-server/src/southwind_agent_server/adk_model.py +18 -3
- package/template/apps/agent-server/src/southwind_agent_server/adk_tools.py +78 -11
- package/template/apps/agent-server/src/southwind_agent_server/app.py +120 -115
- package/template/apps/agent-server/src/southwind_agent_server/artifact_input.py +153 -0
- package/template/apps/agent-server/src/southwind_agent_server/config.py +29 -0
- package/template/apps/agent-server/src/southwind_agent_server/contracts.py +81 -1
- package/template/apps/agent-server/src/southwind_agent_server/deterministic.py +8 -0
- package/template/apps/agent-server/src/southwind_agent_server/engine.py +28 -0
- package/template/apps/agent-server/src/southwind_agent_server/fingerprint.py +41 -0
- package/template/apps/agent-server/src/southwind_agent_server/http_helpers.py +62 -0
- package/template/apps/agent-server/src/southwind_agent_server/lease.py +15 -0
- package/template/apps/agent-server/src/southwind_agent_server/multimodal.py +76 -0
- package/template/apps/agent-server/src/southwind_agent_server/openai_engine.py +112 -20
- package/template/apps/agent-server/src/southwind_agent_server/openai_provider.py +14 -1
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store.py +329 -0
- package/template/apps/agent-server/src/southwind_agent_server/postgres_store_backend.py +332 -0
- package/template/apps/agent-server/src/southwind_agent_server/provider_governance.py +64 -3
- package/template/apps/agent-server/src/southwind_agent_server/runtime_factory.py +68 -0
- package/template/apps/agent-server/src/southwind_agent_server/service.py +218 -56
- package/template/apps/agent-server/src/southwind_agent_server/signal_events.py +36 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_catalog.py +107 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_schema.py +65 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_serialization.py +16 -0
- package/template/apps/agent-server/src/southwind_agent_server/sqlite_store.py +89 -57
- package/template/apps/agent-server/src/southwind_agent_server/store.py +105 -2
- package/template/apps/agent-server/src/southwind_agent_server/store_cipher.py +40 -0
- package/template/apps/agent-server/src/southwind_agent_server/telemetry.py +89 -0
- package/template/apps/agent-server/src/southwind_agent_server/tool_host.py +72 -0
- package/template/apps/agent-server/tests/test_adk_adapter.py +6 -2
- package/template/apps/agent-server/tests/test_api.py +24 -1
- package/template/apps/agent-server/tests/test_artifact_input.py +110 -0
- package/template/apps/agent-server/tests/test_config.py +4 -0
- package/template/apps/agent-server/tests/test_fingerprint.py +10 -0
- package/template/apps/agent-server/tests/test_multimodal.py +51 -0
- package/template/apps/agent-server/tests/test_openai_provider.py +6 -2
- package/template/apps/agent-server/tests/test_postgres_store.py +131 -0
- package/template/apps/agent-server/tests/test_provider_governance.py +61 -0
- package/template/apps/agent-server/tests/test_sqlite_store.py +95 -10
- package/template/apps/agent-server/tests/test_telemetry.py +25 -0
- package/template/apps/agent-server/tests/test_tool_approval.py +28 -0
- package/template/apps/agent-server/uv.lock +165 -0
- package/template/apps/document-server/Dockerfile +19 -0
- package/template/apps/document-server/pyproject.toml +43 -0
- package/template/apps/document-server/src/southwind_document_server/__init__.py +1 -0
- package/template/apps/document-server/src/southwind_document_server/adapter.py +337 -0
- package/template/apps/document-server/src/southwind_document_server/app.py +151 -0
- package/template/apps/document-server/src/southwind_document_server/config.py +94 -0
- package/template/apps/document-server/src/southwind_document_server/contracts.py +103 -0
- package/template/apps/document-server/src/southwind_document_server/service.py +149 -0
- package/template/apps/document-server/src/southwind_document_server/store.py +185 -0
- package/template/apps/document-server/tests/__init__.py +1 -0
- package/template/apps/document-server/tests/test_config.py +42 -0
- package/template/apps/document-server/tests/test_service.py +140 -0
- package/template/apps/document-server/uv.lock +430 -0
- package/template/apps/embedding-server/Dockerfile +17 -0
- package/template/apps/embedding-server/pyproject.toml +44 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/__init__.py +1 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/adapter.py +254 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/app.py +119 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/config.py +120 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/contracts.py +106 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/error.py +6 -0
- package/template/apps/embedding-server/src/southwind_embedding_server/image_input.py +87 -0
- package/template/apps/embedding-server/tests/__init__.py +1 -0
- package/template/apps/embedding-server/tests/test_adapter.py +92 -0
- package/template/apps/embedding-server/tests/test_config.py +38 -0
- package/template/apps/embedding-server/uv.lock +449 -0
- package/template/apps/server/src/agent/background-operation-port.ts +37 -0
- package/template/apps/server/src/agent/background-operation.test.ts +231 -0
- package/template/apps/server/src/agent/background-operation.ts +252 -0
- package/template/apps/server/src/agent/drizzle-run-binding-repository.ts +114 -0
- package/template/apps/server/src/agent/execution-grants.ts +7 -1
- package/template/apps/server/src/agent/fake-runtime.test-support.ts +43 -0
- package/template/apps/server/src/agent/idempotency-key.test.ts +28 -0
- package/template/apps/server/src/agent/idempotency-key.ts +11 -0
- package/template/apps/server/src/agent/remote-runtime.test.ts +115 -1
- package/template/apps/server/src/agent/remote-runtime.ts +173 -5
- package/template/apps/server/src/agent/run-authorization.test-support.ts +9 -0
- package/template/apps/server/src/agent/run-authorization.test.ts +126 -0
- package/template/apps/server/src/agent/run-authorization.ts +180 -0
- package/template/apps/server/src/agent/run-binding-repository.ts +93 -0
- package/template/apps/server/src/agent/run-contracts.ts +88 -1
- package/template/apps/server/src/agent/run-definition-support.ts +58 -0
- package/template/apps/server/src/agent/run-errors.ts +25 -0
- package/template/apps/server/src/agent/run-facade.test.ts +57 -46
- package/template/apps/server/src/agent/run-facade.ts +185 -65
- package/template/apps/server/src/agent/run-release.ts +78 -0
- package/template/apps/server/src/agent/run-route-input.ts +169 -0
- package/template/apps/server/src/agent/run-routes.ts +63 -76
- package/template/apps/server/src/agent/runtime-bootstrap.ts +169 -13
- package/template/apps/server/src/agent/sandbox-client.ts +200 -0
- package/template/apps/server/src/agent/sandbox-protocol.ts +76 -0
- package/template/apps/server/src/agent/sandbox-registry.ts +205 -0
- package/template/apps/server/src/agent/sandbox-runtime.test.ts +137 -0
- package/template/apps/server/src/agent/sandbox-worker-server.ts +195 -0
- package/template/apps/server/src/agent/sandbox-worker.ts +12 -0
- package/template/apps/server/src/agent/tool-approval.test.ts +75 -0
- package/template/apps/server/src/agent/tool-approval.ts +115 -0
- package/template/apps/server/src/agent/tool-audit.ts +62 -0
- package/template/apps/server/src/agent/tool-host.test.ts +39 -11
- package/template/apps/server/src/agent/tool-host.ts +184 -17
- package/template/apps/server/src/agent/tool-registry.ts +52 -47
- package/template/apps/server/src/agent/vision-facade.test.ts +256 -0
- package/template/apps/server/src/agent/vision-input.ts +120 -0
- package/template/apps/server/src/ai-artifact/codec.test.ts +44 -0
- package/template/apps/server/src/ai-artifact/codec.ts +137 -0
- package/template/apps/server/src/ai-artifact/routes.ts +37 -0
- package/template/apps/server/src/ai-artifact/runtime.ts +205 -0
- package/template/apps/server/src/application-services.ts +62 -2
- package/template/apps/server/src/auth/reauthentication.test.ts +40 -0
- package/template/apps/server/src/auth/reauthentication.ts +19 -0
- package/template/apps/server/src/auth/runtime.ts +9 -1
- package/template/apps/server/src/data-access/context.ts +6 -4
- package/template/apps/server/src/data-access/scope-snapshot.ts +27 -0
- package/template/apps/server/src/data-governance/export/approval-port.ts +6 -3
- package/template/apps/server/src/data-governance/export/authorization-port.test.ts +23 -4
- package/template/apps/server/src/data-governance/export/authorization-port.ts +89 -25
- package/template/apps/server/src/data-governance/export/drizzle-repository.integration.test.ts +2 -0
- package/template/apps/server/src/data-governance/export/drizzle-repository.ts +1 -0
- package/template/apps/server/src/data-governance/export/job-runtime.test.ts +15 -4
- package/template/apps/server/src/data-governance/export/job-runtime.ts +68 -15
- package/template/apps/server/src/data-governance/export/ndjson-stream.ts +25 -6
- package/template/apps/server/src/data-governance/export/postgres-recovery.integration.test.ts +4 -2
- package/template/apps/server/src/data-governance/export/renderer-job-runtime.test.ts +235 -0
- package/template/apps/server/src/data-governance/export/renderer-runtime.ts +293 -0
- package/template/apps/server/src/data-governance/export/renderer-selection.test.ts +67 -0
- package/template/apps/server/src/data-governance/export/repository.test.ts +2 -0
- package/template/apps/server/src/data-governance/export/request-fingerprint.test.ts +13 -0
- package/template/apps/server/src/data-governance/export/request-fingerprint.ts +2 -0
- package/template/apps/server/src/data-governance/export/routes.ts +11 -1
- package/template/apps/server/src/data-governance/export/scope-snapshot.ts +6 -18
- package/template/apps/server/src/data-governance/export/service-support.ts +188 -0
- package/template/apps/server/src/data-governance/export/service.ts +90 -113
- package/template/apps/server/src/data-governance/export/source.ts +101 -0
- package/template/apps/server/src/data-governance/export/types.ts +27 -0
- package/template/apps/server/src/document/contracts.ts +76 -0
- package/template/apps/server/src/document/facade.ts +339 -0
- package/template/apps/server/src/document/remote-runtime.test.ts +96 -0
- package/template/apps/server/src/document/remote-runtime.ts +223 -0
- package/template/apps/server/src/document/routes.ts +193 -0
- package/template/apps/server/src/embedding/contracts.ts +83 -0
- package/template/apps/server/src/embedding/error.ts +10 -0
- package/template/apps/server/src/embedding/facade.ts +217 -0
- package/template/apps/server/src/embedding/input.ts +172 -0
- package/template/apps/server/src/embedding/remote-runtime.test.ts +66 -0
- package/template/apps/server/src/embedding/remote-runtime.ts +218 -0
- package/template/apps/server/src/embedding/routes.ts +152 -0
- package/template/apps/server/src/index.ts +40 -43
- package/template/apps/server/src/jobs/artifact-service.test.ts +14 -2
- package/template/apps/server/src/jobs/artifact-service.ts +10 -0
- package/template/apps/server/src/jobs/drizzle-execution-repository.ts +17 -18
- package/template/apps/server/src/jobs/drizzle-execution.integration.test.ts +19 -1
- package/template/apps/server/src/jobs/drizzle-mappers.ts +4 -1
- package/template/apps/server/src/jobs/drizzle-recovery-repository.ts +49 -2
- package/template/apps/server/src/jobs/drizzle-repository.ts +1 -0
- package/template/apps/server/src/jobs/execution-repository.ts +17 -0
- package/template/apps/server/src/jobs/execution.test.ts +34 -0
- package/template/apps/server/src/jobs/in-memory-control.ts +135 -0
- package/template/apps/server/src/jobs/in-memory-execution.ts +34 -65
- package/template/apps/server/src/jobs/legacy-service-runtime.ts +5 -2
- package/template/apps/server/src/jobs/repository.ts +3 -0
- package/template/apps/server/src/jobs/worker.ts +80 -41
- package/template/apps/server/src/module-host/ai-operation-port.ts +170 -0
- package/template/apps/server/src/module-host/durable-context.test.ts +312 -0
- package/template/apps/server/src/module-host/durable-context.ts +124 -0
- package/template/apps/server/src/module-host/durable-handler-registration.ts +72 -0
- package/template/apps/server/src/module-host/governed-export-route-support.ts +171 -0
- package/template/apps/server/src/module-host/governed-export-routes.test.ts +327 -0
- package/template/apps/server/src/module-host/governed-export-routes.ts +238 -0
- package/template/apps/server/src/module-host/governed-renderer-registration.test.ts +247 -0
- package/template/apps/server/src/module-host/governed-resource-routes.ts +331 -0
- package/template/apps/server/src/module-host/governed-resources.test.ts +344 -0
- package/template/apps/server/src/module-host/governed-resources.ts +203 -0
- package/template/apps/server/src/module-host/http-runtime.ts +95 -0
- package/template/apps/server/src/module-host/initialize-contracts.ts +14 -0
- package/template/apps/server/src/module-host/initialize.test.ts +49 -1
- package/template/apps/server/src/module-host/initialize.ts +39 -16
- package/template/apps/server/src/module-host/job-port.test.ts +262 -0
- package/template/apps/server/src/module-host/job-port.ts +334 -0
- package/template/apps/server/src/module-host/request-context.test.ts +88 -2
- package/template/apps/server/src/module-host/request-context.ts +56 -22
- package/template/apps/server/src/module-host/route-installer.test.ts +10 -0
- package/template/apps/server/src/module-host/route-installer.ts +36 -1
- package/template/apps/server/src/module-host/sandbox-tool-registration.ts +42 -0
- package/template/apps/server/src/module-host/tool-handlers.ts +67 -31
- package/template/apps/server/src/module-host.ts +1 -0
- package/template/apps/server/src/module-runtime-validation.ts +7 -3
- package/template/apps/server/src/speech/contracts.ts +76 -0
- package/template/apps/server/src/speech/facade.ts +316 -0
- package/template/apps/server/src/speech/remote-runtime.test.ts +88 -0
- package/template/apps/server/src/speech/remote-runtime.ts +227 -0
- package/template/apps/server/src/speech/routes.ts +180 -0
- package/template/apps/server/src/system/actor.ts +39 -0
- package/template/apps/server/src/system/route-helpers.ts +1 -0
- package/template/apps/server/src/workflow/service.ts +2 -1
- package/template/apps/speech-server/Dockerfile +22 -0
- package/template/apps/speech-server/pyproject.toml +43 -0
- package/template/apps/speech-server/src/southwind_speech_server/__init__.py +1 -0
- package/template/apps/speech-server/src/southwind_speech_server/adapter.py +249 -0
- package/template/apps/speech-server/src/southwind_speech_server/app.py +183 -0
- package/template/apps/speech-server/src/southwind_speech_server/config.py +100 -0
- package/template/apps/speech-server/src/southwind_speech_server/contracts.py +103 -0
- package/template/apps/speech-server/src/southwind_speech_server/errors.py +6 -0
- package/template/apps/speech-server/src/southwind_speech_server/normalizer.py +108 -0
- package/template/apps/speech-server/src/southwind_speech_server/output_validation.py +128 -0
- package/template/apps/speech-server/src/southwind_speech_server/service.py +162 -0
- package/template/apps/speech-server/src/southwind_speech_server/store.py +209 -0
- package/template/apps/speech-server/tests/__init__.py +1 -0
- package/template/apps/speech-server/tests/test_config.py +33 -0
- package/template/apps/speech-server/tests/test_service.py +154 -0
- package/template/apps/speech-server/uv.lock +430 -0
- package/template/apps/web/src/app/business-routes.ts +22 -0
- package/template/apps/web/src/components/common/AccessSnapshotBoundary.vue +112 -0
- package/template/apps/web/src/components/common/AccessSnapshotBoundary.webtest.ts +130 -0
- package/template/apps/web/src/components/common/AccessSnapshotNotice.vue +117 -0
- package/template/apps/web/src/components/common/FormDialog.vue +6 -0
- package/template/apps/web/src/components/common/ModalLayout.webtest.ts +13 -0
- package/template/apps/web/src/composables/access-snapshot-change.ts +131 -0
- package/template/apps/web/src/composables/access-snapshot-change.webtest.ts +103 -0
- package/template/apps/web/src/composables/useAccessSnapshot.ts +48 -2
- package/template/apps/web/src/composables/useAccessSnapshot.webtest.ts +54 -0
- package/template/apps/web/src/composables/useAccessSnapshotMonitor.ts +42 -0
- package/template/apps/web/src/layout/AppShell.vue +28 -25
- package/template/apps/web/src/layout/AppShell.webtest.ts +1 -0
- package/template/apps/web/src/router/business-routes.ts +68 -0
- package/template/apps/web/src/router/business-routes.webtest.ts +85 -0
- package/template/apps/web/src/router/index.ts +7 -0
- package/template/apps/web/src/router/shared-scaffold-neutrality.webtest.ts +12 -0
- package/template/apps/web/src/services/access-api.ts +5 -1
- package/template/apps/web/src/services/access-api.webtest.ts +35 -0
- package/template/docker-compose.yml +127 -0
- package/template/docs/architecture/ai-egress.md +12 -9
- package/template/docs/architecture/ai-runtime.md +23 -11
- package/template/docs/architecture/durable-jobs.md +25 -3
- package/template/docs/architecture/foundation-infrastructure.md +163 -0
- package/template/docs/architecture/module-host.md +115 -0
- package/template/docs/architecture/server-module-interface.md +39 -0
- package/template/docs/architecture/web-access-snapshot-resilience.md +60 -0
- package/template/docs/development/business-web-routes.md +66 -0
- package/template/docs/development/custom-login-page.md +3 -3
- package/template/docs/development/module-lifecycle.md +71 -0
- package/template/docs/operations/observability.md +5 -1
- package/template/docs/platform/agent-runtime.md +21 -11
- package/template/docs/platform/agent-tool-sandbox.md +58 -0
- package/template/docs/platform/agent-tools.md +5 -0
- package/template/docs/platform/document-ai-runtime.md +204 -0
- package/template/docs/platform/governed-export-renderers.md +132 -0
- package/template/docs/platform/navigation-registry.md +5 -0
- package/template/docs/platform/organization-membership.md +2 -1
- package/template/docs/platform/speech-ai-runtime.md +156 -0
- package/template/docs/platform/system-crud-api.md +7 -1
- package/template/docs/platform/vision-ai-runtime.md +97 -0
- package/template/docs/platform/web-system-crud.md +6 -0
- package/template/package.json +16 -2
- package/template/packages/ai-client/index.ts +4 -0
- package/template/packages/ai-client/package.json +5 -2
- package/template/packages/ai-client/src/agent/client/artifact.ts +26 -0
- package/template/packages/ai-client/src/agent/client/attach.test.ts +124 -0
- package/template/packages/ai-client/src/agent/client/client.ts +119 -7
- package/template/packages/ai-client/src/agent/client/run.ts +14 -0
- package/template/packages/ai-client/src/agent/client/types.ts +18 -0
- package/template/packages/ai-client/src/agent/client/vision.test.ts +53 -0
- package/template/packages/ai-client/src/agent/contracts/contracts.test.ts +1 -0
- package/template/packages/ai-client/src/agent/contracts/events.ts +33 -0
- package/template/packages/ai-client/src/agent/contracts/runs.ts +71 -0
- package/template/packages/ai-client/src/agent/index.ts +1 -0
- package/template/packages/ai-client/src/artifact-ref.ts +8 -0
- package/template/packages/ai-client/src/document/client.test.ts +114 -0
- package/template/packages/ai-client/src/document/client.ts +134 -0
- package/template/packages/ai-client/src/document/contracts.ts +152 -0
- package/template/packages/ai-client/src/document/error.ts +43 -0
- package/template/packages/ai-client/src/document/index.ts +3 -0
- package/template/packages/ai-client/src/document/run.ts +104 -0
- package/template/packages/ai-client/src/document/validation.ts +115 -0
- package/template/packages/ai-client/src/embedding/client.test.ts +77 -0
- package/template/packages/ai-client/src/embedding/client.ts +96 -0
- package/template/packages/ai-client/src/embedding/contracts.ts +46 -0
- package/template/packages/ai-client/src/embedding/error.ts +61 -0
- package/template/packages/ai-client/src/embedding/index.ts +3 -0
- package/template/packages/ai-client/src/embedding/validation.ts +117 -0
- package/template/packages/ai-client/src/speech/client.test.ts +135 -0
- package/template/packages/ai-client/src/speech/client.ts +104 -0
- package/template/packages/ai-client/src/speech/contracts.ts +129 -0
- package/template/packages/ai-client/src/speech/error.ts +43 -0
- package/template/packages/ai-client/src/speech/index.ts +3 -0
- package/template/packages/ai-client/src/speech/run.ts +133 -0
- package/template/packages/ai-client/src/speech/validation.ts +132 -0
- package/template/packages/config/package.json +2 -2
- package/template/packages/database/drizzle/0039_early_ezekiel_stane.sql +1 -0
- package/template/packages/database/drizzle/0040_colossal_baron_strucker.sql +63 -0
- package/template/packages/database/drizzle/0041_yummy_prowler.sql +21 -0
- package/template/packages/database/drizzle/0042_puzzling_rumiko_fujikawa.sql +27 -0
- package/template/packages/database/drizzle/meta/0039_snapshot.json +7755 -0
- package/template/packages/database/drizzle/meta/0040_snapshot.json +8150 -0
- package/template/packages/database/drizzle/meta/0041_snapshot.json +8323 -0
- package/template/packages/database/drizzle/meta/0042_snapshot.json +8541 -0
- package/template/packages/database/drizzle/meta/_journal.json +28 -0
- package/template/packages/database/package.json +2 -2
- package/template/packages/database/src/agent-runtime-schema.test.ts +54 -0
- package/template/packages/database/src/schema/agent-runtime.ts +149 -0
- package/template/packages/database/src/schema/common.ts +2 -14
- package/template/packages/database/src/schema/durable-jobs.ts +5 -0
- package/template/packages/database/src/schema/governed-exports.ts +17 -5
- package/template/packages/database/src/schema/index.ts +3 -0
- package/template/packages/database/src/schema-durable-recovery.test.ts +31 -0
- package/template/packages/database/src/schema-governed-exports.test.ts +21 -1
- package/template/packages/database/src/schema.test.ts +6 -23
- package/template/packages/jobs/package.json +3 -2
- package/template/packages/jobs/src/handlers.test.ts +13 -0
- package/template/packages/jobs/src/handlers.ts +7 -1
- package/template/packages/jobs/src/types.ts +4 -0
- package/template/packages/modules/package.json +2 -2
- package/template/packages/modules/src/ai-operation-composition.test-support.ts +165 -0
- package/template/packages/modules/src/ai-operation-composition.test.ts +91 -127
- package/template/packages/modules/src/ai-operation-composition.ts +59 -1
- package/template/packages/modules/src/manifest.ts +25 -1
- package/template/packages/modules/src/tool-composition.ts +18 -0
- package/template/packages/server-sdk/index.ts +50 -0
- package/template/packages/server-sdk/package.json +10 -4
- package/template/packages/server-sdk/src/ai-artifact-port.ts +34 -0
- package/template/packages/server-sdk/src/ai-operation-port.ts +65 -0
- package/template/packages/server-sdk/src/ai-operation-registration.ts +42 -1
- package/template/packages/server-sdk/src/background-ai-port.ts +43 -0
- package/template/packages/server-sdk/src/data-governance-registration.ts +116 -0
- package/template/packages/server-sdk/src/durable-handler.ts +29 -0
- package/template/packages/server-sdk/src/jobs-port.ts +69 -0
- package/template/packages/server-sdk/src/module-host.ts +16 -2
- package/template/packages/server-sdk/src/request-context.ts +6 -2
- package/template/packages/server-sdk/src/sandbox-tool.ts +21 -0
- package/template/packages/server-sdk/src/tool-registration.ts +2 -0
- package/template/packages/shared/package.json +1 -1
- package/template/packages/shared/src/rbac.ts +30 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Component } from "vue";
|
|
2
|
+
import type { RouteRecordRaw } from "vue-router";
|
|
3
|
+
|
|
4
|
+
export interface BusinessAdminRouteRegistration {
|
|
5
|
+
readonly key: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly component: Component;
|
|
9
|
+
readonly featureKey: string;
|
|
10
|
+
readonly permissionKey: string;
|
|
11
|
+
readonly name?: string;
|
|
12
|
+
readonly props?: RouteRecordRaw["props"];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 客户拥有的 Web 业务路由注册表。
|
|
17
|
+
*
|
|
18
|
+
* 导航标题、路径、Feature 和 Permission 必须与业务 Module Manifest 保持一致。
|
|
19
|
+
* 平台 Router 会统一接入访问快照 Guard,业务项目不需要修改 shared-scaffold。
|
|
20
|
+
*/
|
|
21
|
+
export const installedBusinessAdminRoutes =
|
|
22
|
+
[] satisfies readonly BusinessAdminRouteRegistration[];
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, nextTick, useTemplateRef, watch } from "vue";
|
|
3
|
+
import { useRoute, useRouter } from "vue-router";
|
|
4
|
+
import { useAccessSnapshot } from "@/composables/useAccessSnapshot";
|
|
5
|
+
import { useAccessSnapshotMonitor } from "@/composables/useAccessSnapshotMonitor";
|
|
6
|
+
import { evaluateWebAccess } from "@/layout/navigation";
|
|
7
|
+
import AccessSnapshotNotice from "./AccessSnapshotNotice.vue";
|
|
8
|
+
|
|
9
|
+
const route = useRoute();
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const access = useAccessSnapshot();
|
|
12
|
+
const blocker = useTemplateRef<HTMLDivElement>("blocker");
|
|
13
|
+
useAccessSnapshotMonitor();
|
|
14
|
+
|
|
15
|
+
const routeRevoked = computed(() => {
|
|
16
|
+
const snapshot = access.snapshot.value;
|
|
17
|
+
if (!snapshot || route.meta.layout !== "admin") return false;
|
|
18
|
+
return !evaluateWebAccess(snapshot, {
|
|
19
|
+
permissionKey:
|
|
20
|
+
typeof route.meta.permissionKey === "string"
|
|
21
|
+
? route.meta.permissionKey
|
|
22
|
+
: undefined,
|
|
23
|
+
featureKey:
|
|
24
|
+
typeof route.meta.featureKey === "string"
|
|
25
|
+
? route.meta.featureKey
|
|
26
|
+
: undefined,
|
|
27
|
+
}).allowed;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const blockedReason = computed(() => {
|
|
31
|
+
if (routeRevoked.value) return "route-revoked" as const;
|
|
32
|
+
if (access.error.value) {
|
|
33
|
+
return access.failureReason.value || ("snapshot-unavailable" as const);
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const blocked = computed(() => Boolean(blockedReason.value));
|
|
39
|
+
const visibleChange = computed(() =>
|
|
40
|
+
blocked.value ? undefined : access.change.value,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
watch(blocked, async (isBlocked) => {
|
|
44
|
+
if (!isBlocked) return;
|
|
45
|
+
await nextTick();
|
|
46
|
+
blocker.value?.focus();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
async function retry(): Promise<void> {
|
|
50
|
+
try {
|
|
51
|
+
await access.refresh();
|
|
52
|
+
} catch {
|
|
53
|
+
// 失败详情保留在 access.error,由本边界继续安全降级。
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function reload(): void {
|
|
58
|
+
window.location.reload();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function returnHome(): Promise<void> {
|
|
62
|
+
await router.push({ name: "home" });
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div class="contents">
|
|
68
|
+
<!-- 页面节点保留以维持表单基线、dirty 状态与 beforeunload 保护。 -->
|
|
69
|
+
<div
|
|
70
|
+
:inert="blocked"
|
|
71
|
+
:aria-hidden="blocked ? 'true' : undefined"
|
|
72
|
+
:class="{ 'pointer-events-none invisible': blocked }"
|
|
73
|
+
data-testid="access-protected-content"
|
|
74
|
+
>
|
|
75
|
+
<AccessSnapshotNotice
|
|
76
|
+
v-if="visibleChange"
|
|
77
|
+
class="fixed top-4 right-4 z-40 w-[min(32rem,calc(100vw-2rem))] bg-background shadow-lg"
|
|
78
|
+
:blocking="false"
|
|
79
|
+
:change-kind="visibleChange.kind"
|
|
80
|
+
:loading="access.loading.value"
|
|
81
|
+
:fingerprint="access.fingerprint.value"
|
|
82
|
+
@acknowledge="access.acknowledgeChange"
|
|
83
|
+
@reload="reload"
|
|
84
|
+
@retry="retry"
|
|
85
|
+
@return-home="returnHome"
|
|
86
|
+
/>
|
|
87
|
+
<slot />
|
|
88
|
+
</div>
|
|
89
|
+
<div
|
|
90
|
+
v-if="blockedReason"
|
|
91
|
+
ref="blocker"
|
|
92
|
+
role="alertdialog"
|
|
93
|
+
aria-modal="true"
|
|
94
|
+
aria-label="访问状态已变化"
|
|
95
|
+
tabindex="-1"
|
|
96
|
+
class="fixed inset-0 z-40 flex items-start justify-center bg-background/95 p-6 pt-[15vh] outline-none backdrop-blur-sm"
|
|
97
|
+
>
|
|
98
|
+
<div class="w-full max-w-2xl">
|
|
99
|
+
<AccessSnapshotNotice
|
|
100
|
+
:blocking="true"
|
|
101
|
+
:reason="blockedReason"
|
|
102
|
+
:loading="access.loading.value"
|
|
103
|
+
:fingerprint="access.fingerprint.value"
|
|
104
|
+
@acknowledge="access.acknowledgeChange"
|
|
105
|
+
@reload="reload"
|
|
106
|
+
@retry="retry"
|
|
107
|
+
@return-home="returnHome"
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
</div>
|
|
111
|
+
</div>
|
|
112
|
+
</template>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { mount } from "@vue/test-utils";
|
|
2
|
+
import { nextTick } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
createMemoryHistory,
|
|
5
|
+
createRouter,
|
|
6
|
+
type RouteRecordRaw,
|
|
7
|
+
} from "vue-router";
|
|
8
|
+
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
9
|
+
import type { WebAccessSnapshot } from "@/layout/navigation";
|
|
10
|
+
import AccessSnapshotBoundary from "./AccessSnapshotBoundary.vue";
|
|
11
|
+
|
|
12
|
+
const mocks = vi.hoisted(() => ({ loadAccessSnapshot: vi.fn() }));
|
|
13
|
+
vi.mock("@/services/access-api", () => mocks);
|
|
14
|
+
vi.mock("@/composables/useAccessSnapshotMonitor", () => ({
|
|
15
|
+
useAccessSnapshotMonitor: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
resetAccessSnapshot,
|
|
20
|
+
useAccessSnapshot,
|
|
21
|
+
} from "@/composables/useAccessSnapshot";
|
|
22
|
+
|
|
23
|
+
describe("运行中权限快照边界", () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
resetAccessSnapshot();
|
|
26
|
+
mocks.loadAccessSnapshot.mockReset();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("当前路由权限撤销后隐藏但不卸载未保存页面", async () => {
|
|
30
|
+
mocks.loadAccessSnapshot
|
|
31
|
+
.mockResolvedValueOnce(snapshot(["system.user.read"]))
|
|
32
|
+
.mockResolvedValueOnce(snapshot([]));
|
|
33
|
+
const access = useAccessSnapshot();
|
|
34
|
+
await access.ensureLoaded();
|
|
35
|
+
const router = await testRouter();
|
|
36
|
+
const wrapper = mount(AccessSnapshotBoundary, {
|
|
37
|
+
slots: {
|
|
38
|
+
default:
|
|
39
|
+
'<input data-testid="draft" value="尚未保存的编辑内容" />',
|
|
40
|
+
},
|
|
41
|
+
global: { plugins: [router] },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
await access.refresh();
|
|
45
|
+
await nextTick();
|
|
46
|
+
|
|
47
|
+
expect(wrapper.get('[data-testid="access-snapshot-blocker"]').text()).toContain(
|
|
48
|
+
"当前页面权限已被撤销",
|
|
49
|
+
);
|
|
50
|
+
expect(
|
|
51
|
+
wrapper.get('[data-testid="access-protected-content"]').classes(),
|
|
52
|
+
).toContain("invisible");
|
|
53
|
+
expect(
|
|
54
|
+
wrapper.get<HTMLInputElement>('[data-testid="draft"]').element.value,
|
|
55
|
+
).toBe("尚未保存的编辑内容");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("刷新失败时 fail closed,成功重试后恢复原页面", async () => {
|
|
59
|
+
mocks.loadAccessSnapshot
|
|
60
|
+
.mockResolvedValueOnce(snapshot(["system.user.read"]))
|
|
61
|
+
.mockRejectedValueOnce(new Error("network unavailable"))
|
|
62
|
+
.mockResolvedValueOnce(snapshot(["system.user.read"]));
|
|
63
|
+
const access = useAccessSnapshot();
|
|
64
|
+
await access.ensureLoaded();
|
|
65
|
+
await expect(access.refresh()).rejects.toThrow("network unavailable");
|
|
66
|
+
const router = await testRouter();
|
|
67
|
+
const wrapper = mount(AccessSnapshotBoundary, {
|
|
68
|
+
slots: { default: '<p data-testid="content">用户列表</p>' },
|
|
69
|
+
global: { plugins: [router] },
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
await wrapper
|
|
73
|
+
.get('[data-testid="access-snapshot-blocker"] button')
|
|
74
|
+
.trigger("click");
|
|
75
|
+
await nextTick();
|
|
76
|
+
|
|
77
|
+
expect(mocks.loadAccessSnapshot).toHaveBeenCalledTimes(3);
|
|
78
|
+
expect(
|
|
79
|
+
wrapper.find('[data-testid="access-snapshot-blocker"]').exists(),
|
|
80
|
+
).toBe(false);
|
|
81
|
+
expect(wrapper.get('[data-testid="content"]').text()).toBe("用户列表");
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
async function testRouter() {
|
|
86
|
+
const routes: RouteRecordRaw[] = [
|
|
87
|
+
{
|
|
88
|
+
path: "/users",
|
|
89
|
+
component: { template: "<div />" },
|
|
90
|
+
meta: {
|
|
91
|
+
layout: "admin",
|
|
92
|
+
permissionKey: "system.user.read",
|
|
93
|
+
featureKey: "system.user",
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
path: "/",
|
|
98
|
+
name: "home",
|
|
99
|
+
component: { template: "<div />" },
|
|
100
|
+
meta: { layout: "app" },
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
const router = createRouter({ history: createMemoryHistory(), routes });
|
|
104
|
+
await router.push("/users");
|
|
105
|
+
await router.isReady();
|
|
106
|
+
return router;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function snapshot(permissionKeys: string[]): WebAccessSnapshot {
|
|
110
|
+
return {
|
|
111
|
+
actor: {
|
|
112
|
+
id: "user_1",
|
|
113
|
+
type: "user",
|
|
114
|
+
name: "平台用户",
|
|
115
|
+
roleCodes: ["member"],
|
|
116
|
+
permissionKeys,
|
|
117
|
+
},
|
|
118
|
+
menus: [],
|
|
119
|
+
permissions: [],
|
|
120
|
+
features: [
|
|
121
|
+
{
|
|
122
|
+
key: "system.user",
|
|
123
|
+
enabled: true,
|
|
124
|
+
visible: "visible",
|
|
125
|
+
allowed: true,
|
|
126
|
+
reason: "allowed",
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import {
|
|
3
|
+
CircleAlertIcon,
|
|
4
|
+
LoaderCircleIcon,
|
|
5
|
+
RefreshCwIcon,
|
|
6
|
+
RotateCwIcon,
|
|
7
|
+
} from "@lucide/vue";
|
|
8
|
+
import { computed } from "vue";
|
|
9
|
+
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
10
|
+
import { Button } from "@/components/ui/button";
|
|
11
|
+
import type { AccessSnapshotChangeKind } from "@/composables/access-snapshot-change";
|
|
12
|
+
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
blocking: boolean;
|
|
15
|
+
reason?:
|
|
16
|
+
| "route-revoked"
|
|
17
|
+
| "admin-access-revoked"
|
|
18
|
+
| "snapshot-unavailable";
|
|
19
|
+
changeKind?: AccessSnapshotChangeKind;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
fingerprint: string;
|
|
22
|
+
}>();
|
|
23
|
+
|
|
24
|
+
const emit = defineEmits<{
|
|
25
|
+
acknowledge: [];
|
|
26
|
+
reload: [];
|
|
27
|
+
retry: [];
|
|
28
|
+
returnHome: [];
|
|
29
|
+
}>();
|
|
30
|
+
|
|
31
|
+
const title = computed(() => {
|
|
32
|
+
if (props.reason === "route-revoked") return "当前页面权限已被撤销";
|
|
33
|
+
if (props.reason === "admin-access-revoked") {
|
|
34
|
+
return "管理后台访问权限已被撤销";
|
|
35
|
+
}
|
|
36
|
+
if (props.reason === "snapshot-unavailable") return "暂时无法确认最新权限";
|
|
37
|
+
if (props.changeKind === "reduced") return "访问权限已收紧";
|
|
38
|
+
if (props.changeKind === "expanded") return "访问权限已增加";
|
|
39
|
+
return "访问权限已更新";
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const description = computed(() => {
|
|
43
|
+
if (props.reason === "route-revoked") {
|
|
44
|
+
return "页面内容和操作已停止展示。未保存编辑仍保留在当前页面实例中;返回首页时会继续执行原有的未保存确认流程。";
|
|
45
|
+
}
|
|
46
|
+
if (props.reason === "admin-access-revoked") {
|
|
47
|
+
return "管理端内容和操作已停止展示。未保存编辑仍保留在当前页面实例中,可以重新检查权限或返回业务首页。";
|
|
48
|
+
}
|
|
49
|
+
if (props.reason === "snapshot-unavailable") {
|
|
50
|
+
return "为避免继续使用可能已撤销的能力,页面内容已临时隐藏。网络恢复后可重新检查。";
|
|
51
|
+
}
|
|
52
|
+
if (props.changeKind === "reduced") {
|
|
53
|
+
return "已撤销的入口和操作已立即隐藏。当前页面仍符合最新访问策略。";
|
|
54
|
+
}
|
|
55
|
+
if (props.changeKind === "expanded") {
|
|
56
|
+
return "入口和操作已按最新权限更新;如需重新加载页面数据,可以安全刷新。";
|
|
57
|
+
}
|
|
58
|
+
return "角色、功能或菜单策略已更新,当前界面已同步最新访问状态。";
|
|
59
|
+
});
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<template>
|
|
63
|
+
<Alert
|
|
64
|
+
:variant="blocking ? 'destructive' : 'default'"
|
|
65
|
+
:data-testid="
|
|
66
|
+
blocking ? 'access-snapshot-blocker' : 'access-snapshot-notice'
|
|
67
|
+
"
|
|
68
|
+
>
|
|
69
|
+
<CircleAlertIcon aria-hidden="true" />
|
|
70
|
+
<AlertTitle>{{ title }}</AlertTitle>
|
|
71
|
+
<AlertDescription class="space-y-3">
|
|
72
|
+
<p>{{ description }}</p>
|
|
73
|
+
<p v-if="fingerprint" class="font-mono text-[11px]">
|
|
74
|
+
快照:{{ fingerprint }}
|
|
75
|
+
</p>
|
|
76
|
+
<div class="flex flex-wrap gap-2">
|
|
77
|
+
<Button
|
|
78
|
+
v-if="blocking"
|
|
79
|
+
size="sm"
|
|
80
|
+
:disabled="loading"
|
|
81
|
+
@click="emit('retry')"
|
|
82
|
+
>
|
|
83
|
+
<LoaderCircleIcon v-if="loading" class="animate-spin" />
|
|
84
|
+
<RefreshCwIcon v-else />
|
|
85
|
+
{{ loading ? "正在检查…" : "重新检查" }}
|
|
86
|
+
</Button>
|
|
87
|
+
<Button
|
|
88
|
+
v-if="
|
|
89
|
+
reason === 'route-revoked' || reason === 'admin-access-revoked'
|
|
90
|
+
"
|
|
91
|
+
size="sm"
|
|
92
|
+
variant="outline"
|
|
93
|
+
@click="emit('returnHome')"
|
|
94
|
+
>
|
|
95
|
+
返回首页
|
|
96
|
+
</Button>
|
|
97
|
+
<Button
|
|
98
|
+
v-if="!blocking"
|
|
99
|
+
size="sm"
|
|
100
|
+
variant="outline"
|
|
101
|
+
@click="emit('reload')"
|
|
102
|
+
>
|
|
103
|
+
<RotateCwIcon />
|
|
104
|
+
安全刷新
|
|
105
|
+
</Button>
|
|
106
|
+
<Button
|
|
107
|
+
v-if="!blocking"
|
|
108
|
+
size="sm"
|
|
109
|
+
variant="ghost"
|
|
110
|
+
@click="emit('acknowledge')"
|
|
111
|
+
>
|
|
112
|
+
知道了
|
|
113
|
+
</Button>
|
|
114
|
+
</div>
|
|
115
|
+
</AlertDescription>
|
|
116
|
+
</Alert>
|
|
117
|
+
</template>
|
|
@@ -52,6 +52,10 @@ function handleInteractOutside(event: { preventDefault(): void }) {
|
|
|
52
52
|
if (props.preventOutsideClose) event.preventDefault();
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
function handleEscape(event: { preventDefault(): void }) {
|
|
56
|
+
if (props.preventOutsideClose) event.preventDefault();
|
|
57
|
+
}
|
|
58
|
+
|
|
55
59
|
async function handleOpenChange(value: boolean) {
|
|
56
60
|
if (value) {
|
|
57
61
|
open.value = true;
|
|
@@ -69,6 +73,8 @@ async function canClose() {
|
|
|
69
73
|
<Dialog :open="open" @update:open="handleOpenChange">
|
|
70
74
|
<DialogContent
|
|
71
75
|
:class="contentClass"
|
|
76
|
+
:show-close-button="!preventOutsideClose"
|
|
77
|
+
@escape-key-down="handleEscape"
|
|
72
78
|
@interact-outside="handleInteractOutside"
|
|
73
79
|
>
|
|
74
80
|
<DialogHeader>
|
|
@@ -52,6 +52,19 @@ describe("Modal 布局", () => {
|
|
|
52
52
|
expect(preventDefault).toHaveBeenCalledTimes(1);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
test("禁止非显式取消时同时阻止 Escape 并隐藏关闭按钮", async () => {
|
|
56
|
+
const wrapper = mount(FormDialog, {
|
|
57
|
+
props: { open: true, preventOutsideClose: true },
|
|
58
|
+
});
|
|
59
|
+
const preventDefault = vi.fn();
|
|
60
|
+
const content = wrapper.getComponent(DialogContent);
|
|
61
|
+
|
|
62
|
+
content.vm.$emit("escapeKeyDown", { preventDefault });
|
|
63
|
+
|
|
64
|
+
expect(preventDefault).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(content.props("showCloseButton")).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
55
68
|
test("关闭前置检查拒绝时保持打开,通过后才通知父组件关闭", async () => {
|
|
56
69
|
const beforeClose = vi
|
|
57
70
|
.fn<() => boolean | Promise<boolean>>()
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { MenuNode } from "@southwind-ai/shared";
|
|
2
|
+
import type { WebAccessSnapshot } from "@/layout/navigation";
|
|
3
|
+
|
|
4
|
+
export type AccessSnapshotChangeKind = "reduced" | "expanded" | "changed";
|
|
5
|
+
|
|
6
|
+
export interface AccessSnapshotChange {
|
|
7
|
+
readonly kind: AccessSnapshotChangeKind;
|
|
8
|
+
readonly previousFingerprint: string;
|
|
9
|
+
readonly currentFingerprint: string;
|
|
10
|
+
readonly removedCapabilities: readonly string[];
|
|
11
|
+
readonly addedCapabilities: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface AccessSnapshotIdentity {
|
|
15
|
+
readonly signature: string;
|
|
16
|
+
readonly fingerprint: string;
|
|
17
|
+
readonly capabilities: ReadonlySet<string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function accessSnapshotIdentity(
|
|
21
|
+
snapshot: WebAccessSnapshot,
|
|
22
|
+
): AccessSnapshotIdentity {
|
|
23
|
+
const capabilities = collectCapabilities(snapshot);
|
|
24
|
+
const signature = JSON.stringify({
|
|
25
|
+
actor: {
|
|
26
|
+
id: snapshot.actor.id,
|
|
27
|
+
type: snapshot.actor.type,
|
|
28
|
+
roles: sorted(snapshot.actor.roleCodes),
|
|
29
|
+
permissions: sorted(snapshot.actor.permissionKeys),
|
|
30
|
+
},
|
|
31
|
+
features: [...snapshot.features]
|
|
32
|
+
.map(({ key, enabled, visible, allowed, reason }) => ({
|
|
33
|
+
key,
|
|
34
|
+
enabled,
|
|
35
|
+
visible,
|
|
36
|
+
allowed,
|
|
37
|
+
reason,
|
|
38
|
+
}))
|
|
39
|
+
.sort(byKey),
|
|
40
|
+
menus: normalizeMenus(snapshot.menus),
|
|
41
|
+
});
|
|
42
|
+
return {
|
|
43
|
+
signature,
|
|
44
|
+
fingerprint: `access-v1-${fnv1a(signature)}`,
|
|
45
|
+
capabilities,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function describeAccessSnapshotChange(
|
|
50
|
+
previous: AccessSnapshotIdentity,
|
|
51
|
+
current: AccessSnapshotIdentity,
|
|
52
|
+
): AccessSnapshotChange | undefined {
|
|
53
|
+
if (previous.signature === current.signature) return undefined;
|
|
54
|
+
const removedCapabilities = difference(
|
|
55
|
+
previous.capabilities,
|
|
56
|
+
current.capabilities,
|
|
57
|
+
);
|
|
58
|
+
const addedCapabilities = difference(
|
|
59
|
+
current.capabilities,
|
|
60
|
+
previous.capabilities,
|
|
61
|
+
);
|
|
62
|
+
return {
|
|
63
|
+
kind: removedCapabilities.length
|
|
64
|
+
? "reduced"
|
|
65
|
+
: addedCapabilities.length
|
|
66
|
+
? "expanded"
|
|
67
|
+
: "changed",
|
|
68
|
+
previousFingerprint: previous.fingerprint,
|
|
69
|
+
currentFingerprint: current.fingerprint,
|
|
70
|
+
removedCapabilities,
|
|
71
|
+
addedCapabilities,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function collectCapabilities(snapshot: WebAccessSnapshot): ReadonlySet<string> {
|
|
76
|
+
const capabilities = new Set(
|
|
77
|
+
snapshot.actor.permissionKeys.map((key) => `permission:${key}`),
|
|
78
|
+
);
|
|
79
|
+
for (const feature of snapshot.features) {
|
|
80
|
+
if (feature.allowed) capabilities.add(`feature:${feature.key}`);
|
|
81
|
+
}
|
|
82
|
+
collectMenuCapabilities(snapshot.menus, capabilities);
|
|
83
|
+
return capabilities;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function collectMenuCapabilities(
|
|
87
|
+
menus: readonly MenuNode[],
|
|
88
|
+
capabilities: Set<string>,
|
|
89
|
+
): void {
|
|
90
|
+
for (const menu of menus) {
|
|
91
|
+
if (menu.visible) capabilities.add(`menu:${menu.key}`);
|
|
92
|
+
collectMenuCapabilities(menu.children || [], capabilities);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normalizeMenus(menus: readonly MenuNode[]): object[] {
|
|
97
|
+
return [...menus]
|
|
98
|
+
.map((menu) => ({
|
|
99
|
+
key: menu.key,
|
|
100
|
+
path: menu.path || "",
|
|
101
|
+
visible: menu.visible,
|
|
102
|
+
permissionKey: menu.permissionKey || "",
|
|
103
|
+
featureKey: menu.featureKey || "",
|
|
104
|
+
children: normalizeMenus(menu.children || []),
|
|
105
|
+
}))
|
|
106
|
+
.sort(byKey);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function difference(
|
|
110
|
+
left: ReadonlySet<string>,
|
|
111
|
+
right: ReadonlySet<string>,
|
|
112
|
+
): string[] {
|
|
113
|
+
return [...left].filter((item) => !right.has(item)).sort();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function sorted(values: readonly string[]): string[] {
|
|
117
|
+
return [...new Set(values)].sort();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function byKey(left: { key: string }, right: { key: string }): number {
|
|
121
|
+
return left.key.localeCompare(right.key);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function fnv1a(value: string): string {
|
|
125
|
+
let hash = 0x811c9dc5;
|
|
126
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
127
|
+
hash ^= value.charCodeAt(index);
|
|
128
|
+
hash = Math.imul(hash, 0x01000193);
|
|
129
|
+
}
|
|
130
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
131
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import type { WebAccessSnapshot } from "@/layout/navigation";
|
|
3
|
+
import {
|
|
4
|
+
accessSnapshotIdentity,
|
|
5
|
+
describeAccessSnapshotChange,
|
|
6
|
+
} from "./access-snapshot-change";
|
|
7
|
+
|
|
8
|
+
describe("权限快照变化", () => {
|
|
9
|
+
test("不同返回顺序生成相同稳定指纹", () => {
|
|
10
|
+
const first = snapshot();
|
|
11
|
+
const second = snapshot();
|
|
12
|
+
second.actor.permissionKeys.reverse();
|
|
13
|
+
second.actor.roleCodes.reverse();
|
|
14
|
+
second.features.reverse();
|
|
15
|
+
second.menus.reverse();
|
|
16
|
+
|
|
17
|
+
expect(accessSnapshotIdentity(first).fingerprint).toBe(
|
|
18
|
+
accessSnapshotIdentity(second).fingerprint,
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("权限或已授权 Feature 被移除时归类为收紧", () => {
|
|
23
|
+
const previous = accessSnapshotIdentity(snapshot());
|
|
24
|
+
const currentSnapshot = snapshot();
|
|
25
|
+
currentSnapshot.actor.permissionKeys =
|
|
26
|
+
currentSnapshot.actor.permissionKeys.filter(
|
|
27
|
+
(key) => key !== "system.user.manage",
|
|
28
|
+
);
|
|
29
|
+
currentSnapshot.features[0]!.allowed = false;
|
|
30
|
+
const change = describeAccessSnapshotChange(
|
|
31
|
+
previous,
|
|
32
|
+
accessSnapshotIdentity(currentSnapshot),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(change?.kind).toBe("reduced");
|
|
36
|
+
expect(change?.removedCapabilities).toEqual([
|
|
37
|
+
"feature:system.user",
|
|
38
|
+
"permission:system.user.manage",
|
|
39
|
+
]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("只有新增能力时归类为扩展", () => {
|
|
43
|
+
const previousSnapshot = snapshot();
|
|
44
|
+
previousSnapshot.actor.permissionKeys = ["system.user.read"];
|
|
45
|
+
const currentSnapshot = snapshot();
|
|
46
|
+
const change = describeAccessSnapshotChange(
|
|
47
|
+
accessSnapshotIdentity(previousSnapshot),
|
|
48
|
+
accessSnapshotIdentity(currentSnapshot),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(change?.kind).toBe("expanded");
|
|
52
|
+
expect(change?.addedCapabilities).toContain(
|
|
53
|
+
"permission:system.user.manage",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
function snapshot(): WebAccessSnapshot {
|
|
59
|
+
return {
|
|
60
|
+
actor: {
|
|
61
|
+
id: "user_1",
|
|
62
|
+
type: "user",
|
|
63
|
+
name: "平台管理员",
|
|
64
|
+
roleCodes: ["operator", "admin"],
|
|
65
|
+
permissionKeys: ["system.user.read", "system.user.manage"],
|
|
66
|
+
},
|
|
67
|
+
menus: [
|
|
68
|
+
{
|
|
69
|
+
key: "system.role",
|
|
70
|
+
title: "角色",
|
|
71
|
+
type: "menu",
|
|
72
|
+
order: 2,
|
|
73
|
+
visible: true,
|
|
74
|
+
path: "/admin/system/roles",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "system.user",
|
|
78
|
+
title: "用户",
|
|
79
|
+
type: "menu",
|
|
80
|
+
order: 1,
|
|
81
|
+
visible: true,
|
|
82
|
+
path: "/admin/system/users",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
permissions: [],
|
|
86
|
+
features: [
|
|
87
|
+
{
|
|
88
|
+
key: "system.user",
|
|
89
|
+
enabled: true,
|
|
90
|
+
visible: "visible",
|
|
91
|
+
allowed: true,
|
|
92
|
+
reason: "allowed",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
key: "system.role",
|
|
96
|
+
enabled: true,
|
|
97
|
+
visible: "visible",
|
|
98
|
+
allowed: true,
|
|
99
|
+
reason: "allowed",
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
}
|