cabloy 5.1.113 → 5.1.115

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.
Files changed (141) hide show
  1. package/.cabloy-version +1 -1
  2. package/.claude/skills/cabloy-backend-scaffold/references/follow-up-checklist.md +4 -0
  3. package/.github/workflows/vona-test-mysql.yml +12 -0
  4. package/.github/workflows/vona-test-pg.yml +5 -1
  5. package/CHANGELOG.md +20 -0
  6. package/CLAUDE.md +4 -0
  7. package/cabloy-docs/backend/internal-aop-guide.md +35 -0
  8. package/cabloy-docs/backend/unit-testing.md +72 -1
  9. package/package.json +1 -1
  10. package/vona/packages-cli/cli/package.json +1 -1
  11. package/vona/packages-cli/cli-set-api/package.json +1 -1
  12. package/vona/packages-cli/cli-set-api/toolsIsolate/test.ts +26 -13
  13. package/vona/packages-utils/compose/package.json +1 -1
  14. package/vona/packages-utils/compose/src/index.ts +19 -11
  15. package/vona/packages-vona/vona/package.json +1 -1
  16. package/vona/packages-vona/vona-core/package.json +1 -1
  17. package/vona/packages-vona/vona-core/src/lib/bean/beanContainer.ts +15 -3
  18. package/vona/packages-vona/vona-mock/package.json +1 -1
  19. package/vona/pnpm-lock.yaml +143 -12
  20. package/vona/pnpm-workspace.yaml +1 -1
  21. package/vona/src/suite/a-commerce/modules/commerce-catalog/src/.metadata/index.ts +8 -0
  22. package/vona/src/suite/a-commerce/modules/commerce-catalog/src/bean/meta.version.ts +1 -0
  23. package/vona/src/suite/a-commerce/modules/commerce-catalog/src/config/locale/en-us.ts +3 -0
  24. package/vona/src/suite/a-commerce/modules/commerce-catalog/src/config/locale/zh-cn.ts +3 -0
  25. package/vona/src/suite/a-commerce/modules/commerce-catalog/src/dto/skuAttribute.tsx +17 -0
  26. package/vona/src/suite/a-commerce/modules/commerce-catalog/src/entity/sku.tsx +10 -1
  27. package/vona/src/suite/a-commerce/modules/commerce-catalog/test/catalog.test.ts +1 -1
  28. package/vona/src/suite/a-commerce/modules/commerce-member/test/addressOwnership.test.ts +6 -1
  29. package/vona/src/suite/a-commerce/modules/commerce-payment/package.json +2 -1
  30. package/vona/src/suite/a-commerce/modules/commerce-payment/src/.metadata/index.ts +228 -0
  31. package/vona/src/suite/a-commerce/modules/commerce-payment/src/bean/meta.index.ts +15 -0
  32. package/vona/src/suite/a-commerce/modules/commerce-payment/src/bean/meta.version.ts +35 -0
  33. package/vona/src/suite/a-commerce/modules/commerce-payment/src/dto/paymentAttemptView.tsx +26 -0
  34. package/vona/src/suite/a-commerce/modules/commerce-payment/src/entity/paymentAttempt.tsx +34 -0
  35. package/vona/src/suite/a-commerce/modules/commerce-payment/src/model/paymentAttempt.ts +10 -0
  36. package/vona/src/suite/a-commerce/modules/commerce-payment/src/service/paymentAttempt.ts +41 -0
  37. package/vona/src/suite/a-commerce/modules/commerce-payment/test/paymentAttempt.test.ts +33 -0
  38. package/vona/src/suite/a-commerce/modules/commerce-promotion/package.json +4 -2
  39. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/.metadata/index.ts +533 -2
  40. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/.metadata/locales.ts +18 -0
  41. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/bean/meta.index.ts +24 -0
  42. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/bean/meta.version.ts +137 -0
  43. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/bean/ssrMenu.couponTemplate.ts +30 -0
  44. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/config/locale/en-us.ts +37 -0
  45. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/config/locale/zh-cn.ts +37 -0
  46. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/controller/coupon.ts +37 -0
  47. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/controller/couponTemplate.ts +65 -0
  48. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponIssue.tsx +22 -0
  49. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponMineItem.tsx +32 -0
  50. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponTemplateCreate.tsx +43 -0
  51. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponTemplateSelectReq.tsx +28 -0
  52. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponTemplateSelectRes.tsx +11 -0
  53. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponTemplateSelectResItem.tsx +39 -0
  54. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponTemplateUpdate.tsx +19 -0
  55. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/dto/couponTemplateView.tsx +25 -0
  56. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/entity/couponAudit.tsx +73 -0
  57. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/entity/couponGrant.tsx +83 -0
  58. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/entity/couponTemplate.tsx +82 -0
  59. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/index.ts +1 -0
  60. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/model/couponAudit.ts +10 -0
  61. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/model/couponGrant.ts +10 -0
  62. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/model/couponTemplate.ts +10 -0
  63. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/service/coupon.ts +397 -0
  64. package/vona/src/suite/a-commerce/modules/commerce-promotion/src/service/couponTemplate.ts +52 -0
  65. package/vona/src/suite/a-commerce/modules/commerce-promotion/test/couponReservation.test.ts +162 -0
  66. package/vona/src/suite/a-commerce/modules/commerce-seed/src/bean/meta.version.ts +8 -10
  67. package/vona/src/suite/a-commerce/modules/commerce-trade/package.json +4 -1
  68. package/vona/src/suite/a-commerce/modules/commerce-trade/src/.metadata/index.ts +277 -0
  69. package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/bean.scheduleOrderExpiry.ts +26 -0
  70. package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/meta.index.ts +9 -0
  71. package/vona/src/suite/a-commerce/modules/commerce-trade/src/bean/meta.version.ts +75 -0
  72. package/vona/src/suite/a-commerce/modules/commerce-trade/src/config/locale/en-us.ts +11 -2
  73. package/vona/src/suite/a-commerce/modules/commerce-trade/src/config/locale/zh-cn.ts +11 -2
  74. package/vona/src/suite/a-commerce/modules/commerce-trade/src/controller/checkout.ts +19 -0
  75. package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/checkoutCreate.tsx +19 -0
  76. package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/checkoutResult.tsx +32 -0
  77. package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/orderAddressSnapshot.tsx +33 -0
  78. package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/orderCouponSnapshot.tsx +35 -0
  79. package/vona/src/suite/a-commerce/modules/commerce-trade/src/dto/orderLineSkuAttributeSnapshot.tsx +15 -0
  80. package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/order.tsx +90 -0
  81. package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/orderAudit.tsx +36 -0
  82. package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/orderLine.tsx +52 -0
  83. package/vona/src/suite/a-commerce/modules/commerce-trade/src/entity/stockReservation.tsx +4 -1
  84. package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/order.ts +15 -0
  85. package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/orderAudit.ts +10 -0
  86. package/vona/src/suite/a-commerce/modules/commerce-trade/src/model/orderLine.ts +10 -0
  87. package/vona/src/suite/a-commerce/modules/commerce-trade/src/service/order.ts +556 -0
  88. package/vona/src/suite/a-commerce/modules/commerce-trade/src/service/stockBalance.ts +15 -20
  89. package/vona/src/suite/a-commerce/modules/commerce-trade/test/cartOwnership.test.ts +8 -3
  90. package/vona/src/suite/a-commerce/modules/commerce-trade/test/checkoutReservation.test.ts +158 -0
  91. package/vona/src/suite/a-commerce/modules/commerce-trade/test/orderSnapshot.test.ts +203 -0
  92. package/vona/src/suite/a-commerce/modules/commerce-trade/test/reservationExpiry.test.ts +163 -0
  93. package/vona/src/suite/a-commerce/modules/commerce-trade/test/stockBalance.test.ts +11 -6
  94. package/vona/src/suite/a-commerce/modules/commerce-trade/test/stockReservation.test.ts +11 -6
  95. package/vona/src/suite-vendor/a-image/modules/image-cloudflare/package.json +1 -1
  96. package/vona/src/suite-vendor/a-image/modules/image-cloudflare/src/service/imageCloudflare.ts +10 -7
  97. package/vona/src/suite-vendor/a-image/package.json +1 -1
  98. package/vona/src/suite-vendor/a-vona/modules/a-aspect/package.json +1 -1
  99. package/vona/src/suite-vendor/a-vona/modules/a-aspect/src/types/aopMethod.ts +16 -3
  100. package/vona/src/suite-vendor/a-vona/modules/a-core/package.json +4 -2
  101. package/vona/src/suite-vendor/a-vona/modules/a-core/src/bean/bean.core.ts +6 -0
  102. package/vona/src/suite-vendor/a-vona/modules/a-core/src/index.ts +1 -0
  103. package/vona/src/suite-vendor/a-vona/modules/a-core/src/lib/core.ts +6 -0
  104. package/vona/src/suite-vendor/a-vona/modules/a-core/src/types/fetch.ts +7 -0
  105. package/vona/src/suite-vendor/a-vona/modules/a-core/src/types/index.ts +1 -0
  106. package/vona/src/suite-vendor/a-vona/modules/a-executor/package.json +1 -1
  107. package/vona/src/suite-vendor/a-vona/modules/a-executor/src/lib/utils.ts +5 -3
  108. package/vona/src/suite-vendor/a-vona/modules/a-retryable/package.json +50 -0
  109. package/vona/src/suite-vendor/a-vona/modules/a-retryable/src/.metadata/index.ts +55 -0
  110. package/vona/src/suite-vendor/a-vona/modules/a-retryable/src/.metadata/this.ts +2 -0
  111. package/vona/src/suite-vendor/a-vona/modules/a-retryable/src/bean/aopMethod.retryable.ts +45 -0
  112. package/vona/src/suite-vendor/a-vona/modules/a-retryable/src/index.ts +1 -0
  113. package/vona/src/suite-vendor/a-vona/modules/a-retryable/tsconfig.build.json +11 -0
  114. package/vona/src/suite-vendor/a-vona/modules/a-retryable/tsconfig.json +7 -0
  115. package/vona/src/suite-vendor/a-vona/modules/a-vona/package.json +2 -1
  116. package/vona/src/suite-vendor/a-vona/package.json +2 -1
  117. package/vona/src/suite-vendor/a-vona/tsconfig.json +3 -0
  118. package/zova/packages-utils/zova-jsx/package.json +3 -3
  119. package/zova/packages-zova/zova/package.json +3 -3
  120. package/zova/packages-zova/zova-core/package.json +2 -2
  121. package/zova/pnpm-lock.yaml +31 -31
  122. package/zova/src/suite/a-commerce/modules/commerce-promotion/cli/openapi.config.ts +9 -0
  123. package/zova/src/suite/a-commerce/modules/commerce-promotion/package.json +2 -1
  124. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/.metadata/index.ts +115 -1
  125. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/api/commercePromotionCoupon.ts +24 -0
  126. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/api/openapi/baseURL.ts +5 -0
  127. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/api/openapi/index.ts +3 -0
  128. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/api/openapi/schemas.ts +478 -0
  129. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/api/openapi/types.ts +8187 -0
  130. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/apiSchema/commercePromotionCoupon.ts +13 -0
  131. package/zova/src/suite/a-commerce/modules/commerce-promotion/src/model/coupon.ts +19 -0
  132. package/zova/src/suite/a-commerce/modules/commerce-trade/cli/openapi.config.ts +1 -0
  133. package/zova/src/suite/a-commerce/modules/commerce-trade/src/.metadata/index.ts +30 -0
  134. package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/commerceTradeCheckout.ts +27 -0
  135. package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/openapi/schemas.ts +92 -52
  136. package/zova/src/suite/a-commerce/modules/commerce-trade/src/api/openapi/types.ts +1389 -848
  137. package/zova/src/suite/a-commerce/modules/commerce-trade/src/apiSchema/commerceTradeCheckout.ts +13 -0
  138. package/zova/src/suite/a-commerce/modules/commerce-trade/src/model/cart.ts +13 -0
  139. package/zova/src/suite-vendor/a-zova/modules/a-zova/package.json +3 -3
  140. package/zova/src/suite-vendor/a-zova/package.json +2 -2
  141. /package/vona/patches/{zova-core@5.1.78.patch → zova-core@5.1.79.patch} +0 -0
