@tbox.cn/app-module-mall-core 0.3.1 → 0.3.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.
- package/dist/{chunk-HMQKNJEO.js → chunk-FATH6I75.js} +15 -4
- package/dist/client/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/client/home-runtime.ts +13 -0
- package/src/client/home-slot.tsx +6 -2
- package/src/client/member-gate.ts +23 -6
- package/tests/home-runtime.test.ts +23 -0
- package/tests/member-gate.test.ts +41 -1
|
@@ -128,6 +128,9 @@ async function fetchLinkedPanelState(token, mallId, fetcher = fetch, signal) {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
var MALL_CORE_API = "/api/m/mall-core";
|
|
131
|
+
function pickMallId(helloMallId, urlMallId) {
|
|
132
|
+
return helloMallId ?? urlMallId;
|
|
133
|
+
}
|
|
131
134
|
async function fetchLinkedOrderState(token, fetcher = fetch, signal) {
|
|
132
135
|
if (!token) return { status: "unauthenticated" };
|
|
133
136
|
try {
|
|
@@ -1210,16 +1213,24 @@ function createMemberGate(deps) {
|
|
|
1210
1213
|
return;
|
|
1211
1214
|
}
|
|
1212
1215
|
} else {
|
|
1216
|
+
const judgeMallId = deps.readMallId();
|
|
1213
1217
|
let panel;
|
|
1214
1218
|
try {
|
|
1215
|
-
panel = await deps.loadPanel(
|
|
1219
|
+
panel = await deps.loadPanel(judgeMallId);
|
|
1216
1220
|
} catch {
|
|
1217
1221
|
if (flightSeq !== myFlight) return;
|
|
1222
|
+
log(`judge panel-throw mallId=${judgeMallId ?? "none"}`);
|
|
1218
1223
|
setState({ phase: "failed", message: GATE_PANEL_FAILED });
|
|
1219
1224
|
return;
|
|
1220
1225
|
}
|
|
1221
1226
|
if (flightSeq !== myFlight) return;
|
|
1222
|
-
|
|
1227
|
+
const panelStatus = panel.member.status;
|
|
1228
|
+
log(`judge panel status=${panelStatus} mallId=${judgeMallId ?? "none"}`);
|
|
1229
|
+
if (panelStatus === "unavailable" || panelStatus === "error" || panelStatus === "unknown" || panelStatus === "unauthenticated") {
|
|
1230
|
+
setState({ phase: "failed", message: GATE_PANEL_FAILED });
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
upgraded = identityOk && panelStatus === "active";
|
|
1223
1234
|
}
|
|
1224
1235
|
log(`judge ${upgraded ? "active" : "not-enrolled"}`);
|
|
1225
1236
|
if (upgraded) {
|
|
@@ -1370,7 +1381,7 @@ function HomeSlotContent({ onSend, mallName }) {
|
|
|
1370
1381
|
const retryBootstrap = useChatStore((s) => s.retryBootstrap);
|
|
1371
1382
|
const isGenerating = useChatStore((s) => s.isGenerating);
|
|
1372
1383
|
const helloMallId = useChatStore((s) => s.helloAck?.mallScope?.mallId);
|
|
1373
|
-
const mallId = helloMallId
|
|
1384
|
+
const mallId = pickMallId(helloMallId, readMallIdFromUrl());
|
|
1374
1385
|
const [linkedOrder, setLinkedOrder] = useState3({ status: "loading" });
|
|
1375
1386
|
const [linkedOrderReloadEpoch, setLinkedOrderReloadEpoch] = useState3(0);
|
|
1376
1387
|
const [member, setMember] = useState3({ status: "loading" });
|
|
@@ -1408,7 +1419,7 @@ function HomeSlotContent({ onSend, mallName }) {
|
|
|
1408
1419
|
}
|
|
1409
1420
|
return null;
|
|
1410
1421
|
},
|
|
1411
|
-
readMallId: () => readMallIdFromUrl(),
|
|
1422
|
+
readMallId: () => pickMallId(store.getState().helloAck?.mallScope?.mallId, readMallIdFromUrl()),
|
|
1412
1423
|
refreshPanel: () => setLinkedPanelReloadEpoch((epoch) => epoch + 1),
|
|
1413
1424
|
log: (message) => {
|
|
1414
1425
|
gateLogger.info(message);
|
package/dist/client/index.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -271,6 +271,19 @@ export async function fetchParkingState(
|
|
|
271
271
|
/** 商圈基础首页面 API 命名空间(server 端 ctx.routes.register('mall-core') 挂载位——改名单点) */
|
|
272
272
|
export const MALL_CORE_API = '/api/m/mall-core';
|
|
273
273
|
|
|
274
|
+
/**
|
|
275
|
+
* mallId 单一读源(面板与门禁 judge 共用;hello 优先单测锁序):
|
|
276
|
+
* HELLO_ACK mallScope 是服务端确认的会话 scope(URL 无 mallId 的部署经服务端
|
|
277
|
+
* defaultContext 下发),URL 是握手前兜底——两处消费必须同源同序,否则 judge 判定
|
|
278
|
+
* 的 mall 与面板展示的 mall 可能分叉。
|
|
279
|
+
*/
|
|
280
|
+
export function pickMallId(
|
|
281
|
+
helloMallId: string | null | undefined,
|
|
282
|
+
urlMallId: string | null,
|
|
283
|
+
): string | null {
|
|
284
|
+
return helloMallId ?? urlMallId;
|
|
285
|
+
}
|
|
286
|
+
|
|
274
287
|
/** 将首页 HTTP 返回收敛为联单加载态,便于对鉴权、空活动与异常分别回归。 */
|
|
275
288
|
export async function fetchLinkedOrderState(
|
|
276
289
|
token: string | null | undefined,
|
package/src/client/home-slot.tsx
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
loadHomeConfig,
|
|
21
21
|
loadLinkedPanelState,
|
|
22
22
|
loadLinkedOrderState,
|
|
23
|
+
pickMallId,
|
|
23
24
|
} from './home-runtime';
|
|
24
25
|
import type { HomeConfig, LinkedOrderLoadState, MemberLoadState, ParkingLoadState } from './home-runtime';
|
|
25
26
|
import './home-slot.less';
|
|
@@ -47,7 +48,9 @@ function HomeSlotContent({ onSend, mallName }: HomeSlotRenderProps) {
|
|
|
47
48
|
// createConversation + WS HELLO 握手;URL 缺席回退 HELLO_ACK(原逻辑不变)。HELLO 后到且值不同时,
|
|
48
49
|
// 面板 effect 依赖 mallId 自动重载(以 HELLO 为准,旧请求经 AbortController 中止)。
|
|
49
50
|
const helloMallId = useChatStore((s) => s.helloAck?.mallScope?.mallId);
|
|
50
|
-
|
|
51
|
+
// 与 gate judge readMallId 同源同序(pickMallId 单源):HELLO 到达后以其为准(服务端确认 scope),
|
|
52
|
+
// 握手前 helloAck 缺席 → URL 兜底,挂载即可发、免等握手
|
|
53
|
+
const mallId = pickMallId(helloMallId, readMallIdFromUrl());
|
|
51
54
|
|
|
52
55
|
const [linkedOrder, setLinkedOrder] = useState<LinkedOrderLoadState>({ status: 'loading' });
|
|
53
56
|
const [linkedOrderReloadEpoch, setLinkedOrderReloadEpoch] = useState(0);
|
|
@@ -92,7 +95,8 @@ function HomeSlotContent({ onSend, mallName }: HomeSlotRenderProps) {
|
|
|
92
95
|
}
|
|
93
96
|
return null;
|
|
94
97
|
},
|
|
95
|
-
readMallId: () =>
|
|
98
|
+
readMallId: () =>
|
|
99
|
+
pickMallId(store.getState().helloAck?.mallScope?.mallId, readMallIdFromUrl()),
|
|
96
100
|
refreshPanel: () => setLinkedPanelReloadEpoch((epoch) => epoch + 1),
|
|
97
101
|
log: (message) => {
|
|
98
102
|
gateLogger.info(message);
|
|
@@ -60,7 +60,8 @@ export interface MemberGateDeps {
|
|
|
60
60
|
toast(content: string): void;
|
|
61
61
|
isGenerating(): boolean;
|
|
62
62
|
lastUserMessage(): { id: string; content: string } | null;
|
|
63
|
-
/** mallId
|
|
63
|
+
/** mallId 读源(装配方注入;与首页面板同源同序 pickMallId:HELLO_ACK 优先 + URL 兜底)。
|
|
64
|
+
* 消费方 = 入会轴 judge(retryBootstrap 之后,HELLO_ACK 已在 store——活读安全) */
|
|
64
65
|
readMallId(): string | null;
|
|
65
66
|
/** 升级成功后刷新首页面板(bumpEpoch) */
|
|
66
67
|
refreshPanel(): void;
|
|
@@ -123,7 +124,8 @@ export function createMemberGate(deps: MemberGateDeps): MemberGate {
|
|
|
123
124
|
let pendingReplay: PendingReplay | null = null;
|
|
124
125
|
/** 飞行序号:dismiss 不中止升级,新一轮 confirm/retry 递增后旧流程让位 */
|
|
125
126
|
let flightSeq = 0;
|
|
126
|
-
/** 排障五锚:open(source)/receipt(loginStatus)/relogin(ok|fail)/judge(active|not-enrolled)/replay(sent|skipped:reason)
|
|
127
|
+
/** 排障五锚:open(source)/receipt(loginStatus)/relogin(ok|fail)/judge(active|not-enrolled)/replay(sent|skipped:reason);
|
|
128
|
+
* judge 锚前另附明细行 judge panel status=<x> mallId=<y>(面板真值与判定读源,排障先看它) */
|
|
127
129
|
const log = (message: string): void => {
|
|
128
130
|
deps.log?.(message);
|
|
129
131
|
};
|
|
@@ -201,18 +203,33 @@ export function createMemberGate(deps: MemberGateDeps): MemberGate {
|
|
|
201
203
|
return;
|
|
202
204
|
}
|
|
203
205
|
} else {
|
|
204
|
-
// 入会轴:非匿名 ∧ 面板 member.active
|
|
205
|
-
//
|
|
206
|
+
// 入会轴:非匿名 ∧ 面板 member.active。面板状态全谱分类(MemberLoadState):
|
|
207
|
+
// active → settle;not_enrolled/closed → 确认未入会(not-enrolled 态,重开完整 gate);
|
|
208
|
+
// unknown/unavailable/error/unauthenticated → 查询失败 ≠ 确认未入会 → failed
|
|
209
|
+
// (GATE_PANEL_FAILED,retry 仅重跑冷登+判定)——不再把同步失败误报成「尚未完成入会」。
|
|
210
|
+
const judgeMallId = deps.readMallId();
|
|
206
211
|
let panel: { member: { status: string } };
|
|
207
212
|
try {
|
|
208
|
-
panel = await deps.loadPanel(
|
|
213
|
+
panel = await deps.loadPanel(judgeMallId);
|
|
209
214
|
} catch {
|
|
210
215
|
if (flightSeq !== myFlight) return;
|
|
216
|
+
log(`judge panel-throw mallId=${judgeMallId ?? 'none'}`);
|
|
211
217
|
setState({ phase: 'failed', message: GATE_PANEL_FAILED });
|
|
212
218
|
return;
|
|
213
219
|
}
|
|
214
220
|
if (flightSeq !== myFlight) return;
|
|
215
|
-
|
|
221
|
+
const panelStatus = panel.member.status;
|
|
222
|
+
log(`judge panel status=${panelStatus} mallId=${judgeMallId ?? 'none'}`);
|
|
223
|
+
if (
|
|
224
|
+
panelStatus === 'unavailable'
|
|
225
|
+
|| panelStatus === 'error'
|
|
226
|
+
|| panelStatus === 'unknown'
|
|
227
|
+
|| panelStatus === 'unauthenticated'
|
|
228
|
+
) {
|
|
229
|
+
setState({ phase: 'failed', message: GATE_PANEL_FAILED });
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
upgraded = identityOk && panelStatus === 'active';
|
|
216
233
|
}
|
|
217
234
|
log(`judge ${upgraded ? 'active' : 'not-enrolled'}`);
|
|
218
235
|
if (upgraded) {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
parseBumpInDetailCard,
|
|
14
14
|
parseMemberState,
|
|
15
15
|
parseParkingState,
|
|
16
|
+
pickMallId,
|
|
16
17
|
shouldAutoScrollConversation,
|
|
17
18
|
shouldReleaseHistoryAnchorReserve,
|
|
18
19
|
shouldShowHistoryEntry,
|
|
@@ -20,6 +21,28 @@ import {
|
|
|
20
21
|
shouldShowScrollControl,
|
|
21
22
|
} from '../src/client/home-runtime';
|
|
22
23
|
|
|
24
|
+
describe('pickMallId(面板与门禁 judge 单一读源)', () => {
|
|
25
|
+
it('hello 优先锁序:服务端确认 scope 恒赢 URL 兜底', () => {
|
|
26
|
+
expect(pickMallId('mall-hello', 'mall-url')).toBe('mall-hello');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('URL 无 mallId 的部署(mallId 经 HELLO defaultContext 下发)→ 回退 hello', () => {
|
|
30
|
+
expect(pickMallId('mall-hello', null)).toBe('mall-hello');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('握手前(helloAck 缺席)→ URL 兜底', () => {
|
|
34
|
+
expect(pickMallId(undefined, 'mall-url')).toBe('mall-url');
|
|
35
|
+
expect(pickMallId(null, 'mall-url')).toBe('mall-url');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('双缺 → null(面板保持 loading,不误投影服务不可用)', () => {
|
|
39
|
+
expect(pickMallId(null, null)).toBeNull();
|
|
40
|
+
expect(pickMallId(undefined, null)).toBeNull();
|
|
41
|
+
// nullish 语义(?? 与原面板行为逐字一致):仅 null/undefined 回退;URL 读源恒不产空串
|
|
42
|
+
expect(pickMallId(undefined, '')).toBe('');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
23
46
|
describe('member panel state', () => {
|
|
24
47
|
it('严格区分登录与会员状态,并只接受真实非负积分', () => {
|
|
25
48
|
expect(parseMemberState({ authState: 'unauthenticated', state: 'unknown' }))
|
|
@@ -86,11 +86,12 @@ describe('createMemberGate(门禁状态机)', () => {
|
|
|
86
86
|
expect(h.calls.sendMessage).toHaveBeenCalledWith('查询我的会员积分');
|
|
87
87
|
expect(h.calls.hideCard).toHaveBeenCalledWith('card-1');
|
|
88
88
|
expect(h.gate.getState()).toMatchObject({ phase: 'idle', sheetVisible: false });
|
|
89
|
-
// 排障五锚:open → receipt → relogin → judge → replay(一条 grep
|
|
89
|
+
// 排障五锚:open → receipt → relogin → judge → replay(一条 grep 定位全链;judge 附面板明细行)
|
|
90
90
|
expect(h.calls.log.mock.calls.flat()).toEqual([
|
|
91
91
|
'open source=card',
|
|
92
92
|
'receipt loginStatus=success',
|
|
93
93
|
'relogin ok',
|
|
94
|
+
'judge panel status=active mallId=mall-001',
|
|
94
95
|
'judge active',
|
|
95
96
|
'replay sent',
|
|
96
97
|
]);
|
|
@@ -381,4 +382,43 @@ describe('judge 分轴(SPEC-7:login 卡登录轴 / enroll 卡入会轴)',
|
|
|
381
382
|
expect(h.gate.getState()).toMatchObject({ phase: 'failed', message: '会员状态同步失败,请重试' });
|
|
382
383
|
expect(h.calls.sendMessage).not.toHaveBeenCalled();
|
|
383
384
|
});
|
|
385
|
+
|
|
386
|
+
it.each(['unknown', 'unavailable', 'error', 'unauthenticated'] as const)(
|
|
387
|
+
'enroll 卡:panel status=%s(查询失败非确认未入会)→ failed,不误报未入会',
|
|
388
|
+
async (status) => {
|
|
389
|
+
const h = createHarness();
|
|
390
|
+
h.calls.getLoginState.mockResolvedValue({ loginStatus: 'success' });
|
|
391
|
+
h.calls.loadPanel.mockResolvedValue({ member: { status } });
|
|
392
|
+
h.gate.trigger(gateCard('member-enrollment-cta'), undefined);
|
|
393
|
+
h.gate.confirm();
|
|
394
|
+
await flush();
|
|
395
|
+
expect(h.gate.getState()).toMatchObject({ phase: 'failed', message: '会员状态同步失败,请重试' });
|
|
396
|
+
expect(h.calls.refreshPanel).not.toHaveBeenCalled();
|
|
397
|
+
expect(h.calls.sendMessage).not.toHaveBeenCalled();
|
|
398
|
+
expect(h.calls.log.mock.calls.flat()).toContain(`judge panel status=${status} mallId=mall-001`);
|
|
399
|
+
},
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
it('enroll 卡:panel closed(厂商确认态)→ not-enrolled 而非 failed', async () => {
|
|
403
|
+
const h = createHarness();
|
|
404
|
+
h.calls.getLoginState.mockResolvedValue({ loginStatus: 'success' });
|
|
405
|
+
h.calls.loadPanel.mockResolvedValue({ member: { status: 'closed' } });
|
|
406
|
+
h.gate.trigger(gateCard('member-enrollment-cta'), undefined);
|
|
407
|
+
h.gate.confirm();
|
|
408
|
+
await flush();
|
|
409
|
+
expect(h.gate.getState().phase).toBe('not-enrolled');
|
|
410
|
+
expect(h.calls.log.mock.calls.flat()).toContain('judge not-enrolled');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('enroll 卡:judge mallId 注入透传(null → loadPanel(null),明细行归 none)', async () => {
|
|
414
|
+
const h = createHarness({ readMallId: () => null });
|
|
415
|
+
h.calls.getLoginState.mockResolvedValue({ loginStatus: 'success' });
|
|
416
|
+
h.calls.loadPanel.mockResolvedValue({ member: { status: 'active' } });
|
|
417
|
+
h.gate.trigger(gateCard('member-enrollment-cta'), undefined);
|
|
418
|
+
h.gate.confirm();
|
|
419
|
+
await flush();
|
|
420
|
+
expect(h.calls.loadPanel).toHaveBeenCalledWith(null);
|
|
421
|
+
expect(h.gate.getState().phase).toBe('idle');
|
|
422
|
+
expect(h.calls.log.mock.calls.flat()).toContain('judge panel status=active mallId=none');
|
|
423
|
+
});
|
|
384
424
|
});
|