@yss123/cage-cli 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +40 -2
- package/bin/cage.js +6 -0
- package/bin/create-cage-app.js +6 -0
- package/dist/analyze.d.ts +18 -0
- package/dist/analyze.js +28 -0
- package/dist/analyze.js.map +1 -0
- package/dist/baseline.d.ts +5 -0
- package/dist/baseline.js +50 -0
- package/dist/baseline.js.map +1 -0
- package/dist/budget.d.ts +7 -0
- package/dist/budget.js +52 -0
- package/dist/budget.js.map +1 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +72 -0
- package/dist/context.js +202 -0
- package/dist/context.js.map +1 -0
- package/dist/create-prompt.d.ts +5 -0
- package/dist/create-prompt.js +50 -0
- package/dist/create-prompt.js.map +1 -0
- package/dist/create.d.ts +18 -0
- package/dist/create.js +64 -0
- package/dist/create.js.map +1 -0
- package/dist/derive.d.ts +14 -0
- package/dist/derive.js +163 -0
- package/dist/derive.js.map +1 -0
- package/dist/dev.d.ts +2 -0
- package/dist/dev.js +116 -0
- package/dist/dev.js.map +1 -0
- package/dist/env.d.ts +1 -0
- package/dist/env.js +15 -0
- package/dist/env.js.map +1 -0
- package/dist/findings.d.ts +11 -0
- package/dist/findings.js +13 -0
- package/dist/findings.js.map +1 -0
- package/dist/gen/contracts.d.ts +6 -0
- package/dist/gen/contracts.js +188 -0
- package/dist/gen/contracts.js.map +1 -0
- package/dist/gen/index.d.ts +19 -0
- package/dist/gen/index.js +177 -0
- package/dist/gen/index.js.map +1 -0
- package/dist/gen/zod-code.d.ts +7 -0
- package/dist/gen/zod-code.js +163 -0
- package/dist/gen/zod-code.js.map +1 -0
- package/dist/graph-command.d.ts +11 -0
- package/dist/graph-command.js +67 -0
- package/dist/graph-command.js.map +1 -0
- package/dist/graph-model.d.ts +21 -0
- package/dist/graph-model.js +101 -0
- package/dist/graph-model.js.map +1 -0
- package/dist/graph-presentation.d.ts +11 -0
- package/dist/graph-presentation.js +25 -0
- package/dist/graph-presentation.js.map +1 -0
- package/dist/graph-query.d.ts +171 -0
- package/dist/graph-query.js +242 -0
- package/dist/graph-query.js.map +1 -0
- package/dist/graph-relations.d.ts +14 -0
- package/dist/graph-relations.js +142 -0
- package/dist/graph-relations.js.map +1 -0
- package/dist/graph-search.d.ts +21 -0
- package/dist/graph-search.js +63 -0
- package/dist/graph-search.js.map +1 -0
- package/dist/graph-snapshot.d.ts +11 -0
- package/dist/graph-snapshot.js +29 -0
- package/dist/graph-snapshot.js.map +1 -0
- package/dist/graph.d.ts +11 -0
- package/dist/graph.js +105 -0
- package/dist/graph.js.map +1 -0
- package/dist/impact.d.ts +34 -0
- package/dist/impact.js +235 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +6 -0
- package/dist/init.js +131 -0
- package/dist/init.js.map +1 -0
- package/dist/load.d.ts +6 -0
- package/dist/load.js +17 -0
- package/dist/load.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +221 -0
- package/dist/main.js.map +1 -0
- package/dist/migrate.d.ts +4 -0
- package/dist/migrate.js +30 -0
- package/dist/migrate.js.map +1 -0
- package/dist/ontology.d.ts +43 -0
- package/dist/ontology.js +280 -0
- package/dist/ontology.js.map +1 -0
- package/dist/process.d.ts +6 -0
- package/dist/process.js +39 -0
- package/dist/process.js.map +1 -0
- package/dist/project-structure.d.ts +8 -0
- package/dist/project-structure.js +94 -0
- package/dist/project-structure.js.map +1 -0
- package/dist/rules.d.ts +23 -0
- package/dist/rules.js +251 -0
- package/dist/rules.js.map +1 -0
- package/dist/static-check.d.ts +23 -0
- package/dist/static-check.js +222 -0
- package/dist/static-check.js.map +1 -0
- package/dist/sync.d.ts +5 -0
- package/dist/sync.js +118 -0
- package/dist/sync.js.map +1 -0
- package/dist/upgrade.d.ts +10 -0
- package/dist/upgrade.js +81 -0
- package/dist/upgrade.js.map +1 -0
- package/dist/verify.d.ts +7 -0
- package/dist/verify.js +88 -0
- package/dist/verify.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/graph-ui/app.js +1103 -0
- package/graph-ui/graph-model.js +100 -0
- package/graph-ui/graph-relations.js +141 -0
- package/graph-ui/graph-search.js +62 -0
- package/graph-ui/index.html +197 -0
- package/graph-ui/model.js +83 -0
- package/graph-ui/relations.js +2 -0
- package/graph-ui/structure.js +77 -0
- package/graph-ui/style.css +1719 -0
- package/package.json +60 -3
- package/templates/app/.dockerignore +10 -0
- package/templates/app/.env.example +61 -0
- package/templates/app/.github/workflows/cage.yml +44 -0
- package/templates/app/AGENTS.md +96 -0
- package/templates/app/Dockerfile +25 -0
- package/templates/app/README.md +88 -0
- package/templates/app/_gitignore +8 -0
- package/templates/app/apps/api/package.json +16 -0
- package/templates/app/apps/api/src/main.ts +10 -0
- package/templates/app/apps/api/src/worker.ts +14 -0
- package/templates/app/apps/api/tsconfig.json +5 -0
- package/templates/app/apps/web/index.html +13 -0
- package/templates/app/apps/web/package.json +22 -0
- package/templates/app/apps/web/src/app/app.tsx +18 -0
- package/templates/app/apps/web/src/app/styles/global.css +663 -0
- package/templates/app/apps/web/src/app/workspace-layout.tsx +70 -0
- package/templates/app/apps/web/src/main.tsx +13 -0
- package/templates/app/apps/web/src/modules/approval/hooks/use-approval-tasks.ts +20 -0
- package/templates/app/apps/web/src/modules/approval/index.ts +2 -0
- package/templates/app/apps/web/src/modules/approval/pages/approval-tasks-page.tsx +54 -0
- package/templates/app/apps/web/src/modules/auth/index.ts +1 -0
- package/templates/app/apps/web/src/modules/auth/pages/login-page.tsx +59 -0
- package/templates/app/apps/web/src/modules/inventory/index.ts +1 -0
- package/templates/app/apps/web/src/modules/inventory/pages/inventory-page.tsx +74 -0
- package/templates/app/apps/web/src/modules/purchase/components/purchase-order-form.tsx +60 -0
- package/templates/app/apps/web/src/modules/purchase/index.ts +2 -0
- package/templates/app/apps/web/src/modules/purchase/pages/purchase-orders-page.tsx +210 -0
- package/templates/app/apps/web/src/shared/hooks/use-command.ts +29 -0
- package/templates/app/apps/web/src/shared/lib/error-message.ts +15 -0
- package/templates/app/apps/web/src/shared/ui/notice.tsx +13 -0
- package/templates/app/apps/web/src/shared/ui/page-heading.tsx +28 -0
- package/templates/app/apps/web/tsconfig.json +11 -0
- package/templates/app/apps/web/vite.config.ts +19 -0
- package/templates/app/cage.config.json +114 -0
- package/templates/app/db/migrations/0001_init.sql +112 -0
- package/templates/app/docs/ai/README.md +77 -0
- package/templates/app/docs/ai/architecture.md +122 -0
- package/templates/app/docs/ai/ontology-context.md +117 -0
- package/templates/app/docs/ai/primitives.md +249 -0
- package/templates/app/docs/ai/project-structure.md +123 -0
- package/templates/app/docs/ai/purchase-example.md +97 -0
- package/templates/app/docs/ai/recipes.md +81 -0
- package/templates/app/docs/ai/relations.md +160 -0
- package/templates/app/docs/ai/transfers.md +92 -0
- package/templates/app/docs/ai/troubleshooting.md +60 -0
- package/templates/app/docs/ai/workflow.md +139 -0
- package/templates/app/docs/errors/CAGE-APPR-001.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-002.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-003.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-004.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-005.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-006.md +47 -0
- package/templates/app/docs/errors/CAGE-APPR-007.md +50 -0
- package/templates/app/docs/errors/CAGE-APPR-010.md +48 -0
- package/templates/app/docs/errors/CAGE-AUTH-001.md +47 -0
- package/templates/app/docs/errors/CAGE-BUDGET-001.md +47 -0
- package/templates/app/docs/errors/CAGE-BUDGET-002.md +47 -0
- package/templates/app/docs/errors/CAGE-BUDGET-003.md +47 -0
- package/templates/app/docs/errors/CAGE-CMD-002.md +47 -0
- package/templates/app/docs/errors/CAGE-CMD-003.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-001.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-002.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-003.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-004.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-005.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-006.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-007.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-008.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-009.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-010.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-011.md +47 -0
- package/templates/app/docs/errors/CAGE-CONN-012.md +47 -0
- package/templates/app/docs/errors/CAGE-CREATE-001.md +52 -0
- package/templates/app/docs/errors/CAGE-DECL-001.md +48 -0
- package/templates/app/docs/errors/CAGE-DECL-002.md +47 -0
- package/templates/app/docs/errors/CAGE-DECL-003.md +47 -0
- package/templates/app/docs/errors/CAGE-DECL-004.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-001.md +48 -0
- package/templates/app/docs/errors/CAGE-DEP-002.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-003.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-004.md +47 -0
- package/templates/app/docs/errors/CAGE-DEP-005.md +47 -0
- package/templates/app/docs/errors/CAGE-DLQ-001.md +48 -0
- package/templates/app/docs/errors/CAGE-ENV-001.md +52 -0
- package/templates/app/docs/errors/CAGE-EVENT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-EVENT-002.md +50 -0
- package/templates/app/docs/errors/CAGE-FIELD-001.md +47 -0
- package/templates/app/docs/errors/CAGE-FIELD-002.md +47 -0
- package/templates/app/docs/errors/CAGE-FIELD-003.md +47 -0
- package/templates/app/docs/errors/CAGE-FIELD-004.md +47 -0
- package/templates/app/docs/errors/CAGE-GEN-001.md +48 -0
- package/templates/app/docs/errors/CAGE-GEN-002.md +47 -0
- package/templates/app/docs/errors/CAGE-GRANT-001.md +49 -0
- package/templates/app/docs/errors/CAGE-GRANT-002.md +48 -0
- package/templates/app/docs/errors/CAGE-GRANT-003.md +47 -0
- package/templates/app/docs/errors/CAGE-IMPACT-001.md +48 -0
- package/templates/app/docs/errors/CAGE-INIT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-INIT-002.md +49 -0
- package/templates/app/docs/errors/CAGE-INIT-003.md +48 -0
- package/templates/app/docs/errors/CAGE-INIT-004.md +48 -0
- package/templates/app/docs/errors/CAGE-JOB-001.md +47 -0
- package/templates/app/docs/errors/CAGE-JOB-002.md +47 -0
- package/templates/app/docs/errors/CAGE-JOB-003.md +47 -0
- package/templates/app/docs/errors/CAGE-LINT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-MIG-001.md +47 -0
- package/templates/app/docs/errors/CAGE-MIG-002.md +47 -0
- package/templates/app/docs/errors/CAGE-MIG-003.md +5 -0
- package/templates/app/docs/errors/CAGE-MIG-004.md +5 -0
- package/templates/app/docs/errors/CAGE-MIG-005.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-001.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-002.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-003.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-004.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-005.md +47 -0
- package/templates/app/docs/errors/CAGE-NAME-006.md +47 -0
- package/templates/app/docs/errors/CAGE-ORG-001.md +49 -0
- package/templates/app/docs/errors/CAGE-PAIR-002.md +50 -0
- package/templates/app/docs/errors/CAGE-QUERY-001.md +47 -0
- package/templates/app/docs/errors/CAGE-QUERY-002.md +47 -0
- package/templates/app/docs/errors/CAGE-QUERY-003.md +49 -0
- package/templates/app/docs/errors/CAGE-REACT-001.md +47 -0
- package/templates/app/docs/errors/CAGE-REACT-002.md +47 -0
- package/templates/app/docs/errors/CAGE-READS-001.md +47 -0
- package/templates/app/docs/errors/CAGE-REG-001.md +53 -0
- package/templates/app/docs/errors/CAGE-REG-002.md +48 -0
- package/templates/app/docs/errors/CAGE-REG-003.md +47 -0
- package/templates/app/docs/errors/CAGE-REL-001.md +64 -0
- package/templates/app/docs/errors/CAGE-ROUTE-001.md +47 -0
- package/templates/app/docs/errors/CAGE-SCOPE-001.md +47 -0
- package/templates/app/docs/errors/CAGE-SCOPE-002.md +47 -0
- package/templates/app/docs/errors/CAGE-SECRET-001.md +48 -0
- package/templates/app/docs/errors/CAGE-SECRET-002.md +47 -0
- package/templates/app/docs/errors/CAGE-SENS-001.md +48 -0
- package/templates/app/docs/errors/CAGE-SQL-001.md +47 -0
- package/templates/app/docs/errors/CAGE-SQL-002.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-001.md +49 -0
- package/templates/app/docs/errors/CAGE-STATE-002.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-003.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-004.md +47 -0
- package/templates/app/docs/errors/CAGE-STATE-005.md +48 -0
- package/templates/app/docs/errors/CAGE-STATE-010.md +48 -0
- package/templates/app/docs/errors/CAGE-STATE-011.md +48 -0
- package/templates/app/docs/errors/CAGE-STRUCT-001.md +51 -0
- package/templates/app/docs/errors/CAGE-STRUCT-002.md +51 -0
- package/templates/app/docs/errors/CAGE-SYNC-001.md +48 -0
- package/templates/app/docs/errors/CAGE-TEST-001.md +47 -0
- package/templates/app/docs/errors/CAGE-UNSAFE-001.md +48 -0
- package/templates/app/docs/errors/CAGE-UPGRADE-001.md +48 -0
- package/templates/app/docs/errors/README.md +307 -0
- package/templates/app/docs/errors/runtime.md +50 -0
- package/templates/app/package.json +22 -0
- package/templates/app/packages/contracts/package.json +16 -0
- package/templates/app/packages/contracts/src/aggregates/dept/index.ts +74 -0
- package/templates/app/packages/contracts/src/aggregates/inventory/index.ts +57 -0
- package/templates/app/packages/contracts/src/aggregates/inventory-lock/index.ts +52 -0
- package/templates/app/packages/contracts/src/aggregates/purchase-order/index.ts +72 -0
- package/templates/app/packages/contracts/src/aggregates/role/index.ts +85 -0
- package/templates/app/packages/contracts/src/aggregates/user/index.ts +89 -0
- package/templates/app/packages/contracts/src/index.ts +81 -0
- package/templates/app/packages/contracts/src/queries/index.ts +17 -0
- package/templates/app/packages/contracts/tsconfig.json +5 -0
- package/templates/app/packages/domain/package.json +23 -0
- package/templates/app/packages/domain/src/index.ts +6 -0
- package/templates/app/packages/domain/src/integrations/erp.ts +36 -0
- package/templates/app/packages/domain/src/modules/inventory/index.ts +2 -0
- package/templates/app/packages/domain/src/modules/inventory/inventory.ts +43 -0
- package/templates/app/packages/domain/src/modules/purchase/approvals.ts +18 -0
- package/templates/app/packages/domain/src/modules/purchase/index.ts +6 -0
- package/templates/app/packages/domain/src/modules/purchase/jobs.ts +13 -0
- package/templates/app/packages/domain/src/modules/purchase/purchase-order.test.ts +137 -0
- package/templates/app/packages/domain/src/modules/purchase/purchase-order.ts +122 -0
- package/templates/app/packages/domain/src/modules/purchase/queries.ts +10 -0
- package/templates/app/packages/domain/src/workflows/purchase-inventory.ts +24 -0
- package/templates/app/packages/domain/tsconfig.json +5 -0
- package/templates/app/pnpm-workspace.yaml +10 -0
- package/templates/app/renovate.json +5 -0
- package/templates/app/tsconfig.base.json +8 -0
- package/templates/blank/.dockerignore +10 -0
- package/templates/blank/.env.example +61 -0
- package/templates/blank/.github/workflows/cage.yml +44 -0
- package/templates/blank/AGENTS.md +96 -0
- package/templates/blank/Dockerfile +25 -0
- package/templates/blank/README.md +37 -0
- package/templates/blank/_gitignore +8 -0
- package/templates/blank/apps/api/package.json +15 -0
- package/templates/blank/apps/api/src/main.ts +11 -0
- package/templates/blank/apps/api/src/worker.ts +8 -0
- package/templates/blank/apps/api/tsconfig.json +5 -0
- package/templates/blank/apps/web/index.html +13 -0
- package/templates/blank/apps/web/package.json +22 -0
- package/templates/blank/apps/web/src/app/app.tsx +44 -0
- package/templates/blank/apps/web/src/app/styles/global.css +516 -0
- package/templates/blank/apps/web/src/app/workspace-layout.tsx +70 -0
- package/templates/blank/apps/web/src/main.tsx +13 -0
- package/templates/blank/apps/web/src/modules/auth/index.ts +1 -0
- package/templates/blank/apps/web/src/modules/auth/pages/login-page.tsx +87 -0
- package/templates/blank/apps/web/src/modules/workspace/index.ts +1 -0
- package/templates/blank/apps/web/src/modules/workspace/pages/home-page.tsx +45 -0
- package/templates/blank/apps/web/src/shared/lib/error-message.ts +11 -0
- package/templates/blank/apps/web/src/shared/ui/brand.tsx +11 -0
- package/templates/blank/apps/web/tsconfig.json +11 -0
- package/templates/blank/apps/web/vite.config.ts +19 -0
- package/templates/blank/cage.config.json +14 -0
- package/templates/blank/db/migrations/0001_init.sql +63 -0
- package/templates/blank/docs/ai/README.md +77 -0
- package/templates/blank/docs/ai/architecture.md +122 -0
- package/templates/blank/docs/ai/ontology-context.md +117 -0
- package/templates/blank/docs/ai/primitives.md +249 -0
- package/templates/blank/docs/ai/project-structure.md +123 -0
- package/templates/blank/docs/ai/purchase-example.md +97 -0
- package/templates/blank/docs/ai/recipes.md +81 -0
- package/templates/blank/docs/ai/relations.md +160 -0
- package/templates/blank/docs/ai/transfers.md +92 -0
- package/templates/blank/docs/ai/troubleshooting.md +60 -0
- package/templates/blank/docs/ai/workflow.md +139 -0
- package/templates/blank/docs/errors/CAGE-APPR-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-006.md +47 -0
- package/templates/blank/docs/errors/CAGE-APPR-007.md +50 -0
- package/templates/blank/docs/errors/CAGE-APPR-010.md +48 -0
- package/templates/blank/docs/errors/CAGE-AUTH-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-BUDGET-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-BUDGET-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-BUDGET-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-CMD-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-CMD-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-006.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-007.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-008.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-009.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-010.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-011.md +47 -0
- package/templates/blank/docs/errors/CAGE-CONN-012.md +47 -0
- package/templates/blank/docs/errors/CAGE-CREATE-001.md +52 -0
- package/templates/blank/docs/errors/CAGE-DECL-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-DECL-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-DECL-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-DECL-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-DEP-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-DEP-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-DLQ-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-ENV-001.md +52 -0
- package/templates/blank/docs/errors/CAGE-EVENT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-EVENT-002.md +50 -0
- package/templates/blank/docs/errors/CAGE-FIELD-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-FIELD-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-FIELD-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-FIELD-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-GEN-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-GEN-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-GRANT-001.md +49 -0
- package/templates/blank/docs/errors/CAGE-GRANT-002.md +48 -0
- package/templates/blank/docs/errors/CAGE-GRANT-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-IMPACT-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-INIT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-INIT-002.md +49 -0
- package/templates/blank/docs/errors/CAGE-INIT-003.md +48 -0
- package/templates/blank/docs/errors/CAGE-INIT-004.md +48 -0
- package/templates/blank/docs/errors/CAGE-JOB-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-JOB-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-JOB-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-LINT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-MIG-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-MIG-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-MIG-003.md +5 -0
- package/templates/blank/docs/errors/CAGE-MIG-004.md +5 -0
- package/templates/blank/docs/errors/CAGE-MIG-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-005.md +47 -0
- package/templates/blank/docs/errors/CAGE-NAME-006.md +47 -0
- package/templates/blank/docs/errors/CAGE-ORG-001.md +49 -0
- package/templates/blank/docs/errors/CAGE-PAIR-002.md +50 -0
- package/templates/blank/docs/errors/CAGE-QUERY-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-QUERY-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-QUERY-003.md +49 -0
- package/templates/blank/docs/errors/CAGE-REACT-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-REACT-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-READS-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-REG-001.md +53 -0
- package/templates/blank/docs/errors/CAGE-REG-002.md +48 -0
- package/templates/blank/docs/errors/CAGE-REG-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-REL-001.md +64 -0
- package/templates/blank/docs/errors/CAGE-ROUTE-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-SCOPE-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-SCOPE-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-SECRET-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-SECRET-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-SENS-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-SQL-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-SQL-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-001.md +49 -0
- package/templates/blank/docs/errors/CAGE-STATE-002.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-003.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-004.md +47 -0
- package/templates/blank/docs/errors/CAGE-STATE-005.md +48 -0
- package/templates/blank/docs/errors/CAGE-STATE-010.md +48 -0
- package/templates/blank/docs/errors/CAGE-STATE-011.md +48 -0
- package/templates/blank/docs/errors/CAGE-STRUCT-001.md +51 -0
- package/templates/blank/docs/errors/CAGE-STRUCT-002.md +51 -0
- package/templates/blank/docs/errors/CAGE-SYNC-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-TEST-001.md +47 -0
- package/templates/blank/docs/errors/CAGE-UNSAFE-001.md +48 -0
- package/templates/blank/docs/errors/CAGE-UPGRADE-001.md +48 -0
- package/templates/blank/docs/errors/README.md +307 -0
- package/templates/blank/docs/errors/runtime.md +50 -0
- package/templates/blank/docs/examples/purchase-admin/README.md +5 -0
- package/templates/blank/docs/examples/purchase-admin/apps/api/src/main.ts +10 -0
- package/templates/blank/docs/examples/purchase-admin/apps/api/src/worker.ts +14 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/app/app.tsx +18 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/app/styles/global.css +663 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/app/workspace-layout.tsx +70 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/main.tsx +13 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/approval/hooks/use-approval-tasks.ts +20 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/approval/index.ts +2 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/approval/pages/approval-tasks-page.tsx +54 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/auth/index.ts +1 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/auth/pages/login-page.tsx +59 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/inventory/index.ts +1 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/inventory/pages/inventory-page.tsx +74 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/purchase/components/purchase-order-form.tsx +60 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/purchase/index.ts +2 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/modules/purchase/pages/purchase-orders-page.tsx +210 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/hooks/use-command.ts +29 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/lib/error-message.ts +15 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/ui/notice.tsx +13 -0
- package/templates/blank/docs/examples/purchase-admin/apps/web/src/shared/ui/page-heading.tsx +28 -0
- package/templates/blank/docs/examples/purchase-admin/cage.config.json +114 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/dept/index.ts +74 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/inventory/index.ts +57 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/inventory-lock/index.ts +52 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/purchase-order/index.ts +72 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/role/index.ts +85 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/user/index.ts +89 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/index.ts +81 -0
- package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/queries/index.ts +17 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/index.ts +6 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/integrations/erp.ts +36 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/inventory/index.ts +2 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/inventory/inventory.ts +43 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/approvals.ts +18 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/index.ts +6 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/jobs.ts +13 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/purchase-order.test.ts +137 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/purchase-order.ts +122 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/modules/purchase/queries.ts +10 -0
- package/templates/blank/docs/examples/purchase-admin/packages/domain/src/workflows/purchase-inventory.ts +24 -0
- package/templates/blank/package.json +22 -0
- package/templates/blank/packages/contracts/package.json +16 -0
- package/templates/blank/packages/contracts/src/aggregates/dept/index.ts +74 -0
- package/templates/blank/packages/contracts/src/aggregates/role/index.ts +85 -0
- package/templates/blank/packages/contracts/src/aggregates/user/index.ts +89 -0
- package/templates/blank/packages/contracts/src/index.ts +55 -0
- package/templates/blank/packages/contracts/src/queries/index.ts +13 -0
- package/templates/blank/packages/contracts/tsconfig.json +5 -0
- package/templates/blank/packages/domain/package.json +23 -0
- package/templates/blank/packages/domain/src/index.ts +4 -0
- package/templates/blank/packages/domain/tsconfig.json +5 -0
- package/templates/blank/pnpm-workspace.yaml +10 -0
- package/templates/blank/renovate.json +5 -0
- package/templates/blank/tsconfig.base.json +8 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
{
|
|
2
|
+
"domain": "packages/domain/src/index.ts",
|
|
3
|
+
"contracts": "packages/contracts/src",
|
|
4
|
+
"structure": "modular",
|
|
5
|
+
"typecheck": ["packages/domain", "packages/contracts", "apps/api", "apps/web"],
|
|
6
|
+
"graph": {
|
|
7
|
+
"title": "采购业务图谱",
|
|
8
|
+
"labels": {
|
|
9
|
+
"aggregate:PurchaseOrder": "采购单",
|
|
10
|
+
"aggregate:Inventory": "库存台账",
|
|
11
|
+
"aggregate:InventoryLock": "库存锁",
|
|
12
|
+
"aggregate:Dept": "部门",
|
|
13
|
+
"aggregate:User": "用户",
|
|
14
|
+
"aggregate:Role": "角色",
|
|
15
|
+
"command:PurchaseOrder.create": "新建采购单",
|
|
16
|
+
"command:PurchaseOrder.submit": "提交审批",
|
|
17
|
+
"command:PurchaseOrder.approve": "通过审批",
|
|
18
|
+
"command:PurchaseOrder.reject": "驳回审批",
|
|
19
|
+
"command:PurchaseOrder.cancel": "取消采购单",
|
|
20
|
+
"command:PurchaseOrder.markReceived": "确认收货",
|
|
21
|
+
"command:PurchaseOrder.recordErpNo": "回写外部单号",
|
|
22
|
+
"command:Inventory.create": "登记库存",
|
|
23
|
+
"command:InventoryLock.acquire": "锁定库存",
|
|
24
|
+
"command:InventoryLock.release": "释放库存锁",
|
|
25
|
+
"event:OrderSubmitted": "采购单已提交",
|
|
26
|
+
"event:OrderApproved": "采购单已批准",
|
|
27
|
+
"event:OrderCancelled": "采购单已取消",
|
|
28
|
+
"event:OrderReceived": "采购单已收货",
|
|
29
|
+
"reaction:lockOnApprove": "审批通过后锁库存",
|
|
30
|
+
"reaction:releaseOnCancel": "取消后释放库存锁",
|
|
31
|
+
"reaction:releaseOnReceive": "收货后释放库存锁",
|
|
32
|
+
"approval:poApproval": "采购审批流程",
|
|
33
|
+
"route:route:po-approval": "采购审批分支",
|
|
34
|
+
"query:poByStatus": "按状态汇总采购单",
|
|
35
|
+
"job:expireStaleOrders": "清理过期采购草稿",
|
|
36
|
+
"connector:connector:erp": "企业资源系统",
|
|
37
|
+
"outbound:pushToErp": "推送采购单至外部",
|
|
38
|
+
"inbound:erpReceived": "接收外部收货通知",
|
|
39
|
+
"state:PurchaseOrder.draft": "草稿",
|
|
40
|
+
"state:PurchaseOrder.pending_approval": "待审批",
|
|
41
|
+
"state:PurchaseOrder.approved": "已批准",
|
|
42
|
+
"state:PurchaseOrder.received": "已收货",
|
|
43
|
+
"state:PurchaseOrder.rejected": "已驳回",
|
|
44
|
+
"state:PurchaseOrder.cancelled": "已取消",
|
|
45
|
+
"state:Inventory.active": "有效库存",
|
|
46
|
+
"state:Inventory.deleted": "已删除",
|
|
47
|
+
"state:InventoryLock.held": "锁定中",
|
|
48
|
+
"state:InventoryLock.released": "已释放",
|
|
49
|
+
"field:PurchaseOrder.amount": "采购金额",
|
|
50
|
+
"field:PurchaseOrder.deptId": "所属部门",
|
|
51
|
+
"field:PurchaseOrder.createdBy": "提单人",
|
|
52
|
+
"field:PurchaseOrder.supplierPhone": "供应商电话",
|
|
53
|
+
"field:PurchaseOrder.items": "采购明细",
|
|
54
|
+
"field:PurchaseOrder.erpNo": "外部系统单号",
|
|
55
|
+
"field:Inventory.sku": "物料编码",
|
|
56
|
+
"field:Inventory.available": "台账数量",
|
|
57
|
+
"field:InventoryLock.orderId": "采购单编号",
|
|
58
|
+
"field:InventoryLock.items": "锁定明细",
|
|
59
|
+
"capability:PurchaseOrder.read": "查看采购单",
|
|
60
|
+
"capability:PurchaseOrder.export": "导出采购单",
|
|
61
|
+
"capability:Inventory.read": "查看库存台账",
|
|
62
|
+
"capability:Inventory.export": "导出库存台账",
|
|
63
|
+
"capability:InventoryLock.read": "查看库存锁",
|
|
64
|
+
"capability:InventoryLock.export": "导出库存锁",
|
|
65
|
+
"command:Dept.create": "新建部门",
|
|
66
|
+
"command:Dept.update": "修改部门信息",
|
|
67
|
+
"command:Dept.archive": "停用部门",
|
|
68
|
+
"state:Dept.active": "启用中",
|
|
69
|
+
"state:Dept.archived": "已停用",
|
|
70
|
+
"field:Dept.name": "部门名称",
|
|
71
|
+
"field:Dept.code": "部门编码",
|
|
72
|
+
"field:Dept.parentId": "上级部门",
|
|
73
|
+
"field:Dept.ancestors": "部门层级路径",
|
|
74
|
+
"field:Dept.leaderId": "部门负责人",
|
|
75
|
+
"capability:Dept.read": "查看部门",
|
|
76
|
+
"capability:Dept.export": "导出部门",
|
|
77
|
+
"command:User.create": "新建用户",
|
|
78
|
+
"command:User.update": "修改用户信息",
|
|
79
|
+
"command:User.assignRoles": "分配角色",
|
|
80
|
+
"command:User.disable": "停用用户",
|
|
81
|
+
"command:User.enable": "启用用户",
|
|
82
|
+
"command:User.setPassword": "设置密码",
|
|
83
|
+
"state:User.active": "启用中",
|
|
84
|
+
"state:User.disabled": "已停用",
|
|
85
|
+
"field:User.username": "登录账号",
|
|
86
|
+
"field:User.name": "用户姓名",
|
|
87
|
+
"field:User.deptId": "所属部门",
|
|
88
|
+
"field:User.roleIds": "拥有的角色",
|
|
89
|
+
"field:User.phone": "手机号码",
|
|
90
|
+
"field:User.email": "电子邮箱",
|
|
91
|
+
"field:User.ssoSubject": "单点登录标识",
|
|
92
|
+
"field:User.passwordHash": "密码摘要",
|
|
93
|
+
"capability:User.read": "查看用户",
|
|
94
|
+
"capability:User.export": "导出用户",
|
|
95
|
+
"command:Role.create": "新建角色",
|
|
96
|
+
"command:Role.rename": "修改角色名称",
|
|
97
|
+
"command:Role.archive": "停用角色",
|
|
98
|
+
"command:Role.grantCapability": "授予能力",
|
|
99
|
+
"command:Role.revokeCapability": "收回能力",
|
|
100
|
+
"command:Role.setScope": "设置数据范围",
|
|
101
|
+
"state:Role.active": "启用中",
|
|
102
|
+
"state:Role.archived": "已停用",
|
|
103
|
+
"field:Role.code": "角色编码",
|
|
104
|
+
"field:Role.name": "角色名称",
|
|
105
|
+
"field:Role.capabilities": "能力点与额度",
|
|
106
|
+
"field:Role.scopes": "数据访问范围",
|
|
107
|
+
"capability:Role.read": "查看角色",
|
|
108
|
+
"capability:Role.export": "导出角色",
|
|
109
|
+
"resource:inventory.lock": "库存锁",
|
|
110
|
+
"operation:pushOrder": "推送采购单",
|
|
111
|
+
"event:goodsReceived": "外部收货通知"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/dept/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { client, useCageList, useCageQuery, type TransferTask } from '@yss123/cage-client';
|
|
6
|
+
|
|
7
|
+
/** 部门:读侧快照(敏感字段是按权限掩码后的值) */
|
|
8
|
+
export const DeptSchema = z.object({
|
|
9
|
+
id: z.string().uuid(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
code: z.string().nullable().optional(),
|
|
12
|
+
parentId: z.string().uuid().nullable().optional(),
|
|
13
|
+
ancestors: z.string(),
|
|
14
|
+
leaderId: z.string().uuid().nullable().optional(),
|
|
15
|
+
status: z.enum(["active", "archived"]),
|
|
16
|
+
version: z.number().int(),
|
|
17
|
+
createdAt: z.string(),
|
|
18
|
+
updatedAt: z.string(),
|
|
19
|
+
});
|
|
20
|
+
export type Dept = z.infer<typeof DeptSchema>;
|
|
21
|
+
export type DeptStatus = Dept['status'];
|
|
22
|
+
export const DeptStates = ['active', 'archived'] as const;
|
|
23
|
+
|
|
24
|
+
/** 命令输入:和后端命令的输入校验完全一致 */
|
|
25
|
+
export const DeptInputs = {
|
|
26
|
+
archive: z.object({ id: z.string().uuid() }),
|
|
27
|
+
create: z.object({ name: z.string().min(1).max(100), code: z.string().max(64).optional(), parentId: z.string().uuid().nullable().optional(), leaderId: z.string().uuid().nullable().optional() }),
|
|
28
|
+
update: z.object({ id: z.string().uuid(), name: z.string().min(1).max(100).optional(), code: z.string().max(64).nullable().optional(), leaderId: z.string().uuid().nullable().optional() }),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Dept.archive 可能返回的错误码 */
|
|
32
|
+
export type DeptArchiveError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
33
|
+
/** Dept.create 可能返回的错误码 */
|
|
34
|
+
export type DeptCreateError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT';
|
|
35
|
+
/** Dept.update 可能返回的错误码 */
|
|
36
|
+
export type DeptUpdateError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
37
|
+
|
|
38
|
+
export type DeptSortKey = 'createdAt' | 'updatedAt' | 'name' | 'code' | 'parentId' | 'ancestors' | 'leaderId';
|
|
39
|
+
export interface DeptListParams {
|
|
40
|
+
page?: number;
|
|
41
|
+
pageSize?: number;
|
|
42
|
+
/** 排序:字段名,前面加 - 表示倒序 */
|
|
43
|
+
sort?: DeptSortKey | `-${DeptSortKey}`;
|
|
44
|
+
/** 可以逗号分隔多个状态 */
|
|
45
|
+
status?: string;
|
|
46
|
+
createdAfter?: string;
|
|
47
|
+
createdBefore?: string;
|
|
48
|
+
name?: string | number | boolean;
|
|
49
|
+
code?: string | number | boolean;
|
|
50
|
+
parentId?: string | number | boolean;
|
|
51
|
+
ancestors?: string | number | boolean;
|
|
52
|
+
leaderId?: string | number | boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 调用方法:每个命令一个;client 自动生成并附带幂等键和 CSRF 令牌 */
|
|
56
|
+
export const dept = {
|
|
57
|
+
/** 停用部门(没有在职用户和下级部门时) */
|
|
58
|
+
archive: (id: string, expectedVersion?: number) => client.post<Dept, DeptArchiveError>(`/api/dept/${encodeURIComponent(id)}/archive`, { expectedVersion }),
|
|
59
|
+
/** 新建部门 */
|
|
60
|
+
create: (input: z.input<typeof DeptInputs.create>) => client.post<Dept, DeptCreateError>('/api/dept/create', input),
|
|
61
|
+
/** 修改部门名称、编码、负责人 */
|
|
62
|
+
update: (id: string, input: Omit<z.input<typeof DeptInputs.update>, 'id'>, expectedVersion?: number) => client.post<Dept, DeptUpdateError>(`/api/dept/${encodeURIComponent(id)}/update`, { ...input, expectedVersion }),
|
|
63
|
+
/** 异步导出 CSV:返回任务,使用 client.transfer(id) 查状态,完成后下载。需要 Dept.export 能力。 */
|
|
64
|
+
export: (params: DeptListParams = {}, options: { idempotencyKey?: string } = {}) => client.post<TransferTask, 'CONFLICT'>('/api/dept/export', params, options),
|
|
65
|
+
get: (id: string) => client.get<Dept>(`/api/dept/${encodeURIComponent(id)}`),
|
|
66
|
+
list: (params: DeptListParams = {}) => client.get<{ items: Dept[]; total: number; page: number; pageSize: number }>('/api/dept', params as Record<string, unknown>),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/** 详情查询 hook:响应也用 schema 校验;范围外返回 NOT_FOUND */
|
|
70
|
+
export const useDept = (id: string) => useCageQuery(['dept', id], `/api/dept/${encodeURIComponent(id)}`, DeptSchema, { enabled: !!id });
|
|
71
|
+
/** 列表查询 hook:走读侧账号与安全视图 */
|
|
72
|
+
export const useDeptList = (params: DeptListParams = {}) => useCageList(['dept'], '/api/dept', params as Record<string, unknown>, DeptSchema);
|
|
73
|
+
/** 查询缓存键前缀:命令成功后让它失效 */
|
|
74
|
+
export const deptKeys = { all: ['dept'] as const, one: (id: string) => ['dept', id] as const };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { client, useCageList, useCageQuery, type TransferTask } from '@yss123/cage-client';
|
|
6
|
+
|
|
7
|
+
/** Inventory:读侧快照(敏感字段是按权限掩码后的值) */
|
|
8
|
+
export const InventorySchema = z.object({
|
|
9
|
+
id: z.string().uuid(),
|
|
10
|
+
sku: z.string(),
|
|
11
|
+
available: z.number().int(),
|
|
12
|
+
status: z.enum(["active", "deleted"]),
|
|
13
|
+
version: z.number().int(),
|
|
14
|
+
createdAt: z.string(),
|
|
15
|
+
updatedAt: z.string(),
|
|
16
|
+
});
|
|
17
|
+
export type Inventory = z.infer<typeof InventorySchema>;
|
|
18
|
+
export type InventoryStatus = Inventory['status'];
|
|
19
|
+
export const InventoryStates = ['active', 'deleted'] as const;
|
|
20
|
+
|
|
21
|
+
/** 命令输入:和后端命令的输入校验完全一致 */
|
|
22
|
+
export const InventoryInputs = {
|
|
23
|
+
create: z.object({ sku: z.string(), available: z.number().int().min(-9007199254740991).max(9007199254740991) }),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Inventory.create 可能返回的错误码 */
|
|
27
|
+
export type InventoryCreateError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT';
|
|
28
|
+
|
|
29
|
+
export type InventorySortKey = 'createdAt' | 'updatedAt' | 'sku' | 'available';
|
|
30
|
+
export interface InventoryListParams {
|
|
31
|
+
page?: number;
|
|
32
|
+
pageSize?: number;
|
|
33
|
+
/** 排序:字段名,前面加 - 表示倒序 */
|
|
34
|
+
sort?: InventorySortKey | `-${InventorySortKey}`;
|
|
35
|
+
/** 可以逗号分隔多个状态 */
|
|
36
|
+
status?: string;
|
|
37
|
+
createdAfter?: string;
|
|
38
|
+
createdBefore?: string;
|
|
39
|
+
sku?: string | number | boolean;
|
|
40
|
+
available?: string | number | boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 调用方法:每个命令一个;client 自动生成并附带幂等键和 CSRF 令牌 */
|
|
44
|
+
export const inventory = {
|
|
45
|
+
create: (input: z.input<typeof InventoryInputs.create>) => client.post<Inventory, InventoryCreateError>('/api/inventory/create', input),
|
|
46
|
+
/** 异步导出 CSV:返回任务,使用 client.transfer(id) 查状态,完成后下载。需要 Inventory.export 能力。 */
|
|
47
|
+
export: (params: InventoryListParams = {}, options: { idempotencyKey?: string } = {}) => client.post<TransferTask, 'CONFLICT'>('/api/inventory/export', params, options),
|
|
48
|
+
get: (id: string) => client.get<Inventory>(`/api/inventory/${encodeURIComponent(id)}`),
|
|
49
|
+
list: (params: InventoryListParams = {}) => client.get<{ items: Inventory[]; total: number; page: number; pageSize: number }>('/api/inventory', params as Record<string, unknown>),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** 详情查询 hook:响应也用 schema 校验;范围外返回 NOT_FOUND */
|
|
53
|
+
export const useInventory = (id: string) => useCageQuery(['inventory', id], `/api/inventory/${encodeURIComponent(id)}`, InventorySchema, { enabled: !!id });
|
|
54
|
+
/** 列表查询 hook:走读侧账号与安全视图 */
|
|
55
|
+
export const useInventoryList = (params: InventoryListParams = {}) => useCageList(['inventory'], '/api/inventory', params as Record<string, unknown>, InventorySchema);
|
|
56
|
+
/** 查询缓存键前缀:命令成功后让它失效 */
|
|
57
|
+
export const inventoryKeys = { all: ['inventory'] as const, one: (id: string) => ['inventory', id] as const };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { client, useCageList, useCageQuery, type TransferTask } from '@yss123/cage-client';
|
|
6
|
+
|
|
7
|
+
/** InventoryLock:读侧快照(敏感字段是按权限掩码后的值) */
|
|
8
|
+
export const InventoryLockSchema = z.object({
|
|
9
|
+
id: z.string().uuid(),
|
|
10
|
+
orderId: z.string().uuid(),
|
|
11
|
+
items: z.array(z.object({ sku: z.string(), qty: z.number().int() })),
|
|
12
|
+
status: z.enum(["held", "released"]),
|
|
13
|
+
version: z.number().int(),
|
|
14
|
+
createdAt: z.string(),
|
|
15
|
+
updatedAt: z.string(),
|
|
16
|
+
});
|
|
17
|
+
export type InventoryLock = z.infer<typeof InventoryLockSchema>;
|
|
18
|
+
export type InventoryLockStatus = InventoryLock['status'];
|
|
19
|
+
export const InventoryLockStates = ['held', 'released'] as const;
|
|
20
|
+
|
|
21
|
+
/** 命令输入:和后端命令的输入校验完全一致 */
|
|
22
|
+
export const InventoryLockInputs = {
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export type InventoryLockSortKey = 'createdAt' | 'updatedAt' | 'orderId';
|
|
27
|
+
export interface InventoryLockListParams {
|
|
28
|
+
page?: number;
|
|
29
|
+
pageSize?: number;
|
|
30
|
+
/** 排序:字段名,前面加 - 表示倒序 */
|
|
31
|
+
sort?: InventoryLockSortKey | `-${InventoryLockSortKey}`;
|
|
32
|
+
/** 可以逗号分隔多个状态 */
|
|
33
|
+
status?: string;
|
|
34
|
+
createdAfter?: string;
|
|
35
|
+
createdBefore?: string;
|
|
36
|
+
orderId?: string | number | boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** 调用方法:每个命令一个;client 自动生成并附带幂等键和 CSRF 令牌 */
|
|
40
|
+
export const inventoryLock = {
|
|
41
|
+
/** 异步导出 CSV:返回任务,使用 client.transfer(id) 查状态,完成后下载。需要 InventoryLock.export 能力。 */
|
|
42
|
+
export: (params: InventoryLockListParams = {}, options: { idempotencyKey?: string } = {}) => client.post<TransferTask, 'CONFLICT'>('/api/inventory-lock/export', params, options),
|
|
43
|
+
get: (id: string) => client.get<InventoryLock>(`/api/inventory-lock/${encodeURIComponent(id)}`),
|
|
44
|
+
list: (params: InventoryLockListParams = {}) => client.get<{ items: InventoryLock[]; total: number; page: number; pageSize: number }>('/api/inventory-lock', params as Record<string, unknown>),
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** 详情查询 hook:响应也用 schema 校验;范围外返回 NOT_FOUND */
|
|
48
|
+
export const useInventoryLock = (id: string) => useCageQuery(['inventory-lock', id], `/api/inventory-lock/${encodeURIComponent(id)}`, InventoryLockSchema, { enabled: !!id });
|
|
49
|
+
/** 列表查询 hook:走读侧账号与安全视图 */
|
|
50
|
+
export const useInventoryLockList = (params: InventoryLockListParams = {}) => useCageList(['inventory-lock'], '/api/inventory-lock', params as Record<string, unknown>, InventoryLockSchema);
|
|
51
|
+
/** 查询缓存键前缀:命令成功后让它失效 */
|
|
52
|
+
export const inventoryLockKeys = { all: ['inventory-lock'] as const, one: (id: string) => ['inventory-lock', id] as const };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { client, useCageList, useCageQuery, type TransferTask } from '@yss123/cage-client';
|
|
6
|
+
|
|
7
|
+
/** PurchaseOrder:读侧快照(敏感字段是按权限掩码后的值) */
|
|
8
|
+
export const PurchaseOrderSchema = z.object({
|
|
9
|
+
id: z.string().uuid(),
|
|
10
|
+
deptId: z.string().uuid(),
|
|
11
|
+
createdBy: z.string().uuid(),
|
|
12
|
+
supplierPhone: z.string().nullable().optional(),
|
|
13
|
+
amount: z.string(),
|
|
14
|
+
items: z.array(z.object({ sku: z.string(), qty: z.number().int() })),
|
|
15
|
+
erpNo: z.string().nullable().optional(),
|
|
16
|
+
status: z.enum(["draft", "pending_approval", "approved", "received", "rejected", "cancelled"]),
|
|
17
|
+
version: z.number().int(),
|
|
18
|
+
createdAt: z.string(),
|
|
19
|
+
updatedAt: z.string(),
|
|
20
|
+
});
|
|
21
|
+
export type PurchaseOrder = z.infer<typeof PurchaseOrderSchema>;
|
|
22
|
+
export type PurchaseOrderStatus = PurchaseOrder['status'];
|
|
23
|
+
export const PurchaseOrderStates = ['draft', 'pending_approval', 'approved', 'received', 'rejected', 'cancelled'] as const;
|
|
24
|
+
|
|
25
|
+
/** 命令输入:和后端命令的输入校验完全一致 */
|
|
26
|
+
export const PurchaseOrderInputs = {
|
|
27
|
+
cancel: z.object({ id: z.string().uuid() }),
|
|
28
|
+
create: z.object({ amount: z.string(), items: z.array(z.object({ sku: z.string(), qty: z.number().int().max(9007199254740991).gt(0) })).min(1), supplierPhone: z.string().optional(), deptId: z.string().uuid().optional() }),
|
|
29
|
+
submit: z.object({ id: z.string().uuid() }),
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** PurchaseOrder.cancel 可能返回的错误码 */
|
|
33
|
+
export type PurchaseOrderCancelError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'INVARIANT_VIOLATED' | 'NOT_FOUND';
|
|
34
|
+
/** PurchaseOrder.create 可能返回的错误码 */
|
|
35
|
+
export type PurchaseOrderCreateError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVARIANT_VIOLATED';
|
|
36
|
+
/** PurchaseOrder.submit 可能返回的错误码;业务码(domainCode):NO_ITEMS */
|
|
37
|
+
export type PurchaseOrderSubmitError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'INVARIANT_VIOLATED' | 'NOT_FOUND';
|
|
38
|
+
export type PurchaseOrderSubmitDomainCode = 'NO_ITEMS';
|
|
39
|
+
|
|
40
|
+
export type PurchaseOrderSortKey = 'createdAt' | 'updatedAt' | 'deptId' | 'createdBy' | 'supplierPhone' | 'amount' | 'erpNo';
|
|
41
|
+
export interface PurchaseOrderListParams {
|
|
42
|
+
page?: number;
|
|
43
|
+
pageSize?: number;
|
|
44
|
+
/** 排序:字段名,前面加 - 表示倒序 */
|
|
45
|
+
sort?: PurchaseOrderSortKey | `-${PurchaseOrderSortKey}`;
|
|
46
|
+
/** 可以逗号分隔多个状态 */
|
|
47
|
+
status?: string;
|
|
48
|
+
createdAfter?: string;
|
|
49
|
+
createdBefore?: string;
|
|
50
|
+
deptId?: string | number | boolean;
|
|
51
|
+
createdBy?: string | number | boolean;
|
|
52
|
+
amount?: string | number | boolean;
|
|
53
|
+
erpNo?: string | number | boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 调用方法:每个命令一个;client 自动生成并附带幂等键和 CSRF 令牌 */
|
|
57
|
+
export const purchaseOrder = {
|
|
58
|
+
cancel: (id: string, expectedVersion?: number) => client.post<PurchaseOrder, PurchaseOrderCancelError>(`/api/purchase-order/${encodeURIComponent(id)}/cancel`, { expectedVersion }),
|
|
59
|
+
create: (input: z.input<typeof PurchaseOrderInputs.create>) => client.post<PurchaseOrder, PurchaseOrderCreateError>('/api/purchase-order/create', input),
|
|
60
|
+
submit: (id: string, expectedVersion?: number) => client.post<PurchaseOrder, PurchaseOrderSubmitError>(`/api/purchase-order/${encodeURIComponent(id)}/submit`, { expectedVersion }),
|
|
61
|
+
/** 异步导出 CSV:返回任务,使用 client.transfer(id) 查状态,完成后下载。需要 PurchaseOrder.export 能力。 */
|
|
62
|
+
export: (params: PurchaseOrderListParams = {}, options: { idempotencyKey?: string } = {}) => client.post<TransferTask, 'CONFLICT'>('/api/purchase-order/export', params, options),
|
|
63
|
+
get: (id: string) => client.get<PurchaseOrder>(`/api/purchase-order/${encodeURIComponent(id)}`),
|
|
64
|
+
list: (params: PurchaseOrderListParams = {}) => client.get<{ items: PurchaseOrder[]; total: number; page: number; pageSize: number }>('/api/purchase-order', params as Record<string, unknown>),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** 详情查询 hook:响应也用 schema 校验;范围外返回 NOT_FOUND */
|
|
68
|
+
export const usePurchaseOrder = (id: string) => useCageQuery(['purchase-order', id], `/api/purchase-order/${encodeURIComponent(id)}`, PurchaseOrderSchema, { enabled: !!id });
|
|
69
|
+
/** 列表查询 hook:走读侧账号与安全视图 */
|
|
70
|
+
export const usePurchaseOrderList = (params: PurchaseOrderListParams = {}) => useCageList(['purchase-order'], '/api/purchase-order', params as Record<string, unknown>, PurchaseOrderSchema);
|
|
71
|
+
/** 查询缓存键前缀:命令成功后让它失效 */
|
|
72
|
+
export const purchaseOrderKeys = { all: ['purchase-order'] as const, one: (id: string) => ['purchase-order', id] as const };
|
package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/role/index.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { client, useCageList, useCageQuery, type TransferTask } from '@yss123/cage-client';
|
|
6
|
+
|
|
7
|
+
/** 角色:读侧快照(敏感字段是按权限掩码后的值) */
|
|
8
|
+
export const RoleSchema = z.object({
|
|
9
|
+
id: z.string().uuid(),
|
|
10
|
+
code: z.string(),
|
|
11
|
+
name: z.string(),
|
|
12
|
+
capabilities: z.array(z.object({ capability: z.string(), params: z.record(z.string(), z.unknown()).nullable().optional() })),
|
|
13
|
+
scopes: z.array(z.object({ aggregate: z.string(), combinator: z.enum(["all", "self", "dept", "deptSubtree", "deptSet"]), deptIds: z.array(z.string().uuid()).nullable().optional() })),
|
|
14
|
+
status: z.enum(["active", "archived"]),
|
|
15
|
+
version: z.number().int(),
|
|
16
|
+
createdAt: z.string(),
|
|
17
|
+
updatedAt: z.string(),
|
|
18
|
+
});
|
|
19
|
+
export type Role = z.infer<typeof RoleSchema>;
|
|
20
|
+
export type RoleStatus = Role['status'];
|
|
21
|
+
export const RoleStates = ['active', 'archived'] as const;
|
|
22
|
+
|
|
23
|
+
/** 命令输入:和后端命令的输入校验完全一致 */
|
|
24
|
+
export const RoleInputs = {
|
|
25
|
+
archive: z.object({ id: z.string().uuid() }),
|
|
26
|
+
create: z.object({ code: z.string().min(1).max(64).regex(new RegExp("^[a-z][a-z0-9_]*$")), name: z.string().min(1).max(100) }),
|
|
27
|
+
grantCapability: z.object({ id: z.string().uuid(), capability: z.string().min(1).max(200), params: z.record(z.string(), z.unknown()).optional() }),
|
|
28
|
+
rename: z.object({ id: z.string().uuid(), name: z.string().min(1).max(100) }),
|
|
29
|
+
revokeCapability: z.object({ id: z.string().uuid(), capability: z.string().min(1).max(200) }),
|
|
30
|
+
setScope: z.object({ id: z.string().uuid(), aggregate: z.string().min(1).max(100), combinator: z.enum(["all", "self", "dept", "deptSubtree", "deptSet"]).nullable(), deptIds: z.array(z.string().uuid()).optional() }),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** Role.archive 可能返回的错误码 */
|
|
34
|
+
export type RoleArchiveError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
35
|
+
/** Role.create 可能返回的错误码 */
|
|
36
|
+
export type RoleCreateError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT';
|
|
37
|
+
/** Role.grantCapability 可能返回的错误码 */
|
|
38
|
+
export type RoleGrantCapabilityError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
39
|
+
/** Role.rename 可能返回的错误码 */
|
|
40
|
+
export type RoleRenameError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
41
|
+
/** Role.revokeCapability 可能返回的错误码 */
|
|
42
|
+
export type RoleRevokeCapabilityError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
43
|
+
/** Role.setScope 可能返回的错误码 */
|
|
44
|
+
export type RoleSetScopeError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
45
|
+
|
|
46
|
+
export type RoleSortKey = 'createdAt' | 'updatedAt' | 'code' | 'name';
|
|
47
|
+
export interface RoleListParams {
|
|
48
|
+
page?: number;
|
|
49
|
+
pageSize?: number;
|
|
50
|
+
/** 排序:字段名,前面加 - 表示倒序 */
|
|
51
|
+
sort?: RoleSortKey | `-${RoleSortKey}`;
|
|
52
|
+
/** 可以逗号分隔多个状态 */
|
|
53
|
+
status?: string;
|
|
54
|
+
createdAfter?: string;
|
|
55
|
+
createdBefore?: string;
|
|
56
|
+
code?: string | number | boolean;
|
|
57
|
+
name?: string | number | boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 调用方法:每个命令一个;client 自动生成并附带幂等键和 CSRF 令牌 */
|
|
61
|
+
export const role = {
|
|
62
|
+
/** 停用角色 */
|
|
63
|
+
archive: (id: string, expectedVersion?: number) => client.post<Role, RoleArchiveError>(`/api/role/${encodeURIComponent(id)}/archive`, { expectedVersion }),
|
|
64
|
+
/** 新建角色(默认没有任何能力) */
|
|
65
|
+
create: (input: z.input<typeof RoleInputs.create>) => client.post<Role, RoleCreateError>('/api/role/create', input),
|
|
66
|
+
/** 给角色授予能力点(不能授出自己没有的能力点) */
|
|
67
|
+
grantCapability: (id: string, input: Omit<z.input<typeof RoleInputs.grantCapability>, 'id'>, expectedVersion?: number) => client.post<Role, RoleGrantCapabilityError>(`/api/role/${encodeURIComponent(id)}/grant-capability`, { ...input, expectedVersion }),
|
|
68
|
+
/** 修改角色名称 */
|
|
69
|
+
rename: (id: string, input: Omit<z.input<typeof RoleInputs.rename>, 'id'>, expectedVersion?: number) => client.post<Role, RoleRenameError>(`/api/role/${encodeURIComponent(id)}/rename`, { ...input, expectedVersion }),
|
|
70
|
+
/** 收回角色的能力点 */
|
|
71
|
+
revokeCapability: (id: string, input: Omit<z.input<typeof RoleInputs.revokeCapability>, 'id'>, expectedVersion?: number) => client.post<Role, RoleRevokeCapabilityError>(`/api/role/${encodeURIComponent(id)}/revoke-capability`, { ...input, expectedVersion }),
|
|
72
|
+
/** 设置角色在某个聚合上的数据范围(不能授出比自己更宽的范围) */
|
|
73
|
+
setScope: (id: string, input: Omit<z.input<typeof RoleInputs.setScope>, 'id'>, expectedVersion?: number) => client.post<Role, RoleSetScopeError>(`/api/role/${encodeURIComponent(id)}/set-scope`, { ...input, expectedVersion }),
|
|
74
|
+
/** 异步导出 CSV:返回任务,使用 client.transfer(id) 查状态,完成后下载。需要 Role.export 能力。 */
|
|
75
|
+
export: (params: RoleListParams = {}, options: { idempotencyKey?: string } = {}) => client.post<TransferTask, 'CONFLICT'>('/api/role/export', params, options),
|
|
76
|
+
get: (id: string) => client.get<Role>(`/api/role/${encodeURIComponent(id)}`),
|
|
77
|
+
list: (params: RoleListParams = {}) => client.get<{ items: Role[]; total: number; page: number; pageSize: number }>('/api/role', params as Record<string, unknown>),
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/** 详情查询 hook:响应也用 schema 校验;范围外返回 NOT_FOUND */
|
|
81
|
+
export const useRole = (id: string) => useCageQuery(['role', id], `/api/role/${encodeURIComponent(id)}`, RoleSchema, { enabled: !!id });
|
|
82
|
+
/** 列表查询 hook:走读侧账号与安全视图 */
|
|
83
|
+
export const useRoleList = (params: RoleListParams = {}) => useCageList(['role'], '/api/role', params as Record<string, unknown>, RoleSchema);
|
|
84
|
+
/** 查询缓存键前缀:命令成功后让它失效 */
|
|
85
|
+
export const roleKeys = { all: ['role'] as const, one: (id: string) => ['role', id] as const };
|
package/templates/blank/docs/examples/purchase-admin/packages/contracts/src/aggregates/user/index.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { client, useCageList, useCageQuery, type TransferTask } from '@yss123/cage-client';
|
|
6
|
+
|
|
7
|
+
/** 用户:读侧快照(敏感字段是按权限掩码后的值) */
|
|
8
|
+
export const UserSchema = z.object({
|
|
9
|
+
id: z.string().uuid(),
|
|
10
|
+
username: z.string(),
|
|
11
|
+
name: z.string(),
|
|
12
|
+
deptId: z.string().uuid(),
|
|
13
|
+
roleIds: z.array(z.string().uuid()),
|
|
14
|
+
phone: z.string().nullable().optional(),
|
|
15
|
+
email: z.string().nullable().optional(),
|
|
16
|
+
ssoSubject: z.string().nullable().optional(),
|
|
17
|
+
status: z.enum(["active", "disabled"]),
|
|
18
|
+
version: z.number().int(),
|
|
19
|
+
createdAt: z.string(),
|
|
20
|
+
updatedAt: z.string(),
|
|
21
|
+
});
|
|
22
|
+
export type User = z.infer<typeof UserSchema>;
|
|
23
|
+
export type UserStatus = User['status'];
|
|
24
|
+
export const UserStates = ['active', 'disabled'] as const;
|
|
25
|
+
|
|
26
|
+
/** 命令输入:和后端命令的输入校验完全一致 */
|
|
27
|
+
export const UserInputs = {
|
|
28
|
+
assignRoles: z.object({ id: z.string().uuid(), roleIds: z.array(z.string().uuid()).max(50) }),
|
|
29
|
+
create: z.object({ username: z.string().min(2).max(64).regex(new RegExp("^[A-Za-z0-9_.@-]+$")), name: z.string().min(1).max(100), deptId: z.string().uuid(), phone: z.string().max(32).nullable().optional(), email: z.string().email().max(200).nullable().optional(), ssoSubject: z.string().max(200).nullable().optional() }),
|
|
30
|
+
disable: z.object({ id: z.string().uuid() }),
|
|
31
|
+
enable: z.object({ id: z.string().uuid() }),
|
|
32
|
+
setPassword: z.object({ id: z.string().uuid(), password: z.string().min(8).max(200) }),
|
|
33
|
+
update: z.object({ id: z.string().uuid(), name: z.string().min(1).max(100).optional(), deptId: z.string().uuid().optional(), phone: z.string().max(32).nullable().optional(), email: z.string().email().max(200).nullable().optional() }),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** User.assignRoles 可能返回的错误码 */
|
|
37
|
+
export type UserAssignRolesError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
38
|
+
/** User.create 可能返回的错误码 */
|
|
39
|
+
export type UserCreateError = 'CONFLICT' | 'CONSTRAINT_VIOLATED' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT';
|
|
40
|
+
/** User.disable 可能返回的错误码 */
|
|
41
|
+
export type UserDisableError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
42
|
+
/** User.enable 可能返回的错误码 */
|
|
43
|
+
export type UserEnableError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
44
|
+
/** User.setPassword 可能返回的错误码 */
|
|
45
|
+
export type UserSetPasswordError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
46
|
+
/** User.update 可能返回的错误码 */
|
|
47
|
+
export type UserUpdateError = 'CONFLICT' | 'DOMAIN_ERROR' | 'FORBIDDEN' | 'INVALID_INPUT' | 'INVALID_TRANSITION' | 'NOT_FOUND';
|
|
48
|
+
|
|
49
|
+
export type UserSortKey = 'createdAt' | 'updatedAt' | 'username' | 'name' | 'deptId' | 'phone' | 'email' | 'ssoSubject';
|
|
50
|
+
export interface UserListParams {
|
|
51
|
+
page?: number;
|
|
52
|
+
pageSize?: number;
|
|
53
|
+
/** 排序:字段名,前面加 - 表示倒序 */
|
|
54
|
+
sort?: UserSortKey | `-${UserSortKey}`;
|
|
55
|
+
/** 可以逗号分隔多个状态 */
|
|
56
|
+
status?: string;
|
|
57
|
+
createdAfter?: string;
|
|
58
|
+
createdBefore?: string;
|
|
59
|
+
username?: string | number | boolean;
|
|
60
|
+
deptId?: string | number | boolean;
|
|
61
|
+
ssoSubject?: string | number | boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 调用方法:每个命令一个;client 自动生成并附带幂等键和 CSRF 令牌 */
|
|
65
|
+
export const user = {
|
|
66
|
+
/** 设置用户的角色(不能分配包含自己没有的能力的角色) */
|
|
67
|
+
assignRoles: (id: string, input: Omit<z.input<typeof UserInputs.assignRoles>, 'id'>, expectedVersion?: number) => client.post<User, UserAssignRolesError>(`/api/user/${encodeURIComponent(id)}/assign-roles`, { ...input, expectedVersion }),
|
|
68
|
+
/** 新建用户(默认没有任何角色) */
|
|
69
|
+
create: (input: z.input<typeof UserInputs.create>) => client.post<User, UserCreateError>('/api/user/create', input),
|
|
70
|
+
/** 停用用户 */
|
|
71
|
+
disable: (id: string, expectedVersion?: number) => client.post<User, UserDisableError>(`/api/user/${encodeURIComponent(id)}/disable`, { expectedVersion }),
|
|
72
|
+
/** 启用用户 */
|
|
73
|
+
enable: (id: string, expectedVersion?: number) => client.post<User, UserEnableError>(`/api/user/${encodeURIComponent(id)}/enable`, { expectedVersion }),
|
|
74
|
+
/** 重置密码 */
|
|
75
|
+
setPassword: (id: string, input: Omit<z.input<typeof UserInputs.setPassword>, 'id'>, expectedVersion?: number) => client.post<User, UserSetPasswordError>(`/api/user/${encodeURIComponent(id)}/set-password`, { ...input, expectedVersion }),
|
|
76
|
+
/** 修改用户信息 */
|
|
77
|
+
update: (id: string, input: Omit<z.input<typeof UserInputs.update>, 'id'>, expectedVersion?: number) => client.post<User, UserUpdateError>(`/api/user/${encodeURIComponent(id)}/update`, { ...input, expectedVersion }),
|
|
78
|
+
/** 异步导出 CSV:返回任务,使用 client.transfer(id) 查状态,完成后下载。需要 User.export 能力。 */
|
|
79
|
+
export: (params: UserListParams = {}, options: { idempotencyKey?: string } = {}) => client.post<TransferTask, 'CONFLICT'>('/api/user/export', params, options),
|
|
80
|
+
get: (id: string) => client.get<User>(`/api/user/${encodeURIComponent(id)}`),
|
|
81
|
+
list: (params: UserListParams = {}) => client.get<{ items: User[]; total: number; page: number; pageSize: number }>('/api/user', params as Record<string, unknown>),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** 详情查询 hook:响应也用 schema 校验;范围外返回 NOT_FOUND */
|
|
85
|
+
export const useUser = (id: string) => useCageQuery(['user', id], `/api/user/${encodeURIComponent(id)}`, UserSchema, { enabled: !!id });
|
|
86
|
+
/** 列表查询 hook:走读侧账号与安全视图 */
|
|
87
|
+
export const useUserList = (params: UserListParams = {}) => useCageList(['user'], '/api/user', params as Record<string, unknown>, UserSchema);
|
|
88
|
+
/** 查询缓存键前缀:命令成功后让它失效 */
|
|
89
|
+
export const userKeys = { all: ['user'] as const, one: (id: string) => ['user', id] as const };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// 生成物:由 cage gen 从 domain 声明生成,不要手改。
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export * from './aggregates/dept';
|
|
5
|
+
export * from './aggregates/inventory';
|
|
6
|
+
export * from './aggregates/inventory-lock';
|
|
7
|
+
export * from './aggregates/purchase-order';
|
|
8
|
+
export * from './aggregates/role';
|
|
9
|
+
export * from './aggregates/user';
|
|
10
|
+
export * from './queries';
|
|
11
|
+
import { can as baseCan, useCan as baseUseCan } from '@yss123/cage-client';
|
|
12
|
+
import { DeptInputs } from './aggregates/dept';
|
|
13
|
+
import { InventoryInputs } from './aggregates/inventory';
|
|
14
|
+
import { InventoryLockInputs } from './aggregates/inventory-lock';
|
|
15
|
+
import { PurchaseOrderInputs } from './aggregates/purchase-order';
|
|
16
|
+
import { RoleInputs } from './aggregates/role';
|
|
17
|
+
import { UserInputs } from './aggregates/user';
|
|
18
|
+
export { client, configureClient, loadMe, currentUser, CageQueryError, useTransfer, type CageResult, type CommonError, type TransferTask, type ImportReport } from '@yss123/cage-client';
|
|
19
|
+
|
|
20
|
+
/** 能力目录(由代码派生):写错能力点名会编译失败 */
|
|
21
|
+
export const capabilities = [
|
|
22
|
+
'Dept.archive',
|
|
23
|
+
'Dept.create',
|
|
24
|
+
'Dept.export',
|
|
25
|
+
'Dept.read',
|
|
26
|
+
'Dept.update',
|
|
27
|
+
'Inventory.create',
|
|
28
|
+
'Inventory.export',
|
|
29
|
+
'Inventory.read',
|
|
30
|
+
'InventoryLock.acquire',
|
|
31
|
+
'InventoryLock.export',
|
|
32
|
+
'InventoryLock.read',
|
|
33
|
+
'InventoryLock.release',
|
|
34
|
+
'PurchaseOrder.approve',
|
|
35
|
+
'PurchaseOrder.cancel',
|
|
36
|
+
'PurchaseOrder.create',
|
|
37
|
+
'PurchaseOrder.export',
|
|
38
|
+
'PurchaseOrder.markReceived',
|
|
39
|
+
'PurchaseOrder.read',
|
|
40
|
+
'PurchaseOrder.recordErpNo',
|
|
41
|
+
'PurchaseOrder.reject',
|
|
42
|
+
'PurchaseOrder.submit',
|
|
43
|
+
'PurchaseOrder.unmask.phone',
|
|
44
|
+
'Role.archive',
|
|
45
|
+
'Role.create',
|
|
46
|
+
'Role.export',
|
|
47
|
+
'Role.grantCapability',
|
|
48
|
+
'Role.read',
|
|
49
|
+
'Role.rename',
|
|
50
|
+
'Role.revokeCapability',
|
|
51
|
+
'Role.setScope',
|
|
52
|
+
'Sys.audit.read',
|
|
53
|
+
'Sys.ops.manage',
|
|
54
|
+
'Sys.ops.read',
|
|
55
|
+
'User.assignRoles',
|
|
56
|
+
'User.create',
|
|
57
|
+
'User.disable',
|
|
58
|
+
'User.enable',
|
|
59
|
+
'User.export',
|
|
60
|
+
'User.read',
|
|
61
|
+
'User.setPassword',
|
|
62
|
+
'User.unmask.email',
|
|
63
|
+
'User.unmask.name',
|
|
64
|
+
'User.unmask.phone',
|
|
65
|
+
'User.update',
|
|
66
|
+
] as const;
|
|
67
|
+
export type Capability = (typeof capabilities)[number];
|
|
68
|
+
|
|
69
|
+
/** 当前用户有没有某个能力点。只影响界面显示:绕过前端直接调接口,内核一样会拒绝 */
|
|
70
|
+
export const can = (capability: Capability): boolean => baseCan(capability);
|
|
71
|
+
export const useCan = (capability: Capability): boolean => baseUseCan(capability);
|
|
72
|
+
|
|
73
|
+
/** 各聚合的命令输入 schema:按聚合名、命令名访问,可直接供表单库校验 */
|
|
74
|
+
export const schemas = {
|
|
75
|
+
Dept: DeptInputs,
|
|
76
|
+
Inventory: InventoryInputs,
|
|
77
|
+
InventoryLock: InventoryLockInputs,
|
|
78
|
+
PurchaseOrder: PurchaseOrderInputs,
|
|
79
|
+
Role: RoleInputs,
|
|
80
|
+
User: UserInputs,
|
|
81
|
+
};
|