@cloudbase/manager-node 5.8.9-beta.0 → 5.9.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/.codebuddy/rules/error-code-contract.mdc +13 -0
- package/CHANGELOG.md +1 -0
- package/lib/agent/index.js +6 -5
- package/lib/aiModel/index.js +21 -9
- package/lib/cloudApp/index.js +4 -4
- package/lib/cloudrun/index.js +16 -15
- package/lib/common/index.js +1 -1
- package/lib/database/index.js +23 -23
- package/lib/deploy/DatabaseDeployer.js +19 -24
- package/lib/deploy/DeployOrchestrator.js +2 -2
- package/lib/deploy/FunctionDeployer.js +19 -1
- package/lib/deploy/GatewayDeployer.js +5 -5
- package/lib/deploy/StaticDeployer.js +2 -2
- package/lib/deploy/framework.js +2 -1
- package/lib/deploy/function/config-guard.js +23 -3
- package/lib/deploy/function/enterprise-tcr.js +18 -2
- package/lib/docs/index.js +4 -3
- package/lib/env/index.js +16 -16
- package/lib/environment.js +4 -4
- package/lib/environmentManager.js +5 -1
- package/lib/error-docs.js +385 -0
- package/lib/error-types.js +21 -0
- package/lib/error.js +239 -2
- package/lib/function/index.js +135 -41
- package/lib/function/packer.js +1 -1
- package/lib/hosting/index.js +1 -1
- package/lib/index.js +2 -1
- package/lib/integration/crypto.js +4 -3
- package/lib/integration/index.js +1 -1
- package/lib/integration/secretKey.js +4 -4
- package/lib/monitor/index.js +1 -1
- package/lib/mysql/index.js +2 -1
- package/lib/permission/index.js +56 -49
- package/lib/platform/index.js +2 -2
- package/lib/sandbox/index.js +68 -61
- package/lib/storage/index.js +164 -162
- package/lib/user/index.js +32 -31
- package/lib/utils/cloud-api-request.js +13 -5
- package/lib/utils/cloudbase-request.js +21 -0
- package/lib/utils/fs.js +3 -3
- package/lib/utils/http-request.js +2 -2
- package/lib/utils/index.js +4 -3
- package/lib/utils/storage-config.js +3 -3
- package/package.json +2 -2
- package/types/error-docs.d.ts +57 -0
- package/types/error-types.d.ts +32 -0
- package/types/error.d.ts +148 -2
- package/types/function/index.d.ts +14 -1
- package/types/utils/cloudbase-request.d.ts +22 -0
package/lib/permission/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
36
|
+
(0, error_1.throwInvalidParam)('Invalid resource');
|
|
36
37
|
}
|
|
37
38
|
const allowed = PERMISSION_BY_RESOURCE[resourceType];
|
|
38
39
|
if (!allowed.includes(permission)) {
|
|
39
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
66
|
+
(0, error_1.throwInvalidParam)('Invalid resourceType');
|
|
66
67
|
}
|
|
67
68
|
if (resources !== undefined) {
|
|
68
69
|
if (!Array.isArray(resources)) {
|
|
69
|
-
|
|
70
|
+
(0, error_1.throwInvalidParam)('Invalid resources');
|
|
70
71
|
}
|
|
71
72
|
if (resources.length > 100) {
|
|
72
|
-
|
|
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
|
-
|
|
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
|
-
|
|
87
|
+
(0, error_1.throwInvalidParam)('roleName is required');
|
|
87
88
|
}
|
|
88
89
|
if (roleName.length < 2 || roleName.length > 32) {
|
|
89
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
100
|
+
(0, error_1.throwInvalidParam)('roleIdentity is required');
|
|
100
101
|
}
|
|
101
102
|
if (!/^[a-zA-Z0-9\-_:@.]+$/.test(roleIdentity)) {
|
|
102
|
-
|
|
103
|
+
(0, error_1.throwInvalidParam)('roleIdentity can only contain letters, digits, and -_:@.');
|
|
103
104
|
}
|
|
104
105
|
// Description 校验
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
115
|
+
(0, error_1.throwInvalidParam)('memberUids must be an array');
|
|
112
116
|
}
|
|
113
117
|
if (memberUids.length > 100) {
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
128
|
+
(0, error_1.throwInvalidParam)('policies must be an array');
|
|
125
129
|
}
|
|
126
130
|
if (policies.length > 50) {
|
|
127
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
214
|
+
(0, error_1.throwInvalidParam)('roleName can only contain Chinese, letters, digits, and -_:@.');
|
|
211
215
|
}
|
|
212
216
|
}
|
|
213
217
|
// Description 校验
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
291
|
+
(0, error_1.throwInvalidParam)('roleIds is required and must be a non-empty array');
|
|
285
292
|
}
|
|
286
293
|
if (roleIds.length > 100) {
|
|
287
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
361
|
+
(0, error_1.throwInvalidParam)('key must be "authz.user.rego"');
|
|
355
362
|
}
|
|
356
363
|
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
357
|
-
|
|
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,
|
package/lib/platform/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
}
|