@tbox.cn/app-contracts-mall 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tbox.cn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @tbox.cn/app-contracts-mall
2
+
3
+ 商圈领域契约(TIER1,types-only):Port 接口 + MallEventMap + 领域 DTO。
4
+
5
+ ## 安装
6
+
7
+ ```sh
8
+ pnpm add @tbox.cn/app-contracts-mall
9
+ ```
10
+
11
+ ## 说明
12
+
13
+ 商圈业务契约类型真源包;消费方经 `@tbox.cn/app-contracts-mall` 公开入口引用。
@@ -0,0 +1,8 @@
1
+ /** 优惠券(商圈领域 DTO) */
2
+ export interface Coupon {
3
+ couponId: string;
4
+ title: string;
5
+ /** 可抵扣金额(元) */
6
+ amount: number;
7
+ status: 'AVAILABLE' | 'USED' | 'EXPIRED';
8
+ }
@@ -0,0 +1,6 @@
1
+ /** 折扣规则(商圈领域 DTO) */
2
+ export interface DiscountRule {
3
+ level: 'silver' | 'gold' | 'platinum';
4
+ /** 折扣率 0-1(0.9 = 9 折) */
5
+ discount: number;
6
+ }
@@ -0,0 +1,13 @@
1
+ /** 停车费单(商圈领域 DTO,同时是 parking-fee 卡片数据契约) */
2
+ export interface ParkingFee {
3
+ orderId: string;
4
+ userId: string;
5
+ plate: string;
6
+ /** 应付金额(元) */
7
+ fee: number;
8
+ /** 实付金额(抵扣后,元) */
9
+ paidAmount?: number;
10
+ /** 使用积分 */
11
+ pointsUsed?: number;
12
+ status: 'PENDING' | 'PAID' | 'CANCELLED';
13
+ }
@@ -0,0 +1,13 @@
1
+ /** 会员积分与等级(商圈领域 DTO) */
2
+ export interface Points {
3
+ userId: string;
4
+ /** 当前积分余额 */
5
+ balance: number;
6
+ level: 'silver' | 'gold' | 'platinum';
7
+ }
8
+ /** 积分余额变动结果 */
9
+ export interface PointsChangeResult {
10
+ success: boolean;
11
+ balance: number;
12
+ reason?: string;
13
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * MallEventMap:商圈跨模块事件(类型化事件总线 keyof 约束,001 §5.4)。
3
+ * 用 type(非 interface)以获得隐式索引签名,满足 SDK EventMap(Record<string, unknown>)约束。
4
+ */
5
+ export type MallEventMap = {
6
+ /** 会员等级变更 */
7
+ 'member.level.changed': {
8
+ userId: string;
9
+ newLevel: 'silver' | 'gold' | 'platinum';
10
+ };
11
+ /** 停车券核销 */
12
+ 'parking.coupon.used': {
13
+ userId: string;
14
+ couponId: string;
15
+ amount: number;
16
+ };
17
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @tbox.cn/app-contracts-mall:商圈领域契约(TIER1,types-only 纯类型包)。
3
+ * 消费方(module-parking / module-promotion / scenario)只依赖本契约,
4
+ * 不依赖任何模块实现包——结构类型子集接口 + 事件总线破环双向依赖。
5
+ */
6
+ export * from './domain/points';
7
+ export * from './domain/coupon';
8
+ export * from './domain/discount';
9
+ export * from './domain/parking';
10
+ export * from './services/member';
11
+ export * from './services/parking';
12
+ export * from './services/promotion';
13
+ export * from './events';
@@ -0,0 +1,19 @@
1
+ import type { Points } from '../domain/points';
2
+ import type { DiscountRule } from '../domain/discount';
3
+ /**
4
+ * MemberQueryPort:消费方(parking / scenario)需要的 member 查询子集。
5
+ * 结构类型子集接口——模块完整实现 extends 此接口,消费方仅依赖契约包(001 §5.3)。
6
+ */
7
+ export interface MemberQueryPort {
8
+ queryPoints(userId: string): Promise<Points>;
9
+ queryDiscount(userId: string): Promise<DiscountRule | undefined>;
10
+ }
11
+ /**
12
+ * MemberSettlementPort:跨模块写操作(scenario 编排 + 补偿用)。
13
+ * 幂等键由调用方(scenario handler)生成。
14
+ */
15
+ export interface MemberSettlementPort {
16
+ deductPoints(userId: string, amount: number, idempotencyKey: string): Promise<boolean>;
17
+ refundPoints(userId: string, amount: number, idempotencyKey: string): Promise<boolean>;
18
+ awardPoints(userId: string, amount: number): Promise<boolean>;
19
+ }
@@ -0,0 +1,14 @@
1
+ import type { ParkingFee } from '../domain/parking';
2
+ /** ParkingQueryPort:消费方(scenario / member)需要的停车查询子集 */
3
+ export interface ParkingQueryPort {
4
+ queryParkingFee(userId: string, orderId?: string): Promise<ParkingFee | undefined>;
5
+ }
6
+ /** ParkingSettlementPort:停车结算写操作(scenario 编排用) */
7
+ export interface ParkingSettlementPort {
8
+ /** 计算停车费(无订单则生成) */
9
+ calcFee(userId: string, orderId: string): Promise<ParkingFee>;
10
+ /** 核销停车券 */
11
+ useCoupon(userId: string, orderId: string, couponId: string): Promise<boolean>;
12
+ /** 结算停车费(抵扣后支付剩余金额) */
13
+ settlePayment(userId: string, orderId: string, amount: number): Promise<boolean>;
14
+ }
@@ -0,0 +1,5 @@
1
+ import type { Coupon } from '../domain/coupon';
2
+ /** PromotionQueryPort:营销资格查询(scenario 出券用) */
3
+ export interface PromotionQueryPort {
4
+ queryEligibleCoupons(userId: string): Promise<Coupon[]>;
5
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@tbox.cn/app-contracts-mall",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "商圈领域契约(TIER1,types-only):Port 接口 + MallEventMap + 领域 DTO。",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.d.ts"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "src",
15
+ "tsconfig.json",
16
+ "tsconfig.build.json",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "engines": {
21
+ "node": ">=20.0.0"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "peerDependencies": {
27
+ "zod": "^3.24.0"
28
+ },
29
+ "devDependencies": {
30
+ "typescript": "^5.7.0"
31
+ },
32
+ "license": "MIT",
33
+ "scripts": {
34
+ "build": "tsc -p tsconfig.build.json",
35
+ "typecheck": "tsc --noEmit"
36
+ }
37
+ }
@@ -0,0 +1,8 @@
1
+ /** 优惠券(商圈领域 DTO) */
2
+ export interface Coupon {
3
+ couponId: string;
4
+ title: string;
5
+ /** 可抵扣金额(元) */
6
+ amount: number;
7
+ status: 'AVAILABLE' | 'USED' | 'EXPIRED';
8
+ }
@@ -0,0 +1,6 @@
1
+ /** 折扣规则(商圈领域 DTO) */
2
+ export interface DiscountRule {
3
+ level: 'silver' | 'gold' | 'platinum';
4
+ /** 折扣率 0-1(0.9 = 9 折) */
5
+ discount: number;
6
+ }
@@ -0,0 +1,13 @@
1
+ /** 停车费单(商圈领域 DTO,同时是 parking-fee 卡片数据契约) */
2
+ export interface ParkingFee {
3
+ orderId: string;
4
+ userId: string;
5
+ plate: string;
6
+ /** 应付金额(元) */
7
+ fee: number;
8
+ /** 实付金额(抵扣后,元) */
9
+ paidAmount?: number;
10
+ /** 使用积分 */
11
+ pointsUsed?: number;
12
+ status: 'PENDING' | 'PAID' | 'CANCELLED';
13
+ }
@@ -0,0 +1,14 @@
1
+ /** 会员积分与等级(商圈领域 DTO) */
2
+ export interface Points {
3
+ userId: string;
4
+ /** 当前积分余额 */
5
+ balance: number;
6
+ level: 'silver' | 'gold' | 'platinum';
7
+ }
8
+
9
+ /** 积分余额变动结果 */
10
+ export interface PointsChangeResult {
11
+ success: boolean;
12
+ balance: number;
13
+ reason?: string;
14
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * MallEventMap:商圈跨模块事件(类型化事件总线 keyof 约束,001 §5.4)。
3
+ * 用 type(非 interface)以获得隐式索引签名,满足 SDK EventMap(Record<string, unknown>)约束。
4
+ */
5
+ export type MallEventMap = {
6
+ /** 会员等级变更 */
7
+ 'member.level.changed': { userId: string; newLevel: 'silver' | 'gold' | 'platinum' };
8
+ /** 停车券核销 */
9
+ 'parking.coupon.used': { userId: string; couponId: string; amount: number };
10
+ };
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @tbox.cn/app-contracts-mall:商圈领域契约(TIER1,types-only 纯类型包)。
3
+ * 消费方(module-parking / module-promotion / scenario)只依赖本契约,
4
+ * 不依赖任何模块实现包——结构类型子集接口 + 事件总线破环双向依赖。
5
+ */
6
+ export * from './domain/points';
7
+ export * from './domain/coupon';
8
+ export * from './domain/discount';
9
+ export * from './domain/parking';
10
+ export * from './services/member';
11
+ export * from './services/parking';
12
+ export * from './services/promotion';
13
+ export * from './events';
@@ -0,0 +1,21 @@
1
+ import type { Points } from '../domain/points';
2
+ import type { DiscountRule } from '../domain/discount';
3
+
4
+ /**
5
+ * MemberQueryPort:消费方(parking / scenario)需要的 member 查询子集。
6
+ * 结构类型子集接口——模块完整实现 extends 此接口,消费方仅依赖契约包(001 §5.3)。
7
+ */
8
+ export interface MemberQueryPort {
9
+ queryPoints(userId: string): Promise<Points>;
10
+ queryDiscount(userId: string): Promise<DiscountRule | undefined>;
11
+ }
12
+
13
+ /**
14
+ * MemberSettlementPort:跨模块写操作(scenario 编排 + 补偿用)。
15
+ * 幂等键由调用方(scenario handler)生成。
16
+ */
17
+ export interface MemberSettlementPort {
18
+ deductPoints(userId: string, amount: number, idempotencyKey: string): Promise<boolean>;
19
+ refundPoints(userId: string, amount: number, idempotencyKey: string): Promise<boolean>;
20
+ awardPoints(userId: string, amount: number): Promise<boolean>;
21
+ }
@@ -0,0 +1,16 @@
1
+ import type { ParkingFee } from '../domain/parking';
2
+
3
+ /** ParkingQueryPort:消费方(scenario / member)需要的停车查询子集 */
4
+ export interface ParkingQueryPort {
5
+ queryParkingFee(userId: string, orderId?: string): Promise<ParkingFee | undefined>;
6
+ }
7
+
8
+ /** ParkingSettlementPort:停车结算写操作(scenario 编排用) */
9
+ export interface ParkingSettlementPort {
10
+ /** 计算停车费(无订单则生成) */
11
+ calcFee(userId: string, orderId: string): Promise<ParkingFee>;
12
+ /** 核销停车券 */
13
+ useCoupon(userId: string, orderId: string, couponId: string): Promise<boolean>;
14
+ /** 结算停车费(抵扣后支付剩余金额) */
15
+ settlePayment(userId: string, orderId: string, amount: number): Promise<boolean>;
16
+ }
@@ -0,0 +1,6 @@
1
+ import type { Coupon } from '../domain/coupon';
2
+
3
+ /** PromotionQueryPort:营销资格查询(scenario 出券用) */
4
+ export interface PromotionQueryPort {
5
+ queryEligibleCoupons(userId: string): Promise<Coupon[]>;
6
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "declaration": true,
8
+ "emitDeclarationOnly": true,
9
+ "outDir": "dist",
10
+ "skipLibCheck": true,
11
+ "esModuleInterop": true
12
+ },
13
+ "include": ["src/**/*.ts"],
14
+ "exclude": ["node_modules", "dist"]
15
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {},
4
+ "include": ["src"]
5
+ }