bpmax-cli 0.2.1-beta.4 → 0.2.1-beta.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 +12 -4
- package/dist/bin.js +18597 -8166
- package/dist/bin.js.map +1 -1
- package/package.json +7 -4
- package/scripts/run-source-cli.mjs +121 -0
- package/skills/bpmax-ai-taskbook/SKILL.md +1 -0
- package/skills/bpmax-api-platform-editor/SKILL.md +24 -31
- package/skills/bpmax-api-platform-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-api-platform-editor/references/platform-api-map.md +2 -2
- package/skills/bpmax-api-platform-editor/references/runtime-workflow.md +3 -3
- package/skills/bpmax-approval-matrix/SKILL.md +54 -2
- package/skills/bpmax-blueprint-doc-workflow/SKILL.md +87 -0
- package/skills/bpmax-blueprint-doc-workflow/agents/openai.yaml +4 -0
- package/skills/bpmax-blueprint-doc-workflow/references/blueprint-structure.md +60 -0
- package/skills/bpmax-blueprint-doc-workflow/references/per-flow-required-structure.md +98 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-forbidden-term.xml +12 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-mermaid-codeblock.xml +12 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-missing-boundary.xml +10 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-missing-whiteboard.xml +10 -0
- package/skills/bpmax-blueprint-doc-workflow/references/sample-pass.xml +55 -0
- package/skills/bpmax-blueprint-doc-workflow/scripts/lint_blueprint_doc.py +257 -0
- package/skills/bpmax-bug-reporting/SKILL.md +72 -0
- package/skills/bpmax-builder-shared/SKILL.md +1 -0
- package/skills/bpmax-builder-shared/configuration-impact-review.md +76 -0
- package/skills/bpmax-builder-shared/template_script_hard_rules.py +3 -1
- package/skills/bpmax-builder-shared/tests/test_template_script_hard_rules.py +16 -0
- package/skills/bpmax-cli/SKILL.md +42 -0
- package/skills/bpmax-config-latest/SKILL.md +4 -0
- package/skills/bpmax-console-template-editor/SKILL.md +111 -523
- package/skills/bpmax-console-template-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-console-template-editor/references/full-detail-guide.md +45 -0
- package/skills/bpmax-console-template-editor/references/local-temp-workflow.md +13 -12
- package/skills/bpmax-console-template-editor/scripts/console_template_editor_common.py +299 -78
- package/skills/bpmax-console-template-editor/tests/test_console_template_editor.py +344 -30
- package/skills/bpmax-dataset-field-template-editor/SKILL.md +127 -594
- package/skills/bpmax-dataset-field-template-editor/references/full-detail-guide.md +570 -0
- package/skills/bpmax-dataset-field-template-editor/references/runtime-verified-field-page-shape.md +1 -1
- package/skills/bpmax-dataset-field-template-editor/scripts/dataset_field_editor_common.py +11 -77
- package/skills/bpmax-dataset-field-template-editor/scripts/export_dataset_field.py +4 -57
- package/skills/bpmax-dataset-field-template-editor/scripts/init_create_dataset_field.py +2 -0
- package/skills/bpmax-dataset-field-template-editor/scripts/inspect_dataset_field_runtime.py +4 -78
- package/skills/bpmax-dataset-field-template-editor/scripts/submit_dataset_field.py +3 -89
- package/skills/bpmax-dataset-field-template-editor/tests/test_dataset_field_editor.py +14 -0
- package/skills/bpmax-dataset-field-template-editor/tests/test_init_create_dataset_field.py +2 -0
- package/skills/bpmax-dataset-template-editor/SKILL.md +116 -778
- package/skills/bpmax-dataset-template-editor/references/full-detail-guide.md +753 -0
- package/skills/bpmax-dataset-template-editor/references/ui-to-backend-field-map.md +1 -0
- package/skills/bpmax-dataset-template-editor/references/work-file-to-submit-mapping.md +2 -2
- package/skills/bpmax-dataset-template-editor/scripts/basic_table_audit.py +8 -1
- package/skills/bpmax-dataset-template-editor/scripts/dataset_editor_common.py +9 -90
- package/skills/bpmax-dataset-template-editor/scripts/export_dataset.py +8 -1
- package/skills/bpmax-dataset-template-editor/scripts/resolve_dataset.py +8 -1
- package/skills/bpmax-dataset-template-editor/scripts/submit_dataset.py +1 -2
- package/skills/bpmax-dataset-template-editor/scripts/verify_dataset_list.py +8 -1
- package/skills/bpmax-dataset-template-editor/scripts/verify_publish_health.py +8 -1
- package/skills/bpmax-dataset-template-editor/tests/test_dataset_editor.py +6 -40
- package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +15 -4
- package/skills/bpmax-e2e-flow-config-orchestrator/agents/openai.yaml +2 -2
- package/skills/bpmax-e2e-flow-config-orchestrator/references/orchestration-matrix.md +13 -9
- package/skills/bpmax-e2e-flow-test-operator/SKILL.md +138 -533
- package/skills/bpmax-e2e-flow-test-operator/agents/openai.yaml +2 -3
- package/skills/bpmax-e2e-flow-test-operator/references/ai-test-suite.md +149 -9
- package/skills/bpmax-e2e-flow-test-operator/references/browser-only-checkpoints.md +6 -5
- package/skills/bpmax-e2e-flow-test-operator/references/full-detail-guide.md +568 -0
- package/skills/bpmax-e2e-flow-test-operator/references/negative-sale-api-matrix.md +4 -4
- package/skills/bpmax-e2e-flow-test-operator/references/profile-schema.md +1 -1
- package/skills/bpmax-e2e-flow-test-operator/references/state-schema.md +3 -1
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_doc.py +7 -5
- package/skills/bpmax-e2e-flow-test-operator/scripts/e2e_state.py +2 -2
- package/skills/bpmax-e2e-flow-test-operator/scripts/flow_runner.py +5 -1
- package/skills/bpmax-e2e-flow-test-operator/tests/test_negative_sale_api_tools.py +71 -0
- package/skills/bpmax-filter-template-editor/SKILL.md +114 -551
- package/skills/bpmax-filter-template-editor/references/experience-coverage-matrix.md +18 -18
- package/skills/bpmax-filter-template-editor/references/filter-content-schema.md +21 -0
- package/skills/bpmax-filter-template-editor/references/filter-request-shape.md +29 -26
- package/skills/bpmax-filter-template-editor/references/filter-runtime-patterns.md +19 -2
- package/skills/bpmax-filter-template-editor/references/full-detail-guide.md +56 -0
- package/skills/bpmax-filter-template-editor/references/runtime-verified-filter-page-shape.md +10 -9
- package/skills/bpmax-filter-template-editor/scripts/filter_template_editor_common.py +7 -57
- package/skills/bpmax-filter-template-editor/tests/test_filter_template_editor.py +4 -48
- package/skills/bpmax-flow-detail-template-editor/SKILL.md +43 -0
- package/skills/bpmax-flow-template-editor/SKILL.md +117 -1084
- package/skills/bpmax-flow-template-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-flow-template-editor/references/diff-strategy.md +3 -3
- package/skills/bpmax-flow-template-editor/references/editor-runtime-vs-draft.md +9 -9
- package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +2 -1
- package/skills/bpmax-flow-template-editor/references/full-detail-guide.md +1157 -0
- package/skills/bpmax-flow-template-editor/references/local-temp-workflow.md +1 -1
- package/skills/bpmax-flow-template-editor/references/project-create-runtime-gotchas.md +17 -0
- package/skills/bpmax-flow-template-editor/references/requirement-to-node-mapping.md +8 -3
- package/skills/bpmax-flow-template-editor/references/runtime-verified-flow-detail-shape.md +7 -7
- package/skills/bpmax-flow-template-editor/references/runtime-verified-meta-fields.md +2 -2
- package/skills/bpmax-flow-template-editor/references/runtime-verified-node-fields.md +8 -2
- package/skills/bpmax-flow-template-editor/references/save-draft-request-shape.md +7 -23
- package/skills/bpmax-flow-template-editor/references/work-file-to-submit-mapping.md +1 -1
- package/skills/bpmax-flow-template-editor/tests/test_flow_template_editor.py +19 -75
- package/skills/bpmax-form-template-editor/SKILL.md +130 -1104
- package/skills/bpmax-form-template-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-form-template-editor/references/dynamic-field-state.md +164 -0
- package/skills/bpmax-form-template-editor/references/form-template-api-workflow.md +51 -51
- package/skills/bpmax-form-template-editor/references/full-detail-guide.md +1109 -0
- package/skills/bpmax-form-template-editor/references/local-temp-workflow.md +4 -4
- package/skills/bpmax-form-template-editor/references/payload-checklist.md +3 -1
- package/skills/bpmax-form-template-editor/scripts/form_template_editor_common.py +8 -0
- package/skills/bpmax-form-template-editor/tests/test_form_template_editor.py +42 -19
- package/skills/bpmax-functional-test-design/LICENSE.upstream +24 -0
- package/skills/bpmax-functional-test-design/SKILL.md +80 -0
- package/skills/bpmax-functional-test-design/agents/openai.yaml +4 -0
- package/skills/bpmax-functional-test-design/references/bpmax-test-suite-output.md +95 -0
- package/skills/bpmax-functional-test-design/references/decision-table-testing.md +50 -0
- package/skills/bpmax-functional-test-design/references/domain-testing.md +43 -0
- package/skills/bpmax-functional-test-design/references/state-transition-testing.md +47 -0
- package/skills/bpmax-functional-test-design/references/technique-selection.md +38 -0
- package/skills/bpmax-functional-test-design/references/use-case-testing.md +55 -0
- package/skills/bpmax-group-model-editor/SKILL.md +24 -0
- package/skills/bpmax-list-template-editor/SKILL.md +119 -466
- package/skills/bpmax-list-template-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-list-template-editor/references/content-config-shape.md +16 -4
- package/skills/bpmax-list-template-editor/references/full-detail-guide.md +458 -0
- package/skills/bpmax-list-template-editor/references/list-template-api-workflow.md +6 -9
- package/skills/bpmax-list-template-editor/references/local-temp-workflow.md +1 -1
- package/skills/bpmax-list-template-editor/references/special-formats.md +5 -2
- package/skills/bpmax-list-template-editor/scripts/list_template_editor_common.py +9 -78
- package/skills/bpmax-memory-protocol/SKILL.md +7 -6
- package/skills/bpmax-nav-config-editor/SKILL.md +13 -17
- package/skills/bpmax-nav-config-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-nav-config-editor/references/api-workflow.md +2 -2
- package/skills/bpmax-nav-config-editor/references/runtime-probing.md +11 -12
- package/skills/bpmax-plugin-config/SKILL.md +20 -4
- package/skills/bpmax-project/SKILL.md +37 -1
- package/skills/bpmax-project-detail-template-editor/SKILL.md +13 -39
- package/skills/bpmax-project-detail-template-editor/agents/openai.yaml +2 -2
- package/skills/bpmax-role-editor/SKILL.md +7 -30
- package/skills/bpmax-shared/SKILL.md +19 -9
- package/skills/bpmax-team-editor/SKILL.md +27 -0
- package/skills/bpmax-ui-ux-audit/LICENSE.upstream +23 -0
- package/skills/bpmax-ui-ux-audit/SKILL.md +42 -0
- package/skills/bpmax-ui-ux-audit/agents/openai.yaml +4 -0
- package/skills/bpmax-ui-ux-audit/references/audit-framework.md +39 -0
- package/skills/bpmax-ui-ux-audit/references/bpmax-ux-findings.md +56 -0
- package/skills/bpmax-user/SKILL.md +33 -1
- package/skills/bpmax-user-mock-operator/SKILL.md +20 -48
- package/skills/bpmax-user-mock-operator/agents/openai.yaml +2 -2
- package/skills/bpmax-user-model-editor/SKILL.md +24 -0
- package/skills/form-control-library/references/form-template-submit-schema.md +1 -1
- package/skills/bpmax-user-mock-operator/scripts/switch_user_identity.py +0 -37
- package/skills/bpmax-user-mock-operator/scripts/user_mock_operator_common.py +0 -136
- package/skills/bpmax-user-mock-operator/tests/test_user_mock_operator.py +0 -138
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
interface:
|
|
2
2
|
display_name: "BPMAX Console Template Editor"
|
|
3
|
-
short_description: "
|
|
4
|
-
default_prompt: "使用 $bpmax-console-template-editor
|
|
3
|
+
short_description: "通过 bpmax-cli typed config 创建或编辑 BPMAX 数据看板模板"
|
|
4
|
+
default_prompt: "使用 $bpmax-console-template-editor 通过 bpmax-cli typed config 创建或编辑 BPMAX 数据看板模板,并用回读验证确认结果。"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Console Template Archive Guide
|
|
2
|
+
|
|
3
|
+
> Archive reference for details that used to live in `../SKILL.md`. The active entrypoint is `../SKILL.md`; this file preserves historical decisions and case lessons without weakening the typed CLI write path.
|
|
4
|
+
|
|
5
|
+
## 常驻结论
|
|
6
|
+
- 看板模板是 `flow_page_template.type = 4`。
|
|
7
|
+
- `content.layout[]` 是模块主结构;`search_temp_id` 是看板绑定筛选器的入口。
|
|
8
|
+
- 模板写入必须走 `bpmax-cli config console-template ...` typed CLI。
|
|
9
|
+
- 运行态页面只用于只读展示和真实用户身份 E2E 验收,不是配置写入入口。
|
|
10
|
+
|
|
11
|
+
## 历史经验
|
|
12
|
+
|
|
13
|
+
### 真实结构优先
|
|
14
|
+
编辑前必须先 export/readback 线上模板。仓库镜像、旧请求样例和记忆只能做候选线索。
|
|
15
|
+
|
|
16
|
+
### 局部需求不能扩大范围
|
|
17
|
+
只改模块标题时,默认不改 `dataSource`、筛选器绑定、layout 坐标和其它模块。任何联动改动都必须归入 `required-collateral` 并逐项确认。
|
|
18
|
+
|
|
19
|
+
### 统计类看板必须下推查询
|
|
20
|
+
库存、销量、项目数等统计不能拉大批明细到前端循环计数。优先使用 ES aggregation,并说明事实源、状态口径、排除口径和分组键。
|
|
21
|
+
|
|
22
|
+
### driver 语义
|
|
23
|
+
看板前端 `useDataSource` 识别的是 `driver: 'es'` 等模块数据源类型;`raw-es-search` 是接口/helper 语义,不能写成看板模块 driver。
|
|
24
|
+
|
|
25
|
+
### 保存成功不等于预览通过
|
|
26
|
+
submit 成功后仍要 verify/readback,并在需要时打开预览页验证模块渲染、console 错误、network 请求和筛选联动。
|
|
27
|
+
|
|
28
|
+
## 旧规则去向
|
|
29
|
+
- 本地双确认流程:`local-temp-workflow.md`
|
|
30
|
+
- 模板 shape:`template-shape.md`
|
|
31
|
+
- 模块 catalog:`module-catalog.md`
|
|
32
|
+
- 筛选器联动:`filter-integration.md`
|
|
33
|
+
- 页面只读验收:`runtime-page-shape.md`
|
|
34
|
+
- 简历看板案例:`lessons-from-resume-dashboard.md`
|
|
35
|
+
|
|
36
|
+
## 统一执行入口
|
|
37
|
+
```bash
|
|
38
|
+
bpmax-cli config console-template export --id <id> --out .codex/tmp/console-template-editor --profile <profile> --format json
|
|
39
|
+
bpmax-cli config console-template lint --work .codex/tmp/console-template-editor/work/<file>.json --profile <profile> --format json
|
|
40
|
+
bpmax-cli config console-template build --work .codex/tmp/console-template-editor/work/<file>.json --meta .codex/tmp/console-template-editor/meta/<file>.meta.json --out .codex/tmp/console-template-editor/submit/<file>.json --profile <profile> --format json
|
|
41
|
+
bpmax-cli config console-template submit --id <id> --payload .codex/tmp/console-template-editor/submit/<file>.json --profile <profile> --confirm "submit console-template <id>" --format json
|
|
42
|
+
bpmax-cli config console-template verify --id <id> --expect .codex/tmp/console-template-editor/work/<file>.json --profile <profile> --format json
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
旧 Python 脚本只保留为本地结构/lint 参考,不是线上写入路径。
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
- 接口确认真实线上结构
|
|
6
6
|
- 导出本地临时文件
|
|
7
7
|
- work 第一次确认
|
|
8
|
-
- submit
|
|
8
|
+
- typed CLI build 生成 submit
|
|
9
9
|
- lint
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
10
|
+
- submit 第二次确认
|
|
11
|
+
- typed CLI submit/create/delete
|
|
12
|
+
- typed CLI verify/readback
|
|
13
|
+
- 真实用户身份只读预览验收
|
|
13
14
|
|
|
14
15
|
## 目录结构
|
|
15
16
|
- 所有临时文件固定写到 `.codex/tmp/console-template-editor/`
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
- 不允许 build submit
|
|
34
35
|
- `work_confirmed`
|
|
35
36
|
- 用户已确认 `work`
|
|
36
|
-
- 允许执行
|
|
37
|
+
- 允许执行 typed CLI build
|
|
37
38
|
- `submit_built`
|
|
38
39
|
- `submit` 已从 `work` 构建完成
|
|
39
40
|
- `lint_passed`
|
|
@@ -41,14 +42,14 @@
|
|
|
41
42
|
- 等待第二次确认
|
|
42
43
|
- `submit_confirmed`
|
|
43
44
|
- 用户已确认 `submit`
|
|
44
|
-
- 允许执行
|
|
45
|
+
- 允许执行 typed CLI submit/create/delete
|
|
45
46
|
- `submitted`
|
|
46
|
-
-
|
|
47
|
-
-
|
|
47
|
+
- 已通过 typed CLI 提交
|
|
48
|
+
- 已有 verify/readback 与只读预览验收入口
|
|
48
49
|
|
|
49
50
|
## 强制门禁
|
|
50
|
-
- 不能跳过
|
|
51
|
-
-
|
|
51
|
+
- 不能跳过 typed CLI export/readback 或样例详情读取。
|
|
52
|
+
- 平台接口形态只作为 typed adapter 背后的契约说明,不是 Agent 直接调用入口。
|
|
52
53
|
- 没有 `work_confirmed`,不得构建 `submit`。
|
|
53
54
|
- 没有 `lint_passed`,不得做第二次确认。
|
|
54
55
|
- 没有 `submit_confirmed`,不得执行提交。
|
|
@@ -64,6 +65,6 @@
|
|
|
64
65
|
## 验收规则
|
|
65
66
|
- 接口成功不算完成。
|
|
66
67
|
- 必须至少同时满足:
|
|
67
|
-
-
|
|
68
|
-
-
|
|
68
|
+
- typed CLI verify/readback 一致
|
|
69
|
+
- 编辑页只读回显正确
|
|
69
70
|
- 预览页运行态可继续验收
|
|
@@ -4,14 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
import copy
|
|
5
5
|
import hashlib
|
|
6
6
|
import json
|
|
7
|
-
import os
|
|
8
7
|
import re
|
|
9
8
|
import sys
|
|
10
|
-
import ssl
|
|
11
|
-
import urllib.error
|
|
12
|
-
import urllib.parse
|
|
13
|
-
import urllib.request
|
|
14
|
-
from dataclasses import dataclass
|
|
15
9
|
from datetime import datetime, timezone
|
|
16
10
|
from difflib import unified_diff
|
|
17
11
|
from pathlib import Path
|
|
@@ -21,9 +15,9 @@ from typing import Any, Dict, Iterable, Optional
|
|
|
21
15
|
SHARED_SKILL_ROOT = Path(__file__).resolve().parents[2] / "bpmax-builder-shared"
|
|
22
16
|
if str(SHARED_SKILL_ROOT) not in sys.path:
|
|
23
17
|
sys.path.insert(0, str(SHARED_SKILL_ROOT))
|
|
24
|
-
from base_url import DEFAULT_BASE_URL, resolve_base_url
|
|
25
18
|
|
|
26
19
|
DEFAULT_LANGUAGE = "zhCN"
|
|
20
|
+
DEFAULT_BASE_URL = ""
|
|
27
21
|
REPO_ROOT = Path(__file__).resolve().parents[4]
|
|
28
22
|
TMP_ROOT = REPO_ROOT / ".codex" / "tmp" / "console-template-editor"
|
|
29
23
|
TMP_SUBDIRS = ("raw", "work", "meta", "submit", "diffs", "result")
|
|
@@ -44,6 +38,11 @@ OVERVIEW_REQUIRED_CONFIG_KEYS = ("title", "height", "dataSource", "config")
|
|
|
44
38
|
SUPPORTED_DATA_SOURCE_DRIVERS = ("es", "mysql", "customer", "custom_bpmax", "service")
|
|
45
39
|
OVERVIEW_SUPPORTED_ICONS = ("total", "finished", "delay_warning", "delay")
|
|
46
40
|
LINT_FORBIDDEN_PLACEHOLDERS = ("${page_size}", "${offset}")
|
|
41
|
+
LEGACY_NETWORK_DISABLED_MESSAGE = (
|
|
42
|
+
"Legacy console-template network scripts are disabled in bpmax-cli. "
|
|
43
|
+
"Use `bpmax-cli config console-template export|lint|build|submit|create|delete|verify` "
|
|
44
|
+
"so profile, capability, dry-run, confirmation, audit, and baseline checks are enforced."
|
|
45
|
+
)
|
|
47
46
|
|
|
48
47
|
from template_script_hard_rules import scan_named_script_surfaces
|
|
49
48
|
|
|
@@ -399,17 +398,296 @@ def _has_ctx_config_fallback(script: str) -> bool:
|
|
|
399
398
|
|
|
400
399
|
|
|
401
400
|
def _check_data_source_driver(script: Any, module_name: str, errors: list[str]) -> None:
|
|
402
|
-
if
|
|
401
|
+
if isinstance(script, str):
|
|
402
|
+
text = script
|
|
403
|
+
elif isinstance(script, (dict, list)):
|
|
404
|
+
text = json.dumps(script, ensure_ascii=False, sort_keys=True)
|
|
405
|
+
else:
|
|
403
406
|
return
|
|
404
|
-
if "raw-es-search" in
|
|
407
|
+
if "raw-es-search" in text:
|
|
405
408
|
errors.append(
|
|
406
409
|
f"{module_name} dataSource uses unsupported driver raw-es-search; current console frontend supports "
|
|
407
410
|
"driver: 'es' for ES data sources"
|
|
408
411
|
)
|
|
409
|
-
for match in re.finditer(r"['\"]?driver['\"]?\s*:\s*['\"]([^'\"]+)['\"]",
|
|
412
|
+
for match in re.finditer(r"['\"]?driver['\"]?\s*:\s*['\"]([^'\"]+)['\"]", text):
|
|
410
413
|
driver = match.group(1)
|
|
411
414
|
if driver and driver not in SUPPORTED_DATA_SOURCE_DRIVERS:
|
|
412
415
|
errors.append(f"{module_name} dataSource uses unsupported driver: {driver}")
|
|
416
|
+
if re.search(r"['\"]?driver['\"]?\s*:", text) and not re.search(
|
|
417
|
+
r"['\"]?driver['\"]?\s*:\s*['\"][^'\"]+['\"]", text
|
|
418
|
+
):
|
|
419
|
+
errors.append(f"{module_name} dataSource driver must be a static string literal")
|
|
420
|
+
if re.search(r"\[\s*['\"][^\]]+['\"]\s*(?:\+[^\]]*)?\]\s*:", text):
|
|
421
|
+
errors.append(f"{module_name} dataSource property names must be static identifiers")
|
|
422
|
+
if re.search(r"\bdata_set_id\b", text, re.IGNORECASE) and re.search(
|
|
423
|
+
r"raw-es-search|project/list|ESProjectList|\$esQuery|query|search", text, re.IGNORECASE
|
|
424
|
+
):
|
|
425
|
+
errors.append(f"{module_name} must not use data_set_id as an ES/project query entrypoint")
|
|
426
|
+
waiver = isinstance(script, str) and re.search(
|
|
427
|
+
r"bpmax-allow-user-scope-project-list[ \t]*:[ \t]*[^\s\r\n][^\r\n]{2,}", text, re.IGNORECASE
|
|
428
|
+
)
|
|
429
|
+
if re.search(r"/bpmax/project/list|/api/project/list|ESProjectList", text, re.IGNORECASE) and not waiver:
|
|
430
|
+
errors.append(f"{module_name} must not use project/list or ESProjectList without a non-empty allow reason")
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def _check_wildcard_fallback(value: Any, module_name: str, errors: list[str]) -> None:
|
|
434
|
+
if isinstance(value, dict):
|
|
435
|
+
for key, child in value.items():
|
|
436
|
+
if key in ("wildcard", "value") and child in ("*", "**"):
|
|
437
|
+
errors.append(f"{module_name}.{key} must not use {child} as a fallback result")
|
|
438
|
+
_check_wildcard_fallback(child, module_name, errors)
|
|
439
|
+
elif isinstance(value, list):
|
|
440
|
+
for child in value:
|
|
441
|
+
_check_wildcard_fallback(child, module_name, errors)
|
|
442
|
+
elif isinstance(value, str) and re.search(r"(?:wildcard|value)\s*:\s*['\"]\*{1,2}['\"]", value):
|
|
443
|
+
errors.append(f"{module_name} must not use wildcard * or ** as a scripted fallback result")
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
def _check_frontend_detail_counting(
|
|
447
|
+
script: Any, data_source: Any, module_name: str, errors: list[str]
|
|
448
|
+
) -> None:
|
|
449
|
+
if not isinstance(script, str):
|
|
450
|
+
return
|
|
451
|
+
source_text = data_source if isinstance(data_source, str) else json.dumps(data_source, ensure_ascii=False, sort_keys=True)
|
|
452
|
+
def strip_js_non_code(value: str) -> str:
|
|
453
|
+
output: list[str] = []
|
|
454
|
+
state = "code"
|
|
455
|
+
escaped = False
|
|
456
|
+
index = 0
|
|
457
|
+
while index < len(value):
|
|
458
|
+
char = value[index]
|
|
459
|
+
next_char = value[index + 1] if index + 1 < len(value) else ""
|
|
460
|
+
if state == "code" and char == "/" and next_char == "/":
|
|
461
|
+
state = "line"; output.extend((" ", " ")); index += 2; continue
|
|
462
|
+
if state == "code" and char == "/" and next_char == "*":
|
|
463
|
+
state = "block"; output.extend((" ", " ")); index += 2; continue
|
|
464
|
+
if state == "code" and char in ("'", '"'):
|
|
465
|
+
end = index + 1
|
|
466
|
+
quote_escaped = False
|
|
467
|
+
while end < len(value):
|
|
468
|
+
if quote_escaped: quote_escaped = False
|
|
469
|
+
elif value[end] == "\\": quote_escaped = True
|
|
470
|
+
elif value[end] == char: break
|
|
471
|
+
end += 1
|
|
472
|
+
literal = value[index + 1:end]
|
|
473
|
+
previous = next((item for item in reversed(output) if not item.isspace()), "")
|
|
474
|
+
if end < len(value) and re.fullmatch(r"[A-Za-z_$][\w$]*", literal) and previous in ("{", ",") and re.match(r"\s*:", value[end + 1:]):
|
|
475
|
+
output.extend(f" {literal} "); index = end + 1; continue
|
|
476
|
+
state = "single" if char == "'" else "double"; output.append(" "); index += 1; continue
|
|
477
|
+
if state == "code" and char == "`":
|
|
478
|
+
state = "template"; output.append(" "); index += 1; continue
|
|
479
|
+
if state == "line":
|
|
480
|
+
if char == "\n": state = "code"; output.append("\n")
|
|
481
|
+
else: output.append(" ")
|
|
482
|
+
index += 1; continue
|
|
483
|
+
if state == "block":
|
|
484
|
+
if char == "*" and next_char == "/": state = "code"; output.extend((" ", " ")); index += 2
|
|
485
|
+
else: output.append("\n" if char == "\n" else " "); index += 1
|
|
486
|
+
continue
|
|
487
|
+
if state != "code":
|
|
488
|
+
output.append("\n" if char == "\n" else " ")
|
|
489
|
+
if escaped: escaped = False
|
|
490
|
+
elif char == "\\": escaped = True
|
|
491
|
+
elif (state == "single" and char == "'") or (state == "double" and char == '"') or (state == "template" and char == "`"): state = "code"
|
|
492
|
+
index += 1; continue
|
|
493
|
+
output.append(char); index += 1
|
|
494
|
+
return "".join(output)
|
|
495
|
+
|
|
496
|
+
pagination_code = strip_js_non_code(source_text)
|
|
497
|
+
frontend_code = strip_js_non_code(script)
|
|
498
|
+
has_frontend_detail_access = bool(re.search(r"\brows\b|\bctx\s*\[|\bctx\.data\?*\.hits\?*\.hits\b|\.(?:forEach|map|reduce|filter)\s*\(|for\s*\([^)]*\b(?:of|in)\b", frontend_code, re.IGNORECASE))
|
|
499
|
+
has_metric = bool(re.search(r"count|total|amount|qty|quantity|inventory|stock|sale|销量|库存|项目数|数量|金额|合计|总数", frontend_code, re.IGNORECASE))
|
|
500
|
+
def top_level_returned_objects(code: str) -> list[str]:
|
|
501
|
+
objects: list[str] = []
|
|
502
|
+
scan_depth = 0
|
|
503
|
+
scan_index = 0
|
|
504
|
+
for match in re.finditer(r"\breturn\s*{", code):
|
|
505
|
+
while scan_index < match.start():
|
|
506
|
+
if code[scan_index] == "{": scan_depth += 1
|
|
507
|
+
elif code[scan_index] == "}": scan_depth -= 1
|
|
508
|
+
scan_index += 1
|
|
509
|
+
if scan_depth != 0:
|
|
510
|
+
continue
|
|
511
|
+
start = code.find("{", match.start())
|
|
512
|
+
depth = 0
|
|
513
|
+
for index in range(start, len(code)):
|
|
514
|
+
if code[index] == "{": depth += 1
|
|
515
|
+
elif code[index] == "}": depth -= 1
|
|
516
|
+
if depth == 0:
|
|
517
|
+
objects.append(code[start:index + 1])
|
|
518
|
+
break
|
|
519
|
+
return objects
|
|
520
|
+
|
|
521
|
+
returned_objects = top_level_returned_objects(pagination_code)
|
|
522
|
+
returned_query = returned_objects[0] if len(returned_objects) == 1 else ""
|
|
523
|
+
frontend_returned_objects = top_level_returned_objects(frontend_code)
|
|
524
|
+
frontend_returned_query = frontend_returned_objects[0] if len(frontend_returned_objects) == 1 else ""
|
|
525
|
+
def top_level_properties(object_text: str) -> dict[str, list[str]] | None:
|
|
526
|
+
if not object_text.startswith("{") or not object_text.endswith("}"):
|
|
527
|
+
return None
|
|
528
|
+
entries: list[str] = []
|
|
529
|
+
depth = 0
|
|
530
|
+
start = 1
|
|
531
|
+
for index in range(1, len(object_text) - 1):
|
|
532
|
+
char = object_text[index]
|
|
533
|
+
if char in "{[(": depth += 1
|
|
534
|
+
elif char in "}])": depth -= 1
|
|
535
|
+
elif char == "," and depth == 0:
|
|
536
|
+
entries.append(object_text[start:index]); start = index + 1
|
|
537
|
+
entries.append(object_text[start:-1])
|
|
538
|
+
fields: dict[str, list[str]] = {}
|
|
539
|
+
for entry in entries:
|
|
540
|
+
value = entry.strip()
|
|
541
|
+
if not value:
|
|
542
|
+
continue
|
|
543
|
+
if value.startswith("..."):
|
|
544
|
+
return None
|
|
545
|
+
match = re.fullmatch(r"([A-Za-z_$][\w$]*)\s*:\s*([\s\S]*)", value)
|
|
546
|
+
if not match:
|
|
547
|
+
return None
|
|
548
|
+
fields.setdefault(match.group(1), []).append(match.group(2).strip())
|
|
549
|
+
return fields
|
|
550
|
+
|
|
551
|
+
returned_fields = top_level_properties(returned_query)
|
|
552
|
+
frontend_returned_fields = top_level_properties(frontend_returned_query)
|
|
553
|
+
aggregation_value = (returned_fields.get("aggs") or returned_fields.get("aggregations") or []) if returned_fields else []
|
|
554
|
+
has_aggregation = (
|
|
555
|
+
bool(returned_fields and returned_fields.get("size") == ["0"] and len(aggregation_value) == 1 and aggregation_value[0].strip().startswith("{"))
|
|
556
|
+
if isinstance(data_source, str)
|
|
557
|
+
else isinstance(data_source, dict) and data_source.get("size") == 0
|
|
558
|
+
and (isinstance(data_source.get("aggs"), dict) or isinstance(data_source.get("aggregations"), dict))
|
|
559
|
+
)
|
|
560
|
+
map_receivers = [match.group(1).lower() for match in re.finditer(r"\b([A-Za-z_$][\w$]*)\s*\.\s*map\s*\(", frontend_code, re.IGNORECASE)]
|
|
561
|
+
def unique_frontend_field(name: str) -> str:
|
|
562
|
+
values = frontend_returned_fields.get(name, []) if frontend_returned_fields else []
|
|
563
|
+
return values[0] if len(values) == 1 else ""
|
|
564
|
+
data_expression = unique_frontend_field("data")
|
|
565
|
+
data_map_match = re.fullmatch(r"hits\s*\.\s*map\s*\(\s*\(?\s*([A-Za-z_$][\w$]*)\s*\)?\s*=>\s*\1\s*\.\s*_source\s*\)", data_expression, re.IGNORECASE)
|
|
566
|
+
page_info_fields = top_level_properties(unique_frontend_field("pageInfo"))
|
|
567
|
+
count_values = page_info_fields.get("count", []) if page_info_fields else []
|
|
568
|
+
count_expression = count_values[0] if len(count_values) == 1 else ""
|
|
569
|
+
has_only_trusted_result_map = len(map_receivers) == 1 and map_receivers[0] == "hits" and bool(data_map_match)
|
|
570
|
+
def top_level_prefix_before(code: str, object_text: str) -> str:
|
|
571
|
+
object_index = code.find(object_text) if object_text else -1
|
|
572
|
+
if object_index < 0:
|
|
573
|
+
return ""
|
|
574
|
+
output: list[str] = []
|
|
575
|
+
depth = 0
|
|
576
|
+
for char in code[:object_index]:
|
|
577
|
+
if char == "{": depth += 1; output.append(" "); continue
|
|
578
|
+
if char == "}": depth -= 1; output.append(" "); continue
|
|
579
|
+
output.append(char if depth == 0 else ("\n" if char == "\n" else " "))
|
|
580
|
+
return "".join(output)
|
|
581
|
+
frontend_top_level_prefix = top_level_prefix_before(frontend_code, frontend_returned_query)
|
|
582
|
+
hits_binding_match = re.search(r"\bconst\s+hits\s*=\s*([^;]+);?", frontend_top_level_prefix, re.IGNORECASE)
|
|
583
|
+
hits_binding = hits_binding_match.group(1) if hits_binding_match else ""
|
|
584
|
+
has_trusted_hits_binding = bool(re.fullmatch(r"\s*ctx\.data\?*\.hits\?*\.hits(?:\s*(?:\|\||\?\?)\s*\[\])?\s*", hits_binding, re.IGNORECASE))
|
|
585
|
+
total_binding_match = re.search(r"\bconst\s+total\s*=\s*([^;]+);?", frontend_top_level_prefix, re.IGNORECASE)
|
|
586
|
+
total_binding = total_binding_match.group(1) if total_binding_match else ""
|
|
587
|
+
has_trusted_total_binding = bool(re.fullmatch(r"\s*ctx\.data\?*\.hits\?*\.total\?*\.value(?:\s*(?:\|\||\?\?)\s*0)?\s*", total_binding, re.IGNORECASE)) and count_expression == "total"
|
|
588
|
+
residual_frontend_prefix = frontend_top_level_prefix
|
|
589
|
+
if hits_binding_match: residual_frontend_prefix = residual_frontend_prefix.replace(hits_binding_match.group(0), "", 1)
|
|
590
|
+
if total_binding_match: residual_frontend_prefix = residual_frontend_prefix.replace(total_binding_match.group(0), "", 1)
|
|
591
|
+
has_readonly_frontend_inputs = not re.search(r"\bhits\b|\brows\b|\bctx\s*\[", residual_frontend_prefix, re.IGNORECASE)
|
|
592
|
+
has_disallowed_frontend_loop = bool(
|
|
593
|
+
re.search(r"\.(?:forEach|reduce|filter)\s*\(|for\s*\([^)]*\b(?:of|in)\b", frontend_code)
|
|
594
|
+
) or any(receiver != "hits" for receiver in map_receivers) or bool(
|
|
595
|
+
re.search(r"\)\s*\.\s*map\s*\(", frontend_code, re.IGNORECASE)
|
|
596
|
+
) or bool(re.search(r"\[\s*\]\s*\(", frontend_code)) or (bool(map_receivers) and not has_only_trusted_result_map)
|
|
597
|
+
top_level_prefix = top_level_prefix_before(pagination_code, returned_query)
|
|
598
|
+
top_level_const_declarations = list(re.finditer(r"\bconst\s+([A-Za-z_$][\w$]*)\s*=\s*([^;]+);?", top_level_prefix))
|
|
599
|
+
residual_pagination_prefix = top_level_prefix
|
|
600
|
+
for declaration in top_level_const_declarations:
|
|
601
|
+
residual_pagination_prefix = residual_pagination_prefix.replace(declaration.group(0), "", 1)
|
|
602
|
+
residual_pagination_prefix = re.sub(r"\breturn\s*$", "", residual_pagination_prefix)
|
|
603
|
+
has_only_const_pagination_prefix = not residual_pagination_prefix.strip() and all(
|
|
604
|
+
declaration.group(1) not in ("ctx", "Number") for declaration in top_level_const_declarations
|
|
605
|
+
)
|
|
606
|
+
def assignment(name: str) -> str:
|
|
607
|
+
match = re.search(rf"\bconst\s+{re.escape(name)}\s*=\s*([^;]+)", top_level_prefix)
|
|
608
|
+
if not match:
|
|
609
|
+
return ""
|
|
610
|
+
remaining = top_level_prefix[match.end():]
|
|
611
|
+
if re.search(rf"(?:^|[;\n])\s*{re.escape(name)}\s*=", remaining):
|
|
612
|
+
return ""
|
|
613
|
+
return match.group(1)
|
|
614
|
+
|
|
615
|
+
def unwrap_number(expression: str) -> str:
|
|
616
|
+
value = expression.strip()
|
|
617
|
+
match = re.fullmatch(r"Number\s*\(([\s\S]*)\)", value)
|
|
618
|
+
return (match.group(1) if match else value).strip()
|
|
619
|
+
|
|
620
|
+
def safe_fallback(expression: str, source: re.Pattern[str]) -> bool:
|
|
621
|
+
terms = [term.strip() for term in re.split(r"\|\||\?\?", unwrap_number(expression))]
|
|
622
|
+
if not any(source.fullmatch(term) for term in terms):
|
|
623
|
+
return False
|
|
624
|
+
return all(
|
|
625
|
+
source.fullmatch(term) or (term.isdigit() and 0 < int(term) <= 1000)
|
|
626
|
+
for term in terms
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
def safe_const_expression(expression: str, source: re.Pattern[str], seen: set[str] | None = None) -> bool:
|
|
630
|
+
value = expression.strip()
|
|
631
|
+
if re.fullmatch(r"[A-Za-z_$][\w$]*", value):
|
|
632
|
+
visited = seen or set()
|
|
633
|
+
if value in visited:
|
|
634
|
+
return False
|
|
635
|
+
binding = assignment(value)
|
|
636
|
+
return bool(binding) and safe_const_expression(binding, source, visited | {value})
|
|
637
|
+
return safe_fallback(value, source)
|
|
638
|
+
|
|
639
|
+
def safe_from_expression(expression: str) -> bool:
|
|
640
|
+
value = expression.strip()
|
|
641
|
+
offset_source = re.compile(r"ctx\.pageInfo\?*\.offset")
|
|
642
|
+
if safe_const_expression(value, offset_source):
|
|
643
|
+
return True
|
|
644
|
+
formula = re.fullmatch(r"\(\s*([A-Za-z_$][\w$]*)\s*-\s*1\s*\)\s*\*\s*([A-Za-z_$][\w$]*)", value)
|
|
645
|
+
if not formula:
|
|
646
|
+
return False
|
|
647
|
+
page_source = re.compile(r"ctx\.pageInfo\?*\.(?:page|pageIndex|current)")
|
|
648
|
+
size_source = re.compile(r"(?:ctx\.pageInfo\?*\.pageSize|ctx\.config\?*\.page_size|cfg\.page_size)")
|
|
649
|
+
return safe_const_expression(formula.group(1), page_source) and safe_const_expression(formula.group(2), size_source)
|
|
650
|
+
|
|
651
|
+
def unique_field(name: str) -> str:
|
|
652
|
+
values = returned_fields.get(name, []) if returned_fields else []
|
|
653
|
+
return values[0] if len(values) == 1 else ""
|
|
654
|
+
size_source = re.compile(r"(?:ctx\.pageInfo\?*\.pageSize|ctx\.config\?*\.page_size|cfg\.page_size)")
|
|
655
|
+
page_source = re.compile(r"ctx\.pageInfo\?*\.(?:page|pageIndex|current)")
|
|
656
|
+
offset_source = re.compile(r"ctx\.pageInfo\?*\.offset")
|
|
657
|
+
has_controlled_from = safe_from_expression(unique_field("from"))
|
|
658
|
+
has_controlled_size = safe_const_expression(unique_field("size"), size_source)
|
|
659
|
+
cfg_binding = assignment("cfg")
|
|
660
|
+
has_trusted_cfg_binding = not re.search(r"\bcfg\.page_size\b", top_level_prefix) or bool(
|
|
661
|
+
re.fullmatch(r"ctx\.config(?:\s*\|\|\s*)?", cfg_binding.strip())
|
|
662
|
+
)
|
|
663
|
+
def canonical_pagination_declaration(declaration: re.Match[str]) -> bool:
|
|
664
|
+
name = declaration.group(1)
|
|
665
|
+
expression = declaration.group(2)
|
|
666
|
+
if name == "cfg":
|
|
667
|
+
return bool(re.fullmatch(r"ctx\.config(?:\s*\|\|\s*)?", expression.strip()))
|
|
668
|
+
if name == "pageSize":
|
|
669
|
+
return safe_const_expression(expression, size_source)
|
|
670
|
+
if name == "page":
|
|
671
|
+
return safe_const_expression(expression, page_source)
|
|
672
|
+
if name == "offset":
|
|
673
|
+
return safe_const_expression(expression, offset_source)
|
|
674
|
+
return False
|
|
675
|
+
has_canonical_pagination_declarations = all(canonical_pagination_declaration(item) for item in top_level_const_declarations)
|
|
676
|
+
has_server_pagination = (
|
|
677
|
+
has_controlled_from
|
|
678
|
+
and has_controlled_size
|
|
679
|
+
and has_only_const_pagination_prefix
|
|
680
|
+
and has_trusted_cfg_binding
|
|
681
|
+
and has_canonical_pagination_declarations
|
|
682
|
+
and unique_field("track_total_hits").lower() == "true"
|
|
683
|
+
and has_trusted_hits_binding
|
|
684
|
+
and has_trusted_total_binding
|
|
685
|
+
and has_readonly_frontend_inputs
|
|
686
|
+
and has_only_trusted_result_map
|
|
687
|
+
and not has_disallowed_frontend_loop
|
|
688
|
+
)
|
|
689
|
+
if has_frontend_detail_access and has_metric and not has_aggregation and not has_server_pagination:
|
|
690
|
+
errors.append(f"{module_name} must use ES size: 0 with aggs/aggregations instead of frontend row counting")
|
|
413
691
|
|
|
414
692
|
|
|
415
693
|
def _check_project_overview_script(script: Any, module_name: str, errors: list[str], warnings: list[str]) -> None:
|
|
@@ -459,11 +737,12 @@ def _check_module_config(module: Dict[str, Any], errors: list[str], warnings: li
|
|
|
459
737
|
module_check = {"id": module_id, "name": module_name, "configKeys": sorted(config.keys())}
|
|
460
738
|
checks.setdefault("modules", []).append(module_check)
|
|
461
739
|
|
|
740
|
+
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
741
|
+
|
|
462
742
|
if module_name == "图表":
|
|
463
743
|
missing = [key for key in CHART_REQUIRED_CONFIG_KEYS if config.get(key) in (None, "")]
|
|
464
744
|
if missing:
|
|
465
745
|
errors.append(f"{module_name} missing required config keys: {', '.join(missing)}")
|
|
466
|
-
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
467
746
|
chart_script = config.get("config")
|
|
468
747
|
if isinstance(chart_script, str) and "ctx.config" in chart_script and not _has_ctx_config_fallback(chart_script):
|
|
469
748
|
errors.append(f"{module_name} config script references ctx.config without fallback")
|
|
@@ -471,12 +750,11 @@ def _check_module_config(module: Dict[str, Any], errors: list[str], warnings: li
|
|
|
471
750
|
missing = [key for key in TABLE_REQUIRED_CONFIG_KEYS if config.get(key) in (None, "")]
|
|
472
751
|
if missing:
|
|
473
752
|
errors.append(f"{module_name} missing required config keys: {', '.join(missing)}")
|
|
474
|
-
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
475
753
|
table_script = config.get("config")
|
|
476
754
|
if isinstance(table_script, str):
|
|
477
755
|
compact_script = table_script.replace(" ", "").replace("\n", "")
|
|
478
756
|
if "cfg.page_size" in compact_script and "ctx.pageInfo" not in table_script and "allRows" not in table_script:
|
|
479
|
-
|
|
757
|
+
errors.append(
|
|
480
758
|
f"{module_name} config script uses cfg.page_size without ctx.pageInfo/allRows export branch; "
|
|
481
759
|
"TableSmart export may only include the first page"
|
|
482
760
|
)
|
|
@@ -484,9 +762,12 @@ def _check_module_config(module: Dict[str, Any], errors: list[str], warnings: li
|
|
|
484
762
|
missing = [key for key in OVERVIEW_REQUIRED_CONFIG_KEYS if config.get(key) in (None, "")]
|
|
485
763
|
if missing:
|
|
486
764
|
errors.append(f"{module_name} missing required config keys: {', '.join(missing)}")
|
|
487
|
-
_check_data_source_driver(config.get("dataSource"), module_name, errors)
|
|
488
765
|
_check_project_overview_script(config.get("config"), module_name, errors, warnings)
|
|
489
766
|
|
|
767
|
+
_check_wildcard_fallback(config.get("dataSource"), f"{module_name}.dataSource", errors)
|
|
768
|
+
_check_wildcard_fallback(config.get("config"), f"{module_name}.config", errors)
|
|
769
|
+
_check_frontend_detail_counting(config.get("config"), config.get("dataSource"), module_name, errors)
|
|
770
|
+
|
|
490
771
|
serialized = json.dumps(config, ensure_ascii=False)
|
|
491
772
|
for placeholder in LINT_FORBIDDEN_PLACEHOLDERS:
|
|
492
773
|
if placeholder in serialized:
|
|
@@ -883,75 +1164,15 @@ def record_submission_meta(
|
|
|
883
1164
|
return payload
|
|
884
1165
|
|
|
885
1166
|
|
|
886
|
-
@dataclass
|
|
887
|
-
class ApiClient:
|
|
888
|
-
base_url: str
|
|
889
|
-
workspace: str
|
|
890
|
-
language: str
|
|
891
|
-
cookie_header: str
|
|
892
|
-
timeout: float
|
|
893
|
-
insecure: bool = False
|
|
894
|
-
|
|
895
|
-
def _build_url(self, path: str) -> str:
|
|
896
|
-
suffix = f"$workspace={urllib.parse.quote(self.workspace)}&$language={urllib.parse.quote(self.language)}"
|
|
897
|
-
joiner = "&" if "?" in path else "?"
|
|
898
|
-
return self.base_url.rstrip("/") + path + joiner + suffix
|
|
899
|
-
|
|
900
|
-
def request(self, method: str, path: str, body: Optional[dict] = None) -> dict:
|
|
901
|
-
headers = {
|
|
902
|
-
"content-type": "application/json",
|
|
903
|
-
"cookie": self.cookie_header,
|
|
904
|
-
"accept": "application/json, text/plain, */*",
|
|
905
|
-
}
|
|
906
|
-
data = None if body is None else json.dumps(body, ensure_ascii=False).encode("utf-8")
|
|
907
|
-
req = urllib.request.Request(self._build_url(path), data=data, headers=headers, method=method)
|
|
908
|
-
context = ssl._create_unverified_context() if self.insecure else None
|
|
909
|
-
try:
|
|
910
|
-
with urllib.request.urlopen(req, timeout=self.timeout, context=context) as resp:
|
|
911
|
-
raw = resp.read().decode("utf-8", "replace")
|
|
912
|
-
except urllib.error.HTTPError as err:
|
|
913
|
-
raw = err.read().decode("utf-8", "replace")
|
|
914
|
-
raise SystemExit(f"HTTP {err.code} {path}: {raw}") from err
|
|
915
|
-
except urllib.error.URLError as err:
|
|
916
|
-
raise SystemExit(f"Request failed {path}: {err}") from err
|
|
917
|
-
payload = json.loads(raw)
|
|
918
|
-
if isinstance(payload, dict) and payload.get("code") not in (None, 0):
|
|
919
|
-
raise SystemExit(f"API error {path}: {payload}")
|
|
920
|
-
return payload
|
|
921
|
-
|
|
922
|
-
def get_template(self, template_id: int) -> dict:
|
|
923
|
-
return self.request("GET", f"/flow_page_template/{template_id}?skip_i18n=true")
|
|
924
|
-
|
|
925
|
-
def update_template(self, template_id: int, body: Dict[str, Any]) -> dict:
|
|
926
|
-
return self.request("PUT", f"/flow_page_template/{template_id}", body)
|
|
927
|
-
|
|
928
|
-
def create_template(self, body: Dict[str, Any]) -> dict:
|
|
929
|
-
return self.request("POST", "/flow_page_template", body)
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
def resolve_cookie_header(value: Optional[str]) -> str:
|
|
933
|
-
cookie = value or os.environ.get("BPMAX_COOKIE_HEADER", "")
|
|
934
|
-
if not cookie:
|
|
935
|
-
raise SystemExit("missing cookie header: pass --cookie-header or set BPMAX_COOKIE_HEADER")
|
|
936
|
-
return cookie
|
|
937
|
-
|
|
938
|
-
|
|
939
1167
|
def resolve_workspace(value: Optional[str]) -> str:
|
|
940
|
-
workspace = value or
|
|
1168
|
+
workspace = value or ""
|
|
941
1169
|
if not workspace:
|
|
942
|
-
raise SystemExit("missing workspace: pass --workspace
|
|
1170
|
+
raise SystemExit("missing workspace: pass --workspace")
|
|
943
1171
|
return workspace
|
|
944
1172
|
|
|
945
1173
|
|
|
946
|
-
def build_client(args: Any) ->
|
|
947
|
-
|
|
948
|
-
base_url=resolve_base_url(getattr(args, "base_url", None)),
|
|
949
|
-
workspace=resolve_workspace(getattr(args, "workspace", None)),
|
|
950
|
-
language=getattr(args, "language", DEFAULT_LANGUAGE),
|
|
951
|
-
cookie_header=resolve_cookie_header(getattr(args, "cookie_header", None)),
|
|
952
|
-
timeout=float(getattr(args, "timeout", 30)),
|
|
953
|
-
insecure=bool(getattr(args, "insecure", False)),
|
|
954
|
-
)
|
|
1174
|
+
def build_client(args: Any) -> None:
|
|
1175
|
+
raise SystemExit(LEGACY_NETWORK_DISABLED_MESSAGE)
|
|
955
1176
|
|
|
956
1177
|
|
|
957
1178
|
def sanitize_create_detail(detail: Dict[str, Any]) -> Dict[str, Any]:
|