create-windy 0.2.7 → 0.2.8
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 +6 -0
- package/dist/cli.js +180 -87
- package/package.json +1 -1
- package/template/.windy-template.json +2 -2
- package/template/apps/server/Dockerfile +2 -0
- package/template/apps/server/package.json +10 -8
- package/template/apps/server/src/access-guards.ts +1 -1
- package/template/apps/server/src/admin/routes.test.ts +10 -0
- package/template/apps/server/src/admin/routes.ts +4 -2
- package/template/apps/server/src/agent/routes.test.ts +1 -1
- package/template/apps/server/src/agent/routes.ts +2 -2
- package/template/apps/server/src/application-services.ts +3 -0
- package/template/apps/server/src/audit/drizzle-log-store.ts +2 -2
- package/template/apps/server/src/audit/policy.ts +1 -1
- package/template/apps/server/src/audit/recovery-queue.test.ts +1 -1
- package/template/apps/server/src/audit/recovery-queue.ts +1 -1
- package/template/apps/server/src/audit/redaction.ts +1 -1
- package/template/apps/server/src/audit/reliable-writer.test.ts +1 -1
- package/template/apps/server/src/audit/reliable-writer.ts +1 -1
- package/template/apps/server/src/audit/search-summary.ts +1 -1
- package/template/apps/server/src/auth/authentication-provider.test.ts +1 -1
- package/template/apps/server/src/auth/credential-service.ts +1 -1
- package/template/apps/server/src/auth/drizzle-repository.ts +2 -2
- package/template/apps/server/src/auth/drizzle-session-operations.ts +1 -1
- package/template/apps/server/src/auth/own-session-routes.test.ts +1 -1
- package/template/apps/server/src/auth/password.ts +2 -2
- package/template/apps/server/src/auth/repository.ts +1 -1
- package/template/apps/server/src/auth/routes.test.ts +1 -1
- package/template/apps/server/src/auth/service.ts +1 -1
- package/template/apps/server/src/bulk-data/artifact-store.ts +1 -1
- package/template/apps/server/src/bulk-data/dictionary-handler.ts +1 -1
- package/template/apps/server/src/bulk-data/drizzle-repository.ts +3 -3
- package/template/apps/server/src/bulk-data/repository.ts +1 -1
- package/template/apps/server/src/bulk-data/routes.test.ts +1 -1
- package/template/apps/server/src/bulk-data/routes.ts +1 -1
- package/template/apps/server/src/bulk-data/service.test.ts +1 -1
- package/template/apps/server/src/bulk-data/service.ts +1 -1
- package/template/apps/server/src/bulk-data/types.ts +1 -1
- package/template/apps/server/src/configuration/bootstrap.ts +2 -2
- package/template/apps/server/src/configuration/definition.ts +2 -2
- package/template/apps/server/src/configuration/drizzle-repository.ts +2 -2
- package/template/apps/server/src/configuration/repository.ts +1 -1
- package/template/apps/server/src/configuration/routes.ts +1 -1
- package/template/apps/server/src/configuration/service.ts +1 -1
- package/template/apps/server/src/data-access/context.ts +2 -2
- package/template/apps/server/src/data-access/query-specification.test.ts +1 -1
- package/template/apps/server/src/data-access/scoped-repository.integration.test.ts +1 -1
- package/template/apps/server/src/data-access/scoped-repository.ts +1 -1
- package/template/apps/server/src/data-access/scoped-resource.test.ts +1 -1
- package/template/apps/server/src/data-access/scoped-resource.ts +1 -1
- package/template/apps/server/src/data-governance/export/approval-port.ts +1 -1
- package/template/apps/server/src/data-governance/export/drizzle-repository.ts +1 -1
- package/template/apps/server/src/data-governance/export/job-runtime.test.ts +2 -2
- package/template/apps/server/src/data-governance/export/job-runtime.ts +2 -3
- package/template/apps/server/src/data-governance/export/postgres-api-fixture.ts +2 -2
- package/template/apps/server/src/data-governance/export/postgres-api.integration.test.ts +1 -1
- package/template/apps/server/src/data-governance/export/routes-test-fixture.ts +3 -3
- package/template/apps/server/src/data-governance/export/routes.ts +1 -1
- package/template/apps/server/src/data-governance/export/scope-snapshot.ts +1 -1
- package/template/apps/server/src/data-governance/export/service.ts +2 -2
- package/template/apps/server/src/data-governance/export/source.ts +1 -1
- package/template/apps/server/src/data-governance/export/types.ts +1 -1
- package/template/apps/server/src/data-governance/plaintext-access.test.ts +1 -1
- package/template/apps/server/src/data-governance/plaintext-access.ts +1 -1
- package/template/apps/server/src/data-governance/plaintext-postgres.integration.test.ts +1 -1
- package/template/apps/server/src/data-governance/user-plaintext-routes.ts +1 -1
- package/template/apps/server/src/data-governance/user-projection.ts +2 -2
- package/template/apps/server/src/example-modules.ts +25 -1
- package/template/apps/server/src/feature/manifest-feature-repository.test.ts +1 -1
- package/template/apps/server/src/feature/manifest-feature-repository.ts +1 -1
- package/template/apps/server/src/feature/routes.ts +3 -6
- package/template/apps/server/src/foundation-access.test.ts +1 -1
- package/template/apps/server/src/foundation-access.ts +1 -1
- package/template/apps/server/src/foundation.ts +21 -7
- package/template/apps/server/src/guards.test.ts +1 -1
- package/template/apps/server/src/guards.ts +3 -3
- package/template/apps/server/src/index.ts +27 -3
- package/template/{packages/modules → apps/server}/src/installed-business-modules.ts +2 -2
- package/template/apps/server/src/jobs/artifact-service.test.ts +1 -1
- package/template/apps/server/src/jobs/artifact-service.ts +2 -2
- package/template/apps/server/src/jobs/drizzle-artifact.ts +2 -2
- package/template/apps/server/src/jobs/drizzle-claim.ts +1 -1
- package/template/apps/server/src/jobs/drizzle-execution-repository.ts +2 -2
- package/template/apps/server/src/jobs/drizzle-execution.integration.test.ts +1 -1
- package/template/apps/server/src/jobs/drizzle-lease.ts +2 -2
- package/template/apps/server/src/jobs/drizzle-mappers.ts +3 -3
- package/template/apps/server/src/jobs/drizzle-recovery-repository.ts +1 -1
- package/template/apps/server/src/jobs/drizzle-repository.integration.test.ts +1 -1
- package/template/apps/server/src/jobs/drizzle-repository.ts +3 -3
- package/template/apps/server/src/jobs/execution-repository.ts +1 -1
- package/template/apps/server/src/jobs/execution.test.ts +2 -2
- package/template/apps/server/src/jobs/in-memory-claim.ts +1 -1
- package/template/apps/server/src/jobs/in-memory-execution.ts +1 -1
- package/template/apps/server/src/jobs/in-memory-lease.ts +1 -1
- package/template/apps/server/src/jobs/legacy-adapter.integration.test.ts +1 -1
- package/template/apps/server/src/jobs/legacy-adapter.test.ts +1 -1
- package/template/apps/server/src/jobs/legacy-adapter.ts +1 -1
- package/template/apps/server/src/jobs/legacy-service-runtime.ts +4 -2
- package/template/apps/server/src/jobs/repository.ts +2 -2
- package/template/apps/server/src/jobs/service.ts +2 -2
- package/template/apps/server/src/jobs/worker.ts +3 -2
- package/template/apps/server/src/license/legacy-license-resolver.ts +1 -1
- package/template/apps/server/src/license/license-resolver.test.ts +1 -1
- package/template/apps/server/src/license/license-resolver.ts +3 -3
- package/template/apps/server/src/license/routes-offline-code.test.ts +2 -2
- package/template/apps/server/src/license/routes.ts +1 -1
- package/template/apps/server/src/license/runtime-audit-reliability.test.ts +2 -2
- package/template/apps/server/src/license/runtime-reminder.test.ts +2 -2
- package/template/apps/server/src/license/runtime-service.test.ts +2 -2
- package/template/apps/server/src/license/runtime-service.ts +2 -2
- package/template/apps/server/src/module-composition.test.ts +1 -1
- package/template/apps/server/src/module-composition.ts +1 -1
- package/template/apps/server/src/module-host.test.ts +145 -0
- package/template/apps/server/src/module-host.ts +110 -0
- package/template/apps/server/src/notification/drizzle-repository.ts +2 -2
- package/template/apps/server/src/notification/repository.ts +1 -1
- package/template/apps/server/src/notification/routes.ts +1 -1
- package/template/apps/server/src/pagination.ts +1 -1
- package/template/apps/server/src/persistence.integration.test.ts +1 -1
- package/template/apps/server/src/persistence.ts +1 -1
- package/template/apps/server/src/profile/routes.ts +1 -1
- package/template/apps/server/src/route-guards.test.ts +1 -1
- package/template/apps/server/src/route-guards.ts +1 -1
- package/template/apps/server/src/runtime-feature.ts +125 -0
- package/template/apps/server/src/runtime-license.ts +1 -1
- package/template/apps/server/src/runtime.test.ts +48 -1
- package/template/apps/server/src/runtime.ts +17 -64
- package/template/apps/server/src/scheduler/audit.ts +1 -1
- package/template/apps/server/src/scheduler/definitions.test.ts +1 -1
- package/template/apps/server/src/scheduler/definitions.ts +2 -2
- package/template/apps/server/src/scheduler/drizzle-durable-links.ts +1 -1
- package/template/apps/server/src/scheduler/drizzle-mappers.ts +1 -1
- package/template/apps/server/src/scheduler/drizzle-repository.ts +1 -1
- package/template/apps/server/src/scheduler/execution-recorder.ts +1 -1
- package/template/apps/server/src/scheduler/history.ts +1 -1
- package/template/apps/server/src/scheduler/overview.ts +1 -1
- package/template/apps/server/src/scheduler/recovery-service.test.ts +1 -1
- package/template/apps/server/src/scheduler/recovery-service.ts +1 -1
- package/template/apps/server/src/scheduler/repository.ts +1 -1
- package/template/apps/server/src/scheduler/routes.ts +1 -1
- package/template/apps/server/src/scheduler/service-idle.test.ts +1 -1
- package/template/apps/server/src/scheduler/service.test.ts +1 -1
- package/template/apps/server/src/scheduler/service.ts +1 -1
- package/template/apps/server/src/scheduler/types.ts +1 -1
- package/template/apps/server/src/search/contracts.ts +2 -2
- package/template/apps/server/src/search/host.ts +1 -1
- package/template/apps/server/src/search/registry.ts +1 -1
- package/template/apps/server/src/search/routes.test.ts +1 -1
- package/template/apps/server/src/search/routes.ts +1 -1
- package/template/apps/server/src/search/service.ts +2 -2
- package/template/apps/server/src/search/test-support.ts +2 -2
- package/template/apps/server/src/session/routes.ts +1 -1
- package/template/apps/server/src/settings/drizzle-repository.ts +2 -2
- package/template/apps/server/src/settings/repository.ts +1 -1
- package/template/apps/server/src/settings/routes.test.ts +1 -1
- package/template/apps/server/src/settings/routes.ts +1 -1
- package/template/apps/server/src/settings/runtime.ts +1 -1
- package/template/apps/server/src/storage/blob-reference-registry.test.ts +1 -1
- package/template/apps/server/src/storage/blob-reference-registry.ts +1 -1
- package/template/apps/server/src/storage/drizzle-upload-repository.integration.test.ts +1 -1
- package/template/apps/server/src/storage/drizzle-upload-repository.ts +2 -2
- package/template/apps/server/src/storage/route-support.ts +1 -1
- package/template/apps/server/src/storage/routes.test.ts +1 -1
- package/template/apps/server/src/storage/routes.ts +2 -2
- package/template/apps/server/src/storage/runtime.ts +6 -4
- package/template/apps/server/src/system/audit-routes.ts +1 -1
- package/template/apps/server/src/system/department-routes.ts +1 -1
- package/template/apps/server/src/system/drizzle-repository.ts +1 -1
- package/template/apps/server/src/system/drizzle-scoped-repository.ts +1 -1
- package/template/apps/server/src/system/drizzle-system.ts +1 -1
- package/template/apps/server/src/system/entities.ts +1 -1
- package/template/apps/server/src/system/identity-route-config.ts +1 -1
- package/template/apps/server/src/system/interface-catalog.test.ts +3 -3
- package/template/apps/server/src/system/interface-catalog.ts +2 -2
- package/template/apps/server/src/system/menu-registry.ts +1 -1
- package/template/apps/server/src/system/menu-routes.ts +1 -1
- package/template/apps/server/src/system/operations.test.ts +1 -1
- package/template/apps/server/src/system/operations.ts +1 -1
- package/template/apps/server/src/system/redis-health.ts +1 -1
- package/template/apps/server/src/system/repository.ts +1 -1
- package/template/apps/server/src/system/resource-route-support.ts +1 -1
- package/template/apps/server/src/system/route-helpers.ts +1 -1
- package/template/apps/server/src/system/route-types.ts +1 -1
- package/template/apps/server/src/system/routes.test.ts +1 -1
- package/template/apps/server/src/system/routes.ts +1 -1
- package/template/apps/server/src/system/user-projection.ts +1 -1
- package/template/apps/server/src/work-order/data-scope.integration.test.ts +1 -1
- package/template/apps/server/src/work-order/drizzle-repository.integration.test.ts +1 -1
- package/template/apps/server/src/work-order/drizzle-repository.ts +2 -2
- package/template/apps/server/src/work-order/foundation-modules.test.ts +15 -5
- package/template/apps/server/src/work-order/repository.ts +1 -1
- package/template/apps/server/src/work-order/routes.test.ts +2 -2
- package/template/apps/server/src/work-order/routes.ts +2 -2
- package/template/apps/server/src/work-order/search-api.test.ts +3 -3
- package/template/apps/server/src/work-order/search-provider.test.ts +3 -3
- package/template/apps/server/src/work-order/service.ts +1 -1
- package/template/apps/server/src/work-order/task.test.ts +1 -1
- package/template/apps/server/src/work-order/task.ts +2 -2
- package/template/apps/server/src/workflow/drizzle-repository.integration.test.ts +2 -2
- package/template/apps/server/src/workflow/drizzle-repository.ts +3 -3
- package/template/apps/server/src/workflow/effects.test.ts +1 -1
- package/template/apps/server/src/workflow/effects.ts +1 -1
- package/template/apps/server/src/workflow/repository.ts +2 -2
- package/template/apps/server/src/workflow/routes.ts +3 -3
- package/template/apps/server/src/workflow/service.ts +1 -1
- package/template/apps/server/src/workflow/timeout-runtime.test.ts +1 -1
- package/template/apps/server/src/workflow/timeout-runtime.ts +2 -2
- package/template/apps/web/Dockerfile +2 -0
- package/template/apps/web/package.json +4 -4
- package/template/apps/web/runtime-server.ts +1 -1
- package/template/apps/web/src/app/layouts/AppLayout.vue +6 -0
- package/template/apps/web/src/components/auth/PasswordChangeForm.vue +1 -1
- package/template/apps/web/src/components/common/DataPagination.vue +1 -1
- package/template/apps/web/src/components/license/LicenseActivationCodeForm.vue +1 -1
- package/template/apps/web/src/components/license/LicenseFlow.webtest.ts +2 -2
- package/template/apps/web/src/composables/useModuleConfigurations.ts +1 -1
- package/template/apps/web/src/composables/useWatermarkSettings.ts +1 -0
- package/template/apps/web/src/composables/watermark-settings.ts +6 -0
- package/template/apps/web/src/composables/watermark-settings.webtest.ts +27 -1
- package/template/apps/web/src/layout/AppSidebar.vue +12 -3
- package/template/apps/web/src/layout/AppSidebar.webtest.ts +11 -0
- package/template/apps/web/src/layout/GlobalWatermark.vue +25 -8
- package/template/apps/web/src/layout/GlobalWatermark.webtest.ts +109 -0
- package/template/apps/web/src/layout/NavigationSearchDialog.vue +1 -1
- package/template/apps/web/src/layout/NotificationMenu.vue +1 -1
- package/template/apps/web/src/layout/navigation.ts +5 -1
- package/template/apps/web/src/layout/navigation.webtest.ts +1 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigRollbackDialog.vue +1 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigVersionList.vue +1 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.vue +1 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationEditor.webtest.ts +1 -1
- package/template/apps/web/src/pages/configuration/components/ModuleConfigurationWorkbench.vue +1 -1
- package/template/apps/web/src/pages/dashboard/dashboard-presenter.webtest.ts +1 -1
- package/template/apps/web/src/pages/settings/WatermarkSettingsSection.vue +21 -0
- package/template/apps/web/src/pages/system/SystemNotificationsPage.vue +2 -2
- package/template/apps/web/src/pages/system/components/AuditActionCell.vue +7 -2
- package/template/apps/web/src/pages/system/components/AuditLogFilters.vue +7 -2
- package/template/apps/web/src/pages/system/components/NotificationPublishForm.vue +1 -1
- package/template/apps/web/src/pages/system/components/SchedulerOperationsPanel.vue +1 -1
- package/template/apps/web/src/pages/system/components/SchedulerOperationsPanel.webtest.ts +1 -1
- package/template/apps/web/src/pages/system/components/SchedulerRunTable.vue +1 -1
- package/template/apps/web/src/pages/system/components/SchedulerRunTable.webtest.ts +1 -1
- package/template/apps/web/src/pages/system/components/SchedulerStaleRecoveryForm.vue +1 -1
- package/template/apps/web/src/pages/system/components/SchedulerStaleRecoveryForm.webtest.ts +1 -1
- package/template/apps/web/src/pages/system/components/SystemResourcePage.vue +1 -1
- package/template/apps/web/src/pages/system/components/SystemResourceTable.vue +10 -3
- package/template/apps/web/src/pages/system/components/role-policy/RolePermissionTree.vue +1 -1
- package/template/apps/web/src/pages/system/components/role-policy/RolePermissionTree.webtest.ts +1 -1
- package/template/apps/web/src/pages/system/components/role-policy/RolePolicyForm.vue +1 -1
- package/template/apps/web/src/pages/system/components/role-policy/permission-tree.ts +1 -1
- package/template/apps/web/src/pages/system/components/role-policy/permission-tree.webtest.ts +1 -1
- package/template/apps/web/src/pages/system/composables/useSchedulerOperations.ts +2 -2
- package/template/apps/web/src/pages/system/composables/useSchedulerOperations.webtest.ts +1 -1
- package/template/apps/web/src/pages/system/composables/useSystemResource.ts +1 -1
- package/template/apps/web/src/router/manifest-routes.ts +1 -1
- package/template/apps/web/src/router/manifest-routes.webtest.ts +1 -1
- package/template/apps/web/src/services/access-api.ts +10 -1
- package/template/apps/web/src/services/configuration-api.ts +1 -1
- package/template/apps/web/src/services/license-api.ts +1 -1
- package/template/apps/web/src/services/notification-api.ts +2 -2
- package/template/apps/web/src/services/operations-api.ts +1 -1
- package/template/apps/web/src/services/platform-settings-api.ts +2 -2
- package/template/apps/web/src/services/profile-api.ts +2 -2
- package/template/docs/architecture/durable-jobs.md +5 -0
- package/template/docs/architecture/module-manifest-composition.md +14 -7
- package/template/docs/architecture/object-storage.md +1 -1
- package/template/docs/development/crud-generator.md +4 -1
- package/template/docs/platform/audit-reliability.md +1 -1
- package/template/package.json +2 -1
- package/template/packages/config/package.json +15 -4
- package/template/packages/config/src/platform.ts +1 -1
- package/template/packages/crud-generator/package.json +1 -1
- package/template/packages/crud-generator/src/generator.test.ts +16 -0
- package/template/packages/crud-generator/src/templates/domain.ts +1 -1
- package/template/packages/crud-generator/src/templates/manifest.ts +2 -2
- package/template/packages/crud-generator/src/templates/project.ts +3 -3
- package/template/packages/crud-generator/src/templates/repository.ts +1 -1
- package/template/packages/crud-generator/src/templates/routes.ts +2 -2
- package/template/packages/crud-generator/src/validation.ts +22 -1
- package/template/packages/database/package.json +15 -5
- package/template/packages/database/src/bundle-validation.ts +218 -0
- package/template/packages/database/src/dialects.ts +1 -1
- package/template/packages/database/src/runner.test.ts +160 -13
- package/template/packages/database/src/runner.ts +95 -77
- package/template/packages/database/src/schema/governed-exports.ts +1 -1
- package/template/packages/database/src/schema/identity.ts +1 -1
- package/template/packages/database/src/schema/license-v1.ts +1 -1
- package/template/packages/database/src/schema/notifications.ts +1 -1
- package/template/packages/database/src/schema/platform-settings.ts +1 -1
- package/template/packages/database/src/schema/workflow.ts +1 -1
- package/template/packages/database/src/sql-store.ts +1 -1
- package/template/packages/database/src/store.ts +1 -1
- package/template/packages/example-work-order/index.ts +1 -0
- package/template/packages/example-work-order/package.json +4 -3
- package/template/packages/example-work-order/src/contract.ts +1 -1
- package/template/packages/example-work-order/src/manifest.ts +8 -3
- package/template/packages/example-work-order/src/migration-bundle.test.ts +43 -0
- package/template/packages/example-work-order/src/migration-bundle.ts +64 -0
- package/template/packages/jobs/index.ts +2 -0
- package/template/packages/jobs/package.json +29 -0
- package/template/packages/jobs/src/handlers.test.ts +72 -0
- package/template/{apps/server/src/jobs/handler-registry.ts → packages/jobs/src/handlers.ts} +4 -4
- package/template/{apps/server/src/jobs → packages/jobs/src}/types.ts +7 -1
- package/template/packages/{license-sdk → jobs}/tsconfig.json +0 -1
- package/template/packages/modules/index.ts +1 -1
- package/template/packages/modules/package.json +15 -5
- package/template/packages/modules/src/catalog-validation.ts +123 -0
- package/template/packages/modules/src/composition.test.ts +75 -2
- package/template/packages/modules/src/composition.ts +4 -2
- package/template/packages/modules/src/manifest.ts +7 -12
- package/template/packages/modules/src/menu-composition.ts +1 -1
- package/template/packages/modules/src/system-api-binding.ts +1 -1
- package/template/packages/modules/src/system-api-data-governance.ts +1 -1
- package/template/packages/modules/src/system-api-permissions.ts +1 -1
- package/template/packages/modules/src/system-data-governance.ts +1 -1
- package/template/packages/modules/src/system-features.ts +1 -1
- package/template/packages/modules/src/system-governed-export-bindings.ts +1 -1
- package/template/packages/modules/src/system-module-catalog.ts +1 -1
- package/template/packages/server-sdk/index.ts +5 -0
- package/template/packages/server-sdk/package.json +25 -0
- package/template/packages/server-sdk/src/module-host.ts +29 -0
- package/template/packages/server-sdk/tsconfig.json +16 -0
- package/template/packages/shared/index.ts +2 -0
- package/template/packages/shared/package.json +14 -3
- package/template/packages/shared/src/audit.ts +22 -1
- package/template/packages/shared/src/license-catalog.test.ts +17 -0
- package/template/packages/shared/src/license-catalog.ts +33 -0
- package/template/packages/shared/src/migration.ts +39 -0
- package/template/packages/storage/package.json +14 -3
- package/template/packages/license-sdk/index.ts +0 -13
- package/template/packages/license-sdk/package.json +0 -18
- package/template/packages/license-sdk/src/bounded-json-body.test.ts +0 -65
- package/template/packages/license-sdk/src/bounded-json-body.ts +0 -135
- package/template/packages/license-sdk/src/canonical-json.test.ts +0 -28
- package/template/packages/license-sdk/src/canonical-json.ts +0 -104
- package/template/packages/license-sdk/src/client.test.ts +0 -82
- package/template/packages/license-sdk/src/client.ts +0 -86
- package/template/packages/license-sdk/src/device.ts +0 -46
- package/template/packages/license-sdk/src/file-storage.test.ts +0 -80
- package/template/packages/license-sdk/src/file-storage.ts +0 -77
- package/template/packages/license-sdk/src/installation.test.ts +0 -241
- package/template/packages/license-sdk/src/installation.ts +0 -150
- package/template/packages/license-sdk/src/license-parser.ts +0 -56
- package/template/packages/license-sdk/src/offline-code-base32.ts +0 -57
- package/template/packages/license-sdk/src/offline-code-decompression.ts +0 -55
- package/template/packages/license-sdk/src/offline-code-limits.ts +0 -10
- package/template/packages/license-sdk/src/offline-code-wire.ts +0 -72
- package/template/packages/license-sdk/src/offline-code.test.ts +0 -172
- package/template/packages/license-sdk/src/offline-code.ts +0 -319
- package/template/packages/license-sdk/src/payload.test.ts +0 -72
- package/template/packages/license-sdk/src/payload.ts +0 -201
- package/template/packages/license-sdk/src/storage.ts +0 -64
- package/template/packages/license-sdk/src/test-fixtures.ts +0 -59
- package/template/packages/license-sdk/src/v1-test-vector.ts +0 -49
- package/template/packages/license-sdk/src/validation.test.ts +0 -62
- package/template/packages/license-sdk/src/validation.ts +0 -143
- package/template/packages/license-sdk/src/verification.test.ts +0 -97
- package/template/packages/license-sdk/src/verification.ts +0 -199
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { licenseKeys, licenses } from "@
|
|
1
|
+
import { licenseKeys, licenses } from "@southwind-ai/database";
|
|
2
2
|
import {
|
|
3
3
|
parseLicenseSigningDocument,
|
|
4
4
|
verifyLicensePayloadSignature,
|
|
5
|
-
} from "@
|
|
6
|
-
import type { LicenseV1Claims } from "@
|
|
5
|
+
} from "@southwind-ai/license";
|
|
6
|
+
import type { LicenseV1Claims } from "@southwind-ai/shared";
|
|
7
7
|
import { and, desc, eq, gt } from "drizzle-orm";
|
|
8
8
|
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
9
9
|
import type {
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
canonicalizeJson,
|
|
5
5
|
encodeOfflineActivationCode,
|
|
6
6
|
LICENSE_V1_TEST_VECTOR,
|
|
7
|
-
} from "@
|
|
8
|
-
import type { SignedLicenseV1 } from "@
|
|
7
|
+
} from "@southwind-ai/license";
|
|
8
|
+
import type { SignedLicenseV1 } from "@southwind-ai/shared";
|
|
9
9
|
import { registerPlatformLicenseRoutes } from "./routes.js";
|
|
10
10
|
import type { PlatformLicenseRuntime } from "./runtime-service.js";
|
|
11
11
|
|
|
@@ -3,12 +3,12 @@ import { describe, expect, test } from "bun:test";
|
|
|
3
3
|
import {
|
|
4
4
|
createLicenseSigningPayload,
|
|
5
5
|
MemoryAtomicLicenseStore,
|
|
6
|
-
} from "@
|
|
6
|
+
} from "@southwind-ai/license";
|
|
7
7
|
import {
|
|
8
8
|
licenseVersionKey,
|
|
9
9
|
type LicenseV1Claims,
|
|
10
10
|
type SignedLicenseV1,
|
|
11
|
-
} from "@
|
|
11
|
+
} from "@southwind-ai/shared";
|
|
12
12
|
import { MemoryAuditRecoveryQueue } from "../audit/recovery-queue.js";
|
|
13
13
|
import { ReliableAuditWriter } from "../audit/reliable-writer.js";
|
|
14
14
|
import { InMemoryAuditSink } from "../runtime.js";
|
|
@@ -3,12 +3,12 @@ import { describe, expect, test } from "bun:test";
|
|
|
3
3
|
import {
|
|
4
4
|
createLicenseSigningPayload,
|
|
5
5
|
MemoryAtomicLicenseStore,
|
|
6
|
-
} from "@
|
|
6
|
+
} from "@southwind-ai/license";
|
|
7
7
|
import {
|
|
8
8
|
licenseVersionKey,
|
|
9
9
|
type LicenseV1Claims,
|
|
10
10
|
type SignedLicenseV1,
|
|
11
|
-
} from "@
|
|
11
|
+
} from "@southwind-ai/shared";
|
|
12
12
|
import type { RequestActor } from "../guards.js";
|
|
13
13
|
import { PlatformLicenseRuntime } from "./runtime-service.js";
|
|
14
14
|
|
|
@@ -4,13 +4,13 @@ import { Elysia } from "elysia";
|
|
|
4
4
|
import {
|
|
5
5
|
createLicenseSigningPayload,
|
|
6
6
|
MemoryAtomicLicenseStore,
|
|
7
|
-
} from "@
|
|
7
|
+
} from "@southwind-ai/license";
|
|
8
8
|
import {
|
|
9
9
|
featureKey,
|
|
10
10
|
licenseVersionKey,
|
|
11
11
|
type LicenseV1Claims,
|
|
12
12
|
type SignedLicenseV1,
|
|
13
|
-
} from "@
|
|
13
|
+
} from "@southwind-ai/shared";
|
|
14
14
|
import { evaluateAccessGuards } from "../access-guards.js";
|
|
15
15
|
import {
|
|
16
16
|
createSystemToolHandlers,
|
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
type LicenseInstallResult,
|
|
12
12
|
type LicensePublicKeyMap,
|
|
13
13
|
type LicenseStorage,
|
|
14
|
-
} from "@
|
|
14
|
+
} from "@southwind-ai/license";
|
|
15
15
|
import type {
|
|
16
16
|
AuditEvent,
|
|
17
17
|
LicenseFailureReason,
|
|
18
18
|
SignedLicense,
|
|
19
|
-
} from "@
|
|
19
|
+
} from "@southwind-ai/shared";
|
|
20
20
|
import type { RequestActor } from "../guards.js";
|
|
21
21
|
import type { InMemoryAuditSink } from "../runtime.js";
|
|
22
22
|
import type {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import type { ModuleManifest } from "@
|
|
2
|
+
import type { ModuleManifest } from "@southwind-ai/modules";
|
|
3
3
|
import { Elysia } from "elysia";
|
|
4
4
|
import { validateServerModuleComposition } from "./module-composition.js";
|
|
5
5
|
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { DurableHandlerRegistry } from "@southwind-ai/jobs";
|
|
3
|
+
import type { ModuleInitializer } from "@southwind-ai/server-sdk";
|
|
4
|
+
import { workOrderModuleInitializer } from "./example-modules.js";
|
|
5
|
+
import { initializeModuleHosts } from "./module-host.js";
|
|
6
|
+
import {
|
|
7
|
+
createStorageRuntime,
|
|
8
|
+
platformUploadPolicies,
|
|
9
|
+
} from "./storage/runtime.js";
|
|
10
|
+
|
|
11
|
+
describe("模块 Host 初始化", () => {
|
|
12
|
+
test("按安装顺序完成初始化后再创建运行时注册表", async () => {
|
|
13
|
+
const events: string[] = [];
|
|
14
|
+
const first = initializer("alpha", async (host) => {
|
|
15
|
+
events.push("alpha:start");
|
|
16
|
+
await Promise.resolve();
|
|
17
|
+
host.registerDurableHandler({
|
|
18
|
+
key: "alpha.refresh",
|
|
19
|
+
payload: { parse: () => ({}) },
|
|
20
|
+
execute: () => undefined,
|
|
21
|
+
});
|
|
22
|
+
events.push("alpha:end");
|
|
23
|
+
});
|
|
24
|
+
const second = initializer("beta", () => {
|
|
25
|
+
events.push("beta");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const initialized = await initializeModuleHosts({
|
|
29
|
+
modules: [{ name: "alpha" }, { name: "beta" }],
|
|
30
|
+
initializers: [first, second],
|
|
31
|
+
});
|
|
32
|
+
expect(events).toEqual(["alpha:start", "alpha:end", "beta"]);
|
|
33
|
+
|
|
34
|
+
const registry = new DurableHandlerRegistry();
|
|
35
|
+
initialized.installDurableHandlers(registry);
|
|
36
|
+
expect(registry.keys()).toEqual(["alpha.refresh"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("未知模块、错误命名空间和重复注册立即失败", async () => {
|
|
40
|
+
await expect(
|
|
41
|
+
initializeModuleHosts({
|
|
42
|
+
modules: [{ name: "known" }],
|
|
43
|
+
initializers: [initializer("missing", () => undefined)],
|
|
44
|
+
}),
|
|
45
|
+
).rejects.toThrow("模块初始化器与已安装模块不匹配:missing");
|
|
46
|
+
|
|
47
|
+
await expect(
|
|
48
|
+
initializeModuleHosts({
|
|
49
|
+
modules: [{ name: "known" }],
|
|
50
|
+
initializers: [
|
|
51
|
+
initializer("known", (host) => {
|
|
52
|
+
host.registerUploadPolicy(policy("other.attachment"));
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
).rejects.toThrow("上传用途不属于模块 known:other.attachment");
|
|
57
|
+
|
|
58
|
+
await expect(
|
|
59
|
+
initializeModuleHosts({
|
|
60
|
+
modules: [{ name: "known" }],
|
|
61
|
+
initializers: [
|
|
62
|
+
initializer("known", (host) => {
|
|
63
|
+
host.registerUploadPolicy(policy("known.attachment"));
|
|
64
|
+
host.registerUploadPolicy(policy("known.attachment"));
|
|
65
|
+
}),
|
|
66
|
+
],
|
|
67
|
+
}),
|
|
68
|
+
).rejects.toThrow("上传用途重复注册:known.attachment");
|
|
69
|
+
|
|
70
|
+
await expect(
|
|
71
|
+
initializeModuleHosts({
|
|
72
|
+
modules: [],
|
|
73
|
+
initializers: [],
|
|
74
|
+
baseUploadPolicies: [policy("platform.file"), policy("platform.file")],
|
|
75
|
+
}),
|
|
76
|
+
).rejects.toThrow("上传用途重复注册:platform.file");
|
|
77
|
+
|
|
78
|
+
await expect(
|
|
79
|
+
initializeModuleHosts({
|
|
80
|
+
modules: [{ name: "known" }],
|
|
81
|
+
initializers: [
|
|
82
|
+
initializer("known", (host) => {
|
|
83
|
+
const definition = {
|
|
84
|
+
key: "known.refresh",
|
|
85
|
+
payload: { parse: () => ({}) },
|
|
86
|
+
execute: () => undefined,
|
|
87
|
+
};
|
|
88
|
+
host.registerDurableHandler(definition);
|
|
89
|
+
host.registerDurableHandler(definition);
|
|
90
|
+
}),
|
|
91
|
+
],
|
|
92
|
+
}),
|
|
93
|
+
).rejects.toThrow("任务 handler 重复注册:known.refresh");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("work-order 附件策略只随模块初始化并被上传运行时采用", async () => {
|
|
97
|
+
const withoutWorkOrder = await initializeModuleHosts({
|
|
98
|
+
modules: [],
|
|
99
|
+
initializers: [],
|
|
100
|
+
baseUploadPolicies: platformUploadPolicies,
|
|
101
|
+
});
|
|
102
|
+
expect(
|
|
103
|
+
withoutWorkOrder.uploadPolicies.some(
|
|
104
|
+
({ purpose }) => purpose === "work-order.ticket.attachment",
|
|
105
|
+
),
|
|
106
|
+
).toBe(false);
|
|
107
|
+
|
|
108
|
+
const withWorkOrder = await initializeModuleHosts({
|
|
109
|
+
modules: [{ name: "work-order" }],
|
|
110
|
+
initializers: [workOrderModuleInitializer],
|
|
111
|
+
baseUploadPolicies: platformUploadPolicies,
|
|
112
|
+
});
|
|
113
|
+
const storage = createStorageRuntime(
|
|
114
|
+
{},
|
|
115
|
+
undefined,
|
|
116
|
+
withWorkOrder.uploadPolicies,
|
|
117
|
+
);
|
|
118
|
+
const session = await storage.uploads.create({
|
|
119
|
+
ownerId: "user-1",
|
|
120
|
+
purpose: "work-order.ticket.attachment",
|
|
121
|
+
filename: "现场照片.jpg",
|
|
122
|
+
mimeType: "image/jpeg",
|
|
123
|
+
expectedByteSize: 1024,
|
|
124
|
+
});
|
|
125
|
+
expect(session.purpose).toBe("work-order.ticket.attachment");
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
function initializer(
|
|
130
|
+
moduleName: string,
|
|
131
|
+
initialize: ModuleInitializer["initialize"],
|
|
132
|
+
): ModuleInitializer {
|
|
133
|
+
return { moduleName, initialize };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function policy(purpose: string) {
|
|
137
|
+
return {
|
|
138
|
+
purpose,
|
|
139
|
+
maxByteSize: 1024,
|
|
140
|
+
maxPartByteSize: 512,
|
|
141
|
+
sessionTtlMs: 60_000,
|
|
142
|
+
allowedTypes: { "text/plain": ["txt"] },
|
|
143
|
+
signature: "none" as const,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DurableHandlerRegistry,
|
|
3
|
+
type DurableHandlerDefinition,
|
|
4
|
+
} from "@southwind-ai/jobs";
|
|
5
|
+
import type { ModuleHost, ModuleInitializer } from "@southwind-ai/server-sdk";
|
|
6
|
+
import type { UploadPolicy } from "@southwind-ai/storage";
|
|
7
|
+
|
|
8
|
+
interface InstalledModule {
|
|
9
|
+
name: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface InitializeModuleHostsInput {
|
|
13
|
+
modules: readonly InstalledModule[];
|
|
14
|
+
initializers: readonly ModuleInitializer[];
|
|
15
|
+
baseUploadPolicies?: readonly UploadPolicy[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface InitializedModuleHosts {
|
|
19
|
+
readonly uploadPolicies: readonly UploadPolicy[];
|
|
20
|
+
installDurableHandlers(registry: DurableHandlerRegistry): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type HandlerInstaller = (registry: DurableHandlerRegistry) => void;
|
|
24
|
+
|
|
25
|
+
export async function initializeModuleHosts(
|
|
26
|
+
input: InitializeModuleHostsInput,
|
|
27
|
+
): Promise<InitializedModuleHosts> {
|
|
28
|
+
const installedNames = new Set(input.modules.map(({ name }) => name));
|
|
29
|
+
const initializedNames = new Set<string>();
|
|
30
|
+
const uploadPolicies: UploadPolicy[] = [];
|
|
31
|
+
const uploadPurposes = new Set<string>();
|
|
32
|
+
for (const policy of input.baseUploadPolicies ?? []) {
|
|
33
|
+
if (uploadPurposes.has(policy.purpose)) {
|
|
34
|
+
throw new Error(`上传用途重复注册:${policy.purpose}`);
|
|
35
|
+
}
|
|
36
|
+
uploadPurposes.add(policy.purpose);
|
|
37
|
+
uploadPolicies.push(policy);
|
|
38
|
+
}
|
|
39
|
+
const handlerKeys = new Set<string>();
|
|
40
|
+
const handlerInstallers: HandlerInstaller[] = [];
|
|
41
|
+
|
|
42
|
+
for (const initializer of input.initializers) {
|
|
43
|
+
const moduleName = initializer.moduleName.trim();
|
|
44
|
+
if (!installedNames.has(moduleName)) {
|
|
45
|
+
throw new Error(`模块初始化器与已安装模块不匹配:${moduleName}`);
|
|
46
|
+
}
|
|
47
|
+
if (initializedNames.has(moduleName)) {
|
|
48
|
+
throw new Error(`模块初始化器重复注册:${moduleName}`);
|
|
49
|
+
}
|
|
50
|
+
initializedNames.add(moduleName);
|
|
51
|
+
await initializer.initialize(
|
|
52
|
+
createScopedHost({
|
|
53
|
+
moduleName,
|
|
54
|
+
uploadPolicies,
|
|
55
|
+
uploadPurposes,
|
|
56
|
+
handlerKeys,
|
|
57
|
+
handlerInstallers,
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
uploadPolicies: [...uploadPolicies],
|
|
64
|
+
installDurableHandlers(registry) {
|
|
65
|
+
for (const install of handlerInstallers) install(registry);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface ScopedHostState {
|
|
71
|
+
moduleName: string;
|
|
72
|
+
uploadPolicies: UploadPolicy[];
|
|
73
|
+
uploadPurposes: Set<string>;
|
|
74
|
+
handlerKeys: Set<string>;
|
|
75
|
+
handlerInstallers: HandlerInstaller[];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createScopedHost(state: ScopedHostState): ModuleHost {
|
|
79
|
+
return {
|
|
80
|
+
moduleName: state.moduleName,
|
|
81
|
+
registerUploadPolicy(policy) {
|
|
82
|
+
requireModuleNamespace("上传用途", policy.purpose, state.moduleName);
|
|
83
|
+
if (state.uploadPurposes.has(policy.purpose)) {
|
|
84
|
+
throw new Error(`上传用途重复注册:${policy.purpose}`);
|
|
85
|
+
}
|
|
86
|
+
state.uploadPurposes.add(policy.purpose);
|
|
87
|
+
state.uploadPolicies.push(policy);
|
|
88
|
+
},
|
|
89
|
+
registerDurableHandler<T>(definition: DurableHandlerDefinition<T>) {
|
|
90
|
+
requireModuleNamespace("任务 handler", definition.key, state.moduleName);
|
|
91
|
+
if (state.handlerKeys.has(definition.key)) {
|
|
92
|
+
throw new Error(`任务 handler 重复注册:${definition.key}`);
|
|
93
|
+
}
|
|
94
|
+
state.handlerKeys.add(definition.key);
|
|
95
|
+
state.handlerInstallers.push((registry) => {
|
|
96
|
+
registry.register(definition);
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function requireModuleNamespace(
|
|
103
|
+
kind: string,
|
|
104
|
+
value: string,
|
|
105
|
+
moduleName: string,
|
|
106
|
+
): void {
|
|
107
|
+
if (value !== moduleName && !value.startsWith(`${moduleName}.`)) {
|
|
108
|
+
throw new Error(`${kind}不属于模块 ${moduleName}:${value}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { notificationReads, platformNotifications } from "@
|
|
1
|
+
import { notificationReads, platformNotifications } from "@southwind-ai/database";
|
|
2
2
|
import type {
|
|
3
3
|
NotificationInboxItem,
|
|
4
4
|
PageResult,
|
|
5
5
|
PlatformNotification,
|
|
6
6
|
PublishNotificationInput,
|
|
7
|
-
} from "@
|
|
7
|
+
} from "@southwind-ai/shared";
|
|
8
8
|
import { and, desc, eq, ilike, isNull, or, sql, type SQL } from "drizzle-orm";
|
|
9
9
|
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
10
10
|
import type { RequestActor } from "../guards.js";
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
FeatureFlagDefinition,
|
|
5
5
|
HttpMethod,
|
|
6
6
|
PublishNotificationInput,
|
|
7
|
-
} from "@
|
|
7
|
+
} from "@southwind-ai/shared";
|
|
8
8
|
import type { RequestGuardContext } from "../guards.js";
|
|
9
9
|
import { evaluateRouteGuards, findSystemFeature } from "../route-guards.js";
|
|
10
10
|
import type { createServerRuntime } from "../runtime.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
|
-
import type { AuditEvent } from "@
|
|
2
|
+
import type { AuditEvent } from "@southwind-ai/shared";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
5
5
|
import { migrate } from "drizzle-orm/node-postgres/migrator";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PlatformConfig } from "@
|
|
1
|
+
import type { PlatformConfig } from "@southwind-ai/config";
|
|
2
2
|
import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
3
3
|
import { Pool } from "pg";
|
|
4
4
|
import type { AuditWriteStatus } from "./audit/contracts.js";
|
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
FeatureFlagDefinition,
|
|
4
4
|
UserProfile,
|
|
5
5
|
UserProfileUpdate,
|
|
6
|
-
} from "@
|
|
6
|
+
} from "@southwind-ai/shared";
|
|
7
7
|
import { recordMutationAudit } from "../audit/policy.js";
|
|
8
8
|
import type { AuthRepository, AuthUserRecord } from "../auth/repository.js";
|
|
9
9
|
import { evaluateRouteGuards, findFeature } from "../route-guards.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { entitlementKey, featureKey } from "@
|
|
2
|
+
import { entitlementKey, featureKey } from "@southwind-ai/shared";
|
|
3
3
|
import { evaluateAccessGuards } from "./access-guards.js";
|
|
4
4
|
import { createServerRuntime } from "./runtime.js";
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ApiPermissionBinding,
|
|
3
3
|
FeatureFlagDefinition,
|
|
4
|
-
} from "@
|
|
4
|
+
} from "@southwind-ai/shared";
|
|
5
5
|
import { evaluateAccessGuards } from "./access-guards.js";
|
|
6
6
|
import type { GuardDecision, RequestGuardContext } from "./guards.js";
|
|
7
7
|
import type { createServerRuntime } from "./runtime.js";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { FeatureFlagDefinition } from "@southwind-ai/shared";
|
|
2
|
+
|
|
3
|
+
export interface FeatureFlagRuntimeResolver {
|
|
4
|
+
resolve(
|
|
5
|
+
key: string,
|
|
6
|
+
):
|
|
7
|
+
| Promise<FeatureFlagRuntimeState | undefined>
|
|
8
|
+
| FeatureFlagRuntimeState
|
|
9
|
+
| undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface FeatureFlagRuntimeState {
|
|
13
|
+
key: string;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
visible: FeatureFlagDefinition["visible"];
|
|
16
|
+
allowedLicenseVersions?: FeatureFlagDefinition["allowedLicenseVersions"];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class RuntimeFeatureCatalog {
|
|
20
|
+
private readonly definitions = new Map<string, FeatureFlagDefinition>();
|
|
21
|
+
private readonly requestCache = new WeakMap<
|
|
22
|
+
object,
|
|
23
|
+
Map<string, FeatureFlagDefinition>
|
|
24
|
+
>();
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
definitions: readonly FeatureFlagDefinition[],
|
|
28
|
+
private readonly resolver: FeatureFlagRuntimeResolver | undefined,
|
|
29
|
+
private readonly production: boolean,
|
|
30
|
+
) {
|
|
31
|
+
for (const definition of definitions) {
|
|
32
|
+
this.definitions.set(definition.key, definition);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
resolve(
|
|
37
|
+
context: object,
|
|
38
|
+
manifestFeature: FeatureFlagDefinition,
|
|
39
|
+
): Promise<FeatureFlagDefinition> {
|
|
40
|
+
this.definitions.set(manifestFeature.key, manifestFeature);
|
|
41
|
+
return this.resolveInternal(context, manifestFeature, new Set());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private async resolveInternal(
|
|
45
|
+
context: object,
|
|
46
|
+
manifestFeature: FeatureFlagDefinition,
|
|
47
|
+
visiting: ReadonlySet<string>,
|
|
48
|
+
): Promise<FeatureFlagDefinition> {
|
|
49
|
+
const cache = this.cacheFor(context);
|
|
50
|
+
const cached = cache.get(manifestFeature.key);
|
|
51
|
+
if (cached) return cached;
|
|
52
|
+
if (visiting.has(manifestFeature.key)) {
|
|
53
|
+
return disabledFeature(manifestFeature);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const resolved = await this.resolveOwnState(manifestFeature);
|
|
57
|
+
if (!resolved.enabled || !manifestFeature.dependencies?.length) {
|
|
58
|
+
cache.set(manifestFeature.key, resolved);
|
|
59
|
+
return resolved;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const nextVisiting = new Set(visiting);
|
|
63
|
+
nextVisiting.add(manifestFeature.key);
|
|
64
|
+
for (const dependencyKey of manifestFeature.dependencies) {
|
|
65
|
+
const dependency = this.definitions.get(dependencyKey);
|
|
66
|
+
if (!dependency) {
|
|
67
|
+
const disabled = disabledFeature(resolved);
|
|
68
|
+
cache.set(manifestFeature.key, disabled);
|
|
69
|
+
return disabled;
|
|
70
|
+
}
|
|
71
|
+
const dependencyState = await this.resolveInternal(
|
|
72
|
+
context,
|
|
73
|
+
dependency,
|
|
74
|
+
nextVisiting,
|
|
75
|
+
);
|
|
76
|
+
if (!dependencyState.enabled || dependencyState.visible !== "visible") {
|
|
77
|
+
const disabled = { ...resolved, enabled: false };
|
|
78
|
+
cache.set(manifestFeature.key, disabled);
|
|
79
|
+
return disabled;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
cache.set(manifestFeature.key, resolved);
|
|
84
|
+
return resolved;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private async resolveOwnState(
|
|
88
|
+
manifestFeature: FeatureFlagDefinition,
|
|
89
|
+
): Promise<FeatureFlagDefinition> {
|
|
90
|
+
if (!this.resolver) {
|
|
91
|
+
return this.production
|
|
92
|
+
? disabledFeature(manifestFeature)
|
|
93
|
+
: manifestFeature;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const state = await this.resolver.resolve(manifestFeature.key);
|
|
97
|
+
if (!state) return disabledFeature(manifestFeature);
|
|
98
|
+
return {
|
|
99
|
+
...manifestFeature,
|
|
100
|
+
enabled: state.enabled,
|
|
101
|
+
visible: state.visible,
|
|
102
|
+
...(Object.hasOwn(state, "allowedLicenseVersions")
|
|
103
|
+
? { allowedLicenseVersions: state.allowedLicenseVersions }
|
|
104
|
+
: {}),
|
|
105
|
+
};
|
|
106
|
+
} catch {
|
|
107
|
+
return disabledFeature(manifestFeature);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private cacheFor(context: object): Map<string, FeatureFlagDefinition> {
|
|
112
|
+
let cache = this.requestCache.get(context);
|
|
113
|
+
if (!cache) {
|
|
114
|
+
cache = new Map();
|
|
115
|
+
this.requestCache.set(context, cache);
|
|
116
|
+
}
|
|
117
|
+
return cache;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function disabledFeature(
|
|
122
|
+
feature: FeatureFlagDefinition,
|
|
123
|
+
): FeatureFlagDefinition {
|
|
124
|
+
return { ...feature, enabled: false, visible: "hidden" };
|
|
125
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { randomUUIDv7 } from "bun";
|
|
2
2
|
import { describe, expect, test } from "bun:test";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
entitlementKey,
|
|
5
|
+
featureKey,
|
|
6
|
+
type AuditEvent,
|
|
7
|
+
type FeatureFlagDefinition,
|
|
8
|
+
} from "@southwind-ai/shared";
|
|
4
9
|
import { createFoundationSnapshot } from "./foundation.js";
|
|
5
10
|
import { createServerRuntime } from "./runtime.js";
|
|
6
11
|
import { AuditWriteUnavailableError } from "./audit/contracts.js";
|
|
@@ -240,6 +245,37 @@ describe("server runtime", () => {
|
|
|
240
245
|
});
|
|
241
246
|
});
|
|
242
247
|
|
|
248
|
+
test("Feature 依赖在运行时实际 fail closed", async () => {
|
|
249
|
+
const dependency = runtimeFeature("business.base");
|
|
250
|
+
const capability = {
|
|
251
|
+
...runtimeFeature("business.report"),
|
|
252
|
+
dependencies: [dependency.key],
|
|
253
|
+
};
|
|
254
|
+
const runtime = createServerRuntime(
|
|
255
|
+
{},
|
|
256
|
+
{
|
|
257
|
+
featureCatalog: [dependency, capability],
|
|
258
|
+
featureResolver: {
|
|
259
|
+
resolve(key) {
|
|
260
|
+
return {
|
|
261
|
+
key,
|
|
262
|
+
enabled: key !== dependency.key,
|
|
263
|
+
visible: "visible",
|
|
264
|
+
};
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
const context = await runtime.createGuardContext(
|
|
270
|
+
new Request("http://localhost/api/business/report"),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(await runtime.resolveFeature(context, capability)).toMatchObject({
|
|
274
|
+
enabled: false,
|
|
275
|
+
visible: "visible",
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
243
279
|
test("数据库运行态读取失败时 fail closed", async () => {
|
|
244
280
|
const manifest = createFoundationSnapshot().features[0]!;
|
|
245
281
|
const runtime = createServerRuntime(
|
|
@@ -262,3 +298,14 @@ describe("server runtime", () => {
|
|
|
262
298
|
});
|
|
263
299
|
});
|
|
264
300
|
});
|
|
301
|
+
|
|
302
|
+
function runtimeFeature(key: string): FeatureFlagDefinition {
|
|
303
|
+
return {
|
|
304
|
+
key: featureKey(key),
|
|
305
|
+
label: key,
|
|
306
|
+
module: "business",
|
|
307
|
+
visible: "visible",
|
|
308
|
+
enabled: true,
|
|
309
|
+
stage: "stable",
|
|
310
|
+
};
|
|
311
|
+
}
|