qmai-cli-public 0.1.2 → 0.1.4

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 (35) hide show
  1. package/README.md +18 -1
  2. package/npm/install.js +128 -32
  3. package/package.json +2 -1
  4. package/skills/qmai-delivery/SKILL.md +52 -0
  5. package/skills/qmai-delivery/references/qmai-delivery-order.md +23 -0
  6. package/skills/qmai-delivery/references/qmai-delivery-status.md +19 -0
  7. package/skills/qmai-finance/SKILL.md +53 -0
  8. package/skills/qmai-finance/references/qmai-finance-statement.md +22 -0
  9. package/skills/qmai-finance/references/qmai-finance-stats.md +22 -0
  10. package/skills/qmai-inventory/SKILL.md +72 -0
  11. package/skills/qmai-inventory/references/qmai-inventory-master.md +29 -0
  12. package/skills/qmai-inventory/references/qmai-inventory-sales.md +25 -0
  13. package/skills/qmai-inventory/references/qmai-inventory-stock.md +29 -0
  14. package/skills/qmai-marketing/SKILL.md +80 -0
  15. package/skills/qmai-marketing/references/qmai-marketing-card-pricing.md +29 -0
  16. package/skills/qmai-marketing/references/qmai-marketing-coupon.md +27 -0
  17. package/skills/qmai-member/SKILL.md +175 -0
  18. package/skills/qmai-member/references/qmai-member-asset.md +35 -0
  19. package/skills/qmai-member/references/qmai-member-profile-tag.md +51 -0
  20. package/skills/qmai-order/SKILL.md +64 -0
  21. package/skills/qmai-order/references/qmai-order-query.md +26 -0
  22. package/skills/qmai-order/references/qmai-order-write.md +21 -0
  23. package/skills/qmai-product/SKILL.md +183 -0
  24. package/skills/qmai-product/references/qmai-product-advanced.md +92 -0
  25. package/skills/qmai-product/references/qmai-product-batch.md +113 -0
  26. package/skills/qmai-product/references/qmai-product-category.md +67 -0
  27. package/skills/qmai-product/references/qmai-product-crud.md +126 -0
  28. package/skills/qmai-queue/SKILL.md +38 -0
  29. package/skills/qmai-queue/references/qmai-queue-read.md +21 -0
  30. package/skills/qmai-shared/SKILL.md +155 -0
  31. package/skills/qmai-shared/references/qmai-shared-auth.md +54 -0
  32. package/skills/qmai-shared/references/qmai-shared-config.md +69 -0
  33. package/skills/qmai-store/SKILL.md +90 -0
  34. package/skills/qmai-store/references/qmai-store-read.md +45 -0
  35. package/skills/qmai-store/references/qmai-store-write.md +44 -0
