@waffo/pancake-cli 0.0.0-stage → 0.0.1-rc.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/CONTRIBUTING.md +38 -0
  3. package/LICENSE +21 -0
  4. package/README.md +218 -2
  5. package/SECURITY.md +23 -0
  6. package/SKILL.md +108 -0
  7. package/dist/adapters/browser-login.js +210 -0
  8. package/dist/adapters/config.js +133 -0
  9. package/dist/adapters/files.js +222 -0
  10. package/dist/adapters/loopback-forward.js +33 -0
  11. package/dist/adapters/operations.js +89 -0
  12. package/dist/adapters/pancake/client.js +238 -0
  13. package/dist/adapters/pancake/conflict-error.js +18 -0
  14. package/dist/adapters/pancake/graphql-errors.js +41 -0
  15. package/dist/adapters/pancake/http-error-reason.js +12 -0
  16. package/dist/adapters/pancake/queries.js +9 -0
  17. package/dist/adapters/pancake/safe-reason.js +23 -0
  18. package/dist/adapters/system-process.js +12 -0
  19. package/dist/application/action-result.js +41 -0
  20. package/dist/application/api-actions.js +82 -0
  21. package/dist/application/api-reads.js +56 -0
  22. package/dist/application/auth-context.js +34 -0
  23. package/dist/application/auth.js +112 -0
  24. package/dist/application/confirmation.js +14 -0
  25. package/dist/application/diagnostics.js +48 -0
  26. package/dist/application/dispatch.js +107 -0
  27. package/dist/application/listen.js +147 -0
  28. package/dist/application/local.js +35 -0
  29. package/dist/application/product-verification.js +96 -0
  30. package/dist/application/products.js +72 -0
  31. package/dist/application/queries.js +26 -0
  32. package/dist/application/read-handlers.js +30 -0
  33. package/dist/application/read-operation.js +30 -0
  34. package/dist/application/webhooks.js +59 -0
  35. package/dist/cli/guidance.js +29 -0
  36. package/dist/cli/human-output.js +44 -0
  37. package/dist/cli/input.js +62 -0
  38. package/dist/cli/listen-output.js +10 -0
  39. package/dist/cli/login-prompt.js +66 -0
  40. package/dist/cli/output.js +43 -0
  41. package/dist/cli/run.js +128 -0
  42. package/dist/commands/action-definitions.js +75 -0
  43. package/dist/commands/action-schemas.js +47 -0
  44. package/dist/commands/action-values.js +11 -0
  45. package/dist/commands/api-coverage.js +24 -0
  46. package/dist/commands/checkout-action-schema.js +25 -0
  47. package/dist/commands/discount-definitions.js +43 -0
  48. package/dist/commands/discount-schemas.js +39 -0
  49. package/dist/commands/discount-validation.js +17 -0
  50. package/dist/commands/listen-input.js +12 -0
  51. package/dist/commands/operation-impact.js +16 -0
  52. package/dist/commands/product-action-schemas.js +26 -0
  53. package/dist/commands/read-definitions.js +92 -0
  54. package/dist/commands/read-query.js +49 -0
  55. package/dist/commands/read-schemas.js +17 -0
  56. package/dist/commands/registry.js +45 -0
  57. package/dist/commands/schemas.js +94 -0
  58. package/dist/contracts/command.js +1 -0
  59. package/dist/contracts/errors.js +26 -0
  60. package/dist/contracts/impact.js +1 -0
  61. package/dist/contracts/listen.js +1 -0
  62. package/dist/contracts/loopback-target.js +14 -0
  63. package/dist/contracts/types.js +1 -0
  64. package/dist/index.js +20 -0
  65. package/docs/api-coverage.md +154 -0
  66. package/docs/usage.md +455 -0
  67. package/package.json +60 -4
