@tbox.cn/app-module-activity-play 0.3.1 → 0.4.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.
Files changed (51) hide show
  1. package/INTEGRATION.md +57 -66
  2. package/README.md +13 -5
  3. package/dist/chunk-GDHTMID6.js +185 -0
  4. package/dist/chunk-XIDGKP5D.js +1154 -0
  5. package/dist/client/index.d.ts +2 -0
  6. package/dist/client/index.js +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +38 -10
  9. package/dist/server/index.d.ts +593 -85
  10. package/dist/server/index.js +37 -9
  11. package/package.json +5 -5
  12. package/skills/activity-play/SKILL.md +41 -15
  13. package/src/client/cards/activity-play/ActivityPlayCard.tsx +3 -3
  14. package/src/client/cards/activity-play-prize/ActivityPlayPrizeDetailCard.tsx +44 -0
  15. package/src/client/cards/activity-play-prize/ActivityPlayPrizeListCard.tsx +62 -0
  16. package/src/client/cards/activity-play-prize/index.ts +8 -0
  17. package/src/client/cards/view.ts +6 -3
  18. package/src/client/index.ts +6 -0
  19. package/src/server/cards/activity-play/meta.ts +5 -4
  20. package/src/server/cards/activity-play/samples.ts +43 -18
  21. package/src/server/cards/activity-play-prize-detail/meta.ts +29 -0
  22. package/src/server/cards/activity-play-prize-detail/samples.ts +54 -0
  23. package/src/server/cards/activity-play-prize-list/meta.ts +41 -0
  24. package/src/server/cards/activity-play-prize-list/samples.ts +78 -0
  25. package/src/server/cards/index.ts +5 -1
  26. package/src/server/errors.ts +9 -28
  27. package/src/server/index.ts +48 -11
  28. package/src/server/ports.ts +4 -25
  29. package/src/server/prizes/cards.ts +79 -0
  30. package/src/server/prizes/errors.ts +88 -0
  31. package/src/server/prizes/ports.ts +35 -0
  32. package/src/server/prizes/query.ts +104 -0
  33. package/src/server/prizes/routes.ts +139 -0
  34. package/src/server/prizes/subject.ts +29 -0
  35. package/src/server/prizes/tools.ts +180 -0
  36. package/src/server/query.ts +47 -28
  37. package/src/server/routes.ts +44 -230
  38. package/src/server/tools.ts +36 -31
  39. package/tbox.module.json +16 -6
  40. package/tests/cards-capture.test.ts +3 -4
  41. package/tests/ports.test.ts +57 -0
  42. package/tests/prizes-routes.test.ts +230 -0
  43. package/tests/prizes-tools.test.ts +216 -0
  44. package/tests/prizes.test.ts +375 -0
  45. package/tests/routes.test.ts +89 -16
  46. package/tests/samples.test.ts +2 -2
  47. package/tests/smoke.test.ts +8 -4
  48. package/tests/tools.test.ts +50 -31
  49. package/dist/chunk-CM4OEPC3.js +0 -689
  50. package/dist/chunk-HUBEOW44.js +0 -98
  51. package/tests/entry.test.ts +0 -458
@@ -29,18 +29,16 @@ const reqCtxOf = (mallId: string, userId = 'guest_1'): RequestContext => ({
29
29
  });
30
30
 
31
31
  const ITEM = {
32
- activityRef: 'demo:wheel',
32
+ activityId: 'demo:wheel',
33
33
  title: '幸运大转盘',
34
34
  description: '进入活动页面查看参与规则',
35
35
  status: 'active' as const,
36
- loginRequired: false,
37
36
  };
38
37
  const ITEM_B = {
39
- activityRef: 'demo:checkin',
38
+ activityId: 'demo:checkin',
40
39
  title: '签到有礼',
41
40
  startsAt: '2027-01-01T00:00:00+08:00',
42
41
  status: 'not_started' as const,
43
- loginRequired: true,
44
42
  };
45
43
 
46
44
  function makeTools(port: unknown) {
@@ -55,7 +53,7 @@ const listPort = (items: readonly unknown[]) => ({
55
53
  lastListCall = { q, input };
56
54
  return { items: (items as never[]) };
57
55
  }),
58
- getActivity: vi.fn(async (_q: unknown, ref: string) => (items as never[]).find((i: { activityRef?: string }) => i.activityRef === ref) ?? null),
56
+ getActivity: vi.fn(async (_q: unknown, ref: string) => (items as never[]).find((i: { activityId?: string }) => i.activityId === ref) ?? null),
59
57
  });
60
58
  let lastListCall: { q: unknown; input: { keyword?: string; limit?: number } } | undefined;
61
59
 
