@cloudbase/cli 2.12.4 → 2.12.5-beta.1

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.
@@ -326169,7 +326169,7 @@ module.exports = function generate_pattern(it, $keyword, $ruleType) {
326169
326169
  /***/ ((module) => {
326170
326170
 
326171
326171
  "use strict";
326172
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.4","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.7.4","@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 - 腾讯云云开发命令行工具,支持云函数、云数据库、静态托管等全栈云开发能力"}}');
326172
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@cloudbase/cli","version":"2.12.5-beta.1","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.7.4","@cloudbase/toolbox":"0.7.17-beta.0","@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 - 腾讯云云开发命令行工具,支持云函数、云数据库、静态托管等全栈云开发能力"}}');
326173
326173
 
326174
326174
  /***/ }),
326175
326175
 
@@ -398312,12 +398312,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
398312
398312
  Object.defineProperty(exports, "__esModule", ({ value: true }));
398313
398313
  exports.AuthSupevisor = exports.AuthSupervisor = void 0;
398314
398314
  const web_auth_1 = __webpack_require__(76097);
398315
+ const oauth_1 = __webpack_require__(92423);
398315
398316
  const common_1 = __webpack_require__(96711);
398316
398317
  const credential_1 = __webpack_require__(99795);
398318
+ const web_1 = __webpack_require__(2240);
398317
398319
  const error_1 = __webpack_require__(64119);
398318
398320
  __exportStar(__webpack_require__(96711), exports);
398319
398321
  __exportStar(__webpack_require__(99795), exports);
398320
398322
  __exportStar(__webpack_require__(76097), exports);
398323
+ __exportStar(__webpack_require__(92423), exports);
398321
398324
  class AuthSupervisor {
398322
398325
  /**
398323
398326
  * 单例模式,全局缓存
@@ -398367,7 +398370,7 @@ class AuthSupervisor {
398367
398370
  */
398368
398371
  loginByWebAuth(options = {}) {
398369
398372
  return __awaiter(this, void 0, void 0, function* () {
398370
- const { getAuthUrl, throwError, noBrowser, callbackTimeout } = options;
398373
+ const { getAuthUrl, throwError, noBrowser, callbackTimeout, mode: authFlowType, client_id, onDeviceCode } = options;
398371
398374
  if (this.cacheCredential && this.needCache && !this.isCacheExpire()) {
398372
398375
  return this.cacheCredential;
398373
398376
  }
@@ -398375,12 +398378,45 @@ class AuthSupervisor {
398375
398378
  let credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
398376
398379
  if (credential)
398377
398380
  return credential;
398378
- // 兼容临时秘钥
398379
- credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
398380
- getAuthUrl,
398381
- noBrowser,
398382
- callbackTimeout
398383
- });
398381
+ // 根据授权方式获取凭证
398382
+ switch (authFlowType) {
398383
+ case 'device':
398384
+ credential = yield (0, oauth_1.getAuthTokenByDeviceFlow)({ client_id, onDeviceCode });
398385
+ break;
398386
+ case 'web':
398387
+ credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
398388
+ getAuthUrl,
398389
+ noBrowser,
398390
+ callbackTimeout
398391
+ });
398392
+ break;
398393
+ case 'default':
398394
+ default: {
398395
+ const isNoBrowser = noBrowser || (0, web_1.isTruthyFlag)(process.env.TCB_NO_BROWSER);
398396
+ if (isNoBrowser) {
398397
+ credential = yield (0, oauth_1.getAuthTokenByDeviceFlow)({ client_id, onDeviceCode });
398398
+ }
398399
+ else {
398400
+ try {
398401
+ credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
398402
+ getAuthUrl,
398403
+ callbackTimeout,
398404
+ onOpenFailed: () => { }
398405
+ });
398406
+ }
398407
+ catch (e) {
398408
+ if ((e === null || e === void 0 ? void 0 : e.code) === 'BROWSER_OPEN_FAILED') {
398409
+ credential = yield (0, oauth_1.getAuthTokenByDeviceFlow)({ client_id, onDeviceCode });
398410
+ }
398411
+ else {
398412
+ throw e;
398413
+ }
398414
+ }
398415
+ }
398416
+ break;
398417
+ }
398418
+ }
398419
+ credential = (0, common_1.resolveCredential)(credential);
398384
398420
  try {
398385
398421
  yield (0, common_1.checkAuth)(credential, this.requestConfig);
398386
398422
  }
