bpmax-cli 0.1.19 → 0.1.21
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 +4 -2
- package/dist/bin.js +176 -31
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-project/SKILL.md +8 -5
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 --
|
|
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.
|
|
815
|
+
version: "0.1.21",
|
|
816
816
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
817
817
|
type: "module",
|
|
818
818
|
bin: {
|
|
@@ -1516,11 +1516,103 @@ async function promptProjectCreateForm(input) {
|
|
|
1516
1516
|
};
|
|
1517
1517
|
}
|
|
1518
1518
|
|
|
1519
|
+
// src/core/project-form.ts
|
|
1520
|
+
function isRecord3(value) {
|
|
1521
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1522
|
+
}
|
|
1523
|
+
function clone(value) {
|
|
1524
|
+
return JSON.parse(JSON.stringify(value));
|
|
1525
|
+
}
|
|
1526
|
+
function getFlowFormTemplateId(flowDetail) {
|
|
1527
|
+
const data = isRecord3(flowDetail?.data) ? flowDetail.data : void 0;
|
|
1528
|
+
const meta = isRecord3(data?.meta) ? data.meta : void 0;
|
|
1529
|
+
const templateId = meta?.form_template;
|
|
1530
|
+
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
1531
|
+
return templateId;
|
|
1532
|
+
}
|
|
1533
|
+
if (typeof templateId === "string" && templateId.trim()) {
|
|
1534
|
+
const parsed = Number(templateId);
|
|
1535
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
1536
|
+
}
|
|
1537
|
+
return void 0;
|
|
1538
|
+
}
|
|
1539
|
+
async function fetchProjectFormTemplate(client, flowDetail) {
|
|
1540
|
+
const templateId = getFlowFormTemplateId(flowDetail);
|
|
1541
|
+
if (!templateId) {
|
|
1542
|
+
return void 0;
|
|
1543
|
+
}
|
|
1544
|
+
const template = await apiRequest(client, "GET", `/form_template/${templateId}`);
|
|
1545
|
+
return { templateId, template };
|
|
1546
|
+
}
|
|
1547
|
+
function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1548
|
+
if (Array.isArray(value)) {
|
|
1549
|
+
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
1550
|
+
}
|
|
1551
|
+
if (!isRecord3(value)) {
|
|
1552
|
+
return false;
|
|
1553
|
+
}
|
|
1554
|
+
if (seen.has(value)) {
|
|
1555
|
+
return false;
|
|
1556
|
+
}
|
|
1557
|
+
seen.add(value);
|
|
1558
|
+
if (value.lambdaInit === true && typeof value.lambda === "string" && value.lambda.trim().length > 0) {
|
|
1559
|
+
return true;
|
|
1560
|
+
}
|
|
1561
|
+
return Object.values(value).some((item) => hasAutoInitLambda(item, seen));
|
|
1562
|
+
}
|
|
1563
|
+
function setControlValue(control, value) {
|
|
1564
|
+
const next = clone(control);
|
|
1565
|
+
next.value = {
|
|
1566
|
+
...isRecord3(next.value) ? next.value : {},
|
|
1567
|
+
type: next.value?.type ?? next.field_type,
|
|
1568
|
+
value
|
|
1569
|
+
};
|
|
1570
|
+
return next;
|
|
1571
|
+
}
|
|
1572
|
+
function applyRowValues(rowTemplate, rowValue) {
|
|
1573
|
+
const source = isRecord3(rowValue) ? rowValue : {};
|
|
1574
|
+
return rowTemplate.map((control) => {
|
|
1575
|
+
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
1576
|
+
return setControlValue(control, source[control.key]);
|
|
1577
|
+
}
|
|
1578
|
+
return clone(control);
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
function buildProjectFormValue(template, form) {
|
|
1582
|
+
const values = Array.isArray(template.value) ? template.value : [];
|
|
1583
|
+
return values.map((control) => {
|
|
1584
|
+
const key = control.key;
|
|
1585
|
+
if (!key || !Object.prototype.hasOwnProperty.call(form, key)) {
|
|
1586
|
+
return clone(control);
|
|
1587
|
+
}
|
|
1588
|
+
const inputValue = form[key];
|
|
1589
|
+
if (control.field_type === "sub_form") {
|
|
1590
|
+
const subFormRows = control.value?.value;
|
|
1591
|
+
const rowTemplate = Array.isArray(subFormRows) && Array.isArray(subFormRows[0]) ? subFormRows[0] : [];
|
|
1592
|
+
const rows = Array.isArray(inputValue) ? inputValue.map((row) => applyRowValues(rowTemplate, row)) : [];
|
|
1593
|
+
return setControlValue(control, rows);
|
|
1594
|
+
}
|
|
1595
|
+
return setControlValue(control, inputValue);
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
async function buildProjectFormPayload(client, flowDetail, form, knownTemplate) {
|
|
1599
|
+
const templateResult = knownTemplate ?? await fetchProjectFormTemplate(client, flowDetail);
|
|
1600
|
+
if (!templateResult) {
|
|
1601
|
+
return {};
|
|
1602
|
+
}
|
|
1603
|
+
return {
|
|
1604
|
+
projectForm: {
|
|
1605
|
+
template_id: templateResult.templateId,
|
|
1606
|
+
value: buildProjectFormValue(templateResult.template, form)
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1519
1611
|
// src/core/urls.ts
|
|
1520
1612
|
function stripSlashes(value) {
|
|
1521
1613
|
return value.trim().replace(/^\/+|\/+$/g, "");
|
|
1522
1614
|
}
|
|
1523
|
-
function
|
|
1615
|
+
function isRecord4(value) {
|
|
1524
1616
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1525
1617
|
}
|
|
1526
1618
|
function normalizeWorkspaceForUrl(workspace) {
|
|
@@ -1606,7 +1698,7 @@ function buildBpmaxUrl(profile, kind, params = {}) {
|
|
|
1606
1698
|
};
|
|
1607
1699
|
}
|
|
1608
1700
|
function extractProjectId(value) {
|
|
1609
|
-
if (!
|
|
1701
|
+
if (!isRecord4(value)) {
|
|
1610
1702
|
return void 0;
|
|
1611
1703
|
}
|
|
1612
1704
|
const candidates = [value.id, value.project_id, value.projectId];
|
|
@@ -1618,7 +1710,7 @@ function extractProjectId(value) {
|
|
|
1618
1710
|
return /^\d+$/.test(projectId) ? projectId : void 0;
|
|
1619
1711
|
}
|
|
1620
1712
|
function attachProjectDetailUrl(profile, value) {
|
|
1621
|
-
if (!
|
|
1713
|
+
if (!isRecord4(value) || typeof value.url === "string") {
|
|
1622
1714
|
return value;
|
|
1623
1715
|
}
|
|
1624
1716
|
const projectId = extractProjectId(value);
|
|
@@ -1683,6 +1775,19 @@ async function validateCreateForm(client, options) {
|
|
|
1683
1775
|
flowDetail = flows[0];
|
|
1684
1776
|
}
|
|
1685
1777
|
const fields = extractFormFields(flowDetail);
|
|
1778
|
+
if (fields.length === 0) {
|
|
1779
|
+
const templateId = getFlowFormTemplateId(flowDetail);
|
|
1780
|
+
if (templateId) {
|
|
1781
|
+
const template = await apiRequest(client, "GET", `/form_template/${templateId}`);
|
|
1782
|
+
const templateFields = extractFormFields(template);
|
|
1783
|
+
const result2 = validateFormAgainstFields(options.form, templateFields);
|
|
1784
|
+
if (result2.errors.length > 0) {
|
|
1785
|
+
throw new Error(`Form validation failed:
|
|
1786
|
+
- ${result2.errors.join("\n- ")}`);
|
|
1787
|
+
}
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1686
1791
|
if (fields.length === 0) {
|
|
1687
1792
|
throw new Error(
|
|
1688
1793
|
[
|
|
@@ -1697,6 +1802,24 @@ async function validateCreateForm(client, options) {
|
|
|
1697
1802
|
- ${result.errors.join("\n- ")}`);
|
|
1698
1803
|
}
|
|
1699
1804
|
}
|
|
1805
|
+
function printCreateFormHandoff(format, profile, flowIdentifiers, options) {
|
|
1806
|
+
const url = buildBpmaxUrl(profile, "project-create", {
|
|
1807
|
+
flowType: flowIdentifiers.flow_type,
|
|
1808
|
+
flowKey: flowIdentifiers.flow_key,
|
|
1809
|
+
initValue: {
|
|
1810
|
+
project: { name: options.name },
|
|
1811
|
+
key_to_value: options.form
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
printResult(format, {
|
|
1815
|
+
handoff: true,
|
|
1816
|
+
...options.reason ? { reason: options.reason } : {},
|
|
1817
|
+
url: url.url,
|
|
1818
|
+
pc_url: url.pc_url,
|
|
1819
|
+
mobile_path: url.mobile_path,
|
|
1820
|
+
message: options.message
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1700
1823
|
function registerProjectCommands(program2) {
|
|
1701
1824
|
const project = program2.command("project").description("Project commands");
|
|
1702
1825
|
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) => {
|
|
@@ -1757,13 +1880,15 @@ function registerProjectCommands(program2) {
|
|
|
1757
1880
|
);
|
|
1758
1881
|
printResult(options.format, result);
|
|
1759
1882
|
});
|
|
1760
|
-
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) => {
|
|
1761
|
-
|
|
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("--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) => {
|
|
1884
|
+
const interactiveSource = command.getOptionValueSource("interactive");
|
|
1885
|
+
if (options.body && options.interactive === true && interactiveSource === "cli") {
|
|
1762
1886
|
throw new Error("--body and --interactive cannot be used together.");
|
|
1763
1887
|
}
|
|
1764
1888
|
const config = await loadConfig();
|
|
1765
1889
|
const profile = resolveProfile(config, options.profile);
|
|
1766
1890
|
const client = createApiClient(profile);
|
|
1891
|
+
const useInteractive = !options.body && options.interactive !== false;
|
|
1767
1892
|
let payload = parseJson2(options.body);
|
|
1768
1893
|
if (!options.body) {
|
|
1769
1894
|
const flow = await resolveFlowIdentifiers(client, options);
|
|
@@ -1771,9 +1896,16 @@ function registerProjectCommands(program2) {
|
|
|
1771
1896
|
const extra = parseJson2(options.json);
|
|
1772
1897
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
1773
1898
|
let name = options.name;
|
|
1774
|
-
|
|
1899
|
+
let projectFormTemplate;
|
|
1900
|
+
const loadProjectFormTemplate = async () => {
|
|
1901
|
+
if (projectFormTemplate === void 0) {
|
|
1902
|
+
projectFormTemplate = await fetchProjectFormTemplate(client, flowDetail);
|
|
1903
|
+
}
|
|
1904
|
+
return projectFormTemplate;
|
|
1905
|
+
};
|
|
1906
|
+
if (useInteractive) {
|
|
1775
1907
|
if (!flowDetail) {
|
|
1776
|
-
throw new Error("
|
|
1908
|
+
throw new Error("Interactive project creation requires --flow-id so the form schema can be discovered.");
|
|
1777
1909
|
}
|
|
1778
1910
|
const fields = extractFormFields(flowDetail);
|
|
1779
1911
|
const promptResult = await promptProjectCreateForm({
|
|
@@ -1791,23 +1923,23 @@ function registerProjectCommands(program2) {
|
|
|
1791
1923
|
printResult(options.format, { cancelled: true });
|
|
1792
1924
|
return;
|
|
1793
1925
|
}
|
|
1926
|
+
projectFormTemplate = await loadProjectFormTemplate();
|
|
1927
|
+
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
1928
|
+
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1929
|
+
name,
|
|
1930
|
+
form,
|
|
1931
|
+
reason: "form_template_auto_init_lambda",
|
|
1932
|
+
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"
|
|
1933
|
+
});
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1794
1936
|
if (promptResult.action === "open_form") {
|
|
1795
1937
|
if (!options.allowFormHandoff) {
|
|
1796
1938
|
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
1797
1939
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
initValue: {
|
|
1802
|
-
project: { name },
|
|
1803
|
-
key_to_value: form
|
|
1804
|
-
}
|
|
1805
|
-
});
|
|
1806
|
-
printResult(options.format, {
|
|
1807
|
-
handoff: true,
|
|
1808
|
-
url: url.url,
|
|
1809
|
-
pc_url: url.pc_url,
|
|
1810
|
-
mobile_path: url.mobile_path,
|
|
1940
|
+
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1941
|
+
name,
|
|
1942
|
+
form,
|
|
1811
1943
|
message: "\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
1812
1944
|
});
|
|
1813
1945
|
return;
|
|
@@ -1816,12 +1948,25 @@ function registerProjectCommands(program2) {
|
|
|
1816
1948
|
if (!name) {
|
|
1817
1949
|
throw new Error("--name is required unless --body is provided.");
|
|
1818
1950
|
}
|
|
1951
|
+
projectFormTemplate = await loadProjectFormTemplate();
|
|
1952
|
+
if (projectFormTemplate && hasAutoInitLambda(projectFormTemplate.template)) {
|
|
1953
|
+
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1954
|
+
name,
|
|
1955
|
+
form,
|
|
1956
|
+
reason: "form_template_auto_init_lambda",
|
|
1957
|
+
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"
|
|
1958
|
+
});
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
const { form: _rawForm, ...projectExtra } = extra;
|
|
1962
|
+
const { flow_key: flowKey, ...projectFlowIdentifiers } = flowIdentifiers;
|
|
1819
1963
|
payload = {
|
|
1820
|
-
...
|
|
1821
|
-
...
|
|
1964
|
+
...projectExtra,
|
|
1965
|
+
...projectFlowIdentifiers,
|
|
1966
|
+
key: flowKey,
|
|
1822
1967
|
name,
|
|
1823
1968
|
workspace: profile.config.workspace,
|
|
1824
|
-
form
|
|
1969
|
+
...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, projectFormTemplate)
|
|
1825
1970
|
};
|
|
1826
1971
|
if (!options.skipFormValidation) {
|
|
1827
1972
|
await validateCreateForm(client, { flowId: options.flowId, flowDetail, form });
|
|
@@ -1830,7 +1975,7 @@ function registerProjectCommands(program2) {
|
|
|
1830
1975
|
const result = await apiRequest(
|
|
1831
1976
|
client,
|
|
1832
1977
|
"POST",
|
|
1833
|
-
"/project
|
|
1978
|
+
"/project",
|
|
1834
1979
|
{
|
|
1835
1980
|
data: payload
|
|
1836
1981
|
}
|
|
@@ -1876,7 +2021,7 @@ function getRecipesDir(options) {
|
|
|
1876
2021
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
1877
2022
|
return path3.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
1878
2023
|
}
|
|
1879
|
-
function
|
|
2024
|
+
function isRecord5(value) {
|
|
1880
2025
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1881
2026
|
}
|
|
1882
2027
|
function asString(value, fieldName) {
|
|
@@ -1886,7 +2031,7 @@ function asString(value, fieldName) {
|
|
|
1886
2031
|
return value;
|
|
1887
2032
|
}
|
|
1888
2033
|
function parseRecipeDefinition(input) {
|
|
1889
|
-
if (!
|
|
2034
|
+
if (!isRecord5(input)) {
|
|
1890
2035
|
throw new Error("recipe.json must be a JSON object.");
|
|
1891
2036
|
}
|
|
1892
2037
|
if (input.version !== 1) {
|
|
@@ -1894,7 +2039,7 @@ function parseRecipeDefinition(input) {
|
|
|
1894
2039
|
}
|
|
1895
2040
|
const name = asString(input.name, "recipe.name");
|
|
1896
2041
|
assertSafeName("Recipe name", name);
|
|
1897
|
-
if (!
|
|
2042
|
+
if (!isRecord5(input.command)) {
|
|
1898
2043
|
throw new Error("recipe.command must be an object.");
|
|
1899
2044
|
}
|
|
1900
2045
|
const argv = input.command.argv;
|
|
@@ -1902,7 +2047,7 @@ function parseRecipeDefinition(input) {
|
|
|
1902
2047
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
1903
2048
|
}
|
|
1904
2049
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
1905
|
-
if (!
|
|
2050
|
+
if (!isRecord5(item)) {
|
|
1906
2051
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
1907
2052
|
}
|
|
1908
2053
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -1978,7 +2123,7 @@ function parseVarsJson(input) {
|
|
|
1978
2123
|
return {};
|
|
1979
2124
|
}
|
|
1980
2125
|
const parsed = JSON.parse(input);
|
|
1981
|
-
if (!
|
|
2126
|
+
if (!isRecord5(parsed)) {
|
|
1982
2127
|
throw new Error("--vars must be a JSON object.");
|
|
1983
2128
|
}
|
|
1984
2129
|
const variables = {};
|
|
@@ -2211,7 +2356,7 @@ var schemaEntries = [
|
|
|
2211
2356
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
2212
2357
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
2213
2358
|
{ name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },
|
|
2214
|
-
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project
|
|
2359
|
+
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project" },
|
|
2215
2360
|
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" }
|
|
2216
2361
|
];
|
|
2217
2362
|
|