@cloudbase/cloudbase-mcp 2.10.0 → 2.11.0
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/cli.cjs +3 -3
- package/dist/index.cjs +593 -64
- package/dist/index.js +71 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -22401,11 +22401,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22401
22401
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
22402
22402
|
exports.getPort = void 0;
|
|
22403
22403
|
const portfinder_1 = __importDefault(__webpack_require__(31323));
|
|
22404
|
-
|
|
22404
|
+
// 默认端口
|
|
22405
|
+
const LOCAL_DEFAULT_PORT = 9012;
|
|
22406
|
+
const REMOTE_DEFAULT_PORT = 19012;
|
|
22407
|
+
function isRemoteEnvironment() {
|
|
22408
|
+
return Boolean(process.env.SSH_CONNECTION
|
|
22409
|
+
|| process.env.SSH_CLIENT
|
|
22410
|
+
|| process.env.SSH_TTY
|
|
22411
|
+
|| process.env.VSCODE_IPC_HOOK_CLI
|
|
22412
|
+
|| process.env.VSCODE_AGENT_FOLDER
|
|
22413
|
+
|| process.env.REMOTE_CONTAINERS
|
|
22414
|
+
|| process.env.CODESPACES
|
|
22415
|
+
|| process.env.GITPOD_WORKSPACE_ID);
|
|
22416
|
+
}
|
|
22417
|
+
function getStartPort() {
|
|
22418
|
+
const customStartPort = Number(process.env.TCB_WEB_LOGIN_START_PORT);
|
|
22419
|
+
if (Number.isInteger(customStartPort) && customStartPort > 0 && customStartPort < 65535) {
|
|
22420
|
+
return customStartPort;
|
|
22421
|
+
}
|
|
22422
|
+
return isRemoteEnvironment() ? REMOTE_DEFAULT_PORT : LOCAL_DEFAULT_PORT;
|
|
22423
|
+
}
|
|
22424
|
+
// 获取本地可用端口
|
|
22405
22425
|
function getPort() {
|
|
22406
22426
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22427
|
+
const startPort = getStartPort();
|
|
22407
22428
|
const port = yield portfinder_1.default.getPortPromise({
|
|
22408
|
-
port:
|
|
22429
|
+
port: startPort,
|
|
22430
|
+
stopPort: 65535
|
|
22409
22431
|
});
|
|
22410
22432
|
return port;
|
|
22411
22433
|
});
|
|
@@ -41982,6 +42004,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41982
42004
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
41983
42005
|
exports.getMacAddress = void 0;
|
|
41984
42006
|
const address_1 = __importDefault(__webpack_require__(56163));
|
|
42007
|
+
// 获取本机 Mac 地址
|
|
41985
42008
|
function getMacAddress() {
|
|
41986
42009
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41987
42010
|
return new Promise((resolve) => {
|
|
@@ -42617,6 +42640,9 @@ const DefaultCloudBaseConfig = {
|
|
|
42617
42640
|
functionRoot: './functions',
|
|
42618
42641
|
functions: []
|
|
42619
42642
|
};
|
|
42643
|
+
/**
|
|
42644
|
+
* 从配置文件中解析 cloudbase 配置
|
|
42645
|
+
*/
|
|
42620
42646
|
function resolveCloudBaseConfig(options) {
|
|
42621
42647
|
var _a, _b;
|
|
42622
42648
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -42625,17 +42651,21 @@ function resolveCloudBaseConfig(options) {
|
|
|
42625
42651
|
searchFrom,
|
|
42626
42652
|
moduleName: 'tcb'
|
|
42627
42653
|
});
|
|
42654
|
+
// 检查旧的配置文件
|
|
42628
42655
|
if (oldTcbConfig) {
|
|
42629
42656
|
throw new error_1.CloudBaseError('tcbrc.json 配置文件已废弃,请使用 cloudbaserc 配置文件!');
|
|
42630
42657
|
}
|
|
42658
|
+
// 可能为 null
|
|
42631
42659
|
const localCloudBaseConfig = yield (0, cosmiconfig_1.loadConfig)({
|
|
42632
42660
|
searchFrom,
|
|
42633
42661
|
configPath
|
|
42634
42662
|
});
|
|
42663
|
+
// localCloudBaseConfig 不为空,且不存在 envId
|
|
42635
42664
|
if (localCloudBaseConfig && !localCloudBaseConfig.envId) {
|
|
42636
42665
|
throw new error_1.CloudBaseError('无效的配置文件,配置文件必须包含环境 Id(envId) 字段');
|
|
42637
42666
|
}
|
|
42638
42667
|
const cloudbaseConfig = Object.assign(Object.assign({}, DefaultCloudBaseConfig), localCloudBaseConfig);
|
|
42668
|
+
// 兼容不同形式的配置
|
|
42639
42669
|
if ((_a = cloudbaseConfig.functions) === null || _a === void 0 ? void 0 : _a.length) {
|
|
42640
42670
|
cloudbaseConfig.functions = (_b = cloudbaseConfig.functions) === null || _b === void 0 ? void 0 : _b.map((func) => {
|
|
42641
42671
|
if (func.config) {
|
|
@@ -42653,19 +42683,25 @@ function resolveCloudBaseConfig(options) {
|
|
|
42653
42683
|
});
|
|
42654
42684
|
}
|
|
42655
42685
|
exports.resolveCloudBaseConfig = resolveCloudBaseConfig;
|
|
42686
|
+
/**
|
|
42687
|
+
* 从命令行和配置文件中获取 envId
|
|
42688
|
+
*/
|
|
42656
42689
|
function getEnvId(commandOptions) {
|
|
42657
42690
|
var _a;
|
|
42658
42691
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42659
42692
|
const envId = commandOptions === null || commandOptions === void 0 ? void 0 : commandOptions.envId;
|
|
42660
42693
|
const configPath = (_a = commandOptions === null || commandOptions === void 0 ? void 0 : commandOptions.parent) === null || _a === void 0 ? void 0 : _a.configFile;
|
|
42661
42694
|
const cloudbaseConfig = yield resolveCloudBaseConfig(configPath);
|
|
42695
|
+
// 命令行 envId 可以覆盖配置文件 envId
|
|
42662
42696
|
const assignEnvId = envId || (cloudbaseConfig === null || cloudbaseConfig === void 0 ? void 0 : cloudbaseConfig.envId);
|
|
42663
42697
|
return assignEnvId;
|
|
42664
42698
|
});
|
|
42665
42699
|
}
|
|
42666
42700
|
exports.getEnvId = getEnvId;
|
|
42667
42701
|
const renderConfig = (template, view) => {
|
|
42702
|
+
// 渲染时不 escape
|
|
42668
42703
|
mustache_1.default.escape = (text) => {
|
|
42704
|
+
// 将对象转成 JSON 字符串
|
|
42669
42705
|
if (typeof text === 'object') {
|
|
42670
42706
|
try {
|
|
42671
42707
|
return JSON.stringify(text).replace(/"/g, '\\"');
|
|
@@ -42679,6 +42715,7 @@ const renderConfig = (template, view) => {
|
|
|
42679
42715
|
return mustache_1.default.render(template, view, ['"{{', '}}"']);
|
|
42680
42716
|
};
|
|
42681
42717
|
exports.renderConfig = renderConfig;
|
|
42718
|
+
// cloudbase v2+ 配置文件解析器
|
|
42682
42719
|
class ConfigParser {
|
|
42683
42720
|
static get(key, defaultValue, options) {
|
|
42684
42721
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -42696,14 +42733,22 @@ class ConfigParser {
|
|
|
42696
42733
|
return this.instance.options(options).update(key, value);
|
|
42697
42734
|
});
|
|
42698
42735
|
}
|
|
42736
|
+
// 解析配置
|
|
42699
42737
|
static parseRawConfig(rawConfig, cwd = process.cwd()) {
|
|
42700
42738
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42701
42739
|
let config = lodash_1.default.cloneDeep(rawConfig);
|
|
42740
|
+
// 命令行中指定的 envId,优先级最高
|
|
42702
42741
|
const envId = yargs_1.default.argv.e || yargs_1.default.argv.envId;
|
|
42742
|
+
// 加载本地 env 文件
|
|
42703
42743
|
const env = (0, env_1.loadEnvVariables)(cwd);
|
|
42744
|
+
// 转换成字符串
|
|
42704
42745
|
let configString = JSON.stringify(config);
|
|
42705
42746
|
const envs = {
|
|
42706
|
-
|
|
42747
|
+
// 环境变量
|
|
42748
|
+
env: Object.assign(Object.assign({
|
|
42749
|
+
// 注入 ENV_ID,同云端部署保持一致
|
|
42750
|
+
ENV_ID: envId || config.envId }, env), process.env),
|
|
42751
|
+
// 云开发相关的变量
|
|
42707
42752
|
tcb: {
|
|
42708
42753
|
envId: envId || config.envId
|
|
42709
42754
|
},
|
|
@@ -42711,14 +42756,17 @@ class ConfigParser {
|
|
|
42711
42756
|
uid: (0, uid_1.uuid)(24)
|
|
42712
42757
|
}
|
|
42713
42758
|
};
|
|
42759
|
+
// --envId 优先级最高
|
|
42714
42760
|
if (envId) {
|
|
42715
42761
|
envs.env.envId = envId;
|
|
42716
42762
|
envs.env.ENV_ID = envId;
|
|
42717
42763
|
}
|
|
42764
|
+
// 使用模板渲染
|
|
42718
42765
|
configString = (0, exports.renderConfig)(configString, envs);
|
|
42719
42766
|
config = JSON.parse(configString, (key, value) => {
|
|
42720
42767
|
if (typeof value === 'string') {
|
|
42721
42768
|
try {
|
|
42769
|
+
// 只解析对象
|
|
42722
42770
|
const parsed = JSON.parse(value);
|
|
42723
42771
|
if (typeof parsed === 'object') {
|
|
42724
42772
|
return parsed;
|
|
@@ -42737,6 +42785,7 @@ class ConfigParser {
|
|
|
42737
42785
|
constructor(options = {}) {
|
|
42738
42786
|
this.options(options);
|
|
42739
42787
|
}
|
|
42788
|
+
// 重写内部配置
|
|
42740
42789
|
options(options = {}) {
|
|
42741
42790
|
const { cwd = process.cwd(), cover = true, configPath } = options;
|
|
42742
42791
|
this.cwd = cwd;
|
|
@@ -42744,21 +42793,28 @@ class ConfigParser {
|
|
|
42744
42793
|
this.configPath = configPath;
|
|
42745
42794
|
return this;
|
|
42746
42795
|
}
|
|
42796
|
+
// get config value by lodash object paths
|
|
42797
|
+
// https://lodash.com/docs/4.17.15#get
|
|
42747
42798
|
get(key, defaultValue) {
|
|
42748
42799
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42749
42800
|
const config = yield this.getConfig();
|
|
42801
|
+
// 不带 key,返回整个配置
|
|
42750
42802
|
if (!key) {
|
|
42751
42803
|
return config;
|
|
42752
42804
|
}
|
|
42805
|
+
// 返回具体字段的值
|
|
42753
42806
|
return lodash_1.default.get(config, key, defaultValue);
|
|
42754
42807
|
});
|
|
42755
42808
|
}
|
|
42809
|
+
// update config value by lodash object paths
|
|
42810
|
+
// https://lodash.com/docs/4.17.15#set
|
|
42756
42811
|
update(key, value, cover) {
|
|
42757
42812
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42758
42813
|
const config = yield resolveCloudBaseConfig({
|
|
42759
42814
|
configPath: this.configPath
|
|
42760
42815
|
});
|
|
42761
42816
|
let unionConfig;
|
|
42817
|
+
// 当 value 为 undefined 且 key 为对象时,直接把 key 作为值更新到 config 中
|
|
42762
42818
|
if (typeof value === 'undefined' && typeof key === 'object') {
|
|
42763
42819
|
unionConfig = Object.assign(Object.assign({}, config), key);
|
|
42764
42820
|
}
|
|
@@ -42768,24 +42824,34 @@ class ConfigParser {
|
|
|
42768
42824
|
yield this.updateConfig(unionConfig, cover);
|
|
42769
42825
|
});
|
|
42770
42826
|
}
|
|
42827
|
+
// 读配置,支持外部直接调用
|
|
42771
42828
|
getConfig() {
|
|
42772
42829
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42830
|
+
// 配置文件路径不存在
|
|
42773
42831
|
if (!this.configPath) {
|
|
42832
|
+
// 搜索配置,获取配置目录
|
|
42774
42833
|
const result = yield (0, cosmiconfig_1.searchConfig)(this.cwd);
|
|
42834
|
+
// 设置 config 路径
|
|
42775
42835
|
this.configPath = result === null || result === void 0 ? void 0 : result.filepath;
|
|
42776
42836
|
}
|
|
42837
|
+
// 读取原配置
|
|
42777
42838
|
const rawConfig = yield resolveCloudBaseConfig({
|
|
42778
42839
|
configPath: this.configPath
|
|
42779
42840
|
});
|
|
42780
42841
|
return ConfigParser.parseRawConfig(rawConfig, this.cwd);
|
|
42781
42842
|
});
|
|
42782
42843
|
}
|
|
42844
|
+
// 写配置
|
|
42783
42845
|
updateConfig(config, cover = this.cover) {
|
|
42784
42846
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42847
|
+
// 配置文件路径不存在
|
|
42785
42848
|
if (!this.configPath) {
|
|
42849
|
+
// 搜索配置,获取配置目录
|
|
42786
42850
|
const result = yield (0, cosmiconfig_1.searchConfig)(this.cwd);
|
|
42851
|
+
// 设置 config 路径,config 可能不存在
|
|
42787
42852
|
this.configPath = result === null || result === void 0 ? void 0 : result.filepath;
|
|
42788
42853
|
}
|
|
42854
|
+
// 原配置
|
|
42789
42855
|
const baseConfig = yield (0, cosmiconfig_1.loadConfig)({
|
|
42790
42856
|
searchFrom: this.cwd,
|
|
42791
42857
|
configPath: this.configPath
|
|
@@ -42793,14 +42859,17 @@ class ConfigParser {
|
|
|
42793
42859
|
const unionConfig = cover
|
|
42794
42860
|
? Object.assign(Object.assign({}, baseConfig), config) : Object.assign(Object.assign({}, config), baseConfig);
|
|
42795
42861
|
let indent = 2;
|
|
42862
|
+
// 文件存在,检测文件缩进
|
|
42796
42863
|
if (this.configPath) {
|
|
42797
42864
|
const fileContent = yield fs_1.default.promises.readFile(this.configPath);
|
|
42798
42865
|
const detectRet = (0, detect_indent_1.detectIndent)(fileContent === null || fileContent === void 0 ? void 0 : fileContent.toString());
|
|
42799
42866
|
indent = (detectRet === null || detectRet === void 0 ? void 0 : detectRet.amount) || indent;
|
|
42800
42867
|
}
|
|
42801
42868
|
else {
|
|
42869
|
+
// 配置文件可能不存在,设置配置文件路径,直接写内容
|
|
42802
42870
|
this.configPath = path_1.default.join(this.cwd, 'cloudbaserc.json');
|
|
42803
42871
|
}
|
|
42872
|
+
// 写入配置到 json 文件中
|
|
42804
42873
|
jsonfile_1.default.writeFileSync(this.configPath, unionConfig, { spaces: indent });
|
|
42805
42874
|
});
|
|
42806
42875
|
}
|
|
@@ -67211,11 +67280,17 @@ module.exports = flatten;
|
|
|
67211
67280
|
|
|
67212
67281
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
67213
67282
|
exports.getPropertyByPath = void 0;
|
|
67283
|
+
// Resolves property names or property paths defined with period-delimited
|
|
67284
|
+
// strings or arrays of strings. Property names that are found on the source
|
|
67285
|
+
// object are used directly (even if they include a period).
|
|
67286
|
+
// Nested property names that include periods, within a path, are only
|
|
67287
|
+
// understood in array paths.
|
|
67214
67288
|
function getPropertyByPath(source, path) {
|
|
67215
67289
|
if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) {
|
|
67216
67290
|
return source[path];
|
|
67217
67291
|
}
|
|
67218
67292
|
const parsedPath = typeof path === 'string' ? path.split('.') : path;
|
|
67293
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67219
67294
|
return parsedPath.reduce((previous, key) => {
|
|
67220
67295
|
if (previous === undefined) {
|
|
67221
67296
|
return previous;
|
|
@@ -82787,7 +82862,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
82787
82862
|
});
|
|
82788
82863
|
};
|
|
82789
82864
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
82790
|
-
exports.AuthSupevisor = void 0;
|
|
82865
|
+
exports.AuthSupevisor = exports.AuthSupervisor = void 0;
|
|
82791
82866
|
const web_auth_1 = __webpack_require__(76097);
|
|
82792
82867
|
const common_1 = __webpack_require__(96711);
|
|
82793
82868
|
const credential_1 = __webpack_require__(99795);
|
|
@@ -82795,13 +82870,17 @@ const error_1 = __webpack_require__(64119);
|
|
|
82795
82870
|
__exportStar(__webpack_require__(96711), exports);
|
|
82796
82871
|
__exportStar(__webpack_require__(99795), exports);
|
|
82797
82872
|
__exportStar(__webpack_require__(76097), exports);
|
|
82798
|
-
class
|
|
82873
|
+
class AuthSupervisor {
|
|
82874
|
+
/**
|
|
82875
|
+
* 单例模式,全局缓存
|
|
82876
|
+
* @param options
|
|
82877
|
+
*/
|
|
82799
82878
|
static getInstance(options = {}) {
|
|
82800
|
-
if (
|
|
82801
|
-
return
|
|
82879
|
+
if (AuthSupervisor.instance) {
|
|
82880
|
+
return AuthSupervisor.instance;
|
|
82802
82881
|
}
|
|
82803
|
-
const instance = new
|
|
82804
|
-
|
|
82882
|
+
const instance = new AuthSupervisor(options);
|
|
82883
|
+
AuthSupervisor.instance = instance;
|
|
82805
82884
|
return instance;
|
|
82806
82885
|
}
|
|
82807
82886
|
constructor(options = {}) {
|
|
@@ -82814,11 +82893,15 @@ class AuthSupevisor {
|
|
|
82814
82893
|
this.cacheExpiredTime = 0;
|
|
82815
82894
|
this.throwError = throwError;
|
|
82816
82895
|
}
|
|
82896
|
+
/**
|
|
82897
|
+
* 获取登录状态信息
|
|
82898
|
+
*/
|
|
82817
82899
|
getLoginState() {
|
|
82818
82900
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82819
82901
|
if (this.cacheCredential && this.needCache && !this.isCacheExpire()) {
|
|
82820
82902
|
return this.cacheCredential;
|
|
82821
82903
|
}
|
|
82904
|
+
// 获取本地登录状态
|
|
82822
82905
|
const credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
|
|
82823
82906
|
if (this.needCache && credential) {
|
|
82824
82907
|
this.cacheCredential = credential;
|
|
@@ -82830,17 +82913,25 @@ class AuthSupevisor {
|
|
|
82830
82913
|
return credential;
|
|
82831
82914
|
});
|
|
82832
82915
|
}
|
|
82916
|
+
/**
|
|
82917
|
+
* 通过网页授权登录
|
|
82918
|
+
* @returns credential
|
|
82919
|
+
*/
|
|
82833
82920
|
loginByWebAuth(options = {}) {
|
|
82834
82921
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82835
|
-
const { getAuthUrl, throwError } = options;
|
|
82922
|
+
const { getAuthUrl, throwError, noBrowser, callbackTimeout } = options;
|
|
82836
82923
|
if (this.cacheCredential && this.needCache && !this.isCacheExpire()) {
|
|
82837
82924
|
return this.cacheCredential;
|
|
82838
82925
|
}
|
|
82926
|
+
// 校验本地秘钥
|
|
82839
82927
|
let credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
|
|
82840
82928
|
if (credential)
|
|
82841
82929
|
return credential;
|
|
82930
|
+
// 兼容临时秘钥
|
|
82842
82931
|
credential = yield (0, web_auth_1.getAuthTokenFromWeb)({
|
|
82843
|
-
getAuthUrl
|
|
82932
|
+
getAuthUrl,
|
|
82933
|
+
noBrowser,
|
|
82934
|
+
callbackTimeout
|
|
82844
82935
|
});
|
|
82845
82936
|
try {
|
|
82846
82937
|
yield (0, common_1.checkAuth)(credential, this.requestConfig);
|
|
@@ -82851,8 +82942,10 @@ class AuthSupevisor {
|
|
|
82851
82942
|
}
|
|
82852
82943
|
return null;
|
|
82853
82944
|
}
|
|
82945
|
+
// 通过 Web 登录时,本地要存储 tmpSecretId 形式,方式 CLI 登录失效
|
|
82854
82946
|
const webCredential = (0, common_1.resolveWebCredential)(credential);
|
|
82855
82947
|
yield credential_1.authStore.set('credential', webCredential);
|
|
82948
|
+
// 缓存处理转换后的 credential
|
|
82856
82949
|
if (this.needCache && credential) {
|
|
82857
82950
|
this.cacheCredential = credential;
|
|
82858
82951
|
const { accessTokenExpired } = credential;
|
|
@@ -82863,26 +82956,41 @@ class AuthSupevisor {
|
|
|
82863
82956
|
return credential;
|
|
82864
82957
|
});
|
|
82865
82958
|
}
|
|
82866
|
-
|
|
82959
|
+
/**
|
|
82960
|
+
* 通过 API Secret 登录,支持临时秘钥
|
|
82961
|
+
* @param secretId
|
|
82962
|
+
* @param secretKey
|
|
82963
|
+
* @param token
|
|
82964
|
+
* @param opts 选项配置,包括强制更新和额外的 Credential 字段
|
|
82965
|
+
* @returns credential
|
|
82966
|
+
*/
|
|
82967
|
+
// eslint-disable-next-line max-params
|
|
82968
|
+
loginByApiSecret(secretId, secretKey, token, opts) {
|
|
82867
82969
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82868
|
-
|
|
82970
|
+
const { forceUpdate = false, storeAsWebCredential = false, additionalCredentialFields } = opts || {};
|
|
82971
|
+
if (this.cacheCredential && this.needCache && !this.isCacheExpire() && !forceUpdate) {
|
|
82869
82972
|
return this.cacheCredential;
|
|
82870
82973
|
}
|
|
82871
|
-
|
|
82872
|
-
if (
|
|
82873
|
-
|
|
82974
|
+
// 校验本地秘钥(如果不是强制更新)
|
|
82975
|
+
if (!forceUpdate) {
|
|
82976
|
+
let credential = yield (0, credential_1.checkAndGetCredential)(this.requestConfig);
|
|
82977
|
+
if (credential)
|
|
82978
|
+
return credential;
|
|
82979
|
+
}
|
|
82980
|
+
// 当本地身份信息不存在时,才使用传入参数进行校验
|
|
82874
82981
|
if (!secretId || !secretKey) {
|
|
82875
82982
|
throw new error_1.CloudBaseError('secretId 或 secretKey 不能为空');
|
|
82876
82983
|
}
|
|
82877
|
-
credential = {
|
|
82878
|
-
secretId,
|
|
82984
|
+
const credential = Object.assign(Object.assign({}, additionalCredentialFields), { secretId,
|
|
82879
82985
|
secretKey,
|
|
82880
|
-
token
|
|
82881
|
-
};
|
|
82986
|
+
token });
|
|
82882
82987
|
try {
|
|
82883
82988
|
yield (0, common_1.checkAuth)(credential, this.requestConfig);
|
|
82884
82989
|
}
|
|
82885
82990
|
catch (e) {
|
|
82991
|
+
// CAM 错误视为登录正常
|
|
82992
|
+
// if (isCamRefused(e)) return credential;
|
|
82993
|
+
// 请求超时
|
|
82886
82994
|
if (e.type === 'request-timeout') {
|
|
82887
82995
|
throw new error_1.CloudBaseError('请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!');
|
|
82888
82996
|
}
|
|
@@ -82891,7 +82999,12 @@ class AuthSupevisor {
|
|
|
82891
82999
|
}
|
|
82892
83000
|
return null;
|
|
82893
83001
|
}
|
|
82894
|
-
|
|
83002
|
+
// 根据选项决定存储格式
|
|
83003
|
+
const credentialToStore = storeAsWebCredential
|
|
83004
|
+
? (0, common_1.resolveWebCredential)(credential)
|
|
83005
|
+
: credential;
|
|
83006
|
+
// 存储信息
|
|
83007
|
+
yield credential_1.authStore.set('credential', credentialToStore);
|
|
82895
83008
|
if (this.needCache && credential) {
|
|
82896
83009
|
this.cacheCredential = credential;
|
|
82897
83010
|
this.cacheExpiredTime = Date.now() + 3600 * 1000;
|
|
@@ -82904,10 +83017,11 @@ class AuthSupevisor {
|
|
|
82904
83017
|
if (this.cacheCredential) {
|
|
82905
83018
|
this.cacheCredential = null;
|
|
82906
83019
|
}
|
|
82907
|
-
const
|
|
83020
|
+
const credential = yield (0, credential_1.getCredentialWithoutCheck)();
|
|
82908
83021
|
try {
|
|
82909
|
-
|
|
82910
|
-
|
|
83022
|
+
// 仅使用 Web 控制台授权登录时才删除 token
|
|
83023
|
+
if (credential === null || credential === void 0 ? void 0 : credential.refreshToken) {
|
|
83024
|
+
yield (0, credential_1.refreshTmpToken)(Object.assign(Object.assign({}, credential), { isLogout: true }));
|
|
82911
83025
|
}
|
|
82912
83026
|
yield credential_1.authStore.delete('credential');
|
|
82913
83027
|
}
|
|
@@ -82922,6 +83036,29 @@ class AuthSupevisor {
|
|
|
82922
83036
|
return now >= this.cacheExpiredTime;
|
|
82923
83037
|
}
|
|
82924
83038
|
}
|
|
83039
|
+
exports.AuthSupervisor = AuthSupervisor;
|
|
83040
|
+
/**
|
|
83041
|
+
* @deprecated Use `AuthSupervisor` instead. This class has a spelling error and will be removed in a future version.
|
|
83042
|
+
*/
|
|
83043
|
+
class AuthSupevisor extends AuthSupervisor {
|
|
83044
|
+
/**
|
|
83045
|
+
* @deprecated Use `AuthSupervisor.getInstance` instead
|
|
83046
|
+
*/
|
|
83047
|
+
static getInstance(options = {}) {
|
|
83048
|
+
if (AuthSupevisor.instance) {
|
|
83049
|
+
return AuthSupevisor.instance;
|
|
83050
|
+
}
|
|
83051
|
+
const instance = new AuthSupevisor(options);
|
|
83052
|
+
AuthSupevisor.instance = instance;
|
|
83053
|
+
return instance;
|
|
83054
|
+
}
|
|
83055
|
+
/**
|
|
83056
|
+
* @deprecated Use `AuthSupervisor` constructor instead
|
|
83057
|
+
*/
|
|
83058
|
+
constructor(options = {}) {
|
|
83059
|
+
super(options);
|
|
83060
|
+
}
|
|
83061
|
+
}
|
|
82925
83062
|
exports.AuthSupevisor = AuthSupevisor;
|
|
82926
83063
|
|
|
82927
83064
|
|
|
@@ -84723,14 +84860,17 @@ exports.getDataFromWeb = void 0;
|
|
|
84723
84860
|
const open_1 = __importDefault(__webpack_require__(30353));
|
|
84724
84861
|
const query_string_1 = __importDefault(__webpack_require__(86663));
|
|
84725
84862
|
const http_1 = __importDefault(__webpack_require__(81630));
|
|
84863
|
+
const child_process_1 = __webpack_require__(79646);
|
|
84726
84864
|
const system_1 = __webpack_require__(62179);
|
|
84727
84865
|
const error_1 = __webpack_require__(64119);
|
|
84728
84866
|
const html_1 = __webpack_require__(74856);
|
|
84867
|
+
// 创建本地 Web 服务器,接受 Web 控制台传入的信息
|
|
84729
84868
|
function createLocalServer() {
|
|
84730
84869
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84731
84870
|
const server = http_1.default.createServer();
|
|
84732
84871
|
const port = yield (0, system_1.getPort)();
|
|
84733
84872
|
return new Promise((resolve, reject) => {
|
|
84873
|
+
// 服务启动异常
|
|
84734
84874
|
server.on('error', (e) => {
|
|
84735
84875
|
reject(e);
|
|
84736
84876
|
});
|
|
@@ -84743,6 +84883,7 @@ function createLocalServer() {
|
|
|
84743
84883
|
});
|
|
84744
84884
|
});
|
|
84745
84885
|
}
|
|
84886
|
+
// 返回 HTML 响应
|
|
84746
84887
|
function respondWithFile(options) {
|
|
84747
84888
|
const { req, res, statusCode, filename } = options;
|
|
84748
84889
|
return new Promise(function (resolve) {
|
|
@@ -84756,20 +84897,108 @@ function respondWithFile(options) {
|
|
|
84756
84897
|
resolve();
|
|
84757
84898
|
});
|
|
84758
84899
|
}
|
|
84759
|
-
function
|
|
84900
|
+
function isTruthyFlag(value) {
|
|
84901
|
+
if (!value) {
|
|
84902
|
+
return false;
|
|
84903
|
+
}
|
|
84904
|
+
return ['1', 'true', 'yes', 'on'].includes(String(value).trim().toLowerCase());
|
|
84905
|
+
}
|
|
84906
|
+
function isVSCodeEnvironment() {
|
|
84907
|
+
return Boolean(process.env.VSCODE_IPC_HOOK_CLI
|
|
84908
|
+
|| process.env.VSCODE_PID
|
|
84909
|
+
|| process.env.TERM_PROGRAM === 'vscode');
|
|
84910
|
+
}
|
|
84911
|
+
function parseBrowserCommand(browser) {
|
|
84912
|
+
const parts = browser.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
|
|
84913
|
+
return parts.map((item) => item.replace(/^"(.*)"$/, '$1'));
|
|
84914
|
+
}
|
|
84915
|
+
function openUrlByBrowserEnv(url) {
|
|
84916
|
+
var _a;
|
|
84917
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84918
|
+
const browser = (_a = process.env.BROWSER) === null || _a === void 0 ? void 0 : _a.trim();
|
|
84919
|
+
if (!browser) {
|
|
84920
|
+
return false;
|
|
84921
|
+
}
|
|
84922
|
+
const [command, ...args] = parseBrowserCommand(browser);
|
|
84923
|
+
if (!command) {
|
|
84924
|
+
return false;
|
|
84925
|
+
}
|
|
84926
|
+
const finalArgs = args.map((arg) => (arg === '%s' ? url : arg));
|
|
84927
|
+
if (!args.includes('%s')) {
|
|
84928
|
+
finalArgs.push(url);
|
|
84929
|
+
}
|
|
84930
|
+
return new Promise((resolve) => {
|
|
84931
|
+
(0, child_process_1.execFile)(command, finalArgs, (error) => {
|
|
84932
|
+
resolve(!error);
|
|
84933
|
+
});
|
|
84934
|
+
});
|
|
84935
|
+
});
|
|
84936
|
+
}
|
|
84937
|
+
function shouldUseBrowserEnvFallback() {
|
|
84938
|
+
return process.platform === 'linux' && isVSCodeEnvironment();
|
|
84939
|
+
}
|
|
84940
|
+
function openUrl(url) {
|
|
84760
84941
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84761
|
-
const { server, port } = yield createLocalServer();
|
|
84762
|
-
const url = getUrl(port);
|
|
84763
84942
|
try {
|
|
84764
|
-
yield (0, open_1.default)(url, { url: true });
|
|
84943
|
+
const child = yield (0, open_1.default)(url, { url: true });
|
|
84944
|
+
if (child === null || child === void 0 ? void 0 : child.once) {
|
|
84945
|
+
child.once('error', (error) => __awaiter(this, void 0, void 0, function* () {
|
|
84946
|
+
if (shouldUseBrowserEnvFallback()) {
|
|
84947
|
+
yield openUrlByBrowserEnv(url);
|
|
84948
|
+
}
|
|
84949
|
+
}));
|
|
84950
|
+
}
|
|
84951
|
+
return true;
|
|
84765
84952
|
}
|
|
84766
84953
|
catch (e) {
|
|
84767
|
-
|
|
84954
|
+
if (shouldUseBrowserEnvFallback()) {
|
|
84955
|
+
return openUrlByBrowserEnv(url);
|
|
84956
|
+
}
|
|
84957
|
+
return false;
|
|
84958
|
+
}
|
|
84959
|
+
});
|
|
84960
|
+
}
|
|
84961
|
+
// 从 Web 页面中获取数据
|
|
84962
|
+
function getDataFromWeb(getUrl, type, options = {}) {
|
|
84963
|
+
var _a, _b;
|
|
84964
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84965
|
+
const { server, port } = yield createLocalServer();
|
|
84966
|
+
const noBrowser = (_a = options.noBrowser) !== null && _a !== void 0 ? _a : isTruthyFlag(process.env.TCB_NO_BROWSER);
|
|
84967
|
+
const callbackTimeout = (_b = options.callbackTimeout) !== null && _b !== void 0 ? _b : 180000;
|
|
84968
|
+
if (!Number.isFinite(callbackTimeout) || callbackTimeout <= 0) {
|
|
84969
|
+
throw new error_1.CloudBaseError('callbackTimeout must be a positive number');
|
|
84970
|
+
}
|
|
84971
|
+
const url = getUrl(port);
|
|
84972
|
+
console.log('\n\n若链接未自动打开,请手动复制至浏览器,或尝试其他登录方式:');
|
|
84973
|
+
console.log(`\n${url}\n`);
|
|
84974
|
+
if (!noBrowser) {
|
|
84975
|
+
// 对 url 转码, 避免 wsl 无法正常打开地址
|
|
84976
|
+
// https://www.npmjs.com/package/open#url
|
|
84977
|
+
// https://github.com/sindresorhus/open/blob/master/index.js#L48
|
|
84978
|
+
yield openUrl(url);
|
|
84768
84979
|
}
|
|
84769
84980
|
return new Promise((resolve, reject) => {
|
|
84981
|
+
let finished = false;
|
|
84982
|
+
const timer = setTimeout(() => {
|
|
84983
|
+
if (finished) {
|
|
84984
|
+
return;
|
|
84985
|
+
}
|
|
84986
|
+
finished = true;
|
|
84987
|
+
server.close();
|
|
84988
|
+
reject(new error_1.CloudBaseError(`等待浏览器授权回调超时(${Math.floor(callbackTimeout / 1000)}s)!`));
|
|
84989
|
+
}, callbackTimeout);
|
|
84990
|
+
const finish = (fn) => {
|
|
84991
|
+
if (finished) {
|
|
84992
|
+
return;
|
|
84993
|
+
}
|
|
84994
|
+
finished = true;
|
|
84995
|
+
clearTimeout(timer);
|
|
84996
|
+
fn();
|
|
84997
|
+
};
|
|
84770
84998
|
server.on('request', (req, res) => {
|
|
84771
|
-
const
|
|
84999
|
+
const url = req.url || '/';
|
|
84772
85000
|
const { query } = query_string_1.default.parseUrl(url);
|
|
85001
|
+
// 响应 HTML 文件
|
|
84773
85002
|
if (query === null || query === void 0 ? void 0 : query.html) {
|
|
84774
85003
|
return respondWithFile({
|
|
84775
85004
|
req,
|
|
@@ -84777,25 +85006,33 @@ function getDataFromWeb(getUrl, type) {
|
|
|
84777
85006
|
statusCode: 200,
|
|
84778
85007
|
filename: `${type}Success`
|
|
84779
85008
|
}).then(() => {
|
|
84780
|
-
|
|
84781
|
-
|
|
85009
|
+
finish(() => {
|
|
85010
|
+
server.close();
|
|
85011
|
+
resolve(query);
|
|
85012
|
+
});
|
|
84782
85013
|
}).catch((e) => {
|
|
84783
|
-
|
|
84784
|
-
|
|
85014
|
+
finish(() => {
|
|
85015
|
+
server.close();
|
|
85016
|
+
reject(e);
|
|
85017
|
+
});
|
|
84785
85018
|
});
|
|
84786
85019
|
}
|
|
85020
|
+
// CORS 响应普通文本
|
|
84787
85021
|
res.writeHead(200, {
|
|
84788
85022
|
'Access-Control-Allow-Origin': '*',
|
|
84789
85023
|
'Access-Control-Allow-Methods': '*',
|
|
84790
85024
|
'Access-Control-Allow-Headers': '*',
|
|
84791
85025
|
'Content-Type': 'text/plain',
|
|
85026
|
+
// 立即关闭 http 连接
|
|
84792
85027
|
Connection: 'close'
|
|
84793
85028
|
});
|
|
84794
85029
|
res.end();
|
|
84795
85030
|
if (req.method !== 'OPTIONS') {
|
|
84796
85031
|
server.close();
|
|
84797
85032
|
}
|
|
84798
|
-
|
|
85033
|
+
finish(() => {
|
|
85034
|
+
resolve(query);
|
|
85035
|
+
});
|
|
84799
85036
|
});
|
|
84800
85037
|
});
|
|
84801
85038
|
});
|
|
@@ -89001,6 +89238,7 @@ __exportStar(__webpack_require__(31153), exports);
|
|
|
89001
89238
|
__exportStar(__webpack_require__(33283), exports);
|
|
89002
89239
|
__exportStar(__webpack_require__(79998), exports);
|
|
89003
89240
|
__exportStar(__webpack_require__(19835), exports);
|
|
89241
|
+
// export types
|
|
89004
89242
|
__exportStar(__webpack_require__(42612), exports);
|
|
89005
89243
|
|
|
89006
89244
|
|
|
@@ -93051,6 +93289,7 @@ const cloud_api_1 = __webpack_require__(2090);
|
|
|
93051
93289
|
const constant_1 = __webpack_require__(53393);
|
|
93052
93290
|
let commonCredential;
|
|
93053
93291
|
class CloudApiService {
|
|
93292
|
+
// 单例模式
|
|
93054
93293
|
static getInstance(service) {
|
|
93055
93294
|
var _a;
|
|
93056
93295
|
if ((_a = CloudApiService.serviceCacheMap) === null || _a === void 0 ? void 0 : _a[service]) {
|
|
@@ -93061,6 +93300,7 @@ class CloudApiService {
|
|
|
93061
93300
|
return apiService;
|
|
93062
93301
|
}
|
|
93063
93302
|
constructor(service, baseParams, version = '') {
|
|
93303
|
+
// 初始化 API 实例
|
|
93064
93304
|
this.apiService = new cloud_api_1.CloudApiService({
|
|
93065
93305
|
service,
|
|
93066
93306
|
version,
|
|
@@ -93089,6 +93329,7 @@ class CloudApiService {
|
|
|
93089
93329
|
}
|
|
93090
93330
|
}
|
|
93091
93331
|
exports.CloudApiService = CloudApiService;
|
|
93332
|
+
// 缓存请求实例
|
|
93092
93333
|
CloudApiService.serviceCacheMap = {};
|
|
93093
93334
|
|
|
93094
93335
|
|
|
@@ -101388,8 +101629,16 @@ const archiver_1 = __importDefault(__webpack_require__(30989));
|
|
|
101388
101629
|
exports.decompress = decompress_1.default;
|
|
101389
101630
|
const unzip = (zipFile, dest) => (0, exports.decompress)(zipFile, dest);
|
|
101390
101631
|
exports.unzip = unzip;
|
|
101632
|
+
/**
|
|
101633
|
+
* 解压流(使用临时 zip 包)
|
|
101634
|
+
* @param source 可读流
|
|
101635
|
+
* @param dest 解压目标文件夹
|
|
101636
|
+
* @param name 可选的临时 zip 包名
|
|
101637
|
+
*/
|
|
101391
101638
|
const unzipStream = (source, dest, name = 'gape3il5rk8.zip') => __awaiter(void 0, void 0, void 0, function* () {
|
|
101639
|
+
// 确保文件夹存在
|
|
101392
101640
|
yield (0, fs_2.mkdirAsync)(dest);
|
|
101641
|
+
// 使用一个临时文件下载 zip 包
|
|
101393
101642
|
const zipPath = path_1.default.join(dest, `${name}.zip`);
|
|
101394
101643
|
const zip = fs_1.default.createWriteStream(zipPath);
|
|
101395
101644
|
source.pipe(zip);
|
|
@@ -101432,13 +101681,16 @@ function zipFiles(allFilesPath, outputPath, ignore) {
|
|
|
101432
101681
|
archive.pipe(output);
|
|
101433
101682
|
allFilesPath.forEach(filePath => {
|
|
101434
101683
|
if (fs_1.default.statSync(filePath).isDirectory()) {
|
|
101684
|
+
// append files from a glob pattern
|
|
101435
101685
|
archive.glob('**/*', {
|
|
101686
|
+
// 目标路径
|
|
101436
101687
|
cwd: filePath,
|
|
101437
101688
|
ignore: ignore,
|
|
101438
101689
|
dot: true
|
|
101439
101690
|
});
|
|
101440
101691
|
}
|
|
101441
101692
|
else {
|
|
101693
|
+
// append file
|
|
101442
101694
|
archive.file(filePath);
|
|
101443
101695
|
}
|
|
101444
101696
|
});
|
|
@@ -112046,7 +112298,11 @@ Promise.PromiseInspection = PromiseInspection;
|
|
|
112046
112298
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
112047
112299
|
exports.AsyncMerge = void 0;
|
|
112048
112300
|
const cache_1 = __webpack_require__(51995);
|
|
112301
|
+
// 使用 Symbol 值,判断缓存结果时,可以准确判断是否为 Error 类型
|
|
112049
112302
|
const ERROR_KEY = Symbol('ERROR_KEY');
|
|
112303
|
+
/**
|
|
112304
|
+
* 异步任务合并
|
|
112305
|
+
*/
|
|
112050
112306
|
class AsyncMerge {
|
|
112051
112307
|
constructor() {
|
|
112052
112308
|
this.tasks = {};
|
|
@@ -112060,7 +112316,10 @@ class AsyncMerge {
|
|
|
112060
112316
|
throw new Error('AsyncMerge taskId could not be empty, it will cause unexpected result!');
|
|
112061
112317
|
}
|
|
112062
112318
|
return new Promise((resolve, reject) => {
|
|
112319
|
+
// 取缓存
|
|
112063
112320
|
const cacheRet = cache_1.nilCache.get(taskId);
|
|
112321
|
+
// 校验缓存,缓存结果可能为 null, undefined 等空值
|
|
112322
|
+
// 使用 Symbol 值做判断
|
|
112064
112323
|
if (maxAge > 0 && cacheRet !== cache_1.Cache.NIL) {
|
|
112065
112324
|
const e = cacheRet[ERROR_KEY];
|
|
112066
112325
|
if (e) {
|
|
@@ -112082,6 +112341,7 @@ class AsyncMerge {
|
|
|
112082
112341
|
}
|
|
112083
112342
|
});
|
|
112084
112343
|
}
|
|
112344
|
+
// eslint-disable-next-line
|
|
112085
112345
|
runTask(fn, taskId, taskOptions, cb) {
|
|
112086
112346
|
const { tasks } = this;
|
|
112087
112347
|
const { maxAge = 0, timeout = 60000 } = taskOptions;
|
|
@@ -112093,15 +112353,18 @@ class AsyncMerge {
|
|
|
112093
112353
|
}
|
|
112094
112354
|
tasks[taskId].callbacks.push(cb);
|
|
112095
112355
|
const task = tasks[taskId];
|
|
112356
|
+
// 当前类型的任务没有运行
|
|
112096
112357
|
if (!task.lock) {
|
|
112097
112358
|
let timerId = null;
|
|
112098
112359
|
if (timeout) {
|
|
112099
112360
|
timerId = setTimeout(() => {
|
|
112361
|
+
// 超时回调
|
|
112100
112362
|
task.callbacks.forEach((cb) => cb(new Error('TASK_TIMEOUT')));
|
|
112101
112363
|
task.lock = false;
|
|
112102
112364
|
delete tasks[taskId];
|
|
112103
112365
|
}, timeout);
|
|
112104
112366
|
}
|
|
112367
|
+
// 上锁,标志任务处理开始
|
|
112105
112368
|
task.lock = true;
|
|
112106
112369
|
fn()
|
|
112107
112370
|
.then((res) => {
|
|
@@ -112115,6 +112378,7 @@ class AsyncMerge {
|
|
|
112115
112378
|
clearTimeout(timerId);
|
|
112116
112379
|
task.lock = false;
|
|
112117
112380
|
delete tasks[taskId];
|
|
112381
|
+
// 任务异常,缓存异常值
|
|
112118
112382
|
maxAge > 0 && cache_1.nilCache.set(taskId, { ERROR_KEY: e }, maxAge);
|
|
112119
112383
|
task.callbacks.forEach((cb) => cb(e));
|
|
112120
112384
|
});
|
|
@@ -124758,6 +125022,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
124758
125022
|
exports.md5Encoding = void 0;
|
|
124759
125023
|
const crypto_1 = __importDefault(__webpack_require__(55511));
|
|
124760
125024
|
const error_1 = __webpack_require__(64119);
|
|
125025
|
+
// MD5
|
|
124761
125026
|
function md5Encoding(str = '') {
|
|
124762
125027
|
if (typeof str !== 'string')
|
|
124763
125028
|
throw new error_1.CloudBaseError('参数必须为字符串!');
|
|
@@ -125537,9 +125802,13 @@ const FileAsync_1 = __importDefault(__webpack_require__(19778));
|
|
|
125537
125802
|
const FileSync_1 = __importDefault(__webpack_require__(29303));
|
|
125538
125803
|
const fs_1 = __webpack_require__(96185);
|
|
125539
125804
|
const homeDir = os_1.default.homedir();
|
|
125805
|
+
// 系统配置目录
|
|
125540
125806
|
const homeAccessible = (0, fs_1.checkFullAccess)(homeDir);
|
|
125807
|
+
// 仅当 home 目录可访问时,才使用 home 目录,否则使用临时目录
|
|
125541
125808
|
const configDir = homeDir && homeAccessible ? path_1.default.join(homeDir, '.config') : path_1.default.join(os_1.default.tmpdir(), '.config');
|
|
125809
|
+
// cloudbase 配置目录
|
|
125542
125810
|
exports.cloudbaseConfigDir = path_1.default.join(configDir, '.cloudbase');
|
|
125811
|
+
// 确保目录存在
|
|
125543
125812
|
make_dir_1.default.sync(exports.cloudbaseConfigDir);
|
|
125544
125813
|
function getAsyncDB(file) {
|
|
125545
125814
|
const dbPath = path_1.default.join(exports.cloudbaseConfigDir, `${file}.json`);
|
|
@@ -126762,9 +127031,11 @@ function handleTimeout(e) {
|
|
|
126762
127031
|
throw new error_1.CloudBaseError('请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!');
|
|
126763
127032
|
}
|
|
126764
127033
|
else {
|
|
127034
|
+
// 其他错误,抛出
|
|
126765
127035
|
throw e;
|
|
126766
127036
|
}
|
|
126767
127037
|
}
|
|
127038
|
+
// 使用 fetch + 代理
|
|
126768
127039
|
function fetch(url, config = {}) {
|
|
126769
127040
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126770
127041
|
const proxy = (0, system_1.getProxy)();
|
|
@@ -126787,6 +127058,7 @@ function fetch(url, config = {}) {
|
|
|
126787
127058
|
});
|
|
126788
127059
|
}
|
|
126789
127060
|
exports.fetch = fetch;
|
|
127061
|
+
// 使用 fetch + 代理
|
|
126790
127062
|
function postFetch(url, data) {
|
|
126791
127063
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126792
127064
|
const proxy = (0, system_1.getProxy)();
|
|
@@ -126833,6 +127105,7 @@ function fetchStream(url, config = {}) {
|
|
|
126833
127105
|
});
|
|
126834
127106
|
}
|
|
126835
127107
|
exports.fetchStream = fetchStream;
|
|
127108
|
+
// 使用 fetch + 代理
|
|
126836
127109
|
function putFetch(url, config = {}) {
|
|
126837
127110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126838
127111
|
const proxy = (0, system_1.getProxy)();
|
|
@@ -136935,7 +137208,7 @@ class TelemetryReporter {
|
|
|
136935
137208
|
const nodeVersion = process.version; // Node.js版本
|
|
136936
137209
|
const arch = os_1.default.arch(); // 系统架构
|
|
136937
137210
|
// 从构建时注入的版本号获取MCP版本信息
|
|
136938
|
-
const mcpVersion = process.env.npm_package_version || "2.
|
|
137211
|
+
const mcpVersion = process.env.npm_package_version || "2.11.0" || 0;
|
|
136939
137212
|
return {
|
|
136940
137213
|
userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
|
|
136941
137214
|
deviceId: this.deviceId,
|
|
@@ -137261,6 +137534,9 @@ exports.getRegion = exports.getCloudBaseConfig = void 0;
|
|
|
137261
137534
|
const yargs_1 = __importDefault(__webpack_require__(5945));
|
|
137262
137535
|
const path_1 = __importDefault(__webpack_require__(39902));
|
|
137263
137536
|
const cloudbase_1 = __webpack_require__(10304);
|
|
137537
|
+
/**
|
|
137538
|
+
* 获取当前目录下的 cloudbase 配置
|
|
137539
|
+
*/
|
|
137264
137540
|
const getCloudBaseConfig = (configPath) => __awaiter(void 0, void 0, void 0, function* () {
|
|
137265
137541
|
let specificConfigPath = configPath || yargs_1.default.argv['config-path'];
|
|
137266
137542
|
specificConfigPath = specificConfigPath ? path_1.default.resolve(specificConfigPath) : undefined;
|
|
@@ -137271,7 +137547,11 @@ const getCloudBaseConfig = (configPath) => __awaiter(void 0, void 0, void 0, fun
|
|
|
137271
137547
|
return config;
|
|
137272
137548
|
});
|
|
137273
137549
|
exports.getCloudBaseConfig = getCloudBaseConfig;
|
|
137550
|
+
/**
|
|
137551
|
+
* 从命令行参数和配置文件中读取 region
|
|
137552
|
+
*/
|
|
137274
137553
|
const getRegion = (noDefault = false) => __awaiter(void 0, void 0, void 0, function* () {
|
|
137554
|
+
// region 缩写
|
|
137275
137555
|
const regionMap = {
|
|
137276
137556
|
gz: 'ap-guangzhou',
|
|
137277
137557
|
bj: 'ap-beijing',
|
|
@@ -137280,16 +137560,19 @@ const getRegion = (noDefault = false) => __awaiter(void 0, void 0, void 0, funct
|
|
|
137280
137560
|
cd: 'ap-chengdu',
|
|
137281
137561
|
cq: 'ap-chongqing'
|
|
137282
137562
|
};
|
|
137563
|
+
// 命令行中指定的 region
|
|
137283
137564
|
const argvRegion = (yargs_1.default.argv.r || yargs_1.default.argv.region);
|
|
137284
137565
|
if (argvRegion && regionMap[argvRegion]) {
|
|
137285
137566
|
return regionMap[argvRegion];
|
|
137286
137567
|
}
|
|
137287
137568
|
if (argvRegion)
|
|
137288
137569
|
return argvRegion;
|
|
137570
|
+
// 配置文件中的 region
|
|
137289
137571
|
const config = yield (0, exports.getCloudBaseConfig)();
|
|
137290
137572
|
if ((config === null || config === void 0 ? void 0 : config.region) && regionMap[config === null || config === void 0 ? void 0 : config.region]) {
|
|
137291
137573
|
return regionMap[config.region];
|
|
137292
137574
|
}
|
|
137575
|
+
// 不使用默认值时,不会默认返回 region
|
|
137293
137576
|
return noDefault ? config === null || config === void 0 ? void 0 : config.region : (config === null || config === void 0 ? void 0 : config.region) || 'ap-shanghai';
|
|
137294
137577
|
});
|
|
137295
137578
|
exports.getRegion = getRegion;
|
|
@@ -154757,6 +155040,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
154757
155040
|
exports.getOSInfo = exports.getPlatformRelease = void 0;
|
|
154758
155041
|
const os_1 = __importDefault(__webpack_require__(21820));
|
|
154759
155042
|
const macOSMap = new Map([
|
|
155043
|
+
[24, 'Sequoia'],
|
|
155044
|
+
[23, 'Sonoma'],
|
|
155045
|
+
[22, 'Ventura'],
|
|
155046
|
+
[21, 'Monterey'],
|
|
154760
155047
|
[20, 'BigSur'],
|
|
154761
155048
|
[19, 'Catalina'],
|
|
154762
155049
|
[18, 'Mojave'],
|
|
@@ -154772,9 +155059,19 @@ const macOSMap = new Map([
|
|
|
154772
155059
|
[8, 'Tiger'],
|
|
154773
155060
|
[7, 'Panther'],
|
|
154774
155061
|
[6, 'Jaguar'],
|
|
154775
|
-
[5, 'Puma']
|
|
155062
|
+
[5, 'Puma'] // macOS 10.1 Puma (2001)
|
|
154776
155063
|
]);
|
|
154777
155064
|
const winMap = new Map([
|
|
155065
|
+
['10.0.22000', '11'],
|
|
155066
|
+
['10.0.19041', '10'],
|
|
155067
|
+
['10.0.18363', '10'],
|
|
155068
|
+
['10.0.17763', '10'],
|
|
155069
|
+
['10.0.17134', '10'],
|
|
155070
|
+
['10.0.16299', '10'],
|
|
155071
|
+
['10.0.15063', '10'],
|
|
155072
|
+
['10.0.14393', '10'],
|
|
155073
|
+
['10.0.10586', '10'],
|
|
155074
|
+
['10.0.10240', '10'],
|
|
154778
155075
|
['10.0', '10'],
|
|
154779
155076
|
['6.3', '8.1'],
|
|
154780
155077
|
['6.2', '8'],
|
|
@@ -154785,28 +155082,55 @@ const winMap = new Map([
|
|
|
154785
155082
|
['5.0', '2000'],
|
|
154786
155083
|
['4.9', 'ME'],
|
|
154787
155084
|
['4.1', '98'],
|
|
154788
|
-
['4.0', '95']
|
|
155085
|
+
['4.0', '95'] // Windows 95 (1995)
|
|
154789
155086
|
]);
|
|
154790
155087
|
function getPlatformRelease(platform, release) {
|
|
155088
|
+
// macOS
|
|
154791
155089
|
if (platform === 'darwin') {
|
|
154792
|
-
const
|
|
154793
|
-
const
|
|
155090
|
+
const releaseParts = release.split('.');
|
|
155091
|
+
const majorNum = Number(releaseParts[0]);
|
|
155092
|
+
const minorNum = Number(releaseParts[1]) || 0;
|
|
155093
|
+
const name = macOSMap.get(majorNum) || 'macOS';
|
|
154794
155094
|
let version;
|
|
154795
|
-
|
|
154796
|
-
|
|
155095
|
+
// macOS 11 及以上版本 (majorNum >= 20)
|
|
155096
|
+
if (majorNum >= 20) {
|
|
155097
|
+
// releaseNum 20 -> macOS 11, 21 -> macOS 12, etc.
|
|
155098
|
+
const majorVersion = majorNum - 9;
|
|
155099
|
+
version = `${majorVersion}.${minorNum}`;
|
|
155100
|
+
// macOS 10.x 版本 (majorNum < 20)
|
|
154797
155101
|
}
|
|
154798
155102
|
else {
|
|
154799
|
-
|
|
155103
|
+
// releaseNum 19 -> 10.15, 18 -> 10.14, etc.
|
|
155104
|
+
const minorVersion = majorNum - 4;
|
|
155105
|
+
version = `10.${minorVersion}`;
|
|
154800
155106
|
}
|
|
154801
155107
|
return `${name} ${version}`;
|
|
154802
155108
|
}
|
|
155109
|
+
// windows
|
|
154803
155110
|
if (platform === 'win32') {
|
|
154804
|
-
|
|
154805
|
-
|
|
155111
|
+
// 尝试精确匹配完整版本号
|
|
155112
|
+
let windowsVersion = winMap.get(release);
|
|
155113
|
+
if (!windowsVersion) {
|
|
155114
|
+
// 如果没有精确匹配,尝试匹配主版本号
|
|
155115
|
+
const majorVersion = (/^\d+\.\d+/.exec(release) || [])[0];
|
|
155116
|
+
windowsVersion = winMap.get(majorVersion);
|
|
155117
|
+
}
|
|
155118
|
+
if (!windowsVersion) {
|
|
155119
|
+
// 如果还是没有匹配,尝试只匹配第一部分
|
|
155120
|
+
const firstPart = (/^\d+/.exec(release) || [])[0];
|
|
155121
|
+
if (firstPart === '10') {
|
|
155122
|
+
windowsVersion = '10';
|
|
155123
|
+
}
|
|
155124
|
+
}
|
|
155125
|
+
// 显示完整的版本信息
|
|
155126
|
+
const versionDisplay = windowsVersion || release;
|
|
155127
|
+
return `Windows ${versionDisplay}`;
|
|
154806
155128
|
}
|
|
155129
|
+
// 其他 Linux
|
|
154807
155130
|
return 'Linux';
|
|
154808
155131
|
}
|
|
154809
155132
|
exports.getPlatformRelease = getPlatformRelease;
|
|
155133
|
+
// 获取 hostname 和平台信息
|
|
154810
155134
|
function getOSInfo() {
|
|
154811
155135
|
const hostname = os_1.default.hostname();
|
|
154812
155136
|
const platform = os_1.default.platform();
|
|
@@ -155004,12 +155328,18 @@ function readFile(target) {
|
|
|
155004
155328
|
return '';
|
|
155005
155329
|
}
|
|
155006
155330
|
}
|
|
155331
|
+
// 从 env 文件中加载环境变量
|
|
155332
|
+
// 参考 https://cli.vuejs.org/zh/guide/mode-and-env.html
|
|
155007
155333
|
function loadEnvVariables(from = process.cwd()) {
|
|
155008
155334
|
const mode = yargs_1.default.argv.mode;
|
|
155335
|
+
// .env
|
|
155009
155336
|
const baseEnv = dotenv_1.default.parse(readFile(path_1.default.join(from, '.env')));
|
|
155337
|
+
// .env.local
|
|
155010
155338
|
const localEnv = dotenv_1.default.parse(readFile(path_1.default.join(from, '.env.local')));
|
|
155339
|
+
// .env.mode
|
|
155011
155340
|
const modeEnv = dotenv_1.default.parse(readFile(path_1.default.join(from, `.env.${mode}`)));
|
|
155012
155341
|
const unionConfig = lodash_1.default.merge({}, baseEnv, localEnv, modeEnv);
|
|
155342
|
+
// 扩展 dotenv 解析模式,支持 functions.xxx=xxx 形式设置对象
|
|
155013
155343
|
return Object.keys(unionConfig).reduce((prev, key) => {
|
|
155014
155344
|
return lodash_1.default.set(prev, key, unionConfig[key]);
|
|
155015
155345
|
}, {});
|
|
@@ -155095,28 +155425,46 @@ module.exports = diff
|
|
|
155095
155425
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
155096
155426
|
exports.nilCache = exports.memoryCache = exports.Cache = void 0;
|
|
155097
155427
|
class Entry {
|
|
155428
|
+
// eslint-disable-next-line
|
|
155098
155429
|
constructor(key, value, now, maxAge) {
|
|
155099
155430
|
this.key = key;
|
|
155100
155431
|
this.value = value;
|
|
155101
155432
|
this.now = now;
|
|
155102
155433
|
this.maxAge = maxAge;
|
|
155103
155434
|
}
|
|
155435
|
+
// 当前 entry 是否过期
|
|
155104
155436
|
isExpired() {
|
|
155105
155437
|
const now = Date.now();
|
|
155106
155438
|
return this.now + this.maxAge <= now;
|
|
155107
155439
|
}
|
|
155108
155440
|
}
|
|
155441
|
+
/**
|
|
155442
|
+
* 缓存模块
|
|
155443
|
+
* 1. 内存缓存
|
|
155444
|
+
* 2. TODO: 本地缓存
|
|
155445
|
+
*/
|
|
155109
155446
|
class Cache {
|
|
155110
155447
|
constructor(nil) {
|
|
155448
|
+
// use map to cache
|
|
155111
155449
|
this.store = new Map();
|
|
155112
155450
|
this.nil = false;
|
|
155113
155451
|
this.nil = nil;
|
|
155114
155452
|
}
|
|
155453
|
+
/**
|
|
155454
|
+
* 设置缓存
|
|
155455
|
+
* @param key 缓存 key
|
|
155456
|
+
* @param value 缓存值
|
|
155457
|
+
* @param maxAge 缓存保持时间,单位 ms
|
|
155458
|
+
*/
|
|
155115
155459
|
set(key, value, maxAge = 0) {
|
|
155116
155460
|
const now = maxAge ? Date.now() : 0;
|
|
155117
155461
|
const entry = new Entry(key, value, now, maxAge);
|
|
155118
155462
|
this.store.set(key, entry);
|
|
155119
155463
|
}
|
|
155464
|
+
/**
|
|
155465
|
+
* 获取缓存结果
|
|
155466
|
+
* @param key 缓存 key
|
|
155467
|
+
*/
|
|
155120
155468
|
get(key) {
|
|
155121
155469
|
const { nil } = this;
|
|
155122
155470
|
const entry = this.store.get(key);
|
|
@@ -155130,6 +155478,7 @@ class Cache {
|
|
|
155130
155478
|
}
|
|
155131
155479
|
}
|
|
155132
155480
|
exports.Cache = Cache;
|
|
155481
|
+
// 标志缓存不存在或过期
|
|
155133
155482
|
Cache.NIL = Symbol('NIL');
|
|
155134
155483
|
exports.memoryCache = new Cache();
|
|
155135
155484
|
exports.nilCache = new Cache(true);
|
|
@@ -162451,6 +162800,7 @@ class Explorer extends ExplorerBase_1.ExplorerBase {
|
|
|
162451
162800
|
return placeResult;
|
|
162452
162801
|
}
|
|
162453
162802
|
}
|
|
162803
|
+
// config not found
|
|
162454
162804
|
return null;
|
|
162455
162805
|
});
|
|
162456
162806
|
}
|
|
@@ -181629,12 +181979,15 @@ exports.execWithLoading = exports.loadingFactory = void 0;
|
|
|
181629
181979
|
const ora_1 = __importDefault(__webpack_require__(88267));
|
|
181630
181980
|
class Loading {
|
|
181631
181981
|
constructor() {
|
|
181982
|
+
// @ts-ignore
|
|
181632
181983
|
process.on('tcbExit', this.stop.bind(this));
|
|
181984
|
+
// @ts-ignore
|
|
181633
181985
|
process.on('tcbError', this.stop.bind(this));
|
|
181634
181986
|
this.spinner = (0, ora_1.default)({
|
|
181635
181987
|
discardStdin: false
|
|
181636
181988
|
});
|
|
181637
181989
|
}
|
|
181990
|
+
// eslint-disable-next-line
|
|
181638
181991
|
set text(text) {
|
|
181639
181992
|
this.spinner.text = text;
|
|
181640
181993
|
}
|
|
@@ -181661,9 +182014,15 @@ const loadingFactory = () => {
|
|
|
181661
182014
|
return new Loading();
|
|
181662
182015
|
};
|
|
181663
182016
|
exports.loadingFactory = loadingFactory;
|
|
182017
|
+
/**
|
|
182018
|
+
* 执行异步任务,显示 loading 动画
|
|
182019
|
+
* @param task
|
|
182020
|
+
* @param options
|
|
182021
|
+
*/
|
|
181664
182022
|
const execWithLoading = (task, options = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
181665
182023
|
const { startTip, successTip, failTip } = options;
|
|
181666
182024
|
const loading = (0, exports.loadingFactory)();
|
|
182025
|
+
// 刷新 loading 提示
|
|
181667
182026
|
const flush = (text) => {
|
|
181668
182027
|
loading.text = text;
|
|
181669
182028
|
};
|
|
@@ -196377,6 +196736,7 @@ module.exports = {
|
|
|
196377
196736
|
|
|
196378
196737
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
196379
196738
|
exports.getProxy = void 0;
|
|
196739
|
+
// 解析 Proxy 配置
|
|
196380
196740
|
function getProxy() {
|
|
196381
196741
|
const httpProxy = process.env.http_proxy ||
|
|
196382
196742
|
process.env.HTTP_PROXY ||
|
|
@@ -203507,7 +203867,7 @@ ${envIdSection}
|
|
|
203507
203867
|
## 环境信息
|
|
203508
203868
|
- 操作系统: ${os_1.default.type()} ${os_1.default.release()}
|
|
203509
203869
|
- Node.js版本: ${process.version}
|
|
203510
|
-
- MCP 版本:${process.env.npm_package_version || "2.
|
|
203870
|
+
- MCP 版本:${process.env.npm_package_version || "2.11.0" || 0}
|
|
203511
203871
|
- 系统架构: ${os_1.default.arch()}
|
|
203512
203872
|
- 时间: ${new Date().toISOString()}
|
|
203513
203873
|
- 请求ID: ${requestId}
|
|
@@ -203892,12 +204252,17 @@ const getSearchPlaces = (moduleName) => [
|
|
|
203892
204252
|
`${moduleName}rc.js`,
|
|
203893
204253
|
`${moduleName}.config.js`
|
|
203894
204254
|
];
|
|
204255
|
+
/**
|
|
204256
|
+
* 搜索指定配置文件,返回包含路径等信息
|
|
204257
|
+
*/
|
|
203895
204258
|
function searchConfig(dest, moduleName = MODULE_NAME) {
|
|
203896
204259
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203897
204260
|
const explorer = (0, explorer_1.cosmiconfig)(moduleName, {
|
|
204261
|
+
// 不向上搜索
|
|
203898
204262
|
stopDir: process.cwd(),
|
|
203899
204263
|
searchPlaces: getSearchPlaces(moduleName)
|
|
203900
204264
|
});
|
|
204265
|
+
// 搜索配置文件
|
|
203901
204266
|
try {
|
|
203902
204267
|
return explorer.search(dest || process.cwd());
|
|
203903
204268
|
}
|
|
@@ -203907,14 +204272,21 @@ function searchConfig(dest, moduleName = MODULE_NAME) {
|
|
|
203907
204272
|
});
|
|
203908
204273
|
}
|
|
203909
204274
|
exports.searchConfig = searchConfig;
|
|
204275
|
+
/**
|
|
204276
|
+
* 搜索或指定配置文件路径
|
|
204277
|
+
* 加载配置文件内容
|
|
204278
|
+
*/
|
|
203910
204279
|
function loadConfig(options = {}) {
|
|
203911
204280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
203912
204281
|
const { moduleName = MODULE_NAME, configPath, searchFrom } = options;
|
|
203913
204282
|
const explorer = (0, explorer_1.cosmiconfig)(moduleName, {
|
|
204283
|
+
// 不向上搜索
|
|
203914
204284
|
stopDir: process.cwd(),
|
|
203915
204285
|
searchPlaces: getSearchPlaces(moduleName)
|
|
203916
204286
|
});
|
|
204287
|
+
// 从指定路径加载配置文件
|
|
203917
204288
|
if (configPath) {
|
|
204289
|
+
// 校验路径是否存在
|
|
203918
204290
|
(0, fs_1.checkReadable)(configPath, true);
|
|
203919
204291
|
try {
|
|
203920
204292
|
const result = yield explorer.load(configPath);
|
|
@@ -203929,6 +204301,7 @@ function loadConfig(options = {}) {
|
|
|
203929
204301
|
});
|
|
203930
204302
|
}
|
|
203931
204303
|
}
|
|
204304
|
+
// 搜索配置文件
|
|
203932
204305
|
try {
|
|
203933
204306
|
const result = yield searchConfig(searchFrom || process.cwd(), moduleName);
|
|
203934
204307
|
if (!result)
|
|
@@ -205414,6 +205787,7 @@ function cosmiconfig(moduleName, options = {}) {
|
|
|
205414
205787
|
};
|
|
205415
205788
|
}
|
|
205416
205789
|
exports.cosmiconfig = cosmiconfig;
|
|
205790
|
+
// do not allow mutation of default loaders. Make sure it is set inside options
|
|
205417
205791
|
const defaultLoaders = Object.freeze({
|
|
205418
205792
|
'.js': loaders_1.loaders.loadJs,
|
|
205419
205793
|
'.json': loaders_1.loaders.loadJson,
|
|
@@ -211109,11 +211483,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
211109
211483
|
};
|
|
211110
211484
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
211111
211485
|
exports.yaml = exports.yamlStringify = exports.yamlParse = void 0;
|
|
211486
|
+
// https://github.com/nodeca/js-yaml
|
|
211112
211487
|
const yaml_1 = __importDefault(__webpack_require__(51381));
|
|
211488
|
+
// 解析 YAML 字符串
|
|
211113
211489
|
const yamlParse = (doc) => {
|
|
211114
211490
|
return yaml_1.default.parse(doc);
|
|
211115
211491
|
};
|
|
211116
211492
|
exports.yamlParse = yamlParse;
|
|
211493
|
+
// 导出为 YAML 字符串
|
|
211117
211494
|
const yamlStringify = (object) => {
|
|
211118
211495
|
return yaml_1.default.stringify(object);
|
|
211119
211496
|
};
|
|
@@ -211651,8 +212028,11 @@ checkIndex: 检查索引是否存在`),
|
|
|
211651
212028
|
title: "修改 NoSQL 数据库结构",
|
|
211652
212029
|
description: "修改 NoSQL 数据库结构",
|
|
211653
212030
|
inputSchema: {
|
|
211654
|
-
action: zod_1.z.enum([
|
|
211655
|
-
|
|
212031
|
+
action: zod_1.z.enum([
|
|
212032
|
+
"createCollection",
|
|
212033
|
+
"updateCollection",
|
|
212034
|
+
"deleteCollection",
|
|
212035
|
+
]).describe(`createCollection: 创建集合
|
|
211656
212036
|
updateCollection: 更新集合
|
|
211657
212037
|
deleteCollection: 删除集合`),
|
|
211658
212038
|
collectionName: zod_1.z.string().describe("集合名称"),
|
|
@@ -211732,9 +212112,7 @@ deleteCollection: 删除集合`),
|
|
|
211732
212112
|
success: true,
|
|
211733
212113
|
requestId: result.RequestId,
|
|
211734
212114
|
action,
|
|
211735
|
-
message: result.Exists === false
|
|
211736
|
-
? "集合不存在"
|
|
211737
|
-
: "云开发数据库集合删除成功",
|
|
212115
|
+
message: result.Exists === false ? "集合不存在" : "云开发数据库集合删除成功",
|
|
211738
212116
|
};
|
|
211739
212117
|
if (result.Exists === false) {
|
|
211740
212118
|
body.exists = false;
|
|
@@ -211765,9 +212143,17 @@ deleteCollection: 删除集合`),
|
|
|
211765
212143
|
.optional()
|
|
211766
212144
|
.describe("返回字段投影(对象或字符串,推荐对象)"),
|
|
211767
212145
|
sort: zod_1.z
|
|
211768
|
-
.union([
|
|
212146
|
+
.union([
|
|
212147
|
+
zod_1.z.array(zod_1.z
|
|
212148
|
+
.object({
|
|
212149
|
+
key: zod_1.z.string().describe("sort 字段名"),
|
|
212150
|
+
direction: zod_1.z.number().describe("排序方向,1:升序,-1:降序"),
|
|
212151
|
+
})
|
|
212152
|
+
.passthrough()),
|
|
212153
|
+
zod_1.z.string(),
|
|
212154
|
+
])
|
|
211769
212155
|
.optional()
|
|
211770
|
-
.describe("
|
|
212156
|
+
.describe("排序条件,使用对象或字符串。"),
|
|
211771
212157
|
limit: zod_1.z.number().optional().describe("返回数量限制"),
|
|
211772
212158
|
offset: zod_1.z.number().optional().describe("跳过的记录数"),
|
|
211773
212159
|
},
|
|
@@ -211813,7 +212199,8 @@ deleteCollection: 删除集合`),
|
|
|
211813
212199
|
title: "修改 NoSQL 数据库数据记录",
|
|
211814
212200
|
description: "修改 NoSQL 数据库数据记录",
|
|
211815
212201
|
inputSchema: {
|
|
211816
|
-
action: zod_1.z
|
|
212202
|
+
action: zod_1.z
|
|
212203
|
+
.enum(["insert", "update", "delete"])
|
|
211817
212204
|
.describe(`insert: 插入数据(新增文档)\nupdate: 更新数据\ndelete: 删除数据`),
|
|
211818
212205
|
collectionName: zod_1.z.string().describe("集合名称"),
|
|
211819
212206
|
documents: zod_1.z
|
|
@@ -217366,24 +217753,38 @@ const common_1 = __webpack_require__(96711);
|
|
|
217366
217753
|
const coding_1 = __webpack_require__(40540);
|
|
217367
217754
|
const web_1 = __webpack_require__(2240);
|
|
217368
217755
|
const system_1 = __webpack_require__(62179);
|
|
217369
|
-
const CliAuthBaseUrl = 'https://tcb.cloud.tencent.com/dev
|
|
217756
|
+
const CliAuthBaseUrl = 'https://tcb.cloud.tencent.com/dev';
|
|
217757
|
+
// 打开云开发控制台,获取授权
|
|
217370
217758
|
function getAuthTokenFromWeb(options = {}) {
|
|
217371
217759
|
return __awaiter(this, void 0, void 0, function* () {
|
|
217372
|
-
const { getAuthUrl } = options;
|
|
217760
|
+
const { getAuthUrl, noBrowser, callbackTimeout } = options;
|
|
217373
217761
|
const mac = yield (0, system_1.getMacAddress)();
|
|
217374
217762
|
const os = (0, system_1.getOSInfo)();
|
|
217375
217763
|
const macHash = (0, coding_1.md5Encoding)(mac);
|
|
217376
217764
|
const query = yield (0, web_1.getDataFromWeb)((port) => {
|
|
217377
|
-
|
|
217765
|
+
const callbackUrl = `http://127.0.0.1:${port}`;
|
|
217766
|
+
const encodedQuery = `port=${encodeURIComponent(String(port))}`
|
|
217767
|
+
+ `&hash=${encodeURIComponent(macHash)}`
|
|
217768
|
+
+ `&mac=${encodeURIComponent(mac)}`
|
|
217769
|
+
+ `&os=${encodeURIComponent(os)}`
|
|
217770
|
+
+ '&from=cli';
|
|
217771
|
+
const encodedCallbackUrl = encodeURIComponent(callbackUrl);
|
|
217772
|
+
// 授权链接
|
|
217773
|
+
const rawAuthUrl = `${CliAuthBaseUrl}?authCallbackUrl=${encodedCallbackUrl}#/cli-auth?${encodedQuery}`;
|
|
217774
|
+
let cliAuthUrl = rawAuthUrl;
|
|
217378
217775
|
if (getAuthUrl) {
|
|
217379
217776
|
try {
|
|
217380
|
-
cliAuthUrl = getAuthUrl(
|
|
217777
|
+
cliAuthUrl = getAuthUrl(rawAuthUrl);
|
|
217381
217778
|
}
|
|
217382
217779
|
catch (error) {
|
|
217780
|
+
// 忽略错误
|
|
217383
217781
|
}
|
|
217384
217782
|
}
|
|
217385
217783
|
return cliAuthUrl;
|
|
217386
|
-
}, 'login'
|
|
217784
|
+
}, 'login', {
|
|
217785
|
+
noBrowser,
|
|
217786
|
+
callbackTimeout
|
|
217787
|
+
});
|
|
217387
217788
|
const credential = (0, common_1.resolveCredential)(query);
|
|
217388
217789
|
return credential;
|
|
217389
217790
|
});
|
|
@@ -218223,7 +218624,7 @@ function registerSetupTools(server) {
|
|
|
218223
218624
|
title: "下载项目模板",
|
|
218224
218625
|
description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
|
|
218225
218626
|
|
|
218226
|
-
**CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置\n- cursor: Cursor AI编辑器\n- 其他IDE类型见下方列表\n\n注意:如果未传入 ide 参数且无法从环境变量检测到 IDE,将提示错误并要求传入 ide 参数\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n- kiro: Kiro AI编辑器\n- aider: Aider AI编辑器\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.
|
|
218627
|
+
**CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置\n- cursor: Cursor AI编辑器\n- 其他IDE类型见下方列表\n\n注意:如果未传入 ide 参数且无法从环境变量检测到 IDE,将提示错误并要求传入 ide 参数\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n- kiro: Kiro AI编辑器\n- aider: Aider AI编辑器\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.11.0" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
|
|
218227
218628
|
inputSchema: {
|
|
218228
218629
|
template: zod_1.z
|
|
218229
218630
|
.enum(["react", "vue", "miniprogram", "uniapp", "rules"])
|
|
@@ -255443,6 +255844,7 @@ module.exports = exports
|
|
|
255443
255844
|
|
|
255444
255845
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
255445
255846
|
exports.detectIndent = void 0;
|
|
255847
|
+
// https://github.com/sindresorhus/detect-indent/blob/master/index.js
|
|
255446
255848
|
const INDENT_REGEX = /^(?:( )+|\t+)/;
|
|
255447
255849
|
const INDENT_TYPE_SPACE = 'space';
|
|
255448
255850
|
const INDENT_TYPE_TAB = 'tab';
|
|
@@ -255453,6 +255855,7 @@ function makeIndentsMap(string) {
|
|
|
255453
255855
|
let key;
|
|
255454
255856
|
for (const line of string.split(/\n/g)) {
|
|
255455
255857
|
if (!line) {
|
|
255858
|
+
// Ignore empty lines
|
|
255456
255859
|
continue;
|
|
255457
255860
|
}
|
|
255458
255861
|
let indent;
|
|
@@ -255479,16 +255882,19 @@ function makeIndentsMap(string) {
|
|
|
255479
255882
|
weight = 0;
|
|
255480
255883
|
const indentDifference = indent - previousSize;
|
|
255481
255884
|
previousSize = indent;
|
|
255885
|
+
// Previous line have same indent?
|
|
255482
255886
|
if (indentDifference === 0) {
|
|
255483
255887
|
weight++;
|
|
255888
|
+
// We use the key from previous loop
|
|
255484
255889
|
}
|
|
255485
255890
|
else {
|
|
255486
255891
|
const absoluteIndentDifference = indentDifference > 0 ? indentDifference : -indentDifference;
|
|
255487
255892
|
key = encodeIndentsKey(indentType, absoluteIndentDifference);
|
|
255488
255893
|
}
|
|
255894
|
+
// Update the stats
|
|
255489
255895
|
entry = indents.get(key);
|
|
255490
255896
|
if (entry === undefined) {
|
|
255491
|
-
entry = [1, 0];
|
|
255897
|
+
entry = [1, 0]; // Init
|
|
255492
255898
|
}
|
|
255493
255899
|
else {
|
|
255494
255900
|
entry = [++entry[0], entry[1] + weight];
|
|
@@ -255498,16 +255904,20 @@ function makeIndentsMap(string) {
|
|
|
255498
255904
|
}
|
|
255499
255905
|
return indents;
|
|
255500
255906
|
}
|
|
255907
|
+
// Encode the indent type and amount as a string (e.g. 's4') for use as a compound key in the indents Map.
|
|
255501
255908
|
function encodeIndentsKey(indentType, indentAmount) {
|
|
255502
255909
|
const typeCharacter = indentType === INDENT_TYPE_SPACE ? 's' : 't';
|
|
255503
255910
|
return typeCharacter + String(indentAmount);
|
|
255504
255911
|
}
|
|
255912
|
+
// Extract the indent type and amount from a key of the indents Map.
|
|
255505
255913
|
function decodeIndentsKey(indentsKey) {
|
|
255506
255914
|
const keyHasTypeSpace = indentsKey[0] === 's';
|
|
255507
255915
|
const type = keyHasTypeSpace ? INDENT_TYPE_SPACE : INDENT_TYPE_TAB;
|
|
255508
255916
|
const amount = Number(indentsKey.slice(1));
|
|
255509
255917
|
return { type, amount };
|
|
255510
255918
|
}
|
|
255919
|
+
// Return the key (e.g. 's4') from the indents Map that represents the most common indent,
|
|
255920
|
+
// or return undefined if there are no indents.
|
|
255511
255921
|
function getMostUsedKey(indents) {
|
|
255512
255922
|
let result;
|
|
255513
255923
|
let maxUsed = 0;
|
|
@@ -256217,11 +256627,43 @@ exports.resetInteractiveServer = resetInteractiveServer;
|
|
|
256217
256627
|
exports.getInteractiveServerSafe = getInteractiveServerSafe;
|
|
256218
256628
|
const express_1 = __importDefault(__webpack_require__(26083));
|
|
256219
256629
|
const http_1 = __importDefault(__webpack_require__(81630));
|
|
256630
|
+
const child_process_1 = __webpack_require__(79646);
|
|
256220
256631
|
const open_1 = __importDefault(__webpack_require__(45368));
|
|
256221
256632
|
const ws_1 = __webpack_require__(17699);
|
|
256222
256633
|
const index_js_1 = __webpack_require__(79529);
|
|
256223
256634
|
const logger_js_1 = __webpack_require__(13039);
|
|
256224
|
-
|
|
256635
|
+
function isVSCodeEnvironment() {
|
|
256636
|
+
return Boolean(process.env.VSCODE_IPC_HOOK_CLI ||
|
|
256637
|
+
process.env.VSCODE_PID ||
|
|
256638
|
+
process.env.TERM_PROGRAM === "vscode");
|
|
256639
|
+
}
|
|
256640
|
+
function parseBrowserCommand(browser) {
|
|
256641
|
+
const parts = browser.match(/(?:[^\s"]+|"[^"]*")+/g) || [];
|
|
256642
|
+
return parts.map((item) => item.replace(/^"(.*)"$/, "$1"));
|
|
256643
|
+
}
|
|
256644
|
+
async function openUrlByBrowserEnv(url) {
|
|
256645
|
+
const browser = process.env.BROWSER?.trim();
|
|
256646
|
+
if (!browser) {
|
|
256647
|
+
return false;
|
|
256648
|
+
}
|
|
256649
|
+
const [command, ...args] = parseBrowserCommand(browser);
|
|
256650
|
+
if (!command) {
|
|
256651
|
+
return false;
|
|
256652
|
+
}
|
|
256653
|
+
const finalArgs = args.map((arg) => (arg === "%s" ? url : arg));
|
|
256654
|
+
if (!args.includes("%s")) {
|
|
256655
|
+
finalArgs.push(url);
|
|
256656
|
+
}
|
|
256657
|
+
return new Promise((resolve) => {
|
|
256658
|
+
(0, child_process_1.execFile)(command, finalArgs, (execError) => {
|
|
256659
|
+
resolve(!execError);
|
|
256660
|
+
});
|
|
256661
|
+
});
|
|
256662
|
+
}
|
|
256663
|
+
function shouldUseBrowserEnvFallback() {
|
|
256664
|
+
return process.platform === "linux" && isVSCodeEnvironment();
|
|
256665
|
+
}
|
|
256666
|
+
// Dynamic open behavior with IDE awareness and VSCode/Linux fallback
|
|
256225
256667
|
async function openUrl(url, options, mcpServer) {
|
|
256226
256668
|
// mcpServer 是 ExtendedMcpServer 实例,它有 server 和 ide 属性
|
|
256227
256669
|
// server 属性是 MCP server 的内部 server 实例,有 sendLoggingMessage 方法
|
|
@@ -256253,13 +256695,28 @@ async function openUrl(url, options, mcpServer) {
|
|
|
256253
256695
|
return;
|
|
256254
256696
|
}
|
|
256255
256697
|
}
|
|
256256
|
-
//
|
|
256698
|
+
// 默认行为:直接打开网页(带 VSCode/Linux 降级逻辑)
|
|
256257
256699
|
(0, logger_js_1.debug)(`[openUrl] Opening URL in browser: ${url}`);
|
|
256258
256700
|
try {
|
|
256259
|
-
|
|
256701
|
+
const openOptions = options ? { url: true, ...options } : { url: true };
|
|
256702
|
+
const child = await (0, open_1.default)(url, openOptions);
|
|
256703
|
+
if (child?.once) {
|
|
256704
|
+
child.once("error", async () => {
|
|
256705
|
+
if (shouldUseBrowserEnvFallback()) {
|
|
256706
|
+
(0, logger_js_1.debug)("[openUrl] open() failed, trying BROWSER fallback");
|
|
256707
|
+
await openUrlByBrowserEnv(url);
|
|
256708
|
+
}
|
|
256709
|
+
});
|
|
256710
|
+
}
|
|
256711
|
+
return;
|
|
256260
256712
|
}
|
|
256261
256713
|
catch (err) {
|
|
256262
256714
|
(0, logger_js_1.error)(`Failed to open ${url} ${options} ${err instanceof Error ? err.message : err} `, err instanceof Error ? err : new Error(String(err)));
|
|
256715
|
+
if (shouldUseBrowserEnvFallback()) {
|
|
256716
|
+
(0, logger_js_1.debug)("[openUrl] open() threw, trying BROWSER fallback");
|
|
256717
|
+
await openUrlByBrowserEnv(url);
|
|
256718
|
+
return;
|
|
256719
|
+
}
|
|
256263
256720
|
(0, logger_js_1.warn)(`Please manually open: ${url}`);
|
|
256264
256721
|
}
|
|
256265
256722
|
}
|
|
@@ -274943,8 +275400,14 @@ const fs_1 = __importDefault(__webpack_require__(29021));
|
|
|
274943
275400
|
const del_1 = __importDefault(__webpack_require__(62958));
|
|
274944
275401
|
const make_dir_1 = __importDefault(__webpack_require__(55589));
|
|
274945
275402
|
const error_1 = __webpack_require__(64119);
|
|
275403
|
+
/**
|
|
275404
|
+
* 检查路径是否可以访问(读、写)
|
|
275405
|
+
* @param dest 目标路径
|
|
275406
|
+
* @param throwError 无权限时是否抛出异常
|
|
275407
|
+
*/
|
|
274946
275408
|
function checkFullAccess(dest, throwError = false) {
|
|
274947
275409
|
try {
|
|
275410
|
+
// 可见、可写
|
|
274948
275411
|
fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
|
|
274949
275412
|
fs_1.default.accessSync(dest, fs_1.default.constants.W_OK);
|
|
274950
275413
|
fs_1.default.accessSync(dest, fs_1.default.constants.R_OK);
|
|
@@ -274960,8 +275423,14 @@ function checkFullAccess(dest, throwError = false) {
|
|
|
274960
275423
|
}
|
|
274961
275424
|
}
|
|
274962
275425
|
exports.checkFullAccess = checkFullAccess;
|
|
275426
|
+
/**
|
|
275427
|
+
* 检查路径是否可以读
|
|
275428
|
+
* @param dest 目标路径
|
|
275429
|
+
* @param throwError 无权限时是否抛出异常
|
|
275430
|
+
*/
|
|
274963
275431
|
function checkWritable(dest, throwError = false) {
|
|
274964
275432
|
try {
|
|
275433
|
+
// 可见、可写
|
|
274965
275434
|
fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
|
|
274966
275435
|
fs_1.default.accessSync(dest, fs_1.default.constants.W_OK);
|
|
274967
275436
|
return true;
|
|
@@ -274976,8 +275445,14 @@ function checkWritable(dest, throwError = false) {
|
|
|
274976
275445
|
}
|
|
274977
275446
|
}
|
|
274978
275447
|
exports.checkWritable = checkWritable;
|
|
275448
|
+
/**
|
|
275449
|
+
* 检查路径是否可以写
|
|
275450
|
+
* @param dest 目标路径
|
|
275451
|
+
* @param throwError 无权限或路径不存在时是否抛出异常
|
|
275452
|
+
*/
|
|
274979
275453
|
function checkReadable(dest, throwError = false) {
|
|
274980
275454
|
try {
|
|
275455
|
+
// 可见、可读
|
|
274981
275456
|
fs_1.default.accessSync(dest, fs_1.default.constants.F_OK);
|
|
274982
275457
|
fs_1.default.accessSync(dest, fs_1.default.constants.R_OK);
|
|
274983
275458
|
return true;
|
|
@@ -274992,10 +275467,18 @@ function checkReadable(dest, throwError = false) {
|
|
|
274992
275467
|
}
|
|
274993
275468
|
}
|
|
274994
275469
|
exports.checkReadable = checkReadable;
|
|
275470
|
+
/**
|
|
275471
|
+
* 检查指定路径是否为文件夹
|
|
275472
|
+
* @param dest 目标路径
|
|
275473
|
+
*/
|
|
274995
275474
|
function isDirectorySync(dest) {
|
|
274996
275475
|
return fs_1.default.statSync(dest).isDirectory();
|
|
274997
275476
|
}
|
|
274998
275477
|
exports.isDirectorySync = isDirectorySync;
|
|
275478
|
+
/**
|
|
275479
|
+
* 检查指定路径是否为文件夹,异步
|
|
275480
|
+
* @param dest 目标路径
|
|
275481
|
+
*/
|
|
274999
275482
|
function isDirectoryAsync(dest) {
|
|
275000
275483
|
return __awaiter(this, void 0, void 0, function* () {
|
|
275001
275484
|
const stat = yield fs_1.default.promises.stat(dest);
|
|
@@ -275003,6 +275486,12 @@ function isDirectoryAsync(dest) {
|
|
|
275003
275486
|
});
|
|
275004
275487
|
}
|
|
275005
275488
|
exports.isDirectoryAsync = isDirectoryAsync;
|
|
275489
|
+
/**
|
|
275490
|
+
* 格式化文件大小,保留两位小数
|
|
275491
|
+
* @param size 原数据,单位 Byte
|
|
275492
|
+
* @param unit 目标单位,支持 KB、MB、GB、TB
|
|
275493
|
+
* @param fixed 保留小数位数,默认 2 位
|
|
275494
|
+
*/
|
|
275006
275495
|
function formateFileSize(size, unit, fixed) {
|
|
275007
275496
|
const numSize = Number(size);
|
|
275008
275497
|
const unitMap = {
|
|
@@ -275014,6 +275503,7 @@ function formateFileSize(size, unit, fixed) {
|
|
|
275014
275503
|
return Number(numSize / unitMap[unit]).toFixed(fixed);
|
|
275015
275504
|
}
|
|
275016
275505
|
exports.formateFileSize = formateFileSize;
|
|
275506
|
+
// 创建文件夹
|
|
275017
275507
|
function mkdirSync(dest) {
|
|
275018
275508
|
make_dir_1.default.sync(dest);
|
|
275019
275509
|
}
|
|
@@ -275024,6 +275514,7 @@ function mkdirAsync(dest) {
|
|
|
275024
275514
|
});
|
|
275025
275515
|
}
|
|
275026
275516
|
exports.mkdirAsync = mkdirAsync;
|
|
275517
|
+
// 转换 Windows 下的反斜杠路径
|
|
275027
275518
|
const slash = (input) => {
|
|
275028
275519
|
const isExtendedLengthPath = /^\\\\\?\\/.test(input);
|
|
275029
275520
|
if (isExtendedLengthPath) {
|
|
@@ -275032,8 +275523,10 @@ const slash = (input) => {
|
|
|
275032
275523
|
return input.replace(/\\/g, '/');
|
|
275033
275524
|
};
|
|
275034
275525
|
exports.slash = slash;
|
|
275526
|
+
// 删除文件
|
|
275035
275527
|
function delSync(patterns) {
|
|
275036
275528
|
let paths;
|
|
275529
|
+
// 不能再使用反斜杠,修复 Windows 下的问题 https://github.com/sindresorhus/del/releases/tag/v5.0.0
|
|
275037
275530
|
if (Array.isArray(patterns)) {
|
|
275038
275531
|
paths = patterns.map((item) => (0, exports.slash)(item));
|
|
275039
275532
|
}
|
|
@@ -275732,8 +276225,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
|
275732
276225
|
exports.resolveWebCredential = exports.resolveCredential = exports.checkAuth = void 0;
|
|
275733
276226
|
const cloud_api_1 = __webpack_require__(2090);
|
|
275734
276227
|
const config_1 = __webpack_require__(88472);
|
|
276228
|
+
// 调用 env:list 接口,检查密钥是否有效
|
|
275735
276229
|
function checkAuth(credential, options = {}) {
|
|
275736
276230
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276231
|
+
// 兼容原临时秘钥
|
|
275737
276232
|
const { secretId, secretKey, token } = resolveCredential(credential);
|
|
275738
276233
|
const { proxy, timeout } = options;
|
|
275739
276234
|
const region = yield (0, config_1.getRegion)();
|
|
@@ -275754,8 +276249,10 @@ function checkAuth(credential, options = {}) {
|
|
|
275754
276249
|
});
|
|
275755
276250
|
}
|
|
275756
276251
|
exports.checkAuth = checkAuth;
|
|
276252
|
+
// 兼容解析旧的登录态
|
|
275757
276253
|
function resolveCredential(data) {
|
|
275758
276254
|
let { secretId, secretKey, token, accessTokenExpired, tmpSecretId, tmpSecretKey, tmpToken, tmpExpired, expired, authTime, refreshToken, uin, hash, envId } = data;
|
|
276255
|
+
// 兼容旧的登录态信息
|
|
275759
276256
|
token = token || tmpToken;
|
|
275760
276257
|
secretId = secretId || tmpSecretId;
|
|
275761
276258
|
secretKey = secretKey || tmpSecretKey;
|
|
@@ -281712,6 +282209,7 @@ function resolveCredentialFormEnv() {
|
|
|
281712
282209
|
token
|
|
281713
282210
|
};
|
|
281714
282211
|
}
|
|
282212
|
+
// 获取 credential 数据
|
|
281715
282213
|
function getCredentialData() {
|
|
281716
282214
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281717
282215
|
const localData = (yield exports.authStore.get('credential'));
|
|
@@ -281720,6 +282218,7 @@ function getCredentialData() {
|
|
|
281720
282218
|
const keys = Object.keys(credential)
|
|
281721
282219
|
.filter((key) => credential[key])
|
|
281722
282220
|
.filter((key) => key !== '-');
|
|
282221
|
+
// 检查是否为空对象
|
|
281723
282222
|
if (!credential || keys.length === 0) {
|
|
281724
282223
|
return null;
|
|
281725
282224
|
}
|
|
@@ -281727,6 +282226,7 @@ function getCredentialData() {
|
|
|
281727
282226
|
});
|
|
281728
282227
|
}
|
|
281729
282228
|
exports.getCredentialData = getCredentialData;
|
|
282229
|
+
// 临时密钥过期后,进行续期
|
|
281730
282230
|
function refreshTmpToken(metaData) {
|
|
281731
282231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281732
282232
|
const mac = yield (0, system_1.getMacAddress)();
|
|
@@ -281735,6 +282235,7 @@ function refreshTmpToken(metaData) {
|
|
|
281735
282235
|
const credential = (0, common_1.resolveWebCredential)(metaData);
|
|
281736
282236
|
const res = yield async_1.AsyncMerge.merge(() => (0, cloud_api_1.fetch)(refreshTokenUrl, {
|
|
281737
282237
|
method: 'POST',
|
|
282238
|
+
// 超时时间:15S
|
|
281738
282239
|
timeout: 15000,
|
|
281739
282240
|
body: JSON.stringify(credential),
|
|
281740
282241
|
headers: { 'Content-Type': 'application/json' }
|
|
@@ -281758,6 +282259,7 @@ function refreshTmpToken(metaData) {
|
|
|
281758
282259
|
});
|
|
281759
282260
|
}
|
|
281760
282261
|
exports.refreshTmpToken = refreshTmpToken;
|
|
282262
|
+
// 是否为 CAM 权限错误
|
|
281761
282263
|
const isCamRefused = (e) => {
|
|
281762
282264
|
return (Number(e.code) === 4102 ||
|
|
281763
282265
|
Number(e.code) === 42 ||
|
|
@@ -281765,16 +282267,22 @@ const isCamRefused = (e) => {
|
|
|
281765
282267
|
e.code === 'AuthFailure.UnauthorizedOperation');
|
|
281766
282268
|
};
|
|
281767
282269
|
exports.isCamRefused = isCamRefused;
|
|
282270
|
+
// 报错返回 null 值
|
|
281768
282271
|
function wrapCheckAuth(credential, options) {
|
|
281769
282272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281770
282273
|
const { timeout = 15000 } = options;
|
|
281771
282274
|
try {
|
|
282275
|
+
// 合并请求,避免超过接口限频
|
|
281772
282276
|
yield async_1.AsyncMerge.merge(() => (0, common_1.checkAuth)(credential, options), 'checkAuth', {
|
|
282277
|
+
// 超时时间不能小于发送请求的超时时间
|
|
281773
282278
|
timeout: Number(timeout) ? (timeout < 15000 ? 15000 : timeout + 1000) : 15000
|
|
281774
282279
|
});
|
|
281775
282280
|
return credential;
|
|
281776
282281
|
}
|
|
281777
282282
|
catch (e) {
|
|
282283
|
+
// CAM 错误视为登录正常
|
|
282284
|
+
// if (isCamRefused(e)) return credential;
|
|
282285
|
+
// 请求超时
|
|
281778
282286
|
if (e.type === 'request-timeout') {
|
|
281779
282287
|
throw new error_1.CloudBaseError('请求超时,请检查你的网络,如果终端无法直接访问公网,请设置终端 HTTP 请求代理!');
|
|
281780
282288
|
}
|
|
@@ -281782,38 +282290,50 @@ function wrapCheckAuth(credential, options) {
|
|
|
281782
282290
|
}
|
|
281783
282291
|
});
|
|
281784
282292
|
}
|
|
282293
|
+
// token 将在 n 分钟内过期
|
|
281785
282294
|
const isTokenExpired = (credential, gap = 120) => credential.accessTokenExpired &&
|
|
281786
282295
|
Number(credential.accessTokenExpired) < Date.now() + gap * 1000;
|
|
282296
|
+
// 获取身份认证信息并校验、自动刷新
|
|
281787
282297
|
function checkAndGetCredential(options = {}) {
|
|
281788
282298
|
return __awaiter(this, void 0, void 0, function* () {
|
|
282299
|
+
// 从本地存储中读取 credential
|
|
281789
282300
|
const credential = yield getCredentialData();
|
|
281790
282301
|
if (!credential) {
|
|
281791
282302
|
return null;
|
|
281792
282303
|
}
|
|
282304
|
+
// 存在临时密钥信息
|
|
281793
282305
|
if (credential.refreshToken) {
|
|
282306
|
+
// 临时密钥在 2 小时有效期内,可以直接使用
|
|
281794
282307
|
if (!isTokenExpired(credential)) {
|
|
282308
|
+
// 检查 credential
|
|
281795
282309
|
return wrapCheckAuth(credential, options);
|
|
281796
282310
|
}
|
|
281797
282311
|
else if (Date.now() < Number(credential.expired)) {
|
|
282312
|
+
// 临时密钥超过两小时有效期,但在 1 个月 refresh 有效期内,刷新临时密钥
|
|
281798
282313
|
let refreshCredential;
|
|
281799
282314
|
try {
|
|
281800
282315
|
refreshCredential = yield refreshTmpToken(credential);
|
|
281801
282316
|
}
|
|
281802
282317
|
catch (e) {
|
|
282318
|
+
// 登录态失效
|
|
281803
282319
|
if (e.code === 'AUTH_FAIL') {
|
|
281804
282320
|
return null;
|
|
281805
282321
|
}
|
|
281806
282322
|
else if (e.code === 'InternalError.GetRoleError') {
|
|
282323
|
+
// 用户未开通服务,视为登录态失效
|
|
281807
282324
|
return null;
|
|
281808
282325
|
}
|
|
281809
282326
|
else {
|
|
282327
|
+
// 异常错误
|
|
281810
282328
|
throw e;
|
|
281811
282329
|
}
|
|
281812
282330
|
}
|
|
282331
|
+
// 存储新的秘钥
|
|
281813
282332
|
yield exports.authStore.set('credential', refreshCredential || {});
|
|
281814
282333
|
return wrapCheckAuth((0, common_1.resolveCredential)(refreshCredential), options);
|
|
281815
282334
|
}
|
|
281816
282335
|
}
|
|
282336
|
+
// 存在永久密钥
|
|
281817
282337
|
if (credential.secretId && credential.secretKey) {
|
|
281818
282338
|
return wrapCheckAuth(credential, options);
|
|
281819
282339
|
}
|
|
@@ -281821,36 +282341,45 @@ function checkAndGetCredential(options = {}) {
|
|
|
281821
282341
|
});
|
|
281822
282342
|
}
|
|
281823
282343
|
exports.checkAndGetCredential = checkAndGetCredential;
|
|
282344
|
+
// 获取身份认证信息,不校验
|
|
281824
282345
|
function getCredentialWithoutCheck() {
|
|
281825
282346
|
return __awaiter(this, void 0, void 0, function* () {
|
|
281826
282347
|
const credential = yield getCredentialData();
|
|
281827
282348
|
if (!credential) {
|
|
281828
282349
|
return null;
|
|
281829
282350
|
}
|
|
282351
|
+
// 存在临时密钥信息
|
|
281830
282352
|
if (credential.refreshToken) {
|
|
282353
|
+
// 临时密钥在 2 小时有效期内,可以直接使用
|
|
281831
282354
|
if (!isTokenExpired(credential)) {
|
|
281832
282355
|
return credential;
|
|
281833
282356
|
}
|
|
281834
282357
|
else if (Date.now() < Number(credential.expired)) {
|
|
282358
|
+
// 临时密钥超过两小时有效期,但在 1 个月 refresh 有效期内,刷新临时密钥
|
|
281835
282359
|
let refreshCredential;
|
|
281836
282360
|
try {
|
|
281837
282361
|
refreshCredential = yield refreshTmpToken(credential);
|
|
281838
282362
|
}
|
|
281839
282363
|
catch (e) {
|
|
282364
|
+
// 登录态失效
|
|
281840
282365
|
if (e.code === 'AUTH_FAIL') {
|
|
281841
282366
|
return null;
|
|
281842
282367
|
}
|
|
281843
282368
|
else if (e.code === 'InternalError.GetRoleError') {
|
|
282369
|
+
// 用户未开通服务,视为登录态失效
|
|
281844
282370
|
return null;
|
|
281845
282371
|
}
|
|
281846
282372
|
else {
|
|
282373
|
+
// 异常错误
|
|
281847
282374
|
throw e;
|
|
281848
282375
|
}
|
|
281849
282376
|
}
|
|
282377
|
+
// 存储新的秘钥
|
|
281850
282378
|
yield exports.authStore.set('credential', refreshCredential || {});
|
|
281851
282379
|
return (0, common_1.resolveCredential)(refreshCredential);
|
|
281852
282380
|
}
|
|
281853
282381
|
}
|
|
282382
|
+
// 存在永久密钥
|
|
281854
282383
|
if (credential.secretId && credential.secretKey) {
|
|
281855
282384
|
return credential;
|
|
281856
282385
|
}
|