@cloudbase/manager-node 4.11.0-alpha.1 → 4.11.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/lib/agent/index.js +607 -16
  3. package/lib/agent/type.js +1 -0
  4. package/lib/cloudApp/index.js +243 -0
  5. package/lib/cloudApp/types.js +10 -0
  6. package/lib/database/index.js +79 -0
  7. package/lib/docs/index.js +288 -0
  8. package/lib/docs/types.js +2 -0
  9. package/lib/env/index.js +94 -0
  10. package/lib/environment.js +20 -0
  11. package/lib/function/index.js +97 -33
  12. package/lib/index.js +34 -0
  13. package/lib/interfaces/cloudApp.interface.js +20 -0
  14. package/lib/interfaces/index.js +1 -0
  15. package/lib/log/index.js +105 -0
  16. package/lib/log/types.js +24 -0
  17. package/lib/mysql/index.js +551 -0
  18. package/lib/mysql/types/account.js +2 -0
  19. package/lib/mysql/types/backup.js +2 -0
  20. package/lib/mysql/types/base.js +2 -0
  21. package/lib/mysql/types/index.js +19 -0
  22. package/lib/permission/index.js +313 -0
  23. package/lib/permission/types.js +2 -0
  24. package/lib/storage/index.js +424 -10
  25. package/lib/user/index.js +200 -0
  26. package/package.json +1 -1
  27. package/types/agent/index.d.ts +115 -5
  28. package/types/agent/type.d.ts +389 -0
  29. package/types/cloudApp/index.d.ts +73 -0
  30. package/types/cloudApp/types.d.ts +325 -0
  31. package/types/database/index.d.ts +112 -0
  32. package/types/docs/index.d.ts +37 -0
  33. package/types/docs/types.d.ts +24 -0
  34. package/types/env/index.d.ts +39 -1
  35. package/types/env/type.d.ts +187 -0
  36. package/types/environment.d.ts +12 -0
  37. package/types/function/index.d.ts +34 -5
  38. package/types/index.d.ts +26 -0
  39. package/types/interfaces/cloudApp.interface.d.ts +4 -0
  40. package/types/interfaces/index.d.ts +1 -0
  41. package/types/log/index.d.ts +53 -0
  42. package/types/log/types.d.ts +177 -0
  43. package/types/mysql/index.d.ts +261 -0
  44. package/types/mysql/types/account.d.ts +160 -0
  45. package/types/mysql/types/backup.d.ts +161 -0
  46. package/types/mysql/types/base.d.ts +579 -0
  47. package/types/mysql/types/index.d.ts +3 -0
  48. package/types/permission/index.d.ts +31 -0
  49. package/types/permission/types.d.ts +127 -0
  50. package/types/storage/index.d.ts +151 -3
  51. package/types/user/index.d.ts +17 -1
  52. package/types/user/types.d.ts +62 -0
