bpmax-cli 0.1.38 → 0.1.40
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 +28 -14
- package/dist/bin.js +170 -75
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-project/SKILL.md +9 -6
- package/skills/bpmax-schema/SKILL.md +2 -1
package/dist/bin.js
CHANGED
|
@@ -318,9 +318,42 @@ async function parseJsonAny(input, label = "JSON input") {
|
|
|
318
318
|
function isMutatingMethod(method) {
|
|
319
319
|
return ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase());
|
|
320
320
|
}
|
|
321
|
+
function normalizeApiPath(path6) {
|
|
322
|
+
let normalized = path6.trim();
|
|
323
|
+
const queryIndex = normalized.indexOf("?");
|
|
324
|
+
if (queryIndex >= 0) {
|
|
325
|
+
normalized = normalized.slice(0, queryIndex);
|
|
326
|
+
}
|
|
327
|
+
if (!normalized.startsWith("/")) {
|
|
328
|
+
normalized = `/${normalized}`;
|
|
329
|
+
}
|
|
330
|
+
normalized = normalized.replace(/\/+/g, "/");
|
|
331
|
+
if (normalized.startsWith("/api/")) {
|
|
332
|
+
normalized = normalized.slice(4);
|
|
333
|
+
}
|
|
334
|
+
if (normalized.length > 1) {
|
|
335
|
+
normalized = normalized.replace(/\/+$/g, "");
|
|
336
|
+
}
|
|
337
|
+
return normalized;
|
|
338
|
+
}
|
|
339
|
+
function assertRawApiPathAllowed(method, path6) {
|
|
340
|
+
if (!isMutatingMethod(method)) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const normalizedPath = normalizeApiPath(path6);
|
|
344
|
+
const isProjectPath = normalizedPath === "/project" || normalizedPath.startsWith("/project/");
|
|
345
|
+
const isAllowedProjectReadPost = method === "POST" && normalizedPath === "/project/list";
|
|
346
|
+
if (!isProjectPath || isAllowedProjectReadPost) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
throw new Error(
|
|
350
|
+
`Raw API ${method} ${path6} is blocked because /api/project/<id> falls back to project creation in huanpingtong-server. Do not call /project/es-search or /project/raw-es-search; huanpingtong-server does not expose those as public ES APIs. Use bpmax-cli project create --flow-id <id> --json <json> for project creation, or bpmax-cli es project-search / project list for project reads.`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
321
353
|
function registerApiCommands(program2) {
|
|
322
354
|
program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method, path6, options) => {
|
|
323
355
|
const normalizedMethod = method.toUpperCase();
|
|
356
|
+
assertRawApiPathAllowed(normalizedMethod, path6);
|
|
324
357
|
if (isMutatingMethod(normalizedMethod) && options.confirmMutating !== true) {
|
|
325
358
|
printResult(options.format, {
|
|
326
359
|
ok: false,
|
|
@@ -733,7 +766,7 @@ import { readFile as readFile5 } from "fs/promises";
|
|
|
733
766
|
// package.json
|
|
734
767
|
var package_default = {
|
|
735
768
|
name: "bpmax-cli",
|
|
736
|
-
version: "0.1.
|
|
769
|
+
version: "0.1.40",
|
|
737
770
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
738
771
|
type: "module",
|
|
739
772
|
bin: {
|
|
@@ -1211,7 +1244,9 @@ async function lintBusinessSkillDirectory(skillDir, options = {}) {
|
|
|
1211
1244
|
{ pattern: /\bgit\s+reset\s+--hard\b/, code: "dangerous_git_reset", message: "Dangerous git reset --hard command found." },
|
|
1212
1245
|
{ pattern: /\bgit\s+checkout\s+--\b/, code: "dangerous_git_checkout", message: "Dangerous git checkout -- command found." },
|
|
1213
1246
|
{ pattern: /authorization\s*:\s*bearer|api[_-]?key\s*[:=]\s*['"][^'"]+/i, code: "secret_literal", message: "Possible literal credential found." },
|
|
1214
|
-
{ pattern: /\bcurl\b[\s\S]{0,160}\b-X\s*(POST|PUT|PATCH|DELETE)\b/i, code: "raw_mutating_curl", message: "Raw mutating curl command found; use bpmax-cli wrappers." }
|
|
1247
|
+
{ pattern: /\bcurl\b[\s\S]{0,160}\b-X\s*(POST|PUT|PATCH|DELETE)\b/i, code: "raw_mutating_curl", message: "Raw mutating curl command found; use bpmax-cli wrappers." },
|
|
1248
|
+
{ pattern: /bpmax-cli\s+project\s+create\b[^\n`]*\s--body\b/i, code: "unsafe_project_create_body", message: "BBS must not use bpmax-cli project create --body; use project create --json so the CLI can enforce form handoff safety." },
|
|
1249
|
+
{ pattern: /bpmax-cli\s+api\s+POST\s+\/(?:api\/)?project\b/i, code: "unsafe_raw_project_create_api", message: "BBS must not call raw api POST /project; use bpmax-cli project create --json." }
|
|
1215
1250
|
].forEach((rule) => {
|
|
1216
1251
|
if (rule.pattern.test(skillMarkdown)) {
|
|
1217
1252
|
issues.push(issue("error", rule.code, rule.message));
|
|
@@ -1730,17 +1765,33 @@ function registerConfigCommands(program2) {
|
|
|
1730
1765
|
}
|
|
1731
1766
|
|
|
1732
1767
|
// src/commands/es.ts
|
|
1768
|
+
function isRecord3(value) {
|
|
1769
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1770
|
+
}
|
|
1771
|
+
function hasRawProjectSearchBody(value) {
|
|
1772
|
+
return isRecord3(value) && Object.prototype.hasOwnProperty.call(value, "body");
|
|
1773
|
+
}
|
|
1733
1774
|
function registerEsCommands(program2) {
|
|
1734
1775
|
const es = program2.command("es").description("Fast ES-backed data queries");
|
|
1735
|
-
es.command("project-search").description("
|
|
1776
|
+
es.command("project-search").description("Search project ES data with the huanpingtong project-list API").option("--profile <profile>", "Profile name").option("--page <page>", "Page number for project-list payloads", "1").option("--page-size <pageSize>", "Page size for project-list payloads", "20").requiredOption("--body <json>", "Project list body JSON or @file").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1777
|
+
const body = await parseJsonInput(options.body, "--body");
|
|
1778
|
+
if (hasRawProjectSearchBody(body)) {
|
|
1779
|
+
throw new Error(
|
|
1780
|
+
"Raw ES DTO with top-level body is not supported through huanpingtong-server. Use a project-list body with bpmax-cli es project-search so the CLI calls /api/project/list. /api/project/raw-es-search is not exposed by huanpingtong-server and legacy /api/project/<id> routing can create projects."
|
|
1781
|
+
);
|
|
1782
|
+
}
|
|
1736
1783
|
const config = await loadConfig();
|
|
1737
1784
|
const profile = resolveProfile(config, options.profile);
|
|
1738
|
-
const
|
|
1785
|
+
const client = createApiClient(profile);
|
|
1739
1786
|
const result = await apiRequest(
|
|
1740
|
-
|
|
1787
|
+
client,
|
|
1741
1788
|
"POST",
|
|
1742
|
-
"/project/
|
|
1789
|
+
"/project/list",
|
|
1743
1790
|
{
|
|
1791
|
+
params: {
|
|
1792
|
+
page: Number(options.page),
|
|
1793
|
+
page_size: Number(options.pageSize)
|
|
1794
|
+
},
|
|
1744
1795
|
data: body,
|
|
1745
1796
|
preserveErrorBody: true
|
|
1746
1797
|
}
|
|
@@ -2137,7 +2188,7 @@ var OPTION_NAMES = ["options", "items", "choices", "values"];
|
|
|
2137
2188
|
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
|
|
2138
2189
|
var HIDDEN_NAMES = ["hidden", "is_hidden", "isHidden", "hide", "hideInForm"];
|
|
2139
2190
|
var VISIBLE_NAMES = ["visible", "display", "show"];
|
|
2140
|
-
function
|
|
2191
|
+
function isRecord4(value) {
|
|
2141
2192
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2142
2193
|
}
|
|
2143
2194
|
function pickString(source, keys) {
|
|
@@ -2164,10 +2215,10 @@ function pickBoolean(source, keys) {
|
|
|
2164
2215
|
}
|
|
2165
2216
|
const rules = source.rules;
|
|
2166
2217
|
if (Array.isArray(rules)) {
|
|
2167
|
-
return rules.some((rule) =>
|
|
2218
|
+
return rules.some((rule) => isRecord4(rule) && pickBoolean(rule, REQUIRED_NAMES));
|
|
2168
2219
|
}
|
|
2169
2220
|
const validateMap = source.validateMap;
|
|
2170
|
-
if (
|
|
2221
|
+
if (isRecord4(validateMap) && pickBoolean(validateMap, REQUIRED_NAMES)) {
|
|
2171
2222
|
return true;
|
|
2172
2223
|
}
|
|
2173
2224
|
return false;
|
|
@@ -2191,7 +2242,7 @@ function optionValue(option) {
|
|
|
2191
2242
|
if (typeof option === "string" || typeof option === "number") {
|
|
2192
2243
|
return String(option);
|
|
2193
2244
|
}
|
|
2194
|
-
if (!
|
|
2245
|
+
if (!isRecord4(option)) {
|
|
2195
2246
|
return null;
|
|
2196
2247
|
}
|
|
2197
2248
|
return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
|
|
@@ -2256,7 +2307,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
2256
2307
|
}
|
|
2257
2308
|
return;
|
|
2258
2309
|
}
|
|
2259
|
-
if (!
|
|
2310
|
+
if (!isRecord4(value)) {
|
|
2260
2311
|
return;
|
|
2261
2312
|
}
|
|
2262
2313
|
const field = fieldFromRecord(value);
|
|
@@ -2264,7 +2315,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
2264
2315
|
if (isSubFormField(field)) {
|
|
2265
2316
|
const childFields = /* @__PURE__ */ new Map();
|
|
2266
2317
|
for (const child of Object.values(value)) {
|
|
2267
|
-
if (
|
|
2318
|
+
if (isRecord4(child) || Array.isArray(child)) {
|
|
2268
2319
|
collectFieldCandidates(child, childFields, depth + 1);
|
|
2269
2320
|
}
|
|
2270
2321
|
}
|
|
@@ -2278,7 +2329,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
2278
2329
|
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
2279
2330
|
}
|
|
2280
2331
|
for (const child of Object.values(value)) {
|
|
2281
|
-
if (
|
|
2332
|
+
if (isRecord4(child) || Array.isArray(child)) {
|
|
2282
2333
|
collectFieldCandidates(child, fields, depth + 1);
|
|
2283
2334
|
}
|
|
2284
2335
|
}
|
|
@@ -2296,7 +2347,7 @@ function validateComplexSelector(field, value) {
|
|
|
2296
2347
|
if (!isComplexSelectorType(type)) {
|
|
2297
2348
|
return null;
|
|
2298
2349
|
}
|
|
2299
|
-
const validObject = (item) =>
|
|
2350
|
+
const validObject = (item) => isRecord4(item);
|
|
2300
2351
|
if (Array.isArray(value)) {
|
|
2301
2352
|
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
|
|
2302
2353
|
}
|
|
@@ -2312,7 +2363,7 @@ function isEnumSelectType(type) {
|
|
|
2312
2363
|
return /enum_select/.test(type);
|
|
2313
2364
|
}
|
|
2314
2365
|
function optionComparableValue(value) {
|
|
2315
|
-
if (
|
|
2366
|
+
if (isRecord4(value) && ("value" in value || "label" in value)) {
|
|
2316
2367
|
return value.value ?? value.label;
|
|
2317
2368
|
}
|
|
2318
2369
|
return value;
|
|
@@ -2326,7 +2377,7 @@ function validateType(field, value) {
|
|
|
2326
2377
|
if (!Array.isArray(value)) {
|
|
2327
2378
|
return `${field.key} must be a JSON array of row objects`;
|
|
2328
2379
|
}
|
|
2329
|
-
const invalidRowIndex = value.findIndex((row) => !
|
|
2380
|
+
const invalidRowIndex = value.findIndex((row) => !isRecord4(row));
|
|
2330
2381
|
return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
|
|
2331
2382
|
}
|
|
2332
2383
|
const selectorError = validateComplexSelector(field, value);
|
|
@@ -2352,7 +2403,7 @@ function validateType(field, value) {
|
|
|
2352
2403
|
if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
|
|
2353
2404
|
return `${field.key} must be an array`;
|
|
2354
2405
|
}
|
|
2355
|
-
if (isEnumSelectType(type) &&
|
|
2406
|
+
if (isEnumSelectType(type) && isRecord4(value)) {
|
|
2356
2407
|
const optionValue2 = value.value ?? value.label;
|
|
2357
2408
|
return typeof optionValue2 === "string" || typeof optionValue2 === "number" ? null : `${field.key} must be an enum option object with a scalar value`;
|
|
2358
2409
|
}
|
|
@@ -2382,7 +2433,7 @@ function validateFormEntries(form, fields, prefix = "") {
|
|
|
2382
2433
|
}
|
|
2383
2434
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
2384
2435
|
for (const [index, row] of value.entries()) {
|
|
2385
|
-
if (
|
|
2436
|
+
if (isRecord4(row)) {
|
|
2386
2437
|
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
2387
2438
|
}
|
|
2388
2439
|
}
|
|
@@ -2605,15 +2656,15 @@ async function promptProjectCreateForm(input) {
|
|
|
2605
2656
|
}
|
|
2606
2657
|
|
|
2607
2658
|
// src/core/project-form.ts
|
|
2608
|
-
function
|
|
2659
|
+
function isRecord5(value) {
|
|
2609
2660
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2610
2661
|
}
|
|
2611
2662
|
function clone(value) {
|
|
2612
2663
|
return JSON.parse(JSON.stringify(value));
|
|
2613
2664
|
}
|
|
2614
2665
|
function getFlowFormTemplateId(flowDetail) {
|
|
2615
|
-
const data =
|
|
2616
|
-
const meta =
|
|
2666
|
+
const data = isRecord5(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2667
|
+
const meta = isRecord5(data?.meta) ? data.meta : void 0;
|
|
2617
2668
|
const templateId = meta?.form_template;
|
|
2618
2669
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
2619
2670
|
return templateId;
|
|
@@ -2636,7 +2687,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
2636
2687
|
if (Array.isArray(value)) {
|
|
2637
2688
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
2638
2689
|
}
|
|
2639
|
-
if (!
|
|
2690
|
+
if (!isRecord5(value)) {
|
|
2640
2691
|
return false;
|
|
2641
2692
|
}
|
|
2642
2693
|
if (seen.has(value)) {
|
|
@@ -2651,14 +2702,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
2651
2702
|
function setControlValue(control, value) {
|
|
2652
2703
|
const next = clone(control);
|
|
2653
2704
|
next.value = {
|
|
2654
|
-
...
|
|
2705
|
+
...isRecord5(next.value) ? next.value : {},
|
|
2655
2706
|
type: next.value?.type ?? next.field_type,
|
|
2656
2707
|
value
|
|
2657
2708
|
};
|
|
2658
2709
|
return next;
|
|
2659
2710
|
}
|
|
2660
2711
|
function applyRowValues(rowTemplate, rowValue) {
|
|
2661
|
-
const source =
|
|
2712
|
+
const source = isRecord5(rowValue) ? rowValue : {};
|
|
2662
2713
|
return rowTemplate.map((control) => {
|
|
2663
2714
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
2664
2715
|
return setControlValue(control, source[control.key]);
|
|
@@ -2858,6 +2909,7 @@ async function printCreateFormHandoff(client, format, profile, flowIdentifiers,
|
|
|
2858
2909
|
printResult(format, {
|
|
2859
2910
|
handoff: true,
|
|
2860
2911
|
...options.reason ? { reason: options.reason } : {},
|
|
2912
|
+
...options.handoffReasons?.length ? { handoff_reasons: options.handoffReasons } : {},
|
|
2861
2913
|
url: url.url,
|
|
2862
2914
|
pc_url: url.pc_url,
|
|
2863
2915
|
mobile_path: url.mobile_path,
|
|
@@ -2921,8 +2973,8 @@ function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
|
2921
2973
|
}));
|
|
2922
2974
|
}
|
|
2923
2975
|
function metaUsesTemplateProjectName(flowDetail) {
|
|
2924
|
-
const data =
|
|
2925
|
-
const meta =
|
|
2976
|
+
const data = isRecord6(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2977
|
+
const meta = isRecord6(data?.meta) ? data.meta : void 0;
|
|
2926
2978
|
const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
2927
2979
|
return meta?.use_template_project_name === true || hideFields.includes("project.name");
|
|
2928
2980
|
}
|
|
@@ -2944,6 +2996,41 @@ function assertHandoffFormCompatible(fields, form) {
|
|
|
2944
2996
|
);
|
|
2945
2997
|
}
|
|
2946
2998
|
}
|
|
2999
|
+
function isRiskyFormField(field) {
|
|
3000
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
3001
|
+
const label = field.label?.toLowerCase() ?? "";
|
|
3002
|
+
const key = field.key.toLowerCase();
|
|
3003
|
+
return /(serial|sequence|auto[_-]?number|auto[_-]?no|流水|编号)/.test(`${type} ${label} ${key}`) || /(plugin_|selector|upload|rich[_-]?text|editor|relation[_-]?project|relation[_-]?form|associated[_-]?form|sub[_-]?form|table)/.test(type);
|
|
3004
|
+
}
|
|
3005
|
+
function collectHandoffReasons(fields, template) {
|
|
3006
|
+
const reasons = /* @__PURE__ */ new Set();
|
|
3007
|
+
if (template && hasAutoInitLambda(template)) {
|
|
3008
|
+
reasons.add("auto_init_lambda");
|
|
3009
|
+
}
|
|
3010
|
+
for (const field of fields) {
|
|
3011
|
+
if (field.hidden) {
|
|
3012
|
+
continue;
|
|
3013
|
+
}
|
|
3014
|
+
if (isRiskyFormField(field)) {
|
|
3015
|
+
const type = field.type ?? "unknown";
|
|
3016
|
+
const label = field.label ? ` (${field.label})` : "";
|
|
3017
|
+
reasons.add(`page_only_field:${field.key}:${type}${label}`);
|
|
3018
|
+
}
|
|
3019
|
+
if (field.children?.length) {
|
|
3020
|
+
for (const child of field.children) {
|
|
3021
|
+
if (!child.hidden && isRiskyFormField(child)) {
|
|
3022
|
+
const type = child.type ?? "unknown";
|
|
3023
|
+
const label = child.label ? ` (${child.label})` : "";
|
|
3024
|
+
reasons.add(`page_only_field:${field.key}.${child.key}:${type}${label}`);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
return [...reasons];
|
|
3030
|
+
}
|
|
3031
|
+
function formatHandoffReasonsForMessage(reasons) {
|
|
3032
|
+
return reasons.map((reason) => reason === "auto_init_lambda" ? "\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C" : reason).join(", ");
|
|
3033
|
+
}
|
|
2947
3034
|
function isEmptyValue(value) {
|
|
2948
3035
|
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
2949
3036
|
}
|
|
@@ -2977,7 +3064,7 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
|
2977
3064
|
result.filled_fields.push(contextField(field, "prefilled", fieldOptions));
|
|
2978
3065
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
2979
3066
|
value.forEach((row, index) => {
|
|
2980
|
-
if (
|
|
3067
|
+
if (isRecord6(row)) {
|
|
2981
3068
|
collectPrefillContextForFields(field.children ?? [], row, result, {
|
|
2982
3069
|
prefix: `${field.key}[${index}]`,
|
|
2983
3070
|
rootKey: field.key,
|
|
@@ -3004,7 +3091,7 @@ function buildPrefillContext(fields, form) {
|
|
|
3004
3091
|
}
|
|
3005
3092
|
};
|
|
3006
3093
|
}
|
|
3007
|
-
function
|
|
3094
|
+
function isRecord6(value) {
|
|
3008
3095
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3009
3096
|
}
|
|
3010
3097
|
function isEndedStep(step) {
|
|
@@ -3027,7 +3114,7 @@ function stepIdOf(step) {
|
|
|
3027
3114
|
function pickStepFormPayload(step) {
|
|
3028
3115
|
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
3029
3116
|
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
3030
|
-
const metaForm =
|
|
3117
|
+
const metaForm = isRecord6(step.metaForm) ? step.metaForm : void 0;
|
|
3031
3118
|
return {
|
|
3032
3119
|
step_id: step.id,
|
|
3033
3120
|
flow_step_id: step.flow_step_id,
|
|
@@ -3044,7 +3131,7 @@ function pickStepFormPayload(step) {
|
|
|
3044
3131
|
}
|
|
3045
3132
|
async function buildApprovalContext(client, projectId, options) {
|
|
3046
3133
|
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
3047
|
-
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(
|
|
3134
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord6) : [];
|
|
3048
3135
|
const targetStepIds = /* @__PURE__ */ new Set();
|
|
3049
3136
|
for (const step of steps) {
|
|
3050
3137
|
const id = stepIdOf(step);
|
|
@@ -3070,7 +3157,7 @@ async function buildApprovalContext(client, projectId, options) {
|
|
|
3070
3157
|
}
|
|
3071
3158
|
return {
|
|
3072
3159
|
project: projectDetail,
|
|
3073
|
-
project_form:
|
|
3160
|
+
project_form: isRecord6(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
3074
3161
|
inspected_step_count: stepForms.length,
|
|
3075
3162
|
step_forms: stepForms,
|
|
3076
3163
|
failed_steps: failedSteps
|
|
@@ -3146,18 +3233,27 @@ function registerProjectCommands(program2) {
|
|
|
3146
3233
|
project: attachProjectDetailUrl(profile, context.project)
|
|
3147
3234
|
});
|
|
3148
3235
|
});
|
|
3149
|
-
project.command("create").description("Minimal project create shortcut").option("--profile <profile>", "Profile name").option("--flow-id <flowId>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--name <name>", "Project name").option("--json <json>", "Additional request JSON").option("--body <body>", "Full request body JSON override").option("--interactive", "Guide the user through filling project form fields").option("--no-interactive", "Disable the project create guide and submit directly when safe").option("--allow-form-handoff", "Allow interactive mode to hand off to the BPMAX web create form").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
|
|
3236
|
+
project.command("create").description("Minimal project create shortcut").option("--profile <profile>", "Profile name").option("--flow-id <flowId>", "Flow id").option("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--name <name>", "Project name").option("--json <json>", "Additional request JSON").option("--body <body>", "Full request body JSON override").option("--unsafe-direct-create", "Allow raw --body direct project creation without form-template safety checks").option("--interactive", "Guide the user through filling project form fields").option("--no-interactive", "Disable the project create guide and submit directly when safe").option("--allow-form-handoff", "Allow interactive mode to hand off to the BPMAX web create form").option("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options, command) => {
|
|
3150
3237
|
const interactiveSource = command.getOptionValueSource("interactive");
|
|
3151
3238
|
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
3152
3239
|
throw new Error("--body and --interactive cannot be used together.");
|
|
3153
3240
|
}
|
|
3241
|
+
if (options.body && options.unsafeDirectCreate !== true) {
|
|
3242
|
+
throw new Error(
|
|
3243
|
+
[
|
|
3244
|
+
"--body direct project creation bypasses flow form-template safety checks and is blocked by default.",
|
|
3245
|
+
"Use project create --json with --flow-id/--flow-type so bpmax-cli can return a handoff URL when needed.",
|
|
3246
|
+
"Only local experts may re-run with --unsafe-direct-create if they intentionally want the raw legacy behavior."
|
|
3247
|
+
].join("\n")
|
|
3248
|
+
);
|
|
3249
|
+
}
|
|
3154
3250
|
const config = await loadConfig();
|
|
3155
3251
|
const profile = resolveProfile(config, options.profile);
|
|
3156
3252
|
const client = createApiClient(profile);
|
|
3157
3253
|
const useInteractive = !options.body && options.interactive !== false;
|
|
3158
3254
|
let payload = parseJson(options.body);
|
|
3159
3255
|
if (!options.body) {
|
|
3160
|
-
const flow = await resolveFlowIdentifiers(client, options, { loadDetail:
|
|
3256
|
+
const flow = await resolveFlowIdentifiers(client, options, { loadDetail: true });
|
|
3161
3257
|
const { flowDetail, ...flowIdentifiers } = flow;
|
|
3162
3258
|
const extra = parseJson(options.json);
|
|
3163
3259
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
@@ -3192,15 +3288,17 @@ function registerProjectCommands(program2) {
|
|
|
3192
3288
|
printResult(options.format, { cancelled: true });
|
|
3193
3289
|
return;
|
|
3194
3290
|
}
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3291
|
+
const handoffReasons2 = collectHandoffReasons(fields, projectFormTemplate?.template);
|
|
3292
|
+
if (handoffReasons2.length > 0) {
|
|
3293
|
+
const handoffFields2 = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3294
|
+
assertHandoffFormCompatible(handoffFields2, form);
|
|
3198
3295
|
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
3199
3296
|
name,
|
|
3200
3297
|
form,
|
|
3201
|
-
fields:
|
|
3202
|
-
reason: "
|
|
3203
|
-
|
|
3298
|
+
fields: handoffFields2,
|
|
3299
|
+
reason: "form_template_requires_page_handoff",
|
|
3300
|
+
handoffReasons: handoffReasons2,
|
|
3301
|
+
message: `\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u9700\u8981\u9875\u9762\u63A5\u7BA1\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002\u539F\u56E0\uFF1A${formatHandoffReasonsForMessage(handoffReasons2)}`
|
|
3204
3302
|
});
|
|
3205
3303
|
return;
|
|
3206
3304
|
}
|
|
@@ -3208,12 +3306,12 @@ function registerProjectCommands(program2) {
|
|
|
3208
3306
|
if (!options.allowFormHandoff) {
|
|
3209
3307
|
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
3210
3308
|
}
|
|
3211
|
-
const
|
|
3212
|
-
assertHandoffFormCompatible(
|
|
3309
|
+
const handoffFields2 = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3310
|
+
assertHandoffFormCompatible(handoffFields2, form);
|
|
3213
3311
|
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
3214
3312
|
name,
|
|
3215
3313
|
form,
|
|
3216
|
-
fields:
|
|
3314
|
+
fields: handoffFields2,
|
|
3217
3315
|
message: "\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
3218
3316
|
});
|
|
3219
3317
|
return;
|
|
@@ -3223,23 +3321,17 @@ function registerProjectCommands(program2) {
|
|
|
3223
3321
|
throw new Error("--name is required unless --body is provided.");
|
|
3224
3322
|
}
|
|
3225
3323
|
projectFormTemplate = await loadProjectFormTemplate();
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
throw new Error(
|
|
3230
|
-
[
|
|
3231
|
-
"Form template has auto initialization scripts and cannot be handed off before any form values are collected.",
|
|
3232
|
-
"Rerun without --no-interactive to guide the user through the form, or provide --json.form with the missing values."
|
|
3233
|
-
].join("\n")
|
|
3234
|
-
);
|
|
3235
|
-
}
|
|
3324
|
+
const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3325
|
+
const handoffReasons = collectHandoffReasons(handoffFields, projectFormTemplate?.template);
|
|
3326
|
+
if (handoffReasons.length > 0) {
|
|
3236
3327
|
assertHandoffFormCompatible(handoffFields, form);
|
|
3237
3328
|
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
3238
3329
|
name: name ?? "",
|
|
3239
3330
|
form,
|
|
3240
3331
|
fields: handoffFields,
|
|
3241
|
-
reason: "
|
|
3242
|
-
|
|
3332
|
+
reason: "form_template_requires_page_handoff",
|
|
3333
|
+
handoffReasons,
|
|
3334
|
+
message: `\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u9700\u8981\u9875\u9762\u63A5\u7BA1\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002\u539F\u56E0\uFF1A${formatHandoffReasonsForMessage(handoffReasons)}`
|
|
3243
3335
|
});
|
|
3244
3336
|
return;
|
|
3245
3337
|
}
|
|
@@ -3306,7 +3398,7 @@ function getRecipesDir(options) {
|
|
|
3306
3398
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
3307
3399
|
return path4.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
3308
3400
|
}
|
|
3309
|
-
function
|
|
3401
|
+
function isRecord7(value) {
|
|
3310
3402
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3311
3403
|
}
|
|
3312
3404
|
function asString(value, fieldName) {
|
|
@@ -3316,7 +3408,7 @@ function asString(value, fieldName) {
|
|
|
3316
3408
|
return value;
|
|
3317
3409
|
}
|
|
3318
3410
|
function parseRecipeDefinition(input) {
|
|
3319
|
-
if (!
|
|
3411
|
+
if (!isRecord7(input)) {
|
|
3320
3412
|
throw new Error("recipe.json must be a JSON object.");
|
|
3321
3413
|
}
|
|
3322
3414
|
if (input.version !== 1) {
|
|
@@ -3324,7 +3416,7 @@ function parseRecipeDefinition(input) {
|
|
|
3324
3416
|
}
|
|
3325
3417
|
const name = asString(input.name, "recipe.name");
|
|
3326
3418
|
assertSafeName("Recipe name", name);
|
|
3327
|
-
if (!
|
|
3419
|
+
if (!isRecord7(input.command)) {
|
|
3328
3420
|
throw new Error("recipe.command must be an object.");
|
|
3329
3421
|
}
|
|
3330
3422
|
const argv = input.command.argv;
|
|
@@ -3332,7 +3424,7 @@ function parseRecipeDefinition(input) {
|
|
|
3332
3424
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
3333
3425
|
}
|
|
3334
3426
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
3335
|
-
if (!
|
|
3427
|
+
if (!isRecord7(item)) {
|
|
3336
3428
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
3337
3429
|
}
|
|
3338
3430
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -3408,7 +3500,7 @@ function parseVarsJson(input) {
|
|
|
3408
3500
|
return {};
|
|
3409
3501
|
}
|
|
3410
3502
|
const parsed = JSON.parse(input);
|
|
3411
|
-
if (!
|
|
3503
|
+
if (!isRecord7(parsed)) {
|
|
3412
3504
|
throw new Error("--vars must be a JSON object.");
|
|
3413
3505
|
}
|
|
3414
3506
|
const variables = {};
|
|
@@ -3489,9 +3581,12 @@ async function writeRecipeScaffold(options) {
|
|
|
3489
3581
|
title,
|
|
3490
3582
|
description: "Describe what this BPMAX environment recipe does.",
|
|
3491
3583
|
workspace: options.location.workspaceDirName,
|
|
3492
|
-
variables: [
|
|
3584
|
+
variables: [
|
|
3585
|
+
{ name: "flow_id", required: true },
|
|
3586
|
+
{ name: "name", required: true }
|
|
3587
|
+
],
|
|
3493
3588
|
command: {
|
|
3494
|
-
argv: ["project", "create", "--
|
|
3589
|
+
argv: ["project", "create", "--flow-id", "{{flow_id}}", "--name", "{{name}}", "--json", "@payload.json", "--format", "json"],
|
|
3495
3590
|
mutating: true
|
|
3496
3591
|
}
|
|
3497
3592
|
};
|
|
@@ -3499,7 +3594,7 @@ async function writeRecipeScaffold(options) {
|
|
|
3499
3594
|
`, "utf8");
|
|
3500
3595
|
await writeFile4(
|
|
3501
3596
|
path4.join(options.location.recipeDir, "payload.json"),
|
|
3502
|
-
`${JSON.stringify({
|
|
3597
|
+
`${JSON.stringify({ form: {} }, null, 2)}
|
|
3503
3598
|
`,
|
|
3504
3599
|
"utf8"
|
|
3505
3600
|
);
|
|
@@ -3638,7 +3733,7 @@ var schemaEntries = [
|
|
|
3638
3733
|
{ name: "flow.list", description: "List flows.", method: "GET", path: "/api/flow/flow_type" },
|
|
3639
3734
|
{ name: "flow.options", description: "List flow options.", method: "GET", path: "/api/flow/options" },
|
|
3640
3735
|
{ name: "flow.get", description: "Fetch flow details by id.", method: "POST", path: "/api/flow/batch_get" },
|
|
3641
|
-
{ name: "es.project-search", description: "
|
|
3736
|
+
{ name: "es.project-search", description: "Search project ES data through huanpingtong /api/project/list only.", method: "POST", path: "/api/project/list" },
|
|
3642
3737
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
3643
3738
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
3644
3739
|
{ name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
|
|
@@ -3754,7 +3849,7 @@ function registerSetupCommand(program2, deps = {}) {
|
|
|
3754
3849
|
}
|
|
3755
3850
|
|
|
3756
3851
|
// src/commands/step.ts
|
|
3757
|
-
function
|
|
3852
|
+
function isRecord8(value) {
|
|
3758
3853
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3759
3854
|
}
|
|
3760
3855
|
function stringValue(value) {
|
|
@@ -3781,7 +3876,7 @@ function hasMeaningfulValue(value) {
|
|
|
3781
3876
|
if (Array.isArray(value)) {
|
|
3782
3877
|
return value.some(hasMeaningfulValue);
|
|
3783
3878
|
}
|
|
3784
|
-
if (
|
|
3879
|
+
if (isRecord8(value)) {
|
|
3785
3880
|
return Object.values(value).some(hasMeaningfulValue);
|
|
3786
3881
|
}
|
|
3787
3882
|
return false;
|
|
@@ -3790,7 +3885,7 @@ function isEmptyValue2(value) {
|
|
|
3790
3885
|
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
3791
3886
|
}
|
|
3792
3887
|
function projectIdOfStep(step) {
|
|
3793
|
-
const nestedProjectId =
|
|
3888
|
+
const nestedProjectId = isRecord8(step.project) ? step.project.id : void 0;
|
|
3794
3889
|
return idValue(step.project_id ?? step.projectId ?? nestedProjectId);
|
|
3795
3890
|
}
|
|
3796
3891
|
function stepFlowNodeId(step) {
|
|
@@ -3818,12 +3913,12 @@ function collectRecords(value, output = [], seen = /* @__PURE__ */ new Set()) {
|
|
|
3818
3913
|
value.forEach((item) => collectRecords(item, output, seen));
|
|
3819
3914
|
return output;
|
|
3820
3915
|
}
|
|
3821
|
-
if (!
|
|
3916
|
+
if (!isRecord8(value)) {
|
|
3822
3917
|
return output;
|
|
3823
3918
|
}
|
|
3824
3919
|
output.push(value);
|
|
3825
3920
|
for (const child of Object.values(value)) {
|
|
3826
|
-
if (Array.isArray(child) ||
|
|
3921
|
+
if (Array.isArray(child) || isRecord8(child)) {
|
|
3827
3922
|
collectRecords(child, output, seen);
|
|
3828
3923
|
}
|
|
3829
3924
|
}
|
|
@@ -3907,7 +4002,7 @@ function formListOfStep(step) {
|
|
|
3907
4002
|
return values.filter(hasMeaningfulValue);
|
|
3908
4003
|
}
|
|
3909
4004
|
function unwrapFormValue(value) {
|
|
3910
|
-
if (!
|
|
4005
|
+
if (!isRecord8(value)) {
|
|
3911
4006
|
return value;
|
|
3912
4007
|
}
|
|
3913
4008
|
if ("value" in value && Object.keys(value).length <= 3) {
|
|
@@ -3924,7 +4019,7 @@ function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set())
|
|
|
3924
4019
|
value.forEach((item) => collectFormValues(item, output, seen));
|
|
3925
4020
|
return output;
|
|
3926
4021
|
}
|
|
3927
|
-
if (!
|
|
4022
|
+
if (!isRecord8(value)) {
|
|
3928
4023
|
return output;
|
|
3929
4024
|
}
|
|
3930
4025
|
const key = stringValue(value.key ?? value.field_key ?? value.fieldKey ?? value.name);
|
|
@@ -3935,7 +4030,7 @@ function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set())
|
|
|
3935
4030
|
}
|
|
3936
4031
|
}
|
|
3937
4032
|
for (const child of Object.values(value)) {
|
|
3938
|
-
if (Array.isArray(child) ||
|
|
4033
|
+
if (Array.isArray(child) || isRecord8(child)) {
|
|
3939
4034
|
collectFormValues(child, output, seen);
|
|
3940
4035
|
}
|
|
3941
4036
|
}
|
|
@@ -3982,7 +4077,7 @@ function collectMissingRequiredInputs(fields, values) {
|
|
|
3982
4077
|
continue;
|
|
3983
4078
|
}
|
|
3984
4079
|
value.forEach((row, index) => {
|
|
3985
|
-
if (!
|
|
4080
|
+
if (!isRecord8(row)) {
|
|
3986
4081
|
return;
|
|
3987
4082
|
}
|
|
3988
4083
|
for (const child of field.children ?? []) {
|
|
@@ -4037,7 +4132,7 @@ function ownerIdsFromStep(step) {
|
|
|
4037
4132
|
];
|
|
4038
4133
|
const ids = /* @__PURE__ */ new Set();
|
|
4039
4134
|
for (const owner of owners) {
|
|
4040
|
-
if (
|
|
4135
|
+
if (isRecord8(owner)) {
|
|
4041
4136
|
const id = idValue(owner.owner_id ?? owner.user_id ?? owner.id);
|
|
4042
4137
|
if (id) {
|
|
4043
4138
|
ids.add(id);
|
|
@@ -4140,12 +4235,12 @@ function extractSubmitInputValues(data) {
|
|
|
4140
4235
|
const candidates = [data.form, data.form_data, data.formData, data.fields, data.values];
|
|
4141
4236
|
const values = {};
|
|
4142
4237
|
for (const candidate of candidates) {
|
|
4143
|
-
if (
|
|
4238
|
+
if (isRecord8(candidate)) {
|
|
4144
4239
|
Object.assign(values, candidate);
|
|
4145
4240
|
}
|
|
4146
4241
|
}
|
|
4147
4242
|
for (const [key, value] of Object.entries(data)) {
|
|
4148
|
-
if (!SUBMIT_NON_FORM_KEYS.has(key) && !
|
|
4243
|
+
if (!SUBMIT_NON_FORM_KEYS.has(key) && !isRecord8(value) && !Array.isArray(value)) {
|
|
4149
4244
|
values[key] = value;
|
|
4150
4245
|
}
|
|
4151
4246
|
}
|