@tbox.cn/app-provider-mock 0.3.0 → 0.5.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.
@@ -1,20 +1,9 @@
1
1
  // src/server/index.ts
2
+ import { randomBytes } from "crypto";
2
3
  import { readLoginMallId } from "@tbox.cn/app-contracts-mall";
3
4
 
4
- // src/server/config.ts
5
- function resolveConfig(raw, defaults, intKeys = []) {
6
- const src = raw && typeof raw === "object" ? raw : {};
7
- const out = {};
8
- for (const [key, fallback] of Object.entries(defaults)) {
9
- const value = src[key];
10
- const ok = typeof value === typeof fallback && (typeof value !== "number" || Number.isFinite(value) && (!intKeys.includes(key) || Number.isInteger(value))) && (typeof value !== "string" || value !== "");
11
- out[key] = ok ? value : fallback;
12
- }
13
- return out;
14
- }
15
-
16
5
  // src/server/member.ts
17
- var MEMBER_CFG_DEFAULTS = {
6
+ var CFG = {
18
7
  memberName: "\u793A\u4F8B\u4F1A\u5458",
19
8
  cardName: "\u793A\u4F8B\u4F1A\u5458\u5361",
20
9
  levelName: "",
@@ -23,7 +12,6 @@ var MEMBER_CFG_DEFAULTS = {
23
12
  enrollUrl: "alipays://platformapi/startapp?appId=demo&page=v/index/index",
24
13
  loginUrl: "alipays://platformapi/startapp?appId=demo&page=v/login/index"
25
14
  };
26
- var MEMBER_CFG_INT_KEYS = ["initialPoints"];
27
15
  var mockMemberState = {
28
16
  enrolled: /* @__PURE__ */ new Set(),
29
17
  balances: /* @__PURE__ */ new Map(),
@@ -61,17 +49,14 @@ var MockMemberServiceImpl = class {
61
49
  enrollUrl;
62
50
  /** 登录页深链(同上,可选透传素材;供未登录引导卡跳转)。 */
63
51
  loginUrl;
64
- /** 配置快照(fail-soft,构造期一次解析;键集 ≡ MEMBER_CFG_DEFAULTS) */
65
- cfg;
66
52
  /** 积分流水(金额随 initialPoints 派生——与余额同源) */
67
53
  usage;
68
54
  /** 默认访客(无种子):demo-user 初始 not_enrolled,经入会闭环翻为 active */
69
- constructor(initial = {}, config = {}) {
70
- this.cfg = resolveConfig(config, MEMBER_CFG_DEFAULTS, MEMBER_CFG_INT_KEYS);
71
- this.enrollUrl = this.cfg.enrollUrl;
72
- this.loginUrl = this.cfg.loginUrl;
55
+ constructor(initial = {}) {
56
+ this.enrollUrl = CFG.enrollUrl;
57
+ this.loginUrl = CFG.loginUrl;
73
58
  this.usage = [
74
- { usageRecordRef: "demo:usage:1", title: "\u5F00\u5361\u793C", amount: `+${String(this.cfg.initialPoints)}`, usedAt: (/* @__PURE__ */ new Date()).toISOString(), description: "mock \u6F14\u793A\u6D41\u6C34" }
59
+ { usageRecordRef: "demo:usage:1", title: "\u5F00\u5361\u793C", amount: `+${String(CFG.initialPoints)}`, usedAt: (/* @__PURE__ */ new Date()).toISOString(), description: "mock \u6F14\u793A\u6D41\u6C34" }
75
60
  ];
76
61
  for (const [userId, balance] of Object.entries(initial)) {
77
62
  mockMemberState.enrolled.add(userId);
@@ -88,20 +73,20 @@ var MockMemberServiceImpl = class {
88
73
  };
89
74
  }
90
75
  async getProfile(_userId) {
91
- return { labels: [{ labelRef: "demo:label:1", name: this.cfg.memberName }], observedAt: (/* @__PURE__ */ new Date()).toISOString() };
76
+ return { labels: [{ labelRef: "demo:label:1", name: CFG.memberName }], observedAt: (/* @__PURE__ */ new Date()).toISOString() };
92
77
  }
93
78
  async getCard(userId) {
94
79
  if (!isMockMemberActive(userId)) return null;
95
80
  return {
96
81
  cardRef: `demo:card:${userId}`,
97
- cardDisplay: this.cfg.cardName,
82
+ cardDisplay: CFG.cardName,
98
83
  status: "active",
99
- ...this.cfg.levelName !== "" ? { levelName: this.cfg.levelName } : {},
84
+ ...CFG.levelName !== "" ? { levelName: CFG.levelName } : {},
100
85
  observedAt: (/* @__PURE__ */ new Date()).toISOString()
101
86
  };
102
87
  }
103
88
  async queryPoints(userId) {
104
- return { userId, balance: this.currentBalanceOf(userId), membershipLabel: this.cfg.cardName };
89
+ return { userId, balance: this.currentBalanceOf(userId), membershipLabel: CFG.cardName };
105
90
  }
106
91
  async getBenefits(userId) {
107
92
  return { availablePoints: this.currentBalanceOf(userId), levelName: "\u793A\u4F8B\u7B49\u7EA7", observedAt: (/* @__PURE__ */ new Date()).toISOString() };
@@ -131,7 +116,7 @@ var MockMemberServiceImpl = class {
131
116
  currentBalanceOf(userId) {
132
117
  const override = mockMemberState.balances.get(userId);
133
118
  if (override !== void 0) return override;
134
- return isMockMemberEnrolled(userId) ? this.cfg.initialPoints : 0;
119
+ return isMockMemberEnrolled(userId) ? CFG.initialPoints : 0;
135
120
  }
136
121
  async enroll(input) {
137
122
  enrollMockMember(input.userId);
@@ -156,7 +141,7 @@ var MockMemberServiceImpl = class {
156
141
 
157
142
  // src/server/parking.ts
158
143
  var now = () => (/* @__PURE__ */ new Date()).toISOString();
159
- var PARKING_CFG_DEFAULTS = {
144
+ var CFG2 = {
160
145
  parkName: "\u793A\u4F8B\u505C\u8F66\u573A",
161
146
  feeName: "\u505C\u8F66\u8D39\uFF083 \u5C0F\u65F6\uFF09",
162
147
  feeCents: 1500,
@@ -170,24 +155,20 @@ var PARKING_CFG_DEFAULTS = {
170
155
  vehicleZone: "A \u533A",
171
156
  vehicleSpaceNo: "A-128"
172
157
  };
173
- var PARKING_CFG_INT_KEYS = ["feeCents", "remainingSpaces", "memberBenefitDiscountCents"];
174
158
  var MockParkingServiceImpl = class {
175
159
  vehicles = /* @__PURE__ */ new Map();
176
160
  records;
177
- /** 配置快照(fail-soft,构造期一次解析;键集 ≡ PARKING_CFG_DEFAULTS) */
178
- cfg;
179
- constructor(mallId = "mall-demo", config = {}) {
161
+ constructor(mallId = "mall-demo") {
180
162
  this.mallId = mallId;
181
163
  void this.mallId;
182
- this.cfg = resolveConfig(config, PARKING_CFG_DEFAULTS, PARKING_CFG_INT_KEYS);
183
164
  this.records = [
184
165
  {
185
166
  recordRef: "demo:record:1",
186
167
  plateNo: "demo-plate",
187
- amountCents: this.cfg.feeCents,
168
+ amountCents: CFG2.feeCents,
188
169
  paidAt: now(),
189
170
  status: "PAID",
190
- parkName: this.cfg.parkName,
171
+ parkName: CFG2.parkName,
191
172
  orderCompleted: true
192
173
  }
193
174
  ];
@@ -200,10 +181,10 @@ var MockParkingServiceImpl = class {
200
181
  */
201
182
  benefits() {
202
183
  const benefits = [];
203
- if (this.cfg.memberBenefitEnabled) {
204
- benefits.push({ benefitRef: "demo:benefit:member-discount", title: "\u4F1A\u5458 95 \u6298", description: "mock \u6F14\u793A\u6743\u76CA", kind: "discount", autoSelected: true, estimatedDiscountCents: this.cfg.memberBenefitDiscountCents });
184
+ if (CFG2.memberBenefitEnabled) {
185
+ benefits.push({ benefitRef: "demo:benefit:member-discount", title: "\u4F1A\u5458 95 \u6298", description: "mock \u6F14\u793A\u6743\u76CA", kind: "discount", autoSelected: true, estimatedDiscountCents: CFG2.memberBenefitDiscountCents });
205
186
  }
206
- if (this.cfg.pointsBenefitEnabled) {
187
+ if (CFG2.pointsBenefitEnabled) {
207
188
  benefits.push({ benefitRef: "demo:benefit:points-offset", title: "\u79EF\u5206\u62B5 5 \u5143", description: "mock \u6F14\u793A\u6743\u76CA", kind: "points", autoSelected: false, estimatedDiscountCents: 500, requiredPoints: 500, previewPayableCents: 1e3 });
208
189
  }
209
190
  return benefits;
@@ -214,10 +195,10 @@ var MockParkingServiceImpl = class {
214
195
  plateNo,
215
196
  mallId: q.scope.mallId ?? "demo",
216
197
  entryAt: now(),
217
- feeItems: [{ name: this.cfg.feeName, amountCents: this.cfg.feeCents }],
218
- totalCents: this.cfg.feeCents,
198
+ feeItems: [{ name: CFG2.feeName, amountCents: CFG2.feeCents }],
199
+ totalCents: CFG2.feeCents,
219
200
  discountCents: 0,
220
- payableCents: this.cfg.feeCents,
201
+ payableCents: CFG2.feeCents,
221
202
  appliedBenefits: [],
222
203
  revision: 1,
223
204
  paymentState: "UNPAID"
@@ -243,7 +224,7 @@ var MockParkingServiceImpl = class {
243
224
  return record;
244
225
  }
245
226
  async getInvoiceSettings() {
246
- return { parkingInvoiceEnabled: this.cfg.invoiceEnabled };
227
+ return { parkingInvoiceEnabled: CFG2.invoiceEnabled };
247
228
  }
248
229
  async listInvoiceableOrders(_q, page, pageSize) {
249
230
  const all = this.records.filter((r) => r.orderCompleted === true);
@@ -253,11 +234,11 @@ var MockParkingServiceImpl = class {
253
234
  async queryParkingInfo(_q, kind) {
254
235
  return {
255
236
  kind,
256
- title: this.cfg.parkName,
237
+ title: CFG2.parkName,
257
238
  entries: [
258
- { label: "\u5269\u4F59\u8F66\u4F4D", value: String(this.cfg.remainingSpaces) },
259
- { label: "\u9996\u5C0F\u65F6\u8D39\u7387", value: this.cfg.firstHourRate },
260
- { label: "\u4F1A\u5458\u6743\u76CA", value: this.cfg.memberBenefitEnabled ? "\u4F1A\u5458 95 \u6298" : "\u2014" }
239
+ { label: "\u5269\u4F59\u8F66\u4F4D", value: String(CFG2.remainingSpaces) },
240
+ { label: "\u9996\u5C0F\u65F6\u8D39\u7387", value: CFG2.firstHourRate },
241
+ { label: "\u4F1A\u5458\u6743\u76CA", value: CFG2.memberBenefitEnabled ? "\u4F1A\u5458 95 \u6298" : "\u2014" }
261
242
  ]
262
243
  };
263
244
  }
@@ -265,14 +246,14 @@ var MockParkingServiceImpl = class {
265
246
  return this.benefits();
266
247
  }
267
248
  async locateVehicle(_q, _plateNo) {
268
- return { floorName: this.cfg.vehicleFloor, zoneName: this.cfg.vehicleZone, spaceNo: this.cfg.vehicleSpaceNo, walkingRoute: "\u7535\u68AF\u5DE6\u8F6C 50 \u7C73" };
249
+ return { floorName: CFG2.vehicleFloor, zoneName: CFG2.vehicleZone, spaceNo: CFG2.vehicleSpaceNo, walkingRoute: "\u7535\u68AF\u5DE6\u8F6C 50 \u7C73" };
269
250
  }
270
251
  // ===== 支付三步链(mock:reconcile 恒 PAID 收口) =====
271
252
  async createOrder(_q, quoteRef) {
272
253
  return { payOrderId: `demo:pay:${quoteRef}`, paymentRef: `demo:payment:${quoteRef}` };
273
254
  }
274
255
  async getOrderInfo(_q, _paymentRef) {
275
- return { orderInfo: "demo-order-info", channel: "50", payableFeeCents: this.cfg.feeCents };
256
+ return { orderInfo: "demo-order-info", channel: "50", payableFeeCents: CFG2.feeCents };
276
257
  }
277
258
  async getPaymentSign(_q, _paymentRef) {
278
259
  return { orderInfo: "demo-order-info" };
@@ -316,7 +297,7 @@ var MockParkingServiceImpl = class {
316
297
  // src/server/promotion.ts
317
298
  var now2 = () => (/* @__PURE__ */ new Date()).toISOString();
318
299
  var inDays = (d) => new Date(Date.now() + d * 864e5).toISOString();
319
- var PROMOTION_CFG_DEFAULTS = {
300
+ var CFG3 = {
320
301
  couponTitle: "\u6EE1 100 \u51CF 20 \u5143\u5238",
321
302
  couponValueCents: 2e3,
322
303
  couponThresholdCents: 1e4,
@@ -324,25 +305,21 @@ var PROMOTION_CFG_DEFAULTS = {
324
305
  grouponEnabled: true,
325
306
  activityTitle: "\u793A\u4F8B\u5546\u573A\u5468\u5E74\u5E86"
326
307
  };
327
- var PROMOTION_CFG_INT_KEYS = ["couponValueCents", "couponThresholdCents", "couponValidityDays"];
328
308
  var MockPromotionServiceImpl = class {
329
- /** 配置快照(fail-soft,构造期一次解析;键集 ≡ PROMOTION_CFG_DEFAULTS) */
330
- cfg;
331
309
  /** 供/资产/活动三表(构造期按 cfg 构建——请求级实例,成本可忽略) */
332
310
  offers;
333
311
  entitlements;
334
312
  activities;
335
- constructor(config = {}) {
336
- this.cfg = resolveConfig(config, PROMOTION_CFG_DEFAULTS, PROMOTION_CFG_INT_KEYS);
313
+ constructor() {
337
314
  const ts = now2();
338
315
  const couponOffer = {
339
316
  offerRef: "demo:coupon:1001",
340
317
  offerType: "COUPON",
341
- title: this.cfg.couponTitle,
318
+ title: CFG3.couponTitle,
342
319
  subtitle: "\u5168\u573A\u901A\u7528\uFF08mock \u6F14\u793A\uFF09",
343
320
  tags: ["\u901A\u7528"],
344
- validity: { start: ts, end: inDays(this.cfg.couponValidityDays) },
345
- facets: [{ kind: "COUPON", discountType: "AMOUNT", value: this.cfg.couponValueCents, thresholdCents: this.cfg.couponThresholdCents }],
321
+ validity: { start: ts, end: inDays(CFG3.couponValidityDays) },
322
+ facets: [{ kind: "COUPON", discountType: "AMOUNT", value: CFG3.couponValueCents, thresholdCents: CFG3.couponThresholdCents }],
346
323
  availability: { status: "AVAILABLE", reasonCodes: [], evaluatedAt: ts, authoritative: false },
347
324
  participation: { mode: "CLAIM_THEN_PURCHASE", steps: [{ title: "\u9886\u53D6", description: "\u70B9\u51FB\u9886\u53D6\u540E\u81EA\u52A8\u5B58\u5165\u5361\u5305" }] }
348
325
  };
@@ -357,12 +334,12 @@ var MockPromotionServiceImpl = class {
357
334
  availability: { status: "AVAILABLE", reasonCodes: [], evaluatedAt: ts, authoritative: false },
358
335
  participation: { mode: "CLAIM_THEN_PURCHASE", steps: [{ title: "\u8D2D\u4E70", description: "\u6309\u56E2\u8D2D\u4EF7\u4E0B\u5355" }] }
359
336
  };
360
- this.offers = this.cfg.grouponEnabled ? [couponOffer, grouponOffer] : [couponOffer];
337
+ this.offers = CFG3.grouponEnabled ? [couponOffer, grouponOffer] : [couponOffer];
361
338
  this.entitlements = [
362
339
  {
363
340
  entitlementRef: "demo:entitlement:1",
364
341
  offerRef: "demo:coupon:1001",
365
- title: this.cfg.couponTitle,
342
+ title: CFG3.couponTitle,
366
343
  entitlementType: "COUPON",
367
344
  status: "EFFECTIVE",
368
345
  codeMasked: "DEMO-****-1001"
@@ -371,7 +348,7 @@ var MockPromotionServiceImpl = class {
371
348
  this.activities = [
372
349
  {
373
350
  activityRef: "demo:activity:3001",
374
- title: this.cfg.activityTitle,
351
+ title: CFG3.activityTitle,
375
352
  subtitle: "mock \u6F14\u793A\u6D3B\u52A8",
376
353
  registrationRequired: false,
377
354
  offerRefs: ["demo:coupon:1001"]
@@ -428,7 +405,7 @@ var MockPromotionServiceImpl = class {
428
405
  };
429
406
 
430
407
  // src/server/shopping.ts
431
- var SHOPPING_CFG_DEFAULTS = {
408
+ var CFG4 = {
432
409
  extraShopName: "",
433
410
  // '' = 不追加门店(空串 = 缺省/不生效语义)
434
411
  extraShopCategory: "\u9910\u996E",
@@ -436,7 +413,6 @@ var SHOPPING_CFG_DEFAULTS = {
436
413
  extraShopUnit: "304",
437
414
  extraShopOpen: true
438
415
  };
439
- var SHOPPING_CFG_INT_KEYS = [];
440
416
  var SHOPPING_FLOORS = ["B1", "1 \u697C", "2 \u697C", "3 \u697C", "4 \u697C"];
441
417
  var DEMO_BUILDINGS = [
442
418
  {
@@ -518,13 +494,10 @@ function toFloorRecord(floor) {
518
494
  return { floorCode: floor.floorName, floorName: floor.floorName, businessCategories: cats, merchantCount: floor.shops.length };
519
495
  }
520
496
  var MockShoppingServiceImpl = class {
521
- /** 配置快照(fail-soft,构造期一次解析;键集 ≡ SHOPPING_CFG_DEFAULTS) */
522
- cfg;
523
497
  buildings;
524
498
  shops;
525
499
  categories;
526
- constructor(seed = DEMO_BUILDINGS, config = {}) {
527
- this.cfg = resolveConfig(config, SHOPPING_CFG_DEFAULTS, SHOPPING_CFG_INT_KEYS);
500
+ constructor(seed = DEMO_BUILDINGS) {
528
501
  const withExtra = this.withExtraShop(seed);
529
502
  this.buildings = withExtra;
530
503
  this.shops = flattenShops(withExtra);
@@ -532,15 +505,15 @@ var MockShoppingServiceImpl = class {
532
505
  }
533
506
  /** extraShopName 非空 → 指定楼层追加演示门店(名称 trim 判空 + 楼层白名单回退——消费点守卫) */
534
507
  withExtraShop(seed) {
535
- const name = this.cfg.extraShopName.trim();
508
+ const name = CFG4.extraShopName.trim();
536
509
  if (!name) return seed;
537
- const floor = SHOPPING_FLOORS.includes(this.cfg.extraShopFloor) ? this.cfg.extraShopFloor : "3 \u697C";
510
+ const floor = SHOPPING_FLOORS.includes(CFG4.extraShopFloor) ? CFG4.extraShopFloor : "3 \u697C";
538
511
  const extra = {
539
512
  merchantId: "demo-shop-1013",
540
513
  name,
541
- businessCategories: [this.cfg.extraShopCategory],
542
- unitName: this.cfg.extraShopUnit,
543
- status: this.cfg.extraShopOpen ? { code: "enabled", label: "\u8425\u4E1A\u4E2D" } : { code: "disabled", label: "\u4F11\u606F\u4E2D" }
514
+ businessCategories: [CFG4.extraShopCategory],
515
+ unitName: CFG4.extraShopUnit,
516
+ status: CFG4.extraShopOpen ? { code: "enabled", label: "\u8425\u4E1A\u4E2D" } : { code: "disabled", label: "\u4F11\u606F\u4E2D" }
544
517
  };
545
518
  return seed.map((b) => ({
546
519
  ...b,
@@ -610,26 +583,25 @@ var MockShoppingServiceImpl = class {
610
583
  // src/server/mall-info.ts
611
584
  var MOCK_MALL_INFO_PROVIDER = "mock";
612
585
  var MOCK_MALL_INFO_IMPL = "mock-mall-info@1";
613
- var MALL_INFO_CFG_DEFAULTS = {
586
+ var CFG5 = {
614
587
  name: "",
615
588
  // '' 哨兵 = 动态别名回退
616
589
  address: "\u793A\u4F8B\u5546\u573A\u5730\u5740\uFF08demo\uFF09",
617
590
  latitude: 30,
618
591
  longitude: 120
619
592
  };
620
- var MALL_INFO_CFG_INT_KEYS = [];
621
593
  var MALL_ID_RE = /^[\w-]{1,32}$/;
622
594
  var mockMallInfoFactory = (input) => {
623
- const cfg = resolveConfig(input.config, MALL_INFO_CFG_DEFAULTS, MALL_INFO_CFG_INT_KEYS);
595
+ void input;
624
596
  return {
625
597
  async getMallInfo(mallId) {
626
598
  if (!MALL_ID_RE.test(mallId)) return void 0;
627
599
  return {
628
600
  mallId,
629
- name: cfg.name !== "" ? cfg.name : `\u793A\u4F8B\u5546\u573A\uFF08${mallId}\uFF09`,
630
- address: cfg.address,
631
- latitude: cfg.latitude,
632
- longitude: cfg.longitude
601
+ name: CFG5.name !== "" ? CFG5.name : `\u793A\u4F8B\u5546\u573A\uFF08${mallId}\uFF09`,
602
+ address: CFG5.address,
603
+ latitude: CFG5.latitude,
604
+ longitude: CFG5.longitude
633
605
  };
634
606
  }
635
607
  };
@@ -637,7 +609,7 @@ var mockMallInfoFactory = (input) => {
637
609
 
638
610
  // src/server/mock-enroll-route.ts
639
611
  import { Router } from "express";
640
- import { getRequestContext } from "@tbox.cn/app-sdk/server";
612
+ import { getRequestContext } from "@tbox.cn/app-agent-sdk-server";
641
613
  function resolveMockEnroll(input) {
642
614
  if ((input.nodeEnv ?? process.env.NODE_ENV) === "production") {
643
615
  return { status: 503, body: { error: "mock-only" } };
@@ -646,7 +618,7 @@ function resolveMockEnroll(input) {
646
618
  return { status: 401, body: { error: "unauthorized" } };
647
619
  }
648
620
  const body = input.body ?? {};
649
- const userId = typeof body.userId === "string" && body.userId.trim() ? body.userId.trim() : MOCK_SHELL_USER_ID;
621
+ const userId = typeof body.userId === "string" && body.userId.trim() ? body.userId.trim() : input.identity.userId ?? `guest_${Date.now()}`;
650
622
  enrollMockMember(userId);
651
623
  return { status: 200, body: { state: "active", memberRef: `demo:member:${userId}` } };
652
624
  }
@@ -658,7 +630,7 @@ function resolveMockLogout(input) {
658
630
  return { status: 401, body: { error: "unauthorized" } };
659
631
  }
660
632
  const body = input.body ?? {};
661
- const userId = typeof body.userId === "string" && body.userId.trim() ? body.userId.trim() : MOCK_SHELL_USER_ID;
633
+ const userId = typeof body.userId === "string" && body.userId.trim() ? body.userId.trim() : input.identity.userId ?? `guest_${Date.now()}`;
662
634
  logoutMockMember(userId);
663
635
  return { status: 200, body: { state: "logged_out" } };
664
636
  }
@@ -683,33 +655,37 @@ var MOCK_MEMBER_IMPL = "mock-member@1";
683
655
  var MOCK_PARKING_IMPL = "mock-parking@1";
684
656
  var MOCK_PROMOTION_IMPL = "mock-promotion@1";
685
657
  var MOCK_SHOPPING_IMPL = "mock-shopping@1";
686
- var memberFactory = (input) => new MockMemberServiceImpl({}, input.config);
687
- var parkingFactory = (input) => new MockParkingServiceImpl(input.instanceId || "mall-demo", input.config);
688
- var promotionFactory = (input) => new MockPromotionServiceImpl(input.config);
658
+ var memberFactory = () => new MockMemberServiceImpl({});
659
+ var parkingFactory = (input) => new MockParkingServiceImpl(input.instanceId || "mall-demo");
660
+ var promotionFactory = () => new MockPromotionServiceImpl();
689
661
  var shoppingFactory = (input) => {
690
662
  if (input.service !== "shopping-guide.catalog" && input.service !== "shopping-guide.shops" && input.service !== "shopping-guide.categories" && input.service !== "shopping-guide.directory") {
691
663
  throw new Error(`mock guide \u5DE5\u5382\u4E0D\u4F9B\u7ED9\u69FD\uFF1A${input.service}`);
692
664
  }
693
- return new MockShoppingServiceImpl(void 0, input.config);
665
+ return new MockShoppingServiceImpl(void 0);
694
666
  };
695
667
  var mallInfoFactory = (input) => mockMallInfoFactory(input);
696
668
  function createMockAlipayLoginExchange(integrations) {
697
669
  return {
698
670
  provider: "alipay",
671
+ /** 裸/demo 域默认开放 guest 登录(browser 轴 auto 档 → guest 签发) */
672
+ allowsGuestLogin() {
673
+ return true;
674
+ },
699
675
  matches(context) {
700
676
  const mallId = readLoginMallId(context);
701
677
  if (!mallId) return true;
702
678
  if (!integrations) return false;
703
679
  return integrations.hasProviderBinding("member.account", { mallId }, MOCK_PROVIDER, MOCK_MEMBER_IMPL);
704
680
  },
705
- async exchangeByCode(_code, _platform, context) {
681
+ async exchangeByCode({ context, previousIdentity }) {
706
682
  if (!readLoginMallId(context)) {
707
683
  throw new Error("AUTH_NOT_CONFIGURED: \u672A\u9009\u62E9\u5546\u573A\uFF08\u767B\u5F55 context \u65E0 mallId\uFF09");
708
684
  }
709
- const userId = MOCK_SHELL_USER_ID;
685
+ const userId = previousIdentity?.source === "guest" ? previousIdentity.userId : `guest_${randomBytes(16).toString("hex")}`;
710
686
  if (isMockMemberEnrolled(userId) && !isMockMemberLoggedOut(userId)) {
711
687
  return {
712
- identity: { userId, source: "external" },
688
+ identity: { userId, source: "guest" },
713
689
  credentials: {
714
690
  token: `demo:token:${userId}`,
715
691
  provider: "mock",
@@ -718,7 +694,7 @@ function createMockAlipayLoginExchange(integrations) {
718
694
  };
719
695
  }
720
696
  return {
721
- identity: { userId, source: "external" },
697
+ identity: { userId, source: "guest" },
722
698
  credentials: {
723
699
  token: "",
724
700
  provider: "mock",
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-provider-mock",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
- "description": "商圈 Mock Provider 包(17 槽全 local:true:member×5 / parking×3 / promotion×4 / guide×4 + mall.info):模板缺省开箱演示——免传输/凭据/实例配置,裸跑即完整 mock 演示;全槽 config schema(schemas/×5 域共享)+ 内存 config 消费(改配置重启即变)。",
5
+ "description": "商圈 Mock Provider 包(极简零配置):17 槽 local 供给开箱即用——免传输/凭据/实例配置/集成配置;config 消费与配置验证面见 @tbox.cn/app-provider-mocktest。",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
@@ -14,9 +14,10 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@tbox.cn/app-sdk": "0.19.0",
18
- "@tbox.cn/app-contracts": "0.10.0",
19
- "@tbox.cn/app-contracts-mall": "0.10.0"
17
+ "@tbox.cn/app-contracts": "0.12.0",
18
+ "@tbox.cn/app-contracts-mall": "0.12.0",
19
+ "@tbox.cn/app-agent-sdk-client": "0.1.0",
20
+ "@tbox.cn/app-agent-sdk-server": "0.1.0"
20
21
  },
21
22
  "devDependencies": {
22
23
  "@types/express": "4.17.25",
@@ -28,7 +29,6 @@
28
29
  },
29
30
  "files": [
30
31
  "dist",
31
- "schemas",
32
32
  "src",
33
33
  "tests",
34
34
  "tbox.module.json",
@@ -12,28 +12,29 @@
12
12
  * (catalog 空 + shop/category/directory 纯 mock 数据);assistance/navigation 本地知识库域
13
13
  * 归模块本地 adapter,不属 provider 供给面。
14
14
  *
15
- * config 消费:五域工厂透传 input.config → 各 impl 构造期 fail-soft 快照
16
- * (src/server/config.ts;键集/缺省双锁 tests/config-schema.test.ts);零配置 = 零行为变化。
15
+ * 零配置开箱(2026-09-20 拆分):五域工厂不带 config——演示常量冻结在各 impl
16
+ * (值 ≡ 0.4.0 缺省);config 消费面随 provider-mocktest 迁出。
17
17
  *
18
18
  * 隐式默认单实例(零拓扑部署兜底):register 期经 ctx.integrations.declareProviderInstances
19
19
  * 声明 mall-demo——显式 instances/defaultInstanceId 恒赢(融合规则见 contracts-mall
20
20
  * mallControlPlaneOf);值与 .real-env mock 档演示语义一致(星河 Mock 小镇 / mock-demo-app)。
21
21
  *
22
22
  * 入会体验闭环(C5)追加两件:
23
- * - scoped mock 换码器(ctx.authExchanges):固定 demo-user、GUEST/MEMBER 双形态对齐
24
- * 真实厂商换码协议(潜客 token=''+openid ↔ 会员 token+memberId)——mock 档冷登走与
25
- * 真实档同一条换码链,H5 侧代码零分叉。刻意不实现 devExternalCredentials:dev-login
26
- * 走协议 fail-soft 无 claim 签发(login-routes 三层解析能力口缺席即跳过)。
23
+ * - scoped mock 换码器(ctx.authExchanges):随机访客身份(guest_<32hex>,统一登录改造
24
+ * T17——固定 demo-user 共享身份退役)、GUEST/MEMBER 双形态对齐真实厂商换码协议
25
+ * (潜客 token=''+openid ↔ 会员 token+memberId)——mock 档冷登走与真实档同一条换码链,
26
+ * H5 侧代码零分叉。会话连续性由 previousIdentity 复用轨(previousToken source=guest
27
+ * 同 sub 续签)保证。
27
28
  * - mock 入会落地路由(ctx.routes):POST /demo/member-enroll(容器 mock-enrollment 页
28
29
  * 回调 + curl 联调)。
29
30
  */
30
- import type { ServerContext, ServerModule } from '@tbox.cn/app-sdk/server';
31
- import type { ServiceAdapterFactory } from '@tbox.cn/app-sdk/server';
31
+ import { randomBytes } from 'node:crypto';
32
+ import type { ServerContext, ServerModule } from '@tbox.cn/app-agent-sdk-server';
33
+ import type { ServiceAdapterFactory } from '@tbox.cn/app-agent-sdk-server';
32
34
  import type { ExchangeResult } from '@tbox.cn/app-contracts';
33
35
  import { readLoginMallId } from '@tbox.cn/app-contracts-mall';
34
36
  import {
35
37
  MockMemberServiceImpl,
36
- MOCK_SHELL_USER_ID,
37
38
  isMockMemberEnrolled,
38
39
  isMockMemberLoggedOut,
39
40
  } from './member';
@@ -56,9 +57,9 @@ export { MockShoppingServiceImpl } from './shopping';
56
57
  export { MOCK_MALL_INFO_PROVIDER, MOCK_MALL_INFO_IMPL, mockMallInfoFactory } from './mall-info';
57
58
  export { createMockEnrollRouter } from './mock-enroll-route';
58
59
 
59
- const memberFactory: ServiceAdapterFactory = (input) => new MockMemberServiceImpl({}, input.config);
60
- const parkingFactory: ServiceAdapterFactory = (input) => new MockParkingServiceImpl(input.instanceId || 'mall-demo', input.config);
61
- const promotionFactory: ServiceAdapterFactory = (input) => new MockPromotionServiceImpl(input.config);
60
+ const memberFactory: ServiceAdapterFactory = () => new MockMemberServiceImpl({});
61
+ const parkingFactory: ServiceAdapterFactory = (input) => new MockParkingServiceImpl(input.instanceId || 'mall-demo');
62
+ const promotionFactory: ServiceAdapterFactory = () => new MockPromotionServiceImpl();
62
63
  /** shopping-guide:四槽分支(017 槽位原子化)——MockShoppingServiceImpl 实现全部四 Port,
63
64
  * 结构类型满足任一槽产物(catalog 槽 = mock 空商品数据,对齐真实档无商品端点形态)。 */
64
65
  const shoppingFactory: ServiceAdapterFactory = (input) => {
@@ -70,7 +71,7 @@ const shoppingFactory: ServiceAdapterFactory = (input) => {
70
71
  ) {
71
72
  throw new Error(`mock guide 工厂不供给槽:${input.service}`);
72
73
  }
73
- return new MockShoppingServiceImpl(undefined, input.config);
74
+ return new MockShoppingServiceImpl(undefined);
74
75
  };
75
76
  /** mall.info:动态商场演示源(任意合法 mallId → 确定性别名;对齐真实厂商 mall-info adapter 通用形态) */
76
77
  const mallInfoFactory: ServiceAdapterFactory = (input) => mockMallInfoFactory(input);
@@ -81,11 +82,20 @@ const mallInfoFactory: ServiceAdapterFactory = (input) => mockMallInfoFactory(in
81
82
  * 为语义锚;mock 档无独立 auth 槽;无条件兜底位归部署装配的自定义换码器,本候选恒
82
83
  * scoped 层 first-match)。authCode 忽略(mock 语义:单 demo 用户/部署,无真实授权码可换)。
83
84
  * 统一范式:context 无 mallId(未选择商场)→ 命中本候选,exchangeByCode 显性抛错,
84
- * 不落内置本地 alipay(缺 env 报错误导部署)。
85
+ * 不落内置本地 alipay(缺 env 报错会误导部署)。
86
+ *
87
+ * 随机访客身份(统一登录改造 T17):mock 档壳内登录恒服务端随机(guest_<32hex>,
88
+ * source 'guest')——固定 demo-user 共享身份退役。会话连续性(enroll 后 MEMBER 形态、
89
+ * 记忆归属)由 previousIdentity 复用轨保证:客户端 previousToken 上送 → previousIdentity
90
+ * source=guest 时同 sub 续签(真实厂商忽略,mock 换码器是唯一复用消费方)。
85
91
  */
86
92
  function createMockAlipayLoginExchange(integrations: ServerContext['integrations']) {
87
93
  return {
88
94
  provider: 'alipay' as const,
95
+ /** 裸/demo 域默认开放 guest 登录(browser 轴 auto 档 → guest 签发) */
96
+ allowsGuestLogin() {
97
+ return true;
98
+ },
89
99
  matches(context?: Readonly<Record<string, unknown>>) {
90
100
  const mallId = readLoginMallId(context);
91
101
  // 未选择商场(context 无 mallId)→ 命中本换码器,由 exchangeByCode 显性抛
@@ -96,22 +106,23 @@ function createMockAlipayLoginExchange(integrations: ServerContext['integrations
96
106
  return integrations.hasProviderBinding('member.account', { mallId }, MOCK_PROVIDER, MOCK_MEMBER_IMPL);
97
107
  },
98
108
  async exchangeByCode(
99
- _code: string,
100
- _platform?: string,
101
- context?: Readonly<Record<string, unknown>>,
109
+ { context, previousIdentity }: { context?: Readonly<Record<string, unknown>>; previousIdentity?: { userId: string; source: string } },
102
110
  ): Promise<ExchangeResult> {
103
111
  // 未选择商场前置校验(与 matches 语义一致:域缺失显性报错,不产出 demo 身份)
104
112
  if (!readLoginMallId(context)) {
105
113
  throw new Error('AUTH_NOT_CONFIGURED: 未选择商场(登录 context 无 mallId)');
106
114
  }
107
- const userId = MOCK_SHELL_USER_ID;
115
+ // 随机访客身份(previousToken 复用轨:guest 同 sub 续签)
116
+ const userId = previousIdentity?.source === 'guest'
117
+ ? previousIdentity.userId
118
+ : `guest_${randomBytes(16).toString('hex')}`;
108
119
  // 会员形态需登录态健康:登出态(loggedOut)降级 GUEST 形态——对齐真实档 silentLogin 信封
109
120
  // 非 200 降级(2026-09-02 真机实测):登出后换码 = 潜客同构结果(token=''),H5 侧
110
121
  // not_enrolled → 入会引导卡 → 半屏 getLoginState 闭环恢复;enroll 清登出态后冷登回 MEMBER。
111
122
  if (isMockMemberEnrolled(userId) && !isMockMemberLoggedOut(userId)) {
112
123
  // MEMBER 形态(对齐真实档会员换码输出):token + memberId 随 attributes 流动
113
124
  return {
114
- identity: { userId, source: 'external' as const },
125
+ identity: { userId, source: 'guest' as const },
115
126
  credentials: {
116
127
  token: `demo:token:${userId}`,
117
128
  provider: 'mock',
@@ -122,7 +133,7 @@ function createMockAlipayLoginExchange(integrations: ServerContext['integrations
122
133
  // GUEST 形态(对齐真实档潜客分支):token='' + openid 身份——「合法登录未入会」;
123
134
  // 登出降级同走此构造(单源)。真实档另携 visitortoken,mock 链路无消费方故极简。
124
135
  return {
125
- identity: { userId, source: 'external' as const },
136
+ identity: { userId, source: 'guest' as const },
126
137
  credentials: {
127
138
  token: '',
128
139
  provider: 'mock',
@@ -9,40 +9,38 @@
9
9
  * - mallId 形状守卫(/^[\w-]{1,32}$/):畸形 ID 直接返回 undefined(S4 DoS 防线——
10
10
  * 记录≠校验教训:请求形状断言在 provider adapter 单测锁死)
11
11
  * - fail-soft 契约恒满足:本实现无 IO,不可能失败——契约面与真实档保持一致
12
- * - config 消费:MALL_INFO_CFG_DEFAULTS 为契约单源(name 空串 = 动态别名回退;
13
- * 双锁测试 tests/config-schema.test.ts)
12
+ * - 演示常量零配置冻结:CFG 值 ≡ 0.4.0 缺省(2026-09-20 拆分——config 消费随
13
+ * provider-mocktest 迁出)
14
14
  */
15
- import { resolveConfig, type CfgDefaults } from './config';
16
15
  import type { MallInfo, MallInfoPort } from '@tbox.cn/app-contracts-mall';
17
- import type { ServiceAdapterFactory } from '@tbox.cn/app-sdk/server';
16
+ import type { ServiceAdapterFactory } from '@tbox.cn/app-agent-sdk-server';
18
17
 
19
18
  export const MOCK_MALL_INFO_PROVIDER = 'mock';
20
19
  export const MOCK_MALL_INFO_IMPL = 'mock-mall-info@1';
21
20
 
22
- /** config 契约单源(键集/缺省/整数约束;lat/lon 分式合法——不进 intKeys) */
23
- export const MALL_INFO_CFG_DEFAULTS = {
21
+ /** 演示常量(零配置冻结——0.5.0 起本包无 config 面;值 ≡ 0.4.0 缺省) */
22
+ const CFG = {
24
23
  name: '', // '' 哨兵 = 动态别名回退
25
24
  address: '示例商场地址(demo)',
26
25
  latitude: 30.0,
27
26
  longitude: 120.0,
28
- } as const satisfies CfgDefaults;
29
- export const MALL_INFO_CFG_INT_KEYS: readonly string[] = [];
27
+ } as const;
30
28
 
31
29
  /** mallId 形状守卫(防注入类字符;畸形 → undefined——与真实厂商 adapter 同规则) */
32
30
  const MALL_ID_RE = /^[\w-]{1,32}$/;
33
31
 
34
32
  /** mock mall.info adapter 工厂(对齐真实厂商 adapter 工厂形态) */
35
33
  export const mockMallInfoFactory: ServiceAdapterFactory = (input): MallInfoPort => {
36
- const cfg = resolveConfig(input.config, MALL_INFO_CFG_DEFAULTS, MALL_INFO_CFG_INT_KEYS);
34
+ void input; // 零配置开箱(2026-09-20 拆分):config 面随 provider-mocktest 迁出,签名保持 adapter 通用形态
37
35
  return {
38
36
  async getMallInfo(mallId: string): Promise<MallInfo | undefined> {
39
37
  if (!MALL_ID_RE.test(mallId)) return undefined;
40
38
  return {
41
39
  mallId,
42
- name: cfg.name !== '' ? cfg.name : `示例商场(${mallId})`,
43
- address: cfg.address,
44
- latitude: cfg.latitude,
45
- longitude: cfg.longitude,
40
+ name: CFG.name !== '' ? CFG.name : `示例商场(${mallId})`,
41
+ address: CFG.address,
42
+ latitude: CFG.latitude,
43
+ longitude: CFG.longitude,
46
44
  };
47
45
  },
48
46
  };