Files
atlas-seller-kit/docs/project/m2.2-m2.3-extension-collection.md
T

35 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# M2.2 / M2.3:扩展授权、素材转存与 Ozon 公开页采集
> 状态:已完成首个可运行闭环(2026-09-05)。Seller 网页四接口观察实验不属于本批次,仍待独立任务实施。
## 已交付
1. 扩展使用 PKCE 授权码登录,而不是读取 Atlas Web 的 localStorage 或 refresh Cookie。`GET /api/extension/authorize` 会优先复用用户浏览器已有的 Atlas Web 会话:会话有效则无感签发一次性 code;没有会话才跳转登录页,成功登录后回到原授权请求。
2. 服务端保存 code 与扩展 refresh token 的哈希,code 60 秒且一次性使用,扩展 access token 15 分钟、refresh token 30 天并轮换。令牌含扩展专用 audience,不能被普通 Web/API 身份守卫接受。
3. 扩展上报仅携带来源、规范化 SKU/规格轴、候选素材 URL 和证据;`POST /api/extension/materials` 从扩展令牌解析工作空间,不接受目标平台、门店、Cookie 或 API Key。相同工作空间、来源平台和来源 item key 复用同一采集记录。
4. 上报事务创建来源采集记录、SPU、来源确认 SKU 和素材转存任务;素材异步事件经 Transactional Outbox 进入 Worker。Worker 仅下载 HTTPS 公网地址,限制重定向、私网地址、20MB 和 PNG/JPEG/WebP,按 SHA-256 去重后写入对象存储。单张失败不会使商品草稿丢失。
5. Ozon (`ru/kz/by`) 商品详情页显示 Shadow DOM 小浮窗。未登录只显示“登录 Atlas ERP”;已登录显示“编辑上架 / 采集商品 / 进入 ERP”。编辑上架成功后打开现有 `/products/{productId}` ERP 编辑入口;采集商品只提示进入采集箱。
6. Ozon 解析器保留当前公开 SKU,并只从带 `webProducts`、`webAspects` 或 `aspects` 标识的页面状态发现关联 SKU;不会扫描整页 SKU 或把规格轴做笛卡尔积。来源未给可确认组合时,仍保留当前 SKU。主图作为商品候选素材上报,不伪造 SKU 图片关系。
## 配置与安全前提
- `EXTENSION_COLLECTOR_REDIRECT_URI` 必须精确等于已安装扩展的 `chrome.identity.getRedirectURL('callback')`;不可用通配符代替。
- 本地默认 API 为 `http://localhost:8200`。生产构建应为 Atlas API 域配置扩展 host permission 与 `ATLAS_API_ORIGIN`,并登记对应扩展 ID 的回调 URI。
- 扩展 refresh token 仅存 Chrome extension storage;Web refresh Cookie 从不返回给扩展。Worker 不接触浏览器 Cookie。
## 尚未实现
- Ozon 变体队列逐页 hydrate、SKU 级公开详情补全;当前只消费已加载公开页面状态。
- 1688、淘宝、天猫解析器,以及 Ozon Seller 网页四接口本地观察实验。
- 采集箱详情页的素材关联可视化、重试 UI 和商品编辑/发布闭环。
## 验收命令
```sh
./packages/contracts/node_modules/.bin/tsc -p packages/contracts/tsconfig.json
./apps/api/node_modules/.bin/tsc -p apps/api/tsconfig.json --noEmit
./apps/worker/node_modules/.bin/tsc -p apps/worker/tsconfig.json --noEmit
(cd apps/extension && ./node_modules/.bin/wxt prepare && ./node_modules/.bin/tsc -p tsconfig.json --noEmit && ./node_modules/.bin/wxt build)
(cd apps/web && ./node_modules/.bin/vite build)
```