bpmax-cli 0.1.39 → 0.1.40

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 CHANGED
@@ -174,8 +174,7 @@ Direct `project create --body` is blocked by default because it bypasses flow fo
174
174
 
175
175
  ## ES project queries
176
176
 
177
- Use ES project search for high-volume reads, budget summaries, trend analysis, and other reporting-style queries.
178
- For normal project searches, pass a project-list style body. The CLI calls `POST /api/project/list`, so BPMAX still applies project list permissions, workspace filters, and dataset hooks:
177
+ Use ES project search for high-volume reads and reporting-style queries that can be expressed with the huanpingtong project-list request body. The CLI calls `POST /api/project/list`, so BPMAX still applies project list permissions, workspace filters, and dataset hooks:
179
178
 
180
179
  ```bash
181
180
  bpmax-cli es project-search --profile yuanrong --body @project-list-query.json --page 1 --page-size 20 --format json
@@ -193,20 +192,19 @@ bpmax-cli es project-search --profile yuanrong --body @project-list-query.json -
193
192
  }
194
193
  ```
195
194
 
196
- For advanced aggregations or raw Elasticsearch requests, include a top-level `body` field. In that case the CLI calls `POST /api/project/raw-es-search` unchanged:
195
+ Raw Elasticsearch DTOs are intentionally not supported through `bpmax-cli es project-search`. `huanpingtong-server` does not expose `/api/project/raw-es-search` as a public endpoint, and legacy `/api/project/<id>` routing can fall through to project creation. If the payload contains a top-level `body` field, the CLI fails before sending any request.
196
+
197
+ Use a project-list body instead:
197
198
 
198
199
  ```json
199
200
  {
200
201
  "data_set_key": "budget_project",
201
202
  "flow_type": "flow123",
202
203
  "flow_key": "",
203
- "body": {
204
- "size": 0,
205
- "query": { "match_all": {} },
206
- "aggs": {
207
- "by_status": { "terms": { "field": "status" } }
208
- }
209
- }
204
+ "query": {
205
+ "name": { "type": "match_phrase", "value": "董永喜" }
206
+ },
207
+ "is_select_all": false
210
208
  }
211
209
  ```
212
210
 
@@ -307,7 +305,7 @@ bpmax-cli --config-dir <config_dir> bbs ensure <skill-key> --agent <agent> --pro
307
305
 
308
306
  Use `bbs sync` when there is no local/catalog match, then check again before falling back to generic flow/project/API commands. `bbs sync` installs only the catalog skill; individual business skills are installed lazily with `bbs ensure`.
309
307
 
310
- For mutating raw API calls, `bpmax-cli api` requires `--confirm-mutating` and supports `--data @file.json`. Prefer typed commands such as `step submit` for workflow state changes.
308
+ For mutating raw API calls, `bpmax-cli api` requires `--confirm-mutating` and supports `--data @file.json`. Raw API calls to `POST /project` or `POST /project/<anything>` are blocked even with `--confirm-mutating`; the only project POST allowed in raw mode is the read-style `/project/list`. Create projects through `bpmax-cli project create --flow-id <id> --json <json>` so the CLI can run form-template checks and choose safe direct submit or handoff. Prefer typed commands such as `step submit` for workflow state changes.
311
309
 
312
310
  If `aily-skillhub` is available in `PATH`, the installer also runs:
313
311
 
