@geek-fun/serverlessinsight 0.7.7 → 0.7.9

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 (34) hide show
  1. package/dist/package.json +15 -14
  2. package/dist/src/common/aliyunClient/ossOperations.js +41 -0
  3. package/dist/src/common/aliyunClient/ramOperations.js +161 -7
  4. package/dist/src/common/iamStatements.js +48 -0
  5. package/dist/src/common/imsClient.js +1 -0
  6. package/dist/src/common/tencentClient/camOperations.js +317 -0
  7. package/dist/src/common/tencentClient/cosOperations.js +67 -0
  8. package/dist/src/common/tencentClient/index.js +18 -0
  9. package/dist/src/common/tencentClient/scfOperations.js +2 -0
  10. package/dist/src/common/volcengineClient/iamOperations.js +133 -47
  11. package/dist/src/common/volcengineClient/tosOperations.js +79 -0
  12. package/dist/src/lang/en.js +24 -0
  13. package/dist/src/lang/zh-CN.js +24 -0
  14. package/dist/src/parser/bucketParser.js +31 -0
  15. package/dist/src/parser/functionParser.js +34 -0
  16. package/dist/src/stack/aliyunStack/fc3Planner.js +2 -1
  17. package/dist/src/stack/aliyunStack/fc3Resource.js +72 -14
  18. package/dist/src/stack/aliyunStack/ossResource.js +63 -0
  19. package/dist/src/stack/aliyunStack/ossTypes.js +9 -0
  20. package/dist/src/stack/scfStack/cosResource.js +58 -0
  21. package/dist/src/stack/scfStack/cosTypes.js +9 -0
  22. package/dist/src/stack/scfStack/scfPlanner.js +1 -1
  23. package/dist/src/stack/scfStack/scfResource.js +195 -22
  24. package/dist/src/stack/scfStack/scfTypes.js +6 -4
  25. package/dist/src/stack/volcengineStack/tosResource.js +56 -0
  26. package/dist/src/stack/volcengineStack/tosTypes.js +9 -0
  27. package/dist/src/stack/volcengineStack/vefaasPlanner.js +2 -1
  28. package/dist/src/stack/volcengineStack/vefaasResource.js +46 -5
  29. package/dist/src/types/domains/state.js +2 -0
  30. package/dist/src/validator/bucketSchema.js +45 -0
  31. package/dist/src/validator/functionSchema.js +43 -0
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +15 -14
  34. package/samples/aliyun-poc-api-cdn.yml +75 -0
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.7.7",
3
+ "version": "0.7.9",
4
4
  "description": "Full life cycle cross providers serverless application management for your fast-growing business.",
5
5
  "homepage": "https://serverlessinsight.geekfun.club",
6
6
  "main": "dist/src/index.js",
@@ -54,14 +54,14 @@
54
54
  ],