@@ -410279,7 +410315,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
410279
410315
  return (mod && mod.__esModule) ? mod : { "default": mod };
410280
410316
  };
410281
410317
  Object.defineProperty(exports, "__esModule", ({ value: true }));
410282
- exports.getDataFromWeb = void 0;
410318
+ exports.getDataFromWeb = exports.openUrl = exports.isTruthyFlag = void 0;
410283
410319
  const open_1 = __importDefault(__webpack_require__(30353));
410284
410320
  const query_string_1 = __importDefault(__webpack_require__(86663));
410285
410321
  const http_1 = __importDefault(__webpack_require__(58611));
@@ -410326,6 +410362,7 @@ function isTruthyFlag(value) {
410326
410362
  }
410327
410363
  return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
410328
410364
  }
410365
+ exports.isTruthyFlag = isTruthyFlag;
410329
410366
  function isVSCodeEnvironment() {
410330
410367
  return Boolean(process.env.VSCODE_IPC_HOOK_CLI
410331
410368
  || process.env.VSCODE_PID
@@ -410360,11 +410397,12 @@ function openUrlByBrowserEnv(url) {
410360
410397
  function shouldUseBrowserEnvFallback() {
410361
410398
  return process.platform === 'linux' && isVSCodeEnvironment();
410362
410399
  }
410363
- function openUrl(url) {
410400
+ function openUrl(url, options = {}) {
410364
410401
  return __awaiter(this, void 0, void 0, function* () {
410402
+ const { skipBrowserFallback = false } = options;
410365
410403
  try {
410366
410404
  const child = yield (0, open_1.default)(url, { url: true });
410367
- if (child === null || child === void 0 ? void 0 : child.once) {
410405
+ if ((child === null || child === void 0 ? void 0 : child.once) && !skipBrowserFallback) {
410368
410406
  child.once('error', (error) => __awaiter(this, void 0, void 0, function* () {
410369
410407
  if (shouldUseBrowserEnvFallback()) {
410370
410408
  yield openUrlByBrowserEnv(url);
@@ -410374,13 +410412,14 @@ function openUrl(url) {
410374
410412
  return true;
410375
410413
  }
410376
410414
  catch (e) {
410377
- if (shouldUseBrowserEnvFallback()) {
410415
+ if (!skipBrowserFallback && shouldUseBrowserEnvFallback()) {
410378
410416
  return openUrlByBrowserEnv(url);
410379
410417
  }
410380
410418
  return false;
410381
410419
  }
410382
410420
  });
410383
410421
  }
410422
+ exports.openUrl = openUrl;
410384
410423
  // 从 Web 页面中获取数据
410385
410424
  function getDataFromWeb(getUrl, type, options = {}) {
410386
410425
  var _a, _b;
@@ -410398,7 +410437,13 @@ function getDataFromWeb(getUrl, type, options = {}) {
410398
410437
  // 对 url 转码, 避免 wsl 无法正常打开地址
410399
410438
  // https://www.npmjs.com/package/open#url
410400
410439
  // https://github.com/sindresorhus/open/blob/master/index.js#L48
410401
- yield openUrl(url);
410440
+ const skipBrowserFallback = !!options.onOpenFailed;
410441
+ const opened = yield openUrl(url, { skipBrowserFallback });
410442
+ if (!opened && options.onOpenFailed) {
410443
+ server.close();
410444
+ options.onOpenFailed();
410445
+ throw new error_1.CloudBaseError('浏览器打开失败', { code: 'BROWSER_OPEN_FAILED' });
410446
+ }
410402
410447
  }
410403
410448
  return new Promise((resolve, reject) => {
410404
410449
  let finished = false;
@@ -743390,16 +743435,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
743390
743435
  });
743391
743436
  };
743392
743437
  Object.defineProperty(exports, "__esModule", ({ value: true }));
743393
- exports.getAuthTokenFromWeb = void 0;
743438
+ exports.getAuthTokenFromWeb = exports.CLI_AUTH_BASE_URL = void 0;
743394
743439
  const common_1 = __webpack_require__(96711);
743395
743440
  const coding_1 = __webpack_require__(40540);
743396
743441
  const web_1 = __webpack_require__(2240);
743397
743442
  const system_1 = __webpack_require__(62179);
743398
- const CliAuthBaseUrl = 'https://tcb.cloud.tencent.com/dev';
743443
+ exports.CLI_AUTH_BASE_URL = 'https://tcb.cloud.tencent.com/dev';
743399
743444
  // 打开云开发控制台,获取授权
743400
743445
  function getAuthTokenFromWeb(options = {}) {
743401
743446
  return __awaiter(this, void 0, void 0, function* () {
743402
- const { getAuthUrl, noBrowser, callbackTimeout } = options;
743447
+ const { getAuthUrl, noBrowser, callbackTimeout, onOpenFailed } = options;
743403
743448
  const mac = yield (0, system_1.getMacAddress)();
743404
743449
  const os = (0, system_1.getOSInfo)();
743405
743450
  const macHash = (0, coding_1.md5Encoding)(mac);
@@ -743412,7 +743457,7 @@ function getAuthTokenFromWeb(options = {}) {
743412
743457
  + '&from=cli';
743413
743458
  const encodedCallbackUrl = encodeURIComponent(callbackUrl);
743414
743459
  // 授权链接
743415
- const rawAuthUrl = `${CliAuthBaseUrl}?authCallbackUrl=${encodedCallbackUrl}#/cli-auth?${encodedQuery}`;
743460
+ const rawAuthUrl = `${exports.CLI_AUTH_BASE_URL}?authCallbackUrl=${encodedCallbackUrl}#/cli-auth?${encodedQuery}`;
743416
743461
  let cliAuthUrl = rawAuthUrl;
743417
743462
  if (getAuthUrl) {
743418
743463
  try {
@@ -743425,7 +743470,8 @@ function getAuthTokenFromWeb(options = {}) {
743425
743470
  return cliAuthUrl;
743426
743471
  }, 'login', {
743427
743472
  noBrowser,
743428
- callbackTimeout
743473
+ callbackTimeout,
743474
+ onOpenFailed
743429
743475
  });
743430
743476
  const credential = (0, common_1.resolveCredential)(query);
743431
743477
  return credential;
@@ -866641,6 +866687,137 @@ const format = [format_1.default];
866641
866687
  exports["default"] = format;
866642
866688
  //# sourceMappingURL=index.js.map
866643
866689
 
866690
+ /***/ }),
866691
+
866692
+ /***/ 92423:
866693
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
866694
+
866695
+ "use strict";
866696
+
866697
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
866698
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
866699
+ return new (P || (P = Promise))(function (resolve, reject) {
866700
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
866701
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
866702
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
866703
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
866704
+ });
866705
+ };
866706
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
866707
+ exports.getAuthTokenByDeviceFlow = void 0;
866708
+ const net_1 = __webpack_require__(31153);
866709
+ const web_1 = __webpack_require__(2240);
866710
+ const error_1 = __webpack_require__(64119);
866711
+ const coding_1 = __webpack_require__(40540);
866712
+ const system_1 = __webpack_require__(62179);
866713
+ const web_auth_1 = __webpack_require__(76097);
866714
+ const OAUTH_ENDPOINT = process.env.TCB_OAUTH_ENDPOINT || 'https://tcb-api.cloud.tencent.com/qcloud-tcb/v1/oauth';
866715
+ const DEFAULT_CLIENT_ID = 'cloudbase-toolbox';
866716
+ const POLL_ERROR_CODES = {
866717
+ AUTHORIZATION_PENDING: 'authorization_pending',
866718
+ SLOW_DOWN: 'slow_down',
866719
+ EXPIRED_TOKEN: 'expired_token',
866720
+ ACCESS_DENIED: 'access_denied',
866721
+ };
866722
+ const SUCCESS_CODE = 'NORMAL';
866723
+ function fetchDeviceCode(options = {}) {
866724
+ const { client_id = DEFAULT_CLIENT_ID } = options;
866725
+ return (0, net_1.postFetch)(`${OAUTH_ENDPOINT}/device/code`, { client_id });
866726
+ }
866727
+ function fetchPollToken(options) {
866728
+ return __awaiter(this, void 0, void 0, function* () {
866729
+ const { device_code, client_id = DEFAULT_CLIENT_ID } = options;
866730
+ const mac = yield (0, system_1.getMacAddress)();
866731
+ return (0, net_1.postFetch)(`${OAUTH_ENDPOINT}/token`, {
866732
+ device_code,
866733
+ client_id,
866734
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
866735
+ device_info: {
866736
+ mac,
866737
+ os: (0, system_1.getOSInfo)(),
866738
+ hash: (0, coding_1.md5Encoding)(mac),
866739
+ }
866740
+ });
866741
+ });
866742
+ }
866743
+ function sleep(ms) {
866744
+ return new Promise((resolve) => {
866745
+ setTimeout(resolve, ms);
866746
+ });
866747
+ }
866748
+ function getAuthTokenByDeviceFlow(options = {}) {
866749
+ return __awaiter(this, void 0, void 0, function* () {
866750
+ const { client_id, onDeviceCode } = options;
866751
+ const deviceCodeResp = yield fetchDeviceCode({ client_id });
866752
+ if (deviceCodeResp.code !== SUCCESS_CODE) {
866753
+ throw new error_1.CloudBaseError('Device Flow fetchDeviceCode failed', {
866754
+ code: deviceCodeResp.code,
866755
+ requestId: deviceCodeResp.reqId,
866756
+ });
866757
+ }
866758
+ const { device_code, user_code, expires_in, interval } = deviceCodeResp.result;
866759
+ // const defaultVerificationUri = deviceCodeResp.result.verification_uri || `${CLI_AUTH_BASE_URL}#/cli-auth`;
866760
+ // 暂时不消费 verification_uri,由客户端控制跳转
866761
+ const defaultVerificationUri = `${web_auth_1.CLI_AUTH_BASE_URL}#/cli-auth`;
866762
+ // from=cli 后续考虑改用 client_id,因为 toolbox 作为公共依赖,可能被不同 client 所引用
866763
+ const verification_uri = `${defaultVerificationUri}?user_code=${user_code}&from=cli&mode=device`;
866764
+ // 打印授权信息,引导用户操作
866765
+ console.log('\n\n若链接未自动打开,请手动复制至浏览器,或尝试其他登录方式:');
866766
+ console.log(`\n${verification_uri}`);
866767
+ console.log(`\n用户码: ${user_code}\n`);
866768
+ // 尝试自动打开授权页面
866769
+ yield (0, web_1.openUrl)(verification_uri);
866770
+ if (onDeviceCode) {
866771
+ onDeviceCode({ user_code, verification_uri, device_code, expires_in });
866772
+ }
866773
+ let pollInterval = interval;
866774
+ const deadline = Date.now() + expires_in * 1000;
866775
+ while (Date.now() < deadline) {
866776
+ yield sleep(pollInterval * 1000);
866777
+ let resp;
866778
+ try {
866779
+ resp = yield fetchPollToken({ device_code, interval: pollInterval, client_id });
866780
+ }
866781
+ catch (e) {
866782
+ throw new error_1.CloudBaseError('Device Flow 轮询请求失败', { original: e });
866783
+ }
866784
+ const { code, result } = resp;
866785
+ // 服务端返回业务错误(result 中携带 error 字段)
866786
+ if (result && 'error' in result) {
866787
+ const { error, error_description } = result;
866788
+ if (error === POLL_ERROR_CODES.AUTHORIZATION_PENDING) {
866789
+ continue;
866790
+ }
866791
+ if (error === POLL_ERROR_CODES.SLOW_DOWN) {
866792
+ pollInterval += 5;
866793
+ continue;
866794
+ }
866795
+ if (error === POLL_ERROR_CODES.EXPIRED_TOKEN) {
866796
+ throw new error_1.CloudBaseError('设备码已过期,请重新发起授权');
866797
+ }
866798
+ if (error === POLL_ERROR_CODES.ACCESS_DENIED) {
866799
+ throw new error_1.CloudBaseError('用户拒绝了授权请求');
866800
+ }
866801
+ throw new error_1.CloudBaseError(error_description || `Device Flow 授权失败,错误: ${error}`, {
866802
+ code: error,
866803
+ requestId: resp.reqId,
866804
+ });
866805
+ }
866806
+ // 服务端返回成功的 Credential
866807
+ if (code === SUCCESS_CODE && result) {
866808
+ return result;
866809
+ }
866810
+ throw new error_1.CloudBaseError(`Device Flow 授权失败,错误码: ${code}`, {
866811
+ code,
866812
+ requestId: resp.reqId,
866813
+ });
866814
+ }
866815
+ throw new error_1.CloudBaseError('授权超时,用户未在有效期内完成授权,请重试');
866816
+ });
866817
+ }
866818
+ exports.getAuthTokenByDeviceFlow = getAuthTokenByDeviceFlow;
866819
+
866820
+
866644
866821
  /***/ }),
866645
866822
 
866646
866823
  /***/ 92452:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.12.4",
3
+ "version": "2.12.5-beta.1",
4
4
  "description": "CLI for Tencent CloudBase (standalone bundle)",
5
5
  "bin": {
6
6
  "tcb": "bin/tcb",