@cloudbase/manager-node 5.8.9-beta.1 → 5.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.codebuddy/rules/error-code-contract.mdc +13 -0
  2. package/.coding-ci-publish-beta.yaml +19 -12
  3. package/CHANGELOG.md +8 -0
  4. package/changelog_content_en.md +16 -0
  5. package/changelog_content_zh.md +16 -0
  6. package/lib/agent/index.js +6 -5
  7. package/lib/aiModel/index.js +21 -9
  8. package/lib/cloudApp/index.js +4 -4
  9. package/lib/cloudrun/index.js +16 -15
  10. package/lib/common/index.js +1 -1
  11. package/lib/database/index.js +23 -23
  12. package/lib/deploy/DatabaseDeployer.js +19 -24
  13. package/lib/deploy/DeployOrchestrator.js +2 -2
  14. package/lib/deploy/FunctionDeployer.js +19 -1
  15. package/lib/deploy/GatewayDeployer.js +5 -5
  16. package/lib/deploy/StaticDeployer.js +2 -2
  17. package/lib/deploy/framework.js +2 -1
  18. package/lib/deploy/function/config-guard.js +23 -3
  19. package/lib/deploy/function/enterprise-tcr.js +18 -2
  20. package/lib/docs/index.js +4 -3
  21. package/lib/env/index.js +16 -16
  22. package/lib/environment.js +4 -4
  23. package/lib/environmentManager.js +5 -1
  24. package/lib/error-docs.js +385 -0
  25. package/lib/error-types.js +21 -0
  26. package/lib/error.js +239 -2
  27. package/lib/function/index.js +454 -90
  28. package/lib/function/packer.js +1 -1
  29. package/lib/hosting/index.js +1 -1
  30. package/lib/index.js +2 -1
  31. package/lib/integration/crypto.js +4 -3
  32. package/lib/integration/index.js +1 -1
  33. package/lib/integration/secretKey.js +4 -4
  34. package/lib/monitor/index.js +1 -1
  35. package/lib/mysql/index.js +2 -1
  36. package/lib/permission/index.js +56 -49
  37. package/lib/platform/index.js +2 -2
  38. package/lib/sandbox/index.js +68 -61
  39. package/lib/storage/index.js +164 -162
  40. package/lib/user/index.js +32 -31
  41. package/lib/utils/cloud-api-request.js +13 -5
  42. package/lib/utils/cloudbase-request.js +21 -0
  43. package/lib/utils/fs.js +3 -3
  44. package/lib/utils/http-request.js +2 -2
  45. package/lib/utils/index.js +4 -3
  46. package/lib/utils/storage-config.js +3 -3
  47. package/package.json +2 -2
  48. package/types/error-docs.d.ts +57 -0
  49. package/types/error-types.d.ts +32 -0
  50. package/types/error.d.ts +148 -2
  51. package/types/function/index.d.ts +166 -8
  52. package/types/utils/cloudbase-request.d.ts +22 -0
@@ -100,7 +100,7 @@ class FunctionPacker {
100
100
  const jarExist = (0, utils_1.checkFullAccess)(`${filePath}.jar`);
101
101
  const zipExist = (0, utils_1.checkFullAccess)(`${filePath}.zip`);
102
102
  if (!jarExist && !zipExist) {
103
- throw new error_1.CloudBaseError('未找到部署函数的 Jar 或者 ZIP 格式文件!');
103
+ (0, error_1.throwNotFound)('未找到部署函数的 Jar 或者 ZIP 格式文件!');
104
104
  }
105
105
  this.zipFilePath = jarExist ? `${filePath}.jar` : `${filePath}.zip`;
106
106
  }
@@ -54,7 +54,7 @@ class HostingService {
54
54
  const website = hostings[0];
55
55
  // offline 状态的服务可重新开启
56
56
  if (website.Status !== 'offline') {
57
- throw new error_1.CloudBaseError('静态网站服务已开启,请勿重复操作!');
57
+ (0, error_1.throwApiError)('静态网站服务已开启,请勿重复操作!');
58
58
  }
59
59
  }
