bpmax-cli 0.2.1-beta.30 → 0.2.1-beta.32
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 +2 -0
- package/dist/bin.js +1883 -282
- package/dist/bin.js.map +1 -1
- package/package.json +4 -3
- package/scripts/run-source-cli.mjs +121 -0
- package/skills/bpmax-approval-matrix/SKILL.md +32 -1
- package/skills/bpmax-cli/SKILL.md +5 -0
- package/skills/bpmax-e2e-flow-config-orchestrator/SKILL.md +1 -1
- package/skills/bpmax-flow-template-editor/SKILL.md +1 -0
- package/skills/bpmax-flow-template-editor/references/flow-template-api-workflow.md +1 -0
- package/skills/bpmax-group-model-editor/SKILL.md +24 -0
- package/skills/bpmax-memory-protocol/SKILL.md +7 -6
- package/skills/bpmax-shared/SKILL.md +19 -9
- package/skills/bpmax-team-editor/SKILL.md +27 -0
- package/skills/bpmax-user/SKILL.md +26 -1
- package/skills/bpmax-user-model-editor/SKILL.md +24 -0
package/dist/bin.js
CHANGED
|
@@ -345,6 +345,20 @@ function capabilityForRequest(method, path16) {
|
|
|
345
345
|
if (normalizedMethod === "DELETE" && /^\/role\/[^/]+$/.test(normalizedPath)) return "config.role.delete";
|
|
346
346
|
if (normalizedMethod === "DELETE" && /^\/point\/[^/]+$/.test(normalizedPath)) return "config.role.delete";
|
|
347
347
|
if (normalizedMethod === "DELETE" && /^\/user_role\/[^/]+$/.test(normalizedPath)) return "config.role.delete";
|
|
348
|
+
if (normalizedMethod === "GET" && /^\/group\/\d+$/.test(normalizedPath)) return "config.team.export";
|
|
349
|
+
if (normalizedMethod === "POST" && normalizedPath === "/group") return "config.team.create";
|
|
350
|
+
if (normalizedMethod === "PUT" && /^\/group\/\d+$/.test(normalizedPath)) return "config.team.submit";
|
|
351
|
+
if (normalizedMethod === "DELETE" && /^\/group\/\d+$/.test(normalizedPath)) return "config.team.delete";
|
|
352
|
+
if (normalizedMethod === "GET" && /^\/user\/\d+$/.test(normalizedPath)) return "config.user.export";
|
|
353
|
+
if (normalizedMethod === "POST" && normalizedPath === "/user") return "config.user.create";
|
|
354
|
+
if (normalizedMethod === "PUT" && /^\/user\/\d+$/.test(normalizedPath)) return "config.user.submit";
|
|
355
|
+
if (normalizedMethod === "DELETE" && /^\/user\/\d+$/.test(normalizedPath)) return "config.user.delete";
|
|
356
|
+
for (const [resource, capability] of [["user_model", "config.user_model"], ["group_model", "config.group_model"]]) {
|
|
357
|
+
if (normalizedMethod === "GET" && (normalizedPath === `/${resource}/get_by_uuid` || new RegExp(`^/${resource}/[^/]+$`).test(normalizedPath))) return `${capability}.export`;
|
|
358
|
+
if (normalizedMethod === "POST" && normalizedPath === `/${resource}`) return `${capability}.create`;
|
|
359
|
+
if (normalizedMethod === "PUT" && new RegExp(`^/${resource}/[^/]+$`).test(normalizedPath)) return `${capability}.submit`;
|
|
360
|
+
if (normalizedMethod === "DELETE" && new RegExp(`^/${resource}/[^/]+$`).test(normalizedPath)) return `${capability}.delete`;
|
|
361
|
+
}
|
|
348
362
|
if (normalizedMethod === "POST" && normalizedPath === "/configuration") return "config.nav_config.create";
|
|
349
363
|
if (normalizedMethod === "PUT" && /^\/configuration\/[^/]+$/.test(normalizedPath)) return "config.nav_config.submit";
|
|
350
364
|
if (normalizedMethod === "DELETE" && /^\/configuration\/[^/]+$/.test(normalizedPath)) return "config.nav_config.delete";
|
|
@@ -478,15 +492,16 @@ function pluginAgentCapabilityForRequest(method, normalizedPath) {
|
|
|
478
492
|
// package.json
|
|
479
493
|
var package_default = {
|
|
480
494
|
name: "bpmax-cli",
|
|
481
|
-
version: "0.2.1-beta.
|
|
495
|
+
version: "0.2.1-beta.32",
|
|
482
496
|
description: "CLI for BPMAX environments with multi-profile config and local login callback flow",
|
|
483
497
|
type: "module",
|
|
484
498
|
bin: {
|
|
485
|
-
"bpmax-cli": "
|
|
499
|
+
"bpmax-cli": "scripts/run-source-cli.mjs"
|
|
486
500
|
},
|
|
487
501
|
files: [
|
|
488
502
|
"dist",
|
|
489
503
|
"scripts/install-skills.mjs",
|
|
504
|
+
"scripts/run-source-cli.mjs",
|
|
490
505
|
"skills",
|
|
491
506
|
"!skills/**/__pycache__/**",
|
|
492
507
|
"!skills/**/*.py[cod]",
|
|
@@ -504,7 +519,7 @@ var package_default = {
|
|
|
504
519
|
node: ">=18"
|
|
505
520
|
},
|
|
506
521
|
dependencies: {
|
|
507
|
-
"@clack/prompts": "
|
|
522
|
+
"@clack/prompts": "1.0.1",
|
|
508
523
|
axios: "^1.9.0",
|
|
509
524
|
commander: "^14.0.0",
|
|
510
525
|
jszip: "^3.10.1",
|
|
@@ -749,6 +764,9 @@ function printResult(format, value) {
|
|
|
749
764
|
switch (format) {
|
|
750
765
|
case "json":
|
|
751
766
|
console.log(JSON.stringify(withJsonNotice(value), null, 2));
|
|
767
|
+
if (!isRecord(value)) {
|
|
768
|
+
emitTextNotice();
|
|
769
|
+
}
|
|
752
770
|
return;
|
|
753
771
|
case "ndjson":
|
|
754
772
|
if (Array.isArray(value)) {
|
|
@@ -758,6 +776,7 @@ function printResult(format, value) {
|
|
|
758
776
|
} else {
|
|
759
777
|
console.log(JSON.stringify(value));
|
|
760
778
|
}
|
|
779
|
+
emitTextNotice();
|
|
761
780
|
return;
|
|
762
781
|
case "table":
|
|
763
782
|
if (Array.isArray(value)) {
|
|
@@ -767,6 +786,7 @@ function printResult(format, value) {
|
|
|
767
786
|
} else {
|
|
768
787
|
console.log(value);
|
|
769
788
|
}
|
|
789
|
+
emitTextNotice();
|
|
770
790
|
return;
|
|
771
791
|
case "pretty":
|
|
772
792
|
default:
|
|
@@ -2163,7 +2183,8 @@ async function checkSkillsSync(currentVersion, configDir = getConfigDir(), agent
|
|
|
2163
2183
|
return { current: target, target, inSync: true };
|
|
2164
2184
|
}
|
|
2165
2185
|
const current = await readSkillsStamp(configDir);
|
|
2166
|
-
|
|
2186
|
+
const inSync = agent ? current === target : current === target || current.startsWith(`${target}:`);
|
|
2187
|
+
return { current, target, inSync };
|
|
2167
2188
|
}
|
|
2168
2189
|
async function resolvePackageRootFrom(entrypointPath) {
|
|
2169
2190
|
const entryDir = path3.dirname(entrypointPath);
|
|
@@ -2328,9 +2349,9 @@ function validateAllowedPath(relative) {
|
|
|
2328
2349
|
}
|
|
2329
2350
|
return void 0;
|
|
2330
2351
|
}
|
|
2331
|
-
function validateSafeSkillName(name, issues,
|
|
2352
|
+
function validateSafeSkillName(name, issues, context2 = "Plugin skill") {
|
|
2332
2353
|
if (!safeSkillNamePattern.test(name)) {
|
|
2333
|
-
issues.push(issue2("error", "invalid_name", `${
|
|
2354
|
+
issues.push(issue2("error", "invalid_name", `${context2} name must match ${safeSkillNamePattern.source}: ${name}`));
|
|
2334
2355
|
}
|
|
2335
2356
|
}
|
|
2336
2357
|
function assertSafeStateSegment(value, label) {
|
|
@@ -2381,33 +2402,33 @@ function normalizePluginConfigAdapterManifests(value) {
|
|
|
2381
2402
|
version: typeof item.version === "string" || typeof item.version === "number" ? item.version : void 0
|
|
2382
2403
|
})).filter((item) => item.domain && item.plugin_key && item.capability_prefix && item.adapter);
|
|
2383
2404
|
}
|
|
2384
|
-
function validatePluginConfigAdapterManifest(item, issues,
|
|
2405
|
+
function validatePluginConfigAdapterManifest(item, issues, context2) {
|
|
2385
2406
|
if (!/^[a-z][a-z0-9-]*$/.test(item.domain)) {
|
|
2386
|
-
issues.push(issue2("error", "invalid_config_adapter_domain", `${
|
|
2407
|
+
issues.push(issue2("error", "invalid_config_adapter_domain", `${context2} config adapter domain must be kebab-case.`));
|
|
2387
2408
|
}
|
|
2388
2409
|
if (!/^plugin_[A-Za-z0-9_]+$/.test(item.plugin_key)) {
|
|
2389
|
-
issues.push(issue2("error", "invalid_config_adapter_plugin_key", `${
|
|
2410
|
+
issues.push(issue2("error", "invalid_config_adapter_plugin_key", `${context2} config adapter plugin_key must look like plugin_xxx.`));
|
|
2390
2411
|
}
|
|
2391
2412
|
if (!item.capability_prefix.startsWith(`config.plugin.${item.plugin_key}.`)) {
|
|
2392
|
-
issues.push(issue2("error", "invalid_config_adapter_capability", `${
|
|
2413
|
+
issues.push(issue2("error", "invalid_config_adapter_capability", `${context2} config adapter capability_prefix must start with config.plugin.${item.plugin_key}.`));
|
|
2393
2414
|
}
|
|
2394
2415
|
const normalized = item.adapter.replace(/\\/g, "/");
|
|
2395
2416
|
const parts = normalized.split("/");
|
|
2396
2417
|
if (!normalized.startsWith("config/") || parts.some((part) => part === "" || part === "." || part === "..") || normalized.startsWith("/") || path4.isAbsolute(normalized) || !normalized.endsWith(".json")) {
|
|
2397
|
-
issues.push(issue2("error", "invalid_config_adapter_path", `${
|
|
2418
|
+
issues.push(issue2("error", "invalid_config_adapter_path", `${context2} config adapter path must be a config/*.json file.`));
|
|
2398
2419
|
}
|
|
2399
2420
|
}
|
|
2400
|
-
function validatePluginConfigAdapterEndpoint(endpoints, pluginKey, operation, allowedMethods, issues,
|
|
2421
|
+
function validatePluginConfigAdapterEndpoint(endpoints, pluginKey, operation, allowedMethods, issues, context2) {
|
|
2401
2422
|
const endpoint = endpoints[operation];
|
|
2402
2423
|
if (endpoint === void 0) return;
|
|
2403
2424
|
if (!endpoint || typeof endpoint !== "object" || Array.isArray(endpoint)) {
|
|
2404
|
-
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${
|
|
2425
|
+
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${context2} config adapter endpoint ${operation} must be an object.`));
|
|
2405
2426
|
return;
|
|
2406
2427
|
}
|
|
2407
2428
|
const value = endpoint;
|
|
2408
2429
|
const method = typeof value.method === "string" ? value.method : allowedMethods[0];
|
|
2409
2430
|
if (!allowedMethods.includes(method)) {
|
|
2410
|
-
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${
|
|
2431
|
+
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${context2} config adapter endpoint ${operation} method must be ${allowedMethods.join(" or ")}.`));
|
|
2411
2432
|
}
|
|
2412
2433
|
const endpointPath2 = typeof value.path === "string" ? value.path : "";
|
|
2413
2434
|
const variants = [endpointPath2];
|
|
@@ -2419,7 +2440,7 @@ function validatePluginConfigAdapterEndpoint(endpoints, pluginKey, operation, al
|
|
|
2419
2440
|
variants.push(decoded);
|
|
2420
2441
|
current = decoded;
|
|
2421
2442
|
} catch {
|
|
2422
|
-
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${
|
|
2443
|
+
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${context2} config adapter endpoint ${operation} contains malformed URL encoding.`));
|
|
2423
2444
|
return;
|
|
2424
2445
|
}
|
|
2425
2446
|
}
|
|
@@ -2428,43 +2449,43 @@ function validatePluginConfigAdapterEndpoint(endpoints, pluginKey, operation, al
|
|
|
2428
2449
|
return !variant.startsWith("/") || variant.includes("\\") || /%(?:2e|2f|5c)/i.test(variant) || endpointParts.some((part) => part === "." || part === "..");
|
|
2429
2450
|
});
|
|
2430
2451
|
if (hasUnsafePath) {
|
|
2431
|
-
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${
|
|
2452
|
+
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${context2} config adapter endpoint ${operation} contains an unsafe path.`));
|
|
2432
2453
|
return;
|
|
2433
2454
|
}
|
|
2434
2455
|
const expectedPrefix = `/${pluginKey}`;
|
|
2435
2456
|
if (!endpointPath2 || variants.some((variant) => !variant.startsWith(`${expectedPrefix}/`) && variant !== expectedPrefix)) {
|
|
2436
|
-
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${
|
|
2457
|
+
issues.push(issue2("error", "invalid_config_adapter_endpoint", `${context2} config adapter endpoint ${operation} must stay under ${expectedPrefix}.`));
|
|
2437
2458
|
}
|
|
2438
2459
|
}
|
|
2439
|
-
function validatePluginConfigAdapterEndpoints(endpoints, pluginKey, issues,
|
|
2440
|
-
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "list", ["GET"], issues,
|
|
2441
|
-
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "get", ["GET"], issues,
|
|
2442
|
-
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "create", ["POST"], issues,
|
|
2443
|
-
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "update", ["PUT"], issues,
|
|
2444
|
-
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "test", ["POST"], issues,
|
|
2460
|
+
function validatePluginConfigAdapterEndpoints(endpoints, pluginKey, issues, context2) {
|
|
2461
|
+
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "list", ["GET"], issues, context2);
|
|
2462
|
+
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "get", ["GET"], issues, context2);
|
|
2463
|
+
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "create", ["POST"], issues, context2);
|
|
2464
|
+
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "update", ["PUT"], issues, context2);
|
|
2465
|
+
validatePluginConfigAdapterEndpoint(endpoints, pluginKey, "test", ["POST"], issues, context2);
|
|
2445
2466
|
}
|
|
2446
|
-
async function validatePluginConfigAdapterFile(skillDir, item, issues,
|
|
2467
|
+
async function validatePluginConfigAdapterFile(skillDir, item, issues, context2) {
|
|
2447
2468
|
const adapterFile = path4.join(skillDir, item.adapter);
|
|
2448
2469
|
if (!await exists2(adapterFile)) {
|
|
2449
|
-
issues.push(issue2("error", "missing_config_adapter_file", `${
|
|
2470
|
+
issues.push(issue2("error", "missing_config_adapter_file", `${context2} config adapter file not found: ${item.adapter}`));
|
|
2450
2471
|
return;
|
|
2451
2472
|
}
|
|
2452
2473
|
try {
|
|
2453
2474
|
const parsed = JSON.parse(await readFile6(adapterFile, "utf8"));
|
|
2454
2475
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed) || parsed.version !== 1 || parsed.domain !== item.domain || parsed.plugin_key !== item.plugin_key || parsed.capability_prefix !== item.capability_prefix || !parsed.endpoints || typeof parsed.endpoints !== "object" || Array.isArray(parsed.endpoints)) {
|
|
2455
|
-
issues.push(issue2("error", "invalid_config_adapter_file", `${
|
|
2476
|
+
issues.push(issue2("error", "invalid_config_adapter_file", `${context2} config adapter file must match manifest and declare endpoints: ${item.adapter}`));
|
|
2456
2477
|
return;
|
|
2457
2478
|
}
|
|
2458
|
-
validatePluginConfigAdapterEndpoints(parsed.endpoints, item.plugin_key, issues,
|
|
2479
|
+
validatePluginConfigAdapterEndpoints(parsed.endpoints, item.plugin_key, issues, context2);
|
|
2459
2480
|
const capabilities = parsed.capabilities;
|
|
2460
2481
|
if (capabilities !== void 0) {
|
|
2461
2482
|
if (!capabilities || typeof capabilities !== "object" || Array.isArray(capabilities)) {
|
|
2462
|
-
issues.push(issue2("error", "invalid_config_adapter_capabilities", `${
|
|
2483
|
+
issues.push(issue2("error", "invalid_config_adapter_capabilities", `${context2} config adapter capabilities must be an object: ${item.adapter}`));
|
|
2463
2484
|
return;
|
|
2464
2485
|
}
|
|
2465
2486
|
for (const value of Object.values(capabilities)) {
|
|
2466
2487
|
if (typeof value !== "string" || !value.startsWith(`config.plugin.${item.plugin_key}.`)) {
|
|
2467
|
-
issues.push(issue2("error", "invalid_config_adapter_capabilities", `${
|
|
2488
|
+
issues.push(issue2("error", "invalid_config_adapter_capabilities", `${context2} config adapter capabilities must stay under config.plugin.${item.plugin_key}.`));
|
|
2468
2489
|
return;
|
|
2469
2490
|
}
|
|
2470
2491
|
}
|
|
@@ -2472,53 +2493,53 @@ async function validatePluginConfigAdapterFile(skillDir, item, issues, context)
|
|
|
2472
2493
|
const work = parsed.work;
|
|
2473
2494
|
if (work !== void 0) {
|
|
2474
2495
|
if (!work || typeof work !== "object" || Array.isArray(work)) {
|
|
2475
|
-
issues.push(issue2("error", "invalid_config_adapter_work", `${
|
|
2496
|
+
issues.push(issue2("error", "invalid_config_adapter_work", `${context2} config adapter work must be an object: ${item.adapter}`));
|
|
2476
2497
|
return;
|
|
2477
2498
|
}
|
|
2478
2499
|
const lintPath = work.lint;
|
|
2479
2500
|
if (lintPath !== void 0) {
|
|
2480
2501
|
if (typeof lintPath !== "string") {
|
|
2481
|
-
issues.push(issue2("error", "invalid_config_adapter_lint", `${
|
|
2502
|
+
issues.push(issue2("error", "invalid_config_adapter_lint", `${context2} config adapter work.lint must be a lint/*.json path: ${item.adapter}`));
|
|
2482
2503
|
return;
|
|
2483
2504
|
}
|
|
2484
2505
|
const normalizedLintPath = lintPath.replace(/\\/g, "/");
|
|
2485
2506
|
const lintParts = normalizedLintPath.split("/");
|
|
2486
2507
|
if (!normalizedLintPath.startsWith("lint/") || lintParts.some((part) => part === "" || part === "." || part === "..") || normalizedLintPath.startsWith("/") || path4.isAbsolute(normalizedLintPath) || !normalizedLintPath.endsWith(".json")) {
|
|
2487
|
-
issues.push(issue2("error", "invalid_config_adapter_lint", `${
|
|
2508
|
+
issues.push(issue2("error", "invalid_config_adapter_lint", `${context2} config adapter work.lint must be a lint/*.json path: ${item.adapter}`));
|
|
2488
2509
|
return;
|
|
2489
2510
|
}
|
|
2490
2511
|
const lintFile = path4.join(skillDir, normalizedLintPath);
|
|
2491
2512
|
if (!await exists2(lintFile)) {
|
|
2492
|
-
issues.push(issue2("error", "missing_config_adapter_lint", `${
|
|
2513
|
+
issues.push(issue2("error", "missing_config_adapter_lint", `${context2} config adapter lint file not found: ${normalizedLintPath}`));
|
|
2493
2514
|
return;
|
|
2494
2515
|
}
|
|
2495
2516
|
const lint = JSON.parse(await readFile6(lintFile, "utf8"));
|
|
2496
2517
|
if (!lint || typeof lint !== "object" || Array.isArray(lint) || lint.version !== 1 || lint.domain !== item.domain || lint.plugin_key !== item.plugin_key || !Array.isArray(lint.rules) || !lint.rules.length) {
|
|
2497
|
-
issues.push(issue2("error", "invalid_config_adapter_lint", `${
|
|
2518
|
+
issues.push(issue2("error", "invalid_config_adapter_lint", `${context2} config adapter lint file must match adapter manifest and declare rules: ${normalizedLintPath}`));
|
|
2498
2519
|
return;
|
|
2499
2520
|
}
|
|
2500
2521
|
}
|
|
2501
2522
|
}
|
|
2502
2523
|
} catch (error) {
|
|
2503
|
-
issues.push(issue2("error", "invalid_config_adapter_file", `${
|
|
2524
|
+
issues.push(issue2("error", "invalid_config_adapter_file", `${context2} config adapter file must be valid JSON: ${item.adapter}`));
|
|
2504
2525
|
}
|
|
2505
2526
|
}
|
|
2506
|
-
function validatePluginLintManifest(item, issues,
|
|
2527
|
+
function validatePluginLintManifest(item, issues, context2) {
|
|
2507
2528
|
if (item.domain !== "flow-template-node") {
|
|
2508
|
-
issues.push(issue2("error", "unsupported_lint_domain", `${
|
|
2529
|
+
issues.push(issue2("error", "unsupported_lint_domain", `${context2} lint domain is not supported: ${item.domain}`));
|
|
2509
2530
|
}
|
|
2510
2531
|
if (!/^plugin_[A-Za-z0-9_]+$/.test(item.plugin_key)) {
|
|
2511
|
-
issues.push(issue2("error", "invalid_lint_plugin_key", `${
|
|
2532
|
+
issues.push(issue2("error", "invalid_lint_plugin_key", `${context2} lint plugin_key must look like plugin_xxx.`));
|
|
2512
2533
|
}
|
|
2513
2534
|
const normalized = item.path.replace(/\\/g, "/");
|
|
2514
2535
|
const parts = normalized.split("/");
|
|
2515
2536
|
if (!normalized.startsWith("lint/") || parts.some((part) => part === "" || part === "." || part === "..") || normalized.startsWith("/") || path4.isAbsolute(normalized) || !normalized.endsWith(".json")) {
|
|
2516
|
-
issues.push(issue2("error", "invalid_lint_path", `${
|
|
2537
|
+
issues.push(issue2("error", "invalid_lint_path", `${context2} lint path must be a lint/*.json file.`));
|
|
2517
2538
|
}
|
|
2518
2539
|
if (item.paths) {
|
|
2519
2540
|
item.paths.forEach((scanPath) => {
|
|
2520
2541
|
if (!isAllowedPluginConfigScanPath(scanPath)) {
|
|
2521
|
-
issues.push(issue2("error", "invalid_lint_scan_path", `${
|
|
2542
|
+
issues.push(issue2("error", "invalid_lint_scan_path", `${context2} lint scan path is not supported: ${scanPath}`));
|
|
2522
2543
|
}
|
|
2523
2544
|
});
|
|
2524
2545
|
}
|
|
@@ -3703,7 +3724,7 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
3703
3724
|
deviceCode
|
|
3704
3725
|
});
|
|
3705
3726
|
config.profiles[profile.name] = updateProfileAuth(config.profiles[profile.name], result);
|
|
3706
|
-
const
|
|
3727
|
+
const safeUser3 = config.profiles[profile.name].user;
|
|
3707
3728
|
await save(config);
|
|
3708
3729
|
let capabilitiesProbe;
|
|
3709
3730
|
let pluginSkillUpdates;
|
|
@@ -3733,7 +3754,7 @@ function registerAuthCommands(program2, deps = {}) {
|
|
|
3733
3754
|
ok: true,
|
|
3734
3755
|
profile: profile.name,
|
|
3735
3756
|
login: "authenticated",
|
|
3736
|
-
user:
|
|
3757
|
+
user: safeUser3,
|
|
3737
3758
|
...capabilitiesProbe ? { capabilities_probe: capabilitiesProbe } : {},
|
|
3738
3759
|
...pluginSkillUpdates ? { plugin_skill_updates: pluginSkillUpdates } : {},
|
|
3739
3760
|
...nextCommands ? { next_commands: nextCommands } : {}
|
|
@@ -4224,6 +4245,13 @@ import { createHash as createHash4 } from "crypto";
|
|
|
4224
4245
|
import { mkdir as mkdir5, readdir as readdir2, readFile as readFile8, writeFile as writeFile5 } from "fs/promises";
|
|
4225
4246
|
import path5 from "path";
|
|
4226
4247
|
import { isDeepStrictEqual } from "util";
|
|
4248
|
+
function numericConfigResourcePath(resource, id, query = "") {
|
|
4249
|
+
const normalized = id.trim();
|
|
4250
|
+
if (!/^\d+$/.test(normalized) || normalized === "0") {
|
|
4251
|
+
throw new Error(`${resource} config id \u5FC5\u987B\u662F\u6B63\u6574\u6570\uFF1B\u8DE8\u73AF\u5883 UUID \u8BF7\u5148\u4F7F\u7528 config resolve-id\u3002`);
|
|
4252
|
+
}
|
|
4253
|
+
return `/${resource}/${encodeURIComponent(normalized)}${query}`;
|
|
4254
|
+
}
|
|
4227
4255
|
function configWorkflowError(message, details) {
|
|
4228
4256
|
return Object.assign(new Error(message), details);
|
|
4229
4257
|
}
|
|
@@ -4232,6 +4260,9 @@ function errorStatus(error) {
|
|
|
4232
4260
|
const status = Number(error.response.status);
|
|
4233
4261
|
return Number.isFinite(status) ? status : void 0;
|
|
4234
4262
|
}
|
|
4263
|
+
function workflowErrorCode(error) {
|
|
4264
|
+
return isRecord3(error) && typeof error.code === "string" ? error.code : void 0;
|
|
4265
|
+
}
|
|
4235
4266
|
function isJsonParseFailure(error) {
|
|
4236
4267
|
const message = error instanceof Error ? error.message : String(error ?? "");
|
|
4237
4268
|
return error instanceof SyntaxError || /Unexpected end of JSON input|JSON.*(?:parse|position)|unterminated JSON/i.test(message);
|
|
@@ -4250,6 +4281,8 @@ var NAV_DEFAULT_NAME_BY_TYPE = {
|
|
|
4250
4281
|
shortcut_mobile: "\u79FB\u52A8\u5FEB\u6377\u5165\u53E3"
|
|
4251
4282
|
};
|
|
4252
4283
|
var MAX_FORM_TEMPLATE_NAME_LENGTH = 20;
|
|
4284
|
+
var MAX_DATASET_CUSTOM_KEY_LENGTH = 20;
|
|
4285
|
+
var MAX_PAGE_TEMPLATE_NAME_LENGTH = 20;
|
|
4253
4286
|
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/;
|
|
4254
4287
|
var FORM_TEMPLATE_ID_PROP_PATTERN = /(?:\btemplate_id\b|['"]template_id['"])\s*:\s*\d+\b|\.template_id\s*=\s*\d+\b|\[['"]template_id['"]]\s*=\s*\d+\b/;
|
|
4255
4288
|
var UUID_RE = /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/;
|
|
@@ -4272,6 +4305,10 @@ var LOCAL_UUID_DOMAIN_DIR = {
|
|
|
4272
4305
|
dataset: "think_data_set",
|
|
4273
4306
|
"dataset-field": "think_data_set_field",
|
|
4274
4307
|
role: "think_role",
|
|
4308
|
+
team: "think_group",
|
|
4309
|
+
user: "think_user",
|
|
4310
|
+
"user-model": "think_user_model",
|
|
4311
|
+
"group-model": "think_group_model",
|
|
4275
4312
|
workspace: "think_workspace"
|
|
4276
4313
|
};
|
|
4277
4314
|
var REMOTE_UUID_EXPORT_PATH = {
|
|
@@ -4280,7 +4317,9 @@ var REMOTE_UUID_EXPORT_PATH = {
|
|
|
4280
4317
|
"filter-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
|
|
4281
4318
|
"project-detail-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
|
|
4282
4319
|
"step-detail-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
|
|
4283
|
-
"console-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}
|
|
4320
|
+
"console-template": (uuid) => `/flow_page_template/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
|
|
4321
|
+
"user-model": (uuid) => `/user_model/get_by_uuid?uuid=${encodeURIComponent(uuid)}`,
|
|
4322
|
+
"group-model": (uuid) => `/group_model/get_by_uuid?uuid=${encodeURIComponent(uuid)}`
|
|
4284
4323
|
};
|
|
4285
4324
|
var CONFIG_DOMAINS = {
|
|
4286
4325
|
"form-template": {
|
|
@@ -4489,6 +4528,70 @@ var CONFIG_DOMAINS = {
|
|
|
4489
4528
|
writeEndpoints: ["POST /api/role", "PUT /api/role/:id", "DELETE /api/role/:id", "POST/PUT/DELETE /api/point", "POST/DELETE /api/user_role"],
|
|
4490
4529
|
notes: ["Role submit executes point operations, role create/update, then member operations with role_id injection."]
|
|
4491
4530
|
},
|
|
4531
|
+
team: {
|
|
4532
|
+
capability: "config.team",
|
|
4533
|
+
exportPath: (id) => numericConfigResourcePath("group", id),
|
|
4534
|
+
exportStatus: "supported",
|
|
4535
|
+
buildStatus: "supported",
|
|
4536
|
+
submitStatus: "supported",
|
|
4537
|
+
createPath: "/group",
|
|
4538
|
+
createMethod: "POST",
|
|
4539
|
+
deletePath: (id) => numericConfigResourcePath("group", id),
|
|
4540
|
+
deleteMethod: "DELETE",
|
|
4541
|
+
submitPath: (id) => numericConfigResourcePath("group", id),
|
|
4542
|
+
submitMethod: "PUT",
|
|
4543
|
+
readEndpoints: ["GET /api/group/:id"],
|
|
4544
|
+
writeEndpoints: ["POST /api/group", "PUT /api/group/:id", "DELETE /api/group/:id"],
|
|
4545
|
+
notes: ["Team maps to the BPMAX group tree and manages parent, model, permission, and administrator configuration."]
|
|
4546
|
+
},
|
|
4547
|
+
user: {
|
|
4548
|
+
capability: "config.user",
|
|
4549
|
+
exportPath: (id) => numericConfigResourcePath("user", id, "?only_user_role=1"),
|
|
4550
|
+
exportStatus: "supported",
|
|
4551
|
+
buildStatus: "supported",
|
|
4552
|
+
submitStatus: "supported",
|
|
4553
|
+
createPath: "/user",
|
|
4554
|
+
createMethod: "POST",
|
|
4555
|
+
deletePath: (id) => numericConfigResourcePath("user", id),
|
|
4556
|
+
deleteMethod: "DELETE",
|
|
4557
|
+
submitPath: (id) => numericConfigResourcePath("user", id),
|
|
4558
|
+
submitMethod: "PUT",
|
|
4559
|
+
readEndpoints: ["GET /api/user/:id?only_user_role=1"],
|
|
4560
|
+
writeEndpoints: ["POST /api/user", "PUT /api/user/:id", "DELETE /api/user/:id"],
|
|
4561
|
+
notes: ["User export is privacy-safe. Phone is accepted only in explicit create work and is never copied from readback into edit work."]
|
|
4562
|
+
},
|
|
4563
|
+
"user-model": {
|
|
4564
|
+
capability: "config.user_model",
|
|
4565
|
+
exportPath: (id) => numericConfigResourcePath("user_model", id, "?with_role=1"),
|
|
4566
|
+
exportStatus: "supported",
|
|
4567
|
+
buildStatus: "supported",
|
|
4568
|
+
submitStatus: "supported",
|
|
4569
|
+
createPath: "/user_model",
|
|
4570
|
+
createMethod: "POST",
|
|
4571
|
+
deletePath: (id) => numericConfigResourcePath("user_model", id),
|
|
4572
|
+
deleteMethod: "DELETE",
|
|
4573
|
+
submitPath: (id) => numericConfigResourcePath("user_model", id),
|
|
4574
|
+
submitMethod: "PUT",
|
|
4575
|
+
readEndpoints: ["GET /api/user_model/:id?with_role=1", "GET /api/user_model/get_by_uuid?uuid=:uuid"],
|
|
4576
|
+
writeEndpoints: ["POST /api/user_model", "PUT /api/user_model/:id", "DELETE /api/user_model/:id"],
|
|
4577
|
+
notes: ["User-model normalizes permission, object events, automatic flow triggers, role, form-template, and UUID fields."]
|
|
4578
|
+
},
|
|
4579
|
+
"group-model": {
|
|
4580
|
+
capability: "config.group_model",
|
|
4581
|
+
exportPath: (id) => numericConfigResourcePath("group_model", id),
|
|
4582
|
+
exportStatus: "supported",
|
|
4583
|
+
buildStatus: "supported",
|
|
4584
|
+
submitStatus: "supported",
|
|
4585
|
+
createPath: "/group_model",
|
|
4586
|
+
createMethod: "POST",
|
|
4587
|
+
deletePath: (id) => numericConfigResourcePath("group_model", id),
|
|
4588
|
+
deleteMethod: "DELETE",
|
|
4589
|
+
submitPath: (id) => numericConfigResourcePath("group_model", id),
|
|
4590
|
+
submitMethod: "PUT",
|
|
4591
|
+
readEndpoints: ["GET /api/group_model/:id", "GET /api/group_model/get_by_uuid?uuid=:uuid"],
|
|
4592
|
+
writeEndpoints: ["POST /api/group_model", "PUT /api/group_model/:id", "DELETE /api/group_model/:id"],
|
|
4593
|
+
notes: ["Group-model normalizes permission, child models, object events, automatic flow triggers, form-template, and UUID fields."]
|
|
4594
|
+
},
|
|
4492
4595
|
"nav-config": {
|
|
4493
4596
|
capability: "config.nav_config",
|
|
4494
4597
|
exportStatus: "supported",
|
|
@@ -4836,7 +4939,7 @@ function validateFlowTemplateFormDrivenCreateBaseline(value, errors, options = {
|
|
|
4836
4939
|
if (!options.force && !hasConfiguredFlowTemplateFormSource(value, meta)) {
|
|
4837
4940
|
return;
|
|
4838
4941
|
}
|
|
4839
|
-
const
|
|
4942
|
+
const context2 = options.context || "flow-template create";
|
|
4840
4943
|
const missing = [];
|
|
4841
4944
|
const hideFields = Array.isArray(meta.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
4842
4945
|
for (const field of FORM_DRIVEN_CREATE_HIDE_FIELDS) {
|
|
@@ -4853,7 +4956,7 @@ function validateFlowTemplateFormDrivenCreateBaseline(value, errors, options = {
|
|
|
4853
4956
|
if (missing.length === 0) {
|
|
4854
4957
|
return;
|
|
4855
4958
|
}
|
|
4856
|
-
const message = `${
|
|
4959
|
+
const message = `${context2} for form-driven project creation requires default system-field hiding and a project name template: ${missing.join("; ")}.`;
|
|
4857
4960
|
if (errors) {
|
|
4858
4961
|
errors.push(message);
|
|
4859
4962
|
return;
|
|
@@ -6599,6 +6702,17 @@ function lintConsoleTemplateWork(value, errors, warnings) {
|
|
|
6599
6702
|
}
|
|
6600
6703
|
});
|
|
6601
6704
|
}
|
|
6705
|
+
function lintFilterTemplateWork(value, errors) {
|
|
6706
|
+
const content = parseTemplateContent(value, errors);
|
|
6707
|
+
if (!isRecord3(content) || !Array.isArray(content.config)) {
|
|
6708
|
+
return;
|
|
6709
|
+
}
|
|
6710
|
+
content.config.forEach((item, index) => {
|
|
6711
|
+
if (isRecord3(item) && item.console === true) {
|
|
6712
|
+
errors.push(`filter-template content.config[${index}].console=true is reserved for console/dashboard filters and is not allowed in ordinary filter templates.`);
|
|
6713
|
+
}
|
|
6714
|
+
});
|
|
6715
|
+
}
|
|
6602
6716
|
function listTemplateNodeLabel(node) {
|
|
6603
6717
|
return [
|
|
6604
6718
|
node.title,
|
|
@@ -7244,11 +7358,32 @@ function validateExpectedType(domain, definition, data) {
|
|
|
7244
7358
|
);
|
|
7245
7359
|
}
|
|
7246
7360
|
}
|
|
7361
|
+
function validatePageTemplateName(work, errors) {
|
|
7362
|
+
const basic = isRecord3(work.basic) ? work.basic : work;
|
|
7363
|
+
const name = normalizeText(basic.name ?? "");
|
|
7364
|
+
if (!name || name.length <= MAX_PAGE_TEMPLATE_NAME_LENGTH) {
|
|
7365
|
+
return;
|
|
7366
|
+
}
|
|
7367
|
+
const message = `page-template name is too long (${name.length} > ${MAX_PAGE_TEMPLATE_NAME_LENGTH}); BPMAX flow_page_template.name rejects longer names.`;
|
|
7368
|
+
if (errors) {
|
|
7369
|
+
errors.push(message);
|
|
7370
|
+
return;
|
|
7371
|
+
}
|
|
7372
|
+
throw new Error(message);
|
|
7373
|
+
}
|
|
7247
7374
|
function normalizePageTemplatePayload(domain, work) {
|
|
7248
7375
|
const definition = CONFIG_DOMAINS[domain];
|
|
7376
|
+
validatePageTemplateName(work);
|
|
7249
7377
|
if (domain === "list-template") {
|
|
7250
7378
|
validateListTemplateActionGate(work);
|
|
7251
7379
|
}
|
|
7380
|
+
if (domain === "filter-template") {
|
|
7381
|
+
const errors = [];
|
|
7382
|
+
lintFilterTemplateWork(work, errors);
|
|
7383
|
+
if (errors.length) {
|
|
7384
|
+
throw new Error(`filter-template lint failed: ${errors.join("; ")}`);
|
|
7385
|
+
}
|
|
7386
|
+
}
|
|
7252
7387
|
if (domain === "console-template") {
|
|
7253
7388
|
const errors = [];
|
|
7254
7389
|
const warnings = [];
|
|
@@ -7519,7 +7654,7 @@ function normalizeDatasetPayload(work) {
|
|
|
7519
7654
|
payload.flow_key = flowKey;
|
|
7520
7655
|
}
|
|
7521
7656
|
const id = work.id;
|
|
7522
|
-
if (id !== void 0 && id !== null && id !== "") {
|
|
7657
|
+
if (mode !== "create" && id !== void 0 && id !== null && id !== "") {
|
|
7523
7658
|
payload.id = id;
|
|
7524
7659
|
}
|
|
7525
7660
|
validateDatasetPayload(payload, mode === "create" ? "create" : "edit");
|
|
@@ -7535,9 +7670,18 @@ function validateDatasetPayload(payload, mode) {
|
|
|
7535
7670
|
if (required.length) {
|
|
7536
7671
|
throw new Error(`dataset ${mode} requires identity fields: ${required.map(([key]) => key).join(", ")}.`);
|
|
7537
7672
|
}
|
|
7673
|
+
const customKey = String(payload.custom_key ?? "");
|
|
7674
|
+
if (customKey.length > MAX_DATASET_CUSTOM_KEY_LENGTH) {
|
|
7675
|
+
throw new Error(
|
|
7676
|
+
`dataset custom_key is too long (${customKey.length} > ${MAX_DATASET_CUSTOM_KEY_LENGTH}); the BPMAX dataset storage column rejects longer identities.`
|
|
7677
|
+
);
|
|
7678
|
+
}
|
|
7538
7679
|
if (mode === "edit" && (payload.id === void 0 || payload.id === null || String(payload.id).trim() === "")) {
|
|
7539
7680
|
throw new Error("dataset edit requires payload.id to preserve dataset identity.");
|
|
7540
7681
|
}
|
|
7682
|
+
if (mode === "create" && payload.id !== void 0 && payload.id !== null && String(payload.id).trim() !== "") {
|
|
7683
|
+
throw new Error("dataset create \u7981\u6B62\u643A\u5E26 payload.id\uFF1B\u6570\u636E\u96C6 ID \u5FC5\u987B\u7531\u5E73\u53F0\u751F\u6210\u3002");
|
|
7684
|
+
}
|
|
7541
7685
|
if (!Array.isArray(payload.fields) || payload.fields.length === 0) {
|
|
7542
7686
|
throw new Error(`dataset ${mode} requires at least one relationFields field key.`);
|
|
7543
7687
|
}
|
|
@@ -7624,6 +7768,14 @@ function executedFields() {
|
|
|
7624
7768
|
confirm_required: false
|
|
7625
7769
|
};
|
|
7626
7770
|
}
|
|
7771
|
+
function configPayloadForOutput(domain, payload) {
|
|
7772
|
+
if (domain !== "user") return payload;
|
|
7773
|
+
const result = { ...payload };
|
|
7774
|
+
if (Object.prototype.hasOwnProperty.call(result, "phone")) {
|
|
7775
|
+
result.phone = "[REDACTED]";
|
|
7776
|
+
}
|
|
7777
|
+
return result;
|
|
7778
|
+
}
|
|
7627
7779
|
function validateDatasetFieldCreatePayload(payload) {
|
|
7628
7780
|
if (!isRecord3(payload)) {
|
|
7629
7781
|
throw new Error("dataset-field create requires an object payload.");
|
|
@@ -7871,11 +8023,11 @@ function extractEmbeddedSubformOrder(template, field) {
|
|
|
7871
8023
|
if (!item || !isRecord3(item.value)) {
|
|
7872
8024
|
return [];
|
|
7873
8025
|
}
|
|
7874
|
-
const
|
|
7875
|
-
if (Array.isArray(
|
|
7876
|
-
return flattenFieldOrder(
|
|
8026
|
+
const rows2 = item.value.value;
|
|
8027
|
+
if (Array.isArray(rows2) && Array.isArray(rows2[0])) {
|
|
8028
|
+
return flattenFieldOrder(rows2[0]);
|
|
7877
8029
|
}
|
|
7878
|
-
return flattenFieldOrder(
|
|
8030
|
+
return flattenFieldOrder(rows2);
|
|
7879
8031
|
}
|
|
7880
8032
|
function ordersMismatch(orders) {
|
|
7881
8033
|
const comparable2 = orders.filter((order) => order.length > 0);
|
|
@@ -8766,6 +8918,327 @@ function validateWorkspaceSubmitClears(payload, current) {
|
|
|
8766
8918
|
}
|
|
8767
8919
|
}
|
|
8768
8920
|
}
|
|
8921
|
+
var USER_SENSITIVE_CONFIG_FIELDS = [
|
|
8922
|
+
"password",
|
|
8923
|
+
"api_key",
|
|
8924
|
+
"authorization",
|
|
8925
|
+
"token",
|
|
8926
|
+
"cookie",
|
|
8927
|
+
"session",
|
|
8928
|
+
"create_ip",
|
|
8929
|
+
"last_login_ip",
|
|
8930
|
+
"last_login_time"
|
|
8931
|
+
];
|
|
8932
|
+
function configSource(work) {
|
|
8933
|
+
return isRecord3(work.basic) ? { ...work, ...work.basic } : work;
|
|
8934
|
+
}
|
|
8935
|
+
function normalizedNumberList(value, field) {
|
|
8936
|
+
const values = Array.isArray(value) ? value : typeof value === "string" ? value.split(",").map((item) => item.trim()).filter(Boolean) : value === void 0 || value === null || value === "" ? [] : [value];
|
|
8937
|
+
const result = values.map((item) => Number(item));
|
|
8938
|
+
if (result.some((item) => !Number.isSafeInteger(item) || item <= 0)) {
|
|
8939
|
+
throw new Error(`${field} \u5FC5\u987B\u53EA\u5305\u542B\u6B63\u6574\u6570 ID\u3002`);
|
|
8940
|
+
}
|
|
8941
|
+
return [...new Set(result)];
|
|
8942
|
+
}
|
|
8943
|
+
function normalizedOptionalId(value, field, allowZero = true) {
|
|
8944
|
+
if (value === void 0 || value === null || value === "") return null;
|
|
8945
|
+
const result = Number(value);
|
|
8946
|
+
if (!Number.isSafeInteger(result) || result < (allowZero ? 0 : 1)) {
|
|
8947
|
+
throw new Error(`${field} \u5FC5\u987B\u662F${allowZero ? "\u975E\u8D1F" : "\u6B63"}\u6574\u6570 ID\u3002`);
|
|
8948
|
+
}
|
|
8949
|
+
return result;
|
|
8950
|
+
}
|
|
8951
|
+
function normalizedJsonValue(value, field, kind) {
|
|
8952
|
+
let parsed = value;
|
|
8953
|
+
if (typeof value === "string") {
|
|
8954
|
+
try {
|
|
8955
|
+
parsed = JSON.parse(value);
|
|
8956
|
+
} catch {
|
|
8957
|
+
throw new Error(`${field} \u5FC5\u987B\u662F\u6709\u6548 JSON\u3002`);
|
|
8958
|
+
}
|
|
8959
|
+
}
|
|
8960
|
+
if (kind === "array" && !Array.isArray(parsed)) {
|
|
8961
|
+
throw new Error(`${field} \u5FC5\u987B\u662F\u6570\u7EC4\u3002`);
|
|
8962
|
+
}
|
|
8963
|
+
if (kind === "object" && !isRecord3(parsed)) {
|
|
8964
|
+
throw new Error(`${field} \u5FC5\u987B\u662F\u5BF9\u8C61\u3002`);
|
|
8965
|
+
}
|
|
8966
|
+
return parsed;
|
|
8967
|
+
}
|
|
8968
|
+
function normalizeTeamPayload(work, raw) {
|
|
8969
|
+
const source = configSource(work);
|
|
8970
|
+
if (source.admin_users === void 0 && Array.isArray(source.admins)) {
|
|
8971
|
+
source.admin_users = source.admins.filter(isRecord3).map((item) => item.id);
|
|
8972
|
+
}
|
|
8973
|
+
const payload = pickDefined(source, [
|
|
8974
|
+
"name",
|
|
8975
|
+
"intro",
|
|
8976
|
+
"parent_id",
|
|
8977
|
+
"model_id",
|
|
8978
|
+
"platform_id",
|
|
8979
|
+
"permission",
|
|
8980
|
+
"admin_users",
|
|
8981
|
+
"meta_form"
|
|
8982
|
+
]);
|
|
8983
|
+
if (work.mode === "create" && payload.platform_id !== void 0) {
|
|
8984
|
+
throw new Error("team create \u4E0D\u5141\u8BB8\u624B\u5DE5\u6307\u5B9A platform_id\uFF1B\u8BE5\u5916\u90E8\u7ED1\u5B9A\u5B57\u6BB5\u5FC5\u987B\u7531\u5E73\u53F0\u7BA1\u7406\u3002");
|
|
8985
|
+
}
|
|
8986
|
+
payload.name = String(payload.name ?? "").trim();
|
|
8987
|
+
if (!payload.name || String(payload.name).length > 100) {
|
|
8988
|
+
throw new Error("team.name \u5FC5\u987B\u662F 1-100 \u4E2A\u5B57\u7B26\u3002");
|
|
8989
|
+
}
|
|
8990
|
+
const parentId = normalizedOptionalId(payload.parent_id, "team.parent_id");
|
|
8991
|
+
payload.parent_id = parentId ?? 0;
|
|
8992
|
+
const currentId = normalizedOptionalId(work.id ?? source.id, "team.id", false);
|
|
8993
|
+
if (currentId && Number(payload.parent_id) === currentId) {
|
|
8994
|
+
throw new Error("team.parent_id \u4E0D\u80FD\u6307\u5411\u56E2\u961F\u81EA\u8EAB\u3002");
|
|
8995
|
+
}
|
|
8996
|
+
const modelId = normalizedOptionalId(payload.model_id, "team.model_id");
|
|
8997
|
+
payload.model_id = modelId || null;
|
|
8998
|
+
if (payload.platform_id !== void 0) {
|
|
8999
|
+
payload.platform_id = normalizedOptionalId(payload.platform_id, "team.platform_id");
|
|
9000
|
+
}
|
|
9001
|
+
if (raw && Object.prototype.hasOwnProperty.call(raw, "platform_id")) {
|
|
9002
|
+
if (payload.platform_id === void 0 || Number(payload.platform_id) !== Number(raw.platform_id)) {
|
|
9003
|
+
throw new Error("team edit \u5FC5\u987B\u539F\u6837\u4FDD\u7559\u5BFC\u51FA\u65F6\u7684 platform_id\uFF1B\u4E0D\u5F97\u5220\u9664\u6216\u4FEE\u6539\u5916\u90E8\u5E73\u53F0\u7ED1\u5B9A\u3002");
|
|
9004
|
+
}
|
|
9005
|
+
}
|
|
9006
|
+
if (payload.permission !== void 0 && payload.permission !== null) {
|
|
9007
|
+
payload.permission = normalizedJsonValue(payload.permission, "team.permission", "object");
|
|
9008
|
+
}
|
|
9009
|
+
if (payload.admin_users !== void 0) {
|
|
9010
|
+
payload.admin_users = normalizedNumberList(payload.admin_users, "team.admin_users").join(",");
|
|
9011
|
+
}
|
|
9012
|
+
if (payload.meta_form !== void 0 && payload.meta_form !== null) {
|
|
9013
|
+
payload.meta_form = normalizedJsonValue(payload.meta_form, "team.meta_form", "object");
|
|
9014
|
+
}
|
|
9015
|
+
return payload;
|
|
9016
|
+
}
|
|
9017
|
+
function normalizeUserPayload(work) {
|
|
9018
|
+
const source = configSource(work);
|
|
9019
|
+
for (const field of USER_SENSITIVE_CONFIG_FIELDS) {
|
|
9020
|
+
if (Object.prototype.hasOwnProperty.call(source, field)) {
|
|
9021
|
+
throw new Error(`user.${field} \u5C5E\u4E8E\u654F\u611F\u6216\u670D\u52A1\u7AEF\u7BA1\u7406\u5B57\u6BB5\uFF0Ctyped config \u4E0D\u5141\u8BB8\u5199\u5165\u3002`);
|
|
9022
|
+
}
|
|
9023
|
+
}
|
|
9024
|
+
const createMode = work.mode === "create";
|
|
9025
|
+
if (!createMode && Object.prototype.hasOwnProperty.call(source, "phone")) {
|
|
9026
|
+
throw new Error("user.phone \u53EA\u5141\u8BB8\u5728 mode=create \u65F6\u663E\u5F0F\u63D0\u4F9B\uFF1B\u7F16\u8F91\u7528\u6237\u8EAB\u4EFD\u65F6\u4E0D\u5F97\u901A\u8FC7\u914D\u7F6E\u6587\u4EF6\u4FEE\u6539\u624B\u673A\u53F7\u3002");
|
|
9027
|
+
}
|
|
9028
|
+
if (Object.prototype.hasOwnProperty.call(source, "hide_in_contact")) {
|
|
9029
|
+
throw new Error("user.hide_in_contact \u5F53\u524D\u5E73\u53F0\u63A5\u53E3\u672A\u5B9E\u73B0\uFF0Ctyped config \u4E0D\u5141\u8BB8\u63D0\u4EA4\u8BE5\u5B57\u6BB5\u3002");
|
|
9030
|
+
}
|
|
9031
|
+
const payload = pickDefined(source, [
|
|
9032
|
+
"name",
|
|
9033
|
+
"phone",
|
|
9034
|
+
"partner_id",
|
|
9035
|
+
"title",
|
|
9036
|
+
"email",
|
|
9037
|
+
"status",
|
|
9038
|
+
"leader_id",
|
|
9039
|
+
"language_preference",
|
|
9040
|
+
"group_ids",
|
|
9041
|
+
"role_ids",
|
|
9042
|
+
"modelList",
|
|
9043
|
+
"user_model_id"
|
|
9044
|
+
]);
|
|
9045
|
+
if (payload.group_ids === void 0 && Array.isArray(source.group_list)) {
|
|
9046
|
+
payload.group_ids = source.group_list.filter(isRecord3).map((item) => item.id);
|
|
9047
|
+
}
|
|
9048
|
+
if (payload.role_ids === void 0 && Array.isArray(source.role)) {
|
|
9049
|
+
payload.role_ids = source.role.filter(isRecord3).map((item) => item.id);
|
|
9050
|
+
}
|
|
9051
|
+
if (payload.modelList === void 0 && Array.isArray(source.models)) {
|
|
9052
|
+
payload.modelList = source.models.filter(isRecord3).map((item) => item.id);
|
|
9053
|
+
}
|
|
9054
|
+
payload.name = String(payload.name ?? "").trim();
|
|
9055
|
+
if (!payload.name || String(payload.name).length > 200) {
|
|
9056
|
+
throw new Error("user.name \u5FC5\u987B\u662F 1-200 \u4E2A\u5B57\u7B26\u3002");
|
|
9057
|
+
}
|
|
9058
|
+
if (payload.partner_id !== void 0 && String(payload.partner_id).length > 30) {
|
|
9059
|
+
throw new Error("user.partner_id \u6700\u957F 30 \u4E2A\u5B57\u7B26\u3002");
|
|
9060
|
+
}
|
|
9061
|
+
if (payload.title !== void 0 && String(payload.title).length > 20) {
|
|
9062
|
+
throw new Error("user.title \u6700\u957F 20 \u4E2A\u5B57\u7B26\u3002");
|
|
9063
|
+
}
|
|
9064
|
+
if (payload.email !== void 0 && String(payload.email).length > 20) {
|
|
9065
|
+
throw new Error("user.email \u6700\u957F 20 \u4E2A\u5B57\u7B26\u3002");
|
|
9066
|
+
}
|
|
9067
|
+
if (createMode) {
|
|
9068
|
+
const phone = String(payload.phone ?? "").trim();
|
|
9069
|
+
if (!/^\+?\d{6,20}$/.test(phone)) {
|
|
9070
|
+
throw new Error("user.phone \u5728 mode=create \u65F6\u5FC5\u586B\uFF0C\u4E14\u5FC5\u987B\u662F 6-20 \u4F4D\u6570\u5B57\uFF0C\u53EF\u5E26\u524D\u5BFC +\u3002");
|
|
9071
|
+
}
|
|
9072
|
+
payload.phone = phone;
|
|
9073
|
+
const roleIds = normalizedNumberList(payload.role_ids, "user.role_ids");
|
|
9074
|
+
if (!roleIds.length) {
|
|
9075
|
+
throw new Error("user.role_ids \u5728 mode=create \u65F6\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u89D2\u8272 ID\u3002");
|
|
9076
|
+
}
|
|
9077
|
+
payload.role_ids = roleIds;
|
|
9078
|
+
} else {
|
|
9079
|
+
delete payload.phone;
|
|
9080
|
+
}
|
|
9081
|
+
for (const field of ["group_ids", "role_ids", "modelList"]) {
|
|
9082
|
+
if (payload[field] !== void 0) {
|
|
9083
|
+
payload[field] = normalizedNumberList(payload[field], `user.${field}`);
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
if (payload.user_model_id !== void 0) {
|
|
9087
|
+
payload.user_model_id = normalizedOptionalId(payload.user_model_id, "user.user_model_id", false);
|
|
9088
|
+
}
|
|
9089
|
+
if (payload.leader_id !== void 0) {
|
|
9090
|
+
payload.leader_id = normalizedOptionalId(payload.leader_id, "user.leader_id");
|
|
9091
|
+
const currentId = normalizedOptionalId(work.id ?? source.id, "user.id", false);
|
|
9092
|
+
if (currentId && Number(payload.leader_id) === currentId) {
|
|
9093
|
+
throw new Error("user.leader_id \u4E0D\u80FD\u6307\u5411\u7528\u6237\u81EA\u8EAB\u3002");
|
|
9094
|
+
}
|
|
9095
|
+
}
|
|
9096
|
+
if (payload.status !== void 0 && ![0, 1, 2].includes(Number(payload.status))) {
|
|
9097
|
+
throw new Error("user.status \u53EA\u5141\u8BB8 0\u30011\u30012\u3002");
|
|
9098
|
+
}
|
|
9099
|
+
if (payload.status !== void 0) payload.status = Number(payload.status);
|
|
9100
|
+
return payload;
|
|
9101
|
+
}
|
|
9102
|
+
function privacySafeUserConfig(value) {
|
|
9103
|
+
if (!isRecord3(value)) return value;
|
|
9104
|
+
const result = pickDefined(value, [
|
|
9105
|
+
"id",
|
|
9106
|
+
"uuid",
|
|
9107
|
+
"guid",
|
|
9108
|
+
"name",
|
|
9109
|
+
"partner_id",
|
|
9110
|
+
"title",
|
|
9111
|
+
"email",
|
|
9112
|
+
"status",
|
|
9113
|
+
"leader_id",
|
|
9114
|
+
"hide_in_contact",
|
|
9115
|
+
"language_preference",
|
|
9116
|
+
"organization_id",
|
|
9117
|
+
"is_del",
|
|
9118
|
+
"group_ids",
|
|
9119
|
+
"group_list",
|
|
9120
|
+
"role_ids",
|
|
9121
|
+
"role",
|
|
9122
|
+
"models"
|
|
9123
|
+
]);
|
|
9124
|
+
if (Array.isArray(result.group_list)) {
|
|
9125
|
+
result.group_list = result.group_list.filter(isRecord3).map((item) => pickDefined(item, ["id", "name", "path", "is_admin"]));
|
|
9126
|
+
}
|
|
9127
|
+
if (Array.isArray(result.role)) {
|
|
9128
|
+
result.role = result.role.filter(isRecord3).map((item) => pickDefined(item, ["id", "key", "name"]));
|
|
9129
|
+
}
|
|
9130
|
+
if (Array.isArray(result.models)) {
|
|
9131
|
+
result.models = result.models.filter(isRecord3).map((item) => pickDefined(item, ["id", "uuid", "key", "name", "form_id"]));
|
|
9132
|
+
}
|
|
9133
|
+
return result;
|
|
9134
|
+
}
|
|
9135
|
+
function privacySafePermission(value) {
|
|
9136
|
+
if (!isRecord3(value)) return value;
|
|
9137
|
+
const result = { ...value };
|
|
9138
|
+
if (isRecord3(result.config)) {
|
|
9139
|
+
const config = { ...result.config };
|
|
9140
|
+
for (const field of ["user", "group", "role"]) {
|
|
9141
|
+
if (Array.isArray(config[field])) {
|
|
9142
|
+
config[field] = config[field].filter(isRecord3).map((item) => pickDefined(item, ["id", "key", "name"]));
|
|
9143
|
+
}
|
|
9144
|
+
}
|
|
9145
|
+
result.config = config;
|
|
9146
|
+
}
|
|
9147
|
+
return result;
|
|
9148
|
+
}
|
|
9149
|
+
function privacySafeTeamConfig(value) {
|
|
9150
|
+
if (!isRecord3(value)) return value;
|
|
9151
|
+
const result = pickDefined(value, [
|
|
9152
|
+
"id",
|
|
9153
|
+
"uuid",
|
|
9154
|
+
"guid",
|
|
9155
|
+
"name",
|
|
9156
|
+
"intro",
|
|
9157
|
+
"parent_id",
|
|
9158
|
+
"path",
|
|
9159
|
+
"model_id",
|
|
9160
|
+
"platform_id",
|
|
9161
|
+
"meta_form_id",
|
|
9162
|
+
"permission",
|
|
9163
|
+
"admins"
|
|
9164
|
+
]);
|
|
9165
|
+
result.permission = privacySafePermission(result.permission);
|
|
9166
|
+
if (Array.isArray(result.admins)) {
|
|
9167
|
+
result.admins = result.admins.filter(isRecord3).map((item) => pickDefined(item, ["id", "name"]));
|
|
9168
|
+
}
|
|
9169
|
+
return result;
|
|
9170
|
+
}
|
|
9171
|
+
function privacySafeModelConfig(domain, value) {
|
|
9172
|
+
if (!isRecord3(value)) return value;
|
|
9173
|
+
const fields = domain === "user-model" ? ["id", "uuid", "guid", "key", "name", "form_template_id", "object_event", "auto_trigger_flows", "permission", "role_id", "role"] : ["id", "uuid", "guid", "key", "name", "form_template_id", "object_event", "auto_trigger_flows", "permission", "sub_ids"];
|
|
9174
|
+
const result = pickDefined(value, fields);
|
|
9175
|
+
result.permission = privacySafePermission(result.permission);
|
|
9176
|
+
if (isRecord3(result.role)) {
|
|
9177
|
+
result.role = pickDefined(result.role, ["id", "key", "name"]);
|
|
9178
|
+
}
|
|
9179
|
+
return result;
|
|
9180
|
+
}
|
|
9181
|
+
async function assertTeamParentDoesNotCreateCycle(profile, id, payload, definition, current) {
|
|
9182
|
+
const teamId = normalizedOptionalId(id, "team.id", false);
|
|
9183
|
+
const parentId = normalizedOptionalId(payload.parent_id, "team.parent_id");
|
|
9184
|
+
if (!teamId || !parentId) return;
|
|
9185
|
+
if (isRecord3(current) && Number(current.parent_id || 0) === parentId) return;
|
|
9186
|
+
if (teamId === parentId) {
|
|
9187
|
+
throw new Error("team.parent_id \u4E0D\u80FD\u6307\u5411\u56E2\u961F\u81EA\u8EAB\u3002");
|
|
9188
|
+
}
|
|
9189
|
+
const parent = await readRemoteConfigDomain(profile, "team", String(parentId), definition);
|
|
9190
|
+
if (!isRecord3(parent) || Number(parent.id) !== parentId) {
|
|
9191
|
+
throw new Error(`team.parent_id ${parentId} \u4E0D\u5B58\u5728\uFF0C\u4E0D\u80FD\u63D0\u4EA4\u5C42\u7EA7\u53D8\u66F4\u3002`);
|
|
9192
|
+
}
|
|
9193
|
+
const ancestorIds = String(parent.path ?? "").split(/[|,]/).map((item) => Number(item.trim())).filter((item) => Number.isSafeInteger(item) && item > 0);
|
|
9194
|
+
if (ancestorIds.includes(teamId)) {
|
|
9195
|
+
throw new Error(`team.parent_id ${parentId} \u662F\u56E2\u961F ${teamId} \u7684\u540E\u4EE3\uFF0C\u63D0\u4EA4\u540E\u4F1A\u5F62\u6210\u7EC4\u7EC7\u6811\u5FAA\u73AF\u3002`);
|
|
9196
|
+
}
|
|
9197
|
+
}
|
|
9198
|
+
function normalizeModelPayload(domain, work) {
|
|
9199
|
+
const source = configSource(work);
|
|
9200
|
+
const fields = domain === "user-model" ? ["key", "name", "form_template_id", "object_event", "auto_trigger_flows", "permission", "uuid", "role_id"] : ["key", "name", "form_template_id", "object_event", "auto_trigger_flows", "permission", "sub_ids", "uuid"];
|
|
9201
|
+
const payload = pickDefined(source, fields);
|
|
9202
|
+
payload.key = String(payload.key ?? "").trim();
|
|
9203
|
+
payload.name = String(payload.name ?? "").trim();
|
|
9204
|
+
if (!/^[A-Za-z][A-Za-z0-9_-]{0,19}$/.test(String(payload.key))) {
|
|
9205
|
+
throw new Error(`${domain}.key \u5FC5\u987B\u4EE5\u5B57\u6BCD\u5F00\u5934\uFF0C\u957F\u5EA6 1-20\uFF0C\u53EA\u80FD\u5305\u542B\u5B57\u6BCD\u3001\u6570\u5B57\u3001_\u3001-\u3002`);
|
|
9206
|
+
}
|
|
9207
|
+
const maxNameLength = domain === "group-model" ? 20 : 200;
|
|
9208
|
+
if (!payload.name || String(payload.name).length > maxNameLength) {
|
|
9209
|
+
throw new Error(`${domain}.name \u5FC5\u987B\u662F 1-${maxNameLength} \u4E2A\u5B57\u7B26\u3002`);
|
|
9210
|
+
}
|
|
9211
|
+
if (payload.form_template_id !== void 0) {
|
|
9212
|
+
payload.form_template_id = normalizedOptionalId(payload.form_template_id, `${domain}.form_template_id`);
|
|
9213
|
+
}
|
|
9214
|
+
if (payload.role_id !== void 0) {
|
|
9215
|
+
payload.role_id = normalizedOptionalId(payload.role_id, "user-model.role_id");
|
|
9216
|
+
}
|
|
9217
|
+
if (payload.object_event !== void 0 && payload.object_event !== null) {
|
|
9218
|
+
payload.object_event = normalizedJsonValue(payload.object_event, `${domain}.object_event`, "array");
|
|
9219
|
+
}
|
|
9220
|
+
if (payload.auto_trigger_flows !== void 0 && payload.auto_trigger_flows !== null) {
|
|
9221
|
+
payload.auto_trigger_flows = normalizedJsonValue(payload.auto_trigger_flows, `${domain}.auto_trigger_flows`, "object");
|
|
9222
|
+
}
|
|
9223
|
+
if (payload.permission !== void 0 && payload.permission !== null) {
|
|
9224
|
+
payload.permission = normalizedJsonValue(payload.permission, `${domain}.permission`, "object");
|
|
9225
|
+
}
|
|
9226
|
+
if (domain === "group-model" && payload.sub_ids !== void 0) {
|
|
9227
|
+
const rawSubIds = Array.isArray(payload.sub_ids) ? payload.sub_ids : typeof payload.sub_ids === "string" ? payload.sub_ids.split(",").map((item) => item.trim()).filter(Boolean) : [payload.sub_ids];
|
|
9228
|
+
payload.sub_ids = normalizedNumberList(payload.sub_ids, "group-model.sub_ids");
|
|
9229
|
+
if (rawSubIds.length !== payload.sub_ids.length) {
|
|
9230
|
+
throw new Error("group-model.sub_ids \u4E0D\u5141\u8BB8\u91CD\u590D ID\u3002");
|
|
9231
|
+
}
|
|
9232
|
+
const currentId = normalizedOptionalId(work.id ?? source.id, "group-model.id", false);
|
|
9233
|
+
if (currentId && payload.sub_ids.includes(currentId)) {
|
|
9234
|
+
throw new Error("group-model.sub_ids \u4E0D\u80FD\u5305\u542B\u6A21\u578B\u81EA\u8EAB\u3002");
|
|
9235
|
+
}
|
|
9236
|
+
}
|
|
9237
|
+
if (payload.uuid !== void 0 && payload.uuid !== null && payload.uuid !== "" && !String(payload.uuid).match(/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/)) {
|
|
9238
|
+
throw new Error(`${domain}.uuid \u5FC5\u987B\u662F\u6709\u6548 UUID\u3002`);
|
|
9239
|
+
}
|
|
9240
|
+
return payload;
|
|
9241
|
+
}
|
|
8769
9242
|
function parseApiPlatformIdentity(id) {
|
|
8770
9243
|
const trimmed = id.trim();
|
|
8771
9244
|
if (!trimmed) {
|
|
@@ -9329,6 +9802,15 @@ function buildDomainSubmitPayload(domain, work, options = {}, raw) {
|
|
|
9329
9802
|
if (domain === "role") {
|
|
9330
9803
|
return buildRoleSubmitPayload(work);
|
|
9331
9804
|
}
|
|
9805
|
+
if (domain === "team") {
|
|
9806
|
+
return normalizeTeamPayload(work, isRecord3(raw) ? raw : void 0);
|
|
9807
|
+
}
|
|
9808
|
+
if (domain === "user") {
|
|
9809
|
+
return normalizeUserPayload(work);
|
|
9810
|
+
}
|
|
9811
|
+
if (domain === "user-model" || domain === "group-model") {
|
|
9812
|
+
return normalizeModelPayload(domain, work);
|
|
9813
|
+
}
|
|
9332
9814
|
if (domain === "nav-config") {
|
|
9333
9815
|
return buildNavConfigSubmitPayload(work, isRecord3(raw) ? raw : void 0, options);
|
|
9334
9816
|
}
|
|
@@ -9687,7 +10169,7 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
|
|
|
9687
10169
|
const expectedConfirm = `create flow-template ${createShell.name}`;
|
|
9688
10170
|
if (confirm3 !== expectedConfirm) {
|
|
9689
10171
|
return {
|
|
9690
|
-
|
|
10172
|
+
...dryRunFields(expectedConfirm),
|
|
9691
10173
|
domain: "flow-template",
|
|
9692
10174
|
create_endpoint: "/flow/flow_type",
|
|
9693
10175
|
create_payload: createShell,
|
|
@@ -9747,7 +10229,7 @@ async function createFlowTemplateFromWork(config, profile, workFile, confirm3, o
|
|
|
9747
10229
|
{ capability: `${definition.capability}.export` }
|
|
9748
10230
|
);
|
|
9749
10231
|
return {
|
|
9750
|
-
|
|
10232
|
+
...executedFields(),
|
|
9751
10233
|
domain: "flow-template",
|
|
9752
10234
|
flow_type: flowType,
|
|
9753
10235
|
create_response: createResponse,
|
|
@@ -10036,6 +10518,364 @@ async function createFlowAppFromWork(config, profile, formWorkFile, flowWorkFile
|
|
|
10036
10518
|
throw new Error(`flow-app create failed: ${message}. Created resources: ${JSON.stringify(createdResources)}. Next recovery: fix the failing step, then rerun the corresponding typed config command or rerun flow-app create only if duplicate resources are acceptable.`);
|
|
10037
10519
|
}
|
|
10038
10520
|
}
|
|
10521
|
+
function matrixMaintenanceNode(flowWork) {
|
|
10522
|
+
const data = isRecord3(flowWork.data) ? flowWork.data : {};
|
|
10523
|
+
const nodes = Array.isArray(data.nodes) ? data.nodes.filter(isRecord3) : [];
|
|
10524
|
+
return nodes.find((node) => {
|
|
10525
|
+
const name = String(node.name ?? "").trim();
|
|
10526
|
+
return name === "\u751F\u6548\u4E2D" || name === "\u8FDB\u884C\u4E2D" || Number(node.status) === 1;
|
|
10527
|
+
});
|
|
10528
|
+
}
|
|
10529
|
+
function matrixListHasEditAction(value) {
|
|
10530
|
+
if (typeof value === "string") {
|
|
10531
|
+
return value.includes("ProjectDetailEdit");
|
|
10532
|
+
}
|
|
10533
|
+
if (Array.isArray(value)) {
|
|
10534
|
+
return value.some(matrixListHasEditAction);
|
|
10535
|
+
}
|
|
10536
|
+
if (isRecord3(value)) {
|
|
10537
|
+
return Object.entries(value).some(([key, child]) => key === "is" && child === "ProjectDetailEdit" || matrixListHasEditAction(child));
|
|
10538
|
+
}
|
|
10539
|
+
return false;
|
|
10540
|
+
}
|
|
10541
|
+
function matrixCreateMeta(domain, id, profile) {
|
|
10542
|
+
return {
|
|
10543
|
+
domain,
|
|
10544
|
+
id,
|
|
10545
|
+
mode: "create",
|
|
10546
|
+
profile: profile.name,
|
|
10547
|
+
workspace: profile.config.workspace
|
|
10548
|
+
};
|
|
10549
|
+
}
|
|
10550
|
+
function matrixCreatedId(response, domain, options = {}) {
|
|
10551
|
+
if (!isRecord3(response)) {
|
|
10552
|
+
throw new Error(`matrix app ${domain} create returned an invalid response.`);
|
|
10553
|
+
}
|
|
10554
|
+
if (response.readback_status !== void 0 && response.readback_status !== "verified" && !options.allowRecoverableReadbackMismatch) {
|
|
10555
|
+
throw new Error(`matrix app ${domain} create did not complete exact readback: ${String(response.readback_status)}.`);
|
|
10556
|
+
}
|
|
10557
|
+
const id = response.id ?? response.created_id;
|
|
10558
|
+
if (id === void 0 || id === null || String(id).trim() === "") {
|
|
10559
|
+
throw new Error(`matrix app ${domain} create did not return a created id.`);
|
|
10560
|
+
}
|
|
10561
|
+
if (!/^\d+$/.test(String(id))) {
|
|
10562
|
+
throw new Error(`matrix app ${domain} create returned a non-numeric config id: ${String(id)}.`);
|
|
10563
|
+
}
|
|
10564
|
+
return String(id);
|
|
10565
|
+
}
|
|
10566
|
+
function matrixDatasetFieldDefinitions(work) {
|
|
10567
|
+
const candidates = [work.dataSetFields, work.data_set_fields, work.fields];
|
|
10568
|
+
for (const candidate of candidates) {
|
|
10569
|
+
if (Array.isArray(candidate)) {
|
|
10570
|
+
return candidate.filter(isRecord3);
|
|
10571
|
+
}
|
|
10572
|
+
if (isRecord3(candidate) && Array.isArray(candidate.selected)) {
|
|
10573
|
+
return candidate.selected.filter(isRecord3);
|
|
10574
|
+
}
|
|
10575
|
+
}
|
|
10576
|
+
return [];
|
|
10577
|
+
}
|
|
10578
|
+
async function createMatrixDatasetField(config, profile, field, datasetId, flowType, index, workDir) {
|
|
10579
|
+
const domain = "dataset-field";
|
|
10580
|
+
const id = "create:dataset-field";
|
|
10581
|
+
const suffix = `${index + 1}-${String(field.key ?? field.field ?? "field").replace(/[^A-Za-z0-9_-]+/g, "-")}`;
|
|
10582
|
+
const workFile = path5.join(workDir, `dataset-field-${suffix}.work.json`);
|
|
10583
|
+
const metaFile = path5.join(workDir, `dataset-field-${suffix}.meta.json`);
|
|
10584
|
+
const submitFile = path5.join(workDir, `dataset-field-${suffix}.submit.json`);
|
|
10585
|
+
await writeJsonFile(workFile, {
|
|
10586
|
+
...field,
|
|
10587
|
+
mode: "create",
|
|
10588
|
+
data_set_id: datasetId,
|
|
10589
|
+
flow_type: flowType,
|
|
10590
|
+
flowType
|
|
10591
|
+
});
|
|
10592
|
+
await writeJsonFile(metaFile, matrixCreateMeta(domain, id, profile));
|
|
10593
|
+
const lint = await lintConfigWorkFile(workFile, { domain });
|
|
10594
|
+
if (lint.ok !== true) {
|
|
10595
|
+
throw new Error(`matrix app dataset-field lint failed: ${(Array.isArray(lint.errors) ? lint.errors : []).join("; ")}`);
|
|
10596
|
+
}
|
|
10597
|
+
await buildConfigSubmitPayload(domain, workFile, submitFile, metaFile);
|
|
10598
|
+
return submitConfigDomain(config, profile, domain, id, submitFile, `submit ${domain} ${id}`);
|
|
10599
|
+
}
|
|
10600
|
+
function bindMatrixPageTemplateWork(work, flowType, datasetId) {
|
|
10601
|
+
const basic = isRecord3(work.basic) ? { ...work.basic } : void 0;
|
|
10602
|
+
const binding = { flow_type: flowType, flow_key: "", data_set_id: Number(datasetId) };
|
|
10603
|
+
return {
|
|
10604
|
+
...work,
|
|
10605
|
+
...binding,
|
|
10606
|
+
...basic ? { basic: { ...basic, ...binding } } : {}
|
|
10607
|
+
};
|
|
10608
|
+
}
|
|
10609
|
+
async function createMatrixConfigObject(config, profile, domain, work, workDir) {
|
|
10610
|
+
const id = `create:${domain}`;
|
|
10611
|
+
const workFile = path5.join(workDir, `${domain}.work.json`);
|
|
10612
|
+
const metaFile = path5.join(workDir, `${domain}.meta.json`);
|
|
10613
|
+
const submitFile = path5.join(workDir, `${domain}.submit.json`);
|
|
10614
|
+
await writeJsonFile(workFile, { ...work, mode: "create" });
|
|
10615
|
+
await writeJsonFile(metaFile, matrixCreateMeta(domain, id, profile));
|
|
10616
|
+
const lint = await lintConfigWorkFile(workFile, { domain });
|
|
10617
|
+
if (lint.ok !== true) {
|
|
10618
|
+
throw new Error(`matrix app ${domain} lint failed: ${(Array.isArray(lint.errors) ? lint.errors : []).join("; ")}`);
|
|
10619
|
+
}
|
|
10620
|
+
await buildConfigSubmitPayload(domain, workFile, submitFile, metaFile);
|
|
10621
|
+
return submitConfigDomain(config, profile, domain, id, submitFile, `submit ${domain} ${id}`);
|
|
10622
|
+
}
|
|
10623
|
+
async function createMatrixAppFromWork(config, profile, formWorkFile, flowWorkFile, datasetWorkFile, listWorkFile, filterWorkFile, confirm3, options = { workspace: "", name: "" }) {
|
|
10624
|
+
const workspace = normalizeWorkspaceKey(options.workspace || profile.config.workspace);
|
|
10625
|
+
const name = options.name.trim();
|
|
10626
|
+
const expectedConfirm = `create matrix app ${name} in ${workspace}`;
|
|
10627
|
+
if (!workspace || !name) {
|
|
10628
|
+
throw new Error("matrix app create requires workspace and name.");
|
|
10629
|
+
}
|
|
10630
|
+
const [flowWorkValue, datasetWorkValue, listWorkValue, filterWorkValue] = await Promise.all([
|
|
10631
|
+
readJsonFile(flowWorkFile),
|
|
10632
|
+
readJsonFile(datasetWorkFile),
|
|
10633
|
+
readJsonFile(listWorkFile),
|
|
10634
|
+
readJsonFile(filterWorkFile)
|
|
10635
|
+
]);
|
|
10636
|
+
if (![flowWorkValue, datasetWorkValue, listWorkValue, filterWorkValue].every(isRecord3)) {
|
|
10637
|
+
throw new Error("matrix app create work files must be JSON objects.");
|
|
10638
|
+
}
|
|
10639
|
+
const flowWork = flowWorkValue;
|
|
10640
|
+
const datasetWork = datasetWorkValue;
|
|
10641
|
+
const listWork = listWorkValue;
|
|
10642
|
+
const filterWork = filterWorkValue;
|
|
10643
|
+
const errors = [];
|
|
10644
|
+
if (String(flowWork.category ?? "") !== "matrix") {
|
|
10645
|
+
errors.push("flow-template category must be matrix.");
|
|
10646
|
+
}
|
|
10647
|
+
if (!matrixMaintenanceNode(flowWork)) {
|
|
10648
|
+
errors.push("flow-template requires at least one maintenance node named \u751F\u6548\u4E2D/\u8FDB\u884C\u4E2D or status=1.");
|
|
10649
|
+
}
|
|
10650
|
+
if (!matrixListHasEditAction(listWork)) {
|
|
10651
|
+
errors.push("list-template requires the built-in ProjectDetailEdit modification action.");
|
|
10652
|
+
}
|
|
10653
|
+
const datasetBasic = isRecord3(datasetWork.basic) ? datasetWork.basic : datasetWork;
|
|
10654
|
+
const datasetCustomKey = normalizeText(datasetBasic.customKey ?? datasetBasic.custom_key ?? "");
|
|
10655
|
+
if (datasetCustomKey.length > MAX_DATASET_CUSTOM_KEY_LENGTH) {
|
|
10656
|
+
errors.push(
|
|
10657
|
+
`dataset custom_key is too long (${datasetCustomKey.length} > ${MAX_DATASET_CUSTOM_KEY_LENGTH}); shorten it before matrix resources are created.`
|
|
10658
|
+
);
|
|
10659
|
+
}
|
|
10660
|
+
const datasetFieldDefinitions = matrixDatasetFieldDefinitions(datasetWork);
|
|
10661
|
+
if (datasetFieldDefinitions.length === 0) {
|
|
10662
|
+
errors.push("dataset requires inline field definitions so a newly allocated matrix flow can create its dataset-field records.");
|
|
10663
|
+
}
|
|
10664
|
+
for (const [index, field] of datasetFieldDefinitions.entries()) {
|
|
10665
|
+
const missing = ["key", "name", "type", "classify", "source_table", "source_field", "source_fk"].filter((key) => normalizeText(field[key]) === "");
|
|
10666
|
+
if (missing.length > 0) {
|
|
10667
|
+
errors.push(`dataset field ${index + 1} requires inline source mapping: ${missing.join(", ")}.`);
|
|
10668
|
+
}
|
|
10669
|
+
}
|
|
10670
|
+
const flowPreflight = await lintFlowAppWorkFiles(formWorkFile, flowWorkFile, {
|
|
10671
|
+
workspace,
|
|
10672
|
+
name,
|
|
10673
|
+
pluginLint: { profile, agent: options.agent || "codex", requireInstalled: true }
|
|
10674
|
+
});
|
|
10675
|
+
if (flowPreflight.ok !== true) {
|
|
10676
|
+
errors.push(...Array.isArray(flowPreflight.errors) ? flowPreflight.errors.map(String) : ["flow-app lint failed"]);
|
|
10677
|
+
}
|
|
10678
|
+
if (errors.length) {
|
|
10679
|
+
throw new Error(`matrix app create lint failed: ${errors.join("; ")}`);
|
|
10680
|
+
}
|
|
10681
|
+
if (confirm3 !== expectedConfirm) {
|
|
10682
|
+
return {
|
|
10683
|
+
...dryRunFields(expectedConfirm),
|
|
10684
|
+
domain: "approval-matrix",
|
|
10685
|
+
action: "app.create",
|
|
10686
|
+
workspace,
|
|
10687
|
+
name,
|
|
10688
|
+
operation_plan: [
|
|
10689
|
+
"create and publish form-template",
|
|
10690
|
+
"create matrix flow-template with one active maintenance node",
|
|
10691
|
+
"bind flow to workspace",
|
|
10692
|
+
"create dataset and require exact readback",
|
|
10693
|
+
"create and bind dataset-field definitions for the generated matrix flow",
|
|
10694
|
+
"create list-template with ProjectDetailEdit and require exact readback",
|
|
10695
|
+
"create filter-template and require exact readback",
|
|
10696
|
+
"bind list/filter template ids into flow.data.meta and publish live",
|
|
10697
|
+
"publish dataset",
|
|
10698
|
+
"exact-readback all matrix definition objects"
|
|
10699
|
+
],
|
|
10700
|
+
flow_app_preflight: flowPreflight,
|
|
10701
|
+
next: `Run again with --confirm "${expectedConfirm}" to create.`
|
|
10702
|
+
};
|
|
10703
|
+
}
|
|
10704
|
+
const workDir = path5.resolve(options.workDir || `.codex/tmp/matrix-app-create-${Date.now()}`);
|
|
10705
|
+
await mkdir5(workDir, { recursive: true });
|
|
10706
|
+
const createdResources = {};
|
|
10707
|
+
try {
|
|
10708
|
+
const flowApp = await createFlowAppFromWork(
|
|
10709
|
+
config,
|
|
10710
|
+
profile,
|
|
10711
|
+
formWorkFile,
|
|
10712
|
+
flowWorkFile,
|
|
10713
|
+
`create flow-app ${name} in ${workspace}`,
|
|
10714
|
+
{ ...options, workspace, name }
|
|
10715
|
+
);
|
|
10716
|
+
Object.assign(createdResources, isRecord3(flowApp.created_ids) ? flowApp.created_ids : {
|
|
10717
|
+
form_template_id: flowApp.form_template_id,
|
|
10718
|
+
form_template_draft_id: flowApp.form_template_draft_id,
|
|
10719
|
+
flow_type: flowApp.flow_type
|
|
10720
|
+
});
|
|
10721
|
+
const flowType = String(flowApp.flow_type ?? "");
|
|
10722
|
+
if (!flowType) {
|
|
10723
|
+
throw new Error("matrix app create did not receive the generated flow_type.");
|
|
10724
|
+
}
|
|
10725
|
+
const datasetResponse = await createMatrixConfigObject(config, profile, "dataset", {
|
|
10726
|
+
...datasetWork,
|
|
10727
|
+
flow_type: flowType,
|
|
10728
|
+
flowType
|
|
10729
|
+
}, workDir);
|
|
10730
|
+
const datasetId = matrixCreatedId(datasetResponse, "dataset", { allowRecoverableReadbackMismatch: true });
|
|
10731
|
+
createdResources.dataset_id = Number(datasetId);
|
|
10732
|
+
const datasetFieldResponses = [];
|
|
10733
|
+
for (const [index, field] of datasetFieldDefinitions.entries()) {
|
|
10734
|
+
const response = await createMatrixDatasetField(config, profile, field, datasetId, flowType, index, workDir);
|
|
10735
|
+
const datasetFieldId = matrixCreatedId(response, "dataset-field");
|
|
10736
|
+
datasetFieldResponses.push(response);
|
|
10737
|
+
createdResources.dataset_field_ids = [
|
|
10738
|
+
...Array.isArray(createdResources.dataset_field_ids) ? createdResources.dataset_field_ids : [],
|
|
10739
|
+
Number(datasetFieldId)
|
|
10740
|
+
];
|
|
10741
|
+
}
|
|
10742
|
+
const exportedDataset = await exportConfigDomain(config, profile, "dataset", datasetId, workDir);
|
|
10743
|
+
const exportedDatasetWork = await readJsonFile(String(exportedDataset.work_file));
|
|
10744
|
+
if (!isRecord3(exportedDatasetWork)) {
|
|
10745
|
+
throw new Error("matrix app dataset exact export did not contain work data.");
|
|
10746
|
+
}
|
|
10747
|
+
const datasetBoundWorkFile = path5.join(workDir, "dataset.bound.work.json");
|
|
10748
|
+
const datasetBoundSubmitFile = path5.join(workDir, "dataset.bound.submit.json");
|
|
10749
|
+
await writeJsonFile(datasetBoundWorkFile, {
|
|
10750
|
+
...exportedDatasetWork,
|
|
10751
|
+
mode: "edit",
|
|
10752
|
+
id: Number(datasetId),
|
|
10753
|
+
flow_type: flowType,
|
|
10754
|
+
flowType,
|
|
10755
|
+
fields: { selected: datasetFieldDefinitions },
|
|
10756
|
+
dataSetFields: datasetFieldDefinitions
|
|
10757
|
+
});
|
|
10758
|
+
await buildConfigSubmitPayload(
|
|
10759
|
+
"dataset",
|
|
10760
|
+
datasetBoundWorkFile,
|
|
10761
|
+
datasetBoundSubmitFile,
|
|
10762
|
+
String(exportedDataset.meta_file)
|
|
10763
|
+
);
|
|
10764
|
+
const datasetBindResponse = await submitConfigDomain(
|
|
10765
|
+
config,
|
|
10766
|
+
profile,
|
|
10767
|
+
"dataset",
|
|
10768
|
+
datasetId,
|
|
10769
|
+
datasetBoundSubmitFile,
|
|
10770
|
+
`submit dataset ${datasetId}`
|
|
10771
|
+
);
|
|
10772
|
+
if (datasetBindResponse.readback_status !== void 0 && datasetBindResponse.readback_status !== "verified") {
|
|
10773
|
+
throw new Error(`matrix app dataset field binding did not complete exact readback: ${String(datasetBindResponse.readback_status)}.`);
|
|
10774
|
+
}
|
|
10775
|
+
const datasetAfterFields = await readbackConfigDomain(config, profile, "dataset", datasetId);
|
|
10776
|
+
const datasetReadbackValue = isRecord3(datasetAfterFields.readback) ? datasetAfterFields.readback : {};
|
|
10777
|
+
const attachedFields = Array.isArray(datasetReadbackValue.dataSetFields) ? datasetReadbackValue.dataSetFields.filter(isRecord3).map((field) => String(field.key ?? "")) : [];
|
|
10778
|
+
const expectedFields = datasetFieldDefinitions.map((field) => String(field.key ?? field.field ?? ""));
|
|
10779
|
+
const missingAttachedFields = expectedFields.filter((key) => key && !attachedFields.includes(key));
|
|
10780
|
+
if (missingAttachedFields.length > 0) {
|
|
10781
|
+
throw new Error(`matrix app dataset exact readback is missing attached fields: ${missingAttachedFields.join(", ")}.`);
|
|
10782
|
+
}
|
|
10783
|
+
const listResponse = await createMatrixConfigObject(
|
|
10784
|
+
config,
|
|
10785
|
+
profile,
|
|
10786
|
+
"list-template",
|
|
10787
|
+
bindMatrixPageTemplateWork(listWork, flowType, datasetId),
|
|
10788
|
+
workDir
|
|
10789
|
+
);
|
|
10790
|
+
const listTemplateId = matrixCreatedId(listResponse, "list-template");
|
|
10791
|
+
createdResources.list_template_id = Number(listTemplateId);
|
|
10792
|
+
const filterResponse = await createMatrixConfigObject(
|
|
10793
|
+
config,
|
|
10794
|
+
profile,
|
|
10795
|
+
"filter-template",
|
|
10796
|
+
bindMatrixPageTemplateWork(filterWork, flowType, datasetId),
|
|
10797
|
+
workDir
|
|
10798
|
+
);
|
|
10799
|
+
const filterTemplateId = matrixCreatedId(filterResponse, "filter-template");
|
|
10800
|
+
createdResources.filter_template_id = Number(filterTemplateId);
|
|
10801
|
+
const exportedFlow = await exportConfigDomain(config, profile, "flow-template", flowType, workDir);
|
|
10802
|
+
const exportedFlowWork = await readJsonFile(String(exportedFlow.work_file));
|
|
10803
|
+
if (!isRecord3(exportedFlowWork) || !isRecord3(exportedFlowWork.data)) {
|
|
10804
|
+
throw new Error("matrix app flow exact export did not contain data.");
|
|
10805
|
+
}
|
|
10806
|
+
const flowData = { ...exportedFlowWork.data };
|
|
10807
|
+
const flowMeta = isRecord3(flowData.meta) ? { ...flowData.meta } : {};
|
|
10808
|
+
flowMeta.table_list_template = Number(listTemplateId);
|
|
10809
|
+
flowMeta.table_filter_template = Number(filterTemplateId);
|
|
10810
|
+
flowData.meta = flowMeta;
|
|
10811
|
+
const boundFlowWorkFile = path5.join(workDir, "flow-template.bound.work.json");
|
|
10812
|
+
const boundFlowSubmitFile = path5.join(workDir, "flow-template.bound.submit.json");
|
|
10813
|
+
await writeJsonFile(boundFlowWorkFile, { ...exportedFlowWork, category: "matrix", data: flowData });
|
|
10814
|
+
await buildConfigSubmitPayload("flow-template", boundFlowWorkFile, boundFlowSubmitFile, String(exportedFlow.meta_file), {
|
|
10815
|
+
publishLive: options.publishLive !== false,
|
|
10816
|
+
pluginLint: { profile, agent: options.agent || "codex", requireInstalled: true }
|
|
10817
|
+
});
|
|
10818
|
+
const flowBindResponse = await submitConfigDomain(
|
|
10819
|
+
config,
|
|
10820
|
+
profile,
|
|
10821
|
+
"flow-template",
|
|
10822
|
+
flowType,
|
|
10823
|
+
boundFlowSubmitFile,
|
|
10824
|
+
`submit flow-template ${flowType}`,
|
|
10825
|
+
{ publishLive: options.publishLive !== false, agent: options.agent || "codex" }
|
|
10826
|
+
);
|
|
10827
|
+
createdResources.flow_templates_bound = true;
|
|
10828
|
+
const datasetPublishResponse = options.publishLive === false ? null : await runDatasetLifecycleAction(config, profile, "publish", datasetId, `publish dataset ${datasetId}`);
|
|
10829
|
+
createdResources.dataset_published = options.publishLive !== false;
|
|
10830
|
+
const [flowReadback, formReadback, datasetReadback, listReadback, filterReadback, workspaceReadback] = await Promise.all([
|
|
10831
|
+
readbackConfigDomain(config, profile, "flow-template", flowType),
|
|
10832
|
+
readbackConfigDomain(config, profile, "form-template", String(flowApp.form_template_draft_id)),
|
|
10833
|
+
readbackConfigDomain(config, profile, "dataset", datasetId),
|
|
10834
|
+
readbackConfigDomain(config, profile, "list-template", listTemplateId),
|
|
10835
|
+
readbackConfigDomain(config, profile, "filter-template", filterTemplateId),
|
|
10836
|
+
readbackConfigDomain(config, profile, "workspace-flow", workspace)
|
|
10837
|
+
]);
|
|
10838
|
+
return {
|
|
10839
|
+
...executedFields(),
|
|
10840
|
+
domain: "approval-matrix",
|
|
10841
|
+
action: "app.create",
|
|
10842
|
+
workspace,
|
|
10843
|
+
name,
|
|
10844
|
+
flow_type: flowType,
|
|
10845
|
+
created_ids: {
|
|
10846
|
+
form_template_id: flowApp.form_template_id,
|
|
10847
|
+
form_template_draft_id: flowApp.form_template_draft_id,
|
|
10848
|
+
flow_type: flowType,
|
|
10849
|
+
dataset_id: Number(datasetId),
|
|
10850
|
+
dataset_field_ids: datasetFieldResponses.map((response) => Number(response.id ?? response.created_id)),
|
|
10851
|
+
list_template_id: Number(listTemplateId),
|
|
10852
|
+
filter_template_id: Number(filterTemplateId)
|
|
10853
|
+
},
|
|
10854
|
+
operations: { flow_app: flowApp, dataset: datasetResponse, dataset_fields: datasetFieldResponses, dataset_bind: datasetBindResponse, list_template: listResponse, filter_template: filterResponse, flow_bind: flowBindResponse, dataset_publish: datasetPublishResponse },
|
|
10855
|
+
exact_readback: { flow: flowReadback, form: formReadback, dataset: datasetReadback, list_template: listReadback, filter_template: filterReadback, workspace_flow: workspaceReadback },
|
|
10856
|
+
work_dir: workDir
|
|
10857
|
+
};
|
|
10858
|
+
} catch (error) {
|
|
10859
|
+
if (Object.keys(createdResources).length === 0) {
|
|
10860
|
+
throw error;
|
|
10861
|
+
}
|
|
10862
|
+
const message = error instanceof Error ? error.message : String(error || "");
|
|
10863
|
+
return {
|
|
10864
|
+
...executedFields(),
|
|
10865
|
+
status: "partial_success",
|
|
10866
|
+
partial_success: true,
|
|
10867
|
+
requires_follow_up: true,
|
|
10868
|
+
domain: "approval-matrix",
|
|
10869
|
+
action: "app.create",
|
|
10870
|
+
workspace,
|
|
10871
|
+
name,
|
|
10872
|
+
created_ids: createdResources,
|
|
10873
|
+
error: message,
|
|
10874
|
+
work_dir: workDir,
|
|
10875
|
+
next_recovery: "Do not rerun the complete matrix app create command. Inspect created_ids, repair the failed stage with the corresponding typed config command, then run matrix app inspect/readback."
|
|
10876
|
+
};
|
|
10877
|
+
}
|
|
10878
|
+
}
|
|
10039
10879
|
async function readBackConfigDomain(profile, domain, id, definition) {
|
|
10040
10880
|
const data = await readRemoteConfigDomain(profile, domain, id, definition);
|
|
10041
10881
|
if (domain === "form-template") {
|
|
@@ -10120,6 +10960,9 @@ function normalizeTypedReadbackComparable(domain, value) {
|
|
|
10120
10960
|
normalized.value = canonicalFormTemplateValues(normalized.value);
|
|
10121
10961
|
}
|
|
10122
10962
|
if (domain === "dataset") {
|
|
10963
|
+
if (Object.prototype.hasOwnProperty.call(normalized, "id")) {
|
|
10964
|
+
normalized.id = normalizeComparableId(normalized.id);
|
|
10965
|
+
}
|
|
10123
10966
|
normalized.refresh_setting = refreshSettingToSubmit(normalized.refresh_setting);
|
|
10124
10967
|
const raw = isRecord3(value) ? value : {};
|
|
10125
10968
|
normalized.fields = normalizeComparableFieldKeys(
|
|
@@ -10127,9 +10970,36 @@ function normalizeTypedReadbackComparable(domain, value) {
|
|
|
10127
10970
|
);
|
|
10128
10971
|
}
|
|
10129
10972
|
if (domain === "dataset-field") {
|
|
10130
|
-
normalized.data_set_id
|
|
10131
|
-
|
|
10132
|
-
|
|
10973
|
+
delete normalized.data_set_id;
|
|
10974
|
+
delete normalized.dataSetId;
|
|
10975
|
+
delete normalized.dataset_id;
|
|
10976
|
+
}
|
|
10977
|
+
if (domain === "user") {
|
|
10978
|
+
delete normalized.phone;
|
|
10979
|
+
if (normalized.user_model_id !== void 0 && normalized.modelList === void 0) {
|
|
10980
|
+
const modelId = normalizeComparableId(normalized.user_model_id);
|
|
10981
|
+
normalized.modelList = modelId === null || modelId === void 0 || modelId === "" ? [] : [modelId];
|
|
10982
|
+
}
|
|
10983
|
+
delete normalized.user_model_id;
|
|
10984
|
+
for (const field of ["group_ids", "role_ids", "modelList"]) {
|
|
10985
|
+
if (Array.isArray(normalized[field])) {
|
|
10986
|
+
normalized[field] = [...new Set(normalized[field].map(normalizeComparableId))].sort((left, right) => String(left).localeCompare(String(right)));
|
|
10987
|
+
}
|
|
10988
|
+
}
|
|
10989
|
+
}
|
|
10990
|
+
if (domain === "team" && typeof normalized.admin_users === "string") {
|
|
10991
|
+
normalized.admin_users = normalized.admin_users.split(",").map((item) => normalizeComparableId(item.trim())).filter(Boolean).sort((left, right) => String(left).localeCompare(String(right)));
|
|
10992
|
+
}
|
|
10993
|
+
if (domain === "team" && (normalized.platform_id === null || normalized.platform_id === 0 || normalized.platform_id === "0")) {
|
|
10994
|
+
normalized.platform_id = null;
|
|
10995
|
+
}
|
|
10996
|
+
if (domain === "user-model" || domain === "group-model") {
|
|
10997
|
+
for (const field of ["form_template_id", "role_id"]) {
|
|
10998
|
+
if (normalized[field] !== void 0 && normalized[field] !== null) normalized[field] = normalizeComparableId(normalized[field]);
|
|
10999
|
+
}
|
|
11000
|
+
if (Array.isArray(normalized.sub_ids)) {
|
|
11001
|
+
normalized.sub_ids = [...new Set(normalized.sub_ids.map(normalizeComparableId))].sort((left, right) => String(left).localeCompare(String(right)));
|
|
11002
|
+
}
|
|
10133
11003
|
}
|
|
10134
11004
|
if (domain === "list-template" || domain === "filter-template" || domain === "project-detail-template" || domain === "step-detail-template" || domain === "console-template") {
|
|
10135
11005
|
if (Object.prototype.hasOwnProperty.call(normalized, "data_set_id")) {
|
|
@@ -10226,8 +11096,8 @@ async function resolveFlowAppContextFlowId(profile, flow) {
|
|
|
10226
11096
|
}
|
|
10227
11097
|
const client = createApiClient(profile);
|
|
10228
11098
|
const options = await apiRequest(client, "GET", "/flow/options", { capability: "flow.options" });
|
|
10229
|
-
const
|
|
10230
|
-
const matches =
|
|
11099
|
+
const rows2 = extractListData(options);
|
|
11100
|
+
const matches = rows2.filter((item) => String(item.name || item.title || "").trim() === trimmed);
|
|
10231
11101
|
if (matches.length !== 1) {
|
|
10232
11102
|
throw new Error(
|
|
10233
11103
|
`flow-app context could not resolve flow name "${trimmed}" (${matches.length} matches). Use --flow flow_type:<flow_type>, --flow key:<flow_key>, or run bpmax-cli flow options --name "<name>" --format json first.`
|
|
@@ -10434,15 +11304,49 @@ async function readRemoteConfigDomain(profile, domain, id, definition) {
|
|
|
10434
11304
|
definition.exportPath(id),
|
|
10435
11305
|
{ capability: `${definition.capability}.export` }
|
|
10436
11306
|
);
|
|
11307
|
+
if (domain !== "flow-template") {
|
|
11308
|
+
assertRemoteConfigExists(domain, id, data);
|
|
11309
|
+
}
|
|
11310
|
+
if (domain === "user") {
|
|
11311
|
+
return privacySafeUserConfig(data);
|
|
11312
|
+
}
|
|
11313
|
+
if (domain === "team") {
|
|
11314
|
+
return privacySafeTeamConfig(data);
|
|
11315
|
+
}
|
|
11316
|
+
if (domain === "user-model" || domain === "group-model") {
|
|
11317
|
+
return privacySafeModelConfig(domain, data);
|
|
11318
|
+
}
|
|
10437
11319
|
if (domain !== "flow-template" || hasUsableFlowTemplateData(data)) {
|
|
11320
|
+
if (domain === "flow-template") assertRemoteConfigExists(domain, id, data);
|
|
10438
11321
|
return data;
|
|
10439
11322
|
}
|
|
10440
|
-
|
|
11323
|
+
const liveData = await apiRequest(
|
|
10441
11324
|
createApiClient(profile),
|
|
10442
11325
|
"GET",
|
|
10443
11326
|
flowLiveExportPath(id),
|
|
10444
11327
|
{ capability: `${definition.capability}.export` }
|
|
10445
11328
|
);
|
|
11329
|
+
assertRemoteConfigExists(domain, id, liveData);
|
|
11330
|
+
return liveData;
|
|
11331
|
+
}
|
|
11332
|
+
function assertRemoteConfigExists(domain, id, value) {
|
|
11333
|
+
if (domain === "project-detail-template" && id === "0") return;
|
|
11334
|
+
const identityRequired = domain === "user" || domain === "team" || domain === "user-model" || domain === "group-model";
|
|
11335
|
+
const identityMissing = identityRequired && /^\d+$/.test(id) && (!isRecord3(value) || String(value.id ?? "") !== id);
|
|
11336
|
+
const nestedDataMissing = isRecord3(value) && Object.prototype.hasOwnProperty.call(value, "data") && value.data === null;
|
|
11337
|
+
const deleted = isRecord3(value) && (value.is_del === 1 || value.is_del === "1");
|
|
11338
|
+
const emptyObject = isRecord3(value) && Object.keys(value).length === 0;
|
|
11339
|
+
const emptyFormPlaceholder = domain === "form-template" && isRecord3(value) && Array.isArray(value.rule) && value.rule.length === 0 && Array.isArray(value.value) && value.value.length === 0 && Object.keys(value).every((key) => key === "rule" || key === "value");
|
|
11340
|
+
if (value !== null && value !== void 0 && !nestedDataMissing && !deleted && !emptyObject && !emptyFormPlaceholder && !identityMissing) {
|
|
11341
|
+
return;
|
|
11342
|
+
}
|
|
11343
|
+
throw configWorkflowError(`\u8FDC\u7AEF ${domain} \u914D\u7F6E ${id} \u4E0D\u5B58\u5728\u6216\u5DF2\u5220\u9664\u3002`, {
|
|
11344
|
+
code: "config_remote_not_found",
|
|
11345
|
+
rule_id: "config.readback.exists",
|
|
11346
|
+
domain,
|
|
11347
|
+
path: id,
|
|
11348
|
+
suggestion: "\u91CD\u65B0\u67E5\u8BE2\u6709\u6548\u914D\u7F6E ID\uFF1B\u4E0D\u8981\u628A\u7A7A\u54CD\u5E94\u3001\u5220\u9664\u6807\u8BB0\u6216\u5360\u4F4D\u5BF9\u8C61\u5F53\u6210\u6210\u529F\u56DE\u8BFB\u3002"
|
|
11349
|
+
});
|
|
10446
11350
|
}
|
|
10447
11351
|
function extractRecords(value) {
|
|
10448
11352
|
if (Array.isArray(value)) return value.filter(isRecord3);
|
|
@@ -10766,7 +11670,7 @@ async function buildConfigSubmitPayload(domain, workFile, outFile, metaFile, opt
|
|
|
10766
11670
|
throw new Error(`step-detail-template lint failed: ${errors.join("; ")}`);
|
|
10767
11671
|
}
|
|
10768
11672
|
}
|
|
10769
|
-
const payloadWork = domain === "dataset-field" && createMode && isRecord3(work) ? { ...work, mode: "create" } : work;
|
|
11673
|
+
const payloadWork = (domain === "dataset" || domain === "dataset-field") && createMode && isRecord3(work) ? { ...work, mode: "create" } : work;
|
|
10770
11674
|
const payload = buildDomainSubmitPayload(domain, payloadWork, options, raw);
|
|
10771
11675
|
if (domain === "flow-template" && options.publishLive) {
|
|
10772
11676
|
payload.publish_live = true;
|
|
@@ -10925,6 +11829,13 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
10925
11829
|
errors.push(error instanceof Error ? error.message : String(error));
|
|
10926
11830
|
}
|
|
10927
11831
|
}
|
|
11832
|
+
if (options.domain === "team" || options.domain === "user" || options.domain === "user-model" || options.domain === "group-model") {
|
|
11833
|
+
try {
|
|
11834
|
+
buildDomainSubmitPayload(options.domain, value);
|
|
11835
|
+
} catch (error) {
|
|
11836
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
11837
|
+
}
|
|
11838
|
+
}
|
|
10928
11839
|
if (Object.prototype.hasOwnProperty.call(value, "content")) {
|
|
10929
11840
|
lintTemplateFieldReferences(value, errors);
|
|
10930
11841
|
}
|
|
@@ -10932,6 +11843,12 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
10932
11843
|
if (shouldLintFormTemplate) {
|
|
10933
11844
|
validateFormTemplateWorkLint(value, errors);
|
|
10934
11845
|
}
|
|
11846
|
+
if (options.domain === "filter-template") {
|
|
11847
|
+
lintFilterTemplateWork(value, errors);
|
|
11848
|
+
}
|
|
11849
|
+
if (options.domain && CONFIG_DOMAINS[options.domain].expectedType !== void 0) {
|
|
11850
|
+
validatePageTemplateName(value, errors);
|
|
11851
|
+
}
|
|
10935
11852
|
if (options.domain === "step-detail-template") {
|
|
10936
11853
|
stepDetailAnalysis = lintStepDetailTemplateWork(value, errors, warnings);
|
|
10937
11854
|
}
|
|
@@ -10967,7 +11884,7 @@ async function lintConfigWorkFile(file, options = {}) {
|
|
|
10967
11884
|
errors.push(...stepDetailReferenceAudit.errors.filter((error) => !errors.includes(error)));
|
|
10968
11885
|
warnings.push(...stepDetailReferenceAudit.warnings);
|
|
10969
11886
|
}
|
|
10970
|
-
if (flowWork.mode === "create") {
|
|
11887
|
+
if (options.mode === "create" || flowWork.mode === "create") {
|
|
10971
11888
|
validateFlowTemplateFormDrivenCreateBaseline(flowWork, errors, { context: "flow-template create" });
|
|
10972
11889
|
} else {
|
|
10973
11890
|
validateFlowTemplateStandardFlowType(flowWork, errors);
|
|
@@ -11275,6 +12192,13 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11275
12192
|
}
|
|
11276
12193
|
let stepDetailAnalysis;
|
|
11277
12194
|
const submitMode = isRecord3(meta) ? meta.mode : void 0;
|
|
12195
|
+
if (domain === "team" || domain === "user" || domain === "user-model" || domain === "group-model") {
|
|
12196
|
+
const validationWork = { ...submit.payload, mode: submitMode };
|
|
12197
|
+
if (submitMode !== "create") validationWork.id = id;
|
|
12198
|
+
const normalizedPayload = buildDomainSubmitPayload(domain, validationWork);
|
|
12199
|
+
for (const key of Object.keys(submit.payload)) delete submit.payload[key];
|
|
12200
|
+
Object.assign(submit.payload, normalizedPayload);
|
|
12201
|
+
}
|
|
11278
12202
|
if (submitMode === "create" && domain !== "form-template") {
|
|
11279
12203
|
if (!definition.createPath || !definition.createMethod) {
|
|
11280
12204
|
throw new Error(`${domain} create is not implemented in the typed adapter.`);
|
|
@@ -11282,6 +12206,13 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11282
12206
|
if (domain === "list-template") {
|
|
11283
12207
|
validateListTemplateActionGate(submit.payload);
|
|
11284
12208
|
}
|
|
12209
|
+
if (domain === "filter-template") {
|
|
12210
|
+
const errors = [];
|
|
12211
|
+
lintFilterTemplateWork(submit.payload, errors);
|
|
12212
|
+
if (errors.length) {
|
|
12213
|
+
throw new Error(`filter-template lint failed: ${errors.join("; ")}`);
|
|
12214
|
+
}
|
|
12215
|
+
}
|
|
11285
12216
|
if (domain === "flow-template") {
|
|
11286
12217
|
validateNonEmptyFlowCreatePayload(submit.payload);
|
|
11287
12218
|
}
|
|
@@ -11314,7 +12245,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11314
12245
|
id,
|
|
11315
12246
|
endpoint: definition.createPath,
|
|
11316
12247
|
method: definition.createMethod,
|
|
11317
|
-
payload: submit.payload,
|
|
12248
|
+
payload: configPayloadForOutput(domain, submit.payload),
|
|
11318
12249
|
...stepDetailAnalysis ? {
|
|
11319
12250
|
step_detail_template: stepDetailAnalysisEvidence(stepDetailAnalysis),
|
|
11320
12251
|
warnings: stepDetailAnalysis.warnings,
|
|
@@ -11324,12 +12255,34 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11324
12255
|
};
|
|
11325
12256
|
}
|
|
11326
12257
|
const client2 = createApiClient(profile);
|
|
11327
|
-
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
12258
|
+
let response2;
|
|
12259
|
+
try {
|
|
12260
|
+
response2 = await apiRequest(
|
|
12261
|
+
client2,
|
|
12262
|
+
definition.createMethod,
|
|
12263
|
+
definition.createPath,
|
|
12264
|
+
{ data: submit.payload, capability: `${definition.capability}.create` }
|
|
12265
|
+
);
|
|
12266
|
+
} catch (error) {
|
|
12267
|
+
const status = errorStatus(error);
|
|
12268
|
+
const remoteWriteState = status && status >= 400 && status < 500 ? "not_started" : "unknown";
|
|
12269
|
+
throw configWorkflowError(
|
|
12270
|
+
`${domain} \u521B\u5EFA\u8BF7\u6C42\u5931\u8D25${status ? `\uFF08HTTP ${status}\uFF09` : ""}\uFF1B\u8FDC\u7AEF\u5199\u5165\u72B6\u6001\u4E3A ${remoteWriteState}\u3002${remoteWriteState === "unknown" ? " \u4E0D\u8981\u76F4\u63A5\u91CD\u8BD5\uFF0C\u4EE5\u514D\u521B\u5EFA\u91CD\u590D\u5BF9\u8C61\u3002" : ""}`,
|
|
12271
|
+
{
|
|
12272
|
+
code: "config_remote_create_failed",
|
|
12273
|
+
rule_id: "config.create.remote_mutation",
|
|
12274
|
+
domain,
|
|
12275
|
+
path: definition.createPath,
|
|
12276
|
+
request_phase: "mutation",
|
|
12277
|
+
http_status: status ?? null,
|
|
12278
|
+
remote_error: error instanceof Error ? error.message : String(error ?? ""),
|
|
12279
|
+
remote_write_state: remoteWriteState,
|
|
12280
|
+
remote_submitted: remoteWriteState === "not_started" ? false : null,
|
|
12281
|
+
readback_confirmed: false,
|
|
12282
|
+
suggestion: remoteWriteState === "unknown" ? `\u5148\u4F7F\u7528 bpmax-cli config ${domain} export/readback \u6216\u5BF9\u5E94\u641C\u7D22\u547D\u4EE4\u786E\u8BA4\u5BF9\u8C61\u662F\u5426\u5DF2\u521B\u5EFA\uFF1B\u786E\u8BA4\u4E0D\u5B58\u5728\u540E\u518D\u91CD\u8BD5\u3002` : "\u4FEE\u6B63\u8FDC\u7AEF\u6821\u9A8C\u9519\u8BEF\u540E\u91CD\u65B0\u6267\u884C create\u3002"
|
|
12283
|
+
}
|
|
12284
|
+
);
|
|
12285
|
+
}
|
|
11333
12286
|
const createdId = responseDataId(response2);
|
|
11334
12287
|
if (createdId === void 0 || createdId === null || createdId === "") {
|
|
11335
12288
|
throw new Error(`${domain} create did not return an id required for exact typed readback.`);
|
|
@@ -11440,6 +12393,13 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11440
12393
|
if (domain === "list-template") {
|
|
11441
12394
|
validateListTemplateActionGate(submit.payload);
|
|
11442
12395
|
}
|
|
12396
|
+
if (domain === "filter-template") {
|
|
12397
|
+
const errors = [];
|
|
12398
|
+
lintFilterTemplateWork(submit.payload, errors);
|
|
12399
|
+
if (errors.length) {
|
|
12400
|
+
throw new Error(`filter-template lint failed: ${errors.join("; ")}`);
|
|
12401
|
+
}
|
|
12402
|
+
}
|
|
11443
12403
|
if (domain === "console-template") {
|
|
11444
12404
|
const errors = [];
|
|
11445
12405
|
const warnings = [];
|
|
@@ -11466,7 +12426,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11466
12426
|
id,
|
|
11467
12427
|
endpoint: endpoint2,
|
|
11468
12428
|
method: "POST",
|
|
11469
|
-
payload: submit.payload,
|
|
12429
|
+
payload: configPayloadForOutput(domain, submit.payload),
|
|
11470
12430
|
publish_endpoint: "/form_template/publish",
|
|
11471
12431
|
next: `Run again with --confirm "${expectedConfirm2}" to submit.`
|
|
11472
12432
|
};
|
|
@@ -11536,6 +12496,14 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11536
12496
|
throw new Error("dataset edit refuses to change custom_key identity through relationFields.");
|
|
11537
12497
|
}
|
|
11538
12498
|
}
|
|
12499
|
+
if (domain === "team") {
|
|
12500
|
+
if (isRecord3(current) && Object.prototype.hasOwnProperty.call(current, "platform_id")) {
|
|
12501
|
+
if (submit.payload.platform_id === void 0 || Number(submit.payload.platform_id) !== Number(current.platform_id)) {
|
|
12502
|
+
throw new Error("team edit \u5FC5\u987B\u539F\u6837\u4FDD\u7559\u7EBF\u4E0A platform_id\uFF1B\u4E0D\u5F97\u5220\u9664\u6216\u4FEE\u6539\u5916\u90E8\u5E73\u53F0\u7ED1\u5B9A\u3002");
|
|
12503
|
+
}
|
|
12504
|
+
}
|
|
12505
|
+
await assertTeamParentDoesNotCreateCycle(profile, id, submit.payload, definition, current);
|
|
12506
|
+
}
|
|
11539
12507
|
validateExpectedType(domain, definition, current);
|
|
11540
12508
|
const currentHash = hashJson(current);
|
|
11541
12509
|
if (currentHash !== submit.base_hash) {
|
|
@@ -11627,7 +12595,7 @@ async function submitConfigDomain(config, profile, domain, id, submitFile, confi
|
|
|
11627
12595
|
remote_error: remoteError,
|
|
11628
12596
|
changed_paths: changedPaths,
|
|
11629
12597
|
remote_write_state: remoteWriteState,
|
|
11630
|
-
remote_submitted: remoteWriteState === "confirmed",
|
|
12598
|
+
remote_submitted: remoteWriteState === "confirmed" ? true : remoteWriteState === "not_started" ? false : null,
|
|
11631
12599
|
readback_confirmed: readbackConfirmed,
|
|
11632
12600
|
...readbackError ? { readback_error: readbackError } : {},
|
|
11633
12601
|
suggestion: `\u5148\u6267\u884C bpmax-cli config ${domain} verify --id ${id} --profile ${profile.name} --format json\uFF1B\u786E\u8BA4\u7EBF\u4E0A\u72B6\u6001\u540E\u518D\u51B3\u5B9A\u662F\u5426\u91CD\u8BD5\u3002`
|
|
@@ -11720,12 +12688,53 @@ async function deleteConfigDomain(config, profile, domain, id, confirm3) {
|
|
|
11720
12688
|
next: `Run again with --confirm "${expectedConfirm}" to delete.`
|
|
11721
12689
|
};
|
|
11722
12690
|
}
|
|
11723
|
-
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
12691
|
+
let response;
|
|
12692
|
+
try {
|
|
12693
|
+
response = await apiRequest(
|
|
12694
|
+
client,
|
|
12695
|
+
definition.deleteMethod,
|
|
12696
|
+
endpoint,
|
|
12697
|
+
{ capability: `${definition.capability}.delete` }
|
|
12698
|
+
);
|
|
12699
|
+
} catch (error) {
|
|
12700
|
+
let remoteWriteState = "unknown";
|
|
12701
|
+
let readbackConfirmed = false;
|
|
12702
|
+
let readbackError;
|
|
12703
|
+
if (domain === "team" || domain === "user" || domain === "user-model" || domain === "group-model") {
|
|
12704
|
+
try {
|
|
12705
|
+
await readRemoteConfigDomain(profile, domain, id, definition);
|
|
12706
|
+
remoteWriteState = "not_started";
|
|
12707
|
+
} catch (readError) {
|
|
12708
|
+
if (workflowErrorCode(readError) === "config_remote_not_found") {
|
|
12709
|
+
remoteWriteState = "confirmed";
|
|
12710
|
+
readbackConfirmed = true;
|
|
12711
|
+
} else {
|
|
12712
|
+
readbackError = readError instanceof Error ? readError.message : String(readError ?? "");
|
|
12713
|
+
}
|
|
12714
|
+
}
|
|
12715
|
+
} else {
|
|
12716
|
+
const status2 = errorStatus(error);
|
|
12717
|
+
if (status2 && status2 >= 400 && status2 < 500) remoteWriteState = "not_started";
|
|
12718
|
+
}
|
|
12719
|
+
const status = errorStatus(error);
|
|
12720
|
+
throw configWorkflowError(
|
|
12721
|
+
`${domain} \u5220\u9664\u8BF7\u6C42\u5931\u8D25${status ? `\uFF08HTTP ${status}\uFF09` : ""}\uFF1B\u8FDC\u7AEF\u5199\u5165\u72B6\u6001\u4E3A ${remoteWriteState}\u3002${remoteWriteState === "unknown" ? " \u5728\u5B8C\u6210\u53EA\u8BFB\u56DE\u8BFB\u524D\u4E0D\u8981\u91CD\u590D\u5220\u9664\u3002" : ""}`,
|
|
12722
|
+
{
|
|
12723
|
+
code: "config_remote_delete_failed",
|
|
12724
|
+
rule_id: "config.delete.remote_mutation",
|
|
12725
|
+
domain,
|
|
12726
|
+
path: endpoint,
|
|
12727
|
+
request_phase: "mutation",
|
|
12728
|
+
http_status: status ?? null,
|
|
12729
|
+
remote_error: error instanceof Error ? error.message : String(error ?? ""),
|
|
12730
|
+
remote_write_state: remoteWriteState,
|
|
12731
|
+
remote_submitted: remoteWriteState === "confirmed",
|
|
12732
|
+
readback_confirmed: readbackConfirmed,
|
|
12733
|
+
...readbackError ? { readback_error: readbackError } : {},
|
|
12734
|
+
suggestion: remoteWriteState === "not_started" ? "\u8FDC\u7AEF\u5BF9\u8C61\u4ECD\u5B58\u5728\uFF1B\u6392\u9664\u963B\u65AD\u539F\u56E0\u540E\u53EF\u91CD\u65B0\u6267\u884C\u5220\u9664\u3002" : `\u5148\u6267\u884C bpmax-cli config ${domain} export --id ${id} --inline --profile ${profile.name} --format json \u786E\u8BA4\u5BF9\u8C61\u72B6\u6001\u3002`
|
|
12735
|
+
}
|
|
12736
|
+
);
|
|
12737
|
+
}
|
|
11729
12738
|
return {
|
|
11730
12739
|
dry_run: false,
|
|
11731
12740
|
domain,
|
|
@@ -12005,6 +13014,10 @@ var CONFIG_DOMAINS2 = [
|
|
|
12005
13014
|
["dataset-field", "bpmax-dataset-field-template-editor", "\u6570\u636E\u96C6\u5B57\u6BB5"],
|
|
12006
13015
|
["api-platform", "bpmax-api-platform-editor", "API \u5E73\u53F0"],
|
|
12007
13016
|
["role", "bpmax-role-editor", "\u89D2\u8272\u6743\u9650"],
|
|
13017
|
+
["team", "bpmax-team-editor", "\u56E2\u961F\u4E0E\u7EC4\u7EC7\u6811"],
|
|
13018
|
+
["user", "bpmax-user", "\u7528\u6237\u4E0E\u7EC4\u7EC7\u5173\u7CFB"],
|
|
13019
|
+
["user-model", "bpmax-user-model-editor", "\u7528\u6237\u6A21\u578B"],
|
|
13020
|
+
["group-model", "bpmax-group-model-editor", "\u56E2\u961F\u6A21\u578B"],
|
|
12008
13021
|
["nav-config", "bpmax-nav-config-editor", "\u5BFC\u822A\u914D\u7F6E"]
|
|
12009
13022
|
];
|
|
12010
13023
|
var CONFIG_DIRECTORY_PURPOSES = [
|
|
@@ -12018,6 +13031,10 @@ var CONFIG_DIRECTORY_PURPOSES = [
|
|
|
12018
13031
|
["think_api_proxy/", "API proxy configurations"],
|
|
12019
13032
|
["think_workspace/", "Workspace definitions"],
|
|
12020
13033
|
["think_role/", "Role definitions"],
|
|
13034
|
+
["think_group/", "Team hierarchy and organization-unit definitions"],
|
|
13035
|
+
["think_user/", "Organization user definitions and relation bindings"],
|
|
13036
|
+
["think_user_model/", "User model definitions"],
|
|
13037
|
+
["think_group_model/", "Team model definitions"],
|
|
12021
13038
|
["think_category/", "Category definitions"]
|
|
12022
13039
|
];
|
|
12023
13040
|
async function hasExpectedWorkspaceEntry(root, entry) {
|
|
@@ -12180,7 +13197,7 @@ function renderConfigWorkspaceGuide(options) {
|
|
|
12180
13197
|
const profileArg = shellQuote3(options.profileName);
|
|
12181
13198
|
const envArg = shellQuote3(options.env);
|
|
12182
13199
|
const commandPrefix3 = options.commandPrefix || "bpmax-cli";
|
|
12183
|
-
const
|
|
13200
|
+
const rows2 = CONFIG_DOMAINS2.map(
|
|
12184
13201
|
([domain, skill, label]) => `| ${label} | \`${skill}\` | \`${commandPrefix3} config ${domain} ...\` |`
|
|
12185
13202
|
).join("\n");
|
|
12186
13203
|
const directoryRows = CONFIG_DIRECTORY_PURPOSES.map(
|
|
@@ -12225,7 +13242,7 @@ ${directoryRows}
|
|
|
12225
13242
|
## Skill \u8DEF\u7531
|
|
12226
13243
|
| \u914D\u7F6E\u7C7B\u578B | Skill | CLI |
|
|
12227
13244
|
| --- | --- | --- |
|
|
12228
|
-
${
|
|
13245
|
+
${rows2}
|
|
12229
13246
|
| \u63D2\u4EF6 typed config | \u63D2\u4EF6\u4E13\u9879 skill | \`${commandPrefix3} config plugin <domain> ...\` |
|
|
12230
13247
|
| \u6700\u65B0\u914D\u7F6E\u540C\u6B65 | \`bpmax-config-latest\` | \`${commandPrefix3} config latest pull ${options.env}\` |
|
|
12231
13248
|
| \u957F\u671F\u8BB0\u5FC6 | \`bpmax-memory-protocol\` | \`${commandPrefix3} memory search --scope all --query "<env> <flow_type> <task>"\` |
|
|
@@ -13656,7 +14673,7 @@ function registerConfigCommands(program2) {
|
|
|
13656
14673
|
});
|
|
13657
14674
|
profile.command("list").description("List profiles").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
13658
14675
|
const configData = await loadConfig();
|
|
13659
|
-
const
|
|
14676
|
+
const rows2 = Object.entries(configData.profiles).map(([name, profileConfig]) => ({
|
|
13660
14677
|
name,
|
|
13661
14678
|
current: configData.current_profile === name,
|
|
13662
14679
|
origin: profileConfig.origin,
|
|
@@ -13664,7 +14681,7 @@ function registerConfigCommands(program2) {
|
|
|
13664
14681
|
language: profileConfig.language || DEFAULT_LANGUAGE,
|
|
13665
14682
|
api_key: maskApiKey(profileConfig.api_key)
|
|
13666
14683
|
}));
|
|
13667
|
-
printResult(options.format,
|
|
14684
|
+
printResult(options.format, rows2);
|
|
13668
14685
|
});
|
|
13669
14686
|
profile.command("use <name>").description("Set the active profile").action(async (name) => {
|
|
13670
14687
|
const configData = await loadConfig();
|
|
@@ -13711,13 +14728,13 @@ function registerConfigCommands(program2) {
|
|
|
13711
14728
|
});
|
|
13712
14729
|
config.command("adapters").description("Show typed config domain adapter coverage and verified API surfaces").option("--profile <profile>", "Profile name (accepted for consistency; adapter coverage is local and profile-independent)").option("--capability <capability>", "Filter by capability name, e.g. config.dataset_field.create").option("--format <format>", "Output format", "table").action(async (options) => {
|
|
13713
14730
|
void options.profile;
|
|
13714
|
-
const
|
|
13715
|
-
const filtered = options.capability ?
|
|
14731
|
+
const rows2 = configAdapterMatrix();
|
|
14732
|
+
const filtered = options.capability ? rows2.filter((row) => Object.values(row).some((value) => {
|
|
13716
14733
|
if (Array.isArray(value)) {
|
|
13717
14734
|
return value.includes(options.capability);
|
|
13718
14735
|
}
|
|
13719
14736
|
return value === options.capability;
|
|
13720
|
-
})) :
|
|
14737
|
+
})) : rows2;
|
|
13721
14738
|
printResult(options.format, filtered);
|
|
13722
14739
|
});
|
|
13723
14740
|
config.command("plugin").description("Manage plugin-provided typed config adapters").argument("[domain]", "Plugin typed config domain, or adapters").argument("[operation]", "Operation: export, lint, build, diff, submit, verify, test").option("--id <id>", "Remote plugin config id, list/all, or create:<stable-key>").option("--work <file>", "Work JSON file").option("--base <file>", "Optional raw baseline JSON for lifecycle rules").option("--out <file>", "Output file or directory").option("--meta <file>", "Export meta JSON file").option("--submit <file>", "Submit JSON file for diff").option("--payload <file>", "Submit payload JSON file produced by build").option("--expect <file>", "Expected work JSON file").option("--message <message>", "Smoke test message").option("--profile <profile>", "Profile name").option("--agent <agent>", "Agent adapter for installed plugin adapter discovery", "codex").option("--confirm <text>", "Exact confirmation text").option("--format <format>", "Output format", "pretty").action(async (domain, operation, options) => {
|
|
@@ -13987,7 +15004,10 @@ function registerConfigCommands(program2) {
|
|
|
13987
15004
|
await saveConfig(configData);
|
|
13988
15005
|
printResult(options.format, result);
|
|
13989
15006
|
});
|
|
13990
|
-
domainCommand.command("lint").description(`Lint a ${domain} work file`).requiredOption("--work <file>", "Work JSON file").option("--profile <profile>", "Profile name for plugin lint discovery").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
15007
|
+
domainCommand.command("lint").description(`Lint a ${domain} work file`).requiredOption("--work <file>", "Work JSON file").option("--mode <mode>", "Lint mode: create | edit").option("--profile <profile>", "Profile name for plugin lint discovery").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--format <format>", "Output format", "pretty").action(async (options) => {
|
|
15008
|
+
if (options.mode && options.mode !== "create" && options.mode !== "edit") {
|
|
15009
|
+
throw new Error("--mode \u53EA\u5141\u8BB8 create \u6216 edit\u3002");
|
|
15010
|
+
}
|
|
13991
15011
|
let pluginLint;
|
|
13992
15012
|
if (domain === "flow-template") {
|
|
13993
15013
|
pluginLint = await resolveFlowTemplatePluginLintOptions({
|
|
@@ -13996,7 +15016,11 @@ function registerConfigCommands(program2) {
|
|
|
13996
15016
|
requireInstalled: true
|
|
13997
15017
|
});
|
|
13998
15018
|
}
|
|
13999
|
-
const result = await lintConfigWorkFile(options.work, {
|
|
15019
|
+
const result = await lintConfigWorkFile(options.work, {
|
|
15020
|
+
domain,
|
|
15021
|
+
mode: options.mode,
|
|
15022
|
+
pluginLint
|
|
15023
|
+
});
|
|
14000
15024
|
if (!result.ok) {
|
|
14001
15025
|
printResult(options.format, result);
|
|
14002
15026
|
throw new Error(`Config lint failed for ${options.work}`);
|
|
@@ -14146,6 +15170,9 @@ function registerConfigCommands(program2) {
|
|
|
14146
15170
|
);
|
|
14147
15171
|
await saveConfig(configData);
|
|
14148
15172
|
printResult(options.format, result);
|
|
15173
|
+
if (result.ok === false) {
|
|
15174
|
+
process.exitCode = 1;
|
|
15175
|
+
}
|
|
14149
15176
|
});
|
|
14150
15177
|
});
|
|
14151
15178
|
}
|
|
@@ -14445,8 +15472,8 @@ function csvValue(value) {
|
|
|
14445
15472
|
const text5 = String(value ?? "");
|
|
14446
15473
|
return /[",\r\n]/.test(text5) ? `"${text5.replace(/"/g, '""')}"` : text5;
|
|
14447
15474
|
}
|
|
14448
|
-
function csvText(fields,
|
|
14449
|
-
return `${[fields.join(","), ...
|
|
15475
|
+
function csvText(fields, rows2) {
|
|
15476
|
+
return `${[fields.join(","), ...rows2.map((row) => fields.map((field) => csvValue(row[field])).join(","))].join("\n")}
|
|
14450
15477
|
`;
|
|
14451
15478
|
}
|
|
14452
15479
|
async function readCases(filePath) {
|
|
@@ -14612,10 +15639,10 @@ function keywordCandidates(value) {
|
|
|
14612
15639
|
return [...new Set(value.split(/[、,,;;\s>,。::/]+/).map((word) => word.trim()).filter((word) => word.length >= 2).flatMap((word) => word.length >= 4 ? [word, word.slice(0, 4)] : [word]))].slice(0, 12);
|
|
14613
15640
|
}
|
|
14614
15641
|
function businessScenarioAlignmentMessage(filePath, caseId, row, steps, scenarioValue) {
|
|
14615
|
-
const
|
|
14616
|
-
const contextKeywords = keywordCandidates(
|
|
15642
|
+
const context2 = [row.title, row.preconditions, row.prep_data, caseStepText(steps), row.expected_result].join(" ");
|
|
15643
|
+
const contextKeywords = keywordCandidates(context2);
|
|
14617
15644
|
const scenarioKeywords = keywordCandidates(scenarioValue);
|
|
14618
|
-
const unmatched = scenarioKeywords.filter((word) => !
|
|
15645
|
+
const unmatched = scenarioKeywords.filter((word) => !context2.includes(word));
|
|
14619
15646
|
const suggestion = `\u4E1A\u52A1\u573A\u666F=${row.title || "<\u5BA2\u6237\u4E1A\u52A1\u52A8\u4F5C>"};\u4E1A\u52A1\u903B\u8F91=<\u8BF4\u660E\u8BE5\u573A\u666F\u9A8C\u8BC1\u7684\u6D41\u7A0B/\u6570\u636E/\u5BA1\u6279\u89C4\u5219>;\u6837\u672C\u6570\u636E=<\u8BF4\u660E\u771F\u5B9E\u4E1A\u52A1\u6837\u672C\u5C5E\u6027>;\u5408\u7406\u6027=<\u8BF4\u660E\u6837\u672C\u7B26\u5408\u5BA2\u6237\u4E1A\u52A1\u89C4\u5219>`;
|
|
14620
15647
|
return [
|
|
14621
15648
|
`${filePath}:${caseId}: \`test_data\` token \`\u4E1A\u52A1\u573A\u666F=\` must align with the case title, preconditions, steps, or expected result.`,
|
|
@@ -14887,10 +15914,10 @@ async function collectE2eAccelerationGaps(root) {
|
|
|
14887
15914
|
if (!await exists3(casesPath)) {
|
|
14888
15915
|
continue;
|
|
14889
15916
|
}
|
|
14890
|
-
const
|
|
15917
|
+
const rows2 = await readCases(casesPath);
|
|
14891
15918
|
const steps = await readCaseSteps(path10.join(dir, "case_steps.csv"));
|
|
14892
|
-
const stepsByCase = validateCaseSteps(path10.join(dir, "case_steps.csv"),
|
|
14893
|
-
for (const row of
|
|
15919
|
+
const stepsByCase = validateCaseSteps(path10.join(dir, "case_steps.csv"), rows2, steps);
|
|
15920
|
+
for (const row of rows2) {
|
|
14894
15921
|
const caseSteps = stepsByCase.get(row.case_id.trim()) ?? [];
|
|
14895
15922
|
if (row.status === "deprecated" || hasE2eReusableAsset(row, caseSteps)) {
|
|
14896
15923
|
continue;
|
|
@@ -14914,18 +15941,18 @@ async function scenarioDirs(root) {
|
|
|
14914
15941
|
async function validateScenario(scenarioDir) {
|
|
14915
15942
|
const metadata = await validateReadme(scenarioDir);
|
|
14916
15943
|
const casesPath = path10.join(scenarioDir, "cases.csv");
|
|
14917
|
-
const
|
|
15944
|
+
const rows2 = await readCases(casesPath);
|
|
14918
15945
|
const caseStepsPath = path10.join(scenarioDir, "case_steps.csv");
|
|
14919
15946
|
const caseSteps = await readCaseSteps(caseStepsPath);
|
|
14920
|
-
const stepsByCase = validateCaseSteps(caseStepsPath,
|
|
14921
|
-
if (
|
|
15947
|
+
const stepsByCase = validateCaseSteps(caseStepsPath, rows2, caseSteps);
|
|
15948
|
+
if (rows2.length === 0) fail(`${casesPath}: at least one case is required`);
|
|
14922
15949
|
const seen = /* @__PURE__ */ new Set();
|
|
14923
|
-
for (const row of
|
|
14924
|
-
const activeRows =
|
|
14925
|
-
const availableRows =
|
|
15950
|
+
for (const row of rows2) await validateCase(casesPath, row, stepsByCase.get(row.case_id.trim()) ?? [], seen);
|
|
15951
|
+
const activeRows = rows2.filter((row) => row.status === "active");
|
|
15952
|
+
const availableRows = rows2.filter((row) => row.status !== "deprecated");
|
|
14926
15953
|
if (metadata.status === "active" && activeRows.length === 0) fail(`${scenarioDir}: active scenario must contain active cases`);
|
|
14927
15954
|
if (metadata.core.toLowerCase() === "true" && metadata.status !== "deprecated") {
|
|
14928
|
-
const hasCorePositive =
|
|
15955
|
+
const hasCorePositive = rows2.some((row) => row.status !== "deprecated" && row.priority === "P0" && row.type === "positive");
|
|
14929
15956
|
if (!hasCorePositive) fail(`${scenarioDir}: non-deprecated core scenario requires a non-deprecated P0 positive case`);
|
|
14930
15957
|
}
|
|
14931
15958
|
await validateCopyDiffArtifacts(scenarioDir);
|
|
@@ -14937,10 +15964,10 @@ async function validateScenario(scenarioDir) {
|
|
|
14937
15964
|
core: metadata.core,
|
|
14938
15965
|
status: metadata.status,
|
|
14939
15966
|
summary: metadata.summary,
|
|
14940
|
-
case_count:
|
|
15967
|
+
case_count: rows2.length,
|
|
14941
15968
|
active_case_count: activeRows.length,
|
|
14942
15969
|
available_case_count: availableRows.length,
|
|
14943
|
-
tags: [...new Set(
|
|
15970
|
+
tags: [...new Set(rows2.flatMap((row) => row.tags.split(",").map((tag) => tag.trim()).filter(Boolean)))].sort()
|
|
14944
15971
|
};
|
|
14945
15972
|
}
|
|
14946
15973
|
async function lintSuite(root = DEFAULT_SUITE_ROOT) {
|
|
@@ -15392,11 +16419,11 @@ function currentManifestStep(manifest) {
|
|
|
15392
16419
|
async function startTestSuiteRun(options) {
|
|
15393
16420
|
const scenarioDir = scenarioPath(options.suiteRoot ?? DEFAULT_SUITE_ROOT, options.scenario);
|
|
15394
16421
|
await validateScenario(scenarioDir);
|
|
15395
|
-
const
|
|
15396
|
-
const row =
|
|
16422
|
+
const rows2 = await readCases(path10.join(scenarioDir, "cases.csv"));
|
|
16423
|
+
const row = rows2.find((item) => item.case_id === options.caseId && item.status !== "deprecated");
|
|
15397
16424
|
if (!row) fail(`${scenarioDir}: active case not found: ${options.caseId}`, { rule_id: "test_suite.run.case_not_found" });
|
|
15398
16425
|
const allSteps = await readCaseSteps(path10.join(scenarioDir, "case_steps.csv"));
|
|
15399
|
-
const grouped = validateCaseSteps(path10.join(scenarioDir, "case_steps.csv"),
|
|
16426
|
+
const grouped = validateCaseSteps(path10.join(scenarioDir, "case_steps.csv"), rows2, allSteps);
|
|
15400
16427
|
const selectedSteps = grouped.get(options.caseId) ?? [];
|
|
15401
16428
|
const reportDir = await nextReportDir(options.reportRoot ?? DEFAULT_REPORT_ROOT, true);
|
|
15402
16429
|
const runId = path10.basename(reportDir);
|
|
@@ -15827,9 +16854,9 @@ async function validateReviewGate(scenarioDir) {
|
|
|
15827
16854
|
if (!Array.isArray(review.fixes) || review.fixes.length === 0) reviewFail(reviewPath, `${reviewPath}: fixes must be a non-empty list`);
|
|
15828
16855
|
}
|
|
15829
16856
|
async function validateExecutionOperabilityReview(reviewPath, scenarioDir, item) {
|
|
15830
|
-
const
|
|
16857
|
+
const rows2 = await readCases(path10.join(scenarioDir, "cases.csv"));
|
|
15831
16858
|
const steps = await readCaseSteps(path10.join(scenarioDir, "case_steps.csv"));
|
|
15832
|
-
const activeCases = new Set(
|
|
16859
|
+
const activeCases = new Set(rows2.filter((row) => row.status !== "deprecated").map((row) => row.case_id));
|
|
15833
16860
|
const required = steps.filter((step) => activeCases.has(step.case_id)).map((step) => `${step.case_id}/${step.step_id}`);
|
|
15834
16861
|
const judgments = item.step_judgments;
|
|
15835
16862
|
if (!Array.isArray(judgments) || judgments.length === 0) {
|
|
@@ -15876,8 +16903,8 @@ async function validateConfigConsistencyReview(reviewPath, item) {
|
|
|
15876
16903
|
function asRecord(value) {
|
|
15877
16904
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
15878
16905
|
}
|
|
15879
|
-
function defaultCaseJudgments(
|
|
15880
|
-
return
|
|
16906
|
+
function defaultCaseJudgments(rows2) {
|
|
16907
|
+
return rows2.map((row) => {
|
|
15881
16908
|
const locations = configBasisLocations(row.config_basis).filter((location) => {
|
|
15882
16909
|
try {
|
|
15883
16910
|
return location.length > 0;
|
|
@@ -15901,7 +16928,7 @@ function defaultStepJudgments(steps) {
|
|
|
15901
16928
|
evidence: "Initialized by bpmax-cli; reviewer must confirm this one-row step is independently executable before promote."
|
|
15902
16929
|
}));
|
|
15903
16930
|
}
|
|
15904
|
-
function mergeReviewDraft(scenarioId, proof,
|
|
16931
|
+
function mergeReviewDraft(scenarioId, proof, rows2, steps, existing) {
|
|
15905
16932
|
const existingPerspectives = Array.isArray(existing?.perspectives) ? existing.perspectives.filter((item) => item && typeof item === "object") : [];
|
|
15906
16933
|
const byName = new Map(existingPerspectives.map((item) => [String(item.name || ""), item]));
|
|
15907
16934
|
const configConsistency = asRecord(byName.get("config_consistency"));
|
|
@@ -15929,7 +16956,7 @@ function mergeReviewDraft(scenarioId, proof, rows, steps, existing) {
|
|
|
15929
16956
|
reviewer: configConsistency.reviewer || "subagent-config",
|
|
15930
16957
|
status: configConsistency.status || "fixed",
|
|
15931
16958
|
summary: configConsistency.summary || "Initialized by bpmax-cli; replace with actual config consistency summary.",
|
|
15932
|
-
case_judgments: Array.isArray(configConsistency.case_judgments) && configConsistency.case_judgments.length > 0 ? configConsistency.case_judgments : defaultCaseJudgments(
|
|
16959
|
+
case_judgments: Array.isArray(configConsistency.case_judgments) && configConsistency.case_judgments.length > 0 ? configConsistency.case_judgments : defaultCaseJudgments(rows2),
|
|
15933
16960
|
missing_case_review: asRecord(configConsistency.missing_case_review).summary ? configConsistency.missing_case_review : { needed: false, summary: "Initialized by bpmax-cli; reviewer must confirm whether any P0/P1 cases are missing." }
|
|
15934
16961
|
};
|
|
15935
16962
|
});
|
|
@@ -15952,7 +16979,7 @@ async function initOrRepairReview(options) {
|
|
|
15952
16979
|
const scenarioDir = scenarioPath(options.draftRoot ?? DEFAULT_DRAFT_ROOT, options.scenario);
|
|
15953
16980
|
if (!await exists3(scenarioDir)) fail(`draft scenario not found: ${scenarioDir}`);
|
|
15954
16981
|
await validateReadme(scenarioDir);
|
|
15955
|
-
const
|
|
16982
|
+
const rows2 = await readCases(path10.join(scenarioDir, "cases.csv"));
|
|
15956
16983
|
const steps = await readCaseSteps(path10.join(scenarioDir, "case_steps.csv"));
|
|
15957
16984
|
const proof = await readLatestProof(options.latestProof);
|
|
15958
16985
|
const reviewPath = path10.join(scenarioDir, "review.json");
|
|
@@ -15966,7 +16993,7 @@ async function initOrRepairReview(options) {
|
|
|
15966
16993
|
existing = {};
|
|
15967
16994
|
}
|
|
15968
16995
|
}
|
|
15969
|
-
const review = mergeReviewDraft(path10.basename(scenarioDir), proof,
|
|
16996
|
+
const review = mergeReviewDraft(path10.basename(scenarioDir), proof, rows2, steps, existing);
|
|
15970
16997
|
await writeFile9(reviewPath, `${JSON.stringify(review, null, 2)}
|
|
15971
16998
|
`, "utf8");
|
|
15972
16999
|
return {
|
|
@@ -17326,27 +18353,27 @@ function registerStepCommands(program2) {
|
|
|
17326
18353
|
const config = await loadConfig();
|
|
17327
18354
|
const profile = resolveProfile(config, options.profile);
|
|
17328
18355
|
const client = createApiClient(profile);
|
|
17329
|
-
const
|
|
18356
|
+
const context2 = await buildStepContext(profile, client, id, options.projectId);
|
|
17330
18357
|
printResult(options.format, {
|
|
17331
|
-
project_id:
|
|
17332
|
-
step_id:
|
|
17333
|
-
current_flow_node:
|
|
17334
|
-
actions:
|
|
17335
|
-
identity_unverified:
|
|
17336
|
-
risk_warnings:
|
|
18358
|
+
project_id: context2.project_id,
|
|
18359
|
+
step_id: context2.step_id,
|
|
18360
|
+
current_flow_node: context2.current_flow_node,
|
|
18361
|
+
actions: context2.actions,
|
|
18362
|
+
identity_unverified: context2.identity_unverified,
|
|
18363
|
+
risk_warnings: context2.risk_warnings
|
|
17337
18364
|
});
|
|
17338
18365
|
});
|
|
17339
18366
|
step.command("requirements <id>").description("List required step inputs before submitting").requiredOption("--project-id <projectId>", "Project id").option("--data <json>", "Additional submit payload JSON or @file").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (id, options) => {
|
|
17340
18367
|
const config = await loadConfig();
|
|
17341
18368
|
const profile = resolveProfile(config, options.profile);
|
|
17342
18369
|
const client = createApiClient(profile);
|
|
17343
|
-
const
|
|
18370
|
+
const context2 = await buildStepContext(profile, client, id, options.projectId);
|
|
17344
18371
|
const data = await loadSubmitData(options.data);
|
|
17345
|
-
const requirements = buildStepRequirements(
|
|
18372
|
+
const requirements = buildStepRequirements(context2.step, context2.current_flow_node, data);
|
|
17346
18373
|
printResult(options.format, {
|
|
17347
|
-
project_id:
|
|
17348
|
-
step_id:
|
|
17349
|
-
url:
|
|
18374
|
+
project_id: context2.project_id,
|
|
18375
|
+
step_id: context2.step_id,
|
|
18376
|
+
url: context2.url,
|
|
17350
18377
|
requirements
|
|
17351
18378
|
});
|
|
17352
18379
|
});
|
|
@@ -17354,9 +18381,9 @@ function registerStepCommands(program2) {
|
|
|
17354
18381
|
const config = await loadConfig();
|
|
17355
18382
|
const profile = resolveProfile(config, options.profile);
|
|
17356
18383
|
const client = createApiClient(profile);
|
|
17357
|
-
const
|
|
18384
|
+
const context2 = await buildStepContext(profile, client, id, options.projectId);
|
|
17358
18385
|
const data = await loadSubmitData(options.data);
|
|
17359
|
-
const requirements = buildStepRequirements(
|
|
18386
|
+
const requirements = buildStepRequirements(context2.step, context2.current_flow_node, data);
|
|
17360
18387
|
const payload = {
|
|
17361
18388
|
...data,
|
|
17362
18389
|
project_id: Number(options.projectId),
|
|
@@ -17379,27 +18406,27 @@ function registerStepCommands(program2) {
|
|
|
17379
18406
|
dry_run: true,
|
|
17380
18407
|
request,
|
|
17381
18408
|
context: {
|
|
17382
|
-
project_id:
|
|
17383
|
-
step_id:
|
|
17384
|
-
url:
|
|
17385
|
-
identity_unverified:
|
|
17386
|
-
current_user_can_process:
|
|
17387
|
-
step_finished:
|
|
18409
|
+
project_id: context2.project_id,
|
|
18410
|
+
step_id: context2.step_id,
|
|
18411
|
+
url: context2.url,
|
|
18412
|
+
identity_unverified: context2.identity_unverified,
|
|
18413
|
+
current_user_can_process: context2.current_user_can_process,
|
|
18414
|
+
step_finished: context2.step_finished,
|
|
17388
18415
|
requirements,
|
|
17389
|
-
risk_warnings:
|
|
18416
|
+
risk_warnings: context2.risk_warnings
|
|
17390
18417
|
},
|
|
17391
18418
|
next_command_hint: requirements.can_submit ? "Re-run with --confirm after verifying project identity, target action, and payload." : "Fill missing required step input(s) in --data before confirming."
|
|
17392
18419
|
});
|
|
17393
18420
|
return;
|
|
17394
18421
|
}
|
|
17395
|
-
if (
|
|
18422
|
+
if (context2.identity_unverified) {
|
|
17396
18423
|
throw new Error("Refusing to submit: project identity is unverified because project and step form evidence is empty.");
|
|
17397
18424
|
}
|
|
17398
|
-
if (
|
|
18425
|
+
if (context2.step_finished) {
|
|
17399
18426
|
throw new Error("Refusing to submit: step appears to be finished.");
|
|
17400
18427
|
}
|
|
17401
|
-
if (
|
|
17402
|
-
throw new Error(`Refusing to submit: ${
|
|
18428
|
+
if (context2.current_user_can_process === false) {
|
|
18429
|
+
throw new Error(`Refusing to submit: ${context2.current_user_reason}`);
|
|
17403
18430
|
}
|
|
17404
18431
|
if (!requirements.can_submit) {
|
|
17405
18432
|
throw new Error(`Refusing to submit: missing required step input(s): ${requirements.missing_required_inputs.map((field) => field.key).join(", ")}`);
|
|
@@ -17415,12 +18442,22 @@ function registerStepCommands(program2) {
|
|
|
17415
18442
|
result,
|
|
17416
18443
|
project_id: options.projectId,
|
|
17417
18444
|
step_id: id,
|
|
17418
|
-
url:
|
|
18445
|
+
url: context2.url
|
|
17419
18446
|
});
|
|
17420
18447
|
});
|
|
17421
18448
|
}
|
|
17422
18449
|
|
|
17423
18450
|
// src/commands/e2e.ts
|
|
18451
|
+
var BrowserSessionRejectedError = class extends Error {
|
|
18452
|
+
constructor(message, status, apiCode) {
|
|
18453
|
+
super(message);
|
|
18454
|
+
this.status = status;
|
|
18455
|
+
this.apiCode = apiCode;
|
|
18456
|
+
this.name = "BrowserSessionRejectedError";
|
|
18457
|
+
}
|
|
18458
|
+
status;
|
|
18459
|
+
apiCode;
|
|
18460
|
+
};
|
|
17424
18461
|
async function requireE2eExecutionBinding(options, runners, evidenceDir) {
|
|
17425
18462
|
if (options.diagnostic) return;
|
|
17426
18463
|
if (!options.executionManifest || !options.caseId || !options.caseStepId) {
|
|
@@ -17572,10 +18609,17 @@ async function browserSessionRequest(profile, cookie, method, apiPath2, data, hr
|
|
|
17572
18609
|
});
|
|
17573
18610
|
const body = response.data;
|
|
17574
18611
|
if (response.status >= 400) {
|
|
17575
|
-
throw new
|
|
18612
|
+
throw new BrowserSessionRejectedError(
|
|
18613
|
+
`e2e.identity.http_error: HTTP ${response.status} ${apiPath2}\u3002`,
|
|
18614
|
+
response.status
|
|
18615
|
+
);
|
|
17576
18616
|
}
|
|
17577
18617
|
if (isRecord8(body) && typeof body.code === "number" && body.code !== 0) {
|
|
17578
|
-
throw new
|
|
18618
|
+
throw new BrowserSessionRejectedError(
|
|
18619
|
+
`e2e.identity.api_error: ${String(body.msg ?? body.message ?? body.code)}`,
|
|
18620
|
+
response.status,
|
|
18621
|
+
body.code
|
|
18622
|
+
);
|
|
17579
18623
|
}
|
|
17580
18624
|
return isRecord8(body) && Object.prototype.hasOwnProperty.call(body, "data") ? body.data : body;
|
|
17581
18625
|
}
|
|
@@ -17628,16 +18672,16 @@ function normalizeExpectedChecks(value) {
|
|
|
17628
18672
|
...Array.isArray(item.values) ? { values: item.values } : {}
|
|
17629
18673
|
})).filter((item) => item.path);
|
|
17630
18674
|
}
|
|
17631
|
-
function expectationTarget(
|
|
18675
|
+
function expectationTarget(context2, requirements) {
|
|
17632
18676
|
return {
|
|
17633
18677
|
context: {
|
|
17634
|
-
current_user_can_process:
|
|
17635
|
-
identity_unverified:
|
|
17636
|
-
step_finished:
|
|
17637
|
-
current_user_reason:
|
|
17638
|
-
actions:
|
|
17639
|
-
action_labels:
|
|
17640
|
-
owner_sources:
|
|
18678
|
+
current_user_can_process: context2.current_user_can_process,
|
|
18679
|
+
identity_unverified: context2.identity_unverified,
|
|
18680
|
+
step_finished: context2.step_finished,
|
|
18681
|
+
current_user_reason: context2.current_user_reason,
|
|
18682
|
+
actions: context2.actions.map((action) => action.action),
|
|
18683
|
+
action_labels: context2.actions.map((action) => action.label),
|
|
18684
|
+
owner_sources: context2.owner_diagnostics.owner_sources
|
|
17641
18685
|
},
|
|
17642
18686
|
requirements: {
|
|
17643
18687
|
can_submit: requirements.can_submit,
|
|
@@ -17818,14 +18862,14 @@ async function writeRefreshedCache(file, template) {
|
|
|
17818
18862
|
`, "utf8");
|
|
17819
18863
|
return out;
|
|
17820
18864
|
}
|
|
17821
|
-
function blockedReason(
|
|
17822
|
-
if (
|
|
18865
|
+
function blockedReason(context2, canSubmit) {
|
|
18866
|
+
if (context2.identity_unverified) {
|
|
17823
18867
|
return "identity_unverified";
|
|
17824
18868
|
}
|
|
17825
|
-
if (
|
|
18869
|
+
if (context2.step_finished) {
|
|
17826
18870
|
return "step_finished";
|
|
17827
18871
|
}
|
|
17828
|
-
if (
|
|
18872
|
+
if (context2.current_user_can_process === false) {
|
|
17829
18873
|
return "current_user_cannot_process";
|
|
17830
18874
|
}
|
|
17831
18875
|
if (!canSubmit) {
|
|
@@ -17960,14 +19004,24 @@ function registerE2eCommands(program2) {
|
|
|
17960
19004
|
const before = safeIdentity(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
17961
19005
|
let after = null;
|
|
17962
19006
|
try {
|
|
17963
|
-
await browserSessionRequest(profile, cookie, "PUT", `/user/${userId}`, { mock: true }, options.hrefPath);
|
|
17964
|
-
after = safeIdentity(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
19007
|
+
await browserSessionRequest(profile, cookie, "PUT", `/user/${userId}?identity_action=mock`, { mock: true }, options.hrefPath);
|
|
17965
19008
|
} catch (error) {
|
|
17966
|
-
|
|
19009
|
+
if (error instanceof BrowserSessionRejectedError) {
|
|
19010
|
+
throw new Error(
|
|
19011
|
+
`e2e.identity.mock_rejected: mock \u8BF7\u6C42\u88AB\u5E73\u53F0\u660E\u786E\u62D2\u7EDD\uFF0Cremote_submitted=false\u3002${error.message}`
|
|
19012
|
+
);
|
|
19013
|
+
}
|
|
19014
|
+
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
17967
19015
|
throw new Error(`e2e.identity.mock_outcome_unknown: mock \u8BF7\u6C42\u6216\u5199\u540E\u56DE\u8BFB\u5931\u8D25\uFF0CCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\uFF1B\u4E0D\u5F97\u91CD\u590D\u6267\u884C\u5F53\u524D\u6B65\u9AA4\uFF0C\u5148\u8FD0\u884C identity status \u786E\u8BA4\u4F1A\u8BDD\u8EAB\u4EFD\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
17968
19016
|
}
|
|
19017
|
+
try {
|
|
19018
|
+
after = safeIdentity(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
19019
|
+
} catch (error) {
|
|
19020
|
+
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
19021
|
+
throw new Error(`e2e.identity.mock_outcome_unknown: mock \u5DF2\u63D0\u4EA4\u4F46\u5199\u540E\u56DE\u8BFB\u5931\u8D25\uFF0CCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\uFF1B\u4E0D\u5F97\u91CD\u590D\u6267\u884C\u5F53\u524D\u6B65\u9AA4\uFF0C\u5148\u8FD0\u884C identity status \u786E\u8BA4\u4F1A\u8BDD\u8EAB\u4EFD\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
19022
|
+
}
|
|
17969
19023
|
if (!after || Number(after.id) !== userId || after.mock !== true) {
|
|
17970
|
-
await browserSessionRequest(profile, cookie, "PUT", "/user/current", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
19024
|
+
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
17971
19025
|
throw new Error("e2e.identity.mock_verify_failed: \u8FDC\u7A0B mock \u8BF7\u6C42\u5DF2\u63D0\u4EA4\uFF0C\u4F46\u5F53\u524D\u4F1A\u8BDD\u8EAB\u4EFD\u6821\u9A8C\u5931\u8D25\uFF1BCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\u3002");
|
|
17972
19026
|
}
|
|
17973
19027
|
let evidence;
|
|
@@ -17983,13 +19037,13 @@ function registerE2eCommands(program2) {
|
|
|
17983
19037
|
target_user_id: userId
|
|
17984
19038
|
});
|
|
17985
19039
|
} catch (error) {
|
|
17986
|
-
await browserSessionRequest(profile, cookie, "PUT", "/user/current", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
19040
|
+
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
17987
19041
|
throw new Error(`e2e.identity.evidence_failed: mock \u540E\u8BC1\u636E\u5199\u5165\u5931\u8D25\uFF0C\u5DF2\u5C1D\u8BD5\u6062\u590D\u539F\u8EAB\u4EFD\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
17988
19042
|
}
|
|
17989
19043
|
try {
|
|
17990
19044
|
await appendE2eExecutionEvidence(options, evidence, ["browser"]);
|
|
17991
19045
|
} catch (error) {
|
|
17992
|
-
await browserSessionRequest(profile, cookie, "PUT", "/user/current", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
19046
|
+
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath).catch(() => void 0);
|
|
17993
19047
|
throw new Error(`e2e.identity.manifest_evidence_failed: mock \u5DF2\u6267\u884C\u4F46\u7528\u4F8B\u8BC1\u636E\u767B\u8BB0\u5931\u8D25\uFF0CCLI \u5DF2\u5C1D\u8BD5\u81EA\u52A8 unmock\u3002${error instanceof Error ? error.message : String(error)}`);
|
|
17994
19048
|
}
|
|
17995
19049
|
printResult(options.format, {
|
|
@@ -18014,7 +19068,7 @@ function registerE2eCommands(program2) {
|
|
|
18014
19068
|
remote_submitted: false
|
|
18015
19069
|
});
|
|
18016
19070
|
const before = safeIdentity(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
18017
|
-
await browserSessionRequest(profile, cookie, "PUT", "/user/current", { unmock: true }, options.hrefPath);
|
|
19071
|
+
await browserSessionRequest(profile, cookie, "PUT", "/user/current?identity_action=unmock", { unmock: true }, options.hrefPath);
|
|
18018
19072
|
const after = safeIdentity(await browserSessionRequest(profile, cookie, "GET", "/user/current", void 0, options.hrefPath));
|
|
18019
19073
|
if (!after || after.mock === true || before?.mock_by_user && Number(after.id) !== Number(before.mock_by_user)) {
|
|
18020
19074
|
throw new Error("e2e.identity.unmock_verify_failed: unmock \u5DF2\u63D0\u4EA4\uFF0C\u4F46\u672A\u786E\u8BA4\u6062\u590D\u539F\u59CB\u8EAB\u4EFD\uFF0C\u5FC5\u987B\u505C\u6B62\u540E\u7EED\u7528\u4F8B\u3002");
|
|
@@ -18069,15 +19123,15 @@ function registerE2eCommands(program2) {
|
|
|
18069
19123
|
break;
|
|
18070
19124
|
}
|
|
18071
19125
|
const prefix = `${String(index + 1).padStart(2, "0")}-step-${plan.step_id}`;
|
|
18072
|
-
const
|
|
18073
|
-
const requirements = buildStepRequirements(
|
|
19126
|
+
const context2 = await buildStepContext(profile, client, plan.step_id, options.projectId);
|
|
19127
|
+
const requirements = buildStepRequirements(context2.step, context2.current_flow_node, plan.data);
|
|
18074
19128
|
const payload = buildSubmitPayload(options.projectId, plan);
|
|
18075
19129
|
const contextFile = await writeEvidence(evidenceDir, `${prefix}-context.json`, {
|
|
18076
|
-
...
|
|
19130
|
+
...context2,
|
|
18077
19131
|
requirements
|
|
18078
19132
|
});
|
|
18079
19133
|
if (options.dataProfile) {
|
|
18080
|
-
const target = expectationTarget(
|
|
19134
|
+
const target = expectationTarget(context2, requirements);
|
|
18081
19135
|
const checkResults = evaluateExpectedChecks(plan.expected_checks, target);
|
|
18082
19136
|
const failedChecks = checkResults.filter((check) => !check.ok);
|
|
18083
19137
|
const missingChecks = plan.expected_checks.length === 0;
|
|
@@ -18094,7 +19148,7 @@ function registerE2eCommands(program2) {
|
|
|
18094
19148
|
name: plan.label ?? `step-${plan.step_id}`,
|
|
18095
19149
|
projectId: options.projectId,
|
|
18096
19150
|
plan,
|
|
18097
|
-
context,
|
|
19151
|
+
context: context2,
|
|
18098
19152
|
requirements,
|
|
18099
19153
|
evidenceDir,
|
|
18100
19154
|
contextFile
|
|
@@ -18122,7 +19176,7 @@ function registerE2eCommands(program2) {
|
|
|
18122
19176
|
params: { action: plan.action },
|
|
18123
19177
|
data: payload
|
|
18124
19178
|
};
|
|
18125
|
-
const block = blockedReason(
|
|
19179
|
+
const block = blockedReason(context2, requirements.can_submit);
|
|
18126
19180
|
if (block) {
|
|
18127
19181
|
stopped = true;
|
|
18128
19182
|
steps.push({
|
|
@@ -18161,7 +19215,7 @@ function registerE2eCommands(program2) {
|
|
|
18161
19215
|
} catch (error) {
|
|
18162
19216
|
readbackError = error instanceof Error ? error.message : String(error);
|
|
18163
19217
|
}
|
|
18164
|
-
const readbackConfirmed2 = Boolean(readback && stepReadbackConfirmed(
|
|
19218
|
+
const readbackConfirmed2 = Boolean(readback && stepReadbackConfirmed(context2, readback));
|
|
18165
19219
|
let submitFile;
|
|
18166
19220
|
let evidenceError;
|
|
18167
19221
|
try {
|
|
@@ -18375,15 +19429,15 @@ function registerE2eCommands(program2) {
|
|
|
18375
19429
|
if (inferredStepId && !contextFile && !submitFile) {
|
|
18376
19430
|
throw new Error(`No step evidence files found for step ${inferredStepId} in ${options.evidenceDir}.`);
|
|
18377
19431
|
}
|
|
18378
|
-
const
|
|
19432
|
+
const context2 = contextFile ? await readOptionalJson(path11.join(options.evidenceDir, contextFile)) : null;
|
|
18379
19433
|
const submit = submitFile ? await readOptionalJson(path11.join(options.evidenceDir, submitFile)) : null;
|
|
18380
|
-
const requirements = isRecord8(
|
|
19434
|
+
const requirements = isRecord8(context2?.requirements) ? context2.requirements : {};
|
|
18381
19435
|
const requiredInputs = Array.isArray(requirements.required_inputs) ? requirements.required_inputs.filter(isRecord8) : [];
|
|
18382
19436
|
const missingInputs = Array.isArray(requirements.missing_required_inputs) ? requirements.missing_required_inputs.filter(isRecord8) : [];
|
|
18383
19437
|
const requestData = isRecord8(submit?.request) && isRecord8(submit.request.data) ? submit.request.data : {};
|
|
18384
19438
|
const recordedAction = stringValue3(requestData.action);
|
|
18385
19439
|
const expectedChecks = buildExpectedChecks({
|
|
18386
|
-
context,
|
|
19440
|
+
context: context2,
|
|
18387
19441
|
requirements: {
|
|
18388
19442
|
required_inputs: requiredInputs,
|
|
18389
19443
|
missing_required_inputs: submitFile ? [] : missingInputs
|
|
@@ -19300,10 +20354,10 @@ async function fetchAllMatrixRuleRecords(client, flowType) {
|
|
|
19300
20354
|
data: { flow_type: flowType, page, page_size: pageSize },
|
|
19301
20355
|
capability: "project.list"
|
|
19302
20356
|
});
|
|
19303
|
-
const
|
|
19304
|
-
records.push(...
|
|
20357
|
+
const rows2 = dataArray(result).filter(isRecord10);
|
|
20358
|
+
records.push(...rows2);
|
|
19305
20359
|
const total = Number(result.count ?? result.total ?? records.length);
|
|
19306
|
-
if (
|
|
20360
|
+
if (rows2.length < pageSize || records.length >= total) break;
|
|
19307
20361
|
if (records.length >= maxRecords) {
|
|
19308
20362
|
truncated = true;
|
|
19309
20363
|
break;
|
|
@@ -19360,13 +20414,14 @@ function flowCategory(flow) {
|
|
|
19360
20414
|
function hasIdentifier(value) {
|
|
19361
20415
|
return value !== void 0 && value !== null && String(value).trim() !== "" && String(value) !== "0";
|
|
19362
20416
|
}
|
|
19363
|
-
function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], workspaceBound = false) {
|
|
20417
|
+
function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], datasets = [], workspaceBound = false) {
|
|
19364
20418
|
const data = isRecord10(flow.data) ? flow.data : {};
|
|
19365
20419
|
const meta = isRecord10(data.meta) ? data.meta : {};
|
|
19366
20420
|
const refs = {
|
|
19367
20421
|
form_template_id: meta.form_template ?? flow.form_template_id,
|
|
19368
20422
|
list_template_ids: listTemplates.map((item) => item.id ?? item.flow_page_template_id).filter(hasIdentifier),
|
|
19369
|
-
filter_template_ids: filterTemplates.map((item) => item.id ?? item.flow_page_template_id).filter(hasIdentifier)
|
|
20423
|
+
filter_template_ids: filterTemplates.map((item) => item.id ?? item.flow_page_template_id).filter(hasIdentifier),
|
|
20424
|
+
dataset_ids: datasets.map((item) => item.id ?? item.data_set_id).filter(hasIdentifier)
|
|
19370
20425
|
};
|
|
19371
20426
|
const errors = [];
|
|
19372
20427
|
if (flowCategory(flow) !== "matrix") {
|
|
@@ -19402,12 +20457,91 @@ function matrixAppSummary(flow, listTemplates = [], filterTemplates = [], worksp
|
|
|
19402
20457
|
suggestion: "\u4ECE\u6700\u65B0 workspace-flow \u56DE\u8BFB merge \u540E\u901A\u8FC7 typed CLI \u63D0\u4EA4\u7ED1\u5B9A\u3002"
|
|
19403
20458
|
});
|
|
19404
20459
|
}
|
|
19405
|
-
|
|
20460
|
+
const nodes = dataArray(data.nodes).filter(isRecord10);
|
|
20461
|
+
const activeNodes = nodes.filter((node) => {
|
|
20462
|
+
const name = String(node.name ?? "").trim();
|
|
20463
|
+
return name === "\u751F\u6548\u4E2D" || name === "\u8FDB\u884C\u4E2D" || Number(node.status) === 1;
|
|
20464
|
+
});
|
|
20465
|
+
if (!activeNodes.length) {
|
|
20466
|
+
errors.push({
|
|
20467
|
+
code: "matrix.app.active_maintenance_node_required",
|
|
20468
|
+
rule_id: "matrix.app.active_maintenance_node_required",
|
|
20469
|
+
domain: "approval-matrix",
|
|
20470
|
+
path: "$.data.nodes",
|
|
20471
|
+
message: "\u77E9\u9635\u6D41\u7A0B\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u201C\u751F\u6548\u4E2D/\u8FDB\u884C\u4E2D\u201D\u7684\u7EF4\u62A4\u73AF\u8282\u3002",
|
|
20472
|
+
suggestion: "\u4FDD\u7559\u4E00\u4E2A\u77E9\u9635\u6570\u636E\u7EF4\u62A4\u73AF\u8282\u5373\u53EF\uFF0C\u4E0D\u9700\u8981\u642D\u5EFA\u591A\u73AF\u8282\u5BA1\u6279\u94FE\u3002"
|
|
20473
|
+
});
|
|
20474
|
+
}
|
|
20475
|
+
const hasEditAction = listTemplates.some((template) => JSON.stringify(template).includes("ProjectDetailEdit"));
|
|
20476
|
+
if (!hasEditAction) {
|
|
20477
|
+
errors.push({
|
|
20478
|
+
code: "matrix.app.list_edit_action_required",
|
|
20479
|
+
rule_id: "matrix.app.list_edit_action_required",
|
|
20480
|
+
domain: "approval-matrix",
|
|
20481
|
+
path: "$.list_template.content",
|
|
20482
|
+
message: "\u77E9\u9635\u5217\u8868\u7F3A\u5C11\u5185\u7F6E\u4FEE\u6539\u64CD\u4F5C ProjectDetailEdit\u3002",
|
|
20483
|
+
suggestion: "\u5728\u64CD\u4F5C\u5217\u52A0\u5165 ProjectDetailEdit\uFF0C\u4F7F\u89C4\u5219\u884C\u53EF\u901A\u8FC7\u62BD\u5C49\u4FEE\u6539\u3002"
|
|
20484
|
+
});
|
|
20485
|
+
}
|
|
20486
|
+
return {
|
|
20487
|
+
category: flowCategory(flow),
|
|
20488
|
+
template_refs: refs,
|
|
20489
|
+
workspace_bound: workspaceBound,
|
|
20490
|
+
maintenance_nodes: activeNodes.map((node) => ({ id: node.id ?? null, name: node.name ?? null, status: node.status ?? null })),
|
|
20491
|
+
list_edit_action: hasEditAction ? "ProjectDetailEdit" : null,
|
|
20492
|
+
errors
|
|
20493
|
+
};
|
|
20494
|
+
}
|
|
20495
|
+
function matrixHash(value) {
|
|
20496
|
+
return hashJson(value);
|
|
20497
|
+
}
|
|
20498
|
+
function uniqueIds(values) {
|
|
20499
|
+
return [...new Set(values.filter(hasIdentifier).map((value) => String(value)))];
|
|
20500
|
+
}
|
|
20501
|
+
async function inspectMatrixAppDefinition(profile, flowType, workspace, includeRaw = false, strict = true) {
|
|
20502
|
+
const client = createApiClient(profile);
|
|
20503
|
+
const [flow, listResult, filterResult, workspaceResult] = await Promise.all([
|
|
20504
|
+
apiRequest(client, "GET", "/flow", { params: { flow_type: flowType, draft: 0, skip_i18n: true } }),
|
|
20505
|
+
apiRequest(client, "GET", "/flow_page_template", { params: { type: 1, flow_type: flowType, flow_key: "", skip_i18n: true }, capability: "config.list_template.export" }),
|
|
20506
|
+
apiRequest(client, "GET", "/flow_page_template", { params: { type: 3, flow_type: flowType, flow_key: "", skip_i18n: true }, capability: "config.filter_template.export" }),
|
|
20507
|
+
apiRequest(client, "GET", "/workspace/by_key", { params: { key: workspace }, capability: "config.workspace_flow.export" })
|
|
20508
|
+
]);
|
|
20509
|
+
const flowData = isRecord10(flow.data) ? flow.data : {};
|
|
20510
|
+
const meta = isRecord10(flowData.meta) ? flowData.meta : {};
|
|
20511
|
+
const listRows = dataArray(listResult).filter(isRecord10);
|
|
20512
|
+
const filterRows = dataArray(filterResult).filter(isRecord10);
|
|
20513
|
+
const listIds = uniqueIds([meta.table_list_template, ...listRows.map((item) => item.id ?? item.flow_page_template_id)]);
|
|
20514
|
+
const filterIds = uniqueIds([meta.table_filter_template, ...filterRows.map((item) => item.id ?? item.flow_page_template_id)]);
|
|
20515
|
+
const formId = String(meta.form_template ?? flow.form_template_id ?? "");
|
|
20516
|
+
const [form, listTemplates, filterTemplates] = await Promise.all([
|
|
20517
|
+
formId ? apiRequest(client, "GET", `/form_template/${encodeURIComponent(formId)}`, { capability: "config.form_template.export" }) : Promise.resolve({}),
|
|
20518
|
+
Promise.all(listIds.map((id) => apiRequest(client, "GET", `/flow_page_template/${encodeURIComponent(id)}?skip_i18n=true`, { capability: "config.list_template.export" }))),
|
|
20519
|
+
Promise.all(filterIds.map((id) => apiRequest(client, "GET", `/flow_page_template/${encodeURIComponent(id)}?skip_i18n=true`, { capability: "config.filter_template.export" })))
|
|
20520
|
+
]);
|
|
20521
|
+
const datasetIds = uniqueIds([
|
|
20522
|
+
...listTemplates.map((item) => item.data_set_id),
|
|
20523
|
+
...filterTemplates.map((item) => item.data_set_id)
|
|
20524
|
+
]);
|
|
20525
|
+
const datasets = await Promise.all(datasetIds.map((id) => apiRequest(client, "GET", `/data_set/${encodeURIComponent(id)}`, { capability: "config.dataset.export" })));
|
|
20526
|
+
const summary = matrixAppSummary(flow, listTemplates, filterTemplates, datasets, workspaceHasFlow(workspaceResult, flowType));
|
|
20527
|
+
if (strict) {
|
|
20528
|
+
assertNoMatrixErrors(summary.errors);
|
|
20529
|
+
}
|
|
20530
|
+
const formRecord = isRecord10(form) ? form : {};
|
|
20531
|
+
const exactReadback = {
|
|
20532
|
+
flow: { id: flowType, readback_hash: matrixHash(flow), ...includeRaw ? { readback: flow } : {} },
|
|
20533
|
+
form_template: { id: formId, draft_id: formRecord.origin_template_id ?? formRecord.id ?? null, readback_hash: matrixHash(formRecord), ...includeRaw ? { readback: formRecord } : {} },
|
|
20534
|
+
datasets: datasets.map((item, index) => ({ id: datasetIds[index], readback_hash: matrixHash(item), ...includeRaw ? { readback: item } : {} })),
|
|
20535
|
+
list_templates: listTemplates.map((item, index) => ({ id: listIds[index], readback_hash: matrixHash(item), ...includeRaw ? { readback: item } : {} })),
|
|
20536
|
+
filter_templates: filterTemplates.map((item, index) => ({ id: filterIds[index], readback_hash: matrixHash(item), ...includeRaw ? { readback: item } : {} })),
|
|
20537
|
+
workspace_flow: { id: workspace, readback_hash: matrixHash(workspaceResult), ...includeRaw ? { readback: workspaceResult } : {} }
|
|
20538
|
+
};
|
|
20539
|
+
return { ok: summary.errors.length === 0, domain: "approval-matrix", action: "app.inspect", flow_type: flowType, workspace, ...summary, exact_readback: exactReadback };
|
|
19406
20540
|
}
|
|
19407
20541
|
function workspaceHasFlow(value, flowType) {
|
|
19408
20542
|
if (!isRecord10(value)) return false;
|
|
19409
|
-
const
|
|
19410
|
-
return
|
|
20543
|
+
const rows2 = Array.isArray(value.workspace_flow) ? value.workspace_flow.filter(isRecord10) : isRecord10(value.data) && Array.isArray(value.data.workspace_flow) ? value.data.workspace_flow.filter(isRecord10) : [];
|
|
20544
|
+
return rows2.some((item) => String(item.flow_type ?? "") === flowType && Number(item.is_del ?? 0) === 0);
|
|
19411
20545
|
}
|
|
19412
20546
|
function matrixConsumerSummary(node, expectedMatrixFlowType) {
|
|
19413
20547
|
const errors = [];
|
|
@@ -19471,6 +20605,23 @@ function collectUserIds(value) {
|
|
|
19471
20605
|
const direct = Number(value);
|
|
19472
20606
|
return Number.isSafeInteger(direct) && direct > 0 ? [direct] : [];
|
|
19473
20607
|
}
|
|
20608
|
+
async function readMatrixApprovers(client, ids) {
|
|
20609
|
+
const users = [];
|
|
20610
|
+
for (let index = 0; index < ids.length; index += 100) {
|
|
20611
|
+
const chunk = ids.slice(index, index + 100);
|
|
20612
|
+
const result = await apiRequest(client, "GET", "/user", {
|
|
20613
|
+
params: {
|
|
20614
|
+
ids: chunk.join(","),
|
|
20615
|
+
page: 1,
|
|
20616
|
+
page_size: 100,
|
|
20617
|
+
field_filter: "id,name,status,is_del,organization_id"
|
|
20618
|
+
},
|
|
20619
|
+
capability: "user.readback"
|
|
20620
|
+
});
|
|
20621
|
+
users.push(...dataArray(result).filter(isRecord10));
|
|
20622
|
+
}
|
|
20623
|
+
return users;
|
|
20624
|
+
}
|
|
19474
20625
|
function assertNoMatrixErrors(errors) {
|
|
19475
20626
|
if (!errors.length) return;
|
|
19476
20627
|
throw new Error(`Matrix validation failed:
|
|
@@ -19587,27 +20738,102 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
19587
20738
|
]
|
|
19588
20739
|
});
|
|
19589
20740
|
});
|
|
19590
|
-
const app = matrix.command("app").description("
|
|
19591
|
-
app.command("
|
|
20741
|
+
const app = matrix.command("app").description("Create, edit, inspect, and delete approval matrix application definitions");
|
|
20742
|
+
const registerAppInspect = (name) => app.command(name).description("Exact-readback matrix flow, form, dataset, list, filter, and workspace binding").requiredOption("--flow-type <flowType>", "Matrix flow type").option("--workspace <workspace>", "Workspace binding to verify; defaults to profile workspace").option("--profile <profile>", "Profile name").option("--include-raw", "Include full config readback objects in JSON output").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
19592
20743
|
const config = await loadConfig();
|
|
19593
20744
|
const profile = resolveProfile(config, options.profile);
|
|
19594
|
-
const client = createApiClient(profile);
|
|
19595
20745
|
const workspace = String(options.workspace || profile.config.workspace || "").replace(/^w:/, "");
|
|
19596
20746
|
if (!workspace) throw new Error("matrix.app.workspace_required: \u8BF7\u63D0\u4F9B --workspace \u4EE5\u9A8C\u8BC1\u77E9\u9635\u5E94\u7528\u7ED1\u5B9A\u3002");
|
|
19597
|
-
const
|
|
19598
|
-
|
|
19599
|
-
|
|
19600
|
-
|
|
19601
|
-
|
|
19602
|
-
|
|
19603
|
-
const
|
|
19604
|
-
|
|
19605
|
-
|
|
19606
|
-
|
|
19607
|
-
|
|
20747
|
+
const result = await inspectMatrixAppDefinition(profile, options.flowType, workspace, Boolean(options.includeRaw));
|
|
20748
|
+
printResult(options.format, { ...result, action: `app.${name}` });
|
|
20749
|
+
});
|
|
20750
|
+
registerAppInspect("inspect");
|
|
20751
|
+
registerAppInspect("readback");
|
|
20752
|
+
app.command("create").description("Create a complete matrix definition: form, flow, dataset, editable list, filter, and workspace binding").requiredOption("--workspace <workspace>", "Target workspace key, e.g. oa or w:oa").requiredOption("--name <name>", "Matrix application name").requiredOption("--form-work <file>", "Form-template create work JSON").requiredOption("--flow-work <file>", "Matrix flow-template create work JSON").requiredOption("--dataset-work <file>", "Dataset create work JSON").requiredOption("--list-work <file>", "List-template create work JSON containing ProjectDetailEdit").requiredOption("--filter-work <file>", "Filter-template create work JSON").option("--profile <profile>", "Profile name").option("--agent <agent>", "Agent adapter for installed plugin lint discovery", "codex").option("--draft-only", "Create configuration without publishing the flow and dataset live").option("--confirm <text>", "Exact confirmation text").option("--work-dir <dir>", "Directory for generated typed submit/readback evidence").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
20753
|
+
const config = await loadConfig();
|
|
20754
|
+
const profile = resolveProfile(config, options.profile);
|
|
20755
|
+
const result = await createMatrixAppFromWork(
|
|
20756
|
+
config,
|
|
20757
|
+
profile,
|
|
20758
|
+
options.formWork,
|
|
20759
|
+
options.flowWork,
|
|
20760
|
+
options.datasetWork,
|
|
20761
|
+
options.listWork,
|
|
20762
|
+
options.filterWork,
|
|
20763
|
+
options.confirm,
|
|
20764
|
+
{
|
|
20765
|
+
workspace: options.workspace,
|
|
20766
|
+
name: options.name,
|
|
20767
|
+
publishLive: !options.draftOnly,
|
|
20768
|
+
agent: options.agent,
|
|
20769
|
+
workDir: options.workDir
|
|
20770
|
+
}
|
|
19608
20771
|
);
|
|
19609
|
-
|
|
19610
|
-
printResult(options.format,
|
|
20772
|
+
await saveConfig(config);
|
|
20773
|
+
printResult(options.format, result);
|
|
20774
|
+
});
|
|
20775
|
+
app.command("update").description("Update matrix definition objects through a typed config batch manifest, then exact-readback the complete app").requiredOption("--flow-type <flowType>", "Matrix flow type").requiredOption("--manifest <file>", "Typed config batch submit manifest").option("--workspace <workspace>", "Workspace binding to verify; defaults to profile workspace").option("--profile <profile>", "Profile name").option("--continue-on-error", "Continue after a failed manifest row").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
20776
|
+
const config = await loadConfig();
|
|
20777
|
+
const profile = resolveProfile(config, options.profile);
|
|
20778
|
+
const workspace = String(options.workspace || profile.config.workspace || "").replace(/^w:/, "");
|
|
20779
|
+
if (!workspace) throw new Error("matrix.app.workspace_required: \u8BF7\u63D0\u4F9B --workspace \u4EE5\u9A8C\u8BC1\u77E9\u9635\u5E94\u7528\u7ED1\u5B9A\u3002");
|
|
20780
|
+
const batch = await runConfigBatchSubmit(config, profile, options.manifest, { continueOnError: Boolean(options.continueOnError) });
|
|
20781
|
+
if (batch.ok !== true) {
|
|
20782
|
+
printResult(options.format, { ok: false, domain: "approval-matrix", action: "app.update", batch });
|
|
20783
|
+
throw new Error("matrix app update failed; exact readback was not executed.");
|
|
20784
|
+
}
|
|
20785
|
+
const readback = await inspectMatrixAppDefinition(profile, options.flowType, workspace, false);
|
|
20786
|
+
await saveConfig(config);
|
|
20787
|
+
printResult(options.format, { ok: true, domain: "approval-matrix", action: "app.update", batch, exact_readback: readback });
|
|
20788
|
+
});
|
|
20789
|
+
app.command("delete").description("Delete a complete matrix definition in dependency order").requiredOption("--flow-type <flowType>", "Matrix flow type").option("--workspace <workspace>", "Workspace binding to remove; defaults to profile workspace").option("--profile <profile>", "Profile name").option("--confirm <text>", "Exact confirmation text").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
20790
|
+
const config = await loadConfig();
|
|
20791
|
+
const profile = resolveProfile(config, options.profile);
|
|
20792
|
+
const workspace = String(options.workspace || profile.config.workspace || "").replace(/^w:/, "");
|
|
20793
|
+
if (!workspace) throw new Error("matrix.app.workspace_required: \u8BF7\u63D0\u4F9B --workspace \u4EE5\u5220\u9664\u77E9\u9635\u5E94\u7528\u3002");
|
|
20794
|
+
const definition = await inspectMatrixAppDefinition(profile, options.flowType, workspace, true, false);
|
|
20795
|
+
const exact = definition.exact_readback;
|
|
20796
|
+
const listItems = Array.isArray(exact.list_templates) ? exact.list_templates.filter(isRecord10) : [];
|
|
20797
|
+
const filterItems = Array.isArray(exact.filter_templates) ? exact.filter_templates.filter(isRecord10) : [];
|
|
20798
|
+
const datasetItems = Array.isArray(exact.datasets) ? exact.datasets.filter(isRecord10) : [];
|
|
20799
|
+
const datasetFieldIds = uniqueIds(datasetItems.flatMap((item) => {
|
|
20800
|
+
const readback = isRecord10(item.readback) ? item.readback : {};
|
|
20801
|
+
return Array.isArray(readback.dataSetFields) ? readback.dataSetFields.filter(isRecord10).map((field) => field.id) : [];
|
|
20802
|
+
}));
|
|
20803
|
+
const formItem = isRecord10(exact.form_template) ? exact.form_template : {};
|
|
20804
|
+
const formDraftId = String(formItem.draft_id ?? formItem.id ?? "");
|
|
20805
|
+
const expectedConfirm = `delete matrix app ${options.flowType} from ${workspace}`;
|
|
20806
|
+
const plan = [
|
|
20807
|
+
{ domain: "workspace-flow", id: `${workspace}|${options.flowType}|` },
|
|
20808
|
+
...listItems.map((item) => ({ domain: "list-template", id: String(item.id) })),
|
|
20809
|
+
...filterItems.map((item) => ({ domain: "filter-template", id: String(item.id) })),
|
|
20810
|
+
...datasetFieldIds.map((id) => ({ domain: "dataset-field", id })),
|
|
20811
|
+
...datasetItems.map((item) => ({ domain: "dataset", id: String(item.id) })),
|
|
20812
|
+
{ domain: "flow-template", id: options.flowType },
|
|
20813
|
+
...formDraftId ? [{ domain: "form-template", id: formDraftId }] : []
|
|
20814
|
+
];
|
|
20815
|
+
if (options.confirm !== expectedConfirm) {
|
|
20816
|
+
printResult(options.format, {
|
|
20817
|
+
ok: true,
|
|
20818
|
+
dry_run: true,
|
|
20819
|
+
operation_executed: false,
|
|
20820
|
+
domain: "approval-matrix",
|
|
20821
|
+
action: "app.delete",
|
|
20822
|
+
flow_type: options.flowType,
|
|
20823
|
+
workspace,
|
|
20824
|
+
exact_readback: definition,
|
|
20825
|
+
operation_plan: plan,
|
|
20826
|
+
required_confirm: expectedConfirm
|
|
20827
|
+
});
|
|
20828
|
+
return;
|
|
20829
|
+
}
|
|
20830
|
+
const results = [];
|
|
20831
|
+
for (const item of plan) {
|
|
20832
|
+
const domain = item.domain;
|
|
20833
|
+
results.push(await deleteConfigDomain(config, profile, domain, item.id, `delete ${domain} ${item.id}`));
|
|
20834
|
+
}
|
|
20835
|
+
await saveConfig(config);
|
|
20836
|
+
printResult(options.format, { ok: true, domain: "approval-matrix", action: "app.delete", flow_type: options.flowType, workspace, deleted: results });
|
|
19611
20837
|
});
|
|
19612
20838
|
const consumer = matrix.command("consumer").description("Lint a business-flow matrix owner or CC consumer node");
|
|
19613
20839
|
consumer.command("lint").requiredOption("--flow-type <flowType>", "Business flow type").requiredOption("--node <nodeId>", "Consumer node id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
@@ -19636,12 +20862,13 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
19636
20862
|
apiRequest(client, "GET", "/flow_page_template", { params: { type: 3, flow_type: options.matrixFlowType, flow_key: "", skip_i18n: true }, capability: "config.filter_template.export" }),
|
|
19637
20863
|
apiRequest(client, "GET", "/workspace/by_key", { params: { key: workspace }, capability: "config.workspace_flow.export" })
|
|
19638
20864
|
]);
|
|
19639
|
-
const
|
|
19640
|
-
|
|
19641
|
-
|
|
19642
|
-
|
|
19643
|
-
|
|
19644
|
-
);
|
|
20865
|
+
const listRows = dataArray(listResult).filter(isRecord10);
|
|
20866
|
+
const filterRows = dataArray(filterResult).filter(isRecord10);
|
|
20867
|
+
const listTemplates = await Promise.all(uniqueIds(listRows.map((item) => item.id ?? item.flow_page_template_id)).map((id) => apiRequest(client, "GET", `/flow_page_template/${encodeURIComponent(id)}?skip_i18n=true`, { capability: "config.list_template.export" })));
|
|
20868
|
+
const filterTemplates = await Promise.all(uniqueIds(filterRows.map((item) => item.id ?? item.flow_page_template_id)).map((id) => apiRequest(client, "GET", `/flow_page_template/${encodeURIComponent(id)}?skip_i18n=true`, { capability: "config.filter_template.export" })));
|
|
20869
|
+
const datasetIds = uniqueIds([...listTemplates.map((item) => item.data_set_id), ...filterTemplates.map((item) => item.data_set_id)]);
|
|
20870
|
+
const datasets = await Promise.all(datasetIds.map((id) => apiRequest(client, "GET", `/data_set/${encodeURIComponent(id)}`, { capability: "config.dataset.export" })));
|
|
20871
|
+
const appSummary = matrixAppSummary(matrixFlow, listTemplates, filterTemplates, datasets, workspaceHasFlow(workspaceResult, options.matrixFlowType));
|
|
19645
20872
|
const consumerNode = findFlowNode2(consumerFlow, options.node);
|
|
19646
20873
|
const consumerSummary = matrixConsumerSummary(consumerNode, options.matrixFlowType);
|
|
19647
20874
|
const records = await hydrateMatrixRuleRecords(client, listedRecords);
|
|
@@ -19664,11 +20891,7 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
19664
20891
|
});
|
|
19665
20892
|
let approvers = [];
|
|
19666
20893
|
if (approverIds.size) {
|
|
19667
|
-
|
|
19668
|
-
params: { ids: [...approverIds].join(","), field_filter: "id,name,status,is_del,organization_id" },
|
|
19669
|
-
capability: "user.readback"
|
|
19670
|
-
});
|
|
19671
|
-
approvers = dataArray(usersResult).filter(isRecord10);
|
|
20894
|
+
approvers = await readMatrixApprovers(client, [...approverIds]);
|
|
19672
20895
|
const activeIds = new Set(approvers.filter((user) => Number(user.status) === 0 && Number(user.is_del ?? 0) === 0).map((user) => Number(user.id)));
|
|
19673
20896
|
[...approverIds].filter((id) => !activeIds.has(id)).forEach((id) => errors.push({ code: "matrix.rules.approver_inactive", rule_id: "matrix.rules.approver_inactive", domain: "approval-matrix", path: "$.rules", message: `\u5BA1\u6279\u4EBA ${id} \u4E0D\u5B58\u5728\u6216\u4E0D\u662F\u6709\u6548\u5728\u804C\u72B6\u6001\u3002`, suggestion: "\u91CD\u65B0\u7ED1\u5B9A\u6709\u6548 BPMAX \u7528\u6237\u3002" }));
|
|
19674
20897
|
}
|
|
@@ -19697,6 +20920,326 @@ ${errors.map((error) => `- [${error.rule_index}] ${error.code}${error.path ? ` $
|
|
|
19697
20920
|
});
|
|
19698
20921
|
}
|
|
19699
20922
|
|
|
20923
|
+
// src/commands/organization.ts
|
|
20924
|
+
function isRecord11(value) {
|
|
20925
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20926
|
+
}
|
|
20927
|
+
function rows(value) {
|
|
20928
|
+
if (Array.isArray(value)) return value.filter(isRecord11);
|
|
20929
|
+
if (!isRecord11(value)) return [];
|
|
20930
|
+
if (Array.isArray(value.data)) return value.data.filter(isRecord11);
|
|
20931
|
+
return value.id ? [value] : [];
|
|
20932
|
+
}
|
|
20933
|
+
function positiveId(value, errorCode) {
|
|
20934
|
+
const id = Number(value);
|
|
20935
|
+
if (!Number.isSafeInteger(id) || id <= 0) {
|
|
20936
|
+
throw new Error(`${errorCode}: id \u5FC5\u987B\u662F\u6B63\u6574\u6570\u3002`);
|
|
20937
|
+
}
|
|
20938
|
+
return id;
|
|
20939
|
+
}
|
|
20940
|
+
function safeDepartment(group) {
|
|
20941
|
+
return {
|
|
20942
|
+
id: group.id,
|
|
20943
|
+
name: group.name,
|
|
20944
|
+
parent_id: group.parent_id ?? null,
|
|
20945
|
+
path: group.path ?? null,
|
|
20946
|
+
model_id: group.model_id ?? null,
|
|
20947
|
+
partner_id: group.partner_id ?? null,
|
|
20948
|
+
is_deleted: group.is_del === void 0 ? null : Number(group.is_del) !== 0
|
|
20949
|
+
};
|
|
20950
|
+
}
|
|
20951
|
+
function departmentRows(value) {
|
|
20952
|
+
const result = [];
|
|
20953
|
+
const visit = (item) => {
|
|
20954
|
+
if (!isRecord11(item)) return;
|
|
20955
|
+
if (item.id !== void 0) result.push(safeDepartment(item));
|
|
20956
|
+
if (Array.isArray(item.children)) item.children.forEach(visit);
|
|
20957
|
+
};
|
|
20958
|
+
rows(value).forEach(visit);
|
|
20959
|
+
return result;
|
|
20960
|
+
}
|
|
20961
|
+
function relationDepartments(value) {
|
|
20962
|
+
if (!Array.isArray(value)) return [];
|
|
20963
|
+
return value.filter(isRecord11).map(safeDepartment);
|
|
20964
|
+
}
|
|
20965
|
+
function safeUser(user) {
|
|
20966
|
+
const status = user.status === void 0 ? null : Number(user.status);
|
|
20967
|
+
const isDeleted = user.is_del === void 0 ? null : Number(user.is_del) !== 0;
|
|
20968
|
+
return {
|
|
20969
|
+
id: user.id,
|
|
20970
|
+
name: user.name,
|
|
20971
|
+
employee_no: user.partner_id ?? null,
|
|
20972
|
+
organization_id: user.organization_id ?? null,
|
|
20973
|
+
position: user.title ?? null,
|
|
20974
|
+
leader_id: user.leader_id ?? null,
|
|
20975
|
+
status,
|
|
20976
|
+
is_deleted: isDeleted,
|
|
20977
|
+
active: status === 0 && isDeleted === false,
|
|
20978
|
+
departments: relationDepartments(user.group_list),
|
|
20979
|
+
managed_departments: relationDepartments(user.admin_list)
|
|
20980
|
+
};
|
|
20981
|
+
}
|
|
20982
|
+
async function fetchUsers(client, params, capability) {
|
|
20983
|
+
const result = await apiRequest(client, "GET", "/user", {
|
|
20984
|
+
params: {
|
|
20985
|
+
...params,
|
|
20986
|
+
subRelations: "group",
|
|
20987
|
+
field_filter: "id,name,partner_id,title,leader_id,partner_leader_id,status,is_del,organization_id"
|
|
20988
|
+
},
|
|
20989
|
+
capability
|
|
20990
|
+
});
|
|
20991
|
+
return rows(result).map((raw) => ({ raw, safe: safeUser(raw) }));
|
|
20992
|
+
}
|
|
20993
|
+
async function readUser(client, userId) {
|
|
20994
|
+
const users = await fetchUsers(client, { ids: String(userId) }, "user.readback");
|
|
20995
|
+
const matched = users.find((user) => Number(user.safe.id) === userId);
|
|
20996
|
+
if (!matched) throw new Error(`organization.user.not_found: \u672A\u627E\u5230\u7528\u6237 ${userId}\u3002`);
|
|
20997
|
+
return matched;
|
|
20998
|
+
}
|
|
20999
|
+
async function readDepartments(client, ids) {
|
|
21000
|
+
if (ids.length === 0) return [];
|
|
21001
|
+
const result = await apiRequest(client, "GET", "/group/get_group_info", {
|
|
21002
|
+
params: { ids: ids.join(",") },
|
|
21003
|
+
capability: "user.readback"
|
|
21004
|
+
});
|
|
21005
|
+
return departmentRows(result);
|
|
21006
|
+
}
|
|
21007
|
+
function pathIds(departments) {
|
|
21008
|
+
const ids = /* @__PURE__ */ new Set();
|
|
21009
|
+
for (const department of departments) {
|
|
21010
|
+
const path16 = String(department.path ?? "");
|
|
21011
|
+
for (const part of path16.split(/[|,]/)) {
|
|
21012
|
+
const id = Number(part);
|
|
21013
|
+
if (Number.isSafeInteger(id) && id > 0) ids.add(id);
|
|
21014
|
+
}
|
|
21015
|
+
}
|
|
21016
|
+
return [...ids];
|
|
21017
|
+
}
|
|
21018
|
+
function mainDepartmentId(raw) {
|
|
21019
|
+
for (const key of ["main_department_id", "main_group_id", "main_department"]) {
|
|
21020
|
+
const value = raw[key];
|
|
21021
|
+
if (isRecord11(value)) {
|
|
21022
|
+
const id2 = Number(value.id);
|
|
21023
|
+
if (Number.isSafeInteger(id2) && id2 > 0) return id2;
|
|
21024
|
+
}
|
|
21025
|
+
const id = Number(value);
|
|
21026
|
+
if (Number.isSafeInteger(id) && id > 0) return id;
|
|
21027
|
+
}
|
|
21028
|
+
return null;
|
|
21029
|
+
}
|
|
21030
|
+
function branchId(raw) {
|
|
21031
|
+
for (const key of ["branch_id", "branch_group_id", "branch"]) {
|
|
21032
|
+
const value = raw[key];
|
|
21033
|
+
if (isRecord11(value)) {
|
|
21034
|
+
const id2 = Number(value.id);
|
|
21035
|
+
if (Number.isSafeInteger(id2) && id2 > 0) return id2;
|
|
21036
|
+
}
|
|
21037
|
+
const id = Number(value);
|
|
21038
|
+
if (Number.isSafeInteger(id) && id > 0) return id;
|
|
21039
|
+
}
|
|
21040
|
+
return null;
|
|
21041
|
+
}
|
|
21042
|
+
async function directSuperiorChain(client, userId, maxLevels) {
|
|
21043
|
+
const chain = [];
|
|
21044
|
+
const visited = /* @__PURE__ */ new Set([userId]);
|
|
21045
|
+
let current = await readUser(client, userId);
|
|
21046
|
+
let stopReason = "max_levels_reached";
|
|
21047
|
+
for (let level = 1; level <= maxLevels; level += 1) {
|
|
21048
|
+
const leaderId = Number(current.safe.leader_id);
|
|
21049
|
+
if (!Number.isSafeInteger(leaderId) || leaderId <= 0) {
|
|
21050
|
+
stopReason = "no_further_superior";
|
|
21051
|
+
break;
|
|
21052
|
+
}
|
|
21053
|
+
if (visited.has(leaderId)) {
|
|
21054
|
+
stopReason = "cycle_detected";
|
|
21055
|
+
break;
|
|
21056
|
+
}
|
|
21057
|
+
visited.add(leaderId);
|
|
21058
|
+
current = await readUser(client, leaderId);
|
|
21059
|
+
chain.push({ level, ...current.safe });
|
|
21060
|
+
}
|
|
21061
|
+
return { chain, stop_reason: stopReason };
|
|
21062
|
+
}
|
|
21063
|
+
async function context(profileName) {
|
|
21064
|
+
const config = await loadConfig();
|
|
21065
|
+
const profile = resolveProfile(config, profileName);
|
|
21066
|
+
return { profile, client: createApiClient(profile) };
|
|
21067
|
+
}
|
|
21068
|
+
function registerOrganizationCommands(program2) {
|
|
21069
|
+
const organization = program2.command("organization").description("Typed organization directory queries and authoritative readback");
|
|
21070
|
+
const department = organization.command("department").description("Department queries");
|
|
21071
|
+
department.command("search").description("Search departments by name").requiredOption("--query <query>", "Department name query").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21072
|
+
const query = options.query.trim();
|
|
21073
|
+
if (!query) throw new Error("organization.department.search.query_required: --query \u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
21074
|
+
const { client } = await context(options.profile);
|
|
21075
|
+
const result = await apiRequest(client, "GET", "/group/tree", {
|
|
21076
|
+
params: { name: query, parent_id: 0, recursive: 1, with_model_form_template: 0 },
|
|
21077
|
+
capability: "user.search"
|
|
21078
|
+
});
|
|
21079
|
+
const departments = departmentRows(result);
|
|
21080
|
+
printResult(options.format, {
|
|
21081
|
+
ok: true,
|
|
21082
|
+
domain: "organization.department",
|
|
21083
|
+
action: "search",
|
|
21084
|
+
authority: "platform_group_directory",
|
|
21085
|
+
query,
|
|
21086
|
+
count: departments.length,
|
|
21087
|
+
departments
|
|
21088
|
+
});
|
|
21089
|
+
});
|
|
21090
|
+
department.command("readback").description("Read one department by exact BPMAX group id").requiredOption("--id <id>", "BPMAX group id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21091
|
+
const id = positiveId(options.id, "organization.department.readback.invalid_id");
|
|
21092
|
+
const { client } = await context(options.profile);
|
|
21093
|
+
const departments = await readDepartments(client, [id]);
|
|
21094
|
+
const matched = departments.find((item) => Number(item.id) === id);
|
|
21095
|
+
if (!matched) throw new Error(`organization.department.readback.not_found: \u672A\u627E\u5230\u90E8\u95E8 ${id}\u3002`);
|
|
21096
|
+
printResult(options.format, {
|
|
21097
|
+
ok: true,
|
|
21098
|
+
domain: "organization.department",
|
|
21099
|
+
action: "readback",
|
|
21100
|
+
authority: "platform_group_directory",
|
|
21101
|
+
department: matched
|
|
21102
|
+
});
|
|
21103
|
+
});
|
|
21104
|
+
department.command("memberships").description("Read authoritative department memberships for one user").requiredOption("--user-id <userId>", "BPMAX user id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21105
|
+
const userId = positiveId(options.userId, "organization.department.memberships.invalid_user_id");
|
|
21106
|
+
const { client } = await context(options.profile);
|
|
21107
|
+
const user = await readUser(client, userId);
|
|
21108
|
+
printResult(options.format, {
|
|
21109
|
+
ok: true,
|
|
21110
|
+
domain: "organization.department",
|
|
21111
|
+
action: "memberships",
|
|
21112
|
+
authority: "platform_user_group_relation",
|
|
21113
|
+
user: user.safe,
|
|
21114
|
+
departments: user.safe.departments,
|
|
21115
|
+
managed_departments: user.safe.managed_departments
|
|
21116
|
+
});
|
|
21117
|
+
});
|
|
21118
|
+
organization.command("main-department").description("Read the authoritative main department for one user when the platform exposes it").requiredOption("--user-id <userId>", "BPMAX user id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21119
|
+
const userId = positiveId(options.userId, "organization.main_department.invalid_user_id");
|
|
21120
|
+
const { client } = await context(options.profile);
|
|
21121
|
+
const user = await readUser(client, userId);
|
|
21122
|
+
const id = mainDepartmentId(user.raw);
|
|
21123
|
+
const matches = id ? await readDepartments(client, [id]) : [];
|
|
21124
|
+
printResult(options.format, {
|
|
21125
|
+
ok: true,
|
|
21126
|
+
domain: "organization.main_department",
|
|
21127
|
+
action: "readback",
|
|
21128
|
+
authoritative: Boolean(id),
|
|
21129
|
+
status: id ? "verified" : "platform_authority_required",
|
|
21130
|
+
user: user.safe,
|
|
21131
|
+
main_department: matches.find((item) => Number(item.id) === id) ?? null,
|
|
21132
|
+
candidates: user.safe.departments,
|
|
21133
|
+
...!id ? {
|
|
21134
|
+
reason: "\u5F53\u524D\u5E73\u53F0\u7528\u6237\u6A21\u578B\u672A\u8FD4\u56DE\u4E3B\u90E8\u95E8\u6807\u8BC6\uFF1BCLI \u4E0D\u4F1A\u628A\u7B2C\u4E00\u4E2A\u90E8\u95E8\u731C\u4F5C\u4E3B\u90E8\u95E8\u3002",
|
|
21135
|
+
platform_change_required: true
|
|
21136
|
+
} : {}
|
|
21137
|
+
});
|
|
21138
|
+
});
|
|
21139
|
+
organization.command("branch").description("Read branch mapping candidates without guessing a business branch").requiredOption("--user-id <userId>", "BPMAX user id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21140
|
+
const userId = positiveId(options.userId, "organization.branch.invalid_user_id");
|
|
21141
|
+
const { client } = await context(options.profile);
|
|
21142
|
+
const user = await readUser(client, userId);
|
|
21143
|
+
const departments = user.safe.departments;
|
|
21144
|
+
const id = branchId(user.raw);
|
|
21145
|
+
const matches = id ? await readDepartments(client, [id]) : [];
|
|
21146
|
+
const ancestors = id ? [] : await readDepartments(client, pathIds(departments));
|
|
21147
|
+
printResult(options.format, {
|
|
21148
|
+
ok: true,
|
|
21149
|
+
domain: "organization.branch",
|
|
21150
|
+
action: "readback",
|
|
21151
|
+
authoritative: Boolean(id),
|
|
21152
|
+
status: id ? "verified" : "platform_authority_required",
|
|
21153
|
+
user: user.safe,
|
|
21154
|
+
branch: matches.find((item) => Number(item.id) === id) ?? null,
|
|
21155
|
+
department_ancestors: ancestors,
|
|
21156
|
+
...!id ? {
|
|
21157
|
+
reason: "\u5F53\u524D\u5E73\u53F0\u6CA1\u6709\u7EDF\u4E00\u7684\u5206\u90E8\u7C7B\u578B\u6216 branch_id\uFF1BCLI \u53EA\u8FD4\u56DE\u90E8\u95E8\u7956\u5148\u5019\u9009\uFF0C\u4E0D\u6309\u5C42\u7EA7\u6216\u540D\u79F0\u731C\u6D4B\u5206\u90E8\u3002",
|
|
21158
|
+
platform_change_required: true
|
|
21159
|
+
} : {}
|
|
21160
|
+
});
|
|
21161
|
+
});
|
|
21162
|
+
organization.command("position").description("Read the authoritative position/title field for one user").requiredOption("--user-id <userId>", "BPMAX user id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21163
|
+
const userId = positiveId(options.userId, "organization.position.invalid_user_id");
|
|
21164
|
+
const { client } = await context(options.profile);
|
|
21165
|
+
const user = await readUser(client, userId);
|
|
21166
|
+
printResult(options.format, {
|
|
21167
|
+
ok: true,
|
|
21168
|
+
domain: "organization.position",
|
|
21169
|
+
action: "readback",
|
|
21170
|
+
authority: "platform_user.title",
|
|
21171
|
+
user_id: userId,
|
|
21172
|
+
position: user.safe.position
|
|
21173
|
+
});
|
|
21174
|
+
});
|
|
21175
|
+
organization.command("direct-superior").description("Read the exact direct superior for one user").requiredOption("--user-id <userId>", "BPMAX user id").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21176
|
+
const userId = positiveId(options.userId, "organization.direct_superior.invalid_user_id");
|
|
21177
|
+
const { client } = await context(options.profile);
|
|
21178
|
+
const user = await readUser(client, userId);
|
|
21179
|
+
const leaderId = Number(user.safe.leader_id);
|
|
21180
|
+
const superior = Number.isSafeInteger(leaderId) && leaderId > 0 ? (await readUser(client, leaderId)).safe : null;
|
|
21181
|
+
printResult(options.format, {
|
|
21182
|
+
ok: true,
|
|
21183
|
+
domain: "organization.direct_superior",
|
|
21184
|
+
action: "readback",
|
|
21185
|
+
authority: "platform_user.leader_id",
|
|
21186
|
+
user: user.safe,
|
|
21187
|
+
superior
|
|
21188
|
+
});
|
|
21189
|
+
});
|
|
21190
|
+
organization.command("superior-chain").description("Read a cycle-safe continuous direct-superior chain").requiredOption("--user-id <userId>", "BPMAX user id").option("--levels <levels>", "Maximum superior levels", "20").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21191
|
+
const userId = positiveId(options.userId, "organization.superior_chain.invalid_user_id");
|
|
21192
|
+
const levels = positiveId(options.levels, "organization.superior_chain.invalid_levels");
|
|
21193
|
+
if (levels > 100) throw new Error("organization.superior_chain.invalid_levels: --levels \u4E0D\u80FD\u8D85\u8FC7 100\u3002");
|
|
21194
|
+
const { client } = await context(options.profile);
|
|
21195
|
+
const result = await directSuperiorChain(client, userId, levels);
|
|
21196
|
+
printResult(options.format, {
|
|
21197
|
+
ok: true,
|
|
21198
|
+
domain: "organization.superior_chain",
|
|
21199
|
+
action: "readback",
|
|
21200
|
+
authority: "platform_user.leader_id",
|
|
21201
|
+
user_id: userId,
|
|
21202
|
+
requested_levels: levels,
|
|
21203
|
+
count: result.chain.length,
|
|
21204
|
+
superiors: result.chain,
|
|
21205
|
+
stop_reason: result.stop_reason
|
|
21206
|
+
});
|
|
21207
|
+
});
|
|
21208
|
+
organization.command("readback").description("Read an organization mapping readiness snapshot for one user").requiredOption("--user-id <userId>", "BPMAX user id").option("--levels <levels>", "Maximum direct-superior levels", "20").option("--profile <profile>", "Profile name").option("--format <format>", "Output format", "json").action(async (options) => {
|
|
21209
|
+
const userId = positiveId(options.userId, "organization.readback.invalid_user_id");
|
|
21210
|
+
const levels = positiveId(options.levels, "organization.readback.invalid_levels");
|
|
21211
|
+
if (levels > 100) throw new Error("organization.readback.invalid_levels: --levels \u4E0D\u80FD\u8D85\u8FC7 100\u3002");
|
|
21212
|
+
const { client } = await context(options.profile);
|
|
21213
|
+
const user = await readUser(client, userId);
|
|
21214
|
+
const chain = await directSuperiorChain(client, userId, levels);
|
|
21215
|
+
const mainId = mainDepartmentId(user.raw);
|
|
21216
|
+
const resolvedBranchId = branchId(user.raw);
|
|
21217
|
+
const mainDepartments = mainId ? await readDepartments(client, [mainId]) : [];
|
|
21218
|
+
const branches = resolvedBranchId ? await readDepartments(client, [resolvedBranchId]) : [];
|
|
21219
|
+
printResult(options.format, {
|
|
21220
|
+
ok: true,
|
|
21221
|
+
domain: "organization",
|
|
21222
|
+
action: "readback",
|
|
21223
|
+
user: user.safe,
|
|
21224
|
+
departments: { authoritative: true, value: user.safe.departments },
|
|
21225
|
+
main_department: {
|
|
21226
|
+
authoritative: Boolean(mainId),
|
|
21227
|
+
value: mainDepartments.find((item) => Number(item.id) === mainId) ?? null,
|
|
21228
|
+
status: mainId ? "verified" : "platform_authority_required"
|
|
21229
|
+
},
|
|
21230
|
+
branch: {
|
|
21231
|
+
authoritative: Boolean(resolvedBranchId),
|
|
21232
|
+
value: branches.find((item) => Number(item.id) === resolvedBranchId) ?? null,
|
|
21233
|
+
status: resolvedBranchId ? "verified" : "platform_authority_required"
|
|
21234
|
+
},
|
|
21235
|
+
position: { authoritative: true, value: user.safe.position },
|
|
21236
|
+
direct_superior: { authoritative: true, value: chain.chain[0] ?? null },
|
|
21237
|
+
superior_chain: { authoritative: true, value: chain.chain, stop_reason: chain.stop_reason },
|
|
21238
|
+
platform_change_required: !mainId || !resolvedBranchId
|
|
21239
|
+
});
|
|
21240
|
+
});
|
|
21241
|
+
}
|
|
21242
|
+
|
|
19700
21243
|
// src/commands/plugin.ts
|
|
19701
21244
|
function defaultAgent2(options) {
|
|
19702
21245
|
return options.agent || process.env.BPMAX_CLI_AGENT || "codex";
|
|
@@ -20005,15 +21548,15 @@ async function promptProjectCreateForm(input) {
|
|
|
20005
21548
|
}
|
|
20006
21549
|
|
|
20007
21550
|
// src/core/project-form.ts
|
|
20008
|
-
function
|
|
21551
|
+
function isRecord12(value) {
|
|
20009
21552
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20010
21553
|
}
|
|
20011
21554
|
function clone(value) {
|
|
20012
21555
|
return JSON.parse(JSON.stringify(value));
|
|
20013
21556
|
}
|
|
20014
21557
|
function getFlowFormTemplateId(flowDetail) {
|
|
20015
|
-
const data =
|
|
20016
|
-
const meta =
|
|
21558
|
+
const data = isRecord12(flowDetail?.data) ? flowDetail.data : void 0;
|
|
21559
|
+
const meta = isRecord12(data?.meta) ? data.meta : void 0;
|
|
20017
21560
|
const templateId = meta?.form_template;
|
|
20018
21561
|
if (typeof templateId === "number" && Number.isFinite(templateId)) {
|
|
20019
21562
|
return templateId;
|
|
@@ -20038,7 +21581,7 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
20038
21581
|
if (Array.isArray(value)) {
|
|
20039
21582
|
return value.some((item) => hasAutoInitLambda(item, seen));
|
|
20040
21583
|
}
|
|
20041
|
-
if (!
|
|
21584
|
+
if (!isRecord12(value)) {
|
|
20042
21585
|
return false;
|
|
20043
21586
|
}
|
|
20044
21587
|
if (seen.has(value)) {
|
|
@@ -20053,14 +21596,14 @@ function hasAutoInitLambda(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
20053
21596
|
function setControlValue(control, value) {
|
|
20054
21597
|
const next = clone(control);
|
|
20055
21598
|
next.value = {
|
|
20056
|
-
...
|
|
21599
|
+
...isRecord12(next.value) ? next.value : {},
|
|
20057
21600
|
type: next.value?.type ?? next.field_type,
|
|
20058
21601
|
value
|
|
20059
21602
|
};
|
|
20060
21603
|
return next;
|
|
20061
21604
|
}
|
|
20062
21605
|
function applyRowValues(rowTemplate, rowValue) {
|
|
20063
|
-
const source =
|
|
21606
|
+
const source = isRecord12(rowValue) ? rowValue : {};
|
|
20064
21607
|
return rowTemplate.map((control) => {
|
|
20065
21608
|
if (control.key && Object.prototype.hasOwnProperty.call(source, control.key)) {
|
|
20066
21609
|
return setControlValue(control, source[control.key]);
|
|
@@ -20079,8 +21622,8 @@ function buildProjectFormValue(template, form) {
|
|
|
20079
21622
|
if (control.field_type === "sub_form") {
|
|
20080
21623
|
const subFormRows = control.value?.value;
|
|
20081
21624
|
const rowTemplate = Array.isArray(subFormRows) && Array.isArray(subFormRows[0]) ? subFormRows[0] : [];
|
|
20082
|
-
const
|
|
20083
|
-
return setControlValue(control,
|
|
21625
|
+
const rows2 = Array.isArray(inputValue) ? inputValue.map((row) => applyRowValues(rowTemplate, row)) : [];
|
|
21626
|
+
return setControlValue(control, rows2);
|
|
20084
21627
|
}
|
|
20085
21628
|
return setControlValue(control, inputValue);
|
|
20086
21629
|
});
|
|
@@ -20099,7 +21642,7 @@ async function buildProjectFormPayload(client, flowDetail, form, knownTemplate)
|
|
|
20099
21642
|
}
|
|
20100
21643
|
|
|
20101
21644
|
// src/commands/project.ts
|
|
20102
|
-
function projectCreateErrorDiagnostic(error,
|
|
21645
|
+
function projectCreateErrorDiagnostic(error, context2) {
|
|
20103
21646
|
const baseMessage = error instanceof Error ? error.message : String(error || "");
|
|
20104
21647
|
const response = typeof error === "object" && error !== null && "response" in error ? error.response : void 0;
|
|
20105
21648
|
const status = response?.status;
|
|
@@ -20108,12 +21651,12 @@ function projectCreateErrorDiagnostic(error, context) {
|
|
|
20108
21651
|
const summary = bodyText.length > 1e3 ? `${bodyText.slice(0, 1e3)}...` : bodyText;
|
|
20109
21652
|
return new Error([
|
|
20110
21653
|
`Project create failed${status ? ` with status ${String(status)}` : ""}: ${baseMessage}`,
|
|
20111
|
-
`local_form_validation=${
|
|
20112
|
-
`direct_body=${
|
|
20113
|
-
`no_interactive=${
|
|
20114
|
-
`handoff_available=${
|
|
21654
|
+
`local_form_validation=${context2.localFormValidation}`,
|
|
21655
|
+
`direct_body=${context2.usedBody ? "true" : "false"}`,
|
|
21656
|
+
`no_interactive=${context2.noInteractive ? "true" : "false"}`,
|
|
21657
|
+
`handoff_available=${context2.handoffAvailable ? "true" : "false"}`,
|
|
20115
21658
|
summary ? `server_error_summary=${summary}` : "",
|
|
20116
|
-
|
|
21659
|
+
context2.handoffAvailable ? "next_action=Use the generated form handoff path unless the template is proven safe for direct create." : "next_action=Check field keys/types and server error body; do not bypass with raw API."
|
|
20117
21660
|
].filter(Boolean).join("\n"));
|
|
20118
21661
|
}
|
|
20119
21662
|
async function parseProjectJson(input, label = "--json") {
|
|
@@ -20618,8 +22161,8 @@ function fieldsForValidation(flowDetail, projectFormTemplate) {
|
|
|
20618
22161
|
}));
|
|
20619
22162
|
}
|
|
20620
22163
|
function metaUsesTemplateProjectName(flowDetail) {
|
|
20621
|
-
const data =
|
|
20622
|
-
const meta =
|
|
22164
|
+
const data = isRecord13(flowDetail?.data) ? flowDetail.data : void 0;
|
|
22165
|
+
const meta = isRecord13(data?.meta) ? data.meta : void 0;
|
|
20623
22166
|
const hideFields = Array.isArray(meta?.hide_fields) ? meta.hide_fields.map(String) : [];
|
|
20624
22167
|
return meta?.use_template_project_name === true || hideFields.includes("project.name");
|
|
20625
22168
|
}
|
|
@@ -20728,7 +22271,7 @@ function collectPrefillContextForFields(fields, form, result, options = {}) {
|
|
|
20728
22271
|
result.filled_fields.push(contextField(field, "prefilled", fieldOptions));
|
|
20729
22272
|
if (isSubFormField(field) && Array.isArray(value) && field.children?.length) {
|
|
20730
22273
|
value.forEach((row, index) => {
|
|
20731
|
-
if (
|
|
22274
|
+
if (isRecord13(row)) {
|
|
20732
22275
|
collectPrefillContextForFields(field.children ?? [], row, result, {
|
|
20733
22276
|
prefix: `${field.key}[${index}]`,
|
|
20734
22277
|
rootKey: field.key,
|
|
@@ -20755,7 +22298,7 @@ function buildPrefillContext(fields, form) {
|
|
|
20755
22298
|
}
|
|
20756
22299
|
};
|
|
20757
22300
|
}
|
|
20758
|
-
function
|
|
22301
|
+
function isRecord13(value) {
|
|
20759
22302
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
20760
22303
|
}
|
|
20761
22304
|
function isEndedStep(step) {
|
|
@@ -20778,7 +22321,7 @@ function stepIdOf(step) {
|
|
|
20778
22321
|
function pickStepFormPayload(step) {
|
|
20779
22322
|
const formList = Array.isArray(step.formList) ? step.formList : [];
|
|
20780
22323
|
const forms = Array.isArray(step.forms) ? step.forms : [];
|
|
20781
|
-
const metaForm =
|
|
22324
|
+
const metaForm = isRecord13(step.metaForm) ? step.metaForm : void 0;
|
|
20782
22325
|
return {
|
|
20783
22326
|
step_id: step.id,
|
|
20784
22327
|
flow_step_id: step.flow_step_id,
|
|
@@ -20795,7 +22338,7 @@ function pickStepFormPayload(step) {
|
|
|
20795
22338
|
}
|
|
20796
22339
|
async function buildApprovalContext(client, projectId, options) {
|
|
20797
22340
|
const projectDetail = await apiRequest(client, "GET", `/project/${projectId}`);
|
|
20798
|
-
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(
|
|
22341
|
+
const steps = Array.isArray(projectDetail.steps) ? projectDetail.steps.filter(isRecord13) : [];
|
|
20799
22342
|
const targetStepIds = /* @__PURE__ */ new Set();
|
|
20800
22343
|
for (const step of steps) {
|
|
20801
22344
|
const id = stepIdOf(step);
|
|
@@ -20821,7 +22364,7 @@ async function buildApprovalContext(client, projectId, options) {
|
|
|
20821
22364
|
}
|
|
20822
22365
|
return {
|
|
20823
22366
|
project: projectDetail,
|
|
20824
|
-
project_form:
|
|
22367
|
+
project_form: isRecord13(projectDetail.metaForm) ? projectDetail.metaForm : null,
|
|
20825
22368
|
inspected_step_count: stepForms.length,
|
|
20826
22369
|
step_forms: stepForms,
|
|
20827
22370
|
failed_steps: failedSteps
|
|
@@ -20915,10 +22458,10 @@ function registerProjectCommands(program2) {
|
|
|
20915
22458
|
const config = await loadConfig();
|
|
20916
22459
|
const profile = resolveProfile(config, options.profile);
|
|
20917
22460
|
const client = createApiClient(profile);
|
|
20918
|
-
const
|
|
22461
|
+
const context2 = await buildApprovalContext(client, projectId, { stepId: options.stepId });
|
|
20919
22462
|
printResult(options.format, {
|
|
20920
|
-
...
|
|
20921
|
-
project: attachProjectDetailUrl(profile,
|
|
22463
|
+
...context2,
|
|
22464
|
+
project: attachProjectDetailUrl(profile, context2.project)
|
|
20922
22465
|
});
|
|
20923
22466
|
});
|
|
20924
22467
|
const handoff = project.command("handoff").description("Inspect BPMAX project create-page handoff state");
|
|
@@ -21184,7 +22727,7 @@ function getRecipesDir(options) {
|
|
|
21184
22727
|
const workspaceDirName = normalizeWorkspaceForPath(options.workspace || DEFAULT_WORKSPACE);
|
|
21185
22728
|
return path12.join((options.getProfileDir || getProfileDataDir)(options.profileName), "recipes", workspaceDirName);
|
|
21186
22729
|
}
|
|
21187
|
-
function
|
|
22730
|
+
function isRecord14(value) {
|
|
21188
22731
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21189
22732
|
}
|
|
21190
22733
|
function asString(value, fieldName) {
|
|
@@ -21194,7 +22737,7 @@ function asString(value, fieldName) {
|
|
|
21194
22737
|
return value;
|
|
21195
22738
|
}
|
|
21196
22739
|
function parseRecipeDefinition(input) {
|
|
21197
|
-
if (!
|
|
22740
|
+
if (!isRecord14(input)) {
|
|
21198
22741
|
throw new Error("recipe.json must be a JSON object.");
|
|
21199
22742
|
}
|
|
21200
22743
|
if (input.version !== 1) {
|
|
@@ -21202,7 +22745,7 @@ function parseRecipeDefinition(input) {
|
|
|
21202
22745
|
}
|
|
21203
22746
|
const name = asString(input.name, "recipe.name");
|
|
21204
22747
|
assertSafeName("Recipe name", name);
|
|
21205
|
-
if (!
|
|
22748
|
+
if (!isRecord14(input.command)) {
|
|
21206
22749
|
throw new Error("recipe.command must be an object.");
|
|
21207
22750
|
}
|
|
21208
22751
|
const argv = input.command.argv;
|
|
@@ -21210,7 +22753,7 @@ function parseRecipeDefinition(input) {
|
|
|
21210
22753
|
throw new Error("recipe.command.argv must be a non-empty string array.");
|
|
21211
22754
|
}
|
|
21212
22755
|
const variables = Array.isArray(input.variables) ? input.variables.map((item, index) => {
|
|
21213
|
-
if (!
|
|
22756
|
+
if (!isRecord14(item)) {
|
|
21214
22757
|
throw new Error(`recipe.variables[${index}] must be an object.`);
|
|
21215
22758
|
}
|
|
21216
22759
|
const variableName = asString(item.name, `recipe.variables[${index}].name`);
|
|
@@ -21286,7 +22829,7 @@ function parseVarsJson(input) {
|
|
|
21286
22829
|
return {};
|
|
21287
22830
|
}
|
|
21288
22831
|
const parsed = JSON.parse(input);
|
|
21289
|
-
if (!
|
|
22832
|
+
if (!isRecord14(parsed)) {
|
|
21290
22833
|
throw new Error("--vars must be a JSON object.");
|
|
21291
22834
|
}
|
|
21292
22835
|
const variables = {};
|
|
@@ -21449,8 +22992,8 @@ function registerRecipeCommands(program2, deps = {}) {
|
|
|
21449
22992
|
const configData = await load();
|
|
21450
22993
|
const target = resolveTargetProfile(configData, options.profile);
|
|
21451
22994
|
const workspace = options.workspace || target.workspace;
|
|
21452
|
-
const
|
|
21453
|
-
printResult(options.format,
|
|
22995
|
+
const rows2 = await listRecipes(getRecipesDir({ profileName: target.name, workspace, getProfileDir }));
|
|
22996
|
+
printResult(options.format, rows2);
|
|
21454
22997
|
});
|
|
21455
22998
|
recipe.command("show <name>").description("Show a recipe definition").option("--profile <profile>", "Profile name").option("--workspace <workspace>", "Workspace override").option("--format <format>", "Output format", "pretty").action(async (name, options) => {
|
|
21456
22999
|
const configData = await load();
|
|
@@ -21609,6 +23152,22 @@ var schemaEntries = [
|
|
|
21609
23152
|
{ name: "config.role.create", description: "Create roles, custom points, and role members through typed operation plans.", method: "POST", path: "/api/role + /api/point + /api/user_role" },
|
|
21610
23153
|
{ name: "config.role.delete", description: "Delete roles, custom points, or role members through typed adapters.", method: "DELETE", path: "/api/role/:id + /api/point/:id + /api/user_role/:id" },
|
|
21611
23154
|
{ name: "config.role.submit", description: "Submit role operation plan through a verified typed adapter.", method: "POST/PUT/DELETE", path: "/api/role + /api/point + /api/user_role" },
|
|
23155
|
+
{ name: "config.team.export", description: "Export one BPMAX team with hierarchy, model, permission, and administrator readback.", method: "GET", path: "/api/group/:id" },
|
|
23156
|
+
{ name: "config.team.create", description: "Create one BPMAX team through the typed group adapter.", method: "POST", path: "/api/group" },
|
|
23157
|
+
{ name: "config.team.delete", description: "Delete one BPMAX team through the typed group adapter.", method: "DELETE", path: "/api/group/:id" },
|
|
23158
|
+
{ name: "config.team.submit", description: "Submit one BPMAX team edit through the typed group adapter.", method: "PUT", path: "/api/group/:id" },
|
|
23159
|
+
{ name: "config.user.export", description: "Export one BPMAX user with privacy-safe identity and relation readback.", method: "GET", path: "/api/user/:id?only_user_role=1" },
|
|
23160
|
+
{ name: "config.user.create", description: "Create one BPMAX organization user through the typed adapter.", method: "POST", path: "/api/user" },
|
|
23161
|
+
{ name: "config.user.delete", description: "Delete one BPMAX organization user through the typed adapter.", method: "DELETE", path: "/api/user/:id" },
|
|
23162
|
+
{ name: "config.user.submit", description: "Submit safe BPMAX user and organization relation edits.", method: "PUT", path: "/api/user/:id" },
|
|
23163
|
+
{ name: "config.user_model.export", description: "Export one BPMAX user model by id or UUID.", method: "GET", path: "/api/user_model/:id + /api/user_model/get_by_uuid" },
|
|
23164
|
+
{ name: "config.user_model.create", description: "Create one BPMAX user model through the typed adapter.", method: "POST", path: "/api/user_model" },
|
|
23165
|
+
{ name: "config.user_model.delete", description: "Delete one BPMAX user model through the typed adapter.", method: "DELETE", path: "/api/user_model/:id" },
|
|
23166
|
+
{ name: "config.user_model.submit", description: "Submit one BPMAX user model edit through the typed adapter.", method: "PUT", path: "/api/user_model/:id" },
|
|
23167
|
+
{ name: "config.group_model.export", description: "Export one BPMAX group model by id or UUID.", method: "GET", path: "/api/group_model/:id + /api/group_model/get_by_uuid" },
|
|
23168
|
+
{ name: "config.group_model.create", description: "Create one BPMAX group model through the typed adapter.", method: "POST", path: "/api/group_model" },
|
|
23169
|
+
{ name: "config.group_model.delete", description: "Delete one BPMAX group model through the typed adapter.", method: "DELETE", path: "/api/group_model/:id" },
|
|
23170
|
+
{ name: "config.group_model.submit", description: "Submit one BPMAX group model edit through the typed adapter.", method: "PUT", path: "/api/group_model/:id" },
|
|
21612
23171
|
{ name: "config.nav_config.export", description: "Export all workspace navigation config records.", method: "GET", path: "/api/configuration?q_type=:type&is_default_action=1" },
|
|
21613
23172
|
{ name: "config.nav_config.create", description: "Create workspace navigation config records through a typed operation plan.", method: "POST", path: "/api/configuration?is_default_action=1" },
|
|
21614
23173
|
{ name: "config.nav_config.delete", description: "Delete workspace navigation config records through a typed operation plan.", method: "DELETE", path: "/api/configuration/:id?is_default_action=1" },
|
|
@@ -21851,7 +23410,7 @@ var PROMPT_REQUIRED_TERMS = [
|
|
|
21851
23410
|
"\u8FDB\u5EA6 CSV"
|
|
21852
23411
|
];
|
|
21853
23412
|
var BPMAX_SKILL_PATTERN = /bpmax-[a-z0-9-]+|form-control-library|bpmax-memory-protocol/;
|
|
21854
|
-
var FLOW_LOCK_PATTERN =
|
|
23413
|
+
var FLOW_LOCK_PATTERN = /(?<![A-Za-z0-9_-])flow:([A-Za-z0-9_-]+)/g;
|
|
21855
23414
|
var UUID_PATTERN = /\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/gi;
|
|
21856
23415
|
var CONFIG_TASK_RULES = [
|
|
21857
23416
|
{
|
|
@@ -22101,9 +23660,9 @@ function hasForbiddenListDeleteStepGuard(value) {
|
|
|
22101
23660
|
}
|
|
22102
23661
|
function validateTaskbookNavigationAndListGates(text5, issues) {
|
|
22103
23662
|
const strategy = validateNavigationStrategy(text5, issues, "navigation_strategy", "\u4EFB\u52A1\u4E66");
|
|
22104
|
-
const
|
|
22105
|
-
const navRows =
|
|
22106
|
-
const listRows =
|
|
23663
|
+
const rows2 = extractTaskRows(text5);
|
|
23664
|
+
const navRows = rows2.filter((row) => /bpmax-nav-config-editor/.test(row.required_skills || ""));
|
|
23665
|
+
const listRows = rows2.filter((row) => /bpmax-list-template-editor/.test(row.required_skills || ""));
|
|
22107
23666
|
if (strategy === "nav-config:included" && navRows.length === 0) {
|
|
22108
23667
|
addTaskbookIssue(
|
|
22109
23668
|
issues,
|
|
@@ -22271,8 +23830,8 @@ function validateConfigRuleForTaskRow(row, rule, issues) {
|
|
|
22271
23830
|
}
|
|
22272
23831
|
}
|
|
22273
23832
|
function validateTaskbookConfigSkillGates(text5, issues) {
|
|
22274
|
-
const
|
|
22275
|
-
for (const row of
|
|
23833
|
+
const rows2 = extractTaskRows(text5);
|
|
23834
|
+
for (const row of rows2) {
|
|
22276
23835
|
for (const rule of CONFIG_TASK_RULES) {
|
|
22277
23836
|
validateConfigRuleForTaskRow(row, rule, issues);
|
|
22278
23837
|
}
|
|
@@ -22622,7 +24181,7 @@ function csvEscape(value) {
|
|
|
22622
24181
|
}
|
|
22623
24182
|
function extractTaskRows(text5) {
|
|
22624
24183
|
const lines = text5.split(/\r?\n/);
|
|
22625
|
-
const
|
|
24184
|
+
const rows2 = [];
|
|
22626
24185
|
for (let index = 0; index < lines.length; index += 1) {
|
|
22627
24186
|
const line = lines[index];
|
|
22628
24187
|
if (!line.trim().startsWith("|")) {
|
|
@@ -22647,17 +24206,17 @@ function extractTaskRows(text5) {
|
|
|
22647
24206
|
row[header] = cells[cellIndex] || "";
|
|
22648
24207
|
});
|
|
22649
24208
|
if (row.task_id) {
|
|
22650
|
-
|
|
24209
|
+
rows2.push(row);
|
|
22651
24210
|
}
|
|
22652
24211
|
cursor += 1;
|
|
22653
24212
|
}
|
|
22654
24213
|
}
|
|
22655
|
-
return
|
|
24214
|
+
return rows2;
|
|
22656
24215
|
}
|
|
22657
24216
|
async function initTaskbookProgress(source, outFile) {
|
|
22658
24217
|
const text5 = await readTaskbookText(source);
|
|
22659
|
-
const
|
|
22660
|
-
if (
|
|
24218
|
+
const rows2 = extractTaskRows(text5);
|
|
24219
|
+
if (rows2.length === 0) {
|
|
22661
24220
|
throw new TaskbookError("Taskbook progress init could not find an AI task table with task_id/status/subagent_mode columns.");
|
|
22662
24221
|
}
|
|
22663
24222
|
const fields = [
|
|
@@ -22678,11 +24237,11 @@ async function initTaskbookProgress(source, outFile) {
|
|
|
22678
24237
|
];
|
|
22679
24238
|
const csv = [
|
|
22680
24239
|
fields.join(","),
|
|
22681
|
-
...
|
|
24240
|
+
...rows2.map((row) => fields.map((field) => csvEscape(field === "status" ? "\u672A\u5F00\u59CB" : row[field] || "")).join(","))
|
|
22682
24241
|
].join("\n") + "\n";
|
|
22683
24242
|
await mkdir12(path13.dirname(outFile), { recursive: true });
|
|
22684
24243
|
await writeFile12(outFile, csv, "utf8");
|
|
22685
|
-
return { source, out: outFile, task_count:
|
|
24244
|
+
return { source, out: outFile, task_count: rows2.length };
|
|
22686
24245
|
}
|
|
22687
24246
|
|
|
22688
24247
|
// src/commands/taskbook.ts
|
|
@@ -22825,10 +24384,14 @@ var UPDATE_STATE_FILE = "update-state.json";
|
|
|
22825
24384
|
var CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
22826
24385
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
22827
24386
|
var NPM_INSTALL_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
22828
|
-
function
|
|
24387
|
+
function updateChannelForVersion(version) {
|
|
24388
|
+
const prerelease = version.trim().replace(/^v/, "").split("+", 1)[0].split("-", 2)[1] || "";
|
|
24389
|
+
return prerelease.split(".", 1)[0].toLowerCase() === "beta" ? "beta" : "latest";
|
|
24390
|
+
}
|
|
24391
|
+
function buildRegistryUrl(packageName = NPM_PACKAGE, env = process.env, distTag = "latest") {
|
|
22829
24392
|
const base = env.BPMAX_CLI_REGISTRY_URL || DEFAULT_REGISTRY_URL;
|
|
22830
24393
|
const normalizedBase = base.endsWith("/") ? base : `${base}/`;
|
|
22831
|
-
return new URL(`${encodeURIComponent(packageName).replace("%40", "@")}
|
|
24394
|
+
return new URL(`${encodeURIComponent(packageName).replace("%40", "@")}/${distTag}`, normalizedBase).toString();
|
|
22832
24395
|
}
|
|
22833
24396
|
function parseVersion(version) {
|
|
22834
24397
|
const clean = version.trim().replace(/^v/, "").split("+")[0];
|
|
@@ -22915,7 +24478,7 @@ async function fetchLatestVersion(options = {}) {
|
|
|
22915
24478
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
22916
24479
|
try {
|
|
22917
24480
|
const fetchImpl = options.fetchImpl || fetch;
|
|
22918
|
-
const response = await fetchImpl(buildRegistryUrl(options.packageName, options.env), {
|
|
24481
|
+
const response = await fetchImpl(buildRegistryUrl(options.packageName, options.env, options.distTag), {
|
|
22919
24482
|
signal: controller.signal
|
|
22920
24483
|
});
|
|
22921
24484
|
if (!response.ok) {
|
|
@@ -22940,7 +24503,11 @@ async function readUpdateState(configDir) {
|
|
|
22940
24503
|
if (typeof parsed.latest_version !== "string" || typeof parsed.checked_at !== "number") {
|
|
22941
24504
|
return null;
|
|
22942
24505
|
}
|
|
22943
|
-
return {
|
|
24506
|
+
return {
|
|
24507
|
+
latest_version: parsed.latest_version,
|
|
24508
|
+
checked_at: parsed.checked_at,
|
|
24509
|
+
channel: parsed.channel === "beta" ? "beta" : "latest"
|
|
24510
|
+
};
|
|
22944
24511
|
} catch {
|
|
22945
24512
|
return null;
|
|
22946
24513
|
}
|
|
@@ -22957,6 +24524,10 @@ async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
|
22957
24524
|
if (!state) {
|
|
22958
24525
|
return null;
|
|
22959
24526
|
}
|
|
24527
|
+
const channel = updateChannelForVersion(currentVersion);
|
|
24528
|
+
if (state.channel !== channel) {
|
|
24529
|
+
return null;
|
|
24530
|
+
}
|
|
22960
24531
|
const checkedAtMs = state.checked_at * 1e3;
|
|
22961
24532
|
if (Date.now() - checkedAtMs > CACHE_TTL_MS) {
|
|
22962
24533
|
return null;
|
|
@@ -22964,19 +24535,24 @@ async function checkCachedUpdate(currentVersion, configDir = getConfigDir()) {
|
|
|
22964
24535
|
if (!isNewerVersion(state.latest_version, currentVersion)) {
|
|
22965
24536
|
return null;
|
|
22966
24537
|
}
|
|
22967
|
-
return { current: currentVersion, latest: state.latest_version };
|
|
24538
|
+
return { current: currentVersion, latest: state.latest_version, channel };
|
|
22968
24539
|
}
|
|
22969
24540
|
async function refreshUpdateCache(currentVersion, configDir = getConfigDir(), options = {}) {
|
|
22970
24541
|
if (process.env.BPMAX_CLI_NO_UPDATE_NOTIFIER) {
|
|
22971
24542
|
return null;
|
|
22972
24543
|
}
|
|
24544
|
+
const channel = updateChannelForVersion(currentVersion);
|
|
22973
24545
|
const state = await readUpdateState(configDir);
|
|
22974
|
-
if (state && Date.now() - state.checked_at * 1e3 < CACHE_TTL_MS) {
|
|
22975
|
-
return isNewerVersion(state.latest_version, currentVersion) ? { current: currentVersion, latest: state.latest_version } : null;
|
|
24546
|
+
if (state && state.channel === channel && Date.now() - state.checked_at * 1e3 < CACHE_TTL_MS) {
|
|
24547
|
+
return isNewerVersion(state.latest_version, currentVersion) ? { current: currentVersion, latest: state.latest_version, channel } : null;
|
|
22976
24548
|
}
|
|
22977
|
-
const latest = await fetchLatestVersion(options);
|
|
22978
|
-
await writeUpdateState({
|
|
22979
|
-
|
|
24549
|
+
const latest = await fetchLatestVersion({ ...options, distTag: options.distTag || channel });
|
|
24550
|
+
await writeUpdateState({
|
|
24551
|
+
latest_version: latest,
|
|
24552
|
+
checked_at: Math.floor(Date.now() / 1e3),
|
|
24553
|
+
channel
|
|
24554
|
+
}, configDir);
|
|
24555
|
+
return isNewerVersion(latest, currentVersion) ? { current: currentVersion, latest, channel } : null;
|
|
22980
24556
|
}
|
|
22981
24557
|
async function executablePath() {
|
|
22982
24558
|
const candidate = process.argv[1] || "";
|
|
@@ -23047,7 +24623,8 @@ function skillsAction(result) {
|
|
|
23047
24623
|
};
|
|
23048
24624
|
}
|
|
23049
24625
|
function registerUpdateCommands(program2, deps = {}) {
|
|
23050
|
-
const
|
|
24626
|
+
const channel = updateChannelForVersion(VERSION);
|
|
24627
|
+
const fetchLatest = deps.fetchLatest || (() => fetchLatestVersion({ packageName: NPM_PACKAGE, distTag: channel }));
|
|
23051
24628
|
const detectInstall = deps.detectInstall || detectCurrentInstallMethod;
|
|
23052
24629
|
const install = deps.install || ((version) => runNpmInstall(version, { packageName: NPM_PACKAGE }));
|
|
23053
24630
|
const runSkills = deps.syncSkills || ((version, options) => syncSkills(version, options));
|
|
@@ -23074,6 +24651,7 @@ function registerUpdateCommands(program2, deps = {}) {
|
|
|
23074
24651
|
previous_version: VERSION,
|
|
23075
24652
|
current_version: VERSION,
|
|
23076
24653
|
latest_version: latest,
|
|
24654
|
+
channel,
|
|
23077
24655
|
action: updateAvailable ? "update_available" : "already_up_to_date",
|
|
23078
24656
|
auto_update: detect.method === "npm" && detect.npmAvailable,
|
|
23079
24657
|
skills_status: {
|
|
@@ -23099,6 +24677,7 @@ function registerUpdateCommands(program2, deps = {}) {
|
|
|
23099
24677
|
previous_version: VERSION,
|
|
23100
24678
|
current_version: VERSION,
|
|
23101
24679
|
latest_version: latest,
|
|
24680
|
+
channel,
|
|
23102
24681
|
action: "already_up_to_date",
|
|
23103
24682
|
...skillsAction(synced2)
|
|
23104
24683
|
};
|
|
@@ -23121,6 +24700,7 @@ function registerUpdateCommands(program2, deps = {}) {
|
|
|
23121
24700
|
previous_version: VERSION,
|
|
23122
24701
|
current_version: VERSION,
|
|
23123
24702
|
latest_version: latest,
|
|
24703
|
+
channel,
|
|
23124
24704
|
action: "manual_required",
|
|
23125
24705
|
message: `Automatic update unavailable: ${manualReason(detect)} (path: ${detect.resolvedPath})`,
|
|
23126
24706
|
manual_command: `npm install -g ${NPM_PACKAGE}@${latest}`,
|
|
@@ -23161,6 +24741,7 @@ ${detail}` : ""}`);
|
|
|
23161
24741
|
previous_version: VERSION,
|
|
23162
24742
|
current_version: latest,
|
|
23163
24743
|
latest_version: latest,
|
|
24744
|
+
channel,
|
|
23164
24745
|
action: "updated",
|
|
23165
24746
|
...skillsAction(synced)
|
|
23166
24747
|
};
|
|
@@ -23232,17 +24813,17 @@ function registerUrlCommands(program2, deps = {}) {
|
|
|
23232
24813
|
}
|
|
23233
24814
|
|
|
23234
24815
|
// src/commands/user.ts
|
|
23235
|
-
function
|
|
24816
|
+
function isRecord15(value) {
|
|
23236
24817
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23237
24818
|
}
|
|
23238
24819
|
function userRows(value) {
|
|
23239
|
-
if (Array.isArray(value)) return value.filter(
|
|
23240
|
-
if (!
|
|
23241
|
-
if (Array.isArray(value.data)) return value.data.filter(
|
|
24820
|
+
if (Array.isArray(value)) return value.filter(isRecord15);
|
|
24821
|
+
if (!isRecord15(value)) return [];
|
|
24822
|
+
if (Array.isArray(value.data)) return value.data.filter(isRecord15);
|
|
23242
24823
|
return value.id ? [value] : [];
|
|
23243
24824
|
}
|
|
23244
|
-
function
|
|
23245
|
-
const roles = Array.isArray(user.role) ? user.role.filter(
|
|
24825
|
+
function safeUser2(user) {
|
|
24826
|
+
const roles = Array.isArray(user.role) ? user.role.filter(isRecord15).map((role) => ({
|
|
23246
24827
|
id: role.id,
|
|
23247
24828
|
key: role.key,
|
|
23248
24829
|
name: role.name
|
|
@@ -23252,7 +24833,7 @@ function safeUser(user) {
|
|
|
23252
24833
|
return {
|
|
23253
24834
|
id: user.id,
|
|
23254
24835
|
name: user.name,
|
|
23255
|
-
employee_no: user.partner_id ??
|
|
24836
|
+
employee_no: user.partner_id ?? null,
|
|
23256
24837
|
organization_id: user.organization_id,
|
|
23257
24838
|
status,
|
|
23258
24839
|
is_deleted: isDeleted,
|
|
@@ -23260,16 +24841,16 @@ function safeUser(user) {
|
|
|
23260
24841
|
roles
|
|
23261
24842
|
};
|
|
23262
24843
|
}
|
|
23263
|
-
async function
|
|
24844
|
+
async function fetchUsers2(client, params, capability = "user.search") {
|
|
23264
24845
|
const result = await apiRequest(client, "GET", "/user", {
|
|
23265
24846
|
params: {
|
|
23266
24847
|
...params,
|
|
23267
24848
|
subRelations: "role",
|
|
23268
|
-
field_filter: "id,name,partner_id,
|
|
24849
|
+
field_filter: "id,name,partner_id,status,is_del,organization_id"
|
|
23269
24850
|
},
|
|
23270
24851
|
capability
|
|
23271
24852
|
});
|
|
23272
|
-
return userRows(result).map(
|
|
24853
|
+
return userRows(result).map(safeUser2);
|
|
23273
24854
|
}
|
|
23274
24855
|
function registerUserCommands(program2) {
|
|
23275
24856
|
const user = program2.command("user").description("User commands");
|
|
@@ -23288,7 +24869,7 @@ function registerUserCommands(program2) {
|
|
|
23288
24869
|
if (!query) throw new Error("user.search.query_required: --query \u4E0D\u80FD\u4E3A\u7A7A\u3002");
|
|
23289
24870
|
const config = await loadConfig();
|
|
23290
24871
|
const profile = resolveProfile(config, options.profile);
|
|
23291
|
-
let users = await
|
|
24872
|
+
let users = await fetchUsers2(createApiClient(profile), { querystring: query });
|
|
23292
24873
|
if (options.activeOnly) users = users.filter((user2) => user2.active === true);
|
|
23293
24874
|
printResult(options.format, {
|
|
23294
24875
|
ok: true,
|
|
@@ -23306,7 +24887,7 @@ function registerUserCommands(program2) {
|
|
|
23306
24887
|
}
|
|
23307
24888
|
const config = await loadConfig();
|
|
23308
24889
|
const profile = resolveProfile(config, options.profile);
|
|
23309
|
-
const users = await
|
|
24890
|
+
const users = await fetchUsers2(createApiClient(profile), { ids: String(id) }, "user.readback");
|
|
23310
24891
|
const matched = users.find((user2) => Number(user2.id) === id);
|
|
23311
24892
|
if (!matched) throw new Error(`user.readback.not_found: \u672A\u627E\u5230\u7528\u6237 ${id}\u3002`);
|
|
23312
24893
|
printResult(options.format, {
|
|
@@ -23325,7 +24906,7 @@ function registerUserCommands(program2) {
|
|
|
23325
24906
|
const config = await loadConfig();
|
|
23326
24907
|
const profile = resolveProfile(config, options.profile);
|
|
23327
24908
|
const query = employeeNo || name || "";
|
|
23328
|
-
const users = await
|
|
24909
|
+
const users = await fetchUsers2(createApiClient(profile), { querystring: query });
|
|
23329
24910
|
const exact = users.filter((user2) => (!name || String(user2.name ?? "") === name) && (!employeeNo || String(user2.employee_no ?? "") === employeeNo));
|
|
23330
24911
|
if (exact.length === 0) {
|
|
23331
24912
|
throw new Error("user.resolve.not_found: \u672A\u627E\u5230\u7B26\u5408\u7CBE\u786E\u59D3\u540D/\u5DE5\u53F7\u6761\u4EF6\u7684 BPMAX \u7528\u6237\u3002");
|
|
@@ -23351,13 +24932,13 @@ var pendingUpdate = null;
|
|
|
23351
24932
|
var pendingSkills = null;
|
|
23352
24933
|
var pendingSetup = null;
|
|
23353
24934
|
function updateMessage(info) {
|
|
23354
|
-
return
|
|
24935
|
+
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`;
|
|
23355
24936
|
}
|
|
23356
24937
|
function skillsMessage(info) {
|
|
23357
24938
|
if (!info.current) {
|
|
23358
|
-
return "bpmax-cli
|
|
24939
|
+
return "\u5C1A\u672A\u5B89\u88C5\u4E0E\u5F53\u524D bpmax-cli \u5339\u914D\u7684 Skills\uFF0C\u8BF7\u6267\u884C\uFF1Abpmax-cli update --json";
|
|
23359
24940
|
}
|
|
23360
|
-
return `bpmax-cli
|
|
24941
|
+
return `bpmax-cli Skills \u7248\u672C ${info.current} \u4E0E CLI ${info.target} \u4E0D\u4E00\u81F4\uFF0C\u8BF7\u6267\u884C\uFF1Abpmax-cli update --json`;
|
|
23361
24942
|
}
|
|
23362
24943
|
function setupMessage() {
|
|
23363
24944
|
return [
|
|
@@ -23376,6 +24957,13 @@ function shouldWriteSetupNotice(argv) {
|
|
|
23376
24957
|
}
|
|
23377
24958
|
return args.includes("--version") || args.includes("-V");
|
|
23378
24959
|
}
|
|
24960
|
+
function shouldWriteImmediateVersionNotice(argv) {
|
|
24961
|
+
const args = argv.slice(2);
|
|
24962
|
+
if (args.length === 0) {
|
|
24963
|
+
return true;
|
|
24964
|
+
}
|
|
24965
|
+
return args.some((arg) => ["--version", "-V", "--help", "-h"].includes(arg));
|
|
24966
|
+
}
|
|
23379
24967
|
async function setupNotices(argv = process.argv) {
|
|
23380
24968
|
pendingUpdate = await checkCachedUpdate(VERSION);
|
|
23381
24969
|
const skills = await checkSkillsSync(VERSION);
|
|
@@ -23396,6 +24984,8 @@ async function setupNotices(argv = process.argv) {
|
|
|
23396
24984
|
notice.update = {
|
|
23397
24985
|
current: pendingUpdate.current,
|
|
23398
24986
|
latest: pendingUpdate.latest,
|
|
24987
|
+
channel: pendingUpdate.channel,
|
|
24988
|
+
next_command: "bpmax-cli update --json",
|
|
23399
24989
|
message: updateMessage(pendingUpdate)
|
|
23400
24990
|
};
|
|
23401
24991
|
}
|
|
@@ -23403,17 +24993,26 @@ async function setupNotices(argv = process.argv) {
|
|
|
23403
24993
|
notice.skills = {
|
|
23404
24994
|
current: pendingSkills.current,
|
|
23405
24995
|
target: pendingSkills.target,
|
|
24996
|
+
next_command: "bpmax-cli update --json",
|
|
23406
24997
|
message: skillsMessage(pendingSkills)
|
|
23407
24998
|
};
|
|
23408
24999
|
}
|
|
23409
25000
|
return Object.keys(notice).length > 0 ? notice : null;
|
|
23410
25001
|
});
|
|
23411
|
-
|
|
23412
|
-
|
|
23413
|
-
pendingUpdate =
|
|
25002
|
+
if (!pendingUpdate) {
|
|
25003
|
+
try {
|
|
25004
|
+
pendingUpdate = await refreshUpdateCache(VERSION);
|
|
25005
|
+
} catch {
|
|
23414
25006
|
}
|
|
23415
|
-
}
|
|
23416
|
-
|
|
25007
|
+
}
|
|
25008
|
+
if (shouldWriteImmediateVersionNotice(argv)) {
|
|
25009
|
+
if (pendingUpdate) {
|
|
25010
|
+
console.error(updateMessage(pendingUpdate));
|
|
25011
|
+
}
|
|
25012
|
+
if (pendingSkills) {
|
|
25013
|
+
console.error(skillsMessage(pendingSkills));
|
|
25014
|
+
}
|
|
25015
|
+
}
|
|
23417
25016
|
}
|
|
23418
25017
|
|
|
23419
25018
|
// src/bin.ts
|
|
@@ -23509,7 +25108,7 @@ function printCommandError(error) {
|
|
|
23509
25108
|
const message = error instanceof Error ? error.message : String(error);
|
|
23510
25109
|
const structured = error && typeof error === "object" ? error : {};
|
|
23511
25110
|
if (formatFromArgv(process.argv) === "json") {
|
|
23512
|
-
console.log(JSON.stringify({
|
|
25111
|
+
console.log(JSON.stringify(withJsonNotice({
|
|
23513
25112
|
ok: false,
|
|
23514
25113
|
error: message,
|
|
23515
25114
|
...typeof structured.code === "string" ? { code: structured.code } : {},
|
|
@@ -23531,9 +25130,10 @@ function printCommandError(error) {
|
|
|
23531
25130
|
...typeof structured.env === "string" ? { env: structured.env } : {},
|
|
23532
25131
|
...commandDomainFromArgv(process.argv) ? { domain: commandDomainFromArgv(process.argv) } : {},
|
|
23533
25132
|
...commandEndpointHint(process.argv) ? { endpoint: commandEndpointHint(process.argv) } : {}
|
|
23534
|
-
}, null, 2));
|
|
25133
|
+
}), null, 2));
|
|
23535
25134
|
return;
|
|
23536
25135
|
}
|
|
25136
|
+
emitTextNotice();
|
|
23537
25137
|
console.error(message);
|
|
23538
25138
|
}
|
|
23539
25139
|
function commanderExitCode(error) {
|
|
@@ -23592,6 +25192,7 @@ registerFlowCommands(program);
|
|
|
23592
25192
|
registerIssueCommands(program);
|
|
23593
25193
|
registerMemoryCommands(program);
|
|
23594
25194
|
registerMatrixCommands(program);
|
|
25195
|
+
registerOrganizationCommands(program);
|
|
23595
25196
|
registerPluginCommands(program);
|
|
23596
25197
|
registerProjectCommands(program);
|
|
23597
25198
|
registerStepCommands(program);
|