@tbox.cn/app-module-activity-play 0.0.0-stage → 0.3.1
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/INTEGRATION.md +82 -0
- package/LICENSE +21 -0
- package/README.md +30 -2
- package/dist/chunk-CM4OEPC3.js +689 -0
- package/dist/chunk-HUBEOW44.js +98 -0
- package/dist/client/index.css +107 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +6 -0
- package/dist/index.css +107 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +46 -0
- package/dist/server/index.d.ts +309 -0
- package/dist/server/index.js +42 -0
- package/package.json +67 -3
- package/skills/activity-play/SKILL.md +55 -0
- package/src/client/cards/activity-play/ActivityPlayCard.tsx +77 -0
- package/src/client/cards/activity-play/index.ts +1 -0
- package/src/client/cards/view.ts +42 -0
- package/src/client/index.ts +22 -0
- package/src/client/styles/activity-play.css +136 -0
- package/src/index.ts +6 -0
- package/src/server/cards/activity-play/meta.ts +26 -0
- package/src/server/cards/activity-play/samples.ts +116 -0
- package/src/server/cards/index.ts +7 -0
- package/src/server/errors.ts +101 -0
- package/src/server/index.ts +72 -0
- package/src/server/ports.ts +50 -0
- package/src/server/query.ts +98 -0
- package/src/server/routes.ts +371 -0
- package/src/server/tools.ts +187 -0
- package/tbox.module.json +62 -0
- package/tests/cards-capture.test.ts +110 -0
- package/tests/entry.test.ts +458 -0
- package/tests/ports.test.ts +83 -0
- package/tests/routes.test.ts +271 -0
- package/tests/samples.test.ts +53 -0
- package/tests/smoke.test.ts +27 -0
- package/tests/tools.test.ts +251 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +27 -0
package/INTEGRATION.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# INTEGRATION —— module-activity-play 接入指引
|
|
2
|
+
|
|
3
|
+
> 结构事实以本包 `tbox.module.json` 为准(`declare.consumes`:槽位与必选性、`declare.owns`:
|
|
4
|
+
> 服务归属);接口签名以消费的契约包 Port(`@tbox.cn/app-contracts-mall` services/activity-play)为准;
|
|
5
|
+
> 本文件只写二者推不出的接入语义(顺序/配置形态/错误约定)。
|
|
6
|
+
|
|
7
|
+
## 服务与依赖
|
|
8
|
+
|
|
9
|
+
- 消费并归属 `activity-play.query` 槽(第 19 个 TIER1 词汇域槽);供给须由 provider 包承担
|
|
10
|
+
(当前唯一供给 = `provider-hupo`,本地目录形态;不得把绑定指向其他域槽)。
|
|
11
|
+
- 依赖 `contracts-mall ≥ 0.15.0`(`ACTIVITY_PLAY_QUERY_SERVICE` / Port / 状态计算单源)。
|
|
12
|
+
- 接入顺序:安装本模块(`npx --yes @tbox.cn/app-cli module add @tbox.cn/app-module-activity-play`,显式加装,
|
|
13
|
+
不在 mall profile 默认清单)→ 绑定供给(integrations.json 提供槽 `activity-play.query`,
|
|
14
|
+
激活恒显式:`instances` 在场)→ `npx --yes @tbox.cn/app-cli module doctor` 复查。
|
|
15
|
+
|
|
16
|
+
## 智能体消费面(task-02 起:两只读工具 + 服务端出卡 + 模块技能)
|
|
17
|
+
|
|
18
|
+
- 工具:`listActivityPlays`(keyword?/limit? 字符串化输入)与 `getActivityPlayDetail`
|
|
19
|
+
(activityRef 必填)——经 `withCardEmissionHint` 包装注册;上下文/商圈恒取 execute 第二参
|
|
20
|
+
可信上下文(输入不含任何身份/scope 覆盖字段)。
|
|
21
|
+
- 出卡:非空查询经 cards 出参产出 `activity-play` 单卡型(data = mallId/mode/items——mode
|
|
22
|
+
list|detail;契约 `@tbox.cn/app-contracts-mall` `activityPlayCardDataSchema`);空结果与
|
|
23
|
+
全部失败路径**不出卡**;失败 fact 携 errorCode(与 HTTP 信封同 code 单源)。
|
|
24
|
+
- 技能:`skills/activity-play/SKILL.md`(文件化 loadModuleSkills——玩法查询 SOP 与旧域分流)。
|
|
25
|
+
- 前端联调要点:卡渲染器按 mode 组织(列表/详情),读取 data.mallId/mode/items;详情卡片
|
|
26
|
+
可按 activityRef 调用本模块 HTTP 详情接口做只读刷新(复用任务 01 接口)。
|
|
27
|
+
|
|
28
|
+
## 参与入口准备(task-03:POST,前端按钮调用)
|
|
29
|
+
|
|
30
|
+
- `POST /api/m/activity-play/activities/:activityRef/entry?mallId=…`(业务体空对象或省略;
|
|
31
|
+
唯一保留键 `context` 由平台中间件消费为请求上下文——**本模块不读该键**,其余非空字段 400 拒收)
|
|
32
|
+
- 成功:`{"data":{"protocolVersion":"1","activityRef":…,"target":{"kind":"miniapp-plugin","pluginAlias","page","params"}}}`
|
|
33
|
+
——`Cache-Control: no-store`;后端不生成跳转 URL,`plugin://` URI 由前端按宿主桥构造
|
|
34
|
+
- 检查序(每次点击重新执行/hash 卡片旧状态不参与):商圈与输入 → 活动 404 → 状态门
|
|
35
|
+
(`ACTIVITY_DISABLED/NOT_STARTED/ENDED` 409 族,仅 active 前进)→ `loginRequired=true`
|
|
36
|
+
且身份 anonymous → 401 `LOGIN_REQUIRED`(前端走既有登录流程后**重新**请求)→ entry
|
|
37
|
+
槽(未配 503 `NOT_CONFIGURED`;条目缺席或两槽目录不一致 409 `ENTRY_UNAVAILABLE`;
|
|
38
|
+
配置/供给非法 502 `PROVIDER_ERROR`)→ 出站 schema 自证
|
|
39
|
+
- 配置(integrations.json,与查询共用 activities 数组,按需给条目加 `entry`;显式激活
|
|
40
|
+
`activity-play.entry` 槽实例)与服务重启生效语义同任务 01/02
|
|
41
|
+
- 前端契约要点:只传 mallId+activityRef;不缓存/不续用历史 target;重试无参与副作用
|
|
42
|
+
(重复准备=重新读);失败展示当前状态而非回退旧营销领取
|
|
43
|
+
|
|
44
|
+
## HTTP 接口(挂载前缀 /api/m/activity-play)
|
|
45
|
+
|
|
46
|
+
| 方法与路径 | 参数 | 成功 |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| GET /activities | mallId 必填;keyword 可选;limit 缺省 20、合法域 1—50 | `{"data":{"items":[活动对象]}}` |
|
|
49
|
+
| GET /activities/:activityRef | mallId 必填;activityRef 按路径段编码 | `{"data":活动对象}` |
|
|
50
|
+
| POST /activities/:activityRef/entry | mallId 必填;业务体空/省略 | `{"data":ActivityPlayEntry}`(no-store) |
|
|
51
|
+
|
|
52
|
+
- 鉴权沿用应用 `/api` 统一中间件(无 token → 上层 401)。查询(HTTP 列表/详情/工具)
|
|
53
|
+
不做登录拦截——`loginRequired` 仅为活动描述字段;**入口准备(POST entry)按活动
|
|
54
|
+
loginRequired 检查本系统登录态**(identity=anonymous 且要求登录 → 401 LOGIN_REQUIRED,
|
|
55
|
+
登录成功后须重新请求入口、不可重放旧 target)。
|
|
56
|
+
- 错误统一 `{"error":{"code","message"}}`:`SCOPE_REQUIRED`(400)/`INVALID_REQUEST`(400)/
|
|
57
|
+
`SCOPE_MISMATCH`(403)/`ACTIVITY_NOT_FOUND`(404)/`ACTIVITY_DISABLED`/`ACTIVITY_NOT_STARTED`/
|
|
58
|
+
`ACTIVITY_ENDED`/`ENTRY_UNAVAILABLE`(409——状态门与入口缺席/两槽不一致)/
|
|
59
|
+
`NOT_CONFIGURED`(503——未配置槽、实例缺席或禁用)/`PROVIDER_ERROR`(502——供给配置非法、
|
|
60
|
+
供给对象/目标非法或执行异常)。
|
|
61
|
+
- 供给错误不当空列表、不回退演示数据;空目录(配置完整零活动)= 200 空 items。
|
|
62
|
+
|
|
63
|
+
## 供给配置(经 provider-hupo 的本地目录)
|
|
64
|
+
|
|
65
|
+
```jsonc
|
|
66
|
+
{
|
|
67
|
+
"modules": { "module-activity-play": { "provider": "hupo" } }, // 模块级绑定声明(可选)
|
|
68
|
+
"services": {
|
|
69
|
+
"activity-play.query": {
|
|
70
|
+
"provider": "hupo",
|
|
71
|
+
"instances": {
|
|
72
|
+
"mall-demo": { "config": { "activities": [ /* 见 provider-hupo/schemas */ ] } }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
实例级 `instances.<mallId>.config` 承载商圈隔离(不同商圈不同目录);字段契约与
|
|
80
|
+
校验规则见 `@tbox.cn/app-provider-hupo`(`schemas/activity-play.config.json`——标题非空、
|
|
81
|
+
引用唯一、时间顺序、目录上限 100、imageUrl 恒 https)。配置为 JSON 文件,**改后需重启
|
|
82
|
+
应用进程生效**(integrations 无热轮换)。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 tbox.cn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tbox.cn/app-module-activity-play
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
活动玩法业务模块(tbox 组件化应用 · codegen 源形态):消费 `activity-play.query` 槽供给,提供
|
|
4
|
+
四条消费面——HTTP 列表/详情(任务 01)、只读工具 `listActivityPlays`/`getActivityPlayDetail`
|
|
5
|
+
与 `activity-play` 单卡型服务端出卡(任务 02)、模块技能(skills/activity-play)。前端卡渲染
|
|
6
|
+
器由前端负责人实现;2026-11-16 起含用户授权的先行占位 renderer(client/cards/activity-play——中立保形展示,装配门禁解锁;正式渲染器落地后整体替换该文件)。
|
|
7
|
+
接入语义见 [INTEGRATION.md](INTEGRATION.md)。
|
|
8
|
+
|
|
9
|
+
## 形态铁律(摘要)
|
|
10
|
+
|
|
11
|
+
- 单包双端、逐行同构:`src/server/index.ts` 与 `src/client/index.ts` 描述对象对称;`satisfies` 声明(禁类型标注)
|
|
12
|
+
- `cards` map 的 key = meta.cardType;`exports` 恒指 `src/`
|
|
13
|
+
- import 边界:只 import contracts/sdk 公开入口;全禁直接 import `@tbox-dev-js/sdk`;`client/**` 引同包 `server/**` 类型必须 `import type`
|
|
14
|
+
- `register` 只注册不解析;跨模块交互一律经 ctx(Port + 事件总线)
|
|
15
|
+
|
|
16
|
+
完整铁律与 doctor 30 条规则见 `docs/reference/modules.md`。
|
|
17
|
+
|
|
18
|
+
## 开发循环
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
pnpm install # workspace 成员(modules/* 已在根 workspace glob 内)
|
|
22
|
+
pnpm --filter @tbox.cn/app-module-activity-play typecheck && pnpm --filter @tbox.cn/app-module-activity-play test
|
|
23
|
+
npx --yes @tbox.cn/app-cli module doctor
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 交付清单(新增能力后)
|
|
27
|
+
|
|
28
|
+
- `tbox.module.json` declare 与实现同步(本模块 declare 仅 consumes/owns——零 tools/cards/handler)
|
|
29
|
+
- 服务槽需求写 `declare.consumes`(demand 侧);供给写 `declare.providers.slots`(仅 provider 包)
|
|
30
|
+
- skills 文件化:`skills/<name>/SKILL.md`(loadModuleSkills 声明式通道)
|
|
31
|
+
- 发布:`tbox-app-dev module publish module-activity-play`(需人工确认;SOP 见 docs/cookbook/release.md)
|