55
55
  "dependencies": {
56
56
  "@alicloud/alidns20150109": "^4.4.1",
57
- "@alicloud/cas20200407": "^3.2.8",
57
+ "@alicloud/cas20200407": "^3.2.9",
58
58
  "@alicloud/cdn20180510": "^9.2.0",
59
59
  "@alicloud/cloudapi20160714": "^4.8.0",
60
- "@alicloud/ecs20140526": "^7.8.6",
60
+ "@alicloud/ecs20140526": "^7.9.0",
61
61
  "@alicloud/es-serverless20230627": "^2.3.1",
62
- "@alicloud/fc20230330": "^4.7.7",
63
- "@alicloud/ims20190815": "^2.3.6",
64
- "@alicloud/nas20170626": "^3.4.2",
62
+ "@alicloud/fc20230330": "^4.7.8",
63
+ "@alicloud/ims20190815": "^2.4.1",
64
+ "@alicloud/nas20170626": "^3.5.0",
65
65
  "@alicloud/openapi-client": "^0.4.15",
66
66
  "@alicloud/ram20150501": "^1.2.1",
67
67
  "@alicloud/rds20140815": "^15.9.0",
@@ -73,15 +73,16 @@
73
73
  "commander": "^15.0.0",
74
74
  "cos-nodejs-sdk-v5": "^2.16.0-beta.8",
75
75
  "i18n": "^0.15.3",
76
- "iconv-lite": "^0.7.2",
76
+ "iconv-lite": "^0.7.3",
77
77
  "jszip": "^3.10.1",
78
78
  "lodash": "^4.18.1",
79
79
  "pino": "^10.3.1",
80
80
  "pino-pretty": "^13.1.3",
81
81
  "tablestore": "^5.6.5",
82
- "tencentcloud-sdk-nodejs-cynosdb": "^4.1.257",
83
- "tencentcloud-sdk-nodejs-dnspod": "^4.1.257",
84
- "tencentcloud-sdk-nodejs-es": "^4.1.257",
82
+ "tencentcloud-sdk-nodejs-cam": "^4.1.265",
83
+ "tencentcloud-sdk-nodejs-cynosdb": "^4.1.265",
84
+ "tencentcloud-sdk-nodejs-dnspod": "^4.1.265",
85
+ "tencentcloud-sdk-nodejs-es": "^4.1.263",
85
86
  "tencentcloud-sdk-nodejs-scf": "^4.1.168",
86
87
  "tencentcloud-sdk-nodejs-ssl": "^4.1.239",
87
88
  "yaml": "^2.9.0"
@@ -93,9 +94,9 @@
93
94
  "@types/i18n": "^0.13.12",
94
95
  "@types/jest": "^30.0.0",
95
96
  "@types/lodash": "^4.17.24",
96
- "@types/node": "^26.0.1",
97
- "@typescript-eslint/eslint-plugin": "^8.62.0",
98
- "@typescript-eslint/parser": "^8.62.0",
97
+ "@types/node": "^26.1.1",
98
+ "@typescript-eslint/eslint-plugin": "^8.63.0",
99
+ "@typescript-eslint/parser": "^8.63.0",
99
100
  "cross-env": "^10.1.0",
100
101
  "eslint": "^10.6.0",
101
102
  "eslint-config-prettier": "^10.1.8",
@@ -103,7 +104,7 @@
103
104
  "globals": "^17.7.0",
104
105
  "husky": "^9.1.7",
105
106
  "jest": "^30.4.2",
106
- "prettier": "^3.8.5",
107
+ "prettier": "^3.9.5",
107
108
  "ts-jest": "^29.4.11",
108
109
  "ts-node": "^10.9.2",
109
110
  "typescript": "^6.0.3"
@@ -772,6 +772,47 @@ const parseXmlResponse = (xml, tagName) => {
772
772
  unbindCustomDomain,
773
773
  createCnameToken,
774
774
  getBucketCnameEndpoint,
775
+ putBucketPolicy: async (bucketName, policy) => {
776
+ useBucket(bucketName);
777
+ await ossClient.putBucketPolicy(bucketName, policy);
778
+ logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_POLICY_SET', { bucketName }));
779
+ },
780
+ getBucketPolicy: async (bucketName) => {
781
+ useBucket(bucketName);
782
+ try {
783
+ const result = (await ossClient.getBucketPolicy(bucketName));
784
+ return result.policy
785
+ ? typeof result.policy === 'string'
786
+ ? JSON.parse(result.policy)
787
+ : result.policy
788
+ : null;
789
+ }
790
+ catch (error) {
791
+ if (error &&
792
+ typeof error === 'object' &&
793
+ 'code' in error &&
794
+ error.code === 'NoSuchBucketPolicy') {
795
+ return null;
796
+ }
797
+ throw error;
798
+ }
799
+ },
800
+ deleteBucketPolicy: async (bucketName) => {
801
+ useBucket(bucketName);
802
+ try {
803
+ await ossClient.deleteBucketPolicy(bucketName);
804
+ logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_POLICY_DELETED', { bucketName }));
805
+ }
806
+ catch (error) {
807
+ if (error &&
808
+ typeof error === 'object' &&
809
+ 'code' in error &&
810
+ error.code === 'NoSuchBucketPolicy') {
811
+ return;
812
+ }
813
+ throw error;
814
+ }
815
+ },
775
816
  };
776
817
  };
777
818
  exports.createOssOperations = createOssOperations;
@@ -37,6 +37,7 @@ exports.createRamOperations = void 0;
37
37
  const ram = __importStar(require("@alicloud/ram20150501"));
38
38
  const lang_1 = require("../../lang");
39
39
  const logger_1 = require("../logger");
40
+ const iamStatements_1 = require("../iamStatements");
40
41
  const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
41
42
  Version: '1',
