bpmax-cli 0.1.20 → 0.1.22

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
@@ -135,10 +135,12 @@ Use `--flow-key` when the target flow has a non-empty key. `--flow-step-id` maps
135
135
  Create a project with an interactive form guide:
136
136
 
137
137
  ```bash
138
- bpmax-cli project create --profile yuanrong --flow-id 123 --interactive --format json
138
+ bpmax-cli project create --profile yuanrong --flow-id 123 --format json
139
139
  ```
140
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`.
141
+ `project create` uses the interactive guide by default. 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
+
143
+ Use `--no-interactive` only for explicit direct-submit automation. If the target form template contains auto-init lambda scripts, the CLI still refuses direct submit and prints a web form handoff URL with `reason: "form_template_auto_init_lambda"`.
142
144
 
143
145
  ## ES fast queries
144
146
 
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.20",
815
+ version: "0.1.22",
816
816
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
817
817
  type: "module",
818
818
  bin: {
@@ -1820,6 +1820,12 @@ function printCreateFormHandoff(format, profile, flowIdentifiers, options) {
1820
1820
  message: options.message
1821
1821
  });
1822
1822
  }
1823
+ function isEmptyFormValue(value) {
1824
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1825
+ }
1826
+ function missingRequiredFormFields(fields, form) {
1827
+ return fields.filter((field) => field.required && isEmptyFormValue(form[field.key])).map((field) => field.label ? `${field.label} (${field.key})` : field.key);
1828
+ }
1823
1829
  function registerProjectCommands(program2) {
1824
1830
  const project = program2.command("project").description("Project commands");
1825
1831
  project.command("list").description("List projects").option("--profile <profile>", "Profile name").option("--page <page>", "Page number", "1").option("--page-size <pageSize>", "Page size", "20").option("--body <json>", "Project list body JSON", "{}").option("--format <format>", "Output format", "table").action(async (options) => {
@@ -1880,13 +1886,15 @@ function registerProjectCommands(program2) {
1880
1886
  );
1881
1887
  printResult(options.format, result);
1882
1888
  });
1883
- 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) => {
1884
- if (options.body && options.interactive) {
1889
+ 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) => {
1890
+ const interactiveSource = command.getOptionValueSource("interactive");
1891
+ if (options.body && options.interactive === true && interactiveSource === "cli") {
1885
1892
  throw new Error("--body and --interactive cannot be used together.");
1886
1893
  }
1887
1894
  const config = await loadConfig();
1888
1895
  const profile = resolveProfile(config, options.profile);
1889
1896
  const client = createApiClient(profile);
1897
+ const useInteractive = !options.body && options.interactive !== false;
1890
1898
  let payload = parseJson2(options.body);
1891
1899
  if (!options.body) {
1892
1900
  const flow = await resolveFlowIdentifiers(client, options);
@@ -1894,10 +1902,16 @@ function registerProjectCommands(program2) {
1894
1902
  const extra = parseJson2(options.json);
1895
1903
  const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
1896
1904
  let name = options.name;
1897
- let interactiveTemplate;
1898
- if (options.interactive) {
1905
+ let projectFormTemplate;
1906
+ const loadProjectFormTemplate = async () => {
1907
+ if (projectFormTemplate === void 0) {
1908
+ projectFormTemplate = await fetchProjectFormTemplate(client, flowDetail);
1909
+ }
1910
+ return projectFormTemplate;
1911
+ };
1912
+ if (useInteractive) {
1899
1913
  if (!flowDetail) {
1900
- throw new Error("--interactive requires --flow-id so the form schema can be discovered.");
1914
+ throw new Error("Interactive project creation requires --flow-id so the form schema can be discovered.");
1901
1915
  }
1902
1916
  const fields = extractFormFields(flowDetail);
1903
1917
  const promptResult = await promptProjectCreateForm({
@@ -1915,8 +1929,8 @@ function registerProjectCommands(program2) {
1915
1929
  printResult(options.format, { cancelled: true });
1916
1930
  return;
1917
1931
  }
1918
- interactiveTemplate = await fetchProjectFormTemplate(client, flowDetail);
1919
- if (interactiveTemplate && hasAutoInitLambda(interactiveTemplate.template)) {
1932
+ projectFormTemplate = await loadProjectFormTemplate();
1933
+ if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
1920
1934
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1921
1935
  name,
1922
1936
  form,
@@ -1940,6 +1954,26 @@ function registerProjectCommands(program2) {
1940
1954
  if (!name) {
1941
1955
  throw new Error("--name is required unless --body is provided.");
1942
1956
  }
1957
+ projectFormTemplate = await loadProjectFormTemplate();
1958
+ if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
1959
+ const missingFields = missingRequiredFormFields(extractFormFields(flowDetail), form);
1960
+ if (!useInteractive && missingFields.length > 0) {
1961
+ throw new Error(
1962
+ [
1963
+ "Form template has auto initialization scripts and cannot be handed off before required fields are collected.",
1964
+ "Rerun without --no-interactive to guide the user through the form, or provide --json.form with the missing values.",
1965
+ `Missing required fields: ${missingFields.join(", ")}`
1966
+ ].join("\n")
1967
+ );
1968
+ }
1969
+ printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1970
+ name,
1971
+ form,
1972
+ reason: "form_template_auto_init_lambda",
1973
+ message: "\u68C0\u6D4B\u5230\u8868\u5355\u6A21\u677F\u5305\u542B\u81EA\u52A8\u521D\u59CB\u5316\u811A\u672C\uFF0C\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
1974
+ });
1975
+ return;
1976
+ }
1943
1977
  const { form: _rawForm, ...projectExtra } = extra;
1944
1978
  const { flow_key: flowKey, ...projectFlowIdentifiers } = flowIdentifiers;
1945
1979
  payload = {
@@ -1948,7 +1982,7 @@ function registerProjectCommands(program2) {
1948
1982
  key: flowKey,
1949
1983
  name,
1950
1984
  workspace: profile.config.workspace,
1951
- ...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, interactiveTemplate)
1985
+ ...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, projectFormTemplate)
1952
1986
  };
1953
1987
  if (!options.skipFormValidation) {
1954
1988
  await validateCreateForm(client, { flowId: options.flowId, flowDetail, form });