bpmax-cli 0.1.19 → 0.1.20
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 +154 -27
- package/dist/bin.js.map +1 -1
- package/package.json +1 -1
- package/skills/bpmax-project/SKILL.md +2 -0
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.20",
|
|
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) => {
|
|
@@ -1771,6 +1894,7 @@ function registerProjectCommands(program2) {
|
|
|
1771
1894
|
const extra = parseJson2(options.json);
|
|
1772
1895
|
const form = typeof extra.form === "object" && extra.form !== null && !Array.isArray(extra.form) ? extra.form : {};
|
|
1773
1896
|
let name = options.name;
|
|
1897
|
+
let interactiveTemplate;
|
|
1774
1898
|
if (options.interactive) {
|
|
1775
1899
|
if (!flowDetail) {
|
|
1776
1900
|
throw new Error("--interactive requires --flow-id so the form schema can be discovered.");
|
|
@@ -1791,23 +1915,23 @@ function registerProjectCommands(program2) {
|
|
|
1791
1915
|
printResult(options.format, { cancelled: true });
|
|
1792
1916
|
return;
|
|
1793
1917
|
}
|
|
1918
|
+
interactiveTemplate = await fetchProjectFormTemplate(client, flowDetail);
|
|
1919
|
+
if (interactiveTemplate && hasAutoInitLambda(interactiveTemplate.template)) {
|
|
1920
|
+
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1921
|
+
name,
|
|
1922
|
+
form,
|
|
1923
|
+
reason: "form_template_auto_init_lambda",
|
|
1924
|
+
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"
|
|
1925
|
+
});
|
|
1926
|
+
return;
|
|
1927
|
+
}
|
|
1794
1928
|
if (promptResult.action === "open_form") {
|
|
1795
1929
|
if (!options.allowFormHandoff) {
|
|
1796
1930
|
throw new Error("Form handoff requires --allow-form-handoff. Continue interactive filling by default.");
|
|
1797
1931
|
}
|
|
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,
|
|
1932
|
+
printCreateFormHandoff(options.format, profile, flowIdentifiers, {
|
|
1933
|
+
name,
|
|
1934
|
+
form,
|
|
1811
1935
|
message: "\u5DF2\u751F\u6210 BPMAX \u521B\u5EFA\u9875\u94FE\u63A5\uFF0C\u8BF7\u70B9\u51FB\u7EE7\u7EED\u586B\u5199\u5E76\u63D0\u4EA4\u3002"
|
|
1812
1936
|
});
|
|
1813
1937
|
return;
|
|
@@ -1816,12 +1940,15 @@ function registerProjectCommands(program2) {
|
|
|
1816
1940
|
if (!name) {
|
|
1817
1941
|
throw new Error("--name is required unless --body is provided.");
|
|
1818
1942
|
}
|
|
1943
|
+
const { form: _rawForm, ...projectExtra } = extra;
|
|
1944
|
+
const { flow_key: flowKey, ...projectFlowIdentifiers } = flowIdentifiers;
|
|
1819
1945
|
payload = {
|
|
1820
|
-
...
|
|
1821
|
-
...
|
|
1946
|
+
...projectExtra,
|
|
1947
|
+
...projectFlowIdentifiers,
|
|
1948
|
+
key: flowKey,
|
|
1822
1949
|
name,
|
|
1823
1950
|
workspace: profile.config.workspace,
|
|
1824
|
-
form
|
|
1951
|
+
...projectExtra.projectForm ? {} : await buildProjectFormPayload(client, flowDetail, form, interactiveTemplate)
|
|
1825
1952
|
};
|
|
1826
1953
|
if (!options.skipFormValidation) {
|
|
1827
1954
|
await validateCreateForm(client, { flowId: options.flowId, flowDetail, form });
|
|
@@ -1830,7 +1957,7 @@ function registerProjectCommands(program2) {
|
|
|
1830
1957
|
const result = await apiRequest(
|
|
1831
1958
|
client,
|
|
1832
1959
|
"POST",
|
|
1833
|
-
"/project
|
|
1960
|
+
"/project",
|
|
1834
1961
|
{
|
|
1835
1962
|
data: payload
|
|
1836
1963
|
}
|
|
@@ -1876,7 +2003,7 @@ function getRecipesDir(options) {
|
|
|
1876
2003
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
1877
2004
|
return path3.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
1878
2005
|
}
|
|
1879
|
-
function
|
|
2006
|
+
function isRecord5(value) {
|
|
1880
2007
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1881
2008
|
}
|
|
1882
2009
|
function asString(value, fieldName) {
|
|
@@ -1886,7 +2013,7 @@ function asString(value, fieldName) {
|
|
|
1886
2013
|
return value;
|
|
1887
2014
|
}
|
|
1888
2015
|
function parseRecipeDefinition(input) {
|
|
1889
|
-
if (!
|
|
2016
|
+
if (!isRecord5(input)) {
|
|
1890
2017
|
throw new Error("recipe.json must be a JSON object.");
|
|
1891
2018
|
}
|
|
1892
2019
|
if (input.version !== 1) {
|
|
@@ -1894,7 +2021,7 @@ function parseRecipeDefinition(input) {
|
|
|
1894
2021
|
}
|
|
1895
2022
|
const name = asString(input.name, "recipe.name");
|
|
1896
2023
|
assertSafeName("Recipe name", name);
|
|
1897
|
-
if (!
|
|
2024
|
+
if (!isRecord5(input.command)) {
|
|
1898
2025
|
throw new Error("recipe.command must be an object.");
|
|
1899
2026
|
}
|
|
1900
2027
|
const argv = input.command.argv;
|
|
@@ -1902,7 +2029,7 @@ function parseRecipeDefinition(input) {
|
|
|
1902
2029
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
1903
2030
|
}
|
|
1904
2031
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
1905
|
-
if (!
|
|
2032
|
+
if (!isRecord5(item)) {
|
|
1906
2033
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
1907
2034
|
}
|
|
1908
2035
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -1978,7 +2105,7 @@ function parseVarsJson(input) {
|
|
|
1978
2105
|
return {};
|
|
1979
2106
|
}
|
|
1980
2107
|
const parsed = JSON.parse(input);
|
|
1981
|
-
if (!
|
|
2108
|
+
if (!isRecord5(parsed)) {
|
|
1982
2109
|
throw new Error("--vars must be a JSON object.");
|
|
1983
2110
|
}
|
|
1984
2111
|
const variables = {};
|
|
@@ -2211,7 +2338,7 @@ var schemaEntries = [
|
|
|
2211
2338
|
{ name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
|
|
2212
2339
|
{ name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
|
|
2213
2340
|
{ 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
|
|
2341
|
+
{ name: "project.create", description: "Create a project with local form schema validation when form payload is provided.", method: "POST", path: "/api/project" },
|
|
2215
2342
|
{ name: "step.get", description: "Get step detail.", method: "GET", path: "/api/step/:id" }
|
|
2216
2343
|
];
|
|
2217
2344
|
|