bpmax-cli 0.1.16 → 0.1.17

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 CHANGED
@@ -132,6 +132,14 @@ bpmax-cli project my-step --key-of-flow-node 'flow802926525::1776572829122' --fo
132
132
 
133
133
  Use `--flow-key` when the target flow has a non-empty key. `--flow-step-id` maps to the backend node filter.
134
134
 
135
+ Create a project with an interactive form guide:
136
+
137
+ ```bash
138
+ bpmax-cli project create --profile yuanrong --flow-id 123 --interactive --format json
139
+ ```
140
+
141
+ During the guide, choose "打开 BPMAX 表单页继续填写" to hand off to the web form. The CLI prints a PC URL and mobile path with the fields already entered encoded in `init_value`.
142
+
135
143
  ## ES fast queries
136
144
 
137
145
  Use raw ES project search for high-volume reads, aggregations, budget summaries, trend analysis, and other reporting-style queries. Prefer ES aggregations over paging through `project list` and grouping locally.
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.16",
815
+ version: "0.1.17",
816
816
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
817
817
  type: "module",
818
818
  bin: {
@@ -1268,6 +1268,170 @@ function validateFormAgainstFields(form, fields) {
1268
1268
  return { fields, errors };
1269
1269
  }
1270
1270
 
1271
+ // src/core/form-prompts.ts
1272
+ import { confirm, isCancel, multiselect, select, text as text2 } from "@clack/prompts";
1273
+ function isEmpty2(value) {
1274
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1275
+ }
1276
+ function cancelIfNeeded(value) {
1277
+ if (isCancel(value)) {
1278
+ throw new Error("Interactive project creation cancelled.");
1279
+ }
1280
+ }
1281
+ function fieldLabel(field) {
1282
+ return field.label ? `${field.label} (${field.key})` : field.key;
1283
+ }
1284
+ function isArrayField(field) {
1285
+ return /(array|multi|multiple)/.test(field.type?.toLowerCase() ?? "");
1286
+ }
1287
+ function isBooleanField(field) {
1288
+ return /(boolean|bool|switch|checkbox)/.test(field.type?.toLowerCase() ?? "");
1289
+ }
1290
+ function isNumberField(field) {
1291
+ return /(number|int|decimal|float|double|amount)/.test(field.type?.toLowerCase() ?? "");
1292
+ }
1293
+ function stringifyInitial(value) {
1294
+ if (value === void 0 || value === null) {
1295
+ return "";
1296
+ }
1297
+ return typeof value === "string" ? value : JSON.stringify(value);
1298
+ }
1299
+ async function promptField(field, currentValue) {
1300
+ const message = field.required ? `${fieldLabel(field)} *` : fieldLabel(field);
1301
+ if (field.options?.length && isArrayField(field)) {
1302
+ const value2 = await multiselect({
1303
+ message,
1304
+ options: field.options.map((option) => ({ value: option, label: option })),
1305
+ initialValues: Array.isArray(currentValue) ? currentValue.map(String) : [],
1306
+ required: field.required
1307
+ });
1308
+ cancelIfNeeded(value2);
1309
+ return value2;
1310
+ }
1311
+ if (field.options?.length) {
1312
+ const value2 = await select({
1313
+ message,
1314
+ options: [
1315
+ ...!field.required ? [{ value: "", label: "(skip)" }] : [],
1316
+ ...field.options.map((option) => ({ value: option, label: option }))
1317
+ ],
1318
+ initialValue: typeof currentValue === "string" ? currentValue : void 0
1319
+ });
1320
+ cancelIfNeeded(value2);
1321
+ return value2;
1322
+ }
1323
+ if (isBooleanField(field)) {
1324
+ const value2 = await confirm({
1325
+ message,
1326
+ initialValue: typeof currentValue === "boolean" ? currentValue : false
1327
+ });
1328
+ cancelIfNeeded(value2);
1329
+ return value2;
1330
+ }
1331
+ const value = await text2({
1332
+ message,
1333
+ placeholder: isArrayField(field) ? 'JSON array, e.g. ["A","B"]' : void 0,
1334
+ initialValue: stringifyInitial(currentValue),
1335
+ validate(input) {
1336
+ const candidate = input ?? "";
1337
+ if (field.required && !candidate.trim()) {
1338
+ return `${field.key} is required`;
1339
+ }
1340
+ if (!candidate.trim()) {
1341
+ return;
1342
+ }
1343
+ if (isNumberField(field) && Number.isNaN(Number(candidate))) {
1344
+ return `${field.key} must be a number`;
1345
+ }
1346
+ if (isArrayField(field)) {
1347
+ try {
1348
+ const parsed = JSON.parse(candidate);
1349
+ if (!Array.isArray(parsed)) {
1350
+ return `${field.key} must be a JSON array`;
1351
+ }
1352
+ } catch {
1353
+ return `${field.key} must be valid JSON`;
1354
+ }
1355
+ }
1356
+ }
1357
+ });
1358
+ cancelIfNeeded(value);
1359
+ if (typeof value !== "string" || !value.trim()) {
1360
+ return void 0;
1361
+ }
1362
+ if (isNumberField(field)) {
1363
+ return Number(value);
1364
+ }
1365
+ if (isArrayField(field)) {
1366
+ return JSON.parse(value);
1367
+ }
1368
+ return value;
1369
+ }
1370
+ async function promptAction(message) {
1371
+ const value = await select({
1372
+ message,
1373
+ options: [
1374
+ { value: "continue", label: "\u7EE7\u7EED\u586B\u5199" },
1375
+ { value: "open_form", label: "\u6253\u5F00 BPMAX \u8868\u5355\u9875\u7EE7\u7EED\u586B\u5199" },
1376
+ { value: "submit", label: "\u76F4\u63A5\u63D0\u4EA4" },
1377
+ { value: "cancel", label: "\u53D6\u6D88" }
1378
+ ],
1379
+ initialValue: "continue"
1380
+ });
1381
+ cancelIfNeeded(value);
1382
+ return value;
1383
+ }
1384
+ async function promptProjectCreateForm(input) {
1385
+ let name = input.name;
1386
+ if (!name?.trim()) {
1387
+ const value = await text2({
1388
+ message: "\u6D41\u7A0B\u5355\u6807\u9898 *",
1389
+ validate(candidate) {
1390
+ if (!(candidate ?? "").trim()) {
1391
+ return "\u6D41\u7A0B\u5355\u6807\u9898 is required";
1392
+ }
1393
+ }
1394
+ });
1395
+ cancelIfNeeded(value);
1396
+ name = String(value).trim();
1397
+ }
1398
+ const form = { ...input.form };
1399
+ const requiredFields = input.fields.filter((field) => field.required);
1400
+ const optionalFields = input.fields.filter((field) => !field.required);
1401
+ for (const field of requiredFields) {
1402
+ form[field.key] = await promptField(field, form[field.key]);
1403
+ const action2 = await promptAction("\u4E0B\u4E00\u6B65");
1404
+ if (action2 === "open_form" || action2 === "submit" || action2 === "cancel") {
1405
+ return { name, form, action: action2 };
1406
+ }
1407
+ }
1408
+ if (optionalFields.length > 0) {
1409
+ const fillOptional = await confirm({
1410
+ message: "\u662F\u5426\u7EE7\u7EED\u586B\u5199\u53EF\u9009\u5B57\u6BB5\uFF1F",
1411
+ initialValue: false
1412
+ });
1413
+ cancelIfNeeded(fillOptional);
1414
+ if (fillOptional) {
1415
+ for (const field of optionalFields) {
1416
+ const value = await promptField(field, form[field.key]);
1417
+ if (!isEmpty2(value)) {
1418
+ form[field.key] = value;
1419
+ }
1420
+ const action2 = await promptAction("\u4E0B\u4E00\u6B65");
1421
+ if (action2 === "open_form" || action2 === "submit" || action2 === "cancel") {
1422
+ return { name, form, action: action2 };
1423
+ }
1424
+ }
1425
+ }
1426
+ }
1427
+ const action = await promptAction("\u5B57\u6BB5\u586B\u5199\u5B8C\u6210\uFF0C\u4E0B\u4E00\u6B65");
1428
+ return {
1429
+ name,
1430
+ form,
1431
+ action: action === "continue" ? "submit" : action
1432
+ };
1433
+ }
1434
+
1271
1435
  // src/core/urls.ts
1272
1436
  function stripSlashes(value) {
1273
1437
  return value.trim().replace(/^\/+|\/+$/g, "");
@@ -1300,7 +1464,12 @@ function requireNumericId(value, name) {
1300
1464
  return nextValue;
1301
1465
  }
1302
1466
  function withQuery(path5, query) {
1303
- const params = new URLSearchParams(query);
1467
+ const params = new URLSearchParams();
1468
+ for (const [key, value] of Object.entries(query)) {
1469
+ if (value !== void 0) {
1470
+ params.set(key, value);
1471
+ }
1472
+ }
1304
1473
  return `${path5}?${params.toString()}`;
1305
1474
  }
1306
1475
  function buildBpmaxUrl(profile, kind, params = {}) {
@@ -1329,11 +1498,27 @@ function buildBpmaxUrl(profile, kind, params = {}) {
1329
1498
  });
1330
1499
  result.project_id = projectId;
1331
1500
  result.step_id = stepId;
1501
+ } else if (kind === "project-create") {
1502
+ const flowType = params.flowType || "default";
1503
+ const flowKey = params.flowKey || "";
1504
+ const initValue = params.initValue ? JSON.stringify(params.initValue) : void 0;
1505
+ const query = {
1506
+ flow_type: flowType,
1507
+ flow_key: flowKey,
1508
+ ...flowKey ? { key: flowKey } : {},
1509
+ init_value: initValue
1510
+ };
1511
+ path5 = withQuery(`${basePath}/project/create`, query);
1512
+ result.flow_type = flowType;
1513
+ result.flow_key = flowKey;
1514
+ result.mobile_path = withQuery("/pages/projectCreate/projectCreate", query);
1332
1515
  }
1516
+ const url = `${origin}${path5}`;
1333
1517
  return {
1334
1518
  ...result,
1335
1519
  path: path5,
1336
- url: `${origin}${path5}`
1520
+ url,
1521
+ ...kind === "project-create" ? { pc_url: url } : {}
1337
1522
  };
1338
1523
  }