@@ -0,0 +1,155 @@
1
+ ---
2
+ name: qmai-shared
3
+ version: 3.0.0
4
+ description: "基础能力:开放平台认证、配置管理、安全规则、通用约定"
5
+ metadata:
6
+ bins: [qmai]
7
+ help: "qmai --help"
8
+ ---
9
+
10
+ ## 概述
11
+
12
+ qmai CLI 是门店经营命令行工具。通过企迈开放平台 (`openapi.qmai.cn`) 管理门店商品、门店与组织、会员、营销、订单、财务、聚合配送、进销存和排队。本 Skill 描述认证、配置和安全相关的基础能力。
13
+
14
+ ## 认证流程
15
+
16
+ ### 凭证配置
17
+
18
+ ```bash
19
+ qmai auth login [--profile <name>]
20
+ ```
21
+
22
+ 流程:
23
+ 1. 交互式输入 openId、grantCode、openKey、shopCode
24
+ 2. openKey 存入 OS keychain(敏感凭证)
25
+ 3. openId/grantCode/shopCode 写入 config profile
26
+ 4. 设为 active_profile
27
+
28
+ ### 认证管理命令
29
+
30
+ | 命令 | 说明 |
31
+ |------|------|
32
+ | `qmai auth login` | 配置开放平台凭证 |
33
+ | `qmai auth logout` | 清除凭证(keychain + config) |
34
+
35
+ ### 凭证存储
36
+
37
+ - **openKey**: macOS Keychain(service: `qmai-cli`),Linux: libsecret
38
+ - **openId/grantCode/shopCode**: `~/.config/qmai/config.yaml` profile 中
39
+
40
+ ### 请求签名
41
+
42
+ 每个 API 请求自动签名,无需手动操作:
43
+ 1. 生成随机 nonce + 当前时间戳
44
+ 2. 按字典序拼接 `grantCode=xx&nonce=xx&openId=xx&timestamp=xx`
45
+ 3. HmacSHA1(拼接串, openKey) → Base64 → URL Encode → token
46
+ 4. 请求体: `{openId, grantCode, nonce, timestamp, token, params}`
47
+
48
+ ## 配置管理
49
+
50
+ ### 配置文件
51
+
52
+ 位置:`~/.config/qmai/config.yaml`
53
+
54
+ ```yaml
55
+ active_profile: default
56
+ default_format: table
57
+ debug: false
58
+ profiles:
59
+ default:
60
+ name: default
61
+ shop_code: "S001"
62
+ open_id: "d14c1559..."
63
+ grant_code: "ba67d4fa46"
64
+ store2:
65
+ name: store2
66
+ shop_code: "S002"
67
+ open_id: "..."
68
+ grant_code: "..."
69
+ ```
70
+
71
+ ### 配置优先级
72
+
73
+ flags → profile 配置 → 默认值
74
+
75
+ ### 配置命令
76
+
77
+ ```bash
78
+ qmai config init # 交互式初始化
79
+ qmai config set <key> <val> # 设置配置项
80
+ qmai config get <key> # 读取配置项
81
+ qmai config list # 查看所有配置
82
+ qmai config profile add <name> --shop-code xxx # 添加 profile
83
+ qmai config profile remove <name> # 删除 profile
84
+ qmai config profile list # 列出 profiles
85
+ ```
86
+
87
+ ## 输出格式
88
+
89
+ 所有命令支持 `--format` flag:
90
+
91
+ | 格式 | 说明 |
92
+ |------|------|
93
+ | `table` | 对齐的文本表格(默认,终端友好) |
94
+ | `json` | JSON 输出(脚本友好) |
95
+ | `csv` | CSV 输出(Excel/导入友好) |
96
+
97
+ ## Debug 模式
98
+
99
+ ```bash
100
+ qmai product list --debug
101
+ ```
102
+
103
+ 启用后在 `Client.Call` 层输出完整日志(一行包含全部信息):
104
+ ```
105
+ [DEBUG] POST <url> | req=<完整请求JSON> | resp=<完整响应JSON> | <耗时>ms
106
+ ```
107
+
108
+ 用于排查 API 对接问题,查看实际请求参数和响应结构。
109
+
110
+ ## 安全规则(Agent 必读)
111
+
112
+ 1. **openKey 安全**: openKey 仅存储在 OS keychain,不写入配置文件或日志
113
+ 2. **不存储敏感信息**: config 中不保存 openKey
114
+ 3. **Dry-run 优先**: 所有变更操作建议先使用 `--dry-run` 预览
115
+ 4. **确认机制**: 删除/下架操作需要 `--force` 确认
116
+ 5. **批量操作安全**: 批量操作前务必备份(`export`),建议先 `--dry-run`
117
+
118
+ ## API 基础
119
+
120
+ - Base URL: `https://openapi.qmai.cn/`
121
+ - 协议: 全部 HTTP POST,Content-Type: application/json
122
+ - QPS 限制: 单接口最高 10
123
+ - 分页限制: pageSize 最大 50
124
+ - 认证: 请求体签名(自动注入)
125
+ - 响应格式:
126
+ ```json
127
+ {
128
+ "status": true,
129
+ "code": 0,
130
+ "message": "请求成功",
131
+ "data": { ... },
132
+ "traceId": "..."
133
+ }
134
+ ```
135
+
136
+ ## 可用命令
137
+
138
+ ```
139
+ qmai
140
+ ├── auth 认证管理
141
+ ├── config 配置管理
142
+ ├── product 商品管理
143
+ ├── store 门店与组织管理
144
+ ├── member 会员服务
145
+ ├── marketing 营销服务
146
+ ├── order 订单服务
147
+ ├── finance 财务服务
148
+ ├── delivery 聚合配送
149
+ ├── inventory 进销存
150
+ ├── queue 排队服务
151
+ ├── api Raw API 请求透传
152
+ ├── doctor 诊断检查
153
+ ├── completion Shell 自动补全
154
+ └── version 版本信息
155
+ ```
@@ -0,0 +1,54 @@
1
+ # 开放平台认证详情
2
+
3
+ ## 凭证配置流程
4
+
5
+ ```
6
+ $ qmai auth login
7
+ 请输入 openId: d14c1559e87b747d577c834b275a4310
8
+ 请输入 grantCode: ba67d4fa46
9
+ 请输入 openKey: LyvrkvkxRkG2R6aM55bXpPwjYAbkEXTbVnKwfDYvVHjNwNFAmx
10
+ 请输入门店编码 (shopCode): S001
11
+ ✓ 凭证已保存 (profile: default)
12
+ ```
13
+
14
+ ## 凭证说明
15
+
16
+ | 凭证 | 说明 | 存储位置 |
17
+ |------|------|----------|
18
+ | openId | 开放平台应用 ID | config yaml |
19
+ | grantCode | 授权码 | config yaml |
20
+ | openKey | 签名密钥(敏感) | OS keychain |
21
+ | shopCode | 门店编码 | config yaml |
22
+
23
+ ## 请求签名算法 (HmacSHA1)
24
+
25
+ 1. 取 openId, grantCode, nonce, timestamp 四个字段
26
+ 2. 按 key 字典序升序排列
27
+ 3. 拼接为 `grantCode=xx&nonce=xx&openId=xx&timestamp=xx`
28
+ 4. HmacSHA1(拼接串, openKey) → Base64 → URL Encode
29
+ 5. 得到 token,一次性使用
30
+
31
+ 示例签名验证:
32
+ - openKey: `LyvrkvkxRkG2R6aM55bXpPwjYAbkEXTbVnKwfDYvVHjNwNFAmx`
33
+ - openId: `d14c1559e87b747d577c834b275a4310`
34
+ - grantCode: `ba67d4fa46`
35
+ - timestamp: `1465185768`, nonce: `11886`
36
+ - 期望 token: `cFw0t9IuvL9jVo9qAzk0qMcw5BM%3D`
37
+
38
+ ## AES 加解密(敏感字段)
39
+
40
+ 部分接口的敏感字段需要 AES 加密传输:
41
+
42
+ - 算法: AES-256/CBC/PKCS5Padding
43
+ - Key: MD5(openKey) → 32 hex chars 作为字节
44
+ - IV: MD5(openId)[8:24] → 16 hex chars 作为字节
45
+
46
+ ## 多门店支持
47
+
48
+ 每个 profile 独立存储凭证:
49
+
50
+ ```bash
51
+ qmai auth login --profile store1
52
+ qmai auth login --profile store2
53
+ qmai config set active_profile store1 # 切换到 store1
54
+ ```
@@ -0,0 +1,69 @@
1
+ # 配置管理详情
2
+
3
+ ## 配置文件结构
4
+
5
+ ```yaml
6
+ # ~/.config/qmai/config.yaml
7
+ active_profile: default
8
+ default_format: table # json | table | csv
9
+ debug: false
10
+
11
+ profiles:
12
+ default:
13
+ name: default
14
+ shop_code: "S001"
15
+ open_id: "d14c1559e87b747d577c834b275a4310"
16
+ grant_code: "ba67d4fa46"
17
+ base_url: "" # 空则使用默认值
18
+
19
+ test-store:
20
+ name: test-store
21
+ shop_code: "S002"
22
+ open_id: "..."
23
+ grant_code: "..."
24
+ base_url: "https://openapi.qmai.co/" # 沙箱环境
25
+ ```
26
+
27
+ ## 初始化流程
28
+
29
+ ```bash
30
+ $ qmai config init
31
+ qmai CLI 配置初始化
32
+ ------------------------------
33
+ Profile 名称 (default): my-store
34
+ 门店编码 shopCode (可选): S001
35
+ API Base URL (https://openapi.qmai.cn/):
36
+ 默认输出格式 [table/json/csv] (table): json
37
+
38
+ ✓ 配置已保存到 ~/.config/qmai/config.yaml
39
+ Active profile: my-store
40
+
41
+ 下一步: 运行 'qmai auth login' 配置开放平台凭证
42
+ ```
43
+
44
+ ## 配置键列表
45
+
46
+ | 键 | 说明 | 默认值 |
47
+ |---|------|--------|
48
+ | `active_profile` | 当前活动 profile | `default` |
49
+ | `default_format` | 默认输出格式 | `table` |
50
+ | `debug` | 调试模式 | `false` |
51
+ | `base_url` | API 基础 URL(per profile) | `https://openapi.qmai.cn/` |
52
+ | `shop_code` | 门店编码(per profile) | - |
53
+ | `open_id` | 开放平台 openId(per profile) | - |
54
+ | `grant_code` | 开放平台 grantCode(per profile) | - |
55
+
56
+ ## Profile 管理
57
+
58
+ ```bash
59
+ # 添加 profile
60
+ qmai config profile add new-store --shop-code S003 --base-url https://...
61
+
62
+ # 列出所有 profiles
63
+ qmai config profile list
64
+ # * default (shop: S001)
65
+ # test-store (shop: S002) [https://openapi.qmai.co/]
66
+
67
+ # 删除 profile
68
+ qmai config profile remove test-store
69
+ ```
@@ -0,0 +1,90 @@
1
+ ---
2
+ name: qmai-store
3
+ version: 1.0.0
4
+ description: "门店与组织管理:门店详情、门店列表、组织树、门店组、配置查询、门店状态与门店同步"
5
+ metadata:
6
+ bins: [qmai]
7
+ help: "qmai store --help"
8
+ ---
9
+
10
+ > 前置条件: 请先阅读 ../qmai-shared/SKILL.md 了解认证和配置
11
+
12
+ ## 核心概念
13
+
14
+ - **shopCode**: 门店编码,很多查询和状态修改命令以此为主键
15
+ - **shopId / storeId**: 门店 ID,配置、扩展字段、标签和部分批量查询接口会使用
16
+ - **teamId**: 门店组 ID,用于门店组别调整
17
+ - **fieldCodes**: 门店配置或品牌配置的编码列表,一次最多建议传 10 个
18
+ - **shopInfoSync**: 门店主数据同步接口,字段多、副作用大,建议只通过 JSON 文件驱动
19
+
20
+ ## 命令概览
21
+
22
+ ### 门店详情与列表
23
+ ```bash
24
+ qmai store get <shop-code>
25
+ qmai store get-by-id <shop-id>
26
+ qmai store list [--keyword 门店名] [--page 1] [--page-size 10]
27
+ qmai store id <shop-code>
28
+ ```
29
+
30
+ ### 外卖映射
31
+ ```bash
32
+ qmai store takeout-map-list --platform-type 4 [--page 1] [--page-size 10]
33
+ ```
34
+
35
+ ### 门店状态与组别
36
+ ```bash
37
+ qmai store set-status <shop-code> --status 1 --dry-run
38
+ qmai store move-team --shop-id 1001 --team-id 2001
39
+ ```
40
+
41
+ ### 配置、扩展字段与标签
42
+ ```bash
43
+ qmai store config --store-id 1001 --field-codes OrderSettingConfig:autoCancelMinutes
44
+ qmai store brand-config --field-codes OrderSettingConfig:autoCancelMinutes
45
+ qmai store ext-data --shop-id 1001
46
+ qmai store labels --shop-id 1001
47
+ ```
48
+
49
+ ### 组织结构
50
+ ```bash
51
+ qmai store org-tree [--contain-close 1]
52
+ qmai store team-list [--name 华东区]
53
+ qmai store dept-tree
54
+ ```
55
+
56
+ ### 门店同步
57
+ ```bash
58
+ qmai store sync --from-json shop.json --dry-run
59
+ qmai store sync --from-json shop.json
60
+ ```
61
+
62
+ ## 开放平台 API 端点
63
+
64
+ | 操作 | 端点 |
65
+ | --- | --- |
66
+ | 根据门店编码查询门店详情 | POST /v3/org/shop/getShopDetail |
67
+ | 批量查询门店 | POST /v3/org/shop/getShopList |
68
+ | 查询平台外卖门店映射明细 | POST /v3/dist/meTakeoutShopMapPage |
69
+ | 设置门店营业状态 | POST /v3/org/shop/changeStatus |
70
+ | 门店信息同步 | POST /v3/org/shop/shopInfoSync |
71
+ | 根据门店编码查询门店id | POST /v3/org/shop/shopCode2Id |
72
+ | 根据ID查询门店详情 | POST /v3/org/shop/getShopDetailById |
73
+ | 修改门店的组别 | POST /v3/org/shop/modifyShopTeam |
74
+ | 查询门店配置(支持批量) | POST /v3/storeConfig/queryStoreConfigBatch |
75
+ | 查询品牌配置(支持批量) | POST /v3/sellerConfig/querySellerConfigBatch |
76
+ | 查询门店扩展字段信息 | POST /v3/newPattern/orgCenter/post/shop/get-shop-ext-data |
77
+ | 查询门店标签列表 | POST /v3/newPattern/orgCenter/get/shop/label-by-id |
78
+ | 查询组织机构列表 | POST /v3/org/shop/getOrgTree |
79
+ | 查询门店组列表 | POST /v3/org/shop/shopTeamList |
80
+ | 查询门店树结构数据 | POST /v3/org/shop/shopDeptTree |
81
+
82
+ ## 注意事项(Agent 必读)
83
+
84
+ - `store get` 和 `store id` 用 `shopCode`
85
+ - `store config`、`store ext-data`、`store labels` 常用 `storeId` 或 `shopId`
86
+ - `set-status` 是变更命令,建议优先 `--dry-run`
87
+ - `sync` 字段复杂,优先用 `--from-json`
88
+ - `shopInfoSync` 可能不是立即一致,不要假设提交成功后列表立刻更新
89
+ - `getShopList` 和 `takeout-map-list` 当前是显式分页,不会自动拉全量
90
+ - `2.3 人员管理` 尚未纳入当前 `qmai store` 命令面
@@ -0,0 +1,45 @@
1
+ # 门店与组织读取指南
2
+
3
+ ## 门店详情
4
+
5
+ ```bash
6
+ # 按门店编码
7
+ qmai store get S001
8
+
9
+ # 按门店 ID
10
+ qmai store get-by-id 10001
11
+
12
+ # 门店编码转门店 ID
13
+ qmai store id S001
14
+ ```
15
+
16
+ ## 门店列表
17
+
18
+ ```bash
19
+ qmai store list --keyword 咖啡 --page 1 --page-size 10
20
+ qmai store list --contain-close 1
21
+ ```
22
+
23
+ ## 外卖映射
24
+
25
+ ```bash
26
+ # 4=美团 5=饿了么
27
+ qmai store takeout-map-list --platform-type 4
28
+ ```
29
+
30
+ ## 配置、扩展字段、标签
31
+
32
+ ```bash
33
+ qmai store config --store-id 10001 --field-codes OrderSettingConfig:autoCancelMinutes
34
+ qmai store brand-config --field-codes OrderSettingConfig:autoCancelMinutes
35
+ qmai store ext-data --shop-id 10001
36
+ qmai store labels --shop-id 10001
37
+ ```
38
+
39
+ ## 组织结构
40
+
41
+ ```bash
42
+ qmai store org-tree
43
+ qmai store team-list
44
+ qmai store dept-tree
45
+ ```
@@ -0,0 +1,44 @@
1
+ # 门店与组织写操作指南
2
+
3
+ ## 设置门店营业状态
4
+
5
+ ```bash
6
+ # 1=开启 2=关闭
7
+ qmai store set-status S001 --status 1 --dry-run
8
+ qmai store set-status S001 --status 2
9
+ ```
10
+
11
+ ## 修改门店组别
12
+
13
+ ```bash
14
+ qmai store move-team --shop-id 10001 --team-id 20001 --dry-run
15
+ qmai store move-team --shop-id 10001 --team-id 20001
16
+ ```
17
+
18
+ ## 门店信息同步
19
+
20
+ 推荐使用 JSON 文件:
21
+
22
+ ```bash
23
+ qmai store sync --from-json shop.json --dry-run
24
+ qmai store sync --from-json shop.json
25
+ ```
26
+
27
+ `shop.json` 最少应包含:
28
+
29
+ ```json
30
+ {
31
+ "name": "测试门店",
32
+ "provinceId": 310000,
33
+ "cityId": 310100,
34
+ "districtId": 310101,
35
+ "lat": "31.2304",
36
+ "lng": "121.4737",
37
+ "managerStatus": 1
38
+ }
39
+ ```
40
+
41
+ 注意:
42
+ - `sync` 副作用大,先 `--dry-run`
43
+ - `shopInfoSync` 字段很多,避免直接在命令行拼长 JSON
44
+ - 提交成功不等于立即可查到变更结果