cabloy 5.1.111 → 5.1.113
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 +31 -1
- package/.claude/skills/cabloy-backend-scaffold/references/follow-up-checklist.md +21 -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 +77 -0
- package/.github/workflows/vona-test-pg.yml +8 -0
- package/.gitignore +1 -0
- package/CHANGELOG.md +30 -0
- package/CLAUDE.md +6 -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/migration-and-changes.md +13 -9
- 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/backend/unit-testing.md +25 -0
- 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/scripts/startE2eVona.ts +51 -13
- package/e2e/specs/a-commerce/commerce.spec.ts +125 -1
- package/e2e/specs/{a-basic → cabloy-basic}/basic.spec.ts +12 -7
- package/package.json +2 -1
- package/scripts/init.ts +6 -12
- package/scripts/upgrade.ts +3 -1
- package/vona/packages-cli/cli/package.json +1 -1
- package/vona/packages-cli/cli-set-api/package.json +1 -1
- package/vona/packages-cli/cli-set-api/src/lib/bean/cli.bin.test.ts +6 -9
- package/vona/packages-cli/cli-set-api/toolsIsolate/test.ts +50 -21
- package/vona/packages-vona/vona/package.json +1 -1
- package/vona/pnpm-lock.yaml +94 -163
- package/vona/src/backend/config/config/config.test.ts +1 -1
- 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 +592 -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 +83 -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 +29 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/src/config/locale/zh-cn.ts +29 -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 +118 -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 +342 -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 +389 -0
- package/vona/src/suite/a-commerce/modules/commerce-trade/test/stockReservation.test.ts +457 -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-startup/package.json +1 -1
- package/vona/src/suite-vendor/a-vona/modules/a-startup/src/service/startup.ts +2 -2
- 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-version/src/service/version.ts +12 -12
- package/vona/src/suite-vendor/a-vona/modules/a-version/src/types/version.ts +4 -4
- 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 +107 -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 +78 -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/a-home/modules/home-layoutadmin/src/component/layoutAdmin/controller.tsx +17 -7
- package/zova/src/suite/a-home/modules/home-layoutadmin/src/component/layoutAdmin/render.header.tsx +1 -1
- package/zova/src/suite/a-home/modules/home-layoutweb/src/component/layoutWeb/controller.tsx +17 -7
- 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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
|
|
3
|
+
import { BeanBase } from 'vona';
|
|
4
|
+
import { Service } from 'vona-module-a-bean';
|
|
5
|
+
import { Core } from 'vona-module-a-core';
|
|
6
|
+
|
|
7
|
+
import type { DtoCartAddItem } from '../dto/cartAddItem.tsx';
|
|
8
|
+
import type { DtoCartItem } from '../dto/cartItem.tsx';
|
|
9
|
+
import type { DtoCartUpdateItem } from '../dto/cartUpdateItem.tsx';
|
|
10
|
+
import type { DtoCartView } from '../dto/cartView.tsx';
|
|
11
|
+
import type { EntityCart } from '../entity/cart.tsx';
|
|
12
|
+
|
|
13
|
+
@Service()
|
|
14
|
+
export class ServiceCart extends BeanBase {
|
|
15
|
+
async current(): Promise<DtoCartView> {
|
|
16
|
+
const cart = await this._getCurrentCart();
|
|
17
|
+
return await this._toCartView(cart);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
21
|
+
async addItem(command: DtoCartAddItem): Promise<DtoCartView> {
|
|
22
|
+
await this._assertSellableSku(command.skuId, command.quantity);
|
|
23
|
+
const cart = await this._getOrCreateCurrentCart();
|
|
24
|
+
const item = await this.scope.model.cartItem.getForUpdate({
|
|
25
|
+
cartId: cart.id,
|
|
26
|
+
skuId: command.skuId,
|
|
27
|
+
});
|
|
28
|
+
if (item) {
|
|
29
|
+
const quantity = item.quantity + command.quantity;
|
|
30
|
+
await this._assertSellableSku(command.skuId, quantity);
|
|
31
|
+
await this.scope.model.cartItem.updateById(item.id, { quantity });
|
|
32
|
+
} else {
|
|
33
|
+
await this.scope.model.cartItem.insert({
|
|
34
|
+
cartId: cart.id,
|
|
35
|
+
skuId: command.skuId,
|
|
36
|
+
quantity: command.quantity,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return await this._toCartView(cart);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
43
|
+
async updateItem(id: TableIdentity, command: DtoCartUpdateItem): Promise<DtoCartView> {
|
|
44
|
+
const cart = await this._getCurrentCartForUpdate();
|
|
45
|
+
if (!cart) return { items: [] };
|
|
46
|
+
const item = await this.scope.model.cartItem.getForUpdate({ id, cartId: cart.id });
|
|
47
|
+
if (!item) return await this._toCartView(cart);
|
|
48
|
+
await this._assertSellableSku(item.skuId, command.quantity);
|
|
49
|
+
await this.scope.model.cartItem.updateById(item.id, { quantity: command.quantity });
|
|
50
|
+
return await this._toCartView(cart);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
54
|
+
async deleteItem(id: TableIdentity): Promise<DtoCartView> {
|
|
55
|
+
const cart = await this._getCurrentCartForUpdate();
|
|
56
|
+
if (!cart) return { items: [] };
|
|
57
|
+
const item = await this.scope.model.cartItem.getForUpdate({ id, cartId: cart.id });
|
|
58
|
+
if (item) await this.scope.model.cartItem.deleteById(item.id);
|
|
59
|
+
return await this._toCartView(cart);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
63
|
+
async clear(): Promise<DtoCartView> {
|
|
64
|
+
const cart = await this._getCurrentCartForUpdate();
|
|
65
|
+
if (!cart) return { items: [] };
|
|
66
|
+
await this.scope.model.cartItem.delete({ cartId: cart.id });
|
|
67
|
+
return await this._toCartView(cart);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private _getCurrentUserId(): TableIdentity {
|
|
71
|
+
return this.bean.passport.currentUser!.id;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private async _getCurrentCart(): Promise<EntityCart | undefined> {
|
|
75
|
+
return await this.scope.model.cart.get({ userId: this._getCurrentUserId() });
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private async _getCurrentCartForUpdate(): Promise<EntityCart | undefined> {
|
|
79
|
+
return await this.scope.model.cart.getForUpdate({ userId: this._getCurrentUserId() });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async _getOrCreateCurrentCart(): Promise<EntityCart> {
|
|
83
|
+
let cart = await this._getCurrentCartForUpdate();
|
|
84
|
+
if (!cart) {
|
|
85
|
+
cart = await this.scope.model.cart.insert({ userId: this._getCurrentUserId() });
|
|
86
|
+
}
|
|
87
|
+
return cart;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private async _toCartView(cart: EntityCart | undefined): Promise<DtoCartView> {
|
|
91
|
+
if (!cart) return { items: [] };
|
|
92
|
+
const items = await this.scope.model.cartItem.select({
|
|
93
|
+
where: { cartId: cart.id },
|
|
94
|
+
orders: [['id', 'asc']],
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
id: cart.id,
|
|
98
|
+
items: (await Promise.all(items.map(item => this._toCartItem(item)))).flatMap(item =>
|
|
99
|
+
item ? [item] : [],
|
|
100
|
+
),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private async _toCartItem(item: {
|
|
105
|
+
id: TableIdentity;
|
|
106
|
+
skuId: TableIdentity;
|
|
107
|
+
quantity: number;
|
|
108
|
+
}): Promise<DtoCartItem | undefined> {
|
|
109
|
+
const sku = await this.$scope.commerceCatalog.model.sku.getById(item.skuId, {
|
|
110
|
+
include: {
|
|
111
|
+
product: {
|
|
112
|
+
include: {
|
|
113
|
+
category: true,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const balance = await this.scope.model.stockBalance.get({ skuId: item.skuId });
|
|
119
|
+
if (!sku || !sku.product || !sku.product.category || !balance) return undefined;
|
|
120
|
+
return {
|
|
121
|
+
id: item.id,
|
|
122
|
+
skuId: item.skuId,
|
|
123
|
+
quantity: item.quantity,
|
|
124
|
+
skuCode: sku.code,
|
|
125
|
+
productTitle: sku.product.title,
|
|
126
|
+
priceCents: sku.priceCents,
|
|
127
|
+
available: balance.available,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private async _assertSellableSku(skuId: TableIdentity, quantity: number) {
|
|
132
|
+
const sku = await this.$scope.commerceCatalog.model.sku.getById(skuId, {
|
|
133
|
+
include: {
|
|
134
|
+
product: {
|
|
135
|
+
include: {
|
|
136
|
+
category: true,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
if (!sku || sku.lifecycle !== 'active') {
|
|
142
|
+
this.app.throw(404, 'SKU not found');
|
|
143
|
+
}
|
|
144
|
+
if (!sku.product?.published || !sku.product.category?.published) {
|
|
145
|
+
this.app.throw(409, 'SKU is not sellable');
|
|
146
|
+
}
|
|
147
|
+
const balance = await this.scope.model.stockBalance.get({ skuId });
|
|
148
|
+
if (!balance || balance.available < quantity) {
|
|
149
|
+
this.app.throw(409, 'insufficient available stock');
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
|
|
7
|
+
import type { DtoStockAuditSelectRes } from '../dto/stockAuditSelectRes.tsx';
|
|
8
|
+
import type { DtoStockAuditView } from '../dto/stockAuditView.tsx';
|
|
9
|
+
import type { ModelStockAudit } from '../model/stockAudit.ts';
|
|
10
|
+
|
|
11
|
+
@Service()
|
|
12
|
+
export class ServiceStockAudit extends BeanBase {
|
|
13
|
+
async select(params?: IQueryParams<ModelStockAudit>): Promise<DtoStockAuditSelectRes> {
|
|
14
|
+
return await this.scope.model.stockAudit.selectAndCount(params);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async view(id: TableIdentity): Promise<DtoStockAuditView | undefined> {
|
|
18
|
+
return await this.scope.model.stockAudit.getById(id);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,342 @@
|
|
|
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
|
+
const priorBalance = stockBalance ?? {
|
|
51
|
+
onHand: 0,
|
|
52
|
+
reserved: 0,
|
|
53
|
+
available: 0,
|
|
54
|
+
};
|
|
55
|
+
if (!stockBalance) {
|
|
56
|
+
if (stockAdjust.delta < 0) {
|
|
57
|
+
throw new Error('stock adjustment would make balance negative');
|
|
58
|
+
}
|
|
59
|
+
stockBalance = await this.scope.model.stockBalance.insert({
|
|
60
|
+
skuId: stockAdjust.skuId,
|
|
61
|
+
onHand: stockAdjust.delta,
|
|
62
|
+
reserved: 0,
|
|
63
|
+
available: stockAdjust.delta,
|
|
64
|
+
});
|
|
65
|
+
} else {
|
|
66
|
+
const onHand = stockBalance.onHand + stockAdjust.delta;
|
|
67
|
+
const reserved = stockBalance.reserved;
|
|
68
|
+
const available = onHand - reserved;
|
|
69
|
+
if (onHand < 0 || reserved < 0 || available < 0) {
|
|
70
|
+
throw new Error('stock adjustment would make balance negative');
|
|
71
|
+
}
|
|
72
|
+
await this.scope.model.stockBalance.updateById(stockBalance.id, {
|
|
73
|
+
onHand,
|
|
74
|
+
reserved,
|
|
75
|
+
available,
|
|
76
|
+
});
|
|
77
|
+
stockBalance = {
|
|
78
|
+
...stockBalance,
|
|
79
|
+
onHand,
|
|
80
|
+
reserved,
|
|
81
|
+
available,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
await this._appendAudit({
|
|
86
|
+
stockBalance,
|
|
87
|
+
priorBalance,
|
|
88
|
+
delta: stockAdjust.delta,
|
|
89
|
+
operation: 'adjust',
|
|
90
|
+
reason: stockAdjust.reason,
|
|
91
|
+
correlationId: stockAdjust.correlationId,
|
|
92
|
+
});
|
|
93
|
+
return stockBalance;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async reserve(command: IStockReservationCommand): Promise<EntityStockReservation> {
|
|
97
|
+
const transaction = this.bean.database.current.transaction;
|
|
98
|
+
if (transaction.inTransaction) {
|
|
99
|
+
return await this._reserve(command);
|
|
100
|
+
}
|
|
101
|
+
for (let attempt = 0; ; attempt++) {
|
|
102
|
+
try {
|
|
103
|
+
return await transaction.begin(() => this._reserve(command), {
|
|
104
|
+
isolationLevel: 'SERIALIZABLE',
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (!this._isSerializationFailure(error) || attempt >= 1) throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private async _reserve(command: IStockReservationCommand): Promise<EntityStockReservation> {
|
|
113
|
+
this._assertReservationCommand(command);
|
|
114
|
+
const sku = await this.$scope.commerceCatalog.model.sku.getById(command.skuId, {
|
|
115
|
+
include: {
|
|
116
|
+
product: {
|
|
117
|
+
include: {
|
|
118
|
+
category: true,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
if (!sku || sku.lifecycle !== 'active') {
|
|
124
|
+
this.app.throw(404, 'SKU not found');
|
|
125
|
+
}
|
|
126
|
+
if (!sku.product?.published || !sku.product.category?.published) {
|
|
127
|
+
this.app.throw(409, 'SKU is not sellable');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const stockBalance = await this._getLockedBalance(command.skuId);
|
|
131
|
+
if (!stockBalance) {
|
|
132
|
+
this.app.throw(409, 'insufficient available stock');
|
|
133
|
+
}
|
|
134
|
+
const existingReservation = await this.scope.model.stockReservation.get({
|
|
135
|
+
correlationId: command.correlationId,
|
|
136
|
+
});
|
|
137
|
+
if (existingReservation) {
|
|
138
|
+
if (
|
|
139
|
+
String(existingReservation.skuId) !== String(command.skuId) ||
|
|
140
|
+
existingReservation.quantity !== command.quantity
|
|
141
|
+
) {
|
|
142
|
+
this.app.throw(409, 'stock reservation correlation conflicts with an existing reservation');
|
|
143
|
+
}
|
|
144
|
+
return existingReservation;
|
|
145
|
+
}
|
|
146
|
+
if (stockBalance.available < command.quantity) {
|
|
147
|
+
this.app.throw(409, 'insufficient available stock');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const reservation = await this.scope.model.stockReservation.insert({
|
|
151
|
+
stockBalanceId: stockBalance.id,
|
|
152
|
+
skuId: command.skuId,
|
|
153
|
+
quantity: command.quantity,
|
|
154
|
+
state: 'reserved',
|
|
155
|
+
correlationId: command.correlationId,
|
|
156
|
+
});
|
|
157
|
+
const priorBalance = stockBalance;
|
|
158
|
+
const updatedBalance = await this._updateBalance(stockBalance, {
|
|
159
|
+
onHand: stockBalance.onHand,
|
|
160
|
+
reserved: stockBalance.reserved + command.quantity,
|
|
161
|
+
});
|
|
162
|
+
await this._appendAudit({
|
|
163
|
+
stockBalance: updatedBalance,
|
|
164
|
+
priorBalance,
|
|
165
|
+
stockReservationId: reservation.id,
|
|
166
|
+
delta: -command.quantity,
|
|
167
|
+
operation: 'reserve',
|
|
168
|
+
reason: command.reason,
|
|
169
|
+
correlationId: command.correlationId,
|
|
170
|
+
});
|
|
171
|
+
return reservation;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
175
|
+
async consume(transition: IStockReservationTransition): Promise<EntityStockReservation> {
|
|
176
|
+
return await this._transitionReservation(
|
|
177
|
+
transition,
|
|
178
|
+
'reserved',
|
|
179
|
+
'consumed',
|
|
180
|
+
(stockBalance, reservation) => ({
|
|
181
|
+
onHand: stockBalance.onHand - reservation.quantity,
|
|
182
|
+
reserved: stockBalance.reserved - reservation.quantity,
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
188
|
+
async release(transition: IStockReservationTransition): Promise<EntityStockReservation> {
|
|
189
|
+
return await this._transitionReservation(
|
|
190
|
+
transition,
|
|
191
|
+
'reserved',
|
|
192
|
+
'released',
|
|
193
|
+
(stockBalance, reservation) => ({
|
|
194
|
+
onHand: stockBalance.onHand,
|
|
195
|
+
reserved: stockBalance.reserved - reservation.quantity,
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@Core.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
201
|
+
async restore(transition: IStockReservationTransition): Promise<EntityStockReservation> {
|
|
202
|
+
return await this._transitionReservation(
|
|
203
|
+
transition,
|
|
204
|
+
'consumed',
|
|
205
|
+
'restored',
|
|
206
|
+
(stockBalance, reservation) => ({
|
|
207
|
+
onHand: stockBalance.onHand + reservation.quantity,
|
|
208
|
+
reserved: stockBalance.reserved,
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
private async _transitionReservation(
|
|
214
|
+
transition: IStockReservationTransition,
|
|
215
|
+
sourceState: TypeStockReservationState,
|
|
216
|
+
targetState: TypeStockReservationState,
|
|
217
|
+
calculateBalance: (
|
|
218
|
+
stockBalance: EntityStockBalance,
|
|
219
|
+
reservation: EntityStockReservation,
|
|
220
|
+
) => Pick<EntityStockBalance, 'onHand' | 'reserved'>,
|
|
221
|
+
): Promise<EntityStockReservation> {
|
|
222
|
+
if (!transition.reason.trim()) {
|
|
223
|
+
this.app.throw(400, 'stock reservation reason is required');
|
|
224
|
+
}
|
|
225
|
+
const reservation = await this.scope.model.stockReservation.getByIdForUpdate(
|
|
226
|
+
transition.reservationId,
|
|
227
|
+
);
|
|
228
|
+
if (!reservation) {
|
|
229
|
+
this.app.throw(404, 'stock reservation not found');
|
|
230
|
+
}
|
|
231
|
+
if (reservation.state === targetState) {
|
|
232
|
+
return reservation;
|
|
233
|
+
}
|
|
234
|
+
if (reservation.state !== sourceState) {
|
|
235
|
+
this.app.throw(409, `cannot ${targetState} a ${reservation.state} stock reservation`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const stockBalance = await this.scope.model.stockBalance.getByIdForUpdate(
|
|
239
|
+
reservation.stockBalanceId,
|
|
240
|
+
);
|
|
241
|
+
if (!stockBalance) {
|
|
242
|
+
this.app.throw(404, 'stock balance not found');
|
|
243
|
+
}
|
|
244
|
+
const priorBalance = stockBalance;
|
|
245
|
+
const updatedBalance = await this._updateBalance(
|
|
246
|
+
stockBalance,
|
|
247
|
+
calculateBalance(stockBalance, reservation),
|
|
248
|
+
);
|
|
249
|
+
await this.scope.model.stockReservation.updateById(reservation.id, { state: targetState });
|
|
250
|
+
const updatedReservation = { ...reservation, state: targetState };
|
|
251
|
+
const operation =
|
|
252
|
+
targetState === 'consumed' ? 'consume' : targetState === 'released' ? 'release' : 'restore';
|
|
253
|
+
await this._appendAudit({
|
|
254
|
+
stockBalance: updatedBalance,
|
|
255
|
+
priorBalance,
|
|
256
|
+
stockReservationId: reservation.id,
|
|
257
|
+
delta:
|
|
258
|
+
operation === 'consume'
|
|
259
|
+
? -reservation.quantity
|
|
260
|
+
: operation === 'restore'
|
|
261
|
+
? reservation.quantity
|
|
262
|
+
: 0,
|
|
263
|
+
operation,
|
|
264
|
+
reason: transition.reason,
|
|
265
|
+
correlationId: reservation.correlationId,
|
|
266
|
+
});
|
|
267
|
+
return updatedReservation;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private async _getLockedBalance(skuId: TableIdentity): Promise<EntityStockBalance | undefined> {
|
|
271
|
+
return await this.scope.model.stockBalance.getForUpdate({ skuId });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private async _updateBalance(
|
|
275
|
+
stockBalance: EntityStockBalance,
|
|
276
|
+
values: Pick<EntityStockBalance, 'onHand' | 'reserved'>,
|
|
277
|
+
): Promise<EntityStockBalance> {
|
|
278
|
+
const available = values.onHand - values.reserved;
|
|
279
|
+
if (values.onHand < 0 || values.reserved < 0 || available < 0) {
|
|
280
|
+
this.app.throw(409, 'stock balance would become negative');
|
|
281
|
+
}
|
|
282
|
+
await this.scope.model.stockBalance.updateById(stockBalance.id, {
|
|
283
|
+
onHand: values.onHand,
|
|
284
|
+
reserved: values.reserved,
|
|
285
|
+
available,
|
|
286
|
+
});
|
|
287
|
+
return { ...stockBalance, ...values, available };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
private async _appendAudit({
|
|
291
|
+
stockBalance,
|
|
292
|
+
priorBalance,
|
|
293
|
+
stockReservationId,
|
|
294
|
+
delta,
|
|
295
|
+
operation,
|
|
296
|
+
reason,
|
|
297
|
+
correlationId,
|
|
298
|
+
}: {
|
|
299
|
+
stockBalance: EntityStockBalance;
|
|
300
|
+
priorBalance: Pick<EntityStockBalance, 'onHand' | 'reserved' | 'available'>;
|
|
301
|
+
stockReservationId?: TableIdentity;
|
|
302
|
+
delta: number;
|
|
303
|
+
operation: 'adjust' | 'reserve' | 'consume' | 'release' | 'restore';
|
|
304
|
+
reason: string;
|
|
305
|
+
correlationId: string;
|
|
306
|
+
}) {
|
|
307
|
+
await this.scope.model.stockAudit.insert({
|
|
308
|
+
stockBalanceId: stockBalance.id,
|
|
309
|
+
skuId: stockBalance.skuId,
|
|
310
|
+
stockReservationId,
|
|
311
|
+
actorId: this.bean.passport.currentUser?.anonymous
|
|
312
|
+
? undefined
|
|
313
|
+
: this.bean.passport.currentUser?.id,
|
|
314
|
+
operation,
|
|
315
|
+
delta,
|
|
316
|
+
reason,
|
|
317
|
+
correlationId,
|
|
318
|
+
priorOnHand: priorBalance.onHand,
|
|
319
|
+
priorReserved: priorBalance.reserved,
|
|
320
|
+
priorAvailable: priorBalance.available,
|
|
321
|
+
onHand: stockBalance.onHand,
|
|
322
|
+
reserved: stockBalance.reserved,
|
|
323
|
+
available: stockBalance.available,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private _isSerializationFailure(error: unknown) {
|
|
328
|
+
return (error as { code?: unknown })?.code === '40001';
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private _assertReservationCommand(command: IStockReservationCommand) {
|
|
332
|
+
if (!Number.isInteger(command.quantity) || command.quantity <= 0) {
|
|
333
|
+
this.app.throw(400, 'stock reservation quantity must be a positive integer');
|
|
334
|
+
}
|
|
335
|
+
if (!command.correlationId.trim()) {
|
|
336
|
+
this.app.throw(400, 'stock reservation correlationId is required');
|
|
337
|
+
}
|
|
338
|
+
if (!command.reason.trim()) {
|
|
339
|
+
this.app.throw(400, 'stock reservation reason is required');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -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
|
+
});
|