@cloudbase/cli 2.12.5 → 2.12.6

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.
@@ -326254,7 +326254,7 @@ module.exports = function generate_pattern(it, $keyword, $ruleType) {
326254
326254
  /***/ ((module) => {
326255
326255
 
326256
326256
  "use strict";
326257
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.5","description":"cli tool for cloudbase","main":"lib/index.js","scripts":{"build":"rimraf lib types && tsc --resolveJsonModule && cpx \\"src/**/*.html\\" lib","watch":"rimraf lib types && tsc -w","dev":"rimraf lib types && cpx \\"src/**/*.html\\" lib && tsc -w","eslint":"eslint \\"./**/*.ts\\"","test":"node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --forceExit --detectOpenHandles --coverage --verbose --testTimeout=10000","tsc":"tsc","pkg":"pkg ./bin/cloudbase.js --out-path ./pkg","postinstall":"node ./post-install.js || exit 0 && patch-package","prepublishOnly":"node ./scripts/check-publish-source.js","debug":"bin/tcb.js lowcode watch","build:bundle":"webpack --config build/webpack/cli.cjs && webpack --config build/webpack/ccr.cjs && node build/scripts/copy-figlet-fonts.js","package:darwin-arm64":"OS=darwin ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:darwin-x64":"OS=darwin ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:linux-arm64":"OS=linux ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:linux-x64":"OS=linux ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:all":"bash build/scripts/build-all.sh","node:fetch:one":"node -e \\"require(\'child_process\').execSync(\'bash build/scripts/fetch-node.sh\',{stdio:\'inherit\'})\\"","node:fetch:all":"NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh --all","node:fetch:win-x64":"OS=windows ARCH=x64 NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh","node:fetch:win-arm64":"OS=windows ARCH=arm64 NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh","package:windows-x64":"OS=windows ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:windows-arm64":"OS=windows ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:windows-all":"npm run -s node:fetch:win-x64 && npm run -s node:fetch:win-arm64 && npm run -s package:windows-x64 && npm run -s package:windows-arm64","package:npm":"npm run build && npm run build:bundle && bash build/scripts/prepare-publish.sh","out:prune":"bash build/scripts/prune-out.sh","i18n:scan":"i18next-scanner --config locales/i18next-scanner.config.js && node locales/scripts/generate.js","i18n:sync":"node locales/scripts/sync.js sync","publish":"node ./scripts/publish.js"},"repository":{"type":"git","url":"https://github.com/TencentCloudBase/cloud-base-cli.git"},"bin":{"cloudbase":"bin/cloudbase.js","cloudbase-mcp":"bin/cloudbase-mcp.cjs","tcb":"bin/tcb.js"},"husky":{"hooks":{"pre-commit":"npm run build"}},"author":"cwuyiqing@gmail.com","license":"ISC","dependencies":{"@cloudbase/cloud-api":"^0.5.5","@cloudbase/cloudbase-mcp":"^2.7.3","@cloudbase/framework-core":"^1.9.7","@cloudbase/functions-framework":"1.16.0","@cloudbase/iac-core":"0.0.3-alpha.14","@cloudbase/lowcode-cli":"^0.23.0","@cloudbase/manager-node":"4.10.2","@cloudbase/toolbox":"0.7.16","@dotenvx/dotenvx":"^1.48.3","@musistudio/claude-code-router":"1.0.36","address":"^1.1.2","camelcase-keys":"^7.0.2","chalk":"^2.4.2","cli-table3":"^0.5.1","commander":"7","del":"^5.1.0","didyoumean":"^1.2.2","enquirer":"^2.3.6","execa":"^4.0.3","figlet":"^1.7.0","fs-extra":"^8.1.0","gradient-string":"^2.0.2","https-proxy-agent":"^5.0.1","i":"^0.3.7","inquirer":"^6.5.0","json-schema-to-typescript":"^14.0.5","lodash":"^4.17.21","log-symbols":"^3.0.0","lowdb":"^1.0.0","make-dir":"^3.0.0","node-fetch":"^2.6.0","nodemon":"^3.1.4","npm":"^11.5.2","open":"^7.0.0","ora":"^4.0.2","os-locale":"5.0.0","patch-package":"^8.0.0","portfinder":"^1.0.28","progress":"^2.0.3","query-string":"^6.8.1","reflect-metadata":"^0.1.13","semver":"^7.3.7","simple-git":"^3.28.0","tar-fs":"^2.0.1","terminal-link":"^2.1.1","toml":"^3.0.0","unzipper":"^0.10.10","update-notifier":"^4.0.0","xdg-basedir":"^4.0.0","yargs":"^16.2.0","yargs-parser":"^21.0.1","zod":"^4.0.13"},"devDependencies":{"@babel/parser":"^7.28.4","@babel/traverse":"^7.28.4","@babel/types":"^7.28.4","@types/fs-extra":"^11.0.4","@types/jest":"^27","@types/koa__router":"^8.0.11","@types/lodash":"^4.14.182","@types/node":"^12.12.38","@types/node-fetch":"^2.5.4","@types/react":"^17.0.37","@types/semver":"^7.3.9","@types/unzipper":"^0.10.11","@types/webpack-dev-server":"^3.11.1","@typescript-eslint/eslint-plugin":"^4.8.1","@typescript-eslint/parser":"^4.8.1","cpx":"^1.5.0","eslint":"^7.14.0","eslint-config-alloy":"^3.8.2","husky":"^3.0.9","i18next-scanner":"^4.6.0","jest":"^27","rimraf":"^3.0.2","ts-jest":"^27","typescript":"^4.7.2","webpack":"^5.92.0","webpack-cli":"^5.1.4"},"packageManager":"yarn@3.6.2+sha512.2c2f8b9615e6659773f65cdec7cf92ef773a98a99e611579601f61c7a91ec94c89c929aac86f1cee819421a9b0db7acfd53ec3ebb95af44f77f77634b08b9557","ai":{"skills":"./skills","skillsIndex":"./skills/index.json","compatible":["codebuddy","cursor","copilot","claude","windsurf"],"description":"CloudBase CLI - 腾讯云云开发命令行工具,支持云函数、云数据库、静态托管等全栈云开发能力"}}');
326257
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.6","description":"cli tool for cloudbase","main":"lib/index.js","scripts":{"build":"rimraf lib types && tsc --resolveJsonModule && cpx \\"src/**/*.html\\" lib","watch":"rimraf lib types && tsc -w","dev":"rimraf lib types && cpx \\"src/**/*.html\\" lib && tsc -w","eslint":"eslint \\"./**/*.ts\\"","test":"node --experimental-vm-modules node_modules/jest/bin/jest.js --runInBand --forceExit --detectOpenHandles --coverage --verbose --testTimeout=10000","tsc":"tsc","pkg":"pkg ./bin/cloudbase.js --out-path ./pkg","postinstall":"node ./post-install.js || exit 0 && patch-package","prepublishOnly":"node ./scripts/check-publish-source.js","debug":"bin/tcb.js lowcode watch","build:bundle":"webpack --config build/webpack/cli.cjs && webpack --config build/webpack/ccr.cjs && node build/scripts/copy-figlet-fonts.js","package:darwin-arm64":"OS=darwin ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:darwin-x64":"OS=darwin ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:linux-arm64":"OS=linux ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:linux-x64":"OS=linux ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:all":"bash build/scripts/build-all.sh","node:fetch:one":"node -e \\"require(\'child_process\').execSync(\'bash build/scripts/fetch-node.sh\',{stdio:\'inherit\'})\\"","node:fetch:all":"NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh --all","node:fetch:win-x64":"OS=windows ARCH=x64 NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh","node:fetch:win-arm64":"OS=windows ARCH=arm64 NODE_VERSION=22.18.0 bash build/scripts/fetch-node.sh","package:windows-x64":"OS=windows ARCH=x64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:windows-arm64":"OS=windows ARCH=arm64 VERSION= node -e \\"require(\'child_process\').execSync(\'bash build/scripts/package.sh\',{stdio:\'inherit\'})\\"","package:windows-all":"npm run -s node:fetch:win-x64 && npm run -s node:fetch:win-arm64 && npm run -s package:windows-x64 && npm run -s package:windows-arm64","package:npm":"npm run build && npm run build:bundle && bash build/scripts/prepare-publish.sh","out:prune":"bash build/scripts/prune-out.sh","i18n:scan":"i18next-scanner --config locales/i18next-scanner.config.js && node locales/scripts/generate.js","i18n:sync":"node locales/scripts/sync.js sync","publish":"node ./scripts/publish.js"},"repository":{"type":"git","url":"https://github.com/TencentCloudBase/cloud-base-cli.git"},"bin":{"cloudbase":"bin/cloudbase.js","cloudbase-mcp":"bin/cloudbase-mcp.cjs","tcb":"bin/tcb.js"},"husky":{"hooks":{"pre-commit":"npm run build"}},"author":"cwuyiqing@gmail.com","license":"ISC","dependencies":{"@cloudbase/cloud-api":"^0.5.5","@cloudbase/cloudbase-mcp":"^2.7.3","@cloudbase/framework-core":"^1.9.7","@cloudbase/functions-framework":"1.16.0","@cloudbase/iac-core":"0.0.3-alpha.14","@cloudbase/lowcode-cli":"^0.23.0","@cloudbase/manager-node":"4.10.2","@cloudbase/toolbox":"0.7.17","@dotenvx/dotenvx":"^1.48.3","@musistudio/claude-code-router":"1.0.36","address":"^1.1.2","camelcase-keys":"^7.0.2","chalk":"^2.4.2","cli-table3":"^0.5.1","commander":"7","del":"^5.1.0","didyoumean":"^1.2.2","enquirer":"^2.3.6","execa":"^4.0.3","figlet":"^1.7.0","fs-extra":"^8.1.0","gradient-string":"^2.0.2","https-proxy-agent":"^5.0.1","i":"^0.3.7","inquirer":"^6.5.0","json-schema-to-typescript":"^14.0.5","lodash":"^4.17.21","log-symbols":"^3.0.0","lowdb":"^1.0.0","make-dir":"^3.0.0","node-fetch":"^2.6.0","nodemon":"^3.1.4","npm":"^11.5.2","open":"^7.0.0","ora":"^4.0.2","os-locale":"5.0.0","patch-package":"^8.0.0","portfinder":"^1.0.28","progress":"^2.0.3","query-string":"^6.8.1","reflect-metadata":"^0.1.13","semver":"^7.3.7","simple-git":"^3.28.0","tar-fs":"^2.0.1","terminal-link":"^2.1.1","toml":"^3.0.0","unzipper":"^0.10.10","update-notifier":"^4.0.0","xdg-basedir":"^4.0.0","yargs":"^16.2.0","yargs-parser":"^21.0.1","zod":"^4.0.13"},"devDependencies":{"@babel/parser":"^7.28.4","@babel/traverse":"^7.28.4","@babel/types":"^7.28.4","@types/fs-extra":"^11.0.4","@types/jest":"^27","@types/koa__router":"^8.0.11","@types/lodash":"^4.14.182","@types/node":"^12.12.38","@types/node-fetch":"^2.5.4","@types/react":"^17.0.37","@types/semver":"^7.3.9","@types/unzipper":"^0.10.11","@types/webpack-dev-server":"^3.11.1","@typescript-eslint/eslint-plugin":"^4.8.1","@typescript-eslint/parser":"^4.8.1","cpx":"^1.5.0","eslint":"^7.14.0","eslint-config-alloy":"^3.8.2","husky":"^3.0.9","i18next-scanner":"^4.6.0","jest":"^27","rimraf":"^3.0.2","ts-jest":"^27","typescript":"^4.7.2","webpack":"^5.92.0","webpack-cli":"^5.1.4"},"packageManager":"yarn@3.6.2+sha512.2c2f8b9615e6659773f65cdec7cf92ef773a98a99e611579601f61c7a91ec94c89c929aac86f1cee819421a9b0db7acfd53ec3ebb95af44f77f77634b08b9557","ai":{"skills":"./skills","skillsIndex":"./skills/index.json","compatible":["codebuddy","cursor","copilot","claude","windsurf"],"description":"CloudBase CLI - 腾讯云云开发命令行工具,支持云函数、云数据库、静态托管等全栈云开发能力"}}');
326258
326258
 
326259
326259
  /***/ }),
326260
326260
 
@@ -398398,12 +398398,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
398398
398398
  Object.defineProperty(exports, "__esModule", ({ value: true }));
398399
398399
  exports.AuthSupevisor = exports.AuthSupervisor = void 0;
398400
398400
  const web_auth_1 = __webpack_require__(76097);
398401
+ const oauth_1 = __webpack_require__(92423);
398401
398402
  const common_1 = __webpack_require__(96711);
398402
398403
  const credential_1 = __webpack_require__(99795);
398403
398404
  const error_1 = __webpack_require__(64119);
398404
398405
  __exportStar(__webpack_require__(96711), exports);
398405
398406
  __exportStar(__webpack_require__(99795), exports);
398406
398407
  __exportStar(__webpack_require__(76097), exports);
398408
+ __exportStar(__webpack_require__(92423), exports);
398407
398409
  class AuthSupervisor {
398408
398410
  /**
398409
398411
  * 单例模式,全局缓存
@@ -398453,7 +398455,7 @@ class AuthSupervisor {
398453
398455
  */
398454
398456
  loginByWebAuth(options = {}) {
398455
398457
  return __awaiter(this, void 0, void 0, function* () {
398456
- const { getAuthUrl, throwError, noBrowser, callbackTimeout } = options;
398458
+ const { getAuthUrl, throwError, noBrowser, callbackTimeout, flow = 'device', client_id, onDeviceCode, getOAuthEndpoint, silent } = options;
398457
398459
  if (this.cacheCredential && this.needCache && !this.isCacheExpire()) {
398458
398460
  return this.cacheCredential;
398459
398461
  }
@@ -398461,12 +398463,19 @@ class AuthSupervisor {
398461
398463
  let credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
398462
398464
  if (credential)
398463
398465
  return credential;
398464
- // 兼容临时秘钥
398465
- credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
398466
- getAuthUrl,
398467
- noBrowser,
398468
- callbackTimeout
398469
- });
398466
+ // 根据授权方式获取凭证
398467
+ if (flow === 'web') {
398468
+ credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
398469
+ getAuthUrl,
398470
+ noBrowser,
398471
+ callbackTimeout,
398472
+ silent
398473
+ });
398474
+ }
398475
+ else {
398476
+ credential = yield (0, oauth_1.getAuthTokenByDeviceFlow)({ client_id, onDeviceCode, getOAuthEndpoint, getAuthUrl, silent });
398477
+ }
398478
+ credential = (0, common_1.resolveCredential)(credential);
398470
398479
  try {
398471
398480
  yield (0, common_1.checkAuth)(credential, this.requestConfig);
398472
398481
  }
@@ -410365,7 +410374,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
410365
410374
  return (mod && mod.__esModule) ? mod : { "default": mod };
410366
410375
  };
410367
410376
  Object.defineProperty(exports, "__esModule", ({ value: true }));
410368
- exports.getDataFromWeb = void 0;
410377
+ exports.getDataFromWeb = exports.openUrl = exports.isTruthyFlag = void 0;
410369
410378
  const open_1 = __importDefault(__webpack_require__(30353));
410370
410379
  const query_string_1 = __importDefault(__webpack_require__(86663));
410371
410380
  const http_1 = __importDefault(__webpack_require__(58611));
@@ -410412,6 +410421,7 @@ function isTruthyFlag(value) {
410412
410421
  }
410413
410422
  return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
410414
410423
  }
