@senguoyunnpm/producer-cli 0.0.2 → 0.0.4
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 +23 -12
- package/dist/config.d.ts +1 -0
- package/dist/config.js +33 -15
- package/dist/config.js.map +1 -1
- package/dist/main.js +23 -40
- package/dist/main.js.map +1 -1
- package/dist/main.mjs +70 -69
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +11 -0
- package/dist/paths.js.map +1 -0
- package/dist/update/layout.d.ts +11 -2
- package/dist/update/layout.js +41 -18
- package/dist/update/layout.js.map +1 -1
- package/dist/update/version.d.ts +1 -1
- package/dist/update/version.js +1 -1
- package/dist/v5-credentials.d.ts +27 -0
- package/dist/v5-credentials.js +147 -0
- package/dist/v5-credentials.js.map +1 -0
- package/package.json +6 -6
- package/dist/generated/catalog-revision.d.ts +0 -1
- package/dist/generated/catalog-revision.js +0 -2
- package/dist/generated/catalog-revision.js.map +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
森果产地通命令行工具。命令、参数和输出由随包发布的离线业务契约生成,业务调用统一经 `ai-platform` MCP 执行,覆盖采购、销售、库存、加工、分选、资金、客户与报表等产地业务。
|
|
7
7
|
|
|
8
8
|
- 渐进式命令发现:`producer schema` 从能力包到叶子契约逐层展开。
|
|
9
|
-
- 读写命令同一入口:写命令只接受显式意图参数与 `--yes
|
|
9
|
+
- 读写命令同一入口:写命令只接受显式意图参数与 `--yes`;V5 写权限由服务端 `producer_write_execute` 在执行边界校验。
|
|
10
10
|
- 结构化输出:成功/失败统一信封,支持 `--format`、`--fields`、`--jq` 和分页。
|
|
11
11
|
- 不直连业务后端,不内置登录:MCP Token 由宿主注入。
|
|
12
12
|
|
|
@@ -28,7 +28,7 @@ export SENGUO_AI_MCP_ENV=test # test | production
|
|
|
28
28
|
export SENGUO_AI_MCP_TOKEN=... # 宿主提供的登录态 Token
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
也可以在当前目录写 `.env`(格式相同);显式环境变量优先,`schema`
|
|
31
|
+
也可以在当前目录写 `.env`(格式相同);显式环境变量优先,`schema` 命令不读取凭据。`SENGUO_AI_MCP_URL` 优先于环境选择,用于宿主注入远端 V5 MCP endpoint;URL 与 Token 必须成对来自环境变量或同一个 `.env` 文件。
|
|
32
32
|
|
|
33
33
|
选择店铺并查询:
|
|
34
34
|
|
|
@@ -65,7 +65,7 @@ cat input.json | producer stockin document create --params - --yes
|
|
|
65
65
|
```
|
|
66
66
|
|
|
67
67
|
- 未传 `--yes` 时不发起预检或写入,返回结构化 `confirmation_required`。
|
|
68
|
-
- `--yes`
|
|
68
|
+
- `--yes` 只确认用户提交意图。CLI 不用 read-only `producer_capability_check` 预检 mutation;write-only 授权不能被 read 预检误挡,实际写授权由 `producer_write_execute` 校验。
|
|
69
69
|
- 写命令不提供 `--dry-run`,参数以 `producer schema <path>` 为准。
|
|
70
70
|
- 结果到 stdout,错误同样输出 JSON 信封 `{ok:false,outcome:"failure",error:{type,code,message,details}}`,并用退出码区分成功与失败。
|
|
71
71
|
|
|
@@ -79,20 +79,31 @@ producer status --jq '.data.user.nickname'
|
|
|
79
79
|
|
|
80
80
|
`--fields` 按顶层数组逐元素投影并保留信封其余键;`--jq` 作用于完整输出并内嵌 jq(WebAssembly),无需本机安装。
|
|
81
81
|
|
|
82
|
+
## 客户银行账户
|
|
83
|
+
|
|
84
|
+
`producer customer shop detail --customer-id "$CUSTOMER_ID"` 查询客户详情及当前身份可见的银行账户;`CUSTOMER_ID` 取自 `producer customer shop list` 的 `data.records[].producer_shop_map_id`。账户列表为空可能是未维护或权限受限,不能据此断言没有账户。
|
|
85
|
+
|
|
86
|
+
`producer customer shop create` 和 `update` 的 `--params` 支持 `bank_card_info_ls`:省略或 `null` 保留原值,`[]` 清空,非空数组完整替换(最多20个)。更新已有账户时保留详情中的 `account_id`;银行账号 `bank_card_num` 使用字符串以保留前导零。账户详情和各字段约束通过 `producer schema customer shop detail`、`create`、`update` 查询,写入仍需 `--yes`。
|
|
87
|
+
|
|
88
|
+
兼容字段 `bank_card_info` 用于维护单个默认账户;与 `bank_card_info_ls` 同时传入时,非 `null` 的列表优先。
|
|
89
|
+
|
|
82
90
|
## 配置
|
|
83
91
|
|
|
84
|
-
| 变量/参数
|
|
85
|
-
|
|
|
86
|
-
| `SENGUO_AI_MCP_ENV`
|
|
87
|
-
| `SENGUO_AI_MCP_URL`
|
|
88
|
-
| `SENGUO_AI_MCP_TOKEN`
|
|
89
|
-
|
|
|
90
|
-
| `--
|
|
92
|
+
| 变量/参数 | 说明 |
|
|
93
|
+
| -------------------------------- | ---------------------------------------------------------- |
|
|
94
|
+
| `SENGUO_AI_MCP_ENV` | `test` 或 `production`,使用内置 MCP 地址 |
|
|
95
|
+
| `SENGUO_AI_MCP_URL` | 自定义 MCP 地址,优先于 `SENGUO_AI_MCP_ENV` |
|
|
96
|
+
| `SENGUO_AI_MCP_TOKEN` | MCP 登录态 Token,以 `Authorization: Bearer` 发送 |
|
|
97
|
+
| `SENGUO_AI_MCP_CREDENTIALS_FILE` | 本地登录态文件路径;默认用户配置目录下 `credentials.json` |
|
|
98
|
+
| `--shop-ref <ref>` | 单次命令覆盖当前店铺;`shop_ref` 来自 `producer shop list` |
|
|
99
|
+
| `--last <dur>` | 相对时间窗,展开为业务日期范围 |
|
|
91
100
|
|
|
92
|
-
当前店铺保存在用户配置目录:macOS/Linux 为 `~/.config/producer/config.json`(`XDG_CONFIG_HOME` 优先),Windows 为 `%APPDATA%\producer\config.json`。Token 不进入 argv
|
|
101
|
+
当前店铺保存在用户配置目录:macOS/Linux 为 `~/.config/producer/config.json`(`XDG_CONFIG_HOME` 优先),Windows 为 `%APPDATA%\producer\config.json`。Token 不进入 argv、日志或输出。本地开发可用 `npm run mcp:login` 保存登录态;脚本只把 MCP 地址和凭据文件路径写入 `.env`,access/refresh token 统一保存在 `credentials.json`。没有显式 Token 时,CLI 从匹配 resource 的登录态读取并在到期前一分钟续期;临时网络或 408/5xx 故障最多重试一次,明确失效或限流不重试,失败保留登录态。显式注入的 Token 不由 CLI 续期,Desktop 在启动命令前负责获取有效 Token。业务写入不自动重放。旧登录脚本生成的 `.env` Token 需重新登录以删除,避免覆盖更新后的凭据。
|
|
93
102
|
|
|
94
103
|
## 常用工作流
|
|
95
104
|
|
|
105
|
+
**部门采购汇总**:`producer purchase summary by-department --last this-month --all` 按采购单部门汇总,`0` 为未归属;指定部门需从返回行识别,不能传未声明的部门过滤参数,也不支持部门下钻。`data_updated_at` 是缓存数据时间,明确需要更新时传 `--force-refresh 1`。`summary` 为整次筛选范围的合计,不是某个部门或当前页合计;价格权限遮罩产生的金额 0 不代表真实零成本。
|
|
106
|
+
|
|
96
107
|
**采购单转成品入库**:先读取采购单事务预填,修改本次入库的数量/重量/备注后提交。关联采购单时,剩余普通费用与成品辅料费用会按服务端规则分摊到明细。
|
|
97
108
|
|
|
98
109
|
```bash
|
|
@@ -127,7 +138,7 @@ producer upgrade # 安装当前通道最新版本
|
|
|
127
138
|
producer upgrade --rollback # 切回上一个版本
|
|
128
139
|
```
|
|
129
140
|
|
|
130
|
-
|
|
141
|
+
测试环境从私有库 `https://npm.senguo.me/` 的 alpha 通道升级(匿名可读,仅发布需要凭据),生产环境从 npmjs 的 latest 通道升级;两套 registry 不互相回退。显式覆盖用 `PRODUCER_CLI_REGISTRY`,未设置环境时按安装 tarball 的 `publishConfig.registry` 或当前版本通道推断。桌面内置版本随森果云 AI 助手升级。遇到能力缺失、命令报错或 `CATALOG_REVISION_MISMATCH` 时,先执行 `producer upgrade`。
|
|
131
142
|
|
|
132
143
|
## 开发
|
|
133
144
|
|
package/dist/config.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export interface CliConfig {
|
|
|
7
7
|
shopFile?: string;
|
|
8
8
|
}
|
|
9
9
|
export declare function clientConfig(input?: CliConfig): ClientConfig;
|
|
10
|
+
export declare function commandConfig(input?: CliConfig): Promise<ClientConfig>;
|
|
10
11
|
export declare function defaultShopFile(env?: Record<string, string | undefined>, platform?: NodeJS.Platform): string;
|
|
11
12
|
export declare function readShopRef(file?: string): string | undefined;
|
|
12
13
|
export declare function writeShopRef(ref: string, file?: string): void;
|
package/dist/config.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { dirname, join, resolve, win32 } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
4
|
import { mcpUrlForEnvironment } from '@senguoyunnpm/producersdk';
|
|
6
5
|
import { CliError } from './errors.js';
|
|
6
|
+
import { defaultConfigDir } from './paths.js';
|
|
7
|
+
import { credentialsFile, freshStoredToken, storedAccessToken } from './v5-credentials.js';
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
8
9
|
function currentCliVersion() {
|
|
9
10
|
try {
|
|
@@ -15,9 +16,12 @@ function currentCliVersion() {
|
|
|
15
16
|
}
|
|
16
17
|
const MCP_ENVIRONMENTS = ['test', 'production'];
|
|
17
18
|
function resolveMcpUrl(env) {
|
|
19
|
+
// A host-provided endpoint (including Desktop's V5 endpoint) is authoritative.
|
|
20
|
+
if (env.SENGUO_AI_MCP_URL?.trim())
|
|
21
|
+
return env.SENGUO_AI_MCP_URL;
|
|
18
22
|
const selected = env.SENGUO_AI_MCP_ENV?.trim().toLowerCase();
|
|
19
23
|
if (!selected)
|
|
20
|
-
return
|
|
24
|
+
return undefined;
|
|
21
25
|
if (!MCP_ENVIRONMENTS.includes(selected)) {
|
|
22
26
|
throw new CliError('SENGUO_AI_MCP_ENV must be test or production', 'validation', 'mcp_config_invalid');
|
|
23
27
|
}
|
|
@@ -46,11 +50,14 @@ function parseEnvFile(path) {
|
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
52
|
export function clientConfig(input = {}) {
|
|
53
|
+
return resolveConfiguration(input).config;
|
|
54
|
+
}
|
|
55
|
+
function resolveConfiguration(input) {
|
|
49
56
|
const explicitEnv = input.env;
|
|
50
57
|
const envFile = input.envFile ?? resolve(process.cwd(), '.env');
|
|
51
58
|
const fileEnv = parseEnvFile(envFile);
|
|
52
59
|
const env = explicitEnv === undefined ? { ...fileEnv, ...process.env } : explicitEnv;
|
|
53
|
-
if (explicitEnv === undefined
|
|
60
|
+
if (explicitEnv === undefined) {
|
|
54
61
|
const source = (key) => {
|
|
55
62
|
if (Object.hasOwn(process.env, key))
|
|
56
63
|
return 'environment';
|
|
@@ -65,27 +72,38 @@ export function clientConfig(input = {}) {
|
|
|
65
72
|
throw new CliError('SENGUO_AI_MCP_URL 与 SENGUO_AI_MCP_TOKEN 必须来自同一来源(环境变量或 .env)', 'validation', 'mcp_config_invalid');
|
|
66
73
|
}
|
|
67
74
|
const url = resolveMcpUrl(env);
|
|
68
|
-
const token = env.SENGUO_AI_MCP_TOKEN;
|
|
69
75
|
if (!url)
|
|
70
76
|
throw new CliError('SENGUO_AI_MCP_URL is required for a business command', 'validation', 'mcp_credentials_missing');
|
|
77
|
+
// 本地登录态只在没有显式注入 env 时作为 token 回退;显式 env 视为宿主完整注入。
|
|
78
|
+
const local = explicitEnv === undefined && env.SENGUO_AI_MCP_TOKEN === undefined;
|
|
79
|
+
const token = env.SENGUO_AI_MCP_TOKEN ?? (local ? storedAccessToken(url, env) : undefined);
|
|
71
80
|
if (!token)
|
|
72
81
|
throw new CliError('SENGUO_AI_MCP_TOKEN is required for a business command', 'validation', 'mcp_credentials_missing');
|
|
73
82
|
return {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
config: {
|
|
84
|
+
url,
|
|
85
|
+
token,
|
|
86
|
+
shopRef: input.shopRef,
|
|
87
|
+
fetch: input.fetch,
|
|
88
|
+
clientName: 'producer-cli',
|
|
89
|
+
clientVersion: currentCliVersion(),
|
|
90
|
+
},
|
|
91
|
+
...(local ? { localFile: credentialsFile(env) } : {}),
|
|
80
92
|
};
|
|
81
93
|
}
|
|
94
|
+
// 业务命令统一入口:在同步配置之后续期本地 V5 登录态。
|
|
95
|
+
// 只有 `mcp:login` 写入的 access token 会被续期;宿主注入的 token 原样使用。
|
|
96
|
+
export async function commandConfig(input = {}) {
|
|
97
|
+
const { config, localFile } = resolveConfiguration(input);
|
|
98
|
+
if (!localFile || !config.url || !config.token)
|
|
99
|
+
return config;
|
|
100
|
+
const token = await freshStoredToken({ url: config.url, token: config.token }, { file: localFile, fetch: input.fetch });
|
|
101
|
+
return token && token !== config.token ? { ...config, token } : config;
|
|
102
|
+
}
|
|
82
103
|
// 当前店铺持久化:写入用户级配置(与 .env 的 URL/token 分离)。
|
|
83
|
-
// Windows 用 %APPDATA%,其他平台沿用 XDG;显式 XDG_CONFIG_HOME 在所有平台优先。
|
|
84
104
|
export function defaultShopFile(env = process.env, platform = process.platform) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
return win32.join(xdg ?? env.APPDATA ?? win32.join(homedir(), 'AppData', 'Roaming'), 'producer', 'config.json');
|
|
88
|
-
return join(xdg ?? join(homedir(), '.config'), 'producer', 'config.json');
|
|
105
|
+
const dir = defaultConfigDir(env, platform);
|
|
106
|
+
return platform === 'win32' ? win32.join(dir, 'config.json') : join(dir, 'config.json');
|
|
89
107
|
}
|
|
90
108
|
export function readShopRef(file = defaultShopFile()) {
|
|
91
109
|
try {
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
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oB,OAAO,CAAC,QAAQ;IAE5C,MAAM,GAAG,GAAG,gBAAgB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC5C,OAAO,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAI,GAAW,eAAe,EAAE;IAC1D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAA2B,CAAC;QAC9E,OAAO,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACxF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QACzE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,IAAI,GAAW,eAAe,EAAE;IACxE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACzE,CAAC"}
|
package/dist/main.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createRequire } from 'node:module';
|
|
|
6
6
|
import { basename, join } from 'node:path';
|
|
7
7
|
import { pathToFileURL } from 'node:url';
|
|
8
8
|
import { catalog, contractOf, createClient, getCommandExecutor, purchaseRefundHelp, refreshSalesOrderPackageMaterials, validateConstraints, validateInput, validatePurchaseRefundStock, } from '@senguoyunnpm/producersdk';
|
|
9
|
-
import {
|
|
9
|
+
import { commandConfig, readShopRef, writeShopRef } from './config.js';
|
|
10
10
|
import { actionSupportsDraft, inputSchemaForAction, schemaValueWithOptions, resolveSchema, } from './schema.js';
|
|
11
11
|
import { applyFields, applyJq, formatOutput, parseOutputFormat } from './output.js';
|
|
12
12
|
import { CliError, errorExitCode, errorPayload } from './errors.js';
|
|
@@ -18,7 +18,6 @@ import { checkForUpdate, cleanupInstall, detectForm, installRelease, rollbackRel
|
|
|
18
18
|
import { bootstrapInstall } from './update/launcher.js';
|
|
19
19
|
import { installRoot, resolveRegistry } from './update/layout.js';
|
|
20
20
|
import { isValidVersion, compareVersions, resolveChannel } from './update/version.js';
|
|
21
|
-
import { CATALOG_REVISION } from './generated/catalog-revision.js';
|
|
22
21
|
import { cliType, coerceFlagValue, compileCommandParameters, enumValues, exampleCommand, exampleJson, flagName, isBooleanEnum, lastWindow, typeHint, } from './parameters.js';
|
|
23
22
|
const CLI_PACKAGE_NAME = '@senguoyunnpm/producer-cli';
|
|
24
23
|
const require = createRequire(import.meta.url);
|
|
@@ -42,7 +41,7 @@ function globalRootOrUndefined() {
|
|
|
42
41
|
return undefined;
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
/** 已安装包自带的发布 registry
|
|
44
|
+
/** 已安装包自带的发布 registry;alpha 私有包与 npmjs 稳定包各自描述自己的来源。 */
|
|
46
45
|
function installedPackageRegistry() {
|
|
47
46
|
try {
|
|
48
47
|
const manifest = JSON.parse(readFileSync(join(cliPackageRoot(), 'package.json'), 'utf8'));
|
|
@@ -53,6 +52,7 @@ function installedPackageRegistry() {
|
|
|
53
52
|
return undefined;
|
|
54
53
|
}
|
|
55
54
|
}
|
|
55
|
+
/** 升级与安装来源由运行环境与安装来源决定;通道仍由环境或当前版本推断。 */
|
|
56
56
|
function latestCliVersion(tag, registry) {
|
|
57
57
|
try {
|
|
58
58
|
const spawn = npmSpawn(npmExecutable(), [
|
|
@@ -356,24 +356,6 @@ function readParams(value, readStdin = () => readFileSync(0, 'utf8')) {
|
|
|
356
356
|
throw new CliError('--params 需为合法 JSON 对象', 'validation', 'invalid_parameter_json');
|
|
357
357
|
return parsed;
|
|
358
358
|
}
|
|
359
|
-
// 叶子执行前的可用性预检。区分两种失败:
|
|
360
|
-
// - 服务端明确返回 available=false:能力不可用,拒绝执行。
|
|
361
|
-
// - 预检调用本身失败:读取可以继续(避免假阴性);idempotency=unknown 的写入必须 fail-closed,
|
|
362
|
-
// 因为无法确认重复提交的后果。
|
|
363
|
-
async function assertCapabilityAvailable(client, operationId, shopRef, signal, contract) {
|
|
364
|
-
let result;
|
|
365
|
-
try {
|
|
366
|
-
result = await client.check(operationId, { shopRef, ...(signal ? { signal } : {}) });
|
|
367
|
-
}
|
|
368
|
-
catch {
|
|
369
|
-
if (contract?.effect === 'write' && contract.idempotency === 'unknown')
|
|
370
|
-
throw new CliError('能力预检不可用,已停止写入', 'api', 'preflight_unavailable', '无法确认预检结果,也无法确认写入是否幂等;请稍后重试预检或先回读确认,不要直接重放写入。');
|
|
371
|
-
return;
|
|
372
|
-
}
|
|
373
|
-
if (result && result.available === false) {
|
|
374
|
-
throw new Error(result.reason ?? '当前账户无权限执行该操作');
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
359
|
function assertNotTruncated(result) {
|
|
378
360
|
if (result !== null &&
|
|
379
361
|
typeof result === 'object' &&
|
|
@@ -636,7 +618,7 @@ export function buildProgram(ctx) {
|
|
|
636
618
|
throw new Error(`workflow 缺少 planner: ${commandPath}`);
|
|
637
619
|
const executor = workflowExecutor(planner);
|
|
638
620
|
const shopRef = resolveShopRef();
|
|
639
|
-
const sdk = createClient(
|
|
621
|
+
const sdk = createClient(await commandConfig({ ...ctx, shopRef }));
|
|
640
622
|
const signal = timeoutSignal();
|
|
641
623
|
renderOutput(await executor(sdk, params, {
|
|
642
624
|
...(signal ? { signal } : {}),
|
|
@@ -706,9 +688,8 @@ export function buildProgram(ctx) {
|
|
|
706
688
|
throw CliError.confirmationRequired(commandPath);
|
|
707
689
|
if (intent && submitAsIntent) {
|
|
708
690
|
const intentShopRef = resolveShopRef();
|
|
709
|
-
const sdk = createClient(
|
|
691
|
+
const sdk = createClient(await commandConfig({ ...ctx, shopRef: intentShopRef }));
|
|
710
692
|
const signal = timeoutSignal();
|
|
711
|
-
await assertCapabilityAvailable(sdk, intent.target_operation_id, requireShopRef(intentShopRef), signal, baseline);
|
|
712
693
|
renderOutput(await sdk.planner.run(intent.planner, params, {
|
|
713
694
|
...(signal ? { signal } : {}),
|
|
714
695
|
...(intentShopRef !== undefined ? { shopRef: intentShopRef } : {}),
|
|
@@ -716,13 +697,15 @@ export function buildProgram(ctx) {
|
|
|
716
697
|
return;
|
|
717
698
|
}
|
|
718
699
|
const shopRef = resolveShopRef();
|
|
719
|
-
const sdk = createClient(
|
|
700
|
+
const sdk = createClient(await commandConfig({ ...ctx, shopRef }));
|
|
720
701
|
const operationId = intent?.target_operation_id ?? action.contract.operation_id;
|
|
721
702
|
const executor = getCommandExecutor(sdk.commands, operationId);
|
|
722
703
|
if (!executor)
|
|
723
704
|
throw new Error(`no command executor for operation ${operationId}`);
|
|
724
705
|
const signal = timeoutSignal();
|
|
725
|
-
|
|
706
|
+
// Producer V5's compatibility capability check is read-only. Do not
|
|
707
|
+
// use it to block a mutation; producer_write_execute validates the
|
|
708
|
+
// write grant at the authoritative execution boundary.
|
|
726
709
|
// SDK 拥有销售单辅料重算(含详情重读)与采退库存规则;CLI 只按 planner/operation 触发。
|
|
727
710
|
if (intent?.planner === 'sales.order.update')
|
|
728
711
|
await refreshSalesOrderPackageMaterials(sdk.commands, params, {
|
|
@@ -796,7 +779,7 @@ export function buildProgram(ctx) {
|
|
|
796
779
|
params[endName] = window.to_date;
|
|
797
780
|
}
|
|
798
781
|
const shopRef = resolveShopRef();
|
|
799
|
-
const sdk = createClient(
|
|
782
|
+
const sdk = createClient(await commandConfig({ ...ctx, shopRef }));
|
|
800
783
|
const missing = required.filter((key) => !(key in params));
|
|
801
784
|
if (missing.length)
|
|
802
785
|
throw new CliError(`缺少必填参数: ${missing.map(flagName).join(', ')}。执行 \`${commandPath} --help\` 查看完整参数。`, 'validation', 'missing_required_parameter');
|
|
@@ -857,7 +840,6 @@ export function buildProgram(ctx) {
|
|
|
857
840
|
package: CLI_PACKAGE_NAME,
|
|
858
841
|
version,
|
|
859
842
|
channel: resolveChannel(version, ctx.env ?? process.env),
|
|
860
|
-
catalog_revision: CATALOG_REVISION,
|
|
861
843
|
});
|
|
862
844
|
});
|
|
863
845
|
program
|
|
@@ -931,7 +913,11 @@ export function buildProgram(ctx) {
|
|
|
931
913
|
if (form === 'embedded' && !options.check)
|
|
932
914
|
throw managed();
|
|
933
915
|
// 未显式选择环境时回退到安装 tarball 的 publishConfig.registry(npm 与 launcher 一致)。
|
|
934
|
-
const registry = resolveRegistry(
|
|
916
|
+
const registry = resolveRegistry({
|
|
917
|
+
env,
|
|
918
|
+
fallback: installedPackageRegistry(),
|
|
919
|
+
version: effectiveCurrent,
|
|
920
|
+
});
|
|
935
921
|
if (form === 'npm' || form === 'source') {
|
|
936
922
|
const latest = latestCliVersion(tag, registry);
|
|
937
923
|
if (options.check || latest === current) {
|
|
@@ -941,7 +927,6 @@ export function buildProgram(ctx) {
|
|
|
941
927
|
latest,
|
|
942
928
|
channel: tag,
|
|
943
929
|
updated: false,
|
|
944
|
-
catalog_revision: CATALOG_REVISION,
|
|
945
930
|
});
|
|
946
931
|
return;
|
|
947
932
|
}
|
|
@@ -955,7 +940,6 @@ export function buildProgram(ctx) {
|
|
|
955
940
|
latest,
|
|
956
941
|
channel: tag,
|
|
957
942
|
updated: false,
|
|
958
|
-
catalog_revision: CATALOG_REVISION,
|
|
959
943
|
});
|
|
960
944
|
return;
|
|
961
945
|
}
|
|
@@ -984,7 +968,6 @@ export function buildProgram(ctx) {
|
|
|
984
968
|
latest,
|
|
985
969
|
channel: tag,
|
|
986
970
|
updated: false,
|
|
987
|
-
catalog_revision: CATALOG_REVISION,
|
|
988
971
|
});
|
|
989
972
|
return;
|
|
990
973
|
}
|
|
@@ -1032,7 +1015,7 @@ export function buildProgram(ctx) {
|
|
|
1032
1015
|
.description('列出已授权店铺')
|
|
1033
1016
|
.action(async () => {
|
|
1034
1017
|
// producer_shops_list 只依赖凭据,不依赖当前店铺:首次使用(尚无 shop_ref)也必须可用。
|
|
1035
|
-
const sdk = createClient(
|
|
1018
|
+
const sdk = createClient(await commandConfig({ ...ctx }));
|
|
1036
1019
|
const signal = timeoutSignal();
|
|
1037
1020
|
renderOutput(await sdk.shop.list(signal ? { signal } : undefined));
|
|
1038
1021
|
});
|
|
@@ -1040,7 +1023,7 @@ export function buildProgram(ctx) {
|
|
|
1040
1023
|
.command('current')
|
|
1041
1024
|
.description('查询当前店铺')
|
|
1042
1025
|
.action(async () => {
|
|
1043
|
-
const sdk = createClient(
|
|
1026
|
+
const sdk = createClient(await commandConfig({ ...ctx }));
|
|
1044
1027
|
const signal = timeoutSignal();
|
|
1045
1028
|
const shops = (await sdk.shop.list(signal ? { signal } : undefined)).shops;
|
|
1046
1029
|
const ref = readShopRef(ctx.shopFile);
|
|
@@ -1052,7 +1035,7 @@ export function buildProgram(ctx) {
|
|
|
1052
1035
|
.description('设置当前店铺(持久化)')
|
|
1053
1036
|
.argument('<ref>', '店铺引用')
|
|
1054
1037
|
.action(async (ref) => {
|
|
1055
|
-
const sdk = createClient(
|
|
1038
|
+
const sdk = createClient(await commandConfig({ ...ctx }));
|
|
1056
1039
|
const signal = timeoutSignal();
|
|
1057
1040
|
const shops = (await sdk.shop.list(signal ? { signal } : undefined)).shops;
|
|
1058
1041
|
const shop = shops.find((item) => item.shop_ref === ref);
|
|
@@ -1065,7 +1048,7 @@ export function buildProgram(ctx) {
|
|
|
1065
1048
|
.command('status')
|
|
1066
1049
|
.description('查询当前用户、环境、店铺和业务上下文')
|
|
1067
1050
|
.action(async () => {
|
|
1068
|
-
const config =
|
|
1051
|
+
const config = await commandConfig({ ...ctx });
|
|
1069
1052
|
const sdk = createClient(config);
|
|
1070
1053
|
const signal = timeoutSignal();
|
|
1071
1054
|
const ref = readShopRef(ctx.shopFile);
|
|
@@ -1080,7 +1063,7 @@ export function buildProgram(ctx) {
|
|
|
1080
1063
|
...context,
|
|
1081
1064
|
});
|
|
1082
1065
|
});
|
|
1083
|
-
const check = program.command('check').description('
|
|
1066
|
+
const check = program.command('check').description('查询权限与开关预检(不代表写权限)');
|
|
1084
1067
|
check
|
|
1085
1068
|
.argument('<capability>', '能力包')
|
|
1086
1069
|
.argument('<resource>', '资源')
|
|
@@ -1090,7 +1073,7 @@ export function buildProgram(ctx) {
|
|
|
1090
1073
|
if (!('contract' in resolved))
|
|
1091
1074
|
throw new Error('未找到该叶子动作,请检查路径');
|
|
1092
1075
|
const operationId = resolved.contract.operation_id;
|
|
1093
|
-
const sdk = createClient(
|
|
1076
|
+
const sdk = createClient(await commandConfig({ ...ctx, shopRef: requireShopRef() }));
|
|
1094
1077
|
const signal = timeoutSignal();
|
|
1095
1078
|
renderOutput(await sdk.check(operationId, signal ? { signal } : undefined));
|
|
1096
1079
|
});
|
|
@@ -1102,7 +1085,7 @@ export function buildProgram(ctx) {
|
|
|
1102
1085
|
.description('查询服务端当前字段、绑定与 contract revision;不会执行写入')
|
|
1103
1086
|
.argument('<operation-id>', 'Operation ID,例如 producer.sales.order.create')
|
|
1104
1087
|
.action(async (operationId) => {
|
|
1105
|
-
const sdk = createClient(
|
|
1088
|
+
const sdk = createClient(await commandConfig({ ...ctx }));
|
|
1106
1089
|
const signal = timeoutSignal();
|
|
1107
1090
|
const result = await sdk.describeContract(operationId, signal ? { signal } : undefined);
|
|
1108
1091
|
renderOutput({
|
|
@@ -1125,7 +1108,7 @@ export function buildProgram(ctx) {
|
|
|
1125
1108
|
.option('--upload-host <url>', '上传域名;默认使用服务端返回的 upload_url')
|
|
1126
1109
|
.action(async (options) => {
|
|
1127
1110
|
const shopRef = requireShopRef();
|
|
1128
|
-
const sdk = createClient(
|
|
1111
|
+
const sdk = createClient(await commandConfig({ ...ctx, shopRef }));
|
|
1129
1112
|
const host = options.uploadHost ?? process.env.QINIU_UPLOAD_HOST;
|
|
1130
1113
|
const asset = await uploadAsset({
|
|
1131
1114
|
filePath: options.file,
|