1339
1524
  function extractProjectId(value) {
@@ -1488,23 +1673,61 @@ function registerProjectCommands(program2) {
1488
1673
  );
1489
1674
  printResult(options.format, result);
1490
1675
  });
1491
- 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("--skip-form-validation", "Skip local form schema validation before submit").option("--format <format>", "Output format", "pretty").action(async (options) => {
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) => {
1677
+ if (options.body && options.interactive) {
1678
+ throw new Error("--body and --interactive cannot be used together.");
1679
+ }
1492
1680
  const config = await loadConfig();
1493
1681
  const profile = resolveProfile(config, options.profile);
1494
1682
  const client = createApiClient(profile);
1495
1683
  let payload = parseJson2(options.body);
1496
1684
  if (!options.body) {
1497
- if (!options.name) {
1498
- throw new Error("--name is required unless --body is provided.");
1499
- }
1500
1685
  const flow = await resolveFlowIdentifiers(client, options);
1501
1686
  const { flowDetail, ...flowIdentifiers } = flow;
1502
1687
  const extra = parseJson2(options.json);
1503
1688
  const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
1689
+ let name = options.name;
1690
+ if (options.interactive) {
1691
+ if (!flowDetail) {
1692
+ throw new Error("--interactive requires --flow-id so the form schema can be discovered.");
1693
+ }
1694
+ const fields = extractFormFields(flowDetail);
1695
+ const promptResult = await promptProjectCreateForm({ name, form: { ...form }, fields });
1696
+ name = promptResult.name;
1697
+ Object.keys(form).forEach((key) => {
1698
+ delete form[key];
1699
+ });
1700
+ Object.assign(form, promptResult.form);
1701
+ if (promptResult.action === "cancel") {
1702
+ printResult(options.format, { cancelled: true });
1703
+ return;
1704
+ }
1705
+ if (promptResult.action === "open_form") {
1706
+ const url = buildBpmaxUrl(profile, "project-create", {
1707
+ flowType: flowIdentifiers.flow_type,
1708
+ flowKey: flowIdentifiers.flow_key,
1709
+ initValue: {
1710
+ project: { name },
1711
+ key_to_value: form
1712
+ }
1713
+ });
1714
+ printResult(options.format, {
1715
+ handoff: true,
1716
+ url: url.url,
1717
+ pc_url: url.pc_url,
1718
+ mobile_path: url.mobile_path,
1719
+ message: "\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
1720
+ });
1721
+ return;
1722
+ }
1723
+ }
1724
+ if (!name) {
1725
+ throw new Error("--name is required unless --body is provided.");
1726
+ }
1504
1727
  payload = {
1505
1728
  ...extra,
1506
1729
  ...flowIdentifiers,
1507
- name: options.name,
1730
+ name,
1508
1731
  workspace: profile.config.workspace,
1509
1732
  form
1510
1733
  };
@@ -1916,19 +2139,19 @@ function registerSchemaCommands(program2) {
1916
2139
  }
1917
2140
 
1918
2141
  // src/commands/setup.ts
1919
- import { confirm, text as text2 } from "@clack/prompts";
2142
+ import { confirm as confirm2, text as text3 } from "@clack/prompts";
1920
2143
  async function promptText(current, message, placeholder) {
1921
2144
  if (current?.trim()) {
1922
2145
  return current.trim();
1923
2146
  }
1924
- const value = await text2({ message, placeholder });
2147
+ const value = await text3({ message, placeholder });
1925
2148
  if (typeof value !== "string" || !value.trim()) {
1926
2149
  throw new Error(`${message} is required.`);
1927
2150
  }
1928
2151
  return value.trim();
1929
2152
  }
1930
2153
  async function promptConfirm(message) {
1931
- const value = await confirm({ message, initialValue: true });
2154
+ const value = await confirm2({ message, initialValue: true });
1932
2155
  return value === true;
1933
2156
  }
1934
2157
  function registerSetupCommand(program2, deps = {}) {
@@ -2395,6 +2618,18 @@ async function resolveUrl(load, kind, options) {
2395
2618
  function registerUrlCommands(program2, deps = {}) {
2396
2619
  const load = deps.loadConfig || loadConfig;
2397
2620
  const url = program2.command("url").description("Generate BPMAX web URLs");
2621
+ url.command("project-create").description("Generate a project create URL").requiredOption("--flow-type <flowType>", "Flow type").option("--flow-key <flowKey>", "Flow key", "").option("--workspace <workspace>", "Workspace override").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "pretty").action(async (options) => {
2622
+ const config = await load();
2623
+ const profile = resolveProfile(config, options.profile);
2624
+ printUrl(
2625
+ options.format,
2626
+ buildBpmaxUrl(profile, "project-create", {
2627
+ workspace: options.workspace,
2628
+ flowType: options.flowType,
2629
+ flowKey: options.flowKey
2630
+ })
2631
+ );
2632
+ });
2398
2633
  url.command("workspace").description("Generate the current workspace URL").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(async (options) => {
2399
2634
  await resolveUrl(load, "workspace", options);
2400
2635
  });