bpmax-cli 0.1.31 → 0.1.33

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
@@ -665,7 +665,7 @@ async function parseJsonInput(input, label = "JSON input") {
665
665
  // package.json
666
666
  var package_default = {
667
667
  name: "bpmax-cli",
668
- version: "0.1.31",
668
+ version: "0.1.33",
669
669
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
670
670
  type: "module",
671
671
  bin: {
@@ -1975,6 +1975,8 @@ var FIELD_LABEL_NAMES = ["label", "title", "display_name", "displayName", "text"
1975
1975
  var FIELD_TYPE_NAMES = ["type", "field_type", "fieldType", "value_type", "valueType", "control", "component", "widget"];
1976
1976
  var OPTION_NAMES = ["options", "items", "choices", "values"];
1977
1977
  var REQUIRED_NAMES = ["required", "is_required", "isRequired", "require", "must", "validateRequired"];
1978
+ var HIDDEN_NAMES = ["hidden", "is_hidden", "isHidden", "hide", "hideInForm"];
1979
+ var VISIBLE_NAMES = ["visible", "display", "show"];
1978
1980
  function isRecord3(value) {
1979
1981
  return typeof value === "object" && value !== null && !Array.isArray(value);
1980
1982
  }
@@ -2004,6 +2006,25 @@ function pickBoolean(source, keys) {
2004
2006
  if (Array.isArray(rules)) {
2005
2007
  return rules.some((rule) => isRecord3(rule) && pickBoolean(rule, REQUIRED_NAMES));
2006
2008
  }
2009
+ const validateMap = source.validateMap;
2010
+ if (isRecord3(validateMap) && pickBoolean(validateMap, REQUIRED_NAMES)) {
2011
+ return true;
2012
+ }
2013
+ return false;
2014
+ }
2015
+ function pickHidden(source) {
2016
+ for (const key of HIDDEN_NAMES) {
2017
+ const value = source[key];
2018
+ if (value === true || value === 1 || value === "1" || value === "true") {
2019
+ return true;
2020
+ }
2021
+ }
2022
+ for (const key of VISIBLE_NAMES) {
2023
+ const value = source[key];
2024
+ if (value === false || value === 0 || value === "0" || value === "false") {
2025
+ return true;
2026
+ }
2027
+ }
2007
2028
  return false;
2008
2029
  }
2009
2030
  function optionValue(option) {
@@ -2037,6 +2058,7 @@ function fieldFromRecord(source) {
2037
2058
  const label = pickString(source, FIELD_LABEL_NAMES);
2038
2059
  const options = pickOptions(source);
2039
2060
  const required = pickBoolean(source, REQUIRED_NAMES);
2061
+ const hidden = pickHidden(source);
2040
2062
  if (!type && !label && !options && !required) {
2041
2063
  return null;
2042
2064
  }
@@ -2045,6 +2067,7 @@ function fieldFromRecord(source) {
2045
2067
  ...label ? { label } : {},
2046
2068
  ...type ? { type } : {},
2047
2069
  required,
2070
+ ...hidden ? { hidden } : {},
2048
2071
  ...options ? { options } : {}
2049
2072
  };
2050
2073
  }
@@ -2054,10 +2077,12 @@ function isSubFormField(field) {
2054
2077
  }
2055
2078
  function mergeField(existing, incoming) {
2056
2079
  const children = incoming.children ?? existing?.children;
2080
+ const hidden = incoming.hidden === true || existing?.hidden === true && incoming.hidden !== false;
2057
2081
  return {
2058
2082
  ...existing,
2059
2083
  ...incoming,
2060
2084
  required: Boolean(existing?.required || incoming.required),
2085
+ ...hidden ? { hidden } : {},
2061
2086
  ...children?.length ? { children } : {}
2062
2087
  };
2063
2088
  }
@@ -2123,6 +2148,15 @@ function validateComplexSelector(field, value) {
2123
2148
  function isComplexSelectorType(type) {
2124
2149
  return /(plugin_city_selector|plugin_project_selector|plugin_user_selector|plugin_department_selector|relation_project|relation_form|user_selector|department_selector|group_select|project_selector_new)/.test(type);
2125
2150
  }
2151
+ function isEnumSelectType(type) {
2152
+ return /enum_select/.test(type);
2153
+ }
2154
+ function optionComparableValue(value) {
2155
+ if (isRecord3(value) && ("value" in value || "label" in value)) {
2156
+ return value.value ?? value.label;
2157
+ }
2158
+ return value;
2159
+ }
2126
2160
  function validateType(field, value) {
2127
2161
  const type = field.type?.toLowerCase() ?? "";
2128
2162
  if (!type || isEmpty(value)) {
@@ -2143,7 +2177,7 @@ function validateType(field, value) {
2143
2177
  return null;
2144
2178
  }
2145
2179
  if (field.options) {
2146
- const values = Array.isArray(value) ? value.map(String) : [String(value)];
2180
+ const values = Array.isArray(value) ? value.map((item) => String(optionComparableValue(item))) : [String(optionComparableValue(value))];
2147
2181
  const invalid = values.filter((item) => !field.options?.includes(item));
2148
2182
  if (invalid.length > 0) {
2149
2183
  return `${field.key} has invalid option value(s): ${invalid.join(", ")}`;
@@ -2158,6 +2192,10 @@ function validateType(field, value) {
2158
2192
  if (/(array|multi|multiple)/.test(type) && !Array.isArray(value)) {
2159
2193
  return `${field.key} must be an array`;
2160
2194
  }
2195
+ if (isEnumSelectType(type) && isRecord3(value)) {
2196
+ const optionValue2 = value.value ?? value.label;
2197
+ return typeof optionValue2 === "string" || typeof optionValue2 === "number" ? null : `${field.key} must be an enum option object with a scalar value`;
2198
+ }
2161
2199
  if (/(string|text|textarea|input|date|time|select|user|department)/.test(type) && typeof value === "object" && value !== null && !Array.isArray(value)) {
2162
2200
  return `${field.key} must be a scalar value`;
2163
2201
  }
@@ -2637,13 +2675,20 @@ async function printCreateFormHandoff(client, format, profile, flowIdentifiers,
2637
2675
  key_to_value: options.form
2638
2676
  };
2639
2677
  const prefillContext = buildPrefillContext(options.fields ?? [], options.form);
2640
- const prefill = await storeCreateFormPrefill(client, flowIdentifiers, initValue, prefillContext);
2678
+ let prefill;
2679
+ let prefillError;
2680
+ try {
2681
+ prefill = await storeCreateFormPrefill(client, flowIdentifiers, initValue, prefillContext);
2682
+ } catch (error) {
2683
+ prefillError = error instanceof Error ? error.message : String(error);
2684
+ }
2641
2685
  const url = buildBpmaxUrl(profile, "project-create", {
2642
2686
  flowType: flowIdentifiers.flow_type,
2643
2687
  flowKey: flowIdentifiers.flow_key,
2644
- prefillToken: prefill.token
2688
+ initValue,
2689
+ ...prefill ? { prefillToken: prefill.token } : {}
2645
2690
  });
2646
- assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form), prefill.token);
2691
+ assertCreateFormHandoffUrl(url, initValue, Object.keys(options.form), prefill?.token);
2647
2692
  const replyMarkdown = `[\u586B\u5199\u8868\u5355](${url.url})`;
2648
2693
  const agentWarning = [
2649
2694
  "Agent must reply with the full create form URL exactly as provided.",
@@ -2658,9 +2703,14 @@ async function printCreateFormHandoff(client, format, profile, flowIdentifiers,
2658
2703
  mobile_path: url.mobile_path,
2659
2704
  reply_markdown: replyMarkdown,
2660
2705
  agent_warning: agentWarning,
2661
- prefill_token: prefill.token,
2662
- prefill_expires_in: prefill.expires_in,
2663
- prefill_expires_at: prefill.expires_at,
2706
+ ...prefill ? {
2707
+ prefill_token: prefill.token,
2708
+ prefill_expires_in: prefill.expires_in,
2709
+ prefill_expires_at: prefill.expires_at
2710
+ } : {
2711
+ prefill_fallback: "init_value",
2712
+ ...prefillError ? { prefill_error: prefillError } : {}
2713
+ },
2664
2714
  init_value: initValue,
2665
2715
  init_value_keys: Object.keys(options.form),
2666
2716
  prefill_context: prefillContext,
@@ -2671,9 +2721,26 @@ function assertCreateFormHandoffUrl(url, expectedInitValue, expectedFormKeys, ex
2671
2721
  const targets = [url.url, url.pc_url, url.mobile_path].filter((item) => Boolean(item));
2672
2722
  for (const target of targets) {
2673
2723
  const base = target.startsWith("http") ? void 0 : "https://bpmax.local";
2674
- const prefillToken = new URL(target, base).searchParams.get("prefill_token");
2675
- if (prefillToken !== expectedPrefillToken) {
2676
- throw new Error("Generated project create handoff URL is missing prefill_token; refusing to output an un-prefilled link.");
2724
+ const params = new URL(target, base).searchParams;
2725
+ const prefillToken = params.get("prefill_token");
2726
+ if (expectedPrefillToken) {
2727
+ if (prefillToken !== expectedPrefillToken) {
2728
+ throw new Error("Generated project create handoff URL is missing prefill_token; refusing to output an un-prefilled link.");
2729
+ }
2730
+ continue;
2731
+ }
2732
+ const initValueRaw = params.get("init_value");
2733
+ if (!initValueRaw) {
2734
+ throw new Error("Generated project create handoff URL is missing init_value fallback; refusing to output an un-prefilled link.");
2735
+ }
2736
+ const initValue = JSON.parse(initValueRaw);
2737
+ const keyToValue2 = initValue.key_to_value;
2738
+ if (typeof keyToValue2 !== "object" || keyToValue2 === null || Array.isArray(keyToValue2)) {
2739
+ throw new Error("Generated project create handoff URL is missing init_value.key_to_value; refusing to output an un-prefilled link.");
2740
+ }
2741
+ const missingKeys2 = expectedFormKeys.filter((key) => !Object.prototype.hasOwnProperty.call(keyToValue2, key));
2742
+ if (missingKeys2.length > 0) {
2743
+ throw new Error(`Generated project create handoff URL is missing prefilled form keys: ${missingKeys2.join(", ")}`);
2677
2744
  }
2678
2745
  }
2679
2746
  const keyToValue = expectedInitValue.key_to_value;
@@ -2720,10 +2787,6 @@ function assertHandoffFormCompatible(fields, form) {
2720
2787
  function isEmptyValue(value) {
2721
2788
  return value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
2722
2789
  }
2723
- function isSuggestedManualField(field) {
2724
- const type = field.type?.toLowerCase() ?? "";
2725
- return /(plugin_|selector|relation_|sub[_-]?form|associated[_-]?form|table|upload|image|file|attachment)/.test(type);
2726
- }
2727
2790
  function contextField(field, reason, options = {}) {
2728
2791
  return {
2729
2792
  key: options.path ?? field.key,
@@ -2746,10 +2809,8 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
2746
2809
  parentKey: options.parentKey
2747
2810
  };
2748
2811
  if (isEmptyValue(value)) {
2749
- if (field.required) {
2812
+ if (field.required && !field.hidden) {
2750
2813
  result.missing_fields.push(contextField(field, "required_empty", fieldOptions));
2751
- } else if (isSuggestedManualField(field)) {
2752
- result.suggested_fields.push(contextField(field, "manual_confirm_recommended", fieldOptions));
2753
2814
  }
2754
2815
  continue;
2755
2816
  }