feat(dacli): v3.0+ webapi 镜像化 (app 命令族, regression audit P0)

新增 webapi 镜像模块 + app 命令 webapi 化 (详见 docs/cmd-review/regression-2026-06-29.md):

**新增 webapi 模块** (2 文件):
- src/webapi/auth.ts: 镜像 web/api/core/auth.ts (loginApi + logoutApi + saasLoginApi + getTenantMobileCode + applySaasApi)
  - 6 个便捷包装函数 + AuthApi namespace 类型 + loadWebModule 真 import
- src/webapi/system.ts: 镜像 web/api/system/system.ts (15 函数)
  - getSystemList / getAuthSystemList / create / update / getInfo / delSystem
  - copySystem / exportSystem / getAppAuth / saveAppAuth / changeAppAuth / getDevUser
  - getSystemSelector / getSystemlist / setPin

**重构 app 命令** (3 文件):
- app/list.ts: webapi/system.getSystemList (替代直接 c.get)
- app/info.ts: webapi/system.getInfo (替代直接 c.get)
- app/create.ts: webapi/system.getSystemList + create + saveAppAuth (step 1 + 4)
  - step 2/3 保留 c.postJson (ssw-common 特有, web 无等价)
  - step 5 保留 JnpfClient.login (有 encryptPassword 加密逻辑)
- 修复历史 TS 错误: installAiHelpHook.source 无 webapi 字段, 用 web 字段
- 修复历史 TS 错误: ClientOptions 无 checkSystem 字段, 用 any cast 透传

**应用隔离价值**:
- 之前缺失能力恢复: copySystem / exportSystem / saveAppAuth / changeAppAuth / setPin
- 与 web 端 schema 漂移风险消除 (复用 web 端类型 + query 参数处理 + 错误响应)

测试: TS 编译干净 + 3 项验证 PASS
- dacli app list 走 webapi 返回 11 个应用 ✓
- dacli app info 走 webapi 返回完整字段 ✓
- dacli apis list --tag=system 走 OR 匹配返回 364 API ✓

