@tbox.cn/app-contracts-mall 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,216 @@
1
+ /**
2
+ * 导购域 Port 接口(011 S7:shopping-guide 6 Port,TIER1 结构类型子集)。
3
+ * 模块完整实现 extends 本接口;消费方(其他模块)仅依赖契约包。
4
+ */
5
+ import type { MallRequestContext, MallScope } from '../scope';
6
+ export interface ShoppingQueryContext {
7
+ /** mall scope(session 绑定) */
8
+ readonly scope: MallScope;
9
+ /** 当前主体(会员体系 subjectId;匿名缺省) */
10
+ readonly subjectId?: string;
11
+ /** 请求上下文(handler 内可用;跨模块消费方仅依赖本契约) */
12
+ readonly requestContext: MallRequestContext;
13
+ }
14
+ export interface ShoppingPage<T> {
15
+ readonly items: readonly T[];
16
+ readonly page: number;
17
+ readonly pageSize: number;
18
+ readonly total: number;
19
+ readonly hasMore: boolean;
20
+ }
21
+ export interface ProductSearchCriteria {
22
+ readonly ctx: ShoppingQueryContext;
23
+ readonly keyword?: string;
24
+ readonly keywords?: readonly string[];
25
+ readonly categoryCode?: string;
26
+ readonly brandCode?: string;
27
+ readonly minPriceMinor?: number;
28
+ readonly maxPriceMinor?: number;
29
+ readonly floorCode?: string;
30
+ readonly buildingCode?: string;
31
+ readonly page: number;
32
+ readonly pageSize: number;
33
+ readonly marketableOnly?: boolean;
34
+ }
35
+ export interface CatalogQueryPort {
36
+ searchProducts(criteria: ProductSearchCriteria): Promise<ShoppingPage<ProductRecord>>;
37
+ getProduct(productId: string, ctx: ShoppingQueryContext): Promise<ProductRecord | null>;
38
+ getFacets(criteria: ProductSearchCriteria): Promise<ProductFacetsRecord>;
39
+ }
40
+ export interface ProductRecord {
41
+ readonly productId: string;
42
+ readonly name: string;
43
+ readonly description?: string;
44
+ readonly imageUrls: readonly string[];
45
+ readonly brand?: string;
46
+ readonly categoryPath: readonly string[];
47
+ readonly price: {
48
+ readonly sale?: MoneyRecord;
49
+ readonly original?: MoneyRecord;
50
+ readonly promotion?: MoneyRecord;
51
+ };
52
+ readonly availability: {
53
+ readonly status: 'in_stock' | 'out_of_stock' | 'limited' | 'unknown';
54
+ readonly label: string;
55
+ readonly marketable: boolean;
56
+ readonly observedAt: string;
57
+ };
58
+ readonly merchant: {
59
+ readonly merchantId: string;
60
+ readonly name: string;
61
+ readonly location?: MerchantLocationRecord;
62
+ };
63
+ readonly labels: readonly string[];
64
+ readonly attributes: ReadonlyArray<{
65
+ readonly name: string;
66
+ readonly value: string;
67
+ }>;
68
+ readonly promotionFacts: readonly string[];
69
+ readonly observedAt: string;
70
+ }
71
+ export interface MoneyRecord {
72
+ readonly currency: 'CNY';
73
+ readonly amountMinor: number;
74
+ readonly display: string;
75
+ }
76
+ export interface MerchantLocationRecord {
77
+ readonly buildingName?: string;
78
+ readonly floorName?: string;
79
+ readonly unitName?: string;
80
+ readonly displayText: string;
81
+ readonly poiId?: string;
82
+ }
83
+ export interface ProductFacetsRecord {
84
+ readonly brands: ReadonlyArray<{
85
+ readonly code: string;
86
+ readonly name: string;
87
+ readonly count: number;
88
+ }>;
89
+ readonly categories: ReadonlyArray<{
90
+ readonly code: string;
91
+ readonly name: string;
92
+ readonly count: number;
93
+ }>;
94
+ readonly priceRanges: ReadonlyArray<{
95
+ readonly minMinor: number;
96
+ readonly maxMinor: number;
97
+ readonly displayLabel: string;
98
+ readonly count: number;
99
+ }>;
100
+ readonly floors: ReadonlyArray<{
101
+ readonly code: string;
102
+ readonly displayName: string;
103
+ readonly count: number;
104
+ }>;
105
+ }
106
+ export interface MerchantSearchCriteria {
107
+ readonly ctx: ShoppingQueryContext;
108
+ readonly keyword?: string;
109
+ readonly keywords?: readonly string[];
110
+ readonly brandCode?: string;
111
+ readonly businessCategory?: string;
112
+ readonly floorCode?: string;
113
+ readonly buildingCode?: string;
114
+ readonly page: number;
115
+ readonly pageSize: number;
116
+ }
117
+ export interface MerchantDirectoryQueryPort {
118
+ searchMerchants(criteria: MerchantSearchCriteria): Promise<ShoppingPage<MerchantRecord>>;
119
+ getMerchant(merchantId: string, ctx: ShoppingQueryContext): Promise<MerchantRecord | null>;
120
+ }
121
+ export interface MerchantRecord {
122
+ readonly merchantId: string;
123
+ readonly name: string;
124
+ readonly logoUrl?: string;
125
+ readonly coverUrls: readonly string[];
126
+ readonly brand?: string;
127
+ readonly businessCategories: readonly string[];
128
+ readonly location: MerchantLocationRecord;
129
+ readonly status: {
130
+ readonly code: 'enabled' | 'disabled' | 'unknown';
131
+ readonly label: string;
132
+ readonly observedAt: string;
133
+ };
134
+ readonly description?: string;
135
+ readonly contactInfo?: ReadonlyArray<{
136
+ readonly channel: string;
137
+ readonly value: string;
138
+ }>;
139
+ readonly services: readonly string[];
140
+ readonly promotionFacts: readonly string[];
141
+ readonly observedAt: string;
142
+ }
143
+ export interface CommercialCategoryQueryPort {
144
+ listCategories(ctx: ShoppingQueryContext): Promise<readonly CategoryRecord[]>;
145
+ }
146
+ export interface CategoryRecord {
147
+ readonly code: string;
148
+ readonly name: string;
149
+ readonly description?: string;
150
+ readonly merchantCount: number;
151
+ readonly subCategories?: ReadonlyArray<{
152
+ readonly code: string;
153
+ readonly name: string;
154
+ readonly merchantCount: number;
155
+ }>;
156
+ }
157
+ export interface MallDirectoryQueryPort {
158
+ getDirectory(ctx: ShoppingQueryContext): Promise<MallDirectoryRecord | null>;
159
+ }
160
+ export interface MallDirectoryRecord {
161
+ readonly mallId: string;
162
+ readonly mallName: string;
163
+ readonly buildings: ReadonlyArray<{
164
+ readonly buildingCode: string;
165
+ readonly buildingName: string;
166
+ readonly floors: ReadonlyArray<{
167
+ readonly floorCode: string;
168
+ readonly floorName: string;
169
+ readonly businessCategories: readonly string[];
170
+ readonly merchantCount: number;
171
+ }>;
172
+ }>;
173
+ readonly observedAt: string;
174
+ }
175
+ export interface FaqEntry {
176
+ readonly question: string;
177
+ readonly answer: string;
178
+ readonly category?: string;
179
+ readonly relevanceScore: number;
180
+ }
181
+ export interface AssistanceQueryPort {
182
+ searchFaq(ctx: ShoppingQueryContext, query: string, topK?: number): Promise<readonly FaqEntry[]>;
183
+ searchKnowledge(ctx: ShoppingQueryContext, query: string, topK?: number): Promise<readonly KnowledgeEntry[]>;
184
+ listHumanGuides(merchantId: string, ctx: ShoppingQueryContext): Promise<readonly HumanGuideRecord[]>;
185
+ }
186
+ export interface KnowledgeEntry {
187
+ readonly content: string;
188
+ readonly title?: string;
189
+ readonly score: number;
190
+ }
191
+ export interface HumanGuideRecord {
192
+ readonly guideId: string;
193
+ readonly name: string;
194
+ readonly title?: string;
195
+ readonly avatarUrl?: string;
196
+ readonly contactInfo?: ReadonlyArray<{
197
+ readonly channel: string;
198
+ readonly value: string;
199
+ }>;
200
+ readonly available: boolean;
201
+ }
202
+ export interface NavigationPort {
203
+ getLocation(merchantId: string, ctx: ShoppingQueryContext): Promise<MerchantLocationRecord | null>;
204
+ listNearbyMalls(ctx: ShoppingQueryContext, query?: string): Promise<readonly NearbyMallRecord[]>;
205
+ listBrowsingHistory(ctx: ShoppingQueryContext, page: number, pageSize: number): Promise<ShoppingPage<ProductRecord>>;
206
+ }
207
+ export interface NearbyMallRecord {
208
+ readonly mallId: string;
209
+ readonly name: string;
210
+ readonly address: string;
211
+ readonly distanceKm?: number;
212
+ readonly status: {
213
+ readonly code: 'open' | 'closed' | 'unknown';
214
+ readonly label: string;
215
+ };
216
+ }
package/package.json CHANGED
@@ -1,18 +1,16 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-contracts-mall",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
- "description": "商圈领域契约(TIER1,types-only):Port 接口 + MallEventMap + 领域 DTO",
5
+ "description": "商圈领域契约(TIER1,types + runtime):Port 接口 + MallEventMap + 领域 DTO + scope/装配器运行时。",
6
6
  "exports": {
7
7
  ".": {
8
- "types": "./dist/index.d.ts"
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/runtime.js"
9
10
  }
10
11
  },
