@tbox.cn/app-module-parking 0.10.1 → 0.10.2

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.
@@ -1534,7 +1534,13 @@ function createParkingActions(ctx) {
1534
1534
  payOrderNoMasked: payOrderId.length > 8 ? `${payOrderId.slice(0, 4)}****${payOrderId.slice(-4)}` : payOrderId,
1535
1535
  ...payOrderFlowId ? { payOrderFlowId } : {},
1536
1536
  status: "PAYING",
1537
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
1537
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1538
+ quoteProjection: {
1539
+ totalCents: quote.totalCents,
1540
+ discountCents: quote.discountCents,
1541
+ revision: quote.revision,
1542
+ feeItems: quote.feeItems
1543
+ }
1538
1544
  });
1539
1545
  return {
1540
1546
  text: `\u6B63\u5728\u62C9\u8D77\u652F\u4ED8\u5B9D\u652F\u4ED8\uFF08\u5E94\u4ED8 ${formatCents(authoritativeAmount)})\u2026`,
@@ -1595,6 +1601,17 @@ function createParkingActions(ctx) {
1595
1601
  );
1596
1602
  const current = settled ?? op;
1597
1603
  if (current.status === "PAID") {
1604
+ if (current.quoteProjection) {
1605
+ return {
1606
+ update: {
1607
+ data: settledPaymentCardData(
1608
+ { ...current, ...current.quoteProjection },
1609
+ { state: "paid", text: "\u5DF2\u5B8C\u6210\u652F\u4ED8\uFF0C\u8BF7\u5728 15 \u5206\u949F\u5185\u79BB\u573A\uFF0C\u8D85\u65F6\u5C06\u91CD\u65B0\u8BA1\u8D39" }
1610
+ )
1611
+ },
1612
+ text: "\u505C\u8F66\u8D39\u652F\u4ED8\u6210\u529F"
1613
+ };
1614
+ }
1598
1615
  return {
1599
1616
  card: paymentResultCard({
1600
1617
  paymentRef,
@@ -1765,7 +1782,7 @@ function createParkingActions(ctx) {
1765
1782
  async execute(input, reqCtx) {
1766
1783
  const { plateNo, vehicleRef } = input ?? {};
1767
1784
  const s = await serviceOf(reqCtx, resolveParkingVehiclePort);
1768
- if (!s || !plateNo) return { text: "\u89E3\u7ED1\u5931\u8D25\uFF1A\u7F3A\u5C11\u8F66\u724C\u6216\u8F66\u8F86\u5F15\u7528" };
1785
+ if (!s || !plateNo && !vehicleRef) return { text: "\u89E3\u7ED1\u5931\u8D25\uFF1A\u7F3A\u5C11\u8F66\u724C\u6216\u8F66\u8F86\u5F15\u7528" };
1769
1786
  const query = await resolveParkingQueryPort(reqCtx, ctx);
1770
1787
  const { bound } = await query.listVehicles(s.q);
1771
1788
  const matched = bound.find(
@@ -5,6 +5,7 @@ import "./parking-BC2TJ5GU.css";
5
5
  import { useEffect, useState } from "react";
6
6
  import { Car, Check, CheckCircle, Clock, CurrencyCircleDollar, ShieldCheck, Sparkle } from "@phosphor-icons/react";
7
7
  import { callCapability, markSelfRendering, sendCardAction } from "@tbox.cn/app-agent-sdk-client";
8
+ import { TBOX_NOTICE_EVENT_NAME } from "@tbox.cn/app-contracts";
8
9
 
9
10
  // src/client/cards/parking-payment/benefit-selection.ts
10
11
  function conflicts(a, b) {
@@ -58,6 +59,15 @@ function ParkingPaymentCard(props) {
58
59
  const [payOpening, setPayOpening] = useState(false);
59
60
  const [optimisticSettlement, setOptimisticSettlement] = useState();
60
61
  const confirmToken = actionTokens?.["parking.confirm-payment"];
62
+ useEffect(() => {
63
+ const onNotice = (e) => {
64
+ const n = e.detail;
65
+ if (n?.surfaceId && n.surfaceId !== cardId) return;
66
+ setSubmitting(false);
67
+ };
68
+ window.addEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
69
+ return () => window.removeEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
70
+ }, [cardId]);
61
71
  const onPayResult = (r) => {
62
72
  const ps = r?.payStatus;
63
73
  if (ps === "success") setOptimisticSettlement({ state: "paid", text: "\u5DF2\u5B8C\u6210\u652F\u4ED8\uFF0C\u8BF7\u572830\u5206\u949F\u5185\u79BB\u573A" });
@@ -625,7 +635,7 @@ var parking_payment_records_default = markSelfRendering3(ParkingPaymentRecordsCa
625
635
  import { Fragment, useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
626
636
  import { Car as Car2, Plus, SealCheck, TrashSimple } from "@phosphor-icons/react";
627
637
  import { markSelfRendering as markSelfRendering4, sendCardAction as sendCardAction4 } from "@tbox.cn/app-agent-sdk-client";
628
- import { TBOX_NOTICE_EVENT_NAME } from "@tbox.cn/app-contracts";
638
+ import { TBOX_NOTICE_EVENT_NAME as TBOX_NOTICE_EVENT_NAME2 } from "@tbox.cn/app-contracts";
629
639
 
630
640
  // src/client/cards/parking-vehicle-management/plate-keyboard.ts
631
641
  var PLATE_PROVINCES = "\u4EAC\u6D25\u6CAA\u6E1D\u5180\u8C6B\u4E91\u8FBD\u9ED1\u6E58\u7696\u9C81\u65B0\u82CF\u6D59\u8D63\u9102\u6842\u7518\u664B\u8499\u9655\u5409\u95FD\u8D35\u7CA4\u9752\u85CF\u5DDD\u5B81\u743C".split("");
@@ -811,8 +821,8 @@ function ParkingVehicleManagementCard(props) {
811
821
  setBindingAction(null);
812
822
  setUnbindingRefs(/* @__PURE__ */ new Set());
813
823
  };
814
- window.addEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
815
- return () => window.removeEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
824
+ window.addEventListener(TBOX_NOTICE_EVENT_NAME2, onNotice);
825
+ return () => window.removeEventListener(TBOX_NOTICE_EVENT_NAME2, onNotice);
816
826
  }, [cardId]);
817
827
  const isEmpty = data.bound.length === 0;
818
828
  useEffect3(() => {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  cards,
3
3
  clientModule
4
- } from "../chunk-3Y7H35W3.js";
4
+ } from "../chunk-SI5NHAIK.js";
5
5
  export {
6
6
  clientModule,
7
7
  cards as parkingClientCards
package/dist/index.js CHANGED
@@ -6,11 +6,11 @@ import {
6
6
  resolveParkingQueryPort,
7
7
  resolveParkingVehiclePort,
8
8
  serverModule
9
- } from "./chunk-J3M7F6YT.js";
9
+ } from "./chunk-AC5FKXIW.js";
10
10
  import {
11
11
  cards,
12
12
  clientModule
13
- } from "./chunk-3Y7H35W3.js";
13
+ } from "./chunk-SI5NHAIK.js";
14
14
  export {
15
15
  InMemoryParkingService,
16
16
  clientModule,
@@ -6,7 +6,7 @@ import {
6
6
  resolveParkingQueryPort,
7
7
  resolveParkingVehiclePort,
8
8
  serverModule
9
- } from "../chunk-J3M7F6YT.js";
9
+ } from "../chunk-AC5FKXIW.js";
10
10
  export {
11
11
  InMemoryParkingService,
12
12
  inMemoryParking,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-parking",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "type": "module",
5
5
  "description": "商圈停车模块:计费支付、车辆寻车、缴费记录与开票(codegen 源)。",
6
6
  "exports": {
@@ -18,10 +18,10 @@
18
18
  }
19
19
  },
20
20
  "dependencies": {
21
- "@tbox.cn/app-contracts": "0.12.0",
22
- "@tbox.cn/app-contracts-mall": "0.12.0",
23
- "@tbox.cn/app-agent-sdk-client": "0.1.0",
24
- "@tbox.cn/app-agent-sdk-server": "0.1.0"
21
+ "@tbox.cn/app-contracts": "0.12.1",
22
+ "@tbox.cn/app-contracts-mall": "0.12.2",
23
+ "@tbox.cn/app-agent-sdk-client": "0.1.2",
24
+ "@tbox.cn/app-agent-sdk-server": "0.1.2"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "3.25.76",
@@ -7,6 +7,7 @@
7
7
  import { useEffect, useState } from 'react';
8
8
  import { Car, Check, CheckCircle, Clock, CurrencyCircleDollar, ShieldCheck, Sparkle } from '@phosphor-icons/react';
9
9
  import { callCapability, markSelfRendering, sendCardAction } from '@tbox.cn/app-agent-sdk-client';
10
+ import { TBOX_NOTICE_EVENT_NAME } from '@tbox.cn/app-contracts';
10
11
  import type { ParkingPaymentCardData } from '@tbox.cn/app-contracts-mall';
11
12
 
12
13
  /** 重算超时兜底(ms):避免重算失败时勾选被永久锁死 */
@@ -45,6 +46,19 @@ export function ParkingPaymentCard(props: {
45
46
  >();
46
47
  const confirmToken = actionTokens?.['parking.confirm-payment'];
47
48
 
49
+ // 动作失败复位:服务端 confirm-payment 失败时发 tbox:notice(非 card-update)——
50
+ // 否则 submitting 无复位路径(对齐车辆管理卡同款防守),按钮永久卡"支付处理中…"。
51
+ // payOpening 不在此复位:宿主效果链自带 .finally 兜底
52
+ useEffect(() => {
53
+ const onNotice = (e: Event) => {
54
+ const n = (e as CustomEvent).detail as { surfaceId?: string } | undefined;
55
+ if (n?.surfaceId && n.surfaceId !== cardId) return;
56
+ setSubmitting(false);
57
+ };
58
+ window.addEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
59
+ return () => window.removeEventListener(TBOX_NOTICE_EVENT_NAME, onNotice);
60
+ }, [cardId]);
61
+
48
62
  // 壳侧 openParkingPay/openParkingUnpaidOrder 回执 data 形态(厂商协议)
49
63
  type PayResult = {
50
64
  payStatus?: 'success' | 'fail' | 'unpaid' | 'cancelled' | 'none';
@@ -366,6 +366,8 @@ export function createParkingActions(
366
366
  }
367
367
 
368
368
  // PAYING 持久化(悬挂收口锚点,V2)
369
+ // quoteProjection:报价投影随建单快照(对齐 entryAt 同模式——PAID 原卡翻转
370
+ // 要重灌终态卡数据,而 W4 报价缓存仅 UNPAID 态可见、届时不可达)
369
371
  await persistPaymentOperation(state, {
370
372
  paymentRef,
371
373
  providerPaymentRef,
@@ -382,6 +384,12 @@ export function createParkingActions(
382
384
  ...(payOrderFlowId ? { payOrderFlowId } : {}),
383
385
  status: 'PAYING',
384
386
  createdAt: new Date().toISOString(),
387
+ quoteProjection: {
388
+ totalCents: quote.totalCents,
389
+ discountCents: quote.discountCents,
390
+ revision: quote.revision,
391
+ feeItems: quote.feeItems,
392
+ },
385
393
  });
386
394
 
387
395
  // step2:payment effect(dispatcher 补签 → client tradePay,R1 orderInfo 内联)
@@ -467,6 +475,20 @@ export function createParkingActions(
467
475
  const current = settled ?? op;
468
476
 
469
477
  if (current.status === 'PAID') {
478
+ // PAID 原卡翻转(host-effect-card-anchor D2 出/刷二分):经 dispatcher 签名锚定
479
+ // 原地回写发起报价卡——成功回执新卡冗余(历史凭证由缴费记录卡兜底)。
480
+ // 投影缺失(存量 PAYING 单、旧版本发起)降级出新回执卡,零回归。
481
+ if (current.quoteProjection) {
482
+ return {
483
+ update: {
484
+ data: settledPaymentCardData(
485
+ { ...current, ...current.quoteProjection },
486
+ { state: 'paid', text: '已完成支付,请在 15 分钟内离场,超时将重新计费' },
487
+ ),
488
+ },
489
+ text: '停车费支付成功',
490
+ };
491
+ }
470
492
  return {
471
493
  card: paymentResultCard({
472
494
  paymentRef,
@@ -661,7 +683,8 @@ export function createParkingActions(
661
683
  vehicleRef?: string;
662
684
  };
663
685
  const s = await serviceOf(reqCtx, resolveParkingVehiclePort);
664
- if (!s || !plateNo) return { text: '解绑失败:缺少车牌或车辆引用' };
686
+ // 与下方 matched 双路匹配同构:车牌或引用任一在场即放行(卡片按钮路径只传 vehicleRef)
687
+ if (!s || (!plateNo && !vehicleRef)) return { text: '解绑失败:缺少车牌或车辆引用' };
665
688
  // 列表匹配与刷新走 query 槽;解绑写走 vehicle 槽(双槽动作,方法分属)
666
689
  const query = await resolveParkingQueryPort(reqCtx as RequestContext, ctx);
667
690
  const { bound } = await query.listVehicles(s.q);
@@ -218,6 +218,32 @@ describe('parking × dispatcher 集成回归锁(reqCtx 注入语义)', () =>
218
218
  ).toHaveLength(0);
219
219
  });
220
220
 
221
+ it('解绑客户端真实路径:formData 只传 vehicleRef(卡片按钮 vehicleAction 契约)', async () => {
222
+ const { sessions, grants, dispatcher, svc } = buildHarness();
223
+ const session = sessions.bootstrap(makeReqCtx());
224
+ const bound = await svc.api.bindVehicle({} as never, '苏E11111');
225
+ const emitted: unknown[] = [];
226
+ const result = await dispatcher.dispatch({
227
+ token: await grants.issue({
228
+ moduleId: 'parking',
229
+ actionId: 'parking.unbind-vehicle',
230
+ cardType: 'parking-vehicle-management',
231
+ sessionId: session.sessionId,
232
+ scope: { miniAppId: 'app', mallId: 'mall-1' },
233
+ singleUse: true,
234
+ cardId: 'card_v1',
235
+ }),
236
+ actionId: 'parking.unbind-vehicle',
237
+ sessionId: session.sessionId,
238
+ surfaceId: 'card_v1',
239
+ ctx: makeReqCtx(),
240
+ formData: { vehicleRef: bound.vehicleRef },
241
+ emit: (e) => emitted.push(e),
242
+ });
243
+ expect(result.text).toBe('解绑成功');
244
+ expect(svc.bound).toHaveLength(0);
245
+ });
246
+
221
247
  it('入参非法 → INPUT_INVALID 且令牌可重试(统一护栏在模块链路生效)', async () => {
222
248
  const { sessions, grants, dispatcher } = buildHarness();
223
249
  const session = sessions.bootstrap(makeReqCtx());
@@ -418,3 +418,90 @@ describe('P1:confirm-payment 签名空串防御', () => {
418
418
  expect((await loadPaymentOperation(state, paymentRef!))?.quoteRef).toBe('q_2');
419
419
  });
420
420
  });
421
+
422
+ describe('D2/D3:PAID 原卡翻转(host-effect-card-anchor)', () => {
423
+ /** 三步链 fake 服务:建单 → 签名 → 上报后 reconcile 收口 */
424
+ const makeThreeStepService = (
425
+ reconcileResult: 'PAID' | 'CANCELLED' | 'PAYING',
426
+ ): ParkingService &
427
+ Record<'uploadResult' | 'reconcile', ReturnType<typeof vi.fn>> =>
428
+ ({
429
+ createOrder: async () => ({ payOrderId: 'PO1234567890', paymentRef: 'p_3step' }),
430
+ getOrderInfo: async () => ({ channel: '50', payableFeeCents: 1425 }),
431
+ getPaymentSign: async () => ({ orderInfo: 'sign_3step' }),
432
+ uploadResult: vi.fn(async () => undefined),
433
+ reconcile: vi.fn(async () => reconcileResult),
434
+ }) as never;
435
+
436
+ const makeReqCtx = () =>
437
+ ({
438
+ identity: { userId: 'u_1', source: 'local' },
439
+ attributes: { mall: { miniAppId: 'app', mallId: 'mall-1' } },
440
+ }) as never;
441
+
442
+ const setupConfirm = async (reconcileResult: 'PAID' | 'CANCELLED' | 'PAYING') => {
443
+ const state = createInMemoryStateStore();
444
+ mockAllSlots(makeThreeStepService(reconcileResult));
445
+ await cacheQuote(state, makeQuote(), owner);
446
+ const actions = createParkingActions({ state } as never);
447
+ const confirmed = await actions.confirmPayment.execute!(
448
+ { quoteRef: 'q_1', revision: '1' },
449
+ makeReqCtx(),
450
+ );
451
+ const paymentRef = (confirmed.effects?.[0] as { paymentRef?: string } | undefined)!
452
+ .paymentRef!;
453
+ return { state, actions, confirmed, paymentRef };
454
+ };
455
+
456
+ it('T5 全链路:confirm 快照投影 → PAID → update 原卡翻转,出新卡为零', async () => {
457
+ const { state, actions, confirmed, paymentRef } = await setupConfirm('PAID');
458
+ // step1 断言:quoteProjection 随建单快照落库(对齐 entryAt 同模式)
459
+ const op = await loadPaymentOperation(state, paymentRef);
460
+ expect(op?.quoteProjection).toEqual({
461
+ totalCents: 1500,
462
+ discountCents: 75,
463
+ revision: 1,
464
+ feeItems: [{ name: '停车费', amountCents: 1500 }],
465
+ });
466
+ // confirm 既出 update(paying 态原卡)又出 effect——翻转语义由 step3 完成
467
+ expect((confirmed.update?.data as { settlement?: { state?: string } }).settlement)
468
+ .toMatchObject({ state: 'paying' });
469
+ // step3:宿主回传 success → reconcile PAID → 原卡翻转 paid(不出新卡)
470
+ const reported = await actions.reportPaymentResult.execute!(
471
+ { status: 'success', paymentRef },
472
+ makeReqCtx(),
473
+ );
474
+ expect(reported.card).toBeUndefined();
475
+ const data = reported.update?.data as Record<string, unknown> & {
476
+ settlement: { state: string; text: string };
477
+ };
478
+ expect(data.settlement.state).toBe('paid');
479
+ expect(data.settlement.text).toContain('已完成支付');
480
+ expect(data.quoteRef).toBe('q_1');
481
+ expect(data.plateNo).toBe('浙A12345');
482
+ expect(data.totalText).toBe('15.00 元');
483
+ // 服务端 discountText 原样正值(负号归一是客户端 formatDiscountText 的展示职责)
484
+ expect(data.discountText).toBe('0.75 元');
485
+ expect(data.payableText).toBe('14.25 元');
486
+ expect(data.feeItems).toEqual([{ name: '停车费', amountText: '15.00 元' }]);
487
+ expect(data.selectableBenefits).toEqual([]);
488
+ expect(data.revision).toBe(1);
489
+ expect(reported.text).toBe('停车费支付成功');
490
+ });
491
+
492
+ it('T6 降级链:无投影 op(存量 PAYING 单)→ PAID 仍出新回执卡(零回归)', async () => {
493
+ // 直接持久化旧形态 op(无 quoteProjection),绕过 confirm 建单
494
+ const state = createInMemoryStateStore();
495
+ mockAllSlots(makeThreeStepService('PAID'));
496
+ await persistPaymentOperation(state, makeOp());
497
+ const actions = createParkingActions({ state } as never);
498
+ const reported = await actions.reportPaymentResult.execute!(
499
+ { status: 'success', paymentRef: 'p_1' },
500
+ makeReqCtx(),
501
+ );
502
+ expect(reported.update).toBeUndefined();
503
+ expect(reported.card?.cardType).toBe('parking-payment-result');
504
+ expect((reported.card?.data as { status?: string }).status).toBe('PAID');
505
+ expect(reported.text).toBe('停车费支付成功');
506
+ });
507
+ });