connect-api-cli 1.1.4 → 1.1.8
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 +19 -23
- package/dist/cli.js +380 -172
- package/dist/index.d.mts +13 -7
- package/dist/index.d.ts +13 -7
- package/dist/index.js +191 -15
- package/dist/index.mjs +191 -15
- package/package.json +6 -3
package/dist/cli.js
CHANGED
|
@@ -40,8 +40,8 @@ function printResult(result) {
|
|
|
40
40
|
|
|
41
41
|
// src/cli/index.ts
|
|
42
42
|
var import_commander = require("commander");
|
|
43
|
-
var
|
|
44
|
-
var
|
|
43
|
+
var fs9 = __toESM(require("fs"));
|
|
44
|
+
var import_path7 = __toESM(require("path"));
|
|
45
45
|
|
|
46
46
|
// src/core/private-file.ts
|
|
47
47
|
var import_fs = __toESM(require("fs"));
|
|
@@ -550,6 +550,181 @@ function openBrowser(url) {
|
|
|
550
550
|
|
|
551
551
|
// src/core/http.ts
|
|
552
552
|
var import_axios3 = __toESM(require("axios"));
|
|
553
|
+
|
|
554
|
+
// src/core/request-source.ts
|
|
555
|
+
var import_fs5 = __toESM(require("fs"));
|
|
556
|
+
var import_path4 = __toESM(require("path"));
|
|
557
|
+
var REQUEST_SOURCE_HEADER = "Request-Source";
|
|
558
|
+
var SOURCE_TOOL_NAME_HEADER = "Source-Tool-Name";
|
|
559
|
+
var SKILL_CHANNEL = "skill";
|
|
560
|
+
var CLI_CHANNEL = "cli";
|
|
561
|
+
var SKILL_TOOL_NAME = "hmos-connect-api-skill";
|
|
562
|
+
var CLI_TOOL_NAME = "connect-api-cli";
|
|
563
|
+
var TOOL_SPECIFIC_AGENTS = [
|
|
564
|
+
{
|
|
565
|
+
name: "codebuddy",
|
|
566
|
+
match: (env) => nonempty(env.CODEBUDDY) || nonempty(env.CODEBUDDY_SESSION_ID) || nonempty(env.CODEBUDDY_PROJECT_DIR)
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
name: "cursor",
|
|
570
|
+
match: (env) => nonempty(env.CURSOR_AGENT) || env.CURSOR_EXTENSION_HOST_ROLE === "agent-exec" || nonempty(env.CURSOR_SANDBOX)
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
// ZCode(智谱):桌面/CLI Agent 会注入 ZCODE_*(如 ZCODE_APP_VERSION、ZCODE_ENV);
|
|
574
|
+
// 通常不设 AI_AGENT,需靠 Tool-specific 指纹识别。
|
|
575
|
+
name: "zcode",
|
|
576
|
+
match: (env) => looksLikeZcode(env)
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
// TRAE:官方 Hook/Agent 文档常见 TRAE_PROJECT_DIR / TRAE_ENV_FILE;
|
|
580
|
+
// TRAE_AI_SHELL_ID 仅为部分检测库记录,实测 Agent 终端不一定注入。
|
|
581
|
+
name: "trae",
|
|
582
|
+
match: (env) => looksLikeTrae(env)
|
|
583
|
+
},
|
|
584
|
+
{
|
|
585
|
+
// 华为云码道 CodeArts Agent(OpenCode 定制分支):常只露出 OPENCODE_*,
|
|
586
|
+
// 需结合 codeartsdoer 路径 / 家目录,避免被后面的 opencode 抢走。
|
|
587
|
+
// 不把 CODEARTS_CLI_AK/SK 等鉴权变量当作身份。
|
|
588
|
+
name: "codearts",
|
|
589
|
+
match: (env) => looksLikeCodeArts(env)
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
name: "claude-code",
|
|
593
|
+
match: (env) => nonempty(env.CLAUDECODE) || nonempty(env.CLAUDE_CODE_ENTRYPOINT) || nonempty(env.CLAUDE_CODE_SESSION_ID) || nonempty(env.CLAUDE_CODE_EXECPATH)
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
name: "copilot",
|
|
597
|
+
match: (env) => nonempty(env.COPILOT_AGENT) || nonempty(env.COPILOT_CLI) || nonempty(env.COPILOT_AGENT_SESSION_ID) || nonempty(env.VSCODE_AGENT)
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
name: "gemini-cli",
|
|
601
|
+
match: (env) => nonempty(env.GEMINI_CLI)
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
name: "codex",
|
|
605
|
+
match: (env) => nonempty(env.CODEX_THREAD_ID) || nonempty(env.CODEX_SANDBOX) || nonempty(env.CODEX_CI)
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
// 原生 OpenCode:有 OPENCODE_* 且不像码道时才认
|
|
609
|
+
name: "opencode",
|
|
610
|
+
match: (env) => hasOpenCodeSignals(env) && !looksLikeCodeArts(env)
|
|
611
|
+
}
|
|
612
|
+
];
|
|
613
|
+
function injected(value) {
|
|
614
|
+
return typeof value === "string" ? value : "";
|
|
615
|
+
}
|
|
616
|
+
function nonempty(value) {
|
|
617
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
618
|
+
}
|
|
619
|
+
function isUnnamedAgentValue(value) {
|
|
620
|
+
return ["0", "false", "no", "off", "1", "true"].includes(value);
|
|
621
|
+
}
|
|
622
|
+
function envValueContains(env, pattern) {
|
|
623
|
+
for (const value of Object.values(env)) {
|
|
624
|
+
if (typeof value === "string" && pattern.test(value)) return true;
|
|
625
|
+
}
|
|
626
|
+
return false;
|
|
627
|
+
}
|
|
628
|
+
function hasOpenCodeSignals(env) {
|
|
629
|
+
return nonempty(env.OPENCODE) || nonempty(env.OPENCODE_PID) || nonempty(env.OPENCODE_BIN_PATH) || nonempty(env.OPENCODE_SERVER) || nonempty(env.OPENCODE_APP_INFO) || nonempty(env.OPENCODE_CLIENT) || nonempty(env.OPENCODE_MODES);
|
|
630
|
+
}
|
|
631
|
+
function looksLikeZcode(env = process.env) {
|
|
632
|
+
if (nonempty(env.ZCODE_APP_VERSION) || nonempty(env.ZCODE_ENV) || nonempty(env.ZCODE_RUNTIME_ENV) || nonempty(env.ZCODE_BASE_URL) || nonempty(env.ZCODE_WINDOWS_APP_INSTALL_DIR) || nonempty(env.ZCODE_PROCESS_LABEL) || nonempty(env.ZCODE_SERVER_WORKSPACE) || nonempty(env.ZCODE_DATA_BASE_DIR)) {
|
|
633
|
+
return true;
|
|
634
|
+
}
|
|
635
|
+
for (const [key, value] of Object.entries(env)) {
|
|
636
|
+
if (/^ZCODE[_-]/i.test(key) && nonempty(value)) return true;
|
|
637
|
+
}
|
|
638
|
+
if (envValueContains(env, /(?:^|[\\/])ZCode(?:[\\/]|$)/)) return true;
|
|
639
|
+
if (envValueContains(env, /(?:^|[\\/])\.zcode(?:[\\/]|$)/)) return true;
|
|
640
|
+
if (env.TERM_PROGRAM && /zcode/i.test(env.TERM_PROGRAM)) return true;
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
function looksLikeTrae(env = process.env) {
|
|
644
|
+
if (nonempty(env.TRAE_AI_SHELL_ID) || nonempty(env.TRAE_PROJECT_DIR) || nonempty(env.TRAE_ENV_FILE)) {
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
for (const [key, value] of Object.entries(env)) {
|
|
648
|
+
if (/^TRAE[_-]/i.test(key) && nonempty(value)) return true;
|
|
649
|
+
}
|
|
650
|
+
if (envValueContains(env, /(?:^|[\\/])Trae(?:[\\/]|$)/i)) return true;
|
|
651
|
+
if (env.TERM_PROGRAM && /trae/i.test(env.TERM_PROGRAM)) return true;
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
function looksLikeCodeArts(env = process.env) {
|
|
655
|
+
if (nonempty(env.CODEARTS_AGENT) || nonempty(env.CODEARTS_SESSION_ID) || nonempty(env.CODEARTS_DOER) || nonempty(env.CODEARTSDOER)) {
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
if (envValueContains(env, /codeartsdoer|codearts[-_]?agent/i)) return true;
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
function normalizeAgentSlug(raw) {
|
|
662
|
+
const v = raw.trim().toLowerCase();
|
|
663
|
+
if (!v || isUnnamedAgentValue(v)) return void 0;
|
|
664
|
+
let slug = v.replace(/_agent$/i, "");
|
|
665
|
+
const versionCut = slug.match(/^([a-z][a-z0-9_-]*?)(?:_\d)/);
|
|
666
|
+
if (versionCut) slug = versionCut[1];
|
|
667
|
+
slug = slug.replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
668
|
+
if (!slug) return void 0;
|
|
669
|
+
if (/^(?:codearts[-_]?agent|madao)$/.test(slug)) return "codearts";
|
|
670
|
+
return slug;
|
|
671
|
+
}
|
|
672
|
+
function detectAgentName(env = process.env) {
|
|
673
|
+
for (const key of ["AI_AGENT", "AGENT"]) {
|
|
674
|
+
const raw = env[key];
|
|
675
|
+
if (!nonempty(raw)) continue;
|
|
676
|
+
const trimmed = raw.trim();
|
|
677
|
+
if (isUnnamedAgentValue(trimmed.toLowerCase())) continue;
|
|
678
|
+
const slug = normalizeAgentSlug(trimmed);
|
|
679
|
+
if (slug) return slug;
|
|
680
|
+
}
|
|
681
|
+
for (const agent of TOOL_SPECIFIC_AGENTS) {
|
|
682
|
+
if (agent.match(env)) return agent.name;
|
|
683
|
+
}
|
|
684
|
+
return void 0;
|
|
685
|
+
}
|
|
686
|
+
function getSourceChannel() {
|
|
687
|
+
const raw = injected(true ? "cli" : void 0);
|
|
688
|
+
return raw === SKILL_CHANNEL ? SKILL_CHANNEL : CLI_CHANNEL;
|
|
689
|
+
}
|
|
690
|
+
function getRequestSource() {
|
|
691
|
+
if (getSourceChannel() !== SKILL_CHANNEL) return CLI_CHANNEL;
|
|
692
|
+
const agent = detectAgentName();
|
|
693
|
+
return agent ? `${agent}-skill` : SKILL_CHANNEL;
|
|
694
|
+
}
|
|
695
|
+
function readVersion() {
|
|
696
|
+
const fromBuild = injected(true ? "1.1.8" : void 0);
|
|
697
|
+
if (fromBuild) return fromBuild;
|
|
698
|
+
const candidates = [
|
|
699
|
+
import_path4.default.join(__dirname, "..", "..", "package.json"),
|
|
700
|
+
import_path4.default.join(__dirname, "..", "package.json")
|
|
701
|
+
];
|
|
702
|
+
for (const pkgPath of candidates) {
|
|
703
|
+
try {
|
|
704
|
+
const pkg = JSON.parse(import_fs5.default.readFileSync(pkgPath, "utf8"));
|
|
705
|
+
if (pkg.version) return pkg.version;
|
|
706
|
+
} catch {
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return "0.0.0";
|
|
710
|
+
}
|
|
711
|
+
function getSourceToolName() {
|
|
712
|
+
const base = getSourceChannel() === SKILL_CHANNEL ? SKILL_TOOL_NAME : CLI_TOOL_NAME;
|
|
713
|
+
return `${base}-${readVersion()}`;
|
|
714
|
+
}
|
|
715
|
+
function applySourceHeaders(headers) {
|
|
716
|
+
const source = getRequestSource();
|
|
717
|
+
const toolName = getSourceToolName();
|
|
718
|
+
if (typeof headers?.set === "function") {
|
|
719
|
+
headers.set(REQUEST_SOURCE_HEADER, source);
|
|
720
|
+
headers.set(SOURCE_TOOL_NAME_HEADER, toolName);
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
headers[REQUEST_SOURCE_HEADER] = source;
|
|
724
|
+
headers[SOURCE_TOOL_NAME_HEADER] = toolName;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// src/core/http.ts
|
|
553
728
|
var agcClient = import_axios3.default.create({ maxRedirects: 0 });
|
|
554
729
|
function setHeader(headers, name, value) {
|
|
555
730
|
if (typeof headers?.set === "function") {
|
|
@@ -595,6 +770,7 @@ agcClient.interceptors.request.use(async (config2) => {
|
|
|
595
770
|
if (!config2.headers) {
|
|
596
771
|
config2.headers = {};
|
|
597
772
|
}
|
|
773
|
+
applySourceHeaders(config2.headers);
|
|
598
774
|
applyAuthHeaders(config2.headers, token, cfg);
|
|
599
775
|
if (cfg.authMode === "oauth" && !getHeader(config2.headers, "teamId")) {
|
|
600
776
|
const teamId = await resolveOAuthTeamId(cfg, token);
|
|
@@ -657,17 +833,19 @@ var PublishService = class {
|
|
|
657
833
|
});
|
|
658
834
|
return response.data;
|
|
659
835
|
}
|
|
660
|
-
/**
|
|
836
|
+
/**
|
|
837
|
+
* 创建应用或元服务。
|
|
838
|
+
* projectId 为可选 query:不传时服务端先创建与应用同名的项目,再创建应用。
|
|
839
|
+
*/
|
|
661
840
|
static async createApp(req) {
|
|
662
841
|
const { projectId, packageName, ...rest } = req;
|
|
663
842
|
const body = { ...rest };
|
|
664
843
|
if (req.installationFree === 0 && packageName) {
|
|
665
844
|
body.packageName = packageName;
|
|
666
845
|
}
|
|
667
|
-
const response = await agcClient.post(
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
);
|
|
846
|
+
const response = projectId ? await agcClient.post("/api/publish/v3/app", body, {
|
|
847
|
+
params: { projectId }
|
|
848
|
+
}) : await agcClient.post("/api/publish/v3/app", body);
|
|
671
849
|
return response.data;
|
|
672
850
|
}
|
|
673
851
|
/** 查询团队账号下的成员角色列表 */
|
|
@@ -747,7 +925,7 @@ var PublishService = class {
|
|
|
747
925
|
);
|
|
748
926
|
return response.data;
|
|
749
927
|
}
|
|
750
|
-
/** 更新应用软件包信息(OBS 上传后上报,
|
|
928
|
+
/** 更新应用软件包信息(OBS 上传后上报,HarmonyOS 开发者中心才会出现记录) */
|
|
751
929
|
static async updateAppPackageInfo(req) {
|
|
752
930
|
const { appId, releaseType, releasePhase, fileName, objectId } = req;
|
|
753
931
|
const response = await agcClient.put(
|
|
@@ -1095,8 +1273,8 @@ var ProvisionService = class {
|
|
|
1095
1273
|
|
|
1096
1274
|
// src/services/upload.ts
|
|
1097
1275
|
var import_axios4 = __toESM(require("axios"));
|
|
1098
|
-
var
|
|
1099
|
-
var
|
|
1276
|
+
var import_fs6 = __toESM(require("fs"));
|
|
1277
|
+
var import_path5 = __toESM(require("path"));
|
|
1100
1278
|
function pickObjectId(res) {
|
|
1101
1279
|
return res.urlInfo?.objectId || res.objectId;
|
|
1102
1280
|
}
|
|
@@ -1132,11 +1310,11 @@ var UploadService = class {
|
|
|
1132
1310
|
/**
|
|
1133
1311
|
* 封装好的上传文件核心流程(支持根据文件大小自动单文件或分片上传)
|
|
1134
1312
|
* 文件大小 < 5MB 时使用单文件上传,否则使用分片上传。
|
|
1135
|
-
* 仅完成 OBS 落盘;HarmonyOS `.app` 还须调用更新应用软件包信息,
|
|
1313
|
+
* 仅完成 OBS 落盘;HarmonyOS `.app` 还须调用更新应用软件包信息,HarmonyOS 开发者中心才会有记录。
|
|
1136
1314
|
*/
|
|
1137
1315
|
static async uploadFile(options) {
|
|
1138
|
-
const stat =
|
|
1139
|
-
const fileName =
|
|
1316
|
+
const stat = import_fs6.default.statSync(options.filePath);
|
|
1317
|
+
const fileName = import_path5.default.basename(options.filePath) || "unknown";
|
|
1140
1318
|
if (stat.size < 5 * 1024 * 1024) {
|
|
1141
1319
|
return this.uploadSingleFile(options, fileName, stat.size);
|
|
1142
1320
|
}
|
|
@@ -1177,7 +1355,7 @@ var UploadService = class {
|
|
|
1177
1355
|
);
|
|
1178
1356
|
}
|
|
1179
1357
|
const { url, headers } = urlRes.urlInfo;
|
|
1180
|
-
const fileStream =
|
|
1358
|
+
const fileStream = import_fs6.default.createReadStream(options.filePath);
|
|
1181
1359
|
await import_axios4.default.put(url, fileStream, {
|
|
1182
1360
|
headers: this.buildObsPutHeaders(headers, contentLength),
|
|
1183
1361
|
maxBodyLength: Infinity,
|
|
@@ -1218,7 +1396,7 @@ var UploadService = class {
|
|
|
1218
1396
|
if (!uploadInfoMap) {
|
|
1219
1397
|
throw new Error(`Failed to get parts upload URL: ${JSON.stringify(partsRes.ret)}`);
|
|
1220
1398
|
}
|
|
1221
|
-
const fd =
|
|
1399
|
+
const fd = import_fs6.default.openSync(options.filePath, "r");
|
|
1222
1400
|
const composeReqBody = {};
|
|
1223
1401
|
for (let i = 1; i <= partsCount; i++) {
|
|
1224
1402
|
const propKey = `additionalProp${i}`;
|
|
@@ -1227,7 +1405,7 @@ var UploadService = class {
|
|
|
1227
1405
|
const end = Math.min(start + partSize, fileSize);
|
|
1228
1406
|
const length = end - start;
|
|
1229
1407
|
const buffer = Buffer.alloc(length);
|
|
1230
|
-
|
|
1408
|
+
import_fs6.default.readSync(fd, buffer, 0, length, start);
|
|
1231
1409
|
const res = await import_axios4.default.put(uploadInfo.url, buffer, {
|
|
1232
1410
|
headers: this.buildObsPutHeaders(uploadInfo.headers, length),
|
|
1233
1411
|
maxBodyLength: Infinity,
|
|
@@ -1239,7 +1417,7 @@ var UploadService = class {
|
|
|
1239
1417
|
etag
|
|
1240
1418
|
};
|
|
1241
1419
|
}
|
|
1242
|
-
|
|
1420
|
+
import_fs6.default.closeSync(fd);
|
|
1243
1421
|
await this.composeMultipart({
|
|
1244
1422
|
objectId,
|
|
1245
1423
|
nspUploadId,
|
|
@@ -1250,7 +1428,7 @@ var UploadService = class {
|
|
|
1250
1428
|
};
|
|
1251
1429
|
|
|
1252
1430
|
// src/services/domain.ts
|
|
1253
|
-
var
|
|
1431
|
+
var import_fs7 = __toESM(require("fs"));
|
|
1254
1432
|
var DomainService = class {
|
|
1255
1433
|
/**
|
|
1256
1434
|
* 查询元服务的域名配置信息
|
|
@@ -1303,7 +1481,7 @@ var DomainService = class {
|
|
|
1303
1481
|
}
|
|
1304
1482
|
);
|
|
1305
1483
|
return new Promise((resolve, reject) => {
|
|
1306
|
-
const writer =
|
|
1484
|
+
const writer = import_fs7.default.createWriteStream(outputPath);
|
|
1307
1485
|
response.data.pipe(writer);
|
|
1308
1486
|
let error = null;
|
|
1309
1487
|
writer.on("error", (err) => {
|
|
@@ -1334,8 +1512,9 @@ var DomainService = class {
|
|
|
1334
1512
|
};
|
|
1335
1513
|
|
|
1336
1514
|
// src/services/sign.ts
|
|
1337
|
-
var
|
|
1338
|
-
var
|
|
1515
|
+
var import_fs8 = __toESM(require("fs"));
|
|
1516
|
+
var import_os3 = __toESM(require("os"));
|
|
1517
|
+
var import_path6 = __toESM(require("path"));
|
|
1339
1518
|
var import_child_process2 = require("child_process");
|
|
1340
1519
|
var import_crypto = __toESM(require("crypto"));
|
|
1341
1520
|
var DEFAULT_SIGN_OUT_DIR = ".certs";
|
|
@@ -1347,16 +1526,22 @@ var SIGN_FILE_PREFIX = {
|
|
|
1347
1526
|
};
|
|
1348
1527
|
var SignService = class {
|
|
1349
1528
|
static resolveSignOutputLayout(options) {
|
|
1350
|
-
const rootDir = options.outDir ?
|
|
1529
|
+
const rootDir = options.outDir ? import_path6.default.resolve(options.outDir) : import_path6.default.join(process.cwd(), DEFAULT_SIGN_OUT_DIR);
|
|
1351
1530
|
const signId = options.filename || this.createSignDefaultId();
|
|
1352
1531
|
return {
|
|
1353
1532
|
rootDir,
|
|
1354
|
-
bundleDir:
|
|
1533
|
+
bundleDir: import_path6.default.join(rootDir, signId),
|
|
1355
1534
|
filename: signId
|
|
1356
1535
|
};
|
|
1357
1536
|
}
|
|
1358
|
-
/**
|
|
1359
|
-
|
|
1537
|
+
/**
|
|
1538
|
+
* 签名工具都在 SDK 的 `toolchains/lib/`。
|
|
1539
|
+
* Windows / macOS 是 `hap-sign-tool.jar`(`java -jar`);
|
|
1540
|
+
* 鸿蒙 PC 是同目录无后缀的 `hap-sign-tool`(直接执行)。
|
|
1541
|
+
*/
|
|
1542
|
+
static HAP_SIGN_TOOL_DIR = ["default", "openharmony", "toolchains", "lib"];
|
|
1543
|
+
static HAP_SIGN_TOOL_JAR = "hap-sign-tool.jar";
|
|
1544
|
+
static HAP_SIGN_TOOL_NATIVE = "hap-sign-tool";
|
|
1360
1545
|
/**
|
|
1361
1546
|
* 只根据调用方给出的路径解析 SDK:`--sdk-path` → `DEVECO_HOME` 下的 `sdk/` 或 `Contents/sdk/`。
|
|
1362
1547
|
* 不扫盘、不猜常见安装目录。
|
|
@@ -1368,12 +1553,33 @@ var SignService = class {
|
|
|
1368
1553
|
/** 仅检查 `DEVECO_HOME` 本身及其 `Contents/`,找不到就返回 undefined */
|
|
1369
1554
|
static sdkPathFromDevEcoHome(home) {
|
|
1370
1555
|
if (!home) return void 0;
|
|
1371
|
-
for (const sdk of [
|
|
1372
|
-
if (
|
|
1556
|
+
for (const sdk of [import_path6.default.join(home, "sdk"), import_path6.default.join(home, "Contents", "sdk")]) {
|
|
1557
|
+
if (this.resolveSignTool(sdk)) return sdk;
|
|
1373
1558
|
}
|
|
1374
1559
|
return void 0;
|
|
1375
1560
|
}
|
|
1561
|
+
/** jar 与无后缀可执行文件的绝对路径(不一定存在) */
|
|
1562
|
+
static signToolCandidates(sdkPath) {
|
|
1563
|
+
const dir = import_path6.default.join(sdkPath, ...this.HAP_SIGN_TOOL_DIR);
|
|
1564
|
+
return {
|
|
1565
|
+
jar: import_path6.default.join(dir, this.HAP_SIGN_TOOL_JAR),
|
|
1566
|
+
native: import_path6.default.join(dir, this.HAP_SIGN_TOOL_NATIVE)
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* 有 jar 就用 jar(Windows / macOS)。否则用同目录无后缀可执行文件(鸿蒙 PC)。
|
|
1571
|
+
*/
|
|
1572
|
+
static resolveSignTool(sdkPath) {
|
|
1573
|
+
const { jar, native } = this.signToolCandidates(sdkPath);
|
|
1574
|
+
if (import_fs8.default.existsSync(jar)) return { mode: "jar", path: jar };
|
|
1575
|
+
if (import_fs8.default.existsSync(native)) return { mode: "native", path: native };
|
|
1576
|
+
return void 0;
|
|
1577
|
+
}
|
|
1376
1578
|
static async createSignP12AndCsr(options) {
|
|
1579
|
+
const pwd = options.pwd;
|
|
1580
|
+
if (!pwd) {
|
|
1581
|
+
throw new Error("pwd is required. Ask the user for the keystore password and pass --pwd.");
|
|
1582
|
+
}
|
|
1377
1583
|
const javaPath = options.javaPath || "java";
|
|
1378
1584
|
const sdkPath = this.resolveHarmonySdkPath(options.sdkPath);
|
|
1379
1585
|
if (!sdkPath) {
|
|
@@ -1386,24 +1592,24 @@ var SignService = class {
|
|
|
1386
1592
|
"sdkPath is required. Provide it via --sdk-path or DEVECO_HOME in .env."
|
|
1387
1593
|
);
|
|
1388
1594
|
}
|
|
1389
|
-
const
|
|
1390
|
-
if (!
|
|
1391
|
-
|
|
1595
|
+
const signTool = this.resolveSignTool(sdkPath);
|
|
1596
|
+
if (!signTool) {
|
|
1597
|
+
const { jar, native } = this.signToolCandidates(sdkPath);
|
|
1598
|
+
throw new Error(`hap-sign-tool not found at ${jar} or ${native}`);
|
|
1392
1599
|
}
|
|
1393
1600
|
const { rootDir, bundleDir, filename } = this.resolveSignOutputLayout(options);
|
|
1394
|
-
const createdBundleDir = !
|
|
1395
|
-
if (!
|
|
1396
|
-
|
|
1601
|
+
const createdBundleDir = !import_fs8.default.existsSync(bundleDir);
|
|
1602
|
+
if (!import_fs8.default.existsSync(rootDir)) {
|
|
1603
|
+
import_fs8.default.mkdirSync(rootDir, { recursive: true });
|
|
1397
1604
|
}
|
|
1398
|
-
|
|
1399
|
-
const p12FilePath =
|
|
1400
|
-
const csrFilePath =
|
|
1605
|
+
import_fs8.default.mkdirSync(bundleDir, { recursive: true });
|
|
1606
|
+
const p12FilePath = import_path6.default.join(bundleDir, this.signFileName(filename, "p12"));
|
|
1607
|
+
const csrFilePath = import_path6.default.join(bundleDir, this.signFileName(filename, "csr"));
|
|
1401
1608
|
const alias = options.alias;
|
|
1402
|
-
const pwd = options.pwd || this.createSignDefaultPassword();
|
|
1403
1609
|
try {
|
|
1404
|
-
this.doCreateSignFileP12(javaPath,
|
|
1405
|
-
this.doCreateSignFileCsr(javaPath,
|
|
1406
|
-
const csrContent =
|
|
1610
|
+
this.doCreateSignFileP12(javaPath, signTool, alias, pwd, p12FilePath);
|
|
1611
|
+
this.doCreateSignFileCsr(javaPath, signTool, alias, pwd, p12FilePath, csrFilePath);
|
|
1612
|
+
const csrContent = import_fs8.default.readFileSync(csrFilePath, "utf8");
|
|
1407
1613
|
const materialPath = this.placeMaterialBesideStore(bundleDir);
|
|
1408
1614
|
return {
|
|
1409
1615
|
alias,
|
|
@@ -1413,13 +1619,13 @@ var SignService = class {
|
|
|
1413
1619
|
csrPath: csrFilePath,
|
|
1414
1620
|
csrContent,
|
|
1415
1621
|
storePath: bundleDir,
|
|
1416
|
-
cerPath:
|
|
1417
|
-
p7bPath:
|
|
1622
|
+
cerPath: import_path6.default.join(bundleDir, this.signFileName(filename, "cer")),
|
|
1623
|
+
p7bPath: import_path6.default.join(bundleDir, this.signFileName(filename, "p7b")),
|
|
1418
1624
|
...materialPath ? { materialPath } : {}
|
|
1419
1625
|
};
|
|
1420
1626
|
} catch (err) {
|
|
1421
1627
|
if (createdBundleDir) {
|
|
1422
|
-
|
|
1628
|
+
import_fs8.default.rmSync(bundleDir, { recursive: true, force: true });
|
|
1423
1629
|
}
|
|
1424
1630
|
throw err;
|
|
1425
1631
|
}
|
|
@@ -1437,23 +1643,19 @@ var SignService = class {
|
|
|
1437
1643
|
return import_crypto.default.randomBytes(16).toString("hex");
|
|
1438
1644
|
}
|
|
1439
1645
|
/**
|
|
1440
|
-
* hvigor 在 `.p12` 同级目录找 `material
|
|
1441
|
-
*
|
|
1646
|
+
* hvigor 在 `.p12` 同级目录找 `material/`。把加密材料放到本套证书目录,
|
|
1647
|
+
* 避免签名文件被拷到工程根目录才能编过。配置目录里还没有 material 时先生成。
|
|
1442
1648
|
*/
|
|
1443
1649
|
static placeMaterialBesideStore(bundleDir, configDir) {
|
|
1444
|
-
const dest =
|
|
1445
|
-
if (
|
|
1650
|
+
const dest = import_path6.default.join(bundleDir, "material");
|
|
1651
|
+
if (import_fs8.default.existsSync(dest)) {
|
|
1446
1652
|
return dest;
|
|
1447
1653
|
}
|
|
1448
|
-
const
|
|
1449
|
-
const src = import_path5.default.resolve(configDir || import_path5.default.join(home, ".ohos", "config"), "material");
|
|
1450
|
-
if (!import_fs7.default.existsSync(src)) {
|
|
1451
|
-
return void 0;
|
|
1452
|
-
}
|
|
1654
|
+
const src = this.ensureMaterial(this.resolveOhosConfigDir(configDir));
|
|
1453
1655
|
try {
|
|
1454
|
-
|
|
1656
|
+
import_fs8.default.symlinkSync(src, dest, process.platform === "win32" ? "junction" : "dir");
|
|
1455
1657
|
} catch {
|
|
1456
|
-
|
|
1658
|
+
import_fs8.default.cpSync(src, dest, { recursive: true });
|
|
1457
1659
|
}
|
|
1458
1660
|
return dest;
|
|
1459
1661
|
}
|
|
@@ -1467,14 +1669,19 @@ var SignService = class {
|
|
|
1467
1669
|
* 执行签名工具:命令行与子进程输出统一走 stderr,
|
|
1468
1670
|
* 保证 stdout 只有 CLI 的 JSON 结果,便于 jq 等下游解析。
|
|
1469
1671
|
*/
|
|
1470
|
-
|
|
1672
|
+
/** jar 走 `java -jar`;无后缀可执行文件直接执行,子命令参数相同 */
|
|
1673
|
+
static runSignTool(javaPath, tool, toolArgs) {
|
|
1674
|
+
if (tool.mode === "native") {
|
|
1675
|
+
console.error(`Executing: ${tool.path} ${this.maskArgs(toolArgs)}`);
|
|
1676
|
+
(0, import_child_process2.execFileSync)(tool.path, toolArgs, { stdio: ["ignore", 2, "inherit"] });
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
const args = ["-jar", tool.path, ...toolArgs];
|
|
1471
1680
|
console.error(`Executing: ${javaPath} ${this.maskArgs(args)}`);
|
|
1472
1681
|
(0, import_child_process2.execFileSync)(javaPath, args, { stdio: ["ignore", 2, "inherit"] });
|
|
1473
1682
|
}
|
|
1474
|
-
static doCreateSignFileP12(javaPath,
|
|
1683
|
+
static doCreateSignFileP12(javaPath, tool, alias, pwd, outFilePath) {
|
|
1475
1684
|
const args = [
|
|
1476
|
-
"-jar",
|
|
1477
|
-
signToolPath,
|
|
1478
1685
|
"generate-keypair",
|
|
1479
1686
|
"-keyAlias",
|
|
1480
1687
|
alias,
|
|
@@ -1489,12 +1696,10 @@ var SignService = class {
|
|
|
1489
1696
|
"-keystorePwd",
|
|
1490
1697
|
pwd
|
|
1491
1698
|
];
|
|
1492
|
-
this.runSignTool(javaPath, args);
|
|
1699
|
+
this.runSignTool(javaPath, tool, args);
|
|
1493
1700
|
}
|
|
1494
|
-
static doCreateSignFileCsr(javaPath,
|
|
1701
|
+
static doCreateSignFileCsr(javaPath, tool, alias, pwd, p12Path, outFilePath) {
|
|
1495
1702
|
const args = [
|
|
1496
|
-
"-jar",
|
|
1497
|
-
signToolPath,
|
|
1498
1703
|
"generate-csr",
|
|
1499
1704
|
"-keyAlias",
|
|
1500
1705
|
alias,
|
|
@@ -1511,16 +1716,16 @@ var SignService = class {
|
|
|
1511
1716
|
"-outFile",
|
|
1512
1717
|
outFilePath
|
|
1513
1718
|
];
|
|
1514
|
-
this.runSignTool(javaPath, args);
|
|
1719
|
+
this.runSignTool(javaPath, tool, args);
|
|
1515
1720
|
}
|
|
1516
1721
|
static COMPONENT = new Int8Array([49, 243, 9, 115, 214, 175, 91, 184, 211, 190, 177, 88, 101, 131, 192, 119]);
|
|
1517
1722
|
static readDirBytes(dirPath) {
|
|
1518
|
-
const entries =
|
|
1519
|
-
return new Int8Array(
|
|
1723
|
+
const entries = import_fs8.default.readdirSync(dirPath).filter((f) => f !== ".DS_Store");
|
|
1724
|
+
return new Int8Array(import_fs8.default.readFileSync(import_path6.default.resolve(dirPath, entries[0])));
|
|
1520
1725
|
}
|
|
1521
1726
|
static readFd(materialPath) {
|
|
1522
|
-
const fdDir =
|
|
1523
|
-
return
|
|
1727
|
+
const fdDir = import_path6.default.resolve(materialPath, "fd");
|
|
1728
|
+
return import_fs8.default.readdirSync(fdDir).filter((f) => f !== ".DS_Store").map((e) => this.readDirBytes(import_path6.default.resolve(fdDir, e)));
|
|
1524
1729
|
}
|
|
1525
1730
|
static xorBuffers(a, b) {
|
|
1526
1731
|
const result = new Int8Array(a.byteLength);
|
|
@@ -1541,34 +1746,97 @@ var SignService = class {
|
|
|
1541
1746
|
decipher.setAuthTag(d.subarray(d.length - 16));
|
|
1542
1747
|
return Buffer.concat([decipher.update(d.subarray(4 + ivLen, d.length - 16)), decipher.final()]);
|
|
1543
1748
|
}
|
|
1544
|
-
static
|
|
1749
|
+
static aesSeal(key, plaintext) {
|
|
1545
1750
|
const iv = import_crypto.default.randomBytes(12);
|
|
1546
1751
|
const cipher = import_crypto.default.createCipheriv("aes-128-gcm", key, iv);
|
|
1547
|
-
const enc = Buffer.concat([cipher.update(plaintext
|
|
1752
|
+
const enc = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
1548
1753
|
const tag = cipher.getAuthTag();
|
|
1549
1754
|
const header = Buffer.alloc(4);
|
|
1550
1755
|
header.writeUInt32BE(enc.length + 16, 0);
|
|
1551
|
-
return Buffer.concat([header, iv, enc, tag])
|
|
1756
|
+
return Buffer.concat([header, iv, enc, tag]);
|
|
1757
|
+
}
|
|
1758
|
+
static aesEncrypt(key, plaintext) {
|
|
1759
|
+
return this.aesSeal(key, Buffer.from(plaintext, "utf-8")).toString("hex").toUpperCase();
|
|
1760
|
+
}
|
|
1761
|
+
static deriveRootKey(components, salt) {
|
|
1762
|
+
return import_crypto.default.pbkdf2Sync(
|
|
1763
|
+
this.xorAll(components.concat(this.COMPONENT)).toString(),
|
|
1764
|
+
Buffer.from(salt),
|
|
1765
|
+
1e4,
|
|
1766
|
+
16,
|
|
1767
|
+
"sha256"
|
|
1768
|
+
);
|
|
1552
1769
|
}
|
|
1553
1770
|
static deriveEncryptionKey(configDir) {
|
|
1554
|
-
const materialDir =
|
|
1771
|
+
const materialDir = import_path6.default.resolve(configDir, "material");
|
|
1555
1772
|
const fd = this.readFd(materialDir);
|
|
1556
|
-
const salt = this.readDirBytes(
|
|
1557
|
-
const rawKey = new Int8Array(
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1773
|
+
const salt = this.readDirBytes(import_path6.default.resolve(materialDir, "ac"));
|
|
1774
|
+
const rawKey = new Int8Array(this.deriveRootKey(fd, salt));
|
|
1775
|
+
return new Int8Array(this.aesDecrypt(rawKey, this.readDirBytes(import_path6.default.resolve(materialDir, "ce"))));
|
|
1776
|
+
}
|
|
1777
|
+
/** 显式目录优先;否则用户主目录。不用空的 HOME 落到当前工作目录。 */
|
|
1778
|
+
static resolveOhosConfigDir(configDir) {
|
|
1779
|
+
if (configDir) return import_path6.default.resolve(configDir);
|
|
1780
|
+
const home = process.env.HOME || process.env.USERPROFILE || import_os3.default.homedir();
|
|
1781
|
+
return import_path6.default.join(home, ".ohos", "config");
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* 与 devecocli KeyManager.generateMaterial 相同的 material/{fd,ac,ce}。
|
|
1785
|
+
* 目录已存在则直接复用,不删除、不覆盖,避免已加密密码失效。
|
|
1786
|
+
*/
|
|
1787
|
+
static ensureMaterial(configDir) {
|
|
1788
|
+
const materialDir = import_path6.default.resolve(configDir, "material");
|
|
1789
|
+
if (!import_fs8.default.existsSync(materialDir)) this.generateMaterial(configDir);
|
|
1790
|
+
return materialDir;
|
|
1791
|
+
}
|
|
1792
|
+
static generateMaterial(configDir) {
|
|
1793
|
+
const materialDir = import_path6.default.resolve(configDir, "material");
|
|
1794
|
+
if (import_fs8.default.existsSync(materialDir)) return;
|
|
1795
|
+
import_fs8.default.mkdirSync(configDir, { recursive: true, mode: 448 });
|
|
1796
|
+
const staging = import_path6.default.join(configDir, `.material-${import_crypto.default.randomBytes(8).toString("hex")}`);
|
|
1797
|
+
const acDir = import_path6.default.join(staging, "ac");
|
|
1798
|
+
const ceDir = import_path6.default.join(staging, "ce");
|
|
1799
|
+
import_fs8.default.mkdirSync(acDir, { recursive: true, mode: 448 });
|
|
1800
|
+
import_fs8.default.mkdirSync(ceDir, { recursive: true, mode: 448 });
|
|
1801
|
+
const salt = import_crypto.default.randomBytes(16);
|
|
1802
|
+
const components = [0, 1, 2].map(() => new Int8Array(import_crypto.default.randomBytes(16)));
|
|
1803
|
+
for (let i = 0; i < components.length; i++) {
|
|
1804
|
+
import_fs8.default.mkdirSync(import_path6.default.join(staging, "fd", String(i)), { recursive: true, mode: 448 });
|
|
1805
|
+
}
|
|
1806
|
+
const workKey = import_crypto.default.randomBytes(16);
|
|
1807
|
+
const derived = this.deriveRootKey(components, salt);
|
|
1808
|
+
this.writeMaterialFile(acDir, salt);
|
|
1809
|
+
this.writeMaterialFile(ceDir, this.aesSeal(derived, workKey));
|
|
1810
|
+
components.forEach((part, i) => {
|
|
1811
|
+
this.writeMaterialFile(import_path6.default.join(staging, "fd", String(i)), Buffer.from(part));
|
|
1812
|
+
});
|
|
1813
|
+
try {
|
|
1814
|
+
import_fs8.default.renameSync(staging, materialDir);
|
|
1815
|
+
} catch (err) {
|
|
1816
|
+
import_fs8.default.rmSync(staging, { recursive: true, force: true });
|
|
1817
|
+
if (!import_fs8.default.existsSync(materialDir)) throw err;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
static writeMaterialFile(dir, data) {
|
|
1821
|
+
import_fs8.default.writeFileSync(import_path6.default.join(dir, import_crypto.default.randomBytes(16).toString("hex")), data, { mode: 384 });
|
|
1561
1822
|
}
|
|
1562
1823
|
/**
|
|
1563
|
-
*
|
|
1824
|
+
* 使用与 devecocli / hvigor 相同的 AES-128-GCM 密钥加密密码,
|
|
1564
1825
|
* 生成 build-profile.json5 中 signingConfigs 所需的加密密码。
|
|
1826
|
+
* 配置目录下没有 material/ 时自动生成,已有目录不覆盖。
|
|
1565
1827
|
*/
|
|
1566
1828
|
static encryptPassword(password, configDir) {
|
|
1567
|
-
const dir =
|
|
1568
|
-
|
|
1569
|
-
|
|
1829
|
+
const dir = this.resolveOhosConfigDir(configDir);
|
|
1830
|
+
this.ensureMaterial(dir);
|
|
1831
|
+
let key;
|
|
1832
|
+
try {
|
|
1833
|
+
key = this.deriveEncryptionKey(dir);
|
|
1834
|
+
} catch (err) {
|
|
1835
|
+
throw new Error(
|
|
1836
|
+
`\u65E0\u6CD5\u8BFB\u53D6\u52A0\u5BC6\u6750\u6599 ${import_path6.default.resolve(dir, "material")}\u3002\u5DF2\u6709\u76EE\u5F55\u4E0D\u4F1A\u91CD\u65B0\u751F\u6210\uFF0C\u4EE5\u514D\u5DF2\u52A0\u5BC6\u5BC6\u7801\u5931\u6548\u3002`,
|
|
1837
|
+
{ cause: err }
|
|
1838
|
+
);
|
|
1570
1839
|
}
|
|
1571
|
-
const key = this.deriveEncryptionKey(dir);
|
|
1572
1840
|
return {
|
|
1573
1841
|
keyPassword: this.aesEncrypt(key, password),
|
|
1574
1842
|
storePassword: this.aesEncrypt(key, password)
|
|
@@ -1714,15 +1982,16 @@ var TestingService = class {
|
|
|
1714
1982
|
}
|
|
1715
1983
|
/** 查询测试群组成员 */
|
|
1716
1984
|
static async listGroupUsers(req) {
|
|
1717
|
-
const params = {
|
|
1718
|
-
groupId: req.groupId,
|
|
1719
|
-
appId: req.appId
|
|
1720
|
-
};
|
|
1985
|
+
const params = {};
|
|
1721
1986
|
if (req.current !== void 0) params.current = req.current;
|
|
1722
1987
|
if (req.pageSize !== void 0) params.pageSize = req.pageSize;
|
|
1723
1988
|
const response = await agcClient.get(
|
|
1724
1989
|
"/api/app-test/v1/test-user",
|
|
1725
|
-
{
|
|
1990
|
+
{
|
|
1991
|
+
params,
|
|
1992
|
+
// Connect 网关要求 groupId 走 header,query 会 400 Parameter is required
|
|
1993
|
+
headers: { ...appIdHeaders2(req.appId), groupId: req.groupId }
|
|
1994
|
+
}
|
|
1726
1995
|
);
|
|
1727
1996
|
return response.data;
|
|
1728
1997
|
}
|
|
@@ -1749,7 +2018,7 @@ var TestingService = class {
|
|
|
1749
2018
|
static async notifyUsers(req) {
|
|
1750
2019
|
const { appId, ...body } = req;
|
|
1751
2020
|
const response = await agcClient.post(
|
|
1752
|
-
"/api/publish/
|
|
2021
|
+
"/api/publish/v2/test/user/action/notify",
|
|
1753
2022
|
body,
|
|
1754
2023
|
{ headers: appIdHeaders2(appId) }
|
|
1755
2024
|
);
|
|
@@ -1852,80 +2121,21 @@ var TestingService = class {
|
|
|
1852
2121
|
}
|
|
1853
2122
|
};
|
|
1854
2123
|
|
|
1855
|
-
// src/cli/project-pick.ts
|
|
1856
|
-
var readline = __toESM(require("readline"));
|
|
1857
|
-
async function resolveProjectId(explicit) {
|
|
1858
|
-
if (explicit) return explicit;
|
|
1859
|
-
const res = await ProjectService.listProjects();
|
|
1860
|
-
if (res.ret?.code !== 0) {
|
|
1861
|
-
console.error(
|
|
1862
|
-
`Failed to list projects: ret.code=${res.ret?.code} msg=${res.ret?.msg ?? "(none)"}`
|
|
1863
|
-
);
|
|
1864
|
-
return void 0;
|
|
1865
|
-
}
|
|
1866
|
-
const list = res.projectList ?? [];
|
|
1867
|
-
if (list.length === 0) {
|
|
1868
|
-
console.error("No projects found. Create a project in AppGallery Connect first.");
|
|
1869
|
-
return void 0;
|
|
1870
|
-
}
|
|
1871
|
-
printProjectChoices(list);
|
|
1872
|
-
if (!process.stdin.isTTY) {
|
|
1873
|
-
console.error(
|
|
1874
|
-
"Non-interactive mode: pass --project-id <id> (from project list)."
|
|
1875
|
-
);
|
|
1876
|
-
return void 0;
|
|
1877
|
-
}
|
|
1878
|
-
const answer = (await promptStderr("Select project by number or paste projectId: ")).trim();
|
|
1879
|
-
if (!answer) {
|
|
1880
|
-
console.error("No project selected.");
|
|
1881
|
-
return void 0;
|
|
1882
|
-
}
|
|
1883
|
-
const byIndex = Number(answer);
|
|
1884
|
-
if (Number.isInteger(byIndex) && byIndex >= 1 && byIndex <= list.length) {
|
|
1885
|
-
const chosen = list[byIndex - 1];
|
|
1886
|
-
console.error(`Using projectId=${chosen.projectId} (${chosen.name ?? ""})`);
|
|
1887
|
-
return chosen.projectId;
|
|
1888
|
-
}
|
|
1889
|
-
const byId = list.find((p) => p.projectId === answer);
|
|
1890
|
-
if (byId) {
|
|
1891
|
-
console.error(`Using projectId=${byId.projectId} (${byId.name ?? ""})`);
|
|
1892
|
-
return byId.projectId;
|
|
1893
|
-
}
|
|
1894
|
-
console.error(`Invalid selection: ${answer}`);
|
|
1895
|
-
return void 0;
|
|
1896
|
-
}
|
|
1897
|
-
function printProjectChoices(list) {
|
|
1898
|
-
console.error("Available projects (use projectId for app-create --project-id):");
|
|
1899
|
-
list.forEach((p, i) => {
|
|
1900
|
-
const name = p.name ? ` ${p.name}` : "";
|
|
1901
|
-
console.error(` [${i + 1}] ${p.projectId}${name}`);
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
function promptStderr(question) {
|
|
1905
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
1906
|
-
return new Promise((resolve) => {
|
|
1907
|
-
rl.question(question, (answer) => {
|
|
1908
|
-
rl.close();
|
|
1909
|
-
resolve(answer);
|
|
1910
|
-
});
|
|
1911
|
-
});
|
|
1912
|
-
}
|
|
1913
|
-
|
|
1914
2124
|
// src/cli/index.ts
|
|
1915
2125
|
var program = new import_commander.Command();
|
|
1916
2126
|
function readCliVersion() {
|
|
1917
|
-
if ("1.1.
|
|
1918
|
-
return "1.1.
|
|
2127
|
+
if ("1.1.8") {
|
|
2128
|
+
return "1.1.8";
|
|
1919
2129
|
}
|
|
1920
2130
|
try {
|
|
1921
|
-
const pkgPath =
|
|
1922
|
-
const pkg = JSON.parse(
|
|
2131
|
+
const pkgPath = import_path7.default.join(__dirname, "..", "package.json");
|
|
2132
|
+
const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
|
|
1923
2133
|
if (pkg.version) return pkg.version;
|
|
1924
2134
|
} catch {
|
|
1925
2135
|
}
|
|
1926
2136
|
return "0.0.0";
|
|
1927
2137
|
}
|
|
1928
|
-
program.name("connect-api-cli").description("
|
|
2138
|
+
program.name("connect-api-cli").description("HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 API CLI Tool").version(readCliVersion());
|
|
1929
2139
|
var authCmd = program.command("auth").description("Authentication management");
|
|
1930
2140
|
authCmd.command("login").description("Login and cache token (client_credentials / service_account JWT / OAuth browser)").action(async () => {
|
|
1931
2141
|
try {
|
|
@@ -1979,7 +2189,7 @@ authCmd.command("logout").description("Logout and clear cached access token").ac
|
|
|
1979
2189
|
});
|
|
1980
2190
|
var publishCmd = program.command("publish").description("Publishing API commands");
|
|
1981
2191
|
function readJsonFile(filePath) {
|
|
1982
|
-
return JSON.parse(
|
|
2192
|
+
return JSON.parse(fs9.readFileSync(filePath, "utf8"));
|
|
1983
2193
|
}
|
|
1984
2194
|
publishCmd.command("app-id").description("Get App ID by package name").requiredOption("-p, --package-name <packageName>", "Package name (comma-separated, max 50)").option("--package-types <packageTypes>", "Optional package types filter").action(async (options) => {
|
|
1985
2195
|
try {
|
|
@@ -1989,7 +2199,10 @@ publishCmd.command("app-id").description("Get App ID by package name").requiredO
|
|
|
1989
2199
|
reportFailure("Request failed:", e.message);
|
|
1990
2200
|
}
|
|
1991
2201
|
});
|
|
1992
|
-
publishCmd.command("app-create").description("Create an app or meta-service (omit --project-id to
|
|
2202
|
+
publishCmd.command("app-create").description("Create an app or meta-service (omit --project-id to let the server create a same-named project)").option(
|
|
2203
|
+
"--project-id <projectId>",
|
|
2204
|
+
"Existing project ID; omit so the server creates a project named after the app"
|
|
2205
|
+
).requiredOption("--app-name <appName>", "App / meta-service name").option("-p, --package-name <packageName>", "Package name (required for app; omit for meta-service)").requiredOption(
|
|
1993
2206
|
"--parent-type <parentType>",
|
|
1994
2207
|
"Primary category: 2 game, 13 app"
|
|
1995
2208
|
).requiredOption(
|
|
@@ -2011,13 +2224,8 @@ publishCmd.command("app-create").description("Create an app or meta-service (omi
|
|
|
2011
2224
|
reportFailure("Missing -p/--package-name: required when creating an app (installation-free=0)");
|
|
2012
2225
|
return;
|
|
2013
2226
|
}
|
|
2014
|
-
const projectId = await resolveProjectId(options.projectId);
|
|
2015
|
-
if (!projectId) {
|
|
2016
|
-
process.exitCode = 1;
|
|
2017
|
-
return;
|
|
2018
|
-
}
|
|
2019
2227
|
const res = await PublishService.createApp({
|
|
2020
|
-
projectId,
|
|
2228
|
+
...options.projectId ? { projectId: options.projectId } : {},
|
|
2021
2229
|
appName: options.appName,
|
|
2022
2230
|
...options.packageName ? { packageName: options.packageName } : {},
|
|
2023
2231
|
parentType,
|
|
@@ -2107,7 +2315,7 @@ publishCmd.command("file-info-update").description("Update app file info (icons/
|
|
|
2107
2315
|
reportFailure("Request failed:", e.message);
|
|
2108
2316
|
}
|
|
2109
2317
|
});
|
|
2110
|
-
publishCmd.command("package-update").description("Report uploaded package to
|
|
2318
|
+
publishCmd.command("package-update").description("Report uploaded package to HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 (call after OBS upload if upload file used --no-bind)").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--file-name <fileName>", "Uploaded file name").requiredOption("--object-id <objectId>", "Uploaded object ID").option("-r, --release-type <releaseType>", "Release type").option("--release-phase <releasePhase>", "Release phase").action(async (options) => {
|
|
2111
2319
|
try {
|
|
2112
2320
|
const res = await PublishService.updateAppPackageInfo({
|
|
2113
2321
|
appId: options.appId,
|
|
@@ -2336,7 +2544,7 @@ publishCmd.command("shelf-off").description("Take app off shelf").requiredOption
|
|
|
2336
2544
|
}
|
|
2337
2545
|
});
|
|
2338
2546
|
var projectCmd = program.command("project").description("Project Management API commands");
|
|
2339
|
-
projectCmd.command("list").description("List
|
|
2547
|
+
projectCmd.command("list").description("List HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 projects (optional --project-id for publish app-create)").action(async () => {
|
|
2340
2548
|
try {
|
|
2341
2549
|
const res = await ProjectService.listProjects();
|
|
2342
2550
|
printResult(res);
|
|
@@ -2352,7 +2560,7 @@ projectCmd.command("list").description("List AGC projects (projectId for publish
|
|
|
2352
2560
|
}
|
|
2353
2561
|
});
|
|
2354
2562
|
var uploadCmd = program.command("upload").description("Upload Management API commands");
|
|
2355
|
-
uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .app is reported to
|
|
2563
|
+
uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .app is reported to HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 unless --no-bind or -r 6").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("-f, --file-path <filePath>", "Path to the local file to upload").option("-r, --release-type <releaseType>", "Release type: 1 for Full, 6 for HarmonyOS Test").option("-c, --chinese-mainland <flag>", "Chinese mainland flag: 0 or 1").option("--no-bind", "OBS upload only; skip reporting the package so it will not appear in HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3").action(async (options) => {
|
|
2356
2564
|
try {
|
|
2357
2565
|
console.error(`Uploading file ${options.filePath}...`);
|
|
2358
2566
|
const releaseType = options.releaseType ? Number(options.releaseType) : void 0;
|
|
@@ -2362,7 +2570,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
|
|
|
2362
2570
|
releaseType,
|
|
2363
2571
|
chineseMainlandFlag: options.chineseMainland ? Number(options.chineseMainland) : void 0
|
|
2364
2572
|
});
|
|
2365
|
-
const ext =
|
|
2573
|
+
const ext = import_path7.default.extname(uploaded.fileName).toLowerCase();
|
|
2366
2574
|
const shouldBind = options.bind !== false && ext === ".app" && releaseType !== 6;
|
|
2367
2575
|
if (!shouldBind) {
|
|
2368
2576
|
console.log(JSON.stringify({
|
|
@@ -2373,7 +2581,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
|
|
|
2373
2581
|
}, null, 2));
|
|
2374
2582
|
return;
|
|
2375
2583
|
}
|
|
2376
|
-
console.error("Reporting package to
|
|
2584
|
+
console.error("Reporting package to HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3...");
|
|
2377
2585
|
const bindRes = await PublishService.updateAppPackageInfo({
|
|
2378
2586
|
appId: options.appId,
|
|
2379
2587
|
fileName: uploaded.fileName,
|
|
@@ -2388,7 +2596,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
|
|
|
2388
2596
|
}, null, 2));
|
|
2389
2597
|
if (bindRes.ret?.code !== 0) {
|
|
2390
2598
|
reportFailure(
|
|
2391
|
-
"Package report failed (file is on OBS but
|
|
2599
|
+
"Package report failed (file is on OBS but HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 has no record):",
|
|
2392
2600
|
bindRes.ret?.msg || JSON.stringify(bindRes.ret)
|
|
2393
2601
|
);
|
|
2394
2602
|
}
|
|
@@ -2397,7 +2605,7 @@ uploadCmd.command("file").description("Upload a file (APP, APK, images, etc.); .
|
|
|
2397
2605
|
}
|
|
2398
2606
|
});
|
|
2399
2607
|
var provisionCmd = program.command("provision").description("Provisioning API commands");
|
|
2400
|
-
provisionCmd.command("csr-generate").description("Generate a new keypair and CSR file").requiredOption("--alias <alias>", "Key alias").
|
|
2608
|
+
provisionCmd.command("csr-generate").description("Generate a new keypair and CSR file").requiredOption("--alias <alias>", "Key alias").requiredOption("--pwd <pwd>", "Key password entered by the user").option("--out-dir <outDir>", "Root output directory (default: ./.certs; each run adds a CSPRNG subdirectory)").option("--filename <filename>", "Shared random id for the cert subdirectory (files get key_/cert_/profile_ prefixes)").option("--sdk-path <sdkPath>", "Path to HarmonyOS SDK (or DEVECO_HOME in .env)").option("--java-path <javaPath>", "Path to java executable (default: java)").action(async (options) => {
|
|
2401
2609
|
try {
|
|
2402
2610
|
const res = await SignService.createSignP12AndCsr({
|
|
2403
2611
|
alias: options.alias,
|
|
@@ -2413,7 +2621,7 @@ provisionCmd.command("csr-generate").description("Generate a new keypair and CSR
|
|
|
2413
2621
|
reportFailure("CSR generation failed:", e.message);
|
|
2414
2622
|
}
|
|
2415
2623
|
});
|
|
2416
|
-
provisionCmd.command("encrypt-pwd").description("\u52A0\u5BC6 P12 \u5BC6\u7801\uFF0C\u751F\u6210 build-profile.json5 \u6240\u9700\u7684 keyPassword / storePassword").requiredOption("--pwd <password>", "P12 \u5BC6\u7801\u660E\u6587").option("--config-dir <configDir>", "
|
|
2624
|
+
provisionCmd.command("encrypt-pwd").description("\u52A0\u5BC6 P12 \u5BC6\u7801\uFF0C\u751F\u6210 build-profile.json5 \u6240\u9700\u7684 keyPassword / storePassword").requiredOption("--pwd <password>", "P12 \u5BC6\u7801\u660E\u6587").option("--config-dir <configDir>", "\u52A0\u5BC6\u6750\u6599\u76EE\u5F55 (\u9ED8\u8BA4 ~/.ohos/config\uFF1B\u6CA1\u6709 material/ \u65F6\u81EA\u52A8\u751F\u6210\uFF0C\u5DF2\u6709\u76EE\u5F55\u4E0D\u8986\u76D6)").action(async (options) => {
|
|
2417
2625
|
try {
|
|
2418
2626
|
const res = SignService.encryptPassword(options.pwd, options.configDir);
|
|
2419
2627
|
printResult(res);
|
|
@@ -2423,7 +2631,7 @@ provisionCmd.command("encrypt-pwd").description("\u52A0\u5BC6 P12 \u5BC6\u7801\u
|
|
|
2423
2631
|
});
|
|
2424
2632
|
provisionCmd.command("cert-create").description("Create a certificate").requiredOption("--csr <csrFile>", "Path to CSR file").requiredOption("--cert-name <certName>", "Certificate name").requiredOption("--cert-type <certType>", "Certificate type (1: debug, 2: release, 3: in-house, 4: binary)").action(async (options) => {
|
|
2425
2633
|
try {
|
|
2426
|
-
const csrContent =
|
|
2634
|
+
const csrContent = fs9.readFileSync(options.csr, "utf8");
|
|
2427
2635
|
const res = await ProvisionService.createCert({
|
|
2428
2636
|
csr: csrContent,
|
|
2429
2637
|
certName: options.certName,
|
|
@@ -2457,7 +2665,7 @@ provisionCmd.command("cert-delete").description("Delete certificates").requiredO
|
|
|
2457
2665
|
});
|
|
2458
2666
|
provisionCmd.command("device-add").description("Add new devices").requiredOption("--devices <devicesFile>", 'Path to JSON file containing devices array [{"deviceName":"name","udid":"udid","deviceType":1}]').action(async (options) => {
|
|
2459
2667
|
try {
|
|
2460
|
-
const fileContent =
|
|
2668
|
+
const fileContent = fs9.readFileSync(options.devices, "utf8");
|
|
2461
2669
|
const deviceList = JSON.parse(fileContent);
|
|
2462
2670
|
const res = await ProvisionService.addDevice({ deviceList });
|
|
2463
2671
|
printResult(res);
|
|
@@ -2580,7 +2788,7 @@ provisionCmd.command("acl-eligible").description("List eligible ACL permissions
|
|
|
2580
2788
|
});
|
|
2581
2789
|
provisionCmd.command("acl-apply").description("Apply for restricted ACL permissions").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--acls <aclsFile>", 'Path to JSON file containing ACL permissions [{"name":"name","reason":"reason"}]').option("--attachment <attachment>", "Attachment object ID").action(async (options) => {
|
|
2582
2790
|
try {
|
|
2583
|
-
const fileContent =
|
|
2791
|
+
const fileContent = fs9.readFileSync(options.acls, "utf8");
|
|
2584
2792
|
const aclPermissionList = JSON.parse(fileContent);
|
|
2585
2793
|
const req = { appId: options.appId, aclPermissionList };
|
|
2586
2794
|
if (options.attachment) req.attachment = options.attachment;
|
|
@@ -2620,7 +2828,7 @@ domainCmd.command("query").description("Query domain configuration").requiredOpt
|
|
|
2620
2828
|
});
|
|
2621
2829
|
domainCmd.command("update").description("Add or update domain configuration").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("-c, --category <category>", "Category: server or business").requiredOption("--domains <domainsFile>", 'Path to JSON file containing domains array [{"type":"httpRequest","value":"https://..."}]').action(async (options) => {
|
|
2622
2830
|
try {
|
|
2623
|
-
const fileContent =
|
|
2831
|
+
const fileContent = fs9.readFileSync(options.domains, "utf8");
|
|
2624
2832
|
const domains = JSON.parse(fileContent);
|
|
2625
2833
|
const res = await DomainService.updateDomain({
|
|
2626
2834
|
appId: options.appId,
|
|
@@ -2655,7 +2863,7 @@ domainCmd.command("verify-file").description("Download domain verify file").requ
|
|
|
2655
2863
|
});
|
|
2656
2864
|
domainCmd.command("pre-check").description("Pre-check business domain configuration").requiredOption("-a, --app-id <appId>", "App ID").requiredOption("--domain <domainFile>", 'Path to JSON file containing domain object {"type":"webView","value":"https://..."}').action(async (options) => {
|
|
2657
2865
|
try {
|
|
2658
|
-
const fileContent =
|
|
2866
|
+
const fileContent = fs9.readFileSync(options.domain, "utf8");
|
|
2659
2867
|
const domain = JSON.parse(fileContent);
|
|
2660
2868
|
const res = await DomainService.preCheckDomain({
|
|
2661
2869
|
appId: options.appId,
|