feat(msg-templatecreate): v0.11e+ step machine + enhanceFromBackend (Phase D1)

msg/templatecreate.ts:
- import validateMsgCreate + enhanceFromBackend/formatErrorLine
- 跑 step machine (fullName/enCode 必填 + MSERR114 系统编码规则禁止 sys_/system_ 开头)
- catch 后端错时 enhanceFromBackend
This commit is contained in:
ssw committed 2026-06-27 03:50:19 +08:00
1 parent df29f18829
commit 9432b65a20
1 file changed
+21 -2
+21 -2
View File
@@ -1,5 +1,5 @@
/**
* commands/msg/templatecreate.ts — 新建消息模板
* commands/msg/templatecreate.ts — 新建消息模板 (v0.11e+ Phase D1 wire up)
*
* 走 JNPF MessageTemplateConfig 端点 (web 真实端点, v0.11+ P0 修复)
*
@@ -11,6 +11,8 @@ import { Command } from 'commander'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
import { validateMsgCreate } from './_validate.ts'
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
interface CreateOpts {
fullName: string
@@ -31,6 +33,22 @@ export function buildMsgTemplateCreateCommand(): Command {
.option('--json', '原始 JSON 输出', false)
.action(async (opts: CreateOpts) => {
const c = await JnpfClient.fromToken()
// v0.11e+ Phase D1: step machine 校验 (fullName/enCode 必填 + MSERR114 系统编码规则)
const validation = validateMsgCreate({
fullName: opts.fullName,
enCode: opts.enCode,
})
if (!validation.ok) {
for (const s of validation.steps) {
for (const e of s.errors) {
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
}
}
process.exit(1)
}
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
const body = {
fullName: opts.fullName,
enCode: opts.enCode,
@@ -42,7 +60,8 @@ export function buildMsgTemplateCreateCommand(): Command {
// web 端真实端点: /api/message/MessageTemplateConfig
const r = await c.postJson<{ id?: string }>('/message/MessageTemplateConfig', body)
if (r.code !== 200) {
log.error(`msg templatecreate 失败 (code=${r.code}): ${r.msg}`)
const enhanced = enhanceFromBackend(r.msg || '', 'msgTemplate', { entity: 'msg' })
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
process.exit(1)
}
let id = r.data?.id