@@ -0,0 +1,15 @@
1
+ import type { IMetaOptionsIndex } from 'vona-module-a-index';
2
+
3
+ import { BeanBase } from 'vona';
4
+ import { Meta } from 'vona-module-a-meta';
5
+ import { $tableColumns } from 'vona-module-a-ormutils';
6
+
7
+ @Meta<IMetaOptionsIndex>({
8
+ indexes: {
9
+ ...$tableColumns('commercePaymentAttempt', 'orderId'),
10
+ ...$tableColumns('commercePaymentAttempt', 'userId'),
11
+ ...$tableColumns('commercePaymentAttempt', 'state'),
12
+ ...$tableColumns('commercePaymentAttempt', 'correlationId'),
13
+ },
14
+ })
15
+ export class MetaIndex extends BeanBase {}
@@ -0,0 +1,35 @@
1
+ import type { IMetaVersionUpdate, IMetaVersionUpdateOptions } from 'vona-module-a-version';
2
+
3
+ import { BeanBase } from 'vona';
4
+ import { Meta } from 'vona-module-a-meta';
5
+
6
+ @Meta()
7
+ export class MetaVersion extends BeanBase implements IMetaVersionUpdate {
8
+ async update(options: IMetaVersionUpdateOptions) {
9
+ if (options.version !== 1) return;
10
+
11
+ const entityPaymentAttempt = this.scope.entity.paymentAttempt;
12
+ await this.bean.model.createTable(entityPaymentAttempt.$table, table => {
13
+ table.comment(entityPaymentAttempt.$comment.$table);
14
+ table.basicFields();
15
+ table
16
+ .tableIdentity(entityPaymentAttempt.orderId)
17
+ .comment(entityPaymentAttempt.$comment.orderId);
18
+ table.userId(entityPaymentAttempt.userId).comment(entityPaymentAttempt.$comment.userId);
19
+ table.string(entityPaymentAttempt.state, 20).comment(entityPaymentAttempt.$comment.state);
20
+ table
21
+ .string(entityPaymentAttempt.currency, 3)
22
+ .comment(entityPaymentAttempt.$comment.currency);
23
+ table
24
+ .integer(entityPaymentAttempt.amountCents)
25
+ .comment(entityPaymentAttempt.$comment.amountCents);
26
+ table
27
+ .string(entityPaymentAttempt.correlationId, 100)
28
+ .comment(entityPaymentAttempt.$comment.correlationId);
29
+ table
30
+ .dateTime(entityPaymentAttempt.cancelledAt)
31
+ .nullable()
32
+ .comment(entityPaymentAttempt.$comment.cancelledAt);
33
+ });
34
+ }
35
+ }
@@ -0,0 +1,26 @@
1
+ import type { TableIdentity } from 'table-identity';
2
+ import type { IDecoratorDtoOptions } from 'vona-module-a-web';
3
+
4
+ import { Api, v } from 'vona-module-a-openapiutils';
5
+ import { Dto } from 'vona-module-a-web';
6
+ import { z } from 'zod';
7
+
8
+ export interface IDtoOptionsPaymentAttemptView extends IDecoratorDtoOptions {}
9
+
10
+ @Dto<IDtoOptionsPaymentAttemptView>()
11
+ export class DtoPaymentAttemptView {
12
+ @Api.field(v.tableIdentity())
13
+ id: TableIdentity;
14
+
15
+ @Api.field(v.tableIdentity())
16
+ orderId: TableIdentity;
17
+
18
+ @Api.field(z.enum(['created', 'cancelled']))
19
+ state: 'created' | 'cancelled';
20
+
21
+ @Api.field(z.literal('USD'))
22
+ currency: 'USD';
23
+
24
+ @Api.field(z.number().int().nonnegative())
25
+ amountCents: number;
26
+ }
@@ -0,0 +1,34 @@
1
+ import type { TableIdentity } from 'table-identity';
2
+ import type { IDecoratorEntityOptions } from 'vona-module-a-orm';
3
+
4
+ import { Api, v } from 'vona-module-a-openapiutils';
5
+ import { Entity, EntityBase } from 'vona-module-a-orm';
6
+ import { z } from 'zod';
7
+
8
+ export type TypePaymentAttemptState = 'created' | 'cancelled';
9
+
10
+ export interface IEntityOptionsPaymentAttempt extends IDecoratorEntityOptions {}
11
+
12
+ @Entity<IEntityOptionsPaymentAttempt>('commercePaymentAttempt')
13
+ export class EntityPaymentAttempt extends EntityBase {
14
+ @Api.field(v.tableIdentity())
15
+ orderId: TableIdentity;
16
+
17
+ @Api.field(v.tableIdentity())
18
+ userId: TableIdentity;
19
+
20
+ @Api.field(z.enum(['created', 'cancelled']))
21
+ state: TypePaymentAttemptState;
22
+
23
+ @Api.field(z.literal('USD'))
24
+ currency: 'USD';
25
+
26
+ @Api.field(z.number().int().nonnegative())
27
+ amountCents: number;
28
+
29
+ @Api.field(v.required(), v.min(1), v.max(100))
30
+ correlationId: string;
31
+
32
+ @Api.field(v.optional())
33
+ cancelledAt?: Date;
34
+ }
@@ -0,0 +1,10 @@
1
+ import type { IDecoratorModelOptions } from 'vona-module-a-orm';
2
+
3
+ import { BeanModelBase, Model } from 'vona-module-a-orm';
4
+
5
+ import { EntityPaymentAttempt } from '../entity/paymentAttempt.tsx';
6
+
7
+ export interface IModelOptionsPaymentAttempt extends IDecoratorModelOptions<EntityPaymentAttempt> {}
8
+
9
+ @Model<IModelOptionsPaymentAttempt>({ entity: EntityPaymentAttempt })
10
+ export class ModelPaymentAttempt extends BeanModelBase<EntityPaymentAttempt> {}
@@ -0,0 +1,41 @@
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 { EntityPaymentAttempt } from '../entity/paymentAttempt.tsx';
8
+
9
+ export interface IPaymentAttemptCreateCommand {
10
+ orderId: TableIdentity;
11
+ userId: TableIdentity;
12
+ currency: 'USD';
13
+ amountCents: number;
14
+ correlationId: string;
15
+ }
16
+
17
+ @Service()
18
+ export class ServicePaymentAttempt extends BeanBase {
19
+ async create(command: IPaymentAttemptCreateCommand): Promise<EntityPaymentAttempt> {
20
+ return await this.scope.model.paymentAttempt.insert({
21
+ orderId: command.orderId,
22
+ userId: command.userId,
23
+ state: 'created',
24
+ currency: command.currency,
25
+ amountCents: command.amountCents,
26
+ correlationId: command.correlationId,
27
+ });
28
+ }
29
+
30
+ @Core.transaction({ isolationLevel: 'SERIALIZABLE' })
31
+ async cancel(orderId: TableIdentity): Promise<EntityPaymentAttempt | undefined> {
32
+ const attempt = await this.scope.model.paymentAttempt.getForUpdate({ orderId });
33
+ if (!attempt || attempt.state === 'cancelled') return attempt;
34
+ const cancelledAt = new Date();
35
+ await this.scope.model.paymentAttempt.updateById(attempt.id, {
36
+ state: 'cancelled',
37
+ cancelledAt,
38
+ });
39
+ return { ...attempt, state: 'cancelled', cancelledAt };
40
+ }
41
+ }
@@ -0,0 +1,33 @@
1
+ import assert from 'node:assert';
2
+ import { randomUUID } from 'node:crypto';
3
+ import { describe, it } from 'node:test';
4
+ import { app } from 'vona-mock';
5
+
6
+ describe('paymentAttempt.test.ts', { concurrency: false }, () => {
7
+ it('creates and internally cancels an attempt exactly once', async () => {
8
+ await app.bean.executor.mockCtx(async () => {
9
+ const scope = app.scope('commerce-payment');
10
+ const suffix = randomUUID().slice(0, 12);
11
+ let attemptId: number | undefined;
12
+ try {
13
+ const user = await app.bean.user.register({ name: `payment-${suffix}` }, true);
14
+ const created = await scope.service.paymentAttempt.create({
15
+ orderId: 900_001,
16
+ userId: user.id,
17
+ currency: 'USD',
18
+ amountCents: 1299,
19
+ correlationId: `payment-${suffix}`,
20
+ });
21
+ attemptId = created.id as number;
22
+ assert.equal(created.state, 'created');
23
+ const cancelled = await scope.service.paymentAttempt.cancel(created.orderId);
24
+ assert.equal(cancelled?.state, 'cancelled');
25
+ const replay = await scope.service.paymentAttempt.cancel(created.orderId);
26
+ assert.equal(replay?.id, created.id);
27
+ assert.equal(replay?.state, 'cancelled');
28
+ } finally {
29
+ if (attemptId !== undefined) await scope.model.paymentAttempt.delete({ id: attemptId });
30
+ }
31
+ });
32
+ });
33
+ });
@@ -46,7 +46,9 @@
46
46
  "title": "commerce-promotion",
47
47
  "vonaModule": {
48
48
  "dependencies": {
49
- "a-vona": "5.0.0"
50
- }
49
+ "a-vona": "5.0.0",
50
+ "commerce-siteadmin": "5.0.0"
51
+ },
52
+ "fileVersion": 1
51
53
  }
52
54
  }