connect-api-cli 1.1.6 → 1.1.9

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, "_");
@@ -369,25 +419,197 @@ function clearOAuthTeamIdCache() {
369
419
  cachedTeamId = void 0;
370
420
  }
371
421
 
422
+ // src/core/deveco-token.ts
423
+ var import_crypto = require("crypto");
424
+ var import_fs4 = require("fs");
425
+ var import_os2 = require("os");
426
+ var import_path3 = require("path");
427
+ var ALGORITHM = "aes-256-gcm";
428
+ var KEY_LENGTH = 32;
429
+ var KEK_VERSIONS = ["kek-v1", "kek-v2", "kek-v3"];
430
+ var CLI_SOURCE_ALIASES = ["cli", "deveco", "deveco-cli"];
431
+ var SOURCE_APP_NAMES = {
432
+ "deveco-code": "deveco"
433
+ };
434
+ function decryptAesGcm(ciphertext, key, iv, authTag) {
435
+ const decipher = (0, import_crypto.createDecipheriv)(ALGORITHM, key, iv);
436
+ decipher.setAuthTag(authTag);
437
+ return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
438
+ }
439
+ function readJson(filePath) {
440
+ return JSON.parse((0, import_fs4.readFileSync)(filePath, "utf8"));
441
+ }
442
+ function requireFile(filePath, label) {
443
+ try {
444
+ return (0, import_fs4.readFileSync)(filePath);
445
+ } catch (err) {
446
+ const code = err.code;
447
+ if (code === "ENOENT") {
448
+ throw new Error(`\u627E\u4E0D\u5230 ${label}: ${filePath}`);
449
+ }
450
+ if (code === "EACCES" || code === "EPERM") {
451
+ throw new Error(`\u65E0\u6743\u9650\u8BFB\u53D6 ${label}: ${filePath}`);
452
+ }
453
+ throw err;
454
+ }
455
+ }
456
+ function loadKek(kekId, keysDir) {
457
+ if (!KEK_VERSIONS.includes(kekId)) {
458
+ throw new Error(`\u975E\u6CD5 kekId: ${kekId}\uFF08\u671F\u671B ${KEK_VERSIONS.join("/")}\uFF09`);
459
+ }
460
+ const rootKeyPath = (0, import_path3.resolve)((0, import_path3.join)(keysDir, `${kekId}.bin`));
461
+ const keysDirBase = (0, import_path3.resolve)(keysDir);
462
+ if (!rootKeyPath.startsWith(keysDirBase)) {
463
+ throw new Error("kekId \u89E3\u6790\u7ED3\u679C\u8D85\u51FA keys \u76EE\u5F55\u8303\u56F4");
464
+ }
465
+ const kek = requireFile(rootKeyPath, "KEK \u6839\u5BC6\u94A5");
466
+ if (kek.length !== KEY_LENGTH) {
467
+ throw new Error(`KEK \u957F\u5EA6\u5F02\u5E38: ${kek.length} \u5B57\u8282\uFF08\u671F\u671B ${KEY_LENGTH}\uFF09`);
468
+ }
469
+ return kek;
470
+ }
471
+ function decryptToken(tokenDir, keysDir) {
472
+ const blob = readJson((0, import_path3.join)(tokenDir, "token.enc"));
473
+ if (blob.algorithm !== ALGORITHM) {
474
+ throw new Error(`\u672A\u77E5\u7B97\u6CD5: ${blob.algorithm}`);
475
+ }
476
+ if (!blob.ciphertext || !blob.iv || !blob.authTag) {
477
+ throw new Error(`token.enc \u683C\u5F0F\u5F02\u5E38\uFF08\u7F3A\u5C11 ciphertext/iv/authTag\uFF09: ${(0, import_path3.join)(tokenDir, "token.enc")}`);
478
+ }
479
+ const wrapped = readJson((0, import_path3.join)(tokenDir, "token.dek"));
480
+ if (!wrapped.encryptedDek || !wrapped.iv || !wrapped.authTag) {
481
+ throw new Error(`token.dek \u683C\u5F0F\u5F02\u5E38\uFF08\u7F3A\u5C11 encryptedDek/iv/authTag\uFF09: ${(0, import_path3.join)(tokenDir, "token.dek")}`);
482
+ }
483
+ const kek = loadKek(wrapped.kekId, keysDir);
484
+ const dek = decryptAesGcm(
485
+ Buffer.from(wrapped.encryptedDek, "base64"),
486
+ kek,
487
+ Buffer.from(wrapped.iv, "base64"),
488
+ Buffer.from(wrapped.authTag, "base64")
489
+ );
490
+ if (dek.length !== KEY_LENGTH) {
491
+ throw new Error(`DEK \u957F\u5EA6\u5F02\u5E38: ${dek.length} \u5B57\u8282\uFF08\u671F\u671B ${KEY_LENGTH}\uFF09`);
492
+ }
493
+ return decryptAesGcm(
494
+ Buffer.from(blob.ciphertext, "base64"),
495
+ dek,
496
+ Buffer.from(blob.iv, "base64"),
497
+ Buffer.from(blob.authTag, "base64")
498
+ ).toString("utf8");
499
+ }
500
+ function extractJwt(plaintext) {
501
+ let jwt = plaintext;
502
+ try {
503
+ const parsed = JSON.parse(plaintext);
504
+ if (parsed && typeof parsed.access_token === "string") {
505
+ jwt = parsed.access_token;
506
+ }
507
+ } catch {
508
+ }
509
+ const parts = jwt.split(".");
510
+ if (parts.length !== 3) {
511
+ 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");
512
+ }
513
+ try {
514
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
515
+ if (typeof payload.exp === "number") {
516
+ return { jwt, expMs: payload.exp * 1e3 };
517
+ }
518
+ } catch {
519
+ }
520
+ return { jwt };
521
+ }
522
+ function configHome() {
523
+ return process.env.XDG_CONFIG_HOME || (0, import_path3.join)((0, import_os2.homedir)(), ".config");
524
+ }
525
+ function candidatesFor(source) {
526
+ const home = (0, import_os2.homedir)();
527
+ if (CLI_SOURCE_ALIASES.includes(source)) {
528
+ if (process.env.DEVECO_CLI_AUTH_SOURCE?.trim() === "deveco-code") {
529
+ return candidatesFor("deveco-code").map((c) => ({
530
+ ...c,
531
+ source,
532
+ via: "DEVECO_CLI_AUTH_SOURCE=deveco-code"
533
+ }));
534
+ }
535
+ return [
536
+ {
537
+ source,
538
+ tokenDir: process.env.DEVECO_CLI_DATA_DIR || (0, import_path3.join)(home, ".config", "deveco-cli"),
539
+ keysDir: (0, import_path3.join)(home, ".local", "share", "deveco-cli", "keys"),
540
+ via: process.env.DEVECO_CLI_DATA_DIR ? "DEVECO_CLI_DATA_DIR" : "\u5E73\u53F0\u9ED8\u8BA4\u8DEF\u5F84"
541
+ }
542
+ ];
543
+ }
544
+ const appName = SOURCE_APP_NAMES[source];
545
+ const viaEnv = process.env.DEVECO_CODE_AUTH_DIR?.trim();
546
+ if (source === "deveco-code" && viaEnv) {
547
+ const tokenDir = (0, import_path3.resolve)(viaEnv);
548
+ return [{ source, tokenDir, keysDir: (0, import_path3.join)(tokenDir, "keys"), via: "DEVECO_CODE_AUTH_DIR" }];
549
+ }
550
+ let dirs;
551
+ if (process.platform === "win32") {
552
+ const appData = process.env.APPDATA || (0, import_path3.join)(home, "AppData", "Roaming");
553
+ dirs = [(0, import_path3.join)(appData, appName), (0, import_path3.join)(home, ".config", appName)];
554
+ } else if (process.platform === "darwin") {
555
+ dirs = [
556
+ (0, import_path3.join)(configHome(), appName),
557
+ (0, import_path3.join)(home, "Library", "Application Support", appName)
558
+ ];
559
+ } else {
560
+ dirs = [(0, import_path3.join)(configHome(), appName)];
561
+ }
562
+ return dirs.map((tokenDir) => ({
563
+ source,
564
+ tokenDir,
565
+ keysDir: (0, import_path3.join)(tokenDir, "keys"),
566
+ via: "\u5E73\u53F0\u9ED8\u8BA4\u8DEF\u5F84"
567
+ }));
568
+ }
569
+ function resolveLocation(source) {
570
+ const candidates = candidatesFor(source);
571
+ const hit = candidates.find((c) => (0, import_fs4.existsSync)((0, import_path3.join)(c.tokenDir, "token.enc")));
572
+ if (hit) {
573
+ return hit;
574
+ }
575
+ const tried = candidates.map((c) => ` - ${c.tokenDir}`).join("\n");
576
+ throw new Error(
577
+ `[${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
578
+ ${tried}`
579
+ );
580
+ }
581
+ function loadDevecoLocalToken(source, authDir) {
582
+ const location = authDir ? { source: "dir", tokenDir: authDir, keysDir: (0, import_path3.join)(authDir, "keys"), via: "AGC_DEVECO_AUTH_DIR" } : resolveLocation(source);
583
+ const plaintext = decryptToken(location.tokenDir, location.keysDir);
584
+ const { jwt, expMs } = extractJwt(plaintext);
585
+ return { jwt, expMs, location };
586
+ }
587
+
372
588
  // src/core/auth-mgr.ts
