@wukongcrm/mcp-server 0.1.4 → 0.2.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.
- package/README.md +32 -3
- package/dist/fc-entry.d.ts +1 -0
- package/dist/fc-entry.js +7 -0
- package/dist/http-entry.js +23 -2
- package/dist/http.d.ts +6 -0
- package/dist/http.js +298 -1
- package/dist/nocode.d.ts +16 -0
- package/dist/nocode.js +1086 -0
- package/dist/oauth-state.d.ts +94 -0
- package/dist/oauth-state.js +310 -0
- package/dist/oauth.d.ts +13 -25
- package/dist/oauth.js +188 -142
- package/dist/server.js +26 -6
- package/package.json +5 -3
package/dist/nocode.js
ADDED
|
@@ -0,0 +1,1086 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CrmClient } from "./client.js";
|
|
3
|
+
const idSchema = z.union([z.string(), z.number()]);
|
|
4
|
+
const payloadSchema = z.record(z.unknown());
|
|
5
|
+
const confirmSchema = z.boolean().optional();
|
|
6
|
+
const versionSchema = z.number().int().nonnegative().optional();
|
|
7
|
+
const moduleContextShape = {
|
|
8
|
+
moduleId: idSchema,
|
|
9
|
+
version: versionSchema,
|
|
10
|
+
categoryId: idSchema.optional()
|
|
11
|
+
};
|
|
12
|
+
const payloadWriteShape = {
|
|
13
|
+
payload: payloadSchema,
|
|
14
|
+
confirm: confirmSchema
|
|
15
|
+
};
|
|
16
|
+
const extendedContextShape = {
|
|
17
|
+
applicationId: idSchema.optional(),
|
|
18
|
+
moduleId: idSchema.optional(),
|
|
19
|
+
targetModuleId: idSchema.optional(),
|
|
20
|
+
dataId: idSchema.optional(),
|
|
21
|
+
tabId: idSchema.optional(),
|
|
22
|
+
stageId: idSchema.optional(),
|
|
23
|
+
followUpId: idSchema.optional(),
|
|
24
|
+
recordId: idSchema.optional(),
|
|
25
|
+
commentId: idSchema.optional(),
|
|
26
|
+
ruleId: idSchema.optional(),
|
|
27
|
+
noticeId: idSchema.optional(),
|
|
28
|
+
categoryId: idSchema.optional(),
|
|
29
|
+
typeId: idSchema.optional(),
|
|
30
|
+
id: idSchema.optional(),
|
|
31
|
+
ids: z.array(idSchema).optional(),
|
|
32
|
+
version: versionSchema,
|
|
33
|
+
type: z.number().int().optional(),
|
|
34
|
+
language: z.string().optional(),
|
|
35
|
+
replaceMask: z.boolean().optional(),
|
|
36
|
+
payload: payloadSchema.optional()
|
|
37
|
+
};
|
|
38
|
+
export const nocodeToolDefinitions = [
|
|
39
|
+
{
|
|
40
|
+
name: "nocode_list_applications",
|
|
41
|
+
description: "查询当前旧 CRM 用户可访问的无代码应用列表;只读。",
|
|
42
|
+
schema: z.object({}).optional(),
|
|
43
|
+
access: "read"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "nocode_get_application",
|
|
47
|
+
description: "按 applicationId 查询旧 CRM 无代码应用详情;只读。",
|
|
48
|
+
schema: z.object({ applicationId: idSchema }),
|
|
49
|
+
access: "read"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "nocode_list_modules",
|
|
53
|
+
description: "查询无代码应用下的模块;mode 可选 latest、released、all 或 bi,默认 released;只读。",
|
|
54
|
+
schema: z.object({ applicationId: idSchema, mode: z.enum(["latest", "released", "all", "bi"]).optional() }),
|
|
55
|
+
access: "read"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "nocode_get_module",
|
|
59
|
+
description: "查询无代码模块详情;传 version 获取指定版本,否则通过 isLatest 获取最新或已发布版本;只读。",
|
|
60
|
+
schema: z.object({ moduleId: idSchema, version: versionSchema, isLatest: z.boolean().optional() }),
|
|
61
|
+
access: "read"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "nocode_get_module_schema",
|
|
65
|
+
description: "一次获取无代码模块字段、表单布局、列表头、页面布局、选项、公式、标签和序列号规则;写入记录前应先调用;只读。",
|
|
66
|
+
schema: z.object({ ...moduleContextShape, includeExtended: z.boolean().optional() }),
|
|
67
|
+
access: "read"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "nocode_search_records",
|
|
71
|
+
description: "按 moduleId 查询无代码模块记录列表;payload 使用旧 CRM ModuleSearchBO 条件,服务端强制启用数据权限过滤;只读。",
|
|
72
|
+
schema: z.object({ moduleId: idSchema, page: z.number().int().positive().optional(), limit: z.number().int().positive().max(200).optional(), payload: payloadSchema.optional() }),
|
|
73
|
+
access: "read"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "nocode_get_record",
|
|
77
|
+
description: "按 dataId 查询无代码记录及动态字段值;replaceMask 默认 true,继续执行字段脱敏;只读。",
|
|
78
|
+
schema: z.object({ dataId: idSchema, replaceMask: z.boolean().optional() }),
|
|
79
|
+
access: "read"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "nocode_calculate_formula",
|
|
83
|
+
description: "根据无代码记录字段 payload 计算公式字段但不保存;只读计算。",
|
|
84
|
+
schema: z.object({ payload: payloadSchema }),
|
|
85
|
+
access: "read"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "nocode_check_duplicate",
|
|
89
|
+
description: "调用无代码字段值验重规则,不修改数据;只读。",
|
|
90
|
+
schema: z.object({ payload: payloadSchema }),
|
|
91
|
+
access: "read"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "nocode_list_team_members",
|
|
95
|
+
description: "查询指定无代码记录的团队成员及当前用户团队权限;只读。",
|
|
96
|
+
schema: z.object({ moduleId: idSchema, dataId: idSchema }),
|
|
97
|
+
access: "read"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "nocode_get_permissions",
|
|
101
|
+
description: "查询无代码权限;kind 支持当前权限总览、应用角色、数据权限、字段权限、角色字段权限;只读。",
|
|
102
|
+
schema: z.object({
|
|
103
|
+
kind: z.enum(["auth", "roles", "rolesByIds", "usersRoles", "viewableUserIds", "data", "field", "roleField"]),
|
|
104
|
+
applicationId: idSchema.optional(),
|
|
105
|
+
moduleId: idSchema.optional(),
|
|
106
|
+
dataId: idSchema.optional(),
|
|
107
|
+
userId: idSchema.optional(),
|
|
108
|
+
ids: z.array(idSchema).optional(),
|
|
109
|
+
payload: payloadSchema.optional()
|
|
110
|
+
}),
|
|
111
|
+
access: "read"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "nocode_list_scenes",
|
|
115
|
+
description: "查询无代码模块的场景筛选配置;只读。",
|
|
116
|
+
schema: z.object({ moduleId: idSchema }),
|
|
117
|
+
access: "read"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "nocode_list_flows",
|
|
121
|
+
description: "查询无代码模块的流程配置;参数按旧 CRM FlowQueryBO 传入;只读。",
|
|
122
|
+
schema: z.object({ payload: payloadSchema }),
|
|
123
|
+
access: "read"
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: "nocode_list_stages",
|
|
127
|
+
description: "查询无代码模块版本或指定记录的阶段配置;只读。",
|
|
128
|
+
schema: z.object({ moduleId: idSchema.optional(), version: versionSchema, dataId: idSchema.optional() }),
|
|
129
|
+
access: "read"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "nocode_list_custom_buttons",
|
|
133
|
+
description: "查询无代码模块版本的自定义按钮配置;只读。",
|
|
134
|
+
schema: z.object({ moduleId: idSchema, version: z.number().int().nonnegative() }),
|
|
135
|
+
access: "read"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "nocode_list_tabs",
|
|
139
|
+
description: "查询无代码模块的自定义详情页 Tab 配置;只读。",
|
|
140
|
+
schema: z.object({ moduleId: idSchema }),
|
|
141
|
+
access: "read"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: "nocode_get_module_file",
|
|
145
|
+
description: "查询无代码模块文件元数据;不下载文件流;只读。",
|
|
146
|
+
schema: z.object({ payload: payloadSchema }),
|
|
147
|
+
access: "read"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: "nocode_query_fields",
|
|
151
|
+
description: "查询无代码字段的导出表头、固定表头、校验、删除影响、关联字段、默认值、树形数据和统计配置/结果;只读。",
|
|
152
|
+
schema: z.object({
|
|
153
|
+
operation: z.enum(["exportHead", "fixedListHead", "verify", "checkDelete", "union", "dashboardHead", "dashboardModule", "defaultList", "defaultValues", "defaultFiltered", "defaultFormula", "treeConfig", "treeData", "statisticConfig", "statisticValues", "statisticUnion"]),
|
|
154
|
+
...extendedContextShape
|
|
155
|
+
}),
|
|
156
|
+
access: "read"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "nocode_query_records",
|
|
160
|
+
description: "查询指定 ID 记录、原始字段值、主字段、字段统计、操作记录、自定义按钮处理记录和 Tab 绑定数据;只读。",
|
|
161
|
+
schema: z.object({
|
|
162
|
+
operation: z.enum(["byDataIds", "raw", "mainField", "mainFields", "mainFieldData", "fieldStatistic", "operationRecords", "customButtonDealRecords", "tabBoundDataIds"]),
|
|
163
|
+
...extendedContextShape
|
|
164
|
+
}),
|
|
165
|
+
access: "read"
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "nocode_query_workflow",
|
|
169
|
+
description: "查询流程预览/详情/处理详情、审批记录、待处理记录、阶段字段/数据/评论;只读。",
|
|
170
|
+
schema: z.object({
|
|
171
|
+
operation: z.enum(["preview", "flowDetail", "dealDetail", "examineRecord", "dealRecords", "stageFields", "stageForm", "stageData", "stageComments"]),
|
|
172
|
+
...extendedContextShape
|
|
173
|
+
}),
|
|
174
|
+
access: "read"
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "nocode_query_followups",
|
|
178
|
+
description: "查询无代码跟进配置字段/表单、跟进配置、跟进数据列表、跟进记录列表及评论;只读,不导出文件流。",
|
|
179
|
+
schema: z.object({
|
|
180
|
+
operation: z.enum(["fieldList", "fieldForm", "availableForm", "configList", "dataPage", "recordPage", "comments"]),
|
|
181
|
+
...extendedContextShape
|
|
182
|
+
}),
|
|
183
|
+
access: "read"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: "nocode_query_configuration",
|
|
187
|
+
description: "查询无代码自定义分类/提醒、数据校验规则、用户搜索配置、外部字段映射和多语言配置;只读。",
|
|
188
|
+
schema: z.object({
|
|
189
|
+
operation: z.enum(["scene", "customCategoryConfig", "customCategories", "customNotice", "dataCheckRules", "dataCheck", "userSearch", "externalFieldMappings", "languageModule", "languageApplication", "languageCurrent"]),
|
|
190
|
+
...extendedContextShape
|
|
191
|
+
}),
|
|
192
|
+
access: "read"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "nocode_query_printing",
|
|
196
|
+
description: "查询无代码打印模板字段、模板列表/详情和打印记录;只读。打印、预览和模板变更请使用 nocode_write_printing。",
|
|
197
|
+
schema: z.object({
|
|
198
|
+
operation: z.enum(["fields", "templates", "template", "records", "record"]),
|
|
199
|
+
...extendedContextShape
|
|
200
|
+
}),
|
|
201
|
+
access: "read"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: "nocode_query_messages",
|
|
205
|
+
description: "查询旧 CRM 无代码消息、应用消息及数据导入进度/结果;只读。",
|
|
206
|
+
schema: z.object({
|
|
207
|
+
operation: z.enum(["summary", "page", "moduleType", "importProgress", "importInfo"]),
|
|
208
|
+
messageId: idSchema.optional(),
|
|
209
|
+
...extendedContextShape
|
|
210
|
+
}),
|
|
211
|
+
access: "read"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "nocode_query_integrations",
|
|
215
|
+
description: "查询外部应用/模块、模块开放配置以及开放模块数据;固定白名单,只读。",
|
|
216
|
+
schema: z.object({
|
|
217
|
+
operation: z.enum(["externalApplications", "externalModules", "externalModule", "moduleByExternalId", "openModules", "openApplication", "openConfig", "openRecords", "openRecord", "openBoundDataIds"]),
|
|
218
|
+
externalModuleId: idSchema.optional(),
|
|
219
|
+
configType: z.number().int().optional(),
|
|
220
|
+
...extendedContextShape
|
|
221
|
+
}),
|
|
222
|
+
access: "read"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "nocode_query_marketplace",
|
|
226
|
+
description: "查询无代码应用模板管理企业、系统分类/应用、发布状态和当前企业应用分类;只读。",
|
|
227
|
+
schema: z.object({ operation: z.enum(["manageCompany", "systemCategories", "systemApps", "publishStatus", "appCategories"]) }),
|
|
228
|
+
access: "read"
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "nocode_write_application",
|
|
232
|
+
description: "新增、修改、启停、删除、排序或安装无代码应用;必须 confirm=true,否则只返回固定接口和请求预览。",
|
|
233
|
+
schema: z.object({
|
|
234
|
+
action: z.enum(["create", "update", "status", "delete", "sort", "install"]),
|
|
235
|
+
applicationId: idSchema.optional(),
|
|
236
|
+
status: z.number().int().optional(),
|
|
237
|
+
ids: z.array(idSchema).optional(),
|
|
238
|
+
payload: payloadSchema.optional(),
|
|
239
|
+
confirm: confirmSchema
|
|
240
|
+
}),
|
|
241
|
+
access: "write",
|
|
242
|
+
destructive: true
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "nocode_write_module",
|
|
246
|
+
description: "保存、启停、复制、发布、丢弃草稿、删除模块、保存页面布局或维护 BI Dashboard 模块;必须 confirm=true。",
|
|
247
|
+
schema: z.object({
|
|
248
|
+
action: z.enum(["save", "status", "copy", "publish", "discardDraft", "delete", "layout", "deleteCancelledCompanyData", "dashboardSave", "dashboardRemove"]),
|
|
249
|
+
moduleId: idSchema.optional(),
|
|
250
|
+
version: versionSchema,
|
|
251
|
+
isEnable: z.boolean().optional(),
|
|
252
|
+
payload: payloadSchema.optional(),
|
|
253
|
+
confirm: confirmSchema
|
|
254
|
+
}),
|
|
255
|
+
access: "write",
|
|
256
|
+
destructive: true
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: "nocode_write_field",
|
|
260
|
+
description: "保存字段,或修改普通/固定模块列表字段排序和样式;必须 confirm=true,否则只返回固定接口和请求预览。",
|
|
261
|
+
schema: z.object({ action: z.enum(["save", "sort", "style", "fixedSort", "fixedStyle"]), ...payloadWriteShape }),
|
|
262
|
+
access: "write",
|
|
263
|
+
destructive: true
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "nocode_write_record",
|
|
267
|
+
description: "新增/修改、删除、转移负责人或设置分组;payload 使用对应旧 CRM BO;必须 confirm=true,否则只返回预览。",
|
|
268
|
+
schema: z.object({ action: z.enum(["save", "delete", "transfer", "setCategory"]), ...payloadWriteShape }),
|
|
269
|
+
access: "write",
|
|
270
|
+
destructive: true
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: "nocode_write_team",
|
|
274
|
+
description: "新增或移除无代码记录团队成员;必须 confirm=true,否则只返回预览。",
|
|
275
|
+
schema: z.object({ action: z.enum(["save", "remove"]), ...payloadWriteShape }),
|
|
276
|
+
access: "write",
|
|
277
|
+
destructive: true
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
name: "nocode_write_scene",
|
|
281
|
+
description: "新增、修改、删除、设为默认或保存场景配置;必须 confirm=true,否则只返回预览。",
|
|
282
|
+
schema: z.object({ action: z.enum(["add", "update", "delete", "default", "config"]), sceneId: idSchema.optional(), payload: payloadSchema.optional(), confirm: confirmSchema }),
|
|
283
|
+
access: "write",
|
|
284
|
+
destructive: true
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
name: "nocode_write_flow",
|
|
288
|
+
description: "保存或删除无代码流程配置;必须 confirm=true,否则只返回预览。",
|
|
289
|
+
schema: z.object({ action: z.enum(["save", "delete"]), ...payloadWriteShape }),
|
|
290
|
+
access: "write",
|
|
291
|
+
destructive: true
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
name: "nocode_write_stage",
|
|
295
|
+
description: "保存、启停或删除阶段配置;必须 confirm=true,否则只返回预览。",
|
|
296
|
+
schema: z.object({ action: z.enum(["save", "status", "delete"]), ...payloadWriteShape }),
|
|
297
|
+
access: "write",
|
|
298
|
+
destructive: true
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: "nocode_write_custom_button",
|
|
302
|
+
description: "保存、删除、执行自定义按钮或保存按钮填写字段;必须 confirm=true,否则只返回预览。",
|
|
303
|
+
schema: z.object({ action: z.enum(["save", "delete", "execute", "saveFieldData"]), ...payloadWriteShape }),
|
|
304
|
+
access: "write",
|
|
305
|
+
destructive: true
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
name: "nocode_write_role",
|
|
309
|
+
description: "保存/删除/复制无代码角色,或保存角色模块、用户、字段权限关系;必须 confirm=true,否则只返回预览。",
|
|
310
|
+
schema: z.object({
|
|
311
|
+
action: z.enum(["save", "delete", "copy", "saveModules", "saveUsers", "saveFields", "saveUserRole", "deleteUserRole"]),
|
|
312
|
+
roleId: idSchema.optional(),
|
|
313
|
+
payload: payloadSchema.optional(),
|
|
314
|
+
confirm: confirmSchema
|
|
315
|
+
}),
|
|
316
|
+
access: "write",
|
|
317
|
+
destructive: true
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
name: "nocode_write_tab",
|
|
321
|
+
description: "保存、启停或删除无代码详情页 Tab;必须 confirm=true,否则只返回预览。",
|
|
322
|
+
schema: z.object({ action: z.enum(["save", "status", "delete"]), id: idSchema.optional(), payload: payloadSchema.optional(), confirm: confirmSchema }),
|
|
323
|
+
access: "write",
|
|
324
|
+
destructive: true
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: "nocode_write_workflow",
|
|
328
|
+
description: "填写/转交流程、审批、自选节点、标记处理记录已查看,或保存阶段数据和评论;必须 confirm=true。",
|
|
329
|
+
schema: z.object({
|
|
330
|
+
operation: z.enum(["fillValue", "transfer", "audit", "optional", "viewDealRecord", "stageData", "stageCommentSave", "stageCommentRemove"]),
|
|
331
|
+
...extendedContextShape,
|
|
332
|
+
confirm: confirmSchema
|
|
333
|
+
}),
|
|
334
|
+
access: "write",
|
|
335
|
+
destructive: true
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: "nocode_write_followup",
|
|
339
|
+
description: "保存跟进字段/配置状态/数据/评论,或删除跟进配置、记录、评论;必须 confirm=true。",
|
|
340
|
+
schema: z.object({
|
|
341
|
+
operation: z.enum(["fieldSave", "updateStatus", "deleteConfig", "dataSave", "deleteData", "commentSave", "deleteComment"]),
|
|
342
|
+
...extendedContextShape,
|
|
343
|
+
confirm: confirmSchema
|
|
344
|
+
}),
|
|
345
|
+
access: "write",
|
|
346
|
+
destructive: true
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
name: "nocode_write_configuration",
|
|
350
|
+
description: "保存/删除自定义分类、提醒、校验规则,或保存用户搜索、外部字段映射、模块文件、应用分类、Tab 绑定和多语言;必须 confirm=true。",
|
|
351
|
+
schema: z.object({
|
|
352
|
+
operation: z.enum(["customCategorySave", "customCategoryDelete", "customNoticeSave", "customNoticeDelete", "dataCheckSave", "dataCheckDelete", "dataCheckSort", "userSearchSave", "externalFieldMappingSave", "moduleFileSave", "categorySave", "categoryDelete", "tabBind", "languageSave"]),
|
|
353
|
+
...extendedContextShape,
|
|
354
|
+
confirm: confirmSchema
|
|
355
|
+
}),
|
|
356
|
+
access: "write",
|
|
357
|
+
destructive: true
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
name: "nocode_write_printing",
|
|
361
|
+
description: "新增/修改/复制/删除打印模板、生成打印/预览内容或保存打印记录;必须 confirm=true;不代理 PDF/Word 下载流。",
|
|
362
|
+
schema: z.object({
|
|
363
|
+
operation: z.enum(["add", "update", "copy", "delete", "print", "preview", "recordSave"]),
|
|
364
|
+
templateId: idSchema.optional(),
|
|
365
|
+
...extendedContextShape,
|
|
366
|
+
confirm: confirmSchema
|
|
367
|
+
}),
|
|
368
|
+
access: "write",
|
|
369
|
+
destructive: true
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "nocode_write_message",
|
|
373
|
+
description: "将无代码消息设为已读或删除;必须 confirm=true。",
|
|
374
|
+
schema: z.object({ operation: z.enum(["setRead", "delete"]), ...payloadWriteShape }),
|
|
375
|
+
access: "write",
|
|
376
|
+
destructive: true
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
name: "nocode_write_integration",
|
|
380
|
+
description: "开放或关闭指定无代码模块;必须 confirm=true。",
|
|
381
|
+
schema: z.object({ operation: z.enum(["openModules", "closeModules"]), ...payloadWriteShape }),
|
|
382
|
+
access: "write",
|
|
383
|
+
destructive: true
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: "nocode_write_marketplace",
|
|
387
|
+
description: "发布/复制/清空应用模板,或维护应用分类、收藏、移动与排序;必须 confirm=true。clearApps 会清空应用,风险极高。",
|
|
388
|
+
schema: z.object({
|
|
389
|
+
operation: z.enum(["publish", "publishAll", "copy", "clearApps", "categorySave", "store", "move", "customCategorySave", "sort"]),
|
|
390
|
+
companyId: idSchema.optional(),
|
|
391
|
+
...extendedContextShape,
|
|
392
|
+
confirm: confirmSchema
|
|
393
|
+
}),
|
|
394
|
+
access: "write",
|
|
395
|
+
destructive: true
|
|
396
|
+
}
|
|
397
|
+
];
|
|
398
|
+
export function createNocodeToolHandlers(config = {}) {
|
|
399
|
+
const client = new CrmClient(config);
|
|
400
|
+
return {
|
|
401
|
+
nocode_list_applications: async () => readonlyResult("/moduleMetadata/customAppList", await client.post("/moduleMetadata/customAppList")),
|
|
402
|
+
nocode_get_application: async (args) => {
|
|
403
|
+
const applicationId = requiredId(args.applicationId, "applicationId");
|
|
404
|
+
const targetPath = `/moduleMetadata/queryById/${applicationId}`;
|
|
405
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
406
|
+
},
|
|
407
|
+
nocode_list_modules: async (args) => {
|
|
408
|
+
const applicationId = requiredId(args.applicationId, "applicationId");
|
|
409
|
+
const mode = args.mode ?? "released";
|
|
410
|
+
const targetPath = mode === "latest"
|
|
411
|
+
? `/moduleM/latest/list/${applicationId}`
|
|
412
|
+
: mode === "bi"
|
|
413
|
+
? `/moduleM/bi/list/${applicationId}`
|
|
414
|
+
: mode === "all"
|
|
415
|
+
? `/moduleM/list/${applicationId}`
|
|
416
|
+
: `/moduleM/released/list/${applicationId}`;
|
|
417
|
+
return readonlyResult(targetPath, await client.post(targetPath), { mode });
|
|
418
|
+
},
|
|
419
|
+
nocode_get_module: async (args) => {
|
|
420
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
421
|
+
if (args.version !== undefined) {
|
|
422
|
+
const version = requiredVersion(args.version);
|
|
423
|
+
const targetPath = `/moduleM/queryDetail/${moduleId}/${version}`;
|
|
424
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
425
|
+
}
|
|
426
|
+
const targetPath = `/moduleM/queryById/${moduleId}`;
|
|
427
|
+
return readonlyResult(targetPath, await client.post(targetPath, undefined, { isLatest: args.isLatest ?? true }));
|
|
428
|
+
},
|
|
429
|
+
nocode_get_module_schema: async (args) => {
|
|
430
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
431
|
+
const version = requiredVersion(args.version);
|
|
432
|
+
const query = cleanObject({ moduleId: numericValue(moduleId), version, categoryId: args.categoryId });
|
|
433
|
+
const [fields, form, listHead, layout, unionModules] = await Promise.all([
|
|
434
|
+
client.post("/moduleField/queryList", query),
|
|
435
|
+
client.post("/moduleField/formList", query),
|
|
436
|
+
client.post("/moduleField/queryListHead", query),
|
|
437
|
+
client.post(`/moduleM/pageLayout/${moduleId}/${version}`),
|
|
438
|
+
client.post(`/moduleM/unionModules/${moduleId}/${version}`)
|
|
439
|
+
]);
|
|
440
|
+
const extended = args.includeExtended === false
|
|
441
|
+
? undefined
|
|
442
|
+
: {
|
|
443
|
+
options: await client.post(`/moduleFieldOptions/list/${moduleId}/${version}`),
|
|
444
|
+
formulas: await client.post(`/moduleFieldFormula/list/${moduleId}/${version}`),
|
|
445
|
+
tags: await client.post(`/moduleFieldTags/list/${moduleId}/${version}`),
|
|
446
|
+
serialNumberRules: await client.post(`/moduleFieldSerialNumberRules/list/${moduleId}/${version}`)
|
|
447
|
+
};
|
|
448
|
+
return {
|
|
449
|
+
readonly: true,
|
|
450
|
+
moduleId,
|
|
451
|
+
version,
|
|
452
|
+
fields,
|
|
453
|
+
form,
|
|
454
|
+
listHead,
|
|
455
|
+
layout,
|
|
456
|
+
unionModules,
|
|
457
|
+
...extended
|
|
458
|
+
};
|
|
459
|
+
},
|
|
460
|
+
nocode_search_records: async (args) => {
|
|
461
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
462
|
+
const targetPath = `/moduleData/queryPageList/${moduleId}`;
|
|
463
|
+
// 分页上限由工具 schema 控制,不能让透传 payload 绕过顶层的 page/limit 约束。
|
|
464
|
+
const body = cleanObject({ ...safePayload(args.payload), page: args.page ?? 1, limit: args.limit ?? 15 });
|
|
465
|
+
return readonlyResult(targetPath, await client.post(targetPath, body), { body });
|
|
466
|
+
},
|
|
467
|
+
nocode_get_record: async (args) => {
|
|
468
|
+
const dataId = requiredId(args.dataId, "dataId");
|
|
469
|
+
const targetPath = `/moduleFieldData/query/${dataId}/${args.replaceMask ?? true}`;
|
|
470
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
471
|
+
},
|
|
472
|
+
nocode_calculate_formula: async (args) => readonlyResult("/moduleFieldData/calculateFormula", await client.post("/moduleFieldData/calculateFormula", safePayload(args.payload))),
|
|
473
|
+
nocode_check_duplicate: async (args) => readonlyResult("/moduleFieldData/doubleCheck", await client.post("/moduleFieldData/doubleCheck", safePayload(args.payload))),
|
|
474
|
+
nocode_list_team_members: async (args) => {
|
|
475
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
476
|
+
const dataId = requiredId(args.dataId, "dataId");
|
|
477
|
+
const [members, currentUser] = await Promise.all([
|
|
478
|
+
client.post(`/moduleFieldData/teamMember/${moduleId}/${dataId}`),
|
|
479
|
+
client.post(`/moduleFieldData/teamMemberInfo/${moduleId}/${dataId}`)
|
|
480
|
+
]);
|
|
481
|
+
return { readonly: true, moduleId, dataId, members, currentUser };
|
|
482
|
+
},
|
|
483
|
+
nocode_get_permissions: async (args) => queryPermissions(client, args),
|
|
484
|
+
nocode_list_scenes: async (args) => {
|
|
485
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
486
|
+
const targetPath = `/moduleScene/list/${moduleId}`;
|
|
487
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
488
|
+
},
|
|
489
|
+
nocode_list_flows: async (args) => readonlyResult("/moduleFlow/queryFlow", await client.post("/moduleFlow/queryFlow", undefined, safePayload(args.payload))),
|
|
490
|
+
nocode_list_stages: async (args) => {
|
|
491
|
+
let targetPath;
|
|
492
|
+
if (args.dataId !== undefined) {
|
|
493
|
+
targetPath = `/moduleStageSetting/queryList/${requiredId(args.dataId, "dataId")}`;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
targetPath = `/moduleStageSetting/queryList/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}`;
|
|
497
|
+
}
|
|
498
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
499
|
+
},
|
|
500
|
+
nocode_list_custom_buttons: async (args) => {
|
|
501
|
+
const targetPath = `/moduleCustomButton/queryList/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}`;
|
|
502
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
503
|
+
},
|
|
504
|
+
nocode_list_tabs: async (args) => {
|
|
505
|
+
const targetPath = `/moduleTab/queryList/${requiredId(args.moduleId, "moduleId")}`;
|
|
506
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
507
|
+
},
|
|
508
|
+
nocode_get_module_file: async (args) => readonlyResult("/moduleFile/query", await client.post("/moduleFile/query", safePayload(args.payload))),
|
|
509
|
+
nocode_query_fields: async (args) => executeNocodeRead(client, queryFieldRoute(args)),
|
|
510
|
+
nocode_query_records: async (args) => executeNocodeRead(client, queryRecordRoute(args)),
|
|
511
|
+
nocode_query_workflow: async (args) => executeNocodeRead(client, queryWorkflowRoute(args)),
|
|
512
|
+
nocode_query_followups: async (args) => executeNocodeRead(client, queryFollowUpRoute(args)),
|
|
513
|
+
nocode_query_configuration: async (args) => executeNocodeRead(client, queryConfigurationRoute(args)),
|
|
514
|
+
nocode_query_printing: async (args) => executeNocodeRead(client, queryPrintingRoute(args)),
|
|
515
|
+
nocode_query_messages: async (args) => executeNocodeRead(client, queryMessageRoute(args)),
|
|
516
|
+
nocode_query_integrations: async (args) => executeNocodeRead(client, queryIntegrationRoute(args)),
|
|
517
|
+
nocode_query_marketplace: async (args) => executeNocodeRead(client, queryMarketplaceRoute(args)),
|
|
518
|
+
nocode_write_application: async (args) => executeApplicationWrite(client, args),
|
|
519
|
+
nocode_write_module: async (args) => executeModuleWrite(client, args),
|
|
520
|
+
nocode_write_field: async (args) => executePayloadWrite(client, args, {
|
|
521
|
+
save: "/moduleField/save",
|
|
522
|
+
sort: "/moduleField/setFieldSort",
|
|
523
|
+
style: "/moduleField/setFieldStyle",
|
|
524
|
+
fixedSort: "/moduleField/fixed/setFieldSort",
|
|
525
|
+
fixedStyle: "/moduleField/fixed/setFieldStyle"
|
|
526
|
+
}),
|
|
527
|
+
nocode_write_record: async (args) => executePayloadWrite(client, args, {
|
|
528
|
+
save: "/moduleFieldData/save",
|
|
529
|
+
delete: "/moduleFieldData/delete",
|
|
530
|
+
transfer: "/moduleFieldData/transfer",
|
|
531
|
+
setCategory: "/moduleFieldData/setDataCategory"
|
|
532
|
+
}),
|
|
533
|
+
nocode_write_team: async (args) => executePayloadWrite(client, args, {
|
|
534
|
+
save: "/moduleFieldData/saveTeamMember",
|
|
535
|
+
remove: "/moduleFieldData/removeTeamMember"
|
|
536
|
+
}),
|
|
537
|
+
nocode_write_scene: async (args) => executeSceneWrite(client, args),
|
|
538
|
+
nocode_write_flow: async (args) => executePayloadWrite(client, args, {
|
|
539
|
+
save: "/moduleFlow/saveFlow",
|
|
540
|
+
delete: "/moduleFlow/delete"
|
|
541
|
+
}),
|
|
542
|
+
nocode_write_stage: async (args) => executePayloadWrite(client, args, {
|
|
543
|
+
save: "/moduleStageSetting/save",
|
|
544
|
+
status: "/moduleStageSetting/updateStatus",
|
|
545
|
+
delete: "/moduleStageSetting/delete"
|
|
546
|
+
}),
|
|
547
|
+
nocode_write_custom_button: async (args) => executePayloadWrite(client, args, {
|
|
548
|
+
save: "/moduleCustomButton/save",
|
|
549
|
+
delete: "/moduleCustomButton/delete",
|
|
550
|
+
execute: "/moduleCustomButton/execute",
|
|
551
|
+
saveFieldData: "/moduleCustomButton/saveFieldData"
|
|
552
|
+
}),
|
|
553
|
+
nocode_write_role: async (args) => executeRoleWrite(client, args),
|
|
554
|
+
nocode_write_tab: async (args) => executeTabWrite(client, args),
|
|
555
|
+
nocode_write_workflow: async (args) => executeNocodeWrite(client, args, writeWorkflowRoute(args)),
|
|
556
|
+
nocode_write_followup: async (args) => executeNocodeWrite(client, args, writeFollowUpRoute(args)),
|
|
557
|
+
nocode_write_configuration: async (args) => executeNocodeWrite(client, args, writeConfigurationRoute(args)),
|
|
558
|
+
nocode_write_printing: async (args) => executeNocodeWrite(client, args, writePrintingRoute(args)),
|
|
559
|
+
nocode_write_message: async (args) => executeNocodeWrite(client, args, writeMessageRoute(args)),
|
|
560
|
+
nocode_write_integration: async (args) => executeNocodeWrite(client, args, writeIntegrationRoute(args)),
|
|
561
|
+
nocode_write_marketplace: async (args) => executeNocodeWrite(client, args, writeMarketplaceRoute(args))
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
async function executeNocodeRead(client, route) {
|
|
565
|
+
return readonlyResult(route.targetPath, await client.post(route.targetPath, route.body, route.query), cleanObject({ operation: route.operation, body: route.body, query: route.query }));
|
|
566
|
+
}
|
|
567
|
+
function executeNocodeWrite(client, args, route) {
|
|
568
|
+
return confirmedPost(client, args, route.operation, route.targetPath, route.body, route.query);
|
|
569
|
+
}
|
|
570
|
+
function queryFieldRoute(args) {
|
|
571
|
+
const operation = String(args.operation);
|
|
572
|
+
const payload = safePayload(args.payload);
|
|
573
|
+
switch (operation) {
|
|
574
|
+
case "exportHead": return bodyRoute(operation, "/moduleField/queryExportHeadList", payload);
|
|
575
|
+
case "fixedListHead": return bodyRoute(operation, "/moduleField/fixed/queryListHead", payload);
|
|
576
|
+
case "verify": return bodyRoute(operation, "/moduleField/verify", payload);
|
|
577
|
+
case "checkDelete": return bodyRoute(operation, "/moduleField/checkFieldDelete", payload);
|
|
578
|
+
case "union": return pathRoute(operation, `/moduleField/queryUnionList/${requiredId(args.targetModuleId, "targetModuleId")}/${requiredId(args.moduleId, "moduleId")}`);
|
|
579
|
+
case "dashboardHead": return bodyRoute(operation, "/moduleField/queryListHeadForDashboard", payload);
|
|
580
|
+
case "dashboardModule": return bodyRoute(operation, "/moduleM/queryByIdForDashboard", payload);
|
|
581
|
+
case "defaultList": return moduleVersionRoute(operation, "/moduleFieldDefault/list", args);
|
|
582
|
+
case "defaultValues": return moduleVersionRoute(operation, "/moduleFieldDefault/values", args);
|
|
583
|
+
case "defaultFiltered": return bodyRoute(operation, "/moduleFieldDefault/values", payload);
|
|
584
|
+
case "defaultFormula": return bodyRoute(operation, "/moduleFieldDefault/values/formula", payload);
|
|
585
|
+
case "treeConfig": return moduleVersionRoute(operation, "/moduleFieldTree/list", args);
|
|
586
|
+
case "treeData": return bodyRoute(operation, "/moduleTreeData/queryTreeData", payload);
|
|
587
|
+
case "statisticConfig": return moduleVersionRoute(operation, "/moduleFieldStatistic/query", args);
|
|
588
|
+
case "statisticValues": return bodyRoute(operation, "/moduleFieldStatistic/values", payload);
|
|
589
|
+
case "statisticUnion": return moduleVersionRoute(operation, "/moduleStatisticFieldUnion/query", args);
|
|
590
|
+
default: return unsupportedRoute("字段查询", operation);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
function queryRecordRoute(args) {
|
|
594
|
+
const operation = String(args.operation);
|
|
595
|
+
const payload = safePayload(args.payload);
|
|
596
|
+
switch (operation) {
|
|
597
|
+
case "byDataIds": return bodyRoute(operation, "/moduleData/queryByDataIds", payload);
|
|
598
|
+
case "raw": return pathRoute(operation, `/moduleFieldData/query/${requiredId(args.dataId, "dataId")}`);
|
|
599
|
+
case "mainField": return pathRoute(operation, `/moduleFieldData/mainField/${requiredId(args.dataId, "dataId")}`);
|
|
600
|
+
case "mainFields": return bodyRoute(operation, "/moduleFieldData/mainField/queryByDataIds", payload);
|
|
601
|
+
case "mainFieldData": return bodyRoute(operation, "/moduleFieldData/queryMainFieldData", requiredIds(args.ids, "ids"));
|
|
602
|
+
case "fieldStatistic": return bodyRoute(operation, "/moduleFieldData/fieldStatistic", payload);
|
|
603
|
+
case "operationRecords": return pathRoute(operation, `/moduleOperationRecord/query/${requiredId(args.moduleId, "moduleId")}/${requiredId(args.dataId, "dataId")}`);
|
|
604
|
+
case "customButtonDealRecords": return pathRoute(operation, `/moduleCustomButton/dealRecord/${requiredId(args.moduleId, "moduleId")}/${requiredId(args.dataId, "dataId")}`);
|
|
605
|
+
case "tabBoundDataIds": return pathRoute(operation, `/moduleTabDataBind/getBoundDataIds/${requiredId(args.dataId, "dataId")}/${requiredId(args.tabId, "tabId")}`);
|
|
606
|
+
default: return unsupportedRoute("记录查询", operation);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function queryWorkflowRoute(args) {
|
|
610
|
+
const operation = String(args.operation);
|
|
611
|
+
const payload = safePayload(args.payload);
|
|
612
|
+
switch (operation) {
|
|
613
|
+
case "preview": return bodyRoute(operation, "/moduleFlow/preview", payload);
|
|
614
|
+
case "flowDetail": return bodyRoute(operation, "/moduleFlow/flowDetail", payload);
|
|
615
|
+
case "dealDetail": return queryRoute(operation, "/moduleFlow/dealDetail", payload);
|
|
616
|
+
case "examineRecord": return pathRoute(operation, `/moduleFlowExamine/record/${requiredId(args.moduleId, "moduleId")}/${requiredId(args.dataId, "dataId")}/${requiredId(args.typeId, "typeId")}`);
|
|
617
|
+
case "dealRecords": return bodyRoute(operation, "/moduleFlowDealRecord/queryList", payload);
|
|
618
|
+
case "stageFields": return stageFieldRoute(operation, "/moduleStageSetting/field/list", args);
|
|
619
|
+
case "stageForm": return stageFieldRoute(operation, "/moduleStageSetting/field/formList", args);
|
|
620
|
+
case "stageData": return bodyRoute(operation, "/moduleStageData/queryList", payload);
|
|
621
|
+
case "stageComments": return pathRoute(operation, `/moduleStageData/comment/list/${requiredId(args.dataId, "dataId")}`);
|
|
622
|
+
default: return unsupportedRoute("流程查询", operation);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
function writeWorkflowRoute(args) {
|
|
626
|
+
const operation = String(args.operation);
|
|
627
|
+
const payload = safePayload(args.payload);
|
|
628
|
+
switch (operation) {
|
|
629
|
+
case "fillValue": return bodyRoute(operation, "/moduleFlow/fill/saveFieldValue", payload);
|
|
630
|
+
case "transfer": return queryRoute(operation, "/moduleFlow/transferFlow", payload);
|
|
631
|
+
case "audit": return bodyRoute(operation, "/moduleFlowExamine/auditExamine", payload);
|
|
632
|
+
case "optional": return bodyRoute(operation, "/moduleFlowOptional/save", payload);
|
|
633
|
+
case "viewDealRecord": return pathRoute(operation, `/moduleFlowDealRecord/view/${requiredId(args.id, "id")}`);
|
|
634
|
+
case "stageData": return bodyRoute(operation, "/moduleStageData/save", payload);
|
|
635
|
+
case "stageCommentSave": return bodyRoute(operation, "/moduleStageData/comment/save", payload);
|
|
636
|
+
case "stageCommentRemove": return bodyRoute(operation, "/moduleStageData/comment/remove", payload);
|
|
637
|
+
default: return unsupportedRoute("流程写操作", operation);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function queryFollowUpRoute(args) {
|
|
641
|
+
const operation = String(args.operation);
|
|
642
|
+
const payload = safePayload(args.payload);
|
|
643
|
+
const moduleId = () => requiredId(args.moduleId, "moduleId");
|
|
644
|
+
const version = () => requiredVersion(args.version);
|
|
645
|
+
const followUpId = () => requiredId(args.followUpId, "followUpId");
|
|
646
|
+
switch (operation) {
|
|
647
|
+
case "fieldList": return pathRoute(operation, `/moduleFollowUp/field/list/${moduleId()}/${version()}/${followUpId()}`);
|
|
648
|
+
case "fieldForm": return pathRoute(operation, `/moduleFollowUp/field/formList/${moduleId()}/${version()}/${followUpId()}`);
|
|
649
|
+
case "availableForm": return pathRoute(operation, `/moduleFollowUp/field/availableFormList/${moduleId()}/${version()}`);
|
|
650
|
+
case "configList": return pathRoute(operation, `/moduleFollowUp/list/${moduleId()}/${version()}`);
|
|
651
|
+
case "dataPage": return bodyRoute(operation, "/moduleFollowUpData/pageList", payload);
|
|
652
|
+
case "recordPage": return bodyRoute(operation, "/moduleFollowUpRecord/pageList", payload);
|
|
653
|
+
case "comments": return pathRoute(operation, `/moduleFollowUpRecordComment/list/${requiredId(args.recordId, "recordId")}`);
|
|
654
|
+
default: return unsupportedRoute("跟进查询", operation);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
function writeFollowUpRoute(args) {
|
|
658
|
+
const operation = String(args.operation);
|
|
659
|
+
const payload = safePayload(args.payload);
|
|
660
|
+
switch (operation) {
|
|
661
|
+
case "fieldSave": return bodyRoute(operation, "/moduleFollowUp/field/save", payload);
|
|
662
|
+
case "updateStatus": return bodyRoute(operation, "/moduleFollowUp/updateStatus", payload);
|
|
663
|
+
case "deleteConfig": return pathRoute(operation, `/moduleFollowUp/delete/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}/${requiredId(args.followUpId, "followUpId")}`);
|
|
664
|
+
case "dataSave": return bodyRoute(operation, "/moduleFollowUpData/save", payload);
|
|
665
|
+
case "deleteData": return pathRoute(operation, `/moduleFollowUpData/delete/${requiredId(args.recordId, "recordId")}`);
|
|
666
|
+
case "commentSave": return bodyRoute(operation, "/moduleFollowUpRecordComment/save", payload);
|
|
667
|
+
case "deleteComment": return pathRoute(operation, `/moduleFollowUpRecordComment/delete/${requiredId(args.commentId, "commentId")}`);
|
|
668
|
+
default: return unsupportedRoute("跟进写操作", operation);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function queryConfigurationRoute(args) {
|
|
672
|
+
const operation = String(args.operation);
|
|
673
|
+
const payload = safePayload(args.payload);
|
|
674
|
+
switch (operation) {
|
|
675
|
+
case "scene": return pathRoute(operation, `/moduleScene/${requiredId(args.id, "id")}`);
|
|
676
|
+
case "customCategoryConfig": return moduleVersionRoute(operation, "/moduleCustomCategory/queryList", args);
|
|
677
|
+
case "customCategories": return pathRoute(operation, "/moduleCustomCategory/list");
|
|
678
|
+
case "customNotice": return moduleVersionRoute(operation, "/moduleCustomNotice/queryList", args);
|
|
679
|
+
case "dataCheckRules": return moduleVersionRoute(operation, "/moduleDataCheckRule/queryList", args);
|
|
680
|
+
case "dataCheck": return bodyRoute(operation, "/moduleDataCheckRule/dataCheck", payload);
|
|
681
|
+
case "userSearch": return pathRoute(operation, `/moduleUserSearch/config/${requiredId(args.moduleId, "moduleId")}`);
|
|
682
|
+
case "externalFieldMappings": return moduleVersionRoute(operation, "/moduleExternalFieldMapping/queryList", args);
|
|
683
|
+
case "languageModule": return pathRoute(operation, `/moduleLanguage/list/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}/${requiredSegment(args.language, "language")}`);
|
|
684
|
+
case "languageApplication": return pathRoute(operation, `/moduleLanguage/listByApplicationId/${requiredId(args.applicationId, "applicationId")}/${requiredSegment(args.language, "language")}`);
|
|
685
|
+
case "languageCurrent": return pathRoute(operation, `/moduleLanguage/listByLanguage/${requiredSegment(args.language, "language")}`);
|
|
686
|
+
default: return unsupportedRoute("配置查询", operation);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function writeConfigurationRoute(args) {
|
|
690
|
+
const operation = String(args.operation);
|
|
691
|
+
const payload = safePayload(args.payload);
|
|
692
|
+
switch (operation) {
|
|
693
|
+
case "customCategorySave": return bodyRoute(operation, "/moduleCustomCategory/save", payload);
|
|
694
|
+
case "customCategoryDelete": return pathRoute(operation, `/moduleCustomCategory/delete/${requiredId(args.categoryId, "categoryId")}/${requiredVersion(args.version)}`);
|
|
695
|
+
case "customNoticeSave": return bodyRoute(operation, "/moduleCustomNotice/save", payload);
|
|
696
|
+
case "customNoticeDelete": return pathRoute(operation, `/moduleCustomNotice/delete/${requiredId(args.noticeId, "noticeId")}/${requiredVersion(args.version)}`);
|
|
697
|
+
case "dataCheckSave": return bodyRoute(operation, "/moduleDataCheckRule/save", payload);
|
|
698
|
+
case "dataCheckDelete": return pathRoute(operation, `/moduleDataCheckRule/delete/${requiredId(args.ruleId, "ruleId")}/${requiredVersion(args.version)}`);
|
|
699
|
+
case "dataCheckSort": return bodyRoute(operation, `/moduleDataCheckRule/sort/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}`, requiredIds(args.ids, "ids"));
|
|
700
|
+
case "userSearchSave": return bodyRoute(operation, "/moduleUserSearch/save", payload);
|
|
701
|
+
case "externalFieldMappingSave": return bodyRoute(operation, "/moduleExternalFieldMapping/save", payload);
|
|
702
|
+
case "moduleFileSave": return bodyRoute(operation, "/moduleFile/save", payload);
|
|
703
|
+
case "categorySave": return bodyRoute(operation, "/moduleCategory/save", payload);
|
|
704
|
+
case "categoryDelete": return pathRoute(operation, `/moduleCategory/delete/${requiredId(args.categoryId, "categoryId")}`);
|
|
705
|
+
case "tabBind": return bodyRoute(operation, "/moduleTabDataBind/bindData", payload);
|
|
706
|
+
case "languageSave": return bodyRoute(operation, "/moduleLanguage/save", payload);
|
|
707
|
+
default: return unsupportedRoute("配置写操作", operation);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function queryPrintingRoute(args) {
|
|
711
|
+
const operation = String(args.operation);
|
|
712
|
+
switch (operation) {
|
|
713
|
+
case "fields": return moduleVersionRoute(operation, "/modulePrintTemplate/getFields", args);
|
|
714
|
+
case "templates": return bodyRoute(operation, `/modulePrintTemplate/list/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}`, safePayload(args.payload));
|
|
715
|
+
case "template": return bodyRoute(operation, "/modulePrintTemplate/getOne", safePayload(args.payload));
|
|
716
|
+
case "records": return pathRoute(operation, `/modulePrintTemplate/printRecord/list/${requiredId(args.moduleId, "moduleId")}`);
|
|
717
|
+
case "record": return pathRoute(operation, `/modulePrintTemplate/printRecord/${requiredId(args.recordId, "recordId")}`);
|
|
718
|
+
default: return unsupportedRoute("打印查询", operation);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
function writePrintingRoute(args) {
|
|
722
|
+
const operation = String(args.operation);
|
|
723
|
+
const payload = safePayload(args.payload);
|
|
724
|
+
switch (operation) {
|
|
725
|
+
case "add": return bodyRoute(operation, "/modulePrintTemplate/add", payload);
|
|
726
|
+
case "update": return bodyRoute(operation, "/modulePrintTemplate/update", payload);
|
|
727
|
+
case "copy": return bodyRoute(operation, "/modulePrintTemplate/copy", payload);
|
|
728
|
+
case "delete": return bodyRoute(operation, "/modulePrintTemplate/delete", payload);
|
|
729
|
+
case "print": return queryRoute(operation, "/modulePrintTemplate/print", {
|
|
730
|
+
templateId: numericValue(requiredId(args.templateId, "templateId")),
|
|
731
|
+
dataId: numericValue(requiredId(args.dataId, "dataId"))
|
|
732
|
+
});
|
|
733
|
+
case "preview": return bodyRoute(operation, "/modulePrintTemplate/preview", payload);
|
|
734
|
+
case "recordSave": return bodyRoute(operation, "/modulePrintTemplate/printRecord/save", payload);
|
|
735
|
+
default: return unsupportedRoute("打印写操作", operation);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
function queryMessageRoute(args) {
|
|
739
|
+
const operation = String(args.operation);
|
|
740
|
+
const payload = safePayload(args.payload);
|
|
741
|
+
switch (operation) {
|
|
742
|
+
case "summary": return pathRoute(operation, "/moduleMessage/list");
|
|
743
|
+
case "page": return bodyRoute(operation, "/moduleMessage/listMessage", payload);
|
|
744
|
+
case "moduleType": return pathRoute(operation, `/moduleMessage/queryList/${requiredId(args.moduleId, "moduleId")}/${requiredInteger(args.type, "type")}`);
|
|
745
|
+
case "importProgress": return queryRoute(operation, "/moduleMessage/queryImportNum", { messageId: numericValue(requiredId(args.messageId, "messageId")) });
|
|
746
|
+
case "importInfo": return queryRoute(operation, "/moduleMessage/queryImportInfo", { messageId: numericValue(requiredId(args.messageId, "messageId")) });
|
|
747
|
+
default: return unsupportedRoute("消息查询", operation);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
function writeMessageRoute(args) {
|
|
751
|
+
const operation = String(args.operation);
|
|
752
|
+
const paths = { setRead: "/moduleMessage/setRead", delete: "/moduleMessage/delete" };
|
|
753
|
+
const targetPath = paths[operation];
|
|
754
|
+
if (!targetPath)
|
|
755
|
+
return unsupportedRoute("消息写操作", operation);
|
|
756
|
+
return bodyRoute(operation, targetPath, safePayload(args.payload));
|
|
757
|
+
}
|
|
758
|
+
function queryIntegrationRoute(args) {
|
|
759
|
+
const operation = String(args.operation);
|
|
760
|
+
const payload = safePayload(args.payload);
|
|
761
|
+
switch (operation) {
|
|
762
|
+
case "externalApplications": return bodyRoute(operation, "/moduleExternalApplication/list", payload);
|
|
763
|
+
case "externalModules": return pathRoute(operation, `/moduleExternal/list/${requiredId(args.applicationId, "applicationId")}`);
|
|
764
|
+
case "externalModule": return pathRoute(operation, `/moduleExternal/queryByModuleId/${requiredId(args.moduleId, "moduleId")}`);
|
|
765
|
+
case "moduleByExternalId": return pathRoute(operation, `/moduleExternal/queryModuleById/${requiredId(args.externalModuleId, "externalModuleId")}`);
|
|
766
|
+
case "openModules": return bodyRoute(operation, "/moduleOpen/pageList", payload);
|
|
767
|
+
case "openApplication": return pathRoute(operation, `/moduleOpenMetadata/queryById/${requiredId(args.applicationId, "applicationId")}`);
|
|
768
|
+
case "openConfig": return pathRoute(operation, `/moduleOpenConfig/queryList/${requiredId(args.moduleId, "moduleId")}/${requiredInteger(args.configType, "configType")}`);
|
|
769
|
+
case "openRecords": return bodyRoute(operation, `/moduleOpenData/pageList/${requiredId(args.moduleId, "moduleId")}`, payload);
|
|
770
|
+
case "openRecord": return pathRoute(operation, `/moduleOpenData/query/${requiredId(args.dataId, "dataId")}/${args.replaceMask ?? true}`);
|
|
771
|
+
case "openBoundDataIds": return pathRoute(operation, `/moduleOpenData/getBoundDataIds/${requiredId(args.dataId, "dataId")}/${requiredId(args.tabId, "tabId")}`);
|
|
772
|
+
default: return unsupportedRoute("开放能力查询", operation);
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function writeIntegrationRoute(args) {
|
|
776
|
+
const operation = String(args.operation);
|
|
777
|
+
const paths = {
|
|
778
|
+
openModules: "/moduleOpen/openModule",
|
|
779
|
+
closeModules: "/moduleOpen/closeModule"
|
|
780
|
+
};
|
|
781
|
+
const targetPath = paths[operation];
|
|
782
|
+
if (!targetPath)
|
|
783
|
+
return unsupportedRoute("开放能力写操作", operation);
|
|
784
|
+
return bodyRoute(operation, targetPath, requiredIds(args.ids, "ids"));
|
|
785
|
+
}
|
|
786
|
+
function queryMarketplaceRoute(args) {
|
|
787
|
+
const operation = String(args.operation);
|
|
788
|
+
const paths = {
|
|
789
|
+
manageCompany: "/moduleAppTemplate/getManageCompany",
|
|
790
|
+
systemCategories: "/moduleAppTemplate/appCategory/list",
|
|
791
|
+
systemApps: "/moduleAppTemplate/app/list",
|
|
792
|
+
publishStatus: "/moduleAppTemplate/queryAppPublishStatus",
|
|
793
|
+
appCategories: "/moduleAppCategory/app/list"
|
|
794
|
+
};
|
|
795
|
+
const targetPath = paths[operation];
|
|
796
|
+
if (!targetPath)
|
|
797
|
+
return unsupportedRoute("应用市场查询", operation);
|
|
798
|
+
return pathRoute(operation, targetPath);
|
|
799
|
+
}
|
|
800
|
+
function writeMarketplaceRoute(args) {
|
|
801
|
+
const operation = String(args.operation);
|
|
802
|
+
const payload = safePayload(args.payload);
|
|
803
|
+
switch (operation) {
|
|
804
|
+
case "publish": return pathRoute(operation, `/moduleAppTemplate/publish/${requiredId(args.applicationId, "applicationId")}`);
|
|
805
|
+
case "publishAll": return pathRoute(operation, "/moduleAppTemplate/publishAll");
|
|
806
|
+
case "copy": return pathRoute(operation, `/moduleAppTemplate/copy/${requiredId(args.companyId, "companyId")}`);
|
|
807
|
+
case "clearApps": return pathRoute(operation, "/moduleAppTemplate/clear");
|
|
808
|
+
case "categorySave": return bodyRoute(operation, "/moduleAppCategory/save", payload);
|
|
809
|
+
case "store": return bodyRoute(operation, "/moduleAppCategory/app/store", payload);
|
|
810
|
+
case "move": return bodyRoute(operation, "/moduleAppCategory/move", payload);
|
|
811
|
+
case "customCategorySave": return bodyRoute(operation, "/moduleAppCategory/saveAppCustomCategory", payload);
|
|
812
|
+
case "sort": return bodyRoute(operation, "/moduleAppCategory/sort", payload);
|
|
813
|
+
default: return unsupportedRoute("应用市场写操作", operation);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
function bodyRoute(operation, targetPath, body) {
|
|
817
|
+
return { operation, targetPath, body };
|
|
818
|
+
}
|
|
819
|
+
function queryRoute(operation, targetPath, query) {
|
|
820
|
+
return { operation, targetPath, query };
|
|
821
|
+
}
|
|
822
|
+
function pathRoute(operation, targetPath) {
|
|
823
|
+
return { operation, targetPath };
|
|
824
|
+
}
|
|
825
|
+
function moduleVersionRoute(operation, basePath, args) {
|
|
826
|
+
return pathRoute(operation, `${basePath}/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}`);
|
|
827
|
+
}
|
|
828
|
+
function stageFieldRoute(operation, basePath, args) {
|
|
829
|
+
return pathRoute(operation, `${basePath}/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}/${requiredId(args.stageId, "stageId")}`);
|
|
830
|
+
}
|
|
831
|
+
function unsupportedRoute(domain, operation) {
|
|
832
|
+
throw new Error(`不支持的无代码${domain}:${operation}`);
|
|
833
|
+
}
|
|
834
|
+
async function queryPermissions(client, args) {
|
|
835
|
+
switch (args.kind) {
|
|
836
|
+
case "auth":
|
|
837
|
+
return readonlyResult("/moduleRole/auth", await client.post("/moduleRole/auth"));
|
|
838
|
+
case "roles": {
|
|
839
|
+
const applicationId = requiredId(args.applicationId, "applicationId");
|
|
840
|
+
const targetPath = `/moduleRole/list/${applicationId}`;
|
|
841
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
842
|
+
}
|
|
843
|
+
case "rolesByIds":
|
|
844
|
+
return readonlyResult("/moduleRole/listByRoleId", await client.post("/moduleRole/listByRoleId", requiredIds(args.ids, "ids")));
|
|
845
|
+
case "usersRoles":
|
|
846
|
+
return readonlyResult("/moduleRole/roles/users", await client.post("/moduleRole/roles/users", requiredIds(args.ids, "ids")));
|
|
847
|
+
case "viewableUserIds": {
|
|
848
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
849
|
+
const targetPath = `/moduleRole/queryViewableUserIds/${moduleId}`;
|
|
850
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
851
|
+
}
|
|
852
|
+
case "data": {
|
|
853
|
+
const dataId = requiredId(args.dataId, "dataId");
|
|
854
|
+
const targetPath = `/moduleRole/dataAuth/${dataId}`;
|
|
855
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
856
|
+
}
|
|
857
|
+
case "field": {
|
|
858
|
+
const moduleId = requiredId(args.moduleId, "moduleId");
|
|
859
|
+
const userId = requiredId(args.userId, "userId");
|
|
860
|
+
const targetPath = `/moduleRole/fieldAuth/${moduleId}/${userId}`;
|
|
861
|
+
return readonlyResult(targetPath, await client.post(targetPath));
|
|
862
|
+
}
|
|
863
|
+
case "roleField":
|
|
864
|
+
return readonlyResult("/moduleRole/roleField", await client.post("/moduleRole/roleField", safePayload(args.payload)));
|
|
865
|
+
default:
|
|
866
|
+
throw new Error(`不支持的无代码权限查询类型:${String(args.kind)}`);
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
async function executeApplicationWrite(client, args) {
|
|
870
|
+
const action = String(args.action);
|
|
871
|
+
let targetPath;
|
|
872
|
+
let body;
|
|
873
|
+
let query;
|
|
874
|
+
switch (action) {
|
|
875
|
+
case "create":
|
|
876
|
+
targetPath = "/moduleMetadata/save";
|
|
877
|
+
body = safePayload(args.payload);
|
|
878
|
+
break;
|
|
879
|
+
case "update":
|
|
880
|
+
targetPath = "/moduleMetadata/update";
|
|
881
|
+
body = safePayload(args.payload);
|
|
882
|
+
break;
|
|
883
|
+
case "status":
|
|
884
|
+
targetPath = `/moduleMetadata/updateStatus/${requiredId(args.applicationId, "applicationId")}`;
|
|
885
|
+
query = { status: requiredInteger(args.status, "status") };
|
|
886
|
+
break;
|
|
887
|
+
case "delete":
|
|
888
|
+
targetPath = `/moduleMetadata/delete/${requiredId(args.applicationId, "applicationId")}`;
|
|
889
|
+
break;
|
|
890
|
+
case "sort":
|
|
891
|
+
targetPath = "/moduleMetadata/setAppSettingSort";
|
|
892
|
+
body = requiredIds(args.ids, "ids");
|
|
893
|
+
break;
|
|
894
|
+
case "install":
|
|
895
|
+
targetPath = `/moduleMetadata/install/${requiredId(args.applicationId, "applicationId")}`;
|
|
896
|
+
break;
|
|
897
|
+
default:
|
|
898
|
+
throw new Error(`不支持的无代码应用写操作:${action}`);
|
|
899
|
+
}
|
|
900
|
+
return confirmedPost(client, args, action, targetPath, body, query);
|
|
901
|
+
}
|
|
902
|
+
async function executeModuleWrite(client, args) {
|
|
903
|
+
const action = String(args.action);
|
|
904
|
+
let targetPath;
|
|
905
|
+
let body;
|
|
906
|
+
let query;
|
|
907
|
+
switch (action) {
|
|
908
|
+
case "save":
|
|
909
|
+
targetPath = "/moduleM/save";
|
|
910
|
+
body = safePayload(args.payload);
|
|
911
|
+
break;
|
|
912
|
+
case "status":
|
|
913
|
+
targetPath = `/moduleM/updateStatus/${requiredId(args.moduleId, "moduleId")}`;
|
|
914
|
+
query = { isEnable: requiredBoolean(args.isEnable, "isEnable") };
|
|
915
|
+
break;
|
|
916
|
+
case "copy":
|
|
917
|
+
targetPath = `/moduleM/copy/${requiredId(args.moduleId, "moduleId")}/${requiredVersion(args.version)}`;
|
|
918
|
+
break;
|
|
919
|
+
case "publish":
|
|
920
|
+
targetPath = `/moduleM/active/${requiredId(args.moduleId, "moduleId")}`;
|
|
921
|
+
break;
|
|
922
|
+
case "discardDraft":
|
|
923
|
+
targetPath = `/moduleM/discardDraft/${requiredId(args.moduleId, "moduleId")}`;
|
|
924
|
+
break;
|
|
925
|
+
case "delete":
|
|
926
|
+
targetPath = `/moduleM/delete/${requiredId(args.moduleId, "moduleId")}`;
|
|
927
|
+
break;
|
|
928
|
+
case "layout":
|
|
929
|
+
targetPath = "/moduleM/pageLayout";
|
|
930
|
+
body = safePayload(args.payload);
|
|
931
|
+
break;
|
|
932
|
+
case "deleteCancelledCompanyData":
|
|
933
|
+
targetPath = "/moduleM/deleteCancelCompanyData";
|
|
934
|
+
body = safePayload(args.payload);
|
|
935
|
+
break;
|
|
936
|
+
case "dashboardSave":
|
|
937
|
+
targetPath = "/moduleM/addOrUpdateModuleForDashboard";
|
|
938
|
+
body = safePayload(args.payload);
|
|
939
|
+
break;
|
|
940
|
+
case "dashboardRemove":
|
|
941
|
+
targetPath = "/moduleM/removeModuleForDashboard";
|
|
942
|
+
body = safePayload(args.payload);
|
|
943
|
+
break;
|
|
944
|
+
default:
|
|
945
|
+
throw new Error(`不支持的无代码模块写操作:${action}`);
|
|
946
|
+
}
|
|
947
|
+
return confirmedPost(client, args, action, targetPath, body, query);
|
|
948
|
+
}
|
|
949
|
+
async function executePayloadWrite(client, args, paths) {
|
|
950
|
+
const action = String(args.action);
|
|
951
|
+
const targetPath = paths[action];
|
|
952
|
+
if (!targetPath) {
|
|
953
|
+
throw new Error(`不支持的无代码写操作:${action}`);
|
|
954
|
+
}
|
|
955
|
+
return confirmedPost(client, args, action, targetPath, safePayload(args.payload));
|
|
956
|
+
}
|
|
957
|
+
async function executeSceneWrite(client, args) {
|
|
958
|
+
const action = String(args.action);
|
|
959
|
+
const targetPath = action === "delete" || action === "default"
|
|
960
|
+
? `/moduleScene/${action}/${requiredId(args.sceneId, "sceneId")}`
|
|
961
|
+
: action === "add" || action === "update" || action === "config"
|
|
962
|
+
? `/moduleScene/${action}`
|
|
963
|
+
: "";
|
|
964
|
+
if (!targetPath) {
|
|
965
|
+
throw new Error(`不支持的无代码场景写操作:${action}`);
|
|
966
|
+
}
|
|
967
|
+
const body = action === "delete" || action === "default" ? undefined : safePayload(args.payload);
|
|
968
|
+
return confirmedPost(client, args, action, targetPath, body);
|
|
969
|
+
}
|
|
970
|
+
async function executeRoleWrite(client, args) {
|
|
971
|
+
const action = String(args.action);
|
|
972
|
+
const pathMap = {
|
|
973
|
+
save: "/moduleRole/save",
|
|
974
|
+
saveModules: "/moduleRole/module/save",
|
|
975
|
+
saveUsers: "/moduleRole/user/save",
|
|
976
|
+
saveFields: "/moduleRole/roleField/save",
|
|
977
|
+
saveUserRole: "/moduleRole/userRole/save",
|
|
978
|
+
deleteUserRole: "/moduleRole/userRole/delete"
|
|
979
|
+
};
|
|
980
|
+
const targetPath = action === "delete" || action === "copy"
|
|
981
|
+
? `/moduleRole/${action}/${requiredId(args.roleId, "roleId")}`
|
|
982
|
+
: pathMap[action];
|
|
983
|
+
if (!targetPath) {
|
|
984
|
+
throw new Error(`不支持的无代码角色写操作:${action}`);
|
|
985
|
+
}
|
|
986
|
+
const body = action === "delete" || action === "copy" ? undefined : safePayload(args.payload);
|
|
987
|
+
return confirmedPost(client, args, action, targetPath, body);
|
|
988
|
+
}
|
|
989
|
+
async function executeTabWrite(client, args) {
|
|
990
|
+
const action = String(args.action);
|
|
991
|
+
const targetPath = action === "delete"
|
|
992
|
+
? `/moduleTab/delete/${requiredId(args.id, "id")}`
|
|
993
|
+
: action === "save"
|
|
994
|
+
? "/moduleTab/save"
|
|
995
|
+
: action === "status"
|
|
996
|
+
? "/moduleTab/updateStatus"
|
|
997
|
+
: "";
|
|
998
|
+
if (!targetPath) {
|
|
999
|
+
throw new Error(`不支持的无代码 Tab 写操作:${action}`);
|
|
1000
|
+
}
|
|
1001
|
+
const body = action === "delete" ? undefined : safePayload(args.payload);
|
|
1002
|
+
return confirmedPost(client, args, action, targetPath, body);
|
|
1003
|
+
}
|
|
1004
|
+
async function confirmedPost(client, args, action, targetPath, body, query) {
|
|
1005
|
+
// 保持旧 MCP 的既有写操作语义:未明确确认时只回显将要调用的固定接口。
|
|
1006
|
+
if (args.confirm !== true) {
|
|
1007
|
+
return {
|
|
1008
|
+
preview: true,
|
|
1009
|
+
message: "写入前预览:未传 confirm=true,MCP 不会调用 72CRM 无代码写接口。",
|
|
1010
|
+
action,
|
|
1011
|
+
targetPath,
|
|
1012
|
+
body,
|
|
1013
|
+
query
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
return {
|
|
1017
|
+
preview: false,
|
|
1018
|
+
action,
|
|
1019
|
+
targetPath,
|
|
1020
|
+
body,
|
|
1021
|
+
query,
|
|
1022
|
+
data: await client.post(targetPath, body, query)
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
function readonlyResult(targetPath, data, extra = {}) {
|
|
1026
|
+
return { readonly: true, targetPath, ...extra, data };
|
|
1027
|
+
}
|
|
1028
|
+
function requiredId(value, field) {
|
|
1029
|
+
const normalized = String(value ?? "").trim();
|
|
1030
|
+
if (!/^\d+$/.test(normalized)) {
|
|
1031
|
+
throw new Error(`${field} 必须是数字 ID。`);
|
|
1032
|
+
}
|
|
1033
|
+
return normalized;
|
|
1034
|
+
}
|
|
1035
|
+
function numericValue(value) {
|
|
1036
|
+
const numeric = Number(value);
|
|
1037
|
+
return Number.isSafeInteger(numeric) ? numeric : value;
|
|
1038
|
+
}
|
|
1039
|
+
function requiredVersion(value) {
|
|
1040
|
+
const normalized = value === undefined ? 1 : Number(value);
|
|
1041
|
+
if (!Number.isInteger(normalized) || normalized < 0) {
|
|
1042
|
+
throw new Error("version 必须是非负整数。");
|
|
1043
|
+
}
|
|
1044
|
+
return normalized;
|
|
1045
|
+
}
|
|
1046
|
+
function requiredInteger(value, field) {
|
|
1047
|
+
const normalized = Number(value);
|
|
1048
|
+
if (!Number.isInteger(normalized)) {
|
|
1049
|
+
throw new Error(`${field} 必须是整数。`);
|
|
1050
|
+
}
|
|
1051
|
+
return normalized;
|
|
1052
|
+
}
|
|
1053
|
+
function requiredBoolean(value, field) {
|
|
1054
|
+
if (typeof value !== "boolean") {
|
|
1055
|
+
throw new Error(`${field} 必须是布尔值。`);
|
|
1056
|
+
}
|
|
1057
|
+
return value;
|
|
1058
|
+
}
|
|
1059
|
+
function requiredSegment(value, field) {
|
|
1060
|
+
const normalized = String(value ?? "").trim();
|
|
1061
|
+
if (!/^[A-Za-z0-9_-]{1,32}$/.test(normalized)) {
|
|
1062
|
+
throw new Error(`${field} 必须是安全的路径参数。`);
|
|
1063
|
+
}
|
|
1064
|
+
return normalized;
|
|
1065
|
+
}
|
|
1066
|
+
function requiredIds(value, field) {
|
|
1067
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
1068
|
+
throw new Error(`${field} 必须是非空 ID 数组。`);
|
|
1069
|
+
}
|
|
1070
|
+
return value.map((item) => numericValue(requiredId(item, field)));
|
|
1071
|
+
}
|
|
1072
|
+
function safePayload(value) {
|
|
1073
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1074
|
+
return {};
|
|
1075
|
+
}
|
|
1076
|
+
return value;
|
|
1077
|
+
}
|
|
1078
|
+
function cleanObject(input) {
|
|
1079
|
+
const output = {};
|
|
1080
|
+
for (const [key, value] of Object.entries(input)) {
|
|
1081
|
+
if (value !== undefined && value !== null) {
|
|
1082
|
+
output[key] = value;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return output;
|
|
1086
|
+
}
|