42
43
  Statement: [
@@ -92,14 +93,34 @@ const FC_EXECUTION_POLICY = JSON.stringify({
92
93
  },
93
94
  ],
94
95
  });
96
+ const FC_EXECUTION_STATEMENTS = (0, iamStatements_1.parseBuiltInStatements)(FC_EXECUTION_POLICY);
97
+ const extractPolicyNameFromArn = (arn) => {
98
+ const parts = arn.split('/');
99
+ return parts[parts.length - 1];
100
+ };
101
+ const mapToAliyunStatement = (stmt) => {
102
+ const result = {
103
+ Effect: stmt.effect,
104
+ Action: stmt.action,
105
+ Resource: stmt.resource,
106
+ };
107
+ if (stmt.sid) {
108
+ result.Sid = stmt.sid;
109
+ }
110
+ return result;
111
+ };
112
+ const buildExecutionPolicy = (customStatements) => {
113
+ const merged = (0, iamStatements_1.mergePolicyStatements)(FC_EXECUTION_STATEMENTS, customStatements, mapToAliyunStatement);
114
+ return (0, iamStatements_1.buildPolicyDocument)(merged, { version: '1' });
115
+ };
95
116
  /* istanbul ignore next */ const createRamOperations = (ramClient) => {
96
- const attachRolePolicyForFc = async (roleName) => {
117
+ const attachRolePolicyForFc = async (roleName, customStatements) => {
97
118
  const policyName = `${roleName}-policy`;
98
119
  // Create policy
99
120
  try {
100
121
  const createPolicyRequest = new ram.CreatePolicyRequest({
101
122
  policyName,
102
- policyDocument: FC_EXECUTION_POLICY,
123
+ policyDocument: buildExecutionPolicy(customStatements),
103
124
  description: `FC execution policy for ${roleName}`,
104
125
  });
105
126
  await ramClient.createPolicy(createPolicyRequest);
@@ -133,8 +154,69 @@ const FC_EXECUTION_POLICY = JSON.stringify({
133
154
  }
134
155
  return policyName;
135
156
  };
157
+ const attachManagedPoliciesFn = async (roleName, policies) => {
158
+ for (const policyArn of policies) {
159
+ try {
160
+ const attachRequest = new ram.AttachPolicyToRoleRequest({
161
+ policyType: 'System',
162
+ policyName: extractPolicyNameFromArn(policyArn),
163
+ roleName,
164
+ });
165
+ await ramClient.attachPolicyToRole(attachRequest);
166
+ }
167
+ catch (error) {
168
+ if (error &&
169
+ typeof error === 'object' &&
170
+ 'code' in error &&
171
+ error.code === 'EntityAlreadyExists.Role.Policy') {
172
+ // Already attached - idempotent
173
+ }
174
+ else {
175
+ throw error;
176
+ }
177
+ }
178
+ }
179
+ };
180
+ const detachManagedPoliciesFn = async (roleName, policies) => {
181
+ for (const policyArn of policies) {
182
+ try {
183
+ const detachRequest = new ram.DetachPolicyFromRoleRequest({
184
+ policyType: 'System',
185
+ policyName: extractPolicyNameFromArn(policyArn),
186
+ roleName,
187
+ });
188
+ await ramClient.detachPolicyFromRole(detachRequest);
189
+ }
190
+ catch (error) {
191
+ if (error &&
192
+ typeof error === 'object' &&
193
+ 'code' in error &&
194
+ error.code === 'EntityNotExist.Role.Policy') {
195
+ // Not attached - idempotent
196
+ }
197
+ else {
198
+ throw error;
199
+ }
200
+ }
201
+ }
202
+ };
203
+ const listAttachedRolePoliciesFn = async (roleName) => {
204
+ try {
205
+ const request = new ram.ListPoliciesForRoleRequest({ roleName });
206
+ const response = await ramClient.listPoliciesForRole(request);
207
+ if (!response?.body?.policies?.policy) {
208
+ return [];
209
+ }
210
+ return response.body.policies.policy
211
+ .filter((p) => p.policyType === 'System')
212
+ .map((p) => p.policyName ?? '');
213
+ }
214
+ catch {
215
+ return [];
216
+ }
217
+ };
136
218
  return {
137
- createRole: async (roleName, trustedServices, description) => {
219
+ createRole: async (roleName, trustedServices, description, customStatements, managedPolicies) => {
138
220
  const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
139
221
  try {
140
222
  const request = new ram.CreateRoleRequest({
@@ -153,8 +235,11 @@ const FC_EXECUTION_POLICY = JSON.stringify({
153
235
  maxSessionDuration: response.body?.role?.maxSessionDuration,
154
236
  assumeRolePolicyDocument: assumeRolePolicy,
155
237
  };
156
- const policyName = await attachRolePolicyForFc(roleName);
157
- return { ...roleInfo, policyName };
238
+ const policyName = await attachRolePolicyForFc(roleName, customStatements);
239
+ if (managedPolicies && managedPolicies.length > 0) {
240
+ await attachManagedPoliciesFn(roleName, managedPolicies);
241
+ }
242
+ return { ...roleInfo, policyName, managedPolicies };
158
243
  }
159
244
  catch (error) {
160
245
  if (error &&
@@ -170,7 +255,10 @@ const FC_EXECUTION_POLICY = JSON.stringify({
170
255
  newAssumeRolePolicyDocument: assumeRolePolicy,
171
256
  });
172
257
  await ramClient.updateRole(updateRequest);
173
- const policyName = await attachRolePolicyForFc(roleName);
258
+ const policyName = await attachRolePolicyForFc(roleName, customStatements);
259
+ if (managedPolicies && managedPolicies.length > 0) {
260
+ await attachManagedPoliciesFn(roleName, managedPolicies);
261
+ }
174
262
  return {
175
263
  roleName,
176
264
  roleId: getResponse.body?.role?.roleId,
@@ -181,6 +269,7 @@ const FC_EXECUTION_POLICY = JSON.stringify({
181
269
  maxSessionDuration: getResponse.body?.role?.maxSessionDuration,
182
270
  assumeRolePolicyDocument: assumeRolePolicy,
183
271
  policyName,
272
+ managedPolicies,
184
273
  };
185
274
  }
186
275
  catch (recoveryError) {
@@ -228,6 +317,51 @@ const FC_EXECUTION_POLICY = JSON.stringify({
228
317
  throw error;
229
318
  }
230
319
  },
320
+ updateRolePolicy: async (roleName, customStatements) => {
321
+ const policyName = `${roleName}-policy`;
322
+ try {
323
+ await ramClient.detachPolicyFromRole(new ram.DetachPolicyFromRoleRequest({ policyType: 'Custom', policyName, roleName }));
324
+ }
325
+ catch {
326
+ /* idempotent */
327
+ }
328
+ try {
329
+ await ramClient.deletePolicy(new ram.DeletePolicyRequest({ policyName }));
330
+ }
331
+ catch {
332
+ /* idempotent */
333
+ }
334
+ try {
335
+ await ramClient.createPolicy(new ram.CreatePolicyRequest({
336
+ policyName,
337
+ policyDocument: buildExecutionPolicy(customStatements),
338
+ description: `FC execution policy for ${roleName}`,
339
+ }));
340
+ }
341
+ catch (error) {
342
+ if (error &&
343
+ typeof error === 'object' &&
344
+ 'code' in error &&
345
+ error.code === 'EntityAlreadyExists.Policy') {
346
+ /* idempotent */
347
+ }
348
+ else
349
+ throw error;
350
+ }
351
+ try {
352
+ await ramClient.attachPolicyToRole(new ram.AttachPolicyToRoleRequest({ policyType: 'Custom', policyName, roleName }));
353
+ }
354
+ catch (error) {
355
+ if (error &&
356
+ typeof error === 'object' &&
357
+ 'code' in error &&
358
+ error.code === 'EntityAlreadyExists.Role.Policy') {
359
+ /* idempotent */
360
+ }
361
+ else
362
+ throw error;
363
+ }
364
+ },
231
365
  getRole: async (roleName) => {
232
366
  try {
233
367
  const request = new ram.GetRoleRequest({
@@ -259,8 +393,11 @@ const FC_EXECUTION_POLICY = JSON.stringify({
259
393
  throw error;
260
394
  }
261
395
  },
262
- deleteRole: async (roleName) => {
396
+ deleteRole: async (roleName, managedPolicies) => {
263
397
  const policyName = `${roleName}-policy`;
398
+ if (managedPolicies && managedPolicies.length > 0) {
399
+ await detachManagedPoliciesFn(roleName, managedPolicies);
400
+ }
264
401
  // Detach policy from role
265
402
  try {
266
403
  const detachRequest = new ram.DetachPolicyFromRoleRequest({
@@ -289,6 +426,23 @@ const FC_EXECUTION_POLICY = JSON.stringify({
289
426
  });
290
427
  await ramClient.deleteRole(request);
291
428
  },
429
+ attachManagedPolicies: attachManagedPoliciesFn,
430
+ detachManagedPolicies: detachManagedPoliciesFn,
431
+ listAttachedRolePolicies: listAttachedRolePoliciesFn,
432
+ updateManagedPolicies: async (roleName, desiredPolicies) => {
433
+ const desiredNames = desiredPolicies.map(extractPolicyNameFromArn);
434
+ const currentNames = await listAttachedRolePoliciesFn(roleName);
435
+ const currentSet = new Set(currentNames);
436
+ const desiredSet = new Set(desiredNames);
437
+ const toAttach = desiredPolicies.filter((p) => !currentSet.has(extractPolicyNameFromArn(p)));
438
+ const toDetach = currentNames.filter((n) => !desiredSet.has(n));
439
+ if (toAttach.length > 0) {
440
+ await attachManagedPoliciesFn(roleName, toAttach);
441
+ }
442
+ if (toDetach.length > 0) {
443
+ await detachManagedPoliciesFn(roleName, toDetach);
444
+ }
445
+ },
292
446
  };
293
447
  };
294
448
  exports.createRamOperations = createRamOperations;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ // Provider-agnostic IAM policy statement merge helpers.
3
+ // These functions operate on raw statement arrays and never import
4
+ // provider-specific modules — consumers supply their own map functions.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildPolicyDocument = exports.parseBuiltInStatements = exports.mergePolicyStatements = void 0;
7
+ /**
8
+ * Merge built-in native statements with optional custom user statements.
9
+ * Returns a NEW array — the input arrays are never mutated.
10
+ *
11
+ * @param nativeBuiltIn - The parsed Statement[] from the provider's built-in policy JSON.
12
+ * @param custom - Optional user custom statements in provider-agnostic format.
13
+ * @param mapFn - Converts an IamStatement into the native statement shape for the specific provider.
14
+ * @returns A new array with built-in statements first, then mapped custom statements.
15
+ */
16
+ const mergePolicyStatements = (nativeBuiltIn, custom, mapFn) => {
17
+ if (!custom || custom.length === 0) {
18
+ return nativeBuiltIn;
19
+ }
20
+ const mappedCustom = custom.map(mapFn);
21
+ return [...nativeBuiltIn, ...mappedCustom];
22
+ };
23
+ exports.mergePolicyStatements = mergePolicyStatements;
24
+ /**
25
+ * Parse a provider's built-in policy JSON string into its raw Statement array.
26
+ * Returns an empty array when the JSON is invalid or has no Statement field.
27
+ */
28
+ const parseBuiltInStatements = (policyJson) => {
29
+ const parsed = JSON.parse(policyJson);
30
+ const statement = parsed.Statement;
31
+ return Array.isArray(statement) ? statement : [];
32
+ };
33
+ exports.parseBuiltInStatements = parseBuiltInStatements;
34
+ /**
35
+ * Build a complete policy document JSON string from an array of statements.
36
+ *
37
+ * @param statements - The policy statements to include.
38
+ * @param providerOptions - Optional per-provider options such as version.
39
+ * @returns A JSON-stringified policy document.
40
+ */
41
+ const buildPolicyDocument = (statements, providerOptions) => {
42
+ const doc = { Statement: statements };
43
+ if (providerOptions?.version) {
44
+ doc.Version = providerOptions.version;
45
+ }
46
+ return JSON.stringify(doc);
47
+ };
48
+ exports.buildPolicyDocument = buildPolicyDocument;
@@ -45,6 +45,7 @@ const getIamInfo = async (context) => {
45
45
  const imsConfig = new openApi.Config({
46
46
  accessKeyId: context.accessKeyId,
47
47
  accessKeySecret: context.accessKeySecret,
48
+ regionId: context.region,
48
49
  });
49
50
  imsConfig.connectTimeout = constants_1.ALIYUN_FC3_CONNECT_TIMEOUT_MS;
50
51
  imsConfig.readTimeout = constants_1.ALIYUN_FC3_READ_TIMEOUT_MS;