@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.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.
Files changed (89) hide show
  1. package/AGENTS.md +16 -0
  2. package/README.md +96 -0
  3. package/dist/chunk-AYQZO2FV.js +1496 -0
  4. package/dist/chunk-QDTU2FRN.js +1682 -0
  5. package/dist/client/index.d.ts +3 -3
  6. package/dist/client/index.js +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +2 -8
  9. package/dist/server/index.d.ts +2512 -608
  10. package/dist/server/index.js +1 -7
  11. package/dist/shop-guide-header-art-pea-v2-OME4MKBW.jpg +0 -0
  12. package/dist/shopping-guide-OQ2SSHXL.css +2593 -0
  13. package/package.json +25 -16
  14. package/skills/shopping-guide/SKILL.md +127 -24
  15. package/src/client/assets/shop-guide-header-art-pea-v2.jpg +0 -0
  16. package/src/client/assets/shop-guide-header-art.png +0 -0
  17. package/src/client/assets.d.ts +10 -0
  18. package/src/client/cards/category-list/index.tsx +113 -0
  19. package/src/client/cards/human-guide-list/index.tsx +72 -0
  20. package/src/client/cards/index.ts +14 -0
  21. package/src/client/cards/location-handoff/index.tsx +52 -0
  22. package/src/client/cards/mall-directory/index.tsx +77 -0
  23. package/src/client/cards/nearby-mall-list/index.tsx +40 -0
  24. package/src/client/cards/product-comparison/index.tsx +100 -0
  25. package/src/client/cards/product-detail/index.tsx +97 -0
  26. package/src/client/cards/product-list/index.tsx +223 -0
  27. package/src/client/cards/recommend-merchants/index.tsx +147 -0
  28. package/src/client/cards/shop-detail/index.tsx +133 -0
  29. package/src/client/cards/shop-list/index.tsx +216 -0
  30. package/src/client/cards/view.ts +147 -0
  31. package/src/client/categories.ts +38 -0
  32. package/src/client/components/ImageWithFallback.tsx +34 -0
  33. package/src/client/components/MerchantRow.tsx +78 -0
  34. package/src/client/components/ShopDetailSheet.tsx +383 -0
  35. package/src/client/components/ShopGuideHeader.tsx +24 -0
  36. package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
  37. package/src/client/components/ShopListSheet.tsx +293 -0
  38. package/src/client/index.ts +8 -6
  39. package/src/client/styles/shopping-guide.css +2593 -0
  40. package/src/client/types/css.d.ts +2 -0
  41. package/src/server/cards/category-list/meta.ts +0 -2
  42. package/src/server/cards/human-guide-list/meta.ts +0 -2
  43. package/src/server/cards/index.ts +10 -10
  44. package/src/server/cards/location-handoff/meta.ts +0 -2
  45. package/src/server/cards/mall-directory/meta.ts +0 -2
  46. package/src/server/cards/nearby-mall-list/meta.ts +1 -3
  47. package/src/server/cards/product-comparison/meta.ts +0 -2
  48. package/src/server/cards/product-detail/meta.ts +0 -2
  49. package/src/server/cards/product-list/meta.ts +0 -2
  50. package/src/server/cards/recommend-merchants/meta.ts +37 -0
  51. package/src/server/cards/recommend-merchants/samples.ts +189 -0
  52. package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
  53. package/src/server/cards/shop-detail/samples.ts +72 -0
  54. package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
  55. package/src/server/cards/shop-list/samples.ts +154 -0
  56. package/src/server/domain/value-objects.ts +1 -2
  57. package/src/server/handler.ts +63 -0
  58. package/src/server/index.ts +161 -101
  59. package/src/server/ports/index.ts +120 -91
  60. package/src/server/ports/local-adapters.ts +5 -55
  61. package/src/server/projections/index.ts +159 -41
  62. package/src/server/tools/index.ts +590 -315
  63. package/tbox.module.json +137 -0
  64. package/tests/cards-render.test.tsx +830 -0
  65. package/tests/floor-pretool.test.ts +275 -0
  66. package/tests/handler.test.ts +259 -0
  67. package/tests/merchant-list-limit.test.ts +53 -0
  68. package/tests/ports-resolve.test.ts +112 -0
  69. package/tests/samples.test.ts +71 -0
  70. package/tests/shopping-guide.test.ts +402 -234
  71. package/tests/skill.test.ts +86 -0
  72. package/tests/view.test.ts +42 -0
  73. package/tsup.config.ts +9 -1
  74. package/dist/chunk-AGBLC6XI.js +0 -1294
  75. package/dist/chunk-U4WDS5PQ.js +0 -173
  76. package/skills/shopping-guide/references/comparison-format.md +0 -5
  77. package/skills/shopping-guide/references/faq-answers.md +0 -5
  78. package/skills/shopping-guide/references/floor-directory.md +0 -4
  79. package/skills/shopping-guide/references/intent-patterns.md +0 -5
  80. package/skills/shopping-guide/references/location-format.md +0 -5
  81. package/skills/shopping-guide/references/policy-lookup.md +0 -5
  82. package/skills/shopping-guide/references/product-search-tips.md +0 -6
  83. package/skills/shopping-guide/references/recommendation-style.md +0 -5
  84. package/src/client/cards/index.tsx +0 -267
  85. package/src/server/cards/customer-service-faq/meta.ts +0 -18
  86. package/src/server/integrations/joycity/adapter.ts +0 -226
  87. package/src/server/integrations/joycity/auth-strategy.ts +0 -38
  88. package/src/server/integrations/joycity/gateway.ts +0 -128
  89. package/tbox.component.json +0 -48