373
589
  var crypto2 = __toESM(require("crypto"));
374
590
  var http = __toESM(require("http"));
375
591
  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"));
592
+ var import_fs5 = __toESM(require("fs"));
593
+ var import_path4 = __toESM(require("path"));
594
+ var import_os3 = __toESM(require("os"));
595
+ var DEVECO_CACHE_TTL_MS = 30 * 60 * 1e3;
379
596
  var AuthManager = class {
380
- static cacheFile = import_path3.default.join(import_os2.default.homedir(), ".connect-api-cli-token.json");
597
+ static cacheFile = import_path4.default.join(import_os3.default.homedir(), ".connect-api-cli-token.json");
598
+ static pendingOAuthLogin;
381
599
  /**
382
600
  * 获取当前生效的 access token,并具备自动刷新能力:
383
601
  * - OAuth 模式:token 过期时优先用 refreshToken 自动刷新,无需重新登录
384
602
  * - client_credentials / service_account:过期后重新换取 / 重新签 JWT
603
+ * - deveco:过期后重新解密本地登录态并 refresh 换取
604
+ *
605
+ * force 跳过缓存(供 DevEco 和自动模式的 401 重试使用)。
385
606
  */
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) {
607
+ static async getAccessToken(force = false) {
608
+ const { config: config2, cache } = this.getStatus();
609
+ return this.getToken(config2, cache, force);
610
+ }
611
+ static async getToken(cfg, cache, force = false) {
612
+ if (!force && cache && cache.expiresAt > Date.now() + 5 * 60 * 1e3) {
391
613
  return cache.accessToken;
392
614
  }
393
615
  if (cfg.authMode === "oauth" && cache?.refreshToken) {
@@ -409,18 +631,31 @@ var AuthManager = class {
409
631
  this.clearCache();
410
632
  }
411
633
  }
412
- return this.acquire();
634
+ return this.acquire(cfg);
413
635
  }
414
636
  /** 登录入口:按当前认证模式获取并缓存 token */
415
637
  static async login() {
416
638
  clearOAuthTeamIdCache();
417
- return this.acquire();
639
+ return this.acquire(getConfig());
418
640
  }
419
- /** 按当前认证模式获取 token(client_credentials / service_account / oauth) */
420
- static async acquire() {
421
- const cfg = getConfig();
641
+ /** 按当前认证模式获取 token(client_credentials / service_account / oauth / deveco) */
642
+ static async acquire(cfg) {
422
643
  if (cfg.authMode === "oauth") {
423
- return this.loginOAuth();
644
+ this.pendingOAuthLogin ??= this.loginOAuth(cfg).finally(() => {
645
+ this.pendingOAuthLogin = void 0;
646
+ });
647
+ return this.pendingOAuthLogin;
648
+ }
649
+ if (cfg.authMode === "deveco") {
650
+ try {
651
+ return await this.acquireDevecoToken(cfg);
652
+ } catch (err) {
653
+ if (process.env.AGC_AUTH_MODE !== void 0) throw err;
654
+ const oauthConfig = getConfig("oauth");
655
+ const cache = this.matchingCache(oauthConfig, this.readCache());
656
+ console.error("\u65E0\u6CD5\u4F7F\u7528\u672C\u5730 DevEco \u767B\u5F55\u6001\uFF0C\u6539\u7528\u534E\u4E3A\u8D26\u53F7 OAuth\u3002");
657
+ return this.getToken(oauthConfig, cache);
658
+ }
424
659
  }
425
660
  if (cfg.authMode === "service_account") {
426
661
  if (!cfg.serviceAccount) {
@@ -451,9 +686,8 @@ var AuthManager = class {
451
686
  throw new Error(`Failed to get token: ${JSON.stringify(res.ret)}`);
452
687
  }
453
688
  /** OAuth 授权码登录:启动本地回调服务器 + 打开浏览器 */
454
- static loginOAuth() {
455
- return new Promise((resolve, reject) => {
456
- const cfg = getConfig();
689
+ static loginOAuth(cfg) {
690
+ return new Promise((resolve2, reject) => {
457
691
  const redirectUri = cfg.oauth.redirectUri;
458
692
  const port = Number(new URL(redirectUri).port || 80);
459
693
  const state = crypto2.randomBytes(32).toString("hex");
@@ -469,6 +703,7 @@ var AuthManager = class {
469
703
  }
470
704
  const token = await AuthService.getOAuthToken(code, redirectUri);
471
705
  const expiresAt = Date.now() + token.expireTime * 1e3;
706
+ clearOAuthTeamIdCache();
472
707
  this.writeCache({
473
708
  accessToken: token.accessToken,
474
709
  expiresAt,
@@ -480,7 +715,7 @@ var AuthManager = class {
480
715
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
481
716
  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
717
  server.close();
483
- resolve(token.accessToken);
718
+ resolve2(token.accessToken);
484
719
  } catch (err) {
485
720
  server.close();
486
721
  reject(err instanceof Error ? err : new Error(String(err)));
@@ -492,19 +727,48 @@ var AuthManager = class {
492
727
  });
493
728
  server.listen(port, () => {
494
729
  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}`);
730
+ console.error("\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u5B8C\u6210\u534E\u4E3A\u8D26\u53F7\u6388\u6743...");
731
+ console.error(`\u82E5\u6D4F\u89C8\u5668\u672A\u81EA\u52A8\u6253\u5F00\uFF0C\u8BF7\u8BBF\u95EE: ${authUrl}`);
497
732
  openBrowser(authUrl);
498
733
  });
499
734
  });
500
735
  }
501
- /** 查询缓存状态(供 status 命令显示) */
736
+ /**
737
+ * deveco 模式:解密本地 DevEco 工具链登录态(只读),
738
+ * 用 JWT 调 jwToken/check(refresh=true)换取 access token 并缓存。
739
+ * 服务端不返回有效期:缓存取「本地 JWT 剩余寿命」与「30 分钟上限」的较小值。
740
+ */
741
+ static async acquireDevecoToken(cfg) {
742
+ const deveco = cfg.deveco;
743
+ const local = loadDevecoLocalToken(deveco.source, deveco.authDir);
744
+ const accessToken = await AuthService.checkDevecoJwtToken(local.jwt, true);
745
+ const jwtLimit = local.expMs !== void 0 ? local.expMs - 5 * 60 * 1e3 : Infinity;
746
+ this.writeCache({
747
+ accessToken,
748
+ expiresAt: Math.min(Date.now() + DEVECO_CACHE_TTL_MS, jwtLimit),
749
+ clientId: cfg.clientId,
750
+ domain: cfg.domain,
751
+ authMode: cfg.authMode
752
+ });
753
+ return accessToken;
754
+ }
755
+ /** 默认模式回退到 OAuth 后,后续命令继续使用该 OAuth 会话。 */
502
756
  static getStatus() {
503
- return this.readCache();
757
+ const config2 = getConfig();
758
+ const cache = this.readCache();
759
+ if (process.env.AGC_AUTH_MODE === void 0 && cache?.authMode === "oauth") {
760
+ const oauthConfig = getConfig("oauth");
761
+ const oauthCache = this.matchingCache(oauthConfig, cache);
762
+ if (oauthCache) return { config: oauthConfig, cache: oauthCache };
763
+ }
764
+ return { config: config2, cache: this.matchingCache(config2, cache) };
765
+ }
766
+ static matchingCache(cfg, cache) {
767
+ return cache?.authMode === cfg.authMode && cache.clientId === cfg.clientId && cache.domain === cfg.domain ? cache : null;
504
768
  }
505
769
  static readCache() {
506
770
  try {
507
- if (import_fs4.default.existsSync(this.cacheFile)) {
771
+ if (import_fs5.default.existsSync(this.cacheFile)) {
508
772
  const data = readPrivateFile(this.cacheFile);
509
773
  return JSON.parse(data);
510
774
  }
@@ -524,8 +788,8 @@ var AuthManager = class {
524
788
  static clearCache() {
525
789
  clearOAuthTeamIdCache();
526
790
  try {
527
- if (import_fs4.default.existsSync(this.cacheFile)) {
528
- import_fs4.default.unlinkSync(this.cacheFile);
791
+ if (import_fs5.default.existsSync(this.cacheFile)) {
792
+ import_fs5.default.unlinkSync(this.cacheFile);
529
793
  return true;
530
794
  }
531
795
  return false;
@@ -545,8 +809,8 @@ function openBrowser(url) {
545
809
  }
546
810
 
547
811
  // src/core/request-source.ts
548
- var import_fs5 = __toESM(require("fs"));
549
- var import_path4 = __toESM(require("path"));
812
+ var import_fs6 = __toESM(require("fs"));
813
+ var import_path5 = __toESM(require("path"));
550
814
  var REQUEST_SOURCE_HEADER = "Request-Source";
551
815
  var SOURCE_TOOL_NAME_HEADER = "Source-Tool-Name";
552
816
  var SKILL_CHANNEL = "skill";
@@ -686,15 +950,15 @@ function getRequestSource() {
686
950
  return agent ? `${agent}-skill` : SKILL_CHANNEL;
687
951
  }
688
952
  function readVersion() {
689
- const fromBuild = injected(true ? "1.1.6" : void 0);
953
+ const fromBuild = injected(true ? "1.1.9" : void 0);
690
954
  if (fromBuild) return fromBuild;
691
955
  const candidates = [
692
- import_path4.default.join(__dirname, "..", "..", "package.json"),
693
- import_path4.default.join(__dirname, "..", "package.json")
956
+ import_path5.default.join(__dirname, "..", "..", "package.json"),
957
+ import_path5.default.join(__dirname, "..", "package.json")
694
958
  ];
695
959
  for (const pkgPath of candidates) {
696
960
  try {
697
- const pkg = JSON.parse(import_fs5.default.readFileSync(pkgPath, "utf8"));
961
+ const pkg = JSON.parse(import_fs6.default.readFileSync(pkgPath, "utf8"));
698
962
  if (pkg.version) return pkg.version;
699
963
  } catch {
700
964
  }
@@ -718,7 +982,7 @@ function applySourceHeaders(headers) {
718
982
  }
719
983
 
720
984
  // src/core/http.ts
721
- var agcClient = import_axios3.default.create({ maxRedirects: 0 });
985
+ var connectApiClient = import_axios3.default.create({ maxRedirects: 0 });
722
986
  function setHeader(headers, name, value) {
723
987
  if (typeof headers?.set === "function") {
724
988
  headers.set(name, value);
@@ -740,7 +1004,7 @@ function getHeader(headers, name) {
740
1004
  return headers?.[name] ?? headers?.[name.toLowerCase()];
741
1005
  }
742
1006
  function applyAuthHeaders(headers, token, cfg, force = false) {
743
- if (cfg.authMode === "oauth") {
1007
+ if (cfg.authMode === "oauth" || cfg.authMode === "deveco") {
744
1008
  deleteHeader(headers, "Authorization");
745
1009
  deleteHeader(headers, "client_id");
746
1010
  setHeader(headers, "oauth2Token", token);
@@ -754,7 +1018,7 @@ function applyAuthHeaders(headers, token, cfg, force = false) {
754
1018
  setHeader(headers, "client_id", cfg.clientId);
755
1019
  }
756
1020
  }
757
- agcClient.interceptors.request.use(async (config2) => {
1021
+ connectApiClient.interceptors.request.use(async (config2) => {
758
1022
  const cfg = getConfig();
759
1023
  if (!config2.baseURL) {
760
1024
  config2.baseURL = `https://${cfg.domain}`;
@@ -765,10 +1029,11 @@ agcClient.interceptors.request.use(async (config2) => {
765
1029
  }
766
1030
  applySourceHeaders(config2.headers);
767
1031
  applyAuthHeaders(config2.headers, token, cfg);
768
- if (cfg.authMode === "oauth" && !getHeader(config2.headers, "teamId")) {
1032
+ if ((cfg.authMode === "oauth" || cfg.authMode === "deveco") && !getHeader(config2.headers, "teamId")) {
769
1033
  const teamId = await resolveOAuthTeamId(cfg, token);
770
1034
  if (teamId) {
771
1035
  setHeader(config2.headers, "teamId", teamId);
1036
+ config2._autoTeamId = true;
772
1037
  }
773
1038
  }
774
1039
  if (config2.data !== void 0 && !getHeader(config2.headers, "Content-Type")) {
@@ -778,7 +1043,7 @@ agcClient.interceptors.request.use(async (config2) => {
778
1043
  }, (error) => {
779
1044
  return Promise.reject(error);
780
1045
  });
781
- agcClient.interceptors.response.use(
1046
+ connectApiClient.interceptors.response.use(
782
1047
  (res) => res,
783
1048
  async (err) => {
784
1049
  const original = err.config;
@@ -787,12 +1052,13 @@ agcClient.interceptors.response.use(
787
1052
  original._retry = true;
788
1053
  try {
789
1054
  const cfg = getConfig();
790
- const newToken = await AuthManager.getAccessToken();
1055
+ const newToken = await AuthManager.getAccessToken(cfg.authMode === "deveco");
791
1056
  if (!original.headers) {
792
1057
  original.headers = {};
793
1058
  }
794
1059
  applyAuthHeaders(original.headers, newToken, cfg, true);
795
- return agcClient(original);
1060
+ if (original._autoTeamId) deleteHeader(original.headers, "teamId");
1061
+ return connectApiClient(original);
796
1062
  } catch (e) {
797
1063
  return Promise.reject(err);
798
1064
  }
@@ -821,7 +1087,7 @@ function withOptionalParams(base) {
821
1087
  var PublishService = class {
822
1088
  /** 查询应用包名对应的 appid */
823
1089
  static async getAppIdList(packageName, packageTypes) {
824
- const response = await agcClient.get("/api/publish/v2/appid-list", {
1090
+ const response = await connectApiClient.get("/api/publish/v2/appid-list", {
825
1091
  params: withOptionalParams({ packageName, packageTypes })
826
1092
  });
827
1093
  return response.data;
@@ -836,14 +1102,14 @@ var PublishService = class {
836
1102
  if (req.installationFree === 0 && packageName) {
837
1103
  body.packageName = packageName;
838
1104
  }
839
- const response = projectId ? await agcClient.post("/api/publish/v3/app", body, {
1105
+ const response = projectId ? await connectApiClient.post("/api/publish/v3/app", body, {
840
1106
  params: { projectId }
841
- }) : await agcClient.post("/api/publish/v3/app", body);
1107
+ }) : await connectApiClient.post("/api/publish/v3/app", body);
842
1108
  return response.data;
843
1109
  }
844
1110
  /** 查询团队账号下的成员角色列表 */
845
1111
  static async getMembersRoleList(req) {
846
- const response = await agcClient.get(
1112
+ const response = await connectApiClient.get(
847
1113
  "/api/publish/v3/members-role-list",
848
1114
  {
849
1115
  params: {
@@ -858,7 +1124,7 @@ var PublishService = class {
858
1124
  /** 查询应用信息 */
859
1125
  static async getAppInfo(appIdOrReq, lang) {
860
1126
  const req = typeof appIdOrReq === "string" ? { appId: appIdOrReq, lang } : appIdOrReq;
861
- const response = await agcClient.get("/api/publish/v3/app-info", {
1127
+ const response = await connectApiClient.get("/api/publish/v3/app-info", {
862
1128
  params: withOptionalParams({
863
1129
  appId: req.appId,
864
1130
  lang: req.lang,
@@ -871,7 +1137,7 @@ var PublishService = class {
871
1137
  /** 更新应用基本信息 */
872
1138
  static async updateAppInfo(req) {
873
1139
  const { appId, releaseType, releasePhase, ...body } = req;
874
- const response = await agcClient.put(
1140
+ const response = await connectApiClient.put(
875
1141
  "/api/publish/v3/app-info",
876
1142
  body,
877
1143
  {
@@ -883,7 +1149,7 @@ var PublishService = class {
883
1149
  /** 更新应用语言信息 */
884
1150
  static async updateLanguageInfo(req) {
885
1151
  const { appId, releaseType, releasePhase, ...body } = req;
886
- const response = await agcClient.put(
1152
+ const response = await connectApiClient.put(
887
1153
  "/api/publish/v3/app-language-info",
888
1154
  body,
889
1155
  {
@@ -894,7 +1160,7 @@ var PublishService = class {
894
1160
  }
895
1161
  /** 删除应用语言信息 */
896
1162
  static async deleteLanguageInfo(req) {
897
- const response = await agcClient.delete(
1163
+ const response = await connectApiClient.delete(
898
1164
  "/api/publish/v2/app-language-info",
899
1165
  {
900
1166
  params: withOptionalParams({
@@ -909,7 +1175,7 @@ var PublishService = class {
909
1175
  /** 更新应用文件信息(图标/截图/视频等) */
910
1176
  static async updateAppFileInfo(req) {
911
1177
  const { appId, releaseType, releasePhase, ...body } = req;
912
- const response = await agcClient.put(
1178
+ const response = await connectApiClient.put(
913
1179
  "/api/publish/v3/app-file-info",
914
1180
  body,
915
1181
  {
@@ -921,7 +1187,7 @@ var PublishService = class {
921
1187
  /** 更新应用软件包信息(OBS 上传后上报,HarmonyOS 开发者中心才会出现记录) */
922
1188
  static async updateAppPackageInfo(req) {
923
1189
  const { appId, releaseType, releasePhase, fileName, objectId } = req;
924
- const response = await agcClient.put(
1190
+ const response = await connectApiClient.put(
925
1191
  "/api/publish/v3/app-package-info",
926
1192
  { fileName, objectId },
927
1193
  {
@@ -933,7 +1199,7 @@ var PublishService = class {
933
1199
  /** 更新版本上架时间 */
934
1200
  static async updateReleaseTime(req) {
935
1201
  const { appId, ...body } = req;
936
- const response = await agcClient.put(
1202
+ const response = await connectApiClient.put(
937
1203
  "/api/publish/v2/on-shelf-time",
938
1204
  body,
939
1205
  { params: { appId } }
@@ -943,7 +1209,7 @@ var PublishService = class {
943
1209
  /** 更新分阶段发布 */
944
1210
  static async updatePhasedRelease(req) {
945
1211
  const { appId, ...body } = req;
946
- const response = await agcClient.put(
1212
+ const response = await connectApiClient.put(
947
1213
  "/api/publish/v2/version/phased-release",
948
1214
  body,
949
1215
  { headers: appIdHeaders(appId) }
@@ -952,7 +1218,7 @@ var PublishService = class {
952
1218
  }
953
1219
  /** 查询应用软件包信息 */
954
1220
  static async getPackageInfo(req) {
955
- const response = await agcClient.get(
1221
+ const response = await connectApiClient.get(
956
1222
  "/api/publish/v2/app-package-info",
957
1223
  {
958
1224
  params: { packageId: req.packageId },
@@ -963,7 +1229,7 @@ var PublishService = class {
963
1229
  }
964
1230
  /** 查询软件包编译状态 */
965
1231
  static async getCompileStatus(req) {
966
- const response = await agcClient.get(
1232
+ const response = await connectApiClient.get(
967
1233
  "/api/publish/v3/package/compile/status",
968
1234
  { params: { appId: req.appId, pkgIds: req.pkgIds } }
969
1235
  );
@@ -972,7 +1238,7 @@ var PublishService = class {
972
1238
  /** 查询应用所有版本类型的版本列表 */
973
1239
  static async queryBriefInfoList(req) {
974
1240
  const { appId, ...body } = req;
975
- const response = await agcClient.post(
1241
+ const response = await connectApiClient.post(
976
1242
  "/api/publish/v3/version/brief-info/list",
977
1243
  body,
978
1244
  { headers: appIdHeaders(appId) }
@@ -982,7 +1248,7 @@ var PublishService = class {
982
1248
  /** 查询应用未处理的问题工单 */
983
1249
  static async queryVersionVoc(req) {
984
1250
  const { appId, ...body } = req;
985
- const response = await agcClient.post(
1251
+ const response = await connectApiClient.post(
986
1252
  "/api/publish/v1/app-voc/version-voc",
987
1253
  body,
988
1254
  { headers: appIdHeaders(appId) }
@@ -991,7 +1257,7 @@ var PublishService = class {
991
1257
  }
992
1258
  /** 查询需要上传的资质文件信息 */
993
1259
  static async queryTagQualDependent() {
994
- const response = await agcClient.get(
1260
+ const response = await connectApiClient.get(
995
1261
  "/api/publish/v2/tag-qual-dependent"
996
1262
  );
997
1263
  return response.data;
@@ -999,7 +1265,7 @@ var PublishService = class {
999
1265
  /** 提交资质审核任务 */
1000
1266
  static async submitQualificationReview(req) {
1001
1267
  const { appId, ...body } = req;
1002
- const response = await agcClient.post(
1268
+ const response = await connectApiClient.post(
1003
1269
  "/api/publish/v2/qualification-review-task",
1004
1270
  body,
1005
1271
  { headers: appIdHeaders(appId) }
@@ -1008,7 +1274,7 @@ var PublishService = class {
1008
1274
  }
1009
1275
  /** 查询资质审核任务详情 */
1010
1276
  static async getQualificationReview(req) {
1011
- const response = await agcClient.get(
1277
+ const response = await connectApiClient.get(
1012
1278
  "/api/publish/v2/qualification-review-task",
1013
1279
  {
1014
1280
  params: { tagIds: req.tagIds },
@@ -1020,7 +1286,7 @@ var PublishService = class {
1020
1286
  /** 修改资质审核任务 */
1021
1287
  static async updateQualificationReview(req) {
1022
1288
  const { appId, ...body } = req;
1023
- const response = await agcClient.put(
1289
+ const response = await connectApiClient.put(
1024
1290
  "/api/publish/v2/qualification-review-task",
1025
1291
  body,
1026
1292
  { headers: appIdHeaders(appId) }
@@ -1029,7 +1295,7 @@ var PublishService = class {
1029
1295
  }
1030
1296
  /** 撤销资质审核任务 */
1031
1297
  static async cancelQualificationReview(req) {
1032
- const response = await agcClient.put(
1298
+ const response = await connectApiClient.put(
1033
1299
  "/api/publish/v2/qualification-review-task/cancel",
1034
1300
  { taskId: req.taskId },
1035
1301
  { headers: appIdHeaders(req.appId) }
@@ -1038,7 +1304,7 @@ var PublishService = class {
1038
1304
  }
1039
1305
  /** 删除资质审核任务 */
1040
1306
  static async deleteQualificationReview(req) {
1041
- const response = await agcClient.delete(
1307
+ const response = await connectApiClient.delete(
1042
1308
  "/api/publish/v2/qualification-review-task",
1043
1309
  {
1044
1310
  data: { tagIds: req.tagIds },
@@ -1050,7 +1316,7 @@ var PublishService = class {
1050
1316
  /** 新建用户协议 / 隐私政策协议(body.type 区分) */
1051
1317
  static async createAgreement(req) {
1052
1318
  const { appId, ...body } = req;
1053
- const response = await agcClient.post(
1319
+ const response = await connectApiClient.post(
1054
1320
  "/api/publish/v2/agreement",
1055
1321
  body,
1056
1322
  { headers: appIdHeaders(appId) }
@@ -1060,7 +1326,7 @@ var PublishService = class {
1060
1326
  /** 查询用户协议 / 隐私政策协议列表(body.type 区分) */
1061
1327
  static async listAgreements(req) {
1062
1328
  const { appId, ...body } = req;
1063
- const response = await agcClient.post(
1329
+ const response = await connectApiClient.post(
1064
1330
  "/api/publish/v2/agreement/list",
1065
1331
  body,
1066
1332
  { headers: appIdHeaders(appId) }
@@ -1070,7 +1336,7 @@ var PublishService = class {
1070
1336
  /** 更新用户协议 / 隐私政策协议 */
1071
1337
  static async updateAgreement(req) {
1072
1338
  const { appId, ...body } = req;
1073
- const response = await agcClient.put(
1339
+ const response = await connectApiClient.put(
1074
1340
  "/api/publish/v2/agreement",
1075
1341
  body,
1076
1342
  { headers: appIdHeaders(appId) }
@@ -1080,7 +1346,7 @@ var PublishService = class {
1080
1346
  /** 提交隐私政策协议 */
1081
1347
  static async submitPrivacyAgreement(req) {
1082
1348
  const { appId, ...body } = req;
1083
- const response = await agcClient.put(
1349
+ const response = await connectApiClient.put(
1084
1350
  "/api/publish/v2/agreement/submit",
1085
1351
  body,
1086
1352
  { headers: appIdHeaders(appId) }
@@ -1090,7 +1356,7 @@ var PublishService = class {
1090
1356
  /** 申请年龄分级 */
1091
1357
  static async applyAgeRating(req) {
1092
1358
  const { appId, releaseType, releasePhase, ...body } = req;
1093
- const response = await agcClient.post(
1359
+ const response = await connectApiClient.post(
1094
1360
  "/api/publish/v2/app-age-rating",
1095
1361
  body,
1096
1362
  {
@@ -1103,16 +1369,16 @@ var PublishService = class {
1103
1369
  /** 提交发布 */
1104
1370
  static async submitApp(req) {
1105
1371
  const { appId, ...body } = req;
1106
- const response = await agcClient.post(
1372
+ const response = await connectApiClient.post(
1107
1373
  "/api/publish/v3/app-submit",
1108
1374
  body,
1109
- { headers: appIdHeaders(appId) }
1375
+ { params: { appId } }
1110
1376
  );
1111
1377
  return response.data;
1112
1378
  }
1113
1379
  /** 撤销审核 */
1114
1380
  static async cancelReview(req) {
1115
- const response = await agcClient.put(
1381
+ const response = await connectApiClient.put(
1116
1382
  "/api/publish/v3/version/on-shelf/cancel",
1117
1383
  { versionId: req.versionId },
1118
1384
  { headers: appIdHeaders(req.appId) }
@@ -1121,7 +1387,7 @@ var PublishService = class {
1121
1387
  }
1122
1388
  /** 下架应用 */
1123
1389
  static async shelfOff(req) {
1124
- const response = await agcClient.post(
1390
+ const response = await connectApiClient.post(
1125
1391
  "/api/publish/v2/app-shelf-off",
1126
1392
  null,
1127
1393
  {
@@ -1140,42 +1406,42 @@ var PublishService = class {
1140
1406
  var ProjectService = class {
1141
1407
  /** 查询团队下的项目列表(Project Management API) */
1142
1408
  static async listProjects() {
1143
- const response = await agcClient.get("/api/project-service/v1/projects");
1409
+ const response = await connectApiClient.get("/api/project-service/v1/projects");
1144
1410
  return response.data;
1145
1411
  }
1146
1412
  };
1147
1413
 
1148
1414
  // src/services/upload.ts
1149
1415
  var import_axios4 = __toESM(require("axios"));
1150
- var import_fs6 = __toESM(require("fs"));
1151
- var import_path5 = __toESM(require("path"));
1416
+ var import_fs7 = __toESM(require("fs"));
1417
+ var import_path6 = __toESM(require("path"));
1152
1418
  function pickObjectId(res) {
1153
1419
  return res.urlInfo?.objectId || res.objectId;
1154
1420
  }
1155
1421
  var UploadService = class {
1156
1422
  // ================= Raw APIs =================
1157
1423
  static async getUploadUrl(req) {
1158
- const response = await agcClient.get("/api/publish/v2/upload-url/for-obs", {
1424
+ const response = await connectApiClient.get("/api/publish/v2/upload-url/for-obs", {
1159
1425
  params: req
1160
1426
  });
1161
1427
  return response.data;
1162
1428
  }
1163
1429
  static async initMultipart(req) {
1164
- const response = await agcClient.post("/api/publish/v2/upload/multipart/init", null, {
1430
+ const response = await connectApiClient.post("/api/publish/v2/upload/multipart/init", null, {
1165
1431
  params: req
1166
1432
  });
1167
1433
  return response.data;
1168
1434
  }
1169
1435
  static async getMultipartParts(req) {
1170
1436
  const { objectId, nspUploadId, parts } = req;
1171
- const response = await agcClient.post("/api/publish/v2/upload/multipart/parts", parts, {
1437
+ const response = await connectApiClient.post("/api/publish/v2/upload/multipart/parts", parts, {
1172
1438
  params: { objectId, nspUploadId }
1173
1439
  });
1174
1440
  return response.data;
1175
1441
  }
1176
1442
  static async composeMultipart(req) {
1177
1443
  const { objectId, nspUploadId, parts } = req;
1178
- const response = await agcClient.post("/api/publish/v2/upload/multipart/compose", parts, {
1444
+ const response = await connectApiClient.post("/api/publish/v2/upload/multipart/compose", parts, {
1179
1445
  params: { objectId, nspUploadId }
1180
1446
  });
1181
1447
  return response.data;
@@ -1187,8 +1453,8 @@ var UploadService = class {
1187
1453
  * 仅完成 OBS 落盘;HarmonyOS `.app` 还须调用更新应用软件包信息,HarmonyOS 开发者中心才会有记录。
1188
1454
  */
1189
1455
  static async uploadFile(options) {
1190
- const stat = import_fs6.default.statSync(options.filePath);
1191
- const fileName = import_path5.default.basename(options.filePath) || "unknown";
1456
+ const stat = import_fs7.default.statSync(options.filePath);
1457
+ const fileName = import_path6.default.basename(options.filePath) || "unknown";
1192
1458
  if (stat.size < 5 * 1024 * 1024) {
1193
1459
  return this.uploadSingleFile(options, fileName, stat.size);
1194
1460
  }
@@ -1229,7 +1495,7 @@ var UploadService = class {
1229
1495
  );
1230
1496
  }
1231
1497
  const { url, headers } = urlRes.urlInfo;
1232
- const fileStream = import_fs6.default.createReadStream(options.filePath);
1498
+ const fileStream = import_fs7.default.createReadStream(options.filePath);
1233
1499
  await import_axios4.default.put(url, fileStream, {
1234
1500
  headers: this.buildObsPutHeaders(headers, contentLength),
1235
1501
  maxBodyLength: Infinity,
@@ -1270,7 +1536,7 @@ var UploadService = class {
1270
1536
  if (!uploadInfoMap) {
1271
1537
  throw new Error(`Failed to get parts upload URL: ${JSON.stringify(partsRes.ret)}`);
1272
1538
  }
1273
- const fd = import_fs6.default.openSync(options.filePath, "r");
1539
+ const fd = import_fs7.default.openSync(options.filePath, "r");
1274
1540
  const composeReqBody = {};
1275
1541
  for (let i = 1; i <= partsCount; i++) {
1276
1542
  const propKey = `additionalProp${i}`;
@@ -1279,7 +1545,7 @@ var UploadService = class {
1279
1545
  const end = Math.min(start + partSize, fileSize);
1280
1546
  const length = end - start;
1281
1547
  const buffer = Buffer.alloc(length);
1282
- import_fs6.default.readSync(fd, buffer, 0, length, start);
1548
+ import_fs7.default.readSync(fd, buffer, 0, length, start);
1283
1549
  const res = await import_axios4.default.put(uploadInfo.url, buffer, {
1284
1550
  headers: this.buildObsPutHeaders(uploadInfo.headers, length),
1285
1551
  maxBodyLength: Infinity,
@@ -1291,7 +1557,7 @@ var UploadService = class {
1291
1557
  etag
1292
1558
  };
1293
1559
  }
1294
- import_fs6.default.closeSync(fd);
1560
+ import_fs7.default.closeSync(fd);
1295
1561
  await this.composeMultipart({
1296
1562
  objectId,
1297
1563
  nspUploadId,
@@ -1305,20 +1571,20 @@ var UploadService = class {
1305
1571
  var ProvisionService = class {
1306
1572
  // ================= Certificates =================
1307
1573
  static async createCert(req) {
1308
- const response = await agcClient.post("/api/publish/v3/cert", req);
1574
+ const response = await connectApiClient.post("/api/publish/v3/cert", req);
1309
1575
  return response.data;
1310
1576
  }
1311
1577
  static async getCertList(req) {
1312
- const response = await agcClient.post("/api/publish/v3/cert/list", req);
1578
+ const response = await connectApiClient.post("/api/publish/v3/cert/list", req);
1313
1579
  return response.data;
1314
1580
  }
1315
1581
  static async deleteCert(req) {
1316
- const response = await agcClient.post("/api/publish/v2/cert/delete", req);
1582
+ const response = await connectApiClient.post("/api/publish/v2/cert/delete", req);
1317
1583
  return response.data;
1318
1584
  }
1319
1585
  // ================= Devices =================
1320
1586
  static async addDevice(req) {
1321
- const response = await agcClient.post("/api/publish/v2/device", req);
1587
+ const response = await connectApiClient.post("/api/publish/v2/device", req);
1322
1588
  return response.data;
1323
1589
  }
1324
1590
  static async getDeviceList(req) {
@@ -1327,16 +1593,16 @@ var ProvisionService = class {
1327
1593
  if (req.fromRecCount !== void 0) params.fromRecCount = req.fromRecCount;
1328
1594
  if (req.maxReqCount !== void 0) params.maxReqCount = req.maxReqCount;
1329
1595
  if (req.order !== void 0) params.order = req.order;
1330
- const response = await agcClient.get("/api/publish/v2/device/list", { params });
1596
+ const response = await connectApiClient.get("/api/publish/v2/device/list", { params });
1331
1597
  return response.data;
1332
1598
  }
1333
1599
  static async deleteDevice(req) {
1334
- const response = await agcClient.post("/api/publish/v2/device/delete", req);
1600
+ const response = await connectApiClient.post("/api/publish/v2/device/delete", req);
1335
1601
  return response.data;
1336
1602
  }
1337
1603
  // ================= Profile / Provision =================
1338
1604
  static async createProvision(req) {
1339
- const response = await agcClient.post("/api/publish/v3/provision", req);
1605
+ const response = await connectApiClient.post("/api/publish/v3/provision", req);
1340
1606
  return response.data;
1341
1607
  }
1342
1608
  static async getProvisionList(req) {
@@ -1345,18 +1611,18 @@ var ProvisionService = class {
1345
1611
  if (req.maxReqCount !== void 0) params.maxReqCount = req.maxReqCount;
1346
1612
  const headers = { appId: req.appId };
1347
1613
  if (req.provisionId) headers.provisionId = req.provisionId;
1348
- const response = await agcClient.get("/api/publish/v3/provision/list", {
1614
+ const response = await connectApiClient.get("/api/publish/v3/provision/list", {
1349
1615
  params,
1350
1616
  headers
1351
1617
  });
1352
1618
  return response.data;
1353
1619
  }
1354
1620
  static async updateProvision(req) {
1355
- const response = await agcClient.put("/api/publish/v3/provision", req);
1621
+ const response = await connectApiClient.put("/api/publish/v3/provision", req);
1356
1622
  return response.data;
1357
1623
  }
1358
1624
  static async deleteProvision(req) {
1359
- const response = await agcClient.delete("/api/publish/v2/provision", {
1625
+ const response = await connectApiClient.delete("/api/publish/v2/provision", {
1360
1626
  params: { id: req.id }
1361
1627
  });
1362
1628
  return response.data;
@@ -1364,7 +1630,7 @@ var ProvisionService = class {
1364
1630
  // ================= Fingerprint =================
1365
1631
  static async addFingerprint(req) {
1366
1632
  const { appId, ...body } = req;
1367
- const response = await agcClient.post(
1633
+ const response = await connectApiClient.post(
1368
1634
  "/api/provision/v1/fingerprints",
1369
1635
  body,
1370
1636
  { headers: { appId } }
@@ -1372,14 +1638,14 @@ var ProvisionService = class {
1372
1638
  return response.data;
1373
1639
  }
1374
1640
  static async getFingerprintList(req) {
1375
- const response = await agcClient.get("/api/provision/v1/fingerprints", {
1641
+ const response = await connectApiClient.get("/api/provision/v1/fingerprints", {
1376
1642
  headers: { appId: req.appId }
1377
1643
  });
1378
1644
  return response.data;
1379
1645
  }
1380
1646
  static async deleteFingerprint(req) {
1381
1647
  const { appId, ...body } = req;
1382
- const response = await agcClient.delete(
1648
+ const response = await connectApiClient.delete(
1383
1649
  "/api/provision/v1/fingerprints",
1384
1650
  { headers: { appId }, data: body }
1385
1651
  );
@@ -1389,7 +1655,7 @@ var ProvisionService = class {
1389
1655
  /** 查询可申请的 ACL 权限列表 */
1390
1656
  static async getEligibleACL(req) {
1391
1657
  const { appId, ...body } = req;
1392
- const response = await agcClient.post(
1658
+ const response = await connectApiClient.post(
1393
1659
  "/api/provision/v1/user/permission/apply/list",
1394
1660
  body,
1395
1661
  { headers: { appId } }
@@ -1398,7 +1664,7 @@ var ProvisionService = class {
1398
1664
  }
1399
1665
  static async applyACL(req) {
1400
1666
  const { appId, ...body } = req;
1401
- const response = await agcClient.post(
1667
+ const response = await connectApiClient.post(
1402
1668
  "/api/provision/v1/user/permission/apply",
1403
1669
  body,
1404
1670
  { headers: { appId } }
@@ -1406,14 +1672,14 @@ var ProvisionService = class {
1406
1672
  return response.data;
1407
1673
  }
1408
1674
  static async getACLStatus(req) {
1409
- const response = await agcClient.get(
1675
+ const response = await connectApiClient.get(
1410
1676
  "/api/provision/v1/user/permission/apply/status",
1411
1677
  { headers: { appId: req.appId } }
1412
1678
  );
1413
1679
  return response.data;
1414
1680
  }
1415
1681
  static async getACLQuery(req) {
1416
- const response = await agcClient.get("/api/provision/v1/user/permission", {
1682
+ const response = await connectApiClient.get("/api/provision/v1/user/permission", {
1417
1683
  headers: { appId: req.appId }
1418
1684
  });
1419
1685
  return response.data;
@@ -1426,6 +1692,6 @@ var ProvisionService = class {
1426
1692
  ProvisionService,
1427
1693
  PublishService,
1428
1694
  UploadService,
1429
- agcClient,
1695
+ connectApiClient,
1430
1696
  getConfig
1431
1697
  });