@wkgeo/cli 1.1.4 → 2.0.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.
@@ -22,6 +22,20 @@ import { UsageError, CliError, EXIT } from '../errors.mjs';
22
22
  import { formatMoney, formatTime } from '../format.mjs';
23
23
  import { renderQrOptional } from '../qr.mjs';
24
24
 
25
+ /**
26
+ * 下单幂等键(★ 2026-11-17 task-627)。
27
+ *
28
+ * 服务端 `billing.orderCreate` 的口径:**同一键同一单**(重放回原单,含新的收银台令牌);
29
+ * 同键带不同参数回 409。CLI 不自动重试(`api.mjs` 约定),所以这里只保证
30
+ * 「每次执行 = 一次新尝试 = 一个新键」,绝不会把两次不同的购买合成一张单。
31
+ * 格式受服务端硬约束:`^[A-Za-z0-9_-]{8,80}$`。
32
+ */
33
+ function newOrderIdempotencyKey() {
34
+ const rand = Math.random().toString(36).slice(2, 11);
35
+
36
+ return `cli-quota-${Date.now().toString(36)}-${rand}`;
37
+ }
38
+
25
39
  /* ------------------------------------------------------------------ */
26
40
  /* products list */
27
41
  /* ------------------------------------------------------------------ */
@@ -180,7 +194,19 @@ export const ordersCreateCommand = {
180
194
  );
181
195
  }
182
196
 
183
- const res = await ctx.callData('createQuotaOrder', { quota_key: quotaKey, quota_amount: quotaAmount });
197
+ /**
198
+ * ★ 2026-11-17(task-627):下单**改调账务域** ——
199
+ * `/cli` → `wkgeo-cli-fc` 白名单转发 → `billing.orderCreate{kind:'quota'}`(网关 `/billing-core`)。
200
+ * 不再打 `/order` 的 `createQuotaOrder`(钱路径只留 billing 一条:
201
+ * `placeOrder` + `fulfillOrder`,金额只从 `product.price_cents` 算)。
202
+ * ⚠️ 必须带 `idempotency_key`:同键重放回原单(不会多建单、不会二次扣余额)。
203
+ */
204
+ const res = await ctx.callData('orderCreate', {
205
+ kind: 'quota',
206
+ quota_key: quotaKey,
207
+ quota_amount: quotaAmount,
208
+ idempotency_key: newOrderIdempotencyKey(),
209
+ });
184
210
  const paid = !!(res && res.paid);
185
211
  const data = {
186
212
  order_id: (res && res.order_id) || null,