package/docs/usage.md ADDED
@@ -0,0 +1,455 @@
1
+ # Pancake CLI 使用说明
2
+
3
+ ## Browser login
4
+
5
+ After signing in, check the account and code against your terminal, then click **Authorize CLI**. Only approve a login you started yourself. Authorization expires after 15 minutes; run login again if it expires. The CLI polls for authorization, verifies and saves its separate session, then confirms completion to the page. You can close the tab afterward. If final confirmation fails, the CLI reports an unconfirmed login and asks you to log in again; that credential may expire within five minutes. Deny, expiry or cancellation before saving preserves the existing login.
6
+
7
+ Run `pnpm cli login` in a terminal, complete Dashboard sign-in, then use `pnpm cli env test` or `pnpm cli env prod`. The CLI verifies the merchant and environment before saving a separate private session. Failed login or environment changes preserve the saved credentials. Environment selection stops if another command has changed or cleared the saved login. Browser-session writes stop before sending when the gateway cannot confirm the selected environment; conflicting evidence in a write response is treated as an unknown outcome, never a safe retry. `logout` revokes the saved browser session before clearing local credentials. RSA logout only clears local references.
8
+
9
+ View CLI sessions under Dashboard → Settings → Security. With the matching service support, new logins show the CLI version, operating system, masked IP and approximate IP-based location. Location may be unavailable or reflect a VPN/proxy exit; existing sessions are not backfilled.
10
+
11
+ Use `pnpm cli login --key-login` for the RSA prompt, or explicit Merchant ID/key-file flags for automation. RSA keys keep their server-assigned environment. Browser login requires the new Dashboard, gateway and user-service routes to be deployed. For local integration, pass `--dashboard-url http://127.0.0.1:3000 --api-url http://127.0.0.1:3002` to login.
12
+
13
+
14
+ 适用版本:0.0.1-rc.1 候选版。以下示例中的 `pnpm cli` 用于源码目录;通过 npm 安装后,替换为 `pancake`,其余参数不变。本说明随安装包提供,无需 GitHub 权限。
15
+
16
+ ## 当前能力与边界
17
+
18
+ | 能力 | 当前状态 |
19
+ | --- | --- |
20
+ | 单凭证登录/退出、当前身份、店铺/商品查询 | 已实现;部分流程已有隔离 Test 环境证据,完整验收待完成 |
21
+ | webhook 查询、添加、修改、删除 | 已实现;写入只允许测试回调配置 |
22
+ | 店铺、商品、订阅商品组管理 | 创建、修改、状态与发布等商户 Actions;真实操作必须加 `--yes` |
23
+ | 结账、订阅取消、退款工单、客户 Token、通知联系人、内容检查 | 已实现;Token/结账链接必须导出到私有文件 |
24
+ | 商品列表/版本、订单、支付、退款、联系人、商户查询 | 显式只读命令;另提供只读 GraphQL / analytics |
25
+ | 命令发现、输入 schema、JSON、非交互 | 已实现 |
26
+ | 操作记录、脱敏调试、自检、诊断导出 | 已实现 |
27
+ | 本地 webhook 监听 | 已实现;仅浏览器会话,需要独立部署 relay/gateway 支持 |
28
+ | 模拟事件发送 | 尚未实现 |
29
+ | npm / npx / Homebrew 正式分发 | 流程已准备;首次正式发版尚未执行 |
30
+
31
+ 当前注册表共 **62 条命令**,覆盖官方索引中的 **33 个商户 API-Key REST 路由**;字段和认证限制见[完整覆盖矩阵](api-coverage.md)。这不代表所有客户侧接口或所有可选字段均开放。
32
+
33
+ 后端通过匹配 RSA 密钥区分测试和生产,两种密钥均可登录。CLI 已接入网关的 `X-Waffo-Environment: test|prod` 响应头,登录、查询结果和调试记录使用本次请求的环境,不需要用户手选。
34
+
35
+ **部署边界:** 环境响应头、网页登录和本地监听依赖配套服务独立部署;隔离 Test 环境已取得部分验证证据,生产可用性尚未确认。缺失或无效的响应头仍显示 `Environment: Unknown (unverified)`;不能把“商户身份验证成功”当成环境已确认。用 `pnpm cli whoami` 核验当前请求。
36
+
37
+ 写操作必须先验证环境并加 `--yes`。生产写入、测试发布到生产还需 `--confirm-production`;店铺和通知收件人变更属于测试/生产共享配置,还需 `--confirm-shared`,在生产执行时两个确认都要有。无需再次网页登录,原有后端权限不变。预览会说明影响范围和所需确认,但离线无法验证当前环境;实际执行和操作记录会标明 `impact`:`test`、`prod`、`shared` 或 `test-to-prod`。未知结果不自动重试,Webhook 写入仍仅限测试。
38
+
39
+ 网页登录首次默认 Test,不弹环境选择。同一账号在同一 API 服务重新登录时保留 CLI 已选环境;更换账号或 API 服务则回到 Test。网页后台切换不影响 CLI。用 `pnpm cli env test` / `pnpm cli env prod` 主动切换,后端验证成功后才保存。
40
+
41
+ ## 1. 不发版也能运行与测试
42
+
43
+ 开发推荐 Node.js 24 LTS;开发和安装后的 CLI 均要求 Node.js >=22.14,固定的 pnpm 11.25.0 支持此最低版本。
44
+
45
+ 项目统一使用 pnpm 11.25.0。首次在自己的电脑上安装:
46
+
47
+ ```sh
48
+ npm install -g pnpm@11.25.0
49
+ ```
50
+
51
+ 以下命令在项目目录运行。`pnpm cli` 后直接接命令和参数,不需要 npm 的 `--` 分隔符。
52
+
53
+ ```sh
54
+ pnpm install --frozen-lockfile
55
+ pnpm run check
56
+ pnpm cli --help
57
+ pnpm cli commands --json
58
+ pnpm cli schema webhook.add --json
59
+ ```
60
+
61
+ `pnpm run check` 执行类型检查、自动测试与构建。测试使用模拟响应,不调用真实商户 API,也不会发布包。
62
+
63
+ 本地检查、安装包验证和远端联调分别记录,不固定测试数量;以当前检查结果为准。2026-11-04 的隔离 Test 环境回归验证了首次网页登录、商品价格精度与回读、价格整体替换提示、客户 Token 认证限制及错误原因/请求编号。这不代表完整跨平台、生产或正式发布验收。
64
+
65
+ 构建使用 TypeScript 官方编译器,将源码编译为 `dist/` 下的多个 ESM JavaScript 模块;安装包保留完整模块目录。Commander 继续负责命令、参数和帮助信息。`pnpm cli` 仍运行 `node dist/index.js`。
66
+
67
+ 日常改代码时,在项目目录打开两个终端。第一个保持自动构建运行:
68
+
69
+ ```sh
70
+ pnpm dev
71
+ ```
72
+
73
+ 看到构建成功后,在第二个终端运行:
74
+
75
+ ```sh
76
+ pnpm cli commands --json
77
+ ```
78
+
79
+ 保存代码会触发 TypeScript 自动重新编译,编译成功后再执行 CLI 命令即可,无需手动 build,也无需执行 `npm link` / `unlink`。`dev` 只负责自动构建,不会启动 API 服务,也不会让全局 `pancake` 命令自动出现。下文统一使用 `pnpm cli`;将 JSON 交给其他程序处理时,使用 `pnpm --silent cli commands --json`,避免 pnpm 的脚本提示混入输出。
80
+
81
+ 删除或重命名源码后,TypeScript 监听模式可能保留旧产物;重启 `pnpm dev` 或运行 `pnpm run build` 会清理后重新编译。`pnpm run pack:release` 也会先清理并重新构建。
82
+
83
+ 还可以验证实际安装包:
84
+
85
+ ```sh
86
+ pnpm run pack:release
87
+ pnpm run test:package
88
+ ```
89
+
90
+ 第二步只在第一步成功后执行。安装包测试会联网下载 npm 依赖,在临时目录验证 npm exec(npx)和全局命令安装,不会发版。安装包与开发源码分开验证。
91
+
92
+ ## 2. 登录、查看当前身份和退出
93
+
94
+ 首次使用先运行 `pnpm cli`,终端以简洁英文显示获取凭证、登录和查看店铺的步骤。`pnpm cli commands` 显示简洁命令列表;带 `--json` 或管道输出时仍返回完整机器格式。
95
+
96
+ 获取凭证:在 Pancake 控制台进入 **API & Development → API Keys**,首次试用选择 Test,创建密钥后下载私钥文件。准备该商户的 Merchant ID(`MER_` 开头,不是 `STO_` 店铺 ID);找不到时向商户管理员获取。参阅[官方说明](https://docs.waffo.ai/api-reference/authentication)。
97
+
98
+ `pnpm cli login` 默认打开网页登录授权;如需输入已有 Merchant ID 和 RSA 私钥,使用 `pnpm cli login --key-login`。登录前取消会显示 `Cancelled.`,退出码为 130,并保留原有凭证;已发起的网页授权会自动过期。写操作开始执行后中断则提示结果可能未知,需要先查询核实。
99
+
100
+ 普通终端中的 `whoami` 会直接提示是否登录及下一步;本地 pnpm/npm 入口的帮助使用对应本地命令,安装后的入口使用 `pancake`。机器模式保留标准 JSON 协议和正式命令名。
101
+
102
+ 准备自己的 Merchant ID 和 RSA 私钥文件,不要把私钥正文放在命令参数里。macOS/Linux 应先限制文件权限:
103
+
104
+ ```sh
105
+ chmod 600 /absolute/path/key.pem
106
+ pnpm cli login --merchant-id MER_example --private-key-file /absolute/path/key.pem --store-id STO_example --json
107
+ pnpm cli whoami --json
108
+ pnpm cli doctor --debug --json
109
+ ```
110
+
111
+ 示例中的 ID 和路径均须替换。Windows 使用当前账户的私有文件访问权限,不运行 `chmod`。
112
+
113
+ `login` 先验证本地 RSA 密钥,再联网确认商户身份,成功后只保存密钥文件的绝对路径和商户信息。一次只保存一套凭证。新凭证验证成功后自动覆盖旧登录,无需退出或 `--force`。交互输入会自动识别私钥正文或文件路径,输入过程隐藏;粘贴的私钥保存为本机仅当前用户可访问的文件。验证失败保留原有配置。
114
+
115
+ `--merchant-id` 和 `--private-key-file` 仅供 `login` 使用;业务命令读取当前凭证。`--store-id` 在登录时保存默认店铺,在业务命令中覆盖本次店铺。只有交互终端且未指定 `--json` / `--no-interactive` 时,RSA 登录(`--key-login` 或显式密钥参数)才会询问缺少的 Merchant ID 和私钥(正文或文件路径,自动识别)。
116
+
117
+ `whoami` 联网验证实际生效的商户身份,并返回来源 `stored` 或 `environment`。没有任何凭证时本地返回 `authenticated:false`,不联网。身份验证和环境验证是两回事:身份验证成功时 `credentialVerified:true`;网关确认环境后同时返回 `actualEnvironment:test|prod`、`environmentVerified:true`。只有网关未提供有效环境信息时,才返回 `actualEnvironment:null`、`environmentVerified:false`。不要把商户 ID 或密钥文件名作为环境依据。
118
+
119
+ `doctor` 检查配置、密钥、连接与身份;已选店铺时同时检查该店铺查询权限。只有网关无法确认环境时,才会以 `ENVIRONMENT_UNVERIFIED` 和非零退出码提示环境缺口。
120
+
121
+ ```sh
122
+ pnpm cli config show --json
123
+ pnpm cli logout --json
124
+ pnpm cli whoami --json
125
+ ```
126
+
127
+ `config show` 隐藏密钥路径,只展示当前保存的凭证与环境变量覆盖状态。浏览器登录的 `logout` 会先撤销当前 CLI 的服务端会话,再清空本地凭证;网络失败时保留凭证并提示到 Dashboard 安全设置撤销。RSA 退出只清本地引用,不吊销 API Key,保留用户原始私钥文件与操作记录。
128
+
129
+ 自动化可通过秘密环境变量注入 `WAFFO_MERCHANT_ID`,并且只提供 `WAFFO_PRIVATE_KEY_FILE`、`WAFFO_PRIVATE_KEY` 中的一项。完整环境变量凭证优先于保存的登录;不同来源不拼接,半套或格式错误的凭证直接报错。环境变量凭证不继承保存的默认店铺。
130
+
131
+ 存在任何上述凭证环境变量时,登录结果明确返回 `savedLoginActive:false` 并给出警告,不会宣称新保存的登录已生效;退出也会提示环境凭证仍然存在。需要使用保存的登录或彻底退出时,从当前进程环境中移除这三个变量。登录验证结果的 `source:login` 表示本次显式提供的凭证;后续 `whoami` 才表示实际生效的身份。
132
+
133
+ ## 3. 查询店铺和商品
134
+
135
+ ```sh
136
+ pnpm cli stores list --limit 20 --offset 0 --fields id,name,status --json
137
+ pnpm cli products get PROD_example --type onetime --json
138
+ pnpm cli products get PROD_example --type subscription --json
139
+ ```
140
+
141
+ 店铺查询每页最多 100 条。当返回条数恰好等于 limit 时,`hasMore` 为 `"unknown"`,可按 `nextOffset` 继续查询;不会宣称必然还有下一页。
142
+
143
+ ## 4. 预览与创建商品
144
+
145
+ 创建 `product.json`:
146
+
147
+ ```json
148
+ {
149
+ "storeId": "STO_example",
150
+ "name": "Demo product",
151
+ "prices": {
152
+ "USD": { "amount": "19.99", "taxCategory": "saas" }
153
+ }
154
+ }
155
+ ```
156
+
157
+ ```sh
158
+ pnpm cli products create --type onetime --file product.json --dry-run --json
159
+ ```
160
+
161
+ 金额必须是字符串,例如 `"19.99"`,避免数值精度变化。订阅商品还需要 `billingPeriod`;用 `schema products.create` 查看当前输入约束。传试用价时需提供正整数 `metadata.trialDays`,且试用价小于正常价格。
162
+
163
+ 离线预览不读取凭证、不联网、不写记录。它只证明本地校验通过,不证明权限、环境或服务端接受该请求。确认商户、密钥来源、店铺和商品内容后,可执行真实创建:
164
+
165
+ ```sh
166
+ pnpm cli products create --type onetime --file product.json --yes --idempotency-key MER_example_product_001 --json
167
+ ```
168
+
169
+ 此命令会真实创建商品。以上示例用于测试;生产操作还须加 `--confirm-production`。后端通过 RSA 密钥选择环境;`--yes` 确认操作意图,不证明环境是测试。执行前 stderr 展示商户、来源、店铺、商品名称和价格及环境警告;stdout 保持一个 JSON 结果。未加 `--yes` 时只返回确认要求和可获得的上下文,不加载私钥或联网。
170
+
171
+ 订阅商品示例 `subscription.json`:
172
+
173
+ ```json
174
+ {
175
+ "storeId": "STO_example",
176
+ "name": "Monthly plan",
177
+ "billingPeriod": "monthly",
178
+ "prices": { "USD": { "amount": "19.99", "taxCategory": "saas", "trialAmount": "1.00" } },
179
+ "metadata": { "trialDays": 7 }
180
+ }
181
+ ```
182
+
183
+ ```sh
184
+ pnpm cli products create --type subscription --file subscription.json --dry-run --json
185
+ pnpm cli products create --type subscription --file subscription.json --yes --idempotency-key MER_example_plan_001 --json
186
+ ```
187
+
188
+ 商品创建和修改会在联网前校验普通价格与试用价格的小数精度:USD 最多两位、JPY 不允许非零小数,BHD/KWD/OMR 最多三位;规则与服务端金额转换一致,末尾零不改变金额。超出精度直接拒绝,不自动四舍五入。
189
+
190
+ 服务端固定使用税外价格;不要传 `taxIncluded`,CLI 会拒绝该字段,避免配置被服务端静默忽略。商品创建成功结果仅展示 ID、店铺、类型、名称、价格、状态和可用时间字段,不输出描述、metadata 或 URL。
191
+
192
+ 每次写入前必须持久化操作意图,写请求只发一次;成功响应后保存商品 ID,再只读回查核验。保留操作 ID 和幂等 key。响应或回读中的金额明确与请求不符时报告 `PRICE_MISMATCH`,操作保留为 `committed_unverified`,不要重放写入;先检查商品当前价格。遇到 `VERIFICATION_PENDING`,按错误中的命令执行 `products get` 并查看 `operations show`,不要再次创建。遇到 `OUTCOME_UNKNOWN` 且没有商品 ID,先按记录中的店铺在商户后台查找;不能换新 key 重试。只读查询不会自动把旧操作记录改为已完成。
193
+
194
+ ## 5. 管理测试 webhook
195
+
196
+ 现有 API 已支持回调配置管理,CLI 直接封装即可,不要求新增后端接口。接收通知的 URL 应由你准备;临时本地监听见 [listen 说明](#local-webhook-listening),CLI 不管理隧道。
197
+
198
+ 创建 `webhook.json`(请替换为真实测试店铺和接收地址):
199
+
200
+ ```json
201
+ {
202
+ "storeId": "STO_example",
203
+ "channel": "http",
204
+ "url": "https://example.com/webhooks/pancake",
205
+ "events": ["order.completed"],
206
+ "testMode": true
207
+ }
208
+ ```
209
+
210
+ ```sh
211
+ pnpm cli webhook list --store-id STO_example --json
212
+ pnpm cli webhook add --file webhook.json --dry-run --json
213
+ pnpm cli webhook add --file webhook.json --yes --idempotency-key MER_example_demo_001 --json
214
+ ```
215
+
216
+ 最后一条会真实修改测试 webhook 配置。预览会隐藏 URL 和 secret,执行前应检查自己的输入文件。`--yes` 仅确认操作意图,不绕过校验、权限或测试资源限制。
217
+
218
+ 修改 `changes.json` 示例:
219
+
220
+ ```json
221
+ { "events": ["order.completed", "refund.succeeded"] }
222
+ ```
223
+
224
+ ```sh
225
+ pnpm cli webhook update WEBHOOK_UUID --store-id STO_example --file changes.json --dry-run --json
226
+ pnpm cli webhook update WEBHOOK_UUID --store-id STO_example --file changes.json --yes --json
227
+ pnpm cli webhook remove WEBHOOK_UUID --store-id STO_example --dry-run --json
228
+ pnpm cli webhook remove WEBHOOK_UUID --store-id STO_example --yes --json
229
+ ```
230
+
231
+ 将 `WEBHOOK_UUID` 替换为列表返回的 UUID。修改只允许 `url`、`events`、`secret`,其中 `secret:null` 表示清空;`channel` 和 `testMode` 不可修改。需在选定店铺找到目标且 `testMode:true` 才能修改或删除。`webhook list` 正常显示地址,secret 始终隐藏;写入摘要继续隐藏地址和 secret。
232
+
233
+ 写前记录操作意图,写后查询核验。发现信息中,新增和修改 Webhook 的 `verification:conditional` 表示默认回读核验;网页登录且传入 secret 时按 `verificationPolicy.browserSecretWrite:response_only` 处理。RSA 登录修改 secret 时仅在内存回读比较,不写日志或结果。网页登录不能读取 secret,修改后依据服务端成功响应标记 `verification:response_only`,无需再到 Dashboard 操作。写请求只发送一次;只读请求最多重试两次,受总时限约束。
234
+
235
+ ## 6. 扩展商户 API 操作与查询
236
+
237
+ 先看输入契约,再构造文件。新增 Actions 都使用 `--file`,远端执行必须加 `--yes`;支持 `--idempotency-key`,不传时生成并返回。建议自动化显式传入唯一 key,并保留操作结果。商品操作的 `--type` 不要在文件中重复提供。ID 字段名称以各命令 schema 为准;例如店铺/商品更新使用文件中的 `id`,不是位置参数。
238
+
239
+ ```sh
240
+ pnpm cli schema stores.create --json
241
+ pnpm cli schema products.update --json
242
+ pnpm cli schema checkout.create --json
243
+ pnpm cli schema refunds.create --json
244
+ pnpm cli schema sessions.create --json
245
+ ```
246
+
247
+ 例如 `store.json` 为 `{"name":"Demo store"}`,`product-change.json` 为 `{"id":"PROD_example","name":"Demo v2"}`:
248
+
249
+ ```sh
250
+ pnpm cli stores create --file store.json --dry-run --json
251
+ pnpm cli products update --type onetime --file product-change.json --dry-run --json
252
+ # 审阅输入后执行;会真实写入,可能影响生产:
253
+ pnpm cli stores create --file store.json --yes --confirm-shared --idempotency-key MER_example_store_001 --json
254
+ ```
255
+
256
+ `products update` 的 `prices` 会**替换完整价格表**,未提供的币种会被删除。修改单个币种时,也须带上其他需要保留的币种及完整价格设置;省略整个 `prices` 才会保留原价格表。预览和执行前均显示此提醒。
257
+
258
+ `products publish` 将测试商品首次发布到生产,`groups publish` 将测试组复制到生产(upsert);**目标明确是生产**。商品 `set-status` 改变可结账状态,不取消已有购买。店铺 `delete` 为软删除并使店铺不可访问;组 `delete` 永久删除组。`subscriptions cancel` 是商户取消请求,生效时间取决于当前订阅状态。`refunds create/resubmit` 创建或重新提交退款工单,不代表款项已退回。`content scan` 是无状态检查,仍要求 `--yes`、操作记录和单次 POST。
259
+
260
+ 新增 Actions 只校验响应结构,成功元数据标记 `verification:response_only`;组删除和发布标记 `acknowledgement_only`,可接受 API 的空确认。它们均未执行资源回读。原有商品创建和测试 webhook 变更继续回读核验。商品创建/修改不接受 `taxIncluded`;结账的 `priceSnapshot.taxIncluded` 是独立字段,以其 schema 为准。
261
+
262
+ `checkout.json` 最小示例为 `{"productId":"PROD_example","currency":"USD"}`;`session.json` 的客户门户示例为 `{"storeId":"STO_example","buyerIdentity":"customer@example.com","purpose":"portal"}`。只在确实需要创建这些资源时执行:
263
+
264
+ ```sh
265
+ pnpm cli checkout create --file checkout.json --dry-run --json
266
+ pnpm cli sessions create --file session.json --dry-run --json
267
+ pnpm cli checkout create --file checkout.json --yes --idempotency-key MER_example_checkout_001 --output ./checkout-result.json --json
268
+ pnpm cli sessions create --file session.json --yes --idempotency-key MER_example_session_001 --output ./session-result.json --json
269
+ ```
270
+
271
+ 这两个命令的真实执行必须指定新的 `--output` 文件。Token、门户和结账链接写入私有文件,stdout 只返回导出结果;已存在文件拒绝覆盖。POSIX 使用 0600,Windows 使用仅当前用户可访问的 ACL。`sessions create` 仅支持 RSA 密钥登录,用于代商户签发客户 Token;浏览器登录不能执行,也不用于登录或切换 CLI 身份。服务端接受后若导出或记录失败,结果是 `committed_unverified`,不能重新发起请求来取回响应。
272
+
273
+ 新增资源读取示例:
274
+
275
+ ```sh
276
+ pnpm cli stores get STO_example --json
277
+ pnpm cli products list --type onetime --store-id STO_example --limit 20 --offset 0 --json
278
+ pnpm cli products versions PROD_example --type subscription --json
279
+ pnpm cli orders list --type onetime --store-id STO_example --json
280
+ pnpm cli subscriptions list --store-id STO_example --json
281
+ pnpm cli payments list --json
282
+ pnpm cli payments get PAY_example --json
283
+ pnpm cli refunds list --json
284
+ pnpm cli refunds get RFD_example --json
285
+ pnpm cli refund-tickets list --json
286
+ pnpm cli recipients list --store-id STO_example --json
287
+ pnpm cli merchants list --json
288
+ pnpm cli merchants get MER_example --json
289
+ ```
290
+
291
+ 新增列表查询支持 `--limit`、`--offset`、`--fields` 和 `--dry-run`;有筛选条件的命令用 `--file` 提供 schema 支持的 `filter`。单次读取一页,满页只能表示 `hasMore:"unknown"`。`products versions` 是例外:API 按商品 ID 返回版本历史,不支持分页参数,也不返回分页信息。商品列表通过 `--store-id` 选择店铺,不接受 `filter.storeId`。不提供 `orders get`、`subscriptions get` 或 `groups list/get` 等未注册命令。商品组没有已确认的独立读取字段契约;需要时先通过 GraphQL introspection/官方文档确认字段,再构造自定义查询,不猜测根字段。
292
+
293
+ 自定义查询文件 `query.json`:
294
+
295
+ ```json
296
+ {"query":"query { merchants(limit: 1, offset: 0) { id } }","variables":{}}
297
+ ```
298
+
299
+ ```sh
300
+ pnpm cli graphql query --file query.json --dry-run --json
301
+ pnpm cli graphql query --file query.json --output ./query-result.json --json
302
+ pnpm cli analytics query --file analytics-query.json --output ./analytics-result.json --json
303
+ ```
304
+
305
+ `analytics-query.json` 需按[官方分析查询文档](https://docs.waffo.ai/api-reference/endpoints/graphql/analytics)提供真实字段与嵌套 selection。两个入口均只接受恰好一个 query 操作,可带变量和 fragment;在读取凭证或联网前拒绝 mutation/subscription,包括 dry-run。它们不会根据名字猜测字段敏感性,执行时必须把完整响应导出到新私有文件。没有任意 REST POST 命令。
306
+
307
+ 客户 Session Token 专属的一次性订单取消、客户侧订阅取消和恢复订阅不在商户命令范围内;商户 `subscriptions cancel` 的 API-Key 权限与客户同路径权限必须分开看待。
308
+
309
+ ## 7. AI 和脚本调用
310
+
311
+ ```sh
312
+ pnpm cli commands --json
313
+ pnpm cli schema webhook.update --json
314
+ pnpm cli stores list --no-interactive --json
315
+ ```
316
+
317
+ `schema` 包含输入字段、命令参数、全局选项、输出协议和示例。嵌套输入用 `--file path.json`;`--file -` 从 stdin 接收一个 JSON 对象。上限为 1 MiB,stdin 最多等待 5 秒。不要同时在文件和参数中指定同一字段。
318
+
319
+ 显式 `--json` 或输出被管道/重定向时,stdout 为一个 JSON 结果(`listen` 例外,使用逐行 NDJSON);`--debug` 信息和真实商品创建前的环境警告写 stderr。帮助和版本在机器模式下也包在 JSON 中。非交互调用缺参数立即报错,不弹提示。身份相关调用和已取得凭证的业务调用,在成功或失败的 `meta` 中包含 `merchantId`、`source`、`actualEnvironment` 和 `environmentVerified`;环境缺少证据时分别为 `null` 和 `false`。人类终端也展示商户、来源、当前环境验证状态和可用的操作/请求编号。
320
+
321
+ ```json
322
+ {
323
+ "schemaVersion": 1,
324
+ "ok": true,
325
+ "data": {},
326
+ "error": null,
327
+ "meta": {
328
+ "cliVersion": "0.0.0",
329
+ "outcome": "completed",
330
+ "operationId": null,
331
+ "requestId": null
332
+ }
333
+ }
334
+ ```
335
+
336
+ 上例展示输出格式,不代表实际执行了某次操作。退出码:0 成功,1 执行或核验失败,2 参数/配置错误,130 中断。`--dry-run` 成功时仍应检查 `data.executed:false`。
337
+
338
+ ## 8. 排障与追溯
339
+
340
+ ```sh
341
+ pnpm cli doctor --debug --json
342
+ pnpm cli operations list --limit 20 --json
343
+ pnpm cli operations show OPERATION_ID --json
344
+ pnpm cli diagnostics export --operation OPERATION_ID --output ./diagnostics.json --json
345
+ ```
346
+
347
+ 诊断文件只导出本地,文件已存在时拒绝覆盖;不会自动上传。私钥、签名、完整请求正文、回调 URL 和 secret 不进入记录。商户/店铺/操作编号仍会包含在诊断元数据中,分享前自行检查。
348
+
349
+ | 结果 | 处理 |
350
+ | --- | --- |
351
+ | `completed` | 操作完成;离线预览仍未发请求 |
352
+ | `rejected` | 按错误原因处理;本次要求的操作未完成 |
353
+ | `unknown` | 远端可能已经写入;保留原操作编号,先查询核验,不能换新 key 重试 |
354
+ | `committed_unverified` | 远端已接受,但回读、导出或记录更新未完成;只查询核验,不重复写入 |
355
+
356
+ `CONFLICT` 会显示后端明确拒绝操作的业务原因(如收件人已存在),操作记录为 `rejected`。网关仍在处理、网络中断或响应不完整时保守返回 `OUTCOME_UNKNOWN`;先核实原操作,不要重放。
357
+
358
+ 服务端未返回请求编号时 `requestId:null`。本地 `operationId` 不是服务端审计编号,共用密钥也无法准确归因到某位员工或 Agent。
359
+
360
+ 同一本地记录目录内,已用的幂等 key 会被阻止重放。此机制不覆盖其他电脑、不同目录或记录清理后的操作,服务端去重仍受其自身规则约束。记录上限 1000 条;新操作时清理 30 天前已完成/已拒绝记录。达到上限时,优先轮转最旧的已完成/已拒绝查询记录;未过期的写入记录、未知或待核验记录不会因此删除。若保留记录仍占满上限,写入会停止。已知目标的写操作会在发请求前记录目标 ID、接口、服务地址和所选环境,便于响应丢失后核查。
361
+
362
+ 默认目录:macOS / Linux 为 `~/.waffo-pancake`;Windows 为 `%USERPROFILE%\.waffo-pancake`。登录凭证保存在其中的 `config.json`。从旧目录升级后需重新登录;旧文件不自动迁移。可用 `WAFFO_CONFIG_DIR` 指向专用目录,不应指向多人共享目录。配置格式为版本 2,操作记录格式仍为版本 1。旧配置版本 1 不自动迁移:显式运行 `logout` 清空旧配置,再用现有密钥文件 `login`。`logout` 可重置能够安全读取的损坏配置,但拒绝符号链接和非普通文件。未知的更高版本始终拒绝改写,包括退出操作。
363
+
364
+ ## 9. 发布后的安装、更新和回退
365
+
366
+ 候选版使用 `next` 渠道,须等维护者完成 npm 发布后使用:
367
+
368
+ ```sh
369
+ npm install -g @waffo/pancake-cli@next
370
+ pancake --version
371
+ pancake login --dashboard-url <uat-dashboard-origin> --api-url <uat-api-origin>
372
+ pancake whoami
373
+ pancake env test
374
+ pancake stores list
375
+ ```
376
+
377
+ 将两个占位值替换为团队提供的 UAT 地址。默认地址指向生产;npm 发包不会部署配套服务。更新候选版仍执行 `npm install -g @waffo/pancake-cli@next`。
378
+
379
+ 下列命令用于首次稳定版发布之后:
380
+
381
+ ```sh
382
+ npm install -g @waffo/pancake-cli
383
+ pancake --help
384
+ npm install -g @waffo/pancake-cli@latest
385
+ ```
386
+
387
+ 自动化固定已经发布的具体版本:
388
+
389
+ ```sh
390
+ npx @waffo/pancake-cli@VERSION commands --json
391
+ ```
392
+
393
+ `VERSION` 替换为实际版本,不能原样运行。预发布使用 `next`;Homebrew 正式渠道需要 tap 发布流程完成后才可安装。
394
+
395
+ ```sh
396
+ brew tap waffo-com/pancake
397
+ brew install waffo-com/pancake/pancake
398
+ brew update
399
+ brew upgrade waffo-com/pancake/pancake
400
+ ```
401
+
402
+ CLI 不提供独立自更新器,任务执行中不自动换版本。回退前先检查配置/记录格式兼容性并备份;程序回退不会撤销远端已经完成的修改。版本变化见随包提供的 [CHANGELOG.md](../CHANGELOG.md)。
403
+
404
+ ## 验收尚未完成的部分
405
+
406
+ 部分浏览器登录、商品、折扣与监听流程已有 Test 环境证据,跨平台 CI 与 Windows ACL 自动测试已通过。生产完整验收、首次发布后的 npm 安装及真实 Windows 终端 Ctrl+C 验收仍需完成。本地测试与单项远端证据不替代这些验收。
407
+
408
+ 开源客户端的使用和开发不要求取得私有服务端源码。联网命令需要可访问、兼容的托管 API 与凭证;网页登录还需要兼容的 Dashboard。离线命令发现、schema 和预览不需要运行服务端。
409
+
410
+ ## Discounts
411
+
412
+ Nine commands cover coupons and promotion codes. Browser sessions and RSA keys are supported by the gateway route configuration; coupon creation requires store owner/admin permission. Other operations remain subject to server-enforced merchant, store and environment access. All nine discount commands passed isolated Test-environment merchant acceptance, including final deactivation read-back. Production and full CLI release acceptance remain unverified.
413
+
414
+ ```sh
415
+ pnpm cli coupons list --store-id STO_example --limit 20 --json
416
+ pnpm cli coupons get CPN_0000000000000000000001 --json
417
+ pnpm cli schema coupons.create --json
418
+ pnpm cli coupons create --file coupon.json --dry-run --json
419
+ pnpm cli coupons create --file coupon.json --yes --idempotency-key launch_coupon_001 --json
420
+ pnpm cli promotion-codes list --file coupon-scope.json --json
421
+ pnpm cli promotion-codes generate --file batch.json --dry-run --json
422
+ pnpm cli promotion-codes generate --file batch.json --yes --idempotency-key launch_batch_001 --json
423
+ ```
424
+
425
+ `coupon.json`:
426
+
427
+ ```json
428
+ {"storeId":"STO_example","name":"Launch discount","code":"LAUNCH","discount":{"type":"percentage","percentOff":10},"duration":"once","maxRedemptions":100}
429
+ ```
430
+
431
+ `coupon-scope.json` contains `{"couponId":"CPN_0000000000000000000001"}`. Replace the example ID with the actual returned coupon ID. `batch.json` adds `"count":10`, optionally `"prefix":"VIP-"` and `"length":10`. Generation accepts 1–500 codes, a 1–12 character prefix, and 8–16 random characters. Codes are letters, digits or hyphens, 3–32 characters; the server normalizes them to uppercase.
432
+
433
+ Fixed discounts use `"discount":{"type":"fixed_amount","amountOff":{"USD":"5.00"}}`. Amounts are positive display-format strings; currency precision is checked by the server. A repeating duration requires positive `durationInPeriods`; once/forever do not accept a non-null period count. Coupon expiry and promotion-code expiry must be more than 60 seconds in the future. Limits and applicability are checked again by the server against current coupon state.
434
+
435
+ `coupons update` accepts only `id` and `name`. `coupons deactivate` and `promotion-codes deactivate` accept `id`; deactivation is permanent and releases the code for reuse. Deactivating a coupon disables its active promotion codes. `promotion-codes create` accepts `couponId`, optional `code` and `restrictions`. Up to 20 promotion codes can also be supplied as `promotionCodes` during coupon creation. Supported restrictions are `customerEmails` (up to 100), `perCustomerLimit`, `maxRedemptions`, `expiresAt` and `minimumAmount`. `firstTimeOnly` and `dailyRedemptionLimit` are currently unsupported.
436
+
437
+ Lists accept JSON `filter` objects. Coupon filters include `status`, `name`, `code`, `anyCode`, `isExhausted`, `isExpired` and `isRedeemable`; promotion-code filters include `status`, `code` and `batchId`. For example, `"filter":{"status":{"eq":"active"}}`. Promotion-code lists exclude the coupon's own code, which is returned as `coupon.code`. `--fields` selects declared top-level fields; named promotion-code reads omit customer emails. Use an explicit arbitrary GraphQL query and private output for those emails.
438
+
439
+ Writes return a safe summary including IDs and usable codes. Batch results include `batchId` and generated codes. Customer restrictions are omitted from these summaries and diagnostics. Optional `--output` exports the full write response to a new private file. Verification is `response_only`; query the coupon/promotion codes to inspect current state. A business 409 is a rejected conflict; unknown outcomes must be investigated through operations and reads, never automatically replayed.
440
+
441
+ ## Local webhook listening
442
+
443
+ Run `pancake listen --store-id STO_example --forward-to http://localhost:3000/webhook` after browser login. Test is always the default; `--live` explicitly selects Production without saving that selection. Optional `--events order.completed,subscription.created` filters event names. Use event names supported by your backend. RSA keys cannot listen.
444
+
445
+ The loopback receiver receives the exact signed body and the allowlisted Content-Type, X-Waffo-Signature and X-Waffo-Event headers. Redirects count as failures. A 2xx response is acknowledged as success; other statuses and network failures retry up to three times. Deduplicate by eventId/deliveryId, which stays stable across attempts.
446
+
447
+ `--json` and piped output stream NDJSON standard envelopes with `ready`, `delivery`, `stopped` events and a terminal error envelope on failure. Event bodies, signatures and response bodies are omitted. Ctrl+C/SIGTERM clean up temporary sessions; kill/crash falls back to a 90-second session TTL. Polls occur every three seconds. Local forwarding times out after ten seconds. Session failures are visible and exit nonzero. The command never modifies configured webhook endpoints and provides no synthetic event trigger.
448
+
449
+ Isolated Test acceptance verified a test payment event, signatures, retry after HTTP 500, and interruption cleanup. Production listening remains unverified.
450
+
451
+ ## Browser permission limits
452
+
453
+ Browser login covers supported business commands in Test and Production within your merchant/store access. API Keys, account deletion, payout/bank changes, other devices, additional CLI authorizations, API credentials, Webhook `secret` fields and identity documents are blocked by the server. Use `logout` to revoke the current CLI session. Environment switching does not ask for another browser authorization. Re-login after the browser permission update; RSA login is unchanged.
454
+
455
+ Webhook configuration can still be changed in Test. Webhook addresses remain readable. Browser secret changes use the server success response (`verification: response_only`), without reading the secret back or requiring another Dashboard step. Raw GraphQL queries follow the same server permissions.
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "@waffo/pancake-cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1-rc.1",
4
+ "packageManager": "pnpm@11.25.0",
5
+ "description": "Developer CLI for Waffo Pancake",
6
+ "type": "module",
7
+ "bin": {
8
+ "pancake": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md",
13
+ "SKILL.md",
14
+ "CHANGELOG.md",
15
+ "CONTRIBUTING.md",
16
+ "SECURITY.md",
17
+ "docs/usage.md",
18
+ "docs/api-coverage.md"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/waffo-com/waffo-pancake-cli.git"
23
+ },
24
+ "homepage": "https://github.com/waffo-com/waffo-pancake-cli#readme",
25
+ "bugs": {
26
+ "url": "https://github.com/waffo-com/waffo-pancake-cli/issues"
27
+ },
28
+ "license": "MIT",
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "scripts": {
34
+ "build": "node scripts/clean.mjs && tsc -p tsconfig.json && node scripts/make-executable.mjs",
35
+ "dev": "node scripts/clean.mjs && tsc -p tsconfig.json --watch --preserveWatchOutput",
36
+ "cli": "node dist/index.js",
37
+ "typecheck": "tsc --noEmit",
38
+ "test": "node --experimental-strip-types --test scripts/*.test.mjs",
39
+ "check": "pnpm run typecheck && pnpm test && pnpm run build",
40
+ "pack:release": "pnpm run build && node scripts/pack.mjs",
41
+ "test:package": "node scripts/smoke-package.mjs",
42
+ "release:check": "node scripts/release-check.mjs",
43
+ "prepack": "pnpm run build",
44
+ "prepublishOnly": "pnpm run release:check"
45
+ },
46
+ "engines": {
47
+ "node": ">=22.14.0"
48
+ },
49
+ "dependencies": {
50
+ "ajv": "^8.20.0",
51
+ "commander": "^12.0.0",
52
+ "graphql": "^16.14.2",
53
+ "proper-lockfile": "^4.1.2"
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "^22.0.0",
57
+ "@types/proper-lockfile": "^4.1.4",
58
+ "cross-spawn": "^7.0.6",
59
+ "semver": "^7.8.5",
60
+ "typescript": "^5.9.0"
61
+ }
62
+ }