bpmax-cli 0.2.1-beta.31 → 0.2.1-beta.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 +483 -36
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-cli/SKILL.md +2 -0
- package/skills/bpmax-form-template-editor/SKILL.md +14 -2
- package/skills/bpmax-form-template-editor/references/dynamic-field-state.md +164 -0
- package/skills/bpmax-shared/SKILL.md +8 -0
package/dist/bin.js
CHANGED
|
@@ -492,7 +492,7 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
|
|
|
492
492
|
// package.json
|
|
493
493
|
var package_default = {
|
|
494
494
|
name: "bpmax-cli",
|
|
495
|
-
version: "0.2.1-beta.
|
|
495
|
+
version: "0.2.1-beta.33",
|
|
496
496
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
497
497
|
type: "module",
|
|
498
498
|
bin: {
|
|
@@ -764,6 +764,9 @@ function printResult(format, value) {
|
|
|
764
764
|
switch (format) {
|
|
765
765
|
case "json":
|
|
766
766
|
console.log(JSON.stringify(withJsonNotice(value), null, 2));
|
|
767
|
+
if (!isRecord(value)) {
|
|
768
|
+
emitTextNotice();
|
|
769
|
+
}
|
|
767
770
|
return;
|
|
768
771
|
case "ndjson":
|
|
769
772
|
if (Array.isArray(value)) {
|
|
@@ -773,6 +776,7 @@ function printResult(format, value) {
|
|
|
773
776
|
} else {
|
|
774
777
|
console.log(JSON.stringify(value));
|
|
775
778
|
}
|
|
779
|
+
emitTextNotice();
|
|
776
780
|
return;
|
|
777
781
|
case "table":
|
|
778
782
|
if (Array.isArray(value)) {
|
|
@@ -782,6 +786,7 @@ function printResult(format, value) {
|
|
|
782
786
|
} else {
|
|
783
787
|
console.log(value);
|
|
784
788
|
}
|
|
789
|
+
emitTextNotice();
|
|
785
790
|
return;
|
|
786
791
|
case "pretty":
|
|
787
792
|
default:
|
|
@@ -4276,6 +4281,7 @@ var NAV_DEFAULT_NAME_BY_TYPE = {
|
|
|
4276
4281
|
shortcut_mobile: "\u79FB\u52A8\u5FEB\u6377\u5165\u53E3"
|
|
4277
4282
|
};
|
|
4278
4283
|
var MAX_FORM_TEMPLATE_NAME_LENGTH = 20;
|
|
4284
|
+
var MAX_FORM_TEMPLATE_FIELD_LENGTH = 20;
|
|
4279
4285
|
var MAX_DATASET_CUSTOM_KEY_LENGTH = 20;
|
|
4280
4286
|
var MAX_PAGE_TEMPLATE_NAME_LENGTH = 20;
|
|
4281
4287
|
var FORM_TEMPLATE_ID_CONST_PATTERN = /\b(?:const|let|var)\s+[A-Za-z_$][\w$]*(?:FORM|Form|form)[A-Za-z0-9_$]*(?:TEMPLATE|Template|template)[A-Za-z0-9_$]*(?:ID|Id|id)\s*=\s*\d+\b/;
|
|
@@ -5019,7 +5025,7 @@ async function lintFlowAppWorkFiles(formWorkFile, flowWorkFile, options = {}) {
|
|
|
5019
5025
|
} else if (formWork.mode !== "create") {
|
|
5020
5026
|
formErrors.push("flow-app create requires form work with mode=create.");
|
|
5021
5027
|
} else {
|
|
5022
|
-
validateFormTemplateWorkLint(formWork, formErrors);
|
|
5028
|
+
validateFormTemplateWorkLint(formWork, formErrors, warnings, "create");
|
|
5023
5029
|
}
|
|
5024
5030
|
if (!isRecord3(flowWork)) {
|
|
5025
5031
|
flowErrors.push("flow-app create requires flow work to be a JSON object.");
|
|
@@ -8302,34 +8308,50 @@ function formTemplateControlValueType(rule, value) {
|
|
|
8302
8308
|
}
|
|
8303
8309
|
return void 0;
|
|
8304
8310
|
}
|
|
8305
|
-
function validateRadioFormTemplateControl(field, rule, value, errors) {
|
|
8311
|
+
function validateRadioFormTemplateControl(field, rule, value, errors, warnings, mode) {
|
|
8306
8312
|
const options = formTemplateControlOptions(rule, value);
|
|
8307
8313
|
if (!options.length) {
|
|
8308
|
-
errors.push(`form
|
|
8314
|
+
errors.push(`[form.radio.options_required] \u5355\u9009\u5B57\u6BB5 ${field} \u5FC5\u987B\u5728 rule/value \u4E2D\u914D\u7F6E\u975E\u7A7A options\uFF0C\u624D\u80FD build/submit\u3002`);
|
|
8309
8315
|
}
|
|
8310
8316
|
for (const [index, option] of options.entries()) {
|
|
8311
8317
|
if (!isRecord3(option)) {
|
|
8312
|
-
errors.push(`form
|
|
8318
|
+
errors.push(`[form.radio.option_object] \u5355\u9009\u5B57\u6BB5 ${field} \u7684 options[${index}] \u5FC5\u987B\u662F\u5305\u542B label/value \u7684\u5BF9\u8C61\u3002`);
|
|
8313
8319
|
continue;
|
|
8314
8320
|
}
|
|
8315
8321
|
const hasLabel = typeof option.label === "string" && option.label.length > 0 || typeof option.title === "string" && option.title.length > 0;
|
|
8316
8322
|
const hasValue = Object.prototype.hasOwnProperty.call(option, "value") || Object.prototype.hasOwnProperty.call(option, "key");
|
|
8317
8323
|
if (!hasLabel || !hasValue) {
|
|
8318
|
-
errors.push(`form
|
|
8324
|
+
errors.push(`[form.radio.option_shape] \u5355\u9009\u5B57\u6BB5 ${field} \u7684 options[${index}] \u5FC5\u987B\u540C\u65F6\u5305\u542B label \u548C value\u3002`);
|
|
8319
8325
|
}
|
|
8320
8326
|
}
|
|
8321
8327
|
const valueType = formTemplateControlValueType(rule, value);
|
|
8322
8328
|
if (valueType === void 0) {
|
|
8323
|
-
errors.push(`form
|
|
8329
|
+
errors.push(`[form.radio.value_type_required] \u5355\u9009\u5B57\u6BB5 ${field} \u5FC5\u987B\u663E\u5F0F\u914D\u7F6E value_type=string\u3002`);
|
|
8324
8330
|
} else if (valueType !== "string") {
|
|
8325
|
-
errors.push(`form
|
|
8331
|
+
errors.push(`[form.radio.value_type] \u5355\u9009\u5B57\u6BB5 ${field} \u7684 value_type \u5FC5\u987B\u662F string\u3002`);
|
|
8326
8332
|
}
|
|
8327
8333
|
const validateMap = value?.validateMap;
|
|
8328
8334
|
if (!isRecord3(validateMap) || !Object.prototype.hasOwnProperty.call(validateMap, "required")) {
|
|
8329
|
-
errors.push(`form
|
|
8335
|
+
errors.push(`[form.radio.validate_required] \u5355\u9009\u5B57\u6BB5 ${field} \u5FC5\u987B\u914D\u7F6E value.validateMap.required\u3002`);
|
|
8336
|
+
}
|
|
8337
|
+
if (!rule || rule._fc_drag_tag !== "radio" || rule.name !== "radio") {
|
|
8338
|
+
errors.push(
|
|
8339
|
+
`[form.radio.runtime_contract] \u5355\u9009\u5B57\u6BB5 ${field} \u5FC5\u987B\u914D\u7F6E rule._fc_drag_tag=radio \u548C rule.name=radio\uFF1B\u7F3A\u5C11\u63A7\u4EF6\u8EAB\u4EFD\u65F6\u8FD0\u884C\u6001\u4F1A\u9519\u8BEF\u6E32\u67D3\u4E3A\u6587\u672C\u6846\u3002`
|
|
8340
|
+
);
|
|
8341
|
+
}
|
|
8342
|
+
if (rule?.defaultValueType !== "option") {
|
|
8343
|
+
const message = `[form.radio.default_value_type] \u5355\u9009\u5B57\u6BB5 ${field} \u5EFA\u8BAE\u914D\u7F6E rule.defaultValueType=option\uFF1B\u68C0\u6D4B\u5230 ${String(rule?.defaultValueType ?? "\u7F3A\u5931")}\u3002`;
|
|
8344
|
+
if (mode === "create") errors.push(message);
|
|
8345
|
+
else warnings.push(`${message} \u5386\u53F2 edit \u6A21\u677F\u6682\u4E0D\u963B\u65AD\uFF1B\u4FEE\u6539\u8BE5\u5B57\u6BB5\u65F6\u5E94\u540C\u6B65\u8FC1\u79FB\u3002`);
|
|
8346
|
+
}
|
|
8347
|
+
const persistedValue = value?.value;
|
|
8348
|
+
if (!isRecord3(persistedValue) || persistedValue.type !== "radio") {
|
|
8349
|
+
const message = `[form.radio.value_shape] \u5355\u9009\u5B57\u6BB5 ${field} \u5EFA\u8BAE\u5C06 value \u6301\u4E45\u5316\u4E3A { type: "radio", value?: <option> }\uFF1B\u68C0\u6D4B\u5230\u5386\u53F2\u6807\u91CF\u6216\u7A7A\u503C\u7ED3\u6784\u3002`;
|
|
8350
|
+
if (mode === "create") errors.push(message);
|
|
8351
|
+
else warnings.push(`${message} \u5386\u53F2 edit \u6A21\u677F\u6682\u4E0D\u963B\u65AD\uFF1B\u4FEE\u6539\u8BE5\u5B57\u6BB5\u65F6\u5E94\u540C\u6B65\u8FC1\u79FB\u3002`);
|
|
8330
8352
|
}
|
|
8331
8353
|
}
|
|
8332
|
-
function validateFormTemplateControlContracts(payload, errors) {
|
|
8354
|
+
function validateFormTemplateControlContracts(payload, errors, warnings, mode) {
|
|
8333
8355
|
const validatePair = (field, rule, value) => {
|
|
8334
8356
|
const type = typeof rule?.type === "string" ? rule.type : value ? formTemplateValueFieldType(value) : "";
|
|
8335
8357
|
if (type === "serial_number") {
|
|
@@ -8339,7 +8361,7 @@ function validateFormTemplateControlContracts(payload, errors) {
|
|
|
8339
8361
|
return;
|
|
8340
8362
|
}
|
|
8341
8363
|
if (type === "radio") {
|
|
8342
|
-
validateRadioFormTemplateControl(field, rule, value, errors);
|
|
8364
|
+
validateRadioFormTemplateControl(field, rule, value, errors, warnings, mode);
|
|
8343
8365
|
}
|
|
8344
8366
|
if (rule?.lambda === "ctx.userInfo?.name || ''") {
|
|
8345
8367
|
const props = isRecord3(rule.props) ? rule.props : {};
|
|
@@ -8528,13 +8550,392 @@ function validateStructuredFormTemplateVisualReview(payload, errors) {
|
|
|
8528
8550
|
}
|
|
8529
8551
|
}
|
|
8530
8552
|
}
|
|
8531
|
-
|
|
8553
|
+
var FORM_TEMPLATE_DYNAMIC_STATE_SPECS = [
|
|
8554
|
+
{
|
|
8555
|
+
kind: "visibility",
|
|
8556
|
+
enabledKey: "hasVisibilityCondition",
|
|
8557
|
+
configKey: "visibilityCondition",
|
|
8558
|
+
label: "\u52A8\u6001\u663E\u9690"
|
|
8559
|
+
},
|
|
8560
|
+
{
|
|
8561
|
+
kind: "disabled",
|
|
8562
|
+
enabledKey: "hasDisabledCondition",
|
|
8563
|
+
configKey: "disabledCondition",
|
|
8564
|
+
label: "\u52A8\u6001\u53EA\u8BFB"
|
|
8565
|
+
},
|
|
8566
|
+
{
|
|
8567
|
+
kind: "required",
|
|
8568
|
+
enabledKey: "hasRequiredCondition",
|
|
8569
|
+
configKey: "requiredCondition",
|
|
8570
|
+
label: "\u52A8\u6001\u5FC5\u586B"
|
|
8571
|
+
}
|
|
8572
|
+
];
|
|
8573
|
+
var FORM_TEMPLATE_CONDITION_LOGICS = /* @__PURE__ */ new Set(["AND", "OR"]);
|
|
8574
|
+
var FORM_TEMPLATE_CONDITION_OPERATORS = /* @__PURE__ */ new Set([
|
|
8575
|
+
"eq",
|
|
8576
|
+
"ne",
|
|
8577
|
+
"gt",
|
|
8578
|
+
"gte",
|
|
8579
|
+
"lt",
|
|
8580
|
+
"lte",
|
|
8581
|
+
"contains",
|
|
8582
|
+
"isEmpty",
|
|
8583
|
+
"isNotEmpty"
|
|
8584
|
+
]);
|
|
8585
|
+
var FORM_TEMPLATE_CONDITION_LEFT_TYPES = /* @__PURE__ */ new Set(["field", "variable"]);
|
|
8586
|
+
var FORM_TEMPLATE_CONDITION_RIGHT_TYPES = /* @__PURE__ */ new Set(["field", "variable", "constant"]);
|
|
8587
|
+
var FORM_TEMPLATE_CONDITION_UNARY_OPERATORS = /* @__PURE__ */ new Set(["isEmpty", "isNotEmpty"]);
|
|
8588
|
+
var FORM_TEMPLATE_DYNAMIC_REQUIRED_UNSUPPORTED_TYPES = /* @__PURE__ */ new Set([
|
|
8589
|
+
"raw",
|
|
8590
|
+
"label",
|
|
8591
|
+
"divider",
|
|
8592
|
+
"i_button",
|
|
8593
|
+
"button"
|
|
8594
|
+
]);
|
|
8595
|
+
function collectFormTemplateRuleEntries(payload) {
|
|
8596
|
+
const entries = [];
|
|
8597
|
+
const visited = /* @__PURE__ */ new Set();
|
|
8598
|
+
const visit = (value, pathName) => {
|
|
8599
|
+
if (Array.isArray(value)) {
|
|
8600
|
+
value.forEach((item, index) => visit(item, `${pathName}[${index}]`));
|
|
8601
|
+
return;
|
|
8602
|
+
}
|
|
8603
|
+
if (!isRecord3(value) || visited.has(value)) {
|
|
8604
|
+
return;
|
|
8605
|
+
}
|
|
8606
|
+
visited.add(value);
|
|
8607
|
+
const field = typeof value.field === "string" ? value.field.trim() : "";
|
|
8608
|
+
if (field) {
|
|
8609
|
+
entries.push({ field, path: pathName, rule: value });
|
|
8610
|
+
}
|
|
8611
|
+
for (const [key, child] of Object.entries(value)) {
|
|
8612
|
+
if (key === "visibilityCondition" || key === "disabledCondition" || key === "requiredCondition") {
|
|
8613
|
+
continue;
|
|
8614
|
+
}
|
|
8615
|
+
if (Array.isArray(child) || isRecord3(child)) {
|
|
8616
|
+
visit(child, `${pathName}.${key}`);
|
|
8617
|
+
}
|
|
8618
|
+
}
|
|
8619
|
+
};
|
|
8620
|
+
if (isRecord3(payload.fields)) {
|
|
8621
|
+
for (const [field, bundle] of Object.entries(payload.fields)) {
|
|
8622
|
+
if (!isRecord3(bundle) || !isRecord3(bundle.rule)) {
|
|
8623
|
+
continue;
|
|
8624
|
+
}
|
|
8625
|
+
visit(bundle.rule, `fields.${field}.rule`);
|
|
8626
|
+
}
|
|
8627
|
+
} else if (Array.isArray(payload.rule)) {
|
|
8628
|
+
visit(payload.rule, "rule");
|
|
8629
|
+
}
|
|
8630
|
+
return entries;
|
|
8631
|
+
}
|
|
8632
|
+
function formTemplateStaticRequiredFields(payload) {
|
|
8633
|
+
const required = /* @__PURE__ */ new Set();
|
|
8634
|
+
const addValue = (value) => {
|
|
8635
|
+
if (!isRecord3(value) || typeof value.field !== "string" || !isRecord3(value.validateMap)) {
|
|
8636
|
+
return;
|
|
8637
|
+
}
|
|
8638
|
+
if (value.validateMap.required === true) {
|
|
8639
|
+
required.add(value.field);
|
|
8640
|
+
}
|
|
8641
|
+
};
|
|
8642
|
+
if (Array.isArray(payload.value)) {
|
|
8643
|
+
payload.value.forEach(addValue);
|
|
8644
|
+
}
|
|
8645
|
+
if (isRecord3(payload.fields)) {
|
|
8646
|
+
Object.values(payload.fields).forEach((bundle) => {
|
|
8647
|
+
if (isRecord3(bundle)) {
|
|
8648
|
+
addValue(bundle.value);
|
|
8649
|
+
}
|
|
8650
|
+
});
|
|
8651
|
+
}
|
|
8652
|
+
if (isRecord3(payload.preserve) && Array.isArray(payload.preserve.value)) {
|
|
8653
|
+
payload.preserve.value.forEach(addValue);
|
|
8654
|
+
}
|
|
8655
|
+
return required;
|
|
8656
|
+
}
|
|
8657
|
+
function formTemplateConditionFieldReferences(expression) {
|
|
8658
|
+
const fields = /* @__PURE__ */ new Set();
|
|
8659
|
+
const pattern = /\$(?:formField|formDisplayField)(?:\[['"]([^'"]+)['"]\]|\.([A-Za-z0-9_]+))/g;
|
|
8660
|
+
let match;
|
|
8661
|
+
while ((match = pattern.exec(expression)) !== null) {
|
|
8662
|
+
const field = match[1] || match[2];
|
|
8663
|
+
if (field) {
|
|
8664
|
+
fields.add(field);
|
|
8665
|
+
}
|
|
8666
|
+
}
|
|
8667
|
+
return Array.from(fields);
|
|
8668
|
+
}
|
|
8669
|
+
function isSupportedFormTemplateConditionVariable(expression) {
|
|
8670
|
+
return /^\$(?:MOMENT|userInfo|formField|formDisplayField|RANGE)(?:\b|\.|\[|\()/.test(expression.trim());
|
|
8671
|
+
}
|
|
8672
|
+
function formTemplateConditionConfigSignature(value) {
|
|
8673
|
+
if (!isRecord3(value) || !isRecord3(value.condition) || typeof value.action !== "boolean") {
|
|
8674
|
+
return null;
|
|
8675
|
+
}
|
|
8676
|
+
const canonicalize = (input) => {
|
|
8677
|
+
if (Array.isArray(input)) {
|
|
8678
|
+
return input.map(canonicalize);
|
|
8679
|
+
}
|
|
8680
|
+
if (!isRecord3(input)) {
|
|
8681
|
+
return input;
|
|
8682
|
+
}
|
|
8683
|
+
const normalized = Object.fromEntries(
|
|
8684
|
+
Object.keys(input).sort().map((key) => [key, canonicalize(input[key])])
|
|
8685
|
+
);
|
|
8686
|
+
if ((normalized.logic === "AND" || normalized.logic === "OR") && Array.isArray(normalized.conditions)) {
|
|
8687
|
+
normalized.conditions = [...normalized.conditions].sort(
|
|
8688
|
+
(left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right))
|
|
8689
|
+
);
|
|
8690
|
+
}
|
|
8691
|
+
return normalized;
|
|
8692
|
+
};
|
|
8693
|
+
return JSON.stringify(canonicalize({ condition: value.condition, action: value.action }));
|
|
8694
|
+
}
|
|
8695
|
+
function validateFormTemplateConditionVariable(expression, reference, side, pathName, knownFields, dependencies, errors) {
|
|
8696
|
+
if (typeof expression !== "string" || !expression.trim()) {
|
|
8697
|
+
errors.push(`[form.dynamic_condition.variable_required] ${pathName}.${side}Value \u5FC5\u987B\u662F\u975E\u7A7A\u53D8\u91CF\u8868\u8FBE\u5F0F\u3002`);
|
|
8698
|
+
return;
|
|
8699
|
+
}
|
|
8700
|
+
if (!isSupportedFormTemplateConditionVariable(expression)) {
|
|
8701
|
+
errors.push(`[form.dynamic_condition.variable_root] ${pathName}.${side}Value \u4F7F\u7528\u4E86\u4E0D\u652F\u6301\u7684\u53D8\u91CF\uFF1B\u4EC5\u5141\u8BB8 $MOMENT\u3001$userInfo\u3001$formField\u3001$formDisplayField\u3001$RANGE\u3002`);
|
|
8702
|
+
return;
|
|
8703
|
+
}
|
|
8704
|
+
const expressionFields = formTemplateConditionFieldReferences(expression);
|
|
8705
|
+
const needsFieldSubscription = expressionFields.length > 0;
|
|
8706
|
+
if (needsFieldSubscription && (typeof reference !== "string" || !reference.trim())) {
|
|
8707
|
+
errors.push(`[form.dynamic_condition.variable_ref_required] ${pathName}.${side}Value \u5F15\u7528\u4E86\u8868\u5355\u5B57\u6BB5\uFF0C\u5FC5\u987B\u540C\u65F6\u63D0\u4F9B ${side}ValueRef \u4EE5\u8BA2\u9605\u5B57\u6BB5\u53D8\u5316\u3002`);
|
|
8708
|
+
}
|
|
8709
|
+
if (reference !== void 0 && reference !== null) {
|
|
8710
|
+
if (typeof reference !== "string" || !reference.trim() || !isSupportedFormTemplateConditionVariable(reference)) {
|
|
8711
|
+
errors.push(`[form.dynamic_condition.variable_ref_invalid] ${pathName}.${side}ValueRef \u5FC5\u987B\u662F\u53D7\u652F\u6301\u7684\u53D8\u91CF\u5F15\u7528\u3002`);
|
|
8712
|
+
}
|
|
8713
|
+
}
|
|
8714
|
+
const referencedFields = /* @__PURE__ */ new Set([
|
|
8715
|
+
...expressionFields,
|
|
8716
|
+
...typeof reference === "string" ? formTemplateConditionFieldReferences(reference) : []
|
|
8717
|
+
]);
|
|
8718
|
+
for (const field of referencedFields) {
|
|
8719
|
+
if (!knownFields.has(field)) {
|
|
8720
|
+
errors.push(`[form.dynamic_condition.field_not_found] ${pathName}.${side}Value \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 ${field}\uFF1B\u8FD0\u884C\u65F6\u6309 rule.field \u53D6\u503C\uFF0C\u4E0D\u80FD\u4F7F\u7528\u4E1A\u52A1 key \u4EE3\u66FF\u3002`);
|
|
8721
|
+
} else {
|
|
8722
|
+
dependencies.add(field);
|
|
8723
|
+
}
|
|
8724
|
+
}
|
|
8725
|
+
}
|
|
8726
|
+
function validateFormTemplateConditionField(fieldValue, subField, side, pathName, knownFields, dependencies, errors) {
|
|
8727
|
+
if (typeof fieldValue !== "string" || !fieldValue.trim()) {
|
|
8728
|
+
errors.push(`[form.dynamic_condition.field_required] ${pathName}.${side}Value \u5FC5\u987B\u586B\u5199\u5B9E\u9645 rule.field\u3002`);
|
|
8729
|
+
return;
|
|
8730
|
+
}
|
|
8731
|
+
const field = fieldValue.trim();
|
|
8732
|
+
if (!knownFields.has(field)) {
|
|
8733
|
+
errors.push(`[form.dynamic_condition.field_not_found] ${pathName}.${side}Value \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5B57\u6BB5 ${field}\uFF1B\u8FD0\u884C\u65F6\u6309 rule.field \u53D6\u503C\uFF0C\u4E0D\u80FD\u4F7F\u7528\u4E1A\u52A1 key \u4EE3\u66FF\u3002`);
|
|
8734
|
+
} else {
|
|
8735
|
+
dependencies.add(field);
|
|
8736
|
+
}
|
|
8737
|
+
if (subField !== void 0 && subField !== null && (typeof subField !== "string" || !subField.trim())) {
|
|
8738
|
+
errors.push(`[form.dynamic_condition.subfield_invalid] ${pathName}.${side}SubField \u63D0\u4F9B\u65F6\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`);
|
|
8739
|
+
}
|
|
8740
|
+
}
|
|
8741
|
+
function validateFormTemplateConditionItem(item, pathName, knownFields, dependencies, errors) {
|
|
8742
|
+
const leftType = item.leftValueType;
|
|
8743
|
+
const rightType = item.rightValueType;
|
|
8744
|
+
const operator = item.operator;
|
|
8745
|
+
if (typeof leftType !== "string" || !FORM_TEMPLATE_CONDITION_LEFT_TYPES.has(leftType)) {
|
|
8746
|
+
errors.push(`[form.dynamic_condition.left_type] ${pathName}.leftValueType \u53EA\u80FD\u662F field \u6216 variable\u3002`);
|
|
8747
|
+
} else if (leftType === "field") {
|
|
8748
|
+
validateFormTemplateConditionField(item.leftValue, item.leftSubField, "left", pathName, knownFields, dependencies, errors);
|
|
8749
|
+
} else {
|
|
8750
|
+
validateFormTemplateConditionVariable(item.leftValue, item.leftValueRef, "left", pathName, knownFields, dependencies, errors);
|
|
8751
|
+
}
|
|
8752
|
+
if (Object.prototype.hasOwnProperty.call(item, "subField") && typeof item.subField === "string" && item.subField.trim()) {
|
|
8753
|
+
errors.push(`[form.dynamic_condition.legacy_subfield] ${pathName}.subField \u4E0D\u4F1A\u88AB\u5F53\u524D\u8868\u5355\u8FD0\u884C\u65F6\u8BFB\u53D6\uFF1B\u5DE6\u4FA7\u8BF7\u6539\u4E3A leftSubField\uFF0C\u53F3\u4FA7\u8BF7\u4F7F\u7528 rightSubField\u3002`);
|
|
8754
|
+
}
|
|
8755
|
+
if (typeof operator !== "string" || !FORM_TEMPLATE_CONDITION_OPERATORS.has(operator)) {
|
|
8756
|
+
errors.push(`[form.dynamic_condition.operator] ${pathName}.operator \u4E0D\u53D7\u652F\u6301\uFF1B\u5141\u8BB8 eq/ne/gt/gte/lt/lte/contains/isEmpty/isNotEmpty\u3002`);
|
|
8757
|
+
return;
|
|
8758
|
+
}
|
|
8759
|
+
if (FORM_TEMPLATE_CONDITION_UNARY_OPERATORS.has(operator)) {
|
|
8760
|
+
if (rightType !== void 0 && (typeof rightType !== "string" || !FORM_TEMPLATE_CONDITION_RIGHT_TYPES.has(rightType))) {
|
|
8761
|
+
errors.push(`[form.dynamic_condition.right_type] ${pathName}.rightValueType \u53EA\u80FD\u662F field\u3001variable \u6216 constant\u3002`);
|
|
8762
|
+
}
|
|
8763
|
+
return;
|
|
8764
|
+
}
|
|
8765
|
+
if (typeof rightType !== "string" || !FORM_TEMPLATE_CONDITION_RIGHT_TYPES.has(rightType)) {
|
|
8766
|
+
errors.push(`[form.dynamic_condition.right_type] ${pathName}.rightValueType \u53EA\u80FD\u662F field\u3001variable \u6216 constant\u3002`);
|
|
8767
|
+
return;
|
|
8768
|
+
}
|
|
8769
|
+
if (rightType === "field") {
|
|
8770
|
+
validateFormTemplateConditionField(item.rightValue, item.rightSubField, "right", pathName, knownFields, dependencies, errors);
|
|
8771
|
+
} else if (rightType === "variable") {
|
|
8772
|
+
validateFormTemplateConditionVariable(item.rightValue, item.rightValueRef, "right", pathName, knownFields, dependencies, errors);
|
|
8773
|
+
} else if (!Object.prototype.hasOwnProperty.call(item, "rightValue")) {
|
|
8774
|
+
errors.push(`[form.dynamic_condition.constant_required] ${pathName}.rightValueType=constant \u65F6\u5FC5\u987B\u663E\u5F0F\u63D0\u4F9B rightValue\u3002`);
|
|
8775
|
+
}
|
|
8776
|
+
}
|
|
8777
|
+
function validateFormTemplateConditionGroup(group, pathName, knownFields, dependencies, errors) {
|
|
8778
|
+
if (typeof group.logic !== "string" || !FORM_TEMPLATE_CONDITION_LOGICS.has(group.logic)) {
|
|
8779
|
+
errors.push(`[form.dynamic_condition.logic] ${pathName}.logic \u53EA\u80FD\u662F AND \u6216 OR\u3002`);
|
|
8780
|
+
}
|
|
8781
|
+
if (!Array.isArray(group.conditions) || group.conditions.length === 0) {
|
|
8782
|
+
errors.push(`[form.dynamic_condition.conditions_required] ${pathName}.conditions \u5FC5\u987B\u662F\u975E\u7A7A\u6570\u7EC4\u3002`);
|
|
8783
|
+
return;
|
|
8784
|
+
}
|
|
8785
|
+
group.conditions.forEach((condition, index) => {
|
|
8786
|
+
const itemPath = `${pathName}.conditions[${index}]`;
|
|
8787
|
+
if (!isRecord3(condition)) {
|
|
8788
|
+
errors.push(`[form.dynamic_condition.item_object] ${itemPath} \u5FC5\u987B\u662F\u6761\u4EF6\u5BF9\u8C61\u6216\u6761\u4EF6\u7EC4\u3002`);
|
|
8789
|
+
return;
|
|
8790
|
+
}
|
|
8791
|
+
if (Object.prototype.hasOwnProperty.call(condition, "logic") || Object.prototype.hasOwnProperty.call(condition, "conditions")) {
|
|
8792
|
+
validateFormTemplateConditionGroup(condition, itemPath, knownFields, dependencies, errors);
|
|
8793
|
+
} else {
|
|
8794
|
+
validateFormTemplateConditionItem(condition, itemPath, knownFields, dependencies, errors);
|
|
8795
|
+
}
|
|
8796
|
+
});
|
|
8797
|
+
}
|
|
8798
|
+
function validateFormTemplateDynamicStateConfig(entry, spec, knownFields, graph, errors, warnings) {
|
|
8799
|
+
const enabled = entry.rule[spec.enabledKey];
|
|
8800
|
+
const config = entry.rule[spec.configKey];
|
|
8801
|
+
if (enabled !== void 0 && typeof enabled !== "boolean") {
|
|
8802
|
+
errors.push(`[form.dynamic_condition.enabled_boolean] ${entry.path}.${spec.enabledKey} \u5FC5\u987B\u662F boolean\u3002`);
|
|
8803
|
+
return;
|
|
8804
|
+
}
|
|
8805
|
+
if (enabled !== true) {
|
|
8806
|
+
if (config !== void 0 && config !== null) {
|
|
8807
|
+
warnings.push(`[form.dynamic_condition.stale_config] ${entry.path}.${spec.configKey} \u5DF2\u4FDD\u7559\u4F46 ${spec.enabledKey} \u672A\u542F\u7528\uFF1B\u8BE5\u914D\u7F6E\u4E0D\u4F1A\u6267\u884C\u3002`);
|
|
8808
|
+
}
|
|
8809
|
+
return;
|
|
8810
|
+
}
|
|
8811
|
+
if (!isRecord3(config)) {
|
|
8812
|
+
errors.push(`[form.dynamic_condition.config_required] \u5B57\u6BB5 ${entry.field} \u5DF2\u542F\u7528${spec.label}\uFF0C\u5FC5\u987B\u63D0\u4F9B ${spec.configKey} \u5BF9\u8C61\u3002`);
|
|
8813
|
+
return;
|
|
8814
|
+
}
|
|
8815
|
+
if (typeof config.action !== "boolean") {
|
|
8816
|
+
errors.push(`[form.dynamic_condition.action_boolean] ${entry.path}.${spec.configKey}.action \u5FC5\u987B\u662F boolean\uFF1Btrue \u8868\u793A\u6761\u4EF6\u6210\u7ACB\u65F6\u6267\u884C\u201C${spec.label.replace("\u52A8\u6001", "")}\u201D\u52A8\u4F5C\u3002`);
|
|
8817
|
+
}
|
|
8818
|
+
if (!isRecord3(config.condition)) {
|
|
8819
|
+
errors.push(`[form.dynamic_condition.condition_required] ${entry.path}.${spec.configKey}.condition \u5FC5\u987B\u662F\u975E\u7A7A\u6761\u4EF6\u7EC4\u3002`);
|
|
8820
|
+
return;
|
|
8821
|
+
}
|
|
8822
|
+
if (!Object.prototype.hasOwnProperty.call(config.condition, "logic") && Object.prototype.hasOwnProperty.call(config.condition, "leftValueType")) {
|
|
8823
|
+
errors.push(`[form.dynamic_condition.legacy_single_item] ${entry.path}.${spec.configKey}.condition \u4ECD\u662F\u65E7\u7684\u5355\u6761\u4EF6\u5BF9\u8C61\uFF1B\u5F53\u524D\u8FD0\u884C\u65F6\u4F1A\u628A\u5B83\u5F53\u7A7A\u6761\u4EF6\uFF0C\u5FC5\u987B\u8FC1\u79FB\u4E3A { logic, conditions: [...] }\u3002`);
|
|
8824
|
+
return;
|
|
8825
|
+
}
|
|
8826
|
+
const dependencies = graph.get(entry.field) ?? /* @__PURE__ */ new Set();
|
|
8827
|
+
graph.set(entry.field, dependencies);
|
|
8828
|
+
validateFormTemplateConditionGroup(
|
|
8829
|
+
config.condition,
|
|
8830
|
+
`${entry.path}.${spec.configKey}.condition`,
|
|
8831
|
+
knownFields,
|
|
8832
|
+
dependencies,
|
|
8833
|
+
errors
|
|
8834
|
+
);
|
|
8835
|
+
}
|
|
8836
|
+
function validateFormTemplateDynamicConditionCycles(graph, errors) {
|
|
8837
|
+
const visited = /* @__PURE__ */ new Set();
|
|
8838
|
+
const active = /* @__PURE__ */ new Set();
|
|
8839
|
+
const stack = [];
|
|
8840
|
+
const reported = /* @__PURE__ */ new Set();
|
|
8841
|
+
const visit = (field) => {
|
|
8842
|
+
if (active.has(field)) {
|
|
8843
|
+
const start = stack.indexOf(field);
|
|
8844
|
+
const cycle = [...stack.slice(start), field];
|
|
8845
|
+
const signature = cycle.join(" -> ");
|
|
8846
|
+
if (!reported.has(signature)) {
|
|
8847
|
+
reported.add(signature);
|
|
8848
|
+
errors.push(`[form.dynamic_condition.cycle] \u52A8\u6001\u5B57\u6BB5\u72B6\u6001\u5B58\u5728\u5FAA\u73AF\u4F9D\u8D56\uFF1A${signature}\u3002`);
|
|
8849
|
+
}
|
|
8850
|
+
return;
|
|
8851
|
+
}
|
|
8852
|
+
if (visited.has(field)) {
|
|
8853
|
+
return;
|
|
8854
|
+
}
|
|
8855
|
+
visited.add(field);
|
|
8856
|
+
active.add(field);
|
|
8857
|
+
stack.push(field);
|
|
8858
|
+
for (const dependency of graph.get(field) ?? []) {
|
|
8859
|
+
if (graph.has(dependency)) {
|
|
8860
|
+
visit(dependency);
|
|
8861
|
+
} else if (dependency === field) {
|
|
8862
|
+
visit(dependency);
|
|
8863
|
+
}
|
|
8864
|
+
}
|
|
8865
|
+
stack.pop();
|
|
8866
|
+
active.delete(field);
|
|
8867
|
+
};
|
|
8868
|
+
for (const field of graph.keys()) {
|
|
8869
|
+
visit(field);
|
|
8870
|
+
}
|
|
8871
|
+
}
|
|
8872
|
+
function validateFormTemplateDynamicStateConflicts(entry, staticRequiredFields, errors) {
|
|
8873
|
+
const rule = entry.rule;
|
|
8874
|
+
const visibilityEnabled = rule.hasVisibilityCondition === true && isRecord3(rule.visibilityCondition);
|
|
8875
|
+
const disabledEnabled = rule.hasDisabledCondition === true && isRecord3(rule.disabledCondition);
|
|
8876
|
+
const requiredEnabled = rule.hasRequiredCondition === true && isRecord3(rule.requiredCondition);
|
|
8877
|
+
const props = isRecord3(rule.props) ? rule.props : {};
|
|
8878
|
+
const permanentlyHidden = (rule.hidden === true || rule.display === false) && !visibilityEnabled;
|
|
8879
|
+
const permanentlyDisabled = (rule.disabled === true || props.disabled === true) && !disabledEnabled;
|
|
8880
|
+
if (requiredEnabled && permanentlyHidden) {
|
|
8881
|
+
errors.push(`[form.dynamic_condition.required_hidden] \u5B57\u6BB5 ${entry.field} \u542F\u7528\u4E86\u52A8\u6001\u5FC5\u586B\uFF0C\u4F46\u5B57\u6BB5\u88AB\u9759\u6001\u9690\u85CF\u4E14\u6CA1\u6709\u52A8\u6001\u663E\u9690\u6062\u590D\u8DEF\u5F84\u3002`);
|
|
8882
|
+
}
|
|
8883
|
+
if (requiredEnabled && permanentlyDisabled) {
|
|
8884
|
+
errors.push(`[form.dynamic_condition.required_disabled] \u5B57\u6BB5 ${entry.field} \u542F\u7528\u4E86\u52A8\u6001\u5FC5\u586B\uFF0C\u4F46\u5B57\u6BB5\u88AB\u9759\u6001\u7981\u7528\u4E14\u6CA1\u6709\u52A8\u6001\u53EA\u8BFB\u6062\u590D\u8DEF\u5F84\u3002`);
|
|
8885
|
+
}
|
|
8886
|
+
if (requiredEnabled) {
|
|
8887
|
+
const requiredSignature = formTemplateConditionConfigSignature(rule.requiredCondition);
|
|
8888
|
+
const visibilitySignature = visibilityEnabled ? formTemplateConditionConfigSignature(rule.visibilityCondition) : null;
|
|
8889
|
+
const disabledSignature = disabledEnabled ? formTemplateConditionConfigSignature(rule.disabledCondition) : null;
|
|
8890
|
+
if (requiredSignature && requiredSignature === visibilitySignature) {
|
|
8891
|
+
errors.push(`[form.dynamic_condition.required_visibility_conflict] \u5B57\u6BB5 ${entry.field} \u5728\u540C\u4E00\u6761\u4EF6\u5206\u652F\u540C\u65F6\u201C\u9690\u85CF\u201D\u548C\u201C\u5FC5\u586B\u201D\uFF1B\u8BF7\u8BA9\u663E\u9690\u6761\u4EF6\u4E0E\u5FC5\u586B\u6761\u4EF6\u4E92\u65A5\u3002`);
|
|
8892
|
+
}
|
|
8893
|
+
if (requiredSignature && requiredSignature === disabledSignature) {
|
|
8894
|
+
errors.push(`[form.dynamic_condition.required_disabled_conflict] \u5B57\u6BB5 ${entry.field} \u5728\u540C\u4E00\u6761\u4EF6\u5206\u652F\u540C\u65F6\u201C\u7981\u7528\u201D\u548C\u201C\u5FC5\u586B\u201D\uFF1B\u8BF7\u8BA9\u53EA\u8BFB\u6761\u4EF6\u4E0E\u5FC5\u586B\u6761\u4EF6\u4E92\u65A5\u3002`);
|
|
8895
|
+
}
|
|
8896
|
+
}
|
|
8897
|
+
if (staticRequiredFields.has(entry.field) && (visibilityEnabled || disabledEnabled) && !requiredEnabled) {
|
|
8898
|
+
errors.push(`[form.dynamic_condition.static_required_conflict] \u5B57\u6BB5 ${entry.field} \u662F\u9759\u6001\u5FC5\u586B\uFF0C\u4F46\u53C8\u53EF\u80FD\u88AB\u52A8\u6001\u9690\u85CF\u6216\u7981\u7528\uFF1B\u5FC5\u987B\u589E\u52A0\u4E92\u65A5\u7684 requiredCondition\uFF0C\u4E0D\u80FD\u4FDD\u7559\u6C38\u4E45\u5FC5\u586B\u3002`);
|
|
8899
|
+
}
|
|
8900
|
+
const type = typeof rule.type === "string" ? rule.type : "";
|
|
8901
|
+
if (requiredEnabled && FORM_TEMPLATE_DYNAMIC_REQUIRED_UNSUPPORTED_TYPES.has(type)) {
|
|
8902
|
+
errors.push(`[form.dynamic_condition.required_control_type] \u5B57\u6BB5 ${entry.field} type=${type} \u662F\u5C55\u793A/\u547D\u4EE4\u63A7\u4EF6\uFF0C\u4E0D\u80FD\u914D\u7F6E\u52A8\u6001\u5FC5\u586B\u3002`);
|
|
8903
|
+
}
|
|
8904
|
+
}
|
|
8905
|
+
function validateFormTemplateDynamicFieldStates(payload, errors, warnings) {
|
|
8906
|
+
const entries = collectFormTemplateRuleEntries(payload);
|
|
8907
|
+
if (!entries.length) {
|
|
8908
|
+
return;
|
|
8909
|
+
}
|
|
8910
|
+
const knownFields = new Set(entries.map((entry) => entry.field));
|
|
8911
|
+
const graph = /* @__PURE__ */ new Map();
|
|
8912
|
+
const staticRequiredFields = formTemplateStaticRequiredFields(payload);
|
|
8913
|
+
for (const entry of entries) {
|
|
8914
|
+
for (const spec of FORM_TEMPLATE_DYNAMIC_STATE_SPECS) {
|
|
8915
|
+
validateFormTemplateDynamicStateConfig(entry, spec, knownFields, graph, errors, warnings);
|
|
8916
|
+
}
|
|
8917
|
+
validateFormTemplateDynamicStateConflicts(entry, staticRequiredFields, errors);
|
|
8918
|
+
}
|
|
8919
|
+
validateFormTemplateDynamicConditionCycles(graph, errors);
|
|
8920
|
+
}
|
|
8921
|
+
function validateFormTemplateFieldIdentifiers(payload, errors) {
|
|
8922
|
+
for (const entry of collectFormTemplateRuleEntries(payload)) {
|
|
8923
|
+
if (entry.field.length > MAX_FORM_TEMPLATE_FIELD_LENGTH) {
|
|
8924
|
+
errors.push(
|
|
8925
|
+
`[form.field.max_length] ${entry.path}.field \u957F\u5EA6\u4E3A ${entry.field.length}\uFF0C\u8D85\u8FC7\u5E73\u53F0 think_form_rule.field \u4E0A\u9650 ${MAX_FORM_TEMPLATE_FIELD_LENGTH}\uFF1B\u8BF7\u7F29\u77ED\u5B57\u6BB5\u6807\u8BC6\uFF0C\u4E1A\u52A1\u8BED\u4E49\u653E\u5728 key/title\u3002`
|
|
8926
|
+
);
|
|
8927
|
+
}
|
|
8928
|
+
}
|
|
8929
|
+
}
|
|
8930
|
+
function validateFormTemplateWorkLint(payload, errors, warnings = [], mode = payload.mode === "create" ? "create" : "edit") {
|
|
8532
8931
|
validateFormTemplateNameLength(payload, errors);
|
|
8932
|
+
validateFormTemplateFieldIdentifiers(payload, errors);
|
|
8533
8933
|
validateFormTemplateValueValidateMaps(payload, errors);
|
|
8534
8934
|
validateStructuredFormTemplateFieldTypes(payload, errors);
|
|
8535
|
-
validateFormTemplateControlContracts(payload, errors);
|
|
8935
|
+
validateFormTemplateControlContracts(payload, errors, warnings, mode);
|
|
8536
8936
|
validateFormTemplateHeaderContract(payload, errors);
|
|
8537
8937
|
validateStructuredFormTemplateVisualReview(payload, errors);
|
|
8938
|
+
validateFormTemplateDynamicFieldStates(payload, errors, warnings);
|
|
8538
8939
|
}
|
|
8539
8940
|
function stripFormTemplateCreateIds(payload) {
|
|
8540
8941
|
const next = { ...payload };
|
|
@@ -11628,6 +12029,7 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
11628
12029
|
throw new Error("Config build requires a meta file produced by `bpmax-cli config <domain> export`.");
|
|
11629
12030
|
}
|
|
11630
12031
|
const raw = typeof meta.raw_file === "string" ? await readJsonFile(meta.raw_file) : void 0;
|
|
12032
|
+
let formTemplateWarnings = [];
|
|
11631
12033
|
let stepDetailReferenceAudit;
|
|
11632
12034
|
let stepDetailAnalysis;
|
|
11633
12035
|
if (domain === "flow-template" && isRecord3(work)) {
|
|
@@ -11644,7 +12046,8 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
11644
12046
|
}
|
|
11645
12047
|
if (domain === "form-template" && isRecord3(work)) {
|
|
11646
12048
|
const errors = [];
|
|
11647
|
-
|
|
12049
|
+
formTemplateWarnings = [];
|
|
12050
|
+
validateFormTemplateWorkLint(work, errors, formTemplateWarnings, createMode ? "create" : "edit");
|
|
11648
12051
|
if (errors.length) {
|
|
11649
12052
|
throw new Error(`form-template lint failed: ${errors.join("; ")}`);
|
|
11650
12053
|
}
|
|
@@ -11684,6 +12087,7 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
11684
12087
|
meta: submitMeta,
|
|
11685
12088
|
base_hash: createMode ? null : typeof meta.base_hash === "string" ? meta.base_hash : null,
|
|
11686
12089
|
payload,
|
|
12090
|
+
...formTemplateWarnings.length ? { form_template_warnings: formTemplateWarnings } : {},
|
|
11687
12091
|
...stepDetailReferenceAudit ? {
|
|
11688
12092
|
step_detail_references: stepDetailReferenceAudit.references,
|
|
11689
12093
|
step_detail_warnings: stepDetailReferenceAudit.warnings,
|
|
@@ -11702,6 +12106,7 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
11702
12106
|
work_file: workFile,
|
|
11703
12107
|
submit_file: outFile,
|
|
11704
12108
|
payload_keys: Object.keys(payload),
|
|
12109
|
+
...formTemplateWarnings.length ? { warnings: formTemplateWarnings } : {},
|
|
11705
12110
|
...stepDetailReferenceAudit ? {
|
|
11706
12111
|
step_detail_references: stepDetailReferenceAudit.references,
|
|
11707
12112
|
warnings: stepDetailReferenceAudit.warnings,
|
|
@@ -11836,7 +12241,8 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
11836
12241
|
}
|
|
11837
12242
|
const shouldLintFormTemplate = options.domain ? options.domain === "form-template" : looksLikeFormTemplateWork(value);
|
|
11838
12243
|
if (shouldLintFormTemplate) {
|
|
11839
|
-
|
|
12244
|
+
const formMode = options.mode ?? (value.mode === "create" ? "create" : "edit");
|
|
12245
|
+
validateFormTemplateWorkLint(value, errors, warnings, formMode);
|
|
11840
12246
|
}
|
|
11841
12247
|
if (options.domain === "filter-template") {
|
|
11842
12248
|
lintFilterTemplateWork(value, errors);
|
|
@@ -24379,10 +24785,14 @@ var UPDATE_STATE_FILE = "update-state.json";
|
|
|
24379
24785
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
24380
24786
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
24381
24787
|
var NPM_INSTALL_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
24382
|
-
function
|
|
24788
|
+
function updateChannelForVersion(version) {
|
|
24789
|
+
const prerelease = version.trim().replace(/^v/, "").split("+", 1)[0].split("-", 2)[1] || "";
|
|
24790
|
+
return prerelease.split(".", 1)[0].toLowerCase() === "beta" ? "beta" : "latest";
|
|
24791
|
+
}
|
|
24792
|
+
function buildRegistryUrl(packageName = NPM_PACKAGE, env = process.env, distTag = "latest") {
|
|
24383
24793
|
const base = env.BPMAX_CLI_REGISTRY_URL || DEFAULT_REGISTRY_URL;
|
|
24384
24794
|
const normalizedBase = base.endsWith("/") ? base : `${base}/`;
|
|
24385
|
-
return new URL(`${encodeURIComponent(packageName).replace("%40", "@")}
|
|
24795
|
+
return new URL(`${encodeURIComponent(packageName).replace("%40", "@")}/${distTag}`, normalizedBase).toString();
|
|
24386
24796
|
}
|
|
24387
24797
|
function parseVersion(version) {
|
|
24388
24798
|
const clean = version.trim().replace(/^v/, "").split("+")[0];
|
|
@@ -24469,7 +24879,7 @@ async function fetchLatestVersion(options = {}) {
|
|
|
24469
24879
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
24470
24880
|
try {
|
|
24471
24881
|
const fetchImpl = options.fetchImpl || fetch;
|
|
24472
|
-
const response = await fetchImpl(buildRegistryUrl(options.packageName, options.env), {
|
|
24882
|
+
const response = await fetchImpl(buildRegistryUrl(options.packageName, options.env, options.distTag), {
|
|
24473
24883
|
signal: controller.signal
|
|
24474
24884
|
});
|
|
24475
24885
|
if (!response.ok) {
|
|
@@ -24494,7 +24904,11 @@ async function readUpdateState(configDir) {
|
|
|
24494
24904
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
24495
24905
|
return null;
|
|
24496
24906
|
}
|
|
24497
|
-
return {
|
|
24907
|
+
return {
|
|
24908
|
+
latest_version: parsed.latest_version,
|
|
24909
|
+
checked_at: parsed.checked_at,
|
|
24910
|
+
channel: parsed.channel === "beta" ? "beta" : "latest"
|
|
24911
|
+
};
|
|
24498
24912
|
} catch {
|
|
24499
24913
|
return null;
|
|
24500
24914
|
}
|
|
@@ -24511,6 +24925,10 @@ async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
|
24511
24925
|
if (!state) {
|
|
24512
24926
|
return null;
|
|
24513
24927
|
}
|
|
24928
|
+
const channel = updateChannelForVersion(currentVersion);
|
|
24929
|
+
if (state.channel !== channel) {
|
|
24930
|
+
return null;
|
|
24931
|
+
}
|
|
24514
24932
|
const checkedAtMs = state.checked_at * 1e3;
|
|
24515
24933
|
if (Date.now() - checkedAtMs > CACHE_TTL_MS) {
|
|
24516
24934
|
return null;
|
|
@@ -24518,19 +24936,24 @@ async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
|
24518
24936
|
if (!isNewerVersion(state.latest_version, currentVersion)) {
|
|
24519
24937
|
return null;
|
|
24520
24938
|
}
|
|
24521
|
-
return { current: currentVersion, latest: state.latest_version };
|
|
24939
|
+
return { current: currentVersion, latest: state.latest_version, channel };
|
|
24522
24940
|
}
|
|
24523
24941
|
async function refreshUpdateCache(currentVersion, configDir = getConfigDir(), options = {}) {
|
|
24524
24942
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
24525
24943
|
return null;
|
|
24526
24944
|
}
|
|
24945
|
+
const channel = updateChannelForVersion(currentVersion);
|
|
24527
24946
|
const state = await readUpdateState(configDir);
|
|
24528
|
-
if (state && Date.now() - state.checked_at * 1e3 < CACHE_TTL_MS) {
|
|
24529
|
-
return isNewerVersion(state.latest_version, currentVersion) ? { current: currentVersion, latest: state.latest_version } : null;
|
|
24947
|
+
if (state && state.channel === channel && Date.now() - state.checked_at * 1e3 < CACHE_TTL_MS) {
|
|
24948
|
+
return isNewerVersion(state.latest_version, currentVersion) ? { current: currentVersion, latest: state.latest_version, channel } : null;
|
|
24530
24949
|
}
|
|
24531
|
-
const latest = await fetchLatestVersion(options);
|
|
24532
|
-
await writeUpdateState({
|
|
24533
|
-
|
|
24950
|
+
const latest = await fetchLatestVersion({ ...options, distTag: options.distTag || channel });
|
|
24951
|
+
await writeUpdateState({
|
|
24952
|
+
latest_version: latest,
|
|
24953
|
+
checked_at: Math.floor(Date.now() / 1e3),
|
|
24954
|
+
channel
|
|
24955
|
+
}, configDir);
|
|
24956
|
+
return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest, channel } : null;
|
|
24534
24957
|
}
|
|
24535
24958
|
async function executablePath() {
|
|
24536
24959
|
const candidate = process.argv[1] || "";
|
|
@@ -24601,7 +25024,8 @@ function skillsAction(result) {
|
|
|
24601
25024
|
};
|
|
24602
25025
|
}
|
|
24603
25026
|
function registerUpdateCommands(program2, deps = {}) {
|
|
24604
|
-
const
|
|
25027
|
+
const channel = updateChannelForVersion(VERSION);
|
|
25028
|
+
const fetchLatest = deps.fetchLatest || (() => fetchLatestVersion({ packageName: NPM_PACKAGE, distTag: channel }));
|
|
24605
25029
|
const detectInstall = deps.detectInstall || detectCurrentInstallMethod;
|
|
24606
25030
|
const install = deps.install || ((version) => runNpmInstall(version, { packageName: NPM_PACKAGE }));
|
|
24607
25031
|
const runSkills = deps.syncSkills || ((version, options) => syncSkills(version, options));
|
|
@@ -24628,6 +25052,7 @@ function registerUpdateCommands(program2, deps = {}) {
|
|
|
24628
25052
|
previous_version: VERSION,
|
|
24629
25053
|
current_version: VERSION,
|
|
24630
25054
|
latest_version: latest,
|
|
25055
|
+
channel,
|
|
24631
25056
|
action: updateAvailable ? "update_available" : "already_up_to_date",
|
|
24632
25057
|
auto_update: detect.method === "npm" && detect.npmAvailable,
|
|
24633
25058
|
skills_status: {
|
|
@@ -24653,6 +25078,7 @@ function registerUpdateCommands(program2, deps = {}) {
|
|
|
24653
25078
|
previous_version: VERSION,
|
|
24654
25079
|
current_version: VERSION,
|
|
24655
25080
|
latest_version: latest,
|
|
25081
|
+
channel,
|
|
24656
25082
|
action: "already_up_to_date",
|
|
24657
25083
|
...skillsAction(synced2)
|
|
24658
25084
|
};
|
|
@@ -24675,6 +25101,7 @@ function registerUpdateCommands(program2, deps = {}) {
|
|
|
24675
25101
|
previous_version: VERSION,
|
|
24676
25102
|
current_version: VERSION,
|
|
24677
25103
|
latest_version: latest,
|
|
25104
|
+
channel,
|
|
24678
25105
|
action: "manual_required",
|
|
24679
25106
|
message: `Automatic update unavailable: ${manualReason(detect)} (path: ${detect.resolvedPath})`,
|
|
24680
25107
|
manual_command: `npm install -g ${NPM_PACKAGE}@${latest}`,
|
|
@@ -24715,6 +25142,7 @@ ${detail}` : ""}`);
|
|
|
24715
25142
|
previous_version: VERSION,
|
|
24716
25143
|
current_version: latest,
|
|
24717
25144
|
latest_version: latest,
|
|
25145
|
+
channel,
|
|
24718
25146
|
action: "updated",
|
|
24719
25147
|
...skillsAction(synced)
|
|
24720
25148
|
};
|
|
@@ -24905,13 +25333,13 @@ var pendingUpdate = null;
|
|
|
24905
25333
|
var pendingSkills = null;
|
|
24906
25334
|
var pendingSetup = null;
|
|
24907
25335
|
function updateMessage(info) {
|
|
24908
|
-
return
|
|
25336
|
+
return `\u68C0\u6D4B\u5230 bpmax-cli \u65B0\u7248\u672C ${info.latest}\uFF0C\u5F53\u524D\u7248\u672C ${info.current}\uFF0C\u8BF7\u6267\u884C\uFF1Abpmax-cli update --json`;
|
|
24909
25337
|
}
|
|
24910
25338
|
function skillsMessage(info) {
|
|
24911
25339
|
if (!info.current) {
|
|
24912
|
-
return "bpmax-cli
|
|
25340
|
+
return "\u5C1A\u672A\u5B89\u88C5\u4E0E\u5F53\u524D bpmax-cli \u5339\u914D\u7684 Skills\uFF0C\u8BF7\u6267\u884C\uFF1Abpmax-cli update --json";
|
|
24913
25341
|
}
|
|
24914
|
-
return `bpmax-cli
|
|
25342
|
+
return `bpmax-cli Skills \u7248\u672C ${info.current} \u4E0E CLI ${info.target} \u4E0D\u4E00\u81F4\uFF0C\u8BF7\u6267\u884C\uFF1Abpmax-cli update --json`;
|
|
24915
25343
|
}
|
|
24916
25344
|
function setupMessage() {
|
|
24917
25345
|
return [
|
|
@@ -24930,6 +25358,13 @@ function shouldWriteSetupNotice(argv) {
|
|
|
24930
25358
|
}
|
|
24931
25359
|
return args.includes("--version") || args.includes("-V");
|
|
24932
25360
|
}
|
|
25361
|
+
function shouldWriteImmediateVersionNotice(argv) {
|
|
25362
|
+
const args = argv.slice(2);
|
|
25363
|
+
if (args.length === 0) {
|
|
25364
|
+
return true;
|
|
25365
|
+
}
|
|
25366
|
+
return args.some((arg) => ["--version", "-V", "--help", "-h"].includes(arg));
|
|
25367
|
+
}
|
|
24933
25368
|
async function setupNotices(argv = process.argv) {
|
|
24934
25369
|
pendingUpdate = await checkCachedUpdate(VERSION);
|
|
24935
25370
|
const skills = await checkSkillsSync(VERSION);
|
|
@@ -24950,6 +25385,8 @@ async function setupNotices(argv = process.argv) {
|
|
|
24950
25385
|
notice.update = {
|
|
24951
25386
|
current: pendingUpdate.current,
|
|
24952
25387
|
latest: pendingUpdate.latest,
|
|
25388
|
+
channel: pendingUpdate.channel,
|
|
25389
|
+
next_command: "bpmax-cli update --json",
|
|
24953
25390
|
message: updateMessage(pendingUpdate)
|
|
24954
25391
|
};
|
|
24955
25392
|
}
|
|
@@ -24957,17 +25394,26 @@ async function setupNotices(argv = process.argv) {
|
|
|
24957
25394
|
notice.skills = {
|
|
24958
25395
|
current: pendingSkills.current,
|
|
24959
25396
|
target: pendingSkills.target,
|
|
25397
|
+
next_command: "bpmax-cli update --json",
|
|
24960
25398
|
message: skillsMessage(pendingSkills)
|
|
24961
25399
|
};
|
|
24962
25400
|
}
|
|
24963
25401
|
return Object.keys(notice).length > 0 ? notice : null;
|
|
24964
25402
|
});
|
|
24965
|
-
|
|
24966
|
-
|
|
24967
|
-
pendingUpdate =
|
|
25403
|
+
if (!pendingUpdate) {
|
|
25404
|
+
try {
|
|
25405
|
+
pendingUpdate = await refreshUpdateCache(VERSION);
|
|
25406
|
+
} catch {
|
|
24968
25407
|
}
|
|
24969
|
-
}
|
|
24970
|
-
|
|
25408
|
+
}
|
|
25409
|
+
if (shouldWriteImmediateVersionNotice(argv)) {
|
|
25410
|
+
if (pendingUpdate) {
|
|
25411
|
+
console.error(updateMessage(pendingUpdate));
|
|
25412
|
+
}
|
|
25413
|
+
if (pendingSkills) {
|
|
25414
|
+
console.error(skillsMessage(pendingSkills));
|
|
25415
|
+
}
|
|
25416
|
+
}
|
|
24971
25417
|
}
|
|
24972
25418
|
|
|
24973
25419
|
// src/bin.ts
|
|
@@ -25063,7 +25509,7 @@ function printCommandError(error) {
|
|
|
25063
25509
|
const message = error instanceof Error ? error.message : String(error);
|
|
25064
25510
|
const structured = error && typeof error === "object" ? error : {};
|
|
25065
25511
|
if (formatFromArgv(process.argv) === "json") {
|
|
25066
|
-
console.log(JSON.stringify({
|
|
25512
|
+
console.log(JSON.stringify(withJsonNotice({
|
|
25067
25513
|
ok: false,
|
|
25068
25514
|
error: message,
|
|
25069
25515
|
...typeof structured.code === "string" ? { code: structured.code } : {},
|
|
@@ -25085,9 +25531,10 @@ function printCommandError(error) {
|
|
|
25085
25531
|
...typeof structured.env === "string" ? { env: structured.env } : {},
|
|
25086
25532
|
...commandDomainFromArgv(process.argv) ? { domain: commandDomainFromArgv(process.argv) } : {},
|
|
25087
25533
|
...commandEndpointHint(process.argv) ? { endpoint: commandEndpointHint(process.argv) } : {}
|
|
25088
|
-
}, null, 2));
|
|
25534
|
+
}), null, 2));
|
|
25089
25535
|
return;
|
|
25090
25536
|
}
|
|
25537
|
+
emitTextNotice();
|
|
25091
25538
|
console.error(message);
|
|
25092
25539
|
}
|
|
25093
25540
|
function commanderExitCode(error) {
|