bpmax-cli 0.1.26 → 0.1.27

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.26",
815
+ version: "0.1.27",
816
816
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
817
817
  type: "module",
818
818
  bin: {
@@ -1246,13 +1246,35 @@ function extractFormFields(flowDetail) {
1246
1246
  function isEmpty(value) {
1247
1247
  return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1248
1248
  }
1249
+ function validateComplexSelector(field, value) {
1250
+ const type = field.type?.toLowerCase() ?? "";
1251
+ if (!/(plugin_.*selector|selector|picker)/.test(type)) {
1252
+ return null;
1253
+ }
1254
+ const validObject = (item) => isRecord2(item);
1255
+ if (Array.isArray(value)) {
1256
+ return value.every(validObject) ? null : `${field.key} must contain selector option object(s), not scalar values`;
1257
+ }
1258
+ if (validObject(value)) {
1259
+ return null;
1260
+ }
1261
+ return `${field.key} must be a selector option object or array of option objects, not a scalar value`;
1262
+ }
1249
1263
  function validateType(field, value) {
1250
1264
  const type = field.type?.toLowerCase() ?? "";
1251
1265
  if (!type || isEmpty(value)) {
1252
1266
  return null;
1253
1267
  }
1254
1268
  if (isSubFormField(field)) {
1255
- return Array.isArray(value) ? null : `${field.key} must be a JSON array of row objects`;
1269
+ if (!Array.isArray(value)) {
1270
+ return `${field.key} must be a JSON array of row objects`;
1271
+ }
1272
+ const invalidRowIndex = value.findIndex((row) => !isRecord2(row));
1273
+ return invalidRowIndex >= 0 ? `${field.key}[${invalidRowIndex}] must be a row object` : null;
1274
+ }
1275
+ const selectorError = validateComplexSelector(field, value);
1276
+ if (selectorError) {
1277
+ return selectorError;
1256
1278
  }
1257
1279
  if (field.options) {
1258
1280
  const values = Array.isArray(value) ? value.map(String) : [String(value)];
@@ -1858,11 +1880,24 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys) {
1858
1880
  throw new Error(`Generated project create handoff URL did not include init_value (${encoded.length} bytes).`);
1859
1881
  }
1860
1882
  }
1861
- function isEmptyFormValue(value) {
1862
- return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
1883
+ function fieldsForValidation(flowDetail, projectFormTemplate) {
1884
+ const templateFields = projectFormTemplate ? extractFormFields(projectFormTemplate.template) : [];
1885
+ return templateFields.length > 0 ? templateFields : extractFormFields(flowDetail);
1863
1886
  }
1864
- function missingRequiredFormFields(fields, form) {
1865
- return fields.filter((field) => field.required && isEmptyFormValue(form[field.key])).map((field) => field.label ? `${field.label} (${field.key})` : field.key);
1887
+ function formValidationErrors(fields, form) {
1888
+ return validateFormAgainstFields(form, fields).errors;
1889
+ }
1890
+ function assertHandoffFormReady(fields, form) {
1891
+ const errors = formValidationErrors(fields, form);
1892
+ if (errors.length > 0) {
1893
+ throw new Error(
1894
+ [
1895
+ "Form handoff cannot be generated because collected values are incomplete or not page-compatible.",
1896
+ "Continue guiding the user to fill missing fields, or ask them to choose complex selector fields in the BPMAX page.",
1897
+ `Validation errors: ${errors.join("; ")}`
1898
+ ].join("\n")
1899
+ );
1900
+ }
1866
1901
  }
1867
1902
  function registerProjectCommands(program2) {
1868
1903
  const project = program2.command("project").description("Project commands");
@@ -1969,6 +2004,7 @@ function registerProjectCommands(program2) {
1969
2004
  }
1970
2005
  projectFormTemplate = await loadProjectFormTemplate();
1971
2006
  if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
2007
+ assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
1972
2008
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1973
2009
  name,
1974
2010
  form,
@@ -1981,6 +2017,7 @@ function registerProjectCommands(program2) {
1981
2017
  if (!options.allowFormHandoff) {
1982
2018
  throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
1983
2019
  }
2020
+ assertHandoffFormReady(fieldsForValidation(flowDetail, projectFormTemplate), form);
1984
2021
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
1985
2022
  name,
1986
2023
  form,
@@ -1994,7 +2031,8 @@ function registerProjectCommands(program2) {
1994
2031
  }
1995
2032
  projectFormTemplate = await loadProjectFormTemplate();
1996
2033
  if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
1997
- const missingFields = missingRequiredFormFields(extractFormFields(flowDetail), form);
2034
+ const handoffFields = fieldsForValidation(flowDetail, projectFormTemplate);
2035
+ const missingFields = formValidationErrors(handoffFields, form);
1998
2036
  if (!useInteractive && missingFields.length > 0) {
1999
2037
  throw new Error(
2000
2038
  [
@@ -2004,6 +2042,7 @@ function registerProjectCommands(program2) {
2004
2042
  ].join("\n")
2005
2043
  );
2006
2044
  }
2045
+ assertHandoffFormReady(handoffFields, form);
2007
2046
  printCreateFormHandoff(options.format, profile, flowIdentifiers, {
2008
2047
  name,
2009
2048
  form,