package/lib/env/index.js CHANGED
@@ -508,6 +508,100 @@ class EnvService {
508
508
  async describeCreditsUsageDetail(params) {
509
509
  return this.cloudService.request('DescribeCreditsUsageDetail', Object.assign({}, params));
510
510
  }
511
+ /**
512
+ * 查询HTTP访问服务域名路由信息
513
+ * @param {DescribeHttpServiceRouteParams} params 查询参数
514
+ * @returns {Promise<DescribeHttpServiceRouteRes>}
515
+ */
516
+ async describeHttpServiceRoute(params) {
517
+ return this.cloudService.request('DescribeHTTPServiceRoute', Object.assign({}, params));
518
+ }
519
+ /**
520
+ * 创建HTTP访问服务域名路由
521
+ * @param {CreateHttpServiceRouteParams} params 创建参数
522
+ * @returns {Promise<CreateHttpServiceRouteRes>}
523
+ */
524
+ async createHttpServiceRoute(params) {
525
+ return this.cloudService.request('CreateHTTPServiceRoute', Object.assign({}, params));
526
+ }
527
+ /**
528
+ * 修改HTTP访问服务域名路由
529
+ * @param {ModifyHttpServiceRouteParams} params 修改参数
530
+ * @returns {Promise<ModifyHttpServiceRouteRes>}
531
+ */
532
+ async modifyHttpServiceRoute(params) {
533
+ return this.cloudService.request('ModifyHTTPServiceRoute', Object.assign({}, params));
534
+ }
535
+ /**
536
+ * 删除HTTP访问服务域名路由
537
+ * @param {DeleteHttpServiceRouteParams} params 删除参数
538
+ * @returns {Promise<DeleteHttpServiceRouteRes>}
539
+ */
540
+ async deleteHttpServiceRoute(params) {
541
+ return this.cloudService.request('DeleteHTTPServiceRoute', Object.assign({}, params));
542
+ }
543
+ /**
544
+ * 绑定自定义域名到HTTP访问服务
545
+ * 底层调用 CreateHTTPServiceRoute API,专用于域名绑定场景
546
+ * @param {BindCustomDomainParams} params 绑定参数
547
+ * @returns {Promise<BindCustomDomainRes>}
548
+ */
549
+ async bindCustomDomain(params) {
550
+ const { EnvId, Domain } = params;
551
+ // 构建域名参数,设置默认值
552
+ const domainParam = {
553
+ Domain: Domain.Domain,
554
+ CertId: Domain.CertId,
555
+ AccessType: Domain.AccessType || 'DIRECT',
556
+ Protocol: Domain.Protocol || 'HTTP_AND_HTTPS',
557
+ Enable: Domain.Enable !== undefined ? Domain.Enable : true
558
+ };
559
+ // 自定义接入类型时需要传入 CustomCname
560
+ if (domainParam.AccessType === 'CUSTOM' && Domain.CustomCname) {
561
+ domainParam.CustomCname = Domain.CustomCname;
562
+ }
563
+ return this.cloudService.request('CreateHTTPServiceRoute', {
564
+ EnvId,
565
+ Domain: domainParam
566
+ });
567
+ }
568
+ /**
569
+ * 删除自定义域名
570
+ * 仅当域名下无路由绑定时可删除,否则抛出错误
571
+ * @param {DeleteCustomDomainParams} params 删除参数
572
+ * @returns {Promise<DeleteCustomDomainRes>}
573
+ */
574
+ async deleteCustomDomain(params) {
575
+ const { EnvId, Domain } = params;
576
+ // 先查询域名下是否有路由绑定
577
+ const queryRes = await this.describeHttpServiceRoute({
578
+ EnvId,
579
+ Filters: [
580
+ {
581
+ Name: 'Domain',
582
+ Values: [Domain]
583
+ }
584
+ ],
585
+ Limit: 1
586
+ });
587
+ // 检查域名是否存在
588
+ const domains = queryRes.Domains || [];
589
+ const targetDomain = domains.find(d => d.Domain === Domain);
590
+ if (!targetDomain) {
591
+ throw new error_1.CloudBaseError(`域名 ${Domain} 不存在`);
592
+ }
593
+ // 检查域名下是否有路由绑定
594
+ const routes = targetDomain.Routes || [];
595
+ if (routes.length > 0) {
596
+ const routePaths = routes.map(r => r.Path).join(', ');
597
+ throw new error_1.CloudBaseError(`域名 ${Domain} 下还有 ${routes.length} 个路由绑定(${routePaths}),请先删除路由后再删除域名`);
598
+ }
599
+ // 无路由绑定,可以删除域名
600
+ return this.cloudService.request('DeleteHTTPServiceRoute', {
601
+ EnvId,
602
+ Domain
603
+ });
604
+ }
511
605
  // 获取 COS CORS 域名
512
606
  async getCOSDomains() {
513
607
  const cos = this.getCos();
@@ -8,6 +8,7 @@ const agent_1 = require("./agent");
8
8
  const storage_1 = require("./storage");
9
9
  const env_1 = require("./env");
10
10
  const common_1 = require("./common");
11
+ const log_1 = require("./log");
11
12
  const error_1 = require("./error");
12
13
  const constant_1 = require("./constant");
13
14
  const utils_1 = require("./utils");
@@ -16,6 +17,9 @@ const third_1 = require("./third");
16
17
  const access_1 = require("./access");
17
18
  const user_1 = require("./user");
18
19
  const cloudBaseRun_1 = require("./cloudBaseRun");
20
+ const mysql_1 = require("./mysql");
21
+ const cloudApp_1 = require("./cloudApp");
22
+ const permission_1 = require("./permission");
19
23
  class Environment {
20
24
  constructor(context, envId) {
21
25
  this.inited = false;
@@ -30,11 +34,15 @@ class Environment {
30
34
  this.databaseService = new database_1.DatabaseService(this);
31
35
  this.storageService = new storage_1.StorageService(this);
32
36
  this.envService = new env_1.EnvService(this);
37
+ this.logService = new log_1.LogService(this);
33
38
  this.hostingService = new hosting_1.HostingService(this);
34
39
  this.thirdService = new third_1.ThirdService(this);
35
40
  this.accessService = new access_1.AccessService(this);
36
41
  this.userService = new user_1.UserService(this);
37
42
  this.cloudBaseRunService = new cloudBaseRun_1.CloudBaseRunService(this);
43
+ this.mysqlService = new mysql_1.MysqlService(this);
44
+ this.permissionService = new permission_1.PermissionService(this);
45
+ this.cloudAppService = new cloudApp_1.CloudAppService(this);
38
46
  }
39
47
  async lazyInit() {
40
48
  if (!this.inited) {
@@ -76,6 +84,9 @@ class Environment {
76
84
  getEnvService() {
77
85
  return this.envService;
78
86
  }
87
+ getLogService() {
88
+ return this.logService;
89
+ }
79
90
  getHostingService() {
80
91
  return this.hostingService;
81
92
  }
@@ -91,6 +102,15 @@ class Environment {
91
102
  getCloudBaseRunService() {
92
103
  return this.cloudBaseRunService;
93
104
  }
105
+ getMysqlService() {
106
+ return this.mysqlService;
107
+ }
108
+ getCloudAppService() {
109
+ return this.cloudAppService;
110
+ }
111
+ getPermissionService() {
112
+ return this.permissionService;
113
+ }
94
114
  getCommonService(serviceType = 'tcb', serviceVersion) {
95
115
  return new common_1.CommonService(this, serviceType, serviceVersion);
96
116
  }
@@ -488,22 +488,25 @@ class FunctionService {
488
488
  * @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
489
489
  * @returns {Promise<IResponseInfo>}
490
490
  */
491
- async deleteFunction({ name }) {
491
+ async deleteFunction(name) {
492
492
  var _a;
493
+ const funcName = typeof name === 'string'
494
+ ? name
495
+ : name === null || name === void 0 ? void 0 : name.name;
493
496
  const { namespace } = this.getFunctionConfig();
494
497
  // 检测是否绑定了 API 网关
495
498
  const accessService = this.environment.getAccessService();
496
499
  const res = await accessService.getAccessList({
497
- name
500
+ name: funcName
498
501
  });
499
502
  // 删除绑定的 API 网关
500
503
  if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
501
504
  await accessService.deleteAccess({
502
- name
505
+ name: funcName
503
506
  });
504
507
  }
505
- await this.scfService.request('DeleteFunction', {
506
- FunctionName: name,
508
+ return await this.scfService.request('DeleteFunction', {
509
+ FunctionName: funcName,
507
510
  Namespace: namespace
508
511
  });
509
512
  }
@@ -741,10 +744,13 @@ class FunctionService {
741
744
  // 注意:dnsCache 需要 'TRUE'/'FALSE' 字符串,在特殊处理阶段处理
742
745
  'intranetconfig': 'IntranetConfig',
743
746
  };
747
+ const { TopicId, LogsetId } = this.getClsServiceConfig();
744
748
  // 构建参数
745
749
  const params = {
746
750
  Namespace: namespace,
747
- FunctionName: func.name
751
+ FunctionName: func.name,
752
+ ClsTopicId: TopicId,
753
+ ClsLogsetId: LogsetId
748
754
  };
749
755
  // 白名单字段自动转换(大小写不敏感,统一输出 PascalCase)
750
756
  for (const key of Object.keys(func)) {
@@ -918,6 +924,56 @@ class FunctionService {
918
924
  });
919
925
  }
920
926
  }
927
+ /**
928
+ * 更新函数代码和配置(带进度信息)
929
+ * 支持同时更新代码和配置,按顺序执行:等待就绪 → 更新代码 → 等待就绪 → 更新配置 → 等待就绪
930
+ * @param options 更新选项
931
+ * @returns 更新结果,包含耗时信息
932
+ */
933
+ async updateFunctionWithProgress(options) {
934
+ const { name, code, config } = options;
935
+ const startTime = Date.now();
936
+ const details = [];
937
+ // codeSecret 在不同阶段可能不同:
938
+ // - 更新代码前/后:用旧的 codeSecret(函数此时还是旧密钥)
939
+ // - 更新配置后:如果 config 中带了新 codeSecret,函数密钥已变更,需用新值
940
+ const oldCodeSecret = (code === null || code === void 0 ? void 0 : code.codeSecret) || (config === null || config === void 0 ? void 0 : config.codeSecret);
941
+ const newCodeSecret = (config === null || config === void 0 ? void 0 : config.codeSecret) || (code === null || code === void 0 ? void 0 : code.codeSecret);
942
+ // 1. 等待函数状态就绪(此时函数还是旧密钥)
943
+ details.push('等待函数状态就绪...');
944
+ await this.waitFunctionActive(name, oldCodeSecret);
945
+ details.push(`函数状态就绪 (${Math.round((Date.now() - startTime) / 1000)}s)`);
946
+ // 2. 更新代码
947
+ if (code && (code.functionPath || code.base64Code)) {
948
+ details.push('开始更新代码...');
949
+ await this.updateFunctionCode(Object.assign({ func: {
950
+ name,
951
+ // 从 config 取公共字段
952
+ runtime: config === null || config === void 0 ? void 0 : config.runtime,
953
+ installDependency: config === null || config === void 0 ? void 0 : config.installDependency,
954
+ ignore: config === null || config === void 0 ? void 0 : config.ignore,
955
+ codeSecret: oldCodeSecret
956
+ } }, code));
957
+ details.push(`代码更新完成 (${Math.round((Date.now() - startTime) / 1000)}s)`);
958
+ // 等待函数再次就绪(代码更新不改变 codeSecret,仍用旧值)
959
+ await this.waitFunctionActive(name, oldCodeSecret);
960
+ }
961
+ // 3. 更新配置
962
+ if (config) {
963
+ details.push('开始更新配置...');
964
+ await this.updateFunctionConfig(Object.assign({ name }, config));
965
+ details.push(`配置更新完成 (${Math.round((Date.now() - startTime) / 1000)}s)`);
966
+ // 等待函数再次就绪(配置更新后 codeSecret 可能已变更,用新值)
967
+ await this.waitFunctionActive(name, newCodeSecret);
968
+ }
969
+ const elapsedTime = Date.now() - startTime;
970
+ details.push(`全部更新完成 (${Math.round(elapsedTime / 1000)}s)`);
971
+ return {
972
+ elapsedTime,
973
+ message: `更新成功,总耗时 ${Math.round(elapsedTime / 1000)}s`,
974
+ details
975
+ };
976
+ }
921
977
  /**
922
978
  * 调用云函数
923
979
  * @param {string} name 云函数名称
@@ -1047,13 +1103,12 @@ class FunctionService {
1047
1103
  async deleteFunctionTrigger(name, triggerName) {
1048
1104
  const { namespace } = this.getFunctionConfig();
1049
1105
  try {
1050
- await this.scfService.request('DeleteTrigger', {
1106
+ return await this.scfService.request('DeleteTrigger', {
1051
1107
  FunctionName: name,
1052
1108
  Namespace: namespace,
1053
1109
  TriggerName: triggerName,
1054
1110
  Type: 'timer'
1055
1111
  });
1056
- (0, utils_1.successLog)(`[${name}] 删除云函数触发器 ${triggerName} 成功!`);
1057
1112
  }
1058
1113
  catch (e) {
1059
1114
  throw new error_1.CloudBaseError(`[${name}] 删除触发器失败:${e.message}`);
@@ -1466,7 +1521,13 @@ class FunctionService {
1466
1521
  }
1467
1522
  });
1468
1523
  return new Promise((resolve, reject) => {
1524
+ // 添加超时保护
1525
+ const timeout = setTimeout(() => {
1526
+ packer.clean();
1527
+ reject(new error_1.CloudBaseError(`[${func.name}] COS 上传超时(60秒)`));
1528
+ }, 60000);
1469
1529
  cos.sliceUploadFile(uploadParams, async (err, data) => {
1530
+ clearTimeout(timeout);
1470
1531
  // 清理临时文件
1471
1532
  await packer.clean();
1472
1533
  if (err) {
@@ -1545,29 +1606,6 @@ class FunctionService {
1545
1606
  UnixTimestamp
1546
1607
  };
1547
1608
  }
1548
- async createAccessPath(name, path) {
1549
- const access = this.environment.getAccessService();
1550
- try {
1551
- await access.createAccess({
1552
- name,
1553
- path
1554
- });
1555
- }
1556
- catch (e) {
1557
- // 当 Path 存在时,校验 Path 绑定的函数是不是当前函数
1558
- if (e.code === 'InvalidParameter.APICreated') {
1559
- const { APISet } = await access.getAccessList({
1560
- name
1561
- });
1562
- if ((APISet === null || APISet === void 0 ? void 0 : APISet[0].Name) !== name || (APISet === null || APISet === void 0 ? void 0 : APISet[0].Type) !== 1) {
1563
- throw e;
1564
- }
1565
- }
1566
- else {
1567
- throw e;
1568
- }
1569
- }
1570
- }
1571
1609
  async getCodeParams(options, installDependency) {
1572
1610
  const { func, functionPath, functionRootPath, base64Code, deployMode } = options;
1573
1611
  // 直接传入 base64Code 的情况,校验大小
@@ -1620,6 +1658,29 @@ class FunctionService {
1620
1658
  TempCosObjectName: `/${legacyResult.Key}`
1621
1659
  };
1622
1660
  }
1661
+ async createAccessPath(name, path) {
1662
+ const access = this.environment.getAccessService();
1663
+ try {
1664
+ await access.createAccess({
1665
+ name,
1666
+ path
1667
+ });
1668
+ }
1669
+ catch (e) {
1670
+ // 当 Path 存在时,校验 Path 绑定的函数是不是当前函数
1671
+ if (e.code === 'InvalidParameter.APICreated') {
1672
+ const { APISet } = await access.getAccessList({
1673
+ name
1674
+ });
1675
+ if ((APISet === null || APISet === void 0 ? void 0 : APISet[0].Name) !== name || (APISet === null || APISet === void 0 ? void 0 : APISet[0].Type) !== 1) {
1676
+ throw e;
1677
+ }
1678
+ }
1679
+ else {
1680
+ throw e;
1681
+ }
1682
+ }
1683
+ }
1623
1684
  // 获取 COS 临时信息
1624
1685
  async getTempCosInfo(name) {
1625
1686
  const { env, appId } = await this.getFunctionConfig();
@@ -1750,6 +1811,9 @@ __decorate([
1750
1811
  __decorate([
1751
1812
  (0, utils_1.preLazy)()
1752
1813
  ], FunctionService.prototype, "updateFunctionCode", null);
1814
+ __decorate([
1815
+ (0, utils_1.preLazy)()
1816
+ ], FunctionService.prototype, "updateFunctionWithProgress", null);
1753
1817
  __decorate([
1754
1818
  (0, utils_1.preLazy)()
1755
1819
  ], FunctionService.prototype, "invokeFunction", null);
@@ -1824,10 +1888,10 @@ __decorate([
1824
1888
  ], FunctionService.prototype, "uploadFunctionZipToCos", null);
1825
1889
  __decorate([
1826
1890
  (0, utils_1.preLazy)()
1827
- ], FunctionService.prototype, "createAccessPath", null);
1891
+ ], FunctionService.prototype, "getCodeParams", null);
1828
1892
  __decorate([
1829
1893
  (0, utils_1.preLazy)()
1830
- ], FunctionService.prototype, "getCodeParams", null);
1894
+ ], FunctionService.prototype, "createAccessPath", null);
1831
1895
  __decorate([
1832
1896
  (0, utils_1.preLazy)()
1833
1897
  ], FunctionService.prototype, "getTempCosInfo", null);
package/lib/index.js CHANGED
@@ -67,21 +67,55 @@ class CloudBase {
67
67
  get access() {
68
68
  return this.currentEnvironment().getAccessService();
69
69
  }
70
+ get mysql() {
71
+ return this.currentEnvironment().getMysqlService();
72
+ }
73
+ /**
74
+ * 云托管服务(CloudBaseRun)
75
+ * 提供云托管版本流量配置等能力
76
+ * @deprecated 请使用 cloudBaseRun 代替,避免与 cloudAppService 混淆
77
+ */
70
78
  get cloudApp() {
71
79
  return this.currentEnvironment().getCloudBaseRunService();
72
80
  }
81
+ /**
82
+ * 云托管服务(CloudBaseRun)
83
+ * 提供云托管版本流量配置等能力
84
+ */
85
+ get cloudBaseRun() {
86
+ return this.currentEnvironment().getCloudBaseRunService();
87
+ }
88
+ /**
89
+ * 云应用服务(CloudApp 统一部署)
90
+ * 提供 Web 应用的创建、部署、版本管理等能力
91
+ */
92
+ get cloudAppService() {
93
+ return this.currentEnvironment().getCloudAppService();
94
+ }
95
+ /**
96
+ * 获取云应用服务
97
+ */
98
+ getCloudAppService() {
99
+ return this.currentEnvironment().getCloudAppService();
100
+ }
73
101
  commonService(service, version) {
74
102
  return this.currentEnvironment().getCommonService(service, version);
75
103
  }
76
104
  get env() {
77
105
  return this.currentEnvironment().getEnvService();
78
106
  }
107
+ get log() {
108
+ return this.currentEnvironment().getLogService();
109
+ }
79
110
  get third() {
80
111
  return this.currentEnvironment().getThirdService();
81
112
  }
82
113
  get user() {
83
114
  return this.currentEnvironment().getUserService();
84
115
  }
116
+ get permission() {
117
+ return this.currentEnvironment().getPermissionService();
118
+ }
85
119
  get docs() {
86
120
  if (!this.docsService) {
87
121
  this.docsService = new docs_1.DocsService();
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * CloudApp 统一部署服务接口导出
19
+ */
20
+ __exportStar(require("../cloudApp/types"), exports);
@@ -21,3 +21,4 @@ __exportStar(require("./base.interface"), exports);
21
21
  __exportStar(require("./storage.interface"), exports);
22
22
  __exportStar(require("./cam.interface"), exports);
23
23
  __exportStar(require("./billing.interface"), exports);
24
+ __exportStar(require("./cloudApp.interface"), exports);
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.LogService = void 0;
18
+ exports.isLogServiceEnabled = isLogServiceEnabled;
19
+ const utils_1 = require("../utils");
20
+ __exportStar(require("./types"), exports);
21
+ /**
22
+ * 纯函数:根据 DescribeEnvs 返回的 LogServices 列表判断日志服务是否已开通。
23
+ * 已开通条件:至少一个条目有有效的 TopicId。
24
+ */
25
+ function isLogServiceEnabled(logServices) {
26
+ if (!logServices || logServices.length === 0)
27
+ return false;
28
+ return logServices.some(svc => !!svc.TopicId);
29
+ }
30
+ class LogService {
31
+ constructor(environment) {
32
+ this.envId = environment.getEnvId();
33
+ this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
34
+ this.tcbrService = new utils_1.CloudService(environment.cloudBaseContext, 'tcbr', '2022-02-17');
35
+ }
36
+ /**
37
+ * 检查当前环境的日志服务是否已开通
38
+ *
39
+ * 通过 DescribeEnvs 接口获取环境信息,判断 LogServices 字段中是否包含有效的
40
+ * 日志主题(TopicId 不为空)。
41
+ *
42
+ * @returns true 表示已开通,false 表示未开通或开通中
43
+ */
44
+ async checkLogServiceEnabled() {
45
+ var _a;
46
+ const res = await this.cloudService.request('DescribeEnvs', {
47
+ EnvId: this.envId
48
+ });
49
+ const envInfo = (_a = res === null || res === void 0 ? void 0 : res.EnvList) === null || _a === void 0 ? void 0 : _a[0];
50
+ if (!envInfo) {
51
+ return false;
52
+ }
53
+ const logServices = envInfo.LogServices;
54
+ if (!logServices || logServices.length === 0) {
55
+ return false;
56
+ }
57
+ // 已开通:LogServiceInfo 中存在有效的日志主题 ID
58
+ return isLogServiceEnabled(logServices);
59
+ }
60
+ /**
61
+ * 开通环境日志服务(异步操作)
62
+ *
63
+ * 调用 CreateEnvResource 接口开通日志资源。
64
+ * 注意:接口调用成功不代表日志资源立即可用,需通过 checkLogServiceEnabled() 轮询确认。
65
+ *
66
+ * @returns 请求 ID
67
+ */
68
+ async createLogService() {
69
+ return this.cloudService.request('CreateEnvResource', {
70
+ EnvId: this.envId,
71
+ Resources: ['log']
72
+ });
73
+ }
74
+ /**
75
+ * 搜索 CLS 日志
76
+ *
77
+ * @param params 查询参数,通过 queryString 使用 CLS 原生检索分析语法
78
+ * @returns 日志搜索结果
79
+ *
80
+ * @remarks
81
+ * - 纯检索结果在 `LogResults.Results` 中
82
+ * - SQL 分析结果(queryString 含 `| select ...`)在 `LogResults.AnalysisRecords` 中
83
+ * - 详细的 QueryString 语法参考见 README.md
84
+ */
85
+ async searchClsLog(params) {
86
+ const { queryString, StartTime, EndTime, Limit, Context, Sort, UseLucene, service } = params;
87
+ const requestService = service === 'tcbr' ? this.tcbrService : this.cloudService;
88
+ const requestParams = {
89
+ EnvId: this.envId,
90
+ StartTime,
91
+ EndTime,
92
+ QueryString: queryString,
93
+ Limit,
94
+ Context,
95
+ Sort,
96
+ UseLucene
97
+ };
98
+ // TenantModel 仅 tcb 服务需要,tcbr 不支持该参数
99
+ if (service !== 'tcbr') {
100
+ requestParams.TenantModel = 'public';
101
+ }
102
+ return requestService.request('SearchClsLog', requestParams);
103
+ }
104
+ }
105
+ exports.LogService = LogService;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // =====================================================
3
+ // CLS 日志字段枚举 & Module 查询 Schema
4
+ // =====================================================
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CLS_MODULE_SCHEMA = void 0;
7
+ // =====================================================
8
+ // CLS Module 运行时常量
9
+ // =====================================================
10
+ /**
11
+ * ClsModuleSchema 的运行时版本,用于动态生成查询条件 / MCP tool description
12
+ *
13
+ * - key 与 ClsLogModule 类型保持同步
14
+ * - eventTypes / logTypes 为字符串数组,空数组表示该维度不可过滤
15
+ */
16
+ exports.CLS_MODULE_SCHEMA = {
17
+ database: { label: '云数据库(文档型)', eventTypes: ['MongoSlowQuery'], logTypes: [] },
18
+ rdb: { label: '云数据库(SQL型)', eventTypes: ['MysqlFreeze', 'MysqlRecover', 'MysqlSlowQuery'], logTypes: [] },
19
+ model: { label: '数据模型', eventTypes: [], logTypes: [] },
20
+ workflow: { label: '审批流', eventTypes: [], logTypes: [] },
21
+ auth: { label: '用户权限', eventTypes: [], logTypes: [] },
22
+ llm: { label: '大模型', eventTypes: [], logTypes: ['llm-tracelog'] },
23
+ app: { label: '应用', eventTypes: ['AppProdPub', 'AppProdDel'], logTypes: [] },
24
+ };