connect-api-cli 1.1.8 → 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/dist/index.js CHANGED
@@ -35,7 +35,7 @@ __export(src_exports, {
35
35
  ProvisionService: () => ProvisionService,
36
36
  PublishService: () => PublishService,
37
37
  UploadService: () => UploadService,
38
- agcClient: () => agcClient,
38
+ connectApiClient: () => connectApiClient,
39
39
  getConfig: () => getConfig
40
40
  });
41
41
  module.exports = __toCommonJS(src_exports);
@@ -90,12 +90,11 @@ function loadServiceAccountCredentials(filePath) {
90
90
  client_cert_uri: creds.client_cert_uri
91
91
  };
92
92
  }
93
- function getConfig() {
93
+ function getConfig(authMode = process.env.AGC_AUTH_MODE ?? "deveco") {
94
94
  const clientId = process.env.AGC_CLIENT_ID;
95
95
  const clientSecret = process.env.AGC_CLIENT_SECRET;
96
- const authMode = process.env.AGC_AUTH_MODE ?? "client_credentials";
97
96
  if (authMode === "client_credentials" && (!clientId || !clientSecret)) {
98
- throw new Error("Missing AGC credentials. Please set AGC_CLIENT_ID and AGC_CLIENT_SECRET environment variables.");
97
+ throw new Error("Missing credentials. Please set AGC_CLIENT_ID and AGC_CLIENT_SECRET environment variables.");
99
98
  }
100
99
  if (authMode === "service_account" && !process.env.AGC_SA_CREDENTIALS) {
101
100
  throw new Error(
@@ -118,7 +117,22 @@ function getConfig() {
118
117
  credentials: loadServiceAccountCredentials(credentialsPath)
119
118
  };
120
119
  }
121
- const resolvedClientId = authMode === "oauth" ? oauth.clientId : authMode === "service_account" ? serviceAccount.credentials.key_id : clientId || "";
120
+ let deveco;
121
+ if (authMode === "deveco") {
122
+ const sourceEnv = process.env.AGC_DEVECO_SOURCE;
123
+ const devecoSources = ["cli", "deveco", "deveco-cli", "deveco-code"];
124
+ if (sourceEnv && !devecoSources.includes(sourceEnv)) {
125
+ throw new Error(
126
+ `Invalid AGC_DEVECO_SOURCE: ${sourceEnv} (expected ${devecoSources.join(" / ")})`
127
+ );
128
+ }
129
+ const authDirEnv = process.env.AGC_DEVECO_AUTH_DIR?.trim();
130
+ deveco = {
131
+ source: sourceEnv || "cli",
132
+ authDir: authDirEnv ? import_path.default.resolve(authDirEnv) : void 0
133
+ };
134
+ }
135
+ const resolvedClientId = authMode === "oauth" ? oauth.clientId : authMode === "service_account" ? serviceAccount.credentials.key_id : authMode === "deveco" ? deveco.authDir ? `deveco:${deveco.source}:${deveco.authDir}` : `deveco:${deveco.source}` : clientId || "";
122
136
  return {
123
137
  clientId: resolvedClientId,
124
138
  clientSecret: clientSecret || "",
@@ -126,19 +140,22 @@ function getConfig() {
126
140
  authMode,
127
141
  oauth,
128
142
  teamId: process.env.AGC_TEAM_ID || void 0,
129
- serviceAccount
143
+ serviceAccount,
144
+ deveco
130
145
  };
131
146
  }
132
147
 
133
148
  // src/services/auth.ts
134
149
  var SA_AUD = "https://oauth-login.cloud.huawei.com/oauth2/v3/token";
135
150
  var SA_JWT_TTL_SEC = 3600;
151
+ var DEVECO_CHECK_URL = process.env.AGC_DEVECO_CHECK_URL || "https://cn.devecostudio.huawei.com/authrouter/auth/api/jwToken/check";
152
+ var DEVECO_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36";
136
153
  var AuthService = class {
137
154
  /**
138
155
  * 获取访问API的Token(service to service,client_credentials 模式)
139
156
  */
140
157
  static async getToken() {
141
- const config2 = getConfig();
158
+ const config2 = getConfig("client_credentials");
142
159
  const url = `https://${config2.domain}/api/oauth2/v1/token`;
143
160
  const payload = {
144
161
  grant_type: "client_credentials",
@@ -193,7 +210,7 @@ var AuthService = class {
193
210
  * 拼装 OAuth 授权 URL(含随机 state 防 CSRF)
194
211
  */
195
212
  static buildAuthUrl(state) {
196
- const cfg = getConfig();
213
+ const cfg = getConfig("oauth");
197
214
  const url = new URL(cfg.oauth.authUrl);
198
215
  url.searchParams.set("client_id", cfg.oauth.clientId);
199
216
  url.searchParams.set("redirect_uri", cfg.oauth.redirectUri);
@@ -207,7 +224,7 @@ var AuthService = class {
207
224
  * 用授权码换取 OAuth token(与插件 /access-token/generate 对齐)
208
225
  */
209
226
  static async getOAuthToken(code, redirectUri) {
210
- const cfg = getConfig();
227
+ const cfg = getConfig("oauth");
211
228
  const controller = new AbortController();
212
229
  const timeoutId = setTimeout(() => controller.abort(), 3e4);
213
230
  try {
@@ -234,7 +251,7 @@ var AuthService = class {
234
251
  * 刷新接口只返回新的 accessToken,refreshToken 沿用旧值。
235
252
  */
236
253
  static async refreshOAuthToken(refreshToken) {
237
- const cfg = getConfig();
254
+ const cfg = getConfig("oauth");
238
255
  const controller = new AbortController();
239
256
  const timeoutId = setTimeout(() => controller.abort(), 3e4);
240
257
  try {
@@ -256,6 +273,39 @@ var AuthService = class {
256
273
  clearTimeout(timeoutId);
257
274
  }
258
275
  }
276
+ /**
277
+ * 用本地解密的 deveco JWT 调 jwToken/check 换取 access token
278
+ * (复刻 DevEco loginService.getUserInfo() / tokenChecker.checkJwtToken())。
279
+ * refresh=true 时服务端会刷新 accessToken;JWT 失效时抛错并提示重新登录 DevEco 工具。
280
+ */
281
+ static async checkDevecoJwtToken(jwtToken, refresh) {
282
+ const controller = new AbortController();
283
+ const timeoutId = setTimeout(() => controller.abort(), 3e4);
284
+ try {
285
+ const res = await import_axios.default.get(DEVECO_CHECK_URL, {
286
+ maxRedirects: 0,
287
+ headers: {
288
+ refresh: String(refresh),
289
+ jwtToken,
290
+ "User-Agent": DEVECO_USER_AGENT,
291
+ "accept-language": "zh-CN"
292
+ },
293
+ signal: controller.signal
294
+ });
295
+ const userInfo = res.data.userInfo;
296
+ if (!res.data.status || !userInfo?.accessToken) {
297
+ throw new Error("\u672C\u5730 DevEco \u767B\u5F55\u6001\u5DF2\u5931\u6548\uFF08jwToken/check \u5224\u5B9A\u65E0\u6548\uFF09\uFF0C\u8BF7\u5728 DevEco \u5DE5\u5177\u4E2D\u91CD\u65B0\u767B\u5F55");
298
+ }
299
+ return userInfo.accessToken;
300
+ } catch (err) {
301
+ if (err instanceof Error && err.name === "AbortError") {
302
+ throw new Error("\u8BF7\u6C42 jwToken/check \u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u8FDE\u63A5");
303
+ }
304
+ throw err;
305
+ } finally {
306
+ clearTimeout(timeoutId);
307
+ }
308
+ }
259
309
  };
260
310
  function base64UrlEncode(buf) {
261
311
  return buf.toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
@@ -325,8 +375,8 @@ async function resolveOAuthTeamId(cfg, accessToken) {
325
375
  if (cfg.teamId) {
326
376
  return cfg.teamId;
327
377
  }
328
- if (cachedTeamId !== void 0) {
329
- return cachedTeamId || void 0;
378
+ if (cachedTeamId) {
379
+ return cachedTeamId;
330
380
  }
331
381
  const persisted = readPersistedTeamId();
332
382
  if (persisted) {
@@ -344,50 +394,214 @@ async function resolveOAuthTeamId(cfg, accessToken) {
344
394
  maxRedirects: 0
345
395
  }
346
396
  );
347
- const teams = res.data.teams || [];
348
397
  if (res.data.ret && res.data.ret.code !== 0) {
349
398
  throw new Error(
350
399
  `Failed to list teams for OAuth teamId: ${res.data.ret.msg || JSON.stringify(res.data.ret)}`
351
400
  );
352
401
  }
353
- if (teams.length === 0) {
354
- cachedTeamId = null;
402
+ const firstTeam = res.data.teams?.[0];
403
+ if (!firstTeam?.id) {
355
404
  throw new Error("OAuth account has no teams. Cannot set teamId for API calls.");
356
405
  }
357
- if (teams.length === 1) {
358
- cachedTeamId = teams[0].id;
359
- writePersistedTeamId(cachedTeamId);
360
- return cachedTeamId;
406
+ cachedTeamId = firstTeam.id;
407
+ writePersistedTeamId(cachedTeamId);
408
+ return cachedTeamId;
409
+ }
410
+ function clearOAuthTeamIdCache() {
411
+ cachedTeamId = void 0;
412
+ }
413
+
414
+ // src/core/deveco-token.ts
415
+ var import_crypto = require("crypto");
416
+ var import_fs4 = require("fs");
417
+ var import_os2 = require("os");
418
+ var import_path3 = require("path");
419
+ var ALGORITHM = "aes-256-gcm";
420
+ var KEY_LENGTH = 32;
421
+ var KEK_VERSIONS = ["kek-v1", "kek-v2", "kek-v3"];
422
+ var CLI_SOURCE_ALIASES = ["cli", "deveco", "deveco-cli"];
423
+ var SOURCE_APP_NAMES = {
424
+ "deveco-code": "deveco"
425
+ };
426
+ function decryptAesGcm(ciphertext, key, iv, authTag) {
427
+ const decipher = (0, import_crypto.createDecipheriv)(ALGORITHM, key, iv);
428
+ decipher.setAuthTag(authTag);
429
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
430
+ }
431
+ function readJson(filePath) {
432
+ return JSON.parse((0, import_fs4.readFileSync)(filePath, "utf8"));
433
+ }
434
+ function requireFile(filePath, label) {
435
+ try {
436
+ return (0, import_fs4.readFileSync)(filePath);
437
+ } catch (err) {
438
+ const code = err.code;
439
+ if (code === "ENOENT") {
440
+ throw new Error(`\u627E\u4E0D\u5230 ${label}: ${filePath}`);
441
+ }
442
+ if (code === "EACCES" || code === "EPERM") {
443
+ throw new Error(`\u65E0\u6743\u9650\u8BFB\u53D6 ${label}: ${filePath}`);
444
+ }
445
+ throw err;
446
+ }
447
+ }
448
+ function loadKek(kekId, keysDir) {
449
+ if (!KEK_VERSIONS.includes(kekId)) {
450
+ throw new Error(`\u975E\u6CD5 kekId: ${kekId}\uFF08\u671F\u671B ${KEK_VERSIONS.join("/")}\uFF09`);
451
+ }
452
+ const rootKeyPath = (0, import_path3.resolve)((0, import_path3.join)(keysDir, `${kekId}.bin`));
453
+ const keysDirBase = (0, import_path3.resolve)(keysDir);
454
+ if (!rootKeyPath.startsWith(keysDirBase)) {
455
+ throw new Error("kekId \u89E3\u6790\u7ED3\u679C\u8D85\u51FA keys \u76EE\u5F55\u8303\u56F4");
456
+ }
457
+ const kek = requireFile(rootKeyPath, "KEK \u6839\u5BC6\u94A5");
458
+ if (kek.length !== KEY_LENGTH) {
459
+ throw new Error(`KEK \u957F\u5EA6\u5F02\u5E38: ${kek.length} \u5B57\u8282\uFF08\u671F\u671B ${KEY_LENGTH}\uFF09`);
460
+ }
461
+ return kek;
462
+ }
463
+ function decryptToken(tokenDir, keysDir) {
464
+ const blob = readJson((0, import_path3.join)(tokenDir, "token.enc"));
465
+ if (blob.algorithm !== ALGORITHM) {
466
+ throw new Error(`\u672A\u77E5\u7B97\u6CD5: ${blob.algorithm}`);
467
+ }
468
+ if (!blob.ciphertext || !blob.iv || !blob.authTag) {
469
+ throw new Error(`token.enc \u683C\u5F0F\u5F02\u5E38\uFF08\u7F3A\u5C11 ciphertext/iv/authTag\uFF09: ${(0, import_path3.join)(tokenDir, "token.enc")}`);
470
+ }
471
+ const wrapped = readJson((0, import_path3.join)(tokenDir, "token.dek"));
472
+ if (!wrapped.encryptedDek || !wrapped.iv || !wrapped.authTag) {
473
+ throw new Error(`token.dek \u683C\u5F0F\u5F02\u5E38\uFF08\u7F3A\u5C11 encryptedDek/iv/authTag\uFF09: ${(0, import_path3.join)(tokenDir, "token.dek")}`);
474
+ }
475
+ const kek = loadKek(wrapped.kekId, keysDir);
476
+ const dek = decryptAesGcm(
477
+ Buffer.from(wrapped.encryptedDek, "base64"),
478
+ kek,
479
+ Buffer.from(wrapped.iv, "base64"),
480
+ Buffer.from(wrapped.authTag, "base64")
481
+ );
482
+ if (dek.length !== KEY_LENGTH) {
483
+ throw new Error(`DEK \u957F\u5EA6\u5F02\u5E38: ${dek.length} \u5B57\u8282\uFF08\u671F\u671B ${KEY_LENGTH}\uFF09`);
484
+ }
485
+ return decryptAesGcm(
486
+ Buffer.from(blob.ciphertext, "base64"),
487
+ dek,
488
+ Buffer.from(blob.iv, "base64"),
489
+ Buffer.from(blob.authTag, "base64")
490
+ ).toString("utf8");
491
+ }
492
+ function extractJwt(plaintext) {
493
+ let jwt = plaintext;
494
+ try {
495
+ const parsed = JSON.parse(plaintext);
496
+ if (parsed && typeof parsed.access_token === "string") {
497
+ jwt = parsed.access_token;
498
+ }
499
+ } catch {
500
+ }
501
+ const parts = jwt.split(".");
502
+ if (parts.length !== 3) {
503
+ throw new Error("\u89E3\u5BC6\u7ED3\u679C\u4E0D\u662F JWT \u683C\u5F0F\uFF0C\u672C\u5730\u767B\u5F55\u6001\u53EF\u80FD\u5DF2\u635F\u574F\uFF0C\u8BF7\u5728 DevEco \u5DE5\u5177\u4E2D\u91CD\u65B0\u767B\u5F55");
504
+ }
505
+ try {
506
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
507
+ if (typeof payload.exp === "number") {
508
+ return { jwt, expMs: payload.exp * 1e3 };
509
+ }
510
+ } catch {
511
+ }
512
+ return { jwt };
513
+ }
514
+ function configHome() {
515
+ return process.env.XDG_CONFIG_HOME || (0, import_path3.join)((0, import_os2.homedir)(), ".config");
516
+ }
517
+ function candidatesFor(source) {
518
+ const home = (0, import_os2.homedir)();
519
+ if (CLI_SOURCE_ALIASES.includes(source)) {
520
+ if (process.env.DEVECO_CLI_AUTH_SOURCE?.trim() === "deveco-code") {
521
+ return candidatesFor("deveco-code").map((c) => ({
522
+ ...c,
523
+ source,
524
+ via: "DEVECO_CLI_AUTH_SOURCE=deveco-code"
525
+ }));
526
+ }
527
+ return [
528
+ {
529
+ source,
530
+ tokenDir: process.env.DEVECO_CLI_DATA_DIR || (0, import_path3.join)(home, ".config", "deveco-cli"),
531
+ keysDir: (0, import_path3.join)(home, ".local", "share", "deveco-cli", "keys"),
532
+ via: process.env.DEVECO_CLI_DATA_DIR ? "DEVECO_CLI_DATA_DIR" : "\u5E73\u53F0\u9ED8\u8BA4\u8DEF\u5F84"
533
+ }
534
+ ];
535
+ }
536
+ const appName = SOURCE_APP_NAMES[source];
537
+ const viaEnv = process.env.DEVECO_CODE_AUTH_DIR?.trim();
538
+ if (source === "deveco-code" && viaEnv) {
539
+ const tokenDir = (0, import_path3.resolve)(viaEnv);
540
+ return [{ source, tokenDir, keysDir: (0, import_path3.join)(tokenDir, "keys"), via: "DEVECO_CODE_AUTH_DIR" }];
541
+ }
542
+ let dirs;
543
+ if (process.platform === "win32") {
544
+ const appData = process.env.APPDATA || (0, import_path3.join)(home, "AppData", "Roaming");
545
+ dirs = [(0, import_path3.join)(appData, appName), (0, import_path3.join)(home, ".config", appName)];
546
+ } else if (process.platform === "darwin") {
547
+ dirs = [
548
+ (0, import_path3.join)(configHome(), appName),
549
+ (0, import_path3.join)(home, "Library", "Application Support", appName)
550
+ ];
551
+ } else {
552
+ dirs = [(0, import_path3.join)(configHome(), appName)];
553
+ }
554
+ return dirs.map((tokenDir) => ({
555
+ source,
556
+ tokenDir,
557
+ keysDir: (0, import_path3.join)(tokenDir, "keys"),
558
+ via: "\u5E73\u53F0\u9ED8\u8BA4\u8DEF\u5F84"
559
+ }));
560
+ }
561
+ function resolveLocation(source) {
562
+ const candidates = candidatesFor(source);
563
+ const hit = candidates.find((c) => (0, import_fs4.existsSync)((0, import_path3.join)(c.tokenDir, "token.enc")));
564
+ if (hit) {
565
+ return hit;
361
566
  }
362
- cachedTeamId = null;
363
- const preview = teams.slice(0, 8).map((t) => `${t.id}${t.name ? `(${t.name})` : ""}`).join(", ");
567
+ const tried = candidates.map((c) => ` - ${c.tokenDir}`).join("\n");
364
568
  throw new Error(
365
- `Multiple teams found (${teams.length}). Set AGC_TEAM_ID to one of: ${preview}`
569
+ `[${source}] \u672A\u627E\u5230\u672C\u5730\u767B\u5F55\u6001 token.enc\uFF0C\u8BF7\u5148\u7528\u5BF9\u5E94 DevEco \u5DE5\u5177\u767B\u5F55\u3002\u5DF2\u63A2\u6D4B\u4EE5\u4E0B\u4F4D\u7F6E\uFF1A
570
+ ${tried}`
366
571
  );
367
572
  }
368
- function clearOAuthTeamIdCache() {
369
- cachedTeamId = void 0;
573
+ function loadDevecoLocalToken(source, authDir) {
574
+ const location = authDir ? { source: "dir", tokenDir: authDir, keysDir: (0, import_path3.join)(authDir, "keys"), via: "AGC_DEVECO_AUTH_DIR" } : resolveLocation(source);
575
+ const plaintext = decryptToken(location.tokenDir, location.keysDir);
576
+ const { jwt, expMs } = extractJwt(plaintext);
577
+ return { jwt, expMs, location };
370
578
  }
371
579
 
372
580
  // src/core/auth-mgr.ts
373
581
  var crypto2 = __toESM(require("crypto"));
374
582
  var http = __toESM(require("http"));
375
583
  var import_child_process = require("child_process");
376
- var import_fs4 = __toESM(require("fs"));
377
- var import_path3 = __toESM(require("path"));
378
- var import_os2 = __toESM(require("os"));
584
+ var import_fs5 = __toESM(require("fs"));
585
+ var import_path4 = __toESM(require("path"));
586
+ var import_os3 = __toESM(require("os"));
587
+ var DEVECO_CACHE_TTL_MS = 30 * 60 * 1e3;
379
588
  var AuthManager = class {
380
- static cacheFile = import_path3.default.join(import_os2.default.homedir(), ".connect-api-cli-token.json");
589
+ static cacheFile = import_path4.default.join(import_os3.default.homedir(), ".connect-api-cli-token.json");
590
+ static pendingOAuthLogin;
381
591
  /**
382
592
  * 获取当前生效的 access token,并具备自动刷新能力:
383
593
  * - OAuth 模式:token 过期时优先用 refreshToken 自动刷新,无需重新登录
384
594
  * - client_credentials / service_account:过期后重新换取 / 重新签 JWT
595
+ * - deveco:过期后重新解密本地登录态并 refresh 换取
596
+ *
597
+ * force 跳过缓存(供 DevEco 和自动模式的 401 重试使用)。
385
598
  */
386
- static async getAccessToken() {
387
- const cfg = getConfig();
388
- const cache = this.readCache();
389
- const sameCredential = cache && cache.clientId === cfg.clientId && cache.domain === cfg.domain && cache.authMode === cfg.authMode;
390
- if (sameCredential && cache.expiresAt > Date.now() + 5 * 60 * 1e3) {
599
+ static async getAccessToken(force = false) {
600
+ const { config: config2, cache } = this.getStatus();
601
+ return this.getToken(config2, cache, force);
602
+ }
603
+ static async getToken(cfg, cache, force = false) {
604
+ if (!force && cache && cache.expiresAt > Date.now() + 5 * 60 * 1e3) {
391
605
  return cache.accessToken;
392
606
  }
393
607
  if (cfg.authMode === "oauth" && cache?.refreshToken) {
@@ -409,18 +623,31 @@ var AuthManager = class {
409
623
  this.clearCache();
410
624
  }
411
625
  }
412
- return this.acquire();
626
+ return this.acquire(cfg);
413
627
  }
414
628
  /** 登录入口:按当前认证模式获取并缓存 token */
415
629
  static async login() {
416
630
  clearOAuthTeamIdCache();
417
- return this.acquire();
631
+ return this.acquire(getConfig());
418
632
  }
419
- /** 按当前认证模式获取 token(client_credentials / service_account / oauth) */
420
- static async acquire() {
421
- const cfg = getConfig();
633
+ /** 按当前认证模式获取 token(client_credentials / service_account / oauth / deveco) */
634
+ static async acquire(cfg) {
422
635
  if (cfg.authMode === "oauth") {
423
- return this.loginOAuth();
636
+ this.pendingOAuthLogin ??= this.loginOAuth(cfg).finally(() => {
637
+ this.pendingOAuthLogin = void 0;
638
+ });
639
+ return this.pendingOAuthLogin;
640
+ }
641
+ if (cfg.authMode === "deveco") {
642
+ try {
643
+ return await this.acquireDevecoToken(cfg);
644
+ } catch (err) {
645
+ if (process.env.AGC_AUTH_MODE !== void 0) throw err;
646
+ const oauthConfig = getConfig("oauth");
647
+ const cache = this.matchingCache(oauthConfig, this.readCache());
648
+ console.error("\u65E0\u6CD5\u4F7F\u7528\u672C\u5730 DevEco \u767B\u5F55\u6001\uFF0C\u6539\u7528\u534E\u4E3A\u8D26\u53F7 OAuth\u3002");
649
+ return this.getToken(oauthConfig, cache);
650
+ }
424
651
  }
425
652
  if (cfg.authMode === "service_account") {
426
653
  if (!cfg.serviceAccount) {
@@ -451,9 +678,8 @@ var AuthManager = class {
451
678
  throw new Error(`Failed to get token: ${JSON.stringify(res.ret)}`);
452
679
  }
453
680
  /** OAuth 授权码登录:启动本地回调服务器 + 打开浏览器 */
454
- static loginOAuth() {
455
- return new Promise((resolve, reject) => {
456
- const cfg = getConfig();
681
+ static loginOAuth(cfg) {
682
+ return new Promise((resolve2, reject) => {
457
683
  const redirectUri = cfg.oauth.redirectUri;
458
684
  const port = Number(new URL(redirectUri).port || 80);
459
685
  const state = crypto2.randomBytes(32).toString("hex");
@@ -469,6 +695,7 @@ var AuthManager = class {
469
695
  }
470
696
  const token = await AuthService.getOAuthToken(code, redirectUri);
471
697
  const expiresAt = Date.now() + token.expireTime * 1e3;
698
+ clearOAuthTeamIdCache();
472
699
  this.writeCache({
473
700
  accessToken: token.accessToken,
474
701
  expiresAt,
@@ -480,7 +707,7 @@ var AuthManager = class {
480
707
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
481
708
  res.end('<!DOCTYPE html><html><body style="font-family:sans-serif;padding:40px;text-align:center"><h2>\u767B\u5F55\u6210\u529F\uFF0C\u53EF\u5173\u95ED\u6B64\u7A97\u53E3</h2></body></html>');
482
709
  server.close();
483
- resolve(token.accessToken);
710
+ resolve2(token.accessToken);
484
711
  } catch (err) {
485
712
  server.close();
486
713
  reject(err instanceof Error ? err : new Error(String(err)));
@@ -492,19 +719,48 @@ var AuthManager = class {
492
719
  });
493
720
  server.listen(port, () => {
494
721
  const authUrl = AuthService.buildAuthUrl(state);
495
- console.log("\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u534E\u4E3A\u8D26\u53F7\u6388\u6743...");
496
- console.log(`\u82E5\u6D4F\u89C8\u5668\u672A\u81EA\u52A8\u6253\u5F00\uFF0C\u8BF7\u8BBF\u95EE: ${authUrl}`);
722
+ console.error("\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u534E\u4E3A\u8D26\u53F7\u6388\u6743...");
723
+ console.error(`\u82E5\u6D4F\u89C8\u5668\u672A\u81EA\u52A8\u6253\u5F00\uFF0C\u8BF7\u8BBF\u95EE: ${authUrl}`);
497
724
  openBrowser(authUrl);
498
725
  });
499
726
  });
500
727
  }
501
- /** 查询缓存状态(供 status 命令显示) */
728
+ /**
729
+ * deveco 模式:解密本地 DevEco 工具链登录态(只读),
730
+ * 用 JWT 调 jwToken/check(refresh=true)换取 access token 并缓存。
731
+ * 服务端不返回有效期:缓存取「本地 JWT 剩余寿命」与「30 分钟上限」的较小值。
732
+ */
733
+ static async acquireDevecoToken(cfg) {
734
+ const deveco = cfg.deveco;
735
+ const local = loadDevecoLocalToken(deveco.source, deveco.authDir);
736
+ const accessToken = await AuthService.checkDevecoJwtToken(local.jwt, true);
737
+ const jwtLimit = local.expMs !== void 0 ? local.expMs - 5 * 60 * 1e3 : Infinity;
738
+ this.writeCache({
739
+ accessToken,
740
+ expiresAt: Math.min(Date.now() + DEVECO_CACHE_TTL_MS, jwtLimit),
741
+ clientId: cfg.clientId,
742
+ domain: cfg.domain,
743
+ authMode: cfg.authMode
744
+ });
745
+ return accessToken;
746
+ }
747
+ /** 默认模式回退到 OAuth 后,后续命令继续使用该 OAuth 会话。 */
502
748
  static getStatus() {
503
- return this.readCache();
749
+ const config2 = getConfig();
750
+ const cache = this.readCache();
751
+ if (process.env.AGC_AUTH_MODE === void 0 && cache?.authMode === "oauth") {
752
+ const oauthConfig = getConfig("oauth");
753
+ const oauthCache = this.matchingCache(oauthConfig, cache);
754
+ if (oauthCache) return { config: oauthConfig, cache: oauthCache };
755
+ }
756
+ return { config: config2, cache: this.matchingCache(config2, cache) };
757
+ }
758
+ static matchingCache(cfg, cache) {
759
+ return cache?.authMode === cfg.authMode && cache.clientId === cfg.clientId && cache.domain === cfg.domain ? cache : null;
504
760
  }
505
761
  static readCache() {
506
762
  try {
507
- if (import_fs4.default.existsSync(this.cacheFile)) {
763
+ if (import_fs5.default.existsSync(this.cacheFile)) {
508
764
  const data = readPrivateFile(this.cacheFile);
509
765
  return JSON.parse(data);
510
766
  }
@@ -524,8 +780,8 @@ var AuthManager = class {
524
780
  static clearCache() {
525
781
  clearOAuthTeamIdCache();
526
782
  try {
527
- if (import_fs4.default.existsSync(this.cacheFile)) {
528
- import_fs4.default.unlinkSync(this.cacheFile);
783
+ if (import_fs5.default.existsSync(this.cacheFile)) {
784
+ import_fs5.default.unlinkSync(this.cacheFile);
529
785
  return true;
530
786
  }
531
787
  return false;
@@ -545,8 +801,8 @@ function openBrowser(url) {
545
801
  }
546
802
 
547
803
  // src/core/request-source.ts
548
- var import_fs5 = __toESM(require("fs"));
549
- var import_path4 = __toESM(require("path"));
804
+ var import_fs6 = __toESM(require("fs"));
805
+ var import_path5 = __toESM(require("path"));
550
806
  var REQUEST_SOURCE_HEADER = "Request-Source";
551
807
  var SOURCE_TOOL_NAME_HEADER = "Source-Tool-Name";
552
808
  var SKILL_CHANNEL = "skill";
@@ -686,15 +942,15 @@ function getRequestSource() {
686
942
  return agent ? `${agent}-skill` : SKILL_CHANNEL;
687
943
  }
688
944
  function readVersion() {
689
- const fromBuild = injected(true ? "1.1.8" : void 0);
945
+ const fromBuild = injected(true ? "1.1.10" : void 0);
690
946
  if (fromBuild) return fromBuild;
691
947
  const candidates = [
692
- import_path4.default.join(__dirname, "..", "..", "package.json"),
693
- import_path4.default.join(__dirname, "..", "package.json")
948
+ import_path5.default.join(__dirname, "..", "..", "package.json"),
949
+ import_path5.default.join(__dirname, "..", "package.json")
694
950
  ];
695
951
  for (const pkgPath of candidates) {
696
952
  try {
697
- const pkg = JSON.parse(import_fs5.default.readFileSync(pkgPath, "utf8"));
953
+ const pkg = JSON.parse(import_fs6.default.readFileSync(pkgPath, "utf8"));
698
954
  if (pkg.version) return pkg.version;
699
955
  } catch {
700
956
  }
@@ -718,7 +974,7 @@ function applySourceHeaders(headers) {
718
974
  }
719
975
 
720
976
  // src/core/http.ts
721
- var agcClient = import_axios3.default.create({ maxRedirects: 0 });
977
+ var connectApiClient = import_axios3.default.create({ maxRedirects: 0 });
722
978
  function setHeader(headers, name, value) {
723
979
  if (typeof headers?.set === "function") {
724
980
  headers.set(name, value);
@@ -740,7 +996,7 @@ function getHeader(headers, name) {
740
996
  return headers?.[name] ?? headers?.[name.toLowerCase()];
741
997
  }
742
998
  function applyAuthHeaders(headers, token, cfg, force = false) {
743
- if (cfg.authMode === "oauth") {
999
+ if (cfg.authMode === "oauth" || cfg.authMode === "deveco") {
744
1000
  deleteHeader(headers, "Authorization");
745
1001
  deleteHeader(headers, "client_id");
746
1002
  setHeader(headers, "oauth2Token", token);
@@ -754,7 +1010,7 @@ function applyAuthHeaders(headers, token, cfg, force = false) {
754
1010
  setHeader(headers, "client_id", cfg.clientId);
755
1011
  }
756
1012
  }
757
- agcClient.interceptors.request.use(async (config2) => {
1013
+ connectApiClient.interceptors.request.use(async (config2) => {
758
1014
  const cfg = getConfig();
759
1015
  if (!config2.baseURL) {
760
1016
  config2.baseURL = `https://${cfg.domain}`;
@@ -765,10 +1021,11 @@ agcClient.interceptors.request.use(async (config2) => {
765
1021
  }
766
1022
  applySourceHeaders(config2.headers);
767
1023
  applyAuthHeaders(config2.headers, token, cfg);
768
- if (cfg.authMode === "oauth" && !getHeader(config2.headers, "teamId")) {
1024
+ if ((cfg.authMode === "oauth" || cfg.authMode === "deveco") && !getHeader(config2.headers, "teamId")) {
769
1025
  const teamId = await resolveOAuthTeamId(cfg, token);
770
1026
  if (teamId) {
771
1027
  setHeader(config2.headers, "teamId", teamId);
1028
+ config2._autoTeamId = true;
772
1029
  }
773
1030
  }
774
1031
  if (config2.data !== void 0 && !getHeader(config2.headers, "Content-Type")) {
@@ -778,7 +1035,7 @@ agcClient.interceptors.request.use(async (config2) => {
778
1035
  }, (error) => {
779
1036
  return Promise.reject(error);
780
1037
  });
781
- agcClient.interceptors.response.use(
1038
+ connectApiClient.interceptors.response.use(
782
1039
  (res) => res,
783
1040
  async (err) => {
784
1041
  const original = err.config;
@@ -787,12 +1044,13 @@ agcClient.interceptors.response.use(
787
1044
  original._retry = true;
788
1045
  try {
789
1046
  const cfg = getConfig();
790
- const newToken = await AuthManager.getAccessToken();
1047
+ const newToken = await AuthManager.getAccessToken(cfg.authMode === "deveco");
791
1048
  if (!original.headers) {
792
1049
  original.headers = {};
793
1050
  }
794
1051
  applyAuthHeaders(original.headers, newToken, cfg, true);
795
- return agcClient(original);
1052
+ if (original._autoTeamId) deleteHeader(original.headers, "teamId");
1053
+ return connectApiClient(original);
796
1054
  } catch (e) {
797
1055
  return Promise.reject(err);
798
1056
  }
@@ -821,7 +1079,7 @@ function withOptionalParams(base) {
821
1079
  var PublishService = class {
822
1080
  /** 查询应用包名对应的 appid */
823
1081
  static async getAppIdList(packageName, packageTypes) {
824
- const response = await agcClient.get("/api/publish/v2/appid-list", {
1082
+ const response = await connectApiClient.get("/api/publish/v2/appid-list", {
825
1083
  params: withOptionalParams({ packageName, packageTypes })
826
1084
  });
827
1085
  return response.data;
@@ -836,14 +1094,14 @@ var PublishService = class {
836
1094
  if (req.installationFree === 0 && packageName) {
837
1095
  body.packageName = packageName;
838
1096
  }
839
- const response = projectId ? await agcClient.post("/api/publish/v3/app", body, {
1097
+ const response = projectId ? await connectApiClient.post("/api/publish/v3/app", body, {
840
1098
  params: { projectId }
841
- }) : await agcClient.post("/api/publish/v3/app", body);
1099
+ }) : await connectApiClient.post("/api/publish/v3/app", body);
842
1100
  return response.data;
843
1101
  }
844
1102
  /** 查询团队账号下的成员角色列表 */
845
1103
  static async getMembersRoleList(req) {
846
- const response = await agcClient.get(
1104
+ const response = await connectApiClient.get(
847
1105
  "/api/publish/v3/members-role-list",
848
1106
  {
849
1107
  params: {
@@ -858,7 +1116,7 @@ var PublishService = class {
858
1116
  /** 查询应用信息 */
859
1117
  static async getAppInfo(appIdOrReq, lang) {
860
1118
  const req = typeof appIdOrReq === "string" ? { appId: appIdOrReq, lang } : appIdOrReq;
861
- const response = await agcClient.get("/api/publish/v3/app-info", {
1119
+ const response = await connectApiClient.get("/api/publish/v3/app-info", {
862
1120
  params: withOptionalParams({
863
1121
  appId: req.appId,
864
1122
  lang: req.lang,
@@ -871,7 +1129,7 @@ var PublishService = class {
871
1129
  /** 更新应用基本信息 */
872
1130
  static async updateAppInfo(req) {
873
1131
  const { appId, releaseType, releasePhase, ...body } = req;
874
- const response = await agcClient.put(
1132
+ const response = await connectApiClient.put(
875
1133
  "/api/publish/v3/app-info",
876
1134
  body,
877
1135
  {
@@ -883,7 +1141,7 @@ var PublishService = class {
883
1141
  /** 更新应用语言信息 */
884
1142
  static async updateLanguageInfo(req) {
885
1143
  const { appId, releaseType, releasePhase, ...body } = req;
886
- const response = await agcClient.put(
1144
+ const response = await connectApiClient.put(
887
1145
  "/api/publish/v3/app-language-info",
888
1146
  body,
889
1147
  {
@@ -894,7 +1152,7 @@ var PublishService = class {
894
1152
  }
895
1153
  /** 删除应用语言信息 */
896
1154
  static async deleteLanguageInfo(req) {
897
- const response = await agcClient.delete(
1155
+ const response = await connectApiClient.delete(
898
1156
  "/api/publish/v2/app-language-info",
899
1157
  {
900
1158
  params: withOptionalParams({
@@ -909,7 +1167,7 @@ var PublishService = class {
909
1167
  /** 更新应用文件信息(图标/截图/视频等) */
910
1168
  static async updateAppFileInfo(req) {
911
1169
  const { appId, releaseType, releasePhase, ...body } = req;
912
- const response = await agcClient.put(
1170
+ const response = await connectApiClient.put(
913
1171
  "/api/publish/v3/app-file-info",
914
1172
  body,
915
1173
  {
@@ -921,7 +1179,7 @@ var PublishService = class {
921
1179
  /** 更新应用软件包信息(OBS 上传后上报,HarmonyOS 开发者中心才会出现记录) */
922
1180
  static async updateAppPackageInfo(req) {
923
1181
  const { appId, releaseType, releasePhase, fileName, objectId } = req;
924
- const response = await agcClient.put(
1182
+ const response = await connectApiClient.put(
925
1183
  "/api/publish/v3/app-package-info",
926
1184
  { fileName, objectId },
927
1185
  {
@@ -933,7 +1191,7 @@ var PublishService = class {
933
1191
  /** 更新版本上架时间 */
934
1192
  static async updateReleaseTime(req) {
935
1193
  const { appId, ...body } = req;
936
- const response = await agcClient.put(
1194
+ const response = await connectApiClient.put(
937
1195
  "/api/publish/v2/on-shelf-time",
938
1196
  body,
939
1197
  { params: { appId } }
@@ -943,7 +1201,7 @@ var PublishService = class {
943
1201
  /** 更新分阶段发布 */
944
1202
  static async updatePhasedRelease(req) {
945
1203
  const { appId, ...body } = req;
946
- const response = await agcClient.put(
1204
+ const response = await connectApiClient.put(
947
1205
  "/api/publish/v2/version/phased-release",
948
1206
  body,
949
1207
  { headers: appIdHeaders(appId) }
@@ -952,7 +1210,7 @@ var PublishService = class {
952
1210
  }
953
1211
  /** 查询应用软件包信息 */
954
1212
  static async getPackageInfo(req) {
955
- const response = await agcClient.get(
1213
+ const response = await connectApiClient.get(
956
1214
  "/api/publish/v2/app-package-info",
957
1215
  {
958
1216
  params: { packageId: req.packageId },
@@ -963,7 +1221,7 @@ var PublishService = class {
963
1221
  }
964
1222
  /** 查询软件包编译状态 */
965
1223
  static async getCompileStatus(req) {
966
- const response = await agcClient.get(
1224
+ const response = await connectApiClient.get(
967
1225
  "/api/publish/v3/package/compile/status",
968
1226
  { params: { appId: req.appId, pkgIds: req.pkgIds } }
969
1227
  );
@@ -972,7 +1230,7 @@ var PublishService = class {
972
1230
  /** 查询应用所有版本类型的版本列表 */
973
1231
  static async queryBriefInfoList(req) {
974
1232
  const { appId, ...body } = req;
975
- const response = await agcClient.post(
1233
+ const response = await connectApiClient.post(
976
1234
  "/api/publish/v3/version/brief-info/list",
977
1235
  body,
978
1236
  { headers: appIdHeaders(appId) }
@@ -982,7 +1240,7 @@ var PublishService = class {
982
1240
  /** 查询应用未处理的问题工单 */
983
1241
  static async queryVersionVoc(req) {
984
1242
  const { appId, ...body } = req;
985
- const response = await agcClient.post(
1243
+ const response = await connectApiClient.post(
986
1244
  "/api/publish/v1/app-voc/version-voc",
987
1245
  body,
988
1246
  { headers: appIdHeaders(appId) }
@@ -991,7 +1249,7 @@ var PublishService = class {
991
1249
  }
992
1250
  /** 查询需要上传的资质文件信息 */
993
1251
  static async queryTagQualDependent() {
994
- const response = await agcClient.get(
1252
+ const response = await connectApiClient.get(
995
1253
  "/api/publish/v2/tag-qual-dependent"
996
1254
  );
997
1255
  return response.data;
@@ -999,7 +1257,7 @@ var PublishService = class {
999
1257
  /** 提交资质审核任务 */
1000
1258
  static async submitQualificationReview(req) {
1001
1259
  const { appId, ...body } = req;
1002
- const response = await agcClient.post(
1260
+ const response = await connectApiClient.post(
1003
1261
  "/api/publish/v2/qualification-review-task",
1004
1262
  body,
1005
1263
  { headers: appIdHeaders(appId) }
@@ -1008,7 +1266,7 @@ var PublishService = class {
1008
1266
  }
1009
1267
  /** 查询资质审核任务详情 */
1010
1268
  static async getQualificationReview(req) {
1011
- const response = await agcClient.get(
1269
+ const response = await connectApiClient.get(
1012
1270
  "/api/publish/v2/qualification-review-task",
1013
1271
  {
1014
1272
  params: { tagIds: req.tagIds },
@@ -1020,7 +1278,7 @@ var PublishService = class {
1020
1278
  /** 修改资质审核任务 */
1021
1279
  static async updateQualificationReview(req) {
1022
1280
  const { appId, ...body } = req;
1023
- const response = await agcClient.put(
1281
+ const response = await connectApiClient.put(
1024
1282
  "/api/publish/v2/qualification-review-task",
1025
1283
  body,
1026
1284
  { headers: appIdHeaders(appId) }
@@ -1029,7 +1287,7 @@ var PublishService = class {
1029
1287
  }
1030
1288
  /** 撤销资质审核任务 */
1031
1289
  static async cancelQualificationReview(req) {
1032
- const response = await agcClient.put(
1290
+ const response = await connectApiClient.put(
1033
1291
  "/api/publish/v2/qualification-review-task/cancel",
1034
1292
  { taskId: req.taskId },
1035
1293
  { headers: appIdHeaders(req.appId) }
@@ -1038,7 +1296,7 @@ var PublishService = class {
1038
1296
  }
1039
1297
  /** 删除资质审核任务 */
1040
1298
  static async deleteQualificationReview(req) {
1041
- const response = await agcClient.delete(
1299
+ const response = await connectApiClient.delete(
1042
1300
  "/api/publish/v2/qualification-review-task",
1043
1301
  {
1044
1302
  data: { tagIds: req.tagIds },
@@ -1050,7 +1308,7 @@ var PublishService = class {
1050
1308
  /** 新建用户协议 / 隐私政策协议(body.type 区分) */
1051
1309
  static async createAgreement(req) {
1052
1310
  const { appId, ...body } = req;
1053
- const response = await agcClient.post(
1311
+ const response = await connectApiClient.post(
1054
1312
  "/api/publish/v2/agreement",
1055
1313
  body,
1056
1314
  { headers: appIdHeaders(appId) }
@@ -1060,7 +1318,7 @@ var PublishService = class {
1060
1318
  /** 查询用户协议 / 隐私政策协议列表(body.type 区分) */
1061
1319
  static async listAgreements(req) {
1062
1320
  const { appId, ...body } = req;
1063
- const response = await agcClient.post(
1321
+ const response = await connectApiClient.post(
1064
1322
  "/api/publish/v2/agreement/list",
1065
1323
  body,
1066
1324
  { headers: appIdHeaders(appId) }
@@ -1070,7 +1328,7 @@ var PublishService = class {
1070
1328
  /** 更新用户协议 / 隐私政策协议 */
1071
1329
  static async updateAgreement(req) {
1072
1330
  const { appId, ...body } = req;
1073
- const response = await agcClient.put(
1331
+ const response = await connectApiClient.put(
1074
1332
  "/api/publish/v2/agreement",
1075
1333
  body,
1076
1334
  { headers: appIdHeaders(appId) }
@@ -1080,7 +1338,7 @@ var PublishService = class {
1080
1338
  /** 提交隐私政策协议 */
1081
1339
  static async submitPrivacyAgreement(req) {
1082
1340
  const { appId, ...body } = req;
1083
- const response = await agcClient.put(
1341
+ const response = await connectApiClient.put(
1084
1342
  "/api/publish/v2/agreement/submit",
1085
1343
  body,
1086
1344
  { headers: appIdHeaders(appId) }
@@ -1090,7 +1348,7 @@ var PublishService = class {
1090
1348
  /** 申请年龄分级 */
1091
1349
  static async applyAgeRating(req) {
1092
1350
  const { appId, releaseType, releasePhase, ...body } = req;
1093
- const response = await agcClient.post(
1351
+ const response = await connectApiClient.post(
1094
1352
  "/api/publish/v2/app-age-rating",
1095
1353
  body,
1096
1354
  {
@@ -1103,16 +1361,16 @@ var PublishService = class {
1103
1361
  /** 提交发布 */
1104
1362
  static async submitApp(req) {
1105
1363
  const { appId, ...body } = req;
1106
- const response = await agcClient.post(
1364
+ const response = await connectApiClient.post(
1107
1365
  "/api/publish/v3/app-submit",
1108
1366
  body,
1109
- { headers: appIdHeaders(appId) }
1367
+ { params: { appId } }
1110
1368
  );
1111
1369
  return response.data;
1112
1370
  }
1113
1371
  /** 撤销审核 */
1114
1372
  static async cancelReview(req) {
1115
- const response = await agcClient.put(
1373
+ const response = await connectApiClient.put(
1116
1374
  "/api/publish/v3/version/on-shelf/cancel",
1117
1375
  { versionId: req.versionId },
1118
1376
  { headers: appIdHeaders(req.appId) }
@@ -1121,7 +1379,7 @@ var PublishService = class {
1121
1379
  }
1122
1380
  /** 下架应用 */
1123
1381
  static async shelfOff(req) {
1124
- const response = await agcClient.post(
1382
+ const response = await connectApiClient.post(
1125
1383
  "/api/publish/v2/app-shelf-off",
1126
1384
  null,
1127
1385
  {
@@ -1140,42 +1398,42 @@ var PublishService = class {
1140
1398
  var ProjectService = class {
1141
1399
  /** 查询团队下的项目列表(Project Management API) */
1142
1400
  static async listProjects() {
1143
- const response = await agcClient.get("/api/project-service/v1/projects");
1401
+ const response = await connectApiClient.get("/api/project-service/v1/projects");
1144
1402
  return response.data;
1145
1403
  }
1146
1404
  };
1147
1405
 
1148
1406
  // src/services/upload.ts
1149
1407
  var import_axios4 = __toESM(require("axios"));
1150
- var import_fs6 = __toESM(require("fs"));
1151
- var import_path5 = __toESM(require("path"));
1408
+ var import_fs7 = __toESM(require("fs"));
1409
+ var import_path6 = __toESM(require("path"));
1152
1410
  function pickObjectId(res) {
1153
1411
  return res.urlInfo?.objectId || res.objectId;
1154
1412
  }
1155
1413
  var UploadService = class {
1156
1414
  // ================= Raw APIs =================
1157
1415
  static async getUploadUrl(req) {
1158
- const response = await agcClient.get("/api/publish/v2/upload-url/for-obs", {
1416
+ const response = await connectApiClient.get("/api/publish/v2/upload-url/for-obs", {
1159
1417
  params: req
1160
1418
  });
1161
1419
  return response.data;
1162
1420
  }
1163
1421
  static async initMultipart(req) {
1164
- const response = await agcClient.post("/api/publish/v2/upload/multipart/init", null, {
1422
+ const response = await connectApiClient.post("/api/publish/v2/upload/multipart/init", null, {
1165
1423
  params: req
1166
1424
  });
1167
1425
  return response.data;
1168
1426
  }
1169
1427
  static async getMultipartParts(req) {
1170
1428
  const { objectId, nspUploadId, parts } = req;
1171
- const response = await agcClient.post("/api/publish/v2/upload/multipart/parts", parts, {
1429
+ const response = await connectApiClient.post("/api/publish/v2/upload/multipart/parts", parts, {
1172
1430
  params: { objectId, nspUploadId }
1173
1431
  });
1174
1432
  return response.data;
1175
1433
  }
1176
1434
  static async composeMultipart(req) {
1177
1435
  const { objectId, nspUploadId, parts } = req;
1178
- const response = await agcClient.post("/api/publish/v2/upload/multipart/compose", parts, {
1436
+ const response = await connectApiClient.post("/api/publish/v2/upload/multipart/compose", parts, {
1179
1437
  params: { objectId, nspUploadId }
1180
1438
  });
1181
1439
  return response.data;
@@ -1187,8 +1445,8 @@ var UploadService = class {
1187
1445
  * 仅完成 OBS 落盘;HarmonyOS `.app` 还须调用更新应用软件包信息,HarmonyOS 开发者中心才会有记录。
1188
1446
  */
1189
1447
  static async uploadFile(options) {
1190
- const stat = import_fs6.default.statSync(options.filePath);
1191
- const fileName = import_path5.default.basename(options.filePath) || "unknown";
1448
+ const stat = import_fs7.default.statSync(options.filePath);
1449
+ const fileName = import_path6.default.basename(options.filePath) || "unknown";
1192
1450
  if (stat.size < 5 * 1024 * 1024) {
1193
1451
  return this.uploadSingleFile(options, fileName, stat.size);
1194
1452
  }
@@ -1229,7 +1487,7 @@ var UploadService = class {
1229
1487
  );
1230
1488
  }
1231
1489
  const { url, headers } = urlRes.urlInfo;
1232
- const fileStream = import_fs6.default.createReadStream(options.filePath);
1490
+ const fileStream = import_fs7.default.createReadStream(options.filePath);
1233
1491
  await import_axios4.default.put(url, fileStream, {
1234
1492
  headers: this.buildObsPutHeaders(headers, contentLength),
1235
1493
  maxBodyLength: Infinity,
@@ -1270,7 +1528,7 @@ var UploadService = class {
1270
1528
  if (!uploadInfoMap) {
1271
1529
  throw new Error(`Failed to get parts upload URL: ${JSON.stringify(partsRes.ret)}`);
1272
1530
  }
1273
- const fd = import_fs6.default.openSync(options.filePath, "r");
1531
+ const fd = import_fs7.default.openSync(options.filePath, "r");
1274
1532
  const composeReqBody = {};
1275
1533
  for (let i = 1; i <= partsCount; i++) {
1276
1534
  const propKey = `additionalProp${i}`;
@@ -1279,7 +1537,7 @@ var UploadService = class {
1279
1537
  const end = Math.min(start + partSize, fileSize);
1280
1538
  const length = end - start;
1281
1539
  const buffer = Buffer.alloc(length);
1282
- import_fs6.default.readSync(fd, buffer, 0, length, start);
1540
+ import_fs7.default.readSync(fd, buffer, 0, length, start);
1283
1541
  const res = await import_axios4.default.put(uploadInfo.url, buffer, {
1284
1542
  headers: this.buildObsPutHeaders(uploadInfo.headers, length),
1285
1543
  maxBodyLength: Infinity,
@@ -1291,7 +1549,7 @@ var UploadService = class {
1291
1549
  etag
1292
1550
  };
1293
1551
  }
1294
- import_fs6.default.closeSync(fd);
1552
+ import_fs7.default.closeSync(fd);
1295
1553
  await this.composeMultipart({
1296
1554
  objectId,
1297
1555
  nspUploadId,
@@ -1305,20 +1563,20 @@ var UploadService = class {
1305
1563
  var ProvisionService = class {
1306
1564
  // ================= Certificates =================
1307
1565
  static async createCert(req) {
1308
- const response = await agcClient.post("/api/publish/v3/cert", req);
1566
+ const response = await connectApiClient.post("/api/publish/v3/cert", req);
1309
1567
  return response.data;
1310
1568
  }
1311
1569
  static async getCertList(req) {
1312
- const response = await agcClient.post("/api/publish/v3/cert/list", req);
1570
+ const response = await connectApiClient.post("/api/publish/v3/cert/list", req);
1313
1571
  return response.data;
1314
1572
  }
1315
1573
  static async deleteCert(req) {
1316
- const response = await agcClient.post("/api/publish/v2/cert/delete", req);
1574
+ const response = await connectApiClient.post("/api/publish/v2/cert/delete", req);
1317
1575
  return response.data;
1318
1576
  }
1319
1577
  // ================= Devices =================
1320
1578
  static async addDevice(req) {
1321
- const response = await agcClient.post("/api/publish/v2/device", req);
1579
+ const response = await connectApiClient.post("/api/publish/v2/device", req);
1322
1580
  return response.data;
1323
1581
  }
1324
1582
  static async getDeviceList(req) {
@@ -1327,16 +1585,16 @@ var ProvisionService = class {
1327
1585
  if (req.fromRecCount !== void 0) params.fromRecCount = req.fromRecCount;
1328
1586
  if (req.maxReqCount !== void 0) params.maxReqCount = req.maxReqCount;
1329
1587
  if (req.order !== void 0) params.order = req.order;
1330
- const response = await agcClient.get("/api/publish/v2/device/list", { params });
1588
+ const response = await connectApiClient.get("/api/publish/v2/device/list", { params });
1331
1589
  return response.data;
1332
1590
  }
1333
1591
  static async deleteDevice(req) {
1334
- const response = await agcClient.post("/api/publish/v2/device/delete", req);
1592
+ const response = await connectApiClient.post("/api/publish/v2/device/delete", req);
1335
1593
  return response.data;
1336
1594
  }
1337
1595
  // ================= Profile / Provision =================
1338
1596
  static async createProvision(req) {
1339
- const response = await agcClient.post("/api/publish/v3/provision", req);
1597
+ const response = await connectApiClient.post("/api/publish/v3/provision", req);
1340
1598
  return response.data;
1341
1599
  }
1342
1600
  static async getProvisionList(req) {
@@ -1345,18 +1603,18 @@ var ProvisionService = class {
1345
1603
  if (req.maxReqCount !== void 0) params.maxReqCount = req.maxReqCount;
1346
1604
  const headers = { appId: req.appId };
1347
1605
  if (req.provisionId) headers.provisionId = req.provisionId;
1348
- const response = await agcClient.get("/api/publish/v3/provision/list", {
1606
+ const response = await connectApiClient.get("/api/publish/v3/provision/list", {
1349
1607
  params,
1350
1608
  headers
1351
1609
  });
1352
1610
  return response.data;
1353
1611
  }
1354
1612
  static async updateProvision(req) {
1355
- const response = await agcClient.put("/api/publish/v3/provision", req);
1613
+ const response = await connectApiClient.put("/api/publish/v3/provision", req);
1356
1614
  return response.data;
1357
1615
  }
1358
1616
  static async deleteProvision(req) {
1359
- const response = await agcClient.delete("/api/publish/v2/provision", {
1617
+ const response = await connectApiClient.delete("/api/publish/v2/provision", {
1360
1618
  params: { id: req.id }
1361
1619
  });
1362
1620
  return response.data;
@@ -1364,7 +1622,7 @@ var ProvisionService = class {
1364
1622
  // ================= Fingerprint =================
1365
1623
  static async addFingerprint(req) {
1366
1624
  const { appId, ...body } = req;
1367
- const response = await agcClient.post(
1625
+ const response = await connectApiClient.post(
1368
1626
  "/api/provision/v1/fingerprints",
1369
1627
  body,
1370
1628
  { headers: { appId } }
@@ -1372,14 +1630,14 @@ var ProvisionService = class {
1372
1630
  return response.data;
1373
1631
  }
1374
1632
  static async getFingerprintList(req) {
1375
- const response = await agcClient.get("/api/provision/v1/fingerprints", {
1633
+ const response = await connectApiClient.get("/api/provision/v1/fingerprints", {
1376
1634
  headers: { appId: req.appId }
1377
1635
  });
1378
1636
  return response.data;
1379
1637
  }
1380
1638
  static async deleteFingerprint(req) {
1381
1639
  const { appId, ...body } = req;
1382
- const response = await agcClient.delete(
1640
+ const response = await connectApiClient.delete(
1383
1641
  "/api/provision/v1/fingerprints",
1384
1642
  { headers: { appId }, data: body }
1385
1643
  );
@@ -1389,7 +1647,7 @@ var ProvisionService = class {
1389
1647
  /** 查询可申请的 ACL 权限列表 */
1390
1648
  static async getEligibleACL(req) {
1391
1649
  const { appId, ...body } = req;
1392
- const response = await agcClient.post(
1650
+ const response = await connectApiClient.post(
1393
1651
  "/api/provision/v1/user/permission/apply/list",
1394
1652
  body,
1395
1653
  { headers: { appId } }
@@ -1398,7 +1656,7 @@ var ProvisionService = class {
1398
1656
  }
1399
1657
  static async applyACL(req) {
1400
1658
  const { appId, ...body } = req;
1401
- const response = await agcClient.post(
1659
+ const response = await connectApiClient.post(
1402
1660
  "/api/provision/v1/user/permission/apply",
1403
1661
  body,
1404
1662
  { headers: { appId } }
@@ -1406,14 +1664,14 @@ var ProvisionService = class {
1406
1664
  return response.data;
1407
1665
  }
1408
1666
  static async getACLStatus(req) {
1409
- const response = await agcClient.get(
1667
+ const response = await connectApiClient.get(
1410
1668
  "/api/provision/v1/user/permission/apply/status",
1411
1669
  { headers: { appId: req.appId } }
1412
1670
  );
1413
1671
  return response.data;
1414
1672
  }
1415
1673
  static async getACLQuery(req) {
1416
- const response = await agcClient.get("/api/provision/v1/user/permission", {
1674
+ const response = await connectApiClient.get("/api/provision/v1/user/permission", {
1417
1675
  headers: { appId: req.appId }
1418
1676
  });
1419
1677
  return response.data;
@@ -1426,6 +1684,6 @@ var ProvisionService = class {
1426
1684
  ProvisionService,
1427
1685
  PublishService,
1428
1686
  UploadService,
1429
- agcClient,
1687
+ connectApiClient,
1430
1688
  getConfig
1431
1689
  });