60
60
  const res = await this.tcbService.request('CreateStaticStore', {
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const error_1 = require("./error");
2
3
  const context_1 = require("./context");
3
4
  const environmentManager_1 = require("./environmentManager");
4
5
  const docs_1 = require("./docs");
@@ -25,7 +26,7 @@ class CloudBase {
25
26
  let { secretId, secretKey, token, envId, proxy, region, envType, useInternalEndpoint, internalEndpointRegion, requestFn } = config;
26
27
  // config 中传入的 secretId secretkey 必须同时存在(有 requestFn 时可以不传)
27
28
  if (!requestFn && ((secretId && !secretKey) || (!secretId && secretKey))) {
28
- throw new Error('secretId and secretKey must be a pair');
29
+ (0, error_1.throwInvalidParam)('secretId and secretKey must be a pair');
29
30
  }
30
31
  this.cloudBaseConfig = {
31
32
  secretId: secretId ? secretId.trim() : secretId,
@@ -49,6 +49,7 @@ exports.aesEncryptWithIv = aesEncryptWithIv;
49
49
  * 使用 Node 内置 crypto 复刻,无需引入额外依赖。
50
50
  */
51
51
  const crypto = __importStar(require("crypto"));
52
+ const error_1 = require("../error");
52
53
  const ALGORITHM = 'aes-256-cbc';
53
54
  const KEY_BYTE_LENGTH = 32;
54
55
  const IV_BYTE_LENGTH = 16;
@@ -56,7 +57,7 @@ const IV_BYTE_LENGTH = 16;
56
57
  const IV_BASE64_LENGTH = 24;
57
58
  function assertKey(key) {
58
59
  if (Buffer.byteLength(key, 'utf8') !== KEY_BYTE_LENGTH) {
59
- throw new Error('AES key 必须是 32 字节长度');
60
+ (0, error_1.throwInvalidParam)('AES key 必须是 32 字节长度');
60
61
  }
61
62
  }
62
63
  /**
@@ -65,7 +66,7 @@ function assertKey(key) {
65
66
  function aesEncryptWithIv(plaintext, key, iv) {
66
67
  assertKey(key);
67
68
  if (iv.length !== IV_BYTE_LENGTH) {
68
- throw new Error('IV 必须是 16 字节长度');
69
+ (0, error_1.throwInvalidParam)('IV 必须是 16 字节长度');
69
70
  }
70
71
  const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(key, 'utf8'), iv);
71
72
  const encrypted = Buffer.concat([cipher.update(plaintext, 'utf8'), cipher.final()]);
@@ -89,7 +90,7 @@ class AESCryptoImpl {
89
90
  const ciphertextBase64 = encryptedData.slice(IV_BASE64_LENGTH);
90
91
  const iv = Buffer.from(ivBase64, 'base64');
91
92
  if (iv.length !== IV_BYTE_LENGTH) {
92
- throw new Error('密文格式错误:IV 长度非法');
93
+ (0, error_1.throwInvalidParam)('密文格式错误:IV 长度非法');
93
94
  }
94
95
  const decipher = crypto.createDecipheriv(ALGORITHM, Buffer.from(key, 'utf8'), iv);
95
96
  const decrypted = Buffer.concat([
@@ -170,7 +170,7 @@ class IntegrationService {
170
170
  validateRequiredParams(params, fields) {
171
171
  for (const field of fields) {
172
172
  if (!params[field]) {
173
- throw new error_1.CloudBaseError(`${field} 是必填参数`);
173
+ (0, error_1.throwInvalidParam)(`${field} 是必填参数`);
174
174
  }
175
175
  }
176
176
  }
@@ -60,24 +60,24 @@ async function getAesKey(params = {}) {
60
60
  });
61
61
  }
62
62
  catch (e) {
63
- throw new error_1.CloudBaseError('获取集成加解密密钥失败:七彩石配置拉取请求异常');
63
+ (0, error_1.throwApiError)('获取集成加解密密钥失败:七彩石配置拉取请求异常');
64
64
  }
65
65
  const data = (_a = resJson === null || resJson === void 0 ? void 0 : resJson.Response) === null || _a === void 0 ? void 0 : _a.Data;
66
66
  if (!data || data.ErrorCode !== '0') {
67
- throw new error_1.CloudBaseError(`获取集成加解密密钥失败:七彩石返回异常(ErrorCode=${data === null || data === void 0 ? void 0 : data.ErrorCode})`);
67
+ (0, error_1.throwApiError)(`获取集成加解密密钥失败:七彩石返回异常(ErrorCode=${data === null || data === void 0 ? void 0 : data.ErrorCode})`);
68
68
  }
69
69
  let config;
70
70
  try {
71
71
  config = JSON.parse(data.ConfigValue)[0];
72
72
  }
73
73
  catch (e) {
74
- throw new error_1.CloudBaseError('获取集成加解密密钥失败:七彩石配置内容解析失败');
74
+ (0, error_1.throwApiError)('获取集成加解密密钥失败:七彩石配置内容解析失败');
75
75
  }
76
76
  const kvs = ((_b = config === null || config === void 0 ? void 0 : config.kvs) === null || _b === void 0 ? void 0 : _b.kvs) || [];
77
77
  const target = kvs.find(kv => kv.key === RAINBOW_CONFIG.CRYPTO_KEY_FIELD);
78
78
  const key = target === null || target === void 0 ? void 0 : target.value;
79
79
  if (!key) {
80
- throw new error_1.CloudBaseError(`获取集成加解密密钥失败:七彩石配置中缺少 ${RAINBOW_CONFIG.CRYPTO_KEY_FIELD} 字段`);
80
+ (0, error_1.throwApiError)(`获取集成加解密密钥失败:七彩石配置中缺少 ${RAINBOW_CONFIG.CRYPTO_KEY_FIELD} 字段`);
81
81
  }
82
82
  keyCache[group] = key;
83
83
  return key;
@@ -37,7 +37,7 @@ function validatePeriod(startStr, endStr, period) {
37
37
  const rangeMs = endMs - startMs;
38
38
  const rule = PERIOD_RULES.find(r => rangeMs <= r.maxRangeMs);
39
39
  if (rule && !rule.allowed.includes(period)) {
40
- throw new error_1.CloudBaseError(`Period=${period} 不适用于当前时间范围。` +
40
+ (0, error_1.throwInvalidParam)(`Period=${period} 不适用于当前时间范围。` +
41
41
  `时间范围 ${startStr} ~ ${endStr}(约 ${(rangeMs / ONE_DAY_MS).toFixed(1)} 天)` +
42
42
  `仅支持 Period: [${rule.allowed.join(', ')}]`);
43
43
  }
@@ -22,6 +22,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MysqlService = void 0;
24
24
  const utils_1 = require("../utils");
25
+ const error_1 = require("../error");
25
26
  __exportStar(require("./types/index"), exports);
26
27
  class MysqlService {
27
28
  constructor(environment) {
@@ -416,7 +417,7 @@ class MysqlService {
416
417
  const res = await this.describeClusterInstanceGroups();
417
418
  const groups = res.InstanceGroupInfoList;
418
419
  if (!groups || groups.length === 0) {
419
- throw new Error('当前集群没有实例组,无法执行外网操作');
420
+ (0, error_1.throwApiError)('当前集群没有实例组,无法执行外网操作');
420
421
  }
421
422
  this._instanceGroupId = groups[0].InstanceGroupId;
422
423
  }
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.PermissionService = void 0;
10
10
  const utils_1 = require("../utils");
11
+ const error_1 = require("../error");
11
12
  const PERMISSION_BY_RESOURCE = {
12
13
  function: ['CUSTOM'],
13
14
  storage: ['READONLY', 'PRIVATE', 'ADMINWRITE', 'ADMINONLY', 'CUSTOM'],
@@ -27,26 +28,26 @@ class PermissionService {
27
28
  const { EnvId } = this.environment.lazyEnvironmentConfig;
28
29
  const { resourceType, resource, permission, securityRule } = options;
29
30
  if (!resourceType || !PERMISSION_BY_RESOURCE[resourceType]) {
30
- throw new Error('Invalid resourceType');
31
+ (0, error_1.throwInvalidParam)('Invalid resourceType');
31
32
  }
32
33
  const isFunctionResourceType = resourceType === 'function';
33
34
  const hasValidResourceValue = typeof resource === 'string' && resource.trim().length > 0;
34
35
  if (!isFunctionResourceType && !hasValidResourceValue) {
35
- throw new Error('Invalid resource');
36
+ (0, error_1.throwInvalidParam)('Invalid resource');
36
37
  }
37
38
  const allowed = PERMISSION_BY_RESOURCE[resourceType];
38
39
  if (!allowed.includes(permission)) {
39
- throw new Error(`Permission ${permission} is not allowed for resourceType ${resourceType}`);
40
+ (0, error_1.throwInvalidParam)(`Permission ${permission} is not allowed for resourceType ${resourceType}`);
40
41
  }
41
42
  if (permission === 'CUSTOM') {
42
43
  if (typeof securityRule !== 'string' || securityRule.trim().length === 0) {
43
- throw new Error('securityRule is required when permission is CUSTOM');
44
+ (0, error_1.throwInvalidParam)('securityRule is required when permission is CUSTOM');
44
45
  }
45
46
  // // 校验 JSON 字符串合法性
46
47
  // try {
47
48
  // JSON.parse(securityRule)
48
49
  // } catch {
49
- // throw new Error('securityRule must be a valid JSON string')
50
+ // throwInvalidParam('securityRule must be a valid JSON string')
50
51
  // }
51
52
  }
52
53
  const reqData = Object.assign({ EnvId, ResourceType: resourceType, Permission: permission }, (hasValidResourceValue || !isFunctionResourceType ? { Resource: resource } : {}));
@@ -62,18 +63,18 @@ class PermissionService {
62
63
  const { EnvId } = this.environment.lazyEnvironmentConfig;
63
64
  const { resourceType, resources } = options;
64
65
  if (!resourceType || !PERMISSION_BY_RESOURCE[resourceType]) {
65
- throw new Error('Invalid resourceType');
66
+ (0, error_1.throwInvalidParam)('Invalid resourceType');
66
67
  }
67
68
  if (resources !== undefined) {
68
69
  if (!Array.isArray(resources)) {
69
- throw new Error('Invalid resources');
70
+ (0, error_1.throwInvalidParam)('Invalid resources');
70
71
  }
71
72
  if (resources.length > 100) {
72
- throw new Error('resources length must be <= 100');
73
+ (0, error_1.throwInvalidParam)('resources length must be <= 100');
73
74
  }
74
75
  const invalid = resources.find(item => typeof item !== 'string' || item.trim().length === 0);
75
76
  if (invalid !== undefined) {
76
- throw new Error('resources contains invalid item');
77
+ (0, error_1.throwInvalidParam)('resources contains invalid item');
77
78
  }
78
79
  }
79
80
  return this.tcbService.request('DescribeResourcePermission', Object.assign({ EnvId, ResourceType: resourceType }, (resources !== undefined ? { Resources: resources } : {})));
@@ -83,52 +84,55 @@ class PermissionService {
83
84
  const { roleName, roleIdentity, description, memberUids, policies } = options;
84
85
  // RoleName 校验:非空,2-32字符,中文/字母/数字/_-:@.,必须以字母或中文开头
85
86
  if (typeof roleName !== 'string' || roleName.trim().length === 0) {
86
- throw new Error('roleName is required');
87
+ (0, error_1.throwInvalidParam)('roleName is required');
87
88
  }
88
89
  if (roleName.length < 2 || roleName.length > 32) {
89
- throw new Error('roleName length must be between 2 and 32');
90
+ (0, error_1.throwInvalidParam)('roleName length must be between 2 and 32');
90
91
  }
91
92
  if (!/^[\u4e00-\u9fa5a-zA-Z]/.test(roleName)) {
92
- throw new Error('roleName must start with a letter or Chinese character');
93
+ (0, error_1.throwInvalidParam)('roleName must start with a letter or Chinese character');
93
94
  }
94
95
  if (!/^[\u4e00-\u9fa5a-zA-Z0-9\-_:@.]+$/.test(roleName)) {
95
- throw new Error('roleName can only contain Chinese, letters, digits, and -_:@.');
96
+ (0, error_1.throwInvalidParam)('roleName can only contain Chinese, letters, digits, and -_:@.');
96
97
  }
97
98
  // RoleIdentity 校验:非空,字母/数字/_-:@.,不能与默认角色标识重复
98
99
  if (typeof roleIdentity !== 'string' || roleIdentity.trim().length === 0) {
99
- throw new Error('roleIdentity is required');
100
+ (0, error_1.throwInvalidParam)('roleIdentity is required');
100
101
  }
101
102
  if (!/^[a-zA-Z0-9\-_:@.]+$/.test(roleIdentity)) {
102
- throw new Error('roleIdentity can only contain letters, digits, and -_:@.');
103
+ (0, error_1.throwInvalidParam)('roleIdentity can only contain letters, digits, and -_:@.');
103
104
  }
104
105
  // Description 校验
105
- if (description !== undefined && description.length > 255) {
106
- throw new Error('description length must be <= 255');
106
+ // ⚠️ 必须先用 `typeof === 'string'` 收窄:调用方(JS / any)传 `null` 时
107
+ // `null !== undefined` 为 true,随后的 `description.length` 会直接 TypeError
108
+ // (代码评审:边界条件 —— 未处理空指针)。
109
+ if (typeof description === 'string' && description.length > 255) {
110
+ (0, error_1.throwInvalidParam)('description length must be <= 255');
107
111
  }
108
112
  // MemberUids 校验
109
113
  if (memberUids !== undefined) {
110
114
  if (!Array.isArray(memberUids)) {
111
- throw new Error('memberUids must be an array');
115
+ (0, error_1.throwInvalidParam)('memberUids must be an array');
112
116
  }
113
117
  if (memberUids.length > 100) {
114
- throw new Error('memberUids length must be <= 100');
118
+ (0, error_1.throwInvalidParam)('memberUids length must be <= 100');
115
119
  }
116
120
  const invalidUid = memberUids.find(uid => typeof uid !== 'string' || uid.trim().length === 0);
117
121
  if (invalidUid !== undefined) {
118
- throw new Error('memberUids contains invalid item');
122
+ (0, error_1.throwInvalidParam)('memberUids contains invalid item');
119
123
  }
120
124
  }
121
125
  // Policies 校验
122
126
  if (policies !== undefined) {
123
127
  if (!Array.isArray(policies)) {
124
- throw new Error('policies must be an array');
128
+ (0, error_1.throwInvalidParam)('policies must be an array');
125
129
  }
126
130
  if (policies.length > 50) {
127
- throw new Error('policies length must be <= 50');
131
+ (0, error_1.throwInvalidParam)('policies length must be <= 50');
128
132
  }
129
133
  const invalidPolicy = policies.find(policy => !policy.ResourceType || !policy.Resource);
130
134
  if (invalidPolicy !== undefined) {
131
- throw new Error('each policy must have ResourceType and Resource');
135
+ (0, error_1.throwInvalidParam)('each policy must have ResourceType and Resource');
132
136
  }
133
137
  }
134
138
  const reqData = {
@@ -152,23 +156,23 @@ class PermissionService {
152
156
  const { pageNumber, pageSize, roleId, roleIdentity, roleName, loadDetails } = options;
153
157
  // PageNumber 校验:从1开始
154
158
  if (pageNumber !== undefined && (pageNumber < 1 || !Number.isInteger(pageNumber))) {
155
- throw new Error('pageNumber must be a positive integer');
159
+ (0, error_1.throwInvalidParam)('pageNumber must be a positive integer');
156
160
  }
157
161
  // PageSize 校验:默认10,最大100
158
162
  if (pageSize !== undefined && (pageSize < 1 || pageSize > 100 || !Number.isInteger(pageSize))) {
159
- throw new Error('pageSize must be an integer between 1 and 100');
163
+ (0, error_1.throwInvalidParam)('pageSize must be an integer between 1 and 100');
160
164
  }
161
165
  // RoleId 校验
162
166
  if (roleId !== undefined && (typeof roleId !== 'string' || roleId.trim().length === 0)) {
163
- throw new Error('Invalid roleId');
167
+ (0, error_1.throwInvalidParam)('Invalid roleId');
164
168
  }
165
169
  // RoleIdentity 校验
166
170
  if (roleIdentity !== undefined && (typeof roleIdentity !== 'string' || roleIdentity.trim().length === 0)) {
167
- throw new Error('Invalid roleIdentity');
171
+ (0, error_1.throwInvalidParam)('Invalid roleIdentity');
168
172
  }
169
173
  // RoleName 校验
170
174
  if (roleName !== undefined && (typeof roleName !== 'string' || roleName.trim().length === 0)) {
171
- throw new Error('Invalid roleName');
175
+ (0, error_1.throwInvalidParam)('Invalid roleName');
172
176
  }
173
177
  const reqData = { EnvId };
174
178
  if (pageNumber !== undefined) {
@@ -196,62 +200,65 @@ class PermissionService {
196
200
  const { roleId, roleName, description, addMemberUids, removeMemberUids, addPolicies, removePolicies } = options;
197
201
  // RoleId 校验:必填
198
202
  if (typeof roleId !== 'string' || roleId.trim().length === 0) {
199
- throw new Error('roleId is required');
203
+ (0, error_1.throwInvalidParam)('roleId is required');
200
204
  }
201
205
  // RoleName 校验:不传或传空 => 不修改;非空时校验规则
202
206
  if (roleName !== undefined && roleName !== '') {
203
207
  if (roleName.length < 2 || roleName.length > 32) {
204
- throw new Error('roleName length must be between 2 and 32');
208
+ (0, error_1.throwInvalidParam)('roleName length must be between 2 and 32');
205
209
  }
206
210
  if (!/^[\u4e00-\u9fa5a-zA-Z]/.test(roleName)) {
207
- throw new Error('roleName must start with a letter or Chinese character');
211
+ (0, error_1.throwInvalidParam)('roleName must start with a letter or Chinese character');
208
212
  }
209
213
  if (!/^[\u4e00-\u9fa5a-zA-Z0-9\-_:@.]+$/.test(roleName)) {
210
- throw new Error('roleName can only contain Chinese, letters, digits, and -_:@.');
214
+ (0, error_1.throwInvalidParam)('roleName can only contain Chinese, letters, digits, and -_:@.');
211
215
  }
212
216
  }
213
217
  // Description 校验
214
- if (description !== undefined && description.length > 255) {
215
- throw new Error('description length must be <= 255');
218
+ // ⚠️ 必须先用 `typeof === 'string'` 收窄:调用方(JS / any)传 `null` 时
219
+ // `null !== undefined` 为 true,随后的 `description.length` 会直接 TypeError
220
+ // (代码评审:边界条件 —— 未处理空指针)。
221
+ if (typeof description === 'string' && description.length > 255) {
222
+ (0, error_1.throwInvalidParam)('description length must be <= 255');
216
223
  }
217
224
  // AddMemberUids 校验
218
225
  if (addMemberUids !== undefined) {
219
226
  if (!Array.isArray(addMemberUids)) {
220
- throw new Error('addMemberUids must be an array');
227
+ (0, error_1.throwInvalidParam)('addMemberUids must be an array');
221
228
  }
222
229
  const invalidUid = addMemberUids.find(uid => typeof uid !== 'string' || uid.trim().length === 0);
223
230
  if (invalidUid !== undefined) {
224
- throw new Error('addMemberUids contains invalid item');
231
+ (0, error_1.throwInvalidParam)('addMemberUids contains invalid item');
225
232
  }
226
233
  }
227
234
  // RemoveMemberUids 校验
228
235
  if (removeMemberUids !== undefined) {
229
236
  if (!Array.isArray(removeMemberUids)) {
230
- throw new Error('removeMemberUids must be an array');
237
+ (0, error_1.throwInvalidParam)('removeMemberUids must be an array');
231
238
  }
232
239
  const invalidUid = removeMemberUids.find(uid => typeof uid !== 'string' || uid.trim().length === 0);
233
240
  if (invalidUid !== undefined) {
234
- throw new Error('removeMemberUids contains invalid item');
241
+ (0, error_1.throwInvalidParam)('removeMemberUids contains invalid item');
235
242
  }
236
243
  }
237
244
  // AddPolicies 校验
238
245
  if (addPolicies !== undefined) {
239
246
  if (!Array.isArray(addPolicies)) {
240
- throw new Error('addPolicies must be an array');
247
+ (0, error_1.throwInvalidParam)('addPolicies must be an array');
241
248
  }
242
249
  const invalidPolicy = addPolicies.find(policy => !policy.ResourceType || !policy.Resource);
243
250
  if (invalidPolicy !== undefined) {
244
- throw new Error('each addPolicy must have ResourceType and Resource');
251
+ (0, error_1.throwInvalidParam)('each addPolicy must have ResourceType and Resource');
245
252
  }
246
253
  }
247
254
  // RemovePolicies 校验
248
255
  if (removePolicies !== undefined) {
249
256
  if (!Array.isArray(removePolicies)) {
250
- throw new Error('removePolicies must be an array');
257
+ (0, error_1.throwInvalidParam)('removePolicies must be an array');
251
258
  }
252
259
  const invalidPolicy = removePolicies.find(policy => !policy.ResourceType || !policy.Resource);
253
260
  if (invalidPolicy !== undefined) {
254
- throw new Error('each removePolicy must have ResourceType and Resource');
261
+ (0, error_1.throwInvalidParam)('each removePolicy must have ResourceType and Resource');
255
262
  }
256
263
  }
257
264
  const reqData = { EnvId, RoleId: roleId };
@@ -281,14 +288,14 @@ class PermissionService {
281
288
  const { roleIds } = options;
282
289
  // RoleIds 校验:必填数组,最多100个
283
290
  if (!Array.isArray(roleIds) || roleIds.length === 0) {
284
- throw new Error('roleIds is required and must be a non-empty array');
291
+ (0, error_1.throwInvalidParam)('roleIds is required and must be a non-empty array');
285
292
  }
286
293
  if (roleIds.length > 100) {
287
- throw new Error('roleIds length must be <= 100');
294
+ (0, error_1.throwInvalidParam)('roleIds length must be <= 100');
288
295
  }
289
296
  const invalidId = roleIds.find(id => typeof id !== 'string' || id.trim().length === 0);
290
297
  if (invalidId !== undefined) {
291
- throw new Error('roleIds contains invalid item');
298
+ (0, error_1.throwInvalidParam)('roleIds contains invalid item');
292
299
  }
293
300
  return this.tcbService.request('DeleteRoles', {
294
301
  EnvId,
@@ -303,7 +310,7 @@ class PermissionService {
303
310
  async describeResourcePolicyList(options = {}) {
304
311
  const { resourceType } = options;
305
312
  if (resourceType !== undefined && (typeof resourceType !== 'string' || resourceType.trim().length === 0)) {
306
- throw new Error('Invalid resourceType');
313
+ (0, error_1.throwInvalidParam)('Invalid resourceType');
307
314
  }
308
315
  // PG 环境无需调用,直接返回空策略列表
309
316
  if (await this.isPostgresqlEnv()) {
@@ -336,7 +343,7 @@ class PermissionService {
336
343
  async describeEnvAuthzConfig(options) {
337
344
  const { key } = options;
338
345
  if (!key || (key !== 'authz.platform.extension.rego' && key !== 'authz.user.rego')) {
339
- throw new Error('key must be "authz.platform.extension.rego" or "authz.user.rego"');
346
+ (0, error_1.throwInvalidParam)('key must be "authz.platform.extension.rego" or "authz.user.rego"');
340
347
  }
341
348
  const { EnvId } = this.environment.lazyEnvironmentConfig;
342
349
  return this.tcbService.request('DescribeEnvConfig', {
@@ -351,10 +358,10 @@ class PermissionService {
351
358
  const { EnvId } = this.environment.lazyEnvironmentConfig;
352
359
  const { key, value } = options;
353
360
  if (key !== 'authz.user.rego') {
354
- throw new Error('key must be "authz.user.rego"');
361
+ (0, error_1.throwInvalidParam)('key must be "authz.user.rego"');
355
362
  }
356
363
  if (typeof value !== 'string' || value.trim().length === 0) {
357
- throw new Error('value is required and must be a non-empty string');
364
+ (0, error_1.throwInvalidParam)('value is required and must be a non-empty string');
358
365
  }
359
366
  return this.tcbService.request('ModifyEnvConfig', {
360
367
  EnvId,
@@ -34,7 +34,7 @@ class PlatformService {
34
34
  async describePlatforms(params = {}) {
35
35
  const { Limit } = params;
36
36
  if (Limit !== undefined && (!Number.isInteger(Limit) || Limit < 10 || Limit > 100)) {
37
- throw new error_1.CloudBaseError('Limit 必须是 10 至 100 的整数');
37
+ (0, error_1.throwInvalidParam)('Limit 必须是 10 至 100 的整数');
38
38
  }
39
39
  return this.cloudService.request('DescribePlatforms', Object.assign({}, params));
40
40
  }
@@ -109,7 +109,7 @@ class PlatformService {
109
109
  const { Status } = params;
110
110
  const validStatus = ['ENABLE', 'DISABLE'];
111
111
  if (Status !== undefined && !validStatus.includes(Status)) {
112
- throw new error_1.CloudBaseError(`Invalid Status value: ${Status}. Only support 'ENABLE', 'DISABLE'`);
112
+ (0, error_1.throwInvalidParam)(`Invalid Status value: ${Status}. Only support 'ENABLE', 'DISABLE'`);
113
113
  }
114
114
  return this.cloudService.request('ModifyPlatformEnv', Object.assign(Object.assign({}, params), { EnvId: params.EnvId || this.envId }));
115
115
  }