bpmax-cli 0.1.17 → 0.1.19
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/dist/bin.js +105 -13
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-project/SKILL.md +28 -2
package/dist/bin.js
CHANGED
|
@@ -812,7 +812,7 @@ function registerFlowCommands(program2) {
|
|
|
812
812
|
// package.json
|
|
813
813
|
var package_default = {
|
|
814
814
|
name: "bpmax-cli",
|
|
815
|
-
version: "0.1.
|
|
815
|
+
version: "0.1.19",
|
|
816
816
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
817
817
|
type: "module",
|
|
818
818
|
bin: {
|
|
@@ -1189,6 +1189,18 @@ function fieldFromRecord(source) {
|
|
|
1189
1189
|
...options ? { options } : {}
|
|
1190
1190
|
};
|
|
1191
1191
|
}
|
|
1192
|
+
function isSubFormField(field) {
|
|
1193
|
+
const type = field.type?.toLowerCase() ?? "";
|
|
1194
|
+
return /(sub[_-]?form|relation[_-]?form|associated[_-]?form|table)/.test(type);
|
|
1195
|
+
}
|
|
1196
|
+
function mergeField(existing, incoming) {
|
|
1197
|
+
const children = incoming.children ?? existing?.children;
|
|
1198
|
+
return {
|
|
1199
|
+
...existing,
|
|
1200
|
+
...incoming,
|
|
1201
|
+
...children?.length ? { children } : {}
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1192
1204
|
function collectFieldCandidates(value, fields, depth = 0) {
|
|
1193
1205
|
if (depth > 8) {
|
|
1194
1206
|
return;
|
|
@@ -1204,7 +1216,21 @@ function collectFieldCandidates(value, fields, depth = 0) {
|
|
|
1204
1216
|
}
|
|
1205
1217
|
const field = fieldFromRecord(value);
|
|
1206
1218
|
if (field) {
|
|
1207
|
-
|
|
1219
|
+
if (isSubFormField(field)) {
|
|
1220
|
+
const childFields = /* @__PURE__ */ new Map();
|
|
1221
|
+
for (const child of Object.values(value)) {
|
|
1222
|
+
if (isRecord2(child) || Array.isArray(child)) {
|
|
1223
|
+
collectFieldCandidates(child, childFields, depth + 1);
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
const children = [...childFields.values()].sort((left, right) => left.key.localeCompare(right.key));
|
|
1227
|
+
fields.set(
|
|
1228
|
+
field.key,
|
|
1229
|
+
mergeField(fields.get(field.key), { ...field, ...children.length ? { children } : {} })
|
|
1230
|
+
);
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
fields.set(field.key, mergeField(fields.get(field.key), field));
|
|
1208
1234
|
}
|
|
1209
1235
|
for (const child of Object.values(value)) {
|
|
1210
1236
|
if (isRecord2(child) || Array.isArray(child)) {
|
|
@@ -1225,6 +1251,9 @@ function validateType(field, value) {
|
|
|
1225
1251
|
if (!type || isEmpty(value)) {
|
|
1226
1252
|
return null;
|
|
1227
1253
|
}
|
|
1254
|
+
if (isSubFormField(field)) {
|
|
1255
|
+
return Array.isArray(value) ? null : `${field.key} must be a JSON array of row objects`;
|
|
1256
|
+
}
|
|
1228
1257
|
if (field.options) {
|
|
1229
1258
|
const values = Array.isArray(value) ? value.map(String) : [String(value)];
|
|
1230
1259
|
const invalid = values.filter((item) => !field.options?.includes(item));
|
|
@@ -1246,25 +1275,37 @@ function validateType(field, value) {
|
|
|
1246
1275
|
}
|
|
1247
1276
|
return null;
|
|
1248
1277
|
}
|
|
1249
|
-
function
|
|
1278
|
+
function validateFormEntries(form, fields, prefix = "") {
|
|
1250
1279
|
const byKey = new Map(fields.map((field) => [field.key, field]));
|
|
1251
1280
|
const errors = [];
|
|
1252
1281
|
for (const field of fields) {
|
|
1253
1282
|
if (field.required && isEmpty(form[field.key])) {
|
|
1254
|
-
errors.push(`${field.key} is required`);
|
|
1283
|
+
errors.push(`${prefix}${field.key} is required`);
|
|
1255
1284
|
}
|
|
1256
1285
|
}
|
|
1257
1286
|
for (const [key, value] of Object.entries(form)) {
|
|
1258
1287
|
const field = byKey.get(key);
|
|
1259
1288
|
if (!field) {
|
|
1260
|
-
errors.push(`${key} is not defined in the flow create form`);
|
|
1289
|
+
errors.push(`${prefix}${key} is not defined in the flow create form`);
|
|
1261
1290
|
continue;
|
|
1262
1291
|
}
|
|
1263
1292
|
const typeError = validateType(field, value);
|
|
1264
1293
|
if (typeError) {
|
|
1265
|
-
errors.push(typeError);
|
|
1294
|
+
errors.push(prefix ? `${prefix}${typeError}` : typeError);
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
1298
|
+
for (const [index, row] of value.entries()) {
|
|
1299
|
+
if (isRecord2(row)) {
|
|
1300
|
+
errors.push(...validateFormEntries(row, field.children, `${prefix}${field.key}[${index}].`));
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1266
1303
|
}
|
|
1267
1304
|
}
|
|
1305
|
+
return errors;
|
|
1306
|
+
}
|
|
1307
|
+
function validateFormAgainstFields(form, fields) {
|
|
1308
|
+
const errors = validateFormEntries(form, fields);
|
|
1268
1309
|
return { fields, errors };
|
|
1269
1310
|
}
|
|
1270
1311
|
|
|
@@ -1296,8 +1337,50 @@ function stringifyInitial(value) {
|
|
|
1296
1337
|
}
|
|
1297
1338
|
return typeof value === "string" ? value : JSON.stringify(value);
|
|
1298
1339
|
}
|
|
1340
|
+
function subFormHint(field) {
|
|
1341
|
+
if (!field.children?.length) {
|
|
1342
|
+
return 'JSON array, e.g. [{"field_key":"value"}]';
|
|
1343
|
+
}
|
|
1344
|
+
const children = field.children.map((child) => `${child.key}${child.required ? "*" : ""}`).join(", ");
|
|
1345
|
+
return `JSON array rows: ${children}`;
|
|
1346
|
+
}
|
|
1299
1347
|
async function promptField(field, currentValue) {
|
|
1300
1348
|
const message = field.required ? `${fieldLabel(field)} *` : fieldLabel(field);
|
|
1349
|
+
if (isSubFormField(field)) {
|
|
1350
|
+
const value2 = await text2({
|
|
1351
|
+
message,
|
|
1352
|
+
placeholder: subFormHint(field),
|
|
1353
|
+
initialValue: stringifyInitial(currentValue),
|
|
1354
|
+
validate(input) {
|
|
1355
|
+
const candidate = input ?? "";
|
|
1356
|
+
if (field.required && !candidate.trim()) {
|
|
1357
|
+
return `${field.key} is required`;
|
|
1358
|
+
}
|
|
1359
|
+
if (!candidate.trim()) {
|
|
1360
|
+
return;
|
|
1361
|
+
}
|
|
1362
|
+
try {
|
|
1363
|
+
const parsed = JSON.parse(candidate);
|
|
1364
|
+
if (!Array.isArray(parsed)) {
|
|
1365
|
+
return `${field.key} must be a JSON array`;
|
|
1366
|
+
}
|
|
1367
|
+
const invalidRowIndex = parsed.findIndex(
|
|
1368
|
+
(item) => typeof item !== "object" || item === null || Array.isArray(item)
|
|
1369
|
+
);
|
|
1370
|
+
if (invalidRowIndex >= 0) {
|
|
1371
|
+
return `${field.key} rows must be JSON objects`;
|
|
1372
|
+
}
|
|
1373
|
+
} catch {
|
|
1374
|
+
return `${field.key} must be valid JSON`;
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
cancelIfNeeded(value2);
|
|
1379
|
+
if (typeof value2 !== "string" || !value2.trim()) {
|
|
1380
|
+
return void 0;
|
|
1381
|
+
}
|
|
1382
|
+
return JSON.parse(value2);
|
|
1383
|
+
}
|
|
1301
1384
|
if (field.options?.length && isArrayField(field)) {
|
|
1302
1385
|
const value2 = await multiselect({
|
|
1303
1386
|
message,
|
|
@@ -1367,12 +1450,12 @@ async function promptField(field, currentValue) {
|
|
|
1367
1450
|
}
|
|
1368
1451
|
return value;
|
|
1369
1452
|
}
|
|
1370
|
-
async function promptAction(message) {
|
|
1453
|
+
async function promptAction(message, allowFormHandoff) {
|
|
1371
1454
|
const value = await select({
|
|
1372
1455
|
message,
|
|
1373
1456
|
options: [
|
|
1374
1457
|
{ value: "continue", label: "\u7EE7\u7EED\u586B\u5199" },
|
|
1375
|
-
{ value: "open_form", label: "\u6253\u5F00 BPMAX \u8868\u5355\u9875\u7EE7\u7EED\u586B\u5199" },
|
|
1458
|
+
...allowFormHandoff ? [{ value: "open_form", label: "\u6253\u5F00 BPMAX \u8868\u5355\u9875\u7EE7\u7EED\u586B\u5199" }] : [],
|
|
1376
1459
|
{ value: "submit", label: "\u76F4\u63A5\u63D0\u4EA4" },
|
|
1377
1460
|
{ value: "cancel", label: "\u53D6\u6D88" }
|
|
1378
1461
|
],
|
|
@@ -1382,6 +1465,7 @@ async function promptAction(message) {
|
|
|
1382
1465
|
return value;
|
|
1383
1466
|
}
|
|
1384
1467
|
async function promptProjectCreateForm(input) {
|
|
1468
|
+
const allowFormHandoff = input.allowFormHandoff === true;
|
|
1385
1469
|
let name = input.name;
|
|
1386
1470
|
if (!name?.trim()) {
|
|
1387
1471
|
const value = await text2({
|
|
@@ -1400,7 +1484,7 @@ async function promptProjectCreateForm(input) {
|
|
|
1400
1484
|
const optionalFields = input.fields.filter((field) => !field.required);
|
|
1401
1485
|
for (const field of requiredFields) {
|
|
1402
1486
|
form[field.key] = await promptField(field, form[field.key]);
|
|
1403
|
-
const action2 = await promptAction("\u4E0B\u4E00\u6B65");
|
|
1487
|
+
const action2 = await promptAction("\u4E0B\u4E00\u6B65", allowFormHandoff);
|
|
1404
1488
|
if (action2 === "open_form" || action2 === "submit" || action2 === "cancel") {
|
|
1405
1489
|
return { name, form, action: action2 };
|
|
1406
1490
|
}
|
|
@@ -1417,14 +1501,14 @@ async function promptProjectCreateForm(input) {
|
|
|
1417
1501
|
if (!isEmpty2(value)) {
|
|
1418
1502
|
form[field.key] = value;
|
|
1419
1503
|
}
|
|
1420
|
-
const action2 = await promptAction("\u4E0B\u4E00\u6B65");
|
|
1504
|
+
const action2 = await promptAction("\u4E0B\u4E00\u6B65", allowFormHandoff);
|
|
1421
1505
|
if (action2 === "open_form" || action2 === "submit" || action2 === "cancel") {
|
|
1422
1506
|
return { name, form, action: action2 };
|
|
1423
1507
|
}
|
|
1424
1508
|
}
|
|
1425
1509
|
}
|
|
1426
1510
|
}
|
|
1427
|
-
const action = await promptAction("\u5B57\u6BB5\u586B\u5199\u5B8C\u6210\uFF0C\u4E0B\u4E00\u6B65");
|
|
1511
|
+
const action = await promptAction("\u5B57\u6BB5\u586B\u5199\u5B8C\u6210\uFF0C\u4E0B\u4E00\u6B65", allowFormHandoff);
|
|
1428
1512
|
return {
|
|
1429
1513
|
name,
|
|
1430
1514
|
form,
|
|
@@ -1673,7 +1757,7 @@ function registerProjectCommands(program2) {
|
|
|
1673
1757
|
);
|
|
1674
1758
|
printResult(options.format, result);
|
|
1675
1759
|
});
|
|
1676
|
-
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("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
1760
|
+
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("--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) => {
|
|
1677
1761
|
if (options.body && options.interactive) {
|
|
1678
1762
|
throw new Error("--body and --interactive cannot be used together.");
|
|
1679
1763
|
}
|
|
@@ -1692,7 +1776,12 @@ function registerProjectCommands(program2) {
|
|
|
1692
1776
|
throw new Error("--interactive requires --flow-id so the form schema can be discovered.");
|
|
1693
1777
|
}
|
|
1694
1778
|
const fields = extractFormFields(flowDetail);
|
|
1695
|
-
const promptResult = await promptProjectCreateForm({
|
|
1779
|
+
const promptResult = await promptProjectCreateForm({
|
|
1780
|
+
name,
|
|
1781
|
+
form: { ...form },
|
|
1782
|
+
fields,
|
|
1783
|
+
allowFormHandoff: options.allowFormHandoff === true
|
|
1784
|
+
});
|
|
1696
1785
|
name = promptResult.name;
|
|
1697
1786
|
Object.keys(form).forEach((key) => {
|
|
1698
1787
|
delete form[key];
|
|
@@ -1703,6 +1792,9 @@ function registerProjectCommands(program2) {
|
|
|
1703
1792
|
return;
|
|
1704
1793
|
}
|
|
1705
1794
|
if (promptResult.action === "open_form") {
|
|
1795
|
+
if (!options.allowFormHandoff) {
|
|
1796
|
+
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
1797
|
+
}
|
|
1706
1798
|
const url = buildBpmaxUrl(profile, "project-create", {
|
|
1707
1799
|
flowType: flowIdentifiers.flow_type,
|
|
1708
1800
|
flowKey: flowIdentifiers.flow_key,
|