@@ -65,7 +63,7 @@ describe('listActivityPlays', () => {
65
63
  const result = await tools.listActivityPlays.execute!({}, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
66
64
  expect(result['found']).toBe(true);
67
65
  expect(result['count']).toBe(2);
68
- expect((result['items'] as Array<{ activityRef: string }>).map((i) => i.activityRef)).toEqual(['demo:wheel', 'demo:checkin']);
66
+ expect((result['items'] as Array<{ activityId: string }>).map((i) => i.activityId)).toEqual(['demo:wheel', 'demo:checkin']);
69
67
  const cards = result['cards'] as Array<{ cardType: string; data: unknown; note: string }>;
70
68
  expect(cards).toHaveLength(1);
71
69
  expect(cards[0]?.cardType).toBe(ACTIVITY_PLAY_CARD_TYPE);
@@ -118,7 +116,7 @@ describe('listActivityPlays', () => {
118
116
  const empty = await tools.listActivityPlays.execute!({}, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
119
117
  expect(empty['found']).toBe(false);
120
118
  expect(empty['count']).toBe(0);
121
- expect(empty['noResultsReason']).toContain('暂未登记');
119
+ expect(empty['noResultsReason']).toContain('暂无活动玩法');
122
120
  expect(empty['cards']).toBeUndefined();
123
121
 
124
122
  const kw = await tools.listActivityPlays.execute!({ keyword: '不存在的活动' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
@@ -172,9 +170,9 @@ describe('listActivityPlays', () => {
172
170
  describe('getActivityPlayDetail', () => {
173
171
  it('命中:一张 mode=detail 卡(items 恰一);facts 含状态/时间/说明', async () => {
174
172
  const tools = makeTools(listPort([ITEM, ITEM_B]));
175
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:checkin' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
173
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:checkin' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
176
174
  expect(result['found']).toBe(true);
177
- expect(result['activityRef']).toBe('demo:checkin');
175
+ expect(result['activityId']).toBe('demo:checkin');
178
176
  expect(result['statusText']).toBe('未开始');
179
177
  expect((result['items'] as unknown[] | undefined)).toBeUndefined(); // detail = 扁平 facts(非列表嵌套)
180
178
  const cards = result['cards'] as Array<{ cardType: string; data: { mode: string; items: unknown[] } }>;
@@ -186,9 +184,9 @@ describe('getActivityPlayDetail', () => {
186
184
  });
187
185
 
188
186
  it('detail 允许返回 disabled(状态说明用),卡 data 不携带 enabled', async () => {
189
- const disabledItem = { activityRef: 'demo:hidden', title: '停用活动', status: 'disabled' as const, loginRequired: false };
187
+ const disabledItem = { activityId: 'demo:hidden', title: '停用活动', status: 'disabled' as const };
190
188
  const tools = makeTools(listPort([disabledItem]));
191
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:hidden' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
189
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:hidden' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
192
190
  expect(result['found']).toBe(true);
193
191
  expect(result['statusText']).toBe('已停用');
194
192
  const card = (result['cards'] as Array<{ data: Record<string, unknown> }>)[0];
@@ -198,54 +196,75 @@ describe('getActivityPlayDetail', () => {
198
196
 
199
197
  it('未知引用 → ACTIVITY_NOT_FOUND 失败事实,无 cards(不猜首项/不造演示详情)', async () => {
200
198
  const tools = makeTools(listPort([ITEM]));
201
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
199
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
202
200
  expect(result['found']).toBe(false);
203
201
  expect(result['errorCode']).toBe('ACTIVITY_NOT_FOUND');
204
202
  expect(result['cards']).toBeUndefined();
205
203
  });
206
204
 
207
- it('非法 activityRef → INVALID_REQUEST(契约引用形状单源)', async () => {
205
+ it('非法 activityId → INVALID_REQUEST(契约引用形状单源;纯空白合法原样透传→未命中)', async () => {
208
206
  const tools = makeTools(listPort([ITEM]));
209
- for (const bad of ['', ' ', 'bad ref!', 'x'.repeat(129)]) {
210
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: bad }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
207
+ for (const bad of ['', 'a/b', 'a?b', 'a%b', 'a#b', 'x'.repeat(129), '.', '..']) {
208
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: bad }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
211
209
  expect(result['errorCode'], JSON.stringify(bad)).toBe('INVALID_REQUEST');
212
210
  expect(result['cards']).toBeUndefined();
213
211
  }
212
+ // ' '(纯空白)=原字符串语义合法字面量(空间非路径段破坏符)——原值透传上游,
213
+ // 不存在 → ACTIVITY_NOT_FOUND(与『不改写』回归同口径;其余控制/破坏符值就地 400)
214
+ const blank = await tools.getActivityPlayDetail.execute!({ activityId: ' ' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
215
+ expect(blank['errorCode']).toBe('ACTIVITY_NOT_FOUND');
214
216
  });
215
217
 
216
218
  it('评审返修回归:数字/布尔形态合法字面量引用(原始字串保留,数字串同型不撞车)', async () => {
217
219
  const weirdRefs = ['1.2', 'true', '0.12345', '42'];
218
- const items = weirdRefs.map((ref) => ({ ...ITEM, activityRef: ref }));
220
+ const items = weirdRefs.map((ref) => ({ ...ITEM, activityId: ref }));
219
221
  const tools = makeTools(listPort(items));
220
222
  for (const ref of weirdRefs) {
221
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
222
- expect(result['found'], `activityRef=${ref}`).toBe(true);
223
- expect(result['activityRef']).toBe(ref);
224
- const cards = result['cards'] as Array<{ data: { items: Array<{ activityRef: string }> } }>;
225
- expect(cards[0]?.data.items[0]?.activityRef).toBe(ref); // 卡 data 原样保留字面量
223
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
224
+ expect(result['found'], `activityId=${ref}`).toBe(true);
225
+ expect(result['activityId']).toBe(ref);
226
+ const cards = result['cards'] as Array<{ data: { items: Array<{ activityId: string }> } }>;
227
+ expect(cards[0]?.data.items[0]?.activityId).toBe(ref); // 卡 data 原样保留字面量
226
228
  }
227
229
  });
228
230
 
229
231
  it('评审返修二轮:数字同型不同值引用不串答(JSON 转换已移除——1.20 不再折叠成 1.2、1e3 不再折叠成 1000)', async () => {
230
232
  // 目录同时含 1.2/1.20 与 1e3/1000 四个独立活动:每个引用必须精确命中自己
231
233
  const refs = ['1.2', '1.20', '1e3', '1000'];
232
- const items = refs.map((ref) => ({ ...ITEM, activityRef: ref, title: `活动${ref}` }));
234
+ const items = refs.map((ref) => ({ ...ITEM, activityId: ref, title: `活动${ref}` }));
233
235
  const tools = makeTools(listPort(items));
234
236
  for (const ref of refs) {
235
- const result = await tools.getActivityPlayDetail.execute!({ activityRef: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
236
- expect(result['found'], `activityRef=${ref}`).toBe(true);
237
- expect(result['activityRef']).toBe(ref);
237
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: ref }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
238
+ expect(result['found'], `activityId=${ref}`).toBe(true);
239
+ expect(result['activityId']).toBe(ref);
238
240
  expect(result['title']).toBe(`活动${ref}`); // 撞车即串答——此处必须各自命中
239
241
  }
240
242
  });
241
243
 
242
- it('名称→引用不隐式回退:非 ref 形状 = INVALID_REQUEST;合法形状未知 = NOT_FOUND(无首项/演示回退)', async () => {
244
+ it('P2 返修回归:标识原值直传(含前后空格照原样命中供给记录——不 trim 不折叠)', async () => {
245
+ const spaced = { ...ITEM, activityId: ' record-001 ', title: '原值活动' };
246
+ const tools = makeTools(listPort([spaced]));
247
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: ' record-001 ' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
248
+ expect(result['found']).toBe(true);
249
+ expect(result['activityId']).toBe(' record-001 ');
250
+ expect(result['title']).toBe('原值活动');
251
+ });
252
+
253
+ it('P2 返修回归:『.』『..』整值 → INVALID_REQUEST(路径段漂移防线——工具与 HTTP 同门)', async () => {
254
+ const tools = makeTools(listPort([ITEM]));
255
+ for (const dot of ['.', '..']) {
256
+ const result = await tools.getActivityPlayDetail.execute!({ activityId: dot }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
257
+ expect(result['errorCode'], dot).toBe('INVALID_REQUEST');
258
+ }
259
+ });
260
+
261
+ it('ID 边界:超长 = INVALID_REQUEST;空间内未知值 = NOT_FOUND(无首项/演示回退)', async () => {
243
262
  const tools = makeTools(listPort([ITEM]));
244
- // 标题字面量不是 activityRef(形状非法——技能引导模型先查列表拿引用,不猜)
245
- const byTitle = await tools.getActivityPlayDetail.execute!({ activityRef: '幸运大转盘' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
246
- expect(byTitle['errorCode']).toBe('INVALID_REQUEST');
247
- // 形状合法但目录中不存在
248
- const byUnknownRef = await tools.getActivityPlayDetail.execute!({ activityRef: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
263
+ // 形态边界 = 控制字符/路径段破坏符/超长(含中文标题等一切非破坏符形态均属供应商标识空间)
264
+ const byTitle = await tools.getActivityPlayDetail.execute!({ activityId: '幸运大转盘' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
265
+ expect(byTitle['errorCode']).toBe('ACTIVITY_NOT_FOUND');
266
+ // 形态合法但供给查不到
267
+ const byUnknownRef = await tools.getActivityPlayDetail.execute!({ activityId: 'demo:none' }, createToolExecContext(reqCtxOf('mall-a')) as never) as Record<string, unknown>;
249
268
  expect(byUnknownRef['errorCode']).toBe('ACTIVITY_NOT_FOUND');
250
269
  });
251
270
  });