connect-api-cli 1.1.9 → 1.1.10
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 +10 -4
- package/dist/cli.js +60 -20
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -16
- package/dist/index.mjs +8 -16
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -15,10 +15,16 @@ connect-api-cli --version
|
|
|
15
15
|
connect-api-cli --help
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
全局安装后,从 npm 官方仓库检查并安装更新版本:
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
|
|
21
|
+
connect-api-cli upgrade
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
如果旧版 CLI 尚未提供 `upgrade`,可运行 `npm install -g connect-api-cli@latest --registry=https://registry.npmjs.org/`。使用 `npx` 时,可直接指定 npm 的最新版本:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx connect-api-cli@latest --help
|
|
22
28
|
```
|
|
23
29
|
|
|
24
30
|
## 环境要求
|
|
@@ -57,7 +63,7 @@ AGC_SA_CREDENTIALS=./your-account_private.json
|
|
|
57
63
|
|
|
58
64
|
```env
|
|
59
65
|
AGC_AUTH_MODE=oauth
|
|
60
|
-
#
|
|
66
|
+
# 可选:指定团队 ID。省略时使用接口返回的第一个团队
|
|
61
67
|
# AGC_TEAM_ID=你的团队ID
|
|
62
68
|
# 以下均可选,默认与插件生产环境一致
|
|
63
69
|
# AGC_OAUTH_CLIENT_ID=117427577
|
|
@@ -95,7 +101,7 @@ AGC_AUTH_MODE=oauth_token
|
|
|
95
101
|
# AGC_DEVECO_SOURCE=cli
|
|
96
102
|
# 可选:显式指定凭据目录(密钥取其 keys/ 子目录)
|
|
97
103
|
# AGC_DEVECO_AUTH_DIR=/path/to/dir
|
|
98
|
-
#
|
|
104
|
+
# 可选:指定团队 ID。省略时使用接口返回的第一个团队
|
|
99
105
|
# AGC_TEAM_ID=你的团队ID
|
|
100
106
|
```
|
|
101
107
|
|
package/dist/cli.js
CHANGED
|
@@ -375,8 +375,8 @@ async function resolveOAuthTeamId(cfg, accessToken) {
|
|
|
375
375
|
if (cfg.teamId) {
|
|
376
376
|
return cfg.teamId;
|
|
377
377
|
}
|
|
378
|
-
if (cachedTeamId
|
|
379
|
-
return cachedTeamId
|
|
378
|
+
if (cachedTeamId) {
|
|
379
|
+
return cachedTeamId;
|
|
380
380
|
}
|
|
381
381
|
const persisted = readPersistedTeamId();
|
|
382
382
|
if (persisted) {
|
|
@@ -394,26 +394,18 @@ async function resolveOAuthTeamId(cfg, accessToken) {
|
|
|
394
394
|
maxRedirects: 0
|
|
395
395
|
}
|
|
396
396
|
);
|
|
397
|
-
const teams = res.data.teams || [];
|
|
398
397
|
if (res.data.ret && res.data.ret.code !== 0) {
|
|
399
398
|
throw new Error(
|
|
400
399
|
`Failed to list teams for OAuth teamId: ${res.data.ret.msg || JSON.stringify(res.data.ret)}`
|
|
401
400
|
);
|
|
402
401
|
}
|
|
403
|
-
|
|
404
|
-
|
|
402
|
+
const firstTeam = res.data.teams?.[0];
|
|
403
|
+
if (!firstTeam?.id) {
|
|
405
404
|
throw new Error("OAuth account has no teams. Cannot set teamId for API calls.");
|
|
406
405
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return cachedTeamId;
|
|
411
|
-
}
|
|
412
|
-
cachedTeamId = null;
|
|
413
|
-
const preview = teams.slice(0, 8).map((t) => `${t.id}${t.name ? `(${t.name})` : ""}`).join(", ");
|
|
414
|
-
throw new Error(
|
|
415
|
-
`Multiple teams found (${teams.length}). Set AGC_TEAM_ID to one of: ${preview}`
|
|
416
|
-
);
|
|
406
|
+
cachedTeamId = firstTeam.id;
|
|
407
|
+
writePersistedTeamId(cachedTeamId);
|
|
408
|
+
return cachedTeamId;
|
|
417
409
|
}
|
|
418
410
|
function getCachedOAuthTeamId() {
|
|
419
411
|
if (cachedTeamId) return cachedTeamId;
|
|
@@ -957,7 +949,7 @@ function getRequestSource() {
|
|
|
957
949
|
return agent ? `${agent}-skill` : SKILL_CHANNEL;
|
|
958
950
|
}
|
|
959
951
|
function readVersion() {
|
|
960
|
-
const fromBuild = injected(true ? "1.1.
|
|
952
|
+
const fromBuild = injected(true ? "1.1.10" : void 0);
|
|
961
953
|
if (fromBuild) return fromBuild;
|
|
962
954
|
const candidates = [
|
|
963
955
|
import_path5.default.join(__dirname, "..", "..", "package.json"),
|
|
@@ -2553,11 +2545,52 @@ var TestingService = class {
|
|
|
2553
2545
|
}
|
|
2554
2546
|
};
|
|
2555
2547
|
|
|
2548
|
+
// src/cli/upgrade.ts
|
|
2549
|
+
var import_node_child_process = require("child_process");
|
|
2550
|
+
var import_node_fs = require("fs");
|
|
2551
|
+
var import_node_path = __toESM(require("path"));
|
|
2552
|
+
var import_semver = require("semver");
|
|
2553
|
+
var CLI_PACKAGE_NAME = "connect-api-cli";
|
|
2554
|
+
var REGISTRY = "--registry=https://registry.npmjs.org/";
|
|
2555
|
+
function runNpm(args, stdio = "pipe") {
|
|
2556
|
+
const options = { encoding: "utf8", stdio };
|
|
2557
|
+
const result = process.platform === "win32" ? (0, import_node_child_process.spawnSync)(`npm ${args.join(" ")}`, { ...options, shell: true }) : (0, import_node_child_process.spawnSync)("npm", args, options);
|
|
2558
|
+
if (result.error) throw result.error;
|
|
2559
|
+
if (result.status !== 0) {
|
|
2560
|
+
const detail = result.stderr?.trim() || `npm exited with ${result.signal || `code ${result.status}`}`;
|
|
2561
|
+
throw new Error(detail);
|
|
2562
|
+
}
|
|
2563
|
+
return result.stdout?.trim() ?? "";
|
|
2564
|
+
}
|
|
2565
|
+
function upgradeCli(currentVersion, packageDirectory) {
|
|
2566
|
+
const npmRoot = runNpm(["root", "--global"]);
|
|
2567
|
+
const installedDirectory = (0, import_node_fs.existsSync)(npmRoot) ? import_node_path.default.join((0, import_node_fs.realpathSync)(npmRoot), CLI_PACKAGE_NAME) : void 0;
|
|
2568
|
+
if (!installedDirectory || (0, import_node_fs.realpathSync)(packageDirectory) !== installedDirectory) {
|
|
2569
|
+
throw new Error(
|
|
2570
|
+
`Run upgrade from the active npm global installation. Install it with npm install -g ${CLI_PACKAGE_NAME}@latest ${REGISTRY}`
|
|
2571
|
+
);
|
|
2572
|
+
}
|
|
2573
|
+
const publishedVersion = JSON.parse(runNpm(["view", `${CLI_PACKAGE_NAME}@latest`, "version", "--json", REGISTRY]));
|
|
2574
|
+
const latestVersion = typeof publishedVersion === "string" ? (0, import_semver.valid)(publishedVersion) : null;
|
|
2575
|
+
if (!latestVersion) throw new Error("npm did not report a valid latest version.");
|
|
2576
|
+
if (!(0, import_semver.gt)(latestVersion, currentVersion)) {
|
|
2577
|
+
console.log(`${CLI_PACKAGE_NAME} ${currentVersion} is up to date (npm latest: ${latestVersion}).`);
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2580
|
+
console.log(`Upgrading ${CLI_PACKAGE_NAME} from ${currentVersion} to ${latestVersion}\u2026`);
|
|
2581
|
+
runNpm(["install", "--global", `${CLI_PACKAGE_NAME}@${latestVersion}`, REGISTRY], "inherit");
|
|
2582
|
+
const installed = JSON.parse((0, import_node_fs.readFileSync)(import_node_path.default.join(installedDirectory, "package.json"), "utf8"));
|
|
2583
|
+
if (installed.version !== latestVersion) {
|
|
2584
|
+
throw new Error(`Expected version ${latestVersion} after npm install, found ${installed.version ?? "unknown"}.`);
|
|
2585
|
+
}
|
|
2586
|
+
console.log(`Upgraded ${CLI_PACKAGE_NAME} to ${latestVersion}.`);
|
|
2587
|
+
}
|
|
2588
|
+
|
|
2556
2589
|
// src/cli/index.ts
|
|
2557
2590
|
var program = new import_commander.Command();
|
|
2558
2591
|
function readCliVersion() {
|
|
2559
|
-
if ("1.1.
|
|
2560
|
-
return "1.1.
|
|
2592
|
+
if ("1.1.10") {
|
|
2593
|
+
return "1.1.10";
|
|
2561
2594
|
}
|
|
2562
2595
|
try {
|
|
2563
2596
|
const pkgPath = import_path8.default.join(__dirname, "..", "package.json");
|
|
@@ -2567,7 +2600,14 @@ function readCliVersion() {
|
|
|
2567
2600
|
}
|
|
2568
2601
|
return "0.0.0";
|
|
2569
2602
|
}
|
|
2570
|
-
program.name(
|
|
2603
|
+
program.name(CLI_PACKAGE_NAME).description("HarmonyOS \u5F00\u53D1\u8005\u4E2D\u5FC3 API CLI Tool").version(readCliVersion());
|
|
2604
|
+
program.command("upgrade").description("Upgrade the npm global installation to the latest published version").action(() => {
|
|
2605
|
+
try {
|
|
2606
|
+
upgradeCli(readCliVersion(), import_path8.default.resolve(__dirname, ".."));
|
|
2607
|
+
} catch (error) {
|
|
2608
|
+
reportFailure("Upgrade failed:", error instanceof Error ? error.message : String(error));
|
|
2609
|
+
}
|
|
2610
|
+
});
|
|
2571
2611
|
var authCmd = program.command("auth").description("Authentication management");
|
|
2572
2612
|
authCmd.command("login").description("Login and cache token (default: local DevEco login, then browser OAuth)").action(async () => {
|
|
2573
2613
|
try {
|
|
@@ -2604,7 +2644,7 @@ authCmd.command("status").description("Show current auth mode and cached token s
|
|
|
2604
2644
|
}
|
|
2605
2645
|
if (cfg.authMode === "oauth" || cfg.authMode === "deveco") {
|
|
2606
2646
|
const teamId = cfg.teamId || getCachedOAuthTeamId();
|
|
2607
|
-
console.log(`Team ID: ${teamId || "(
|
|
2647
|
+
console.log(`Team ID: ${teamId || "(first team returned by the API; override with AGC_TEAM_ID)"}`);
|
|
2608
2648
|
}
|
|
2609
2649
|
if (status) {
|
|
2610
2650
|
const remaining = Math.max(0, Math.floor((status.expiresAt - Date.now()) / 1e3));
|
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -375,8 +375,8 @@ async function resolveOAuthTeamId(cfg, accessToken) {
|
|
|
375
375
|
if (cfg.teamId) {
|
|
376
376
|
return cfg.teamId;
|
|
377
377
|
}
|
|
378
|
-
if (cachedTeamId
|
|
379
|
-
return cachedTeamId
|
|
378
|
+
if (cachedTeamId) {
|
|
379
|
+
return cachedTeamId;
|
|
380
380
|
}
|
|
381
381
|
const persisted = readPersistedTeamId();
|
|
382
382
|
if (persisted) {
|
|
@@ -394,26 +394,18 @@ async function resolveOAuthTeamId(cfg, accessToken) {
|
|
|
394
394
|
maxRedirects: 0
|
|
395
395
|
}
|
|
396
396
|
);
|
|
397
|
-
const teams = res.data.teams || [];
|
|
398
397
|
if (res.data.ret && res.data.ret.code !== 0) {
|
|
399
398
|
throw new Error(
|
|
400
399
|
`Failed to list teams for OAuth teamId: ${res.data.ret.msg || JSON.stringify(res.data.ret)}`
|
|
401
400
|
);
|
|
402
401
|
}
|
|
403
|
-
|
|
404
|
-
|
|
402
|
+
const firstTeam = res.data.teams?.[0];
|
|
403
|
+
if (!firstTeam?.id) {
|
|
405
404
|
throw new Error("OAuth account has no teams. Cannot set teamId for API calls.");
|
|
406
405
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
return cachedTeamId;
|
|
411
|
-
}
|
|
412
|
-
cachedTeamId = null;
|
|
413
|
-
const preview = teams.slice(0, 8).map((t) => `${t.id}${t.name ? `(${t.name})` : ""}`).join(", ");
|
|
414
|
-
throw new Error(
|
|
415
|
-
`Multiple teams found (${teams.length}). Set AGC_TEAM_ID to one of: ${preview}`
|
|
416
|
-
);
|
|
406
|
+
cachedTeamId = firstTeam.id;
|
|
407
|
+
writePersistedTeamId(cachedTeamId);
|
|
408
|
+
return cachedTeamId;
|
|
417
409
|
}
|
|
418
410
|
function clearOAuthTeamIdCache() {
|
|
419
411
|
cachedTeamId = void 0;
|
|
@@ -950,7 +942,7 @@ function getRequestSource() {
|
|
|
950
942
|
return agent ? `${agent}-skill` : SKILL_CHANNEL;
|
|
951
943
|
}
|
|
952
944
|
function readVersion() {
|
|
953
|
-
const fromBuild = injected(true ? "1.1.
|
|
945
|
+
const fromBuild = injected(true ? "1.1.10" : void 0);
|
|
954
946
|
if (fromBuild) return fromBuild;
|
|
955
947
|
const candidates = [
|
|
956
948
|
import_path5.default.join(__dirname, "..", "..", "package.json"),
|
package/dist/index.mjs
CHANGED
|
@@ -333,8 +333,8 @@ async function resolveOAuthTeamId(cfg, accessToken) {
|
|
|
333
333
|
if (cfg.teamId) {
|
|
334
334
|
return cfg.teamId;
|
|
335
335
|
}
|
|
336
|
-
if (cachedTeamId
|
|
337
|
-
return cachedTeamId
|
|
336
|
+
if (cachedTeamId) {
|
|
337
|
+
return cachedTeamId;
|
|
338
338
|
}
|
|
339
339
|
const persisted = readPersistedTeamId();
|
|
340
340
|
if (persisted) {
|
|
@@ -352,26 +352,18 @@ async function resolveOAuthTeamId(cfg, accessToken) {
|
|
|
352
352
|
maxRedirects: 0
|
|
353
353
|
}
|
|
354
354
|
);
|
|
355
|
-
const teams = res.data.teams || [];
|
|
356
355
|
if (res.data.ret && res.data.ret.code !== 0) {
|
|
357
356
|
throw new Error(
|
|
358
357
|
`Failed to list teams for OAuth teamId: ${res.data.ret.msg || JSON.stringify(res.data.ret)}`
|
|
359
358
|
);
|
|
360
359
|
}
|
|
361
|
-
|
|
362
|
-
|
|
360
|
+
const firstTeam = res.data.teams?.[0];
|
|
361
|
+
if (!firstTeam?.id) {
|
|
363
362
|
throw new Error("OAuth account has no teams. Cannot set teamId for API calls.");
|
|
364
363
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return cachedTeamId;
|
|
369
|
-
}
|
|
370
|
-
cachedTeamId = null;
|
|
371
|
-
const preview = teams.slice(0, 8).map((t) => `${t.id}${t.name ? `(${t.name})` : ""}`).join(", ");
|
|
372
|
-
throw new Error(
|
|
373
|
-
`Multiple teams found (${teams.length}). Set AGC_TEAM_ID to one of: ${preview}`
|
|
374
|
-
);
|
|
364
|
+
cachedTeamId = firstTeam.id;
|
|
365
|
+
writePersistedTeamId(cachedTeamId);
|
|
366
|
+
return cachedTeamId;
|
|
375
367
|
}
|
|
376
368
|
function clearOAuthTeamIdCache() {
|
|
377
369
|
cachedTeamId = void 0;
|
|
@@ -908,7 +900,7 @@ function getRequestSource() {
|
|
|
908
900
|
return agent ? `${agent}-skill` : SKILL_CHANNEL;
|
|
909
901
|
}
|
|
910
902
|
function readVersion() {
|
|
911
|
-
const fromBuild = injected(true ? "1.1.
|
|
903
|
+
const fromBuild = injected(true ? "1.1.10" : void 0);
|
|
912
904
|
if (fromBuild) return fromBuild;
|
|
913
905
|
const candidates = [
|
|
914
906
|
path4.join(__dirname, "..", "..", "package.json"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "connect-api-cli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.10",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/"
|
|
6
6
|
},
|
|
@@ -36,10 +36,12 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"axios": "^1.20.0",
|
|
38
38
|
"commander": "^14.0.3",
|
|
39
|
-
"dotenv": "^17.3.1"
|
|
39
|
+
"dotenv": "^17.3.1",
|
|
40
|
+
"semver": "^7.8.6"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/node": "^25.3.0",
|
|
44
|
+
"@types/semver": "^7.8.0",
|
|
43
45
|
"tsup": "^8.5.1",
|
|
44
46
|
"typescript": "^5.9.3",
|
|
45
47
|
"vitest": "^3.2.4"
|