@hcmai/cli 0.19.0 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +58 -20
- package/dist/index.js.map +1 -1
- package/dist/skills/manifest.json +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9201,7 +9201,7 @@ async function resolveAdminPassword(args) {
|
|
|
9201
9201
|
return { pwd: await promptSecret("Admin password: "), stdinTaken: false };
|
|
9202
9202
|
}
|
|
9203
9203
|
async function resolveEndpoint2(args) {
|
|
9204
|
-
if (args.endpoint) return args.endpoint;
|
|
9204
|
+
if (args.endpoint) return { endpoint: args.endpoint };
|
|
9205
9205
|
const g = await loadGlobalConfig7();
|
|
9206
9206
|
const resolved = await resolveEnvContext6({ envFlag: args.env }, process.env, g);
|
|
9207
9207
|
printResolvedEnvironment5(resolved);
|
|
@@ -9212,27 +9212,55 @@ async function resolveEndpoint2(args) {
|
|
|
9212
9212
|
message: "\u672A\u89E3\u6790\u5230 endpoint \u2014\u2014 \u4F20 --endpoint <url>\uFF0C\u6216\u5148 `hcm env add <name> --endpoint <url>`"
|
|
9213
9213
|
});
|
|
9214
9214
|
}
|
|
9215
|
-
return env2.endpoint;
|
|
9215
|
+
return { endpoint: env2.endpoint, frontend: env2.frontend };
|
|
9216
|
+
}
|
|
9217
|
+
function bootstrapDisplayUrl(address, label) {
|
|
9218
|
+
try {
|
|
9219
|
+
const url = new URL(address);
|
|
9220
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") throw new TypeError("unsupported protocol");
|
|
9221
|
+
url.username = "";
|
|
9222
|
+
url.password = "";
|
|
9223
|
+
url.search = "";
|
|
9224
|
+
url.hash = "";
|
|
9225
|
+
return url;
|
|
9226
|
+
} catch {
|
|
9227
|
+
throw new CliError22({
|
|
9228
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
9229
|
+
message: `${label}\u5FC5\u987B\u662F\u5E26 http:// \u6216 https:// \u7684\u5B8C\u6574\u5730\u5740\uFF1B\u8BF7\u5148\u4FEE\u6B63\u914D\u7F6E\uFF0C\u518D\u5F00\u901A\u79DF\u6237\u3002`
|
|
9230
|
+
});
|
|
9231
|
+
}
|
|
9216
9232
|
}
|
|
9217
9233
|
async function tenantBootstrapCommand(args) {
|
|
9218
9234
|
try {
|
|
9219
|
-
if (!args.tenantId
|
|
9235
|
+
if (!args.tenantId) {
|
|
9220
9236
|
throw new CliError22({
|
|
9221
9237
|
code: CliErrorCode23.MISSING_FLAG,
|
|
9222
|
-
message: "--tenant-id \
|
|
9238
|
+
message: "--tenant-id \u5FC5\u586B"
|
|
9239
|
+
});
|
|
9240
|
+
}
|
|
9241
|
+
const adminUsername = args.adminUsername ?? "admin";
|
|
9242
|
+
if (adminUsername !== "admin") {
|
|
9243
|
+
throw new CliError22({
|
|
9244
|
+
code: CliErrorCode23.INVALID_ARGUMENT,
|
|
9245
|
+
message: "\u670D\u52A1\u7AEF\u4EC5\u63A5\u53D7\u7BA1\u7406\u5458\u7528\u6237\u540D admin\uFF1B\u8BF7\u7701\u7565 --admin-username \u6216\u6307\u5B9A admin"
|
|
9223
9246
|
});
|
|
9224
9247
|
}
|
|
9225
|
-
const endpoint = await resolveEndpoint2(args);
|
|
9248
|
+
const { endpoint, frontend: configuredFrontend } = await resolveEndpoint2(args);
|
|
9226
9249
|
const project2 = await discoverProjectEnv4();
|
|
9250
|
+
const matchingFrontends = [...new Set(Object.values(project2?.config.environments ?? {}).filter((candidate) => candidate.endpoint === normalizeOrigin4(endpoint)).map((candidate) => candidate.frontend))];
|
|
9251
|
+
const frontend = configuredFrontend ?? (matchingFrontends.length === 1 ? matchingFrontends[0] : void 0);
|
|
9227
9252
|
const protectedNames = project2 ? Object.entries(project2.config.environments).filter(([, candidate]) => candidate.danger && candidate.endpoint === normalizeOrigin4(endpoint)).map(([name]) => name) : [];
|
|
9228
9253
|
assertDangerWrite4({ name: protectedNames.join(", "), danger: protectedNames.length > 0, allowDanger: args.allowDanger }, "\u5F00\u901A\u79DF\u6237");
|
|
9229
|
-
|
|
9254
|
+
const endpointDisplay = bootstrapDisplayUrl(endpoint, "\u670D\u52A1\u5730\u5740\uFF08endpoint\uFF09");
|
|
9255
|
+
const loginUrl = bootstrapDisplayUrl(frontend ?? endpoint, frontend ? "\u524D\u7AEF\u5730\u5740\uFF08frontend\uFF09" : "\u670D\u52A1\u5730\u5740\uFF08endpoint\uFF09");
|
|
9256
|
+
loginUrl.pathname = `${loginUrl.pathname.replace(/\/+$/, "")}/login`;
|
|
9257
|
+
if (args.endpoint) process.stderr.write(`\u2192 ${endpointDisplay} \xB7 \u79DF\u6237 ${args.tenantId} \xB7 \u8EAB\u4EFD bootstrap key\uFF08\u6765\u81EA --endpoint\uFF09
|
|
9230
9258
|
`);
|
|
9231
9259
|
const { pwd, stdinTaken } = await resolveAdminPassword(args);
|
|
9232
9260
|
const key2 = await resolveBootstrapKey(args, stdinTaken);
|
|
9233
9261
|
if (!args.yes) {
|
|
9234
9262
|
const ok = await promptConfirm(
|
|
9235
|
-
`\u5C06\u5728 ${
|
|
9263
|
+
`\u5C06\u5728 ${endpointDisplay} \u521B\u5EFA\u79DF\u6237 "${args.tenantId}"\uFF08admin: ${adminUsername}\uFF09\u3002\u6B64\u64CD\u4F5C\u4E0D\u53EF\u9006\uFF0C\u7EE7\u7EED\uFF1F`
|
|
9236
9264
|
);
|
|
9237
9265
|
if (!ok) {
|
|
9238
9266
|
process.stderr.write("\u5DF2\u53D6\u6D88\n");
|
|
@@ -9247,19 +9275,19 @@ async function tenantBootstrapCommand(args) {
|
|
|
9247
9275
|
});
|
|
9248
9276
|
const result = await bootstrapTenant(http, key2, {
|
|
9249
9277
|
tenantId: args.tenantId,
|
|
9250
|
-
adminUsername
|
|
9278
|
+
adminUsername,
|
|
9251
9279
|
adminPassword: pwd,
|
|
9252
9280
|
tenantName: args.tenantName
|
|
9253
9281
|
});
|
|
9254
9282
|
const fmt = args.output ?? "json";
|
|
9255
|
-
if (fmt !== "json") {
|
|
9256
|
-
process.stdout.write(
|
|
9257
|
-
`\u2705 \u79DF\u6237 ${result.tenantId} \u5DF2\u5F00\u901A\uFF08adminUserId ${result.adminUserId ?? "-"}\uFF09
|
|
9258
|
-
\u4E0B\u4E00\u6B65\uFF1Ahcm env add <name> --endpoint ${endpoint} && hcm login --env <name>
|
|
9259
|
-
`
|
|
9260
|
-
);
|
|
9261
|
-
}
|
|
9262
9283
|
process.stdout.write(formatObject20(result, { format: fmt }) + "\n");
|
|
9284
|
+
const addressSource = frontend ? "\u767B\u5F55\u5730\u5740" : "\u767B\u5F55\u5730\u5740\uFF08\u672A\u914D\u7F6E\u524D\u7AEF\u5730\u5740\uFF0C\u6309 API \u540C\u6E90\u63A8\u6D4B\uFF0C\u8BF7\u786E\u8BA4\uFF09";
|
|
9285
|
+
loginUrl.searchParams.set("tenantId", result.tenantId);
|
|
9286
|
+
process.stderr.write(
|
|
9287
|
+
`\u4E0B\u4E00\u6B65\uFF1A\u6253\u5F00${addressSource} ${loginUrl.toString()}\uFF0C\u4F7F\u7528 admin \u548C\u521D\u59CB\u5BC6\u7801\u767B\u5F55\u3002
|
|
9288
|
+
\u9996\u6B21\u767B\u5F55\u9700\u8981\u4FEE\u6539\u5BC6\u7801\uFF1B\u767B\u5F55\u540E\u524D\u5F80\u300C\u7CFB\u7EDF\u8BBE\u7F6E \u2192 \u96C6\u6210\u4E2D\u5FC3 \u2192 \u534F\u540C\u5E73\u53F0\u300D\u5F00\u901A\u4F01\u4E1A\u5FAE\u4FE1\u3002
|
|
9289
|
+
`
|
|
9290
|
+
);
|
|
9263
9291
|
process.exitCode = 0;
|
|
9264
9292
|
return;
|
|
9265
9293
|
} catch (e) {
|
|
@@ -16650,11 +16678,12 @@ var GUARDED_EXECUTOR_REASON_CODES = /* @__PURE__ */ new Set([
|
|
|
16650
16678
|
"setting-write",
|
|
16651
16679
|
"credential-reset",
|
|
16652
16680
|
"action-write",
|
|
16653
|
-
//
|
|
16681
|
+
// ACCOUNTING_ONLY、UNKNOWN、未识别值都走与 WRITES 同级的受控执行,原因各自留痕。
|
|
16654
16682
|
// 完全相同的 prepare + execute 通道。分类函数已经返回 R2 guarded;这里漏登记
|
|
16655
16683
|
// 会把 guardedExecutionAvailable 又翻回 false,造成 reason 与 modePolicy 自相矛盾。
|
|
16656
16684
|
"action-effect-undetermined",
|
|
16657
16685
|
"action-effect-unrecognized",
|
|
16686
|
+
"action-effect-accounting-only",
|
|
16658
16687
|
"workspace-create",
|
|
16659
16688
|
"workspace-activate",
|
|
16660
16689
|
"workspace-deactivate",
|
|
@@ -17098,7 +17127,7 @@ function guarded(effect, reasonCode) {
|
|
|
17098
17127
|
};
|
|
17099
17128
|
}
|
|
17100
17129
|
function classifyAction(policy) {
|
|
17101
|
-
if (policy.readOnly) {
|
|
17130
|
+
if (policy.readOnly && (policy.effect === void 0 || policy.effect === "read-only")) {
|
|
17102
17131
|
return {
|
|
17103
17132
|
risk: "R1",
|
|
17104
17133
|
execution: "direct",
|
|
@@ -17116,13 +17145,22 @@ function classifyAction(policy) {
|
|
|
17116
17145
|
reason: "\u4EA7\u54C1\u4FA7\u628A\u8FD9\u4E2A Action \u58F0\u660E\u6210 effect=UNKNOWN\uFF1A**\u6CA1\u4EBA\u5224\u8FC7**\u5B83\u5199\u4E0D\u5199\u5E93\u3002\u6309\u6700\u574F\u60C5\u51B5\u8D70\u53D7\u63A7\u6267\u884C\uFF08\u4E0E\u4F1A\u5199\u7684 Action \u540C\u4E00\u6761\u8DEF\u5F84\uFF09\uFF0C\u4F46\u5B83\u4E0D\u7B49\u4E8E\u300C\u786E\u8BA4\u4F1A\u5199\u300D\u3002next_step=\u53BB\u4EA7\u54C1\u4FA7\u7ED9\u8FD9\u4E2A @ClassAction/@ObjectAction \u628A effect \u5224\u6389\uFF08READ_ONLY / WRITES\uFF09\uFF0C\u800C\u4E0D\u662F\u5728 CLI \u8FD9\u8FB9\u653E\u5BBD\u3002"
|
|
17117
17146
|
};
|
|
17118
17147
|
}
|
|
17148
|
+
if (policy.effect === "accounting-only") {
|
|
17149
|
+
return {
|
|
17150
|
+
risk: "R2",
|
|
17151
|
+
execution: "guarded",
|
|
17152
|
+
effect: "accounting-only",
|
|
17153
|
+
reasonCode: "action-effect-accounting-only",
|
|
17154
|
+
reason: "Core \u5DF2\u5224\u5B9A\u8BE5 Action \u4E0D\u5199\u4E1A\u52A1\u6570\u636E\uFF0C\u4F46\u4F1A\u4EA7\u751F\u767B\u8BB0\u5728\u518C\u7684\u8BB0\u8D26\u7C7B\u526F\u4F5C\u7528\uFF08\u5982\u8C03\u7528\u5916\u90E8\u6A21\u578B\u8BA1\u5165\u79DF\u6237\u9884\u7B97\u3001\u5199\u4E00\u6761\u5BA1\u8BA1\uFF09\uFF1B\u672C\u901A\u9053\u53EA\u8DD1\u53EA\u8BFB\uFF0C\u6240\u4EE5\u6CA1\u6709\u6267\u884C\uFF0C\u4E5F\u4E0D\u80FD\u6309\u53EA\u8BFB\u76F4\u6267\u884C\u3002next_step=\u786E\u9700\u6267\u884C\u65F6\uFF0C\u8BF4\u660E\u8BB0\u8D26\u5F71\u54CD\u5E76\u53D6\u5F97\u672C\u6B21\u663E\u5F0F\u786E\u8BA4\u540E\uFF0C\u76F4\u63A5\u7528 hcm action <Model.Action> \u8C03\u7528\uFF08danger \u73AF\u5883\u53E6\u52A0 --allow-danger\uFF09\u3002"
|
|
17155
|
+
};
|
|
17156
|
+
}
|
|
17119
17157
|
if (policy.effect === "unrecognized-effect") {
|
|
17120
17158
|
return {
|
|
17121
17159
|
risk: "R2",
|
|
17122
17160
|
execution: "guarded",
|
|
17123
17161
|
effect: "undetermined",
|
|
17124
17162
|
reasonCode: "action-effect-unrecognized",
|
|
17125
|
-
reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / UNKNOWN \
|
|
17163
|
+
reason: `Core \u9001\u6765\u7684 effect \u53D6\u503C ${describeEffectRaw(policy.effectRaw)} \u4E0D\u5728 READ_ONLY / WRITES / ACCOUNTING_ONLY / UNKNOWN \u56DB\u6863\u5185\uFF08\u62FC\u5199\u6F02\u79FB\uFF1F\u670D\u52A1\u7AEF\u6BD4\u672C CLI \u65B0\u3001\u591A\u4E86\u4E00\u6863\uFF1F\uFF09\u3002fail-closed\uFF1A\u6309 UNKNOWN \u5904\u7F6E\u8D70\u53D7\u63A7\u6267\u884C\uFF0C\u4E0D\u731C\u6210\u53EA\u8BFB\u3002next_step=\u62FF\u8FD9\u4E2A\u539F\u503C\u53BB\u5BF9\u4EA7\u54C1\u4FA7\u7684 ActionEffect \u5B9A\u4E49\uFF0C\u5FC5\u8981\u65F6\u5347\u7EA7 CLI\u3002`
|
|
17126
17164
|
};
|
|
17127
17165
|
}
|
|
17128
17166
|
return guarded("tenant-write", "action-write");
|
|
@@ -17248,7 +17286,7 @@ function policyFromActionMeta(action, request) {
|
|
|
17248
17286
|
if (typeof action.readOnly !== "boolean") {
|
|
17249
17287
|
return failed(
|
|
17250
17288
|
"action-readonly-unclassified",
|
|
17251
|
-
"Core \u672A\u8FD4\u56DE Action \u7684 effect \
|
|
17289
|
+
"Core \u672A\u8FD4\u56DE Action \u7684 effect \u58F0\u660E\uFF0C\u4E5F\u6CA1\u6709\u56DE\u843D\u7528\u7684 readOnly \u5E03\u5C14\uFF0C\u6309\u5B89\u5168\u9ED8\u8BA4\u62D2\u7EDD\u6267\u884C\u3002"
|
|
17252
17290
|
);
|
|
17253
17291
|
}
|
|
17254
17292
|
return { status: "resolved", policy: { ...shape, readOnly: action.readOnly } };
|
|
@@ -18890,7 +18928,7 @@ datapackage.command("install <artifact>").description("\u4E0A\u4F20 .hcmpkg \u52
|
|
|
18890
18928
|
datapackage.command("status <runId>").description("\u67E5\u770B\u88C5\u8F7D\u6D41\u6C34\u8FDB\u5EA6/\u7EC8\u6001\uFF08\u914D\u5408 install --no-wait \u6216\u7B49\u5F85\u8D85\u65F6\u540E\u4F7F\u7528\uFF09").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4E34\u65F6\u6362\u8EAB\u4EFD").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((runId, opts) => datapackageStatusCommand(runId, opts));
|
|
18891
18929
|
var tenant = program.command("tenant").description("\u79DF\u6237\u5F00\u901A\u4E0E\u751F\u547D\u5468\u671F");
|
|
18892
18930
|
tenant.command("reset").description("\u4EE5\u5F53\u524D\u79DF\u6237\u5185\u7F6E admin \u91CD\u7F6E PostgreSQL \u5230\u51FA\u5382\u57FA\u7EBF\uFF1B\u4E0D\u53EF\u9006\uFF0C\u975E PG \u672A\u5904\u7406\u672A\u6838\u9A8C").option("--env <name>", "\u672C\u6B21\u4F7F\u7528\u7684\u9879\u76EE\u73AF\u5883\u540D\u6216\u672C\u673A\u69FD\u540D").option("--as <identity>", "\u4F7F\u7528\u8BE5\u73AF\u5883\u7684\u76F4\u63A5\u767B\u5F55\u8EAB\u4EFD\uFF0C\u4E0D\u63A5\u53D7\u4EE3\u7406").option("-y, --yes", "\u786E\u8BA4\u91CD\u7F6E\u5DF2\u6838\u9A8C\u7684\u5F53\u524D\u79DF\u6237\uFF0C\u8DF3\u8FC7\u4EA4\u4E92").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => tenantResetCommand(opts));
|
|
18893
|
-
tenant.command("bootstrap").description("\u5F00\u901A\u65B0\u79DF\u6237\uFF08\u5EFA\u79DF\u6237 + admin \u7528\u6237 + \u7ED3\u6784 reconcile\uFF09\u2014\u2014\u4E0D\u53EF\u9006\uFF0C\u9ED8\u8BA4\u8FC7\u786E\u8BA4\u95F8").requiredOption("--tenant-id <id>", "\u79DF\u6237 ID").
|
|
18931
|
+
tenant.command("bootstrap").description("\u5F00\u901A\u65B0\u79DF\u6237\uFF08\u5EFA\u79DF\u6237 + admin \u7528\u6237 + \u7ED3\u6784 reconcile\uFF09\u2014\u2014\u4E0D\u53EF\u9006\uFF0C\u9ED8\u8BA4\u8FC7\u786E\u8BA4\u95F8").requiredOption("--tenant-id <id>", "\u79DF\u6237 ID").option("--admin-username <user>", "\u7BA1\u7406\u5458\u7528\u6237\u540D\uFF08\u670D\u52A1\u7AEF\u4EC5\u63A5\u53D7 admin\uFF09", "admin").option(
|
|
18894
18932
|
"--admin-password <pwd>",
|
|
18895
18933
|
"\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u4F1A\u6CC4\u6F0F\u5230 history/ps\uFF0C\u5EFA\u8BAE --admin-password-stdin\uFF09"
|
|
18896
18934
|
).option("--admin-password-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB\u7BA1\u7406\u5458\u5BC6\u7801\uFF08\u63A8\u8350\uFF09").option("--tenant-name <name>", "\u79DF\u6237\u540D\u79F0\uFF08\u9ED8\u8BA4\u53D6 tenantId\uFF09").option("--bootstrap-key <key>", "bootstrap \u5BC6\u94A5\uFF08\u5EFA\u8BAE\u7528 HCM_BOOTSTRAP_KEY \u73AF\u5883\u53D8\u91CF\uFF09").option("--bootstrap-key-stdin", "\u4ECE\u6807\u51C6\u8F93\u5165\u8BFB bootstrap \u5BC6\u94A5").option("--endpoint <url>", "\u540E\u7AEF\u5730\u5740\uFF08\u9ED8\u8BA4\u53D6\u9879\u76EE\u73AF\u5883\u6216 activeEnv \u7684 endpoint\uFF09").option("--env <name>", "\u4ECE\u8BE5 env \u89E3\u6790 endpoint").option("-y, --yes", "\u8DF3\u8FC7\u786E\u8BA4\uFF08CI \u7528\uFF09").option("--output <fmt>", "\u8F93\u51FA\u683C\u5F0F\uFF1Atable | json | yaml", "json").action((opts) => tenantBootstrapCommand(opts));
|