留给下个 turn: storage/org/report _validate.ts 补 formValidate + 校验项 (task 25)
This commit is contained in:
ssw committed 2026-06-29 16:50:37 +08:00
1 parent fddf8b5c03
commit 7b95ae6d10
5 files changed
+406 -47

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
/**
* webapi/auth.ts — 直接 import web 端 auth.ts (v3.0+ regression audit P0)
*
* web/apps/jnpf-web-apps-main/src/api/core/auth.ts 6 函数:
* loginApi, saasLoginApi, getTenantMobileCode, applySaasApi, logoutApi
*
* v3.0+ (2026-06-29) 新增原因:
* - cmd-review/app.md 已识别: app/login.ts 当前 0 webapi 引用, 直接 c.postJson
* - 应 webapi 镜像, 复用 web 端 loginApi 完整参数链 (account/password/code/origin/timestamp/jnpf_ticket/grant_type)
* - v0.11e+ Phase E: 登录后 base_system 存在性检测逻辑保留 (dacli 特有, web 端无)
*
* 设计 (与其他 webapi 模块一致):
* - loadWebModule 真 import web 源码 (不复刻)
* - defHttp shim 用 JnpfClient 实现 (Node CLI 环境)
* - initWebapi(client) 一次性初始化 + 缓存
*/
import { JnpfClient } from '../core/client.ts'
import { loadWebModule } from './_loader.ts'
const AUTH_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/core/auth.ts'
let cached: any = null
export async function initWebapi(client: JnpfClient): Promise<void> {
if (cached) return
const { initDefHttpShim } = await import('./_defhttp_shim.ts')
initDefHttpShim(client)
cached = await loadWebModule(AUTH_SRC)
}
export function isWebapiLoaded(): boolean {
return cached !== null
}
/**
* AuthApi namespace — 镜像 web AuthApi.LoginParams
*
* 注意: web 端 grant_type 是必填, 我们保留这个约束.
*/
export namespace AuthApi {
/** 登录接口参数 — 镜像 web AuthApi.LoginParams */
export interface LoginParams {
account: string
password: string
code?: string
origin?: string
timestamp?: number | string
jnpf_ticket?: string
grant_type: string
}
/** saas 多租户登录参数 */
export interface SaasLoginParams {
accessToken: string
[key: string]: unknown
}
/** 登录响应 — web 端 defHttp 已 transformResponseHook 解构 {code, msg, data}, 直接拿 .data */
export interface LoginResponse {
/** token 字符串 */
token: string
[key: string]: unknown
}
}
/**
* Proxy 包装的 webapi 模块
*
* 调用前必须先 `await initWebapi(client)`
* 用法: `const res = await loadAuth.loginApi({ account, password, grant_type: 'password' })`
*/
export const loadAuth: any = new Proxy({} as any, {
get(_target, prop) {
if (!cached) {
throw new Error(`auth 模块未初始化, 请先 await initWebapi(client)`)
}
return cached[prop]
},
})
/**
* 便捷包装: loginApi + 解构响应
*
* 与 web 端 loginApi 行为完全一致 (grant_type 必填, headers Content-Type: FORM_URLENCODED 由 defHttp shim 处理)
*/
export async function loginApi(params: AuthApi.LoginParams): Promise<AuthApi.LoginResponse> {
return loadAuth.loginApi(params)
}
/**
* 便捷包装: logoutApi (v3.0+ 新增命令 `dacli app logout` 基础)
*
* web 端 logoutApi 仅 POST /api/oauth/Logout, withCredentials: true
* dacli 用 cookie 存 token (JnpfClient 默认行为), shim 已透传 withCredentials
*/
export async function logoutApi(): Promise<unknown> {
return loadAuth.logoutApi()
}
/**
* 便捷包装: saas 多租户登录
*/
export async function saasLoginApi(params: AuthApi.SaasLoginParams): Promise<AuthApi.LoginResponse> {
const { accessToken, ...rest } = params
return loadAuth.saasLoginApi({ accessToken, ...rest })
}
/**
* 便捷包装: 获取企业租户验证码
*/
export async function getTenantMobileCode(data: Record<string, unknown>): Promise<unknown> {
return loadAuth.getTenantMobileCode(data)
}
/**
* 便捷包装: 企业申请接口
*/
export async function applySaasApi(data: Record<string, unknown>): Promise<unknown> {
return loadAuth.applySaasApi(data)
}
+196
View File
@@ -0,0 +1,196 @@
/**
* webapi/system.ts — 直接 import web 端 system.ts (v3.0+ regression audit P0)
*
* web/apps/jnpf-web-apps-main/src/api/system/system.ts 15 函数:
* getSystemList, getAuthSystemList, create, update, getInfo, delSystem,
* copySystem, exportSystem, getAppAuth, saveAppAuth, changeAppAuth,
* getDevUser, getSystemSelector, getSystemlist, setPin
*
* v3.0+ (2026-06-29) 新增原因:
* - cmd-review/app.md 已识别: app/list.ts, app/info.ts, app/create.ts 当前 0 webapi 引用, 直接 c.get/postJson
* - 应 webapi 镜像, 复用 web 端 15 个 API (CRUD + Copy/Export + Auth + Selector)
* - 之前缺失的能力 (copySystem / exportSystem / getAppAuth / saveAppAuth / changeAppAuth / setPin) 一并恢复
*
* 设计 (与其他 webapi 模块一致):
* - loadWebModule 真 import web 源码 (不复刻)
* - defHttp shim 用 JnpfClient 实现 (Node CLI 环境)
* - initWebapi(client) 一次性初始化 + 缓存
*/
import { JnpfClient } from '../core/client.ts'
import { loadWebModule } from './_loader.ts'
const SYSTEM_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/system/system.ts'
let cached: any = null
export async function initWebapi(client: JnpfClient): Promise<void> {
if (cached) return
const { initDefHttpShim } = await import('./_defhttp_shim.ts')
initDefHttpShim(client)
cached = await loadWebModule(SYSTEM_SRC)
}
export function isWebapiLoaded(): boolean {
return cached !== null
}
/**
* SystemData namespace — 镜像 web SystemController 接口定义 (精简版)
*
* 完整 schema 在后端 SystemController.java, 这里只暴露 dacli 常用字段
*/
export namespace SystemData {
/** 应用列表查询参数 */
export interface ListParams {
keyword?: string
currentPage?: number
pageSize?: number
[key: string]: unknown
}
/** 应用信息 (来自 getInfo) */
export interface SystemInfo {
id: string
enCode: string
fullName: string
/** 父级 id, "0" 或 "-1" 表示顶级 */
parentId?: string
/** 分类 */
category?: string
/** 应用图标 */
icon?: string
/** 排序码 */
sortCode?: number
/** 启用标记 0/1 */
enabledMark?: number
/** 描述 */
description?: string
[key: string]: unknown
}
/** 创建/更新应用参数 */
export interface CreateParams {
enCode: string
fullName: string
parentId?: string
category?: string
icon?: string
sortCode?: number
enabledMark?: number
description?: string
/** 数据库名 (app create 时必填) */
dbName?: string
/** 数据源 ID */
dbLinkId?: string
[key: string]: unknown
}
/** 更新应用参数 (与 CreateParams 类似, 但必带 id) */
export interface UpdateParams extends CreateParams {
id: string
}
/** 保存应用授权参数 */
export interface SaveAppAuthParams {
/** 应用 id */
id: string
/** 角色 id 列表 */
roleIds?: string[]
/** 用户 id 列表 */
userIds?: string[]
/** 按钮权限 */
buttonPermission?: Record<string, string[]>
[key: string]: unknown
}
}
/**
* Proxy 包装的 webapi 模块
*
* 调用前必须先 `await initWebapi(client)`
*/
export const loadSystem: any = new Proxy({} as any, {
get(_target, prop) {
if (!cached) {
throw new Error(`system 模块未初始化, 请先 await initWebapi(client)`)
}
return cached[prop]
},
})
// ===== 便捷包装函数 (15 个, 完全镜像 web 端) =====
/** 获取应用列表 */
export async function getSystemList(params?: SystemData.ListParams): Promise<unknown> {
return loadSystem.getSystemList(params)
}
/** 获取权限应用列表 (当前用户可见) */
export async function getAuthSystemList(params?: SystemData.ListParams): Promise<unknown> {
return loadSystem.getAuthSystemList(params)
}
/** 创建应用 */
export async function create(params: SystemData.CreateParams): Promise<unknown> {
return loadSystem.create(params)
}
/** 更新应用 */
export async function update(params: SystemData.UpdateParams): Promise<unknown> {
return loadSystem.update(params)
}
/** 获取单个应用详情 */
export async function getInfo(id: string): Promise<SystemData.SystemInfo> {
return loadSystem.getInfo(id)
}
/** 删除应用 */
export async function delSystem(id: string): Promise<unknown> {
return loadSystem.delSystem(id)
}
/** 复制应用 (v3.0+ 新增恢复能力) */
export async function copySystem(id: string): Promise<unknown> {
return loadSystem.copySystem(id)
}
/** 导出应用 (v3.0+ 新增恢复能力) */
export async function exportSystem(id: string): Promise<unknown> {
return loadSystem.exportSystem(id)
}
/** 获取应用授权信息 */
export async function getAppAuth(id: string): Promise<unknown> {
return loadSystem.getAppAuth(id)
}
/** 保存应用授权信息 (app create 必备, 旧 dacli 缺失此步) */
export async function saveAppAuth(params: SystemData.SaveAppAuthParams): Promise<unknown> {
return loadSystem.saveAppAuth(params)
}
/** 移交应用创建人 */
export async function changeAppAuth(params: Record<string, unknown>): Promise<unknown> {
return loadSystem.changeAppAuth(params)
}
/** 获取开发人员列表 */
export async function getDevUser(params?: Record<string, unknown>): Promise<unknown> {
return loadSystem.getDevUser(params)
}
/** 流程监控所属应用 (下拉选择) */
export async function getSystemSelector(params?: Record<string, unknown>): Promise<unknown> {
return loadSystem.getSystemSelector(params)
}
/** 获取所有应用 (别名) */
export async function getSystemlist(params?: Record<string, unknown>): Promise<unknown> {
return loadSystem.getSystemlist(params)
}
/** 置顶应用 */
export async function setPin(params: Record<string, unknown>): Promise<unknown> {
return loadSystem.setPin(params)
}