@blod-nm/1kuan-act-01-cli 0.2.2 → 0.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blod-nm/1kuan-act-01-cli",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "type": "module",
5
5
  "description": "Internal operations CLI: invoke preset database functions via a gateway. Zero dependencies, MCP (stdio) support.",
6
6
  "license": "MIT",
package/src/main.js CHANGED
@@ -70,6 +70,9 @@ async function readStdinText() {
70
70
  return Buffer.concat(chunks).toString('utf8').trim()
71
71
  }
72
72
 
73
+ /** 领取入口提示:二维码内容是站内 goto 协议,要在我们小程序里扫 */
74
+ const SCAN_TIP = '打开我们的「1010」小程序 →「我的」→「常用」→「扫码支付」,扫上面二维码即可领取'
75
+
73
76
  /** 网关可能把 jsonb 当字符串回,统一解析一次 */
74
77
  function parseJsonResult(value) {
75
78
  if (typeof value !== 'string') return value
@@ -557,9 +560,11 @@ async function cmdCreate(argv) {
557
560
  console.log('about to deduct from account and create:')
558
561
  for (const line of confirmSummary(input)) console.log(` ${line}`)
559
562
  process.stdout.write('确认执行? [y/N] ')
560
- const chunks = []
561
- for await (const chunk of process.stdin) chunks.push(chunk)
562
- const answer = Buffer.concat(chunks).toString('utf8').trim().toLowerCase()
563
+ // 只读一行:TTY 的 stdin 不会 EOF,for-await 会永远等下一个字节
564
+ const readline = await import('node:readline')
565
+ const rl = readline.createInterface({ input: process.stdin, output: process.stderr })
566
+ const answer = await new Promise((resolve) => rl.question('', (a) => resolve(String(a).trim().toLowerCase())))
567
+ rl.close()
563
568
  if (answer !== 'y' && answer !== 'yes') {
564
569
  console.log('已取消')
565
570
  return 130
@@ -617,7 +622,7 @@ async function cmdCreate(argv) {
617
622
  result,
618
623
  balanceBefore: balance,
619
624
  balanceAfter,
620
- qr: qrContent ? { content: qrContent, format: qrMode, path: qrPath } : null,
625
+ qr: qrContent ? { content: qrContent, format: qrMode, path: qrPath, tip: SCAN_TIP } : null,
621
626
  })
622
627
  } else {
623
628
  console.log(`红包编号 ${packetNo || '(未返回)'}`)
@@ -634,6 +639,7 @@ async function cmdCreate(argv) {
634
639
  process.stderr.write(`${renderAnsi(qr, { color: process.env.NO_COLOR === undefined })}\n`)
635
640
  }
636
641
  if (qrPath) console.error(`二维码已写入: ${qrPath}`)
642
+ if (qrContent) console.error(`提示: ${SCAN_TIP}`)
637
643
  console.error('hint: deducted; recall is not supported — lifecycle is TTL-driven')
638
644
  return 0
639
645
  }
package/src/mcp.js CHANGED
@@ -93,7 +93,9 @@ function withClaimTarget(raw) {
93
93
  if (!result || typeof result !== 'object') return result
94
94
 
95
95
  const packetNo = String(result.packet?.data?.packet_no || result.packet?.packet_no || '').trim()
96
- return packetNo ? { ...result, qr: { content: claimTarget(packetNo) } } : result
96
+ return packetNo
97
+ ? { ...result, qr: { content: claimTarget(packetNo), tip: '打开我们的「1010」小程序 →「我的」→「常用」→「扫码支付」,扫码即可领取' } }
98
+ : result
97
99
  }
98
100
 
99
101
  /** 导出仅为测试:mock tcb 后可以直接断言工具返回形状 */
package/src/tcb.js CHANGED
@@ -39,6 +39,8 @@ export const ACCOUNT_SQL = `
39
39
  export async function execPgsql(config, apikey, sql) {
40
40
  const base = gatewayBase(config)
41
41
  let res
42
+ const abort = new AbortController()
43
+ const timer = setTimeout(() => abort.abort(), 45000)
42
44
  try {
43
45
  res = await fetch(`${base}/v1/rdb/exec-pgsql`, {
44
46
  method: 'POST',
@@ -47,9 +49,13 @@ export async function execPgsql(config, apikey, sql) {
47
49
  Authorization: `Bearer ${apikey}`,
48
50
  },
49
51
  body: JSON.stringify({ sql, role: PG_ROLE }),
52
+ signal: abort.signal,
50
53
  })
51
54
  } catch (err) {
52
- throw new Error(`网关连接失败:${err instanceof Error ? err.message : String(err)}`)
55
+ const timedOut = err instanceof Error && err.name === 'AbortError'
56
+ throw new Error(timedOut ? '网关请求超时(45s)' : `网关连接失败:${err instanceof Error ? err.message : String(err)}`)
57
+ } finally {
58
+ clearTimeout(timer)
53
59
  }
54
60
 
55
61
  const text = await res.text()
package/src/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * (test/version.test.js 会断言两者一致,防止再漏升)。
4
4
  */
5
5
 
6
- export const VERSION = '0.2.2'
6
+ export const VERSION = '0.2.4'