@@ -0,0 +1,112 @@
1
+ /**
2
+ * shopping-guide ports 017 槽位原子化回归锁:四槽独立解析 + navigation 恒本地。
3
+ * - 各槽命中 → 对应 Port 产物(service 参数 = 槽 id);
4
+ * - PROVIDER_NOT_IMPLEMENTED / 预期缺席三码 → 本地空数据兜底(增强面语义——
5
+ * 与 member fail-fast 语义区分);其余错误上抛;
6
+ * - 单槽缺席不影响其他槽命中(部分绑定形态:无商品端点厂商的 catalog / 无目录端点厂商的 directory)。
7
+ */
8
+ import { describe, expect, it, vi } from 'vitest';
9
+ import type { RequestContext } from '@tbox.cn/app-contracts';
10
+ import { createServerContext } from '@tbox.cn/app-sdk/server';
11
+ import type { ServerContext } from '@tbox.cn/app-sdk/server';
12
+ import { resolveShoppingGuidePorts } from '../src/server/ports';
13
+
14
+ function requestContext(mallId = 'mall-demo'): RequestContext {
15
+ return {
16
+ identity: { userId: 'u_1001', source: 'dev' },
17
+ credentials: { provider: 'dev', token: 'user-token' },
18
+ attributes: { mall: { miniAppId: 'app', mallId } },
19
+ };
20
+ }
21
+
22
+ function ctxWithIntegrations(resolveService: (input: unknown) => Promise<unknown>): ServerContext {
23
+ const ctx = createServerContext({});
24
+ (ctx as { integrations?: unknown }).integrations = { resolveService };
25
+ (ctx as { logger?: unknown }).logger = { warn: vi.fn(), info: vi.fn(), debug: vi.fn() };
26
+ return ctx;
27
+ }
28
+
29
+ /** 按槽分发的远端单 Port 产物(service 参数 → 各自 sentinel) */
30
+ const REMOTE_PORTS: Record<string, { marker: string }> = {
31
+ 'shopping-guide.catalog': { marker: 'remote-catalog' },
32
+ 'shopping-guide.shops': { marker: 'remote-shop' },
33
+ 'shopping-guide.categories': { marker: 'remote-category' },
34
+ 'shopping-guide.directory': { marker: 'remote-directory' },
35
+ };
36
+
37
+ const dispatchRemote = async (input: { service: string }) => {
38
+ const port = REMOTE_PORTS[input.service];
39
+ if (!port) throw Object.assign(new Error('未配置'), { code: 'PROVIDER_SERVICE_NOT_CONFIGURED' });
40
+ return port;
41
+ };
42
+
43
+ describe('shopping-guide ports 四槽解析(017 槽位原子化)', () => {
44
+ it('T1 四槽命中 → 各自 Port 产物 + service 参数 = 槽 id;navigation 恒本地', async () => {
45
+ const calls: unknown[] = [];
46
+ const ctx = ctxWithIntegrations(async (input) => {
47
+ calls.push(input);
48
+ return dispatchRemote(input as { service: string });
49
+ });
50
+ const ports = await resolveShoppingGuidePorts(requestContext(), ctx);
51
+ expect((ports.catalog as { marker?: string }).marker).toBe('remote-catalog');
52
+ expect((ports.shop as { marker?: string }).marker).toBe('remote-shop');
53
+ expect((ports.category as { marker?: string }).marker).toBe('remote-category');
54
+ expect((ports.directory as { marker?: string }).marker).toBe('remote-directory');
55
+ expect(typeof ports.navigation.listNearbyMalls).toBe('function');
56
+ expect(calls.map((c) => (c as { service: string }).service).sort()).toEqual(
57
+ ['shopping-guide.catalog', 'shopping-guide.categories', 'shopping-guide.directory', 'shopping-guide.shops'],
58
+ );
59
+ });
60
+
61
+ it('T2 PROVIDER_NOT_IMPLEMENTED → 本地空数据兜底不抛错(增强面缺席语义)', async () => {
62
+ const ctx = ctxWithIntegrations(async () => {
63
+ throw Object.assign(new Error('无 adapter'), { code: 'PROVIDER_NOT_IMPLEMENTED' });
64
+ });
65
+ const ports = await resolveShoppingGuidePorts(requestContext(), ctx);
66
+ expect(ports.shop.searchShops).toBeDefined();
67
+ const page = await ports.catalog.searchProducts({ page: 1, pageSize: 10 } as never);
68
+ expect(page.items).toHaveLength(0);
69
+ });
70
+
71
+ it('T3 预期缺席三码 → 本地空数据兜底', async () => {
72
+ for (const code of ['PROVIDER_SERVICE_NOT_CONFIGURED', 'PROVIDER_INSTANCE_NOT_FOUND', 'PROVIDER_INSTANCE_DISABLED']) {
73
+ const ctx = ctxWithIntegrations(async () => {
74
+ throw Object.assign(new Error(code), { code });
75
+ });
76
+ const ports = await resolveShoppingGuidePorts(requestContext(), ctx);
77
+ expect(ports.category.listCategories).toBeDefined();
78
+ expect(ports.navigation).toBeDefined();
79
+ }
80
+ });
81
+
82
+ it('T4 其余错误(PROVIDER_NOT_FOUND)→ 原样上抛', async () => {
83
+ const ctx = ctxWithIntegrations(async () => {
84
+ throw Object.assign(new Error('未命中 catalog'), { code: 'PROVIDER_NOT_FOUND' });
85
+ });
86
+ await expect(resolveShoppingGuidePorts(requestContext(), ctx)).rejects.toMatchObject({
87
+ code: 'PROVIDER_NOT_FOUND',
88
+ });
89
+ });
90
+
91
+ it('T5 ctx 无 integrations → 全本地兜底(空数据 + 本地 navigation)', async () => {
92
+ const ports = await resolveShoppingGuidePorts(requestContext(), createServerContext({}));
93
+ expect(ports.shop.searchShops).toBeDefined();
94
+ const page = await ports.catalog.searchProducts({ page: 1, pageSize: 10 } as never);
95
+ expect(page.items).toHaveLength(0);
96
+ });
97
+
98
+ it('T6 单槽缺席(catalog 无端点 / directory 无端点形态)→ 其余槽照常命中', async () => {
99
+ const ctx = ctxWithIntegrations(async (input) => {
100
+ const svc = (input as { service: string }).service;
101
+ if (svc === 'shopping-guide.catalog') {
102
+ throw Object.assign(new Error('该厂商无商品检索端点'), { code: 'PROVIDER_SERVICE_NOT_CONFIGURED' });
103
+ }
104
+ return dispatchRemote(input as { service: string });
105
+ });
106
+ const ports = await resolveShoppingGuidePorts(requestContext(), ctx);
107
+ const page = await ports.catalog.searchProducts({ page: 1, pageSize: 10 } as never);
108
+ expect(page.items).toHaveLength(0); // catalog 本地空数据
109
+ expect((ports.shop as { marker?: string }).marker).toBe('remote-shop'); // 其余槽命中
110
+ expect((ports.directory as { marker?: string }).marker).toBe('remote-directory');
111
+ });
112
+ });
@@ -0,0 +1,71 @@
1
+ /**
2
+ * samples 双断言(迁移自 mall dev-gallery brand-guide 画廊守卫):
3
+ * - 全样本 dataSchema.safeParse 通过 + findSampleShapeViolations 无越界键(样本即契约);
4
+ * - 守卫转移:缺图占位在场 + 至少一格缺图分支 / 无促销态(promotionFacts 恒空且文案
5
+ * 不含促销词汇——brand-guide 卡的中立定位)。
6
+ */
7
+ import { describe, expect, it } from 'vitest';
8
+ import { findSampleShapeViolations } from '@tbox.cn/app-sdk/server';
9
+ import shopListMeta from '../src/server/cards/shop-list/meta';
10
+ import shopDetailMeta from '../src/server/cards/shop-detail/meta';
11
+ import recommendMerchantsMeta from '../src/server/cards/recommend-merchants/meta';
12
+
13
+ const metas = [shopListMeta, recommendMerchantsMeta, shopDetailMeta];
14
+
15
+ describe('shopping-guide samples 双断言(样本即契约)', () => {
16
+ for (const meta of metas) {
17
+ it(`${meta.cardType}: 全样本过 schema + shape 无越界`, () => {
18
+ expect(meta.samples?.length ?? 0).toBeGreaterThan(0);
19
+ expect(findSampleShapeViolations(meta).violations).toEqual([]);
20
+ for (const s of meta.samples ?? []) {
21
+ expect(
22
+ meta.dataSchema.safeParse(s.data).success,
23
+ `${meta.cardType}/${s.label}`,
24
+ ).toBe(true);
25
+ }
26
+ });
27
+ }
28
+
29
+ it('样本集覆盖 11 格且卡型收口(shop-list / recommend-merchants / shop-detail)', () => {
30
+ expect(new Set(metas.map((m) => m.cardType))).toEqual(
31
+ new Set(['shop-list', 'recommend-merchants', 'shop-detail']),
32
+ );
33
+ expect(metas.reduce((n, m) => n + (m.samples?.length ?? 0), 0)).toBe(11);
34
+ });
35
+
36
+ it('图位分支:图字段全为 https 占位(契约 httpsUrlSchema)+ 至少一格无图样本', () => {
37
+ // 结构性断言:图字段只允许 https:// 前缀或缺省(契约强制;gallery.invalid 恒不解析
38
+ // → 预览页图位走缺图兜底——「有图」形态需真机 provider 数据,诚实边界)
39
+ for (const meta of metas) {
40
+ for (const s of meta.samples ?? []) {
41
+ const data = s.data as {
42
+ logoUrl?: string;
43
+ coverUrls?: string[];
44
+ items?: { logoUrl?: string; coverUrl?: string }[];
45
+ };
46
+ const urls = [
47
+ data.logoUrl,
48
+ ...(data.coverUrls ?? []),
49
+ ...(data.items ?? []).flatMap((e) => [e.logoUrl, e.coverUrl]),
50
+ ].filter((u): u is string => !!u);
51
+ for (const u of urls) {
52
+ expect(u.startsWith('https://'), `${meta.cardType}/${s.label}`).toBe(true);
53
+ }
54
+ }
55
+ }
56
+
57
+ const withoutImages = (metas[0].samples ?? []).filter((s) => {
58
+ const data = s.data as { logoUrl?: string; items?: readonly { logoUrl?: string }[] };
59
+ return !data.logoUrl && (!data.items || data.items.some((entry) => !entry.logoUrl));
60
+ });
61
+ expect(withoutImages.length).toBeGreaterThan(0);
62
+ });
63
+
64
+ it('无促销态:promotionFacts 恒空、文案不含促销词汇', () => {
65
+ const serialized = JSON.stringify(metas.map((m) => m.samples));
66
+ const promotionFacts = [...serialized.matchAll(/"promotionFacts":\[(.*?)\]/g)];
67
+ expect(promotionFacts.length).toBeGreaterThan(0);
68
+ expect(promotionFacts.every((match) => match[1] === '')).toBe(true);
69
+ expect(serialized).not.toMatch(/优惠|领券|券码|活动|满减|折扣|打折|秒杀|团购|\d+\s*折/);
70
+ });
71
+ });