bpmax-cli 0.1.21 → 0.1.23

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 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.21",
815
+ version: "0.1.23",
816
816
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
817
817
  type: "module",
818
818
  bin: {
@@ -1803,23 +1803,59 @@ async function validateCreateForm(client, options) {
1803
1803
  }
1804
1804
  }
1805
1805
  function printCreateFormHandoff(format, profile, flowIdentifiers, options) {
1806
+ const initValue = {
1807
+ project: { name: options.name },
1808
+ key_to_value: options.form
1809
+ };
1806
1810
  const url = buildBpmaxUrl(profile, "project-create", {
1807
1811
  flowType: flowIdentifiers.flow_type,
1808
1812
  flowKey: flowIdentifiers.flow_key,
1809
- initValue: {
1810
- project: { name: options.name },
1811
- key_to_value: options.form
1812
- }
1813
+ initValue
1813
1814
  });
1815
+ assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form));
1814
1816
  printResult(format, {
1815
1817
  handoff: true,
1816
1818
  ...options.reason ? { reason: options.reason } : {},
1817
1819
  url: url.url,
1818
1820
  pc_url: url.pc_url,
1819
1821
  mobile_path: url.mobile_path,
1822
+ init_value: initValue,
1823
+ init_value_keys: Object.keys(options.form),
1820
1824
  message: options.message
1821
1825
  });
1822
1826
  }
1827
+ function parseInitValueFromUrl(rawUrl) {
1828
+ const base = rawUrl.startsWith("http") ? void 0 : "https://bpmax.local";
1829
+ const initValue = new URL(rawUrl, base).searchParams.get("init_value");
1830
+ if (!initValue) {
1831
+ return void 0;
1832
+ }
1833
+ return JSON.parse(initValue);
1834
+ }
1835
+ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
1836
+ const targets = [url.url, url.pc_url, url.mobile_path].filter((item) => Boolean(item));
1837
+ for (const target of targets) {
1838
+ const initValue = parseInitValueFromUrl(target);
1839
+ const keyToValue = initValue?.key_to_value;
1840
+ if (!initValue || typeof keyToValue !== "object" || keyToValue === null || Array.isArray(keyToValue)) {
1841
+ throw new Error("Generated project create handoff URL is missing init_value.key_to_value; refusing to output an un-prefilled link.");
1842
+ }
1843
+ const missingKeys = expectedFormKeys.filter((key) => !Object.prototype.hasOwnProperty.call(keyToValue, key));
1844
+ if (missingKeys.length > 0) {
1845
+ throw new Error(`Generated project create handoff URL is missing prefilled form keys: ${missingKeys.join(", ")}`);
1846
+ }
1847
+ }
1848
+ const encoded = JSON.stringify(expectedInitValue);
1849
+ if (!url.url.includes("init_value=") || !url.pc_url?.includes("init_value=") || !url.mobile_path?.includes("init_value=")) {
1850
+ throw new Error(`Generated project create handoff URL did not include init_value (${encoded.length} bytes).`);
1851
+ }
1852
+ }
1853
+ function isEmptyFormValue(value) {
1854
+ return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1855
+ }
1856
+ function missingRequiredFormFields(fields, form) {
1857
+ return fields.filter((field) => field.required && isEmptyFormValue(form[field.key])).map((field) => field.label ? `${field.label} (${field.key})` : field.key);
1858
+ }
1823
1859
  function registerProjectCommands(program2) {
1824
1860
  const project = program2.command("project").description("Project commands");
1825
1861
  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) => {
@@ -1950,6 +1986,16 @@ function registerProjectCommands(program2) {
1950
1986
  }
1951
1987
  projectFormTemplate = await loadProjectFormTemplate();
1952
1988
  if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
1989
+ const missingFields = missingRequiredFormFields(extractFormFields(flowDetail), form);
1990
+ if (!useInteractive && missingFields.length > 0) {
1991
+ throw new Error(
1992
+ [
1993
+ "Form template has auto initialization scripts and cannot be handed off before required fields are collected.",
1994
+ "Rerun without --no-interactive to guide the user through the form, or provide --json.form with the missing values.",
1995
+ `Missing required fields: ${missingFields.join(", ")}`
1996
+ ].join("\n")
1997
+ );
1998
+ }
1953
1999
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1954
2000
  name,
1955
2001
  form,