410424
+ exports.isTruthyFlag = isTruthyFlag;
410415
410425
  function isVSCodeEnvironment() {
410416
410426
  return Boolean(process.env.VSCODE_IPC_HOOK_CLI
410417
410427
  || process.env.VSCODE_PID
@@ -410467,19 +410477,23 @@ function openUrl(url) {
410467
410477
  }
410468
410478
  });
410469
410479
  }
410480
+ exports.openUrl = openUrl;
410470
410481
  // 从 Web 页面中获取数据
410471
410482
  function getDataFromWeb(getUrl, type, options = {}) {
410472
- var _a, _b;
410483
+ var _a, _b, _c;
410473
410484
  return __awaiter(this, void 0, void 0, function* () {
410474
410485
  const { server, port } = yield createLocalServer();
410475
410486
  const noBrowser = (_a = options.noBrowser) !== null && _a !== void 0 ? _a : isTruthyFlag(process.env.TCB_NO_BROWSER);
410476
410487
  const callbackTimeout = (_b = options.callbackTimeout) !== null && _b !== void 0 ? _b : 180000;
410488
+ const silent = (_c = options.silent) !== null && _c !== void 0 ? _c : false;
410477
410489
  if (!Number.isFinite(callbackTimeout) || callbackTimeout <= 0) {
410478
410490
  throw new error_1.CloudBaseError('callbackTimeout must be a positive number');
410479
410491
  }
410480
410492
  const url = getUrl(port);
410481
- console.log('\n\n若链接未自动打开,请手动复制至浏览器,或尝试其他登录方式:');
410482
- console.log(`\n${url}\n`);
410493
+ if (!silent) {
410494
+ console.log('\n\n若链接未自动打开,请手动复制至浏览器,或尝试其他登录方式:');
410495
+ console.log(`\n${url}\n`);
410496
+ }
410483
410497
  if (!noBrowser) {
410484
410498
  // 对 url 转码, 避免 wsl 无法正常打开地址
410485
410499
  // https://www.npmjs.com/package/open#url
@@ -440152,16 +440166,23 @@ const LoginRes = {
440152
440166
  };
440153
440167
  }
440154
440168
  };
440155
- function loginByWebAuth() {
440169
+ function loginByWebAuth({ flow } = {}) {
440156
440170
  return __awaiter(this, void 0, void 0, function* () {
440157
440171
  try {
440158
440172
  const credential = yield utils_1.authSupevisor.loginByWebAuth({
440173
+ flow,
440159
440174
  getAuthUrl: (rawUrl) => {
440160
440175
  if ((0, i18n_1.isIntl)()) {
440161
440176
  return rawUrl.replace('https://tcb.cloud.tencent.com/dev', utils_1.EUrl.DevPlatform);
440162
440177
  }
440163
440178
  return rawUrl;
440164
- }
440179
+ },
440180
+ getOAuthEndpoint: (rawEndpoint) => {
440181
+ if ((0, i18n_1.isIntl)()) {
440182
+ return rawEndpoint.replace('https://tcb-api.cloud.tencent.com', 'https://tcb-api.tencentcloud.com');
440183
+ }
440184
+ return rawEndpoint;
440185
+ },
440165
440186
  });
440166
440187
  if (lodash_1.default.isEmpty(credential)) {
440167
440188
  return LoginRes.INVALID_TOKEN;
@@ -440169,9 +440190,6 @@ function loginByWebAuth() {
440169
440190
  return Object.assign({ credential }, LoginRes.SUCCESS);
440170
440191
  }
440171
440192
  catch (error) {
440172
- console.error((0, i18n_1.t)('Web 授权登录失败,可能是环境兼容性问题'));
440173
- console.error((0, i18n_1.t)('建议使用密钥登录:tcb login --key'));
440174
- console.error((0, i18n_1.t)('详细说明请参考:{{url}}', { url: 'https://docs.cloudbase.net/cli-v1/login#%E8%85%BE%E8%AE%AF%E4%BA%91-%E4%BA%91%E5%BC%80%E5%8F%91%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%8E%88%E6%9D%83' }));
440175
440193
  return {
440176
440194
  code: 'WEB_AUTH_FAILED',
440177
440195
  msg: (0, i18n_1.t)('Web 授权登录失败,请使用密钥登录:tcb login --key'),
@@ -440196,8 +440214,8 @@ function loginWithKey(secretId, secretKey, token) {
440196
440214
  exports.loginWithKey = loginWithKey;
440197
440215
  function login(options = {}) {
440198
440216
  return __awaiter(this, void 0, void 0, function* () {
440199
- const { secretId, secretKey, key, token } = options;
440200
- return key ? loginWithKey(secretId, secretKey, token) : loginByWebAuth();
440217
+ const { secretId, secretKey, key, token, flow } = options;
440218
+ return key ? loginWithKey(secretId, secretKey, token) : loginByWebAuth({ flow });
440201
440219
  });
440202
440220
  }
440203
440221
  exports.login = login;
@@ -743531,16 +743549,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
743531
743549
  });
743532
743550
  };
743533
743551
  Object.defineProperty(exports, "__esModule", ({ value: true }));
743534
- exports.getAuthTokenFromWeb = void 0;
743552
+ exports.getAuthTokenFromWeb = exports.CLI_AUTH_BASE_URL = void 0;
743535
743553
  const common_1 = __webpack_require__(96711);
743536
743554
  const coding_1 = __webpack_require__(40540);
743537
743555
  const web_1 = __webpack_require__(2240);
743538
743556
  const system_1 = __webpack_require__(62179);
743539
- const CliAuthBaseUrl = 'https://tcb.cloud.tencent.com/dev';
743557
+ exports.CLI_AUTH_BASE_URL = 'https://tcb.cloud.tencent.com/dev';
743540
743558
  // 打开云开发控制台,获取授权
743541
743559
  function getAuthTokenFromWeb(options = {}) {
743542
743560
  return __awaiter(this, void 0, void 0, function* () {
743543
- const { getAuthUrl, noBrowser, callbackTimeout } = options;
743561
+ const { getAuthUrl, noBrowser, callbackTimeout, silent } = options;
743544
743562
  const mac = yield (0, system_1.getMacAddress)();
743545
743563
  const os = (0, system_1.getOSInfo)();
743546
743564
  const macHash = (0, coding_1.md5Encoding)(mac);
@@ -743553,7 +743571,7 @@ function getAuthTokenFromWeb(options = {}) {
743553
743571
  + '&from=cli';
743554
743572
  const encodedCallbackUrl = encodeURIComponent(callbackUrl);
743555
743573
  // 授权链接
743556
- const rawAuthUrl = `${CliAuthBaseUrl}?authCallbackUrl=${encodedCallbackUrl}#/cli-auth?${encodedQuery}`;
743574
+ const rawAuthUrl = `${exports.CLI_AUTH_BASE_URL}?authCallbackUrl=${encodedCallbackUrl}#/cli-auth?${encodedQuery}`;
743557
743575
  let cliAuthUrl = rawAuthUrl;
743558
743576
  if (getAuthUrl) {
743559
743577
  try {
@@ -743566,7 +743584,8 @@ function getAuthTokenFromWeb(options = {}) {
743566
743584
  return cliAuthUrl;
743567
743585
  }, 'login', {
743568
743586
  noBrowser,
743569
- callbackTimeout
743587
+ callbackTimeout,
743588
+ silent
743570
743589
  });
743571
743590
  const credential = (0, common_1.resolveCredential)(query);
743572
743591
  return credential;
@@ -866805,6 +866824,141 @@ const format = [format_1.default];
866805
866824
  exports["default"] = format;
866806
866825
  //# sourceMappingURL=index.js.map
866807
866826
 
866827
+ /***/ }),
866828
+
866829
+ /***/ 92423:
866830
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
866831
+
866832
+ "use strict";
866833
+
866834
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
866835
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
866836
+ return new (P || (P = Promise))(function (resolve, reject) {
866837
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
866838
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
866839
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
866840
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
866841
+ });
866842
+ };
866843
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
866844
+ exports.getAuthTokenByDeviceFlow = void 0;
866845
+ const net_1 = __webpack_require__(31153);
866846
+ const web_1 = __webpack_require__(2240);
866847
+ const error_1 = __webpack_require__(64119);
866848
+ const coding_1 = __webpack_require__(40540);
866849
+ const system_1 = __webpack_require__(62179);
866850
+ const web_auth_1 = __webpack_require__(76097);
866851
+ /** 默认国内站 应用侧可通过 getOAuthEndpoint 覆写 */
866852
+ const OAUTH_ENDPOINT = process.env.TCB_OAUTH_ENDPOINT || 'https://tcb-api.cloud.tencent.com/qcloud-tcb/v1/oauth';
866853
+ const DEFAULT_CLIENT_ID = 'cloudbase-toolbox';
866854
+ const POLL_ERROR_CODES = {
866855
+ AUTHORIZATION_PENDING: 'authorization_pending',
866856
+ SLOW_DOWN: 'slow_down',
866857
+ EXPIRED_TOKEN: 'expired_token',
866858
+ ACCESS_DENIED: 'access_denied',
866859
+ };
866860
+ const SUCCESS_CODE = 'NORMAL';
866861
+ function fetchDeviceCode(options = {}) {
866862
+ const { client_id = DEFAULT_CLIENT_ID, endpoint = OAUTH_ENDPOINT } = options;
866863
+ return (0, net_1.postFetch)(`${endpoint}/device/code`, { client_id });
866864
+ }
866865
+ function fetchPollToken(options) {
866866
+ return __awaiter(this, void 0, void 0, function* () {
866867
+ const { device_code, client_id = DEFAULT_CLIENT_ID, endpoint = OAUTH_ENDPOINT } = options;
866868
+ const mac = yield (0, system_1.getMacAddress)();
866869
+ return (0, net_1.postFetch)(`${endpoint}/token`, {
866870
+ device_code,
866871
+ client_id,
866872
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
866873
+ device_info: {
866874
+ mac,
866875
+ os: (0, system_1.getOSInfo)(),
866876
+ hash: (0, coding_1.md5Encoding)(mac),
866877
+ }
866878
+ });
866879
+ });
866880
+ }
866881
+ function sleep(ms) {
866882
+ return new Promise((resolve) => {
866883
+ setTimeout(resolve, ms);
866884
+ });
866885
+ }
866886
+ function getAuthTokenByDeviceFlow(options = {}) {
866887
+ return __awaiter(this, void 0, void 0, function* () {
866888
+ const { client_id, onDeviceCode, getOAuthEndpoint, getAuthUrl, silent } = options;
866889
+ const endpoint = getOAuthEndpoint ? getOAuthEndpoint(OAUTH_ENDPOINT) : OAUTH_ENDPOINT;
866890
+ const deviceCodeResp = yield fetchDeviceCode({ client_id, endpoint });
866891
+ if (deviceCodeResp.code !== SUCCESS_CODE) {
866892
+ throw new error_1.CloudBaseError('Device Flow fetchDeviceCode failed', {
866893
+ code: deviceCodeResp.code,
866894
+ requestId: deviceCodeResp.reqId,
866895
+ });
866896
+ }
866897
+ const { device_code, user_code, expires_in, interval } = deviceCodeResp.result;
866898
+ // 暂时不消费 verification_uri,由客户端控制跳转
866899
+ const defaultVerificationUri = `${web_auth_1.CLI_AUTH_BASE_URL}#/cli-auth`;
866900
+ // from=cli 后续考虑改用 client_id,因为 toolbox 作为公共依赖,可能被不同 client 所引用
866901
+ const rawVerificationUri = `${defaultVerificationUri}?user_code=${user_code}&from=cli&flow=device`;
866902
+ const verification_uri = getAuthUrl ? getAuthUrl(rawVerificationUri) : rawVerificationUri;
866903
+ if (!silent) {
866904
+ // 打印授权信息,引导用户操作
866905
+ console.log('\n\n若链接未自动打开,请手动复制至浏览器,或尝试其他登录方式:');
866906
+ console.log(`\n${verification_uri}`);
866907
+ console.log(`\n用户码: ${user_code}\n`);
866908
+ }
866909
+ // 尝试自动打开授权页面
866910
+ yield (0, web_1.openUrl)(verification_uri);
866911
+ if (onDeviceCode) {
866912
+ onDeviceCode({ user_code, verification_uri, device_code, expires_in });
866913
+ }
866914
+ let pollInterval = interval;
866915
+ const deadline = Date.now() + expires_in * 1000;
866916
+ while (Date.now() < deadline) {
866917
+ yield sleep(pollInterval * 1000);
866918
+ let resp;
866919
+ try {
866920
+ resp = yield fetchPollToken({ device_code, interval: pollInterval, client_id, endpoint });
866921
+ }
866922
+ catch (e) {
866923
+ throw new error_1.CloudBaseError('Device Flow 轮询请求失败', { original: e });
866924
+ }
866925
+ const { code, result } = resp;
866926
+ // 服务端返回业务错误(result 中携带 error 字段)
866927
+ if (result && 'error' in result) {
866928
+ const { error, error_description } = result;
866929
+ if (error === POLL_ERROR_CODES.AUTHORIZATION_PENDING) {
866930
+ continue;
866931
+ }
866932
+ if (error === POLL_ERROR_CODES.SLOW_DOWN) {
866933
+ pollInterval += 5;
866934
+ continue;
866935
+ }
866936
+ if (error === POLL_ERROR_CODES.EXPIRED_TOKEN) {
866937
+ throw new error_1.CloudBaseError('设备码已过期,请重新发起授权');
866938
+ }
866939
+ if (error === POLL_ERROR_CODES.ACCESS_DENIED) {
866940
+ throw new error_1.CloudBaseError('用户拒绝了授权请求');
866941
+ }
866942
+ throw new error_1.CloudBaseError(error_description || `Device Flow 授权失败,错误: ${error}`, {
866943
+ code: error,
866944
+ requestId: resp.reqId,
866945
+ });
866946
+ }
866947
+ // 服务端返回成功的 Credential
866948
+ if (code === SUCCESS_CODE && result) {
866949
+ return result;
866950
+ }
866951
+ throw new error_1.CloudBaseError(`Device Flow 授权失败,错误码: ${code}`, {
866952
+ code,
866953
+ requestId: resp.reqId,
866954
+ });
866955
+ }
866956
+ throw new error_1.CloudBaseError('授权超时,用户未在有效期内完成授权,请重试');
866957
+ });
866958
+ }
866959
+ exports.getAuthTokenByDeviceFlow = getAuthTokenByDeviceFlow;
866960
+
866961
+
866808
866962
  /***/ }),
866809
866963
 
866810
866964
  /***/ 92452:
@@ -913315,6 +913469,10 @@ let LoginCommand = class LoginCommand extends common_1.Command {
913315
913469
  {
913316
913470
  flags: '--token [token]',
913317
913471
  desc: (0, i18n_1.t)('腾讯云 API 临时秘钥 Token')
913472
+ },
913473
+ {
913474
+ flags: '--flow <flow>',
913475
+ desc: (0, i18n_1.t)('Web 登录授权方式(device 或 web),默认 device')
913318
913476
  }
913319
913477
  ],
913320
913478
  desc: (0, i18n_1.t)('登录腾讯云账号'),
@@ -913325,7 +913483,7 @@ let LoginCommand = class LoginCommand extends common_1.Command {
913325
913483
  execute(options, log) {
913326
913484
  return __awaiter(this, void 0, void 0, function* () {
913327
913485
  log.verbose(options);
913328
- const { apiKeyId, apiKey, token } = options;
913486
+ const { apiKeyId, apiKey, token, flow } = options;
913329
913487
  const loading = (0, utils_1.loadingFactory)();
913330
913488
  loading.start((0, i18n_1.t)('检验登录状态'));
913331
913489
  const credential = yield (0, utils_1.checkAndGetCredential)();
@@ -913387,7 +913545,7 @@ let LoginCommand = class LoginCommand extends common_1.Command {
913387
913545
  }
913388
913546
  else {
913389
913547
  loading.start((0, i18n_1.t)('请在浏览器中打开的授权页面进行授权...'));
913390
- const res = yield (0, auth_1.login)();
913548
+ const res = yield (0, auth_1.login)({ flow });
913391
913549
  if (res.code === 'SUCCESS') {
913392
913550
  loading.succeed((0, i18n_1.t)('登录成功!'));
913393
913551
  yield askForCollectDataConfirm();
@@ -913395,6 +913553,9 @@ let LoginCommand = class LoginCommand extends common_1.Command {
913395
913553
  }
913396
913554
  else if (res.code === 'WEB_AUTH_FAILED') {
913397
913555
  loading.fail((0, i18n_1.t)('Web 授权登录失败'));
913556
+ if (res.error) {
913557
+ log.error(res.error);
913558
+ }
913398
913559
  console.log(chalk_1.default.yellow((0, i18n_1.t)('⚠️ 检测到环境兼容性问题')));
913399
913560
  console.log(chalk_1.default.cyan((0, i18n_1.t)('建议使用密钥登录:')));
913400
913561
  console.log(chalk_1.default.cyan((0, i18n_1.t)('tcb login --key')));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.12.5",
3
+ "version": "2.12.6",
4
4
  "description": "CLI for Tencent CloudBase (standalone bundle)",
5
5
  "bin": {
6
6
  "tcb": "bin/tcb",