cabloy 5.1.111 → 5.1.112
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/.cabloy-version +1 -1
- package/.claude/skills/cabloy-backend-scaffold/SKILL.md +29 -1
- package/.claude/skills/cabloy-backend-scaffold/references/follow-up-checklist.md +12 -0
- package/.claude/skills/cabloy-frontend-scaffold/SKILL.md +3 -0
- package/.claude/skills/cabloy-frontend-scaffold/references/follow-up-checklist.md +4 -0
- package/.claude/skills/cabloy-master-detail/SKILL.md +13 -2
- package/.github/workflows/playwright-e2e.yml +45 -0
- package/.gitignore +1 -0
- package/CHANGELOG.md +17 -0
- package/CLAUDE.md +4 -1
- package/README.md +8 -8
- package/cabloy-docs/backend/crud-workflow.md +10 -0
- package/cabloy-docs/backend/foundation.md +29 -4
- package/cabloy-docs/backend/introduction.md +1 -1
- package/cabloy-docs/backend/model-guide.md +9 -11
- package/cabloy-docs/backend/multi-instance-and-instance-resolution.md +18 -0
- package/cabloy-docs/backend/service-guide.md +1 -1
- package/cabloy-docs/frontend/a-router-guide.md +1 -1
- package/cabloy-docs/frontend/introduction.md +1 -1
- package/cabloy-docs/frontend/navigation-guards-guide.md +20 -11
- package/cabloy-docs/frontend/route-alias-guide.md +24 -0
- package/cabloy-docs/frontend/scripts.md +71 -24
- package/cabloy-docs/frontend/ssr-init-data.md +25 -0
- package/cabloy-docs/frontend/ssr-review-checklist.md +17 -7
- package/cabloy-docs/frontend/use-state-data-best-practices.md +4 -0
- package/cabloy-docs/frontend/zova-router-under-the-hood.md +4 -1
- package/cabloy-docs/fullstack/comparison-with-other-frameworks.md +19 -13
- package/cabloy-docs/fullstack/introduction.md +10 -10
- package/cabloy-docs/fullstack/quickstart.md +23 -1
- package/cabloy-docs/index.md +14 -14
- package/cabloy-docs/reference/package-map.md +11 -7
- package/cabloy-docs/reference/repo-scripts.md +108 -23
- package/e2e/scripts/e2e.ts +1 -1
- package/e2e/specs/a-commerce/commerce.spec.ts +124 -1
- package/package.json +2 -1
- package/scripts/init.ts +6 -12
- package/scripts/upgrade.ts +3 -1
- package/vona/packages-vona/vona/package.json +1 -1
- package/vona/pnpm-lock.yaml +39 -108
- package/vona/src/backend/config/config/config.ts +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/package.json +4 -2
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/index.ts +732 -2
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/locales.ts +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/bean/meta.index.ts +14 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/bean/meta.version.ts +52 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/bean/ssrMenu.category.ts +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/bean/ssrMenu.product.ts +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/bean/ssrMenu.sku.ts +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/config/locale/en-us.ts +19 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/config/locale/zh-cn.ts +19 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/controller/category.ts +65 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/controller/product.ts +86 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/controller/sku.ts +65 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/categoryCreate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/categorySelectReq.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/categorySelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/categorySelectResItem.tsx +39 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/categoryUpdate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/categoryView.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productCreate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productPublic.tsx +38 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productPublicSelectReq.tsx +23 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productPublicSelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productPublicSku.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productSelectReq.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productSelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productSelectResItem.tsx +39 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productUpdate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/productView.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuCreate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuSelectReq.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuSelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuSelectResItem.tsx +39 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuUpdate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuView.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/entity/category.tsx +53 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/entity/product.tsx +48 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/entity/sku.tsx +66 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/index.ts +1 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/model/category.ts +15 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/model/product.ts +46 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/model/sku.ts +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/service/category.ts +47 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/service/product.ts +162 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/src/service/sku.ts +76 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/test/catalog.test.ts +358 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/test/category.test.ts +91 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/test/product.test.ts +154 -0
- package/vona/src/suite/a-commerce/modules/commerce-catalog/test/sku.test.ts +190 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/package.json +2 -1
- package/vona/src/suite/a-commerce/modules/commerce-member/src/.metadata/index.ts +342 -5
- package/vona/src/suite/a-commerce/modules/commerce-member/src/.metadata/locales.ts +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/bean/meta.index.ts +12 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/bean/meta.version.ts +31 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/config/locale/en-us.ts +12 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/config/locale/zh-cn.ts +12 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/controller/address.ts +59 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/dto/addressCreate.tsx +39 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/dto/addressSelectReq.tsx +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/dto/addressSelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/dto/addressSelectResItem.tsx +53 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/dto/addressUpdate.tsx +39 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/dto/addressView.tsx +39 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/entity/address.tsx +76 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/index.ts +1 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/model/address.ts +10 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/src/service/address.ts +84 -0
- package/vona/src/suite/a-commerce/modules/commerce-member/test/addressOwnership.test.ts +203 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/package.json +52 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/src/.metadata/index.ts +55 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/src/.metadata/this.ts +2 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/src/bean/meta.version.ts +80 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/src/index.ts +1 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/tsconfig.build.json +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-seed/tsconfig.json +7 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/package.json +4 -2
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/.metadata/index.ts +192 -2
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/.metadata/locales.ts +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/bean/meta.version.ts +32 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/bean/ssrMenu.home.ts +3 -1
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/bean/ssrMenuGroup.catalog.ts +21 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/bean/ssrMenuGroup.inventory.ts +21 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/config/locale/en-us.ts +5 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/config/locale/zh-cn.ts +5 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/controller/operator.ts +21 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/dto/operatorContext.ts +21 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/index.ts +1 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/src/service/operator.ts +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/test/meta.version.test.ts +44 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/test/operatorAccess.test.ts +55 -0
- package/vona/src/suite/a-commerce/modules/commerce-siteadmin/test/ssrMenu.test.ts +77 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/package.json +2 -1
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/.metadata/index.ts +773 -2
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/.metadata/locales.ts +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/meta.index.ts +23 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/meta.version.ts +79 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/ssrMenu.stockAudit.ts +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/ssrMenu.stockBalance.ts +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/config/locale/en-us.ts +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/config/locale/zh-cn.ts +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/controller/cart.ts +48 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/controller/stockAudit.ts +38 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/controller/stockBalance.ts +49 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/cartAddItem.tsx +19 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/cartItem.tsx +34 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/cartUpdateItem.tsx +15 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/cartView.tsx +18 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAdjust.tsx +32 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAuditCreate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAuditSelectReq.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAuditSelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAuditSelectResItem.tsx +33 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAuditUpdate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockAuditView.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockBalanceCreate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockBalanceSelectReq.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockBalanceSelectRes.tsx +11 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockBalanceSelectResItem.tsx +33 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockBalanceUpdate.tsx +28 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/stockBalanceView.tsx +25 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/cart.tsx +24 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/cartItem.tsx +30 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/stockAudit.tsx +86 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/stockBalance.tsx +53 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/stockReservation.tsx +63 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/index.ts +1 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/cart.ts +17 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/cartItem.ts +10 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/stockAudit.ts +10 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/stockBalance.ts +15 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/stockReservation.ts +10 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/service/cart.ts +152 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/service/stockAudit.ts +20 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/service/stockBalance.ts +305 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/test/cartOwnership.test.ts +174 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/test/stockAudit.test.ts +37 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/test/stockBalance.test.ts +186 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/test/stockReservation.test.ts +262 -0
- package/vona/src/suite/a-commerce/package.json +1 -0
- package/vona/src/suite/a-commerce/tsconfig.json +3 -0
- package/vona/src/suite/a-home/modules/home-user/src/.metadata/index.ts +7 -1
- package/vona/src/suite/a-home/modules/home-user/test/role.test.ts +14 -23
- package/vona/src/suite/a-training/modules/training-record/src/.metadata/index.ts +10 -8
- package/vona/src/suite/a-training/modules/training-recordsubject/src/.metadata/index.ts +2 -0
- package/vona/src/suite/a-training/modules/training-student/src/.metadata/index.ts +3 -1
- package/vona/src/suite-vendor/a-auth/modules/a-auth/package.json +1 -1
- package/vona/src/suite-vendor/a-auth/modules/a-auth/src/.metadata/index.ts +7 -3
- package/vona/src/suite-vendor/a-auth/modules/auth-simple/package.json +1 -1
- package/vona/src/suite-vendor/a-auth/modules/auth-simple/src/.metadata/index.ts +2 -0
- package/vona/src/suite-vendor/a-auth/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-datasharding/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-datasharding/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-datasource/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-datasource/src/.metadata/index.ts +3 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-socket/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-socket/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-ssr/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-ssr/src/.metadata/index.ts +47 -47
- package/vona/src/suite-vendor/a-cabloy/modules/a-ssrhmr/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-ssrhmr/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-status/package.json +1 -1
- package/vona/src/suite-vendor/a-cabloy/modules/a-status/src/.metadata/index.ts +2 -0
- package/vona/src/suite-vendor/a-cabloy/package.json +1 -1
- package/vona/src/suite-vendor/a-captcha/modules/a-captcha/package.json +1 -1
- package/vona/src/suite-vendor/a-captcha/modules/a-captcha/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-captcha/package.json +1 -1
- package/vona/src/suite-vendor/a-file/modules/a-file/package.json +1 -1
- package/vona/src/suite-vendor/a-file/modules/a-file/src/.metadata/index.ts +42 -38
- package/vona/src/suite-vendor/a-file/package.json +2 -2
- package/vona/src/suite-vendor/a-image/modules/a-image/package.json +1 -1
- package/vona/src/suite-vendor/a-image/modules/a-image/src/.metadata/index.ts +42 -38
- package/vona/src/suite-vendor/a-image/modules/image-cloudflare/package.json +1 -1
- package/vona/src/suite-vendor/a-image/modules/image-cloudflare/src/.metadata/index.ts +42 -27
- package/vona/src/suite-vendor/a-image/package.json +1 -1
- package/vona/src/suite-vendor/a-paypal/modules/a-paypal/package.json +1 -1
- package/vona/src/suite-vendor/a-paypal/modules/a-paypal/src/.metadata/index.ts +3 -1
- package/vona/src/suite-vendor/a-paypal/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-beanmutate/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-beanmutate/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-body/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-body/src/.metadata/index.ts +2 -2
- package/vona/src/suite-vendor/a-vona/modules/a-cache/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-cache/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-core/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-core/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-error/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-error/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-event/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-event/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-executor/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-executor/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-hmr/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-hmr/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-instance/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-instance/src/.metadata/index.ts +3 -1
- package/vona/src/suite-vendor/a-vona/modules/a-jwt/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-jwt/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-logger/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-logger/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-mail/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-mail/src/.metadata/index.ts +3 -1
- package/vona/src/suite-vendor/a-vona/modules/a-mailconfirm/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-mailconfirm/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-onion/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-onion/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-openapi/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-openapi/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-orm/cli/model/metadata/generate.ts +5 -11
- package/vona/src/suite-vendor/a-vona/modules/a-orm/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-orm/src/lib/bean.model/bean.model_cache.ts +52 -0
- package/vona/src/suite-vendor/a-vona/modules/a-orm/src/lib/dto/dtoGet.ts +4 -10
- package/vona/src/suite-vendor/a-vona/modules/a-redis/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-redis/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-security/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-security/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-serialization/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-serialization/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-summer/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-summer/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-user/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-user/src/.metadata/index.ts +4 -5
- package/vona/src/suite-vendor/a-vona/modules/a-validation/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-validation/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-version/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-version/src/.metadata/index.ts +6 -0
- package/vona/src/suite-vendor/a-vona/modules/a-web/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-web/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-worker/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-worker/src/.metadata/index.ts +1 -1
- package/vona/src/suite-vendor/a-vona/package.json +1 -1
- package/zova/packages-cli/cli/package.json +2 -2
- package/zova/packages-cli/cli-set-front/package.json +1 -1
- package/zova/packages-cli/cli-set-front/src/lib/bean/toolsMetadata/generateScope.ts +1 -1
- package/zova/packages-zova/zova/package.json +2 -2
- package/zova/pnpm-lock.yaml +9 -9
- package/zova/src/front/config/config/config.cabloyCommerce.ts +5 -1
- package/zova/src/front/config/config/config.cabloyCommerceAdmin.ts +2 -1
- package/zova/src/suite/a-commerce/modules/commerce-catalog/cli/openapi.config.ts +9 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/package.json +2 -1
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/index.ts +202 -3
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/locales.ts +7 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/page/catalogue.ts +23 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/page/product.ts +19 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/api/commerceCatalogProduct.ts +52 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/api/openapi/baseURL.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/api/openapi/index.ts +3 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/api/openapi/schemas.ts +412 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/api/openapi/types.ts +7159 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/apiSchema/commerceCatalogProduct.ts +20 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/config/locale/en-us.ts +8 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/config/locale/zh-cn.ts +8 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/index.ts +1 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/model/catalogue.ts +38 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/page/catalogue/controller.tsx +71 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/page/product/controller.tsx +108 -0
- package/zova/src/suite/a-commerce/modules/commerce-catalog/src/routes.ts +19 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/cli/openapi.config.ts +9 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/package.json +2 -1
- package/zova/src/suite/a-commerce/modules/commerce-member/src/.metadata/index.ts +182 -3
- package/zova/src/suite/a-commerce/modules/commerce-member/src/.metadata/locales.ts +7 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/.metadata/page/address.ts +19 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/api/commerceMemberAddress.ts +111 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/api/openapi/baseURL.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/api/openapi/index.ts +3 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/api/openapi/schemas.ts +432 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/api/openapi/types.ts +7445 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/apiSchema/commerceMemberAddress.ts +35 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/config/locale/en-us.ts +17 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/config/locale/zh-cn.ts +17 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/index.ts +1 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/model/address.ts +38 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/page/address/controller.tsx +194 -0
- package/zova/src/suite/a-commerce/modules/commerce-member/src/routes.ts +12 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/cli/openapi.config.ts +9 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/package.json +2 -1
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/.metadata/index.ts +175 -3
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/.metadata/locales.ts +7 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/.metadata/page/dashboard.ts +9 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/commerceSiteadminOperator.ts +25 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/openapi/baseURL.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/openapi/index.ts +3 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/openapi/schemas.ts +304 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/api/openapi/types.ts +5710 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/apiSchema/commerceSiteadminOperator.ts +13 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/config/locale/en-us.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/config/locale/zh-cn.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/index.ts +1 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/model/operator.ts +17 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/page/dashboard/controller.tsx +34 -0
- package/zova/src/suite/a-commerce/modules/commerce-siteadmin/src/routes.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/cli/openapi.config.ts +15 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/package.json +2 -1
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/.metadata/index.ts +182 -3
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/.metadata/locales.ts +7 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/.metadata/page/cart.ts +19 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/commerceTradeCart.ts +99 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/openapi/baseURL.ts +5 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/openapi/index.ts +3 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/openapi/schemas.ts +446 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/openapi/types.ts +7651 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/apiSchema/commerceTradeCart.ts +35 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/config/locale/en-us.ts +8 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/config/locale/zh-cn.ts +8 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/index.ts +1 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/model/cart.ts +77 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/page/cart/controller.tsx +108 -0
- package/zova/src/suite/a-commerce/modules/commerce-trade/src/routes.ts +12 -0
- package/zova/src/suite/a-demo/modules/demo-basic/src/.metadata/index.ts +5 -5
- package/zova/src/suite/a-demo/modules/demo-todo/src/.metadata/index.ts +2 -2
- package/zova/src/suite/a-home/modules/home-base/src/service/routerGuards.ts +18 -10
- package/zova/src/suite/a-home/modules/home-indexweb/src/.metadata/index.ts +2 -2
- package/zova/src/suite-vendor/a-cabloy/modules/rest-resource/package.json +1 -1
- package/zova/src/suite-vendor/a-cabloy/modules/rest-resource/src/.metadata/index.ts +4 -4
- package/zova/src/suite-vendor/a-cabloy/modules/rest-resource/src/model/resource.ts +1 -0
- package/zova/src/suite-vendor/a-cabloy/package.json +2 -2
- package/zova/src/suite-vendor/a-zova/modules/a-bean/cli/controller/metadata/generateMetaPage.ts +3 -1
- package/zova/src/suite-vendor/a-zova/modules/a-bean/package.json +1 -1
- package/zova/src/suite-vendor/a-zova/modules/a-fetch/package.json +2 -2
- package/zova/src/suite-vendor/a-zova/modules/a-openapi/package.json +1 -1
- package/zova/src/suite-vendor/a-zova/modules/a-openapi/src/model/sdk.ts +3 -1
- package/zova/src/suite-vendor/a-zova/modules/a-router/package.json +1 -1
- package/zova/src/suite-vendor/a-zova/modules/a-router/src/bean/sys.router.ts +35 -8
- package/zova/src/suite-vendor/a-zova/modules/a-router/src/monkeySys.ts +28 -12
- package/zova/src/suite-vendor/a-zova/modules/a-router/src/service/routerGuards.ts +6 -8
- package/zova/src/suite-vendor/a-zova/modules/a-router/src/types/router.ts +14 -2
- package/zova/src/suite-vendor/a-zova/modules/a-router/src/types/utils.ts +4 -1
- package/zova/src/suite-vendor/a-zova/package.json +5 -5
- package/CLAUDE.local.md +0 -4
- /package/e2e/specs/{a-basic → cabloy-basic}/basic.spec.ts +0 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
import type { IQueryParams } from 'vona-module-a-orm';
|
|
3
|
+
|
|
4
|
+
import { BeanBase } from 'vona';
|
|
5
|
+
import { Service } from 'vona-module-a-bean';
|
|
6
|
+
import { Core } from 'vona-module-a-core';
|
|
7
|
+
|
|
8
|
+
import type { DtoStockAdjust } from '../dto/stockAdjust.tsx';
|
|
9
|
+
import type { DtoStockBalanceSelectRes } from '../dto/stockBalanceSelectRes.tsx';
|
|
10
|
+
import type { DtoStockBalanceView } from '../dto/stockBalanceView.tsx';
|
|
11
|
+
import type { EntityStockBalance } from '../entity/stockBalance.tsx';
|
|
12
|
+
import type {
|
|
13
|
+
EntityStockReservation,
|
|
14
|
+
TypeStockReservationState,
|
|
15
|
+
} from '../entity/stockReservation.tsx';
|
|
16
|
+
import type { ModelStockBalance } from '../model/stockBalance.ts';
|
|
17
|
+
|
|
18
|
+
export interface IStockReservationCommand {
|
|
19
|
+
skuId: TableIdentity;
|
|
20
|
+
quantity: number;
|
|
21
|
+
correlationId: string;
|
|
22
|
+
reason: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IStockReservationTransition {
|
|
26
|
+
reservationId: TableIdentity;
|
|
27
|
+
reason: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@Service()
|
|
31
|
+
export class ServiceStockBalance extends BeanBase {
|
|
32
|
+
async select(params?: IQueryParams<ModelStockBalance>): Promise<DtoStockBalanceSelectRes> {
|
|
33
|
+
return await this.scope.model.stockBalance.selectAndCount(params);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async view(id: TableIdentity): Promise<DtoStockBalanceView | undefined> {
|
|
37
|
+
return await this.scope.model.stockBalance.getById(id);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
41
|
+
async adjustStock(stockAdjust: DtoStockAdjust): Promise<EntityStockBalance> {
|
|
42
|
+
const sku = await this.$scope.commerceCatalog.model.sku.getById(stockAdjust.skuId);
|
|
43
|
+
if (!sku) {
|
|
44
|
+
this.app.throw(404, 'SKU not found');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let stockBalance = await this.scope.model.stockBalance.getForUpdate({
|
|
48
|
+
skuId: stockAdjust.skuId,
|
|
49
|
+
});
|
|
50
|
+
if (!stockBalance) {
|
|
51
|
+
if (stockAdjust.delta < 0) {
|
|
52
|
+
throw new Error('stock adjustment would make balance negative');
|
|
53
|
+
}
|
|
54
|
+
stockBalance = await this.scope.model.stockBalance.insert({
|
|
55
|
+
skuId: stockAdjust.skuId,
|
|
56
|
+
onHand: stockAdjust.delta,
|
|
57
|
+
reserved: 0,
|
|
58
|
+
available: stockAdjust.delta,
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
const onHand = stockBalance.onHand + stockAdjust.delta;
|
|
62
|
+
const reserved = stockBalance.reserved;
|
|
63
|
+
const available = onHand - reserved;
|
|
64
|
+
if (onHand < 0 || reserved < 0 || available < 0) {
|
|
65
|
+
throw new Error('stock adjustment would make balance negative');
|
|
66
|
+
}
|
|
67
|
+
await this.scope.model.stockBalance.updateById(stockBalance.id, {
|
|
68
|
+
onHand,
|
|
69
|
+
reserved,
|
|
70
|
+
available,
|
|
71
|
+
});
|
|
72
|
+
stockBalance = {
|
|
73
|
+
...stockBalance,
|
|
74
|
+
onHand,
|
|
75
|
+
reserved,
|
|
76
|
+
available,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
await this._appendAudit({
|
|
81
|
+
stockBalance,
|
|
82
|
+
delta: stockAdjust.delta,
|
|
83
|
+
operation: 'adjust',
|
|
84
|
+
reason: stockAdjust.reason,
|
|
85
|
+
correlationId: stockAdjust.correlationId,
|
|
86
|
+
});
|
|
87
|
+
return stockBalance;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
91
|
+
async reserve(command: IStockReservationCommand): Promise<EntityStockReservation> {
|
|
92
|
+
this._assertReservationCommand(command);
|
|
93
|
+
const sku = await this.$scope.commerceCatalog.model.sku.getById(command.skuId, {
|
|
94
|
+
include: {
|
|
95
|
+
product: {
|
|
96
|
+
include: {
|
|
97
|
+
category: true,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
if (!sku || sku.lifecycle !== 'active') {
|
|
103
|
+
this.app.throw(404, 'SKU not found');
|
|
104
|
+
}
|
|
105
|
+
if (!sku.product?.published || !sku.product.category?.published) {
|
|
106
|
+
this.app.throw(409, 'SKU is not sellable');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const stockBalance = await this._getLockedBalance(command.skuId);
|
|
110
|
+
if (!stockBalance) {
|
|
111
|
+
this.app.throw(409, 'insufficient available stock');
|
|
112
|
+
}
|
|
113
|
+
const existingReservation = await this.scope.model.stockReservation.get({
|
|
114
|
+
correlationId: command.correlationId,
|
|
115
|
+
});
|
|
116
|
+
if (existingReservation) {
|
|
117
|
+
if (
|
|
118
|
+
String(existingReservation.skuId) !== String(command.skuId) ||
|
|
119
|
+
existingReservation.quantity !== command.quantity
|
|
120
|
+
) {
|
|
121
|
+
this.app.throw(409, 'stock reservation correlation conflicts with an existing reservation');
|
|
122
|
+
}
|
|
123
|
+
return existingReservation;
|
|
124
|
+
}
|
|
125
|
+
if (stockBalance.available < command.quantity) {
|
|
126
|
+
this.app.throw(409, 'insufficient available stock');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const reservation = await this.scope.model.stockReservation.insert({
|
|
130
|
+
stockBalanceId: stockBalance.id,
|
|
131
|
+
skuId: command.skuId,
|
|
132
|
+
quantity: command.quantity,
|
|
133
|
+
state: 'reserved',
|
|
134
|
+
correlationId: command.correlationId,
|
|
135
|
+
});
|
|
136
|
+
const updatedBalance = await this._updateBalance(stockBalance, {
|
|
137
|
+
onHand: stockBalance.onHand,
|
|
138
|
+
reserved: stockBalance.reserved + command.quantity,
|
|
139
|
+
});
|
|
140
|
+
await this._appendAudit({
|
|
141
|
+
stockBalance: updatedBalance,
|
|
142
|
+
stockReservationId: reservation.id,
|
|
143
|
+
delta: -command.quantity,
|
|
144
|
+
operation: 'reserve',
|
|
145
|
+
reason: command.reason,
|
|
146
|
+
correlationId: command.correlationId,
|
|
147
|
+
});
|
|
148
|
+
return reservation;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
152
|
+
async consume(transition: IStockReservationTransition): Promise<EntityStockReservation> {
|
|
153
|
+
return await this._transitionReservation(
|
|
154
|
+
transition,
|
|
155
|
+
'reserved',
|
|
156
|
+
'consumed',
|
|
157
|
+
(stockBalance, reservation) => ({
|
|
158
|
+
onHand: stockBalance.onHand - reservation.quantity,
|
|
159
|
+
reserved: stockBalance.reserved - reservation.quantity,
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
165
|
+
async release(transition: IStockReservationTransition): Promise<EntityStockReservation> {
|
|
166
|
+
return await this._transitionReservation(
|
|
167
|
+
transition,
|
|
168
|
+
'reserved',
|
|
169
|
+
'released',
|
|
170
|
+
(stockBalance, reservation) => ({
|
|
171
|
+
onHand: stockBalance.onHand,
|
|
172
|
+
reserved: stockBalance.reserved - reservation.quantity,
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
178
|
+
async restore(transition: IStockReservationTransition): Promise<EntityStockReservation> {
|
|
179
|
+
return await this._transitionReservation(
|
|
180
|
+
transition,
|
|
181
|
+
'consumed',
|
|
182
|
+
'restored',
|
|
183
|
+
(stockBalance, reservation) => ({
|
|
184
|
+
onHand: stockBalance.onHand + reservation.quantity,
|
|
185
|
+
reserved: stockBalance.reserved,
|
|
186
|
+
}),
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private async _transitionReservation(
|
|
191
|
+
transition: IStockReservationTransition,
|
|
192
|
+
sourceState: TypeStockReservationState,
|
|
193
|
+
targetState: TypeStockReservationState,
|
|
194
|
+
calculateBalance: (
|
|
195
|
+
stockBalance: EntityStockBalance,
|
|
196
|
+
reservation: EntityStockReservation,
|
|
197
|
+
) => Pick<EntityStockBalance, 'onHand' | 'reserved'>,
|
|
198
|
+
): Promise<EntityStockReservation> {
|
|
199
|
+
if (!transition.reason.trim()) {
|
|
200
|
+
this.app.throw(400, 'stock reservation reason is required');
|
|
201
|
+
}
|
|
202
|
+
const reservation = await this.scope.model.stockReservation.getByIdForUpdate(
|
|
203
|
+
transition.reservationId,
|
|
204
|
+
);
|
|
205
|
+
if (!reservation) {
|
|
206
|
+
this.app.throw(404, 'stock reservation not found');
|
|
207
|
+
}
|
|
208
|
+
if (reservation.state === targetState) {
|
|
209
|
+
return reservation;
|
|
210
|
+
}
|
|
211
|
+
if (reservation.state !== sourceState) {
|
|
212
|
+
this.app.throw(409, `cannot ${targetState} a ${reservation.state} stock reservation`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const stockBalance = await this.scope.model.stockBalance.getByIdForUpdate(
|
|
216
|
+
reservation.stockBalanceId,
|
|
217
|
+
);
|
|
218
|
+
if (!stockBalance) {
|
|
219
|
+
this.app.throw(404, 'stock balance not found');
|
|
220
|
+
}
|
|
221
|
+
const updatedBalance = await this._updateBalance(
|
|
222
|
+
stockBalance,
|
|
223
|
+
calculateBalance(stockBalance, reservation),
|
|
224
|
+
);
|
|
225
|
+
await this.scope.model.stockReservation.updateById(reservation.id, { state: targetState });
|
|
226
|
+
const updatedReservation = { ...reservation, state: targetState };
|
|
227
|
+
const operation =
|
|
228
|
+
targetState === 'consumed' ? 'consume' : targetState === 'released' ? 'release' : 'restore';
|
|
229
|
+
await this._appendAudit({
|
|
230
|
+
stockBalance: updatedBalance,
|
|
231
|
+
stockReservationId: reservation.id,
|
|
232
|
+
delta:
|
|
233
|
+
operation === 'consume'
|
|
234
|
+
? -reservation.quantity
|
|
235
|
+
: operation === 'restore'
|
|
236
|
+
? reservation.quantity
|
|
237
|
+
: 0,
|
|
238
|
+
operation,
|
|
239
|
+
reason: transition.reason,
|
|
240
|
+
correlationId: reservation.correlationId,
|
|
241
|
+
});
|
|
242
|
+
return updatedReservation;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private async _getLockedBalance(skuId: TableIdentity): Promise<EntityStockBalance | undefined> {
|
|
246
|
+
return await this.scope.model.stockBalance.getForUpdate({ skuId });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private async _updateBalance(
|
|
250
|
+
stockBalance: EntityStockBalance,
|
|
251
|
+
values: Pick<EntityStockBalance, 'onHand' | 'reserved'>,
|
|
252
|
+
): Promise<EntityStockBalance> {
|
|
253
|
+
const available = values.onHand - values.reserved;
|
|
254
|
+
if (values.onHand < 0 || values.reserved < 0 || available < 0) {
|
|
255
|
+
this.app.throw(409, 'stock balance would become negative');
|
|
256
|
+
}
|
|
257
|
+
await this.scope.model.stockBalance.updateById(stockBalance.id, {
|
|
258
|
+
onHand: values.onHand,
|
|
259
|
+
reserved: values.reserved,
|
|
260
|
+
available,
|
|
261
|
+
});
|
|
262
|
+
return { ...stockBalance, ...values, available };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private async _appendAudit({
|
|
266
|
+
stockBalance,
|
|
267
|
+
stockReservationId,
|
|
268
|
+
delta,
|
|
269
|
+
operation,
|
|
270
|
+
reason,
|
|
271
|
+
correlationId,
|
|
272
|
+
}: {
|
|
273
|
+
stockBalance: EntityStockBalance;
|
|
274
|
+
stockReservationId?: TableIdentity;
|
|
275
|
+
delta: number;
|
|
276
|
+
operation: 'adjust' | 'reserve' | 'consume' | 'release' | 'restore';
|
|
277
|
+
reason: string;
|
|
278
|
+
correlationId: string;
|
|
279
|
+
}) {
|
|
280
|
+
await this.scope.model.stockAudit.insert({
|
|
281
|
+
stockBalanceId: stockBalance.id,
|
|
282
|
+
skuId: stockBalance.skuId,
|
|
283
|
+
stockReservationId,
|
|
284
|
+
operation,
|
|
285
|
+
delta,
|
|
286
|
+
reason,
|
|
287
|
+
correlationId,
|
|
288
|
+
onHand: stockBalance.onHand,
|
|
289
|
+
reserved: stockBalance.reserved,
|
|
290
|
+
available: stockBalance.available,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private _assertReservationCommand(command: IStockReservationCommand) {
|
|
295
|
+
if (!Number.isInteger(command.quantity) || command.quantity <= 0) {
|
|
296
|
+
this.app.throw(400, 'stock reservation quantity must be a positive integer');
|
|
297
|
+
}
|
|
298
|
+
if (!command.correlationId.trim()) {
|
|
299
|
+
this.app.throw(400, 'stock reservation correlationId is required');
|
|
300
|
+
}
|
|
301
|
+
if (!command.reason.trim()) {
|
|
302
|
+
this.app.throw(400, 'stock reservation reason is required');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { DtoCartAddItem, DtoCartUpdateItem } from 'vona-module-commerce-trade';
|
|
2
|
+
|
|
3
|
+
import { catchError } from '@cabloy/utils';
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { describe, it } from 'node:test';
|
|
6
|
+
import { app } from 'vona-mock';
|
|
7
|
+
|
|
8
|
+
const actionPath = '/commerce/trade/cart';
|
|
9
|
+
|
|
10
|
+
function cartItem(skuId: number, quantity = 1): DtoCartAddItem {
|
|
11
|
+
return { skuId, quantity };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function performAs(accessToken: string, method: string, path: string, options = {}) {
|
|
15
|
+
return await app.bean.executor.newCtxIsolate(async () => {
|
|
16
|
+
return await app.bean.executor.performAction(method, path, {
|
|
17
|
+
...options,
|
|
18
|
+
authToken: accessToken,
|
|
19
|
+
innerAccess: false,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function registerAndSignin(name: string) {
|
|
25
|
+
await app.bean.user.register({ name }, true);
|
|
26
|
+
const token = await app.bean.passport.signinMock(name as any);
|
|
27
|
+
return { token: token.accessToken, user: app.bean.passport.currentUser! };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function createSellableSku(suffix: string) {
|
|
31
|
+
await app.bean.passport.signinMock();
|
|
32
|
+
try {
|
|
33
|
+
const categoryId = await app.bean.executor.performAction('post', '/commerce/catalog/category', {
|
|
34
|
+
body: { name: `cart-category-${suffix}`, published: true },
|
|
35
|
+
});
|
|
36
|
+
const productId = await app.bean.executor.performAction('post', '/commerce/catalog/product', {
|
|
37
|
+
body: { categoryId, title: `cart-product-${suffix}`, published: true },
|
|
38
|
+
});
|
|
39
|
+
const skuId = await app.bean.executor.performAction('post', '/commerce/catalog/sku', {
|
|
40
|
+
body: {
|
|
41
|
+
productId,
|
|
42
|
+
code: `cart-sku-${suffix}`,
|
|
43
|
+
priceCents: 100,
|
|
44
|
+
lifecycle: 'active',
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
await app.bean.executor.performAction('post', '/commerce/trade/stockBalance/adjustStock', {
|
|
48
|
+
body: {
|
|
49
|
+
skuId,
|
|
50
|
+
delta: 10,
|
|
51
|
+
reason: `cart stock ${suffix}`,
|
|
52
|
+
correlationId: `cart-stock-${suffix}`,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
return skuId;
|
|
56
|
+
} finally {
|
|
57
|
+
await app.bean.passport.signout();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('cartOwnership.test.ts', () => {
|
|
62
|
+
it('denies anonymous cart actions', async () => {
|
|
63
|
+
await app.bean.executor.mockCtx(async () => {
|
|
64
|
+
for (const [method, path, options] of [
|
|
65
|
+
['get', actionPath, {}],
|
|
66
|
+
['post', `${actionPath}/items`, { body: cartItem(1) }],
|
|
67
|
+
['patch', `${actionPath}/items/:id`, { params: { id: 999999 }, body: { quantity: 1 } }],
|
|
68
|
+
['delete', `${actionPath}/items/:id`, { params: { id: 999999 } }],
|
|
69
|
+
['delete', `${actionPath}/items`, {}],
|
|
70
|
+
] as const) {
|
|
71
|
+
const [_, err] = await catchError(() =>
|
|
72
|
+
app.bean.executor.performAction(method, path, { ...options, innerAccess: false }),
|
|
73
|
+
);
|
|
74
|
+
assert.equal(err?.code, 401);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('derives cart ownership from the authenticated customer and scopes every item action', async () => {
|
|
80
|
+
await app.bean.executor.mockCtx(async () => {
|
|
81
|
+
const suffix = `${Date.now()}`;
|
|
82
|
+
const skuId = await createSellableSku(suffix);
|
|
83
|
+
const customerA = await registerAndSignin(`cart-a-${suffix}`);
|
|
84
|
+
const customerB = await registerAndSignin(`cart-b-${suffix}`);
|
|
85
|
+
|
|
86
|
+
const cart = await performAs(customerA.token, 'post', `${actionPath}/items`, {
|
|
87
|
+
body: { ...cartItem(skuId, 2), userId: customerB.user.id, iid: 999999 } as any,
|
|
88
|
+
});
|
|
89
|
+
assert.equal(cart.items.length, 1);
|
|
90
|
+
assert.equal(cart.items[0].quantity, 2);
|
|
91
|
+
assert.equal(Object.hasOwn(cart, 'userId'), false);
|
|
92
|
+
assert.equal(Object.hasOwn(cart, 'iid'), false);
|
|
93
|
+
const itemId = cart.items[0].id;
|
|
94
|
+
|
|
95
|
+
const persistedCart = await app.scope('commerce-trade').model.cart.getById(cart.id);
|
|
96
|
+
assert.equal(String(persistedCart?.userId), String(customerA.user.id));
|
|
97
|
+
assert.equal(persistedCart?.iid, app.ctx.instance.id);
|
|
98
|
+
const persistedItem = await app.scope('commerce-trade').model.cartItem.getById(itemId);
|
|
99
|
+
assert.equal(String(persistedItem?.cartId), String(cart.id));
|
|
100
|
+
|
|
101
|
+
const updated = await performAs(customerA.token, 'patch', `${actionPath}/items/:id`, {
|
|
102
|
+
params: { id: itemId },
|
|
103
|
+
body: { quantity: 3 } satisfies DtoCartUpdateItem,
|
|
104
|
+
});
|
|
105
|
+
assert.equal(updated.items[0].quantity, 3);
|
|
106
|
+
|
|
107
|
+
assert.deepEqual(await performAs(customerB.token, 'get', actionPath), { items: [] });
|
|
108
|
+
assert.deepEqual(
|
|
109
|
+
await performAs(customerB.token, 'patch', `${actionPath}/items/:id`, {
|
|
110
|
+
params: { id: itemId },
|
|
111
|
+
body: { quantity: 1 },
|
|
112
|
+
}),
|
|
113
|
+
{ items: [] },
|
|
114
|
+
);
|
|
115
|
+
assert.deepEqual(
|
|
116
|
+
await performAs(customerB.token, 'delete', `${actionPath}/items/:id`, {
|
|
117
|
+
params: { id: itemId },
|
|
118
|
+
}),
|
|
119
|
+
{ items: [] },
|
|
120
|
+
);
|
|
121
|
+
assert.equal((await app.scope('commerce-trade').model.cartItem.getById(itemId))?.quantity, 3);
|
|
122
|
+
|
|
123
|
+
const merged = await performAs(customerA.token, 'post', `${actionPath}/items`, {
|
|
124
|
+
body: cartItem(skuId, 2),
|
|
125
|
+
});
|
|
126
|
+
assert.equal(merged.items.length, 1);
|
|
127
|
+
assert.equal(merged.items[0].quantity, 5);
|
|
128
|
+
|
|
129
|
+
const cleared = await performAs(customerA.token, 'delete', `${actionPath}/items`);
|
|
130
|
+
assert.deepEqual(cleared.items, []);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('treats another instance cart as absent', async () => {
|
|
135
|
+
let itemId!: number;
|
|
136
|
+
let customerDefault!: Awaited<ReturnType<typeof registerAndSignin>>;
|
|
137
|
+
await app.bean.executor.mockCtx(async () => {
|
|
138
|
+
const suffix = `${Date.now()}`;
|
|
139
|
+
const skuId = await createSellableSku(suffix);
|
|
140
|
+
customerDefault = await registerAndSignin(`cart-default-${suffix}`);
|
|
141
|
+
const cart = await performAs(customerDefault.token, 'post', `${actionPath}/items`, {
|
|
142
|
+
body: cartItem(skuId),
|
|
143
|
+
});
|
|
144
|
+
itemId = cart.items[0].id;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
await app.bean.executor.mockCtx(
|
|
148
|
+
async () => {
|
|
149
|
+
const customer = await registerAndSignin(`cart-share-${Date.now()}`);
|
|
150
|
+
assert.deepEqual(await performAs(customer.token, 'get', actionPath), { items: [] });
|
|
151
|
+
assert.deepEqual(
|
|
152
|
+
await performAs(customer.token, 'patch', `${actionPath}/items/:id`, {
|
|
153
|
+
params: { id: itemId },
|
|
154
|
+
body: { quantity: 2 },
|
|
155
|
+
}),
|
|
156
|
+
{ items: [] },
|
|
157
|
+
);
|
|
158
|
+
assert.deepEqual(
|
|
159
|
+
await performAs(customer.token, 'delete', `${actionPath}/items/:id`, {
|
|
160
|
+
params: { id: itemId },
|
|
161
|
+
}),
|
|
162
|
+
{ items: [] },
|
|
163
|
+
);
|
|
164
|
+
},
|
|
165
|
+
{ instanceName: 'shareTest' as any },
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
await app.bean.executor.mockCtx(async () => {
|
|
169
|
+
const cart = await performAs(customerDefault.token, 'get', actionPath);
|
|
170
|
+
assert.equal(cart.items.length, 1);
|
|
171
|
+
assert.equal(cart.items[0].id, itemId);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { describe, it } from 'node:test';
|
|
3
|
+
import { app } from 'vona-mock';
|
|
4
|
+
|
|
5
|
+
describe('stockAudit.test.ts', () => {
|
|
6
|
+
it('action:stockAudit permits system-admin read actions only', async () => {
|
|
7
|
+
await app.bean.executor.mockCtx(async () => {
|
|
8
|
+
await app.bean.passport.signinMock();
|
|
9
|
+
try {
|
|
10
|
+
const actions = ['select', 'view'];
|
|
11
|
+
const permissions = await Promise.all(
|
|
12
|
+
actions.map(action =>
|
|
13
|
+
app.bean.permission.retrievePermissionAction('commerce-trade:stockAudit', action),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
16
|
+
assert.deepEqual(
|
|
17
|
+
permissions,
|
|
18
|
+
actions.map(() => true),
|
|
19
|
+
);
|
|
20
|
+
assert.equal(
|
|
21
|
+
await app.bean.permission.retrievePermissionAction('commerce-trade:stockAudit', 'create'),
|
|
22
|
+
false,
|
|
23
|
+
);
|
|
24
|
+
assert.equal(
|
|
25
|
+
await app.bean.permission.retrievePermissionAction('commerce-trade:stockAudit', 'update'),
|
|
26
|
+
false,
|
|
27
|
+
);
|
|
28
|
+
assert.equal(
|
|
29
|
+
await app.bean.permission.retrievePermissionAction('commerce-trade:stockAudit', 'delete'),
|
|
30
|
+
false,
|
|
31
|
+
);
|
|
32
|
+
} finally {
|
|
33
|
+
await app.bean.passport.signout();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { DtoStockAdjust, EntityStockBalance } from 'vona-module-commerce-trade';
|
|
2
|
+
|
|
3
|
+
import { catchError } from '@cabloy/utils';
|
|
4
|
+
import assert from 'node:assert';
|
|
5
|
+
import { describe, it } from 'node:test';
|
|
6
|
+
import { app } from 'vona-mock';
|
|
7
|
+
|
|
8
|
+
const actionPath = '/commerce/trade/stockBalance/adjustStock';
|
|
9
|
+
|
|
10
|
+
function stockAdjust(skuId: number, delta: number, suffix: string): DtoStockAdjust {
|
|
11
|
+
return {
|
|
12
|
+
skuId,
|
|
13
|
+
delta,
|
|
14
|
+
reason: `test adjustment ${suffix}`,
|
|
15
|
+
correlationId: `stock-test-${suffix}`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function createSku(suffix: string): Promise<number> {
|
|
20
|
+
const categoryId = await app.bean.executor.performAction('post', '/commerce/catalog/category', {
|
|
21
|
+
body: { name: `stock-category-${suffix}`, published: true },
|
|
22
|
+
});
|
|
23
|
+
const productId = await app.bean.executor.performAction('post', '/commerce/catalog/product', {
|
|
24
|
+
body: { categoryId, title: `stock-product-${suffix}`, published: true },
|
|
25
|
+
});
|
|
26
|
+
return await app.bean.executor.performAction('post', '/commerce/catalog/sku', {
|
|
27
|
+
body: {
|
|
28
|
+
productId,
|
|
29
|
+
code: `stock-sku-${suffix}`,
|
|
30
|
+
priceCents: 100,
|
|
31
|
+
lifecycle: 'active',
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function adjustStock(stockAdjust: DtoStockAdjust): Promise<EntityStockBalance> {
|
|
37
|
+
return await app.bean.executor.performAction('post', actionPath, { body: stockAdjust });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('stockBalance.test.ts', () => {
|
|
41
|
+
it('action:stockBalance:adjustStock appends an audit with server-scoped balance', async () => {
|
|
42
|
+
await app.bean.executor.mockCtx(async () => {
|
|
43
|
+
await app.bean.passport.signinMock();
|
|
44
|
+
try {
|
|
45
|
+
const skuId = await createSku(`${Date.now()}`);
|
|
46
|
+
const balance = await adjustStock(stockAdjust(skuId, 8, `${skuId}-initial`));
|
|
47
|
+
assert.equal(balance.onHand, 8);
|
|
48
|
+
assert.equal(balance.reserved, 0);
|
|
49
|
+
assert.equal(balance.available, 8);
|
|
50
|
+
|
|
51
|
+
const adjusted = await adjustStock(stockAdjust(skuId, -3, `${skuId}-decrement`));
|
|
52
|
+
assert.equal(adjusted.id, balance.id);
|
|
53
|
+
assert.equal(adjusted.onHand, 5);
|
|
54
|
+
assert.equal(adjusted.reserved, 0);
|
|
55
|
+
assert.equal(adjusted.available, 5);
|
|
56
|
+
|
|
57
|
+
const audits = await app.scope('commerce-trade').model.stockAudit.select({
|
|
58
|
+
where: { skuId },
|
|
59
|
+
});
|
|
60
|
+
assert.equal(audits.length, 2);
|
|
61
|
+
assert.deepEqual(
|
|
62
|
+
audits.map(item => [item.delta, item.onHand, item.reserved, item.available]),
|
|
63
|
+
[
|
|
64
|
+
[8, 8, 0, 8],
|
|
65
|
+
[-3, 5, 0, 5],
|
|
66
|
+
],
|
|
67
|
+
);
|
|
68
|
+
assert.equal(audits[1].stockBalanceId, balance.id);
|
|
69
|
+
} finally {
|
|
70
|
+
await app.bean.passport.signout();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('action:stockBalance:adjustStock rejects negative stock without an audit', async () => {
|
|
76
|
+
await app.bean.executor.mockCtx(async () => {
|
|
77
|
+
await app.bean.passport.signinMock();
|
|
78
|
+
try {
|
|
79
|
+
const skuId = await createSku(`${Date.now()}`);
|
|
80
|
+
const balance = await adjustStock(stockAdjust(skuId, 2, `${skuId}-initial`));
|
|
81
|
+
const [_, err] = await catchError(() =>
|
|
82
|
+
adjustStock(stockAdjust(skuId, -3, `${skuId}-reject`)),
|
|
83
|
+
);
|
|
84
|
+
assert.match(err?.message ?? '', /negative/);
|
|
85
|
+
|
|
86
|
+
const unchanged = await app.scope('commerce-trade').model.stockBalance.getById(balance.id);
|
|
87
|
+
assert.equal(unchanged?.onHand, 2);
|
|
88
|
+
assert.equal(unchanged?.available, 2);
|
|
89
|
+
const audits = await app.scope('commerce-trade').model.stockAudit.select({
|
|
90
|
+
where: { skuId },
|
|
91
|
+
});
|
|
92
|
+
assert.equal(audits.length, 1);
|
|
93
|
+
} finally {
|
|
94
|
+
await app.bean.passport.signout();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('action:stockBalance:adjustStock rolls back the balance when audit insertion fails', async () => {
|
|
100
|
+
await app.bean.executor.mockCtx(async () => {
|
|
101
|
+
await app.bean.passport.signinMock();
|
|
102
|
+
try {
|
|
103
|
+
const skuId = await createSku(`${Date.now()}`);
|
|
104
|
+
const balance = await adjustStock(stockAdjust(skuId, 4, `${skuId}-initial`));
|
|
105
|
+
const modelStockAudit = app.scope('commerce-trade').model.stockAudit;
|
|
106
|
+
const insert = modelStockAudit.insert.bind(modelStockAudit);
|
|
107
|
+
(modelStockAudit as any).insert = async () => {
|
|
108
|
+
throw new Error('audit insert failure');
|
|
109
|
+
};
|
|
110
|
+
try {
|
|
111
|
+
const [_, err] = await catchError(() =>
|
|
112
|
+
adjustStock(stockAdjust(skuId, 1, `${skuId}-rollback`)),
|
|
113
|
+
);
|
|
114
|
+
assert.match(err?.message ?? '', /audit insert failure/);
|
|
115
|
+
} finally {
|
|
116
|
+
(modelStockAudit as any).insert = insert;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const unchanged = await app.scope('commerce-trade').model.stockBalance.getById(balance.id);
|
|
120
|
+
assert.equal(unchanged?.onHand, 4);
|
|
121
|
+
assert.equal(unchanged?.available, 4);
|
|
122
|
+
} finally {
|
|
123
|
+
await app.bean.passport.signout();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('action:stockBalance:adjustStock treats a missing SKU as not found', async () => {
|
|
129
|
+
await app.bean.executor.mockCtx(async () => {
|
|
130
|
+
await app.bean.passport.signinMock();
|
|
131
|
+
try {
|
|
132
|
+
const skuId = 999999999;
|
|
133
|
+
const [_, err] = await catchError(() =>
|
|
134
|
+
adjustStock(stockAdjust(skuId, 1, `${skuId}-missing`)),
|
|
135
|
+
);
|
|
136
|
+
assert.equal(err?.code, 404);
|
|
137
|
+
assert.equal(
|
|
138
|
+
await app.scope('commerce-trade').model.stockBalance.get({ skuId }),
|
|
139
|
+
undefined,
|
|
140
|
+
);
|
|
141
|
+
assert.deepEqual(
|
|
142
|
+
await app.scope('commerce-trade').model.stockAudit.select({ where: { skuId } }),
|
|
143
|
+
[],
|
|
144
|
+
);
|
|
145
|
+
} finally {
|
|
146
|
+
await app.bean.passport.signout();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('action:stockBalance:adjustStock treats a cross-instance SKU as not found', async () => {
|
|
152
|
+
let skuId!: number;
|
|
153
|
+
await app.bean.executor.mockCtx(async () => {
|
|
154
|
+
await app.bean.passport.signinMock();
|
|
155
|
+
try {
|
|
156
|
+
skuId = await createSku(`${Date.now()}`);
|
|
157
|
+
await adjustStock(stockAdjust(skuId, 5, `${skuId}-default`));
|
|
158
|
+
} finally {
|
|
159
|
+
await app.bean.passport.signout();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
await app.bean.executor.mockCtx(
|
|
164
|
+
async () => {
|
|
165
|
+
await app.bean.passport.signinMock();
|
|
166
|
+
try {
|
|
167
|
+
const [_, err] = await catchError(() =>
|
|
168
|
+
adjustStock(stockAdjust(skuId, 1, `${skuId}-share`)),
|
|
169
|
+
);
|
|
170
|
+
assert.equal(err?.code, 404);
|
|
171
|
+
assert.equal(
|
|
172
|
+
await app.scope('commerce-trade').model.stockBalance.get({ skuId }),
|
|
173
|
+
undefined,
|
|
174
|
+
);
|
|
175
|
+
assert.deepEqual(
|
|
176
|
+
await app.scope('commerce-trade').model.stockAudit.select({ where: { skuId } }),
|
|
177
|
+
[],
|
|
178
|
+
);
|
|
179
|
+
} finally {
|
|
180
|
+
await app.bean.passport.signout();
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{ instanceName: 'shareTest' as any },
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
});
|