11
12
  "files": [
12
13
  "dist",
13
- "src",
14
- "tsconfig.json",
15
- "tsconfig.build.json",
16
14
  "README.md",
17
15
  "LICENSE"
18
16
  ],
@@ -22,15 +20,17 @@
22
20
  "publishConfig": {
23
21
  "access": "public"
24
22
  },
25
- "peerDependencies": {
23
+ "dependencies": {
24
+ "@tbox.cn/app-contracts": "^0.1.0",
26
25
  "zod": "^3.24.0"
27
26
  },
28
27
  "devDependencies": {
28
+ "tsup": "^8.0.0",
29
29
  "typescript": "^5.7.0"
30
30
  },
31
31
  "license": "MIT",
32
32
  "scripts": {
33
- "build": "tsc -p tsconfig.build.json",
33
+ "build": "tsc -p tsconfig.build.json && tsup src/runtime.ts --format esm --external @ag-ui/core --out-dir dist",
34
34
  "typecheck": "tsc --noEmit"
35
35
  }
36
36
  }
@@ -1,8 +0,0 @@
1
- /** 优惠券(商圈领域 DTO) */
2
- export interface Coupon {
3
- couponId: string;
4
- title: string;
5
- /** 可抵扣金额(元) */
6
- amount: number;
7
- status: 'AVAILABLE' | 'USED' | 'EXPIRED';
8
- }
@@ -1,6 +0,0 @@
1
- /** 折扣规则(商圈领域 DTO) */
2
- export interface DiscountRule {
3
- level: 'silver' | 'gold' | 'platinum';
4
- /** 折扣率 0-1(0.9 = 9 折) */
5
- discount: number;
6
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,14 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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';
@@ -1,21 +0,0 @@
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
- }
@@ -1,16 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- import type { Coupon } from '../domain/coupon';
2
-
3
- /** PromotionQueryPort:营销资格查询(scenario 出券用) */
4
- export interface PromotionQueryPort {
5
- queryEligibleCoupons(userId: string): Promise<Coupon[]>;
6
- }
@@ -1,15 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {},
4
- "include": ["src"]
5
- }