package/dist/bin.js CHANGED
@@ -318,9 +318,42 @@ async function parseJsonAny(input, label = "JSON input") {
318
318
  function isMutatingMethod(method) {
319
319
  return ["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase());
320
320
  }
321
+ function normalizeApiPath(path6) {
322
+ let normalized = path6.trim();
323
+ const queryIndex = normalized.indexOf("?");
324
+ if (queryIndex >= 0) {
325
+ normalized = normalized.slice(0, queryIndex);
326
+ }
327
+ if (!normalized.startsWith("/")) {
328
+ normalized = `/${normalized}`;
329
+ }
330
+ normalized = normalized.replace(/\/+/g, "/");
331
+ if (normalized.startsWith("/api/")) {
332
+ normalized = normalized.slice(4);
333
+ }
334
+ if (normalized.length > 1) {
335
+ normalized = normalized.replace(/\/+$/g, "");
336
+ }
337
+ return normalized;
338
+ }
339
+ function assertRawApiPathAllowed(method, path6) {
340
+ if (!isMutatingMethod(method)) {
341
+ return;
342
+ }
343
+ const normalizedPath = normalizeApiPath(path6);
344
+ const isProjectPath = normalizedPath === "/project" || normalizedPath.startsWith("/project/");
345
+ const isAllowedProjectReadPost = method === "POST" && normalizedPath === "/project/list";
346
+ if (!isProjectPath || isAllowedProjectReadPost) {
347
+ return;
348
+ }
349
+ throw new Error(
350
+ `Raw API ${method} ${path6} is blocked because /api/project/<id> falls back to project creation in huanpingtong-server. Do not call /project/es-search or /project/raw-es-search; huanpingtong-server does not expose those as public ES APIs. Use bpmax-cli project create --flow-id <id> --json <json> for project creation, or bpmax-cli es project-search / project list for project reads.`
351
+ );
352
+ }
321
353
  function registerApiCommands(program2) {
322
354
  program2.command("api <method> <path>").description("Call an arbitrary BPMAX /api endpoint").option("--profile <profile>", "Profile name").option("--params <json>", "Query params JSON or @file").option("--data <json>", "Request body JSON or @file").option("--confirm-mutating", "Allow mutating API calls").option("--format <format>", "Output format", "json").action(async (method, path6, options) => {
323
355
  const normalizedMethod = method.toUpperCase();
356
+ assertRawApiPathAllowed(normalizedMethod, path6);
324
357
  if (isMutatingMethod(normalizedMethod) && options.confirmMutating !== true) {
325
358
  printResult(options.format, {
326
359
  ok: false,
@@ -733,7 +766,7 @@ import { readFile as readFile5 } from "fs/promises";
733
766
  // package.json
734
767
  var package_default = {
735
768
  name: "bpmax-cli",
736
- version: "0.1.39",
769
+ version: "0.1.40",
737
770
  description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
738
771
  type: "module",
739
772
  bin: {
@@ -1735,29 +1768,21 @@ function registerConfigCommands(program2) {
1735
1768
  function isRecord3(value) {
1736
1769
  return typeof value === "object" && value !== null && !Array.isArray(value);
1737
1770
  }
1738
- function isRawProjectSearchBody(value) {
1771
+ function hasRawProjectSearchBody(value) {
1739
1772
  return isRecord3(value) && Object.prototype.hasOwnProperty.call(value, "body");
1740
1773
  }
1741
1774
  function registerEsCommands(program2) {
1742
1775
  const es = program2.command("es").description("Fast ES-backed data queries");
1743
- es.command("project-search").description("Search project ES data with the project-list API, or raw ES when body.body is provided").option("--profile <profile>", "Profile name").option("--page <page>", "Page number for project-list payloads", "1").option("--page-size <pageSize>", "Page size for project-list payloads", "20").requiredOption("--body <json>", "Project list body JSON or raw ES request body JSON/@file").option("--format <format>", "Output format", "json").action(async (options) => {
1744
- const config = await loadConfig();
1745
- const profile = resolveProfile(config, options.profile);
1776
+ es.command("project-search").description("Search project ES data with the huanpingtong project-list API").option("--profile <profile>", "Profile name").option("--page <page>", "Page number for project-list payloads", "1").option("--page-size <pageSize>", "Page size for project-list payloads", "20").requiredOption("--body <json>", "Project list body JSON or @file").option("--format <format>", "Output format", "json").action(async (options) => {
1746
1777
  const body = await parseJsonInput(options.body, "--body");
1747
- const client = createApiClient(profile);
1748
- if (isRawProjectSearchBody(body)) {
1749
- const result2 = await apiRequest(
1750
- client,
1751
- "POST",
1752
- "/project/raw-es-search",
1753
- {
1754
- data: body,
1755
- preserveErrorBody: true
1756
- }
1778
+ if (hasRawProjectSearchBody(body)) {
1779
+ throw new Error(
1780
+ "Raw ES DTO with top-level body is not supported through huanpingtong-server. Use a project-list body with bpmax-cli es project-search so the CLI calls /api/project/list. /api/project/raw-es-search is not exposed by huanpingtong-server and legacy /api/project/<id> routing can create projects."
1757
1781
  );
1758
- printResult(options.format, result2);
1759
- return;
1760
1782
  }
1783
+ const config = await loadConfig();
1784
+ const profile = resolveProfile(config, options.profile);
1785
+ const client = createApiClient(profile);
1761
1786
  const result = await apiRequest(
1762
1787
  client,
1763
1788
  "POST",
@@ -3708,7 +3733,7 @@ var schemaEntries = [
3708
3733
  { name: "flow.list", description: "List flows.", method: "GET", path: "/api/flow/flow_type" },
3709
3734
  { name: "flow.options", description: "List flow options.", method: "GET", path: "/api/flow/options" },
3710
3735
  { name: "flow.get", description: "Fetch flow details by id.", method: "POST", path: "/api/flow/batch_get" },
3711
- { name: "es.project-search", description: "Search project ES data through /api/project/list, falling back to raw ES when the payload contains body.", method: "POST", path: "/api/project/list or /api/project/raw-es-search" },
3736
+ { name: "es.project-search", description: "Search project ES data through huanpingtong /api/project/list only.", method: "POST", path: "/api/project/list" },
3712
3737
  { name: "project.list", description: "List projects.", method: "POST", path: "/api/project/list" },
3713
3738
  { name: "project.get", description: "Get project detail.", method: "GET", path: "/api/project/:id" },
3714
3739
  { name: "project.my-step", description: "List my pending steps.", method: "GET", path: "/api/project/my_step" },