bpmax-cli 0.1.37 → 0.1.39
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 +26 -8
- package/dist/bin.js +305 -69
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-cli/SKILL.md +1 -1
- package/skills/bpmax-project/SKILL.md +14 -8
- package/skills/bpmax-schema/SKILL.md +2 -1
package/dist/bin.js
CHANGED
|
@@ -733,7 +733,7 @@ import { readFile as readFile5 } from "fs/promises";
|
|
|
733
733
|
// package.json
|
|
734
734
|
var package_default = {
|
|
735
735
|
name: "bpmax-cli",
|
|
736
|
-
version: "0.1.
|
|
736
|
+
version: "0.1.39",
|
|
737
737
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
738
738
|
type: "module",
|
|
739
739
|
bin: {
|
|
@@ -1211,7 +1211,9 @@ async function lintBusinessSkillDirectory(skillDir, options = {}) {
|
|
|
1211
1211
|
{ pattern: /\bgit\s+reset\s+--hard\b/, code: "dangerous_git_reset", message: "Dangerous git reset --hard command found." },
|
|
1212
1212
|
{ pattern: /\bgit\s+checkout\s+--\b/, code: "dangerous_git_checkout", message: "Dangerous git checkout -- command found." },
|
|
1213
1213
|
{ 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." }
|
|
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." },
|
|
1215
|
+
{ 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." },
|
|
1216
|
+
{ 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
1217
|
].forEach((rule) => {
|
|
1216
1218
|
if (rule.pattern.test(skillMarkdown)) {
|
|
1217
1219
|
issues.push(issue("error", rule.code, rule.message));
|
|
@@ -1730,17 +1732,41 @@ function registerConfigCommands(program2) {
|
|
|
1730
1732
|
}
|
|
1731
1733
|
|
|
1732
1734
|
// src/commands/es.ts
|
|
1735
|
+
function isRecord3(value) {
|
|
1736
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1737
|
+
}
|
|
1738
|
+
function isRawProjectSearchBody(value) {
|
|
1739
|
+
return isRecord3(value) && Object.prototype.hasOwnProperty.call(value, "body");
|
|
1740
|
+
}
|
|
1733
1741
|
function registerEsCommands(program2) {
|
|
1734
1742
|
const es = program2.command("es").description("Fast ES-backed data queries");
|
|
1735
|
-
es.command("project-search").description("
|
|
1743
|
+
es.command("project-search").description("Search project ES data with the project-list API, or raw ES when body.body is provided").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 raw ES request body JSON/@file").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
1736
1744
|
const config = await loadConfig();
|
|
1737
1745
|
const profile = resolveProfile(config, options.profile);
|
|
1738
1746
|
const body = await parseJsonInput(options.body, "--body");
|
|
1747
|
+
const client = createApiClient(profile);
|
|
1748
|
+
if (isRawProjectSearchBody(body)) {
|
|
1749
|
+
const result2 = await apiRequest(
|
|
1750
|
+
client,
|
|
1751
|
+
"POST",
|
|
1752
|
+
"/project/raw-es-search",
|
|
1753
|
+
{
|
|
1754
|
+
data: body,
|
|
1755
|
+
preserveErrorBody: true
|
|
1756
|
+
}
|
|
1757
|
+
);
|
|
1758
|
+
printResult(options.format, result2);
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1739
1761
|
const result = await apiRequest(
|
|
1740
|
-
|
|
1762
|
+
client,
|
|
1741
1763
|
"POST",
|
|
1742
|
-
"/project/
|
|
1764
|
+
"/project/list",
|
|
1743
1765
|
{
|
|
1766
|
+
params: {
|
|
1767
|
+
page: Number(options.page),
|
|
1768
|
+
page_size: Number(options.pageSize)
|
|
1769
|
+
},
|
|
1744
1770
|
data: body,
|
|
1745
1771
|
preserveErrorBody: true
|
|
1746
1772
|
}
|
|
@@ -2137,7 +2163,7 @@ var OPTION_NAMES = ["options", "items", "choices", "values"];
|
|
|
2137
2163
|
var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
|
|
2138
2164
|
var HIDDEN_NAMES = ["hidden", "is_hidden", "isHidden", "hide", "hideInForm"];
|
|
2139
2165
|
var VISIBLE_NAMES = ["visible", "display", "show"];
|
|
2140
|
-
function
|
|
2166
|
+
function isRecord4(value) {
|
|
2141
2167
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2142
2168
|
}
|
|
2143
2169
|
function pickString(source, keys) {
|
|
@@ -2164,10 +2190,10 @@ function pickBoolean(source, keys) {
|
|
|
2164
2190
|
}
|
|
2165
2191
|
const rules = source.rules;
|
|
2166
2192
|
if (Array.isArray(rules)) {
|
|
2167
|
-
return rules.some((rule) =>
|
|
2193
|
+
return rules.some((rule) => isRecord4(rule) && pickBoolean(rule, REQUIRED_NAMES));
|
|
2168
2194
|
}
|
|
2169
2195
|
const validateMap = source.validateMap;
|
|
2170
|
-
if (
|
|
2196
|
+
if (isRecord4(validateMap) && pickBoolean(validateMap, REQUIRED_NAMES)) {
|
|
2171
2197
|
return true;
|
|
2172
2198
|
}
|
|
2173
2199
|
return false;
|
|
@@ -2191,7 +2217,7 @@ function optionValue(option) {
|
|
|
2191
2217
|
if (typeof option === "string" || typeof option === "number") {
|
|
2192
2218
|
return String(option);
|
|
2193
2219
|
}
|
|
2194
|
-
if (!
|
|
2220
|
+
if (!isRecord4(option)) {
|
|
2195
2221
|
return null;
|
|
2196
2222
|
}
|
|
2197
2223
|
return pickString(option, ["value", "key", "id", "name", "label", "title"]) ?? null;
|
|
@@ -2256,7 +2282,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
2256
2282
|
}
|
|
2257
2283
|
return;
|
|
2258
2284
|
}
|
|
2259
|
-
if (!
|
|
2285
|
+
if (!isRecord4(value)) {
|
|
2260
2286
|
return;
|
|
2261
2287
|
}
|
|
2262
2288
|
const field = fieldFromRecord(value);
|
|
@@ -2264,7 +2290,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
2264
2290
|
if (isSubFormField(field)) {
|
|
2265
2291
|
const childFields = /* @__PURE__ */ new Map();
|
|
2266
2292
|
for (const child of Object.values(value)) {
|
|
2267
|
-
if (
|
|
2293
|
+
if (isRecord4(child) || Array.isArray(child)) {
|
|
2268
2294
|
collectFieldCandidates(child, childFields, depth + 1);
|
|
2269
2295
|
}
|
|
2270
2296
|
}
|
|
@@ -2278,7 +2304,7 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
2278
2304
|
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
2279
2305
|
}
|
|
2280
2306
|
for (const child of Object.values(value)) {
|
|
2281
|
-
if (
|
|
2307
|
+
if (isRecord4(child) || Array.isArray(child)) {
|
|
2282
2308
|
collectFieldCandidates(child, fields, depth + 1);
|
|
2283
2309
|
}
|
|
2284
2310
|
}
|
|
@@ -2296,7 +2322,7 @@ function validateComplexSelector(field, value) {
|
|
|
2296
2322
|
if (!isComplexSelectorType(type)) {
|
|
2297
2323
|
return null;
|
|
2298
2324
|
}
|
|
2299
|
-
const validObject = (item) =>
|
|
2325
|
+
const validObject = (item) => isRecord4(item);
|
|
2300
2326
|
if (Array.isArray(value)) {
|
|
2301
2327
|
return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
|
|
2302
2328
|
}
|
|
@@ -2312,7 +2338,7 @@ function isEnumSelectType(type) {
|
|
|
2312
2338
|
return /enum_select/.test(type);
|
|
2313
2339
|
}
|
|
2314
2340
|
function optionComparableValue(value) {
|
|
2315
|
-
if (
|
|
2341
|
+
if (isRecord4(value) && ("value" in value || "label" in value)) {
|
|
2316
2342
|
return value.value ?? value.label;
|
|
2317
2343
|
}
|
|
2318
2344
|
return value;
|
|
@@ -2326,7 +2352,7 @@ function validateType(field, value) {
|
|
|
2326
2352
|
if (!Array.isArray(value)) {
|
|
2327
2353
|
return `${field.key} must be a JSON array of row objects`;
|
|
2328
2354
|
}
|
|
2329
|
-
const invalidRowIndex = value.findIndex((row) => !
|
|
2355
|
+
const invalidRowIndex = value.findIndex((row) => !isRecord4(row));
|
|
2330
2356
|
return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
|
|
2331
2357
|
}
|
|
2332
2358
|
const selectorError = validateComplexSelector(field, value);
|
|
@@ -2352,7 +2378,7 @@ function validateType(field, value) {
|
|
|
2352
2378
|
if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
|
|
2353
2379
|
return `${field.key} must be an array`;
|
|
2354
2380
|
}
|
|
2355
|
-
if (isEnumSelectType(type) &&
|
|
2381
|
+
if (isEnumSelectType(type) && isRecord4(value)) {
|
|
2356
2382
|
const optionValue2 = value.value ?? value.label;
|
|
2357
2383
|
return typeof optionValue2 === "string" || typeof optionValue2 === "number" ? null : `${field.key} must be an enum option object with a scalar value`;
|
|
2358
2384
|
}
|
|
@@ -2382,7 +2408,7 @@ function validateFormEntries(form, fields, prefix = "") {
|
|
|
2382
2408
|
}
|
|
2383
2409
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
2384
2410
|
for (const [index, row] of value.entries()) {
|
|
2385
|
-
if (
|
|
2411
|
+
if (isRecord4(row)) {
|
|
2386
2412
|
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
2387
2413
|
}
|
|
2388
2414
|
}
|
|
@@ -2605,15 +2631,15 @@ async function promptProjectCreateForm(input) {
|
|
|
2605
2631
|
}
|
|
2606
2632
|
|
|
2607
2633
|
// src/core/project-form.ts
|
|
2608
|
-
function
|
|
2634
|
+
function isRecord5(value) {
|
|
2609
2635
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2610
2636
|
}
|
|
2611
2637
|
function clone(value) {
|
|
2612
2638
|
return JSON.parse(JSON.stringify(value));
|
|
2613
2639
|
}
|
|
2614
2640
|
function getFlowFormTemplateId(flowDetail) {
|
|
2615
|
-
const data =
|
|
2616
|
-
const meta =
|
|
2641
|
+
const data = isRecord5(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2642
|
+
const meta = isRecord5(data?.meta) ? data.meta : void 0;
|
|
2617
2643
|
const templateId = meta?.form_template;
|
|
2618
2644
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
2619
2645
|
return templateId;
|
|
@@ -2636,7 +2662,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
2636
2662
|
if (Array.isArray(value)) {
|
|
2637
2663
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
2638
2664
|
}
|
|
2639
|
-
if (!
|
|
2665
|
+
if (!isRecord5(value)) {
|
|
2640
2666
|
return false;
|
|
2641
2667
|
}
|
|
2642
2668
|
if (seen.has(value)) {
|
|
@@ -2651,14 +2677,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
2651
2677
|
function setControlValue(control, value) {
|
|
2652
2678
|
const next = clone(control);
|
|
2653
2679
|
next.value = {
|
|
2654
|
-
...
|
|
2680
|
+
...isRecord5(next.value) ? next.value : {},
|
|
2655
2681
|
type: next.value?.type ?? next.field_type,
|
|
2656
2682
|
value
|
|
2657
2683
|
};
|
|
2658
2684
|
return next;
|
|
2659
2685
|
}
|
|
2660
2686
|
function applyRowValues(rowTemplate, rowValue) {
|
|
2661
|
-
const source =
|
|
2687
|
+
const source = isRecord5(rowValue) ? rowValue : {};
|
|
2662
2688
|
return rowTemplate.map((control) => {
|
|
2663
2689
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
2664
2690
|
return setControlValue(control, source[control.key]);
|
|
@@ -2858,6 +2884,7 @@ async function printCreateFormHandoff(client, format, profile, flowIdentifiers,
|
|
|
2858
2884
|
printResult(format, {
|
|
2859
2885
|
handoff: true,
|
|
2860
2886
|
...options.reason ? { reason: options.reason } : {},
|
|
2887
|
+
...options.handoffReasons?.length ? { handoff_reasons: options.handoffReasons } : {},
|
|
2861
2888
|
url: url.url,
|
|
2862
2889
|
pc_url: url.pc_url,
|
|
2863
2890
|
mobile_path: url.mobile_path,
|
|
@@ -2921,8 +2948,8 @@ function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
|
2921
2948
|
}));
|
|
2922
2949
|
}
|
|
2923
2950
|
function metaUsesTemplateProjectName(flowDetail) {
|
|
2924
|
-
const data =
|
|
2925
|
-
const meta =
|
|
2951
|
+
const data = isRecord6(flowDetail?.data) ? flowDetail.data : void 0;
|
|
2952
|
+
const meta = isRecord6(data?.meta) ? data.meta : void 0;
|
|
2926
2953
|
const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
2927
2954
|
return meta?.use_template_project_name === true || hideFields.includes("project.name");
|
|
2928
2955
|
}
|
|
@@ -2944,6 +2971,41 @@ function assertHandoffFormCompatible(fields, form) {
|
|
|
2944
2971
|
);
|
|
2945
2972
|
}
|
|
2946
2973
|
}
|
|
2974
|
+
function isRiskyFormField(field) {
|
|
2975
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
2976
|
+
const label = field.label?.toLowerCase() ?? "";
|
|
2977
|
+
const key = field.key.toLowerCase();
|
|
2978
|
+
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);
|
|
2979
|
+
}
|
|
2980
|
+
function collectHandoffReasons(fields, template) {
|
|
2981
|
+
const reasons = /* @__PURE__ */ new Set();
|
|
2982
|
+
if (template && hasAutoInitLambda(template)) {
|
|
2983
|
+
reasons.add("auto_init_lambda");
|
|
2984
|
+
}
|
|
2985
|
+
for (const field of fields) {
|
|
2986
|
+
if (field.hidden) {
|
|
2987
|
+
continue;
|
|
2988
|
+
}
|
|
2989
|
+
if (isRiskyFormField(field)) {
|
|
2990
|
+
const type = field.type ?? "unknown";
|
|
2991
|
+
const label = field.label ? ` (${field.label})` : "";
|
|
2992
|
+
reasons.add(`page_only_field:${field.key}:${type}${label}`);
|
|
2993
|
+
}
|
|
2994
|
+
if (field.children?.length) {
|
|
2995
|
+
for (const child of field.children) {
|
|
2996
|
+
if (!child.hidden && isRiskyFormField(child)) {
|
|
2997
|
+
const type = child.type ?? "unknown";
|
|
2998
|
+
const label = child.label ? ` (${child.label})` : "";
|
|
2999
|
+
reasons.add(`page_only_field:${field.key}.${child.key}:${type}${label}`);
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
return [...reasons];
|
|
3005
|
+
}
|
|
3006
|
+
function formatHandoffReasonsForMessage(reasons) {
|
|
3007
|
+
return reasons.map((reason) => reason === "auto_init_lambda" ? "\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C" : reason).join(", ");
|
|
3008
|
+
}
|
|
2947
3009
|
function isEmptyValue(value) {
|
|
2948
3010
|
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
2949
3011
|
}
|
|
@@ -2977,7 +3039,7 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
|
2977
3039
|
result.filled_fields.push(contextField(field, "prefilled", fieldOptions));
|
|
2978
3040
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
2979
3041
|
value.forEach((row, index) => {
|
|
2980
|
-
if (
|
|
3042
|
+
if (isRecord6(row)) {
|
|
2981
3043
|
collectPrefillContextForFields(field.children ?? [], row, result, {
|
|
2982
3044
|
prefix: `${field.key}[${index}]`,
|
|
2983
3045
|
rootKey: field.key,
|
|
@@ -3004,7 +3066,7 @@ function buildPrefillContext(fields, form) {
|
|
|
3004
3066
|
}
|
|
3005
3067
|
};
|
|
3006
3068
|
}
|
|
3007
|
-
function
|
|
3069
|
+
function isRecord6(value) {
|
|
3008
3070
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3009
3071
|
}
|
|
3010
3072
|
function isEndedStep(step) {
|
|
@@ -3027,7 +3089,7 @@ function stepIdOf(step) {
|
|
|
3027
3089
|
function pickStepFormPayload(step) {
|
|
3028
3090
|
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
3029
3091
|
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
3030
|
-
const metaForm =
|
|
3092
|
+
const metaForm = isRecord6(step.metaForm) ? step.metaForm : void 0;
|
|
3031
3093
|
return {
|
|
3032
3094
|
step_id: step.id,
|
|
3033
3095
|
flow_step_id: step.flow_step_id,
|
|
@@ -3044,7 +3106,7 @@ function pickStepFormPayload(step) {
|
|
|
3044
3106
|
}
|
|
3045
3107
|
async function buildApprovalContext(client, projectId, options) {
|
|
3046
3108
|
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
3047
|
-
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(
|
|
3109
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord6) : [];
|
|
3048
3110
|
const targetStepIds = /* @__PURE__ */ new Set();
|
|
3049
3111
|
for (const step of steps) {
|
|
3050
3112
|
const id = stepIdOf(step);
|
|
@@ -3070,7 +3132,7 @@ async function buildApprovalContext(client, projectId, options) {
|
|
|
3070
3132
|
}
|
|
3071
3133
|
return {
|
|
3072
3134
|
project: projectDetail,
|
|
3073
|
-
project_form:
|
|
3135
|
+
project_form: isRecord6(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
3074
3136
|
inspected_step_count: stepForms.length,
|
|
3075
3137
|
step_forms: stepForms,
|
|
3076
3138
|
failed_steps: failedSteps
|
|
@@ -3146,18 +3208,27 @@ function registerProjectCommands(program2) {
|
|
|
3146
3208
|
project: attachProjectDetailUrl(profile, context.project)
|
|
3147
3209
|
});
|
|
3148
3210
|
});
|
|
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) => {
|
|
3211
|
+
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
3212
|
const interactiveSource = command.getOptionValueSource("interactive");
|
|
3151
3213
|
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
3152
3214
|
throw new Error("--body and --interactive cannot be used together.");
|
|
3153
3215
|
}
|
|
3216
|
+
if (options.body && options.unsafeDirectCreate !== true) {
|
|
3217
|
+
throw new Error(
|
|
3218
|
+
[
|
|
3219
|
+
"--body direct project creation bypasses flow form-template safety checks and is blocked by default.",
|
|
3220
|
+
"Use project create --json with --flow-id/--flow-type so bpmax-cli can return a handoff URL when needed.",
|
|
3221
|
+
"Only local experts may re-run with --unsafe-direct-create if they intentionally want the raw legacy behavior."
|
|
3222
|
+
].join("\n")
|
|
3223
|
+
);
|
|
3224
|
+
}
|
|
3154
3225
|
const config = await loadConfig();
|
|
3155
3226
|
const profile = resolveProfile(config, options.profile);
|
|
3156
3227
|
const client = createApiClient(profile);
|
|
3157
3228
|
const useInteractive = !options.body && options.interactive !== false;
|
|
3158
3229
|
let payload = parseJson(options.body);
|
|
3159
3230
|
if (!options.body) {
|
|
3160
|
-
const flow = await resolveFlowIdentifiers(client, options, { loadDetail:
|
|
3231
|
+
const flow = await resolveFlowIdentifiers(client, options, { loadDetail: true });
|
|
3161
3232
|
const { flowDetail, ...flowIdentifiers } = flow;
|
|
3162
3233
|
const extra = parseJson(options.json);
|
|
3163
3234
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
@@ -3192,15 +3263,17 @@ function registerProjectCommands(program2) {
|
|
|
3192
3263
|
printResult(options.format, { cancelled: true });
|
|
3193
3264
|
return;
|
|
3194
3265
|
}
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3266
|
+
const handoffReasons2 = collectHandoffReasons(fields, projectFormTemplate?.template);
|
|
3267
|
+
if (handoffReasons2.length > 0) {
|
|
3268
|
+
const handoffFields2 = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3269
|
+
assertHandoffFormCompatible(handoffFields2, form);
|
|
3198
3270
|
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
3199
3271
|
name,
|
|
3200
3272
|
form,
|
|
3201
|
-
fields:
|
|
3202
|
-
reason: "
|
|
3203
|
-
|
|
3273
|
+
fields: handoffFields2,
|
|
3274
|
+
reason: "form_template_requires_page_handoff",
|
|
3275
|
+
handoffReasons: handoffReasons2,
|
|
3276
|
+
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
3277
|
});
|
|
3205
3278
|
return;
|
|
3206
3279
|
}
|
|
@@ -3208,12 +3281,12 @@ function registerProjectCommands(program2) {
|
|
|
3208
3281
|
if (!options.allowFormHandoff) {
|
|
3209
3282
|
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
3210
3283
|
}
|
|
3211
|
-
const
|
|
3212
|
-
assertHandoffFormCompatible(
|
|
3284
|
+
const handoffFields2 = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3285
|
+
assertHandoffFormCompatible(handoffFields2, form);
|
|
3213
3286
|
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
3214
3287
|
name,
|
|
3215
3288
|
form,
|
|
3216
|
-
fields:
|
|
3289
|
+
fields: handoffFields2,
|
|
3217
3290
|
message: "\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
3218
3291
|
});
|
|
3219
3292
|
return;
|
|
@@ -3223,23 +3296,17 @@ function registerProjectCommands(program2) {
|
|
|
3223
3296
|
throw new Error("--name is required unless --body is provided.");
|
|
3224
3297
|
}
|
|
3225
3298
|
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
|
-
}
|
|
3299
|
+
const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
|
|
3300
|
+
const handoffReasons = collectHandoffReasons(handoffFields, projectFormTemplate?.template);
|
|
3301
|
+
if (handoffReasons.length > 0) {
|
|
3236
3302
|
assertHandoffFormCompatible(handoffFields, form);
|
|
3237
3303
|
await printCreateFormHandoff(client, options.format, profile, flowIdentifiers, {
|
|
3238
3304
|
name: name ?? "",
|
|
3239
3305
|
form,
|
|
3240
3306
|
fields: handoffFields,
|
|
3241
|
-
reason: "
|
|
3242
|
-
|
|
3307
|
+
reason: "form_template_requires_page_handoff",
|
|
3308
|
+
handoffReasons,
|
|
3309
|
+
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
3310
|
});
|
|
3244
3311
|
return;
|
|
3245
3312
|
}
|
|
@@ -3306,7 +3373,7 @@ function getRecipesDir(options) {
|
|
|
3306
3373
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
3307
3374
|
return path4.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
3308
3375
|
}
|
|
3309
|
-
function
|
|
3376
|
+
function isRecord7(value) {
|
|
3310
3377
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3311
3378
|
}
|
|
3312
3379
|
function asString(value, fieldName) {
|
|
@@ -3316,7 +3383,7 @@ function asString(value, fieldName) {
|
|
|
3316
3383
|
return value;
|
|
3317
3384
|
}
|
|
3318
3385
|
function parseRecipeDefinition(input) {
|
|
3319
|
-
if (!
|
|
3386
|
+
if (!isRecord7(input)) {
|
|
3320
3387
|
throw new Error("recipe.json must be a JSON object.");
|
|
3321
3388
|
}
|
|
3322
3389
|
if (input.version !== 1) {
|
|
@@ -3324,7 +3391,7 @@ function parseRecipeDefinition(input) {
|
|
|
3324
3391
|
}
|
|
3325
3392
|
const name = asString(input.name, "recipe.name");
|
|
3326
3393
|
assertSafeName("Recipe name", name);
|
|
3327
|
-
if (!
|
|
3394
|
+
if (!isRecord7(input.command)) {
|
|
3328
3395
|
throw new Error("recipe.command must be an object.");
|
|
3329
3396
|
}
|
|
3330
3397
|
const argv = input.command.argv;
|
|
@@ -3332,7 +3399,7 @@ function parseRecipeDefinition(input) {
|
|
|
3332
3399
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
3333
3400
|
}
|
|
3334
3401
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
3335
|
-
if (!
|
|
3402
|
+
if (!isRecord7(item)) {
|
|
3336
3403
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
3337
3404
|
}
|
|
3338
3405
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -3408,7 +3475,7 @@ function parseVarsJson(input) {
|
|
|
3408
3475
|
return {};
|
|
3409
3476
|
}
|
|
3410
3477
|
const parsed = JSON.parse(input);
|
|
3411
|
-
if (!
|
|
3478
|
+
if (!isRecord7(parsed)) {
|
|
3412
3479
|
throw new Error("--vars must be a JSON object.");
|
|
3413
3480
|
}
|
|
3414
3481
|
const variables = {};
|
|
@@ -3489,9 +3556,12 @@ async function writeRecipeScaffold(options) {
|
|
|
3489
3556
|
title,
|
|
3490
3557
|
description: "Describe what this BPMAX environment recipe does.",
|
|
3491
3558
|
workspace: options.location.workspaceDirName,
|
|
3492
|
-
variables: [
|
|
3559
|
+
variables: [
|
|
3560
|
+
{ name: "flow_id", required: true },
|
|
3561
|
+
{ name: "name", required: true }
|
|
3562
|
+
],
|
|
3493
3563
|
command: {
|
|
3494
|
-
argv: ["project", "create", "--
|
|
3564
|
+
argv: ["project", "create", "--flow-id", "{{flow_id}}", "--name", "{{name}}", "--json", "@payload.json", "--format", "json"],
|
|
3495
3565
|
mutating: true
|
|
3496
3566
|
}
|
|
3497
3567
|
};
|
|
@@ -3499,7 +3569,7 @@ async function writeRecipeScaffold(options) {
|
|
|
3499
3569
|
`, "utf8");
|
|
3500
3570
|
await writeFile4(
|
|
3501
3571
|
path4.join(options.location.recipeDir, "payload.json"),
|
|
3502
|
-
`${JSON.stringify({
|
|
3572
|
+
`${JSON.stringify({ form: {} }, null, 2)}
|
|
3503
3573
|
`,
|
|
3504
3574
|
"utf8"
|
|
3505
3575
|
);
|
|
@@ -3638,7 +3708,7 @@ var schemaEntries = [
|
|
|
3638
3708
|
{ name: "flow.list", description: "List flows.", method: "GET", path: "/api/flow/flow_type" },
|
|
3639
3709
|
{ name: "flow.options", description: "List flow options.", method: "GET", path: "/api/flow/options" },
|
|
3640
3710
|
{ name: "flow.get", description: "Fetch flow details by id.", method: "POST", path: "/api/flow/batch_get" },
|
|
3641
|
-
{ name: "es.project-search", description: "
|
|
3711
|
+
{ name: "es.project-search", description: "Search project ES data through /api/project/list, falling back to raw ES when the payload contains body.", method: "POST", path: "/api/project/list or /api/project/raw-es-search" },
|
|
3642
3712
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
3643
3713
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
3644
3714
|
{ name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
|
|
@@ -3647,6 +3717,7 @@ var schemaEntries = [
|
|
|
3647
3717
|
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" },
|
|
3648
3718
|
{ name: "step.context", description: "Get safe step processing context before mutation.", method: "GET", path: "/api/project/:id + /api/step/:id + /api/user/current" },
|
|
3649
3719
|
{ name: "step.actions", description: "List safe step actions parsed from the flow node.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
3720
|
+
{ name: "step.requirements", description: "List required step inputs before submitting.", method: "GET", path: "/api/project/:id + /api/step/:id" },
|
|
3650
3721
|
{ name: "step.submit", description: "Dry-run or submit a step action with safety checks.", method: "PUT", path: "/api/step/:id?action=:action" },
|
|
3651
3722
|
{ name: "bbs.list", description: "List BPMAX Business Skills.", method: "GET", path: "/api/business_skill" },
|
|
3652
3723
|
{ name: "bbs.create", description: "Create a BPMAX Business Skill from a standard skill zip.", method: "POST", path: "/api/business_skill" },
|
|
@@ -3753,7 +3824,7 @@ function registerSetupCommand(program2, deps = {}) {
|
|
|
3753
3824
|
}
|
|
3754
3825
|
|
|
3755
3826
|
// src/commands/step.ts
|
|
3756
|
-
function
|
|
3827
|
+
function isRecord8(value) {
|
|
3757
3828
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3758
3829
|
}
|
|
3759
3830
|
function stringValue(value) {
|
|
@@ -3780,13 +3851,16 @@ function hasMeaningfulValue(value) {
|
|
|
3780
3851
|
if (Array.isArray(value)) {
|
|
3781
3852
|
return value.some(hasMeaningfulValue);
|
|
3782
3853
|
}
|
|
3783
|
-
if (
|
|
3854
|
+
if (isRecord8(value)) {
|
|
3784
3855
|
return Object.values(value).some(hasMeaningfulValue);
|
|
3785
3856
|
}
|
|
3786
3857
|
return false;
|
|
3787
3858
|
}
|
|
3859
|
+
function isEmptyValue2(value) {
|
|
3860
|
+
return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
3861
|
+
}
|
|
3788
3862
|
function projectIdOfStep(step) {
|
|
3789
|
-
const nestedProjectId =
|
|
3863
|
+
const nestedProjectId = isRecord8(step.project) ? step.project.id : void 0;
|
|
3790
3864
|
return idValue(step.project_id ?? step.projectId ?? nestedProjectId);
|
|
3791
3865
|
}
|
|
3792
3866
|
function stepFlowNodeId(step) {
|
|
@@ -3814,12 +3888,12 @@ function collectRecords(value, output = [], seen = /* @__PURE__ */ new Set()) {
|
|
|
3814
3888
|
value.forEach((item) => collectRecords(item, output, seen));
|
|
3815
3889
|
return output;
|
|
3816
3890
|
}
|
|
3817
|
-
if (!
|
|
3891
|
+
if (!isRecord8(value)) {
|
|
3818
3892
|
return output;
|
|
3819
3893
|
}
|
|
3820
3894
|
output.push(value);
|
|
3821
3895
|
for (const child of Object.values(value)) {
|
|
3822
|
-
if (Array.isArray(child) ||
|
|
3896
|
+
if (Array.isArray(child) || isRecord8(child)) {
|
|
3823
3897
|
collectRecords(child, output, seen);
|
|
3824
3898
|
}
|
|
3825
3899
|
}
|
|
@@ -3902,6 +3976,116 @@ function formListOfStep(step) {
|
|
|
3902
3976
|
const values = [step.formList, step.forms, step.metaForm];
|
|
3903
3977
|
return values.filter(hasMeaningfulValue);
|
|
3904
3978
|
}
|
|
3979
|
+
function unwrapFormValue(value) {
|
|
3980
|
+
if (!isRecord8(value)) {
|
|
3981
|
+
return value;
|
|
3982
|
+
}
|
|
3983
|
+
if ("value" in value && Object.keys(value).length <= 3) {
|
|
3984
|
+
return unwrapFormValue(value.value);
|
|
3985
|
+
}
|
|
3986
|
+
return value;
|
|
3987
|
+
}
|
|
3988
|
+
function collectFormValues(value, output = {}, seen = /* @__PURE__ */ new Set()) {
|
|
3989
|
+
if (!value || seen.has(value)) {
|
|
3990
|
+
return output;
|
|
3991
|
+
}
|
|
3992
|
+
seen.add(value);
|
|
3993
|
+
if (Array.isArray(value)) {
|
|
3994
|
+
value.forEach((item) => collectFormValues(item, output, seen));
|
|
3995
|
+
return output;
|
|
3996
|
+
}
|
|
3997
|
+
if (!isRecord8(value)) {
|
|
3998
|
+
return output;
|
|
3999
|
+
}
|
|
4000
|
+
const key = stringValue(value.key ?? value.field_key ?? value.fieldKey ?? value.name);
|
|
4001
|
+
if (key && "value" in value) {
|
|
4002
|
+
const nextValue = unwrapFormValue(value.value);
|
|
4003
|
+
if (hasMeaningfulValue(nextValue)) {
|
|
4004
|
+
output[key] = nextValue;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
for (const child of Object.values(value)) {
|
|
4008
|
+
if (Array.isArray(child) || isRecord8(child)) {
|
|
4009
|
+
collectFormValues(child, output, seen);
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
return output;
|
|
4013
|
+
}
|
|
4014
|
+
function stepRequirementSource(step, flowNode) {
|
|
4015
|
+
return {
|
|
4016
|
+
step_form_template: step.form_template ?? step.formTemplate ?? step.form_template_data ?? step.formTemplateData,
|
|
4017
|
+
step_form_schema: step.form_schema ?? step.formSchema,
|
|
4018
|
+
step_forms: step.forms ?? step.formList ?? step.metaForm,
|
|
4019
|
+
flow_node_step_form_template: flowNode?.form_template ?? flowNode?.formTemplate ?? flowNode?.step_form_template ?? flowNode?.stepFormTemplate,
|
|
4020
|
+
flow_node_form_schema: flowNode?.form_schema ?? flowNode?.formSchema
|
|
4021
|
+
};
|
|
4022
|
+
}
|
|
4023
|
+
function buildSubmitPayloadTemplate(fields) {
|
|
4024
|
+
const template = {};
|
|
4025
|
+
for (const field of fields) {
|
|
4026
|
+
if (field.hidden) {
|
|
4027
|
+
continue;
|
|
4028
|
+
}
|
|
4029
|
+
template[field.key] = isSubFormField(field) ? [
|
|
4030
|
+
Object.fromEntries((field.children ?? []).filter((child) => !child.hidden).map((child) => [child.key, null]))
|
|
4031
|
+
] : null;
|
|
4032
|
+
}
|
|
4033
|
+
return template;
|
|
4034
|
+
}
|
|
4035
|
+
function fieldWithValue(field, value) {
|
|
4036
|
+
const missing = Boolean(field.required && !field.hidden && isEmptyValue2(value));
|
|
4037
|
+
return {
|
|
4038
|
+
...field,
|
|
4039
|
+
...value !== void 0 ? { value } : {},
|
|
4040
|
+
missing
|
|
4041
|
+
};
|
|
4042
|
+
}
|
|
4043
|
+
function collectMissingRequiredInputs(fields, values) {
|
|
4044
|
+
const missing = [];
|
|
4045
|
+
for (const field of fields) {
|
|
4046
|
+
const value = values[field.key];
|
|
4047
|
+
if (field.required && !field.hidden && isEmptyValue2(value)) {
|
|
4048
|
+
missing.push(fieldWithValue(field, value));
|
|
4049
|
+
continue;
|
|
4050
|
+
}
|
|
4051
|
+
if (!isSubFormField(field) || !Array.isArray(value) || !field.children?.length) {
|
|
4052
|
+
continue;
|
|
4053
|
+
}
|
|
4054
|
+
value.forEach((row, index) => {
|
|
4055
|
+
if (!isRecord8(row)) {
|
|
4056
|
+
return;
|
|
4057
|
+
}
|
|
4058
|
+
for (const child of field.children ?? []) {
|
|
4059
|
+
const childValue = row[child.key];
|
|
4060
|
+
if (child.required && !child.hidden && isEmptyValue2(childValue)) {
|
|
4061
|
+
missing.push(fieldWithValue({ ...child, key: `${field.key}[${index}].${child.key}` }, childValue));
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
});
|
|
4065
|
+
}
|
|
4066
|
+
return missing;
|
|
4067
|
+
}
|
|
4068
|
+
function buildStepRequirements(step, flowNode, submitData = {}) {
|
|
4069
|
+
const fields = extractFormFields(stepRequirementSource(step, flowNode));
|
|
4070
|
+
const providedValues = {
|
|
4071
|
+
...collectFormValues(step.formList),
|
|
4072
|
+
...collectFormValues(step.forms),
|
|
4073
|
+
...collectFormValues(step.metaForm),
|
|
4074
|
+
...extractSubmitInputValues(submitData)
|
|
4075
|
+
};
|
|
4076
|
+
const requirementFields = fields.map((field) => fieldWithValue(field, providedValues[field.key]));
|
|
4077
|
+
const missingRequiredInputs = collectMissingRequiredInputs(fields, providedValues);
|
|
4078
|
+
return {
|
|
4079
|
+
fields: requirementFields,
|
|
4080
|
+
required_inputs: requirementFields.filter((field) => field.required && !field.hidden),
|
|
4081
|
+
optional_inputs: requirementFields.filter((field) => !field.required && !field.hidden),
|
|
4082
|
+
missing_required_inputs: missingRequiredInputs,
|
|
4083
|
+
provided_values: providedValues,
|
|
4084
|
+
submit_payload_template: buildSubmitPayloadTemplate(fields),
|
|
4085
|
+
can_submit: missingRequiredInputs.length === 0,
|
|
4086
|
+
blocking_reasons: missingRequiredInputs.length > 0 ? ["missing_required_step_inputs"] : []
|
|
4087
|
+
};
|
|
4088
|
+
}
|
|
3905
4089
|
function buildFormSummary(project, step) {
|
|
3906
4090
|
const projectFormEmpty = !hasMeaningfulValue(project.metaForm ?? project.project_form ?? project.projectForm);
|
|
3907
4091
|
const stepFormsEmpty = formListOfStep(step).length === 0;
|
|
@@ -3923,7 +4107,7 @@ function ownerIdsFromStep(step) {
|
|
|
3923
4107
|
];
|
|
3924
4108
|
const ids = /* @__PURE__ */ new Set();
|
|
3925
4109
|
for (const owner of owners) {
|
|
3926
|
-
if (
|
|
4110
|
+
if (isRecord8(owner)) {
|
|
3927
4111
|
const id = idValue(owner.owner_id ?? owner.user_id ?? owner.id);
|
|
3928
4112
|
if (id) {
|
|
3929
4113
|
ids.add(id);
|
|
@@ -3969,6 +4153,7 @@ async function buildStepContext(profile, client, stepId, projectId) {
|
|
|
3969
4153
|
}
|
|
3970
4154
|
const flowNode = findFlowNode(project, step);
|
|
3971
4155
|
const formSummary = buildFormSummary(project, step);
|
|
4156
|
+
const requirements = buildStepRequirements(step, flowNode);
|
|
3972
4157
|
const identityUnverified = !formSummary.has_identity_evidence;
|
|
3973
4158
|
const userCheck = checkCurrentUserCanProcess(step, currentUser);
|
|
3974
4159
|
const stepFinished = isStepFinished(step);
|
|
@@ -3982,6 +4167,9 @@ async function buildStepContext(profile, client, stepId, projectId) {
|
|
|
3982
4167
|
if (userCheck.current_user_can_process === false) {
|
|
3983
4168
|
riskWarnings.push(userCheck.current_user_reason);
|
|
3984
4169
|
}
|
|
4170
|
+
if (!requirements.can_submit) {
|
|
4171
|
+
riskWarnings.push(`Missing required step input(s): ${requirements.missing_required_inputs.map((field) => field.key).join(", ")}`);
|
|
4172
|
+
}
|
|
3985
4173
|
return {
|
|
3986
4174
|
project_id: projectId,
|
|
3987
4175
|
step_id: stepId,
|
|
@@ -3994,6 +4182,7 @@ async function buildStepContext(profile, client, stepId, projectId) {
|
|
|
3994
4182
|
...userCheck,
|
|
3995
4183
|
step_finished: stepFinished,
|
|
3996
4184
|
form_summary: formSummary,
|
|
4185
|
+
requirements,
|
|
3997
4186
|
identity_unverified: identityUnverified,
|
|
3998
4187
|
risk_warnings: riskWarnings
|
|
3999
4188
|
};
|
|
@@ -4004,6 +4193,34 @@ async function loadSubmitData(data) {
|
|
|
4004
4193
|
}
|
|
4005
4194
|
return parseJsonInput(data, "--data");
|
|
4006
4195
|
}
|
|
4196
|
+
var SUBMIT_NON_FORM_KEYS = /* @__PURE__ */ new Set([
|
|
4197
|
+
"project_id",
|
|
4198
|
+
"projectId",
|
|
4199
|
+
"target_step",
|
|
4200
|
+
"targetStep",
|
|
4201
|
+
"action",
|
|
4202
|
+
"action_label",
|
|
4203
|
+
"actionLabel",
|
|
4204
|
+
"step_comments",
|
|
4205
|
+
"stepComments",
|
|
4206
|
+
"comments",
|
|
4207
|
+
"urgency"
|
|
4208
|
+
]);
|
|
4209
|
+
function extractSubmitInputValues(data) {
|
|
4210
|
+
const candidates = [data.form, data.form_data, data.formData, data.fields, data.values];
|
|
4211
|
+
const values = {};
|
|
4212
|
+
for (const candidate of candidates) {
|
|
4213
|
+
if (isRecord8(candidate)) {
|
|
4214
|
+
Object.assign(values, candidate);
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
for (const [key, value] of Object.entries(data)) {
|
|
4218
|
+
if (!SUBMIT_NON_FORM_KEYS.has(key) && !isRecord8(value) && !Array.isArray(value)) {
|
|
4219
|
+
values[key] = value;
|
|
4220
|
+
}
|
|
4221
|
+
}
|
|
4222
|
+
return values;
|
|
4223
|
+
}
|
|
4007
4224
|
function registerStepCommands(program2) {
|
|
4008
4225
|
const step = program2.command("step").description("Step commands");
|
|
4009
4226
|
step.command("get <id>").description("Get step detail").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (id, options) => {
|
|
@@ -4037,12 +4254,27 @@ function registerStepCommands(program2) {
|
|
|
4037
4254
|
risk_warnings: context.risk_warnings
|
|
4038
4255
|
});
|
|
4039
4256
|
});
|
|
4257
|
+
step.command("requirements <id>").description("List required step inputs before submitting").requiredOption("--project-id <projectId>", "Project id").option("--data <json>", "Additional submit payload JSON or @file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
|
|
4258
|
+
const config = await loadConfig();
|
|
4259
|
+
const profile = resolveProfile(config, options.profile);
|
|
4260
|
+
const client = createApiClient(profile);
|
|
4261
|
+
const context = await buildStepContext(profile, client, id, options.projectId);
|
|
4262
|
+
const data = await loadSubmitData(options.data);
|
|
4263
|
+
const requirements = buildStepRequirements(context.step, context.current_flow_node, data);
|
|
4264
|
+
printResult(options.format, {
|
|
4265
|
+
project_id: context.project_id,
|
|
4266
|
+
step_id: context.step_id,
|
|
4267
|
+
url: context.url,
|
|
4268
|
+
requirements
|
|
4269
|
+
});
|
|
4270
|
+
});
|
|
4040
4271
|
step.command("submit <id>").description("Safely submit a step action").requiredOption("--project-id <projectId>", "Project id").requiredOption("--action <action>", "Step action, e.g. approve/refuse").option("--label <label>", "Action label").option("--target-step <targetStep>", "Target flow step id").option("--data <json>", "Additional submit payload JSON or @file").option("--comments <comments>", "Step comments").option("--urgency <urgency>", "Urgency value", "1").option("--confirm <confirmation>", "Actually submit the step action").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
|
|
4041
4272
|
const config = await loadConfig();
|
|
4042
4273
|
const profile = resolveProfile(config, options.profile);
|
|
4043
4274
|
const client = createApiClient(profile);
|
|
4044
4275
|
const context = await buildStepContext(profile, client, id, options.projectId);
|
|
4045
4276
|
const data = await loadSubmitData(options.data);
|
|
4277
|
+
const requirements = buildStepRequirements(context.step, context.current_flow_node, data);
|
|
4046
4278
|
const payload = {
|
|
4047
4279
|
...data,
|
|
4048
4280
|
project_id: Number(options.projectId),
|
|
@@ -4071,9 +4303,10 @@ function registerStepCommands(program2) {
|
|
|
4071
4303
|
identity_unverified: context.identity_unverified,
|
|
4072
4304
|
current_user_can_process: context.current_user_can_process,
|
|
4073
4305
|
step_finished: context.step_finished,
|
|
4306
|
+
requirements,
|
|
4074
4307
|
risk_warnings: context.risk_warnings
|
|
4075
4308
|
},
|
|
4076
|
-
next_command_hint: "Re-run with --confirm after verifying project identity, target action, and payload."
|
|
4309
|
+
next_command_hint: requirements.can_submit ? "Re-run with --confirm after verifying project identity, target action, and payload." : "Fill missing required step input(s) in --data before confirming."
|
|
4077
4310
|
});
|
|
4078
4311
|
return;
|
|
4079
4312
|
}
|
|
@@ -4086,6 +4319,9 @@ function registerStepCommands(program2) {
|
|
|
4086
4319
|
if (context.current_user_can_process === false) {
|
|
4087
4320
|
throw new Error(`Refusing to submit: ${context.current_user_reason}`);
|
|
4088
4321
|
}
|
|
4322
|
+
if (!requirements.can_submit) {
|
|
4323
|
+
throw new Error(`Refusing to submit: missing required step input(s): ${requirements.missing_required_inputs.map((field) => field.key).join(", ")}`);
|
|
4324
|
+
}
|
|
4089
4325
|
const result = await apiRequest(client, "PUT", `/step/${id}`, {
|
|
4090
4326
|
params: { action: options.action },
|
|
4091
4327
|
data: payload
|