create-windy 0.2.6 → 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 +14 -3
- package/dist/cli.js +191 -87
- package/package.json +1 -1
- package/template/.windy-template.json +2 -2
- package/template/README.md +8 -0
- 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 -4
- 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 +52 -7
- package/template/apps/web/src/components/auth/PasswordChangeForm.webtest.ts +43 -0
- 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 +3 -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/shared/src/password.ts +4 -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,104 +0,0 @@
|
|
|
1
|
-
export type CanonicalJsonPrimitive = string | number | boolean | null;
|
|
2
|
-
export type CanonicalJsonValue =
|
|
3
|
-
| CanonicalJsonPrimitive
|
|
4
|
-
| CanonicalJsonValue[]
|
|
5
|
-
| { [key: string]: CanonicalJsonValue };
|
|
6
|
-
|
|
7
|
-
export type CanonicalJsonErrorCode =
|
|
8
|
-
| "CANONICAL_JSON_INVALID_TYPE"
|
|
9
|
-
| "CANONICAL_JSON_INVALID_NUMBER"
|
|
10
|
-
| "CANONICAL_JSON_INVALID_UNICODE"
|
|
11
|
-
| "CANONICAL_JSON_CYCLE";
|
|
12
|
-
|
|
13
|
-
export class CanonicalJsonError extends Error {
|
|
14
|
-
constructor(
|
|
15
|
-
readonly code: CanonicalJsonErrorCode,
|
|
16
|
-
message: string,
|
|
17
|
-
) {
|
|
18
|
-
super(message);
|
|
19
|
-
this.name = "CanonicalJsonError";
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* RFC 8785 JSON Canonicalization Scheme (JCS) serializer.
|
|
25
|
-
*
|
|
26
|
-
* V1 intentionally accepts JSON values only: no undefined, BigInt, custom
|
|
27
|
-
* toJSON conversion, non-finite numbers, or unpaired UTF-16 surrogates.
|
|
28
|
-
*/
|
|
29
|
-
export function canonicalizeJson(value: unknown): string {
|
|
30
|
-
return serialize(value, new Set<object>());
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function serialize(value: unknown, ancestors: Set<object>): string {
|
|
34
|
-
if (value === null) return "null";
|
|
35
|
-
if (typeof value === "boolean") return value ? "true" : "false";
|
|
36
|
-
if (typeof value === "string") return serializeString(value);
|
|
37
|
-
if (typeof value === "number") return serializeNumber(value);
|
|
38
|
-
if (typeof value !== "object") {
|
|
39
|
-
throw new CanonicalJsonError(
|
|
40
|
-
"CANONICAL_JSON_INVALID_TYPE",
|
|
41
|
-
`JCS 不支持 ${typeof value} 值`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
if (ancestors.has(value)) {
|
|
45
|
-
throw new CanonicalJsonError("CANONICAL_JSON_CYCLE", "JCS 不支持循环引用");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
ancestors.add(value);
|
|
49
|
-
try {
|
|
50
|
-
if (Array.isArray(value)) {
|
|
51
|
-
return `[${value.map((item) => serialize(item, ancestors)).join(",")}]`;
|
|
52
|
-
}
|
|
53
|
-
const object = value as Record<string, unknown>;
|
|
54
|
-
const members = Object.keys(object)
|
|
55
|
-
.sort(compareUtf16)
|
|
56
|
-
.map(
|
|
57
|
-
(key) => `${serializeString(key)}:${serialize(object[key], ancestors)}`,
|
|
58
|
-
);
|
|
59
|
-
return `{${members.join(",")}}`;
|
|
60
|
-
} finally {
|
|
61
|
-
ancestors.delete(value);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function serializeNumber(value: number): string {
|
|
66
|
-
if (!Number.isFinite(value)) {
|
|
67
|
-
throw new CanonicalJsonError(
|
|
68
|
-
"CANONICAL_JSON_INVALID_NUMBER",
|
|
69
|
-
"JCS 不支持 NaN 或无穷大",
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return JSON.stringify(value);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function serializeString(value: string): string {
|
|
76
|
-
assertUnicodeScalarSequence(value);
|
|
77
|
-
return JSON.stringify(value);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function assertUnicodeScalarSequence(value: string): void {
|
|
81
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
82
|
-
const code = value.charCodeAt(index);
|
|
83
|
-
if (code >= 0xd800 && code <= 0xdbff) {
|
|
84
|
-
const next = value.charCodeAt(index + 1);
|
|
85
|
-
if (!Number.isFinite(next) || next < 0xdc00 || next > 0xdfff) {
|
|
86
|
-
invalidUnicode();
|
|
87
|
-
}
|
|
88
|
-
index += 1;
|
|
89
|
-
} else if (code >= 0xdc00 && code <= 0xdfff) {
|
|
90
|
-
invalidUnicode();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function invalidUnicode(): never {
|
|
96
|
-
throw new CanonicalJsonError(
|
|
97
|
-
"CANONICAL_JSON_INVALID_UNICODE",
|
|
98
|
-
"JCS 不支持未配对的 UTF-16 surrogate",
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function compareUtf16(left: string, right: string): number {
|
|
103
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
104
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { WindyLicenseClient } from "./client.js";
|
|
3
|
-
import { MemoryAtomicLicenseStore, MemoryLicenseStorage } from "./storage.js";
|
|
4
|
-
import { LICENSE_V1_TEST_VECTOR } from "./v1-test-vector.js";
|
|
5
|
-
|
|
6
|
-
const vectorLicense = JSON.stringify({
|
|
7
|
-
formatVersion: 1,
|
|
8
|
-
algorithm: "ED25519",
|
|
9
|
-
publicKeyId: LICENSE_V1_TEST_VECTOR.keyId,
|
|
10
|
-
claims: LICENSE_V1_TEST_VECTOR.claims,
|
|
11
|
-
signature: LICENSE_V1_TEST_VECTOR.signature,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe("WindyLicenseClient", () => {
|
|
15
|
-
test("使用固定向量和多公钥环打开 V1 License", async () => {
|
|
16
|
-
const client = new WindyLicenseClient({
|
|
17
|
-
licenseSource: new MemoryAtomicLicenseStore(vectorLicense),
|
|
18
|
-
stateStorage: new MemoryLicenseStorage(),
|
|
19
|
-
productCode: "windy-platform",
|
|
20
|
-
machineCode: "machine-vector-001",
|
|
21
|
-
publicKeys: {
|
|
22
|
-
unrelated: LICENSE_V1_TEST_VECTOR.publicKeyPem,
|
|
23
|
-
[LICENSE_V1_TEST_VECTOR.keyId]: LICENSE_V1_TEST_VECTOR.publicKeyPem,
|
|
24
|
-
},
|
|
25
|
-
now: () => new Date("2026-07-10T10:00:00.000Z"),
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const result = await client.recordOpen();
|
|
29
|
-
|
|
30
|
-
expect(result.valid).toBe(true);
|
|
31
|
-
expect(result.failures).toEqual([]);
|
|
32
|
-
expect(result.license?.claims.licenseId).toBe("license_vector_v1");
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test("未知 publicKeyId 时拒绝运行", async () => {
|
|
36
|
-
const client = new WindyLicenseClient({
|
|
37
|
-
licenseSource: new MemoryAtomicLicenseStore(vectorLicense),
|
|
38
|
-
stateStorage: new MemoryLicenseStorage(),
|
|
39
|
-
productCode: "windy-platform",
|
|
40
|
-
machineCode: "machine-vector-001",
|
|
41
|
-
publicKeys: {},
|
|
42
|
-
now: () => new Date("2026-07-10T10:00:00.000Z"),
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const result = await client.recordOpen();
|
|
46
|
-
|
|
47
|
-
expect(result.valid).toBe(false);
|
|
48
|
-
expect(result.failures).toEqual(["unknown-public-key"]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("明显回拨持续暂停,小幅 NTP 偏差不误判且时间恢复后自动恢复", async () => {
|
|
52
|
-
let now = new Date("2026-07-10T10:00:00.000Z");
|
|
53
|
-
const state = new MemoryLicenseStorage();
|
|
54
|
-
const client = new WindyLicenseClient({
|
|
55
|
-
licenseSource: new MemoryAtomicLicenseStore(vectorLicense),
|
|
56
|
-
stateStorage: state,
|
|
57
|
-
productCode: "windy-platform",
|
|
58
|
-
machineCode: "machine-vector-001",
|
|
59
|
-
publicKeys: {
|
|
60
|
-
[LICENSE_V1_TEST_VECTOR.keyId]: LICENSE_V1_TEST_VECTOR.publicKeyPem,
|
|
61
|
-
},
|
|
62
|
-
clockToleranceMs: 5 * 60 * 1000,
|
|
63
|
-
now: () => now,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
expect((await client.recordOpen()).valid).toBe(true);
|
|
67
|
-
now = new Date("2026-07-10T09:54:00.000Z");
|
|
68
|
-
expect((await client.recordOpen()).failures).toContain("clock-rollback");
|
|
69
|
-
expect(await state.read("last-trusted-at")).toBe(
|
|
70
|
-
"2026-07-10T10:00:00.000Z",
|
|
71
|
-
);
|
|
72
|
-
expect((await client.recordOpen()).failures).toContain("clock-rollback");
|
|
73
|
-
|
|
74
|
-
now = new Date("2026-07-10T09:58:00.000Z");
|
|
75
|
-
const recovered = await client.recordOpen();
|
|
76
|
-
expect(recovered.valid).toBe(true);
|
|
77
|
-
expect(recovered.failures).not.toContain("clock-rollback");
|
|
78
|
-
expect(await state.read("last-trusted-at")).toBe(
|
|
79
|
-
"2026-07-10T10:00:00.000Z",
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
LicenseFailureReason,
|
|
3
|
-
LicenseUsageRecord,
|
|
4
|
-
SignedLicense,
|
|
5
|
-
} from "@windy/shared";
|
|
6
|
-
import type { LicenseSource, LicenseStorage } from "./storage.js";
|
|
7
|
-
import type { LicensePublicKeySource } from "./verification.js";
|
|
8
|
-
import { parseSignedLicense, validateLicenseDocument } from "./validation.js";
|
|
9
|
-
|
|
10
|
-
export interface LicenseClientOptions {
|
|
11
|
-
licenseSource: LicenseSource;
|
|
12
|
-
stateStorage: LicenseStorage;
|
|
13
|
-
productCode: string;
|
|
14
|
-
machineCode: string;
|
|
15
|
-
publicKeys: LicensePublicKeySource;
|
|
16
|
-
now?: () => Date;
|
|
17
|
-
clockToleranceMs?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface LicenseOpenResult {
|
|
21
|
-
valid: boolean;
|
|
22
|
-
license?: SignedLicense;
|
|
23
|
-
usage: LicenseUsageRecord;
|
|
24
|
-
failures: LicenseFailureReason[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const LAST_TRUSTED_AT_KEY = "last-trusted-at";
|
|
28
|
-
|
|
29
|
-
export class WindyLicenseClient {
|
|
30
|
-
private readonly now: () => Date;
|
|
31
|
-
|
|
32
|
-
constructor(private readonly options: LicenseClientOptions) {
|
|
33
|
-
this.now = options.now ?? (() => new Date());
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async readLicense(): Promise<SignedLicense | undefined> {
|
|
37
|
-
const rawLicense = await this.options.licenseSource.readCurrent();
|
|
38
|
-
return rawLicense ? parseSignedLicense(rawLicense) : undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async recordOpen(): Promise<LicenseOpenResult> {
|
|
42
|
-
const openedAt = this.now();
|
|
43
|
-
const rawLicense = await this.options.licenseSource.readCurrent();
|
|
44
|
-
const previousOpenedAt =
|
|
45
|
-
await this.options.stateStorage.read(LAST_TRUSTED_AT_KEY);
|
|
46
|
-
|
|
47
|
-
if (!rawLicense) {
|
|
48
|
-
return {
|
|
49
|
-
valid: false,
|
|
50
|
-
failures: ["invalid-format"],
|
|
51
|
-
usage: {
|
|
52
|
-
machineCode: this.options.machineCode,
|
|
53
|
-
openedAt: openedAt.toISOString(),
|
|
54
|
-
previousOpenedAt,
|
|
55
|
-
status: "invalid",
|
|
56
|
-
reason: "invalid-format",
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const result = await validateLicenseDocument(rawLicense, {
|
|
62
|
-
productCode: this.options.productCode,
|
|
63
|
-
machineCode: this.options.machineCode,
|
|
64
|
-
publicKeys: this.options.publicKeys,
|
|
65
|
-
now: openedAt,
|
|
66
|
-
lastTrustedAt: previousOpenedAt,
|
|
67
|
-
clockToleranceMs: this.options.clockToleranceMs,
|
|
68
|
-
});
|
|
69
|
-
if (
|
|
70
|
-
!result.failures.includes("clock-rollback") &&
|
|
71
|
-
result.nextTrustedAt &&
|
|
72
|
-
result.nextTrustedAt !== previousOpenedAt
|
|
73
|
-
) {
|
|
74
|
-
await this.options.stateStorage.write(
|
|
75
|
-
LAST_TRUSTED_AT_KEY,
|
|
76
|
-
result.nextTrustedAt,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
valid: result.valid,
|
|
81
|
-
license: result.license,
|
|
82
|
-
failures: result.failures,
|
|
83
|
-
usage: result.usage,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export interface DeviceCodeParts {
|
|
2
|
-
hostname?: string;
|
|
3
|
-
platform?: string;
|
|
4
|
-
arch?: string;
|
|
5
|
-
tenant?: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function createDeviceCode(parts: DeviceCodeParts): string {
|
|
9
|
-
const stableParts = [
|
|
10
|
-
parts.hostname || "unknown-host",
|
|
11
|
-
parts.platform || "unknown-platform",
|
|
12
|
-
parts.arch || "unknown-arch",
|
|
13
|
-
parts.tenant || "default",
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
return btoaSafe(stableParts.join("|"));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function createDeviceQrPayload(machineCode: string): string {
|
|
20
|
-
return JSON.stringify({
|
|
21
|
-
type: "windy-device-code",
|
|
22
|
-
version: 1,
|
|
23
|
-
machineCode,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function readDeviceCodeFromQrPayload(
|
|
28
|
-
payload: string,
|
|
29
|
-
): string | undefined {
|
|
30
|
-
try {
|
|
31
|
-
const parsed = JSON.parse(payload) as { machineCode?: unknown };
|
|
32
|
-
return typeof parsed.machineCode === "string"
|
|
33
|
-
? parsed.machineCode
|
|
34
|
-
: undefined;
|
|
35
|
-
} catch {
|
|
36
|
-
return payload.trim() || undefined;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function btoaSafe(value: string): string {
|
|
41
|
-
if (typeof btoa === "function") {
|
|
42
|
-
return btoa(value);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return Buffer.from(value, "utf8").toString("base64");
|
|
46
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import { mkdtemp, readdir, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { tmpdir } from "node:os";
|
|
5
|
-
import { WindyLicenseClient } from "./client.js";
|
|
6
|
-
import {
|
|
7
|
-
FileSystemAtomicLicenseStore,
|
|
8
|
-
FixedPathLicenseSource,
|
|
9
|
-
} from "./file-storage.js";
|
|
10
|
-
import { MemoryLicenseStorage } from "./storage.js";
|
|
11
|
-
import { LICENSE_V1_TEST_VECTOR } from "./v1-test-vector.js";
|
|
12
|
-
|
|
13
|
-
const temporaryDirectories: string[] = [];
|
|
14
|
-
|
|
15
|
-
afterEach(async () => {
|
|
16
|
-
await Promise.all(
|
|
17
|
-
temporaryDirectories
|
|
18
|
-
.splice(0)
|
|
19
|
-
.map((directory) => rm(directory, { force: true, recursive: true })),
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("filesystem License adapters", () => {
|
|
24
|
-
test("固定路径挂载复用统一 V1 校验器", async () => {
|
|
25
|
-
const directory = await temporaryDirectory();
|
|
26
|
-
const path = join(directory, "runtime", "current.license.json");
|
|
27
|
-
const store = new FileSystemAtomicLicenseStore(path);
|
|
28
|
-
await store.replaceCurrentAtomically(
|
|
29
|
-
JSON.stringify({
|
|
30
|
-
formatVersion: 1,
|
|
31
|
-
algorithm: "ED25519",
|
|
32
|
-
publicKeyId: LICENSE_V1_TEST_VECTOR.keyId,
|
|
33
|
-
claims: LICENSE_V1_TEST_VECTOR.claims,
|
|
34
|
-
signature: LICENSE_V1_TEST_VECTOR.signature,
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const client = new WindyLicenseClient({
|
|
39
|
-
licenseSource: new FixedPathLicenseSource(path),
|
|
40
|
-
stateStorage: new MemoryLicenseStorage(),
|
|
41
|
-
productCode: "windy-platform",
|
|
42
|
-
machineCode: "machine-vector-001",
|
|
43
|
-
publicKeys: {
|
|
44
|
-
[LICENSE_V1_TEST_VECTOR.keyId]: LICENSE_V1_TEST_VECTOR.publicKeyPem,
|
|
45
|
-
},
|
|
46
|
-
now: () => new Date("2026-07-10T10:00:00.000Z"),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
await expect(client.recordOpen()).resolves.toMatchObject({
|
|
50
|
-
valid: true,
|
|
51
|
-
failures: [],
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test("模拟原子提交前崩溃时旧文件保持完整且临时文件被清理", async () => {
|
|
56
|
-
const directory = await temporaryDirectory();
|
|
57
|
-
const path = join(directory, "current.license.json");
|
|
58
|
-
await writeFile(path, '{"license":"old"}', "utf8");
|
|
59
|
-
const store = new CrashBeforeCommitStore(path);
|
|
60
|
-
|
|
61
|
-
await expect(
|
|
62
|
-
store.replaceCurrentAtomically('{"license":"new"}'),
|
|
63
|
-
).rejects.toThrow("模拟进程崩溃");
|
|
64
|
-
|
|
65
|
-
await expect(store.readCurrent()).resolves.toBe('{"license":"old"}');
|
|
66
|
-
expect(await readdir(directory)).toEqual(["current.license.json"]);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
class CrashBeforeCommitStore extends FileSystemAtomicLicenseStore {
|
|
71
|
-
protected override async beforeCommit(): Promise<void> {
|
|
72
|
-
throw new Error("模拟进程崩溃");
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function temporaryDirectory(): Promise<string> {
|
|
77
|
-
const directory = await mkdtemp(join(tmpdir(), "windy-license-sdk-"));
|
|
78
|
-
temporaryDirectories.push(directory);
|
|
79
|
-
return directory;
|
|
80
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { basename, dirname, join } from "node:path";
|
|
3
|
-
import { mkdir, open, readFile, rename, unlink } from "node:fs/promises";
|
|
4
|
-
import type { AtomicLicenseStore, LicenseSource } from "./storage.js";
|
|
5
|
-
|
|
6
|
-
export class FixedPathLicenseSource implements LicenseSource {
|
|
7
|
-
constructor(protected readonly licensePath: string) {}
|
|
8
|
-
|
|
9
|
-
async readCurrent(): Promise<string | undefined> {
|
|
10
|
-
try {
|
|
11
|
-
return await readFile(this.licensePath, "utf8");
|
|
12
|
-
} catch (error) {
|
|
13
|
-
if (isMissingFile(error)) return undefined;
|
|
14
|
-
throw error;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Atomic filesystem adapter. Temporary data is synced before the same-directory
|
|
21
|
-
* rename; the directory is synced afterwards so a crash cannot expose a partial file.
|
|
22
|
-
*/
|
|
23
|
-
export class FileSystemAtomicLicenseStore
|
|
24
|
-
extends FixedPathLicenseSource
|
|
25
|
-
implements AtomicLicenseStore
|
|
26
|
-
{
|
|
27
|
-
constructor(
|
|
28
|
-
licensePath: string,
|
|
29
|
-
private readonly fileMode = 0o600,
|
|
30
|
-
) {
|
|
31
|
-
super(licensePath);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async replaceCurrentAtomically(value: string): Promise<void> {
|
|
35
|
-
const directory = dirname(this.licensePath);
|
|
36
|
-
const temporaryPath = join(
|
|
37
|
-
directory,
|
|
38
|
-
`.${basename(this.licensePath)}.${process.pid}.${randomUUID()}.tmp`,
|
|
39
|
-
);
|
|
40
|
-
await mkdir(directory, { recursive: true });
|
|
41
|
-
|
|
42
|
-
let temporaryFile: Awaited<ReturnType<typeof open>> | undefined;
|
|
43
|
-
try {
|
|
44
|
-
temporaryFile = await open(temporaryPath, "wx", this.fileMode);
|
|
45
|
-
await temporaryFile.writeFile(value, "utf8");
|
|
46
|
-
await temporaryFile.sync();
|
|
47
|
-
await temporaryFile.close();
|
|
48
|
-
temporaryFile = undefined;
|
|
49
|
-
await this.beforeCommit();
|
|
50
|
-
await rename(temporaryPath, this.licensePath);
|
|
51
|
-
await syncDirectory(directory);
|
|
52
|
-
} finally {
|
|
53
|
-
await temporaryFile?.close().catch(() => undefined);
|
|
54
|
-
await unlink(temporaryPath).catch(() => undefined);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Test seam for simulating a process failure before the atomic commit. */
|
|
59
|
-
protected async beforeCommit(): Promise<void> {}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function syncDirectory(directory: string): Promise<void> {
|
|
63
|
-
const handle = await open(directory, "r");
|
|
64
|
-
try {
|
|
65
|
-
await handle.sync();
|
|
66
|
-
} finally {
|
|
67
|
-
await handle.close();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function isMissingFile(error: unknown): boolean {
|
|
72
|
-
return (
|
|
73
|
-
error instanceof Error &&
|
|
74
|
-
"code" in error &&
|
|
75
|
-
(error as NodeJS.ErrnoException).code === "ENOENT"
|
|
76
|
-
);
|
|
77
|
-
}
|